diff --git a/src/doc/en/reference/rings/index.rst b/src/doc/en/reference/rings/index.rst index d43d1be4003..52847e952b4 100644 --- a/src/doc/en/reference/rings/index.rst +++ b/src/doc/en/reference/rings/index.rst @@ -8,6 +8,7 @@ Base Classes for Rings, Algebras and Fields :maxdepth: 1 sage/rings/ring + sage/rings/abc Ideals ------ diff --git a/src/sage/misc/cachefunc.pyx b/src/sage/misc/cachefunc.pyx index 9715726659b..bf6aafdc2a7 100644 --- a/src/sage/misc/cachefunc.pyx +++ b/src/sage/misc/cachefunc.pyx @@ -850,6 +850,7 @@ cdef class CachedFunction(): sage: I = P*[x,y] sage: from sage.misc.sageinspect import sage_getdoc sage: print(sage_getdoc(I.groebner_basis)) # indirect doctest + WARNING: the enclosing module is marked... Return the reduced Groebner basis of this ideal. ... diff --git a/src/sage/misc/latex.py b/src/sage/misc/latex.py index 5dc3fbe5ecd..c915ae00e2f 100644 --- a/src/sage/misc/latex.py +++ b/src/sage/misc/latex.py @@ -647,6 +647,7 @@ def latex_extra_preamble(): \newcommand{\RLF}{\Bold{R}} \newcommand{\SL}{\mathrm{SL}} \newcommand{\PSL}{\mathrm{PSL}} + \newcommand{\lcm}{\mathop{\operatorname{lcm}}} \newcommand{\Bold}[1]{\mathbf{#1}} """ diff --git a/src/sage/misc/latex_macros.py b/src/sage/misc/latex_macros.py index 1605d8a22f5..238bd02c0e3 100644 --- a/src/sage/misc/latex_macros.py +++ b/src/sage/misc/latex_macros.py @@ -173,7 +173,8 @@ def convert_latex_macro_to_mathjax(macro): # Use this list to define additional latex macros for sage documentation latex_macros = [r"\newcommand{\SL}{\mathrm{SL}}", - r"\newcommand{\PSL}{\mathrm{PSL}}"] + r"\newcommand{\PSL}{\mathrm{PSL}}", + r"\newcommand{\lcm}{\mathop{\operatorname{lcm}}}"] # The following is to allow customization of typesetting of rings: # mathbf vs mathbb. See latex.py for more information. diff --git a/src/sage/misc/sageinspect.py b/src/sage/misc/sageinspect.py index 7264d1b697b..7511b28fbc9 100644 --- a/src/sage/misc/sageinspect.py +++ b/src/sage/misc/sageinspect.py @@ -1920,8 +1920,8 @@ def _sage_getdoc_unformatted(obj): Integer(x=None, base=0) File: sage/rings/integer.pyx (starting at line ...) - The ``Integer`` class represents arbitrary precision - integers. It derives from the ``Element`` class, so + The :class:`Integer` class represents arbitrary precision + integers. It derives from the :class:`Element` class, so integers can be used as ring elements anywhere in Sage. ... @@ -1995,8 +1995,8 @@ def sage_getdoc_original(obj): sage: print(sage_getdoc_original(sage.rings.integer.Integer)) - The ``Integer`` class represents arbitrary precision - integers. It derives from the ``Element`` class, so + The :class:`Integer` class represents arbitrary precision + integers. It derives from the :class:`Element` class, so integers can be used as ring elements anywhere in Sage. ... diff --git a/src/sage/rings/abc.pyx b/src/sage/rings/abc.pyx index 4d4e9bfd104..77536d718bb 100644 --- a/src/sage/rings/abc.pyx +++ b/src/sage/rings/abc.pyx @@ -14,13 +14,13 @@ class NumberField_quadratic(Field): EXAMPLES:: sage: import sage.rings.abc - sage: K. = QuadraticField(2) # optional - sage.rings.number_field - sage: isinstance(K, sage.rings.abc.NumberField_quadratic) # optional - sage.rings.number_field + sage: K. = QuadraticField(2) # optional - sage.rings.number_field + sage: isinstance(K, sage.rings.abc.NumberField_quadratic) # optional - sage.rings.number_field True By design, there is a unique direct subclass:: - sage: sage.rings.abc.NumberField_quadratic.__subclasses__() # optional - sage.rings.number_field + sage: sage.rings.abc.NumberField_quadratic.__subclasses__() # optional - sage.rings.number_field [] sage: len(sage.rings.abc.NumberField_quadratic.__subclasses__()) <= 1 @@ -40,13 +40,13 @@ class NumberField_cyclotomic(Field): EXAMPLES:: sage: import sage.rings.abc - sage: K. = CyclotomicField(15) # optional - sage.rings.number_field - sage: isinstance(K, sage.rings.abc.NumberField_cyclotomic) # optional - sage.rings.number_field + sage: K. = CyclotomicField(15) # optional - sage.rings.number_field + sage: isinstance(K, sage.rings.abc.NumberField_cyclotomic) # optional - sage.rings.number_field True By design, there is a unique direct subclass:: - sage: sage.rings.abc.NumberField_cyclotomic.__subclasses__() # optional - sage.rings.number_field + sage: sage.rings.abc.NumberField_cyclotomic.__subclasses__() # optional - sage.rings.number_field [] sage: len(sage.rings.abc.NumberField_cyclotomic.__subclasses__()) <= 1 @@ -66,16 +66,16 @@ class AlgebraicField_common(Field): EXAMPLES:: sage: import sage.rings.abc - sage: isinstance(QQbar, sage.rings.abc.AlgebraicField_common) # optional - sage.rings.number_field + sage: isinstance(QQbar, sage.rings.abc.AlgebraicField_common) # optional - sage.rings.number_field True - sage: isinstance(AA, sage.rings.abc.AlgebraicField_common) # optional - sage.rings.number_field + sage: isinstance(AA, sage.rings.abc.AlgebraicField_common) # optional - sage.rings.number_field True By design, other than the abstract subclasses :class:`~sage.rings.abc.AlgebraicField` and :class:`~sage.rings.abc.AlgebraicRealField`, there is only one direct implementation subclass:: - sage: sage.rings.abc.AlgebraicField_common.__subclasses__() # optional - sage.rings.number_field + sage: sage.rings.abc.AlgebraicField_common.__subclasses__() # optional - sage.rings.number_field [, , ] @@ -97,14 +97,14 @@ class AlgebraicField(AlgebraicField_common): EXAMPLES:: sage: import sage.rings.abc - sage: isinstance(QQbar, sage.rings.abc.AlgebraicField) # optional - sage.rings.number_field + sage: isinstance(QQbar, sage.rings.abc.AlgebraicField) # optional - sage.rings.number_field True - sage: isinstance(AA, sage.rings.abc.AlgebraicField) # optional - sage.rings.number_field + sage: isinstance(AA, sage.rings.abc.AlgebraicField) # optional - sage.rings.number_field False By design, there is a unique direct subclass:: - sage: sage.rings.abc.AlgebraicField.__subclasses__() # optional - sage.rings.number_field + sage: sage.rings.abc.AlgebraicField.__subclasses__() # optional - sage.rings.number_field [] sage: len(sage.rings.abc.AlgebraicField.__subclasses__()) <= 1 @@ -124,14 +124,14 @@ class AlgebraicRealField(AlgebraicField_common): EXAMPLES:: sage: import sage.rings.abc - sage: isinstance(QQbar, sage.rings.abc.AlgebraicRealField) # optional - sage.rings.number_field + sage: isinstance(QQbar, sage.rings.abc.AlgebraicRealField) # optional - sage.rings.number_field False - sage: isinstance(AA, sage.rings.abc.AlgebraicRealField) # optional - sage.rings.number_field + sage: isinstance(AA, sage.rings.abc.AlgebraicRealField) # optional - sage.rings.number_field True By design, there is a unique direct subclass:: - sage: sage.rings.abc.AlgebraicRealField.__subclasses__() # optional - sage.rings.number_field + sage: sage.rings.abc.AlgebraicRealField.__subclasses__() # optional - sage.rings.number_field [] sage: len(sage.rings.abc.AlgebraicRealField.__subclasses__()) <= 1 @@ -376,13 +376,13 @@ class Order: EXAMPLES:: sage: import sage.rings.abc - sage: K. = NumberField(x^2 + 1); O = K.order(2*a) # optional - sage.rings.number_field - sage: isinstance(O, sage.rings.abc.Order) # optional - sage.rings.number_field + sage: K. = NumberField(x^2 + 1); O = K.order(2*a) # optional - sage.rings.number_field + sage: isinstance(O, sage.rings.abc.Order) # optional - sage.rings.number_field True By design, there is a unique direct subclass:: - sage: sage.rings.abc.Order.__subclasses__() # optional - sage.rings.number_field + sage: sage.rings.abc.Order.__subclasses__() # optional - sage.rings.number_field [] sage: len(sage.rings.abc.Order.__subclasses__()) <= 1 @@ -402,14 +402,14 @@ class pAdicRing(EuclideanDomain): EXAMPLES:: sage: import sage.rings.abc - sage: isinstance(Zp(5), sage.rings.abc.pAdicRing) + sage: isinstance(Zp(5), sage.rings.abc.pAdicRing) # optional - sage.rings.padics True - sage: isinstance(Qp(5), sage.rings.abc.pAdicRing) + sage: isinstance(Qp(5), sage.rings.abc.pAdicRing) # optional - sage.rings.padics False By design, there is a unique direct subclass:: - sage: sage.rings.abc.pAdicRing.__subclasses__() + sage: sage.rings.abc.pAdicRing.__subclasses__() # optional - sage.rings.padics [] sage: len(sage.rings.abc.pAdicRing.__subclasses__()) <= 1 @@ -429,14 +429,14 @@ class pAdicField(Field): EXAMPLES:: sage: import sage.rings.abc - sage: isinstance(Zp(5), sage.rings.abc.pAdicField) + sage: isinstance(Zp(5), sage.rings.abc.pAdicField) # optional - sage.rings.padics False - sage: isinstance(Qp(5), sage.rings.abc.pAdicField) + sage: isinstance(Qp(5), sage.rings.abc.pAdicField) # optional - sage.rings.padics True By design, there is a unique direct subclass:: - sage: sage.rings.abc.pAdicField.__subclasses__() + sage: sage.rings.abc.pAdicField.__subclasses__() # optional - sage.rings.padics [] sage: len(sage.rings.abc.pAdicField.__subclasses__()) <= 1 @@ -456,13 +456,13 @@ cdef class SymbolicRing(CommutativeRing): EXAMPLES:: sage: import sage.rings.abc - sage: isinstance(SR, sage.rings.abc.SymbolicRing) # optional - sage.symbolic + sage: isinstance(SR, sage.rings.abc.SymbolicRing) # optional - sage.symbolic True By design, other than the abstract subclass :class:`~sage.rings.abc.CallableSymbolicExpressionRing`, there is only one direct implementation subclass:: - sage: sage.rings.abc.SymbolicRing.__subclasses__() # optional - sage.symbolic + sage: sage.rings.abc.SymbolicRing.__subclasses__() # optional - sage.symbolic [, ] @@ -483,13 +483,13 @@ class CallableSymbolicExpressionRing(SymbolicRing): EXAMPLES:: sage: import sage.rings.abc - sage: f = x.function(x).parent() # optional - sage.symbolic - sage: isinstance(f, sage.rings.abc.CallableSymbolicExpressionRing) # optional - sage.symbolic + sage: f = x.function(x).parent() # optional - sage.symbolic + sage: isinstance(f, sage.rings.abc.CallableSymbolicExpressionRing) # optional - sage.symbolic True By design, there is a unique direct subclass:: - sage: sage.rings.abc.CallableSymbolicExpressionRing.__subclasses__() # optional - sage.symbolic + sage: sage.rings.abc.CallableSymbolicExpressionRing.__subclasses__() # optional - sage.symbolic [] sage: len(sage.rings.abc.CallableSymbolicExpressionRing.__subclasses__()) <= 1 diff --git a/src/sage/rings/algebraic_closure_finite_field.py b/src/sage/rings/algebraic_closure_finite_field.py index 6f6b93955cb..fb62627c9dc 100644 --- a/src/sage/rings/algebraic_closure_finite_field.py +++ b/src/sage/rings/algebraic_closure_finite_field.py @@ -1,3 +1,4 @@ +# sage.doctest: optional - sage.rings.finite_rings r""" Algebraic closures of finite fields diff --git a/src/sage/rings/bernmm.pyx b/src/sage/rings/bernmm.pyx index 00a3da0d1ff..fb633e2d6f1 100644 --- a/src/sage/rings/bernmm.pyx +++ b/src/sage/rings/bernmm.pyx @@ -13,7 +13,7 @@ Cython wrapper for bernmm library AUTHOR: - - David Harvey (2008-06): initial version +- David Harvey (2008-06): initial version """ #***************************************************************************** @@ -42,18 +42,18 @@ from sage.rings.rational cimport Rational def bernmm_bern_rat(long k, int num_threads = 1): r""" - Computes k-th Bernoulli number using a multimodular algorithm. + Compute `k`-th Bernoulli number using a multimodular algorithm. (Wrapper for bernmm library.) INPUT: - - k -- non-negative integer - - num_threads -- integer >= 1, number of threads to use + - ``k`` -- non-negative integer + - ``num_threads`` -- integer `\geq 1`, number of threads to use COMPLEXITY: - Pretty much quadratic in `k`. See the paper "A multimodular algorithm - for computing Bernoulli numbers", David Harvey, 2008, for more details. + Pretty much quadratic in `k`. See the paper "A multimodular algorithm + for computing Bernoulli numbers", David Harvey, 2008, for more details. EXAMPLES:: @@ -98,18 +98,18 @@ def bernmm_bern_rat(long k, int num_threads = 1): def bernmm_bern_modp(long p, long k): r""" - Computes `B_k \mod p`, where `B_k` is the k-th Bernoulli number. + Compute `B_k \mod p`, where `B_k` is the `k`-th Bernoulli number. - If `B_k` is not `p`-integral, returns -1. + If `B_k` is not `p`-integral, return `-1`. INPUT: - p -- a prime - k -- non-negative integer + - ``p`` -- a prime + - ``k`` -- non-negative integer COMPLEXITY: - Pretty much linear in `p`. + Pretty much linear in `p`. EXAMPLES:: diff --git a/src/sage/rings/bernoulli_mod_p.pyx b/src/sage/rings/bernoulli_mod_p.pyx index b46c6b41da1..53f1a5fb040 100644 --- a/src/sage/rings/bernoulli_mod_p.pyx +++ b/src/sage/rings/bernoulli_mod_p.pyx @@ -53,11 +53,9 @@ def verify_bernoulli_mod_p(data): INPUT: - data -- list, same format as output of bernoulli_mod_p function + - ``data`` -- list, same format as output of :func:`bernoulli_mod_p` function - OUTPUT: - - bool -- True if checksum passed + OUTPUT: bool -- True if checksum passed EXAMPLES:: @@ -102,7 +100,7 @@ def bernoulli_mod_p(int p): INPUT: - p -- integer, a prime + - ``p`` -- integer, a prime OUTPUT: @@ -134,7 +132,7 @@ def bernoulli_mod_p(int p): AUTHOR: - -- David Harvey (2006-08-06) + - David Harvey (2006-08-06) """ @@ -233,12 +231,12 @@ def bernoulli_mod_p_single(long p, long k): r""" Return the Bernoulli number `B_k` mod `p`. - If `B_k` is not `p`-integral, an ArithmeticError is raised. + If `B_k` is not `p`-integral, an :class:`ArithmeticError` is raised. INPUT: - - p -- integer, a prime - - k -- non-negative integer + - ``p`` -- integer, a prime + - ``k`` -- non-negative integer OUTPUT: @@ -274,7 +272,7 @@ def bernoulli_mod_p_single(long p, long k): ... ValueError: k must be non-negative - Check results against bernoulli_mod_p:: + Check results against :class:`bernoulli_mod_p`:: sage: bernoulli_mod_p(37) [1, 31, 16, 15, 16, 4, 17, 32, 22, 31, 15, 15, 17, 12, 29, 2, 0, 2] @@ -303,8 +301,8 @@ def bernoulli_mod_p_single(long p, long k): AUTHOR: - -- David Harvey (2007-08-31) - -- David Harvey (2008-06): rewrote to use bernmm library + - David Harvey (2007-08-31) + - David Harvey (2008-06): rewrote to use bernmm library """ if p <= 2: diff --git a/src/sage/rings/cfinite_sequence.py b/src/sage/rings/cfinite_sequence.py index 2c109271b5b..14ae02423e4 100644 --- a/src/sage/rings/cfinite_sequence.py +++ b/src/sage/rings/cfinite_sequence.py @@ -1038,7 +1038,7 @@ def an_element(self): def __contains__(self, x): """ - Return True if x is an element of ``CFiniteSequences`` or + Return ``True`` if x is an element of ``CFiniteSequences`` or canonically coerces to this ring. EXAMPLES:: diff --git a/src/sage/rings/complex_arb.pyx b/src/sage/rings/complex_arb.pyx index f17ff37893c..8412cabd59a 100644 --- a/src/sage/rings/complex_arb.pyx +++ b/src/sage/rings/complex_arb.pyx @@ -101,12 +101,13 @@ Coercion Automatic coercions work as expected:: - sage: bpol = 1/3*CBF(i) + AA(sqrt(2)) + (polygen(RealBallField(20), 'x') + QQbar(i)) - sage: bpol + 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 x + [1.41421 +/- ...e-6] + [1.33333 +/- ...e-6]*I - sage: bpol.parent() + sage: bpol.parent() # optional - sage.symbolic Univariate Polynomial Ring in x over Complex ball field with 20 bits of precision - sage: bpol/3 + sage: bpol/3 # optional - sage.symbolic ([0.333333 +/- ...e-7])*x + [0.47140 +/- ...e-6] + [0.44444 +/- ...e-6]*I TESTS:: @@ -116,12 +117,12 @@ TESTS:: :: - sage: SR.coerce(CBF(0.42 + 3.33*I)) + sage: SR.coerce(CBF(0.42 + 3.33*I)) # optional - 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() + sage: log(SR(CBF(0.42))).pyobject().parent() # optional - sage.symbolic Complex ball field with 53 bits of precision :trac:`24621`:: @@ -592,15 +593,15 @@ class ComplexBallField(UniqueRepresentation, sage.rings.abc.ComplexBallField): 1.000000000000000 sage: CBF(1, 1) 1.000000000000000 + 1.000000000000000*I - sage: CBF(pi, sqrt(2)) + sage: CBF(pi, sqrt(2)) # optional - sage.symbolic [3.141592653589793 +/- ...e-16] + [1.414213562373095 +/- ...e-16]*I sage: CBF(I) 1.000000000000000*I - sage: CBF(pi+I/3) + sage: CBF(pi + I/3) # optional - 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))) + sage: CBF(AA(sqrt(2))) # optional - sage.symbolic [1.414213562373095 +/- ...e-16] sage: CBF(CIF(0, 1)) 1.000000000000000*I @@ -637,13 +638,13 @@ class ComplexBallField(UniqueRepresentation, sage.rings.abc.ComplexBallField): The following conversions used to yield incorrect enclosures:: - sage: a = CBF(airy_ai(1)); a + sage: a = CBF(airy_ai(1)); a # optional - sage.symbolic [0.1352924163128814 +/- 6.95e-17] - sage: a.overlaps(ComplexBallField(100).one().airy_ai()) + sage: a.overlaps(ComplexBallField(100).one().airy_ai()) # optional - sage.symbolic True - sage: v = CBF(zetaderiv(1, 3/2)); v + sage: v = CBF(zetaderiv(1, 3/2)); v # optional - sage.symbolic [-3.932239737431101 +/- 5.58e-16] - sage: v.overlaps(ComplexBallField(100)(3/2).zetaderiv(1)) + sage: v.overlaps(ComplexBallField(100)(3/2).zetaderiv(1)) # optional - sage.symbolic True """ try: @@ -1086,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 + sage: RBF(integral(sqrt(x), x, 1, 2)) # long time # optional - sage.symbolic [1.21895141649746 +/- ...e-15] sage: wrong = CBF.integral(lambda z, _: z.sqrt(), 1, 2) # WRONG! sage: correct - wrong @@ -2449,7 +2450,7 @@ cdef class ComplexBall(RingElement): OUTPUT: - Return True iff ``self`` and ``other`` are equal as sets, i.e. if their + Return ``True`` iff ``self`` and ``other`` are equal as sets, i.e. if their real and imaginary parts each have the same midpoint and radius. Note that this is not the same thing as testing whether both ``self`` @@ -2470,7 +2471,7 @@ cdef class ComplexBall(RingElement): def overlaps(self, ComplexBall other): """ - Return True iff ``self`` and ``other`` have some point in common. + Return ``True`` iff ``self`` and ``other`` have some point in common. INPUT: @@ -2509,7 +2510,7 @@ cdef class ComplexBall(RingElement): sage: CBF(1).contains_exact(CBF(1)) True - sage: CBF(sqrt(2)).contains_exact(sqrt(2)) + sage: CBF(sqrt(2)).contains_exact(sqrt(2)) # optional - sage.symbolic Traceback (most recent call last): ... TypeError: unsupported type: @@ -2538,7 +2539,7 @@ cdef class ComplexBall(RingElement): def __contains__(self, other): """ - Return True if ``other`` can be verified to be contained in ``self``. + Return ``True`` if ``other`` can be verified to be contained in ``self``. Depending on the type of ``other``, the test may use interval arithmetic with a precision determined by the parent of ``self`` and @@ -2834,7 +2835,7 @@ cdef class ComplexBall(RingElement): -1024.000000000000 sage: CBF(1,1) ^ -1r 0.5000000000000000 - 0.5000000000000000*I - sage: CBF(2)**SR.var('x') + sage: CBF(2)**SR.var('x') # optional - sage.symbolic 2.000000000000000^x """ if (isinstance(base, ComplexBall) @@ -2868,7 +2869,7 @@ cdef class ComplexBall(RingElement): TESTS:: - sage: CBF(2).pow(SR.var('x')) + sage: CBF(2).pow(SR.var('x')) # optional - sage.symbolic Traceback (most recent call last): ... TypeError: no canonical coercion from Symbolic Ring to Complex ball @@ -3847,9 +3848,9 @@ cdef class ComplexBall(RingElement): sage: CBF(1, pi).hypergeometric([1/4], [1/4]) [-2.7182818284590 +/- ...e-14] + [+/- ...e-14]*I - sage: CBF(1000, 1000).hypergeometric([10], [AA(sqrt(2))]) + sage: CBF(1000, 1000).hypergeometric([10], [AA(sqrt(2))]) # optional - sage.symbolic [9.79300951360e+454 +/- ...e+442] + [5.522579106816e+455 +/- ...e+442]*I - sage: CBF(1000, 1000).hypergeometric([100], [AA(sqrt(2))]) + sage: CBF(1000, 1000).hypergeometric([100], [AA(sqrt(2))]) # optional - sage.symbolic [1.27967355557e+590 +/- ...e+578] + [-9.32333491987e+590 +/- ...e+578]*I sage: CBF(0, 1).hypergeometric([], [1/2, 1/3, 1/4]) @@ -3883,7 +3884,7 @@ cdef class ComplexBall(RingElement): TESTS:: - sage: CBF(0, 1).hypergeometric([QQbar(sqrt(2)), RLF(pi)], [1r, 1/2]) + sage: CBF(0, 1).hypergeometric([QQbar(sqrt(2)), RLF(pi)], [1r, 1/2]) # optional - sage.symbolic [-8.7029449215408 +/- ...e-14] + [-0.8499070546106 +/- ...e-14]*I """ @@ -4483,12 +4484,12 @@ cdef class ComplexBall(RingElement): EXAMPLES:: - sage: tau = CBF(sqrt(2),pi) - sage: tau.modular_lambda() + sage: tau = CBF(sqrt(2),pi) # optional - sage.symbolic + sage: tau.modular_lambda() # optional - sage.symbolic [-0.00022005123884157 +/- ...e-18] + [-0.00079787346459944 +/- ...e-18]*I - sage: (tau + 2).modular_lambda() + sage: (tau + 2).modular_lambda() # optional - sage.symbolic [-0.00022005123884157 +/- ...e-18] + [-0.00079787346459944 +/- ...e-18]*I - sage: (tau / (1 - 2*tau)).modular_lambda() + sage: (tau / (1 - 2*tau)).modular_lambda() # optional - sage.symbolic [-0.00022005123884 +/- ...e-15] + [-0.00079787346460 +/- ...e-15]*I """ @@ -4568,19 +4569,19 @@ cdef class ComplexBall(RingElement): EXAMPLES:: sage: tau = CBF(1,4) - sage: z = CBF(sqrt(2), sqrt(3)) - sage: z.elliptic_p(tau) + sage: z = CBF(sqrt(2), sqrt(3)) # optional - sage.symbolic + sage: z.elliptic_p(tau) # optional - sage.symbolic [-3.28920996772709 +/- ...e-15] + [-0.0003673767302933 +/- ...e-17]*I - sage: (z + tau).elliptic_p(tau) + sage: (z + tau).elliptic_p(tau) # optional - sage.symbolic [-3.28920996772709 +/- ...e-15] + [-0.000367376730293 +/- ...e-16]*I - sage: (z + 1).elliptic_p(tau) + sage: (z + 1).elliptic_p(tau) # optional - sage.symbolic [-3.28920996772709 +/- ...e-15] + [-0.0003673767302933 +/- ...e-17]*I - sage: z.elliptic_p(tau, 3) + sage: z.elliptic_p(tau, 3) # optional - 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) + sage: (z + 3 + 4*tau).elliptic_p(tau, 3) # optional - 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] @@ -4619,7 +4620,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() + sage: CBF(sqrt(2)/2, sqrt(2)/2).elliptic_invariants() # optional - sage.symbolic ([+/- ...e-12] + [-332.5338031465...]*I, [1254.46842157...] + [1254.46842157...]*I) """ diff --git a/src/sage/rings/complex_double.pyx b/src/sage/rings/complex_double.pyx index 332977164f4..b4fec10c68a 100644 --- a/src/sage/rings/complex_double.pyx +++ b/src/sage/rings/complex_double.pyx @@ -473,13 +473,13 @@ cdef class ComplexDoubleField_class(sage.rings.abc.ComplexDoubleField): EXAMPLES:: - sage: CDF._magma_init_(magma) # optional - magma + sage: CDF._magma_init_(magma) # optional - magma 'ComplexField(53 : Bits := true)' - sage: magma(CDF) # optional - magma + sage: magma(CDF) # optional - magma Complex field of precision 15 sage: floor(RR(log(2**53, 10))) 15 - sage: magma(CDF).sage() # optional - magma + sage: magma(CDF).sage() # optional - magma Complex Field with 53 bits of precision """ return "ComplexField(%s : Bits := true)" % self.prec() @@ -1565,7 +1565,7 @@ cdef class ComplexDoubleElement(FieldElement): def is_integer(self): """ - Returns True if this number is a integer + Return ``True`` if this number is a integer EXAMPLES:: @@ -2570,11 +2570,11 @@ cdef class ComplexToCDF(Morphism): EXAMPLES:: - sage: import numpy - sage: f = CDF.coerce_map_from(numpy.complex_) - sage: f(numpy.complex_(I)) + sage: import numpy # optional - numpy + sage: f = CDF.coerce_map_from(numpy.complex_) # optional - numpy + sage: f(numpy.complex_(I)) # optional - numpy 1.0*I - sage: f(numpy.complex_(I)).parent() + sage: f(numpy.complex_(I)).parent() # optional - numpy Complex Double Field """ def __init__(self, R): @@ -2590,8 +2590,8 @@ cdef class ComplexToCDF(Morphism): EXAMPLES:: - sage: import numpy - sage: CDF(numpy.complex_(I)) # indirect doctest + sage: import numpy # optional - numpy + sage: CDF(numpy.complex_(I)) # indirect doctest # optional - numpy 1.0*I """ cdef ComplexDoubleElement z = ComplexDoubleElement.__new__(ComplexDoubleElement) @@ -2604,9 +2604,9 @@ cdef class ComplexToCDF(Morphism): EXAMPLES:: - sage: import numpy - sage: f = sage.rings.complex_double.ComplexToCDF(numpy.complex_) - sage: f._repr_type() + sage: import numpy # optional - numpy + sage: f = sage.rings.complex_double.ComplexToCDF(numpy.complex_) # optional - numpy + sage: f._repr_type() # optional - numpy 'Native' """ return "Native" diff --git a/src/sage/rings/complex_mpfr.pyx b/src/sage/rings/complex_mpfr.pyx index 4fc6c4c8d35..86ebff0b4d0 100644 --- a/src/sage/rings/complex_mpfr.pyx +++ b/src/sage/rings/complex_mpfr.pyx @@ -762,7 +762,7 @@ class ComplexField_class(sage.rings.abc.ComplexField): INPUT: - - ``n`` - an integer (default: 2) + - ``n`` -- an integer (default: 2) OUTPUT: a complex `n`-th root of unity. @@ -1039,10 +1039,10 @@ cdef class ComplexNumber(sage.structure.element.FieldElement): EXAMPLES:: - sage: import numpy - sage: numpy.array([1.0, 2.5j]).dtype + sage: import numpy # optional - numpy + sage: numpy.array([1.0, 2.5j]).dtype # optional - numpy dtype('complex128') - sage: numpy.array([1.000000000000000000000000000000000000j]).dtype + sage: numpy.array([1.000000000000000000000000000000000000j]).dtype # optional - numpy dtype('O') """ if self._prec <= 53: @@ -1183,7 +1183,7 @@ cdef class ComplexNumber(sage.structure.element.FieldElement): INPUT: - - ``i`` - 0 or 1 + - ``i`` -- 0 or 1 - ``0`` -- will return the real component of ``self`` - ``1`` -- will return the imaginary component of ``self`` @@ -1266,20 +1266,19 @@ cdef class ComplexNumber(sage.structure.element.FieldElement): EXAMPLES:: - sage: a = CC(pi + I*e) - sage: a + sage: a = CC(pi + I*e); a # optional - sage.symbolic 3.14159265358979 + 2.71828182845905*I - sage: a.str(truncate=True) + sage: a.str(truncate=True) # optional - sage.symbolic '3.14159265358979 + 2.71828182845905*I' - sage: a.str() + sage: a.str() # optional - sage.symbolic '3.1415926535897931 + 2.7182818284590451*I' - sage: a.str(base=2) + sage: a.str(base=2) # optional - sage.symbolic '11.001001000011111101101010100010001000010110100011000 + 10.101101111110000101010001011000101000101011101101001*I' - sage: CC(0.5 + 0.625*I).str(base=2) + sage: CC(0.5 + 0.625*I).str(base=2) # optional - sage.symbolic '0.10000000000000000000000000000000000000000000000000000 + 0.10100000000000000000000000000000000000000000000000000*I' - sage: a.str(base=16) + sage: a.str(base=16) # optional - sage.symbolic '3.243f6a8885a30 + 2.b7e151628aed2*I' - sage: a.str(base=36) + sage: a.str(base=36) # optional - sage.symbolic '3.53i5ab8p5fc + 2.puw5nggjf8f*I' sage: CC(0) 0.000000000000000 @@ -1392,23 +1391,23 @@ cdef class ComplexNumber(sage.structure.element.FieldElement): Coerce the object using the ``pari`` function:: sage: a = ComplexNumber(2,1) - sage: pari(a) + sage: pari(a) # optional - sage.libs.pari 2.00000000000000 + 1.00000000000000*I - sage: pari(a).type() + sage: pari(a).type() # optional - sage.libs.pari 't_COMPLEX' - sage: type(pari(a)) + sage: type(pari(a)) # optional - sage.libs.pari - sage: a.__pari__() + sage: a.__pari__() # optional - sage.libs.pari 2.00000000000000 + 1.00000000000000*I - sage: type(a.__pari__()) + sage: type(a.__pari__()) # optional - sage.libs.pari - sage: a = CC(pi) - sage: pari(a) + sage: a = CC(pi) # optional - sage.symbolic + sage: pari(a) # optional - sage.libs.pari sage.symbolic 3.14159265358979 - sage: pari(a).type() + sage: pari(a).type() # optional - sage.libs.pari sage.symbolic 't_REAL' sage: a = CC(-2).sqrt() - sage: pari(a) + sage: pari(a) # optional - sage.libs.pari 1.41421356237310*I """ if self.is_real(): @@ -1475,11 +1474,11 @@ cdef class ComplexNumber(sage.structure.element.FieldElement): EXAMPLES:: - sage: CC(1, 0)._sympy_() + sage: CC(1, 0)._sympy_() # optional - sympy 1.00000000000000 - sage: CC(1/3, 1)._sympy_() + sage: CC(1/3, 1)._sympy_() # optional - sympy 0.333333333333333 + 1.0*I - sage: type(_) + sage: type(_) # optional - sympy """ import sympy @@ -1670,7 +1669,7 @@ cdef class ComplexNumber(sage.structure.element.FieldElement): INPUT: - - ``left`` - a complex number to divide by ``self`` + - ``left`` -- a complex number to divide by ``self`` EXAMPLES:: @@ -1759,7 +1758,7 @@ cdef class ComplexNumber(sage.structure.element.FieldElement): def __bool__(self): """ Return ``True`` if ``self`` is not zero. This is an internal function; - use :meth:`is_zero()` instead. + use :meth:`is_zero` instead. EXAMPLES:: @@ -2031,7 +2030,7 @@ cdef class ComplexNumber(sage.structure.element.FieldElement): def multiplicative_order(self): """ Return the multiplicative order of this complex number, if known, - or raise a ``NotImplementedError``. + or raise a :class:`NotImplementedError`. EXAMPLES:: @@ -2092,13 +2091,13 @@ cdef class ComplexNumber(sage.structure.element.FieldElement): You can either use the indirect:: sage: z = CC(0,1) - sage: plot(z) + sage: plot(z) # optional - sage.plot Graphics object consisting of 1 graphics primitive or the more direct:: sage: z = CC(0,1) - sage: z.plot() + sage: z.plot() # optional - sage.plot Graphics object consisting of 1 graphics primitive """ return sage.plot.point.point2d((self.real(), self.imag()), **kargs) @@ -2360,7 +2359,7 @@ cdef class ComplexNumber(sage.structure.element.FieldElement): INPUT: - ``self`` -- element of the upper half plane (if not, - raises a ``ValueError``). + raises a :class:`ValueError`). - ``omit_frac`` -- (bool, default: ``False``), if ``True``, omit the `e^{\pi i z / 12}` factor. @@ -2555,7 +2554,7 @@ cdef class ComplexNumber(sage.structure.element.FieldElement): - ``right`` (complex) -- another complex number - - ``algorithm`` (string, default "optimal") -- the algorithm to use + - ``algorithm`` (string, default ``"optimal"``) -- the algorithm to use (see below). OUTPUT: @@ -2564,18 +2563,18 @@ cdef class ComplexNumber(sage.structure.element.FieldElement): this is a multi-valued function, and the algorithm used affects the value returned, as follows: - - "pari": Call the :pari:`agm` function from the pari library. + - ``"pari"``: Call the :pari:`agm` function from the PARI library. - - "optimal": Use the AGM sequence such that at each stage - `(a,b)` is replaced by `(a_1,b_1)=((a+b)/2,\pm\sqrt{ab})` - where the sign is chosen so that `|a_1-b_1|\le|a_1+b_1|`, or - equivalently `\Re(b_1/a_1)\ge 0`. The resulting limit is - maximal among all possible values. + - ``"optimal"``: Use the AGM sequence such that at each stage + `(a,b)` is replaced by `(a_1,b_1)=((a+b)/2,\pm\sqrt{ab})` + where the sign is chosen so that `|a_1-b_1|\le|a_1+b_1|`, or + equivalently `\Re(b_1/a_1)\ge 0`. The resulting limit is + maximal among all possible values. - - "principal": Use the AGM sequence such that at each stage - `(a,b)` is replaced by `(a_1,b_1)=((a+b)/2,\pm\sqrt{ab})` - where the sign is chosen so that `\Re(b_1)\ge 0` (the - so-called principal branch of the square root). + - ``"principal"``: Use the AGM sequence such that at each stage + `(a,b)` is replaced by `(a_1,b_1)=((a+b)/2,\pm\sqrt{ab})` + where the sign is chosen so that `\Re(b_1)\ge 0` (the + so-called principal branch of the square root). The values `AGM(a,0)`, `AGM(0,a)`, and `AGM(a,-a)` are all taken to be 0. @@ -2777,7 +2776,7 @@ cdef class ComplexNumber(sage.structure.element.FieldElement): def arg(self): """ - See :meth:`argument()`. + See :meth:`argument`. EXAMPLES:: @@ -2826,7 +2825,7 @@ cdef class ComplexNumber(sage.structure.element.FieldElement): sage: a = ComplexNumber(1,0) sage: a.dilog() 1.64493406684823 - sage: float(pi^2/6) + sage: float(pi^2/6) # optional - sage.symbolic 1.6449340668482262 :: @@ -2924,8 +2923,8 @@ cdef class ComplexNumber(sage.structure.element.FieldElement): def log(self, base=None): r""" Complex logarithm of `z` with branch chosen as follows: Write - `z = \rho e^{i \theta}` with `-\pi < \theta <= pi`. Then - `\mathrm{log}(z) = \mathrm{log}(\rho) + i \theta`. + `z = \rho e^{i \theta}` with `-\pi < \theta \leq \pi`. Then + `\log(z) = \log(\rho) + i \theta`. .. WARNING:: @@ -3002,7 +3001,7 @@ cdef class ComplexNumber(sage.structure.element.FieldElement): INPUT: - - ``all`` - bool (default: ``False``); if ``True``, return a + - ``all`` -- bool (default: ``False``); if ``True``, return a list of all square roots. EXAMPLES:: @@ -3071,7 +3070,7 @@ cdef class ComplexNumber(sage.structure.element.FieldElement): INPUT: - - ``all`` - bool (default: ``False``); if ``True``, return a + - ``all`` -- bool (default: ``False``); if ``True``, return a list of all `n`-th roots. EXAMPLES:: @@ -3080,10 +3079,13 @@ cdef class ComplexNumber(sage.structure.element.FieldElement): sage: a.nth_root(3) 3.00000000000000 sage: a.nth_root(3, all=True) - [3.00000000000000, -1.50000000000000 + 2.59807621135332*I, -1.50000000000000 - 2.59807621135332*I] + [3.00000000000000, + -1.50000000000000 + 2.59807621135332*I, + -1.50000000000000 - 2.59807621135332*I] sage: a = ComplexField(20)(2,1) sage: [r^7 for r in a.nth_root(7, all=True)] - [2.0000 + 1.0000*I, 2.0000 + 1.0000*I, 2.0000 + 1.0000*I, 2.0000 + 1.0000*I, 2.0000 + 1.0000*I, 2.0000 + 1.0001*I, 2.0000 + 1.0001*I] + [2.0000 + 1.0000*I, 2.0000 + 1.0000*I, 2.0000 + 1.0000*I, 2.0000 + 1.0000*I, + 2.0000 + 1.0000*I, 2.0000 + 1.0001*I, 2.0000 + 1.0001*I] """ if self.is_zero(): return [self] if all else self @@ -3143,7 +3145,7 @@ cdef class ComplexNumber(sage.structure.element.FieldElement): def is_real(self): """ - Return ``True`` if ``self`` is real, i.e. has imaginary part zero. + Return ``True`` if ``self`` is real, i.e., has imaginary part zero. EXAMPLES:: @@ -3156,7 +3158,7 @@ cdef class ComplexNumber(sage.structure.element.FieldElement): def is_imaginary(self): """ - Return ``True`` if ``self`` is imaginary, i.e. has real part zero. + Return ``True`` if ``self`` is imaginary, i.e., has real part zero. EXAMPLES:: @@ -3169,7 +3171,7 @@ cdef class ComplexNumber(sage.structure.element.FieldElement): def is_integer(self): """ - Return ``True`` if ``self`` is a integer + Return ``True`` if ``self`` is an integer. EXAMPLES:: @@ -3265,8 +3267,8 @@ cdef class ComplexNumber(sage.structure.element.FieldElement): ALGORITHM: Uses the PARI C-library :pari:`algdep` command. - INPUT: Type algdep? at the top level prompt. All additional - parameters are passed onto the top-level algdep command. + INPUT: Type ``algdep?`` at the top level prompt. All additional + parameters are passed onto the top-level :func:`algdep` command. EXAMPLES:: @@ -3465,7 +3467,7 @@ cdef inline mp_exp_t max_exp(ComplexNumber z): cpdef int cmp_abs(ComplexNumber a, ComplexNumber b): """ - Return -1, 0, or 1 according to whether `|a|` is less than, equal to, or + Return `-1`, `0`, or `1` according to whether `|a|` is less than, equal to, or greater than `|b|`. Optimized for non-close numbers, where the ordering can be determined by diff --git a/src/sage/rings/continued_fraction.py b/src/sage/rings/continued_fraction.py index c8a68cb309f..0b836b44f65 100644 --- a/src/sage/rings/continued_fraction.py +++ b/src/sage/rings/continued_fraction.py @@ -2513,13 +2513,13 @@ def continued_fraction_list(x, type="std", partial_convergents=False, def continued_fraction(x, value=None): r""" - Return the continued fraction of ``x``. + Return the continued fraction of `x`. INPUT: - - `x` -- a number or a list of partial quotients (for finite - development) or two list of partial quotients (preperiod and period - for ultimately periodic development) + - ``x`` -- a number or a list of partial quotients (for finite + development) or two list of partial quotients (preperiod and period + for ultimately periodic development) EXAMPLES: @@ -2534,38 +2534,38 @@ 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 + sage: c = continued_fraction(golden_ratio); c # optional - 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) + sage: c.convergent(12) # optional - sage.symbolic 377/233 sage: fibonacci(14)/fibonacci(13) 377/233 - sage: continued_fraction(pi) + sage: continued_fraction(pi) # optional - sage.symbolic [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 + sage: c = continued_fraction(pi); c # optional - sage.symbolic [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 + sage: a = c.convergent(3); a # optional - sage.symbolic 355/113 - sage: a.n() + sage: a.n() # optional - sage.symbolic 3.14159292035398 - sage: pi.n() + sage: pi.n() # optional - sage.symbolic 3.14159265358979 - sage: continued_fraction(sqrt(2)) + sage: continued_fraction(sqrt(2)) # optional - sage.symbolic [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)) + sage: continued_fraction(tan(1)) # optional - sage.symbolic [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)) + sage: continued_fraction(tanh(1)) # optional - sage.symbolic [0; 1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21, 23, 25, 27, 29, 31, 33, 35, 37, ...] - sage: continued_fraction(e) + sage: continued_fraction(e) # optional - sage.symbolic [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: K. = NumberField(x^2-5, embedding=2.23) + 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)*] @@ -2580,7 +2580,7 @@ def continued_fraction(x, value=None): sage: cf.period() (1, 3, 1, 1, 3, 9) - sage: L. = NumberField(x^2-2, embedding=1.41) + sage: L. = NumberField(x^2 - 2, embedding=1.41) sage: cf = continued_fraction(sqrt2); cf [1; (2)*] sage: cf.period() @@ -2594,7 +2594,7 @@ def continued_fraction(x, value=None): continued fraction from its preperiod and its period and get its value back:: - sage: cf = continued_fraction([(1,1),(2,8)]); cf + sage: cf = continued_fraction([(1,1), (2,8)]); cf [1; 1, (2, 8)*] sage: cf.value() 2/11*sqrt5 + 14/11 @@ -2602,7 +2602,7 @@ def continued_fraction(x, value=None): 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: K. = NumberField(x^3 - 2, embedding=1.25) sage: cf = continued_fraction(a); cf [1; 3, 1, 5, 1, 1, 4, 1, 1, 8, 1, 14, 1, 10, 2, 1, 4, 12, 2, 3, ...] @@ -2631,8 +2631,8 @@ def continued_fraction(x, value=None): Constants in symbolic subrings work like constants in ``SR``:: - sage: SCR = SR.subring(no_variables=True) - sage: continued_fraction(SCR(pi)) + sage: SCR = SR.subring(no_variables=True) # optional - sage.symbolic + sage: continued_fraction(SCR(pi)) # optional - 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/derivation.py b/src/sage/rings/derivation.py index 4c8cb4662b9..74903e6072f 100644 --- a/src/sage/rings/derivation.py +++ b/src/sage/rings/derivation.py @@ -35,7 +35,8 @@ sage: A. = QQ[] sage: M = A.derivation_module() sage: M - Module of derivations over Multivariate Polynomial Ring in x, y, z over Rational Field + Module of derivations over + Multivariate Polynomial Ring in x, y, z over Rational Field The method :meth:`~sage.rings.derivation.RingDerivationModule.gens` returns the generators of this module:: @@ -76,8 +77,10 @@ Sage knows moreover that `M` is a Lie algebra:: sage: M.category() - Join of Category of lie algebras with basis over Rational Field - and Category of modules with basis over Multivariate Polynomial Ring in x, y, z over Rational Field + Join of + Category of lie algebras with basis over Rational Field and + Category of modules with basis over + Multivariate Polynomial Ring in x, y, z over Rational Field Computations of Lie brackets are implemented as well:: @@ -116,7 +119,9 @@ sage: M = A.derivation_module(ev) sage: M - Module of derivations from Multivariate Polynomial Ring in x, y, z over Rational Field to Rational Field + Module of derivations + from Multivariate Polynomial Ring in x, y, z over Rational Field + to Rational Field sage: M.gens() (d/dx, d/dy, d/dz) @@ -138,7 +143,8 @@ sage: theta = B.hom([B(y),B(z),B(x)]) sage: theta - Ring endomorphism of Fraction Field of Multivariate Polynomial Ring in x, y, z over Rational Field + Ring endomorphism of Fraction Field of + Multivariate Polynomial Ring in x, y, z over Rational Field Defn: x |--> y y |--> z z |--> x @@ -225,25 +231,32 @@ def __init__(self, domain, codomain, twist=None): sage: TestSuite(M).run() sage: from sage.rings.derivation import RingDerivationModule - sage: R5. = GF(5)[] - sage: R25. = GF(25)[] - sage: R7. = GF(7)[] - - sage: RingDerivationModule(R5, R25) - Module of derivations from Univariate Polynomial Ring in x over Finite Field of size 5 to Univariate Polynomial Ring in x over Finite Field in z2 of size 5^2 - sage: RingDerivationModule(R5, R5^2) + sage: R5. = GF(5)[] # optional - sage.rings.finite_rings + sage: R25. = GF(25)[] # optional - sage.rings.finite_rings + sage: R7. = GF(7)[] # optional - sage.rings.finite_rings + + sage: RingDerivationModule(R5, R25) # optional - sage.rings.finite_rings + Module of derivations + from Univariate Polynomial Ring in x over Finite Field of size 5 + to Univariate Polynomial Ring in x over Finite Field in z2 of size 5^2 + sage: RingDerivationModule(R5, R5^2) # optional - sage.rings.finite_rings Traceback (most recent call last): ... - TypeError: the codomain must be an algebra over the domain or a morphism with the correct domain - sage: RingDerivationModule(R5, R7) + TypeError: the codomain must be an algebra over the domain + or a morphism with the correct domain + sage: RingDerivationModule(R5, R7) # optional - sage.rings.finite_rings Traceback (most recent call last): ... - TypeError: the codomain must be an algebra over the domain or a morphism with the correct domain - - sage: theta = R5.hom([R5.gen()^2]) - sage: RingDerivationModule(R5, R25, twist=theta) - Module of twisted derivations from Univariate Polynomial Ring in x over Finite Field of size 5 to Univariate Polynomial Ring in x over Finite Field in z2 of size 5^2 (twisting morphism: x |--> x^2) - sage: RingDerivationModule(R7, R7, twist=theta) + TypeError: the codomain must be an algebra over the domain + or a morphism with the correct domain + + sage: theta = R5.hom([R5.gen()^2]) # optional - sage.rings.finite_rings + sage: RingDerivationModule(R5, R25, twist=theta) # optional - sage.rings.finite_rings + Module of twisted derivations + from Univariate Polynomial Ring in x over Finite Field of size 5 + to Univariate Polynomial Ring in x over Finite Field in z2 of size 5^2 + (twisting morphism: x |--> x^2) + sage: RingDerivationModule(R7, R7, twist=theta) # optional - sage.rings.finite_rings Traceback (most recent call last): ... TypeError: the domain of the derivation must coerce to the domain of the twisting homomorphism @@ -460,8 +473,10 @@ def _coerce_map_from_(self, R): sage: M1 = A.derivation_module(); M1 Module of derivations over Univariate Polynomial Ring in x over Rational Field sage: M2 = A.derivation_module(B); M2 - Module of derivations from Univariate Polynomial Ring in x over Rational Field - to Univariate Polynomial Ring in y over Univariate Polynomial Ring in x over Rational Field + Module of derivations + from Univariate Polynomial Ring in x over Rational Field + to Univariate Polynomial Ring in y over + Univariate Polynomial Ring in x over Rational Field sage: M1._coerce_map_from_(M2) is None True sage: M1.has_coerce_map_from(M2) @@ -567,7 +582,8 @@ def defining_morphism(self): sage: M.defining_morphism() Polynomial base injection morphism: From: Univariate Polynomial Ring in x over Rational Field - To: Univariate Polynomial Ring in y over Univariate Polynomial Ring in x over Rational Field + To: Univariate Polynomial Ring in y over + Univariate Polynomial Ring in x over Rational Field sage: ev = R.hom([QQ(0)]) sage: M = R.derivation_module(ev) @@ -857,7 +873,8 @@ def codomain(self): sage: S. = R[] sage: M = R.derivation_module(S) sage: M.random_element().codomain() - Univariate Polynomial Ring in y over Univariate Polynomial Ring in x over Rational Field + Univariate Polynomial Ring in y over + Univariate Polynomial Ring in x over Rational Field sage: M.random_element().codomain() is S True @@ -1057,10 +1074,10 @@ def _richcmp_(self, other, op): EXAMPLES:: - sage: R. = GF(5)[] - sage: D = sum(v*R.derivation(v) for v in R.gens()); D + sage: R. = GF(5)[] # optional - sage.rings.finite_rings + sage: D = sum(v*R.derivation(v) for v in R.gens()); D # optional - sage.rings.finite_rings x*d/dx + y*d/dy + z*d/dz - sage: D.pth_power() == D + sage: D.pth_power() == D # optional - sage.rings.finite_rings True """ @@ -1132,17 +1149,17 @@ def pth_power(self): EXAMPLES:: - sage: R. = GF(5)[] - sage: Dx = R.derivation(x) - sage: Dx.pth_power() + sage: R. = GF(5)[] # optional - sage.rings.finite_rings + sage: Dx = R.derivation(x) # optional - sage.rings.finite_rings + sage: Dx.pth_power() # optional - sage.rings.finite_rings 0 - sage: (x*Dx).pth_power() + sage: (x*Dx).pth_power() # optional - sage.rings.finite_rings x*d/dx - sage: (x^6*Dx).pth_power() + sage: (x^6*Dx).pth_power() # optional - sage.rings.finite_rings x^26*d/dx - sage: Dy = R.derivation(y) - sage: (x*Dx + y*Dy).pth_power() + sage: Dy = R.derivation(y) # optional - sage.rings.finite_rings + sage: (x*Dx + y*Dy).pth_power() # optional - sage.rings.finite_rings x*d/dx + y*d/dy An error is raised if the domain has characteristic zero:: @@ -1165,14 +1182,14 @@ def pth_power(self): TESTS:: - sage: R. = GF(3)[] - sage: D = R.derivation_module().random_element() - sage: Dp = D.pth_power() - sage: f = R.random_element() - sage: Dp(f) == D(D(D(f))) + sage: R. = GF(3)[] # optional - sage.rings.finite_rings + sage: D = R.derivation_module().random_element() # optional - sage.rings.finite_rings + sage: Dp = D.pth_power() # optional - sage.rings.finite_rings + sage: f = R.random_element() # optional - sage.rings.finite_rings + sage: Dp(f) == D(D(D(f))) # optional - sage.rings.finite_rings True - sage: D.bracket(Dp) + sage: D.bracket(Dp) # optional - sage.rings.finite_rings 0 """ @@ -1562,14 +1579,14 @@ def __init__(self, parent, arg=None): TESTS:: sage: from sage.rings.derivation import RingDerivationWithoutTwist_wrapper - sage: R. = GF(5)[] - sage: S = R.quo([x^5, y^5]) - sage: M = S.derivation_module() - sage: der = M.random_element() - sage: isinstance(der, RingDerivationWithoutTwist_wrapper) + sage: R. = GF(5)[] # optional - sage.rings.finite_rings + sage: S = R.quo([x^5, y^5]) # optional - sage.rings.finite_rings + sage: M = S.derivation_module() # optional - sage.rings.finite_rings + sage: der = M.random_element() # optional - sage.rings.finite_rings + sage: isinstance(der, RingDerivationWithoutTwist_wrapper) # optional - sage.rings.finite_rings True - sage: TestSuite(der).run() + sage: TestSuite(der).run() # optional - sage.rings.finite_rings """ if isinstance(arg, list) and len(arg) == 1 and isinstance(arg[0], RingDerivation): @@ -1600,11 +1617,11 @@ def _add_(self, other): EXAMPLES:: - sage: R. = GF(5)[] - sage: S. = R.quo([X^5, Y^5]) - sage: Dx = S.derivation(x) - sage: Dy = S.derivation(y) - sage: Dx + Dy + sage: R. = GF(5)[] # optional - sage.rings.finite_rings + sage: S. = R.quo([X^5, Y^5]) # optional - sage.rings.finite_rings + sage: Dx = S.derivation(x) # optional - sage.rings.finite_rings + sage: Dy = S.derivation(y) # optional - sage.rings.finite_rings + sage: Dx + Dy # optional - sage.rings.finite_rings d/dx + d/dy """ @@ -1616,11 +1633,11 @@ def _sub_(self, other): EXAMPLES:: - sage: R. = GF(5)[] - sage: S. = R.quo([X^5, Y^5]) - sage: Dx = S.derivation(x) - sage: Dy = S.derivation(y) - sage: Dx - Dy + sage: R. = GF(5)[] # optional - sage.rings.finite_rings + sage: S. = R.quo([X^5, Y^5]) # optional - sage.rings.finite_rings + sage: Dx = S.derivation(x) # optional - sage.rings.finite_rings + sage: Dy = S.derivation(y) # optional - sage.rings.finite_rings + sage: Dx - Dy # optional - sage.rings.finite_rings d/dx - d/dy """ @@ -1632,10 +1649,10 @@ def _neg_(self): EXAMPLES:: - sage: R. = GF(5)[] - sage: S. = R.quo([X^5, Y^5]) - sage: Dx = S.derivation(x) - sage: -Dx + sage: R. = GF(5)[] # optional - sage.rings.finite_rings + sage: S. = R.quo([X^5, Y^5]) # optional - sage.rings.finite_rings + sage: Dx = S.derivation(x) # optional - sage.rings.finite_rings + sage: -Dx # optional - sage.rings.finite_rings -d/dx """ @@ -1647,12 +1664,12 @@ def _lmul_(self, factor): EXAMPLES:: - sage: R. = GF(5)[] - sage: S. = R.quo([X^5, Y^5]) - sage: Dx = S.derivation(x) - sage: Dx * 2 + sage: R. = GF(5)[] # optional - sage.rings.finite_rings + sage: S. = R.quo([X^5, Y^5]) # optional - sage.rings.finite_rings + sage: Dx = S.derivation(x) # optional - sage.rings.finite_rings + sage: Dx * 2 # optional - sage.rings.finite_rings 2*d/dx - sage: Dx * x^2 + sage: Dx * x^2 # optional - sage.rings.finite_rings x^2*d/dx """ @@ -1664,12 +1681,12 @@ def _rmul_(self, factor): EXAMPLES:: - sage: R. = GF(5)[] - sage: S. = R.quo([X^5, Y^5]) - sage: Dx = S.derivation(x) - sage: 2 * Dx + sage: R. = GF(5)[] # optional - sage.rings.finite_rings + sage: S. = R.quo([X^5, Y^5]) # optional - sage.rings.finite_rings + sage: Dx = S.derivation(x) # optional - sage.rings.finite_rings + sage: 2 * Dx # optional - sage.rings.finite_rings 2*d/dx - sage: x^2 * Dx + sage: x^2 * Dx # optional - sage.rings.finite_rings x^2*d/dx """ @@ -1682,20 +1699,20 @@ def list(self): EXAMPLES:: - sage: R. = GF(5)[] - sage: S. = R.quo([X^5, Y^5]) - sage: M = S.derivation_module() - sage: M.basis() + sage: R. = GF(5)[] # optional - sage.rings.finite_rings + sage: S. = R.quo([X^5, Y^5]) # optional - sage.rings.finite_rings + sage: M = S.derivation_module() # optional - sage.rings.finite_rings + sage: M.basis() # optional - sage.rings.finite_rings Family (d/dx, d/dy) - sage: S.derivation(x).list() + sage: S.derivation(x).list() # optional - sage.rings.finite_rings [1, 0] - sage: S.derivation(y).list() + sage: S.derivation(y).list() # optional - sage.rings.finite_rings [0, 1] - sage: f = x*S.derivation(x) + y*S.derivation(y); f + sage: f = x*S.derivation(x) + y*S.derivation(y); f # optional - sage.rings.finite_rings x*d/dx + y*d/dy - sage: f.list() + sage: f.list() # optional - sage.rings.finite_rings [x, y] """ @@ -1889,19 +1906,19 @@ def list(self): EXAMPLES:: - sage: R. = GF(5)[[]] - sage: M = R.derivation_module() - sage: M.basis() + sage: R. = GF(5)[[]] # optional - sage.rings.finite_rings + sage: M = R.derivation_module() # optional - sage.rings.finite_rings + sage: M.basis() # optional - sage.rings.finite_rings Family (d/dx, d/dy) - sage: R.derivation(x).list() + sage: R.derivation(x).list() # optional - sage.rings.finite_rings [1, 0] - sage: R.derivation(y).list() + sage: R.derivation(y).list() # optional - sage.rings.finite_rings [0, 1] - sage: f = x*R.derivation(x) + y*R.derivation(y); f + sage: f = x*R.derivation(x) + y*R.derivation(y); f # optional - sage.rings.finite_rings x*d/dx + y*d/dy - sage: f.list() + sage: f.list() # optional - sage.rings.finite_rings [x, y] """ @@ -1974,11 +1991,11 @@ def _call_(self, x): EXAMPLES:: - sage: R. = GF(5)[] - sage: S. = R.quo([X^5, Y^5]) - sage: f = x^3*S.derivation(); f + sage: R. = GF(5)[] # optional - sage.rings.finite_rings + sage: S. = R.quo([X^5, Y^5]) # optional - sage.rings.finite_rings + sage: f = x^3*S.derivation(); f # optional - sage.rings.finite_rings x^3*d/dx - sage: f(x^3) + sage: f(x^3) # optional - sage.rings.finite_rings 0 """ @@ -2074,10 +2091,10 @@ def _latex_(self): EXAMPLES:: - sage: k. = GF(5^3) - sage: Frob = k.frobenius_endomorphism() - sage: der = k.derivation(a+1, twist=Frob) - sage: latex(der) + sage: k. = GF(5^3) # optional - sage.rings.finite_rings + sage: Frob = k.frobenius_endomorphism() # optional - sage.rings.finite_rings + sage: der = k.derivation(a + 1, twist=Frob) # optional - sage.rings.finite_rings + sage: latex(der) # optional - sage.rings.finite_rings \left(a + 1\right) \left(\left[a \mapsto a^{5}\right] - \text{id}\right) """ scalar = self._scalar diff --git a/src/sage/rings/fast_arith.pyx b/src/sage/rings/fast_arith.pyx index df9b592cf97..dfaa7782962 100644 --- a/src/sage/rings/fast_arith.pyx +++ b/src/sage/rings/fast_arith.pyx @@ -1,3 +1,4 @@ +# sage.doctest: optional - sage.libs.pari """ Basic arithmetic with C integers """ @@ -58,16 +59,16 @@ cpdef prime_range(start, stop=None, algorithm=None, bint py_ints=False): - ``algorithm`` -- optional string (default: ``None``), one of: - - ``None``: Use algorithm ``"pari_primes"`` if ``stop`` <= 436273009 - (approximately 4.36E8). Otherwise use algorithm ``"pari_isprime"``. + - ``None``: Use algorithm ``"pari_primes"`` if ``stop`` <= 436273009 + (approximately 4.36E8). Otherwise use algorithm ``"pari_isprime"``. - - ``"pari_primes"``: Use PARI's :pari:`primes` function to generate all - primes from 2 to stop. This is fast but may crash if there is - insufficient memory. Raises an error if ``stop`` > 436273009. + - ``"pari_primes"``: Use PARI's :pari:`primes` function to generate all + primes from 2 to stop. This is fast but may crash if there is + insufficient memory. Raises an error if ``stop`` > 436273009. - - ``"pari_isprime"``: Wrapper for ``list(primes(start, stop))``. Each (odd) - integer in the specified range is tested for primality by applying PARI's - :pari:`isprime` function. This is slower but will work for much larger input. + - ``"pari_isprime"``: Wrapper for ``list(primes(start, stop))``. Each (odd) + integer in the specified range is tested for primality by applying PARI's + :pari:`isprime` function. This is slower but will work for much larger input. - ``py_ints`` -- optional boolean (default ``False``), return Python ints rather than Sage Integers (faster). Ignored unless algorithm ``"pari_primes"`` is being diff --git a/src/sage/rings/finite_rings/element_base.pyx b/src/sage/rings/finite_rings/element_base.pyx index a7e32004002..daf39e3b386 100755 --- a/src/sage/rings/finite_rings/element_base.pyx +++ b/src/sage/rings/finite_rings/element_base.pyx @@ -1,3 +1,4 @@ +# sage.doctest: optional - sage.rings.finite_rings """ Base class for finite field elements @@ -25,7 +26,7 @@ from sage.misc.superseded import deprecated_function_alias def is_FiniteFieldElement(x): """ - Return True if ``x`` is a finite field element. + Return ``True`` if ``x`` is a finite field element. This function is deprecated. diff --git a/src/sage/rings/finite_rings/finite_field_base.pyx b/src/sage/rings/finite_rings/finite_field_base.pyx index 086590a962b..49abe86126f 100644 --- a/src/sage/rings/finite_rings/finite_field_base.pyx +++ b/src/sage/rings/finite_rings/finite_field_base.pyx @@ -1,3 +1,4 @@ +# sage.doctest: optional - sage.rings.finite_rings """ Base class for finite fields diff --git a/src/sage/rings/finite_rings/finite_field_constructor.py b/src/sage/rings/finite_rings/finite_field_constructor.py index 048da483147..0ea8a3b0805 100644 --- a/src/sage/rings/finite_rings/finite_field_constructor.py +++ b/src/sage/rings/finite_rings/finite_field_constructor.py @@ -1,3 +1,4 @@ +# sage.doctest: optional - sage.rings.finite_rings r""" Finite fields @@ -791,7 +792,7 @@ def create_object(self, version, key, **kwds): def is_PrimeFiniteField(x): """ - Returns True if ``x`` is a prime finite field. + Return ``True`` if ``x`` is a prime finite field. This function is deprecated. diff --git a/src/sage/rings/finite_rings/hom_finite_field.pyx b/src/sage/rings/finite_rings/hom_finite_field.pyx index a69eb42b8be..23240b9d5b1 100644 --- a/src/sage/rings/finite_rings/hom_finite_field.pyx +++ b/src/sage/rings/finite_rings/hom_finite_field.pyx @@ -317,7 +317,7 @@ cdef class FiniteFieldHomomorphism_generic(RingHomomorphism_im_gens): def is_injective(self): """ - Return True since a embedding between finite fields is + Return ``True`` since a embedding between finite fields is always injective. EXAMPLES:: @@ -334,7 +334,7 @@ cdef class FiniteFieldHomomorphism_generic(RingHomomorphism_im_gens): def is_surjective(self): """ - Return true if this embedding is surjective (and hence an + Return ``True`` if this embedding is surjective (and hence an isomorphism. EXAMPLES:: @@ -773,7 +773,7 @@ cdef class FrobeniusEndomorphism_finite_field(FrobeniusEndomorphism_generic): def is_injective(self): """ - Return true since any power of the Frobenius endomorphism + Return ``True`` since any power of the Frobenius endomorphism over a finite field is always injective. EXAMPLES:: @@ -788,7 +788,7 @@ cdef class FrobeniusEndomorphism_finite_field(FrobeniusEndomorphism_generic): def is_surjective(self): """ - Return true since any power of the Frobenius endomorphism + Return ``True`` since any power of the Frobenius endomorphism over a finite field is always surjective. EXAMPLES:: @@ -803,7 +803,7 @@ cdef class FrobeniusEndomorphism_finite_field(FrobeniusEndomorphism_generic): def is_identity(self): """ - Return true if this morphism is the identity morphism. + Return ``True`` if this morphism is the identity morphism. EXAMPLES:: diff --git a/src/sage/rings/finite_rings/integer_mod.pyx b/src/sage/rings/finite_rings/integer_mod.pyx index ec3268dc84e..561b09766d7 100644 --- a/src/sage/rings/finite_rings/integer_mod.pyx +++ b/src/sage/rings/finite_rings/integer_mod.pyx @@ -349,11 +349,11 @@ cdef class IntegerMod_abstract(FiniteRingElement): sage: TestSuite(Zmod(2^10 * 3^5)).run() sage: TestSuite(Zmod(2^30 * 3^50 * 5^20)).run() - sage: GF(29)(SR(1/3)) + sage: GF(29)(SR(1/3)) # optional - sage.rings.finite_rings sage.symbolic 10 sage: Integers(30)(QQ['x'](1/7)) 13 - sage: Integers(30)(SR(1/4)) + sage: Integers(30)(SR(1/4)) # optional - sage.symbolic Traceback (most recent call last): ... ZeroDivisionError: inverse of Mod(4, 30) does not exist @@ -505,7 +505,7 @@ cdef class IntegerMod_abstract(FiniteRingElement): EXAMPLES:: sage: a = Integers(90384098234^3) - sage: factor(a.order()) + sage: factor(a.order()) # optional - sage.libs.pari 2^3 * 191^3 * 236607587^3 sage: b = a(2*191) sage: b.is_nilpotent() @@ -546,13 +546,13 @@ cdef class IntegerMod_abstract(FiniteRingElement): EXAMPLES:: sage: a = Mod(2,19) - sage: gap(a) + sage: gap(a) # optional - sage.libs.gap Z(19) - sage: gap(Mod(3, next_prime(10000))) + sage: gap(Mod(3, next_prime(10000))) # optional - sage.libs.gap Z(10007)^6190 - sage: gap(Mod(3, next_prime(100000))) + sage: gap(Mod(3, next_prime(100000))) # optional - sage.libs.gap ZmodpZObj( 3, 100003 ) - sage: gap(Mod(4, 48)) + sage: gap(Mod(4, 48)) # optional - sage.libs.gap ZmodnZObj( 4, 48 ) """ return '%s*One(ZmodnZ(%s))' % (self, self.__modulus.sageInteger) @@ -605,18 +605,18 @@ cdef class IntegerMod_abstract(FiniteRingElement): EXAMPLES:: - sage: K = GF(7) - sage: sage_input(K(5), verify=True) + sage: K = GF(7) # optional - sage.rings.finite_rings + sage: sage_input(K(5), verify=True) # optional - sage.rings.finite_rings # Verified GF(7)(5) - sage: sage_input(K(5) * polygen(K), verify=True) + sage: sage_input(K(5) * polygen(K), verify=True) # optional - sage.rings.finite_rings # Verified R. = GF(7)[] 5*x sage: from sage.misc.sage_input import SageInputBuilder - sage: K(5)._sage_input_(SageInputBuilder(), False) + sage: K(5)._sage_input_(SageInputBuilder(), False) # optional - sage.rings.finite_rings {call: {call: {atomic:GF}({atomic:7})}({atomic:5})} - sage: K(5)._sage_input_(SageInputBuilder(), True) + sage: K(5)._sage_input_(SageInputBuilder(), True) # optional - sage.rings.finite_rings {atomic:5} """ v = sib.int(self.lift()) @@ -653,39 +653,39 @@ cdef class IntegerMod_abstract(FiniteRingElement): EXAMPLES:: sage: r = Integers(125) - sage: b = r.multiplicative_generator()^3 - sage: a = b^17 - sage: a.log(b) + sage: b = r.multiplicative_generator()^3 # optional - sage.libs.pari + sage: a = b^17 # optional - sage.libs.pari + sage: a.log(b) # optional - sage.libs.pari 17 - sage: a.log() + sage: a.log() # optional - sage.libs.pari 51 A bigger example:: - sage: FF = FiniteField(2^32+61) - sage: c = FF(4294967356) - sage: x = FF(2) - sage: a = c.log(x) - sage: a + sage: FF = FiniteField(2^32 + 61) # optional - sage.rings.finite_rings + sage: c = FF(4294967356) # optional - sage.rings.finite_rings + sage: x = FF(2) # optional - sage.rings.finite_rings + sage: a = c.log(x) # optional - sage.rings.finite_rings + sage: a # optional - sage.rings.finite_rings 2147483678 - sage: x^a + sage: x^a # optional - sage.rings.finite_rings 4294967356 An example with a highly composite modulus:: sage: m = 2^99 * 77^7 * 123456789 * 13712923537615486607^2 - sage: (Mod(5,m)^5735816763073854953388147237921).log(5) + sage: (Mod(5,m)^5735816763073854953388147237921).log(5) # optional - sage.libs.pari 5735816763073854953388147237921 Errors are generated if the logarithm doesn't exist or the inputs are not units:: - sage: Mod(3, 7).log(Mod(2, 7)) + sage: Mod(3, 7).log(Mod(2, 7)) # optional - sage.libs.pari Traceback (most recent call last): ... ValueError: no logarithm of 3 found to base 2 modulo 7 - sage: a = Mod(16, 100); b = Mod(4,100) - sage: a.log(b) + sage: a = Mod(16, 100); b = Mod(4, 100) # optional - sage.libs.pari + sage: a.log(b) # optional - sage.libs.pari Traceback (most recent call last): ... ValueError: logarithm of 16 is not defined since it is not a unit modulo 100 @@ -694,51 +694,51 @@ cdef class IntegerMod_abstract(FiniteRingElement): We check that :trac:`9205` is fixed:: - sage: Mod(5,9).log(Mod(2, 9)) + sage: Mod(5, 9).log(Mod(2, 9)) # optional - sage.libs.pari 5 We test against a bug (side effect on PARI) fixed in :trac:`9438`:: sage: R. = QQ[] - sage: pari(b) + sage: pari(b) # optional - sage.libs.pari b - sage: GF(7)(5).log() + sage: GF(7)(5).log() # optional - sage.rings.finite_rings 5 - sage: pari(b) + sage: pari(b) # optional - sage.libs.pari b We test that :trac:`23927` is fixed:: sage: x = mod(48475563673907791151, 10^20 + 763)^2 sage: e = 25248843418589594761 - sage: (x^e).log(x)==e + sage: (x^e).log(x) == e # optional - sage.libs.pari True Examples like this took extremely long before :trac:`32375`:: - sage: (Mod(5, 123337052926643**4) ^ (10^50-1)).log(5) + sage: (Mod(5, 123337052926643**4) ^ (10^50-1)).log(5) # optional - sage.libs.pari 99999999999999999999999999999999999999999999999999 We check that non-existence of solutions is detected: No local solutions:: - sage: Mod(1111, 1234567).log(1111**3) + sage: Mod(1111, 1234567).log(1111**3) # optional - sage.libs.pari Traceback (most recent call last): ... ValueError: no logarithm of 1111 found to base 961261 modulo 1234567 (no solution modulo 9721) Incompatible local solutions:: - sage: Mod(230, 323).log(173) + sage: Mod(230, 323).log(173) # optional - sage.libs.pari Traceback (most recent call last): ... ValueError: no logarithm of 230 found to base 173 modulo 323 (incompatible local solutions) We test that :trac:`12419` is fixed:: - sage: R. = GF(2)[] - sage: R(1).factor() + sage: R. = GF(2)[] # optional - sage.rings.finite_rings + sage: R(1).factor() # optional - sage.rings.finite_rings 1 AUTHORS: @@ -818,9 +818,9 @@ cdef class IntegerMod_abstract(FiniteRingElement): EXAMPLES:: sage: m = Mod(3, 1568) - sage: v = m.generalised_log(); v + sage: v = m.generalised_log(); v # optional - sage.libs.pari [1, 3, 1] - sage: prod([Zmod(1568).unit_gens()[i] ** v[i] for i in [0..2]]) + sage: prod([Zmod(1568).unit_gens()[i] ** v[i] for i in [0..2]]) # optional - sage.libs.pari 3 .. SEEALSO:: @@ -869,11 +869,11 @@ cdef class IntegerMod_abstract(FiniteRingElement): EXAMPLES:: - sage: k = GF(3) - sage: a = k.gen() - sage: a.charpoly('x') + sage: k = GF(3) # optional - sage.rings.finite_rings + sage: a = k.gen() # optional - sage.rings.finite_rings + sage: a.charpoly('x') # optional - sage.rings.finite_rings x + 2 - sage: a + 2 + sage: a + 2 # optional - sage.rings.finite_rings 0 AUTHORS: @@ -889,7 +889,7 @@ cdef class IntegerMod_abstract(FiniteRingElement): EXAMPLES:: - sage: GF(241, 'a')(1).minpoly() + sage: GF(241, 'a')(1).minpoly() # optional - sage.rings.finite_rings x + 240 """ return self.charpoly(var) @@ -900,7 +900,7 @@ cdef class IntegerMod_abstract(FiniteRingElement): EXAMPLES:: - sage: GF(241, 'a')(1).minimal_polynomial(var = 'z') + sage: GF(241, 'a')(1).minimal_polynomial(var = 'z') # optional - sage.rings.finite_rings z + 240 """ return self.minpoly(var) @@ -911,12 +911,12 @@ cdef class IntegerMod_abstract(FiniteRingElement): EXAMPLES:: - sage: k = GF(7) - sage: a = k.gen(); a + sage: k = GF(7) # optional - sage.rings.finite_rings + sage: a = k.gen(); a # optional - sage.rings.finite_rings 1 - sage: a.polynomial() + sage: a.polynomial() # optional - sage.rings.finite_rings 1 - sage: type(a.polynomial()) + sage: type(a.polynomial()) # optional - sage.rings.finite_rings """ R = self.parent()[var] @@ -929,9 +929,9 @@ cdef class IntegerMod_abstract(FiniteRingElement): EXAMPLES:: - sage: k = GF(691) - sage: a = k(389) - sage: a.norm() + sage: k = GF(691) # optional - sage.rings.finite_rings + sage: a = k(389) # optional - sage.rings.finite_rings + sage: a.norm() # optional - sage.rings.finite_rings 389 AUTHORS: @@ -947,9 +947,9 @@ cdef class IntegerMod_abstract(FiniteRingElement): EXAMPLES:: - sage: k = GF(691) - sage: a = k(389) - sage: a.trace() + sage: k = GF(691) # optional - sage.rings.finite_rings + sage: a = k(389) # optional - sage.rings.finite_rings + sage: a.trace() # optional - sage.rings.finite_rings 389 AUTHORS: @@ -1028,27 +1028,27 @@ cdef class IntegerMod_abstract(FiniteRingElement): r""" EXAMPLES:: - sage: Mod(3,17).is_square() + sage: Mod(3, 17).is_square() False - sage: Mod(9,17).is_square() + sage: Mod(9, 17).is_square() # optional - sage.libs.pari True - sage: Mod(9,17*19^2).is_square() + sage: Mod(9, 17*19^2).is_square() # optional - sage.libs.pari True - sage: Mod(-1,17^30).is_square() + sage: Mod(-1, 17^30).is_square() # optional - sage.libs.pari True - sage: Mod(1/9, next_prime(2^40)).is_square() + sage: Mod(1/9, next_prime(2^40)).is_square() # optional - sage.libs.pari True - sage: Mod(1/25, next_prime(2^90)).is_square() + sage: Mod(1/25, next_prime(2^90)).is_square() # optional - sage.libs.pari True TESTS:: - sage: Mod(1/25, 2^8).is_square() + sage: Mod(1/25, 2^8).is_square() # optional - sage.libs.pari True - sage: Mod(1/25, 2^40).is_square() + sage: Mod(1/25, 2^40).is_square() # optional - sage.libs.pari True - sage: for p,q,r in cartesian_product_iterator([[3,5],[11,13],[17,19]]): # long time + sage: for p,q,r in cartesian_product_iterator([[3,5],[11,13],[17,19]]): # long time # optional - sage.libs.pari ....: for ep,eq,er in cartesian_product_iterator([[0,1,2,3],[0,1,2,3],[0,1,2,3]]): ....: for e2 in [0, 1, 2, 3, 4]: ....: n = p^ep * q^eq * r^er * 2^e2 @@ -1126,21 +1126,21 @@ cdef class IntegerMod_abstract(FiniteRingElement): 86 sage: mod(7, 18).sqrt() 5 - sage: a = mod(14, 5^60).sqrt() - sage: a*a + sage: a = mod(14, 5^60).sqrt() # optional - sage.libs.pari + sage: a*a # optional - sage.libs.pari 14 - sage: mod(15, 389).sqrt(extend=False) + sage: mod(15, 389).sqrt(extend=False) # optional - sage.libs.pari Traceback (most recent call last): ... ValueError: self must be a square - sage: Mod(1/9, next_prime(2^40)).sqrt()^(-2) + sage: Mod(1/9, next_prime(2^40)).sqrt()^(-2) # optional - sage.libs.pari 9 - sage: Mod(1/25, next_prime(2^90)).sqrt()^(-2) + sage: Mod(1/25, next_prime(2^90)).sqrt()^(-2) # optional - sage.libs.pari 25 :: - sage: a = Mod(3,5); a + sage: a = Mod(3, 5); a 3 sage: x = Mod(-1, 360) sage: x.sqrt(extend=False) @@ -1171,22 +1171,22 @@ cdef class IntegerMod_abstract(FiniteRingElement): sage: R = Integers(5*13^3*37); R Ring of integers modulo 406445 - sage: v = R(-1).sqrt(all=True); v + sage: v = R(-1).sqrt(all=True); v # optional - sage.libs.pari [78853, 111808, 160142, 193097, 213348, 246303, 294637, 327592] - sage: [x^2 for x in v] + sage: [x^2 for x in v] # optional - sage.libs.pari [406444, 406444, 406444, 406444, 406444, 406444, 406444, 406444] - sage: v = R(169).sqrt(all=True); min(v), -max(v), len(v) + sage: v = R(169).sqrt(all=True); min(v), -max(v), len(v) # optional - sage.libs.pari (13, 13, 104) - sage: all(x^2 == 169 for x in v) + sage: all(x^2 == 169 for x in v) # optional - sage.libs.pari True :: - sage: t = FiniteField(next_prime(2^100))(4) - sage: t.sqrt(extend = False, all = True) + sage: t = FiniteField(next_prime(2^100))(4) # optional - sage.rings.finite_rings + sage: t.sqrt(extend=False, all=True) # optional - sage.rings.finite_rings [2, 1267650600228229401496703205651] - sage: t = FiniteField(next_prime(2^100))(2) - sage: t.sqrt(extend = False, all = True) + sage: t = FiniteField(next_prime(2^100))(2) # optional - sage.rings.finite_rings + sage: t.sqrt(extend=False, all=True) # optional - sage.rings.finite_rings [] Modulo a power of 2:: @@ -1378,38 +1378,39 @@ cdef class IntegerMod_abstract(FiniteRingElement): EXAMPLES:: - sage: K = GF(31) - sage: a = K(22) - sage: K(22).nth_root(7) + sage: K = GF(31) # optional - sage.rings.finite_rings + sage: a = K(22) # optional - sage.rings.finite_rings + sage: K(22).nth_root(7) # optional - sage.rings.finite_rings 13 - sage: K(25).nth_root(5) + sage: K(25).nth_root(5) # optional - sage.rings.finite_rings 5 - sage: K(23).nth_root(3) + sage: K(23).nth_root(3) # optional - sage.rings.finite_rings 29 - sage: mod(225,2^5*3^2).nth_root(4, all=True) - [225, 129, 33, 63, 255, 159, 9, 201, 105, 279, 183, 87, 81, 273, 177, 207, 111, 15, 153, 57, 249, 135, 39, 231] - sage: mod(275,2^5*7^4).nth_root(7, all=True) + sage: mod(225, 2^5*3^2).nth_root(4, all=True) # optional - sage.rings.padics + [225, 129, 33, 63, 255, 159, 9, 201, 105, 279, 183, 87, 81, + 273, 177, 207, 111, 15, 153, 57, 249, 135, 39, 231] + sage: mod(275, 2^5*7^4).nth_root(7, all=True) # optional - sage.rings.padics [58235, 25307, 69211, 36283, 3355, 47259, 14331] - sage: mod(1,8).nth_root(2,all=True) + sage: mod(1,8).nth_root(2, all=True) # optional - sage.rings.padics [1, 7, 5, 3] - sage: mod(4,8).nth_root(2,all=True) + sage: mod(4,8).nth_root(2, all=True) # optional - sage.rings.padics [2, 6] - sage: mod(1,16).nth_root(4,all=True) + sage: mod(1,16).nth_root(4, all=True) # optional - sage.rings.padics [1, 15, 13, 3, 9, 7, 5, 11] - sage: (mod(22,31)^200).nth_root(200) + sage: (mod(22,31)^200).nth_root(200) # optional - sage.groups 5 - sage: mod(3,6).nth_root(0,all=True) + sage: mod(3,6).nth_root(0, all=True) # optional - sage.rings.padics [] sage: mod(3,6).nth_root(0) Traceback (most recent call last): ... ValueError - sage: mod(1,6).nth_root(0,all=True) + sage: mod(1,6).nth_root(0, all=True) # optional - sage.rings.padics [1, 2, 3, 4, 5] TESTS:: - sage: for p in [1009,2003,10007,100003]: + sage: for p in [1009,2003,10007,100003]: # optional - sage.rings.finite_rings ....: K = GF(p) ....: for r in (p-1).divisors(): ....: if r == 1: continue @@ -1419,7 +1420,7 @@ cdef class IntegerMod_abstract(FiniteRingElement): ....: if (y^41).nth_root(41*r)**(41*r) != y^41: raise RuntimeError ....: if (y^307).nth_root(307*r)**(307*r) != y^307: raise RuntimeError - sage: for t in range(200): + sage: for t in range(200): # optional - sage.libs.pari ....: n = randint(1,2^63) ....: K = Integers(n) ....: b = K.random_element() @@ -1434,18 +1435,18 @@ cdef class IntegerMod_abstract(FiniteRingElement): We check that :trac:`13172` is resolved:: - sage: mod(-1, 4489).nth_root(2, all=True) + sage: mod(-1, 4489).nth_root(2, all=True) # optional - sage.rings.padics [] We check that :trac:`32084` is fixed:: - sage: mod(24, 25).nth_root(50)^50 + sage: mod(24, 25).nth_root(50)^50 # optional - sage.rings.padics 24 Check that the code path cunningham might be used:: sage: a = Mod(9,11) - sage: a.nth_root(2, False, True, 'Johnston', cunningham = True) # optional - cunningham_tables + sage: a.nth_root(2, False, True, 'Johnston', cunningham=True) # optional - cunningham_tables [3, 8] ALGORITHM: @@ -1626,11 +1627,11 @@ cdef class IntegerMod_abstract(FiniteRingElement): This method is also inherited by prime finite fields elements:: - sage: k = GF(97) - sage: a = k(RationalField()('2/3')) - sage: a + sage: k = GF(97) # optional - sage.rings.finite_rings + sage: a = k(RationalField()('2/3')) # optional - sage.rings.finite_rings + sage: a # optional - sage.rings.finite_rings 33 - sage: a.rational_reconstruction() + sage: a.rational_reconstruction() # optional - sage.rings.finite_rings 2/3 """ return self.lift().rational_reconstruction(self.modulus()) @@ -1645,21 +1646,21 @@ cdef class IntegerMod_abstract(FiniteRingElement): EXAMPLES:: - sage: a = mod(3,5) - sage: b = mod(2,7) + sage: a = mod(3, 5) + sage: b = mod(2, 7) sage: a.crt(b) 23 :: - sage: a = mod(37,10^8) - sage: b = mod(9,3^8) + sage: a = mod(37, 10^8) + sage: b = mod(9, 3^8) sage: a.crt(b) 125900000037 :: - sage: b = mod(0,1) + sage: b = mod(0, 1) sage: a.crt(b) == a True sage: a.crt(b).modulus() @@ -1667,17 +1668,17 @@ cdef class IntegerMod_abstract(FiniteRingElement): TESTS:: - sage: mod(0,1).crt(mod(4,2^127)) + sage: mod(0, 1).crt(mod(4, 2^127)) 4 - sage: mod(4,2^127).crt(mod(0,1)) + sage: mod(4, 2^127).crt(mod(0, 1)) 4 - sage: mod(4,2^30).crt(mod(0,1)) + sage: mod(4, 2^30).crt(mod(0, 1)) 4 - sage: mod(0,1).crt(mod(4,2^30)) + sage: mod(0, 1).crt(mod(4, 2^30)) 4 - sage: mod(0,1).crt(mod(4,2^15)) + sage: mod(0, 1).crt(mod(4, 2^15)) 4 - sage: mod(4,2^15).crt(mod(0,1)) + sage: mod(4, 2^15).crt(mod(0, 1)) 4 AUTHORS: @@ -1736,20 +1737,20 @@ cdef class IntegerMod_abstract(FiniteRingElement): EXAMPLES:: - sage: mod(1,2).is_primitive_root() + sage: mod(1, 2).is_primitive_root() True - sage: mod(3,4).is_primitive_root() + sage: mod(3, 4).is_primitive_root() True - sage: mod(2,7).is_primitive_root() + sage: mod(2, 7).is_primitive_root() # optional - sage.libs.pari False - sage: mod(3,98).is_primitive_root() + sage: mod(3, 98).is_primitive_root() # optional - sage.libs.pari True - sage: mod(11,1009^2).is_primitive_root() + sage: mod(11, 1009^2).is_primitive_root() # optional - sage.libs.pari True TESTS:: - sage: for p in prime_range(3,12): + sage: for p in prime_range(3,12): # optional - sage.libs.pari ....: for k in range(1,4): ....: for even in [1,2]: ....: n = even*p^k @@ -1762,14 +1763,14 @@ cdef class IntegerMod_abstract(FiniteRingElement): `0` is not a primitive root mod `n` (:trac:`23624`) except for `n=0`:: - sage: mod(0, 17).is_primitive_root() + sage: mod(0, 17).is_primitive_root() # optional - sage.libs.pari False - sage: all(not mod(0, n).is_primitive_root() for n in srange(2, 20)) + sage: all(not mod(0, n).is_primitive_root() for n in srange(2, 20)) # optional - sage.libs.pari True sage: mod(0, 1).is_primitive_root() True - sage: all(not mod(p^j, p^k).is_primitive_root() + sage: all(not mod(p^j, p^k).is_primitive_root() # optional - sage.libs.pari ....: for p in prime_range(3, 12) ....: for k in srange(1, 4) ....: for j in srange(0, k)) @@ -1824,14 +1825,15 @@ cdef class IntegerMod_abstract(FiniteRingElement): EXAMPLES:: - sage: Mod(-1,5).multiplicative_order() + sage: Mod(-1, 5).multiplicative_order() # optional - sage.libs.pari 2 - sage: Mod(1,5).multiplicative_order() + sage: Mod(1, 5).multiplicative_order() # optional - sage.libs.pari 1 - sage: Mod(0,5).multiplicative_order() + sage: Mod(0, 5).multiplicative_order() # optional - sage.libs.pari Traceback (most recent call last): ... - ArithmeticError: multiplicative order of 0 not defined since it is not a unit modulo 5 + ArithmeticError: multiplicative order of 0 not defined + since it is not a unit modulo 5 """ try: return sage.rings.integer.Integer(self.__pari__().znorder()) @@ -1841,7 +1843,7 @@ cdef class IntegerMod_abstract(FiniteRingElement): def valuation(self, p): """ - The largest power r such that m is in the ideal generated by p^r or infinity if there is not a largest such power. + The largest power `r` such that `m` is in the ideal generated by `p^r` or infinity if there is not a largest such power. However it is an error to take the valuation with respect to a unit. .. NOTE:: @@ -1850,13 +1852,13 @@ cdef class IntegerMod_abstract(FiniteRingElement): EXAMPLES: - This example shows that the (a*b).valuation(n) is not always the same as a.valuation(n) + b.valuation(n) + This example shows that ``(a*b).valuation(n)`` is not always the same as ``a.valuation(n) + b.valuation(n)`` :: - sage: R=ZZ.quo(9) - sage: a=R(3) - sage: b=R(6) + sage: R = ZZ.quo(9) + sage: a = R(3) + sage: b = R(6) sage: a.valuation(3) 1 sage: a.valuation(3) + b.valuation(3) @@ -1875,9 +1877,9 @@ cdef class IntegerMod_abstract(FiniteRingElement): TESTS:: - sage: R=ZZ.quo(12) - sage: a=R(2) - sage: b=R(4) + sage: R = ZZ.quo(12) + sage: a = R(2) + sage: b = R(4) sage: a.valuation(2) 1 sage: b.valuation(2) @@ -1905,7 +1907,7 @@ cdef class IntegerMod_abstract(FiniteRingElement): EXAMPLES:: - sage: GF(7)(3) // 5 + sage: GF(7)(3) // 5 # optional - sage.rings.finite_rings 2 """ return self._mul_(~right) @@ -1932,9 +1934,9 @@ cdef class IntegerMod_abstract(FiniteRingElement): EXAMPLES:: - sage: F. = GF(13) - sage: V = F.vector_space(map=False) - sage: V(a) + sage: F. = GF(13) # optional - sage.rings.finite_rings + sage: V = F.vector_space(map=False) # optional - sage.rings.finite_rings + sage: V(a) # optional - sage.rings.finite_rings (1) """ return self.parent().vector_space(map=False)([self]) @@ -1977,8 +1979,8 @@ cdef class IntegerMod_gmp(IntegerMod_abstract): r""" EXAMPLES:: - sage: p = next_prime(2^32) - sage: GF(p)(int(p+1)) + sage: p = next_prime(2^32) # optional - sage.libs.pari + sage: GF(p)(int(p + 1)) # optional - sage.rings.finite_rings 1 """ mpz_set_si(self.value, value) @@ -2102,7 +2104,7 @@ cdef class IntegerMod_gmp(IntegerMod_abstract): cpdef bint is_unit(self): """ - Return True iff this element is a unit. + Return ``True`` iff this element is a unit. EXAMPLES:: @@ -2250,9 +2252,9 @@ cdef class IntegerMod_gmp(IntegerMod_abstract): sage: R = Integers(10^10) sage: R(2)^1000 5668069376 - sage: p = next_prime(11^10) - sage: R = Integers(p) - sage: R(9876)^(p-1) + sage: p = next_prime(11^10) # optional - sage.libs.pari + sage: R = Integers(p) # optional - sage.libs.pari + sage: R(9876)^(p-1) # optional - sage.libs.pari 1 sage: mod(3, 10^100)^-2 8888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888889 @@ -2265,14 +2267,14 @@ cdef class IntegerMod_gmp(IntegerMod_abstract): We define ``0^0`` to be unity, :trac:`13894`:: - sage: p = next_prime(11^10) - sage: R = Integers(p) - sage: R(0)^0 + sage: p = next_prime(11^10) # optional - sage.libs.pari + sage: R = Integers(p) # optional - sage.libs.pari + sage: R(0)^0 # optional - sage.libs.pari 1 The value returned from ``0^0`` should belong to our ring:: - sage: type(R(0)^0) == type(R(0)) + sage: type(R(0)^0) == type(R(0)) # optional - sage.libs.pari True When the modulus is ``1``, the only element in the ring is @@ -2489,7 +2491,7 @@ cdef class IntegerMod_int(IntegerMod_abstract): cpdef bint is_unit(IntegerMod_int self): """ - Return True iff this element is a unit + Return ``True`` iff this element is a unit EXAMPLES:: @@ -2908,16 +2910,16 @@ cdef class IntegerMod_int(IntegerMod_abstract): 86 sage: mod(7, 18).sqrt() 5 - sage: a = mod(14, 5^60).sqrt() - sage: a*a + sage: a = mod(14, 5^60).sqrt() # optional - sage.libs.pari + sage: a*a # optional - sage.libs.pari 14 sage: mod(15, 389).sqrt(extend=False) Traceback (most recent call last): ... ValueError: self must be a square - sage: Mod(1/9, next_prime(2^40)).sqrt()^(-2) + sage: Mod(1/9, next_prime(2^40)).sqrt()^(-2) # optional - sage.libs.pari 9 - sage: Mod(1/25, next_prime(2^90)).sqrt()^(-2) + sage: Mod(1/25, next_prime(2^90)).sqrt()^(-2) # optional - sage.libs.pari 25 :: @@ -2932,7 +2934,8 @@ cdef class IntegerMod_int(IntegerMod_abstract): sage: y = x.sqrt(); y sqrt359 sage: y.parent() - Univariate Quotient Polynomial Ring in sqrt359 over Ring of integers modulo 360 with modulus x^2 + 1 + Univariate Quotient Polynomial Ring in sqrt359 + over Ring of integers modulo 360 with modulus x^2 + 1 sage: y^2 359 @@ -2948,20 +2951,20 @@ cdef class IntegerMod_int(IntegerMod_abstract): [1, 19, 71, 89, 91, 109, 161, 179, 181, 199, 251, 269, 271, 289, 341, 359] sage: R(0).sqrt(all=True) [0, 60, 120, 180, 240, 300] - sage: GF(107)(0).sqrt(all=True) + sage: GF(107)(0).sqrt(all=True) # optional - sage.rings.finite_rings [0] :: sage: R = Integers(5*13^3*37); R Ring of integers modulo 406445 - sage: v = R(-1).sqrt(all=True); v + sage: v = R(-1).sqrt(all=True); v # optional - sage.libs.pari [78853, 111808, 160142, 193097, 213348, 246303, 294637, 327592] - sage: [x^2 for x in v] + sage: [x^2 for x in v] # optional - sage.libs.pari [406444, 406444, 406444, 406444, 406444, 406444, 406444, 406444] - sage: v = R(169).sqrt(all=True); min(v), -max(v), len(v) + sage: v = R(169).sqrt(all=True); min(v), -max(v), len(v) # optional - sage.libs.pari (13, 13, 104) - sage: all(x^2 == 169 for x in v) + sage: all(x^2 == 169 for x in v) # optional - sage.libs.pari True Modulo a power of 2:: @@ -2980,7 +2983,7 @@ cdef class IntegerMod_int(IntegerMod_abstract): Check for :trac:`30797`:: - sage: GF(103)(-1).sqrt(extend=False, all=True) + sage: GF(103)(-1).sqrt(extend=False, all=True) # optional - sage.rings.finite_rings [] """ cdef int_fast32_t i, n = self.__modulus.int32 @@ -3312,7 +3315,7 @@ cdef class IntegerMod_int64(IntegerMod_abstract): cpdef bint is_unit(IntegerMod_int64 self): """ - Return True iff this element is a unit. + Return ``True`` iff this element is a unit. EXAMPLES:: @@ -3547,9 +3550,9 @@ cdef class IntegerMod_int64(IntegerMod_abstract): sage: R = Integers(10) sage: R(2)^10 4 - sage: p = next_prime(10^5) - sage: R = Integers(p) - sage: R(1234)^(p-1) + sage: p = next_prime(10^5) # optional - sage.libs.pari + sage: R = Integers(p) # optional - sage.libs.pari + sage: R(1234)^(p - 1) # optional - sage.libs.pari 1 sage: R = Integers(17^5) sage: R(17)^5 @@ -3575,14 +3578,14 @@ cdef class IntegerMod_int64(IntegerMod_abstract): We define ``0^0`` to be unity, :trac:`13894`:: - sage: p = next_prime(10^5) - sage: R = Integers(p) - sage: R(0)^0 + sage: p = next_prime(10^5) # optional - sage.libs.pari + sage: R = Integers(p) # optional - sage.libs.pari + sage: R(0)^0 # optional - sage.libs.pari 1 The value returned from ``0^0`` should belong to our ring:: - sage: type(R(0)^0) == type(R(0)) + sage: type(R(0)^0) == type(R(0)) # optional - sage.libs.pari True When the modulus is ``1``, the only element in the ring is @@ -3902,11 +3905,11 @@ def square_root_mod_prime_power(IntegerMod_abstract a, p, e): :: - sage: a = Mod(72,97^10) - sage: b = square_root_mod_prime_power(a,97,10) - sage: b^2 == a + sage: a = Mod(72, 97^10) + sage: b = square_root_mod_prime_power(a, 97, 10) # optional - sage.libs.pari + sage: b^2 == a # optional - sage.libs.pari True - sage: mod(100, 5^7).sqrt()^2 + sage: mod(100, 5^7).sqrt()^2 # optional - sage.libs.pari 100 TESTS: @@ -3914,15 +3917,15 @@ def square_root_mod_prime_power(IntegerMod_abstract a, p, e): A big example for the binary case (:trac:`33961`):: sage: y = Mod(-7, 2^777) - sage: hex(y.sqrt()^2 - y) + sage: hex(y.sqrt()^2 - y) # optional - sage.libs.pari '0x0' Testing with random squares in random rings:: - sage: p = random_prime(999) - sage: e = randrange(1, 999) - sage: x = Zmod(p^e).random_element() - sage: (x^2).sqrt()^2 == x^2 + sage: p = random_prime(999) # optional - sage.libs.pari + sage: e = randrange(1, 999) # optional - sage.libs.pari + sage: x = Zmod(p^e).random_element() # optional - sage.libs.pari + sage: (x^2).sqrt()^2 == x^2 # optional - sage.libs.pari True """ if a.is_zero() or a.is_one(): @@ -4017,7 +4020,7 @@ cpdef square_root_mod_prime(IntegerMod_abstract a, p=None): :: sage: from sage.rings.finite_rings.integer_mod import square_root_mod_prime # sqrt() uses brute force for small p - sage: all(square_root_mod_prime(a*a)^2 == a*a + sage: all(square_root_mod_prime(a*a)^2 == a*a # optional - sage.libs.pari ....: for p in prime_range(100) ....: for a in Integers(p)) True @@ -4103,7 +4106,7 @@ def lucas_q1(mm, IntegerMod_abstract P): TESTS:: sage: from sage.rings.finite_rings.integer_mod import lucas_q1 - sage: all(lucas_q1(k, a) == BinaryRecurrenceSequence(a, -1, 2, a)(k) + sage: all(lucas_q1(k, a) == BinaryRecurrenceSequence(a, -1, 2, a)(k) # optional - sage.combinat ....: for a in Integers(23) ....: for k in range(13)) True @@ -4171,7 +4174,7 @@ def lucas(k, P, Q=1, n=None): sage: p = randint(0,100000) sage: q = randint(0,100000) sage: n = randint(1,100) - sage: all(lucas(k,p,q,n)[0] == Mod(lucas_number2(k,p,q),n) + sage: all(lucas(k, p, q, n)[0] == Mod(lucas_number2(k, p, q), n) # optional - sage.combinat ....: for k in Integers(20)) True sage: from sage.rings.finite_rings.integer_mod import lucas @@ -4179,7 +4182,7 @@ def lucas(k, P, Q=1, n=None): sage: q = randint(0,100000) sage: n = randint(1,100) sage: k = randint(0,100) - sage: lucas(k,p,q,n) == [Mod(lucas_number2(k,p,q),n),Mod(q^(int(k/2)),n)] + sage: lucas(k, p, q, n) == [Mod(lucas_number2(k, p, q), n), Mod(q^(int(k/2)), n)] # optional - sage.combinat True EXAMPLES:: @@ -4317,8 +4320,14 @@ cdef class IntegerMod_to_IntegerMod(IntegerMod_hom): sage: from sage.rings.finite_rings.integer_mod import IntegerMod_to_IntegerMod sage: Rs = [Integers(3**k) for k in range(1,30,5)] sage: [type(R(0)) for R in Rs] - [, , , , , ] - sage: fs = [IntegerMod_to_IntegerMod(S, R) for R in Rs for S in Rs if S is not R and S.order() > R.order()] + [, + , + , + , + , + ] + sage: fs = [IntegerMod_to_IntegerMod(S, R) + ....: for R in Rs for S in Rs if S is not R and S.order() > R.order()] sage: all(f(-1) == f.codomain()(-1) for f in fs) True sage: [f(-1) for f in fs] @@ -4387,7 +4396,9 @@ cdef class Integer_to_IntegerMod(IntegerMod_hom): sage: from sage.rings.finite_rings.integer_mod import Integer_to_IntegerMod sage: Rs = [Integers(10), Integers(10^5), Integers(10^10)] sage: [type(R(0)) for R in Rs] - [, , ] + [, + , + ] sage: fs = [Integer_to_IntegerMod(R) for R in Rs] sage: [f(-1) for f in fs] [9, 99999, 9999999999] @@ -4449,7 +4460,7 @@ cdef class IntegerMod_to_Integer(Map): EXAMPLES:: - sage: ZZ.convert_map_from(GF(2)) + sage: ZZ.convert_map_from(GF(2)) # optional - sage.rings.finite_rings Lifting map: From: Finite Field of size 2 To: Integer Ring @@ -4461,7 +4472,7 @@ cdef class IntegerMod_to_Integer(Map): Lifting maps are morphisms in the category of sets (see :trac:`15618`):: - sage: ZZ.convert_map_from(GF(2)).parent() + sage: ZZ.convert_map_from(GF(2)).parent() # optional - sage.rings.finite_rings Set of Morphisms from Finite Field of size 2 to Integer Ring in Category of sets """ import sage.categories.homset @@ -4493,7 +4504,11 @@ cdef class Int_to_IntegerMod(IntegerMod_hom): sage: from sage.rings.finite_rings.integer_mod import Int_to_IntegerMod sage: Rs = [Integers(2**k) for k in range(1,50,10)] sage: [type(R(0)) for R in Rs] - [, , , , ] + [, + , + , + , + ] sage: fs = [Int_to_IntegerMod(R) for R in Rs] sage: [f(-1) for f in fs] [1, 2047, 2097151, 2147483647, 2199023255551] diff --git a/src/sage/rings/finite_rings/integer_mod_ring.py b/src/sage/rings/finite_rings/integer_mod_ring.py index a10d84aade9..f34faa4e9a9 100644 --- a/src/sage/rings/finite_rings/integer_mod_ring.py +++ b/src/sage/rings/finite_rings/integer_mod_ring.py @@ -16,16 +16,16 @@ :: sage: r = Integers(7) - sage: s = GF(7) - sage: r.has_coerce_map_from(s) + sage: s = GF(7) # optional - sage.rings.finite_rings + sage: r.has_coerce_map_from(s) # optional - sage.rings.finite_rings False - sage: s.has_coerce_map_from(r) + sage: s.has_coerce_map_from(r) # optional - sage.rings.finite_rings True - sage: s(1) + r(1) + sage: s(1) + r(1) # optional - sage.rings.finite_rings 2 - sage: parent(s(1) + r(1)) + sage: parent(s(1) + r(1)) # optional - sage.rings.finite_rings Finite Field of size 7 - sage: parent(r(1) + s(1)) + sage: parent(r(1) + s(1)) # optional - sage.rings.finite_rings Finite Field of size 7 We list the elements of `\ZZ/3\ZZ`:: @@ -259,9 +259,9 @@ def is_IntegerModRing(x): Use isinstance(..., sage.rings.abc.IntegerModRing) instead. See https://github.com/sagemath/sage/issues/32606 for details. True - sage: is_IntegerModRing(GF(13)) + sage: is_IntegerModRing(GF(13)) # optional - sage.rings.finite_rings True - sage: is_IntegerModRing(GF(4, 'a')) + sage: is_IntegerModRing(GF(4, 'a')) # optional - sage.rings.finite_rings False sage: is_IntegerModRing(10) False @@ -290,9 +290,9 @@ def _unit_gens_primepowercase(p, r): sage: from sage.rings.finite_rings.integer_mod_ring import _unit_gens_primepowercase sage: _unit_gens_primepowercase(2, 3) [(7, 2), (5, 2)] - sage: _unit_gens_primepowercase(17, 1) + sage: _unit_gens_primepowercase(17, 1) # optional - sage.libs.pari [(3, 16)] - sage: _unit_gens_primepowercase(3, 3) + sage: _unit_gens_primepowercase(3, 3) # optional - sage.libs.pari [(2, 18)] """ pr = p**r @@ -344,14 +344,14 @@ class IntegerModRing_generic(quotient_ring.QuotientRing_generic, sage.rings.abc. 29 sage: FF.order() 29 - sage: gens = FF.unit_gens() - sage: a = gens[0] - sage: a + sage: gens = FF.unit_gens() # optional - sage.groups + sage: a = gens[0] # optional - sage.groups + sage: a # optional - sage.groups 2 - sage: a.is_square() + sage: a.is_square() # optional - sage.groups False - sage: def pow(i): return a**i - sage: [pow(i) for i in range(16)] + sage: def pow(i): return a**i # optional - sage.groups + sage: [pow(i) for i in range(16)] # optional - sage.groups [1, 2, 4, 8, 16, 3, 6, 12, 24, 19, 9, 18, 7, 14, 28, 27] sage: TestSuite(FF).run() @@ -404,23 +404,23 @@ class IntegerModRing_generic(quotient_ring.QuotientRing_generic, sage.rings.abc. 16 sage: Z16.characteristic() 16 - sage: gens = Z16.unit_gens() - sage: gens + sage: gens = Z16.unit_gens() # optional - sage.groups + sage: gens # optional - sage.groups (15, 5) - sage: a = gens[0] - sage: b = gens[1] - sage: def powa(i): return a**i - sage: def powb(i): return b**i - sage: gp_exp = FF.unit_group_exponent() - sage: gp_exp + sage: a = gens[0] # optional - sage.groups + sage: b = gens[1] # optional - sage.groups + sage: def powa(i): return a**i # optional - sage.groups + sage: def powb(i): return b**i # optional - sage.groups + sage: gp_exp = FF.unit_group_exponent() # optional - sage.groups + sage: gp_exp # optional - sage.groups 28 - sage: [powa(i) for i in range(15)] + sage: [powa(i) for i in range(15)] # optional - sage.groups [1, 15, 1, 15, 1, 15, 1, 15, 1, 15, 1, 15, 1, 15, 1] - sage: [powb(i) for i in range(15)] + sage: [powb(i) for i in range(15)] # optional - sage.groups [1, 5, 9, 13, 1, 5, 9, 13, 1, 5, 9, 13, 1, 5, 9] - sage: a.multiplicative_order() + sage: a.multiplicative_order() # optional - sage.groups 2 - sage: b.multiplicative_order() + sage: b.multiplicative_order() # optional - sage.groups 4 sage: TestSuite(Z16).run() @@ -572,7 +572,8 @@ def extension(self, poly, name=None, names=None, **kwds): sage: R. = QQ[] sage: Integers(8).extension(t^2 - 3) - Univariate Quotient Polynomial Ring in t over Ring of integers modulo 8 with modulus t^2 + 5 + Univariate Quotient Polynomial Ring in t + over Ring of integers modulo 8 with modulus t^2 + 5 """ if self.modulus() == 1: return self @@ -638,22 +639,22 @@ def multiplicative_subgroups(self): EXAMPLES:: - sage: Integers(5).multiplicative_subgroups() + sage: Integers(5).multiplicative_subgroups() # optional - sage.groups ((2,), (4,), ()) - sage: Integers(15).multiplicative_subgroups() + sage: Integers(15).multiplicative_subgroups() # optional - sage.groups ((11, 7), (11, 4), (2,), (11,), (14,), (7,), (4,), ()) - sage: Integers(2).multiplicative_subgroups() + sage: Integers(2).multiplicative_subgroups() # optional - sage.groups ((),) - sage: len(Integers(341).multiplicative_subgroups()) + sage: len(Integers(341).multiplicative_subgroups()) # optional - sage.groups 80 TESTS:: - sage: IntegerModRing(1).multiplicative_subgroups() + sage: IntegerModRing(1).multiplicative_subgroups() # optional - sage.groups ((),) - sage: IntegerModRing(2).multiplicative_subgroups() + sage: IntegerModRing(2).multiplicative_subgroups() # optional - sage.groups ((),) - sage: IntegerModRing(3).multiplicative_subgroups() + sage: IntegerModRing(3).multiplicative_subgroups() # optional - sage.groups ((2,), ()) """ return tuple(tuple(g.value() for g in H.gens()) @@ -667,7 +668,7 @@ def is_integral_domain(self, proof=None): sage: Integers(389).is_integral_domain() True - sage: Integers(389^2).is_integral_domain() + sage: Integers(389^2).is_integral_domain() # optional - sage.libs.pari False TESTS: @@ -688,7 +689,7 @@ def is_unique_factorization_domain(self, proof=None): sage: Integers(389).is_unique_factorization_domain() True - sage: Integers(389^2).is_unique_factorization_domain() + sage: Integers(389^2).is_unique_factorization_domain() # optional - sage.libs.pari False """ return self.is_field(proof) @@ -696,7 +697,7 @@ def is_unique_factorization_domain(self, proof=None): @cached_method def is_field(self, proof=None): r""" - Return True precisely if the order is prime. + Return ``True`` precisely if the order is prime. INPUT: @@ -790,10 +791,10 @@ def field(self): sage: R = Integers(7); R Ring of integers modulo 7 - sage: R.field() + sage: R.field() # optional - sage.rings.finite_rings Finite Field of size 7 sage: R = Integers(9) - sage: R.field() + sage: R.field() # optional - sage.rings.finite_rings Traceback (most recent call last): ... ValueError: self must be a field @@ -827,8 +828,8 @@ def _pseudo_fraction_field(self): This should be very fast:: - sage: R. = Integers(next_prime(10^101)*next_prime(10^100))[] - sage: x / R.base_ring()(2) + sage: R. = Integers(next_prime(10^101)*next_prime(10^100))[] # optional - sage.libs.pari + sage: x / R.base_ring()(2) # optional - sage.libs.pari 500000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000013365000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000401*x """ return self @@ -847,18 +848,18 @@ def multiplicative_group_is_cyclic(self): sage: R.multiplicative_group_is_cyclic() True sage: R = Integers(9) - sage: R.multiplicative_group_is_cyclic() + sage: R.multiplicative_group_is_cyclic() # optional - sage.libs.pari True - sage: Integers(8).multiplicative_group_is_cyclic() + sage: Integers(8).multiplicative_group_is_cyclic() # optional - sage.libs.pari False - sage: Integers(4).multiplicative_group_is_cyclic() + sage: Integers(4).multiplicative_group_is_cyclic() # optional - sage.libs.pari True - sage: Integers(25*3).multiplicative_group_is_cyclic() + sage: Integers(25*3).multiplicative_group_is_cyclic() # optional - sage.libs.pari False We test that :trac:`5250` is fixed:: - sage: Integers(162).multiplicative_group_is_cyclic() + sage: Integers(162).multiplicative_group_is_cyclic() # optional - sage.libs.pari True """ n = self.order() @@ -885,24 +886,24 @@ def multiplicative_generator(self): sage: R = Integers(7); R Ring of integers modulo 7 - sage: R.multiplicative_generator() + sage: R.multiplicative_generator() # optional - sage.libs.pari 3 sage: R = Integers(9) - sage: R.multiplicative_generator() + sage: R.multiplicative_generator() # optional - sage.libs.pari 2 - sage: Integers(8).multiplicative_generator() + sage: Integers(8).multiplicative_generator() # optional - sage.libs.pari Traceback (most recent call last): ... ValueError: multiplicative group of this ring is not cyclic - sage: Integers(4).multiplicative_generator() + sage: Integers(4).multiplicative_generator() # optional - sage.libs.pari 3 - sage: Integers(25*3).multiplicative_generator() + sage: Integers(25*3).multiplicative_generator() # optional - sage.libs.pari Traceback (most recent call last): ... ValueError: multiplicative group of this ring is not cyclic - sage: Integers(25*3).unit_gens() + sage: Integers(25*3).unit_gens() # optional - sage.libs.pari (26, 52) - sage: Integers(162).unit_gens() + sage: Integers(162).unit_gens() # optional - sage.libs.pari (83,) """ try: @@ -927,9 +928,9 @@ def quadratic_nonresidue(self): EXAMPLES:: sage: R = Integers(17) - sage: R.quadratic_nonresidue() + sage: R.quadratic_nonresidue() # optional - sage.libs.pari 3 - sage: R(3).is_square() + sage: R(3).is_square() # optional - sage.libs.pari False """ try: @@ -954,18 +955,18 @@ def square_roots_of_one(self): sage: R = Integers(2^10) sage: [x for x in R if x^2 == 1] [1, 511, 513, 1023] - sage: R.square_roots_of_one() + sage: R.square_roots_of_one() # optional - sage.libs.pari (1, 511, 513, 1023) :: - sage: v = Integers(9*5).square_roots_of_one(); v + sage: v = Integers(9*5).square_roots_of_one(); v # optional - sage.libs.pari (1, 19, 26, 44) - sage: [x^2 for x in v] + sage: [x^2 for x in v] # optional - sage.libs.pari [1, 1, 1, 1] - sage: v = Integers(9*5*8).square_roots_of_one(); v + sage: v = Integers(9*5*8).square_roots_of_one(); v # optional - sage.libs.pari (1, 19, 71, 89, 91, 109, 161, 179, 181, 199, 251, 269, 271, 289, 341, 359) - sage: [x^2 for x in v] + sage: [x^2 for x in v] # optional - sage.libs.pari [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1] """ try: @@ -1132,7 +1133,7 @@ def _pari_order(self): EXAMPLES:: - sage: Zmod(87)._pari_order() + sage: Zmod(87)._pari_order() # optional - sage.libs.pari 87 """ try: @@ -1145,14 +1146,14 @@ def _element_constructor_(self, x): """ TESTS:: - sage: K2 = GF(2) - sage: K3 = GF(3) - sage: K8 = GF(8,'a') - sage: K8(5) # indirect doctest + sage: K2 = GF(2) # optional - sage.rings.finite_rings + sage: K3 = GF(3) # optional - sage.rings.finite_rings + sage: K8 = GF(8, 'a') # optional - sage.rings.finite_rings + sage: K8(5) # indirect doctest # optional - sage.rings.finite_rings 1 - sage: K8('a+1') + sage: K8('a+1') # optional - sage.rings.finite_rings a + 1 - sage: K8(K2(1)) + sage: K8(K2(1)) # optional - sage.rings.finite_rings 1 The following test refers to :trac:`6468`:: @@ -1164,7 +1165,7 @@ def _element_constructor_(self, x): ....: raise PariError sage: P = foo_parent() sage: F = foo(P) - sage: GF(2)(F) + sage: GF(2)(F) # optional - sage.rings.finite_rings Traceback (most recent call last): ... TypeError: error coercing to finite field @@ -1172,21 +1173,21 @@ def _element_constructor_(self, x): The following test refers to :trac:`8970`:: sage: R = Zmod(13); a = R(2) - sage: a == R(gap(a)) + sage: a == R(gap(a)) # optional - sage.libs.gap True libgap interface (:trac:`23714`):: - sage: a = libgap.eval("Z(13)^2") - sage: a.sage() + sage: a = libgap.eval("Z(13)^2") # optional - sage.libs.gap + sage: a.sage() # optional - sage.libs.gap 4 - sage: libgap(a.sage()) == a + sage: libgap(a.sage()) == a # optional - sage.libs.gap True better syntax for libgap interface:: - sage: a = libgap.Z(13)^2 - sage: libgap(a.sage()) == a + sage: a = libgap.Z(13)^2 # optional - sage.libs.gap + sage: libgap(a.sage()) == a # optional - sage.libs.gap True """ try: @@ -1295,7 +1296,7 @@ def _convert_map_from_(self, other): EXAMPLES:: - sage: Zmod(81).convert_map_from(Qp(3)) + sage: Zmod(81).convert_map_from(Qp(3)) # optional - sage.rings.padics Reduction morphism: From: 3-adic Field with capped relative precision 20 To: Ring of integers modulo 81 @@ -1318,10 +1319,12 @@ def __richcmp__(self, other, op): Ring of integers modulo 12 sage: Z13 = IntegerModRing(13); Z13 Ring of integers modulo 13 - sage: F = GF(11); F + sage: Z11 == Z11, Z11 == Z12, Z11 == Z13 + (True, False, False) + sage: F = GF(11); F # optional - sage.rings.finite_rings Finite Field of size 11 - sage: Z11 == Z11, Z11 == Z12, Z11 == Z13, Z11 == F - (True, False, False, False) + sage: Z11 == F # optional - sage.rings.finite_rings + False In :trac:`15229`, the following was implemented:: @@ -1329,7 +1332,7 @@ def __richcmp__(self, other, op): sage: R2 = IntegerModRing(5, is_field=True) sage: R1 is R2 # used to return False True - sage: R2 == GF(5) + sage: R2 == GF(5) # optional - sage.rings.finite_rings False """ @@ -1363,12 +1366,12 @@ def unit_gens(self, **kwds): EXAMPLES:: sage: R = IntegerModRing(18) - sage: R.unit_gens() + sage: R.unit_gens() # optional - sage.groups (11,) sage: R = IntegerModRing(17) - sage: R.unit_gens() + sage: R.unit_gens() # optional - sage.groups (3,) - sage: IntegerModRing(next_prime(10^30)).unit_gens() + sage: IntegerModRing(next_prime(10^30)).unit_gens() # optional - sage.groups (5,) The choice of generators is affected by the optional keyword @@ -1376,18 +1379,18 @@ def unit_gens(self, **kwds): See :meth:`unit_group` for details. :: sage: A = Zmod(55) - sage: A.unit_gens(algorithm='sage') + sage: A.unit_gens(algorithm='sage') # optional - sage.groups (12, 46) - sage: A.unit_gens(algorithm='pari') + sage: A.unit_gens(algorithm='pari') # optional - sage.groups sage.libs.pari (2, 21) TESTS:: - sage: IntegerModRing(2).unit_gens() + sage: IntegerModRing(2).unit_gens() # optional - sage.groups () - sage: IntegerModRing(4).unit_gens() + sage: IntegerModRing(4).unit_gens() # optional - sage.groups (3,) - sage: IntegerModRing(8).unit_gens() + sage: IntegerModRing(8).unit_gens() # optional - sage.groups (7, 5) """ @@ -1398,10 +1401,10 @@ def unit_group_exponent(self): EXAMPLES:: sage: R = IntegerModRing(17) - sage: R.unit_group_exponent() + sage: R.unit_group_exponent() # optional - sage.groups 16 sage: R = IntegerModRing(18) - sage: R.unit_group_exponent() + sage: R.unit_group_exponent() # optional - sage.groups 6 """ return self.unit_group().exponent() @@ -1413,7 +1416,7 @@ def unit_group_order(self): EXAMPLES:: sage: R = Integers(500) - sage: R.unit_group_order() + sage: R.unit_group_order() # optional - sage.groups 200 """ return self.unit_group().order() @@ -1452,69 +1455,71 @@ def unit_group(self, algorithm='sage'): cyclic factors are computed, but in a different order:: sage: A = Zmod(15) - sage: G = A.unit_group(); G + sage: G = A.unit_group(); G # optional - sage.groups Multiplicative Abelian group isomorphic to C2 x C4 - sage: G.gens_values() + sage: G.gens_values() # optional - sage.groups (11, 7) - sage: H = A.unit_group(algorithm='pari'); H + sage: H = A.unit_group(algorithm='pari'); H # optional - sage.groups sage.libs.pari Multiplicative Abelian group isomorphic to C4 x C2 - sage: H.gens_values() + sage: H.gens_values() # optional - sage.groups sage.libs.pari (7, 11) Here are two examples where the cyclic factors are isomorphic, but are ordered differently and have different generators:: sage: A = Zmod(40) - sage: G = A.unit_group(); G + sage: G = A.unit_group(); G # optional - sage.groups Multiplicative Abelian group isomorphic to C2 x C2 x C4 - sage: G.gens_values() + sage: G.gens_values() # optional - sage.groups (31, 21, 17) - sage: H = A.unit_group(algorithm='pari'); H + sage: H = A.unit_group(algorithm='pari'); H # optional - sage.groups sage.libs.pari Multiplicative Abelian group isomorphic to C4 x C2 x C2 - sage: H.gens_values() + sage: H.gens_values() # optional - sage.groups sage.libs.pari (17, 31, 21) sage: A = Zmod(192) - sage: G = A.unit_group(); G + sage: G = A.unit_group(); G # optional - sage.groups Multiplicative Abelian group isomorphic to C2 x C16 x C2 - sage: G.gens_values() + sage: G.gens_values() # optional - sage.groups (127, 133, 65) - sage: H = A.unit_group(algorithm='pari'); H + sage: H = A.unit_group(algorithm='pari'); H # optional - sage.groups sage.libs.pari Multiplicative Abelian group isomorphic to C16 x C2 x C2 - sage: H.gens_values() + sage: H.gens_values() # optional - sage.groups sage.libs.pari (133, 127, 65) In the following examples, the cyclic factors are not even isomorphic:: sage: A = Zmod(319) - sage: A.unit_group() + sage: A.unit_group() # optional - sage.groups Multiplicative Abelian group isomorphic to C10 x C28 - sage: A.unit_group(algorithm='pari') + sage: A.unit_group(algorithm='pari') # optional - sage.groups sage.libs.pari Multiplicative Abelian group isomorphic to C140 x C2 sage: A = Zmod(30.factorial()) - sage: A.unit_group() - Multiplicative Abelian group isomorphic to C2 x C16777216 x C3188646 x C62500 x C2058 x C110 x C156 x C16 x C18 x C22 x C28 - sage: A.unit_group(algorithm='pari') - Multiplicative Abelian group isomorphic to C20499647385305088000000 x C55440 x C12 x C12 x C4 x C2 x C2 x C2 x C2 x C2 x C2 + sage: A.unit_group() # optional - sage.groups + Multiplicative Abelian group isomorphic to + C2 x C16777216 x C3188646 x C62500 x C2058 x C110 x C156 x C16 x C18 x C22 x C28 + sage: A.unit_group(algorithm='pari') # optional - sage.groups sage.libs.pari + Multiplicative Abelian group isomorphic to + C20499647385305088000000 x C55440 x C12 x C12 x C4 x C2 x C2 x C2 x C2 x C2 x C2 TESTS: We test the cases where the unit group is trivial:: sage: A = Zmod(1) - sage: A.unit_group() + sage: A.unit_group() # optional - sage.groups Trivial Abelian group - sage: A.unit_group(algorithm='pari') + sage: A.unit_group(algorithm='pari') # optional - sage.groups sage.libs.pari Trivial Abelian group sage: A = Zmod(2) - sage: A.unit_group() + sage: A.unit_group() # optional - sage.groups Trivial Abelian group - sage: A.unit_group(algorithm='pari') + sage: A.unit_group(algorithm='pari') # optional - sage.groups sage.libs.pari Trivial Abelian group - sage: Zmod(3).unit_group(algorithm='bogus') + sage: Zmod(3).unit_group(algorithm='bogus') # optional - sage.groups Traceback (most recent call last): ... ValueError: unknown algorithm 'bogus' for computing the unit group @@ -1578,7 +1583,7 @@ def _gap_init_(self): sage: R = Integers(12345678900) sage: R Ring of integers modulo 12345678900 - sage: gap(R) # indirect doctest + sage: gap(R) # indirect doctest # optional - sage.libs.gap (Integers mod 12345678900) """ return 'ZmodnZ({})'.format(self.order()) @@ -1624,7 +1629,7 @@ def crt(v): EXAMPLES:: sage: from sage.rings.finite_rings.integer_mod_ring import crt - sage: crt([mod(3, 8),mod(1,19),mod(7, 15)]) + sage: crt([mod(3, 8), mod(1,19), mod(7, 15)]) 1027 """ if len(v) == 0: diff --git a/src/sage/rings/fraction_field.py b/src/sage/rings/fraction_field.py index 7e5703212bf..91c326b13aa 100644 --- a/src/sage/rings/fraction_field.py +++ b/src/sage/rings/fraction_field.py @@ -264,11 +264,11 @@ def _coerce_map_from_(self, S): number fields:: sage: _. = ZZ[] - sage: K. = NumberField(x^5-3*x^4+2424*x^3+2*x-232) - sage: R = K.ring_of_integers() - sage: S. = R[] - sage: F = FractionField(S) - sage: F(1/a) + sage: K. = NumberField(x^5 - 3*x^4 + 2424*x^3 + 2*x - 232) # optional - sage.rings.number_field + sage: R = K.ring_of_integers() # optional - sage.rings.number_field + sage: S. = R[] # optional - sage.rings.number_field + sage: F = FractionField(S) # optional - sage.rings.number_field + sage: F(1/a) # optional - sage.rings.number_field (a^4 - 3*a^3 + 2424*a^2 + 2)/232 Some corner cases have been known to fail in the past (:trac:`5917`):: @@ -394,11 +394,11 @@ def _number_field_to_frac_of_ring_of_integers(self, x): number fields:: sage: _. = ZZ[] - sage: K. = NumberField(x^5-3*x^4+2424*x^3+2*x-232) - sage: R = K.ring_of_integers() - sage: S. = R[] - sage: F = FractionField(S) # indirect doctest - sage: F(1/a) + sage: K. = NumberField(x^5 - 3*x^4 + 2424*x^3 + 2*x - 232) # optional - sage.rings.number_field + sage: R = K.ring_of_integers() # optional - sage.rings.number_field + sage: S. = R[] # optional - sage.rings.number_field + sage: F = FractionField(S) # indirect doctest # optional - sage.rings.number_field + sage: F(1/a) # optional - sage.rings.number_field (a^4 - 3*a^3 + 2424*a^2 + 2)/232 """ f = x.polynomial() # Polynomial over QQ @@ -459,7 +459,7 @@ def characteristic(self): Integer Ring sage: R = Frac(ZZ['t']); R.characteristic() 0 - sage: R = Frac(GF(5)['w']); R.characteristic() + sage: R = Frac(GF(5)['w']); R.characteristic() # optional - sage.rings.finite_rings 5 """ return self._R.characteristic() @@ -481,7 +481,7 @@ def _latex_(self): EXAMPLES:: - sage: latex(Frac(GF(7)['x,y,z'])) # indirect doctest + sage: latex(Frac(GF(7)['x,y,z'])) # indirect doctest # optional - sage.rings.finite_rings \mathrm{Frac}(\Bold{F}_{7}[x, y, z]) """ return "\\mathrm{Frac}(%s)" % latex.latex(self._R) @@ -494,7 +494,7 @@ def _magma_init_(self, magma): sage: QQ['x'].fraction_field()._magma_init_(magma) # optional - magma 'SageCreateWithNames(FieldOfFractions(SageCreateWithNames(PolynomialRing(_sage_ref...),["x"])),["x"])' - sage: GF(9,'a')['x,y,z'].fraction_field()._magma_init_(magma) # optional - magma + sage: GF(9,'a')['x,y,z'].fraction_field()._magma_init_(magma) # optional - magma # optional - sage.rings.finite_rings 'SageCreateWithNames(FieldOfFractions(SageCreateWithNames(PolynomialRing(_sage_ref...,3,"grevlex"),["x","y","z"])),["x","y","z"])' ``_magma_init_`` gets called implicitly below:: @@ -571,17 +571,17 @@ def _element_constructor_(self, x, y=None, coerce=True): The next example failed before :trac:`4376`:: - sage: K(pari((x + 1)/(x^2 + x + 1))) + sage: K(pari((x + 1)/(x^2 + x + 1))) # optional - sage.libs.pari (x + 1)/(x^2 + x + 1) These examples failed before :trac:`11368`:: sage: R. = PolynomialRing(QQ) sage: S = R.fraction_field() - sage: S(pari((x + y)/y)) + sage: S(pari((x + y)/y)) # optional - sage.libs.pari (x + y)/y - sage: S(pari(x + y + 1/z)) + sage: S(pari(x + y + 1/z)) # optional - sage.libs.pari (x*z + y*z + 1)/z This example failed before :trac:`23664`:: @@ -613,13 +613,13 @@ def _element_constructor_(self, x, y=None, coerce=True): Check that :trac:`24539` is fixed:: sage: tau = polygen(QQ, 'tau') - sage: PolynomialRing(CyclotomicField(2), 'z').fraction_field()(tau/(1+tau)) + sage: PolynomialRing(CyclotomicField(2), 'z').fraction_field()(tau/(1+tau)) # optional - sage.rings.number_field z/(z + 1) Check that :trac:`26150` is fixed:: - sage: z = SR.var('z') - sage: CyclotomicField(2)['z'].fraction_field()(2*(4*z + 5)/((z + 1)*(z - 1)^4)) + sage: 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 (8*z + 10)/(z^5 - 3*z^4 + 2*z^3 + 2*z^2 - 3*z + 1) :: @@ -731,11 +731,12 @@ def construction(self): sage: Frac(ZZ['x']).construction() (FractionField, Univariate Polynomial Ring in x over Integer Ring) - sage: K = Frac(GF(3)['t']) - sage: f, R = K.construction() - sage: f(R) - Fraction Field of Univariate Polynomial Ring in t over Finite Field of size 3 - sage: f(R) == K + sage: K = Frac(GF(3)['t']) # optional - sage.rings.finite_rings + sage: f, R = K.construction() # optional - sage.rings.finite_rings + sage: f(R) # optional - sage.rings.finite_rings + Fraction Field of Univariate Polynomial Ring in t + over Finite Field of size 3 + sage: f(R) == K # optional - sage.rings.finite_rings True """ from sage.categories.pushout import FractionField @@ -801,7 +802,8 @@ def ngens(self): EXAMPLES:: sage: R = Frac(PolynomialRing(QQ,'z',10)); R - Fraction Field of Multivariate Polynomial Ring in z0, z1, z2, z3, z4, z5, z6, z7, z8, z9 over Rational Field + Fraction Field of Multivariate Polynomial Ring + in z0, z1, z2, z3, z4, z5, z6, z7, z8, z9 over Rational Field sage: R.ngens() 10 """ @@ -814,7 +816,8 @@ def gen(self, i=0): EXAMPLES:: sage: R = Frac(PolynomialRing(QQ,'z',10)); R - Fraction Field of Multivariate Polynomial Ring in z0, z1, z2, z3, z4, z5, z6, z7, z8, z9 over Rational Field + Fraction Field of Multivariate Polynomial Ring + in z0, z1, z2, z3, z4, z5, z6, z7, z8, z9 over Rational Field sage: R.0 z0 sage: R.gen(3) @@ -983,8 +986,8 @@ def ring_of_integers(self): EXAMPLES:: - sage: K = FractionField(GF(5)['t']) - sage: K.ring_of_integers() + sage: K = FractionField(GF(5)['t']) # optional - sage.rings.finite_rings + sage: K.ring_of_integers() # optional - sage.rings.finite_rings Univariate Polynomial Ring in t over Finite Field of size 5 """ return self._R @@ -995,8 +998,8 @@ def maximal_order(self): EXAMPLES:: - sage: K = FractionField(GF(5)['t']) - sage: K.maximal_order() + sage: K = FractionField(GF(5)['t']) # optional - sage.rings.finite_rings + sage: K.maximal_order() # optional - sage.rings.finite_rings Univariate Polynomial Ring in t over Finite Field of size 5 """ return self._R @@ -1007,8 +1010,8 @@ def class_number(self): EXAMPLES:: - sage: R. = GF(5)[]; K = R.fraction_field() - sage: K.class_number() + sage: R. = GF(5)[]; K = R.fraction_field() # optional - sage.rings.finite_rings + sage: K.class_number() # optional - sage.rings.finite_rings 1 """ return 1 @@ -1019,11 +1022,11 @@ def _factor_univariate_polynomial(self, f): EXAMPLES:: - sage: k. = GF(9) - sage: K = k['t'].fraction_field() - sage: R. = K[] - sage: f = x^3 + a - sage: f.factor() + sage: k. = GF(9) # optional - sage.rings.finite_rings + sage: K = k['t'].fraction_field() # optional - sage.rings.finite_rings + sage: R. = K[] # optional - sage.rings.finite_rings + sage: f = x^3 + a # optional - sage.rings.finite_rings + sage: f.factor() # optional - sage.rings.finite_rings (x + 2*a + 1)^3 """ @@ -1038,9 +1041,9 @@ def function_field(self): EXAMPLES:: - sage: R. = GF(5)[] - sage: K = R.fraction_field() - sage: K.function_field() + sage: R. = GF(5)[] # optional - sage.rings.finite_rings + sage: K = R.fraction_field() # optional - sage.rings.finite_rings + sage: K.function_field() # optional - sage.rings.finite_rings Rational function field in t over Finite Field of size 5 .. SEEALSO:: @@ -1057,14 +1060,15 @@ def _coerce_map_from_(self, R): EXAMPLES:: - sage: R. = GF(5)[] - sage: K = R.fraction_field() - sage: L = K.function_field() - sage: f = K.coerce_map_from(L); f # indirect doctest + sage: R. = GF(5)[] # optional - sage.rings.finite_rings + sage: K = R.fraction_field() # optional - sage.rings.finite_rings + sage: L = K.function_field() # optional - sage.rings.finite_rings + sage: f = K.coerce_map_from(L); f # indirect doctest # optional - sage.rings.finite_rings Isomorphism: From: Rational function field in t over Finite Field of size 5 - To: Fraction Field of Univariate Polynomial Ring in t over Finite Field of size 5 - sage: f(~L.gen()) + To: Fraction Field of Univariate Polynomial Ring in t + over Finite Field of size 5 + sage: f(~L.gen()) # optional - sage.rings.finite_rings 1/t """ @@ -1162,12 +1166,12 @@ def _richcmp_(self, other, op): sage: R. = QQ[] sage: f = R.fraction_field().coerce_map_from(R) - sage: S. = GF(2)[] - sage: g = S.fraction_field().coerce_map_from(S) + sage: S. = GF(2)[] # optional - sage.rings.finite_rings + sage: g = S.fraction_field().coerce_map_from(S) # optional - sage.rings.finite_rings - sage: f == g # indirect doctest + sage: f == g # indirect doctest # optional - sage.rings.finite_rings False - sage: f == f + sage: f == f # optional - sage.rings.finite_rings True """ @@ -1232,19 +1236,19 @@ def _call_(self, x, check=True): Over inexact rings, we have to take the precision of the denominators into account:: - sage: R=ZpCR(2) - sage: S. = R[] - sage: f = x/S(R(3,absprec=2)) - sage: S(f) + sage: R = ZpCR(2) # optional - sage.rings.padics + sage: S. = R[] # optional - sage.rings.padics + sage: f = x/S(R(3, absprec=2)) # optional - sage.rings.padics + sage: S(f) # optional - sage.rings.padics (1 + 2 + O(2^2))*x Test for Localization:: sage: R. = ZZ[] - sage: L = Localization(R, x**2+2*x+ 1) - sage: 1/(x+1) in L # indirect doctest + sage: L = Localization(R, x**2 + 2*x + 1) # optional - sage.libs.pari + sage: 1/(x + 1) in L # indirect doctest # optional - sage.libs.pari True - sage: 1/(x+2) in L # indirect doctest + sage: 1/(x + 2) in L # indirect doctest # optional - sage.libs.pari False """ codom = self.codomain() @@ -1294,12 +1298,12 @@ def _richcmp_(self, other, op): sage: R. = QQ[] sage: f = R.fraction_field().coerce_map_from(R).section() - sage: S. = GF(2)[] - sage: g = S.fraction_field().coerce_map_from(S).section() + sage: S. = GF(2)[] # optional - sage.rings.finite_rings + sage: g = S.fraction_field().coerce_map_from(S).section() # optional - sage.rings.finite_rings - sage: f == g # indirect doctest + sage: f == g # indirect doctest # optional - sage.rings.finite_rings False - sage: f == f + sage: f == f # optional - sage.rings.finite_rings True """ diff --git a/src/sage/rings/fraction_field_FpT.pyx b/src/sage/rings/fraction_field_FpT.pyx index 8351963a195..1224f2de95b 100644 --- a/src/sage/rings/fraction_field_FpT.pyx +++ b/src/sage/rings/fraction_field_FpT.pyx @@ -30,7 +30,7 @@ from sage.rings.finite_rings.integer_mod cimport mod_inverse_int class FpT(FractionField_1poly_field): r""" - This class represents the fraction field GF(p)(T) for `2 < p < \sqrt{2^31-1}`. + This class represents the fraction field `\GF{p}(T)` for `2 < p < \sqrt{2^31-1}`. EXAMPLES:: @@ -93,7 +93,7 @@ class FpT(FractionField_1poly_field): cdef class FpTElement(FieldElement): """ - An element of an FpT fraction field. + An element of an :class:`FpT` fraction field. TESTS:: @@ -563,7 +563,7 @@ cdef class FpTElement(FieldElement): cpdef FpTElement next(self): """ - This function iterates through all polynomials, returning the "next" polynomial after this one. + Iterate through all polynomials, returning the "next" polynomial after this one. The strategy is as follows: @@ -572,7 +572,7 @@ cdef class FpTElement(FieldElement): - We progress through the elements with both numerator and denominator monic, and with the denominator less than the numerator. For each such, we output all the scalar multiples of it, then all of the scalar multiples of its inverse. - - So if the leading coefficient of the numerator is less than p-1, we scale the numerator to increase it by 1. + - So if the leading coefficient of the numerator is less than `p-1`, we scale the numerator to increase it by 1. - Otherwise, we consider the multiple with numerator and denominator monic. @@ -741,7 +741,7 @@ cdef class FpTElement(FieldElement): cpdef bint is_square(self): """ - Return True if this element is the square of another element of the fraction field. + Return ``True`` if this element is the square of another element of the fraction field. EXAMPLES:: @@ -1848,11 +1848,11 @@ cdef class ZZ_FpT_coerce(RingHomomorphism): cdef inline bint normalize(nmod_poly_t numer, nmod_poly_t denom, long p): """ - Put numer/denom into a normal form: denominator monic and sharing no common factor with the numerator. + Put ``numer`` / ``denom`` into a normal form: denominator monic and sharing no common factor with the numerator. The normalized form of 0 is 0/1. - Return True if numer and denom were changed. + Return ``True`` if ``numer`` and ``denom`` were changed. """ cdef long a cdef bint changed @@ -1923,9 +1923,9 @@ cdef inline long nmod_poly_cmp(nmod_poly_t a, nmod_poly_t b): """ Compare `a` and `b`, returning 0 if they are equal. - - If the degree of `a` is less than that of `b`, returns -1. + - If the degree of `a` is less than that of `b`, returns `-1`. - - If the degree of `b` is less than that of `a`, returns 1. + - If the degree of `b` is less than that of `a`, returns `1`. - Otherwise, compares `a` and `b` lexicographically, starting at the leading terms. """ @@ -1949,7 +1949,7 @@ cdef inline long nmod_poly_cmp(nmod_poly_t a, nmod_poly_t b): cdef bint nmod_poly_sqrt_check(nmod_poly_t poly): """ - Quick check to see if poly could possibly be a square. + Quick check to see if ``poly`` could possibly be a square. """ # We could use Sage's jacobi_int which is for 32 bits integers rather # than FLINT's n_jacobi which is for longs as the FpT class is crafted @@ -1977,8 +1977,8 @@ def unpickle_FpT_element(K, numer, denom): # elsewhere at some point. cdef int sage_cmp_nmod_poly_t(nmod_poly_t L, nmod_poly_t R): """ - Compare two nmod_poly_t in a Pythonic way, so this returns -1, 0, - or 1, and is consistent. + Compare two ``nmod_poly_t`` in a Pythonic way, so this returns `-1`, `0`, + or `1`, and is consistent. """ cdef int j cdef Py_ssize_t i diff --git a/src/sage/rings/fraction_field_element.pyx b/src/sage/rings/fraction_field_element.pyx index b4d59afbf6d..ca1dedf1803 100644 --- a/src/sage/rings/fraction_field_element.pyx +++ b/src/sage/rings/fraction_field_element.pyx @@ -67,9 +67,9 @@ cdef class FractionFieldElement(FieldElement): Test if :trac:`5451` is fixed:: - sage: A = FiniteField(9,'theta')['t'] - sage: K. = FractionField(A) - sage: f= 2/(t^2+2*t); g =t^9/(t^18 + t^10 + t^2);f+g + sage: A = FiniteField(9,'theta')['t'] # optional - sage.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 (2*t^15 + 2*t^14 + 2*t^13 + 2*t^12 + 2*t^11 + 2*t^10 + 2*t^9 + t^7 + t^6 + t^5 + t^4 + t^3 + t^2 + t + 1)/(t^17 + t^9 + t) Test if :trac:`8671` is fixed:: @@ -102,8 +102,8 @@ cdef class FractionFieldElement(FieldElement): sage: f.numerator() 'hi' - sage: x = var('x') - sage: K((x + 1)/(x^2 + x + 1)) + sage: x = var('x') # optional - sage.symbolic + sage: K((x + 1)/(x^2 + x + 1)) # optional - sage.symbolic (x + 1)/(x^2 + x + 1) sage: K(355/113) 355/113 @@ -130,31 +130,31 @@ cdef class FractionFieldElement(FieldElement): sage: F = ZZ['x,y'].fraction_field() sage: x,y = F.gens() - sage: K = GF(7)['a,b'].fraction_field() - sage: a,b = K.gens() + sage: K = GF(7)['a,b'].fraction_field() # optional - sage.rings.finite_rings + sage: a,b = K.gens() # optional - sage.rings.finite_rings :: - sage: phi = F.hom([a+b, a*b], K) - sage: phi(x+y) # indirect doctest + sage: phi = F.hom([a + b, a*b], K) # optional - sage.rings.finite_rings + sage: phi(x+y) # indirect doctest # optional - sage.rings.finite_rings a*b + a + b :: - sage: (x^2/y)._im_gens_(K, [a+b, a*b]) + sage: (x^2/y)._im_gens_(K, [a + b, a*b]) # optional - sage.rings.finite_rings (a^2 + 2*a*b + b^2)/(a*b) - sage: (x^2/y)._im_gens_(K, [a, a*b]) + sage: (x^2/y)._im_gens_(K, [a, a*b]) # optional - sage.rings.finite_rings a/b :: sage: Zx. = ZZ[] - sage: K. = NumberField(x^2 + 1) - sage: cc = K.hom([-i]) - sage: R. = K[] - sage: F = R.fraction_field() - sage: phi = F.hom([F(b),F(a)], base_map=cc) - sage: phi(i/a) + sage: K. = NumberField(x^2 + 1) # optional - sage.rings.number_field + sage: cc = K.hom([-i]) # optional - sage.rings.number_field + sage: R. = K[] # optional - sage.rings.number_field + sage: F = R.fraction_field() # optional - sage.rings.number_field + sage: phi = F.hom([F(b), F(a)], base_map=cc) # optional - sage.rings.number_field + sage: phi(i/a) # optional - sage.rings.number_field ((-i))/b """ nnum = codomain.coerce(self.__numerator._im_gens_(codomain, im_gens, base_map=base_map)) @@ -221,7 +221,7 @@ cdef class FractionFieldElement(FieldElement): EXAMPLES:: sage: R. = ZZ[] - sage: f = x/y+1; f + sage: f = x/y + 1; f (x + y)/y sage: copy(f) (x + y)/y @@ -236,7 +236,7 @@ cdef class FractionFieldElement(FieldElement): EXAMPLES:: sage: R. = ZZ[] - sage: f = x/y+1; f + sage: f = x/y + 1; f (x + y)/y sage: f.numerator() x + y @@ -250,7 +250,7 @@ cdef class FractionFieldElement(FieldElement): EXAMPLES:: sage: R. = ZZ[] - sage: f = x/y+1; f + sage: f = x/y + 1; f (x + y)/y sage: f.denominator() y @@ -396,10 +396,10 @@ cdef class FractionFieldElement(FieldElement): Check that :trac:`25199` is fixed:: - sage: R.=QQbar[] - sage: hash(R.0)==hash(FractionField(R).0) + sage: R. = QQbar[] # optional - sage.rings.number_field + sage: hash(R.0) == hash(FractionField(R).0) # optional - sage.rings.number_field True - sage: ((x+1)/(x^2+1)).subs({x:1}) + sage: ((x+1)/(x^2+1)).subs({x: 1}) # optional - sage.rings.number_field 1 """ if self.__denominator.is_one(): @@ -438,7 +438,7 @@ cdef class FractionFieldElement(FieldElement): -2*x1*x2 + x0 + x1 sage: f(1,2,5) -17 - sage: h = f /(x[1] + x[2]) + sage: h = f / (x[1] + x[2]) sage: h (-2*x1*x2 + x0 + x1)/(x1 + x2) sage: h(1,2,5) @@ -533,7 +533,7 @@ cdef class FractionFieldElement(FieldElement): EXAMPLES:: sage: R. = ZZ[] - sage: magma((x^2 + x + 1)/(x + 1)) # optional - magma # indirect doctest + sage: magma((x^2 + x + 1)/(x + 1)) # optional - magma # indirect doctest (x^2 + x + 1)/(x + 1) :: @@ -576,8 +576,8 @@ cdef class FractionFieldElement(FieldElement): Subtraction is implemented by adding the negative:: - sage: K. = Frac(GF(7)['t']) - sage: t - 1/t # indirect doctest + sage: K. = Frac(GF(7)['t']) # optional - sage.rings.finite_rings + sage: t - 1/t # indirect doctest # optional - sage.rings.finite_rings (t^2 + 6)/t """ rnum = self.__numerator @@ -649,10 +649,10 @@ cdef class FractionFieldElement(FieldElement): EXAMPLES:: - sage: K. = Frac(GF(7)['t']) - sage: a = t/(1+t) - sage: b = 3/t - sage: a*b # indirect doctest + sage: K. = Frac(GF(7)['t']) # optional - sage.rings.finite_rings + sage: a = t/(1+t) # optional - sage.rings.finite_rings + sage: b = 3/t # optional - sage.rings.finite_rings + sage: a * b # indirect doctest # optional - sage.rings.finite_rings 3/(t + 1) """ rnum = self.__numerator @@ -778,7 +778,7 @@ cdef class FractionFieldElement(FieldElement): TESTS:: sage: K = Frac(ZZ['x']) - sage: QQ(K(x) / K(2*x)) + sage: QQ(K(x) / K(2*x)) # optional - sage.symbolic 1/2 """ return self._conversion(QQ) @@ -814,15 +814,15 @@ cdef class FractionFieldElement(FieldElement): 3/2 sage: x = polygen(QQ) - sage: A. = NumberField(x^3 - 2) - sage: A((x+3) / (2*x - 1)) + sage: A. = NumberField(x^3 - 2) # optional - sage.rings.number_field + sage: A((x+3) / (2*x - 1)) # optional - sage.rings.number_field 14/15*u^2 + 7/15*u + 11/15 - sage: B = A['y'].fraction_field() - sage: A(B(u)) + sage: B = A['y'].fraction_field() # optional - sage.rings.number_field + sage: A(B(u)) # optional - sage.rings.number_field u - sage: C = A['x,y'].fraction_field() - sage: A(C(u)) + sage: C = A['x,y'].fraction_field() # optional - sage.rings.number_field + sage: A(C(u)) # optional - sage.rings.number_field u """ if self.__denominator.is_one(): @@ -900,10 +900,10 @@ cdef class FractionFieldElement(FieldElement): """ EXAMPLES:: - sage: K. = Frac(GF(5)['t']) - sage: f = (t^2+t)/(t+2); f + sage: K. = Frac(GF(5)['t']) # optional - sage.rings.finite_rings + sage: f = (t^2+t)/(t+2); f # optional - sage.rings.finite_rings (t^2 + t)/(t + 2) - sage: -f + sage: -f # optional - sage.rings.finite_rings (4*t^2 + 4*t)/(t + 2) """ return self.__class__(self._parent, @@ -924,9 +924,9 @@ cdef class FractionFieldElement(FieldElement): """ EXAMPLES:: - sage: K. = Frac(GF(7)['t']) - sage: f = (t^2+5)/(t-1) - sage: ~f + sage: K. = Frac(GF(7)['t']) # optional - sage.rings.finite_rings + sage: f = (t^2+5)/(t-1) # optional - sage.rings.finite_rings + sage: ~f # optional - sage.rings.finite_rings (t + 6)/(t^2 + 5) """ if self.is_zero(): @@ -938,12 +938,12 @@ cdef class FractionFieldElement(FieldElement): """ EXAMPLES:: - sage: K. = Frac(GF(7)['t']) - sage: t/t == 1 + sage: K. = Frac(GF(7)['t']) # optional - sage.rings.finite_rings + sage: t/t == 1 # optional - sage.rings.finite_rings True - sage: t+1/t == (t^2+1)/t + sage: t + 1/t == (t^2+1)/t # optional - sage.rings.finite_rings True - sage: t == t/5 + sage: t == t/5 # optional - sage.rings.finite_rings False :: @@ -972,7 +972,7 @@ cdef class FractionFieldElement(FieldElement): (-1/2*x^2 - 1/2)/(x^2 - 1/2*x) sage: f.valuation() -1 - sage: f.valuation(x^2+1) + sage: f.valuation(x^2 + 1) 1 """ return self.__numerator.valuation(v) - self.__denominator.valuation(v) @@ -1042,9 +1042,9 @@ cdef class FractionFieldElement(FieldElement): sage: x,y = F.gens() sage: elt = (2*x + 2*y) / (3*x - 3*y); elt (2*x + 2*y)/(3*x - 3*y) - sage: elt._symbolic_(SR) + sage: elt._symbolic_(SR) # optional - sage.symbolic 2/3*(x + y)/(x - y) - sage: symbolic_expression(elt) + sage: symbolic_expression(elt) # optional - sage.symbolic 2/3*(x + y)/(x - y) """ return ring(self.__numerator)/ring(self.__denominator) @@ -1101,18 +1101,18 @@ cdef class FractionFieldElement(FieldElement): Check that :trac:`25440` has been resolved:: - sage: R. = GF(2)[] - sage: S. = R.fraction_field()[] - sage: (y+1)(R.one()) + sage: R. = GF(2)[] # optional - sage.rings.finite_rings + sage: S. = R.fraction_field()[] # optional - sage.rings.finite_rings + sage: (y+1)(R.one()) # optional - sage.rings.finite_rings 0 Check that inexact elements are treated correctly:: - sage: K=Qp(2,5) - sage: R. = K[] - sage: L = R.fraction_field() - sage: S. = L[] - sage: y(K(1,1)/x) + sage: K = Qp(2, 5) # optional - sage.rings.padics + sage: R. = K[] # optional - sage.rings.padics + sage: L = R.fraction_field() # optional - sage.rings.padics + sage: S. = L[] # optional - sage.rings.padics + sage: y(K(1,1)/x) # optional - sage.rings.padics (1 + O(2))/((1 + O(2))*x) """ if self.numerator().is_one(): @@ -1205,8 +1205,9 @@ cdef class FractionFieldElement_1poly_field(FractionFieldElement): EXAMPLES:: sage: R. = QQ[] - sage: h = (t^14 + 2*t^12 - 4*t^11 - 8*t^9 + 6*t^8 + 12*t^6 - 4*t^5 - 8*t^3 + t^2 + 2)/(t^6 + 6*t^5 + 9*t^4 - 2*t^2 - 12*t - 18) - sage: h.support() + 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 [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()] @@ -1249,7 +1250,7 @@ def make_element(parent, numerator, denominator): sage: R = ZZ['x,y'] sage: x,y = R.gens() sage: F = R.fraction_field() - sage: make_element(F, 1+x, 1+y) + sage: make_element(F, 1 + x, 1 + y) (x + 1)/(y + 1) """ @@ -1265,7 +1266,8 @@ def make_element_old(parent, cdict): sage: from sage.rings.fraction_field_element import make_element_old sage: R. = ZZ[] sage: F = R.fraction_field() - sage: make_element_old(F, {'_FractionFieldElement__numerator':x+y,'_FractionFieldElement__denominator':x-y}) + sage: make_element_old(F, {'_FractionFieldElement__numerator': x + y, + ....: '_FractionFieldElement__denominator': x - y}) (x + y)/(x - y) """ return FractionFieldElement(parent, diff --git a/src/sage/rings/function_field/drinfeld_modules/action.py b/src/sage/rings/function_field/drinfeld_modules/action.py index 32a00f9ea71..cfa9774058a 100644 --- a/src/sage/rings/function_field/drinfeld_modules/action.py +++ b/src/sage/rings/function_field/drinfeld_modules/action.py @@ -1,3 +1,4 @@ +# sage.doctest: optional - sage.rings.finite_rings r""" The module action induced by a Drinfeld module @@ -58,7 +59,8 @@ class DrinfeldModuleAction(Action): sage: phi = DrinfeldModule(A, [z, 0, 0, 1]) sage: action = phi.action() sage: action - Action on Finite Field in z of size 11^2 over its base induced by Drinfeld module defined by T |--> t^3 + z + Action on Finite Field in z of size 11^2 over its base + induced by Drinfeld module defined by T |--> t^3 + z The action on elements is computed as follows:: diff --git a/src/sage/rings/function_field/drinfeld_modules/drinfeld_module.py b/src/sage/rings/function_field/drinfeld_modules/drinfeld_module.py index b50193c1862..23a992f2ce1 100644 --- a/src/sage/rings/function_field/drinfeld_modules/drinfeld_module.py +++ b/src/sage/rings/function_field/drinfeld_modules/drinfeld_module.py @@ -1,3 +1,4 @@ +# sage.doctest: optional - sage.rings.finite_rings r""" Drinfeld modules @@ -171,7 +172,10 @@ class DrinfeldModule(Parent, UniqueRepresentation): sage: phi(T) # phi_T, the generator of the Drinfeld module t^2 + t + z sage: phi(T^3 + T + 1) # phi_(T^3 + T + 1) - t^6 + (z^11 + z^9 + 2*z^6 + 2*z^4 + 2*z + 1)*t^4 + (2*z^11 + 2*z^10 + z^9 + z^8 + 2*z^7 + 2*z^6 + z^5 + 2*z^3)*t^3 + (2*z^11 + z^10 + z^9 + 2*z^7 + 2*z^6 + z^5 + z^4 + 2*z^3 + 2*z + 2)*t^2 + (2*z^11 + 2*z^8 + 2*z^6 + z^5 + z^4 + 2*z^2)*t + z^3 + z + 1 + t^6 + (z^11 + z^9 + 2*z^6 + 2*z^4 + 2*z + 1)*t^4 + + (2*z^11 + 2*z^10 + z^9 + z^8 + 2*z^7 + 2*z^6 + z^5 + 2*z^3)*t^3 + + (2*z^11 + z^10 + z^9 + 2*z^7 + 2*z^6 + z^5 + z^4 + 2*z^3 + 2*z + 2)*t^2 + + (2*z^11 + 2*z^8 + 2*z^6 + z^5 + z^4 + 2*z^2)*t + z^3 + z + 1 sage: phi(1) # phi_1 1 @@ -228,7 +232,8 @@ class DrinfeldModule(Parent, UniqueRepresentation): :: sage: phi.ore_polring() # K{t} - Ore Polynomial Ring in t over Finite Field in z of size 3^12 over its base twisted by Frob^2 + Ore Polynomial Ring in t over Finite Field in z of size 3^12 over its base + twisted by Frob^2 :: @@ -252,7 +257,9 @@ class DrinfeldModule(Parent, UniqueRepresentation): sage: phi.morphism() # The Drinfeld module as a morphism Ring morphism: From: Univariate Polynomial Ring in T over Finite Field in z2 of size 3^2 - To: Ore Polynomial Ring in t over Finite Field in z of size 3^12 over its base twisted by Frob^2 + To: Ore Polynomial Ring in t + over Finite Field in z of size 3^12 over its base + twisted by Frob^2 Defn: T |--> t^2 + t + z One can compute the rank and height:: @@ -353,7 +360,8 @@ class DrinfeldModule(Parent, UniqueRepresentation): sage: P = (2*z^6 + z^3 + 2*z^2 + z + 2)*t + z^11 + 2*z^10 + 2*z^9 + 2*z^8 + z^7 + 2*z^6 + z^5 + z^3 + z^2 + z sage: psi = phi.velu(P) sage: psi - Drinfeld module defined by T |--> (2*z^11 + 2*z^9 + z^6 + 2*z^5 + 2*z^4 + 2*z^2 + 1)*t^2 + (2*z^11 + 2*z^10 + 2*z^9 + z^8 + 2*z^7 + 2*z^6 + z^5 + 2*z^4 + 2*z^2 + 2*z)*t + z + Drinfeld module defined by T |--> (2*z^11 + 2*z^9 + z^6 + 2*z^5 + 2*z^4 + 2*z^2 + 1)*t^2 + + (2*z^11 + 2*z^10 + 2*z^9 + z^8 + 2*z^7 + 2*z^6 + z^5 + 2*z^4 + 2*z^2 + 2*z)*t + z sage: P in Hom(phi, psi) True sage: P * phi(T) == psi(T) * P @@ -385,7 +393,8 @@ class DrinfeldModule(Parent, UniqueRepresentation): sage: action = phi.action() sage: action - Action on Finite Field in z of size 3^12 over its base induced by Drinfeld module defined by T |--> t^2 + t + z + Action on Finite Field in z of size 3^12 over its base + induced by Drinfeld module defined by T |--> t^2 + t + z The action on elements is computed by calling the action object:: @@ -867,7 +876,9 @@ def action(self): sage: phi = DrinfeldModule(A, [p_root, z12^3, z12^5]) sage: action = phi.action() sage: action - Action on Finite Field in z12 of size 5^12 over its base induced by Drinfeld module defined by T |--> z12^5*t^2 + z12^3*t + 2*z12^11 + 2*z12^10 + z12^9 + 3*z12^8 + z12^7 + 2*z12^5 + 2*z12^4 + 3*z12^3 + z12^2 + 2*z12 + Action on Finite Field in z12 of size 5^12 over its base + induced by Drinfeld module defined by T |--> z12^5*t^2 + z12^3*t + 2*z12^11 + + 2*z12^10 + z12^9 + 3*z12^8 + z12^7 + 2*z12^5 + 2*z12^4 + 3*z12^3 + z12^2 + 2*z12 The action on elements is computed as follows:: @@ -901,7 +912,8 @@ def coefficient(self, n): sage: p_root = 2*z12^11 + 2*z12^10 + z12^9 + 3*z12^8 + z12^7 + 2*z12^5 + 2*z12^4 + 3*z12^3 + z12^2 + 2*z12 sage: phi = DrinfeldModule(A, [p_root, z12^3, z12^5]) sage: phi.coefficient(0) - 2*z12^11 + 2*z12^10 + z12^9 + 3*z12^8 + z12^7 + 2*z12^5 + 2*z12^4 + 3*z12^3 + z12^2 + 2*z12 + 2*z12^11 + 2*z12^10 + z12^9 + 3*z12^8 + z12^7 + 2*z12^5 + + 2*z12^4 + 3*z12^3 + z12^2 + 2*z12 sage: phi.coefficient(0) == p_root True sage: phi.coefficient(1) @@ -938,7 +950,8 @@ def coefficients(self, sparse=True): sage: p_root = 2*z12^11 + 2*z12^10 + z12^9 + 3*z12^8 + z12^7 + 2*z12^5 + 2*z12^4 + 3*z12^3 + z12^2 + 2*z12 sage: phi = DrinfeldModule(A, [p_root, z12^3, z12^5]) sage: phi.coefficients() - [2*z12^11 + 2*z12^10 + z12^9 + 3*z12^8 + z12^7 + 2*z12^5 + 2*z12^4 + 3*z12^3 + z12^2 + 2*z12, + [2*z12^11 + 2*z12^10 + z12^9 + 3*z12^8 + z12^7 + + 2*z12^5 + 2*z12^4 + 3*z12^3 + z12^2 + 2*z12, z12^3, z12^5] @@ -947,10 +960,12 @@ def coefficients(self, sparse=True): sage: rho = DrinfeldModule(A, [p_root, 0, 0, 0, 1]) sage: rho.coefficients() - [2*z12^11 + 2*z12^10 + z12^9 + 3*z12^8 + z12^7 + 2*z12^5 + 2*z12^4 + 3*z12^3 + z12^2 + 2*z12, + [2*z12^11 + 2*z12^10 + z12^9 + 3*z12^8 + z12^7 + + 2*z12^5 + 2*z12^4 + 3*z12^3 + z12^2 + 2*z12, 1] sage: rho.coefficients(sparse=False) - [2*z12^11 + 2*z12^10 + z12^9 + 3*z12^8 + z12^7 + 2*z12^5 + 2*z12^4 + 3*z12^3 + z12^2 + 2*z12, + [2*z12^11 + 2*z12^10 + z12^9 + 3*z12^8 + z12^7 + + 2*z12^5 + 2*z12^4 + 3*z12^3 + z12^2 + 2*z12, 0, 0, 0, @@ -1120,8 +1135,10 @@ def morphism(self): sage: phi.morphism() Ring morphism: From: Univariate Polynomial Ring in T over Finite Field in z2 of size 5^2 - To: Ore Polynomial Ring in t over Finite Field in z12 of size 5^12 over its base twisted by Frob^2 - Defn: T |--> z12^5*t^2 + z12^3*t + 2*z12^11 + 2*z12^10 + z12^9 + 3*z12^8 + z12^7 + 2*z12^5 + 2*z12^4 + 3*z12^3 + z12^2 + 2*z12 + To: Ore Polynomial Ring in t over Finite Field in z12 of size 5^12 + over its base twisted by Frob^2 + Defn: T |--> z12^5*t^2 + z12^3*t + 2*z12^11 + 2*z12^10 + z12^9 + 3*z12^8 + + z12^7 + 2*z12^5 + 2*z12^4 + 3*z12^3 + z12^2 + 2*z12 sage: from sage.rings.morphism import RingHomomorphism sage: isinstance(phi.morphism(), RingHomomorphism) True @@ -1144,7 +1161,8 @@ class the ``__call__`` method of this morphism:: sage: m.codomain() is phi.ore_polring() True sage: m.im_gens() - [z12^5*t^2 + z12^3*t + 2*z12^11 + 2*z12^10 + z12^9 + 3*z12^8 + z12^7 + 2*z12^5 + 2*z12^4 + 3*z12^3 + z12^2 + 2*z12] + [z12^5*t^2 + z12^3*t + 2*z12^11 + 2*z12^10 + z12^9 + 3*z12^8 + + z12^7 + 2*z12^5 + 2*z12^4 + 3*z12^3 + z12^2 + 2*z12] sage: phi(T) == m.im_gens()[0] True """ @@ -1220,7 +1238,10 @@ def velu(self, isog): sage: isog = t + 2*z12^11 + 4*z12^9 + 2*z12^8 + 2*z12^6 + 3*z12^5 + z12^4 + 2*z12^3 + 4*z12^2 + 4*z12 + 4 sage: psi = phi.velu(isog) sage: psi - Drinfeld module defined by T |--> (z12^11 + 3*z12^10 + z12^9 + z12^7 + z12^5 + 4*z12^4 + 4*z12^3 + z12^2 + 1)*t^2 + (2*z12^11 + 4*z12^10 + 2*z12^8 + z12^6 + 3*z12^5 + z12^4 + 2*z12^3 + z12^2 + z12 + 4)*t + 2*z12^11 + 2*z12^10 + z12^9 + 3*z12^8 + z12^7 + 2*z12^5 + 2*z12^4 + 3*z12^3 + z12^2 + 2*z12 + Drinfeld module defined by T |--> + (z12^11 + 3*z12^10 + z12^9 + z12^7 + z12^5 + 4*z12^4 + 4*z12^3 + z12^2 + 1)*t^2 + + (2*z12^11 + 4*z12^10 + 2*z12^8 + z12^6 + 3*z12^5 + z12^4 + 2*z12^3 + z12^2 + z12 + 4)*t + + 2*z12^11 + 2*z12^10 + z12^9 + 3*z12^8 + z12^7 + 2*z12^5 + 2*z12^4 + 3*z12^3 + z12^2 + 2*z12 sage: isog in Hom(phi, psi) True diff --git a/src/sage/rings/function_field/drinfeld_modules/finite_drinfeld_module.py b/src/sage/rings/function_field/drinfeld_modules/finite_drinfeld_module.py index 6cc78a53fb4..9d468dba511 100644 --- a/src/sage/rings/function_field/drinfeld_modules/finite_drinfeld_module.py +++ b/src/sage/rings/function_field/drinfeld_modules/finite_drinfeld_module.py @@ -1,3 +1,4 @@ +# sage.doctest: optional - sage.rings.finite_rings r""" Finite Drinfeld modules @@ -221,7 +222,8 @@ def frobenius_charpoly(self, var='X'): sage: phi = DrinfeldModule(A, [1, 0, z6]) sage: chi = phi.frobenius_charpoly() sage: chi - X^2 + ((3*z3^2 + z3 + 4)*T + 4*z3^2 + 6*z3 + 3)*X + (5*z3^2 + 2*z3)*T^2 + (4*z3^2 + 3*z3)*T + 5*z3^2 + 2*z3 + X^2 + ((3*z3^2 + z3 + 4)*T + 4*z3^2 + 6*z3 + 3)*X + + (5*z3^2 + 2*z3)*T^2 + (4*z3^2 + 3*z3)*T + 5*z3^2 + 2*z3 :: diff --git a/src/sage/rings/function_field/drinfeld_modules/homset.py b/src/sage/rings/function_field/drinfeld_modules/homset.py index 84fdc4c6e14..c4f43db19da 100644 --- a/src/sage/rings/function_field/drinfeld_modules/homset.py +++ b/src/sage/rings/function_field/drinfeld_modules/homset.py @@ -1,3 +1,4 @@ +# sage.doctest: optional - sage.rings.finite_rings r""" Set of morphisms between two Drinfeld modules @@ -46,7 +47,9 @@ class DrinfeldModuleHomset(Homset): sage: psi = DrinfeldModule(A, [z6, 2*z6^5 + 2*z6^4 + 2*z6 + 1, 2]) sage: H = Hom(phi, psi) sage: H - Set of Drinfeld module morphisms from (gen) 2*t^2 + z6*t + z6 to (gen) 2*t^2 + (2*z6^5 + 2*z6^4 + 2*z6 + 1)*t + z6 + Set of Drinfeld module morphisms + from (gen) 2*t^2 + z6*t + z6 + to (gen) 2*t^2 + (2*z6^5 + 2*z6^4 + 2*z6 + 1)*t + z6 :: diff --git a/src/sage/rings/function_field/drinfeld_modules/morphism.py b/src/sage/rings/function_field/drinfeld_modules/morphism.py index dab86c43efa..2d5414095f5 100644 --- a/src/sage/rings/function_field/drinfeld_modules/morphism.py +++ b/src/sage/rings/function_field/drinfeld_modules/morphism.py @@ -1,3 +1,4 @@ +# sage.doctest: optional - sage.rings.finite_rings r""" Drinfeld module morphisms diff --git a/src/sage/rings/function_field/element_polymod.pyx b/src/sage/rings/function_field/element_polymod.pyx index 2c858f8568c..2d6a0100185 100644 --- a/src/sage/rings/function_field/element_polymod.pyx +++ b/src/sage/rings/function_field/element_polymod.pyx @@ -76,7 +76,7 @@ cdef class FunctionFieldElement_polymod(FunctionFieldElement): def __bool__(self): """ - Return True if the element is not zero. + Return ``True`` if the element is not zero. EXAMPLES:: diff --git a/src/sage/rings/function_field/element_rational.pyx b/src/sage/rings/function_field/element_rational.pyx index 1ff227e5d27..7bbb8f809b5 100644 --- a/src/sage/rings/function_field/element_rational.pyx +++ b/src/sage/rings/function_field/element_rational.pyx @@ -106,7 +106,7 @@ cdef class FunctionFieldElement_rational(FunctionFieldElement): def __bool__(self): """ - Return True if the element is not zero. + Return ``True`` if the element is not zero. EXAMPLES:: diff --git a/src/sage/rings/homset.py b/src/sage/rings/homset.py index 6f7a2d4b415..77fa3323bc0 100644 --- a/src/sage/rings/homset.py +++ b/src/sage/rings/homset.py @@ -133,25 +133,26 @@ def _element_constructor_(self, x, check=True, base_map=None): You can provide a morphism on the base:: - sage: k = GF(9) - sage: z2 = k.gen() - sage: cc = k.frobenius_endomorphism() - sage: R. = k[] - sage: H = Hom(R, R) - sage: phi = H([x^2], base_map=cc); phi - Ring endomorphism of Univariate Polynomial Ring in x over Finite Field in z2 of size 3^2 + sage: k = GF(9) # optional - sage.rings.finite_rings + sage: z2 = k.gen() # optional - sage.rings.finite_rings + sage: cc = k.frobenius_endomorphism() # optional - sage.rings.finite_rings + sage: R. = k[] # optional - sage.rings.finite_rings + sage: H = Hom(R, R) # optional - sage.rings.finite_rings + sage: phi = H([x^2], base_map=cc); phi # optional - sage.rings.finite_rings + Ring endomorphism of Univariate Polynomial Ring in x + over Finite Field in z2 of size 3^2 Defn: x |--> x^2 with map of base ring - sage: phi(z2*x) == z2^3 * x^2 + sage: phi(z2 * x) == z2^3 * x^2 # optional - sage.rings.finite_rings True sage: R. = ZZ[] - sage: K. = GF(7^2) - sage: L. = K.extension(x^3 - 3) - sage: phi = L.hom([u^7], base_map=K.frobenius_endomorphism()) - sage: phi(u) == u^7 + sage: K. = GF(7^2) # optional - sage.rings.finite_rings + sage: L. = K.extension(x^3 - 3) # optional - sage.rings.finite_rings + sage: phi = L.hom([u^7], base_map=K.frobenius_endomorphism()) # optional - sage.rings.finite_rings + sage: phi(u) == u^7 # optional - sage.rings.finite_rings True - sage: phi(a) == a^7 + sage: phi(a) == a^7 # optional - sage.rings.finite_rings True TESTS:: @@ -247,14 +248,15 @@ class RingHomset_quo_ring(RingHomset_generic): EXAMPLES:: sage: R. = PolynomialRing(QQ, 2) - sage: S. = R.quotient(x^2 + y^2) - sage: phi = S.hom([b,a]); phi - Ring endomorphism of Quotient of Multivariate Polynomial Ring in x, y over Rational Field by the ideal (x^2 + y^2) + sage: S. = R.quotient(x^2 + y^2) # optional - sage.libs.singular + sage: phi = S.hom([b,a]); phi # optional - sage.libs.singular + Ring endomorphism of Quotient of Multivariate Polynomial Ring in x, y + over Rational Field by the ideal (x^2 + y^2) Defn: a |--> b b |--> a - sage: phi(a) + sage: phi(a) # optional - sage.libs.singular b - sage: phi(b) + sage: phi(b) # optional - sage.libs.singular a TESTS: @@ -264,15 +266,15 @@ class RingHomset_quo_ring(RingHomset_generic): :: sage: R. = PolynomialRing(QQ, 2) - sage: S. = R.quotient(x^2 + y^2) - sage: H = S.Hom(R) - sage: H == loads(dumps(H)) + sage: S. = R.quotient(x^2 + y^2) # optional - sage.libs.singular + sage: H = S.Hom(R) # optional - sage.libs.singular + sage: H == loads(dumps(H)) # optional - sage.libs.singular True We test pickling of actual homomorphisms in a quotient:: - sage: phi = S.hom([b,a]) - sage: phi == loads(dumps(phi)) + sage: phi = S.hom([b,a]) # optional - sage.libs.singular + sage: phi == loads(dumps(phi)) # optional - sage.libs.singular True """ @@ -285,17 +287,17 @@ def _element_constructor_(self, x, base_map=None, check=True): EXAMPLES:: sage: R. = PolynomialRing(QQ, 2) - sage: S. = R.quotient(x^2 + y^2) - sage: H = S.Hom(R) - sage: phi = H([b, a]); phi + sage: S. = R.quotient(x^2 + y^2) # optional - sage.libs.singular + sage: H = S.Hom(R) # optional - sage.libs.singular + sage: phi = H([b, a]); phi # optional - sage.libs.singular Ring morphism: From: Quotient of Multivariate Polynomial Ring in x, y over Rational Field by the ideal (x^2 + y^2) To: Multivariate Polynomial Ring in x, y over Rational Field Defn: a |--> b b |--> a sage: R2. = PolynomialRing(ZZ, 2) - sage: H2 = Hom(R2, S) - sage: H2(phi) + sage: H2 = Hom(R2, S) # optional - sage.libs.singular + sage: H2(phi) # optional - sage.libs.singular Composite map: From: Multivariate Polynomial Ring in x, y over Integer Ring To: Quotient of Multivariate Polynomial Ring in x, y over Rational Field by the ideal (x^2 + y^2) diff --git a/src/sage/rings/ideal.py b/src/sage/rings/ideal.py index 8c51c69a9ae..bf557adc1a1 100644 --- a/src/sage/rings/ideal.py +++ b/src/sage/rings/ideal.py @@ -125,9 +125,9 @@ def Ideal(*args, **kwds): Note that some rings use different ideal implementations than the standard, even if they are PIDs.:: - sage: R. = GF(5)[] - sage: I = R*(x^2+3) - sage: type(I) + sage: R. = GF(5)[] # optional - sage.rings.finite_rings + sage: I = R * (x^2 + 3) # optional - sage.rings.finite_rings + sage: type(I) # optional - sage.rings.finite_rings You can also pass in a specific ideal type:: @@ -163,11 +163,11 @@ def Ideal(*args, **kwds): sage: J = R.ideal([2*x + 2*x^2]) sage: J Principal ideal (x^2 + x) of Univariate Polynomial Ring in x over Rational Field - sage: S = R.quotient_ring(I) - sage: U = R.quotient_ring(J) + sage: S = R.quotient_ring(I) # optional - sage.libs.pari + sage: U = R.quotient_ring(J) # optional - sage.libs.pari sage: I == J True - sage: S == U + sage: S == U # optional - sage.libs.pari True """ if len(args) == 0: @@ -295,8 +295,8 @@ def _repr_short(self): the generators are not represented from left to right but from top to bottom. This is the case, e.g., for matrices:: - sage: MS = MatrixSpace(QQ,2,2) - sage: MS*[MS.1,2] + sage: MS = MatrixSpace(QQ, 2, 2) # optional - sage.modules + sage: MS * [MS.1, 2] # optional - sage.modules Left Ideal ( [0 1] @@ -337,9 +337,9 @@ def random_element(self, *args, **kwds): EXAMPLES:: - sage: P. = GF(5)[[]] - sage: I = P.ideal([a^2, a*b + c, c^3]) - sage: I.random_element() # random + sage: P. = GF(5)[[]] # optional - sage.rings.finite_rings + sage: I = P.ideal([a^2, a*b + c, c^3]) # optional - sage.rings.finite_rings + sage: I.random_element() # random # optional - sage.rings.finite_rings 2*a^5*c + a^2*b*c^4 + ... + O(a, b, c)^13 """ @@ -376,11 +376,11 @@ def __contains__(self, x): EXAMPLES:: sage: P. = QQ[] - sage: I = P*[a, b] - sage: a + b in I + sage: I = P * [a, b] + sage: a + b in I # optional - sage.libs.singular True sage: P2. = QQ[] - sage: x + 2*y + w*z in I + sage: x + 2*y + w*z in I # optional - sage.libs.singular False """ try: @@ -470,11 +470,11 @@ def base_ring(self): And `p`-adic numbers:: - sage: R = Zp(7, prec=10); R + sage: R = Zp(7, prec=10); R # optional - sage.rings.padics 7-adic Ring with capped relative precision 10 - sage: I = 7*R; I + sage: I = 7*R; I # optional - sage.rings.padics Principal ideal (7 + O(7^11)) of 7-adic Ring with capped relative precision 10 - sage: I.base_ring() + sage: I.base_ring() # optional - sage.rings.padics 7-adic Ring with capped relative precision 10 """ return self.ring().base_ring() @@ -488,11 +488,14 @@ def apply_morphism(self, phi): sage: psi = CC['x'].hom([-CC['x'].0]) sage: J = ideal([CC['x'].0 + 1]); J - Principal ideal (x + 1.00000000000000) of Univariate Polynomial Ring in x over Complex Field with 53 bits of precision + Principal ideal (x + 1.00000000000000) of Univariate Polynomial Ring in x + over Complex Field with 53 bits of precision sage: psi(J) - Principal ideal (x - 1.00000000000000) of Univariate Polynomial Ring in x over Complex Field with 53 bits of precision + Principal ideal (x - 1.00000000000000) of Univariate Polynomial Ring in x + over Complex Field with 53 bits of precision sage: J.apply_morphism(psi) - Principal ideal (x - 1.00000000000000) of Univariate Polynomial Ring in x over Complex Field with 53 bits of precision + Principal ideal (x - 1.00000000000000) of Univariate Polynomial Ring in x + over Complex Field with 53 bits of precision :: @@ -585,12 +588,14 @@ def ring(self): sage: I = R.ideal(x^2 - 3) sage: I.ring() Univariate Polynomial Ring in x over Rational Field - sage: Rbar = R.quotient(I, names='a') - sage: S = PolynomialRing(Rbar, 'y'); y = Rbar.gen(); S - Univariate Polynomial Ring in y over Univariate Quotient Polynomial Ring in a over Rational Field with modulus x^2 - 3 - sage: J = S.ideal(y^2 + 1) - sage: J.ring() - Univariate Polynomial Ring in y over Univariate Quotient Polynomial Ring in a over Rational Field with modulus x^2 - 3 + sage: Rbar = R.quotient(I, names='a') # optional - sage.libs.pari + sage: S = PolynomialRing(Rbar, 'y'); y = Rbar.gen(); S # optional - sage.libs.pari + Univariate Polynomial Ring in y over + Univariate Quotient Polynomial Ring in a over Rational Field with modulus x^2 - 3 + sage: J = S.ideal(y^2 + 1) # optional - sage.libs.pari + sage: J.ring() # optional - sage.libs.pari + Univariate Polynomial Ring in y over + Univariate Quotient Polynomial Ring in a over Rational Field with modulus x^2 - 3 """ return self.__ring @@ -693,16 +698,16 @@ def is_maximal(self): sage: R = ZZ sage: I = R.ideal(7) - sage: I.is_maximal() + sage: I.is_maximal() # optional - sage.libs.pari True - sage: R.ideal(16).is_maximal() + sage: R.ideal(16).is_maximal() # optional - sage.libs.pari False sage: S = Integers(8) - sage: S.ideal(0).is_maximal() + sage: S.ideal(0).is_maximal() # optional - sage.libs.pari False - sage: S.ideal(2).is_maximal() + sage: S.ideal(2).is_maximal() # optional - sage.libs.pari True - sage: S.ideal(4).is_maximal() + sage: S.ideal(4).is_maximal() # optional - sage.libs.pari False """ from sage.rings.integer_ring import ZZ @@ -738,28 +743,28 @@ def is_primary(self, P=None): sage: R. = QQ[] sage: I = R.ideal([x^2, x*y]) - sage: I.is_primary() + sage: I.is_primary() # optional - sage.libs.singular False - sage: J = I.primary_decomposition()[1]; J + sage: J = I.primary_decomposition()[1]; J # optional - sage.libs.singular Ideal (y, x^2) of Multivariate Polynomial Ring in x, y over Rational Field - sage: J.is_primary() + sage: J.is_primary() # optional - sage.libs.singular True - sage: J.is_prime() + sage: J.is_prime() # optional - sage.libs.singular False Some examples from the Macaulay2 documentation:: - sage: R. = GF(101)[] - sage: I = R.ideal([y^6]) - sage: I.is_primary() + sage: R. = GF(101)[] # optional - sage.rings.finite_rings + sage: I = R.ideal([y^6]) # optional - sage.rings.finite_rings + sage: I.is_primary() # optional - sage.libs.singular sage.rings.finite_rings True - sage: I.is_primary(R.ideal([y])) + sage: I.is_primary(R.ideal([y])) # optional - sage.libs.singular sage.rings.finite_rings True - sage: I = R.ideal([x^4, y^7]) - sage: I.is_primary() + sage: I = R.ideal([x^4, y^7]) # optional - sage.libs.singular sage.rings.finite_rings + sage: I.is_primary() # optional - sage.libs.singular sage.rings.finite_rings True - sage: I = R.ideal([x*y, y^2]) - sage: I.is_primary() + sage: I = R.ideal([x*y, y^2]) # optional - sage.libs.singular sage.rings.finite_rings + sage: I.is_primary() # optional - sage.libs.singular sage.rings.finite_rings False .. NOTE:: @@ -798,24 +803,24 @@ def is_prime(self): sage: R. = QQ[] sage: I = R.ideal([x, y]) - sage: I.is_prime() # a maximal ideal + sage: I.is_prime() # a maximal ideal # optional - sage.libs.singular True - sage: I = R.ideal([x^2-y]) - sage: I.is_prime() # a non-maximal prime ideal + sage: I = R.ideal([x^2 - y]) + sage: I.is_prime() # a non-maximal prime ideal # optional - sage.libs.singular True sage: I = R.ideal([x^2, y]) - sage: I.is_prime() # a non-prime primary ideal + sage: I.is_prime() # a non-prime primary ideal # optional - sage.libs.singular False sage: I = R.ideal([x^2, x*y]) - sage: I.is_prime() # a non-prime non-primary ideal + sage: I.is_prime() # a non-prime non-primary ideal # optional - sage.libs.singular False sage: S = Integers(8) - sage: S.ideal(0).is_prime() + sage: S.ideal(0).is_prime() # optional - sage.libs.singular False - sage: S.ideal(2).is_prime() + sage: S.ideal(2).is_prime() # optional - sage.libs.singular True - sage: S.ideal(4).is_prime() + sage: S.ideal(4).is_prime() # optional - sage.libs.singular False Note that this method is not implemented for all rings where it @@ -886,7 +891,7 @@ def embedded_primes(self): sage: R. = QQ[] sage: I = R.ideal(x^2, x*y) - sage: I.embedded_primes() + sage: I.embedded_primes() # optional - sage.libs.singular [Ideal (y, x) of Multivariate Polynomial Ring in x, y over Rational Field] """ # by definition, embedded primes are associated primes that @@ -915,13 +920,13 @@ def is_principal(self): EXAMPLES:: - sage: R = ZZ['x'] - sage: I = R.ideal(2,x) + sage: R. = ZZ[] + sage: I = R.ideal(2, x) sage: I.is_principal() Traceback (most recent call last): ... NotImplementedError - sage: J = R.base_extend(QQ).ideal(2,x) + sage: J = R.base_extend(QQ).ideal(2, x) sage: J.is_principal() True """ @@ -954,7 +959,7 @@ def is_trivial(self): :: sage: I = QQ['x', 'y'].ideal(-5) - sage: I.is_trivial() + sage: I.is_trivial() # optional - sage.libs.singular True :: @@ -967,7 +972,7 @@ def is_trivial(self): sage: R = QQ['x', 'y'] sage: I = R.ideal(R.gens()) - sage: I.is_trivial() + sage: I.is_trivial() # optional - sage.libs.singular False """ return self.is_zero() or self == self.ring().unit_ideal() @@ -1112,10 +1117,11 @@ def norm(self): EXAMPLES:: - sage: R. = GF(8, names='a')[] - sage: I = R.ideal(t^4 + t + 1) - sage: I.norm() - Principal ideal (t^4 + t + 1) of Univariate Polynomial Ring in t over Finite Field in a of size 2^3 + sage: R. = GF(8, names='a')[] # optional - sage.rings.finite_rings + sage: I = R.ideal(t^4 + t + 1) # optional - sage.rings.finite_rings + sage: I.norm() # optional - sage.rings.finite_rings + Principal ideal (t^4 + t + 1) of Univariate Polynomial Ring in t + over Finite Field in a of size 2^3 """ return self @@ -1135,9 +1141,9 @@ def absolute_norm(self): EXAMPLES:: - sage: R. = GF(9, names='a')[] - sage: I = R.ideal(t^4 + t + 1) - sage: I.absolute_norm() + sage: R. = GF(9, names='a')[] # optional - sage.rings.finite_rings + sage: I = R.ideal(t^4 + t + 1) # optional - sage.rings.finite_rings + sage: I.absolute_norm() # optional - sage.rings.finite_rings Traceback (most recent call last): ... NotImplementedError @@ -1155,7 +1161,7 @@ def _macaulay2_init_(self, macaulay2=None): sage: R. = PolynomialRing(ZZ, 4) sage: I = R.ideal([x*y-z^2, y^2-w^2]); I Ideal (x*y - z^2, y^2 - w^2) of Multivariate Polynomial Ring in x, y, z, w over Integer Ring - sage: macaulay2(I) # optional - macaulay2 + sage: macaulay2(I) # optional - macaulay2 2 2 2 ideal (x*y - z , y - w ) @@ -1164,28 +1170,28 @@ def _macaulay2_init_(self, macaulay2=None): sage: R. = PolynomialRing(ZZ) sage: I = R.ideal([4 + 3*x + x^2, 1 + x^2]); I Ideal (x^2 + 3*x + 4, x^2 + 1) of Univariate Polynomial Ring in x over Integer Ring - sage: macaulay2(I) # optional - macaulay2 + sage: macaulay2(I) # optional - macaulay2 2 2 ideal (x + 3x + 4, x + 1) Field ideals generated from the polynomial ring over two variables in the finite field of size 2:: - sage: P. = PolynomialRing(GF(2), 2) - sage: I = sage.rings.ideal.FieldIdeal(P); I - Ideal (x^2 + x, y^2 + y) of Multivariate Polynomial Ring in x, y over - Finite Field of size 2 - sage: macaulay2(I) # optional - macaulay2 + sage: P. = PolynomialRing(GF(2), 2) # optional - sage.rings.finite_rings + sage: I = sage.rings.ideal.FieldIdeal(P); I # optional - sage.rings.finite_rings + Ideal (x^2 + x, y^2 + y) of Multivariate Polynomial Ring in x, y + over Finite Field of size 2 + sage: macaulay2(I) # optional - macaulay2 # optional - sage.rings.finite_rings 2 2 ideal (x + x, y + y) Ideals in PIDs:: - sage: macaulay2(ideal(5)) # optional - macaulay2 + sage: macaulay2(ideal(5)) # optional - macaulay2 ideal 5 sage: J = ideal(QQ(5)) ... - sage: macaulay2(J) # optional - macaulay2 + sage: macaulay2(J) # optional - macaulay2 ideal 1 TESTS: @@ -1222,7 +1228,7 @@ def free_resolution(self, *args, **kwds): sage: R. = PolynomialRing(QQ) sage: I = R.ideal([x^4 + 3*x^2 + 2]) - sage: I.free_resolution() + sage: I.free_resolution() # optional - sage.modules S^1 <-- S^1 <-- 0 """ if not self.is_principal(): @@ -1241,7 +1247,7 @@ def graded_free_resolution(self, *args, **kwds): sage: R. = PolynomialRing(QQ) sage: I = R.ideal([x^3]) - sage: I.graded_free_resolution() + sage: I.graded_free_resolution() # optional - sage.modules S(0) <-- S(-3) <-- 0 """ from sage.homology.graded_resolution import GradedFiniteFreeResolution_free_module @@ -1568,18 +1574,18 @@ def is_prime(self): EXAMPLES:: - sage: ZZ.ideal(2).is_prime() + sage: ZZ.ideal(2).is_prime() # optional - sage.libs.pari True - sage: ZZ.ideal(-2).is_prime() + sage: ZZ.ideal(-2).is_prime() # optional - sage.libs.pari True - sage: ZZ.ideal(4).is_prime() + sage: ZZ.ideal(4).is_prime() # optional - sage.libs.pari False - sage: ZZ.ideal(0).is_prime() + sage: ZZ.ideal(0).is_prime() # optional - sage.libs.pari True sage: R. = QQ[] - sage: P = R.ideal(x^2+1); P + sage: P = R.ideal(x^2 + 1); P # optional - sage.libs.pari Principal ideal (x^2 + 1) of Univariate Polynomial Ring in x over Rational Field - sage: P.is_prime() + sage: P.is_prime() # optional - sage.libs.pari True In fields, only the zero ideal is prime:: @@ -1609,18 +1615,18 @@ def is_maximal(self): EXAMPLES:: - sage: R. = GF(5)[] - sage: p = R.ideal(t^2 + 2) - sage: p.is_maximal() + sage: R. = GF(5)[] # optional - sage.rings.finite_rings + sage: p = R.ideal(t^2 + 2) # optional - sage.rings.finite_rings + sage: p.is_maximal() # optional - sage.rings.finite_rings True - sage: p = R.ideal(t^2 + 1) - sage: p.is_maximal() + sage: p = R.ideal(t^2 + 1) # optional - sage.rings.finite_rings + sage: p.is_maximal() # optional - sage.rings.finite_rings False - sage: p = R.ideal(0) - sage: p.is_maximal() + sage: p = R.ideal(0) # optional - sage.rings.finite_rings + sage: p.is_maximal() # optional - sage.rings.finite_rings False - sage: p = R.ideal(1) - sage: p.is_maximal() + sage: p = R.ideal(1) # optional - sage.rings.finite_rings + sage: p.is_maximal() # optional - sage.rings.finite_rings False """ if not self.ring().is_field() and self.is_zero(): @@ -1640,41 +1646,41 @@ def residue_field(self): sage: P = ZZ.ideal(61); P Principal ideal (61) of Integer Ring - sage: F = P.residue_field(); F + sage: F = P.residue_field(); F # optional - sage.libs.pari Residue field of Integers modulo 61 - sage: pi = F.reduction_map(); pi + sage: pi = F.reduction_map(); pi # optional - sage.libs.pari Partially defined reduction map: From: Rational Field To: Residue field of Integers modulo 61 - sage: pi(123/234) + sage: pi(123/234) # optional - sage.libs.pari 6 - sage: pi(1/61) + sage: pi(1/61) # optional - sage.libs.pari Traceback (most recent call last): ... ZeroDivisionError: Cannot reduce rational 1/61 modulo 61: it has negative valuation - sage: lift = F.lift_map(); lift + sage: lift = F.lift_map(); lift # optional - sage.libs.pari Lifting map: From: Residue field of Integers modulo 61 To: Integer Ring - sage: lift(F(12345/67890)) + sage: lift(F(12345/67890)) # optional - sage.libs.pari 33 sage: (12345/67890) % 61 33 TESTS:: - sage: ZZ.ideal(96).residue_field() + sage: ZZ.ideal(96).residue_field() # optional - sage.libs.pari Traceback (most recent call last): ... ValueError: The ideal (Principal ideal (96) of Integer Ring) is not prime :: - sage: R.=QQ[] - sage: I=R.ideal(x^2+1) - sage: I.is_prime() + sage: R. = QQ[] + sage: I = R.ideal(x^2 + 1) + sage: I.is_prime() # optional - sage.libs.pari True - sage: I.residue_field() + sage: I.residue_field() # optional - sage.libs.pari Traceback (most recent call last): ... TypeError: residue fields only supported for polynomial rings over finite fields. @@ -1699,8 +1705,8 @@ def __repr__(self): EXAMPLES:: sage: from sage.rings.ideal import Ideal_fractional - sage: K. = NumberField(x^2 + 1) - sage: Ideal_fractional(K, [a]) # indirect doctest + sage: K. = NumberField(x^2 + 1) # optional - sage.rings.number_field + sage: Ideal_fractional(K, [a]) # indirect doctest # optional - sage.rings.number_field Fractional ideal (a) of Number Field in a with defining polynomial x^2 + 1 """ return "Fractional ideal %s of %s"%(self._repr_short(), self.ring()) @@ -1735,21 +1741,20 @@ def Cyclic(R, n=None, homog=False, singular=None): An example from a multivariate polynomial ring over the rationals:: - sage: P. = PolynomialRing(QQ,3,order='lex') - sage: I = sage.rings.ideal.Cyclic(P) - sage: I - Ideal (x + y + z, x*y + x*z + y*z, x*y*z - 1) of Multivariate Polynomial - Ring in x, y, z over Rational Field - sage: I.groebner_basis() + sage: P. = PolynomialRing(QQ, 3, order='lex') + sage: I = sage.rings.ideal.Cyclic(P); I # optional - sage.libs.singular + Ideal (x + y + z, x*y + x*z + y*z, x*y*z - 1) + of Multivariate Polynomial Ring in x, y, z over Rational Field + sage: I.groebner_basis() # optional - sage.libs.singular [x + y + z, y^2 + y*z + z^2, z^3 - 1] We compute a Groebner basis for cyclic 6, which is a standard benchmark and test ideal:: sage: R. = QQ['x,y,z,t,u,v'] - sage: I = sage.rings.ideal.Cyclic(R,6) - sage: B = I.groebner_basis() - sage: len(B) + sage: I = sage.rings.ideal.Cyclic(R, 6) # optional - sage.libs.singular + sage: B = I.groebner_basis() # optional - sage.libs.singular + sage: len(B) # optional - sage.libs.singular 45 """ from .rational_field import RationalField @@ -1794,15 +1799,15 @@ def Katsura(R, n=None, homog=False, singular=None): EXAMPLES:: - sage: P. = PolynomialRing(QQ,3) - sage: I = sage.rings.ideal.Katsura(P,3); I + sage: P. = PolynomialRing(QQ, 3) + sage: I = sage.rings.ideal.Katsura(P, 3); I # optional - sage.libs.singular Ideal (x + 2*y + 2*z - 1, x^2 + 2*y^2 + 2*z^2 - x, 2*x*y + 2*y*z - y) of Multivariate Polynomial Ring in x, y, z over Rational Field :: - sage: Q. = PolynomialRing(QQ, implementation="singular") - sage: J = sage.rings.ideal.Katsura(Q,1); J + sage: Q. = PolynomialRing(QQ, implementation="singular") # optional - sage.libs.singular + sage: J = sage.rings.ideal.Katsura(Q,1); J # optional - sage.libs.singular Ideal (x - 1) of Multivariate Polynomial Ring in x over Rational Field """ from .rational_field import RationalField @@ -1842,18 +1847,18 @@ def FieldIdeal(R): The field ideal generated from the polynomial ring over two variables in the finite field of size 2:: - sage: P. = PolynomialRing(GF(2),2) - sage: I = sage.rings.ideal.FieldIdeal(P); I - Ideal (x^2 + x, y^2 + y) of Multivariate Polynomial Ring in x, y over - Finite Field of size 2 + sage: P. = PolynomialRing(GF(2), 2) # optional - sage.rings.finite_rings + sage: I = sage.rings.ideal.FieldIdeal(P); I # optional - sage.rings.finite_rings + Ideal (x^2 + x, y^2 + y) of + Multivariate Polynomial Ring in x, y over Finite Field of size 2 Another, similar example:: - sage: Q. = PolynomialRing(GF(2^4,name='alpha'), 4) - sage: J = sage.rings.ideal.FieldIdeal(Q); J + sage: Q. = PolynomialRing(GF(2^4, name='alpha'), 4) # optional - sage.rings.finite_rings + sage: J = sage.rings.ideal.FieldIdeal(Q); J # optional - sage.rings.finite_rings Ideal (x1^16 + x1, x2^16 + x2, x3^16 + x3, x4^16 + x4) of - Multivariate Polynomial Ring in x1, x2, x3, x4 over Finite - Field in alpha of size 2^4 + Multivariate Polynomial Ring in x1, x2, x3, x4 + over Finite Field in alpha of size 2^4 """ q = R.base_ring().order() import sage.rings.infinity diff --git a/src/sage/rings/ideal_monoid.py b/src/sage/rings/ideal_monoid.py index b22b7208f6f..01193661aae 100644 --- a/src/sage/rings/ideal_monoid.py +++ b/src/sage/rings/ideal_monoid.py @@ -3,8 +3,8 @@ WARNING: This is used by some rings that are not commutative! :: - sage: MS = MatrixSpace(QQ,3,3) - sage: type(MS.ideal(MS.one()).parent()) + sage: MS = MatrixSpace(QQ, 3, 3) # optional - sage.modules + sage: type(MS.ideal(MS.one()).parent()) # optional - sage.modules """ @@ -21,7 +21,8 @@ def IdealMonoid(R): EXAMPLES:: sage: R = QQ['x'] - sage: sage.rings.ideal_monoid.IdealMonoid(R) + sage: from sage.rings.ideal_monoid import IdealMonoid + sage: IdealMonoid(R) Monoid of ideals of Univariate Polynomial Ring in x over Rational Field """ return IdealMonoid_c(R) @@ -34,7 +35,8 @@ class IdealMonoid_c(Parent): TESTS:: sage: R = QQ['x'] - sage: M = sage.rings.ideal_monoid.IdealMonoid(R) + sage: from sage.rings.ideal_monoid import IdealMonoid + sage: M = IdealMonoid(R) sage: TestSuite(M).run() Failure in _test_category: ... @@ -51,16 +53,18 @@ def __init__(self, R): TESTS:: - sage: R = QuadraticField(-23, 'a') - sage: M = sage.rings.ideal_monoid.IdealMonoid(R); M # indirect doctest - Monoid of ideals of Number Field in a with defining polynomial x^2 + 23 with a = 4.795831523312720?*I + sage: R = QuadraticField(-23, 'a') # optional - sage.rings.number_field + sage: from sage.rings.ideal_monoid import IdealMonoid + sage: M = IdealMonoid(R); M # indirect doctest # optional - sage.rings.number_field + Monoid of ideals of Number Field in a with defining polynomial x^2 + 23 + with a = 4.795831523312720?*I sage: id = QQ.ideal(6) sage: id.parent().category() Category of commutative monoids - sage: MS = MatrixSpace(QQ,3,3) - sage: MS.ideal(MS.one()).parent().category() + sage: MS = MatrixSpace(QQ, 3, 3) # optional - sage.modules + sage: MS.ideal(MS.one()).parent().category() # optional - sage.modules Category of monoids """ self.__R = R @@ -77,9 +81,11 @@ def _repr_(self): TESTS:: - sage: R = QuadraticField(-23, 'a') - sage: M = sage.rings.ideal_monoid.IdealMonoid(R); M._repr_() - 'Monoid of ideals of Number Field in a with defining polynomial x^2 + 23 with a = 4.795831523312720?*I' + sage: R = QuadraticField(-23, 'a') # optional - sage.rings.number_field + sage: from sage.rings.ideal_monoid import IdealMonoid + sage: M = IdealMonoid(R); M._repr_() # optional - sage.rings.number_field + 'Monoid of ideals of Number Field in a with defining polynomial x^2 + 23 + with a = 4.795831523312720?*I' """ return "Monoid of ideals of %s" % self.__R @@ -89,8 +95,9 @@ def ring(self): EXAMPLES:: - sage: R = QuadraticField(-23, 'a') - sage: M = sage.rings.ideal_monoid.IdealMonoid(R); M.ring() is R + sage: R = QuadraticField(-23, 'a') # optional - sage.rings.number_field + sage: from sage.rings.ideal_monoid import IdealMonoid + sage: M = IdealMonoid(R); M.ring() is R # optional - sage.rings.number_field True """ return self.__R @@ -101,11 +108,12 @@ def _element_constructor_(self, x): EXAMPLES:: - sage: R. = QuadraticField(-23) - sage: M = sage.rings.ideal_monoid.IdealMonoid(R) - sage: M(a) # indirect doctest + sage: R. = QuadraticField(-23) # optional - sage.rings.number_field + sage: from sage.rings.ideal_monoid import IdealMonoid + sage: M = IdealMonoid(R) # optional - sage.rings.number_field + sage: M(a) # indirect doctest # optional - sage.rings.number_field Fractional ideal (a) - sage: M([a-4, 13]) + sage: M([a-4, 13]) # optional - sage.rings.number_field Fractional ideal (13, 1/2*a + 9/2) """ try: @@ -129,15 +137,15 @@ def _coerce_map_from_(self, x): EXAMPLES:: - sage: R = QuadraticField(-23, 'a') - sage: M = R.ideal_monoid() - sage: M.has_coerce_map_from(R) # indirect doctest + sage: R = QuadraticField(-23, 'a') # optional - sage.rings.number_field + sage: M = R.ideal_monoid() # optional - sage.rings.number_field + sage: M.has_coerce_map_from(R) # indirect doctest # optional - sage.rings.number_field True - sage: M.has_coerce_map_from(QQ.ideal_monoid()) + sage: M.has_coerce_map_from(QQ.ideal_monoid()) # optional - sage.rings.number_field True - sage: M.has_coerce_map_from(Zmod(6)) + sage: M.has_coerce_map_from(Zmod(6)) # optional - sage.rings.number_field False - sage: M.has_coerce_map_from(loads(dumps(M))) + sage: M.has_coerce_map_from(loads(dumps(M))) # optional - sage.rings.number_field True """ if isinstance(x, IdealMonoid_c): @@ -151,13 +159,13 @@ def __eq__(self, other): EXAMPLES:: - sage: R = QuadraticField(-23, 'a') - sage: M = R.ideal_monoid() - sage: M == QQ + sage: R = QuadraticField(-23, 'a') # optional - sage.rings.number_field + sage: M = R.ideal_monoid() # optional - sage.rings.number_field + sage: M == QQ # optional - sage.rings.number_field False - sage: M == 17 + sage: M == 17 # optional - sage.rings.number_field False - sage: M == R.ideal_monoid() + sage: M == R.ideal_monoid() # optional - sage.rings.number_field True """ if not isinstance(other, IdealMonoid_c): @@ -171,13 +179,13 @@ def __ne__(self, other): EXAMPLES:: - sage: R = QuadraticField(-23, 'a') - sage: M = R.ideal_monoid() - sage: M != QQ + sage: R = QuadraticField(-23, 'a') # optional - sage.rings.number_field + sage: M = R.ideal_monoid() # optional - sage.rings.number_field + sage: M != QQ # optional - sage.rings.number_field True - sage: M != 17 + sage: M != 17 # optional - sage.rings.number_field True - sage: M != R.ideal_monoid() + sage: M != R.ideal_monoid() # optional - sage.rings.number_field False """ return not (self == other) @@ -188,13 +196,13 @@ def __hash__(self): EXAMPLES:: - sage: R = QuadraticField(-23, 'a') - sage: M = R.ideal_monoid() - sage: hash(M) == hash(QQ) + sage: R = QuadraticField(-23, 'a') # optional - sage.rings.number_field + sage: M = R.ideal_monoid() # optional - sage.rings.number_field + sage: hash(M) == hash(QQ) # optional - sage.rings.number_field False - sage: hash(M) == 17 + sage: hash(M) == 17 # optional - sage.rings.number_field False - sage: hash(M) == hash(R.ideal_monoid()) + sage: hash(M) == hash(R.ideal_monoid()) # optional - sage.rings.number_field True """ # uses a random number, to have a distinct hash diff --git a/src/sage/rings/infinity.py b/src/sage/rings/infinity.py index c1ac3aee408..d4cbe9372bb 100644 --- a/src/sage/rings/infinity.py +++ b/src/sage/rings/infinity.py @@ -203,8 +203,8 @@ We check that :trac:`17990` is fixed:: - sage: m = Matrix([Infinity]) - sage: m.rows() + sage: m = Matrix([Infinity]) # optional - sage.modules + sage: m.rows() # optional - sage.modules [(+Infinity)] """ #***************************************************************************** @@ -290,7 +290,7 @@ def _maxima_init_(self): """ TESTS:: - sage: maxima(-oo) + sage: maxima(-oo) # optional - sage.symbolic minf sage: [x._maxima_init_() for x in [unsigned_infinity, oo, -oo]] ['inf', 'inf', 'minf'] @@ -324,9 +324,9 @@ def __pari__(self): EXAMPLES:: - sage: pari(-oo) + sage: pari(-oo) # optional - sage.libs.pari -oo - sage: pari(oo) + sage: pari(oo) # optional - sage.libs.pari +oo """ from sage.libs.pari.all import pari @@ -472,7 +472,7 @@ def _div_(self, other): Traceback (most recent call last): ... ValueError: unsigned oo times smaller number not defined - sage: SR(infinity) / unsigned_infinity + sage: SR(infinity) / unsigned_infinity # optional - sage.symbolic Traceback (most recent call last): ... RuntimeError: indeterminate expression: 0 * infinity encountered. @@ -568,8 +568,8 @@ def __init__(self): Sage can understand SymPy's complex infinity (:trac:`17493`):: - sage: import sympy - sage: SR(sympy.zoo) + sage: import sympy # optional - sympy + sage: SR(sympy.zoo) # optional - sympy Infinity Some equality checks:: @@ -676,7 +676,7 @@ def _element_constructor_(self, x): sage: UnsignedInfinityRing(2) # indirect doctest A number less than infinity - sage: UnsignedInfinityRing(I) + sage: UnsignedInfinityRing(I) # optional - sage.rings.number_field A number less than infinity sage: UnsignedInfinityRing(unsigned_infinity) Infinity @@ -684,10 +684,10 @@ def _element_constructor_(self, x): Infinity sage: UnsignedInfinityRing(-oo) Infinity - sage: K. = QuadraticField(3) - sage: UnsignedInfinityRing(a) + sage: K. = QuadraticField(3) # optional - sage.rings.number_field + sage: UnsignedInfinityRing(a) # optional - sage.rings.number_field A number less than infinity - sage: UnsignedInfinityRing(a - 2) + sage: UnsignedInfinityRing(a - 2) # optional - sage.rings.number_field A number less than infinity sage: UnsignedInfinityRing(RDF(oo)), UnsignedInfinityRing(RDF(-oo)) (Infinity, Infinity) @@ -701,14 +701,14 @@ def _element_constructor_(self, x): (Infinity, Infinity) sage: UnsignedInfinityRing(float('+inf')), UnsignedInfinityRing(float('-inf')) (Infinity, Infinity) - sage: UnsignedInfinityRing(SR(oo)), UnsignedInfinityRing(SR(-oo)) + sage: UnsignedInfinityRing(SR(oo)), UnsignedInfinityRing(SR(-oo)) # optional - sage.symbolic (Infinity, Infinity) The following rings have a ``is_infinity`` method:: sage: RR(oo).is_infinity() True - sage: SR(oo).is_infinity() + sage: SR(oo).is_infinity() # optional - sage.symbolic True """ # Lazy elements can wrap infinity or not, unwrap first @@ -748,11 +748,11 @@ def _coerce_map_from_(self, R): True sage: UnsignedInfinityRing.has_coerce_map_from(CC) True - sage: UnsignedInfinityRing.has_coerce_map_from(QuadraticField(-163, 'a')) + sage: UnsignedInfinityRing.has_coerce_map_from(QuadraticField(-163, 'a')) # optional - sage.rings.number_field True - sage: UnsignedInfinityRing.has_coerce_map_from(QQ^3) + sage: UnsignedInfinityRing.has_coerce_map_from(QQ^3) # optional - sage.modules False - sage: UnsignedInfinityRing.has_coerce_map_from(SymmetricGroup(13)) + sage: UnsignedInfinityRing.has_coerce_map_from(SymmetricGroup(13)) # optional - sage.groups False """ return isinstance(R, Ring) or R in (int, float, complex) @@ -942,12 +942,12 @@ def _sympy_(self): EXAMPLES:: - sage: import sympy - sage: SR(unsigned_infinity)._sympy_() + sage: import sympy # optional - sympy + sage: SR(unsigned_infinity)._sympy_() # optional - sympy zoo - sage: gamma(-3)._sympy_() is sympy.factorial(-2) + sage: gamma(-3)._sympy_() is sympy.factorial(-2) # optional - sympy True - sage: gamma(-3) is sympy.factorial(-2)._sage_() + sage: gamma(-3) is sympy.factorial(-2)._sage_() # optional - sympy True """ import sympy @@ -1128,11 +1128,12 @@ def _element_constructor_(self, x): sage: InfinityRing(-1.5) A negative finite number sage: [InfinityRing(a) for a in [-2..2]] - [A negative finite number, A negative finite number, Zero, A positive finite number, A positive finite number] - sage: K. = QuadraticField(3) - sage: InfinityRing(a) + [A negative finite number, A negative finite number, Zero, + A positive finite number, A positive finite number] + sage: K. = QuadraticField(3) # optional - sage.rings.number_field + sage: InfinityRing(a) # optional - sage.rings.number_field A positive finite number - sage: InfinityRing(a - 2) + sage: InfinityRing(a - 2) # optional - sage.rings.number_field A negative finite number sage: InfinityRing(RDF(oo)), InfinityRing(RDF(-oo)) (+Infinity, -Infinity) @@ -1142,7 +1143,7 @@ def _element_constructor_(self, x): (+Infinity, -Infinity) sage: InfinityRing(float('+inf')), InfinityRing(float('-inf')) (+Infinity, -Infinity) - sage: InfinityRing(SR(oo)), InfinityRing(SR(-oo)) + sage: InfinityRing(SR(oo)), InfinityRing(SR(-oo)) # optional - sage.symbolic (+Infinity, -Infinity) The following rings have ``is_positive_infinity`` / @@ -1150,7 +1151,7 @@ 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() + sage: SR(oo).is_positive_infinity(), SR(-oo).is_negative_infinity() # optional - sage.symbolic (True, True) Complex infinity raises an exception. This is fine (there is @@ -1226,7 +1227,7 @@ def _coerce_map_from_(self, R): sage: InfinityRing.has_coerce_map_from(int) # indirect doctest True - sage: InfinityRing.has_coerce_map_from(AA) + sage: InfinityRing.has_coerce_map_from(AA) # optional - sage.rings.number_field True sage: InfinityRing.has_coerce_map_from(RDF) True @@ -1237,7 +1238,7 @@ def _coerce_map_from_(self, R): infinity ring:: sage: cm = get_coercion_model() - sage: cm.explain(AA(3), oo, operator.lt) + sage: cm.explain(AA(3), oo, operator.lt) # optional - sage.rings.number_field Coercion on left operand via Coercion map: From: Algebraic Real Field @@ -1250,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) + sage: SR.has_coerce_map_from(InfinityRing) # optional - sage.symbolic True - sage: InfinityRing.has_coerce_map_from(SR) + sage: InfinityRing.has_coerce_map_from(SR) # optional - sage.symbolic False Complex numbers do not coerce into the infinity ring (what @@ -1278,7 +1279,7 @@ def _pushout_(self, other): r""" EXAMPLES:: - sage: QQbar(-2*i)*infinity + sage: QQbar(-2*i)*infinity # optional - sage.rings.number_field sage.symbolic (-I)*Infinity """ from sage.symbolic.ring import SR @@ -1479,9 +1480,9 @@ def _latex_(self): TESTS:: - sage: a = InfinityRing(pi); a + sage: a = InfinityRing(pi); a # optional - sage.symbolic A positive finite number - sage: a._latex_() + sage: a._latex_() # optional - sage.symbolic 'A positive finite number' sage: [latex(InfinityRing(a)) for a in [-2..2]] [A negative finite number, A negative finite number, Zero, A positive finite number, A positive finite number] @@ -1622,12 +1623,12 @@ def _sympy_(self): EXAMPLES:: - sage: import sympy - sage: bool(-oo == -sympy.oo) + sage: import sympy # optional - sympy + sage: bool(-oo == -sympy.oo) # optional - sympy True - sage: bool(SR(-oo) == -sympy.oo) + sage: bool(SR(-oo) == -sympy.oo) # optional - sympy True - sage: bool((-oo)._sympy_() == -sympy.oo) + sage: bool((-oo)._sympy_() == -sympy.oo) # optional - sympy True """ @@ -1640,9 +1641,9 @@ def _gap_init_(self): EXAMPLES:: - sage: gap(-Infinity) + sage: gap(-Infinity) # optional - sage.libs.gap -infinity - sage: libgap(-Infinity) + sage: libgap(-Infinity) # optional - sage.libs.gap -infinity """ return '-infinity' @@ -1723,10 +1724,10 @@ def _sympy_(self): EXAMPLES:: - sage: import sympy - sage: bool(oo == sympy.oo) # indirect doctest + sage: import sympy # optional - sympy + sage: bool(oo == sympy.oo) # indirect doctest # optional - sympy True - sage: bool(SR(oo) == sympy.oo) + sage: bool(SR(oo) == sympy.oo) # optional - sage.symbolic sympy True """ import sympy @@ -1738,9 +1739,9 @@ def _gap_init_(self): EXAMPLES:: - sage: gap(+Infinity) + sage: gap(+Infinity) # optional - sage.libs.gap infinity - sage: libgap(+Infinity) + sage: libgap(+Infinity) # optional - sage.libs.gap infinity """ return 'infinity' @@ -1768,7 +1769,7 @@ def test_comparison(ring): EXAMPLES:: sage: from sage.rings.infinity import test_comparison - sage: rings = [ZZ, QQ, RR, RealField(200), RDF, RLF, AA, RIF] + sage: rings = [ZZ, QQ, RR, RealField(200), RDF, RLF, RIF] sage: for R in rings: ....: print('testing {}'.format(R)) ....: test_comparison(R) @@ -1778,20 +1779,20 @@ def test_comparison(ring): testing Real Field with 200 bits of precision testing Real Double Field testing Real Lazy Field - testing Algebraic Real Field testing Real Interval Field with 53 bits of precision + sage: test_comparison(AA) # optional - sage.rings.number_field Comparison with number fields does not work:: - sage: K. = NumberField(x^2-3) - sage: (-oo < 1+sqrt3) and (1+sqrt3 < oo) # known bug + sage: K. = NumberField(x^2 - 3) # optional - sage.rings.number_field + sage: (-oo < 1 + sqrt3) and (1 + sqrt3 < oo) # known bug # optional - sage.rings.number_field False The symbolic ring handles its own infinities, but answers ``False`` (meaning: cannot decide) already for some very elementary comparisons:: - sage: test_comparison(SR) # known bug + sage: test_comparison(SR) # known bug # optional - sage.symbolic Traceback (most recent call last): ... AssertionError: testing -1000.0 in Symbolic Ring: id = ... diff --git a/src/sage/rings/integer.pyx b/src/sage/rings/integer.pyx index 61c980557ff..067f10831ac 100644 --- a/src/sage/rings/integer.pyx +++ b/src/sage/rings/integer.pyx @@ -8,7 +8,7 @@ EXAMPLES: Add 2 integers:: - sage: a = Integer(3) ; b = Integer(4) + sage: a = Integer(3); b = Integer(4) sage: a + b == 7 True @@ -25,7 +25,7 @@ Add an integer and a rational number:: Add an integer and a complex number:: sage: b = ComplexField().0 + 1.5 - sage: loads((a+b).dumps()) == a+b + sage: loads((a + b).dumps()) == a + b True sage: z = 32 @@ -40,7 +40,7 @@ Add an integer and a complex number:: Multiplication:: - sage: a = Integer(3) ; b = Integer(4) + sage: a = Integer(3); b = Integer(4) sage: a * b == 12 True sage: loads((a * 4.0).dumps()) == a*b @@ -55,13 +55,13 @@ Multiplication:: :: - sage: 'sage'*Integer(3) + sage: 'sage' * Integer(3) 'sagesagesage' COERCIONS: Return version of this integer in the multi-precision floating -real field R:: +real field `\RR`:: sage: n = 9390823 sage: RR = RealField(200) @@ -235,7 +235,7 @@ cdef _digits_naive(mpz_t v,l,int offset,Integer base,digits): - ``base`` -- the base to which we finding digits - ``digits`` - a python sequence type with objects to use for digits - note that python negative index semantics are relied upon + note that python negative index semantics are relied upon AUTHORS: @@ -277,7 +277,7 @@ cdef _digits_internal(mpz_t v,l,int offset,int power_index,power_list,digits): to fill at - ``power_index`` - a measure of size to fill and index to - power_list we're filling 1 << (power_index+1) digits + power_list we're filling ``1 << (power_index+1)`` digits - ``power_list`` - a list of powers of the base, precomputed in method digits digits - a python sequence type with objects to @@ -323,7 +323,7 @@ mpz_ui_pow_ui(PARI_PSEUDOPRIME_LIMIT, 2, 64) def is_Integer(x): """ - Return true if x is of the Sage integer type. + Return ``True`` if ``x`` is of the Sage :class:`Integer` type. EXAMPLES:: @@ -347,30 +347,30 @@ cdef inline Integer as_Integer(x): cdef class IntegerWrapper(Integer): r""" - Rationale for the ``IntegerWrapper`` class: + Rationale for the :class:`IntegerWrapper` class: - With ``Integers``, the allocation/deallocation function slots are + With :class:`Integer` objects, the allocation/deallocation function slots are hijacked with custom functions that stick already allocated - ``Integers`` (with initialized ``parent`` and ``mpz_t`` fields) + :class:`Integer` objects (with initialized ``parent`` and ``mpz_t`` fields) into a pool on "deallocation" and then pull them out whenever a - new one is needed. Because ``Integers`` are so common, this is - actually a significant savings. However , this does cause issues - with subclassing a Python class directly from ``Integer`` (but + new one is needed. Because :class:`Integers` objects are so common, this is + actually a significant savings. However, this does cause issues + with subclassing a Python class directly from :class:`Integer` (but that's ok for a Cython class). As a workaround, one can instead derive a class from the - intermediate class ``IntegerWrapper``, which sets statically its - alloc/dealloc methods to the *original* ``Integer`` alloc/dealloc + intermediate class :class:`IntegerWrapper`, which sets statically its + alloc/dealloc methods to the *original* :class:`Integer` alloc/dealloc methods, before they are swapped manually for the custom ones. - The constructor of ``IntegerWrapper`` further allows for - specifying an alternative parent to ``IntegerRing()``. + The constructor of :class:`IntegerWrapper` further allows for + specifying an alternative parent to :class:`IntegerRing`. """ def __init__(self, parent=None, x=None, unsigned int base=0): """ We illustrate how to create integers with parents different - from ``IntegerRing()``:: + from :class:`IntegerRing``:: sage: from sage.rings.integer import IntegerWrapper @@ -396,15 +396,15 @@ cdef class IntegerWrapper(Integer): cdef class Integer(sage.structure.element.EuclideanDomainElement): r""" - The ``Integer`` class represents arbitrary precision - integers. It derives from the ``Element`` class, so + The :class:`Integer` class represents arbitrary precision + integers. It derives from the :class:`Element` class, so integers can be used as ring elements anywhere in Sage. - Integer() interprets strings that begin with ``0o`` as octal numbers, + The constructor of :class:`Integer` interprets strings that begin with ``0o`` as octal numbers, strings that begin with ``0x`` as hexadecimal numbers and strings that begin with ``0b`` as binary numbers. - The class ``Integer`` is implemented in Cython, as a wrapper of the + The class :class:`Integer` is implemented in Cython, as a wrapper of the GMP ``mpz_t`` integer type. EXAMPLES:: @@ -425,9 +425,9 @@ cdef class Integer(sage.structure.element.EuclideanDomainElement): Conversion from PARI:: - sage: Integer(pari('-10380104371593008048799446356441519384')) # optional - sage.libs.pari + sage: Integer(pari('-10380104371593008048799446356441519384')) # optional - sage.libs.pari -10380104371593008048799446356441519384 - sage: Integer(pari('Pol([-3])')) # optional - sage.libs.pari + sage: Integer(pari('Pol([-3])')) # optional - sage.libs.pari -3 Conversion from gmpy2:: @@ -463,11 +463,11 @@ cdef class Integer(sage.structure.element.EuclideanDomainElement): -901824309821093821093812093810928309183091832091 sage: ZZ(RR(2.0)^80) 1208925819614629174706176 - sage: ZZ(QQbar(sqrt(28-10*sqrt(3)) + sqrt(3))) # optional - sage.rings.number_field, sage.symbolic + sage: ZZ(QQbar(sqrt(28-10*sqrt(3)) + sqrt(3))) # optional - sage.rings.number_field sage.symbolic 5 - sage: ZZ(AA(32).nth_root(5)) # optional - sage.rings.number_field + sage: ZZ(AA(32).nth_root(5)) # optional - sage.rings.number_field 2 - sage: ZZ(pari('Mod(-3,7)')) # optional - sage.libs.pari + sage: ZZ(pari('Mod(-3,7)')) # optional - sage.libs.pari 4 sage: ZZ('sage') Traceback (most recent call last): @@ -479,10 +479,10 @@ cdef class Integer(sage.structure.element.EuclideanDomainElement): '3b' sage: ZZ( ZZ(5).digits(3) , 3) 5 - sage: import numpy - sage: ZZ(numpy.int64(7^7)) + sage: import numpy # optional - numpy + sage: ZZ(numpy.int64(7^7)) # optional - numpy 823543 - sage: ZZ(numpy.ubyte(-7)) + sage: ZZ(numpy.ubyte(-7)) # optional - numpy 249 sage: ZZ(True) 1 @@ -498,8 +498,8 @@ cdef class Integer(sage.structure.element.EuclideanDomainElement): :: - sage: k = GF(2) # optional - sage.libs.pari - sage: ZZ((k(0),k(1)), 2) # optional - sage.libs.pari + sage: k = GF(2) # optional - sage.rings.finite_rings + sage: ZZ((k(0),k(1)), 2) # optional - sage.rings.finite_rings 2 :: @@ -535,72 +535,72 @@ cdef class Integer(sage.structure.element.EuclideanDomainElement): Test conversion from PARI (:trac:`11685`):: - sage: ZZ(pari(-3)) # optional - sage.libs.pari + sage: ZZ(pari(-3)) # optional - sage.libs.pari -3 - sage: ZZ(pari("-3.0")) # optional - sage.libs.pari + sage: ZZ(pari("-3.0")) # optional - sage.libs.pari -3 - sage: ZZ(pari("-3.5")) # optional - sage.libs.pari + sage: ZZ(pari("-3.5")) # optional - sage.libs.pari Traceback (most recent call last): ... TypeError: Attempt to coerce non-integral real number to an Integer - sage: ZZ(pari("1e100")) # optional - sage.libs.pari + sage: ZZ(pari("1e100")) # optional - sage.libs.pari Traceback (most recent call last): ... PariError: precision too low in truncr (precision loss in truncation) - sage: ZZ(pari("10^50")) # optional - sage.libs.pari + sage: ZZ(pari("10^50")) # optional - sage.libs.pari 100000000000000000000000000000000000000000000000000 - sage: ZZ(pari("Pol(3)")) # optional - sage.libs.pari + sage: ZZ(pari("Pol(3)")) # optional - sage.libs.pari 3 - sage: ZZ(GF(3^20,'t')(1)) # optional - sage.libs.pari + sage: ZZ(GF(3^20,'t')(1)) # optional - sage.rings.finite_rings 1 - sage: ZZ(pari(GF(3^20,'t')(1))) # optional - sage.libs.pari + sage: ZZ(pari(GF(3^20,'t')(1))) # optional - sage.libs.pari sage.rings.finite_rings 1 sage: x = polygen(QQ) - sage: K. = NumberField(x^2+3) # optional - sage.rings.number_field - sage: ZZ(a^2) # optional - sage.rings.number_field + sage: K. = NumberField(x^2 + 3) # optional - sage.rings.number_field + sage: ZZ(a^2) # optional - sage.rings.number_field -3 - sage: ZZ(pari(a)^2) # optional - sage.libs.pari, sage.rings.number_field + sage: ZZ(pari(a)^2) # optional - sage.libs.pari sage.rings.number_field -3 - sage: ZZ(pari("Mod(x, x^3+x+1)")) # Note error message refers to lifted element # optional - sage.libs.pari + sage: ZZ(pari("Mod(x, x^3+x+1)")) # Note error message refers to lifted element # optional - sage.libs.pari Traceback (most recent call last): ... TypeError: Unable to coerce PARI x to an Integer Test coercion of p-adic with negative valuation:: - sage: ZZ(pari(Qp(11)(11^-7))) # optional - sage.libs.pari + sage: ZZ(pari(Qp(11)(11^-7))) # optional - sage.libs.pari sage.rings.padics Traceback (most recent call last): ... TypeError: cannot convert p-adic with negative valuation to an integer Test converting a list with a very large base:: - sage: a=ZZ(randint(0,2^128-1)) + sage: a = ZZ(randint(0, 2^128 - 1)) sage: L = a.digits(2^64) sage: a == sum([x * 2^(64*i) for i,x in enumerate(L)]) True - sage: a == ZZ(L,base=2^64) + sage: a == ZZ(L, base=2^64) True Test comparisons with numpy types (see :trac:`13386` and :trac:`18076`):: - sage: import numpy - sage: numpy.int8('12') == 12 + sage: import numpy # optional - numpy + sage: numpy.int8('12') == 12 # optional - numpy True - sage: 12 == numpy.int8('12') + sage: 12 == numpy.int8('12') # optional - numpy True - sage: float('15') == 15 + sage: float('15') == 15 # optional - numpy True - sage: 15 == float('15') + sage: 15 == float('15') # optional - numpy True Test underscores as digit separators (PEP 515, https://www.python.org/dev/peps/pep-0515/):: - sage: Integer('1_3') + sage: Integer('1_3') # optional - numpy 13 - sage: Integer(b'1_3') + sage: Integer(b'1_3') # optional - numpy 13 """ # TODO: All the code below should somehow be in an external @@ -762,15 +762,15 @@ cdef class Integer(sage.structure.element.EuclideanDomainElement): def _im_gens_(self, codomain, im_gens, base_map=None): """ - Return the image of self under the map that sends the generators of + Return the image of ``self`` under the map that sends the generators of the parent to im_gens. Since ZZ maps canonically in the category of rings, this is just the natural coercion. EXAMPLES:: sage: n = -10 - sage: R = GF(17) # optional - sage.libs.pari - sage: n._im_gens_(R, [R(1)]) # optional - sage.libs.pari + sage: R = GF(17) # optional - sage.rings.finite_rings + sage: n._im_gens_(R, [R(1)]) # optional - sage.rings.finite_rings 7 """ return codomain.coerce(self) @@ -1007,9 +1007,9 @@ cdef class Integer(sage.structure.element.EuclideanDomainElement): EXAMPLES:: - sage: ex = SR(ZZ(7)); ex + sage: ex = SR(ZZ(7)); ex # optional - sage.symbolic 7 - sage: parent(ex) + sage: parent(ex) # optional - sage.symbolic Symbolic Ring """ return sring._force_pyobject(self, force=True) @@ -1020,9 +1020,9 @@ cdef class Integer(sage.structure.element.EuclideanDomainElement): EXAMPLES:: - sage: n = 5; n._sympy_() + sage: n = 5; n._sympy_() # optional - sympy 5 - sage: n = -5; n._sympy_() + sage: n = -5; n._sympy_() # optional - sympy -5 """ import sympy @@ -1077,7 +1077,7 @@ cdef class Integer(sage.structure.element.EuclideanDomainElement): :: - sage: two=Integer(2) + sage: two = Integer(2) sage: two.str(1) Traceback (most recent call last): ... @@ -1114,7 +1114,7 @@ cdef class Integer(sage.structure.element.EuclideanDomainElement): def __format__(self, *args, **kwargs): """ - Returns a string representation using Python's Format protocol. + Return a string representation using Python's Format protocol. Valid format descriptions are exactly those for Python integers. EXAMPLES:: @@ -1127,7 +1127,7 @@ cdef class Integer(sage.structure.element.EuclideanDomainElement): def ordinal_str(self): """ - Returns a string representation of the ordinal associated to self. + Return a string representation of the ordinal associated to ``self``. EXAMPLES:: @@ -1255,7 +1255,7 @@ cdef class Integer(sage.structure.element.EuclideanDomainElement): def bits(self): r""" - Return the bits in self as a list, least significant first. The + Return the bits in ``self`` as a list, least significant first. The result satisfies the identity :: @@ -1338,7 +1338,7 @@ cdef class Integer(sage.structure.element.EuclideanDomainElement): def trailing_zero_bits(self): """ - Return the number of trailing zero bits in self, i.e. + Return the number of trailing zero bits in ``self``, i.e. the exponent of the largest power of 2 dividing self. EXAMPLES:: @@ -1364,7 +1364,7 @@ cdef class Integer(sage.structure.element.EuclideanDomainElement): Return a list of digits for ``self`` in the given base in little endian order. - The returned value is unspecified if self is a negative number + The returned value is unspecified if ``self`` is a negative number and the digits are given. INPUT: @@ -1466,7 +1466,7 @@ cdef class Integer(sage.structure.element.EuclideanDomainElement): sage: l[16] [1, 1] - This function is comparable to ``str`` for speed. + This function is comparable to :func:`str` for speed. :: @@ -1594,7 +1594,7 @@ cdef class Integer(sage.structure.element.EuclideanDomainElement): between ``-b//2`` and ``b//2`` (both included). For instance in base 9, one uses digits from -4 to 4. If ``b`` is even, one has to choose between digits from ``-b//2`` to ``b//2 - 1`` or ``-b//2 + 1`` to ``b//2`` - (base 10 for instance: either -5 to 4 or -4 to 5), and this is + (base 10 for instance: either `-5` to `4` or `-4` to `5`), and this is defined by the value of ``positive_shift``. INPUT: @@ -1603,9 +1603,9 @@ cdef class Integer(sage.structure.element.EuclideanDomainElement): nonnegative or the nonpositive integers can be represented by ``balanced_digits``. Thus we say base must be greater than 2. - - ``positive_shift`` -- boolean (default: True); for even bases, the + - ``positive_shift`` -- boolean (default: ``True``); for even bases, the representation uses digits from ``-b//2 + 1`` to ``b//2`` if set to - True, and from ``-b//2`` to ``b//2 - 1`` otherwise. This has no + ``True``, and from ``-b//2`` to ``b//2 - 1`` otherwise. This has no effect for odd bases. EXAMPLES:: @@ -1695,7 +1695,7 @@ cdef class Integer(sage.structure.element.EuclideanDomainElement): def ndigits(self, base=10): """ - Return the number of digits of self expressed in the given base. + Return the number of digits of ``self`` expressed in the given base. INPUT: @@ -2008,7 +2008,7 @@ cdef class Integer(sage.structure.element.EuclideanDomainElement): Traceback (most recent call last): ... ZeroDivisionError: rational division by zero - sage: 3 / QQbar.zero() # optional - sage.rings.number_field + sage: 3 / QQbar.zero() # optional - sage.rings.number_field Traceback (most recent call last): ... ZeroDivisionError: division by zero in algebraic field @@ -2056,7 +2056,7 @@ cdef class Integer(sage.structure.element.EuclideanDomainElement): EXAMPLES:: - sage: a = Integer(321) ; b = Integer(10) + sage: a = Integer(321); b = Integer(10) sage: a // b 32 sage: z = Integer(-231) @@ -2113,7 +2113,7 @@ cdef class Integer(sage.structure.element.EuclideanDomainElement): 1 sage: 2^-0 1 - sage: (-1)^(1/3) # optional - sage.symbolic + sage: (-1)^(1/3) # optional - sage.symbolic (-1)^(1/3) For consistency with Python and MPFR, 0^0 is defined to be 1 in @@ -2140,7 +2140,7 @@ cdef class Integer(sage.structure.element.EuclideanDomainElement): We raise 2 to various interesting exponents:: - sage: 2^x # symbolic x # optional - sage.symbolic + sage: 2^x # symbolic x # optional - sage.symbolic 2^x sage: 2^1.5 # real number 2.82842712474619 @@ -2151,19 +2151,19 @@ cdef class Integer(sage.structure.element.EuclideanDomainElement): sage: r = 2 ^ int(-3); r; type(r) 1/8 - sage: f = 2^(sin(x)-cos(x)); f # optional - sage.symbolic + sage: f = 2^(sin(x)-cos(x)); f # optional - sage.symbolic 2^(-cos(x) + sin(x)) sage: f(x=3) 2^(-cos(3) + sin(3)) A symbolic sum:: - sage: x, y, z = var('x,y,z') # optional - sage.symbolic - sage: 2^(x + y + z) # optional - sage.symbolic + sage: x, y, z = var('x,y,z') # optional - sage.symbolic + sage: 2^(x + y + z) # optional - sage.symbolic 2^(x + y + z) - sage: 2^(1/2) # optional - sage.symbolic + sage: 2^(1/2) # optional - sage.symbolic sqrt(2) - sage: 2^(-1/2) # optional - sage.symbolic + sage: 2^(-1/2) # optional - sage.symbolic 1/2*sqrt(2) TESTS:: @@ -2220,7 +2220,7 @@ cdef class Integer(sage.structure.element.EuclideanDomainElement): ... ZeroDivisionError: rational division by zero - The exponent must fit in a long unless the base is -1, 0, or 1:: + The exponent must fit in a ``long`` unless the base is `-1`, `0`, or `1`:: sage: 2 ^ 100000000000000000000000 Traceback (most recent call last): @@ -2316,25 +2316,25 @@ cdef class Integer(sage.structure.element.EuclideanDomainElement): def nth_root(self, int n, bint truncate_mode=0): r""" - Returns the (possibly truncated) n'th root of self. + Return the (possibly truncated) ``n``-th root of ``self``. INPUT: - - ``n`` - integer >= 1 (must fit in C int type). + - ``n`` - integer `\geq 1` (must fit in the C ``int`` type). - ``truncate_mode`` - boolean, whether to allow truncation if - self is not an n'th power. + ``self`` is not an ``n``-th power. OUTPUT: - If truncate_mode is 0 (default), then returns the exact n'th root - if self is an n'th power, or raises a ValueError if it is not. + If ``truncate_mode`` is 0 (default), then returns the exact n'th root + if ``self`` is an n'th power, or raises a ValueError if it is not. - If truncate_mode is 1, then if either n is odd or self is - positive, returns a pair (root, exact_flag) where root is the - truncated nth root (rounded towards zero) and exact_flag is a + If ``truncate_mode`` is 1, then if either ``n`` is odd or ``self`` is + positive, returns a pair ``(root, exact_flag)`` where ``root`` is the + truncated ``n``-th root (rounded towards zero) and ``exact_flag`` is a boolean indicating whether the root extraction was exact; - otherwise raises a ValueError. + otherwise raises a :class:`ValueError`. AUTHORS: @@ -2603,7 +2603,7 @@ cdef class Integer(sage.structure.element.EuclideanDomainElement): def exact_log(self, m): r""" - Returns the largest integer `k` such that `m^k \leq \text{self}`, + Return the largest integer `k` such that `m^k \leq \text{self}`, i.e., the floor of `\log_m(\text{self})`. This is guaranteed to return the correct answer even when the usual @@ -2611,13 +2611,13 @@ cdef class Integer(sage.structure.element.EuclideanDomainElement): INPUT: - - ``m`` - integer >= 2 + - ``m`` - integer `\geq 2` AUTHORS: - David Harvey (2006-09-15) - Joel B. Mohler (2009-04-08) -- rewrote this to handle small cases - and/or easy cases up to 100x faster.. + and/or easy cases up to 100x faster.. EXAMPLES:: @@ -2643,11 +2643,12 @@ cdef class Integer(sage.structure.element.EuclideanDomainElement): sage: # The following are very very fast. sage: # Note that for base m a perfect power of 2, we get the exact log by counting bits. - sage: n=2983579823750185701375109835; m=32 + sage: n = 2983579823750185701375109835; m = 32 sage: n.exact_log(m) 18 sage: # The next is a favorite of mine. The log2 approximate is exact and immediately provable. - sage: n=90153710570912709517902579010793251709257901270941709247901209742124;m=213509721309572 + sage: n = 90153710570912709517902579010793251709257901270941709247901209742124 + sage: m = 213509721309572 sage: n.exact_log(m) 4 @@ -2663,9 +2664,9 @@ cdef class Integer(sage.structure.element.EuclideanDomainElement): sage: x.exact_log(3) 100000 - sage: (x+1).exact_log(3) + sage: (x + 1).exact_log(3) 100000 - sage: (x-1).exact_log(3) + sage: (x - 1).exact_log(3) 99999 :: @@ -2750,24 +2751,24 @@ cdef class Integer(sage.structure.element.EuclideanDomainElement): def log(self, m=None, prec=None): r""" - Returns symbolic log by default, unless the logarithm is exact (for - an integer argument). When precision is given, the RealField + Return symbolic log by default, unless the logarithm is exact (for + an integer argument). When ``prec`` is given, the :class:`RealField` approximation to that bit precision is used. This function is provided primarily so that Sage integers may be treated in the same manner as real numbers when convenient. Direct - use of exact_log is probably best for arithmetic log computation. + use of :meth:`exact_log` is probably best for arithmetic log computation. INPUT: - ``m`` - default: natural log base e - - ``prec`` - integer (default: None): if None, returns - symbolic, else to given bits of precision as in RealField + - ``prec`` - integer (default: ``None``): if ``None``, returns + symbolic, else to given bits of precision as in :class:`RealField` EXAMPLES:: - sage: Integer(124).log(5) # optional - sage.symbolic + sage: Integer(124).log(5) # optional - sage.symbolic log(124)/log(5) sage: Integer(124).log(5, 100) 2.9950093311241087454822446806 @@ -2775,7 +2776,7 @@ cdef class Integer(sage.structure.element.EuclideanDomainElement): 3 sage: Integer(125).log(5, prec=53) 3.00000000000000 - sage: log(Integer(125)) + sage: log(Integer(125)) # optional - sage.symbolic 3*log(5) For extremely large numbers, this works:: @@ -2784,32 +2785,32 @@ cdef class Integer(sage.structure.element.EuclideanDomainElement): sage: log(x, 3) 100000 - With the new Pynac symbolic backend, log(x) also - works in a reasonable amount of time for this x:: + Also ``log(x)``, giving a symbolic output, + works in a reasonable amount of time for this ``x``:: sage: x = 3^100000 - sage: log(x) + sage: log(x) # optional - 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 100000.000000000 - sage: (x+1).log(3,53) + sage: (x + 1).log(3, 53) 100000.000000000 - sage: (x+1).log(3,1000) + sage: (x + 1).log(3, 1000) 100000.000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 We can use non-integer bases, with default e:: - sage: x.log(2.5,prec=53) + sage: x.log(2.5, prec=53) 119897.784671579 We also get logarithms of negative integers, via the - symbolic ring, using the branch from `-pi` to `pi`:: + symbolic ring, using the branch from `-\pi` to `\pi`:: - sage: log(-1) + sage: log(-1) # optional - sage.symbolic I*pi The logarithm of zero is done likewise:: @@ -2829,7 +2830,7 @@ cdef class Integer(sage.structure.element.EuclideanDomainElement): TESTS:: - sage: (-2).log(3) # optional - sage.symbolic + sage: (-2).log(3) # optional - sage.symbolic (I*pi + log(2))/log(3) """ cdef int self_sgn @@ -2872,7 +2873,7 @@ cdef class Integer(sage.structure.element.EuclideanDomainElement): def exp(self, prec=None): r""" - Returns the exponential function of self as a real number. + Return the exponential function of ``self`` as a real number. This function is provided only so that Sage integers may be treated in the same manner as real numbers when convenient. @@ -2881,16 +2882,16 @@ cdef class Integer(sage.structure.element.EuclideanDomainElement): - ``prec`` - integer (default: None): if None, returns - symbolic, else to given bits of precision as in RealField + symbolic, else to given bits of precision as in :class:`RealField` EXAMPLES:: - sage: Integer(8).exp() # optional - sage.symbolic + sage: Integer(8).exp() # optional - sage.symbolic e^8 - sage: Integer(8).exp(prec=100) # optional - sage.symbolic + sage: Integer(8).exp(prec=100) # optional - sage.symbolic 2980.9579870417282747435920995 - sage: exp(Integer(8)) # optional - sage.symbolic + sage: exp(Integer(8)) # optional - sage.symbolic e^8 For even fairly large numbers, this may not be useful. @@ -2898,9 +2899,9 @@ cdef class Integer(sage.structure.element.EuclideanDomainElement): :: sage: y = Integer(145^145) - sage: y.exp() # optional - sage.symbolic + sage: y.exp() # optional - sage.symbolic e^25024207011349079210459585279553675697932183658421565260323592409432707306554163224876110094014450895759296242775250476115682350821522931225499163750010280453185147546962559031653355159703678703793369785727108337766011928747055351280379806937944746847277089168867282654496776717056860661614337004721164703369140625 - sage: y.exp(prec=53) # default RealField precision # optional - sage.symbolic + sage: y.exp(prec=53) # default RealField precision # optional - sage.symbolic +infinity """ from sage.functions.all import exp @@ -2911,8 +2912,8 @@ cdef class Integer(sage.structure.element.EuclideanDomainElement): def prime_to_m_part(self, m): """ - Returns the prime-to-m part of self, i.e., the largest divisor of - ``self`` that is coprime to ``m``. + Return the prime-to-`m` part of ``self``, i.e., the largest divisor of + ``self`` that is coprime to `m`. INPUT: @@ -2955,8 +2956,8 @@ cdef class Integer(sage.structure.element.EuclideanDomainElement): """ Return the prime divisors of this integer, sorted in increasing order. - If this integer is negative, we do *not* include -1 among - its prime divisors, since -1 is not a prime number. + If this integer is negative, we do *not* include `-1` among + its prime divisors, since `-1` is not a prime number. INPUT: @@ -2980,12 +2981,12 @@ cdef class Integer(sage.structure.element.EuclideanDomainElement): Setting the optional ``limit`` argument works as expected:: sage: a = 10^100 + 1 - sage: a.prime_divisors() + sage: a.prime_divisors() # optional - sage.libs.pari [73, 137, 401, 1201, 1601, 1676321, 5964848081, 129694419029057750551385771184564274499075700947656757821537291527196801] - sage: a.prime_divisors(limit=10^3) + sage: a.prime_divisors(limit=10^3) # optional - sage.libs.pari [73, 137, 401] - sage: a.prime_divisors(limit=10^7) + sage: a.prime_divisors(limit=10^7) # optional - sage.libs.pari [73, 137, 401, 1201, 1601, 1676321] """ res = [r[0] for r in self.factor(*args, **kwds)] @@ -3027,32 +3028,32 @@ cdef class Integer(sage.structure.element.EuclideanDomainElement): [1, 2, 3, 4, 6, 8, 9, 12, 17, 18, 24, 34, 36, 51, 68, 72, 102, 136, 153, 204, 306, 408, 612, 1224] sage: a = odd_part(factorial(31)) - sage: v = a.divisors() - sage: len(v) + sage: v = a.divisors() # optional - sage.libs.pari + sage: len(v) # optional - sage.libs.pari 172800 - sage: prod(e + 1 for p, e in factor(a)) + sage: prod(e + 1 for p, e in factor(a)) # optional - sage.libs.pari 172800 - sage: all(t.divides(a) for t in v) + sage: all(t.divides(a) for t in v) # optional - sage.libs.pari True :: sage: n = 2^551 - 1 - sage: L = n.divisors() # optional - sage.libs.pari - sage: len(L) # optional - sage.libs.pari + sage: L = n.divisors() # optional - sage.libs.pari + sage: len(L) # optional - sage.libs.pari 256 - sage: L[-1] == n # optional - sage.libs.pari + sage: L[-1] == n # optional - sage.libs.pari True TESTS: Overflow:: - sage: prod(primes_first_n(64)).divisors() # optional - sage.libs.pari + sage: prod(primes_first_n(64)).divisors() # optional - sage.libs.pari Traceback (most recent call last): ... OverflowError: value too large - sage: prod(primes_first_n(58)).divisors() # optional - sage.libs.pari + sage: prod(primes_first_n(58)).divisors() # optional - sage.libs.pari Traceback (most recent call last): ... OverflowError: value too large # 32-bit @@ -3062,8 +3063,8 @@ cdef class Integer(sage.structure.element.EuclideanDomainElement): (the ``divisors`` call below allocates about 800 MB every time, so a memory leak will not go unnoticed):: - sage: n = prod(primes_first_n(25)) # optional - sage.libs.pari - sage: for i in range(20): # long time # optional - sage.libs.pari + sage: n = prod(primes_first_n(25)) # optional - sage.libs.pari + sage: for i in range(20): # long time # optional - sage.libs.pari ....: try: ....: alarm(RDF.random_element(1e-3, 0.5)) ....: _ = n.divisors() @@ -3289,7 +3290,7 @@ cdef class Integer(sage.structure.element.EuclideanDomainElement): def sign(self): """ - Returns the sign of this integer, which is -1, 0, or 1 + Return the sign of this integer, which is `-1`, `0`, or `1` depending on whether this number is negative, zero, or positive respectively. @@ -3345,9 +3346,9 @@ cdef class Integer(sage.structure.element.EuclideanDomainElement): This example caused trouble in :trac:`6083`:: - sage: a = next_prime(2**31) # optional - sage.libs.pari - sage: b = Integers(a)(100) # optional - sage.libs.pari - sage: a % b # optional - sage.libs.pari + sage: a = next_prime(2**31) # optional - sage.libs.pari + sage: b = Integers(a)(100) # optional - sage.libs.pari + sage: a % b # optional - sage.libs.pari Traceback (most recent call last): ... ArithmeticError: reduction modulo 100 not defined @@ -3394,7 +3395,7 @@ cdef class Integer(sage.structure.element.EuclideanDomainElement): def quo_rem(Integer self, other): """ - Returns the quotient and the remainder of self divided by other. + Return the quotient and the remainder of ``self`` divided by other. Note that the remainder returned is always either zero or of the same sign as other. @@ -3443,10 +3444,10 @@ cdef class Integer(sage.structure.element.EuclideanDomainElement): sage: divmod(1, sys.maxsize+1r) # should not raise OverflowError: Python int too large to convert to C long (0, 1) - sage: import mpmath - sage: mpmath.mp.prec = 1000 - sage: root = mpmath.findroot(lambda x: x^2 - 3, 2) - sage: len(str(root)) + sage: import mpmath # optional - mpmath + sage: mpmath.mp.prec = 1000 # optional - mpmath + sage: root = mpmath.findroot(lambda x: x^2 - 3, 2) # optional - mpmath + sage: len(str(root)) # optional - mpmath 301 """ cdef Integer q = PY_NEW(Integer) @@ -3484,7 +3485,7 @@ cdef class Integer(sage.structure.element.EuclideanDomainElement): def powermod(self, exp, mod): r""" - Compute self\*\*exp modulo mod. + Compute ``self**exp`` modulo ``mod``. EXAMPLES:: @@ -3517,11 +3518,11 @@ cdef class Integer(sage.structure.element.EuclideanDomainElement): return x def rational_reconstruction(self, Integer m): - """ - Return the rational reconstruction of this integer modulo m, i.e., - the unique (if it exists) rational number that reduces to self + r""" + Return the rational reconstruction of this integer modulo `m`, i.e., + the unique (if it exists) rational number that reduces to ``self`` modulo m and whose numerator and denominator is bounded by - sqrt(m/2). + `\sqrt{m/2}`. INPUT: @@ -3609,7 +3610,7 @@ cdef class Integer(sage.structure.element.EuclideanDomainElement): def _rpy_(self): """ - Returns int(self) so that rpy can convert self into an object it + Return int(self) so that rpy can convert ``self`` into an object it knows how to work with. EXAMPLES:: @@ -3687,58 +3688,56 @@ cdef class Integer(sage.structure.element.EuclideanDomainElement): def trial_division(self, long bound=LONG_MAX, long start=2): """ - Return smallest prime divisor of self up to bound, beginning - checking at start, or abs(self) if no such divisor is found. + Return smallest prime divisor of ``self`` up to bound, beginning + checking at ``start``, or ``abs(self)`` if no such divisor is found. INPUT: - - ``bound`` -- a positive integer that fits in a C signed long - - ``start`` -- a positive integer that fits in a C signed long - - OUTPUT: + - ``bound`` -- a positive integer that fits in a C ``signed long`` + - ``start`` -- a positive integer that fits in a C ``signed long`` - - a positive integer + OUTPUT: A positive integer EXAMPLES:: - sage: n = next_prime(10^6)*next_prime(10^7); n.trial_division() # optional - sage.libs.pari + sage: n = next_prime(10^6)*next_prime(10^7); n.trial_division() # optional - sage.libs.pari 1000003 - sage: (-n).trial_division() # optional - sage.libs.pari + sage: (-n).trial_division() # optional - sage.libs.pari 1000003 - sage: n.trial_division(bound=100) # optional - sage.libs.pari + sage: n.trial_division(bound=100) # optional - sage.libs.pari 10000049000057 - sage: n.trial_division(bound=-10) # optional - sage.libs.pari + sage: n.trial_division(bound=-10) # optional - sage.libs.pari Traceback (most recent call last): ... ValueError: bound must be positive - sage: n.trial_division(bound=0) # optional - sage.libs.pari + sage: n.trial_division(bound=0) # optional - sage.libs.pari Traceback (most recent call last): ... ValueError: bound must be positive - sage: ZZ(0).trial_division() # optional - sage.libs.pari + sage: ZZ(0).trial_division() # optional - sage.libs.pari Traceback (most recent call last): ... ValueError: self must be nonzero - sage: n = next_prime(10^5) * next_prime(10^40); n.trial_division() # optional - sage.libs.pari + sage: n = next_prime(10^5) * next_prime(10^40); n.trial_division() # optional - sage.libs.pari 100003 - sage: n.trial_division(bound=10^4) # optional - sage.libs.pari + sage: n.trial_division(bound=10^4) # optional - sage.libs.pari 1000030000000000000000000000000000000012100363 - sage: (-n).trial_division(bound=10^4) # optional - sage.libs.pari + sage: (-n).trial_division(bound=10^4) # optional - sage.libs.pari 1000030000000000000000000000000000000012100363 - sage: (-n).trial_division() # optional - sage.libs.pari + sage: (-n).trial_division() # optional - sage.libs.pari 100003 - sage: n = 2 * next_prime(10^40); n.trial_division() # optional - sage.libs.pari + sage: n = 2 * next_prime(10^40); n.trial_division() # optional - sage.libs.pari 2 - sage: n = 3 * next_prime(10^40); n.trial_division() # optional - sage.libs.pari + sage: n = 3 * next_prime(10^40); n.trial_division() # optional - sage.libs.pari 3 - sage: n = 5 * next_prime(10^40); n.trial_division() # optional - sage.libs.pari + sage: n = 5 * next_prime(10^40); n.trial_division() # optional - sage.libs.pari 5 - sage: n = 2 * next_prime(10^4); n.trial_division() # optional - sage.libs.pari + sage: n = 2 * next_prime(10^4); n.trial_division() # optional - sage.libs.pari 2 - sage: n = 3 * next_prime(10^4); n.trial_division() # optional - sage.libs.pari + sage: n = 3 * next_prime(10^4); n.trial_division() # optional - sage.libs.pari 3 - sage: n = 5 * next_prime(10^4); n.trial_division() # optional - sage.libs.pari + sage: n = 5 * next_prime(10^4); n.trial_division() # optional - sage.libs.pari 5 You can specify a starting point:: @@ -3849,12 +3848,12 @@ cdef class Integer(sage.structure.element.EuclideanDomainElement): - ``'ecm'`` - use ECM-GMP, an implementation of Hendrik Lenstra's elliptic curve method. - - ``proof`` - bool (default: True) whether or not to prove + - ``proof`` - bool (default: ``True``) whether or not to prove primality of each factor (only applicable for ``'pari'`` and ``'ecm'``). - ``limit`` - int or None (default: None) if limit is - given it must fit in a signed int, and the factorization is done + given it must fit in a ``signed int``, and the factorization is done using trial division and primes up to limit. OUTPUT: @@ -3864,7 +3863,7 @@ cdef class Integer(sage.structure.element.EuclideanDomainElement): EXAMPLES:: - sage: n = 2^100 - 1; n.factor() # optional - sage.libs.pari + sage: n = 2^100 - 1; n.factor() # optional - sage.libs.pari 3 * 5^3 * 11 * 31 * 41 * 101 * 251 * 601 * 1801 * 4051 * 8101 * 268501 This factorization can be converted into a list of pairs `(p, @@ -3887,13 +3886,13 @@ cdef class Integer(sage.structure.element.EuclideanDomainElement): sage: dict(f)[3] 6 - We use proof=False, which doesn't prove correctness of the primes + We use ``proof=False``, which doesn't prove correctness of the primes that appear in the factorization:: sage: n = 920384092842390423848290348203948092384082349082 - sage: n.factor(proof=False) # optional - sage.libs.pari + sage: n.factor(proof=False) # optional - sage.libs.pari 2 * 11 * 1531 * 4402903 * 10023679 * 619162955472170540533894518173 - sage: n.factor(proof=True) # optional - sage.libs.pari + sage: n.factor(proof=True) # optional - sage.libs.pari 2 * 11 * 1531 * 4402903 * 10023679 * 619162955472170540533894518173 We factor using trial division only:: @@ -3904,15 +3903,15 @@ cdef class Integer(sage.structure.element.EuclideanDomainElement): An example where FLINT is used:: sage: n = 82862385732327628428164127822 - sage: n.factor(algorithm='flint') + sage: n.factor(algorithm='flint') # optional - 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: p = next_prime(10^20) # optional - sage.libs.pari + sage: q = next_prime(10^21) # optional - sage.libs.pari + sage: n = p * q # optional - sage.libs.pari + sage: n.factor(algorithm='qsieve') # optional - sage.libs.pari doctest:... RuntimeWarning: the factorization returned by qsieve may be incomplete (the factors may not be prime) or even wrong; see qsieve? for details @@ -3920,10 +3919,10 @@ cdef class Integer(sage.structure.element.EuclideanDomainElement): We factor using the elliptic curve method:: - sage: p = next_prime(10^15) # optional - sage.libs.pari - sage: q = next_prime(10^21) # optional - sage.libs.pari - sage: n = p * q # optional - sage.libs.pari - sage: n.factor(algorithm='ecm') # optional - sage.libs.pari + sage: p = next_prime(10^15) # optional - sage.libs.pari + sage: q = next_prime(10^21) # optional - sage.libs.pari + sage: n = p * q # optional - sage.libs.pari + sage: n.factor(algorithm='ecm') # optional - sage.libs.pari 1000000000000037 * 1000000000000000000117 TESTS:: @@ -4038,7 +4037,7 @@ cdef class Integer(sage.structure.element.EuclideanDomainElement): sage: (-999).support() [3, 37] - Trying to find the support of 0 gives an arithmetic error:: + Trying to find the support of 0 raises an :class:`ArithmeticError`:: sage: 0.support() Traceback (most recent call last): @@ -4146,7 +4145,7 @@ cdef class Integer(sage.structure.element.EuclideanDomainElement): def divides(self, n): """ - Return True if self divides n. + Return ``True`` if ``self`` divides ``n``. EXAMPLES:: @@ -4170,7 +4169,7 @@ cdef class Integer(sage.structure.element.EuclideanDomainElement): cpdef RingElement _valuation(Integer self, Integer p): r""" - Return the p-adic valuation of self. + Return the p-adic valuation of ``self``. We do not require that p be prime, but it must be at least 2. For more documentation see ``valuation`` @@ -4195,8 +4194,8 @@ cdef class Integer(sage.structure.element.EuclideanDomainElement): cdef object _val_unit(Integer self, Integer p): r""" - Returns a pair: the p-adic valuation of self, and the p-adic unit - of self. + Return a pair: the p-adic valuation of ``self``, and the p-adic unit + of ``self``. We do not require the p be prime, but it must be at least 2. For more documentation see ``val_unit`` @@ -4220,7 +4219,7 @@ cdef class Integer(sage.structure.element.EuclideanDomainElement): def valuation(self, p): """ - Return the p-adic valuation of self. + Return the p-adic valuation of ``self``. INPUT: @@ -4240,7 +4239,7 @@ cdef class Integer(sage.structure.element.EuclideanDomainElement): ... ValueError: You can only compute the valuation with respect to a integer larger than 1. - We do not require that p is a prime:: + We do not require that ``p`` is a prime:: sage: (2^11).valuation(4) 5 @@ -4252,7 +4251,7 @@ cdef class Integer(sage.structure.element.EuclideanDomainElement): def p_primary_part(self, p): """ - Return the p-primary part of ``self``. + Return the ``p``-primary part of ``self``. INPUT: @@ -4281,8 +4280,8 @@ cdef class Integer(sage.structure.element.EuclideanDomainElement): def val_unit(self, p): r""" - Returns a pair: the p-adic valuation of self, and the p-adic unit - of self. + Return a pair: the p-adic valuation of ``self``, and the p-adic unit + of ``self``. INPUT: @@ -4317,10 +4316,10 @@ cdef class Integer(sage.structure.element.EuclideanDomainElement): IMPLEMENTATION: - Currently returns 0 when self is 0. This behaviour is fairly arbitrary, + Currently returns 0 when ``self`` is 0. This behaviour is fairly arbitrary, and in Sage 4.6 this special case was not handled at all, eventually propagating a TypeError. The caller should not rely on the behaviour - in case self is 0. + in case ``self`` is 0. EXAMPLES:: @@ -4344,10 +4343,10 @@ cdef class Integer(sage.structure.element.EuclideanDomainElement): cdef Integer _divide_knowing_divisible_by(Integer self, Integer right): r""" - Returns the integer self / right when self is divisible by right. + Return the integer ``self`` / ``right`` when ``self`` is divisible by right. - If self is not divisible by right, the return value is undefined, - and may not even be close to self/right. For more documentation see + If ``self`` is not divisible by right, the return value is undefined, + and may not even be close to ``self`` / ``right``. For more documentation see ``divide_knowing_divisible_by`` AUTHORS: @@ -4370,10 +4369,10 @@ cdef class Integer(sage.structure.element.EuclideanDomainElement): def divide_knowing_divisible_by(self, right): r""" - Returns the integer self / right when self is divisible by right. + Return the integer ``self`` / ``right`` when ``self`` is divisible by ``right``. - If self is not divisible by right, the return value is undefined, - and may not even be close to self/right for multi-word integers. + If ``self`` is not divisible by right, the return value is undefined, + and may not even be close to ``self`` / ``right`` for multi-word integers. EXAMPLES:: @@ -4400,7 +4399,7 @@ cdef class Integer(sage.structure.element.EuclideanDomainElement): def _lcm(self, Integer n): """ - Returns the least common multiple of self and `n`. + Return the least common multiple of ``self`` and `n`. EXAMPLES:: @@ -4416,7 +4415,7 @@ cdef class Integer(sage.structure.element.EuclideanDomainElement): def _gcd(self, Integer n): """ - Return the greatest common divisor of self and `n`. + Return the greatest common divisor of ``self`` and `n`. EXAMPLES:: @@ -4488,7 +4487,7 @@ cdef class Integer(sage.structure.element.EuclideanDomainElement): r""" Return the factorial `n! = 1 \cdot 2 \cdot 3 \cdots n`. - If the input does not fit in an ``unsigned long int`` an ``OverflowError`` + If the input does not fit in an ``unsigned long int``, an :class:`OverflowError` is raised. EXAMPLES:: @@ -4503,14 +4502,14 @@ cdef class Integer(sage.structure.element.EuclideanDomainElement): 5 120 6 720 - Large integers raise an ``OverflowError``:: + Large integers raise an :class:`OverflowError`:: sage: (2**64).factorial() Traceback (most recent call last): ... OverflowError: argument too large for factorial - And negative ones a ``ValueError``:: + And negative ones a :class:`ValueError`:: sage: (-1).factorial() Traceback (most recent call last): @@ -4533,7 +4532,7 @@ cdef class Integer(sage.structure.element.EuclideanDomainElement): def multifactorial(self, long k): r""" - Compute the k-th factorial `n!^{(k)}` of self. + Compute the k-th factorial `n!^{(k)}` of ``self``. The multifactorial number `n!^{(k)}` is defined for non-negative integers `n` as follows. For `k=1` this is the standard factorial, @@ -4567,7 +4566,7 @@ cdef class Integer(sage.structure.element.EuclideanDomainElement): ... ValueError: multifactorial undefined - When entries are too large an ``OverflowError`` is raised:: + When entries are too large an :class:`OverflowError` is raised:: sage: (2**64).multifactorial(2) Traceback (most recent call last): @@ -4619,13 +4618,13 @@ cdef class Integer(sage.structure.element.EuclideanDomainElement): EXAMPLES:: - sage: gamma(5) + sage: gamma(5) # optional - sage.symbolic 24 - sage: gamma(0) + sage: gamma(0) # optional - sage.symbolic Infinity - sage: gamma(-1) + sage: gamma(-1) # optional - sage.symbolic Infinity - sage: gamma(-2^150) + sage: gamma(-2^150) # optional - sage.symbolic Infinity """ if mpz_sgn(self.value) > 0: @@ -4635,7 +4634,7 @@ cdef class Integer(sage.structure.element.EuclideanDomainElement): def floor(self): """ - Return the floor of self, which is just self since self is an + Return the floor of ``self``, which is just self since ``self`` is an integer. EXAMPLES:: @@ -4648,7 +4647,7 @@ cdef class Integer(sage.structure.element.EuclideanDomainElement): def ceil(self): """ - Return the ceiling of self, which is self since self is an + Return the ceiling of ``self``, which is ``self`` since ``self`` is an integer. EXAMPLES:: @@ -4661,8 +4660,8 @@ cdef class Integer(sage.structure.element.EuclideanDomainElement): def trunc(self): """ - Round this number to the nearest integer, which is self since - self is an integer. + Round this number to the nearest integer, which is ``self`` since + ``self`` is an integer. EXAMPLES:: @@ -4674,8 +4673,8 @@ cdef class Integer(sage.structure.element.EuclideanDomainElement): def round(Integer self, mode="away"): """ - Returns the nearest integer to ``self``, which is self since - self is an integer. + Return the nearest integer to ``self``, which is ``self`` since + ``self`` is an integer. EXAMPLES: @@ -4689,7 +4688,7 @@ cdef class Integer(sage.structure.element.EuclideanDomainElement): def real(self): """ - Returns the real part of self, which is self. + Return the real part of ``self``, which is ``self``. EXAMPLES:: @@ -4700,7 +4699,7 @@ cdef class Integer(sage.structure.element.EuclideanDomainElement): def imag(self): """ - Returns the imaginary part of self, which is zero. + Return the imaginary part of ``self``, which is zero. EXAMPLES:: @@ -4711,7 +4710,7 @@ cdef class Integer(sage.structure.element.EuclideanDomainElement): def is_one(self): r""" - Returns ``True`` if the integer is `1`, otherwise ``False``. + Return ``True`` if the integer is `1`, otherwise ``False``. EXAMPLES:: @@ -4724,7 +4723,7 @@ cdef class Integer(sage.structure.element.EuclideanDomainElement): def __bool__(self): r""" - Returns ``True`` if the integer is not `0`, otherwise ``False``. + Return ``True`` if the integer is not `0`, otherwise ``False``. EXAMPLES:: @@ -4760,7 +4759,7 @@ cdef class Integer(sage.structure.element.EuclideanDomainElement): def is_integer(self): """ - Returns ``True`` as they are integers + Return ``True`` as they are integers EXAMPLES:: @@ -4771,7 +4770,7 @@ cdef class Integer(sage.structure.element.EuclideanDomainElement): def is_unit(self): r""" - Returns ``true`` if this integer is a unit, i.e., 1 or `-1`. + Return ``True`` if this integer is a unit, i.e., `1` or `-1`. EXAMPLES:: @@ -4787,7 +4786,7 @@ cdef class Integer(sage.structure.element.EuclideanDomainElement): def is_square(self): r""" - Returns ``True`` if self is a perfect square. + Return ``True`` if ``self`` is a perfect square. EXAMPLES:: @@ -4800,7 +4799,7 @@ cdef class Integer(sage.structure.element.EuclideanDomainElement): def perfect_power(self): r""" - Returns ``(a, b)``, where this integer is `a^b` and `b` is maximal. + Return ``(a, b)``, where this integer is `a^b` and `b` is maximal. If called on `-1`, `0` or `1`, `b` will be `1`, since there is no maximal value of `b`. @@ -4815,23 +4814,23 @@ cdef class Integer(sage.structure.element.EuclideanDomainElement): EXAMPLES:: - sage: 144.perfect_power() # optional - sage.libs.pari + sage: 144.perfect_power() # optional - sage.libs.pari (12, 2) - sage: 1.perfect_power() # optional - sage.libs.pari + sage: 1.perfect_power() # optional - sage.libs.pari (1, 1) - sage: 0.perfect_power() # optional - sage.libs.pari + sage: 0.perfect_power() # optional - sage.libs.pari (0, 1) - sage: (-1).perfect_power() # optional - sage.libs.pari + sage: (-1).perfect_power() # optional - sage.libs.pari (-1, 1) - sage: (-8).perfect_power() # optional - sage.libs.pari + sage: (-8).perfect_power() # optional - sage.libs.pari (-2, 3) - sage: (-4).perfect_power() # optional - sage.libs.pari + sage: (-4).perfect_power() # optional - sage.libs.pari (-4, 1) - sage: (101^29).perfect_power() # optional - sage.libs.pari + sage: (101^29).perfect_power() # optional - sage.libs.pari (101, 29) - sage: (-243).perfect_power() # optional - sage.libs.pari + sage: (-243).perfect_power() # optional - sage.libs.pari (-3, 5) - sage: (-64).perfect_power() # optional - sage.libs.pari + sage: (-64).perfect_power() # optional - sage.libs.pari (-4, 3) """ parians = self.__pari__().ispower() @@ -4839,7 +4838,7 @@ cdef class Integer(sage.structure.element.EuclideanDomainElement): def global_height(self, prec=None): r""" - Returns the absolute logarithmic height of this rational integer. + Return the absolute logarithmic height of this rational integer. INPUT: @@ -4874,10 +4873,10 @@ cdef class Integer(sage.structure.element.EuclideanDomainElement): cdef bint _is_power_of(Integer self, Integer n): r""" - Returns a non-zero int if there is an integer b with + Return a non-zero int if there is an integer b with `\mathtt{self} = n^b`. - For more documentation see ``is_power_of``. + For more documentation see :meth:`is_power_of`. AUTHORS: @@ -4994,7 +4993,7 @@ cdef class Integer(sage.structure.element.EuclideanDomainElement): def is_power_of(Integer self, n): r""" - Returns ``True`` if there is an integer b with + Return ``True`` if there is an integer `b` with `\mathtt{self} = n^b`. .. SEEALSO:: @@ -5038,8 +5037,8 @@ cdef class Integer(sage.structure.element.EuclideanDomainElement): .. NOTE:: - For large integers self, is_power_of() is faster than - is_perfect_power(). The following examples gives some indication of + For large integers ``self``, :meth:`is_power_of` is faster than + :meth:`is_perfect_power`. The following examples give some indication of how much faster. :: @@ -5047,15 +5046,15 @@ cdef class Integer(sage.structure.element.EuclideanDomainElement): sage: b = lcm(range(1,10000)) sage: b.exact_log(2) 14446 - sage: t=cputime() + sage: t = cputime() sage: for a in range(2, 1000): k = b.is_perfect_power() sage: cputime(t) # random 0.53203299999999976 - sage: t=cputime() + sage: t = cputime() sage: for a in range(2, 1000): k = b.is_power_of(2) sage: cputime(t) # random 0.0 - sage: t=cputime() + sage: t = cputime() sage: for a in range(2, 1000): k = b.is_power_of(3) sage: cputime(t) # random 0.032002000000000308 @@ -5065,19 +5064,20 @@ cdef class Integer(sage.structure.element.EuclideanDomainElement): sage: b = lcm(range(1, 1000)) sage: b.exact_log(2) 1437 - sage: t=cputime() - sage: for a in range(2, 10000): k = b.is_perfect_power() # note that we change the range from the example above + sage: t = cputime() + sage: for a in range(2, 10000): # note: changed range from the example above + ....: k = b.is_perfect_power() sage: cputime(t) # random 0.17201100000000036 - sage: t=cputime(); TWO=int(2) + sage: t = cputime(); TWO = int(2) sage: for a in range(2, 10000): k = b.is_power_of(TWO) sage: cputime(t) # random 0.0040000000000000036 - sage: t=cputime() + sage: t = cputime() sage: for a in range(2, 10000): k = b.is_power_of(3) sage: cputime(t) # random 0.040003000000000011 - sage: t=cputime() + sage: t = cputime() sage: for a in range(2, 10000): k = b.is_power_of(a) sage: cputime(t) # random 0.02800199999999986 @@ -5118,55 +5118,55 @@ cdef class Integer(sage.structure.element.EuclideanDomainElement): EXAMPLES:: - sage: 17.is_prime_power() # optional - sage.libs.pari + sage: 17.is_prime_power() # optional - sage.libs.pari True - sage: 10.is_prime_power() # optional - sage.libs.pari + sage: 10.is_prime_power() # optional - sage.libs.pari False - sage: 64.is_prime_power() # optional - sage.libs.pari + sage: 64.is_prime_power() # optional - sage.libs.pari True - sage: (3^10000).is_prime_power() # optional - sage.libs.pari + sage: (3^10000).is_prime_power() # optional - sage.libs.pari True - sage: (10000).is_prime_power() # optional - sage.libs.pari + sage: (10000).is_prime_power() # optional - sage.libs.pari False - sage: (-3).is_prime_power() # optional - sage.libs.pari + sage: (-3).is_prime_power() # optional - sage.libs.pari False - sage: 0.is_prime_power() # optional - sage.libs.pari + sage: 0.is_prime_power() # optional - sage.libs.pari False - sage: 1.is_prime_power() # optional - sage.libs.pari + sage: 1.is_prime_power() # optional - sage.libs.pari False - sage: p = next_prime(10^20); p # optional - sage.libs.pari + sage: p = next_prime(10^20); p # optional - sage.libs.pari 100000000000000000039 - sage: p.is_prime_power() # optional - sage.libs.pari + sage: p.is_prime_power() # optional - sage.libs.pari True - sage: (p^97).is_prime_power() # optional - sage.libs.pari + sage: (p^97).is_prime_power() # optional - sage.libs.pari True - sage: (p+1).is_prime_power() # optional - sage.libs.pari + sage: (p + 1).is_prime_power() # optional - sage.libs.pari False With the ``get_data`` keyword set to ``True``:: - sage: (3^100).is_prime_power(get_data=True) # optional - sage.libs.pari + sage: (3^100).is_prime_power(get_data=True) # optional - sage.libs.pari (3, 100) - sage: 12.is_prime_power(get_data=True) # optional - sage.libs.pari + sage: 12.is_prime_power(get_data=True) # optional - sage.libs.pari (12, 0) - sage: (p^97).is_prime_power(get_data=True) # optional - sage.libs.pari + sage: (p^97).is_prime_power(get_data=True) # optional - sage.libs.pari (100000000000000000039, 97) - sage: q = p.next_prime(); q # optional - sage.libs.pari + sage: q = p.next_prime(); q # optional - sage.libs.pari 100000000000000000129 - sage: (p*q).is_prime_power(get_data=True) # optional - sage.libs.pari + sage: (p*q).is_prime_power(get_data=True) # optional - sage.libs.pari (10000000000000000016800000000000000005031, 0) - The method works for large entries when `proof=False`:: + The method works for large entries when ``proof=False``:: sage: proof.arithmetic(False) - sage: ((10^500 + 961)^4).is_prime_power() # optional - sage.libs.pari + sage: ((10^500 + 961)^4).is_prime_power() # optional - sage.libs.pari True sage: proof.arithmetic(True) We check that :trac:`4777` is fixed:: sage: n = 150607571^14 - sage: n.is_prime_power() # optional - sage.libs.pari + sage: n.is_prime_power() # optional - sage.libs.pari True """ if mpz_sgn(self.value) <= 0: @@ -5226,9 +5226,9 @@ cdef class Integer(sage.structure.element.EuclideanDomainElement): INPUT: - - ``proof`` -- Boolean or ``None`` (default). If False, use a + - ``proof`` -- Boolean or ``None`` (default). If ``False``, use a strong pseudo-primality test (see :meth:`is_pseudoprime`). - If True, use a provable primality test. If unset, use the + If ``True``, use a provable primality test. If unset, use the :mod:`default arithmetic proof flag `. .. NOTE:: @@ -5240,26 +5240,26 @@ cdef class Integer(sage.structure.element.EuclideanDomainElement): EXAMPLES:: sage: z = 2^31 - 1 - sage: z.is_prime() # optional - sage.libs.pari + sage: z.is_prime() # optional - sage.libs.pari True sage: z = 2^31 - sage: z.is_prime() # optional - sage.libs.pari + sage: z.is_prime() # optional - sage.libs.pari False sage: z = 7 - sage: z.is_prime() # optional - sage.libs.pari + sage: z.is_prime() # optional - sage.libs.pari True sage: z = -7 - sage: z.is_prime() # optional - sage.libs.pari + sage: z.is_prime() # optional - sage.libs.pari False - sage: z.is_irreducible() # optional - sage.libs.pari + sage: z.is_irreducible() # optional - sage.libs.pari True :: sage: z = 10^80 + 129 - sage: z.is_prime(proof=False) # optional - sage.libs.pari + sage: z.is_prime(proof=False) # optional - sage.libs.pari True - sage: z.is_prime(proof=True) # optional - sage.libs.pari + sage: z.is_prime(proof=True) # optional - sage.libs.pari True When starting Sage the arithmetic proof flag is True. We can change @@ -5268,17 +5268,17 @@ cdef class Integer(sage.structure.element.EuclideanDomainElement): sage: proof.arithmetic() True sage: n = 10^100 + 267 - sage: timeit("n.is_prime()") # not tested # optional - sage.libs.pari + sage: timeit("n.is_prime()") # not tested # optional - sage.libs.pari 5 loops, best of 3: 163 ms per loop sage: proof.arithmetic(False) sage: proof.arithmetic() False - sage: timeit("n.is_prime()") # not tested # optional - sage.libs.pari + sage: timeit("n.is_prime()") # not tested # optional - sage.libs.pari 1000 loops, best of 3: 573 us per loop ALGORITHM: - Calls the PARI ``isprime`` function. + Calls the PARI function :pari:`isprime`. TESTS: @@ -5290,7 +5290,7 @@ cdef class Integer(sage.structure.element.EuclideanDomainElement): ....: if tab[i]: ....: for j in range(2*i, size, i): ....: tab[j] = 0 - sage: all(ZZ(i).is_prime() == b for i,b in enumerate(tab)) # optional - sage.libs.pari + sage: all(ZZ(i).is_prime() == b for i,b in enumerate(tab)) # optional - sage.libs.pari True """ if mpz_sgn(self.value) <= 0: @@ -5329,7 +5329,7 @@ cdef class Integer(sage.structure.element.EuclideanDomainElement): - ``self`` -- A PARI pseudoprime - - ``proof`` -- Mandatory proof flag (True, False or None) + - ``proof`` -- Mandatory proof flag (``True``, ``False`` or ``None``) OUTPUT: @@ -5347,22 +5347,22 @@ cdef class Integer(sage.structure.element.EuclideanDomainElement): def is_irreducible(self): r""" - Returns ``True`` if self is irreducible, i.e. +/- + Return ``True`` if ``self`` is irreducible, i.e. +/- prime EXAMPLES:: sage: z = 2^31 - 1 - sage: z.is_irreducible() # optional - sage.libs.pari + sage: z.is_irreducible() # optional - sage.libs.pari True sage: z = 2^31 - sage: z.is_irreducible() # optional - sage.libs.pari + sage: z.is_irreducible() # optional - sage.libs.pari False sage: z = 7 - sage: z.is_irreducible() # optional - sage.libs.pari + sage: z.is_irreducible() # optional - sage.libs.pari True sage: z = -7 - sage: z.is_irreducible() # optional - sage.libs.pari + sage: z.is_irreducible() # optional - sage.libs.pari True """ cdef Integer n = self if self >= 0 else -self @@ -5374,7 +5374,7 @@ cdef class Integer(sage.structure.element.EuclideanDomainElement): This uses PARI's Baillie-PSW probabilistic primality test. Currently, there are no known pseudoprimes for - Baillie-PSW that are not actually prime. However it is + Baillie-PSW that are not actually prime. However, it is conjectured that there are infinitely many. See :wikipedia:`Baillie-PSW_primality_test` @@ -5382,10 +5382,10 @@ cdef class Integer(sage.structure.element.EuclideanDomainElement): EXAMPLES:: sage: z = 2^31 - 1 - sage: z.is_pseudoprime() # optional - sage.libs.pari + sage: z.is_pseudoprime() # optional - sage.libs.pari True sage: z = 2^31 - sage: z.is_pseudoprime() # optional - sage.libs.pari + sage: z.is_pseudoprime() # optional - sage.libs.pari False """ return self.__pari__().ispseudoprime() @@ -5406,17 +5406,17 @@ cdef class Integer(sage.structure.element.EuclideanDomainElement): EXAMPLES:: sage: x = 10^200 + 357 - sage: x.is_pseudoprime() # optional - sage.libs.pari + sage: x.is_pseudoprime() # optional - sage.libs.pari True - sage: (x^12).is_pseudoprime_power() # optional - sage.libs.pari + sage: (x^12).is_pseudoprime_power() # optional - sage.libs.pari True - sage: (x^12).is_pseudoprime_power(get_data=True) # optional - sage.libs.pari + sage: (x^12).is_pseudoprime_power(get_data=True) # optional - sage.libs.pari (1000...000357, 12) - sage: (997^100).is_pseudoprime_power() # optional - sage.libs.pari + sage: (997^100).is_pseudoprime_power() # optional - sage.libs.pari True - sage: (998^100).is_pseudoprime_power() # optional - sage.libs.pari + sage: (998^100).is_pseudoprime_power() # optional - sage.libs.pari False - sage: ((10^1000 + 453)^2).is_pseudoprime_power() # optional - sage.libs.pari + sage: ((10^1000 + 453)^2).is_pseudoprime_power() # optional - sage.libs.pari True TESTS:: @@ -5425,21 +5425,21 @@ cdef class Integer(sage.structure.element.EuclideanDomainElement): False sage: (-1).is_pseudoprime_power() False - sage: 1.is_pseudoprime_power() # optional - sage.libs.pari + sage: 1.is_pseudoprime_power() # optional - sage.libs.pari False """ return self.is_prime_power(proof=False, get_data=get_data) def is_perfect_power(self): r""" - Returns ``True`` if ``self`` is a perfect power, ie if there exist integers + Return ``True`` if ``self`` is a perfect power, ie if there exist integers `a` and `b`, `b > 1` with ``self`` `= a^b`. .. SEEALSO:: - :meth:`perfect_power`: Finds the minimal base for which this integer is a perfect power. - - :meth:`is_power_of`: If you know the base already this method is + - :meth:`is_power_of`: If you know the base already, this method is the fastest option. - :meth:`is_prime_power`: Checks whether the base is prime. @@ -5492,20 +5492,20 @@ cdef class Integer(sage.structure.element.EuclideanDomainElement): EXAMPLES:: - sage: K = NumberField(x^2 - 2, 'beta') # optional - sage.rings.number_field + sage: K = NumberField(x^2 - 2, 'beta') # optional - sage.rings.number_field sage: n = 4 - sage: n.is_norm(K) # optional - sage.rings.number_field + sage: n.is_norm(K) # optional - sage.rings.number_field True - sage: 5.is_norm(K) # optional - sage.rings.number_field + sage: 5.is_norm(K) # optional - sage.rings.number_field False sage: 7.is_norm(QQ) True - sage: n.is_norm(K, element=True) # optional - sage.rings.number_field + sage: n.is_norm(K, element=True) # optional - sage.rings.number_field (True, -4*beta + 6) - sage: n.is_norm(K, element=True)[1].norm() # optional - sage.rings.number_field + sage: n.is_norm(K, element=True)[1].norm() # optional - sage.rings.number_field 4 sage: n = 5 - sage: n.is_norm(K, element=True) # optional - sage.rings.number_field + sage: n.is_norm(K, element=True) # optional - sage.rings.number_field (False, None) sage: n = 7 sage: n.is_norm(QQ, element=True) @@ -5521,9 +5521,9 @@ cdef class Integer(sage.structure.element.EuclideanDomainElement): EXAMPLES:: - sage: 3._bnfisnorm(QuadraticField(-1, 'i')) # optional - sage.rings.number_field + sage: 3._bnfisnorm(QuadraticField(-1, 'i')) # optional - sage.rings.number_field (1, 3) - sage: 7._bnfisnorm(CyclotomicField(7)) # optional - sage.rings.number_field + sage: 7._bnfisnorm(CyclotomicField(7)) # optional - sage.rings.number_field (zeta7^5 - zeta7^2, 1) """ from sage.rings.rational_field import QQ @@ -5531,7 +5531,7 @@ cdef class Integer(sage.structure.element.EuclideanDomainElement): def jacobi(self, b): r""" - Calculate the Jacobi symbol `\left(\frac{self}{b}\right)`. + Calculate the Jacobi symbol `\left(\frac{\text{self}}{b}\right)`. EXAMPLES:: @@ -5568,9 +5568,9 @@ cdef class Integer(sage.structure.element.EuclideanDomainElement): def kronecker(self, b): r""" - Calculate the Kronecker symbol `\left(\frac{self}{b}\right)` - with the Kronecker extension `(self/2)=(2/self)` when `self` is odd, - or `(self/2)=0` when `self` is even. + Calculate the Kronecker symbol `\left(\frac{\text{self}}{b}\right)` + with the Kronecker extension `(\text{self}/2)=(2/\text{self})` when ``self`` is odd, + or `(\text{self}/2)=0` when ``self`` is even. EXAMPLES:: @@ -5599,13 +5599,13 @@ cdef class Integer(sage.structure.element.EuclideanDomainElement): INPUT: - - ``self`` -- an integer congruent to `0` or `1\mod4` which is + - ``self`` -- an integer congruent to `0` or `1` mod `4` which is not a square - - ``proof`` (boolean, default ``True``) -- if ``False`` then + - ``proof`` (boolean, default ``True``) -- if ``False``, then for negative discriminants a faster algorithm is used by the PARI library which is known to give incorrect results - when the class group has many cyclic factors. However the + when the class group has many cyclic factors. However, the results are correct for discriminants `D` with `|D|\le 2\cdot10^{10}`. OUTPUT: @@ -5624,11 +5624,11 @@ cdef class Integer(sage.structure.element.EuclideanDomainElement): EXAMPLES:: - sage: (-163).class_number() # optional - sage.libs.pari + sage: (-163).class_number() # optional - sage.libs.pari 1 - sage: (-104).class_number() # optional - sage.libs.pari + sage: (-104).class_number() # optional - sage.libs.pari 6 - sage: [((4*n+1),(4*n+1).class_number()) for n in [21..29]] # optional - sage.libs.pari + sage: [((4*n + 1), (4*n + 1).class_number()) for n in [21..29]] # optional - sage.libs.pari [(85, 2), (89, 1), (93, 1), @@ -5641,7 +5641,7 @@ cdef class Integer(sage.structure.element.EuclideanDomainElement): TESTS: - The integer must not be a square or an error is raised:: + The integer must not be a square, or an error is raised:: sage: 100.class_number() Traceback (most recent call last): @@ -5649,7 +5649,7 @@ cdef class Integer(sage.structure.element.EuclideanDomainElement): ValueError: class_number not defined for square integers - The integer must be 0 or 1 mod 4 or an error is raised:: + The integer must be 0 or 1 mod 4, or an error is raised:: sage: 10.class_number() Traceback (most recent call last): @@ -5678,7 +5678,7 @@ cdef class Integer(sage.structure.element.EuclideanDomainElement): Use ``self.radical()`` for the product of the primes that divide self. - If self is 0, just returns 0. + If ``self`` is 0, just returns 0. EXAMPLES:: @@ -5710,8 +5710,8 @@ cdef class Integer(sage.structure.element.EuclideanDomainElement): 2 sage: a.squarefree_part(bound=2**14) 2 - sage: a = 7^3 * next_prime(2^100)^2 * next_prime(2^200) # optional - sage.libs.pari - sage: a / a.squarefree_part(bound=1000) # optional - sage.libs.pari + sage: a = 7^3 * next_prime(2^100)^2 * next_prime(2^200) # optional - sage.libs.pari + sage: a / a.squarefree_part(bound=1000) # optional - sage.libs.pari 49 """ cdef Integer z @@ -5754,56 +5754,56 @@ cdef class Integer(sage.structure.element.EuclideanDomainElement): def next_probable_prime(self): """ - Return the next probable prime after self, as determined by PARI. + Return the next probable prime after ``self``, as determined by PARI. EXAMPLES:: - sage: (-37).next_probable_prime() # optional - sage.libs.pari + sage: (-37).next_probable_prime() # optional - sage.libs.pari 2 - sage: (100).next_probable_prime() # optional - sage.libs.pari + sage: (100).next_probable_prime() # optional - sage.libs.pari 101 - sage: (2^512).next_probable_prime() # optional - sage.libs.pari + sage: (2^512).next_probable_prime() # optional - sage.libs.pari 13407807929942597099574024998205846127479365820592393377723561443721764030073546976801874298166903427690031858186486050853753882811946569946433649006084171 - sage: 0.next_probable_prime() # optional - sage.libs.pari + sage: 0.next_probable_prime() # optional - sage.libs.pari 2 - sage: 126.next_probable_prime() # optional - sage.libs.pari + sage: 126.next_probable_prime() # optional - sage.libs.pari 127 - sage: 144168.next_probable_prime() # optional - sage.libs.pari + sage: 144168.next_probable_prime() # optional - sage.libs.pari 144169 """ return Integer( self.__pari__().nextprime(True) ) def next_prime(self, proof=None): r""" - Return the next prime after self. + Return the next prime after ``self``. - This method calls the PARI ``nextprime`` function. + This method calls the PARI function :pari:`nextprime`. INPUT: - ``proof`` - bool or None (default: None, see - proof.arithmetic or sage.structure.proof) Note that the global Sage - default is proof=True + ``proof.arithmetic`` or :mod:`sage.structure.proof`) Note that the global Sage + default is ``proof=True`` EXAMPLES:: - sage: 100.next_prime() # optional - sage.libs.pari + sage: 100.next_prime() # optional - sage.libs.pari 101 - sage: (10^50).next_prime() # optional - sage.libs.pari + sage: (10^50).next_prime() # optional - sage.libs.pari 100000000000000000000000000000000000000000000000151 Use ``proof=False``, which is way faster since it does not need a primality proof:: - sage: b = (2^1024).next_prime(proof=False) # optional - sage.libs.pari - sage: b - 2^1024 # optional - sage.libs.pari + sage: b = (2^1024).next_prime(proof=False) # optional - sage.libs.pari + sage: b - 2^1024 # optional - sage.libs.pari 643 :: - sage: Integer(0).next_prime() # optional - sage.libs.pari + sage: Integer(0).next_prime() # optional - sage.libs.pari 2 - sage: Integer(1001).next_prime() # optional - sage.libs.pari + sage: Integer(1001).next_prime() # optional - sage.libs.pari 1009 """ # Use PARI to compute the next *pseudo*-prime @@ -5814,9 +5814,9 @@ cdef class Integer(sage.structure.element.EuclideanDomainElement): def previous_prime(self, proof=None): r""" - Returns the previous prime before self. + Return the previous prime before ``self``. - This method calls the PARI ``precprime`` function. + This method calls the PARI function :pari:`precprime`. INPUT: @@ -5832,11 +5832,11 @@ cdef class Integer(sage.structure.element.EuclideanDomainElement): EXAMPLES:: - sage: 10.previous_prime() # optional - sage.libs.pari + sage: 10.previous_prime() # optional - sage.libs.pari 7 - sage: 7.previous_prime() # optional - sage.libs.pari + sage: 7.previous_prime() # optional - sage.libs.pari 5 - sage: 14376485.previous_prime() # optional - sage.libs.pari + sage: 14376485.previous_prime() # optional - sage.libs.pari 14376463 sage: 2.previous_prime() @@ -5847,8 +5847,8 @@ cdef class Integer(sage.structure.element.EuclideanDomainElement): An example using ``proof=False``, which is way faster since it does not need a primality proof:: - sage: b = (2^1024).previous_prime(proof=False) # optional - sage.libs.pari - sage: 2^1024 - b # optional - sage.libs.pari + sage: b = (2^1024).previous_prime(proof=False) # optional - sage.libs.pari + sage: 2^1024 - b # optional - sage.libs.pari 105 """ if mpz_cmp_ui(self.value, 2) <= 0: @@ -5862,7 +5862,7 @@ cdef class Integer(sage.structure.element.EuclideanDomainElement): def next_prime_power(self, proof=None): r""" - Return the next prime power after self. + Return the next prime power after ``self``. INPUT: @@ -5874,7 +5874,7 @@ cdef class Integer(sage.structure.element.EuclideanDomainElement): ALGORITHM: - The algorithm is naive. It computes the next power of 2 and go through + The algorithm is naive. It computes the next power of 2 and goes through the odd numbers calling :meth:`is_prime_power`. .. SEEALSO:: @@ -5888,23 +5888,23 @@ cdef class Integer(sage.structure.element.EuclideanDomainElement): sage: (-1).next_prime_power() 2 - sage: 2.next_prime_power() # optional - sage.libs.pari + sage: 2.next_prime_power() # optional - sage.libs.pari 3 - sage: 103.next_prime_power() # optional - sage.libs.pari + sage: 103.next_prime_power() # optional - sage.libs.pari 107 - sage: 107.next_prime_power() # optional - sage.libs.pari + sage: 107.next_prime_power() # optional - sage.libs.pari 109 - sage: 2044.next_prime_power() # optional - sage.libs.pari + sage: 2044.next_prime_power() # optional - sage.libs.pari 2048 TESTS:: - sage: [(2**k-1).next_prime_power() for k in range(1,10)] # optional - sage.libs.pari + sage: [(2**k - 1).next_prime_power() for k in range(1,10)] # optional - sage.libs.pari [2, 4, 8, 16, 32, 64, 128, 256, 512] - sage: [(2**k).next_prime_power() for k in range(10)] # optional - sage.libs.pari + sage: [(2**k).next_prime_power() for k in range(10)] # optional - sage.libs.pari [2, 3, 5, 9, 17, 37, 67, 131, 257, 521] - sage: for _ in range(10): # optional - sage.libs.pari + sage: for _ in range(10): # optional - sage.libs.pari ....: n = ZZ.random_element(2**256).next_prime_power() ....: m = n.next_prime_power().previous_prime_power() ....: assert m == n, "problem with n = {}".format(n) @@ -5928,7 +5928,7 @@ cdef class Integer(sage.structure.element.EuclideanDomainElement): def previous_prime_power(self, proof=None): r""" - Return the previous prime power before self. + Return the previous prime power before ``self``. INPUT: @@ -5940,7 +5940,7 @@ cdef class Integer(sage.structure.element.EuclideanDomainElement): ALGORITHM: - The algorithm is naive. It computes the previous power of 2 and go + The algorithm is naive. It computes the previous power of 2 and goes through the odd numbers calling the method :meth:`is_prime_power`. .. SEEALSO:: @@ -5952,13 +5952,13 @@ cdef class Integer(sage.structure.element.EuclideanDomainElement): EXAMPLES:: - sage: 3.previous_prime_power() # optional - sage.libs.pari + sage: 3.previous_prime_power() # optional - sage.libs.pari 2 - sage: 103.previous_prime_power() # optional - sage.libs.pari + sage: 103.previous_prime_power() # optional - sage.libs.pari 101 - sage: 107.previous_prime_power() # optional - sage.libs.pari + sage: 107.previous_prime_power() # optional - sage.libs.pari 103 - sage: 2044.previous_prime_power() # optional - sage.libs.pari + sage: 2044.previous_prime_power() # optional - sage.libs.pari 2039 sage: 2.previous_prime_power() @@ -5968,12 +5968,12 @@ cdef class Integer(sage.structure.element.EuclideanDomainElement): TESTS:: - sage: [(2**k+1).previous_prime_power() for k in range(1,10)] # optional - sage.libs.pari + sage: [(2**k + 1).previous_prime_power() for k in range(1,10)] # optional - sage.libs.pari [2, 4, 8, 16, 32, 64, 128, 256, 512] - sage: [(2**k).previous_prime_power() for k in range(2, 10)] # optional - sage.libs.pari + sage: [(2**k).previous_prime_power() for k in range(2, 10)] # optional - sage.libs.pari [3, 7, 13, 31, 61, 127, 251, 509] - sage: for _ in range(10): # optional - sage.libs.pari + sage: for _ in range(10): # optional - sage.libs.pari ....: n = ZZ.random_element(3,2**256).previous_prime_power() ....: m = n.previous_prime_power().next_prime_power() ....: assert m == n, "problem with n = {}".format(n) @@ -5999,7 +5999,7 @@ cdef class Integer(sage.structure.element.EuclideanDomainElement): def additive_order(self): """ - Return the additive order of self. + Return the additive order of ``self``. EXAMPLES:: @@ -6015,7 +6015,7 @@ cdef class Integer(sage.structure.element.EuclideanDomainElement): def multiplicative_order(self): r""" - Return the multiplicative order of self. + Return the multiplicative order of ``self``. EXAMPLES:: @@ -6037,23 +6037,23 @@ cdef class Integer(sage.structure.element.EuclideanDomainElement): def is_squarefree(self): """ - Returns True if this integer is not divisible by the square of any - prime and False otherwise. + Return ``True`` if this integer is not divisible by the square of any + prime and ``False`` otherwise. EXAMPLES:: - sage: 100.is_squarefree() # optional - sage.libs.pari + sage: 100.is_squarefree() # optional - sage.libs.pari False - sage: 102.is_squarefree() # optional - sage.libs.pari + sage: 102.is_squarefree() # optional - sage.libs.pari True - sage: 0.is_squarefree() # optional - sage.libs.pari + sage: 0.is_squarefree() # optional - sage.libs.pari False """ return self.__pari__().issquarefree() def is_discriminant(self): """ - Returns True if this integer is a discriminant. + Return ``True`` if this integer is a discriminant. .. NOTE:: @@ -6083,7 +6083,7 @@ cdef class Integer(sage.structure.element.EuclideanDomainElement): def is_fundamental_discriminant(self): """ - Returns True if this integer is a fundamental_discriminant. + Return ``True`` if this integer is a fundamental discriminant. .. NOTE:: @@ -6120,21 +6120,21 @@ cdef class Integer(sage.structure.element.EuclideanDomainElement): cpdef __pari__(self): """ - Returns the PARI version of this integer. + Return the PARI version of this integer. EXAMPLES:: sage: n = 9390823 - sage: m = n.__pari__(); m # optional - sage.libs.pari + sage: m = n.__pari__(); m # optional - sage.libs.pari 9390823 - sage: type(m) # optional - sage.libs.pari + sage: type(m) # optional - sage.libs.pari TESTS:: sage: n = 10^10000000 - sage: m = n.__pari__() # crash from trac 875 # optional - sage.libs.pari - sage: m % 1234567 # optional - sage.libs.pari + sage: m = n.__pari__() # crash from trac 875 # optional - sage.libs.pari + sage: m % 1234567 # optional - sage.libs.pari 1041334 """ @@ -6164,19 +6164,19 @@ cdef class Integer(sage.structure.element.EuclideanDomainElement): EXAMPLES:: - sage: import numpy - sage: numpy.array([1, 2, 3]) + sage: import numpy # optional - numpy + sage: numpy.array([1, 2, 3]) # optional - numpy array([1, 2, 3]) - sage: numpy.array([1, 2, 3]).dtype + sage: numpy.array([1, 2, 3]).dtype # optional - numpy dtype('int32') # 32-bit dtype('int64') # 64-bit - sage: numpy.array(2**40).dtype + sage: numpy.array(2**40).dtype # optional - numpy dtype('int64') - sage: numpy.array(2**400).dtype + sage: numpy.array(2**400).dtype # optional - numpy dtype('O') - sage: numpy.array([1,2,3,0.1]).dtype + sage: numpy.array([1,2,3,0.1]).dtype # optional - numpy dtype('float64') """ if mpz_fits_slong_p(self.value): @@ -6258,9 +6258,9 @@ cdef class Integer(sage.structure.element.EuclideanDomainElement): def sqrtrem(self): r""" - Return (s, r) where s is the integer square root of self and - r is the remainder such that `\text{self} = s^2 + r`. - Raises ``ValueError`` if self is negative. + Return `(s, r)` where `s` is the integer square root of ``self`` and + `r` is the remainder such that `\text{self} = s^2 + r`. + Raises :class:`ValueError` if ``self`` is negative. EXAMPLES:: @@ -6288,8 +6288,8 @@ cdef class Integer(sage.structure.element.EuclideanDomainElement): def isqrt(self): r""" - Returns the integer floor of the square root of self, or raises an - ``ValueError`` if self is negative. + Return the integer floor of the square root of ``self``, or raises an + :class:`ValueError` if ``self`` is negative. EXAMPLES:: @@ -6321,17 +6321,17 @@ cdef class Integer(sage.structure.element.EuclideanDomainElement): INPUT: - - ``prec`` - integer (default: None): if None, return an exact + - ``prec`` -- integer (default: ``None``): if ``None``, return an exact square root; otherwise return a numerical square root, to the given bits of precision. - - ``extend`` - bool (default: True); if True, return a + - ``extend`` -- bool (default: ``True``); if ``True``, return a square root in an extension ring, if necessary. Otherwise, raise a - ValueError if the square is not in the base ring. Ignored if prec - is not None. + :class:`ValueError` if the square is not in the base ring. Ignored if ``prec`` + is not ``None``. - - ``all`` - bool (default: False); if True, return all - square roots of self (a list of length 0, 1 or 2). + - ``all`` - bool (default: ``False``); if ``True``, return all + square roots of ``self`` (a list of length 0, 1, or 2). EXAMPLES:: @@ -6339,13 +6339,13 @@ cdef class Integer(sage.structure.element.EuclideanDomainElement): 12 sage: sqrt(Integer(144)) 12 - sage: Integer(102).sqrt() # optional - sage.symbolic + sage: Integer(102).sqrt() # optional - sage.symbolic sqrt(102) :: sage: n = 2 - sage: n.sqrt(all=True) # optional - sage.symbolic + sage: n.sqrt(all=True) # optional - sage.symbolic [sqrt(2), -sqrt(2)] sage: n.sqrt(prec=10) 1.4 @@ -6368,7 +6368,7 @@ cdef class Integer(sage.structure.element.EuclideanDomainElement): TESTS:: - sage: type(5.sqrt()) # optional - sage.symbolic + sage: type(5.sqrt()) # optional - sage.symbolic sage: type(5.sqrt(prec=53)) @@ -6586,12 +6586,12 @@ cdef class Integer(sage.structure.element.EuclideanDomainElement): cpdef _shift_helper(Integer self, y, int sign): """ - Function used to compute left and right shifts of integers. - Shifts self y bits to the left if sign is 1, and to the right - if sign is -1. + Compute left and right shifts of integers. + Shifts ``self`` ``y`` bits to the left if ``sign`` is `1`, and to the right + if ``sign`` is `-1`. WARNING: This function does no error checking. In particular, - it assumes that sign is either 1 or -1, + it assumes that ``sign`` is either `1` or `-1`. EXAMPLES:: @@ -6768,7 +6768,7 @@ cdef class Integer(sage.structure.element.EuclideanDomainElement): def __invert__(self): """ - Return the multiplicative inverse of self, as a rational number. + Return the multiplicative inverse of ``self``, as a rational number. EXAMPLES:: @@ -6794,8 +6794,8 @@ cdef class Integer(sage.structure.element.EuclideanDomainElement): def inverse_of_unit(self): """ - Return inverse of self if self is a unit in the integers, i.e., - self is -1 or 1. Otherwise, raise a ZeroDivisionError. + Return inverse of ``self`` if ``self`` is a unit in the integers, i.e., + ``self`` is `-1` or `1`. Otherwise, raise a :class:`ZeroDivisionError`. EXAMPLES:: @@ -6819,9 +6819,9 @@ cdef class Integer(sage.structure.element.EuclideanDomainElement): def inverse_mod(self, n): r""" - Return the inverse of self modulo `n`, if this inverse exists. + Return the inverse of ``self`` modulo `n`, if this inverse exists. - Otherwise, raises a ``ZeroDivisionError`` exception. + Otherwise, raise a :class:`ZeroDivisionError` exception. INPUT: @@ -6836,7 +6836,7 @@ cdef class Integer(sage.structure.element.EuclideanDomainElement): IMPLEMENTATION: - Call the mpz_invert GMP library function. + Call the ``mpz_invert`` GMP library function. EXAMPLES:: @@ -6942,7 +6942,7 @@ cdef class Integer(sage.structure.element.EuclideanDomainElement): def popcount(self): """ Return the number of 1 bits in the binary representation. - If self<0, we return Infinity. + If ``self`` < 0, we return Infinity. EXAMPLES:: @@ -6976,7 +6976,7 @@ cdef class Integer(sage.structure.element.EuclideanDomainElement): def binomial(self, m, algorithm='gmp'): """ - Return the binomial coefficient "self choose m". + Return the binomial coefficient "``self`` choose ``m``". INPUT: @@ -6986,15 +6986,13 @@ cdef class Integer(sage.structure.element.EuclideanDomainElement): ``gmp``), or ``'pari'``; ``'gmp'`` is faster for small ``m``, and ``'pari'`` tends to be faster for large ``m`` - OUTPUT: - - - integer + OUTPUT: integer EXAMPLES:: sage: 10.binomial(2) 45 - sage: 10.binomial(2, algorithm='pari') # optional - sage.libs.pari + sage: 10.binomial(2, algorithm='pari') # optional - sage.libs.pari 45 sage: 10.binomial(-2) 0 @@ -7003,11 +7001,11 @@ cdef class Integer(sage.structure.element.EuclideanDomainElement): sage: (-3).binomial(0) 1 - The argument ``m`` or (``self-m``) must fit into unsigned long:: + The argument ``m`` or (``self - m``) must fit into an ``unsigned long``:: sage: (2**256).binomial(2**256) 1 - sage: (2**256).binomial(2**256-1) + sage: (2**256).binomial(2**256 - 1) 115792089237316195423570985008687907853269984665640564039457584007913129639936 sage: (2**256).binomial(2**128) Traceback (most recent call last): @@ -7036,7 +7034,7 @@ cdef class Integer(sage.structure.element.EuclideanDomainElement): check for reliable interrupting, see :trac:`18919`:: sage: from cysignals import AlarmInterrupt - sage: for i in [1..10]: # long time (5s) # optional - sage.libs.pari + sage: for i in [1..10]: # long time (5s) # optional - sage.libs.pari ....: try: ....: alarm(i/11) ....: (2^100).binomial(2^22, algorithm='pari') @@ -7287,7 +7285,7 @@ def GCD_list(v): @cython.binding(True) def make_integer(s): """ - Create a Sage integer from the base-32 Python *string* s. This is + Create a Sage integer from the base-32 Python *string* ``s``. This is used in unpickling integers. EXAMPLES:: @@ -7360,7 +7358,7 @@ cdef class int_to_Z(Morphism): cpdef Element _call_(self, a): """ - Returns a new integer with the same value as a. + Return a new integer with the same value as ``a``. TESTS:: @@ -7433,7 +7431,7 @@ _mpz_realloc(global_dummy_Integer.value, 1) def _check_global_dummy_Integer(): """ - Return true if the global dummy Integer is ok. + Return ``True`` if the global dummy :class:`Integer` is ok. TESTS:: diff --git a/src/sage/rings/integer_ring.pyx b/src/sage/rings/integer_ring.pyx index 09b239a7dea..8a307b3988c 100644 --- a/src/sage/rings/integer_ring.pyx +++ b/src/sage/rings/integer_ring.pyx @@ -126,8 +126,8 @@ cdef class IntegerRing_class(PrincipalIdealDomain): False sage: Z.category() Join of Category of euclidean domains - and Category of infinite enumerated sets - and Category of metric spaces + and Category of infinite enumerated sets + and Category of metric spaces sage: Z(2^(2^5) + 1) 4294967297 @@ -151,9 +151,9 @@ cdef class IntegerRing_class(PrincipalIdealDomain): The lists are interpreted in little-endian order, so that entry ``i`` of the list is the coefficient of ``base^i``:: - sage: Z([4,1,7],base=100) + sage: Z([4,1,7], base=100) 70104 - sage: Z([4,1,7],base=10) + sage: Z([4,1,7], base=10) 714 sage: Z([3, 7], 10) 73 @@ -166,13 +166,13 @@ cdef class IntegerRing_class(PrincipalIdealDomain): ``z`` represent numbers 10 to 36. Letter case does not matter. :: - sage: Z("sage",base=32) + sage: Z("sage", base=32) 928270 - sage: Z("SAGE",base=32) + sage: Z("SAGE", base=32) 928270 - sage: Z("Sage",base=32) + sage: Z("Sage", base=32) 928270 - sage: Z([14, 16, 10, 28],base=32) + sage: Z([14, 16, 10, 28], base=32) 928270 sage: 14 + 16*32 + 10*32^2 + 28*32^3 928270 @@ -248,23 +248,23 @@ cdef class IntegerRing_class(PrincipalIdealDomain): 17 sage: Z(Mod(19,23)) 19 - sage: Z(2 + 3*5 + O(5^3)) + sage: Z(2 + 3*5 + O(5^3)) # optional - sage.rings.padics 17 Arbitrary numeric bases are supported; strings or list of integers are used to provide the digits (more details in :class:`IntegerRing_class`):: - sage: Z("sage",base=32) + sage: Z("sage", base=32) 928270 - sage: Z([14, 16, 10, 28],base=32) + sage: Z([14, 16, 10, 28], base=32) 928270 The :meth:`digits<~sage.rings.integer.Integer.digits>` method allows you to get the list of digits of an integer in a different basis (note that the digits are returned in little-endian order):: - sage: b = Z([4,1,7],base=100) + sage: b = Z([4,1,7], base=100) sage: b 70104 sage: b.digits(base=71) @@ -397,19 +397,19 @@ cdef class IntegerRing_class(PrincipalIdealDomain): EXAMPLES:: - sage: ZZ[sqrt(2), sqrt(3)] + sage: ZZ[sqrt(2), sqrt(3)] # optional - sage.rings.number_field sage.symbolic Relative Order in Number Field in sqrt2 with defining polynomial x^2 - 2 over its base field sage: ZZ['x'] Univariate Polynomial Ring in x over Integer Ring sage: ZZ['x,y'] Multivariate Polynomial Ring in x, y over Integer Ring - sage: R = ZZ[sqrt(5) + 1]; R + sage: R = ZZ[sqrt(5) + 1]; R # optional - sage.rings.number_field sage.symbolic Order in Number Field in a with defining polynomial x^2 - 2*x - 4 with a = 3.236067977499790? - sage: R.is_maximal() + sage: R.is_maximal() # optional - sage.rings.number_field sage.symbolic False - sage: R = ZZ[(1+sqrt(5))/2]; R + sage: R = ZZ[(1 + sqrt(5))/2]; R # optional - sage.rings.number_field sage.symbolic Order in Number Field in a with defining polynomial x^2 - x - 1 with a = 1.618033988749895? - sage: R.is_maximal() + sage: R.is_maximal() # optional - sage.rings.number_field sage.symbolic True """ if x in self: @@ -433,23 +433,25 @@ cdef class IntegerRing_class(PrincipalIdealDomain): sage: ZZ.range(10) [0, 1, 2, 3, 4, 5, 6, 7, 8, 9] - sage: ZZ.range(-5,5) + sage: ZZ.range(-5, 5) [-5, -4, -3, -2, -1, 0, 1, 2, 3, 4] - sage: ZZ.range(0,50,5) + sage: ZZ.range(0, 50, 5) [0, 5, 10, 15, 20, 25, 30, 35, 40, 45] - sage: ZZ.range(0,50,-5) + sage: ZZ.range(0, 50, -5) [] - sage: ZZ.range(50,0,-5) + sage: ZZ.range(50, 0, -5) [50, 45, 40, 35, 30, 25, 20, 15, 10, 5] - sage: ZZ.range(50,0,5) + sage: ZZ.range(50, 0, 5) [] - sage: ZZ.range(50,-1,-5) + sage: ZZ.range(50, -1, -5) [50, 45, 40, 35, 30, 25, 20, 15, 10, 5, 0] It uses different code if the step doesn't fit in a long:: - sage: ZZ.range(0,2^83,2^80) - [0, 1208925819614629174706176, 2417851639229258349412352, 3626777458843887524118528, 4835703278458516698824704, 6044629098073145873530880, 7253554917687775048237056, 8462480737302404222943232] + sage: ZZ.range(0, 2^83, 2^80) + [0, 1208925819614629174706176, 2417851639229258349412352, + 3626777458843887524118528, 4835703278458516698824704, 6044629098073145873530880, + 7253554917687775048237056, 8462480737302404222943232] Make sure :trac:`8818` is fixed:: @@ -532,7 +534,7 @@ cdef class IntegerRing_class(PrincipalIdealDomain): sage: ZZ.coerce(int(5)) # indirect doctest 5 - sage: ZZ.coerce(GF(7)(2)) + sage: ZZ.coerce(GF(7)(2)) # optional - sage.rings.finite_rings Traceback (most recent call last): ... TypeError: no canonical coercion from Finite Field of size 7 to Integer Ring @@ -554,14 +556,14 @@ cdef class IntegerRing_class(PrincipalIdealDomain): Coercions are available from numpy integer types:: - sage: import numpy - sage: ZZ.coerce(numpy.int8('1')) + sage: import numpy # optional - numpy + sage: ZZ.coerce(numpy.int8('1')) # optional - numpy 1 - sage: ZZ.coerce(numpy.int32('32')) + sage: ZZ.coerce(numpy.int32('32')) # optional - numpy 32 - sage: ZZ.coerce(numpy.int64('-12')) + sage: ZZ.coerce(numpy.int64('-12')) # optional - numpy -12 - sage: ZZ.coerce(numpy.uint64('11')) + sage: ZZ.coerce(numpy.uint64('11')) # optional - numpy 11 TESTS:: @@ -666,7 +668,8 @@ cdef class IntegerRing_class(PrincipalIdealDomain): ....: counter += 1 ....: dic[ZZ.random_element(*args, **kwds)] += 1 - sage: prob = lambda x : 1/5 + sage: def prob(x): + ....: return 1/5 sage: dic = defaultdict(Integer) sage: counter = 0.0 sage: add_samples(distribution="uniform") @@ -690,7 +693,8 @@ cdef class IntegerRing_class(PrincipalIdealDomain): sage: -10 <= ZZ.random_element(-10, 10) < 10 True - sage: prob = lambda x : 1/20 + sage: def prob(x): + ....: return 1/20 sage: dic = defaultdict(Integer) sage: counter = 0.0 sage: add_samples(-10, 10) @@ -699,7 +703,8 @@ cdef class IntegerRing_class(PrincipalIdealDomain): sage: 0 <= ZZ.random_element(5) < 5 True - sage: prob = lambda x : 1/5 + sage: def prob(x): + ....: return 1/5 sage: dic = defaultdict(Integer) sage: counter = 0.0 sage: add_samples(5) @@ -831,7 +836,7 @@ cdef class IntegerRing_class(PrincipalIdealDomain): True sage: ZZ._is_valid_homomorphism_(ZZ,[2]) False - sage: ZZ._is_valid_homomorphism_(ZZ.quotient_ring(8),[ZZ.quotient_ring(8)(1)]) + sage: ZZ._is_valid_homomorphism_(ZZ.quotient_ring(8), [ZZ.quotient_ring(8)(1)]) True """ if base_map is None: @@ -920,11 +925,11 @@ cdef class IntegerRing_class(PrincipalIdealDomain): EXAMPLES:: - sage: ZZ.extension(x^2-5, 'a') + sage: ZZ.extension(x^2 - 5, 'a') # optional - sage.rings.number_field Order in Number Field in a with defining polynomial x^2 - 5 - sage: ZZ.extension([x^2 + 1, x^2 + 2], 'a,b') - Relative Order in Number Field in a with defining polynomial - x^2 + 1 over its base field + sage: ZZ.extension([x^2 + 1, x^2 + 2], 'a,b') # optional - sage.rings.number_field + Relative Order in Number Field in a + with defining polynomial x^2 + 1 over its base field """ from sage.rings.number_field.order import EquationOrder return EquationOrder(poly, names=names, **kwds) @@ -976,40 +981,40 @@ cdef class IntegerRing_class(PrincipalIdealDomain): EXAMPLES:: - sage: F = ZZ.residue_field(61); F + sage: F = ZZ.residue_field(61); F # optional - sage.libs.pari Residue field of Integers modulo 61 - sage: pi = F.reduction_map(); pi + sage: pi = F.reduction_map(); pi # optional - sage.libs.pari Partially defined reduction map: From: Rational Field To: Residue field of Integers modulo 61 - sage: pi(123/234) + sage: pi(123/234) # optional - sage.libs.pari 6 - sage: pi(1/61) + sage: pi(1/61) # optional - sage.libs.pari Traceback (most recent call last): ... ZeroDivisionError: Cannot reduce rational 1/61 modulo 61: it has negative valuation - sage: lift = F.lift_map(); lift + sage: lift = F.lift_map(); lift # optional - sage.libs.pari Lifting map: From: Residue field of Integers modulo 61 To: Integer Ring - sage: lift(F(12345/67890)) + sage: lift(F(12345/67890)) # optional - sage.libs.pari 33 - sage: (12345/67890) % 61 + sage: (12345/67890) % 61 # optional - sage.libs.pari 33 Construction can be from a prime ideal instead of a prime:: - sage: ZZ.residue_field(ZZ.ideal(97)) + sage: ZZ.residue_field(ZZ.ideal(97)) # optional - sage.libs.pari Residue field of Integers modulo 97 TESTS:: - sage: ZZ.residue_field(ZZ.ideal(96)) + sage: ZZ.residue_field(ZZ.ideal(96)) # optional - sage.libs.pari Traceback (most recent call last): ... TypeError: Principal ideal (96) of Integer Ring is not prime - sage: ZZ.residue_field(96) + sage: ZZ.residue_field(96) # optional - sage.libs.pari Traceback (most recent call last): ... TypeError: 96 is not prime @@ -1160,7 +1165,7 @@ cdef class IntegerRing_class(PrincipalIdealDomain): sage: ZZ.completion(infinity, 53) Integer Ring - sage: ZZ.completion(5, 15, {'print_mode': 'bars'}) + sage: ZZ.completion(5, 15, {'print_mode': 'bars'}) # optional - sage.rings.padics 5-adic Ring with capped relative precision 15 """ if p == sage.rings.infinity.Infinity: @@ -1275,41 +1280,41 @@ cdef class IntegerRing_class(PrincipalIdealDomain): sage: R. = PolynomialRing(ZZ, sparse=True) sage: p = (x + 1)^23 * (x - 1)^23 * (x - 100) * (x + 5445)^5 - sage: ZZ._roots_univariate_polynomial(p) + sage: ZZ._roots_univariate_polynomial(p) # optional - sage.libs.pari [(100, 1), (-5445, 5), (1, 23), (-1, 23)] sage: p *= (1 + x^3458645 - 76*x^3435423343 + x^45346567867756556) - sage: ZZ._roots_univariate_polynomial(p) + sage: ZZ._roots_univariate_polynomial(p) # optional - sage.libs.pari [(1, 23), (-1, 23), (100, 1), (-5445, 5)] sage: p *= x^156468451540687043504386074354036574634735074 - sage: ZZ._roots_univariate_polynomial(p) + sage: ZZ._roots_univariate_polynomial(p) # optional - sage.libs.pari [(0, 156468451540687043504386074354036574634735074), (1, 23), (-1, 23), (100, 1), (-5445, 5)] - sage: ZZ._roots_univariate_polynomial(p, multiplicities=False) + sage: ZZ._roots_univariate_polynomial(p, multiplicities=False) # optional - sage.libs.pari [0, 1, -1, 100, -5445] sage: R. = PolynomialRing(ZZ, sparse=False) sage: p = (x + 1)^23 * (x - 1)^23 * (x - 100) * (x + 5445)^5 - sage: ZZ._roots_univariate_polynomial(p) + sage: ZZ._roots_univariate_polynomial(p) # optional - sage.libs.pari [(100, 1), (-5445, 5), (1, 23), (-1, 23)] - sage: ZZ._roots_univariate_polynomial(p, multiplicities=False) + sage: ZZ._roots_univariate_polynomial(p, multiplicities=False) # optional - sage.libs.pari [100, -5445, 1, -1] - sage: ZZ._roots_univariate_polynomial(p, algorithm="sparse") + sage: ZZ._roots_univariate_polynomial(p, algorithm="sparse") # optional - sage.libs.pari [(100, 1), (-5445, 5), (1, 23), (-1, 23)] - sage: ZZ._roots_univariate_polynomial(p, algorithm="dense") + sage: ZZ._roots_univariate_polynomial(p, algorithm="dense") # optional - sage.libs.pari [(100, 1), (-5445, 5), (1, 23), (-1, 23)] - sage: ZZ._roots_univariate_polynomial(p, algorithm="foobar") + sage: ZZ._roots_univariate_polynomial(p, algorithm="foobar") # optional - sage.libs.pari Traceback (most recent call last): ... ValueError: unknown algorithm 'foobar' sage: p = x^20 * p - sage: ZZ._roots_univariate_polynomial(p, algorithm="sparse") + sage: ZZ._roots_univariate_polynomial(p, algorithm="sparse") # optional - sage.libs.pari [(0, 20), (100, 1), (-5445, 5), (1, 23), (-1, 23)] - sage: ZZ._roots_univariate_polynomial(p, algorithm="dense") + sage: ZZ._roots_univariate_polynomial(p, algorithm="dense") # optional - sage.libs.pari [(100, 1), (-5445, 5), (0, 20), (1, 23), (-1, 23)] """ deg = p.degree() @@ -1462,7 +1467,7 @@ cdef class IntegerRing_class(PrincipalIdealDomain): EXAMPLES:: - sage: gap(ZZ) # indirect doctest + sage: gap(ZZ) # indirect doctest # optional - sage.libs.gap Integers """ return 'Integers' @@ -1495,7 +1500,7 @@ cdef class IntegerRing_class(PrincipalIdealDomain): EXAMPLES:: - sage: macaulay2(ZZ) #optional - macaulay2 + sage: macaulay2(ZZ) # optional - macaulay2 ZZ """ return "ZZ" @@ -1518,7 +1523,7 @@ cdef class IntegerRing_class(PrincipalIdealDomain): EXAMPLES:: - sage: ZZ._sympy_() + sage: ZZ._sympy_() # optional - sympy Integers """ from sympy import Integers @@ -1548,9 +1553,9 @@ cdef class IntegerRing_class(PrincipalIdealDomain): EXAMPLES:: - sage: v = ZZ.valuation(3); v + sage: v = ZZ.valuation(3); v # optional - sage.rings.padics 3-adic valuation - sage: v(3) + sage: v(3) # optional - sage.rings.padics 1 .. SEEALSO:: diff --git a/src/sage/rings/invariants/invariant_theory.py b/src/sage/rings/invariants/invariant_theory.py index 2f6850f97cc..564af30855d 100644 --- a/src/sage/rings/invariants/invariant_theory.py +++ b/src/sage/rings/invariants/invariant_theory.py @@ -140,15 +140,15 @@ def _guess_variables(polynomial, *args): sage: from sage.rings.invariants.invariant_theory import _guess_variables sage: R. = QQ[] - sage: _guess_variables(x^2+y^2) + sage: _guess_variables(x^2 + y^2) (x, y) sage: _guess_variables([x^2, y^2]) (x, y) - sage: _guess_variables(x^2+y^2, x) + sage: _guess_variables(x^2 + y^2, x) (x,) - sage: _guess_variables(x^2+y^2, x,y) + sage: _guess_variables(x^2 + y^2, x, y) (x, y) - sage: _guess_variables(x^2+y^2, [x,y]) + sage: _guess_variables(x^2 + y^2, [x,y]) (x, y) """ if isinstance(polynomial, (list, tuple)): @@ -177,7 +177,7 @@ def transvectant(f, g, h=1, scale='default'): INPUT: - - ``f,g`` -- two homogeneous binary forms in the same polynomial ring. + - ``f``, ``g`` -- two homogeneous binary forms in the same polynomial ring. - ``h`` -- the order of the transvectant. If it is not specified, the first transvectant is returned. @@ -214,14 +214,14 @@ def transvectant(f, g, h=1, scale='default'): factor will not be invertible in that case. The scale argument ``'none'`` can be used to compute the transvectant in this case:: - sage: R. = GF(5)[] - sage: p = a0*x1^5 + a1*x1^4*x0 + a2*x1^3*x0^2 + a3*x1^2*x0^3 + a4*x1*x0^4 + a5*x0^5 - sage: f = AlgebraicForm(2, 5, p, x0, x1) - sage: transvectant(f, f, 4) + sage: R. = GF(5)[] # optional - sage.rings.finite_rings + sage: f = AlgebraicForm(2, 5, a0*x1^5 + a1*x1^4*x0 + a2*x1^3*x0^2 # optional - sage.rings.finite_rings + ....: + a3*x1^2*x0^3 + a4*x1*x0^4 + a5*x0^5, x0, x1) + sage: transvectant(f, f, 4) # optional - sage.rings.finite_rings Traceback (most recent call last): ... ZeroDivisionError - sage: transvectant(f, f, 4, scale='none') + sage: transvectant(f, f, 4, scale='none') # optional - sage.rings.finite_rings Binary quadratic given by -a3^2*x0^2 + a2*a4*x0^2 + a2*a3*x0*x1 - a1*a4*x0*x1 - a2^2*x1^2 + a1*a3*x1^2 @@ -230,8 +230,8 @@ def transvectant(f, g, h=1, scale='default'): it to the scaled version:: sage: R. = QQ[] - sage: p = a0*x1^5 + a1*x1^4*x0 + a2*x1^3*x0^2 + a3*x1^2*x0^3 + a4*x1*x0^4 + a5*x0^5 - sage: f = AlgebraicForm(2, 5, p, x0, x1) + sage: f = AlgebraicForm(2, 5, a0*x1^5 + a1*x1^4*x0 + a2*x1^3*x0^2 + ....: + a3*x1^2*x0^3 + a4*x1*x0^4 + a5*x0^5, x0, x1) sage: transvectant(f, f, 4) Binary quadratic given by 3/50*a3^2*x0^2 - 4/25*a2*a4*x0^2 + 2/5*a1*a5*x0^2 + 1/25*a2*a3*x0*x1 - 6/25*a1*a4*x0*x1 + 2*a0*a5*x0*x1 @@ -247,14 +247,14 @@ def transvectant(f, g, h=1, scale='default'): one variable:: sage: R. = QQ[] - sage: quintic = invariant_theory.binary_quintic(x^5+x^3+2*x^2+y^5, x) + sage: quintic = invariant_theory.binary_quintic(x^5 + x^3 + 2*x^2 + y^5, x) sage: transvectant(quintic, quintic, 2) Traceback (most recent call last): ... ValueError: polynomial is not homogeneous sage: R. = QQ[] sage: S. = R[] - sage: quintic = invariant_theory.binary_quintic(x^5+x^3+2*x^2+y^5, x) + sage: quintic = invariant_theory.binary_quintic(x^5 + x^3 + 2*x^2 + y^5, x) sage: transvectant(quintic, quintic, 2) Binary sextic given by 1/5*x^6 + 6/5*x^5*h - 3/25*x^4*h^2 + (50*y^5 - 8)/25*x^3*h^3 - 12/25*x^2*h^4 + (3*y^5)/5*x*h^5 @@ -385,12 +385,12 @@ def ring(self): EXAMPLES:: sage: R. = QQ[] - sage: quartic = invariant_theory.binary_quartic(x^4+y^4+t*x^2*y^2, [x,y]) + sage: quartic = invariant_theory.binary_quartic(x^4 + y^4 + t*x^2*y^2, [x,y]) sage: quartic.ring() Multivariate Polynomial Ring in x, y, t over Rational Field sage: R. = QQ[] - sage: quartic = invariant_theory.binary_quartic(x^4+1+t*x^2, [x]) + sage: quartic = invariant_theory.binary_quartic(x^4 + 1 + t*x^2, [x]) sage: quartic.ring() Multivariate Polynomial Ring in x, y, t over Rational Field """ @@ -408,12 +408,12 @@ def variables(self): EXAMPLES:: sage: R. = QQ[] - sage: quartic = invariant_theory.binary_quartic(x^4+y^4+t*x^2*y^2, [x,y]) + sage: quartic = invariant_theory.binary_quartic(x^4 + y^4 + t*x^2*y^2, [x,y]) sage: quartic.variables() (x, y) sage: R. = QQ[] - sage: quartic = invariant_theory.binary_quartic(x^4+1+t*x^2, [x]) + sage: quartic = invariant_theory.binary_quartic(x^4 + 1 + t*x^2, [x]) sage: quartic.variables() (x, None) """ @@ -431,14 +431,14 @@ def is_homogeneous(self): EXAMPLES:: sage: R. = QQ[] - sage: quartic = invariant_theory.binary_quartic(x^4+y^4+t*x^2*y^2, [x,y]) + sage: quartic = invariant_theory.binary_quartic(x^4 + y^4 + t*x^2*y^2, [x,y]) sage: quartic.is_homogeneous() True sage: quartic.form() x^2*y^2*t + x^4 + y^4 sage: R. = QQ[] - sage: quartic = invariant_theory.binary_quartic(x^4+1+t*x^2, [x]) + sage: quartic = invariant_theory.binary_quartic(x^4 + 1 + t*x^2, [x]) sage: quartic.is_homogeneous() False sage: quartic.form() @@ -505,7 +505,7 @@ class AlgebraicForm(FormsBase): ... ValueError: polynomial is of the wrong degree - sage: AlgebraicForm(2, 2, x^2+y, [x,y]).variables() + sage: AlgebraicForm(2, 2, x^2 + y, [x,y]).variables() Traceback (most recent call last): ... ValueError: polynomial is not homogeneous @@ -650,7 +650,7 @@ def _repr_(self): EXAMPLES:: sage: R. = QQ[] - sage: quartic = invariant_theory.binary_quartic(x^4+y^4) + sage: quartic = invariant_theory.binary_quartic(x^4 + y^4) sage: quartic._repr_() 'Binary quartic with coefficients (1, 0, 0, 0, 1)' @@ -694,7 +694,7 @@ def form(self): EXAMPLES:: sage: R. = QQ[] - sage: quartic = invariant_theory.binary_quartic(x^4+y^4) + sage: quartic = invariant_theory.binary_quartic(x^4 + y^4) sage: quartic.form() x^4 + y^4 sage: quartic.polynomial() @@ -792,7 +792,7 @@ def _extract_coefficients(self, monomials): (a30, a03, a00, a21, a20, a12, a02, a10, a01, a11) sage: T. = QQ[] - sage: univariate = AlgebraicForm(2, 3, t^3+2*t^2+3*t+4) + sage: univariate = AlgebraicForm(2, 3, t^3 + 2*t^2 + 3*t + 4) sage: m = [t^3, 1, t, t^2] sage: univariate._extract_coefficients(m) (1, 4, 3, 2) @@ -806,7 +806,7 @@ def _extract_coefficients(self, monomials): Check for :trac:`30035`:: sage: R. = QQ[] - sage: f = 3*a**3+b**3+a*b*c + sage: f = 3*a**3 + b**3 + a*b*c sage: T = invariant_theory.ternary_cubic(f) sage: T.S_invariant().parent() Rational Field @@ -905,9 +905,9 @@ def transformed(self, g): sage: R. = QQ[] sage: cubic = invariant_theory.ternary_cubic(x^3 + 2*y^3 + 3*z^3 + 4*x*y*z) - sage: cubic.transformed({x:y, y:z, z:x}).form() + sage: cubic.transformed({x: y, y: z, z: x}).form() 3*x^3 + y^3 + 4*x*y*z + 2*z^3 - sage: cyc = matrix([[0,1,0],[0,0,1],[1,0,0]]) + sage: cyc = matrix([[0,1,0], [0,0,1], [1,0,0]]) sage: cubic.transformed(cyc) == cubic.transformed({x:y, y:z, z:x}) True sage: g = matrix(QQ, [[1, 0, 0], [-1, 1, -3], [-5, -5, 16]]) @@ -973,11 +973,11 @@ def __init__(self, n, d, polynomial, *args): sage: R. = QQ[] sage: from sage.rings.invariants.invariant_theory import QuadraticForm - sage: form = QuadraticForm(2, 2, x^2+2*y^2+3*x*y) + sage: form = QuadraticForm(2, 2, x^2 + 2*y^2 + 3*x*y) sage: form Binary quadratic with coefficients (1, 2, 3) sage: form._check_covariant('discriminant', invariant=True) - sage: QuadraticForm(3, 2, x^2+y^2) + sage: QuadraticForm(3, 2, x^2 + y^2) Ternary quadratic with coefficients (1, 1, 0, 0, 0, 0) """ assert d == 2 @@ -1024,11 +1024,11 @@ def monomials(self): EXAMPLES:: sage: R. = QQ[] - sage: quadratic = invariant_theory.quadratic_form(x^2+y^2) + sage: quadratic = invariant_theory.quadratic_form(x^2 + y^2) sage: quadratic.monomials() (x^2, y^2, x*y) - sage: quadratic = invariant_theory.inhomogeneous_quadratic_form(x^2+y^2) + sage: quadratic = invariant_theory.inhomogeneous_quadratic_form(x^2 + y^2) sage: quadratic.monomials() (x^2, y^2, 1, x*y, x, y) """ @@ -1158,7 +1158,7 @@ def discriminant(self): EXAMPLES:: sage: R. = QQ[] - sage: p = a*x^2+b*x*y+c*y^2 + sage: p = a*x^2 + b*x*y + c*y^2 sage: quadratic = invariant_theory.quadratic_form(p, x,y) sage: quadratic.discriminant() b^2 - 4*a*c @@ -1291,7 +1291,7 @@ def as_QuadraticForm(self): EXAMPLES:: sage: R. = QQ[] - sage: p = x^2+y^2+z^2+2*x*y+3*x*z + sage: p = x^2 + y^2 + z^2 + 2*x*y + 3*x*z sage: quadratic = invariant_theory.ternary_quadratic(p) sage: matrix(quadratic) [ 1 1 3/2] @@ -1344,7 +1344,7 @@ def __init__(self, n, d, polynomial, *args): sage: R. = QQ[] sage: from sage.rings.invariants.invariant_theory import BinaryQuartic - sage: BinaryQuartic(2, 4, x^4+y^4) + sage: BinaryQuartic(2, 4, x^4 + y^4) Binary quartic with coefficients (1, 0, 0, 0, 1) """ assert n == 2 and d == 4 @@ -1365,7 +1365,7 @@ def monomials(self): EXAMPLES:: sage: R. = QQ[] - sage: quartic = invariant_theory.binary_quartic(x^4+y^4) + sage: quartic = invariant_theory.binary_quartic(x^4 + y^4) sage: quartic.monomials() (y^4, x*y^3, x^2*y^2, x^3*y, x^4) """ @@ -1456,7 +1456,7 @@ def EisensteinD(self): EXAMPLES:: sage: R. = QQ[] - sage: f = a0*x1^4+4*a1*x0*x1^3+6*a2*x0^2*x1^2+4*a3*x0^3*x1+a4*x0^4 + sage: f = a0*x1^4 + 4*a1*x0*x1^3 + 6*a2*x0^2*x1^2 + 4*a3*x0^3*x1 + a4*x0^4 sage: inv = invariant_theory.binary_quartic(f, x0, x1) sage: inv.EisensteinD() 3*a2^2 - 4*a1*a3 + a0*a4 @@ -1485,7 +1485,7 @@ def EisensteinE(self): EXAMPLES:: sage: R. = QQ[] - sage: f = a0*x1^4+4*a1*x0*x1^3+6*a2*x0^2*x1^2+4*a3*x0^3*x1+a4*x0^4 + sage: f = a0*x1^4 + 4*a1*x0*x1^3 + 6*a2*x0^2*x1^2 + 4*a3*x0^3*x1 + a4*x0^4 sage: inv = invariant_theory.binary_quartic(f, x0, x1) sage: inv.EisensteinE() a2^3 - 2*a1*a2*a3 + a0*a3^2 + a1^2*a4 - a0*a2*a4 @@ -1517,7 +1517,7 @@ def g_covariant(self): EXAMPLES:: sage: R. = QQ[] - sage: p = a0*x^4+4*a1*x^3*y+6*a2*x^2*y^2+4*a3*x*y^3+a4*y^4 + sage: p = a0*x^4 + 4*a1*x^3*y + 6*a2*x^2*y^2 + 4*a3*x*y^3 + a4*y^4 sage: inv = invariant_theory.binary_quartic(p, x, y) sage: g = inv.g_covariant(); g a1^2*x^4 - a0*a2*x^4 + 2*a1*a2*x^3*y - 2*a0*a3*x^3*y + 3*a2^2*x^2*y^2 @@ -1568,7 +1568,7 @@ def h_covariant(self): EXAMPLES:: sage: R. = QQ[] - sage: p = a0*x^4+4*a1*x^3*y+6*a2*x^2*y^2+4*a3*x*y^3+a4*y^4 + sage: p = a0*x^4 + 4*a1*x^3*y + 6*a2*x^2*y^2 + 4*a3*x*y^3 + a4*y^4 sage: inv = invariant_theory.binary_quartic(p, x, y) sage: h = inv.h_covariant(); h -2*a1^3*x^6 + 3*a0*a1*a2*x^6 - a0^2*a3*x^6 - 6*a1^2*a2*x^5*y + 9*a0*a2^2*x^5*y @@ -1587,7 +1587,7 @@ def h_covariant(self): + 2*a1*a3*a4*x + a0*a4^2*x + 2*a3^3 - 3*a2*a3*a4 + a1*a4^2 sage: g = inv.g_covariant() - sage: h == 1/8 * (p.derivative(x)*g.derivative(y)-p.derivative(y)*g.derivative(x)) + sage: h == 1/8 * (p.derivative(x)*g.derivative(y) - p.derivative(y)*g.derivative(x)) True """ a0, a1, a2, a3, a4 = self.scaled_coeffs() @@ -1716,7 +1716,7 @@ def monomials(self): EXAMPLES:: sage: R. = QQ[] - sage: quintic = invariant_theory.binary_quintic(x^5+y^5) + sage: quintic = invariant_theory.binary_quintic(x^5 + y^5) sage: quintic.monomials() (y^5, x*y^4, x^2*y^3, x^3*y^2, x^4*y, x^5) """ @@ -2584,7 +2584,7 @@ def monomials(self): EXAMPLES:: sage: R. = QQ[] - sage: quadratic = invariant_theory.ternary_quadratic(x^2+y*z) + sage: quadratic = invariant_theory.ternary_quadratic(x^2 + y*z) sage: quadratic.monomials() (x^2, y^2, z^2, x*y, x*z, y*z) """ @@ -2668,8 +2668,8 @@ def covariant_conic(self, other): EXAMPLES:: sage: ring. = QQ[] - sage: Q = invariant_theory.ternary_quadratic(x^2+y^2+z^2) - sage: R = invariant_theory.ternary_quadratic(x*y+x*z+y*z) + sage: Q = invariant_theory.ternary_quadratic(x^2 + y^2 + z^2) + sage: R = invariant_theory.ternary_quadratic(x*y + x*z + y*z) sage: Q.covariant_conic(R) -x*y - x*z - y*z sage: R.covariant_conic(Q) @@ -2716,7 +2716,7 @@ class TernaryCubic(AlgebraicForm): TESTS:: sage: R. = QQ[] - sage: cubic = invariant_theory.ternary_cubic(x^3+y^3+z^3) + sage: cubic = invariant_theory.ternary_cubic(x^3 + y^3 + z^3) sage: cubic Ternary cubic with coefficients (1, 1, 1, 0, 0, 0, 0, 0, 0, 0) sage: TestSuite(cubic).run() @@ -2850,7 +2850,7 @@ def S_invariant(self): EXAMPLES:: sage: R. = QQ[] - sage: cubic = invariant_theory.ternary_cubic(x^2*y+y^3+z^3+x*y*z) + sage: cubic = invariant_theory.ternary_cubic(x^2*y + y^3 + z^3 + x*y*z) sage: cubic.S_invariant() -1/1296 """ @@ -2871,12 +2871,12 @@ def T_invariant(self): EXAMPLES:: sage: R. = QQ[] - sage: cubic = invariant_theory.ternary_cubic(x^3+y^3+z^3) + sage: cubic = invariant_theory.ternary_cubic(x^3 + y^3 + z^3) sage: cubic.T_invariant() 1 sage: R. = GF(7)[] - sage: cubic = invariant_theory.ternary_cubic(x^3+y^3+z^3+t*x*y*z, [x,y,z]) + sage: cubic = invariant_theory.ternary_cubic(x^3 + y^3 + z^3 + t*x*y*z, [x,y,z]) sage: cubic.T_invariant() -t^6 - t^3 + 1 """ @@ -2972,12 +2972,12 @@ def Hessian(self): EXAMPLES:: sage: R. = QQ[] - sage: cubic = invariant_theory.ternary_cubic(x^3+y^3+z^3) + sage: cubic = invariant_theory.ternary_cubic(x^3 + y^3 + z^3) sage: cubic.Hessian() x*y*z sage: R. = QQ[] - sage: cubic = invariant_theory.ternary_cubic(x^3+y^3+1) + sage: cubic = invariant_theory.ternary_cubic(x^3 + y^3 + 1) sage: cubic.Hessian() x*y """ @@ -3003,12 +3003,12 @@ def Theta_covariant(self): EXAMPLES:: sage: R. = QQ[] - sage: cubic = invariant_theory.ternary_cubic(x^3+y^3+z^3) + sage: cubic = invariant_theory.ternary_cubic(x^3 + y^3 + z^3) sage: cubic.Theta_covariant() -x^3*y^3 - x^3*z^3 - y^3*z^3 sage: R. = QQ[] - sage: cubic = invariant_theory.ternary_cubic(x^3+y^3+1) + sage: cubic = invariant_theory.ternary_cubic(x^3 + y^3 + 1) sage: cubic.Theta_covariant() -x^3*y^3 - x^3 - y^3 @@ -3036,12 +3036,12 @@ def J_covariant(self): EXAMPLES:: sage: R. = QQ[] - sage: cubic = invariant_theory.ternary_cubic(x^3+y^3+z^3) + sage: cubic = invariant_theory.ternary_cubic(x^3 + y^3 + z^3) sage: cubic.J_covariant() x^6*y^3 - x^3*y^6 - x^6*z^3 + y^6*z^3 + x^3*z^6 - y^3*z^6 sage: R. = QQ[] - sage: cubic = invariant_theory.ternary_cubic(x^3+y^3+1) + sage: cubic = invariant_theory.ternary_cubic(x^3 + y^3 + 1) sage: cubic.J_covariant() x^6*y^3 - x^3*y^6 - x^6 + y^6 + x^3 - y^3 """ @@ -3256,7 +3256,7 @@ def homogenized(self, var='h'): EXAMPLES:: sage: R. = QQ[] - sage: q = invariant_theory.quaternary_biquadratic(x^2+1, y^2+1, [x,y,z]) + sage: q = invariant_theory.quaternary_biquadratic(x^2 + 1, y^2 + 1, [x,y,z]) sage: q Joint quaternary quadratic with coefficients (1, 0, 0, 1, 0, 0, 0, 0, 0, 0) and quaternary quadratic with coefficients (0, 1, 0, 1, 0, 0, 0, 0, 0, 0) @@ -3394,7 +3394,8 @@ class TwoTernaryQuadratics(TwoAlgebraicForms): TESTS:: sage: R. = QQ[] - sage: inv = invariant_theory.ternary_biquadratic(x^2+y^2+z^2, x*y+y*z+x*z, [x, y, z]) + sage: inv = invariant_theory.ternary_biquadratic(x^2 + y^2 + z^2, + ....: x*y + y*z + x*z, [x, y, z]) sage: inv Joint ternary quadratic with coefficients (1, 1, 1, 0, 0, 0) and ternary quadratic with coefficients (0, 0, 0, 1, 1, 1) @@ -3451,7 +3452,7 @@ def _Theta_helper(self, scaled_coeffs_1, scaled_coeffs_2): TESTS:: sage: R. = QQ[] - sage: inv = invariant_theory.ternary_biquadratic(x^2 + y*z, x*y+z^2, x, y, z) + sage: inv = invariant_theory.ternary_biquadratic(x^2 + y*z, x*y + z^2, x, y, z) sage: inv._Theta_helper([1]*6, [2]*6) 0 """ @@ -3607,7 +3608,7 @@ class TwoQuaternaryQuadratics(TwoAlgebraicForms): TESTS:: sage: R. = QQ[] - sage: inv = invariant_theory.quaternary_biquadratic(w^2+x^2, y^2+z^2, w, x, y, z) + sage: inv = invariant_theory.quaternary_biquadratic(w^2 + x^2, y^2 + z^2, w, x, y, z) sage: inv Joint quaternary quadratic with coefficients (1, 1, 0, 0, 0, 0, 0, 0, 0, 0) and quaternary quadratic with coefficients (0, 0, 1, 1, 0, 0, 0, 0, 0, 0) @@ -3670,7 +3671,7 @@ def _Theta_helper(self, scaled_coeffs_1, scaled_coeffs_2): TESTS:: sage: R. = QQ[] - sage: inv = invariant_theory.quaternary_biquadratic(w^2+x^2, y^2+z^2, w, x, y, z) + sage: inv = invariant_theory.quaternary_biquadratic(w^2 + x^2, y^2 + z^2, w, x, y, z) sage: inv._Theta_helper([1]*10, [2]*10) 0 """ @@ -4022,10 +4023,10 @@ class InvariantTheoryFactory(): EXAMPLES:: sage: R. = QQ[] - sage: invariant_theory.ternary_cubic(x^3+y^3+z^3) + sage: invariant_theory.ternary_cubic(x^3 + y^3 + z^3) Ternary cubic with coefficients (1, 1, 1, 0, 0, 0, 0, 0, 0, 0) - sage: invariant_theory.ternary_cubic(x^3+y^3+z^3).J_covariant() + sage: invariant_theory.ternary_cubic(x^3 + y^3 + z^3).J_covariant() x^6*y^3 - x^3*y^6 - x^6*z^3 + y^6*z^3 + x^3*z^6 - y^3*z^6 """ @@ -4059,7 +4060,7 @@ def quadratic_form(self, polynomial, *args): EXAMPLES:: sage: R. = QQ[] - sage: quadratic = x^2+y^2+z^2 + sage: quadratic = x^2 + y^2 + z^2 sage: inv = invariant_theory.quadratic_form(quadratic) sage: type(inv) @@ -4068,7 +4069,7 @@ def quadratic_form(self, polynomial, *args): you need to specify the polynomial variables:: sage: R. = QQ[] - sage: quadratic = a*x^2+b*y^2+z^2+2*y*z + sage: quadratic = a*x^2 + b*y^2 + z^2 + 2*y*z sage: invariant_theory.quadratic_form(quadratic, x,y,z) Ternary quadratic with coefficients (a, b, 1, 0, 0, 2) sage: invariant_theory.quadratic_form(quadratic, [x,y,z]) # alternate syntax @@ -4103,11 +4104,11 @@ def inhomogeneous_quadratic_form(self, polynomial, *args): EXAMPLES:: sage: R. = QQ[] - sage: quadratic = x^2+2*y^2+3*x*y+4*x+5*y+6 + sage: quadratic = x^2 + 2*y^2 + 3*x*y + 4*x + 5*y + 6 sage: inv3 = invariant_theory.inhomogeneous_quadratic_form(quadratic) sage: type(inv3) - sage: inv4 = invariant_theory.inhomogeneous_quadratic_form(x^2+y^2+z^2) + sage: inv4 = invariant_theory.inhomogeneous_quadratic_form(x^2 + y^2 + z^2) sage: type(inv4) """ @@ -4136,7 +4137,7 @@ def binary_quadratic(self, quadratic, *args): EXAMPLES:: sage: R. = QQ[] - sage: invariant_theory.binary_quadratic(x^2+y^2) + sage: invariant_theory.binary_quadratic(x^2 + y^2) Binary quadratic with coefficients (1, 1, 0) sage: T. = QQ[] @@ -4164,11 +4165,11 @@ def quaternary_quadratic(self, quadratic, *args): EXAMPLES:: sage: R. = QQ[] - sage: invariant_theory.quaternary_quadratic(w^2+x^2+y^2+z^2) + sage: invariant_theory.quaternary_quadratic(w^2 + x^2 + y^2 + z^2) Quaternary quadratic with coefficients (1, 1, 1, 1, 0, 0, 0, 0, 0, 0) sage: R. = QQ[] - sage: invariant_theory.quaternary_quadratic(1+x^2+y^2+z^2) + sage: invariant_theory.quaternary_quadratic(1 + x^2 + y^2 + z^2) Quaternary quadratic with coefficients (1, 1, 1, 1, 0, 0, 0, 0, 0, 0) """ return QuadraticForm(4, 2, quadratic, *args) @@ -4212,7 +4213,7 @@ def binary_quartic(self, quartic, *args, **kwds): EXAMPLES:: sage: R. = QQ[] - sage: quartic = invariant_theory.binary_quartic(x^4+y^4) + sage: quartic = invariant_theory.binary_quartic(x^4 + y^4) sage: quartic Binary quartic with coefficients (1, 0, 0, 0, 1) sage: type(quartic) @@ -4251,14 +4252,14 @@ def binary_quintic(self, quintic, *args, **kwds): If no variables are provided, they will be guessed:: sage: R. = QQ[] - sage: quintic = invariant_theory.binary_quintic(x^5+y^5) + sage: quintic = invariant_theory.binary_quintic(x^5 + y^5) sage: quintic Binary quintic with coefficients (1, 0, 0, 0, 0, 1) If only one variable is given, the quintic is the homogenisation of the provided polynomial:: - sage: quintic = invariant_theory.binary_quintic(x^5+y^5, x) + sage: quintic = invariant_theory.binary_quintic(x^5 + y^5, x) sage: quintic Binary quintic with coefficients (y^5, 0, 0, 0, 0, 1) sage: quintic.is_homogeneous() @@ -4268,11 +4269,11 @@ def binary_quintic(self, quintic, *args, **kwds): specified:: sage: R. = QQ[] - sage: quintic = invariant_theory.binary_quintic(x^5+z*y^5) + sage: quintic = invariant_theory.binary_quintic(x^5 + z*y^5) Traceback (most recent call last): ... ValueError: need 2 or 1 variables, got (x, y, z) - sage: quintic = invariant_theory.binary_quintic(x^5+z*y^5, x, y) + sage: quintic = invariant_theory.binary_quintic(x^5 + z*y^5, x, y) sage: quintic Binary quintic with coefficients (z, 0, 0, 0, 0, 1) @@ -4342,12 +4343,13 @@ def binary_form_from_invariants(self, degree, invariants, variables=None, as_for Binary quintic with coefficients (-37725479487783/1048576, 565882192316745/8388608, 0, 1033866765362693115/67108864, 12849486940936328715/268435456, -23129076493685391687/2147483648) - sage: invariant_theory.binary_form_from_invariants(5, invariants, scaling='normalized') + sage: invariant_theory.binary_form_from_invariants(5, invariants, + ....: scaling='normalized') Binary quintic with coefficients (24389/892616806656, 4205/11019960576, 0, 1015/209952, -145/1296, -3/16) - sage: invariant_theory.binary_form_from_invariants(5, invariants, scaling='coprime') - Binary quintic with coefficients (-2048, 3840, 0, 876960, 2724840, - -613089) + sage: invariant_theory.binary_form_from_invariants(5, invariants, + ....: scaling='coprime') + Binary quintic with coefficients (-2048, 3840, 0, 876960, 2724840, -613089) The invariants can also be computed using the invariants of a given binary quintic. The resulting form has the same invariants up to scaling, is @@ -4359,7 +4361,8 @@ def binary_form_from_invariants(self, degree, invariants, variables=None, as_for sage: p = 3*x1^5 + 6*x1^4*x0 + 3*x1^3*x0^2 + 4*x1^2*x0^3 - 5*x1*x0^4 + 4*x0^5 sage: quintic = invariant_theory.binary_quintic(p, x0, x1) sage: invariants = quintic.clebsch_invariants(as_tuple=True) - sage: newquintic = invariant_theory.binary_form_from_invariants(5, invariants, variables=quintic.variables()) + sage: newquintic = invariant_theory.binary_form_from_invariants( + ....: 5, invariants, variables=quintic.variables()) sage: newquintic Binary quintic with coefficients (9592267437341790539005557/244140625000000, 2149296928207625556323004064707/610351562500000000, @@ -4468,14 +4471,14 @@ def ternary_quadratic(self, quadratic, *args, **kwds): EXAMPLES:: sage: R. = QQ[] - sage: invariant_theory.ternary_quadratic(x^2+y^2+z^2) + sage: invariant_theory.ternary_quadratic(x^2 + y^2 + z^2) Ternary quadratic with coefficients (1, 1, 1, 0, 0, 0) sage: T. = QQ[] - sage: invariant_theory.ternary_quadratic(1+u^2+v^2) + sage: invariant_theory.ternary_quadratic(1 + u^2 + v^2) Ternary quadratic with coefficients (1, 1, 1, 0, 0, 0) - sage: quadratic = x^2+y^2+z^2 + sage: quadratic = x^2 + y^2 + z^2 sage: inv = invariant_theory.ternary_quadratic(quadratic) sage: type(inv) @@ -4540,7 +4543,7 @@ def ternary_cubic(self, cubic, *args, **kwds): EXAMPLES:: sage: R. = QQ[] - sage: cubic = invariant_theory.ternary_cubic(x^3+y^3+z^3) + sage: cubic = invariant_theory.ternary_cubic(x^3 + y^3 + z^3) sage: type(cubic) """ @@ -4562,7 +4565,7 @@ def ternary_biquadratic(self, quadratic1, quadratic2, *args, **kwds): EXAMPLES:: sage: R. = QQ[] - sage: q1 = x^2+y^2+z^2 + sage: q1 = x^2 + y^2 + z^2 sage: q2 = x*y + y*z + x*z sage: inv = invariant_theory.ternary_biquadratic(q1, q2) sage: type(inv) @@ -4616,7 +4619,7 @@ def quaternary_biquadratic(self, quadratic1, quadratic2, *args, **kwds): EXAMPLES:: sage: R. = QQ[] - sage: q1 = w^2+x^2+y^2+z^2 + sage: q1 = w^2 + x^2 + y^2 + z^2 sage: q2 = w*x + y*z sage: inv = invariant_theory.quaternary_biquadratic(q1, q2) sage: type(inv) diff --git a/src/sage/rings/invariants/reconstruction.py b/src/sage/rings/invariants/reconstruction.py index 99941d306b8..4619bf777f1 100644 --- a/src/sage/rings/invariants/reconstruction.py +++ b/src/sage/rings/invariants/reconstruction.py @@ -41,7 +41,7 @@ def binary_quadratic_coefficients_from_invariants(discriminant, invariant_choice EXAMPLES:: sage: from sage.rings.invariants.reconstruction import binary_quadratic_coefficients_from_invariants - sage: quadratic = invariant_theory.binary_form_from_invariants(2, [24]) # indirect doctest + sage: quadratic = invariant_theory.binary_form_from_invariants(2, [24]) # indirect doctest sage: quadratic Binary quadratic with coefficients (1, -6, 0) sage: quadratic.discriminant() @@ -142,7 +142,8 @@ def binary_quintic_coefficients_from_invariants(invariants, K=None, invariant_ch sage: p = 3*x1^5 + 6*x1^4*x0 + 3*x1^3*x0^2 + 4*x1^2*x0^3 - 5*x1*x0^4 + 4*x0^5 sage: quintic = invariant_theory.binary_quintic(p, x0, x1) sage: invs = quintic.clebsch_invariants(as_tuple=True) - sage: reconstructed = invariant_theory.binary_form_from_invariants(5, invs, variables=quintic.variables()) # indirect doctest + sage: reconstructed = invariant_theory.binary_form_from_invariants( # indirect doctest + ....: 5, invs, variables=quintic.variables()) sage: reconstructed Binary quintic with coefficients (9592267437341790539005557/244140625000000, 2149296928207625556323004064707/610351562500000000, @@ -167,8 +168,10 @@ def binary_quintic_coefficients_from_invariants(invariants, K=None, invariant_ch sage: alpha = quintic.alpha_covariant() sage: beta = quintic.beta_covariant() - sage: g = matrix([[alpha(x0=1,x1=0),alpha(x0=0,x1=1)],[beta(x0=1,x1=0),beta(x0=0,x1=1)]])^-1 - sage: transformed = tuple([g.determinant()^-5*x for x in quintic.transformed(g).coeffs()]) + sage: g = matrix([[alpha(x0=1,x1=0), alpha(x0=0,x1=1)], + ....: [beta(x0=1,x1=0), beta(x0=0,x1=1)]])^-1 + sage: transformed = tuple([g.determinant()^-5*x + ....: for x in quintic.transformed(g).coeffs()]) sage: transformed == reconstructed.coeffs() True @@ -231,7 +234,8 @@ def binary_quintic_coefficients_from_invariants(invariants, K=None, invariant_ch sage: binary_quintic_coefficients_from_invariants([3,1,2], K=GF(5)) Traceback (most recent call last): ... - NotImplementedError: no reconstruction of binary quintics implemented for fields of characteristic 2, 3 or 5 + NotImplementedError: no reconstruction of binary quintics implemented + for fields of characteristic 2, 3 or 5 TESTS:: diff --git a/src/sage/rings/laurent_series_ring.py b/src/sage/rings/laurent_series_ring.py index 56551b50a55..db88e7e53a7 100644 --- a/src/sage/rings/laurent_series_ring.py +++ b/src/sage/rings/laurent_series_ring.py @@ -6,11 +6,11 @@ sage: R = LaurentSeriesRing(QQ, "x") sage: R.base_ring() Rational Field - sage: S = LaurentSeriesRing(GF(17)['x'], 'y') - sage: S - Laurent Series Ring in y over Univariate Polynomial Ring in x over - Finite Field of size 17 - sage: S.base_ring() + sage: S = LaurentSeriesRing(GF(17)['x'], 'y') # optional - sage.rings.finite_rings + sage: S # optional - sage.rings.finite_rings + Laurent Series Ring in y over + Univariate Polynomial Ring in x over Finite Field of size 17 + sage: S.base_ring() # optional - sage.rings.finite_rings Univariate Polynomial Ring in x over Finite Field of size 17 .. SEEALSO:: @@ -74,7 +74,7 @@ class LaurentSeriesRing(UniqueRepresentation, CommutativeRing): sage: R = LaurentSeriesRing(QQ, 'x'); R Laurent Series Ring in x over Rational Field sage: x = R.0 - sage: g = 1 - x + x^2 - x^4 +O(x^8); g + sage: g = 1 - x + x^2 - x^4 + O(x^8); g 1 - x + x^2 - x^4 + O(x^8) sage: g = 10*x^(-3) + 2006 - 19*x + x^2 - x^4 +O(x^8); g 10*x^-3 + 2006 - 19*x + x^2 - x^4 + O(x^8) @@ -84,7 +84,7 @@ class LaurentSeriesRing(UniqueRepresentation, CommutativeRing): sage: Frac(QQ[['x']]) Laurent Series Ring in x over Rational Field - sage: Frac(GF(5)['y']) + sage: Frac(GF(5)['y']) # optional - sage.rings.finite_rings Fraction Field of Univariate Polynomial Ring in y over Finite Field of size 5 When the base ring is a domain, the fraction field is the @@ -96,17 +96,17 @@ class LaurentSeriesRing(UniqueRepresentation, CommutativeRing): Laurent series rings are determined by their variable and the base ring, and are globally unique:: - sage: K = Qp(5, prec = 5) - sage: L = Qp(5, prec = 200) - sage: R. = LaurentSeriesRing(K) - sage: S. = LaurentSeriesRing(L) - sage: R is S + sage: K = Qp(5, prec=5) # optional - sage.rings.padics + sage: L = Qp(5, prec=200) # optional - sage.rings.padics + sage: R. = LaurentSeriesRing(K) # optional - sage.rings.padics + sage: S. = LaurentSeriesRing(L) # optional - sage.rings.padics + sage: R is S # optional - sage.rings.padics False - sage: T. = LaurentSeriesRing(Qp(5,prec=200)) - sage: S is T + sage: T. = LaurentSeriesRing(Qp(5, prec=200)) # optional - sage.rings.padics + sage: S is T # optional - sage.rings.padics True - sage: W. = LaurentSeriesRing(Qp(5,prec=199)) - sage: W is T + sage: W. = LaurentSeriesRing(Qp(5, prec=199)) # optional - sage.rings.padics + sage: W is T # optional - sage.rings.padics False sage: K = LaurentSeriesRing(CC, 'q') @@ -122,11 +122,15 @@ class LaurentSeriesRing(UniqueRepresentation, CommutativeRing): a field equipped with a discrete valuation for which it is complete. The appropriate (sub)category is automatically set in this case:: - sage: k = GF(11) - sage: R. = k[[]] - sage: F = Frac(R) - sage: F.category() - Join of Category of complete discrete valuation fields and Category of commutative algebras over (finite enumerated fields and subquotients of monoids and quotients of semigroups) and Category of infinite sets + sage: k = GF(11) # optional - sage.rings.finite_rings + sage: R. = k[[]] # optional - sage.rings.finite_rings + sage: F = Frac(R) # optional - sage.rings.finite_rings + sage: F.category() # optional - sage.rings.finite_rings + Join of + Category of complete discrete valuation fields and + Category of commutative algebras over (finite enumerated fields and + subquotients of monoids and quotients of semigroups) and + Category of infinite sets sage: TestSuite(F).run() TESTS: @@ -147,11 +151,14 @@ class LaurentSeriesRing(UniqueRepresentation, CommutativeRing): Check categories (:trac:`24420`):: sage: LaurentSeriesRing(ZZ, 'x').category() - Category of infinite commutative no zero divisors algebras over (euclidean domains and infinite enumerated sets and metric spaces) + Category of infinite commutative no zero divisors algebras + over (euclidean domains and infinite enumerated sets and metric spaces) sage: LaurentSeriesRing(QQ, 'x').category() - Join of Category of complete discrete valuation fields and Category of commutative algebras over (number fields and quotient fields and metric spaces) and Category of infinite sets + Join of Category of complete discrete valuation fields and Category of commutative algebras + over (number fields and quotient fields and metric spaces) and Category of infinite sets sage: LaurentSeriesRing(Zmod(4), 'x').category() - Category of infinite commutative algebras over (finite commutative rings and subquotients of monoids and quotients of semigroups and finite enumerated sets) + Category of infinite commutative algebras + over (finite commutative rings and subquotients of monoids and quotients of semigroups and finite enumerated sets) Check coercions (:trac:`24431`):: @@ -215,27 +222,34 @@ def __init__(self, power_series): sage: RZZ = LaurentSeriesRing(ZZ, 't') sage: RZZ.category() - Category of infinite commutative no zero divisors algebras over (euclidean domains and infinite enumerated sets and metric spaces) + Category of infinite commutative no zero divisors algebras + over (euclidean domains and infinite enumerated sets and metric spaces) sage: TestSuite(RZZ).run() sage: R1 = LaurentSeriesRing(Zmod(1), 't') sage: R1.category() - Category of finite commutative algebras over (finite commutative rings and subquotients of monoids and quotients of semigroups and finite enumerated sets) + Category of finite commutative algebras + over (finite commutative rings and subquotients of monoids and quotients of semigroups and finite enumerated sets) sage: TestSuite(R1).run() sage: R2 = LaurentSeriesRing(Zmod(2), 't') sage: R2.category() - Join of Category of complete discrete valuation fields and Category of commutative algebras over (finite enumerated fields and subquotients of monoids and quotients of semigroups) and Category of infinite sets + Join of Category of complete discrete valuation fields + and Category of commutative algebras over (finite enumerated fields and subquotients of monoids and quotients of semigroups) + and Category of infinite sets sage: TestSuite(R2).run() sage: R4 = LaurentSeriesRing(Zmod(4), 't') sage: R4.category() - Category of infinite commutative algebras over (finite commutative rings and subquotients of monoids and quotients of semigroups and finite enumerated sets) + Category of infinite commutative algebras + over (finite commutative rings and subquotients of monoids and quotients of semigroups and finite enumerated sets) sage: TestSuite(R4).run() sage: RQQ = LaurentSeriesRing(QQ, 't') sage: RQQ.category() - Join of Category of complete discrete valuation fields and Category of commutative algebras over (number fields and quotient fields and metric spaces) and Category of infinite sets + Join of Category of complete discrete valuation fields + and Category of commutative algebras over (number fields and quotient fields and metric spaces) + and Category of infinite sets sage: TestSuite(RQQ).run() """ base_ring = power_series.base_ring() @@ -361,9 +375,9 @@ def _repr_(self): """ EXAMPLES:: - sage: LaurentSeriesRing(QQ,'q') # indirect doctest + sage: LaurentSeriesRing(QQ, 'q') # indirect doctest Laurent Series Ring in q over Rational Field - sage: LaurentSeriesRing(ZZ,'t',sparse=True) + sage: LaurentSeriesRing(ZZ, 't', sparse=True) Sparse Laurent Series Ring in t over Integer Ring """ s = "Laurent Series Ring in %s over %s" % (self.variable_name(), self.base_ring()) @@ -386,35 +400,35 @@ def _element_constructor_(self, x, n=0, prec=infinity): EXAMPLES:: - sage: R. = LaurentSeriesRing(Qp(5, 10)) - sage: S. = LaurentSeriesRing(RationalField()) - sage: R(t + t^2 + O(t^3)) + sage: R. = LaurentSeriesRing(Qp(5, 10)) # optional - sage.rings.padics + sage: S. = LaurentSeriesRing(RationalField()) # optional - sage.rings.padics + sage: R(t + t^2 + O(t^3)) # optional - sage.rings.padics (1 + O(5^10))*u + (1 + O(5^10))*u^2 + O(u^3) - sage: R(t + t^2 + O(t^3), prec=2) + sage: R(t + t^2 + O(t^3), prec=2) # optional - sage.rings.padics (1 + O(5^10))*u + O(u^2) Coercing an element into its own parent produces that element again, unless a different ``n`` or ``prec`` is given:: - sage: u is R(u) + sage: u is R(u) # optional - sage.rings.padics True - sage: R(u, n=3, prec=7) + sage: R(u, n=3, prec=7) # optional - sage.rings.padics (1 + O(5^10))*u^4 + O(u^7) Rational functions are accepted:: - sage: I = sqrt(-1) - sage: K. = QQ[I] - sage: P. = PolynomialRing(K) - sage: L. = LaurentSeriesRing(QQ[I]) - sage: L((t*I)/(t^3+I*2*t)) + sage: I = sqrt(-1) # optional - sage.rings.number_field sage.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 1/2 + 1/4*I*u^2 - 1/8*u^4 - 1/16*I*u^6 + 1/32*u^8 + 1/64*I*u^10 - 1/128*u^12 - 1/256*I*u^14 + 1/512*u^16 + 1/1024*I*u^18 + O(u^20) :: - sage: L(t*I) / L(t^3+I*2*t) + sage: L(t*I) / L(t^3+I*2*t) # optional - sage.rings.number_field 1/2 + 1/4*I*u^2 - 1/8*u^4 - 1/16*I*u^6 + 1/32*u^8 + 1/64*I*u^10 - 1/128*u^12 - 1/256*I*u^14 + 1/512*u^16 + 1/1024*I*u^18 + O(u^20) @@ -440,23 +454,23 @@ def _element_constructor_(self, x, n=0, prec=infinity): Various conversions from PARI (see also :trac:`2508`):: sage: L. = LaurentSeriesRing(QQ, default_prec=10) - sage: L(pari('1/x')) + sage: L(pari('1/x')) # optional - sage.libs.pari q^-1 - sage: L(pari('polchebyshev(5)')) + sage: L(pari('polchebyshev(5)')) # optional - sage.libs.pari 5*q - 20*q^3 + 16*q^5 - sage: L(pari('polchebyshev(5) - 1/x^4')) + sage: L(pari('polchebyshev(5) - 1/x^4')) # optional - sage.libs.pari -q^-4 + 5*q - 20*q^3 + 16*q^5 - sage: L(pari('1/polchebyshev(5)')) + sage: L(pari('1/polchebyshev(5)')) # optional - sage.libs.pari 1/5*q^-1 + 4/5*q + 64/25*q^3 + 192/25*q^5 + 2816/125*q^7 + O(q^9) - sage: L(pari('polchebyshev(5) + O(x^40)')) + sage: L(pari('polchebyshev(5) + O(x^40)')) # optional - sage.libs.pari 5*q - 20*q^3 + 16*q^5 + O(q^40) - sage: L(pari('polchebyshev(5) - 1/x^4 + O(x^40)')) + sage: L(pari('polchebyshev(5) - 1/x^4 + O(x^40)')) # optional - sage.libs.pari -q^-4 + 5*q - 20*q^3 + 16*q^5 + O(q^40) - sage: L(pari('1/polchebyshev(5) + O(x^10)')) + sage: L(pari('1/polchebyshev(5) + O(x^10)')) # optional - sage.libs.pari 1/5*q^-1 + 4/5*q + 64/25*q^3 + 192/25*q^5 + 2816/125*q^7 + 8192/125*q^9 + O(q^10) - sage: L(pari('1/polchebyshev(5) + O(x^10)'), -10) # Multiply by q^-10 + sage: L(pari('1/polchebyshev(5) + O(x^10)'), -10) # Multiply by q^-10 # optional - sage.libs.pari 1/5*q^-11 + 4/5*q^-9 + 64/25*q^-7 + 192/25*q^-5 + 2816/125*q^-3 + 8192/125*q^-1 + O(1) - sage: L(pari('O(x^-10)')) + sage: L(pari('O(x^-10)')) # optional - sage.libs.pari O(q^-10) Check that :trac:`30073` is fixed:: @@ -522,8 +536,8 @@ def random_element(self, algorithm='default'): EXAMPLES:: - sage: S. = LaurentSeriesRing(GF(3)) - sage: S.random_element() # random + sage: S. = LaurentSeriesRing(GF(3)) # optional - sage.rings.finite_rings + sage: S.random_element() # random # optional - sage.rings.finite_rings s^-8 + s^-7 + s^-6 + s^-5 + s^-1 + s + s^3 + s^4 + s^5 + 2*s^6 + s^7 + s^11 + O(s^12) """ @@ -559,9 +573,9 @@ def construction(self): sage: parent(1/2 * t) Laurent Series Ring in t over Rational Field - sage: QQbar.gen() * t + sage: QQbar.gen() * t # optional - sage.rings.number_field I*t - sage: parent(QQbar.gen() * t) + sage: parent(QQbar.gen() * t) # optional - sage.rings.number_field Laurent Series Ring in t over Algebraic Field """ from sage.categories.pushout import CompletionFunctor @@ -637,14 +651,15 @@ def _is_valid_homomorphism_(self, codomain, im_gens, base_map=None): """ EXAMPLES:: - sage: R. = LaurentSeriesRing(GF(17)) - sage: S. = LaurentSeriesRing(GF(19)) - sage: R.hom([y], S) # indirect doctest + sage: R. = LaurentSeriesRing(GF(17)) # optional - sage.rings.finite_rings + sage: S. = LaurentSeriesRing(GF(19)) # optional - sage.rings.finite_rings + sage: R.hom([y], S) # indirect doctest # optional - sage.rings.finite_rings Traceback (most recent call last): ... - ValueError: relations do not all (canonically) map to 0 under map determined by images of generators - sage: f = R.hom(x+x^3,R) - sage: f(x^2) + ValueError: relations do not all (canonically) map to 0 + under map determined by images of generators + sage: f = R.hom(x + x^3, R) # optional - sage.rings.finite_rings + sage: f(x^2) # optional - sage.rings.finite_rings x^2 + 2*x^4 + x^6 The image of the generator needs to be a unit:: @@ -671,8 +686,8 @@ def characteristic(self): """ EXAMPLES:: - sage: R. = LaurentSeriesRing(GF(17)) - sage: R.characteristic() + sage: R. = LaurentSeriesRing(GF(17)) # optional - sage.rings.finite_rings + sage: R.characteristic() # optional - sage.rings.finite_rings 17 """ return self.base_ring().characteristic() @@ -686,8 +701,8 @@ def residue_field(self): EXAMPLES:: - sage: R. = LaurentSeriesRing(GF(17)) - sage: R.residue_field() + sage: R. = LaurentSeriesRing(GF(17)) # optional - sage.rings.finite_rings + sage: R.residue_field() # optional - sage.rings.finite_rings Finite Field of size 17 sage: R. = LaurentSeriesRing(ZZ) diff --git a/src/sage/rings/laurent_series_ring_element.pyx b/src/sage/rings/laurent_series_ring_element.pyx index b11989eafbe..8d98c35ddbb 100644 --- a/src/sage/rings/laurent_series_ring_element.pyx +++ b/src/sage/rings/laurent_series_ring_element.pyx @@ -3,16 +3,16 @@ Laurent Series EXAMPLES:: - sage: R. = LaurentSeriesRing(GF(7), 't'); R + sage: R. = LaurentSeriesRing(GF(7), 't'); R # optional - sage.rings.finite_rings Laurent Series Ring in t over Finite Field of size 7 - sage: f = 1/(1-t+O(t^10)); f + sage: f = 1/(1-t+O(t^10)); f # optional - sage.rings.finite_rings 1 + t + t^2 + t^3 + t^4 + t^5 + t^6 + t^7 + t^8 + t^9 + O(t^10) Laurent series are immutable:: - sage: f[2] + sage: f[2] # optional - sage.rings.finite_rings 1 - sage: f[2] = 5 + sage: f[2] = 5 # optional - sage.rings.finite_rings Traceback (most recent call last): ... IndexError: Laurent series are immutable @@ -112,18 +112,18 @@ cdef class LaurentSeries(AlgebraElement): sage: R. = LaurentSeriesRing(ZZ) sage: R([1,2,3]) 1 + 2*q + 3*q^2 - sage: R([1,2,3],-5) + sage: R([1,2,3], -5) q^-5 + 2*q^-4 + 3*q^-3 :: - sage: S. = LaurentSeriesRing(GF(5)) - sage: T. = PowerSeriesRing(pAdicRing(5)) - sage: S(t) + sage: S. = LaurentSeriesRing(GF(5)) # optional - sage.rings.finite_rings sage.rings.padics + sage: T. = PowerSeriesRing(pAdicRing(5)) # optional - sage.rings.finite_rings sage.rings.padics + sage: S(t) # optional - sage.rings.finite_rings sage.rings.padics s - sage: parent(S(t)) + sage: parent(S(t)) # optional - sage.rings.finite_rings sage.rings.padics Laurent Series Ring in s over Finite Field of size 5 - sage: parent(S(t)[1]) + sage: parent(S(t)[1]) # optional - sage.rings.finite_rings sage.rings.padics Finite Field of size 5 """ AlgebraElement.__init__(self, parent) @@ -185,7 +185,7 @@ cdef class LaurentSeries(AlgebraElement): sage: R. = LaurentSeriesRing(ZZ) sage: p = R([1,2,3]); p 1 + 2*q + 3*q^2 - sage: p.change_ring(GF(2)) + sage: p.change_ring(GF(2)) # optional - sage.rings.finite_rings 1 + q^2 """ return self._parent.change_ring(R)(self) @@ -197,9 +197,9 @@ cdef class LaurentSeries(AlgebraElement): EXAMPLES:: sage: R. = LaurentSeriesRing(QQ) - sage: (2+t).is_unit() + sage: (2 + t).is_unit() True - sage: f = 2+t^2+O(t^10); f.is_unit() + sage: f = 2 + t^2 + O(t^10); f.is_unit() True sage: 1/f 1/2 - 1/4*t^2 + 1/8*t^4 - 1/16*t^6 + 1/32*t^8 + O(t^10) @@ -235,7 +235,7 @@ cdef class LaurentSeries(AlgebraElement): def is_monomial(self): """ - Return True if this element is a monomial. That is, if self is + Return ``True`` if this element is a monomial. That is, if self is `x^n` for some integer `n`. EXAMPLES:: @@ -288,16 +288,16 @@ cdef class LaurentSeries(AlgebraElement): EXAMPLES:: sage: Zx. = ZZ[] - sage: K. = NumberField(x^2 + 1) - sage: R. = LaurentSeriesRing(K) - sage: z = t^-1 + i*t - sage: z._im_gens_(R, [t^2]) + sage: K. = NumberField(x^2 + 1) # optional - sage.rings.number_field + sage: R. = LaurentSeriesRing(K) # optional - sage.rings.number_field + sage: z = t^-1 + i*t # optional - sage.rings.number_field + sage: z._im_gens_(R, [t^2]) # optional - sage.rings.number_field t^-2 + i*t^2 The argument base_map is not yet supported, because it isn't over power series:: - sage: cc = K.hom([i]) - sage: z._im_gens_(R, [t^2], base_map=cc) + sage: cc = K.hom([i]) # optional - sage.rings.number_field + sage: z._im_gens_(R, [t^2], base_map=cc) # optional - sage.rings.number_field Traceback (most recent call last): ... NotImplementedError @@ -442,9 +442,9 @@ cdef class LaurentSeries(AlgebraElement): Verify that :trac:`6656` has been fixed:: - sage: R.=PolynomialRing(QQ) - sage: T.=LaurentSeriesRing(R) - sage: y = a*x+b*x + sage: R. = PolynomialRing(QQ) + sage: T. = LaurentSeriesRing(R) + sage: y = a*x + b*x sage: y._latex_() '\\left(a + b\\right)x' sage: latex(y) @@ -616,10 +616,10 @@ cdef class LaurentSeries(AlgebraElement): EXAMPLES:: sage: t = LaurentSeriesRing(ZZ,'t').gen() - sage: f = 1/t**2+2/t+3+4*t + sage: f = 1/t**2 + 2/t + 3 + 4*t sage: f.residue() 2 - sage: f = t+t**2 + sage: f = t + t**2 sage: f.residue() 0 sage: f.residue().parent() @@ -671,11 +671,11 @@ cdef class LaurentSeries(AlgebraElement): EXAMPLES:: - sage: A. = LaurentSeriesRing(GF(5)) - sage: x = t^(-1) + t^2 + O(t^5) - sage: x.lift_to_precision(10) + sage: A. = LaurentSeriesRing(GF(5)) # optional - sage.rings.finite_rings + sage: x = t^(-1) + t^2 + O(t^5) # optional - sage.rings.finite_rings + sage: x.lift_to_precision(10) # optional - sage.rings.finite_rings t^-1 + t^2 + O(t^10) - sage: x.lift_to_precision() + sage: x.lift_to_precision() # optional - sage.rings.finite_rings t^-1 + t^2 """ if absprec is not None and absprec <= self.precision_absolute(): @@ -1028,7 +1028,8 @@ cdef class LaurentSeries(AlgebraElement): sage: A. = LaurentSeriesRing(ZZ) sage: f = 1/(1-x) sage: f - 1 + x + x^2 + x^3 + x^4 + x^5 + x^6 + x^7 + x^8 + x^9 + x^10 + x^11 + x^12 + x^13 + x^14 + x^15 + x^16 + x^17 + x^18 + x^19 + O(x^20) + 1 + x + x^2 + x^3 + x^4 + x^5 + x^6 + x^7 + x^8 + x^9 + x^10 + x^11 + + x^12 + x^13 + x^14 + x^15 + x^16 + x^17 + x^18 + x^19 + O(x^20) sage: f.truncate(10) 1 + x + x^2 + x^3 + x^4 + x^5 + x^6 + x^7 + x^8 + x^9 """ @@ -1046,7 +1047,8 @@ cdef class LaurentSeries(AlgebraElement): sage: A. = LaurentSeriesRing(ZZ) sage: f = 1/(1-x) sage: f - 1 + x + x^2 + x^3 + x^4 + x^5 + x^6 + x^7 + x^8 + x^9 + x^10 + x^11 + x^12 + x^13 + x^14 + x^15 + x^16 + x^17 + x^18 + x^19 + O(x^20) + 1 + x + x^2 + x^3 + x^4 + x^5 + x^6 + x^7 + x^8 + x^9 + x^10 + x^11 + + x^12 + x^13 + x^14 + x^15 + x^16 + x^17 + x^18 + x^19 + O(x^20) sage: f.truncate_laurentseries(10) 1 + x + x^2 + x^3 + x^4 + x^5 + x^6 + x^7 + x^8 + x^9 + O(x^10) """ @@ -1489,8 +1491,11 @@ cdef class LaurentSeries(AlgebraElement): ring:: sage: R. = LaurentSeriesRing(QQ, default_prec=20) - sage: (x - x^2).reverse() # get some Catalan numbers - x + x^2 + 2*x^3 + 5*x^4 + 14*x^5 + 42*x^6 + 132*x^7 + 429*x^8 + 1430*x^9 + 4862*x^10 + 16796*x^11 + 58786*x^12 + 208012*x^13 + 742900*x^14 + 2674440*x^15 + 9694845*x^16 + 35357670*x^17 + 129644790*x^18 + 477638700*x^19 + O(x^20) + sage: (x - x^2).reverse() # get some Catalan numbers + x + x^2 + 2*x^3 + 5*x^4 + 14*x^5 + 42*x^6 + 132*x^7 + 429*x^8 + 1430*x^9 + + 4862*x^10 + 16796*x^11 + 58786*x^12 + 208012*x^13 + 742900*x^14 + + 2674440*x^15 + 9694845*x^16 + 35357670*x^17 + 129644790*x^18 + + 477638700*x^19 + O(x^20) sage: (x - x^2).reverse(precision=3) x + x^2 + O(x^3) @@ -1743,10 +1748,10 @@ cdef class LaurentSeries(AlgebraElement): Check whether a polynomial over a Laurent series ring is contained in the polynomial ring over the power series ring (see :trac:`19459`): - sage: L. = LaurentSeriesRing(GF(2)) - sage: R. = PolynomialRing(L) - sage: S. = PolynomialRing(L._power_series_ring) - sage: t**(-1)*x*y in S + sage: L. = LaurentSeriesRing(GF(2)) # optional - sage.rings.finite_rings + sage: R. = PolynomialRing(L) # optional - sage.rings.finite_rings + sage: S. = PolynomialRing(L._power_series_ring) # optional - sage.rings.finite_rings + sage: t**(-1)*x*y in S # optional - sage.rings.finite_rings False There used to be an issue with non-canonical representations of zero, @@ -1766,8 +1771,8 @@ cdef class LaurentSeries(AlgebraElement): Test for :trac:`32440`:: - sage: L. = LaurentSeriesRing(QQ, implementation='pari') - sage: (x + O(x^3)).power_series() + sage: L. = LaurentSeriesRing(QQ, implementation='pari') # optional - sage.libs.pari + sage: (x + O(x^3)).power_series() # optional - sage.libs.pari x + O(x^3) """ if self.__n < 0: @@ -1808,13 +1813,13 @@ cdef class LaurentSeries(AlgebraElement): x*t^-2 + O(t^2) sage: f(y=x) x*t^-2 + x*t^2 + O(t^8) - sage: f(t^3, x=2, y=x+x^2) + sage: f(t^3, x=2, y=x + x^2) 2*t^-6 + (x^2 + x)*t^6 + O(t^24) sage: f(t^3, 2, x+x^2) 2*t^-6 + (x^2 + x)*t^6 + O(t^24) - sage: f(x=2, t=t^3, y=x+x^2) + sage: f(x=2, t=t^3, y=x + x^2) 2*t^-6 + (x^2 + x)*t^6 + O(t^24) - sage: f(2, x+x^2, t=t^3) + sage: f(2, x + x^2, t=t^3) Traceback (most recent call last): ... ValueError: must not specify t keyword and positional argument @@ -1828,9 +1833,9 @@ cdef class LaurentSeries(AlgebraElement): Test for :trac:`23928`:: - sage: R. = LaurentSeriesRing(QQ, implementation='pari') - sage: f = x.add_bigoh(7) - sage: f(x) + sage: R. = LaurentSeriesRing(QQ, implementation='pari') # optional - sage.libs.pari + sage: f = x.add_bigoh(7) # optional - sage.libs.pari + sage: f(x) # optional - sage.libs.pari x + O(x^7) """ if len(kwds) >= 1: @@ -1870,16 +1875,16 @@ cdef class LaurentSeries(AlgebraElement): sage: L. = LaurentSeriesRing(QQ) sage: f = x + 1/x + O(x^2); f x^-1 + x + O(x^2) - sage: f.__pari__() + sage: f.__pari__() # optional - sage.libs.pari x^-1 + x + O(x^2) Check that :trac:`32437` is fixed:: - sage: F. = GF(257^2) - sage: R. = LaurentSeriesRing(F) - sage: g = t + O(t^99) - sage: f = u*t + O(t^99) - sage: g(f) # indirect doctest + sage: F. = GF(257^2) # optional - sage.rings.finite_rings + sage: R. = LaurentSeriesRing(F) # optional - sage.rings.finite_rings + sage: g = t + O(t^99) # optional - sage.rings.finite_rings + sage: f = u*t + O(t^99) # optional - sage.rings.finite_rings + sage: g(f) # indirect doctest # optional - sage.libs.pari sage.rings.finite_rings u*t + O(t^99) """ f = self.__u diff --git a/src/sage/rings/lazy_series.py b/src/sage/rings/lazy_series.py index f31488d5354..0ee2d591177 100644 --- a/src/sage/rings/lazy_series.py +++ b/src/sage/rings/lazy_series.py @@ -1186,7 +1186,7 @@ def define(self, s): sage: F.define(1 + g*F) sage: F[:16] [1, 1, 1, 2, 1, 3, 1, 4, 2, 3, 1, 8, 1, 3, 3] - sage: oeis(_) # optional, internet + sage: oeis(_) # optional - internet 0: A002033: Number of perfect partitions of n. 1: A074206: Kalmár's [Kalmar's] problem: number of ordered factorizations of n. ... @@ -1275,7 +1275,7 @@ def define(self, s): sage: f 1 + 1/(2^s) - 1/(4^s) + O(1/(8^s)) - sage: oeis(f[:30]) # optional, internet + sage: oeis(f[:30]) # optional - internet 0: A122698: a(1)=a(2)=1 then a(n) = Sum_{d|n, 1 3 u1 |--> 5 u2 |--> 7 q |--> 11 - sage: mFp1 = matrix({k:f(v) for k, v in m1.dict().items()}); mFp1 + sage: mFp1 = matrix({k: f(v) for k, v in m1.dict().items()}); mFp1 # optional - sage.modules sage.rings.finite_rings [5 0 0] [0 3 0] [0 0 3] - sage: mFp1.base_ring() + sage: mFp1.base_ring() # optional - sage.modules sage.rings.finite_rings Finite Field of size 17 - sage: mFp2 = matrix({k:f(v) for k, v in m2.dict().items()}); mFp2 + sage: mFp2 = matrix({k: f(v) for k, v in m2.dict().items()}); mFp2 # optional - sage.modules sage.rings.finite_rings [ 2 3 0] [ 9 8 0] [ 0 0 16] - sage: mFp3 = matrix({k:f(v) for k, v in m3.dict().items()}); mFp3 + sage: mFp3 = matrix({k: f(v) for k, v in m3.dict().items()}); mFp3 # optional - sage.modules sage.rings.finite_rings [16 0 0] [ 0 4 5] [ 0 7 6] Obtain specializations in characteristic 0:: - sage: fQ = L.hom((3,5,7,11), codomain=QQ); fQ + sage: fQ = L.hom((3,5,7,11), codomain=QQ); fQ # optional - sage.rings.finite_rings Ring morphism: - From: Multivariate Polynomial Ring in u0, u1, u2, q over Integer Ring localized at - (q, q + 1, u2, u1, u1 - u2, u0, u0 - u2, u0 - u1, u2*q - u1, u2*q - u0, - u1*q - u2, u1*q - u0, u0*q - u2, u0*q - u1) + From: Multivariate Polynomial Ring in u0, u1, u2, q over Integer Ring + localized at (q, q + 1, u2, u1, u1 - u2, u0, u0 - u2, u0 - u1, + u2*q - u1, u2*q - u0, u1*q - u2, u1*q - u0, u0*q - u2, u0*q - u1) To: Rational Field Defn: u0 |--> 3 u1 |--> 5 u2 |--> 7 q |--> 11 - sage: mQ1 = matrix({k:fQ(v) for k, v in m1.dict().items()}); mQ1 + sage: mQ1 = matrix({k: fQ(v) for k, v in m1.dict().items()}); mQ1 # optional - sage.modules sage.rings.finite_rings [5 0 0] [0 3 0] [0 0 3] - sage: mQ1.base_ring() + sage: mQ1.base_ring() # optional - sage.modules sage.rings.finite_rings Rational Field - sage: mQ2 = matrix({k:fQ(v) for k, v in m2.dict().items()}); mQ2 + sage: mQ2 = matrix({k: fQ(v) for k, v in m2.dict().items()}); mQ2 # optional - sage.modules sage.rings.finite_rings [-15 -14 0] [ 26 25 0] [ 0 0 -1] - sage: mQ3 = matrix({k:fQ(v) for k, v in m3.dict().items()}); mQ3 + sage: mQ3 = matrix({k: fQ(v) for k, v in m3.dict().items()}); mQ3 # optional - sage.modules sage.rings.finite_rings [ -1 0 0] [ 0 -15/26 11/26] [ 0 301/26 275/26] sage: S. = QQ[] - sage: T = S.quo(x+y+z) - sage: F = T.fraction_field() - sage: fF = L.hom((x, y, z, t), codomain=F); fF + sage: T = S.quo(x + y + z) + sage: F = T.fraction_field() # optional - sage.libs.singular + sage: fF = L.hom((x, y, z, t), codomain=F); fF # optional - sage.libs.singular Ring morphism: - From: Multivariate Polynomial Ring in u0, u1, u2, q over Integer Ring localized at - (q, q + 1, u2, u1, u1 - u2, u0, u0 - u2, u0 - u1, u2*q - u1, u2*q - u0, - u1*q - u2, u1*q - u0, u0*q - u2, u0*q - u1) - To: Fraction Field of Quotient of Multivariate Polynomial Ring in x, y, z, t over - Rational Field by the ideal (x + y + z) + From: Multivariate Polynomial Ring in u0, u1, u2, q over Integer Ring + localized at (q, q + 1, u2, u1, u1 - u2, u0, u0 - u2, u0 - u1, + u2*q - u1, u2*q - u0, u1*q - u2, u1*q - u0, u0*q - u2, u0*q - u1) + To: Fraction Field of Quotient of Multivariate Polynomial Ring in x, y, z, t + over Rational Field by the ideal (x + y + z) Defn: u0 |--> -ybar - zbar u1 |--> ybar u2 |--> zbar q |--> tbar - sage: mF1 = matrix({k:fF(v) for k, v in m1.dict().items()}); mF1 + sage: mF1 = matrix({k: fF(v) for k, v in m1.dict().items()}); mF1 # optional - sage.libs.singular sage.modules [ ybar 0 0] [ 0 -ybar - zbar 0] [ 0 0 -ybar - zbar] - sage: mF1.base_ring() == F + sage: mF1.base_ring() == F # optional - sage.libs.singular sage.modules True TESTS:: - sage: TestSuite(L).run() + sage: TestSuite(L).run() # optional - sage.libs.singular sage.modules AUTHORS: @@ -199,21 +199,21 @@ def normalize_extra_units(base_ring, add_units, warning=True): sage: normalize_extra_units(ZZ, [3, -15, 45, 9, 2, 50]) [2, 3, 5] sage: P. = ZZ[] - sage: normalize_extra_units(P, [3*x, z*y**2, 2*z, 18*(x*y*z)**2, x*z, 6*x*z, 5]) + sage: normalize_extra_units(P, [3*x, z*y**2, 2*z, 18*(x*y*z)**2, x*z, 6*x*z, 5]) # optional - sage.libs.pari [2, 3, 5, z, y, x] sage: P. = QQ[] - sage: normalize_extra_units(P, [3*x, z*y**2, 2*z, 18*(x*y*z)**2, x*z, 6*x*z, 5]) + sage: normalize_extra_units(P, [3*x, z*y**2, 2*z, 18*(x*y*z)**2, x*z, 6*x*z, 5]) # optional - sage.libs.pari [z, y, x] sage: R. = ZZ[] - sage: Q. = R.quo(x**2-5) - sage: p = b**2-5 - sage: p == (b-a)*(b+a) + sage: Q. = R.quo(x**2 - 5) # optional - sage.libs.singular + sage: p = b**2 - 5 # optional - sage.libs.singular + sage: p == (b-a)*(b+a) # optional - sage.libs.singular True - sage: normalize_extra_units(Q, [p]) + sage: normalize_extra_units(Q, [p]) # optional - sage.libs.pari doctest:...: UserWarning: Localization may not be represented uniquely [b^2 - 5] - sage: normalize_extra_units(Q, [p], warning=False) + sage: normalize_extra_units(Q, [p], warning=False) # optional - sage.libs.pari [b^2 - 5] """ # convert to base ring @@ -251,11 +251,11 @@ class LocalizationElement(IntegralDomainElement): EXAMPLES:: sage: from sage.rings.localization import LocalizationElement - sage: P. = GF(5)[] - sage: L = P.localization((x, y*z-x)) - sage: LocalizationElement(L, 4/(y*z-x)**2) + sage: P. = GF(5)[] # optional - sage.rings.finite_rings + sage: L = P.localization((x, y*z-x)) # optional - sage.rings.finite_rings + sage: LocalizationElement(L, 4/(y*z-x)**2) # optional - sage.rings.finite_rings (-1)/(y^2*z^2 - 2*x*y*z + x^2) - sage: _.parent() + sage: _.parent() # optional - sage.rings.finite_rings Multivariate Polynomial Ring in x, y, z over Finite Field of size 5 localized at (x, y*z - x) """ @@ -389,10 +389,10 @@ def factor(self, proof=None): EXAMPLES:: sage: P. = QQ['x, y'] - sage: L = P.localization(X-Y) + sage: L = P.localization(X - Y) sage: x, y = L.gens() - sage: p = (x^2 - y^2)/(x-y)^2 - sage: p.factor() + sage: p = (x^2 - y^2)/(x-y)^2 # optional - sage.libs.singular + sage: p.factor() # optional - sage.libs.singular (1/(x - y)) * (x + y) """ num = self._value.numerator() @@ -411,9 +411,9 @@ def _im_gens_(self, codomain, im_gens, base_map=None): EXAMPLES:: sage: R. = ZZ[] - sage: L = Localization(R, x**2+1) - sage: f = L.hom([5], codomain=Localization(ZZ, 26)) # indirect doctest - sage: f(x/(x**2+1)) + sage: L = Localization(R, x**2 + 1) # optional - sage.libs.pari + sage: f = L.hom([5], codomain=Localization(ZZ, 26)) # indirect doctest # optional - sage.libs.pari + sage: f(x/(x**2+1)) # optional - sage.libs.pari 5/26 """ return self._value._im_gens_(codomain, im_gens, base_map=base_map) @@ -449,12 +449,12 @@ def is_unit(self): EXAMPLES:: sage: P. = QQ[] - sage: L = P.localization((x, y*z)) - sage: L(y*z).is_unit() + sage: L = P.localization((x, y*z)) # optional - sage.libs.pari + sage: L(y*z).is_unit() # optional - sage.libs.pari True - sage: L(z).is_unit() + sage: L(z).is_unit() # optional - sage.libs.pari True - sage: L(x*y*z).is_unit() + sage: L(x*y*z).is_unit() # optional - sage.libs.pari True """ return self.parent()._cut_off_extra_units_from_base_ring_element(self._value.numerator()).is_unit() @@ -467,9 +467,9 @@ def inverse_of_unit(self): sage: P. = ZZ[] sage: L = Localization(P, x*y*z) - sage: L(x*y*z).inverse_of_unit() + sage: L(x*y*z).inverse_of_unit() # optional - sage.libs.singular 1/(x*y*z) - sage: L(z).inverse_of_unit() + sage: L(z).inverse_of_unit() # optional - sage.libs.singular 1/z """ parent = self.parent() @@ -481,11 +481,11 @@ def _richcmp_(self, other, op): """ EXAMPLES:: - sage: P. = GF(7)[] - sage: L = Localization(P, (x, y, z)) - sage: L(1/x) < L(3/(x*y*z)**3) + sage: P. = GF(7)[] # optional - sage.rings.finite_rings + sage: L = Localization(P, (x, y, z)) # optional - sage.rings.finite_rings + sage: L(1/x) < L(3/(x*y*z)**3) # optional - sage.rings.finite_rings False - sage: ~L(y*z/x) == L(x/(y*z)) + sage: ~L(y*z/x) == L(x/(y*z)) # optional - sage.rings.finite_rings True """ sval = self._value @@ -518,8 +518,8 @@ def _rational_(self): TESTS:: sage: L = ZZ.localization(5) - sage: cp3 = cyclotomic_polynomial(3).change_ring(L) - sage: cp3.splitting_field('t') # indirect doctest + sage: cp3 = cyclotomic_polynomial(3).change_ring(L) # optional - sage.libs.pari + sage: cp3.splitting_field('t') # indirect doctest # optional - sage.libs.pari sage.rings.number_field Number Field in t with defining polynomial x^2 + x + 1 """ from sage.rings.rational_field import QQ @@ -601,40 +601,41 @@ class Localization(IntegralDomain, UniqueRepresentation): ... ValueError: factor 7 of denominator is not a unit - sage: Localization(Zp(7), (3, 5)) + sage: Localization(Zp(7), (3, 5)) # optional - sage.rings.padics Traceback (most recent call last): ... - ValueError: all given elements are invertible in 7-adic Ring with capped relative precision 20 + ValueError: all given elements are invertible in + 7-adic Ring with capped relative precision 20 sage: R. = ZZ[] - sage: L = R.localization(x**2+1) + sage: L = R.localization(x**2 + 1) # optional - sage.libs.pari sage: s = (x+5)/(x**2+1) - sage: s in L + sage: s in L # optional - sage.libs.pari True sage: t = (x+5)/(x**2+2) - sage: t in L + sage: t in L # optional - sage.libs.pari False - sage: L(t) + sage: L(t) # optional - sage.libs.pari Traceback (most recent call last): ... TypeError: fraction must have unit denominator - sage: L(s) in R + sage: L(s) in R # optional - sage.libs.pari False - sage: y = L(x) - sage: g = L(s) - sage: g.parent() + sage: y = L(x) # optional - sage.libs.pari + sage: g = L(s) # optional - sage.libs.pari + sage: g.parent() # optional - sage.libs.pari Univariate Polynomial Ring in x over Integer Ring localized at (x^2 + 1,) - sage: f = (y+5)/(y**2+1); f + sage: f = (y+5)/(y**2+1); f # optional - sage.libs.pari (x + 5)/(x^2 + 1) - sage: f == g + sage: f == g # optional - sage.libs.pari True - sage: (y+5)/(y**2+2) + sage: (y+5)/(y**2+2) # optional - sage.libs.pari Traceback (most recent call last): ... ValueError: factor x^2 + 2 of denominator is not a unit sage: Lau. = LaurentPolynomialRing(ZZ) - sage: LauL = Lau.localization(u+1) + sage: LauL = Lau.localization(u + 1) sage: LauL(~u).parent() Multivariate Polynomial Ring in u, v over Integer Ring localized at (v, u, u + 1) @@ -657,12 +658,12 @@ def __init__(self, base_ring, extra_units, names=None, normalize=True, category= TESTS:: - sage: L = Localization(ZZ, (3,5)) + sage: L = Localization(ZZ, (3, 5)) sage: TestSuite(L).run() sage: R. = ZZ[] - sage: L = R.localization(x**2+1) - sage: TestSuite(L).run() + sage: L = R.localization(x**2 + 1) # optional - sage.libs.pari + sage: TestSuite(L).run() # optional - sage.libs.pari """ if type(extra_units) is tuple: extra_units = list(extra_units) @@ -702,9 +703,10 @@ def _repr_(self): EXAMPLES:: - sage: R. = GF(3)[] - sage: Localization(R, a**2-1) - Univariate Polynomial Ring in a over Finite Field of size 3 localized at (a + 1, a + 2) + sage: R. = GF(3)[] # optional - sage.rings.finite_rings + sage: Localization(R, a**2 - 1) # optional - sage.rings.finite_rings + Univariate Polynomial Ring in a over Finite Field of size 3 + localized at (a + 1, a + 2) """ return "%s localized at %s" % (self.base(), self._extra_units) @@ -733,37 +735,38 @@ def _is_valid_homomorphism_(self, codomain, im_gens, base_map=None): EXAMPLES:: sage: R. = ZZ[] - sage: L = Localization(R, x**2+1) - sage: L.hom([5]) # indirect doctest + sage: L = Localization(R, x**2 + 1) # optional - sage.libs.pari + sage: L.hom([5]) # indirect doctest # optional - sage.libs.pari Traceback (most recent call last): ... ValueError: images of some localized elements fail to be units - sage: L.hom([5], codomain=Localization(ZZ, 26)) # indirect doctest + sage: L.hom([5], codomain=Localization(ZZ, 26)) # indirect doctest # optional - sage.libs.pari Ring morphism: - From: Univariate Polynomial Ring in x over Integer Ring localized at (x^2 + 1,) + From: Univariate Polynomial Ring in x over Integer Ring + localized at (x^2 + 1,) To: Integer Ring localized at (2, 13) Defn: x |--> 5 TESTS:: - sage: phi=R.hom([5]) - sage: L._is_valid_homomorphism_(ZZ, [3], base_map=phi) + sage: phi = R.hom([5]) + sage: L._is_valid_homomorphism_(ZZ, [3], base_map=phi) # optional - sage.libs.pari Traceback (most recent call last): ... ValueError: given base_map is not compatible with im_gens - sage: L._is_valid_homomorphism_(ZZ, [5], base_map=phi) + sage: L._is_valid_homomorphism_(ZZ, [5], base_map=phi) # optional - sage.libs.pari Traceback (most recent call last): ... ValueError: images of some localized elements fail to be units - sage: phi=R.hom([5], codomain=QQ) - sage: L._is_valid_homomorphism_(ZZ, [5], base_map=phi) + sage: phi = R.hom([5], codomain=QQ) + sage: L._is_valid_homomorphism_(ZZ, [5], base_map=phi) # optional - sage.libs.pari Traceback (most recent call last): ... ValueError: codomain of base_map must be Integer Ring - sage: L._is_valid_homomorphism_(QQ, [5], base_map=phi) + sage: L._is_valid_homomorphism_(QQ, [5], base_map=phi) # optional - sage.libs.pari True """ B = self.base_ring() @@ -795,7 +798,7 @@ def ngens(self): EXAMPLES:: sage: R. = ZZ[] - sage: Localization(R, (x**2+1, y-1)).ngens() + sage: Localization(R, (x**2 + 1, y - 1)).ngens() # optional - sage.libs.pari 2 sage: Localization(ZZ, 2).ngens() @@ -811,7 +814,7 @@ def gen(self, i): EXAMPLES:: sage: R. = ZZ[] - sage: R.localization((x**2+1, y-1)).gen(0) + sage: R.localization((x**2 + 1, y - 1)).gen(0) # optional - sage.libs.pari x sage: ZZ.localization(2).gen(0) @@ -827,7 +830,7 @@ def gens(self): EXAMPLES:: sage: R. = ZZ[] - sage: Localization(R, (x**2+1, y-1)).gens() + sage: Localization(R, (x**2 + 1, y - 1)).gens() # optional - sage.libs.pari (x, y) sage: Localization(ZZ, 2).gens() @@ -851,10 +854,10 @@ def _cut_off_extra_units_from_base_ring_element(self, x): EXAMPLES:: sage: P. = QQ[] - sage: L = Localization(P, (x, y*z)) - sage: L._cut_off_extra_units_from_base_ring_element(x*y*z) + sage: L = Localization(P, (x, y*z)) # optional - sage.libs.pari + sage: L._cut_off_extra_units_from_base_ring_element(x*y*z) # optional - sage.libs.pari 1 - sage: L._cut_off_extra_units_from_base_ring_element(x*z) + sage: L._cut_off_extra_units_from_base_ring_element(x*z) # optional - sage.libs.pari 1 TESTS: @@ -894,16 +897,16 @@ def _fraction_to_element(self, x): EXAMPLES:: sage: P. = QQ[] - sage: d = x**2+y**2+z**2 - sage: L = Localization(P, d) - sage: L._fraction_to_element((x+y+z)/d) + sage: d = x**2 + y**2 + z**2 + sage: L = Localization(P, d) # optional - sage.libs.pari + sage: L._fraction_to_element((x+y+z)/d) # optional - sage.libs.pari (x + y + z)/(x^2 + y^2 + z^2) - sage: _ in L + sage: _ in L # optional - sage.libs.pari True TESTS:: - sage: TestSuite(L).run() + sage: TestSuite(L).run() # optional - sage.libs.pari """ potential_non_unit_denom = self._cut_off_extra_units_from_base_ring_element(x.denominator()) if potential_non_unit_denom.is_unit(): @@ -932,7 +935,7 @@ def _coerce_map_from_(self, S): True sage: N._coerce_map_from_(M) False - sage: O = Localization(L, x**2+1) + sage: O = Localization(L, x**2 + 1) sage: O._coerce_map_from_(M) False sage: O._coerce_map_from_(L) @@ -951,11 +954,11 @@ def fraction_field(self): EXAMPLES:: - sage: R. = GF(5)[] - sage: L = Localization(R, (a**2-3, a)) - sage: L.fraction_field() + sage: R. = GF(5)[] # optional - sage.rings.finite_rings + sage: L = Localization(R, (a**2 - 3, a)) # optional - sage.rings.finite_rings + sage: L.fraction_field() # optional - sage.rings.finite_rings Fraction Field of Univariate Polynomial Ring in a over Finite Field of size 5 - sage: L.is_subring(_) + sage: L.is_subring(_) # optional - sage.rings.finite_rings True """ return self._fraction_field @@ -966,9 +969,9 @@ def characteristic(self): EXAMPLES:: - sage: R. = GF(5)[] - sage: L = R.localization((a**2-3, a)) - sage: L.characteristic() + sage: R. = GF(5)[] # optional - sage.rings.finite_rings + sage: L = R.localization((a**2 - 3, a)) # optional - sage.rings.finite_rings + sage: L.characteristic() # optional - sage.rings.finite_rings 5 """ return self.base_ring().characteristic() @@ -984,7 +987,7 @@ def krull_dimension(self): EXAMPLES:: - sage: R = ZZ.localization((2,3)) + sage: R = ZZ.localization((2, 3)) sage: R.krull_dimension() 1 """ @@ -1008,7 +1011,7 @@ def is_field(self, proof=True): EXAMPLES:: - sage: R = ZZ.localization((2,3)) + sage: R = ZZ.localization((2, 3)) sage: R.is_field() False """ diff --git a/src/sage/rings/morphism.pyx b/src/sage/rings/morphism.pyx index 84f288793d3..929bc55703f 100644 --- a/src/sage/rings/morphism.pyx +++ b/src/sage/rings/morphism.pyx @@ -17,7 +17,8 @@ Natural inclusion `\ZZ \hookrightarrow \QQ`:: sage: phi(2/3) Traceback (most recent call last): ... - TypeError: 2/3 fails to convert into the map's domain Integer Ring, but a `pushforward` method is not properly implemented + TypeError: 2/3 fails to convert into the map's domain Integer Ring, + but a `pushforward` method is not properly implemented There is no homomorphism in the other direction:: @@ -25,30 +26,31 @@ There is no homomorphism in the other direction:: sage: H([1]) Traceback (most recent call last): ... - ValueError: relations do not all (canonically) map to 0 under map determined by images of generators + ValueError: relations do not all (canonically) map to 0 + under map determined by images of generators EXAMPLES: Reduction to finite field:: - sage: H = Hom(ZZ, GF(9, 'a')) - sage: phi = H([1]) - sage: phi(5) + sage: H = Hom(ZZ, GF(9, 'a')) # optional - sage.rings.finite_rings + sage: phi = H([1]) # optional - sage.rings.finite_rings + sage: phi(5) # optional - sage.rings.finite_rings 2 - sage: psi = H([4]) - sage: psi(5) + sage: psi = H([4]) # optional - sage.rings.finite_rings + sage: psi(5) # optional - sage.rings.finite_rings 2 Map from single variable polynomial ring:: sage: R. = ZZ[] - sage: phi = R.hom([2], GF(5)) - sage: phi + sage: phi = R.hom([2], GF(5)) # optional - sage.rings.finite_rings + sage: phi # optional - sage.rings.finite_rings Ring morphism: From: Univariate Polynomial Ring in x over Integer Ring To: Finite Field of size 5 Defn: x |--> 2 - sage: phi(x + 12) + sage: phi(x + 12) # optional - sage.rings.finite_rings 4 Identity map on the real numbers:: @@ -61,7 +63,8 @@ Identity map on the real numbers:: sage: f = RR.hom( [2.0] ) Traceback (most recent call last): ... - ValueError: relations do not all (canonically) map to 0 under map determined by images of generators + ValueError: relations do not all (canonically) map to 0 + under map determined by images of generators Homomorphism from one precision of field to another. @@ -71,7 +74,8 @@ From smaller to bigger doesn't make sense:: sage: f = RR.hom( R200 ) Traceback (most recent call last): ... - TypeError: natural coercion morphism from Real Field with 53 bits of precision to Real Field with 200 bits of precision not defined + TypeError: natural coercion morphism from Real Field with 53 bits of precision + to Real Field with 200 bits of precision not defined From bigger to small does:: @@ -108,7 +112,8 @@ An endomorphism of a quotient of a multi-variate polynomial ring:: sage: S. = quo(R, ideal(1 + y^2)) sage: phi = S.hom([a^2, -b]) sage: phi - Ring endomorphism of Quotient of Multivariate Polynomial Ring in x, y over Rational Field by the ideal (y^2 + 1) + Ring endomorphism of Quotient of Multivariate Polynomial Ring in x, y + over Rational Field by the ideal (y^2 + 1) Defn: a |--> a^2 b |--> -b sage: phi(b) @@ -142,28 +147,28 @@ a quotient ring:: Inclusion of ``GF(2)`` into ``GF(4,'a')``:: - sage: k = GF(2) - sage: i = k.hom(GF(4, 'a')) - sage: i + sage: k = GF(2) # optional - sage.rings.finite_rings + sage: i = k.hom(GF(4, 'a')) # optional - sage.rings.finite_rings + sage: i # optional - sage.rings.finite_rings Ring morphism: From: Finite Field of size 2 To: Finite Field in a of size 2^2 Defn: 1 |--> 1 - sage: i(0) + sage: i(0) # optional - sage.rings.finite_rings 0 - sage: a = i(1); a.parent() + sage: a = i(1); a.parent() # optional - sage.rings.finite_rings Finite Field in a of size 2^2 We next compose the inclusion with reduction from the integers to ``GF(2)``:: - sage: pi = ZZ.hom(k) - sage: pi + sage: pi = ZZ.hom(k) # optional - sage.rings.finite_rings + sage: pi # optional - sage.rings.finite_rings Natural morphism: From: Integer Ring To: Finite Field of size 2 - sage: f = i * pi - sage: f + sage: f = i * pi # optional - sage.rings.finite_rings + sage: f # optional - sage.rings.finite_rings Composite map: From: Integer Ring To: Finite Field in a of size 2^2 @@ -175,27 +180,27 @@ We next compose the inclusion with reduction from the integers to From: Finite Field of size 2 To: Finite Field in a of size 2^2 Defn: 1 |--> 1 - sage: a = f(5); a + sage: a = f(5); a # optional - sage.rings.finite_rings 1 - sage: a.parent() + sage: a.parent() # optional - sage.rings.finite_rings Finite Field in a of size 2^2 Inclusion from `\QQ` to the 3-adic field:: - sage: phi = QQ.hom(Qp(3, print_mode = 'series')) - sage: phi + sage: phi = QQ.hom(Qp(3, print_mode='series')) # optional - sage.rings.padics + sage: phi # optional - sage.rings.padics Ring morphism: From: Rational Field To: 3-adic Field with capped relative precision 20 - sage: phi.codomain() + sage: phi.codomain() # optional - sage.rings.padics 3-adic Field with capped relative precision 20 - sage: phi(394) + sage: phi(394) # optional - sage.rings.padics 1 + 2*3 + 3^2 + 2*3^3 + 3^4 + 3^5 + O(3^20) An automorphism of a quotient of a univariate polynomial ring:: sage: R. = PolynomialRing(QQ) - sage: S. = R.quo(x^2-2) + sage: S. = R.quo(x^2 - 2) sage: sqrt2^2 2 sage: (3+sqrt2)^10 @@ -227,19 +232,19 @@ Endomorphism of power series ring:: Frobenius on a power series ring over a finite field:: - sage: R. = PowerSeriesRing(GF(5)) - sage: f = R.hom([t^5]); f + sage: R. = PowerSeriesRing(GF(5)) # optional - sage.rings.finite_rings + sage: f = R.hom([t^5]); f # optional - sage.rings.finite_rings Ring endomorphism of Power Series Ring in t over Finite Field of size 5 Defn: t |--> t^5 - sage: a = 2 + t + 3*t^2 + 4*t^3 + O(t^4) - sage: b = 1 + t + 2*t^2 + t^3 + O(t^5) - sage: f(a) + sage: a = 2 + t + 3*t^2 + 4*t^3 + O(t^4) # optional - sage.rings.finite_rings + sage: b = 1 + t + 2*t^2 + t^3 + O(t^5) # optional - sage.rings.finite_rings + sage: f(a) # optional - sage.rings.finite_rings 2 + t^5 + 3*t^10 + 4*t^15 + O(t^20) - sage: f(b) + sage: f(b) # optional - sage.rings.finite_rings 1 + t^5 + 2*t^10 + t^15 + O(t^25) - sage: f(a*b) + sage: f(a*b) # optional - sage.rings.finite_rings 2 + 3*t^5 + 3*t^10 + t^15 + O(t^20) - sage: f(a)*f(b) + sage: f(a)*f(b) # optional - sage.rings.finite_rings 2 + 3*t^5 + 3*t^10 + t^15 + O(t^20) Homomorphism of Laurent series ring:: @@ -332,44 +337,51 @@ TESTS:: :: - sage: K. = CyclotomicField(7) - sage: c = K.hom([1/zeta7]) - sage: c == loads(dumps(c)) + sage: K. = CyclotomicField(7) # optional - sage.rings.number_field + sage: c = K.hom([1/zeta7]) # optional - sage.rings.number_field + sage: c == loads(dumps(c)) # optional - sage.rings.number_field True :: - sage: R. = PowerSeriesRing(GF(5)) - sage: f = R.hom([t^5]) - sage: f == loads(dumps(f)) + sage: R. = PowerSeriesRing(GF(5)) # optional - sage.rings.finite_rings + sage: f = R.hom([t^5]) # optional - sage.rings.finite_rings + sage: f == loads(dumps(f)) # optional - sage.rings.finite_rings True We define the identity map in many possible ways. These should all compare equal:: - sage: k = GF(2) - sage: R. = k[] - sage: F4. = R.quo(x^2+x+1) - sage: H = End(F4) + sage: k = GF(2) # optional - sage.rings.finite_rings + sage: R. = k[] # optional - sage.rings.finite_rings + sage: F4. = R.quo(x^2+x+1) # optional - sage.rings.finite_rings + sage: H = End(F4) # optional - sage.rings.finite_rings sage: from sage.rings.morphism import * - sage: phi1 = H.identity(); phi1 - Identity endomorphism of Univariate Quotient Polynomial Ring in a over Finite Field of size 2 with modulus x^2 + x + 1 - sage: phi2 = H([a]); phi2 - Ring endomorphism of Univariate Quotient Polynomial Ring in a over Finite Field of size 2 with modulus x^2 + x + 1 + sage: phi1 = H.identity(); phi1 # optional - sage.rings.finite_rings + Identity endomorphism of Univariate Quotient Polynomial Ring in a + over Finite Field of size 2 with modulus x^2 + x + 1 + sage: phi2 = H([a]); phi2 # optional - sage.rings.finite_rings + Ring endomorphism of Univariate Quotient Polynomial Ring in a + over Finite Field of size 2 with modulus x^2 + x + 1 Defn: a |--> a - sage: phi3 = RingHomomorphism_from_base(H, R.hom([x])); phi3 - Ring endomorphism of Univariate Quotient Polynomial Ring in a over Finite Field of size 2 with modulus x^2 + x + 1 + sage: phi3 = RingHomomorphism_from_base(H, R.hom([x])); phi3 # optional - sage.rings.finite_rings + Ring endomorphism of Univariate Quotient Polynomial Ring in a + over Finite Field of size 2 with modulus x^2 + x + 1 Defn: Induced from base ring by - Ring endomorphism of Univariate Polynomial Ring in x over Finite Field of size 2 (using GF2X) + Ring endomorphism of Univariate Polynomial Ring in x + over Finite Field of size 2 (using GF2X) Defn: x |--> x - sage: phi4 = RingHomomorphism_cover(H); phi4 - Ring endomorphism of Univariate Quotient Polynomial Ring in a over Finite Field of size 2 with modulus x^2 + x + 1 + sage: phi4 = RingHomomorphism_cover(H); phi4 # optional - sage.rings.finite_rings + Ring endomorphism of Univariate Quotient Polynomial Ring in a + over Finite Field of size 2 with modulus x^2 + x + 1 Defn: Natural quotient map - sage: phi5 = F4.frobenius_endomorphism() ^ 2; phi5 - Frobenius endomorphism x |--> x^(2^2) of Univariate Quotient Polynomial Ring in a over Finite Field of size 2 with modulus x^2 + x + 1 - sage: maps = [phi1, phi2, phi3, phi4, phi5] - sage: for f in maps: + sage: phi5 = F4.frobenius_endomorphism() ^ 2; phi5 # optional - sage.rings.finite_rings + Frobenius endomorphism x |--> x^(2^2) of + Univariate Quotient Polynomial Ring in a + over Finite Field of size 2 with modulus x^2 + x + 1 + sage: maps = [phi1, phi2, phi3, phi4, phi5] # optional - sage.rings.finite_rings + sage: for f in maps: # optional - sage.rings.finite_rings ....: for g in maps: ....: if f != g: ....: print("{} != {}".format(f, g)) @@ -457,13 +469,14 @@ cdef class RingMap_lift(RingMap): EXAMPLES:: sage: R. = QQ[] - sage: S. = R.quo( (x^2 + y^2, y) ) - sage: S.lift() + sage: S. = R.quo( (x^2 + y^2, y) ) # optional - sage.libs.singular + sage: S.lift() # optional - sage.libs.singular Set-theoretic ring morphism: - From: Quotient of Multivariate Polynomial Ring in x, y over Rational Field by the ideal (x^2 + y^2, y) + From: Quotient of Multivariate Polynomial Ring in x, y + over Rational Field by the ideal (x^2 + y^2, y) To: Multivariate Polynomial Ring in x, y over Rational Field Defn: Choice of lifting map - sage: S.lift() == 0 + sage: S.lift() == 0 # optional - sage.libs.singular False Since :trac:`11068`, it is possible to create @@ -473,10 +486,10 @@ cdef class RingMap_lift(RingMap): of :class:`sage.rings.ring.Ring`, as in the following example:: - sage: MS = MatrixSpace(GF(5),2,2) - sage: I = MS*[MS.0*MS.1,MS.2+MS.3]*MS - sage: Q = MS.quo(I) - sage: Q.0*Q.1 # indirect doctest + sage: MS = MatrixSpace(GF(5), 2, 2) # optional - sage.modules sage.rings.finite_rings + sage: I = MS * [MS.0*MS.1, MS.2+MS.3] * MS # optional - sage.modules sage.rings.finite_rings + sage: Q = MS.quo(I) # optional - sage.modules sage.rings.finite_rings + sage: Q.0*Q.1 # indirect doctest # optional - sage.modules sage.rings.finite_rings [0 1] [0 0] """ @@ -496,12 +509,13 @@ cdef class RingMap_lift(RingMap): An invalid example:: - sage: GF9. = GaussianIntegers().quotient(3) - sage: from sage.rings.morphism import RingMap_lift - sage: RingMap_lift(GF9, ZZ) + sage: GF9. = GaussianIntegers().quotient(3) # optional - sage.rings.number_field + sage: from sage.rings.morphism import RingMap_lift # optional - sage.rings.number_field + sage: RingMap_lift(GF9, ZZ) # optional - sage.rings.number_field Traceback (most recent call last): ... - TypeError: no canonical coercion from Number Field in I with defining polynomial x^2 + 1 with I = 1*I to Integer Ring + TypeError: no canonical coercion from Number Field in I + with defining polynomial x^2 + 1 with I = 1*I to Integer Ring """ self.S = S x = R(0).lift() @@ -640,14 +654,14 @@ cdef class RingHomomorphism(RingMap): EXAMPLES:: - sage: f = ZZ.hom(Zp(3)); f + sage: f = ZZ.hom(Zp(3)); f # optional - sage.rings.padics Ring morphism: From: Integer Ring To: 3-adic Ring with capped relative precision 20 TESTS:: - sage: isinstance(f, sage.rings.morphism.RingHomomorphism) + sage: isinstance(f, sage.rings.morphism.RingHomomorphism) # optional - sage.rings.padics True """ @@ -662,7 +676,7 @@ cdef class RingHomomorphism(RingMap): TESTS:: - sage: ZZ.hom(Zp(3))._repr_type() + sage: ZZ.hom(Zp(3))._repr_type() # optional - sage.rings.padics 'Ring' """ @@ -775,18 +789,19 @@ cdef class RingHomomorphism(RingMap): result has the type of a homomorphism between its domain and codomain:: - sage: C = CyclotomicField(24) - sage: f = End(C)[1] - sage: type(f*f) == type(f) + sage: C = CyclotomicField(24) # optional - sage.rings.number_field + sage: f = End(C)[1] # optional - sage.rings.number_field + sage: type(f*f) == type(f) # optional - sage.rings.number_field True An example where the domain of ``right`` is a relative number field:: sage: PQ. = QQ[] - sage: K. = NumberField([X^2 - 2, X^2 - 3]) - sage: e, u, v, w = End(K) - sage: u*v - Relative number field endomorphism of Number Field in a with defining polynomial X^2 - 2 over its base field + sage: K. = NumberField([X^2 - 2, X^2 - 3]) # optional - sage.rings.number_field + sage: e, u, v, w = End(K) # optional - sage.rings.number_field + sage: u*v # optional - sage.rings.number_field + Relative number field endomorphism of + Number Field in a with defining polynomial X^2 - 2 over its base field Defn: a |--> -a b |--> b @@ -804,39 +819,44 @@ cdef class RingHomomorphism(RingMap): then Coercion map: From: Multivariate Polynomial Ring in a, b over Rational Field - To: Fraction Field of Multivariate Polynomial Ring in a, b over Rational Field + To: Fraction Field of + Multivariate Polynomial Ring in a, b over Rational Field We check that composition works when there is a base map:: sage: R. = ZZ[] - sage: K. = GF(7^2) - sage: L. = K.extension(x^3 - 3) - sage: phi = L.hom([u^7], base_map=K.frobenius_endomorphism()) - sage: phi - Ring endomorphism of Univariate Quotient Polynomial Ring in u over Finite Field in a of size 7^2 with modulus u^3 + 4 + sage: K. = GF(7^2) # optional - sage.rings.finite_rings + sage: L. = K.extension(x^3 - 3) # optional - sage.rings.finite_rings + sage: phi = L.hom([u^7], base_map=K.frobenius_endomorphism()) # optional - sage.rings.finite_rings + sage: phi # optional - sage.rings.finite_rings + Ring endomorphism of Univariate Quotient Polynomial Ring in u + over Finite Field in a of size 7^2 with modulus u^3 + 4 Defn: u |--> 2*u with map of base ring - sage: psi = phi^3; psi - Ring endomorphism of Univariate Quotient Polynomial Ring in u over Finite Field in a of size 7^2 with modulus u^3 + 4 + sage: psi = phi^3; psi # optional - sage.rings.finite_rings + Ring endomorphism of Univariate Quotient Polynomial Ring in u + over Finite Field in a of size 7^2 with modulus u^3 + 4 Defn: u |--> u with map of base ring - sage: psi(a) == phi(phi(phi(a))) + sage: psi(a) == phi(phi(phi(a))) # optional - sage.rings.finite_rings True It also works when the image of the base map is not contained within the base ring of the codomain:: sage: S. = QQ[] sage: T. = S[] - sage: cc = S.hom([x+y]) - sage: f = T.hom([x-y], base_map=cc) + sage: cc = S.hom([x + y]) + sage: f = T.hom([x - y], base_map=cc) sage: f*f - Ring endomorphism of Univariate Polynomial Ring in y over Univariate Polynomial Ring in x over Rational Field + Ring endomorphism of Univariate Polynomial Ring in y + over Univariate Polynomial Ring in x over Rational Field Defn: y |--> 2*y with map of base ring sage: (f*f).base_map() Ring morphism: From: Univariate Polynomial Ring in x over Rational Field - To: Univariate Polynomial Ring in y over Univariate Polynomial Ring in x over Rational Field + To: Univariate Polynomial Ring in y over + Univariate Polynomial Ring in x over Rational Field Defn: x |--> 2*x with map of base ring @@ -887,9 +907,10 @@ cdef class RingHomomorphism(RingMap): EXAMPLES:: - sage: R. = QQ[]; S. = R.quo([x^2,y^2]); f = S.cover() - sage: f.pushforward(R.ideal([x,3*x+x*y+y^2])) - Ideal (xx, xx*yy + 3*xx) of Quotient of Multivariate Polynomial Ring in x, y over Rational Field by the ideal (x^2, y^2) + sage: R. = QQ[]; S. = R.quo([x^2, y^2]); f = S.cover() # optional - sage.libs.singular + sage: f.pushforward(R.ideal([x, 3*x + x*y + y^2])) # optional - sage.libs.singular + Ideal (xx, xx*yy + 3*xx) of Quotient of Multivariate Polynomial Ring + in x, y over Rational Field by the ideal (x^2, y^2) """ if not ideal.is_Ideal(I): raise TypeError("I must be an ideal") @@ -920,18 +941,18 @@ cdef class RingHomomorphism(RingMap): sage: S. = QQ[] sage: f = R.hom([u^2, u*v, v^2], S) sage: I = S.ideal([u^6, u^5*v, u^4*v^2, u^3*v^3]) - sage: J = f.inverse_image(I); J + sage: J = f.inverse_image(I); J # optional - sage.libs.singular Ideal (y^2 - x*z, x*y*z, x^2*z, x^2*y, x^3) of Multivariate Polynomial Ring in x, y, z over Rational Field - sage: f(J) == I + sage: f(J) == I # optional - sage.libs.singular True Under the above homomorphism, there exists an inverse image for every element that only involves monomials of even degree:: - sage: [f.inverse_image(p) for p in [u^2, u^4, u*v + u^3*v^3]] + sage: [f.inverse_image(p) for p in [u^2, u^4, u*v + u^3*v^3]] # optional - sage.libs.singular [x, x^2, x*y*z + y] - sage: f.inverse_image(u*v^2) + sage: f.inverse_image(u*v^2) # optional - sage.libs.singular Traceback (most recent call last): ... ValueError: element u*v^2 does not have preimage @@ -939,27 +960,27 @@ cdef class RingHomomorphism(RingMap): The image of the inverse image ideal can be strictly smaller than the original ideal:: - sage: S. = QQ['u,v'].quotient('v^2 - 2') - sage: f = QuadraticField(2).hom([v], S) - sage: I = S.ideal(u + v) - sage: J = f.inverse_image(I) - sage: J.is_zero() + sage: S. = QQ['u,v'].quotient('v^2 - 2') # optional - sage.libs.singular + sage: f = QuadraticField(2).hom([v], S) # optional - sage.libs.singular sage.rings.number_field + sage: I = S.ideal(u + v) # optional - sage.libs.singular sage.rings.number_field + sage: J = f.inverse_image(I) # optional - sage.libs.singular sage.rings.number_field + sage: J.is_zero() # optional - sage.libs.singular sage.rings.number_field True - sage: f(J) < I + sage: f(J) < I # optional - sage.libs.singular sage.rings.number_field True Fractional ideals are not yet fully supported:: - sage: K. = NumberField(QQ['x']('x^2+2')) - sage: f = K.hom([-a], K) - sage: I = K.ideal([a + 1]) - sage: f.inverse_image(I) + sage: K. = NumberField(QQ['x']('x^2+2')) # optional - sage.rings.number_field + sage: f = K.hom([-a], K) # optional - sage.rings.number_field + sage: I = K.ideal([a + 1]) # optional - sage.rings.number_field + sage: f.inverse_image(I) # optional - sage.rings.number_field Traceback (most recent call last): ... NotImplementedError: inverse image not implemented... - sage: f.inverse_image(K.ideal(0)).is_zero() + sage: f.inverse_image(K.ideal(0)).is_zero() # optional - sage.rings.number_field True - sage: f.inverse()(I) + sage: f.inverse()(I) # optional - sage.rings.number_field Fractional ideal (-a + 1) ALGORITHM: @@ -973,7 +994,7 @@ cdef class RingHomomorphism(RingMap): TESTS:: - sage: ZZ.hom(Zp(2)).inverse_image(ZZ.ideal(2)) + sage: ZZ.hom(Zp(2)).inverse_image(ZZ.ideal(2)) # optional - sage.rings.padics Traceback (most recent call last): ... ValueError: not an ideal or element in codomain 2-adic Ring @@ -981,7 +1002,7 @@ cdef class RingHomomorphism(RingMap): :: - sage: ZZ.hom(Zp(2)).inverse_image(Zp(2).ideal(2)) + sage: ZZ.hom(Zp(2)).inverse_image(Zp(2).ideal(2)) # optional - sage.rings.padics Traceback (most recent call last): ... NotImplementedError: base rings must be equal @@ -1001,13 +1022,13 @@ cdef class RingHomomorphism(RingMap): EXAMPLES:: - sage: R. = QQbar[] - sage: f = R.hom([x, QQbar(i) * x + y^2], R) - sage: I = R.ideal(y^3) - sage: J = f._inverse_image_ideal(I); J + sage: R. = QQbar[] # optional - sage.rings.number_field + sage: f = R.hom([x, QQbar(i) * x + y^2], R) # optional - sage.rings.number_field + sage: I = R.ideal(y^3) # optional - sage.rings.number_field + sage: J = f._inverse_image_ideal(I); J # optional - sage.rings.number_field Ideal (x^2 + 2*I*x*y - y^2) - of Multivariate Polynomial Ring in x, y over Algebraic Field - sage: f(J) <= I + of Multivariate Polynomial Ring in x, y over Algebraic Field + sage: f(J) <= I # optional - sage.rings.number_field True TESTS: @@ -1015,17 +1036,17 @@ cdef class RingHomomorphism(RingMap): Check that :trac:`31367` is fixed:: sage: A. = QQ[] - sage: B. = QQ['x,y'].quotient('y') - sage: f = A.hom([x], B) - sage: f.kernel() + sage: B. = QQ['x,y'].quotient('y') # optional - sage.libs.singular + sage: f = A.hom([x], B) # optional - sage.libs.singular + sage: f.kernel() # optional - sage.libs.singular Principal ideal (0) of Univariate Polynomial Ring in t over Rational Field :: sage: A. = QQ[] - sage: B. = QQ['x,y,z'].quotient('z') - sage: f = A.hom([x, y], B) - sage: f.kernel() + sage: B. = QQ['x,y,z'].quotient('z') # optional - sage.libs.singular + sage: f = A.hom([x, y], B) # optional - sage.libs.singular + sage: f.kernel() # optional - sage.libs.singular Ideal (0) of Multivariate Polynomial Ring in t, u over Rational Field """ from .polynomial.polynomial_quotient_ring import is_PolynomialQuotientRing @@ -1067,36 +1088,36 @@ cdef class RingHomomorphism(RingMap): A degenerate case:: - sage: R. = QQ['x,y'].quotient(1) - sage: f = R.hom([y, x], R) - sage: f.inverse_image(x), f.inverse_image(y) # indirect doctest + sage: R. = QQ['x,y'].quotient(1) # optional - sage.libs.singular + sage: f = R.hom([y, x], R) # optional - sage.libs.singular + sage: f.inverse_image(x), f.inverse_image(y) # indirect doctest # optional - sage.libs.singular (0, 0) Check cases involving quotient rings in which a generator is constant (:trac:`31178`):: sage: R. = QQ[] - sage: B. = R.quotient(R.ideal(x)) - sage: g = R.hom([d^2, d^3], B) - sage: g.inverse_image(d) + sage: B. = R.quotient(R.ideal(x)) # optional - sage.libs.singular + sage: g = R.hom([d^2, d^3], B) # optional - sage.libs.singular + sage: g.inverse_image(d) # optional - sage.libs.singular Traceback (most recent call last): ... ValueError: element d does not have preimage - sage: g.inverse_image(d^2) + sage: g.inverse_image(d^2) # optional - sage.libs.singular x - sage: g.inverse_image(d^3) + sage: g.inverse_image(d^3) # optional - sage.libs.singular y - sage: A. = R.quotient(R.ideal(y^2 - x^3)) - sage: h = A.hom([d^2, d^3], B) - sage: h.inverse_image(d^2) + sage: A. = R.quotient(R.ideal(y^2 - x^3)) # optional - sage.libs.singular + sage: h = A.hom([d^2, d^3], B) # optional - sage.libs.singular + sage: h.inverse_image(d^2) # optional - sage.libs.singular a Check that quotient rings are handled correctly (:trac:`33217`):: - sage: A. = QQ['X,Y,Z'].quotient('X^2+Y^2+Z^2-1') - sage: B. = QQ['T,U,V,W'].quotient(['T^2+U^2-1', 'V^2+W^2-1']) - sage: psi = A.hom([v*u, w*u, t], B) - sage: psi.inverse_image(t^2) == z^2 + sage: A. = QQ['X,Y,Z'].quotient('X^2+Y^2+Z^2-1') # optional - sage.libs.singular + sage: B. = QQ['T,U,V,W'].quotient(['T^2+U^2-1', 'V^2+W^2-1']) # optional - sage.libs.singular + sage: psi = A.hom([v*u, w*u, t], B) # optional - sage.libs.singular + sage: psi.inverse_image(t^2) == z^2 # optional - sage.libs.singular True """ graph, from_B, to_A = self._graph_ideal() @@ -1116,7 +1137,7 @@ cdef class RingHomomorphism(RingMap): sage: A. = QQ[] sage: B. = QQ[] sage: f = A.hom([t^4, t^3 - t^2], B) - sage: f.kernel() + sage: f.kernel() # optional - sage.libs.singular Ideal (y^4 - x^3 + 4*x^2*y - 2*x*y^2 + x^2) of Multivariate Polynomial Ring in x, y over Rational Field @@ -1124,50 +1145,50 @@ cdef class RingHomomorphism(RingMap): sage: A. = QQ[] sage: B. = QQ[] - sage: f = A.hom([u^3, u^2*v, u*v^2, v^3],B) - sage: f.kernel() == A.ideal(matrix.hankel([a, b, c], [d]).minors(2)) + sage: f = A.hom([u^3, u^2*v, u*v^2, v^3], B) + sage: f.kernel() == A.ideal(matrix.hankel([a, b, c], [d]).minors(2)) # optional - sage.libs.singular True - sage: Q = A.quotient(f.kernel()) - sage: Q.hom(f.im_gens(), B).is_injective() + sage: Q = A.quotient(f.kernel()) # optional - sage.libs.singular + sage: Q.hom(f.im_gens(), B).is_injective() # optional - sage.libs.singular True The Steiner-Roman surface:: sage: R. = QQ[] - sage: S = R.quotient(x^2 + y^2 + z^2 - 1) - sage: f = R.hom([x*y, x*z, y*z], S) - sage: f.kernel() + sage: S = R.quotient(x^2 + y^2 + z^2 - 1) # optional - sage.libs.singular + sage: f = R.hom([x*y, x*z, y*z], S) # optional - sage.libs.singular + sage: f.kernel() # optional - sage.libs.singular Ideal (x^2*y^2 + x^2*z^2 + y^2*z^2 - x*y*z) - of Multivariate Polynomial Ring in x, y, z over Rational Field + of Multivariate Polynomial Ring in x, y, z over Rational Field TESTS: The results are cached:: - sage: f.kernel() is f.kernel() + sage: f.kernel() is f.kernel() # optional - sage.libs.singular True A degenerate case:: sage: R. = QQ[] - sage: f = R.hom([0, 0], R.quotient(1)) - sage: f.kernel().is_one() + sage: f = R.hom([0, 0], R.quotient(1)) # optional - sage.libs.singular + sage: f.kernel().is_one() # optional - sage.libs.singular True :: - sage: K. = QuadraticField(2) - sage: K.hom([-sqrt2], K).kernel().is_zero() + sage: K. = QuadraticField(2) # optional - sage.rings.number_field + sage: K.hom([-sqrt2], K).kernel().is_zero() # optional - sage.rings.number_field True :: - sage: A. = QuadraticField(2) - sage: B. = A.extension(A['b']('b^2-3')) - sage: C. = B.absolute_field() - sage: A.hom([B(a)], C).kernel().is_zero() + sage: A. = QuadraticField(2) # optional - sage.rings.number_field + sage: B. = A.extension(A['b']('b^2-3')) # optional - sage.rings.number_field + sage: C. = B.absolute_field() # optional - sage.rings.number_field + sage: A.hom([B(a)], C).kernel().is_zero() # optional - sage.rings.number_field True - sage: A.hom([a], B).kernel() + sage: A.hom([a], B).kernel() # optional - sage.rings.number_field Traceback (most recent call last): ... NotImplementedError: base rings must be equal @@ -1242,32 +1263,32 @@ cdef class RingHomomorphism(RingMap): Ideals in quotient rings over ``QQbar`` do not support reduction yet, so the graph is constructed in the ambient ring instead:: - sage: A. = QQbar['z,w'].quotient('z*w - 1') - sage: B. = QQbar['x,y'].quotient('2*x^2 + y^2 - 1') - sage: f = A.hom([QQbar(2).sqrt()*x + QQbar(I)*y, + sage: A. = QQbar['z,w'].quotient('z*w - 1') # optional - sage.rings.number_field + sage: B. = QQbar['x,y'].quotient('2*x^2 + y^2 - 1') # optional - sage.rings.number_field + sage: f = A.hom([QQbar(2).sqrt()*x + QQbar(I)*y, # optional - sage.rings.number_field ....: QQbar(2).sqrt()*x - QQbar(I)*y], B) - sage: f._graph_ideal()[0] + sage: f._graph_ideal()[0] # optional - sage.rings.number_field Ideal (z*w - 1, 2*x^2 + y^2 - 1, 1.414213562373095?*x + I*y - z, 1.414213562373095?*x + (-I)*y - w) of Multivariate Polynomial Ring in x, y, z, w over Algebraic Field - sage: f.inverse()(f(z)), f.inverse()(f(w)) + sage: f.inverse()(f(z)), f.inverse()(f(w)) # optional - sage.rings.number_field (z, w) Non-trivial base maps are not supported:: - sage: K. = QuadraticField(2) - sage: R. = K[] - sage: f = R.hom([x, a*x + y], R, base_map=K.hom([-a], K)) - sage: f._graph_ideal() + sage: K. = QuadraticField(2) # optional - sage.rings.number_field + sage: R. = K[] # optional - sage.rings.number_field + sage: f = R.hom([x, a*x + y], R, base_map=K.hom([-a], K)) # optional - sage.rings.number_field + sage: f._graph_ideal() # optional - sage.rings.number_field Traceback (most recent call last): ... NotImplementedError: base map must be trivial Non-commutative rings are not supported (:trac:`32824`):: - sage: A = GradedCommutativeAlgebra(QQ, 'x,y,z') - sage: A.hom(A.gens(), A).kernel() + sage: A = GradedCommutativeAlgebra(QQ, 'x,y,z') # optional - sage.combinat sage.modules + sage: A.hom(A.gens(), A).kernel() # optional - sage.combinat sage.modules Traceback (most recent call last): ... NotImplementedError: rings are not commutative @@ -1324,7 +1345,7 @@ cdef class RingHomomorphism(RingMap): sage: R. = QQ[] sage: f = R.hom([2*t - 1], R) - sage: f.inverse() + sage: f.inverse() # optional - sage.libs.singular Ring endomorphism of Univariate Polynomial Ring in t over Rational Field Defn: t |--> 1/2*t + 1/2 @@ -1333,15 +1354,15 @@ cdef class RingHomomorphism(RingMap): sage: R. = QQ[] sage: f = R.hom([y*z, x*z, x*y], R) - sage: f.inverse() + sage: f.inverse() # optional - sage.libs.singular Traceback (most recent call last): ... ZeroDivisionError: ring homomorphism not surjective - sage: f.is_injective() + sage: f.is_injective() # optional - sage.libs.singular True - sage: Q. = R.quotient(x*y*z - 1) - sage: g = Q.hom([y*z, x*z, x*y], Q) - sage: g.inverse() + sage: Q. = R.quotient(x*y*z - 1) # optional - sage.libs.singular + sage: g = Q.hom([y*z, x*z, x*y], Q) # optional - sage.libs.singular + sage: g.inverse() # optional - sage.libs.singular Ring endomorphism of Quotient of Multivariate Polynomial Ring in x, y, z over Rational Field by the ideal (x*y*z - 1) Defn: x |--> y*z @@ -1352,24 +1373,24 @@ cdef class RingHomomorphism(RingMap): sage: S. = ZZ[] sage: f = S.hom([x + 2*y, x + 3*y], S) - sage: f.inverse() + sage: f.inverse() # optional - sage.libs.singular Ring endomorphism of Multivariate Polynomial Ring in x, y over Integer Ring Defn: x |--> 3*x - 2*y y |--> -x + y - sage: (f.inverse() * f).is_identity() + sage: (f.inverse() * f).is_identity() # optional - sage.libs.singular True The following homomorphism is invertible over the rationals, but not over the integers:: sage: g = S.hom([x + y, x - y - 2], S) - sage: g.inverse() + sage: g.inverse() # optional - sage.libs.singular Traceback (most recent call last): ... ZeroDivisionError: ring homomorphism not surjective sage: R. = QQ[x,y] sage: h = R.hom([x + y, x - y - 2], R) - sage: (h.inverse() * h).is_identity() + sage: (h.inverse() * h).is_identity() # optional - sage.libs.singular True This example by M. Nagata is a wild automorphism:: @@ -1377,13 +1398,13 @@ cdef class RingHomomorphism(RingMap): sage: R. = QQ[] sage: sigma = R.hom([x - 2*y*(z*x+y^2) - z*(z*x+y^2)^2, ....: y + z*(z*x+y^2), z], R) - sage: tau = sigma.inverse(); tau + sage: tau = sigma.inverse(); tau # optional - sage.libs.singular Ring endomorphism of Multivariate Polynomial Ring in x, y, z over Rational Field Defn: x |--> -y^4*z - 2*x*y^2*z^2 - x^2*z^3 + 2*y^3 + 2*x*y*z + x y |--> -y^2*z - x*z^2 + y z |--> z - sage: (tau * sigma).is_identity() + sage: (tau * sigma).is_identity() # optional - sage.libs.singular True We compute the triangular automorphism that converts moments to @@ -1407,37 +1428,37 @@ cdef class RingHomomorphism(RingMap): x1^5 + 10*x1^3*x2 + 15*x1*x2^2 + 10*x1^2*x3 + 10*x2*x3 + 5*x1*x4 + x5] sage: all(p.is_homogeneous() for p in phi.im_gens()) True - sage: phi.inverse().im_gens()[:5] + sage: phi.inverse().im_gens()[:5] # optional - sage.libs.singular [x1, -x1^2 + x2, 2*x1^3 - 3*x1*x2 + x3, -6*x1^4 + 12*x1^2*x2 - 3*x2^2 - 4*x1*x3 + x4, 24*x1^5 - 60*x1^3*x2 + 30*x1*x2^2 + 20*x1^2*x3 - 10*x2*x3 - 5*x1*x4 + x5] - sage: (phi.inverse() * phi).is_identity() + sage: (phi.inverse() * phi).is_identity() # optional - sage.libs.singular True Automorphisms of number fields as well as Galois fields are supported:: - sage: K. = CyclotomicField(7) - sage: c = K.hom([1/zeta7]) - sage: (c.inverse() * c).is_identity() + sage: K. = CyclotomicField(7) # optional - sage.rings.number_field + sage: c = K.hom([1/zeta7]) # optional - sage.rings.number_field + sage: (c.inverse() * c).is_identity() # optional - sage.rings.number_field True - sage: F. = GF(7^3) - sage: f = F.hom(t^7, F) - sage: (f.inverse() * f).is_identity() + sage: F. = GF(7^3) # optional - sage.rings.finite_rings + sage: f = F.hom(t^7, F) # optional - sage.rings.finite_rings + sage: (f.inverse() * f).is_identity() # optional - sage.rings.finite_rings True An isomorphism between the algebraic torus and the circle over a number field:: - sage: K. = QuadraticField(-1) - sage: A. = K['z,w'].quotient('z*w - 1') - sage: B. = K['x,y'].quotient('x^2 + y^2 - 1') - sage: f = A.hom([x + i*y, x - i*y], B) - sage: g = f.inverse() - sage: g.morphism_from_cover().im_gens() + sage: K. = QuadraticField(-1) # optional - sage.rings.number_field + sage: A. = K['z,w'].quotient('z*w - 1') # optional - sage.rings.number_field + sage: B. = K['x,y'].quotient('x^2 + y^2 - 1') # optional - sage.rings.number_field + sage: f = A.hom([x + i*y, x - i*y], B) # optional - sage.rings.number_field + sage: g = f.inverse() # optional - sage.rings.number_field + sage: g.morphism_from_cover().im_gens() # optional - sage.rings.number_field [1/2*z + 1/2*w, (-1/2*i)*z + (1/2*i)*w] - sage: all(g(f(z)) == z for z in A.gens()) + sage: all(g(f(z)) == z for z in A.gens()) # optional - sage.rings.number_field True TESTS: @@ -1445,43 +1466,43 @@ cdef class RingHomomorphism(RingMap): Morphisms involving quotient rings:: sage: R. = QQ[] - sage: S. = QQ['s,u,t'].quotient('u-t^2') - sage: f = R.hom([s, -t], S) - sage: (f.inverse() * f).is_identity() + sage: S. = QQ['s,u,t'].quotient('u-t^2') # optional - sage.libs.singular + sage: f = R.hom([s, -t], S) # optional - sage.libs.singular + sage: (f.inverse() * f).is_identity() # optional - sage.libs.singular True - sage: Q. = R.quotient(x-y^2) - sage: g = Q.hom([v, -w], Q) - sage: g.inverse()(g(v)) == v and g.inverse()(g(w)) == w + sage: Q. = R.quotient(x - y^2) # optional - sage.libs.singular + sage: g = Q.hom([v, -w], Q) # optional - sage.libs.singular + sage: g.inverse()(g(v)) == v and g.inverse()(g(w)) == w # optional - sage.libs.singular True sage: S. = QQ[] - sage: h = Q.hom([z^2, -z], S) - sage: h.inverse()(h(v)) == v and h.inverse()(h(w)) == w + sage: h = Q.hom([z^2, -z], S) # optional - sage.libs.singular + sage: h.inverse()(h(v)) == v and h.inverse()(h(w)) == w # optional - sage.libs.singular True Morphisms between number fields and quotient rings:: - sage: K. = QuadraticField(2) - sage: f = K.hom([-sqrt2], K.polynomial_quotient_ring()) - sage: (f.inverse() * f).is_identity() + sage: K. = QuadraticField(2) # optional - sage.rings.number_field + sage: f = K.hom([-sqrt2], K.polynomial_quotient_ring()) # optional - sage.rings.number_field + sage: (f.inverse() * f).is_identity() # optional - sage.rings.number_field True - sage: g = K.polynomial_quotient_ring().hom([-sqrt2], K) - sage: (g.inverse() * g).is_identity() + sage: g = K.polynomial_quotient_ring().hom([-sqrt2], K) # optional - sage.rings.number_field + sage: (g.inverse() * g).is_identity() # optional - sage.rings.number_field True Morphisms involving Galois fields:: - sage: A. = GF(7^3) - sage: R = A.polynomial_ring().quotient(A.polynomial()) - sage: g = A.hom(R.gens(), R) - sage: (g.inverse() * g).is_identity() + sage: A. = GF(7^3) # optional - sage.rings.finite_rings + sage: R = A.polynomial_ring().quotient(A.polynomial()) # optional - sage.rings.finite_rings + sage: g = A.hom(R.gens(), R) # optional - sage.rings.finite_rings + sage: (g.inverse() * g).is_identity() # optional - sage.rings.finite_rings True - sage: B., f = A.extension(3, map=True) - sage: f.inverse() + sage: B., f = A.extension(3, map=True) # optional - sage.rings.finite_rings + sage: f.inverse() # optional - sage.rings.finite_rings Traceback (most recent call last): ... ZeroDivisionError: ring homomorphism not surjective - sage: B., f = A.extension(1, map=True) - sage: f.inverse() + sage: B., f = A.extension(1, map=True) # optional - sage.rings.finite_rings + sage: f.inverse() # optional - sage.rings.finite_rings Ring morphism: From: Finite Field in T of size 7^3 To: Finite Field in t of size 7^3 @@ -1491,7 +1512,7 @@ cdef class RingHomomorphism(RingMap): sage: R. = QQ[] sage: S. = QQ[] - sage: S.hom([x, y, 0], R).inverse() + sage: S.hom([x, y, 0], R).inverse() # optional - sage.libs.singular Traceback (most recent call last): ... ZeroDivisionError: ring homomorphism not injective @@ -1500,12 +1521,12 @@ cdef class RingHomomorphism(RingMap): Traceback (most recent call last): ... ZeroDivisionError: ring homomorphism not injective - sage: Q. = R.quotient([x^5, y^4]) - sage: R.hom([u, v], Q).inverse() + sage: Q. = R.quotient([x^5, y^4]) # optional - sage.libs.singular + sage: R.hom([u, v], Q).inverse() # optional - sage.libs.singular Traceback (most recent call last): ... ZeroDivisionError: ring homomorphism not injective - sage: Q.cover().inverse() + sage: Q.cover().inverse() # optional - sage.libs.singular Traceback (most recent call last): ... ZeroDivisionError: ring homomorphism not injective @@ -1519,23 +1540,23 @@ cdef class RingHomomorphism(RingMap): A homomorphism over ``QQbar``:: - sage: R. = QQbar[] - sage: f = R.hom([x + QQbar(I)*y^2, -y], R) - sage: (f.inverse() * f).is_identity() + sage: R. = QQbar[] # optional - sage.rings.number_field + sage: f = R.hom([x + QQbar(I)*y^2, -y], R) # optional - sage.rings.number_field + sage: (f.inverse() * f).is_identity() # optional - sage.rings.number_field True Check that results are cached:: - sage: R. = GF(823)[] - sage: f = R.hom([x, y+x^2], R) - sage: f.inverse() is f.inverse() + sage: R. = GF(823)[] # optional - sage.rings.finite_rings + sage: f = R.hom([x, y+x^2], R) # optional - sage.rings.finite_rings + sage: f.inverse() is f.inverse() # optional - sage.rings.finite_rings True Some subclasses of ring homomorphisms are not supported:: sage: from sage.rings.morphism import FrobeniusEndomorphism_generic - sage: K. = PowerSeriesRing(GF(5)) - sage: FrobeniusEndomorphism_generic(K).inverse() + sage: K. = PowerSeriesRing(GF(5)) # optional - sage.rings.finite_rings + sage: FrobeniusEndomorphism_generic(K).inverse() # optional - sage.rings.finite_rings Traceback (most recent call last): ... NotImplementedError @@ -1562,11 +1583,11 @@ cdef class RingHomomorphism(RingMap): sage: R. = QQ[] sage: f = R.hom([x + 123*y^2, y], R) - sage: f._graph_ideal()[0].groebner_basis.is_in_cache() + sage: f._graph_ideal()[0].groebner_basis.is_in_cache() # optional - sage.libs.singular False - sage: f.is_injective() + sage: f.is_injective() # optional - sage.libs.singular True - sage: f._graph_ideal()[0].groebner_basis.is_in_cache() + sage: f._graph_ideal()[0].groebner_basis.is_in_cache() # optional - sage.libs.singular True """ if not self.is_injective(): @@ -1586,9 +1607,9 @@ cdef class RingHomomorphism(RingMap): EXAMPLES:: - sage: R. = GF(17)[] - sage: f = R.hom([3*x, y + x^2 + x^3], R) - sage: (f * ~f).is_identity() + sage: R. = GF(17)[] # optional - sage.rings.finite_rings + sage: f = R.hom([3*x, y + x^2 + x^3], R) # optional - sage.rings.finite_rings + sage: (f * ~f).is_identity() # optional - sage.rings.finite_rings True """ return self.inverse() @@ -1600,10 +1621,10 @@ cdef class RingHomomorphism(RingMap): EXAMPLES:: sage: R. = QQ[] - sage: R.hom([y*z, x*z, x*y], R).is_surjective() + sage: R.hom([y*z, x*z, x*y], R).is_surjective() # optional - sage.libs.singular False - sage: Q. = R.quotient(x*y*z - 1) - sage: R.hom([y*z, x*z, x*y], Q).is_surjective() + sage: Q. = R.quotient(x*y*z - 1) # optional - sage.libs.singular + sage: R.hom([y*z, x*z, x*y], Q).is_surjective() # optional - sage.libs.singular True ALGORITHM: @@ -1624,10 +1645,10 @@ cdef class RingHomomorphism(RingMap): EXAMPLES:: sage: R. = QQ[] - sage: R.hom([y*z, x*z, x*y], R).is_invertible() + sage: R.hom([y*z, x*z, x*y], R).is_invertible() # optional - sage.libs.singular False - sage: Q. = R.quotient(x*y*z - 1) - sage: Q.hom([y*z, x*z, x*y], Q).is_invertible() + sage: Q. = R.quotient(x*y*z - 1) # optional - sage.libs.singular + sage: Q.hom([y*z, x*z, x*y], Q).is_invertible() # optional - sage.libs.singular True ALGORITHM: @@ -1760,7 +1781,7 @@ cdef class RingHomomorphism_im_gens(RingHomomorphism): EXAMPLES:: sage: R. = QQ[] - sage: phi = R.hom([x,x+y]); phi + sage: phi = R.hom([x, x + y]); phi Ring endomorphism of Multivariate Polynomial Ring in x, y over Rational Field Defn: x |--> x y |--> x + y @@ -1769,33 +1790,34 @@ cdef class RingHomomorphism_im_gens(RingHomomorphism): Here's another example where the domain isn't free:: - sage: S. = R.quotient(x - y) - sage: phi = S.hom([xx+1,xx+1]) + sage: S. = R.quotient(x - y) # optional - sage.libs.singular + sage: phi = S.hom([xx + 1, xx + 1]) # optional - sage.libs.singular Note that one has to specify valid images:: - sage: phi = S.hom([xx+1,xx-1]) + sage: phi = S.hom([xx + 1, xx - 1]) # optional - sage.libs.singular Traceback (most recent call last): ... - ValueError: relations do not all (canonically) map to 0 under map determined by images of generators + ValueError: relations do not all (canonically) map to 0 + under map determined by images of generators You can give a map of the base ring:: sage: Zx. = ZZ[] - sage: K. = NumberField(x^2 + 1) - sage: cc = K.hom([-i]) - sage: R. = K[] - sage: z = 1 + i*t + (3+4*i)*t^2 - sage: z._im_gens_(R, [t^2], base_map=cc) + sage: K. = NumberField(x^2 + 1) # optional - sage.rings.number_field + sage: cc = K.hom([-i]) # optional - sage.rings.number_field + sage: R. = K[] # optional - sage.rings.number_field + sage: z = 1 + i*t + (3+4*i)*t^2 # optional - sage.rings.number_field + sage: z._im_gens_(R, [t^2], base_map=cc) # optional - sage.rings.number_field (-4*i + 3)*t^4 - i*t^2 + 1 The base map's codomain is extended to the whole codomain:: sage: S. = QQ[] sage: T. = S[] - sage: cc = S.hom([x+1]) - sage: f = T.hom([x-y], base_map=cc) - sage: g = T.hom([x-y], base_map=cc.extend_codomain(T)) + sage: cc = S.hom([x + 1]) + sage: f = T.hom([x - y], base_map=cc) + sage: g = T.hom([x - y], base_map=cc.extend_codomain(T)) sage: f == g True sage: f.base_map() == cc.extend_codomain(T) @@ -1806,11 +1828,12 @@ cdef class RingHomomorphism_im_gens(RingHomomorphism): speed up creation of a homomorphism:: sage: R. = QQ[] - sage: S. = R.quotient(x - y) - sage: phi = S.hom([xx+1,xx-1], check=False) + sage: S. = R.quotient(x - y) # optional - sage.libs.singular + sage: phi = S.hom([xx + 1, xx - 1], check=False) # optional - sage.libs.singular Traceback (most recent call last): ... - ValueError: relations do not all (canonically) map to 0 under map determined by images of generators + ValueError: relations do not all (canonically) map to 0 + under map determined by images of generators """ RingHomomorphism.__init__(self, parent) if not isinstance(im_gens, sage.structure.sequence.Sequence_generic): @@ -1848,7 +1871,7 @@ cdef class RingHomomorphism_im_gens(RingHomomorphism): EXAMPLES:: sage: R. = QQ[] - sage: f = R.hom([x,x+y]) + sage: f = R.hom([x, x + y]) sage: f.im_gens() [x, x + y] @@ -1869,28 +1892,31 @@ cdef class RingHomomorphism_im_gens(RingHomomorphism): EXAMPLES:: sage: R. = ZZ[] - sage: K. = NumberField(x^2 + 1) - sage: cc = K.hom([-i]) - sage: S. = K[] - sage: phi = S.hom([y^2], base_map=cc) - sage: phi - Ring endomorphism of Univariate Polynomial Ring in y over Number Field in i with defining polynomial x^2 + 1 + sage: K. = NumberField(x^2 + 1) # optional - sage.rings.number_field + sage: cc = K.hom([-i]) # optional - sage.rings.number_field + sage: S. = K[] # optional - sage.rings.number_field + sage: phi = S.hom([y^2], base_map=cc) # optional - sage.rings.number_field + sage: phi # optional - sage.rings.number_field + Ring endomorphism of Univariate Polynomial Ring in y + over Number Field in i with defining polynomial x^2 + 1 Defn: y |--> y^2 with map of base ring - sage: phi(y) + sage: phi(y) # optional - sage.rings.number_field y^2 - sage: phi(i*y) + sage: phi(i*y) # optional - sage.rings.number_field -i*y^2 - sage: phi.base_map() + sage: phi.base_map() # optional - sage.rings.number_field Composite map: From: Number Field in i with defining polynomial x^2 + 1 - To: Univariate Polynomial Ring in y over Number Field in i with defining polynomial x^2 + 1 + To: Univariate Polynomial Ring in y over Number Field in i + with defining polynomial x^2 + 1 Defn: Ring endomorphism of Number Field in i with defining polynomial x^2 + 1 Defn: i |--> -i then Polynomial base injection morphism: From: Number Field in i with defining polynomial x^2 + 1 - To: Univariate Polynomial Ring in y over Number Field in i with defining polynomial x^2 + 1 + To: Univariate Polynomial Ring in y over Number Field in i + with defining polynomial x^2 + 1 """ return self._base_map @@ -1901,7 +1927,7 @@ cdef class RingHomomorphism_im_gens(RingHomomorphism): EXAMPLES:: sage: R. = QQ[] - sage: f = R.hom([x,x+y]) + sage: f = R.hom([x, x + y]) sage: g = copy(f) # indirect doctest sage: g == f True @@ -1921,7 +1947,7 @@ cdef class RingHomomorphism_im_gens(RingHomomorphism): EXAMPLES:: sage: R. = QQ[] - sage: f = R.hom([x,x+y]) + sage: f = R.hom([x, x + y]) sage: g = copy(f) # indirect doctest sage: g == f True @@ -1942,51 +1968,51 @@ cdef class RingHomomorphism_im_gens(RingHomomorphism): A single variate quotient over `\QQ`:: sage: R. = QQ[] - sage: Q. = R.quotient(x^2 + x + 1) - sage: f1 = R.hom([a]) - sage: f2 = R.hom([a + a^2 + a + 1]) - sage: f1 == f2 + sage: Q. = R.quotient(x^2 + x + 1) # optional - sage.libs.pari + sage: f1 = R.hom([a]) # optional - sage.libs.pari + sage: f2 = R.hom([a + a^2 + a + 1]) # optional - sage.libs.pari + sage: f1 == f2 # optional - sage.libs.pari True - sage: f1 == R.hom([a^2]) + sage: f1 == R.hom([a^2]) # optional - sage.libs.pari False - sage: f1(x^3 + x) + sage: f1(x^3 + x) # optional - sage.libs.pari a + 1 - sage: f2(x^3 + x) + sage: f2(x^3 + x) # optional - sage.libs.pari a + 1 TESTS:: - sage: loads(dumps(f2)) == f2 + sage: loads(dumps(f2)) == f2 # optional - sage.libs.pari True :: - sage: R. = QQ[]; f = R.hom([x,x+y]); g = R.hom([y,x]) - sage: f == g # indirect doctest + sage: R. = QQ[]; f = R.hom([x, x + y]); g = R.hom([y, x]) # optional - sage.libs.pari + sage: f == g # indirect doctest # optional - sage.libs.pari False EXAMPLES: A multivariate quotient over a finite field:: - sage: R. = GF(7)[] - sage: Q. = R.quotient([x^2 + x + 1, y^2 + y + 1]) - sage: f1 = R.hom([a, b]) - sage: f2 = R.hom([a + a^2 + a + 1, b + b^2 + b + 1]) - sage: f1 == f2 + sage: R. = GF(7)[] # optional - sage.rings.finite_rings + sage: Q. = R.quotient([x^2 + x + 1, y^2 + y + 1]) # optional - sage.rings.finite_rings + sage: f1 = R.hom([a, b]) # optional - sage.rings.finite_rings + sage: f2 = R.hom([a + a^2 + a + 1, b + b^2 + b + 1]) # optional - sage.rings.finite_rings + sage: f1 == f2 # optional - sage.rings.finite_rings True - sage: f1 == R.hom([b,a]) + sage: f1 == R.hom([b, a]) # optional - sage.rings.finite_rings False - sage: x^3 + x + y^2 + sage: x^3 + x + y^2 # optional - sage.rings.finite_rings x^3 + y^2 + x - sage: f1(x^3 + x + y^2) + sage: f1(x^3 + x + y^2) # optional - sage.rings.finite_rings a - b - sage: f2(x^3 + x + y^2) + sage: f2(x^3 + x + y^2) # optional - sage.rings.finite_rings a - b TESTS:: - sage: loads(dumps(f2)) == f2 + sage: loads(dumps(f2)) == f2 # optional - sage.rings.finite_rings True This was fixed in :trac:`24277`:: @@ -2078,8 +2104,10 @@ cdef class RingHomomorphism_from_base(RingHomomorphism): sage: Pf = PR.hom(f,PS) sage: Pf Ring morphism: - From: Univariate Polynomial Ring in t over Multivariate Polynomial Ring in x, y over Rational Field - To: Univariate Polynomial Ring in t over Univariate Polynomial Ring in z over Rational Field + From: Univariate Polynomial Ring in t + over Multivariate Polynomial Ring in x, y over Rational Field + To: Univariate Polynomial Ring in t + over Univariate Polynomial Ring in z over Rational Field Defn: Induced from base ring by Ring morphism: From: Multivariate Polynomial Ring in x, y over Rational Field @@ -2093,44 +2121,54 @@ cdef class RingHomomorphism_from_base(RingHomomorphism): Similarly, we can construct the induced homomorphism on a matrix ring over our polynomial rings:: - sage: MR = MatrixSpace(R,2,2) - sage: MS = MatrixSpace(S,2,2) - sage: M = MR([x^2 + 1/7*x*y - y^2, - 1/2*y^2 + 2*y + 1/6, 4*x^2 - 14*x, 1/2*y^2 + 13/4*x - 2/11*y]) - sage: Mf = MR.hom(f,MS) - sage: Mf + sage: MR = MatrixSpace(R, 2, 2) # optional - sage.modules + sage: MS = MatrixSpace(S, 2, 2) # optional - sage.modules + sage: M = MR([x^2 + 1/7*x*y - y^2, -1/2*y^2 + 2*y + 1/6, # optional - sage.modules + ....: 4*x^2 - 14*x, 1/2*y^2 + 13/4*x - 2/11*y]) + sage: Mf = MR.hom(f, MS) # optional - sage.modules + sage: Mf # optional - sage.modules Ring morphism: - From: Full MatrixSpace of 2 by 2 dense matrices over Multivariate Polynomial Ring in x, y over Rational Field - To: Full MatrixSpace of 2 by 2 dense matrices over Univariate Polynomial Ring in z over Rational Field + From: Full MatrixSpace of 2 by 2 dense matrices + over Multivariate Polynomial Ring in x, y over Rational Field + To: Full MatrixSpace of 2 by 2 dense matrices + over Univariate Polynomial Ring in z over Rational Field Defn: Induced from base ring by Ring morphism: From: Multivariate Polynomial Ring in x, y over Rational Field To: Univariate Polynomial Ring in z over Rational Field Defn: x |--> 2*z y |--> 3*z - sage: Mf(M) + sage: Mf(M) # optional - sage.modules [ -29/7*z^2 -9/2*z^2 + 6*z + 1/6] [ 16*z^2 - 28*z 9/2*z^2 + 131/22*z] The construction of induced homomorphisms is recursive, and so we have:: - sage: MPR = MatrixSpace(PR, 2) - sage: MPS = MatrixSpace(PS, 2) - sage: M = MPR([(- x + y)*t^2 + 58*t - 3*x^2 + x*y, (- 1/7*x*y - 1/40*x)*t^2 + (5*x^2 + y^2)*t + 2*y, (- 1/3*y + 1)*t^2 + 1/3*x*y + y^2 + 5/2*y + 1/4, (x + 6*y + 1)*t^2]) - sage: MPf = MPR.hom(f,MPS); MPf + sage: MPR = MatrixSpace(PR, 2) # optional - sage.modules + sage: MPS = MatrixSpace(PS, 2) # optional - sage.modules + sage: M = MPR([(-x + y)*t^2 + 58*t - 3*x^2 + x*y, # optional - sage.modules + ....: (- 1/7*x*y - 1/40*x)*t^2 + (5*x^2 + y^2)*t + 2*y, + ....: (- 1/3*y + 1)*t^2 + 1/3*x*y + y^2 + 5/2*y + 1/4, + ....: (x + 6*y + 1)*t^2]) + sage: MPf = MPR.hom(f, MPS); MPf # optional - sage.modules Ring morphism: - From: Full MatrixSpace of 2 by 2 dense matrices over Univariate Polynomial Ring in t over Multivariate Polynomial Ring in x, y over Rational Field - To: Full MatrixSpace of 2 by 2 dense matrices over Univariate Polynomial Ring in t over Univariate Polynomial Ring in z over Rational Field + From: Full MatrixSpace of 2 by 2 dense matrices over Univariate Polynomial + Ring in t over Multivariate Polynomial Ring in x, y over Rational Field + To: Full MatrixSpace of 2 by 2 dense matrices over Univariate Polynomial + Ring in t over Univariate Polynomial Ring in z over Rational Field Defn: Induced from base ring by Ring morphism: - From: Univariate Polynomial Ring in t over Multivariate Polynomial Ring in x, y over Rational Field - To: Univariate Polynomial Ring in t over Univariate Polynomial Ring in z over Rational Field + From: Univariate Polynomial Ring in t + over Multivariate Polynomial Ring in x, y over Rational Field + To: Univariate Polynomial Ring in t + over Univariate Polynomial Ring in z over Rational Field Defn: Induced from base ring by Ring morphism: From: Multivariate Polynomial Ring in x, y over Rational Field To: Univariate Polynomial Ring in z over Rational Field Defn: x |--> 2*z y |--> 3*z - sage: MPf(M) + sage: MPf(M) # optional - sage.modules [ z*t^2 + 58*t - 6*z^2 (-6/7*z^2 - 1/20*z)*t^2 + 29*z^2*t + 6*z] [ (-z + 1)*t^2 + 11*z^2 + 15/2*z + 1/4 (20*z + 1)*t^2] """ @@ -2142,11 +2180,12 @@ cdef class RingHomomorphism_from_base(RingHomomorphism): sage: from sage.rings.morphism import RingHomomorphism_from_base sage: R. = ZZ[] - sage: f = R.hom([2*x],R) - sage: P = MatrixSpace(R,2).Hom(MatrixSpace(R,2)) - sage: g = RingHomomorphism_from_base(P,f) - sage: g - Ring endomorphism of Full MatrixSpace of 2 by 2 dense matrices over Univariate Polynomial Ring in x over Integer Ring + sage: f = R.hom([2*x], R) + sage: P = MatrixSpace(R, 2).Hom(MatrixSpace(R, 2)) # optional - sage.modules + sage: g = RingHomomorphism_from_base(P, f) # optional - sage.modules + sage: g # optional - sage.modules + Ring endomorphism of Full MatrixSpace of 2 by 2 dense matrices + over Univariate Polynomial Ring in x over Integer Ring Defn: Induced from base ring by Ring endomorphism of Univariate Polynomial Ring in x over Integer Ring Defn: x |--> 2*x @@ -2155,11 +2194,13 @@ cdef class RingHomomorphism_from_base(RingHomomorphism): codomain are constructed in a compatible way. So, the following results in an error:: - sage: P = MatrixSpace(R,2).Hom(R['t']) - sage: g = RingHomomorphism_from_base(P,f) + sage: P = MatrixSpace(R, 2).Hom(R['t']) # optional - sage.modules + sage: g = RingHomomorphism_from_base(P, f) # optional - sage.modules Traceback (most recent call last): ... - ValueError: domain (Full MatrixSpace of 2 by 2 dense matrices over Univariate Polynomial Ring in x over Integer Ring) and codomain (Univariate Polynomial Ring in t over Univariate Polynomial Ring in x over Integer Ring) must have the same functorial construction over their base rings + ValueError: domain (Full MatrixSpace of 2 by 2 dense matrices over Univariate Polynomial Ring in x over Integer Ring) + and codomain (Univariate Polynomial Ring in t over Univariate Polynomial Ring in x over Integer Ring) + must have the same functorial construction over their base rings """ RingHomomorphism.__init__(self, parent) if underlying.domain() != parent.domain().base(): @@ -2178,11 +2219,11 @@ cdef class RingHomomorphism_from_base(RingHomomorphism): sage: R. = QQ[] sage: S. = QQ[] - sage: f = R.hom([2*z,3*z],S) - sage: MR = MatrixSpace(R,2) - sage: MS = MatrixSpace(S,2) - sage: g = MR.hom(f,MS) - sage: g.underlying_map() == f + sage: f = R.hom([2*z, 3*z], S) + sage: MR = MatrixSpace(R, 2) # optional - sage.modules + sage: MS = MatrixSpace(S, 2) # optional - sage.modules + sage: g = MR.hom(f, MS) # optional - sage.modules + sage: g.underlying_map() == f # optional - sage.modules True """ return self._underlying @@ -2195,10 +2236,10 @@ cdef class RingHomomorphism_from_base(RingHomomorphism): sage: R. = QQ[] sage: S. = QQ[] - sage: f = R.hom([2*z,3*z],S) + sage: f = R.hom([2*z, 3*z],S) sage: PR. = R[] sage: PS = S['t'] - sage: phi = PR.hom(f,PS) + sage: phi = PR.hom(f, PS) sage: type(phi) sage: psi = copy(phi); psi # indirect doctest @@ -2256,24 +2297,24 @@ cdef class RingHomomorphism_from_base(RingHomomorphism): `\QQ`:: sage: R. = QQ[] - sage: Q. = R.quotient(x^2 + x + 1) - sage: f1 = R.hom([a]) - sage: f2 = R.hom([a + a^2 + a + 1]) - sage: PR. = R[] - sage: PQ = Q['s','t'] - sage: f1P = PR.hom(f1,PQ) - sage: f2P = PR.hom(f2,PQ) - sage: f1P == f2P + sage: Q. = R.quotient(x^2 + x + 1) # optional - sage.libs.pari sage.modules + sage: f1 = R.hom([a]) # optional - sage.libs.pari sage.libs.singular sage.modules + sage: f2 = R.hom([a + a^2 + a + 1]) # optional - sage.libs.pari sage.libs.singular sage.modules + sage: PR. = R[] # optional - sage.libs.pari sage.libs.singular sage.modules + sage: PQ = Q['s','t'] # optional - sage.libs.pari sage.libs.singular sage.modules + sage: f1P = PR.hom(f1,PQ) # optional - sage.libs.pari sage.libs.singular sage.modules + sage: f2P = PR.hom(f2,PQ) # optional - sage.libs.pari sage.libs.singular sage.modules + sage: f1P == f2P # optional - sage.libs.pari sage.libs.singular sage.modules True TESTS:: - sage: f1P == loads(dumps(f1P)) + sage: f1P == loads(dumps(f1P)) # optional - sage.libs.pari sage.libs.singular sage.modules True - sage: R. = QQ[]; f = R.hom([x,x+y]); g = R.hom([y,x]) + sage: R. = QQ[]; f = R.hom([x, x + y]); g = R.hom([y, x]) sage: S. = R[] - sage: fS = S.hom(f,S); gS = S.hom(g,S) + sage: fS = S.hom(f, S); gS = S.hom(g, S) sage: fS != gS # indirect doctest True @@ -2281,20 +2322,20 @@ cdef class RingHomomorphism_from_base(RingHomomorphism): A matrix ring over a multivariate quotient over a finite field:: - sage: R. = GF(7)[] - sage: Q. = R.quotient([x^2 + x + 1, y^2 + y + 1]) - sage: f1 = R.hom([a, b]) - sage: f2 = R.hom([a + a^2 + a + 1, b + b^2 + b + 1]) - sage: MR = MatrixSpace(R,2) - sage: MQ = MatrixSpace(Q,2) - sage: f1M = MR.hom(f1,MQ) - sage: f2M = MR.hom(f2,MQ) - sage: f1M == f2M + sage: R. = GF(7)[] # optional - sage.rings.finite_rings + sage: Q. = R.quotient([x^2 + x + 1, y^2 + y + 1]) # optional - sage.rings.finite_rings + sage: f1 = R.hom([a, b]) # optional - sage.rings.finite_rings + sage: f2 = R.hom([a + a^2 + a + 1, b + b^2 + b + 1]) # optional - sage.rings.finite_rings + sage: MR = MatrixSpace(R, 2) # optional - sage.rings.finite_rings sage.modules + sage: MQ = MatrixSpace(Q, 2) # optional - sage.rings.finite_rings sage.modules + sage: f1M = MR.hom(f1, MQ) # optional - sage.rings.finite_rings sage.modules + sage: f2M = MR.hom(f2, MQ) # optional - sage.rings.finite_rings sage.modules + sage: f1M == f2M # optional - sage.rings.finite_rings sage.modules True TESTS:: - sage: f1M == loads(dumps(f1M)) + sage: f1M == loads(dumps(f1M)) # optional - sage.rings.finite_rings sage.modules True """ if not isinstance(other, RingHomomorphism_from_base): @@ -2314,11 +2355,12 @@ cdef class RingHomomorphism_from_base(RingHomomorphism): over a multivariate polynomial ring:: sage: R1. = ZZ[] - sage: f = R1.hom([x+y,x-y]) - sage: R2 = MatrixSpace(FractionField(R1)['t'],2) - sage: g = R2.hom(f,R2) - sage: g #indirect doctest - Ring endomorphism of Full MatrixSpace of 2 by 2 dense matrices over Univariate Polynomial Ring in t over Fraction Field of Multivariate Polynomial Ring in x, y over Integer Ring + sage: f = R1.hom([x + y, x - y]) + sage: R2 = MatrixSpace(FractionField(R1)['t'], 2) # optional - sage.modules + sage: g = R2.hom(f, R2) # optional - sage.modules + sage: g #indirect doctest # optional - sage.modules + Ring endomorphism of Full MatrixSpace of 2 by 2 dense matrices + over Univariate Polynomial Ring in t over Fraction Field of Multivariate Polynomial Ring in x, y over Integer Ring Defn: Induced from base ring by Ring endomorphism of Univariate Polynomial Ring in t over Fraction Field of Multivariate Polynomial Ring in x, y over Integer Ring Defn: Induced from base ring by @@ -2364,11 +2406,11 @@ cdef class RingHomomorphism_from_base(RingHomomorphism): sage: R. = QQ[] sage: S. = QQ[] - sage: f = R.hom([a+b, a-b], S) + sage: f = R.hom([a + b, a - b], S) # optional - sage.libs.singular sage: PR. = R[] sage: PS = S['t'] - sage: Pf = PR.hom(f, PS) - sage: Pf.inverse() + sage: Pf = PR.hom(f, PS) # optional - sage.libs.singular + sage: Pf.inverse() # optional - sage.libs.singular Ring morphism: From: Univariate Polynomial Ring in t over Multivariate Polynomial Ring in a, b over Rational Field @@ -2380,7 +2422,7 @@ cdef class RingHomomorphism_from_base(RingHomomorphism): To: Multivariate Polynomial Ring in x, y over Rational Field Defn: a |--> 1/2*x + 1/2*y b |--> 1/2*x - 1/2*y - sage: Pf.inverse()(Pf(x*t^2 + y*t)) + sage: Pf.inverse()(Pf(x*t^2 + y*t)) # optional - sage.libs.singular x*t^2 + y*t """ return self.parent().reversed()(self._underlying.inverse()) @@ -2394,8 +2436,8 @@ cdef class RingHomomorphism_from_fraction_field(RingHomomorphism): sage: S. = QQ[] sage: f = S.hom([x^2]) - sage: g = f.extend_to_fraction_field() - sage: type(g) + sage: g = f.extend_to_fraction_field() # optional - sage.libs.singular + sage: type(g) # optional - sage.libs.singular """ def __init__(self, parent, morphism): @@ -2404,10 +2446,11 @@ cdef class RingHomomorphism_from_fraction_field(RingHomomorphism): TESTS:: - sage: A. = ZZ.extension(x^2 - 2) - sage: f = A.coerce_map_from(ZZ) - sage: g = f.extend_to_fraction_field() # indirect doctest - sage: g + sage: x = polygen(ZZ, 'x') + sage: A. = ZZ.extension(x^2 - 2) # optional - sage.rings.number_field + sage: f = A.coerce_map_from(ZZ) # optional - sage.rings.number_field + sage: g = f.extend_to_fraction_field() # indirect doctest # optional - sage.rings.number_field + sage: g # optional - sage.rings.number_field Ring morphism: From: Rational Field To: Number Field in a with defining polynomial x^2 - 2 @@ -2422,11 +2465,11 @@ cdef class RingHomomorphism_from_fraction_field(RingHomomorphism): EXAMPLES:: sage: S. = QQ[] - sage: f = S.hom([x^2]).extend_to_fraction_field() - sage: f + sage: f = S.hom([x^2]).extend_to_fraction_field() # optional - sage.libs.singular + sage: f # optional - sage.libs.singular Ring endomorphism of Fraction Field of Univariate Polynomial Ring in x over Rational Field Defn: x |--> x^2 - sage: f._repr_defn() + sage: f._repr_defn() # optional - sage.libs.singular 'x |--> x^2' """ return self._morphism._repr_defn() @@ -2442,10 +2485,10 @@ cdef class RingHomomorphism_from_fraction_field(RingHomomorphism): EXAMPLES:: sage: S. = QQ[] - sage: f = S.hom([x+1]).extend_to_fraction_field() - sage: f(1/x) + sage: f = S.hom([x + 1]).extend_to_fraction_field() # optional - sage.libs.singular + sage: f(1/x) # optional - sage.libs.singular 1/(x + 1) - sage: f(1/(x-1)) + sage: f(1/(x-1)) # optional - sage.libs.singular 1/x """ return self._morphism(x.numerator()) / self._morphism(x.denominator()) @@ -2457,12 +2500,12 @@ cdef class RingHomomorphism_from_fraction_field(RingHomomorphism): TESTS:: sage: S. = QQ[] - sage: f = S.hom([x+1]).extend_to_fraction_field() + sage: f = S.hom([x + 1]).extend_to_fraction_field() # optional - sage.libs.singular - sage: g = copy(f) # indirect doctest - sage: f == g + sage: g = copy(f) # indirect doctest # optional - sage.libs.singular + sage: f == g # optional - sage.libs.singular True - sage: f is g + sage: f is g # optional - sage.libs.singular False """ self._morphism = _slots['_morphism'] @@ -2475,8 +2518,8 @@ cdef class RingHomomorphism_from_fraction_field(RingHomomorphism): TESTS:: sage: S. = QQ[] - sage: f = S.hom([x+1]).extend_to_fraction_field() - sage: loads(dumps(f)) == f + sage: f = S.hom([x + 1]).extend_to_fraction_field() # optional - sage.libs.singular + sage: loads(dumps(f)) == f # optional - sage.libs.singular True """ slots = RingHomomorphism._extra_slots(self) @@ -2492,10 +2535,10 @@ cdef class RingHomomorphism_from_fraction_field(RingHomomorphism): sage: S. = QQ[] sage: f = S.hom([2*x - 1]) - sage: g = f.extend_to_fraction_field() - sage: g.inverse() + sage: g = f.extend_to_fraction_field() # optional - sage.libs.singular + sage: g.inverse() # optional - sage.libs.singular Ring endomorphism of Fraction Field of Univariate Polynomial Ring - in x over Rational Field + in x over Rational Field Defn: x |--> 1/2*x + 1/2 """ return self.parent().reversed()(self._morphism.inverse()) @@ -2508,13 +2551,14 @@ cdef class RingHomomorphism_cover(RingHomomorphism): EXAMPLES:: sage: R. = PolynomialRing(QQ, 2) - sage: S. = R.quo(x^2 + y^2) - sage: phi = S.cover(); phi + sage: S. = R.quo(x^2 + y^2) # optional - sage.libs.singular + sage: phi = S.cover(); phi # optional - sage.libs.singular Ring morphism: From: Multivariate Polynomial Ring in x, y over Rational Field - To: Quotient of Multivariate Polynomial Ring in x, y over Rational Field by the ideal (x^2 + y^2) + To: Quotient of Multivariate Polynomial Ring in x, y over Rational Field + by the ideal (x^2 + y^2) Defn: Natural quotient map - sage: phi(x+y) + sage: phi(x + y) # optional - sage.libs.singular a + b """ def __init__(self, parent): @@ -2561,7 +2605,8 @@ cdef class RingHomomorphism_cover(RingHomomorphism): sage: f(1/2) Traceback (most recent call last): ... - TypeError: 1/2 fails to convert into the map's domain Integer Ring, but a `pushforward` method is not properly implemented + TypeError: 1/2 fails to convert into the map's domain Integer Ring, + but a `pushforward` method is not properly implemented """ return self.codomain()(x) @@ -2599,11 +2644,11 @@ cdef class RingHomomorphism_cover(RingHomomorphism): EXAMPLES:: sage: R. = PolynomialRing(QQ, 2) - sage: S. = R.quo(x^2 + y^2) - sage: phi = S.cover() - sage: phi == loads(dumps(phi)) + sage: S. = R.quo(x^2 + y^2) # optional - sage.libs.singular + sage: phi = S.cover() # optional - sage.libs.singular + sage: phi == loads(dumps(phi)) # optional - sage.libs.singular True - sage: phi == R.quo(x^2 + y^3).cover() + sage: phi == R.quo(x^2 + y^3).cover() # optional - sage.libs.singular False """ if not isinstance(other, RingHomomorphism_cover): @@ -2619,13 +2664,13 @@ cdef class RingHomomorphism_cover(RingHomomorphism): TESTS:: sage: R. = PolynomialRing(QQ, 2) - sage: S. = R.quo(x^2 + y^2) - sage: phi = S.cover() - sage: type(phi) + sage: S. = R.quo(x^2 + y^2) # optional - sage.libs.singular + sage: phi = S.cover() # optional - sage.libs.singular + sage: type(phi) # optional - sage.libs.singular - sage: hash(phi) == hash(phi) + sage: hash(phi) == hash(phi) # optional - sage.libs.singular True - sage: {phi: 1}[phi] + sage: {phi: 1}[phi] # optional - sage.libs.singular 1 """ return hash((self.domain(), self.codomain())) @@ -2640,12 +2685,12 @@ cdef class RingHomomorphism_cover(RingHomomorphism): EXAMPLES:: - sage: R. = QQ['x,y'].quotient('x^2 * y^2') - sage: R.cover().inverse_image(R.ideal(x^3, y^3 + 1)) + sage: R. = QQ['x,y'].quotient('x^2 * y^2') # optional - sage.libs.singular + sage: R.cover().inverse_image(R.ideal(x^3, y^3 + 1)) # optional - sage.libs.singular Ideal (x^2*y^2, x^3, y^3 + 1) of Multivariate Polynomial Ring in x, y over Rational Field - sage: S. = QQbar['u,v'].quotient('u^4 - 1') - sage: S.cover().inverse_image(S.ideal(u^2 - 1)) + sage: S. = QQbar['u,v'].quotient('u^4 - 1') # optional - sage.libs.singular + sage: S.cover().inverse_image(S.ideal(u^2 - 1)) # optional - sage.libs.singular Ideal (u^4 - 1, u^2 - 1) of Multivariate Polynomial Ring in u, v over Algebraic Field """ @@ -2660,8 +2705,8 @@ cdef class RingHomomorphism_cover(RingHomomorphism): EXAMPLES:: - sage: Q. = QQ['x,y'].quotient('x + y') - sage: Q.cover().inverse_image(u) + sage: Q. = QQ['x,y'].quotient('x + y') # optional - sage.libs.singular + sage: Q.cover().inverse_image(u) # optional - sage.libs.singular -y """ return b.lift() @@ -2690,25 +2735,27 @@ cdef class RingHomomorphism_from_quotient(RingHomomorphism): EXAMPLES:: sage: R. = PolynomialRing(QQ, 3) - sage: S. = R.quo(x^3 + y^3 + z^3) - sage: phi = S.hom([b, c, a]); phi - Ring endomorphism of Quotient of Multivariate Polynomial Ring in x, y, z over Rational Field by the ideal (x^3 + y^3 + z^3) + sage: S. = R.quo(x^3 + y^3 + z^3) # optional - sage.libs.singular + sage: phi = S.hom([b, c, a]); phi # optional - sage.libs.singular + Ring endomorphism of Quotient of Multivariate Polynomial Ring in x, y, z + over Rational Field by the ideal (x^3 + y^3 + z^3) Defn: a |--> b b |--> c c |--> a - sage: phi(a+b+c) + sage: phi(a + b + c) # optional - sage.libs.singular a + b + c - sage: loads(dumps(phi)) == phi + sage: loads(dumps(phi)) == phi # optional - sage.libs.singular True Validity of the homomorphism is determined, when possible, and a ``TypeError`` is raised if there is no homomorphism sending the generators to the given images:: - sage: S.hom([b^2, c^2, a^2]) + sage: S.hom([b^2, c^2, a^2]) # optional - sage.libs.singular Traceback (most recent call last): ... - ValueError: relations do not all (canonically) map to 0 under map determined by images of generators + ValueError: relations do not all (canonically) map to 0 + under map determined by images of generators """ def __init__(self, parent, phi): """ @@ -2716,8 +2763,9 @@ cdef class RingHomomorphism_from_quotient(RingHomomorphism): EXAMPLES:: - sage: R. = QQ[]; S. = R.quo([x^2,y^2]); S.hom([yy,xx]) - Ring endomorphism of Quotient of Multivariate Polynomial Ring in x, y over Rational Field by the ideal (x^2, y^2) + sage: R. = QQ[]; S. = R.quo([x^2,y^2]); S.hom([yy,xx]) # optional - sage.libs.singular + Ring endomorphism of Quotient of Multivariate Polynomial Ring in x, y + over Rational Field by the ideal (x^2, y^2) Defn: xx |--> yy yy |--> xx """ @@ -2743,20 +2791,21 @@ cdef class RingHomomorphism_from_quotient(RingHomomorphism): EXAMPLES:: sage: R. = PolynomialRing(QQ, 3) - sage: S. = R.quo(x^3 + y^3 + z^3) - sage: phi = S.hom([b, c, a]); phi - Ring endomorphism of Quotient of Multivariate Polynomial Ring in x, y, z over Rational Field by the ideal (x^3 + y^3 + z^3) + sage: S. = R.quo(x^3 + y^3 + z^3) # optional - sage.libs.singular + sage: phi = S.hom([b, c, a]); phi # optional - sage.libs.singular + Ring endomorphism of Quotient of Multivariate Polynomial Ring in x, y, z + over Rational Field by the ideal (x^3 + y^3 + z^3) Defn: a |--> b b |--> c c |--> a - sage: phi(a+b+c) + sage: phi(a + b + c) # optional - sage.libs.singular a + b + c - sage: psi = copy(phi) # indirect doctest - sage: psi == phi + sage: psi = copy(phi) # indirect doctest # optional - sage.libs.singular + sage: psi == phi # optional - sage.libs.singular True - sage: psi is phi + sage: psi is phi # optional - sage.libs.singular False - sage: psi(a) == phi(a) + sage: psi(a) == phi(a) # optional - sage.libs.singular True """ @@ -2770,20 +2819,21 @@ cdef class RingHomomorphism_from_quotient(RingHomomorphism): EXAMPLES:: sage: R. = PolynomialRing(QQ, 3) - sage: S. = R.quo(x^3 + y^3 + z^3) - sage: phi = S.hom([b, c, a]); phi - Ring endomorphism of Quotient of Multivariate Polynomial Ring in x, y, z over Rational Field by the ideal (x^3 + y^3 + z^3) + sage: S. = R.quo(x^3 + y^3 + z^3) # optional - sage.libs.singular + sage: phi = S.hom([b, c, a]); phi # optional - sage.libs.singular + Ring endomorphism of Quotient of Multivariate Polynomial Ring in x, y, z + over Rational Field by the ideal (x^3 + y^3 + z^3) Defn: a |--> b b |--> c c |--> a - sage: phi(a+b+c) + sage: phi(a + b + c) # optional - sage.libs.singular a + b + c - sage: psi = copy(phi) # indirect doctest - sage: psi == phi + sage: psi = copy(phi) # indirect doctest # optional - sage.libs.singular + sage: psi == phi # optional - sage.libs.singular True - sage: psi is phi + sage: psi is phi # optional - sage.libs.singular False - sage: psi(a) == phi(a) + sage: psi(a) == phi(a) # optional - sage.libs.singular True """ slots = RingHomomorphism._extra_slots(self) @@ -2797,8 +2847,8 @@ cdef class RingHomomorphism_from_quotient(RingHomomorphism): EXAMPLES:: - sage: R. = QQ[]; S. = R.quo([x^2,y^2]); f = S.hom([yy,xx]) - sage: f._phi() + sage: R. = QQ[]; S. = R.quo([x^2, y^2]); f = S.hom([yy,xx]) # optional - sage.libs.singular + sage: f._phi() # optional - sage.libs.singular Ring morphism: From: Multivariate Polynomial Ring in x, y over Rational Field To: Quotient of Multivariate Polynomial Ring in x, y over Rational Field by the ideal (x^2, y^2) @@ -2814,11 +2864,12 @@ cdef class RingHomomorphism_from_quotient(RingHomomorphism): EXAMPLES:: - sage: R. = QQ[]; S. = R.quo([x^2,y^2]) - sage: S.hom([yy,xx]).morphism_from_cover() + sage: R. = QQ[]; S. = R.quo([x^2, y^2]) # optional - sage.libs.singular + sage: S.hom([yy,xx]).morphism_from_cover() # optional - sage.libs.singular Ring morphism: From: Multivariate Polynomial Ring in x, y over Rational Field - To: Quotient of Multivariate Polynomial Ring in x, y over Rational Field by the ideal (x^2, y^2) + To: Quotient of Multivariate Polynomial Ring in x, y + over Rational Field by the ideal (x^2, y^2) Defn: x |--> yy y |--> xx """ @@ -2830,14 +2881,14 @@ cdef class RingHomomorphism_from_quotient(RingHomomorphism): EXAMPLES:: - sage: R. = PolynomialRing(GF(19), 3) - sage: S. = R.quo(x^3 + y^3 + z^3) - sage: phi = S.hom([b, c, a]) - sage: psi = S.hom([c, b, a]) - sage: f = S.hom([b, c, a + a^3 + b^3 + c^3]) - sage: phi == psi + sage: R. = PolynomialRing(GF(19), 3) # optional - sage.rings.finite_rings + sage: S. = R.quo(x^3 + y^3 + z^3) # optional - sage.rings.finite_rings + sage: phi = S.hom([b, c, a]) # optional - sage.rings.finite_rings + sage: psi = S.hom([c, b, a]) # optional - sage.rings.finite_rings + sage: f = S.hom([b, c, a + a^3 + b^3 + c^3]) # optional - sage.rings.finite_rings + sage: phi == psi # optional - sage.rings.finite_rings False - sage: phi == f + sage: phi == f # optional - sage.rings.finite_rings True """ if not isinstance(other, RingHomomorphism_from_quotient): @@ -2854,14 +2905,14 @@ cdef class RingHomomorphism_from_quotient(RingHomomorphism): EXAMPLES:: - sage: R. = PolynomialRing(GF(19), 3) - sage: S. = R.quo(x^3 + y^3 + z^3) - sage: phi = S.hom([b, c, a]) - sage: type(phi) + sage: R. = PolynomialRing(GF(19), 3) # optional - sage.rings.finite_rings + sage: S. = R.quo(x^3 + y^3 + z^3) # optional - sage.rings.finite_rings + sage: phi = S.hom([b, c, a]) # optional - sage.rings.finite_rings + sage: type(phi) # optional - sage.rings.finite_rings - sage: hash(phi) == hash(phi) + sage: hash(phi) == hash(phi) # optional - sage.rings.finite_rings True - sage: {phi: 1}[phi] + sage: {phi: 1}[phi] # optional - sage.rings.finite_rings 1 """ return hash(self.phi) @@ -2872,9 +2923,9 @@ cdef class RingHomomorphism_from_quotient(RingHomomorphism): EXAMPLES:: - sage: R. = QQ[]; S. = R.quo([x^2,y^2]) - sage: f = S.hom([yy,xx]) - sage: print(f._repr_defn()) + sage: R. = QQ[]; S. = R.quo([x^2,y^2]) # optional - sage.libs.singular + sage: f = S.hom([yy, xx]) # optional - sage.libs.singular + sage: print(f._repr_defn()) # optional - sage.libs.singular xx |--> yy yy |--> xx """ @@ -2889,8 +2940,8 @@ cdef class RingHomomorphism_from_quotient(RingHomomorphism): EXAMPLES:: - sage: R. = QQ[]; S. = R.quo([x^2,y^2]); f = S.hom([yy,xx]) - sage: f(3*x + (1/2)*y) # indirect doctest + sage: R. = QQ[]; S. = R.quo([x^2, y^2]); f = S.hom([yy, xx]) # optional - sage.libs.singular + sage: f(3*x + (1/2)*y) # indirect doctest # optional - sage.libs.singular 1/2*xx + 3*yy """ return self.phi(self.lift(x)) @@ -2917,11 +2968,13 @@ cdef class FrobeniusEndomorphism_generic(RingHomomorphism): TESTS:: sage: from sage.rings.morphism import FrobeniusEndomorphism_generic - sage: K. = PowerSeriesRing(GF(5)) - sage: FrobeniusEndomorphism_generic(K) - Frobenius endomorphism x |--> x^5 of Power Series Ring in u over Finite Field of size 5 - sage: FrobeniusEndomorphism_generic(K, 2) - Frobenius endomorphism x |--> x^(5^2) of Power Series Ring in u over Finite Field of size 5 + sage: K. = PowerSeriesRing(GF(5)) # optional - sage.rings.finite_rings + sage: FrobeniusEndomorphism_generic(K) # optional - sage.rings.finite_rings + Frobenius endomorphism x |--> x^5 of Power Series Ring in u + over Finite Field of size 5 + sage: FrobeniusEndomorphism_generic(K, 2) # optional - sage.rings.finite_rings + Frobenius endomorphism x |--> x^(5^2) of Power Series Ring in u + over Finite Field of size 5 """ from .ring import CommutativeRing from sage.categories.homset import Hom @@ -2948,10 +3001,10 @@ cdef class FrobeniusEndomorphism_generic(RingHomomorphism): EXAMPLES:: - sage: K = Frac(GF(5)['T']) - sage: phi = K.frobenius_endomorphism() - sage: psi = copy(phi) - sage: phi == psi + sage: K = Frac(GF(5)['T']) # optional - sage.rings.finite_rings + sage: phi = K.frobenius_endomorphism() # optional - sage.rings.finite_rings + sage: psi = copy(phi) # optional - sage.rings.finite_rings + sage: phi == psi # optional - sage.rings.finite_rings True """ self._p = _slots['_domain'].characteristic() @@ -2968,14 +3021,16 @@ cdef class FrobeniusEndomorphism_generic(RingHomomorphism): EXAMPLES:: - sage: K = Frac(GF(25)['T']) - sage: phi = K.frobenius_endomorphism(2) - sage: phi - Frobenius endomorphism x |--> x^(5^2) of Fraction Field of Univariate Polynomial Ring in T over Finite Field in z2 of size 5^2 + sage: K = Frac(GF(25)['T']) # optional - sage.rings.finite_rings + sage: phi = K.frobenius_endomorphism(2) # optional - sage.rings.finite_rings + sage: phi # optional - sage.rings.finite_rings + Frobenius endomorphism x |--> x^(5^2) of Fraction Field of + Univariate Polynomial Ring in T over Finite Field in z2 of size 5^2 - sage: psi = loads(dumps(phi)); psi - Frobenius endomorphism x |--> x^(5^2) of Fraction Field of Univariate Polynomial Ring in T over Finite Field in z2 of size 5^2 - sage: phi == psi + sage: psi = loads(dumps(phi)); psi # optional - sage.rings.finite_rings + Frobenius endomorphism x |--> x^(5^2) of Fraction Field of + Univariate Polynomial Ring in T over Finite Field in z2 of size 5^2 + sage: phi == psi # optional - sage.rings.finite_rings True """ slots = RingHomomorphism._extra_slots(self) @@ -2988,12 +3043,14 @@ cdef class FrobeniusEndomorphism_generic(RingHomomorphism): EXAMPLES:: - sage: K. = PowerSeriesRing(GF(5)) - sage: Frob = K.frobenius_endomorphism(); Frob - Frobenius endomorphism x |--> x^5 of Power Series Ring in u over Finite Field of size 5 + sage: K. = PowerSeriesRing(GF(5)) # optional - sage.rings.finite_rings + sage: Frob = K.frobenius_endomorphism(); Frob # optional - sage.rings.finite_rings + Frobenius endomorphism x |--> x^5 of Power Series Ring in u + over Finite Field of size 5 - sage: Frob._repr_() - 'Frobenius endomorphism x |--> x^5 of Power Series Ring in u over Finite Field of size 5' + sage: Frob._repr_() # optional - sage.rings.finite_rings + 'Frobenius endomorphism x |--> x^5 of Power Series Ring in u + over Finite Field of size 5' """ if self._power == 0: s = "Identity endomorphism" @@ -3010,11 +3067,11 @@ cdef class FrobeniusEndomorphism_generic(RingHomomorphism): EXAMPLES:: - sage: K. = PowerSeriesRing(GF(5)) - sage: Frob = K.frobenius_endomorphism() - sage: Frob._repr_short() + sage: K. = PowerSeriesRing(GF(5)) # optional - sage.rings.finite_rings + sage: Frob = K.frobenius_endomorphism() # optional - sage.rings.finite_rings + sage: Frob._repr_short() # optional - sage.rings.finite_rings 'Frob' - sage: (Frob^2)._repr_short() + sage: (Frob^2)._repr_short() # optional - sage.rings.finite_rings 'Frob^2' """ if self._power == 0: @@ -3031,9 +3088,9 @@ cdef class FrobeniusEndomorphism_generic(RingHomomorphism): EXAMPLES:: - sage: K. = PowerSeriesRing(GF(5)) - sage: Frob = K.frobenius_endomorphism(2) - sage: Frob._latex_() + sage: K. = PowerSeriesRing(GF(5)) # optional - sage.rings.finite_rings + sage: Frob = K.frobenius_endomorphism(2) # optional - sage.rings.finite_rings + sage: Frob._latex_() # optional - sage.rings.finite_rings '\\verb"Frob"^{2}' """ if self._power == 0: @@ -3048,11 +3105,11 @@ cdef class FrobeniusEndomorphism_generic(RingHomomorphism): """ TESTS:: - sage: K. = PowerSeriesRing(GF(5)) - sage: Frob = K.frobenius_endomorphism() - sage: Frob(u) + sage: K. = PowerSeriesRing(GF(5)) # optional - sage.rings.finite_rings + sage: Frob = K.frobenius_endomorphism() # optional - sage.rings.finite_rings + sage: Frob(u) # optional - sage.rings.finite_rings u^5 - sage: (Frob^2)(1+u) + sage: (Frob^2)(1 + u) # optional - sage.rings.finite_rings 1 + u^25 """ return x ** self._q @@ -3065,11 +3122,11 @@ cdef class FrobeniusEndomorphism_generic(RingHomomorphism): EXAMPLES:: - sage: K. = PowerSeriesRing(GF(5)) - sage: Frob = K.frobenius_endomorphism() - sage: Frob.power() + sage: K. = PowerSeriesRing(GF(5)) # optional - sage.rings.finite_rings + sage: Frob = K.frobenius_endomorphism() # optional - sage.rings.finite_rings + sage: Frob.power() # optional - sage.rings.finite_rings 1 - sage: (Frob^9).power() + sage: (Frob^9).power() # optional - sage.rings.finite_rings 9 """ return self._power @@ -3080,11 +3137,13 @@ cdef class FrobeniusEndomorphism_generic(RingHomomorphism): EXAMPLES:: - sage: K. = PowerSeriesRing(GF(5)) - sage: Frob = K.frobenius_endomorphism(); Frob - Frobenius endomorphism x |--> x^5 of Power Series Ring in u over Finite Field of size 5 - sage: Frob^2 - Frobenius endomorphism x |--> x^(5^2) of Power Series Ring in u over Finite Field of size 5 + sage: K. = PowerSeriesRing(GF(5)) # optional - sage.rings.finite_rings + sage: Frob = K.frobenius_endomorphism(); Frob # optional - sage.rings.finite_rings + Frobenius endomorphism x |--> x^5 of Power Series Ring in u + over Finite Field of size 5 + sage: Frob^2 # optional - sage.rings.finite_rings + Frobenius endomorphism x |--> x^(5^2) of Power Series Ring in u + over Finite Field of size 5 """ return self.__class__(self.domain(), self.power()*n) @@ -3094,13 +3153,16 @@ cdef class FrobeniusEndomorphism_generic(RingHomomorphism): EXAMPLES:: - sage: K. = PowerSeriesRing(GF(5)) - sage: f = K.frobenius_endomorphism(); f - Frobenius endomorphism x |--> x^5 of Power Series Ring in u over Finite Field of size 5 - sage: g = K.frobenius_endomorphism(2); g - Frobenius endomorphism x |--> x^(5^2) of Power Series Ring in u over Finite Field of size 5 - sage: f * g - Frobenius endomorphism x |--> x^(5^3) of Power Series Ring in u over Finite Field of size 5 + sage: K. = PowerSeriesRing(GF(5)) # optional - sage.rings.finite_rings + sage: f = K.frobenius_endomorphism(); f # optional - sage.rings.finite_rings + Frobenius endomorphism x |--> x^5 of Power Series Ring in u + over Finite Field of size 5 + sage: g = K.frobenius_endomorphism(2); g # optional - sage.rings.finite_rings + Frobenius endomorphism x |--> x^(5^2) of Power Series Ring in u + over Finite Field of size 5 + sage: f * g # optional - sage.rings.finite_rings + Frobenius endomorphism x |--> x^(5^3) of Power Series Ring in u + over Finite Field of size 5 """ if isinstance(right, FrobeniusEndomorphism_generic): return self.__class__(self.domain(), self._power + right.power()) @@ -3140,15 +3202,15 @@ def _tensor_product_ring(B, A): sage: from sage.rings.morphism import _tensor_product_ring sage: R. = QQ[] - sage: S. = R.quotient(x^2 + y^2) - sage: Q = _tensor_product_ring(S, R); Q + sage: S. = R.quotient(x^2 + y^2) # optional - sage.libs.singular + sage: Q = _tensor_product_ring(S, R); Q # optional - sage.libs.singular Quotient of Multivariate Polynomial Ring in u, v, x, y over Rational Field by the ideal (u^2 + v^2) - sage: Q.term_order() + sage: Q.term_order() # optional - sage.libs.singular Block term order with blocks: (Degree reverse lexicographic term order of length 2, Degree reverse lexicographic term order of length 2) - sage: _tensor_product_ring(R, R) + sage: _tensor_product_ring(R, R) # optional - sage.libs.singular Multivariate Polynomial Ring in y0, y1, x0, x1 over Rational Field TESTS: diff --git a/src/sage/rings/multi_power_series_ring.py b/src/sage/rings/multi_power_series_ring.py index 3ed94af4f02..20e3cba3977 100644 --- a/src/sage/rings/multi_power_series_ring.py +++ b/src/sage/rings/multi_power_series_ring.py @@ -49,9 +49,9 @@ True sage: TestSuite(M).run() - sage: H = PowerSeriesRing(PolynomialRing(ZZ,3,'z'),4,'f'); H - Multivariate Power Series Ring in f0, f1, f2, f3 over Multivariate - Polynomial Ring in z0, z1, z2 over Integer Ring + sage: H = PowerSeriesRing(PolynomialRing(ZZ, 3, 'z'), 4, 'f'); H + Multivariate Power Series Ring in f0, f1, f2, f3 + over Multivariate Polynomial Ring in z0, z1, z2 over Integer Ring sage: TestSuite(H).run() sage: loads(dumps(H)) is H True @@ -75,21 +75,21 @@ - Use angle-bracket notation:: - sage: S. = PowerSeriesRing(GF(65537)); S + sage: S. = PowerSeriesRing(GF(65537)); S # optional - sage.rings.finite_rings Multivariate Power Series Ring in x, y over Finite Field of size 65537 - sage: s = -30077*x + 9485*x*y - 6260*y^3 + 12870*x^2*y^2 - 20289*y^4 + S.O(5); s + sage: s = -30077*x + 9485*x*y - 6260*y^3 + 12870*x^2*y^2 - 20289*y^4 + S.O(5); s # optional - sage.rings.finite_rings -30077*x + 9485*x*y - 6260*y^3 + 12870*x^2*y^2 - 20289*y^4 + O(x, y)^5 - sage: s in S + sage: s in S # optional - sage.rings.finite_rings True - sage: TestSuite(S).run() - sage: loads(dumps(S)) is S + sage: TestSuite(S).run() # optional - sage.rings.finite_rings + sage: loads(dumps(S)) is S # optional - sage.rings.finite_rings True - Use double square bracket notation:: sage: ZZ[['s,t,u']] Multivariate Power Series Ring in s, t, u over Integer Ring - sage: GF(127931)[['x,y']] + sage: GF(127931)[['x,y']] # optional - sage.rings.finite_rings Multivariate Power Series Ring in x, y over Finite Field of size 127931 Variable ordering determines how series are displayed. @@ -118,15 +118,15 @@ sage: R. = PowerSeriesRing(QQ); R Multivariate Power Series Ring in t, u, v over Rational Field sage: R.base_extend(RR) - Multivariate Power Series Ring in t, u, v over Real Field with 53 - bits of precision + Multivariate Power Series Ring in t, u, v + over Real Field with 53 bits of precision sage: R.change_ring(IntegerModRing(10)) - Multivariate Power Series Ring in t, u, v over Ring of integers - modulo 10 + Multivariate Power Series Ring in t, u, v + over Ring of integers modulo 10 - sage: S = PowerSeriesRing(GF(65537),2,'x,y'); S + sage: S = PowerSeriesRing(GF(65537),2,'x,y'); S # optional - sage.rings.finite_rings Multivariate Power Series Ring in x, y over Finite Field of size 65537 - sage: S.change_ring(GF(5)) + sage: S.change_ring(GF(5)) # optional - sage.rings.finite_rings Multivariate Power Series Ring in x, y over Finite Field of size 5 Coercion from polynomial ring:: @@ -159,19 +159,19 @@ Coercion from symbolic ring:: - sage: x,y = var('x,y') - sage: S = PowerSeriesRing(GF(11),2,'x,y'); S + sage: x,y = var('x,y') # optional - sage.symbolic + sage: S = PowerSeriesRing(GF(11),2,'x,y'); S # optional - sage.rings.finite_rings Multivariate Power Series Ring in x, y over Finite Field of size 11 - sage: type(x) + sage: type(x) # optional - sage.symbolic - sage: type(S(x)) + sage: type(S(x)) # optional - sage.rings.finite_rings sage.symbolic - sage: f = S(2/7 -100*x^2 + 1/3*x*y + y^2).O(3); f + sage: f = S(2/7 -100*x^2 + 1/3*x*y + y^2).O(3); f # optional - sage.rings.finite_rings sage.symbolic 5 - x^2 + 4*x*y + y^2 + O(x, y)^3 - sage: f.parent() + sage: f.parent() # optional - sage.rings.finite_rings sage.symbolic Multivariate Power Series Ring in x, y over Finite Field of size 11 - sage: f.parent() == S + sage: f.parent() == S # optional - sage.rings.finite_rings sage.symbolic True The implementation of the multivariate power series ring uses a combination @@ -224,18 +224,18 @@ def is_MPowerSeriesRing(x): """ - Return true if input is a multivariate power series ring. + Return ``True`` if input is a multivariate power series ring. TESTS:: sage: from sage.rings.power_series_ring import is_PowerSeriesRing sage: from sage.rings.multi_power_series_ring import is_MPowerSeriesRing - sage: M = PowerSeriesRing(ZZ,4,'v') + sage: M = PowerSeriesRing(ZZ, 4, 'v') sage: is_PowerSeriesRing(M) False sage: is_MPowerSeriesRing(M) True - sage: T = PowerSeriesRing(RR,'v') + sage: T = PowerSeriesRing(RR, 'v') sage: is_PowerSeriesRing(T) True sage: is_MPowerSeriesRing(T) @@ -290,7 +290,7 @@ def __classcall__(cls, base_ring, num_gens, name_list, TESTS:: - sage: P1 = PowerSeriesRing(QQ, ['f0','f1','f2','f3'], order = TermOrder('degrevlex')) + sage: P1 = PowerSeriesRing(QQ, ['f0','f1','f2','f3'], order=TermOrder('degrevlex')) sage: P2 = PowerSeriesRing(QQ,4,'f', order='degrevlex') sage: P1 is P2 # indirect doctest True @@ -390,11 +390,11 @@ def _repr_(self): EXAMPLES:: - sage: R. = PowerSeriesRing(GF(17)) - sage: R #indirect doctest + sage: R. = PowerSeriesRing(GF(17)) # optional - sage.rings.finite_rings + sage: R #indirect doctest # optional - sage.rings.finite_rings Multivariate Power Series Ring in x, y over Finite Field of size 17 - sage: R.rename('my multivariate power series ring') - sage: R + sage: R.rename('my multivariate power series ring') # optional - sage.rings.finite_rings + sage: R # optional - sage.rings.finite_rings my multivariate power series ring """ if self.ngens() == 0: @@ -423,7 +423,7 @@ def _latex_(self): def is_integral_domain(self, proof=False): """ - Return True if the base ring is an integral domain; otherwise + Return ``True`` if the base ring is an integral domain; otherwise return False. EXAMPLES:: @@ -479,10 +479,10 @@ def characteristic(self): EXAMPLES:: - sage: H = PowerSeriesRing(GF(65537),4,'f'); H + sage: H = PowerSeriesRing(GF(65537),4,'f'); H # optional - sage.rings.finite_rings Multivariate Power Series Ring in f0, f1, f2, f3 over Finite Field of size 65537 - sage: H.characteristic() + sage: H.characteristic() # optional - sage.rings.finite_rings 65537 """ return self.base_ring().characteristic() @@ -493,12 +493,12 @@ def construction(self): EXAMPLES:: - sage: M = PowerSeriesRing(QQ,4,'f'); M + sage: M = PowerSeriesRing(QQ, 4, 'f'); M Multivariate Power Series Ring in f0, f1, f2, f3 over Rational Field sage: (c,R) = M.construction(); (c,R) (Completion[('f0', 'f1', 'f2', 'f3'), prec=12], - Multivariate Polynomial Ring in f0, f1, f2, f3 over Rational Field) + Multivariate Polynomial Ring in f0, f1, f2, f3 over Rational Field) sage: c Completion[('f0', 'f1', 'f2', 'f3'), prec=12] sage: c(R) @@ -555,10 +555,10 @@ def change_ring(self, R): TypeError: no base extension defined - sage: S = PowerSeriesRing(GF(65537),2,'x,y'); S + sage: S = PowerSeriesRing(GF(65537),2,'x,y'); S # optional - sage.rings.finite_rings Multivariate Power Series Ring in x, y over Finite Field of size 65537 - sage: S.change_ring(GF(5)) + sage: S.change_ring(GF(5)) # optional - sage.rings.finite_rings Multivariate Power Series Ring in x, y over Finite Field of size 5 """ return PowerSeriesRing(R, names = self.variable_names(), default_prec = self.default_prec()) @@ -576,16 +576,16 @@ def remove_var(self, *var): Power Series Ring in u over Integer Ring - sage: M = PowerSeriesRing(GF(5),5,'t'); M - Multivariate Power Series Ring in t0, t1, t2, t3, t4 over - Finite Field of size 5 - sage: M.remove_var(M.gens()[3]) - Multivariate Power Series Ring in t0, t1, t2, t4 over Finite - Field of size 5 + sage: M = PowerSeriesRing(GF(5),5,'t'); M # optional - sage.rings.finite_rings + Multivariate Power Series Ring in t0, t1, t2, t3, t4 + over Finite Field of size 5 + sage: M.remove_var(M.gens()[3]) # optional - sage.rings.finite_rings + Multivariate Power Series Ring in t0, t1, t2, t4 + over Finite Field of size 5 Removing all variables results in the base ring:: - sage: M.remove_var(*M.gens()) + sage: M.remove_var(*M.gens()) # optional - sage.rings.finite_rings Finite Field of size 5 """ @@ -634,10 +634,10 @@ def _coerce_impl(self, f): sage: R(f2) -2*v^2 + 5*u*v^2 + O(t, u, v)^6 - sage: R2 = R.change_ring(GF(2)) - sage: R2(f1) + sage: R2 = R.change_ring(GF(2)) # optional - sage.rings.finite_rings + sage: R2(f1) # optional - sage.rings.finite_rings v + t*v - sage: R2(f2) + sage: R2(f2) # optional - sage.rings.finite_rings u*v^2 + O(t, u, v)^6 TESTS:: @@ -674,8 +674,8 @@ def _is_valid_homomorphism_(self, codomain, im_gens, base_map=None): EXAMPLES:: sage: R. = PowerSeriesRing(Zmod(8)); R - Multivariate Power Series Ring in a, b, c over Ring of integers - modulo 8 + Multivariate Power Series Ring in a, b, c + over Ring of integers modulo 8 sage: M = PowerSeriesRing(ZZ,3,'x,y,z') sage: M._is_valid_homomorphism_(R,[a,c,b]) True @@ -709,13 +709,13 @@ def _is_valid_homomorphism_(self, codomain, im_gens, base_map=None): from the base ring to the codomain:: sage: T. = ZZ[] - sage: K. = NumberField(t^2 + 1) - sage: Q8. = CyclotomicField(8) - sage: X. = PowerSeriesRing(Q8) - sage: M. = PowerSeriesRing(K) - sage: M._is_valid_homomorphism_(X, [x,x,x+x^2]) # no coercion + sage: K. = NumberField(t^2 + 1) # optional - sage.rings.number_field + sage: Q8. = CyclotomicField(8) # optional - sage.rings.number_field + sage: X. = PowerSeriesRing(Q8) # optional - sage.rings.number_field + sage: M. = PowerSeriesRing(K) # optional - sage.rings.number_field + sage: M._is_valid_homomorphism_(X, [x,x,x+x^2]) # no coercion # optional - sage.rings.number_field False - sage: M._is_valid_homomorphism_(X, [x,x,x+x^2], base_map=K.hom([z^2])) + sage: M._is_valid_homomorphism_(X, [x,x,x+x^2], base_map=K.hom([z^2])) # optional - sage.rings.number_field True """ try: @@ -757,32 +757,32 @@ def _coerce_map_from_(self, P): EXAMPLES:: - sage: A = GF(17)[['x','y']] - sage: A.has_coerce_map_from(ZZ) + sage: A = GF(17)[['x','y']] # optional - sage.rings.finite_rings + sage: A.has_coerce_map_from(ZZ) # optional - sage.rings.finite_rings True - sage: A.has_coerce_map_from(ZZ['x']) + sage: A.has_coerce_map_from(ZZ['x']) # optional - sage.rings.finite_rings True - sage: A.has_coerce_map_from(ZZ['y','x']) + sage: A.has_coerce_map_from(ZZ['y','x']) # optional - sage.rings.finite_rings True - sage: A.has_coerce_map_from(ZZ[['x']]) + sage: A.has_coerce_map_from(ZZ[['x']]) # optional - sage.rings.finite_rings True - sage: A.has_coerce_map_from(ZZ[['y','x']]) + sage: A.has_coerce_map_from(ZZ[['y','x']]) # optional - sage.rings.finite_rings True - sage: A.has_coerce_map_from(ZZ['x','z']) + sage: A.has_coerce_map_from(ZZ['x','z']) # optional - sage.rings.finite_rings False - sage: A.has_coerce_map_from(GF(3)['x','y']) + sage: A.has_coerce_map_from(GF(3)['x','y']) # optional - sage.rings.finite_rings False - sage: A.has_coerce_map_from(Frac(ZZ['y','x'])) + sage: A.has_coerce_map_from(Frac(ZZ['y','x'])) # optional - sage.rings.finite_rings False TESTS:: - sage: M = PowerSeriesRing(ZZ,3,'x,y,z') + sage: M = PowerSeriesRing(ZZ, 3, 'x,y,z') sage: M._coerce_map_from_(M) True - sage: M._coerce_map_from_(M.remove_var(x)) + sage: M._coerce_map_from_(M.remove_var(x)) # optional - sage.symbolic True - sage: M._coerce_map_from_(PowerSeriesRing(ZZ,x)) + sage: M._coerce_map_from_(PowerSeriesRing(ZZ,x)) # optional - sage.symbolic True sage: M._coerce_map_from_(PolynomialRing(ZZ,'x,z')) True @@ -800,7 +800,8 @@ def _coerce_map_from_(self, P): sage: P = PolynomialRing(ZZ,3,'z') sage: H = PowerSeriesRing(P,4,'f'); H - Multivariate Power Series Ring in f0, f1, f2, f3 over Multivariate Polynomial Ring in z0, z1, z2 over Integer Ring + Multivariate Power Series Ring in f0, f1, f2, f3 over + Multivariate Polynomial Ring in z0, z1, z2 over Integer Ring sage: H._coerce_map_from_(P) True sage: H._coerce_map_from_(P.remove_var(P.gen(1))) @@ -919,11 +920,11 @@ def is_sparse(self): EXAMPLES:: - sage: M = PowerSeriesRing(ZZ,3,'s,t,u'); M + sage: M = PowerSeriesRing(ZZ, 3, 's,t,u'); M Multivariate Power Series Ring in s, t, u over Integer Ring sage: M.is_sparse() False - sage: N = PowerSeriesRing(ZZ,3,'s,t,u',sparse=True); N + sage: N = PowerSeriesRing(ZZ, 3, 's,t,u', sparse=True); N Sparse Multivariate Power Series Ring in s, t, u over Integer Ring sage: N.is_sparse() True @@ -936,11 +937,11 @@ def is_dense(self): EXAMPLES:: - sage: M = PowerSeriesRing(ZZ,3,'s,t,u'); M + sage: M = PowerSeriesRing(ZZ, 3, 's,t,u'); M Multivariate Power Series Ring in s, t, u over Integer Ring sage: M.is_dense() True - sage: N = PowerSeriesRing(ZZ,3,'s,t,u',sparse=True); N + sage: N = PowerSeriesRing(ZZ, 3, 's,t,u', sparse=True); N Sparse Multivariate Power Series Ring in s, t, u over Integer Ring sage: N.is_dense() False @@ -953,7 +954,7 @@ def gen(self, n=0): EXAMPLES:: - sage: M = PowerSeriesRing(ZZ,10,'v') + sage: M = PowerSeriesRing(ZZ, 10, 'v') sage: M.gen(6) v6 """ @@ -968,7 +969,7 @@ def ngens(self): EXAMPLES:: - sage: M = PowerSeriesRing(ZZ,10,'v') + sage: M = PowerSeriesRing(ZZ, 10, 'v') sage: M.ngens() 10 """ @@ -984,8 +985,8 @@ def prec_ideal(self): sage: A. = PowerSeriesRing(ZZ) sage: A.prec_ideal() - Ideal (s, t, u) of Multivariate Polynomial Ring in s, t, u over - Integer Ring + Ideal (s, t, u) of + Multivariate Polynomial Ring in s, t, u over Integer Ring """ return self._poly_ring().ideal(self._poly_ring().gens()) diff --git a/src/sage/rings/multi_power_series_ring_element.py b/src/sage/rings/multi_power_series_ring_element.py index 978de36ce2d..98831b3b947 100644 --- a/src/sage/rings/multi_power_series_ring_element.py +++ b/src/sage/rings/multi_power_series_ring_element.py @@ -29,7 +29,7 @@ sage: f*g - g 2*s^2*t^2 + O(s, t)^5 - sage: f*=s; f + sage: f *= s; f s + 2*s^2 + 3*s^3 + O(s, t)^8 sage: f%2 s + s^3 + O(s, t)^8 @@ -56,43 +56,43 @@ sage: f = s^2 + s*t + s^3 + s^2*t + 3*s^4 + 3*s^3*t + R.O(5); f s^2 + s*t + s^3 + s^2*t + 3*s^4 + 3*s^3*t + O(s, t)^5 - sage: f(t,s) + sage: f(t, s) s*t + t^2 + s*t^2 + t^3 + 3*s*t^3 + 3*t^4 + O(s, t)^5 - sage: f(t^2,s^2) + sage: f(t^2, s^2) s^2*t^2 + t^4 + s^2*t^4 + t^6 + 3*s^2*t^6 + 3*t^8 + O(s, t)^10 Substitution is defined only for elements of positive valuation, unless `f` has infinite precision:: - sage: f(t^2,s^2+1) + sage: f(t^2, s^2 + 1) Traceback (most recent call last): ... TypeError: Substitution defined only for elements of positive valuation, unless self has infinite precision. sage: g = f.truncate() - sage: g(t^2,s^2+1) + sage: g(t^2, s^2 + 1) t^2 + s^2*t^2 + 2*t^4 + s^2*t^4 + 4*t^6 + 3*s^2*t^6 + 3*t^8 - sage: g(t^2,(s^2+1).O(3)) + sage: g(t^2, (s^2+1).O(3)) t^2 + s^2*t^2 + 2*t^4 + O(s, t)^5 0 has valuation ``+Infinity``:: - sage: f(t^2,0) + sage: f(t^2, 0) t^4 + t^6 + 3*t^8 + O(s, t)^10 - sage: f(t^2,s^2+s) + sage: f(t^2, s^2 + s) s*t^2 + s^2*t^2 + t^4 + O(s, t)^5 Substitution of power series with finite precision works too:: - sage: f(s.O(2),t) + sage: f(s.O(2), t) s^2 + s*t + O(s, t)^3 - sage: f(f,f) + sage: f(f, f) 2*s^4 + 4*s^3*t + 2*s^2*t^2 + 4*s^5 + 8*s^4*t + 4*s^3*t^2 + 16*s^6 + 34*s^5*t + 20*s^4*t^2 + 2*s^3*t^3 + O(s, t)^7 - sage: t(f,f) + sage: t(f, f) s^2 + s*t + s^3 + s^2*t + 3*s^4 + 3*s^3*t + O(s, t)^5 - sage: t(0,f) == s(f,0) + sage: t(0, f) == s(f, 0) True The ``subs`` syntax works as expected:: @@ -100,10 +100,10 @@ sage: r0 = -t^2 - s*t^3 - 2*t^6 + s^7 + s^5*t^2 + R.O(10) sage: r1 = s^4 - s*t^4 + s^6*t - 4*s^2*t^5 - 6*s^3*t^5 + R.O(10) sage: r2 = 2*s^3*t^2 - 2*s*t^4 - 2*s^3*t^4 + s*t^7 + R.O(10) - sage: r0.subs({t:r2,s:r1}) + sage: r0.subs({t: r2, s: r1}) -4*s^6*t^4 + 8*s^4*t^6 - 4*s^2*t^8 + 8*s^6*t^6 - 8*s^4*t^8 - 4*s^4*t^9 + 4*s^2*t^11 - 4*s^6*t^8 + O(s, t)^15 - sage: r0.subs({t:r2,s:r1}) == r0(r1,r2) + sage: r0.subs({t: r2, s: r1}) == r0(r1, r2) True Construct ring homomorphisms from one power series ring to another:: @@ -253,19 +253,19 @@ class MPowerSeries(PowerSeries): 1 + s + t - s*t + O(s, t)^5 - sage: T = PowerSeriesRing(GF(3),5,'t'); T - Multivariate Power Series Ring in t0, t1, t2, t3, t4 over Finite - Field of size 3 - sage: t = T.gens() - sage: w = t[0] - 2*t[1]*t[3] + 5*t[4]^3 - t[0]^3*t[2]^2; w + sage: T = PowerSeriesRing(GF(3),5,'t'); T # optional - sage.rings.finite_rings + Multivariate Power Series Ring in t0, t1, t2, t3, t4 + over Finite Field of size 3 + sage: t = T.gens() # optional - sage.rings.finite_rings + sage: w = t[0] - 2*t[1]*t[3] + 5*t[4]^3 - t[0]^3*t[2]^2; w # optional - sage.rings.finite_rings t0 + t1*t3 - t4^3 - t0^3*t2^2 - sage: w = w.add_bigoh(5); w + sage: w = w.add_bigoh(5); w # optional - sage.rings.finite_rings t0 + t1*t3 - t4^3 + O(t0, t1, t2, t3, t4)^5 - sage: w in T + sage: w in T # optional - sage.rings.finite_rings True - sage: w = t[0] - 2*t[0]*t[2] + 5*t[4]^3 - t[0]^3*t[2]^2 + T.O(6) - sage: w + sage: w = t[0] - 2*t[0]*t[2] + 5*t[4]^3 - t[0]^3*t[2]^2 + T.O(6) # optional - sage.rings.finite_rings + sage: w # optional - sage.rings.finite_rings t0 + t0*t2 - t4^3 - t0^3*t2^2 + O(t0, t1, t2, t3, t4)^6 @@ -274,20 +274,20 @@ class MPowerSeries(PowerSeries): sage: S.random_element(4) # random -2*t + t^2 - 12*s^3 + O(s, t)^4 - sage: T.random_element(10) # random + sage: T.random_element(10) # random # optional - sage.rings.finite_rings -t1^2*t3^2*t4^2 + t1^5*t3^3*t4 + O(t0, t1, t2, t3, t4)^10 Convert elements from polynomial rings:: - sage: R = PolynomialRing(ZZ,5,T.variable_names()) - sage: t = R.gens() - sage: r = -t[2]*t[3] + t[3]^2 + t[4]^2 - sage: T(r) + sage: R = PolynomialRing(ZZ, 5, T.variable_names()) # optional - sage.libs.pari + sage: t = R.gens() # optional - sage.libs.pari + sage: r = -t[2]*t[3] + t[3]^2 + t[4]^2 # optional - sage.libs.pari + sage: T(r) # optional - sage.libs.pari -t2*t3 + t3^2 + t4^2 - sage: r.parent() + sage: r.parent() # optional - sage.libs.pari Multivariate Polynomial Ring in t0, t1, t2, t3, t4 over Integer Ring - sage: r in T + sage: r in T # optional - sage.libs.pari True """ @@ -313,10 +313,11 @@ def __init__(self, parent, x=0, prec=infinity, is_gen=False, check=False): sage: g.parent() Multivariate Power Series Ring in s, t over Rational Field - sage: K = NumberField(x-3,'a') - sage: g = K.random_element()*f - sage: g.parent() - Multivariate Power Series Ring in s, t over Number Field in a with defining polynomial x - 3 + sage: K = NumberField(x - 3,'a') # optional - sage.rings.number_field + sage: g = K.random_element()*f # optional - sage.rings.number_field + sage: g.parent() # optional - sage.rings.number_field + Multivariate Power Series Ring in s, t over + Number Field in a with defining polynomial x - 3 TESTS:: @@ -449,20 +450,20 @@ def __call__(self, *x, **kwds): Checking that :trac:`15059` is fixed:: - sage: M. = PowerSeriesRing(GF(5)) - sage: s = M.hom([u, u+v]) - sage: s(M.one()) + sage: M. = PowerSeriesRing(GF(5)) # optional - sage.rings.finite_rings + sage: s = M.hom([u, u+v]) # optional - sage.rings.finite_rings + sage: s(M.one()) # optional - sage.rings.finite_rings 1 Since :trac:`26105` you can specify a map on the base ring:: sage: Zx. = ZZ[] - sage: K. = NumberField(x^2 + 1) - sage: cc = K.hom([-i]) - sage: R. = PowerSeriesRing(K) - sage: f = s^2 + i*s*t + (3+4*i)*s^3 + R.O(4); f + sage: K. = NumberField(x^2 + 1) # optional - sage.rings.number_field + sage: cc = K.hom([-i]) # optional - sage.rings.number_field + sage: R. = PowerSeriesRing(K) # optional - sage.rings.number_field + sage: f = s^2 + i*s*t + (3+4*i)*s^3 + R.O(4); f # optional - sage.rings.number_field s^2 + i*s*t + (4*i + 3)*s^3 + O(s, t)^4 - sage: f(t, s, base_map=cc) + sage: f(t, s, base_map=cc) # optional - sage.rings.number_field (-i)*s*t + t^2 + (-4*i + 3)*t^3 + O(s, t)^4 """ if len(x) != self.parent().ngens(): @@ -565,14 +566,14 @@ def _value(self): EXAMPLES:: - sage: R. = PowerSeriesRing(GF(5)); R + sage: R. = PowerSeriesRing(GF(5)); R # optional - sage.rings.finite_rings Multivariate Power Series Ring in a, b, c over Finite Field of size 5 - sage: f = 1 + a + b - a*b + R.O(3); f + sage: f = 1 + a + b - a*b + R.O(3); f # optional - sage.rings.finite_rings 1 + a + b - a*b + O(a, b, c)^3 - sage: f._value() + sage: f._value() # optional - sage.rings.finite_rings 1 + a + b - a*b - sage: f._value().parent() + sage: f._value().parent() # optional - sage.rings.finite_rings Multivariate Polynomial Ring in a, b, c over Finite Field of size 5 """ return self._go_to_fg(self._bg_value) @@ -601,15 +602,15 @@ def _latex_(self): EXAMPLES:: - sage: M = PowerSeriesRing(GF(5),3,'t'); M + sage: M = PowerSeriesRing(GF(5),3,'t'); M # optional - sage.rings.finite_rings Multivariate Power Series Ring in t0, t1, t2 over Finite Field of size 5 - sage: t = M.gens() - sage: f = -t[0]^4*t[1]^3*t[2]^4 - 2*t[0]*t[1]^4*t[2]^7 \ - + 2*t[1]*t[2]^12 + 2*t[0]^7*t[1]^5*t[2]^2 + M.O(15) - sage: f + sage: t = M.gens() # optional - sage.rings.finite_rings + sage: f = (-t[0]^4*t[1]^3*t[2]^4 - 2*t[0]*t[1]^4*t[2]^7 # optional - sage.rings.finite_rings + ....: + 2*t[1]*t[2]^12 + 2*t[0]^7*t[1]^5*t[2]^2 + M.O(15)) + sage: f # optional - sage.rings.finite_rings -t0^4*t1^3*t2^4 - 2*t0*t1^4*t2^7 + 2*t1*t2^12 + 2*t0^7*t1^5*t2^2 + O(t0, t1, t2)^15 - sage: f._latex_() + sage: f._latex_() # optional - sage.rings.finite_rings '-t_{0}^{4} t_{1}^{3} t_{2}^{4} + 3 t_{0} t_{1}^{4} t_{2}^{7} + 2 t_{1} t_{2}^{12} + 2 t_{0}^{7} t_{1}^{5} t_{2}^{2} + O(t_{0}, t_{1}, t_{2})^{15}' @@ -707,30 +708,30 @@ def _richcmp_(self, other, op): EXAMPLES:: - sage: R. = PowerSeriesRing(GF(5)); R + sage: R. = PowerSeriesRing(GF(5)); R # optional - sage.rings.finite_rings Multivariate Power Series Ring in a, b, c over Finite Field of size 5 - sage: f = a + b + c + a^2*c - sage: f == f^2 + sage: f = a + b + c + a^2*c # optional - sage.rings.finite_rings + sage: f == f^2 # optional - sage.rings.finite_rings False - sage: f = f.truncate() - sage: f == f.O(4) + sage: f = f.truncate() # optional - sage.rings.finite_rings + sage: f == f.O(4) # optional - sage.rings.finite_rings True Ordering is determined by underlying polynomial ring:: - sage: a > b + sage: a > b # optional - sage.rings.finite_rings True - sage: a > a^2 + sage: a > a^2 # optional - sage.rings.finite_rings True - sage: b > a^2 + sage: b > a^2 # optional - sage.rings.finite_rings True - sage: (f^2).O(3) + sage: (f^2).O(3) # optional - sage.rings.finite_rings a^2 + 2*a*b + 2*a*c + b^2 + 2*b*c + c^2 + O(a, b, c)^3 - sage: f < f^2 + sage: f < f^2 # optional - sage.rings.finite_rings False - sage: f > f^2 + sage: f > f^2 # optional - sage.rings.finite_rings True - sage: f < 2*f + sage: f < 2*f # optional - sage.rings.finite_rings True """ return richcmp(self._bg_value, other._bg_value, op) @@ -894,22 +895,22 @@ def quo_rem(self, other, precision=None): sage: g = 1 + 2*a - 3*a*b + R.O(3) sage: q, r = f.quo_rem(g); q, r (1 - a + b + 2*a^2 + O(a, b, c)^3, 0 + O(a, b, c)^3) - sage: f == q*g+r + sage: f == q*g + r True sage: q, r = (a*f).quo_rem(g); q, r (a - a^2 + a*b + 2*a^3 + O(a, b, c)^4, 0 + O(a, b, c)^4) - sage: a*f == q*g+r + sage: a*f == q*g + r True - sage: q, r = (a*f).quo_rem(a*g); q, r + sage: q, r = (a*f).quo_rem(a*g); q, r # optional - sage.libs.singular (1 - a + b + 2*a^2 + O(a, b, c)^3, 0 + O(a, b, c)^4) - sage: a*f == q*(a*g)+r + sage: a*f == q*(a*g) + r # optional - sage.libs.singular True - sage: q, r = (a*f).quo_rem(b*g); q, r + sage: q, r = (a*f).quo_rem(b*g); q, r # optional - sage.libs.singular (a - 3*a^2 + O(a, b, c)^3, a + a^2 + O(a, b, c)^4) - sage: a*f == q*(b*g)+r + sage: a*f == q*(b*g) + r # optional - sage.libs.singular True Trying to divide two polynomials, we run into the issue that @@ -918,59 +919,61 @@ def quo_rem(self, other, precision=None): algorithm would never terminate). Here, default precision comes to our help:: - sage: (1+a^3).quo_rem(a+a^2) - (a^2 - a^3 + a^4 - a^5 + a^6 - a^7 + a^8 - a^9 + a^10 + O(a, b, c)^11, 1 + O(a, b, c)^12) + sage: (1 + a^3).quo_rem(a + a^2) # optional - sage.libs.singular + (a^2 - a^3 + a^4 - a^5 + a^6 - a^7 + a^8 - a^9 + a^10 + O(a, b, c)^11, + 1 + O(a, b, c)^12) - sage: (1+a^3+a*b).quo_rem(b+c) + sage: (1 + a^3 + a*b).quo_rem(b + c) # optional - sage.libs.singular (a + O(a, b, c)^11, 1 - a*c + a^3 + O(a, b, c)^12) - sage: (1+a^3+a*b).quo_rem(b+c, precision=17) + sage: (1 + a^3 + a*b).quo_rem(b + c, precision=17) # optional - sage.libs.singular (a + O(a, b, c)^16, 1 - a*c + a^3 + O(a, b, c)^17) - sage: (a^2+b^2+c^2).quo_rem(a+b+c) + sage: (a^2 + b^2 + c^2).quo_rem(a + b + c) # optional - sage.libs.singular (a - b - c + O(a, b, c)^11, 2*b^2 + 2*b*c + 2*c^2 + O(a, b, c)^12) - sage: (a^2+b^2+c^2).quo_rem(1/(1+a+b+c)) - (a^2 + b^2 + c^2 + a^3 + a^2*b + a^2*c + a*b^2 + a*c^2 + b^3 + b^2*c + b*c^2 + c^3 + O(a, b, c)^14, + sage: (a^2 + b^2 + c^2).quo_rem(1/(1+a+b+c)) # optional - sage.libs.singular + (a^2 + b^2 + c^2 + a^3 + a^2*b + a^2*c + a*b^2 + a*c^2 + + b^3 + b^2*c + b*c^2 + c^3 + O(a, b, c)^14, 0) - sage: (a^2+b^2+c^2).quo_rem(a/(1+a+b+c)) + sage: (a^2 + b^2 + c^2).quo_rem(a/(1+a+b+c)) # optional - sage.libs.singular (a + a^2 + a*b + a*c + O(a, b, c)^13, b^2 + c^2) - sage: (1+a+a^15).quo_rem(a^2) + sage: (1 + a + a^15).quo_rem(a^2) # optional - sage.libs.singular (0 + O(a, b, c)^10, 1 + a + O(a, b, c)^12) - sage: (1+a+a^15).quo_rem(a^2, precision=15) + sage: (1 + a + a^15).quo_rem(a^2, precision=15) # optional - sage.libs.singular (0 + O(a, b, c)^13, 1 + a + O(a, b, c)^15) - sage: (1+a+a^15).quo_rem(a^2, precision=16) + sage: (1 + a + a^15).quo_rem(a^2, precision=16) # optional - sage.libs.singular (a^13 + O(a, b, c)^14, 1 + a + O(a, b, c)^16) Illustrating the dependency on the ordering of variables:: - sage: (1+a+b).quo_rem(b+c) + sage: (1 + a + b).quo_rem(b + c) # optional - sage.libs.singular (1 + O(a, b, c)^11, 1 + a - c + O(a, b, c)^12) - sage: (1+b+c).quo_rem(c+a) + sage: (1 + b + c).quo_rem(c + a) # optional - sage.libs.singular (0 + O(a, b, c)^11, 1 + b + c + O(a, b, c)^12) - sage: (1+c+a).quo_rem(a+b) + sage: (1 + c + a).quo_rem(a + b) # optional - sage.libs.singular (1 + O(a, b, c)^11, 1 - b + c + O(a, b, c)^12) TESTS:: - sage: (f).quo_rem(R.zero()) + sage: (f).quo_rem(R.zero()) # optional - sage.libs.singular Traceback (most recent call last): ... ZeroDivisionError - sage: (f).quo_rem(R.zero().add_bigoh(2)) + sage: (f).quo_rem(R.zero().add_bigoh(2)) # optional - sage.libs.singular Traceback (most recent call last): ... ZeroDivisionError Coercion is applied on ``other``:: - sage: (a+b).quo_rem(1) + sage: (a + b).quo_rem(1) # optional - sage.libs.singular (a + b + O(a, b, c)^12, 0 + O(a, b, c)^12) sage: R. = PowerSeriesRing(QQ) - sage: R(3).quo_rem(2) + sage: R(3).quo_rem(2) # optional - sage.libs.singular (3/2 + O(a, b, c)^12, 0 + O(a, b, c)^12) """ parent = self.parent() @@ -1034,30 +1037,30 @@ def _div_(self, denom_r): When possible, division by non-units also works:: - sage: a/(a*f) + sage: a/(a*f) # optional - sage.libs.singular 1 - a - b + a^2 + 3*a*b + b^2 + O(a, b, c)^3 - sage: a/(R.zero()) + sage: a/(R.zero()) # optional - sage.libs.singular Traceback (most recent call last): ZeroDivisionError - sage: (a*f)/f + sage: (a*f)/f # optional - sage.libs.singular a + O(a, b, c)^4 - sage: f/(a*f) + sage: f/(a*f) # optional - sage.libs.singular Traceback (most recent call last): ... ValueError: not divisible An example where one loses precision:: - sage: ((1+a)*f - f) / a*f + sage: ((1+a)*f - f) / a*f # optional - sage.libs.singular 1 + 2*a + 2*b + O(a, b, c)^2 TESTS:: - sage: ((a+b)*f) / f == (a+b) + sage: ((a+b)*f) / f == (a+b) # optional - sage.libs.singular True - sage: ((a+b)*f) / (a+b) == f + sage: ((a+b)*f) / (a+b) == f # optional - sage.libs.singular True """ if denom_r.is_unit(): # faster if denom_r is a unit @@ -1080,7 +1083,7 @@ def __mod__(self, other): False sage: g in R.base_extend(Zmod(2)) True - sage: g.polynomial() == f.polynomial() % 2 + sage: g.polynomial() == f.polynomial() % 2 # optional - sage.libs.singular True """ if isinstance(other, (int, Integer)): @@ -1155,14 +1158,14 @@ def variables(self): EXAMPLES:: - sage: T = PowerSeriesRing(GF(3),5,'t'); T + sage: T = PowerSeriesRing(GF(3),5,'t'); T # optional - sage.rings.finite_rings Multivariate Power Series Ring in t0, t1, t2, t3, t4 over Finite Field of size 3 - sage: t = T.gens() - sage: w = t[0] - 2*t[0]*t[2] + 5*t[4]^3 - t[0]^3*t[2]^2 + T.O(6) - sage: w + sage: t = T.gens() # optional - sage.rings.finite_rings + sage: w = t[0] - 2*t[0]*t[2] + 5*t[4]^3 - t[0]^3*t[2]^2 + T.O(6) # optional - sage.rings.finite_rings + sage: w # optional - sage.rings.finite_rings t0 + t0*t2 - t4^3 - t0^3*t2^2 + O(t0, t1, t2, t3, t4)^6 - sage: w.variables() + sage: w.variables() # optional - sage.rings.finite_rings (t0, t2, t4) """ return tuple(self.parent(v) for v in self._value().variables()) @@ -1392,16 +1395,16 @@ def valuation(self): EXAMPLES:: - sage: R. = PowerSeriesRing(GF(4949717)); R - Multivariate Power Series Ring in a, b over Finite Field of - size 4949717 - sage: f = a^2 + a*b + a^3 + R.O(9) - sage: f.valuation() + sage: R. = PowerSeriesRing(GF(4949717)); R # optional - sage.rings.finite_rings + Multivariate Power Series Ring in a, b + over Finite Field of size 4949717 + sage: f = a^2 + a*b + a^3 + R.O(9) # optional - sage.rings.finite_rings + sage: f.valuation() # optional - sage.rings.finite_rings 2 - sage: g = 1 + a + a^3 - sage: g.valuation() + sage: g = 1 + a + a^3 # optional - sage.rings.finite_rings + sage: g.valuation() # optional - sage.rings.finite_rings 0 - sage: R.zero().valuation() + sage: R.zero().valuation() # optional - sage.rings.finite_rings +Infinity """ try: @@ -1441,8 +1444,7 @@ def is_nilpotent(self): EXAMPLES:: sage: R. = PowerSeriesRing(Zmod(8)); R - Multivariate Power Series Ring in a, b, c over Ring of integers - modulo 8 + Multivariate Power Series Ring in a, b, c over Ring of integers modulo 8 sage: f = a + b + c + a^2*c sage: f.is_nilpotent() False @@ -1535,7 +1537,7 @@ def is_square(self): TESTS:: - sage: T. = PowerSeriesRing(ZZ,2) + sage: T. = PowerSeriesRing(ZZ, 2) sage: f = a + b + a*b + T.O(5) sage: f.is_square() Traceback (most recent call last): @@ -1551,7 +1553,7 @@ def square_root(self): TESTS:: - sage: T. = PowerSeriesRing(ZZ,2) + sage: T. = PowerSeriesRing(ZZ, 2) sage: f = a + b + a*b + T.O(5) sage: f.square_root() Traceback (most recent call last): @@ -1569,7 +1571,7 @@ def derivative(self, *args): EXAMPLES:: - sage: T. = PowerSeriesRing(ZZ,2) + sage: T. = PowerSeriesRing(ZZ, 2) sage: f = a + b + a^2*b + T.O(5) sage: f.derivative(a) 1 + 2*a*b + O(a, b)^4 @@ -1602,7 +1604,7 @@ def integral(self, *args): EXAMPLES:: - sage: T. = PowerSeriesRing(QQ,2) + sage: T. = PowerSeriesRing(QQ, 2) sage: f = a + b + a^2*b + T.O(5) sage: f.integral(a, 2) 1/6*a^3 + 1/2*a^2*b + 1/12*a^4*b + O(a, b)^7 @@ -1613,7 +1615,7 @@ def integral(self, *args): Only integration with respect to variables works:: - sage: f.integral(a+b) + sage: f.integral(a + b) Traceback (most recent call last): ... ValueError: a + b is not a variable @@ -1626,7 +1628,7 @@ def integral(self, *args): first case, Sage will report that it has not been able to coerce some coefficient to the base ring:: - sage: T. = PowerSeriesRing(ZZ,2) + sage: T. = PowerSeriesRing(ZZ, 2) sage: f = a + T.O(5) sage: f.integral(a) Traceback (most recent call last): @@ -1648,7 +1650,7 @@ def integral(self, *args): In non-zero characteristic, Sage will report that a zero division occurred :: - sage: T. = PowerSeriesRing(Zmod(3),2) + sage: T. = PowerSeriesRing(Zmod(3), 2) sage: (a^3).integral(a) a^4 sage: (a^2).integral(a) @@ -1724,7 +1726,7 @@ def ogf(self): TESTS:: - sage: T. = PowerSeriesRing(ZZ,2) + sage: T. = PowerSeriesRing(ZZ, 2) sage: f = a + b + a*b + T.O(5) sage: f.ogf() Traceback (most recent call last): @@ -1739,7 +1741,7 @@ def egf(self): TESTS:: - sage: T. = PowerSeriesRing(ZZ,2) + sage: T. = PowerSeriesRing(ZZ, 2) sage: f = a + b + a*b + T.O(5) sage: f.egf() Traceback (most recent call last): @@ -1754,7 +1756,7 @@ def __pari__(self): TESTS:: - sage: T. = PowerSeriesRing(ZZ,2) + sage: T. = PowerSeriesRing(ZZ, 2) sage: f = a + b + a*b + T.O(5) sage: f.__pari__() Traceback (most recent call last): @@ -1773,7 +1775,7 @@ def list(self): TESTS:: - sage: T. = PowerSeriesRing(ZZ,2) + sage: T. = PowerSeriesRing(ZZ, 2) sage: f = a + b + a*b + T.O(5) sage: f.list() Traceback (most recent call last): @@ -1790,7 +1792,7 @@ def variable(self): TESTS:: - sage: T. = PowerSeriesRing(ZZ,2) + sage: T. = PowerSeriesRing(ZZ, 2) sage: f = a + b + a*b + T.O(5) sage: f.variable() Traceback (most recent call last): @@ -1806,7 +1808,7 @@ def shift(self, n): TESTS:: - sage: T. = PowerSeriesRing(ZZ,2) + sage: T. = PowerSeriesRing(ZZ, 2) sage: f = a + b + a*b + T.O(5) sage: f.shift(3) Traceback (most recent call last): @@ -1821,7 +1823,7 @@ def __lshift__(self, n): TESTS:: - sage: T. = PowerSeriesRing(ZZ,2) + sage: T. = PowerSeriesRing(ZZ, 2) sage: f = a + b + a*b + T.O(5) sage: f.__lshift__(3) Traceback (most recent call last): @@ -1836,7 +1838,7 @@ def __rshift__(self, n): TESTS:: - sage: T. = PowerSeriesRing(ZZ,2) + sage: T. = PowerSeriesRing(ZZ, 2) sage: f = a + b + a*b + T.O(5) sage: f.__rshift__(3) Traceback (most recent call last): @@ -1852,7 +1854,7 @@ def valuation_zero_part(self): TESTS:: - sage: T. = PowerSeriesRing(ZZ,2) + sage: T. = PowerSeriesRing(ZZ, 2) sage: f = a + b + a*b + T.O(5) sage: f.valuation_zero_part() Traceback (most recent call last): @@ -1868,7 +1870,7 @@ def solve_linear_de(self, prec=infinity, b=None, f0=None): TESTS:: - sage: T. = PowerSeriesRing(ZZ,2) + sage: T. = PowerSeriesRing(ZZ, 2) sage: f = a + b + a*b + T.O(5) sage: f.solve_linear_de() Traceback (most recent call last): @@ -1893,15 +1895,15 @@ def exp(self, prec=infinity): EXAMPLES:: - sage: T. = PowerSeriesRing(ZZ,2) + sage: T. = PowerSeriesRing(ZZ, 2) sage: f = a + b + a*b + T.O(3) - sage: exp(f) + sage: exp(f) # optional - sage.symbolic 1 + a + b + 1/2*a^2 + 2*a*b + 1/2*b^2 + O(a, b)^3 sage: f.exp() 1 + a + b + 1/2*a^2 + 2*a*b + 1/2*b^2 + O(a, b)^3 sage: f.exp(prec=2) 1 + a + b + O(a, b)^2 - sage: log(exp(f)) - f + sage: log(exp(f)) - f # optional - sage.symbolic 0 + O(a, b)^3 If the power series has a constant coefficient `c` and @@ -1909,8 +1911,8 @@ def exp(self, prec=infinity): power series over the :class:`~sage.symbolic.ring.SymbolicRing`. These are not yet implemented and therefore such cases raise an error:: - sage: g = 2+f - sage: exp(g) + sage: g = 2 + f + sage: exp(g) # optional - sage.symbolic Traceback (most recent call last): ... TypeError: unsupported operand parent(s) for *: 'Symbolic Ring' and @@ -1920,7 +1922,7 @@ def exp(self, prec=infinity): Another workaround for this limitation is to change base ring to one which is closed under exponentiation, such as `\RR` or `\CC`:: - sage: exp(g.change_ring(RDF)) + sage: exp(g.change_ring(RDF)) # optional - sage.symbolic 7.38905609... + 7.38905609...*a + 7.38905609...*b + 3.69452804...*a^2 + 14.7781121...*a*b + 3.69452804...*b^2 + O(a, b)^3 @@ -1928,17 +1930,17 @@ def exp(self, prec=infinity): sage: T.default_prec() 12 - sage: exp(a) + sage: exp(a) # optional - sage.symbolic 1 + a + 1/2*a^2 + 1/6*a^3 + 1/24*a^4 + 1/120*a^5 + 1/720*a^6 + 1/5040*a^7 + 1/40320*a^8 + 1/362880*a^9 + 1/3628800*a^10 + 1/39916800*a^11 + O(a, b)^12 sage: a.exp(prec=5) 1 + a + 1/2*a^2 + 1/6*a^3 + 1/24*a^4 + O(a, b)^5 - sage: exp(a + T.O(5)) + sage: exp(a + T.O(5)) # optional - sage.symbolic 1 + a + 1/2*a^2 + 1/6*a^3 + 1/24*a^4 + O(a, b)^5 TESTS:: - sage: exp(a^2 + T.O(5)) + sage: exp(a^2 + T.O(5)) # optional - sage.symbolic 1 + a^2 + 1/2*a^4 + O(a, b)^5 """ R = self.parent() @@ -1985,7 +1987,7 @@ def log(self, prec=infinity): EXAMPLES:: - sage: T. = PowerSeriesRing(ZZ,2) + sage: T. = PowerSeriesRing(ZZ, 2) sage: f = 1 + a + b + a*b + T.O(5) sage: f.log() a + b - 1/2*a^2 - 1/2*b^2 + 1/3*a^3 + 1/3*b^3 - 1/4*a^4 - 1/4*b^4 + O(a, b)^5 @@ -1999,7 +2001,7 @@ def log(self, prec=infinity): power series over the :class:`~sage.symbolic.ring.SymbolicRing`. These are not yet implemented and therefore such cases raise an error:: - sage: g = 2+f + sage: g = 2 + f sage: log(g) Traceback (most recent call last): ... @@ -2090,7 +2092,7 @@ class MO(): sage: m^1 0 + O(u, v)^1 - sage: T. = PowerSeriesRing(ZZ,3) + sage: T. = PowerSeriesRing(ZZ, 3) sage: z = O(a, b, c) sage: z^1 0 + O(a, b, c)^1 diff --git a/src/sage/rings/noncommutative_ideals.pyx b/src/sage/rings/noncommutative_ideals.pyx index 0661987be2a..af27882313d 100644 --- a/src/sage/rings/noncommutative_ideals.pyx +++ b/src/sage/rings/noncommutative_ideals.pyx @@ -1,3 +1,4 @@ +# sage.doctest: optional - sage.modules """ Ideals of non-commutative rings diff --git a/src/sage/rings/number_field/S_unit_solver.py b/src/sage/rings/number_field/S_unit_solver.py index af226730584..df27727467d 100644 --- a/src/sage/rings/number_field/S_unit_solver.py +++ b/src/sage/rings/number_field/S_unit_solver.py @@ -1,7 +1,7 @@ r""" Solve S-unit equation x + y = 1 -Inspired by work of Tzanakis--de Weger, Baker--Wustholz and Smart, we use the LLL methods in Sage to implement an algorithm that returns all S-unit solutions to the equation `x + y = 1`. +Inspired by work of Tzanakis--de Weger, Baker--Wustholz and Smart, we use the LLL methods in Sage to implement an algorithm that returns all `S`-unit solutions to the equation `x + y = 1`. REFERENCES: @@ -22,7 +22,7 @@ EXAMPLES:: sage: from sage.rings.number_field.S_unit_solver import solve_S_unit_equation, eq_up_to_order - sage: K. = NumberField(x^2+x+1) + sage: K. = NumberField(x^2 + x + 1) sage: S = K.primes_above(3) sage: expected = [((0, 1), (4, 0), xi + 2, -xi - 1), ....: ((1, -1), (0, -1), 1/3*xi + 2/3, -1/3*xi + 1/3), @@ -96,7 +96,7 @@ def column_Log(SUK, iota, U, prec=106): EXAMPLES:: sage: from sage.rings.number_field.S_unit_solver import column_Log - sage: K. = NumberField(x^3-3) + sage: K. = NumberField(x^3 - 3) sage: S = tuple(K.primes_above(3)) sage: SUK = UnitGroup(K, S=S) sage: phi_complex = K.places()[1] @@ -125,15 +125,15 @@ def c3_func(SUK, prec=106): OUTPUT: - The constant ``c3``, as a real number + The constant `c_3`, as a real number EXAMPLES:: sage: from sage.rings.number_field.S_unit_solver import c3_func - sage: K. = NumberField(x^3-3) + sage: K. = NumberField(x^3 - 3) sage: SUK = UnitGroup(K, S=tuple(K.primes_above(3))) - sage: c3_func(SUK) # abs tol 1e-29 + sage: c3_func(SUK) # abs tol 1e-29 0.4257859134798034746197327286726 .. NOTE:: @@ -177,25 +177,25 @@ def c4_func(SUK, v, A, prec=106): OUTPUT: - The constant ``c4``, as a real number + The constant `c_4`, as a real number EXAMPLES:: sage: from sage.rings.number_field.S_unit_solver import c4_func - sage: K. = NumberField(x^3-3) + sage: K. = NumberField(x^3 - 3) sage: SUK = UnitGroup(K, S=tuple(K.primes_above(3))) sage: phi_real = K.places()[0] sage: phi_complex = K.places()[1] sage: v_fin = tuple(K.primes_above(3))[0] sage: A = K.roots_of_unity() - sage: c4_func(SUK,phi_real,A) + sage: c4_func(SUK, phi_real, A) 1.000000000000000000000000000000 - sage: c4_func(SUK,phi_complex,A) + sage: c4_func(SUK, phi_complex, A) 1.000000000000000000000000000000 - sage: c4_func(SUK,v_fin,A) + sage: c4_func(SUK, v_fin, A) 1.000000000000000000000000000000 REFERENCES: @@ -220,11 +220,11 @@ def beta_k(betas_and_ns): EXAMPLES:: sage: from sage.rings.number_field.S_unit_solver import beta_k - sage: K. = NumberField(x^3-3) + sage: K. = NumberField(x^3 - 3) sage: SUK = UnitGroup(K, S=tuple(K.primes_above(3))) sage: v_fin = tuple(K.primes_above(3))[0] - sage: betas = [ [beta, beta.valuation(v_fin)] for beta in SUK.fundamental_units() ] + sage: betas = [[beta, beta.valuation(v_fin)] for beta in SUK.fundamental_units()] sage: beta_k(betas) [xi, 1] @@ -297,12 +297,12 @@ def possible_mu0s(SUK, v): EXAMPLES:: sage: from sage.rings.number_field.S_unit_solver import possible_mu0s - sage: K. = NumberField(x^3-3) + sage: K. = NumberField(x^3 - 3) sage: S = tuple(K.primes_above(3)) sage: SUK = UnitGroup(K, S=S) sage: v_fin = S[0] - sage: possible_mu0s(SUK,v_fin) + sage: possible_mu0s(SUK, v_fin) [-1, 1] .. NOTE:: @@ -343,7 +343,7 @@ def Yu_a1_kappa1_c1(p, dK, ep): - ``p`` -- a rational prime number - ``dK`` -- the absolute degree of some number field `K` - - ``ep`` -- the absolute ramification index of some prime `frak_p` of `K` lying above `p` + - ``ep`` -- the absolute ramification index of some prime ``frak_p`` of `K` lying above `p` OUTPUT: @@ -515,18 +515,18 @@ def Yu_modified_height(mu, n, v, prec=106): def Omega_prime(dK, v, mu_list, prec=106): r""" - Return the constant Omega' appearing in [AKMRVW]_. + Return the constant `\Omega'` appearing in [AKMRVW]_. INPUT: - ``dK`` -- the degree of a number field `K` - ``v`` -- a finite place of `K` - - ``mu_list`` -- a list of nonzero elements of `K`. It is assumed that the sublist mu[1:] is multiplicatively independent. + - ``mu_list`` -- a list of nonzero elements of `K`. It is assumed that the sublist ``mu_list[1:]`` is multiplicatively independent. - ``prec`` -- the precision of the real field OUTPUT: - The constant `Omega'`. + The constant `\Omega'`. EXAMPLES:: @@ -559,7 +559,7 @@ def Omega_prime(dK, v, mu_list, prec=106): def Yu_C1_star(n, v, prec=106): r""" - Return the constant C_1^* appearing in [Yu2007]_ (1.23). + Return the constant `C_1^*` appearing in [Yu2007]_ (1.23). INPUT: @@ -569,7 +569,7 @@ def Yu_C1_star(n, v, prec=106): OUTPUT: - The constant `C1_star` as a real number. + The constant `C_1^*` as a real number. EXAMPLES:: @@ -619,7 +619,7 @@ def Yu_C1_star(n, v, prec=106): def Yu_bound(SUK, v, prec=106): r""" - Return `c8` such that `c8 >= exp(2)/\log(2)` and `ord_p (\Theta - 1) < c8 \log B`, + Return `c_8` such that `c_8 \geq exp(2)/\log(2)` and `ord_p (\Theta - 1) < c_8 \log B`, where `\Theta = \prod_{j=1}^n \alpha_j^{b_j}` and `B \geq \max_j |b_j|` and `B \geq 3`. INPUT: @@ -630,7 +630,7 @@ def Yu_bound(SUK, v, prec=106): OUTPUT: - The constant `c8` as a real number. + The constant `c_8` as a real number. EXAMPLES:: @@ -707,12 +707,12 @@ def K0_func(SUK, A, prec=106): INPUT: - ``SUK`` -- a group of `S`-units - - ``A`` -- the set of the products of the coefficients of the `S`-unit equation with each root of unity of ``K`` + - ``A`` -- the set of the products of the coefficients of the `S`-unit equation with each root of unity of `K` - ``prec`` -- the precision of the real field (default: 106) OUTPUT: - The constant ``K0``, a real number. + The constant `K_0`, a real number. EXAMPLES:: @@ -756,18 +756,18 @@ def c11_func(SUK, v, A, prec=106): INPUT: - ``SUK`` -- a group of `S`-units - - ``v`` -- a place of ``K``, finite (a fractional ideal) or infinite (element of ``SUK.number_field().places(prec)``) - - ``A`` -- the set of the product of the coefficients of the `S`-unit equation with each root of unity of ``K`` + - ``v`` -- a place of `K`, finite (a fractional ideal) or infinite (element of ``SUK.number_field().places(prec)``) + - ``A`` -- the set of the product of the coefficients of the `S`-unit equation with each root of unity of `K` - ``prec`` -- the precision of the real field (default: 106) OUTPUT: - The constant ``c11``, a real number + The constant `c_{11}`, a real number EXAMPLES:: sage: from sage.rings.number_field.S_unit_solver import c11_func - sage: K. = NumberField(x^3-3) + sage: K. = NumberField(x^3 - 3) sage: SUK = UnitGroup(K, S=tuple(K.primes_above(3))) sage: phi_real = K.places()[0] sage: phi_complex = K.places()[1] @@ -802,7 +802,7 @@ def c13_func(SUK, v, prec=106): OUTPUT: - The constant ``c13``, as a real number + The constant `c_{13}`, as a real number EXAMPLES:: @@ -848,18 +848,18 @@ def K1_func(SUK, v, A, prec=106): INPUT: - ``SUK`` -- a group of `S`-units - - ``v`` -- an infinite place of ``K`` (element of ``SUK.number_field().places(prec)``) - - ``A`` -- a list of all products of each potential ``a``, ``b`` in the `S`-unit equation ``ax + by + 1 = 0`` with each root of unity of ``K`` + - ``v`` -- an infinite place of `K` (element of ``SUK.number_field().places(prec)``) + - ``A`` -- a list of all products of each potential `a`, `b` in the `S`-unit equation `ax + by + 1 = 0` with each root of unity of `K` - ``prec`` -- the precision of the real field (default: 106) OUTPUT: - The constant ``K1,`` a real number + The constant `K_1`, a real number EXAMPLES:: sage: from sage.rings.number_field.S_unit_solver import K1_func - sage: K. = NumberField(x^3-3) + sage: K. = NumberField(x^3 - 3) sage: SUK = UnitGroup(K, S=tuple(K.primes_above(3))) sage: phi_real = K.places()[0] sage: phi_complex = K.places()[1] @@ -914,9 +914,9 @@ def minimal_vector(A, y, prec=106): r""" INPUT: - - ``A`` : a square n by n non-singular integer matrix whose rows generate a lattice `\mathcal L` - - ``y`` : a row (1 by n) vector with integer coordinates - - ``prec`` : precision of real field (default: 106) + - ``A`` -- a square `n` by `n` non-singular integer matrix whose rows generate a lattice `\mathcal L` + - ``y`` -- a row (1 by `n`) vector with integer coordinates + - ``prec`` -- precision of real field (default: 106) OUTPUT: @@ -1002,9 +1002,10 @@ def reduction_step_complex_case(place, B0, list_of_gens, torsion_gen, c13): EXAMPLES:: sage: from sage.rings.number_field.S_unit_solver import reduction_step_complex_case - sage: K. = NumberField([x^3-2]) + sage: K. = NumberField([x^3 - 2]) sage: SK = sum([K.primes_above(p) for p in [2,3,5]],[]) - sage: G = [g for g in K.S_unit_group(S=SK).gens_values() if g.multiplicative_order()==Infinity] + sage: G = [g for g in K.S_unit_group(S=SK).gens_values() + ....: if g.multiplicative_order() == Infinity] sage: p1 = K.places(prec=100)[1] sage: reduction_step_complex_case(p1, 10^5, G, -1, 2) (18, False) @@ -1160,7 +1161,7 @@ def cx_LLL_bound(SUK, A, prec=106): INPUT: - ``SUK`` -- a group of `S`-units - - ``A`` -- a list of all products of each potential ``a``, ``b`` in the `S`-unit equation ``ax + by + 1 = 0`` with each root of unity of ``K`` + - ``A`` -- a list of all products of each potential `a`, `b` in the `S`-unit equation `ax + by + 1 = 0` with each root of unity of `K` - ``prec`` -- precision of real field (default: 106) OUTPUT: @@ -1170,11 +1171,11 @@ def cx_LLL_bound(SUK, A, prec=106): EXAMPLES:: sage: from sage.rings.number_field.S_unit_solver import cx_LLL_bound - sage: K. = NumberField(x^3-3) - sage: SUK = UnitGroup(K,S=tuple(K.primes_above(3))) + sage: K. = NumberField(x^3 - 3) + sage: SUK = UnitGroup(K, S=tuple(K.primes_above(3))) sage: A = K.roots_of_unity() - sage: cx_LLL_bound(SUK,A) # long time + sage: cx_LLL_bound(SUK, A) # long time 35 """ cx_LLL = 0 @@ -1219,7 +1220,7 @@ def log_p(a, prime, prec): OUTPUT: - An element of `K` which is congruent to the ``prime``-adic logarithm of ``a`` with respect to ``prime`` modulo ``p^prec``, where ``p`` is the rational prime below ``prime`` + An element of `K` which is congruent to the ``prime``-adic logarithm of `a` with respect to ``prime`` modulo ``p^prec``, where `p` is the rational prime below ``prime`` .. NOTE:: @@ -1228,7 +1229,7 @@ def log_p(a, prime, prec): EXAMPLES:: sage: from sage.rings.number_field.S_unit_solver import log_p - sage: K. = NumberField(x^2+14) + sage: K. = NumberField(x^2 + 14) sage: p1 = K.primes_above(3)[0] sage: p1 Fractional ideal (3, a + 1) @@ -1237,7 +1238,7 @@ def log_p(a, prime, prec): :: - sage: K. = NumberField(x^4+14) + sage: K. = NumberField(x^4 + 14) sage: p1 = K.primes_above(5)[0] sage: p1 Fractional ideal (5, a + 1) @@ -1283,7 +1284,7 @@ def log_p_series_part(a, prime, prec): OUTPUT: - The ``prime``-adic logarithm of ``a`` and accuracy ``p^prec``, where ``p`` is the rational prime below ``prime`` + The ``prime``-adic logarithm of `a` and accuracy ``p^prec``, where `p` is the rational prime below ``prime`` ALGORITHM: @@ -1292,16 +1293,16 @@ def log_p_series_part(a, prime, prec): EXAMPLES:: sage: from sage.rings.number_field.S_unit_solver import log_p_series_part - sage: K. = NumberField(x^2-5) + sage: K. = NumberField(x^2 - 5) sage: p1 = K.primes_above(3)[0] sage: p1 Fractional ideal (3) - sage: log_p_series_part(a^2-a+1, p1, 30) + sage: log_p_series_part(a^2 - a + 1, p1, 30) 120042736778562*a + 263389019530092 :: - sage: K. = NumberField(x^4+14) + sage: K. = NumberField(x^4 + 14) sage: p1 = K.primes_above(5)[0] sage: p1 Fractional ideal (5, a + 1) @@ -1442,7 +1443,7 @@ def embedding_to_Kp(a, prime, prec): OUTPUT: - An element of `K` that is equivalent to ``a`` modulo ``p^(prec)`` and the generator of `K` appears with exponent less than `e \cdot f`, where ``p`` is the rational prime below ``prime`` and `e,f` are the ramification index and residue degree, respectively. + An element of `K` that is equivalent to `a` modulo ``p^(prec)`` and the generator of `K` appears with exponent less than `e \cdot f`, where `p` is the rational prime below ``prime`` and `e`, `f` are the ramification index and residue degree, respectively. .. NOTE:: @@ -1459,10 +1460,10 @@ def embedding_to_Kp(a, prime, prec): :: - sage: K. = NumberField(x^4-2) + sage: K. = NumberField(x^4 - 2) sage: p = K.prime_above(7); p Fractional ideal (-a^2 + a - 1) - sage: embedding_to_Kp(a^3-3, p, 15) + sage: embedding_to_Kp(a^3 - 3, p, 15) -1261985118949117459462968282807202378 """ K = prime.ring() @@ -1486,7 +1487,7 @@ def p_adic_LLL_bound_one_prime(prime, B0, M, M_logp, m0, c3, prec=106): - ``M_logp`` -- the p-adic logarithm of elements in `M` - ``m0`` -- an element of `K`, this is `\mu_0` from Lemma IX.3 of [Sma1998]_ - ``c3`` -- a positive real constant - - ``prec`` -- the precision of the calculations (default: 106), i.e., values are known to O(p^prec) + - ``prec`` -- the precision of the calculations (default: 106), i.e., values are known to ``O(p^prec)`` OUTPUT: @@ -1506,32 +1507,36 @@ def p_adic_LLL_bound_one_prime(prime, B0, M, M_logp, m0, c3, prec=106): sage: from sage.rings.number_field.S_unit_solver import p_adic_LLL_bound_one_prime sage: prec = 50 - sage: K. = NumberField(x^3-3) + sage: K. = NumberField(x^3 - 3) sage: S = tuple(K.primes_above(3)) sage: SUK = UnitGroup(K, S=S) sage: v = S[0] sage: A = SUK.roots_of_unity() sage: K0_old = 9.4755766731093e17 sage: Mus = [a^2 - 2] - sage: Log_p_Mus = [185056824593551109742400*a^2 + 1389583284398773572269676*a + 717897987691852588770249] + sage: Log_p_Mus = [185056824593551109742400*a^2 + ....: + 1389583284398773572269676*a + 717897987691852588770249] sage: mu0 = K(-1) sage: c3_value = 0.42578591347980 - sage: m0_Kv_new, increase_precision = p_adic_LLL_bound_one_prime(v, K0_old, Mus, Log_p_Mus, mu0, c3_value, prec) + sage: m0_Kv_new, increase_prec = p_adic_LLL_bound_one_prime(v, K0_old, Mus, Log_p_Mus, + ....: mu0, c3_value, prec) sage: m0_Kv_new 0 - sage: increase_precision + sage: increase_prec True And now we increase the precision to make it all work:: sage: prec = 106 sage: K0_old = 9.475576673109275443280257946930e17 - sage: Log_p_Mus = [1029563604390986737334686387890424583658678662701816*a^2 + 661450700156368458475507052066889190195530948403866*a] + sage: Log_p_Mus = [1029563604390986737334686387890424583658678662701816*a^2 + ....: + 661450700156368458475507052066889190195530948403866*a] sage: c3_value = 0.4257859134798034746197327286726 - sage: m0_Kv_new, increase_precision = p_adic_LLL_bound_one_prime(v, K0_old, Mus, Log_p_Mus, mu0, c3_value, prec) + sage: m0_Kv_new, increase_prec = p_adic_LLL_bound_one_prime(v, K0_old, Mus, Log_p_Mus, + ....: mu0, c3_value, prec) sage: m0_Kv_new 476 - sage: increase_precision + sage: increase_prec False """ if any(g.valuation(prime) != 0 for g in M+[m0]): @@ -1629,7 +1634,7 @@ def p_adic_LLL_bound(SUK, A, prec=106): INPUT: - ``SUK`` -- a group of `S`-units - - ``A`` -- a list of all products of each potential ``a``, ``b`` in the `S`-unit equation ``ax + by + 1 = 0`` with each root of unity of ``K`` + - ``A`` -- a list of all products of each potential `a`, `b` in the `S`-unit equation `ax + by + 1 = 0` with each root of unity of `K` - ``prec``-- precision for p-adic LLL calculations (default: 106) OUTPUT: @@ -1639,11 +1644,11 @@ def p_adic_LLL_bound(SUK, A, prec=106): EXAMPLES:: sage: from sage.rings.number_field.S_unit_solver import p_adic_LLL_bound - sage: K. = NumberField(x^3-3) - sage: SUK = UnitGroup(K,S=tuple(K.primes_above(3))) + sage: K. = NumberField(x^3 - 3) + sage: SUK = UnitGroup(K, S=tuple(K.primes_above(3))) sage: A = SUK.roots_of_unity() sage: prec = 100 - sage: p_adic_LLL_bound(SUK,A, prec) + sage: p_adic_LLL_bound(SUK, A, prec) 89 """ S = SUK.primes() @@ -1683,7 +1688,7 @@ def p_adic_LLL_bound(SUK, A, prec=106): def split_primes_large_lcm(SUK, bound): r""" - Return a list ``L`` of rational primes `q` which split completely in `K` and which have desirable properties (see NOTE). + Return a list `L` of rational primes `q` which split completely in `K` and which have desirable properties (see NOTE). INPUT: @@ -1697,7 +1702,7 @@ def split_primes_large_lcm(SUK, bound): - each prime `q` in `L` splits completely in `K` - if `Q` is a prime in `S` and `q` is the rational prime below `Q`, then `q` is **not** in `L` - - the value ``lcm { q-1 : q in L }`` is greater than or equal to ``2*bound + 1``. + - the value `\lcm(\{ q-1 : q \in L \})` is greater than or equal to ``2*bound + 1``. .. NOTE:: @@ -1713,7 +1718,7 @@ def split_primes_large_lcm(SUK, bound): sage: from sage.rings.number_field.S_unit_solver import split_primes_large_lcm sage: K. = NumberField(x^3 - 3*x + 1) sage: S = K.primes_above(3) - sage: SUK = UnitGroup(K,S=tuple(S)) + sage: SUK = UnitGroup(K, S=tuple(S)) sage: split_primes_large_lcm(SUK, 200) [17, 19, 37, 53] @@ -1752,7 +1757,7 @@ def split_primes_large_lcm(SUK, bound): def sieve_ordering(SUK, q): r""" - Returns ordered data for running sieve on the primes in `SUK` over the rational prime `q`. + Return ordered data for running sieve on the primes in ``SUK`` over the rational prime `q`. INPUT: @@ -1763,7 +1768,7 @@ def sieve_ordering(SUK, q): A list of tuples, ``[ideals_over_q, residue_fields, rho_images, product_rho_orders]``, where - 1. ``ideals_over_q`` is a list of the `d = [K:\mathbb{Q}]` ideals in `K` over `q` + 1. ``ideals_over_q`` is a list of the `d = [K:\QQ]` ideals in `K` over `q` 2. ``residue_fields[i]`` is the residue field of ``ideals_over_q[i]`` 3. ``rho_images[i]`` is a list of the reductions of the generators in of the `S`-unit group, modulo ``ideals_over_q[i]`` 4. ``product_rho_orders[i]`` is the product of the multiplicative orders of the elements in ``rho_images[i]`` @@ -1771,7 +1776,7 @@ def sieve_ordering(SUK, q): .. NOTE:: - The list ``ideals_over_q`` is sorted so that the product of orders is smallest for ``ideals_over_q[0]``, as this will make the later sieving steps more efficient. - - The primes of ``S`` must not lie over ``q``. + - The primes of `S` must not lie over `q`. EXAMPLES:: @@ -1821,7 +1826,7 @@ def sieve_ordering(SUK, q): def clean_rfv_dict(rfv_dictionary): r""" - Given a residue field vector dictionary, removes some impossible keys and entries. + Given a residue field vector dictionary, remove some impossible keys and entries. INPUT: @@ -1829,13 +1834,13 @@ def clean_rfv_dict(rfv_dictionary): OUTPUT: - None. But it removes some keys from the input dictionary. + ``None``. But it removes some keys from the input dictionary. .. NOTE:: - - The keys of a residue field vector dictionary are exponent vectors modulo ``(q-1)`` for some prime ``q``. - - The values are residue field vectors. It is known that the entries of a residue field vector - which comes from a solution to the S-unit equation cannot have 1 in any entry. + - The keys of a residue field vector dictionary are exponent vectors modulo `q-1` for some prime `q`. + - The values are residue field vectors. It is known that a residue field vector + which comes from a solution to the `S`-unit equation cannot have 1 in any entry. EXAMPLES: @@ -1843,7 +1848,8 @@ def clean_rfv_dict(rfv_dictionary): polynomial `x^2+x+1` and `S` consists of the primes above 3:: sage: from sage.rings.number_field.S_unit_solver import clean_rfv_dict - sage: rfv_dict = {(1, 3): [3, 2], (3, 0): [6, 6], (5, 4): [3, 6], (2, 1): [4, 6], (5, 1): [3, 1], (2, 5): [1, 5], (0, 3): [1, 6]} + sage: rfv_dict = {(1, 3): [3, 2], (3, 0): [6, 6], (5, 4): [3, 6], (2, 1): [4, 6], + ....: (5, 1): [3, 1], (2, 5): [1, 5], (0, 3): [1, 6]} sage: len(rfv_dict) 7 sage: clean_rfv_dict(rfv_dict) @@ -1866,8 +1872,8 @@ def construct_rfv_to_ev(rfv_dictionary, q, d, verbose=False): - ``rfv_dictionary`` -- a dictionary whose keys are exponent vectors and whose values are the associated residue field vectors - ``q`` -- a prime (assumed to split completely in the relevant number field) - - ``d`` -- the number of primes in `K` above the rational prime ``q`` - - ``verbose`` -- a boolean flag to indicate more detailed output is desired (default: False) + - ``d`` -- the number of primes in `K` above the rational prime `q` + - ``verbose`` -- a boolean flag to indicate more detailed output is desired (default: ``False``) OUTPUT: @@ -1876,7 +1882,7 @@ def construct_rfv_to_ev(rfv_dictionary, q, d, verbose=False): .. NOTE:: - - For example, if ``rfv_dictionary[ e0 ] = r0``, then ``P[ r0 ]`` is a list which contains ``e0``. + - For example, if ``rfv_dictionary[e0] = r0``, then ``P[r0]`` is a list which contains ``e0``. - During construction, some residue field vectors can be eliminated as coming from solutions to the `S`-unit equation. Such vectors are dropped from the keys of the dictionary ``P``. @@ -1886,7 +1892,8 @@ def construct_rfv_to_ev(rfv_dictionary, q, d, verbose=False): polynomial `x^2+x+1` and `S` consists of the primes above 3:: sage: from sage.rings.number_field.S_unit_solver import construct_rfv_to_ev - sage: rfv_dict = {(1, 3): [3, 2], (3, 0): [6, 6], (5, 4): [3, 6], (2, 1): [4, 6], (4, 0): [4, 2], (1, 2): [5, 6]} + sage: rfv_dict = {(1, 3): [3, 2], (3, 0): [6, 6], (5, 4): [3, 6], (2, 1): [4, 6], + ....: (4, 0): [4, 2], (1, 2): [5, 6]} sage: construct_rfv_to_ev(rfv_dict,7,2,False) {(3, 2): [(1, 3)], (4, 2): [(4, 0)], (4, 6): [(2, 1)], (5, 6): [(1, 2)]} """ @@ -2013,7 +2020,15 @@ def construct_comp_exp_vec(rfv_to_ev_dict, q): :: sage: from sage.rings.number_field.S_unit_solver import construct_comp_exp_vec - sage: rfv_to_ev_dict = {(6, 6): [(3, 0)], (5, 6): [(1, 2)], (5, 4): [(5, 3)], (6, 2): [(5, 5)], (2, 5): [(0, 1)], (5, 5): [(3, 4)], (4, 4): [(0, 2)], (6, 3): [(1, 4)], (3, 6): [(5, 4)], (2, 2): [(0, 4)], (3, 5): [(1, 0)], (6, 4): [(1, 1)], (3, 2): [(1, 3)], (2, 6): [(4, 5)], (4, 5): [(4, 3)], (2, 3): [(2, 3)], (4, 2): [(4, 0)], (6, 5): [(5, 2)], (3, 3): [(3, 2)], (5, 3): [(5, 0)], (4, 6): [(2, 1)], (3, 4): [(3, 5)], (4, 3): [(0, 5)], (5, 2): [(3, 1)], (2, 4): [(2, 0)]} + sage: rfv_to_ev_dict = {(6, 6): [(3, 0)], (5, 6): [(1, 2)], (5, 4): [(5, 3)], + ....: (6, 2): [(5, 5)], (2, 5): [(0, 1)], (5, 5): [(3, 4)], + ....: (4, 4): [(0, 2)], (6, 3): [(1, 4)], (3, 6): [(5, 4)], + ....: (2, 2): [(0, 4)], (3, 5): [(1, 0)], (6, 4): [(1, 1)], + ....: (3, 2): [(1, 3)], (2, 6): [(4, 5)], (4, 5): [(4, 3)], + ....: (2, 3): [(2, 3)], (4, 2): [(4, 0)], (6, 5): [(5, 2)], + ....: (3, 3): [(3, 2)], (5, 3): [(5, 0)], (4, 6): [(2, 1)], + ....: (3, 4): [(3, 5)], (4, 3): [(0, 5)], (5, 2): [(3, 1)], + ....: (2, 4): [(2, 0)]} sage: construct_comp_exp_vec(rfv_to_ev_dict, 7) {(0, 1): [(1, 4)], (0, 2): [(0, 2)], @@ -2054,17 +2069,17 @@ def construct_comp_exp_vec(rfv_to_ev_dict, q): def drop_vector(ev, p, q, complement_ev_dict): r""" - Determines if the exponent vector, ``ev``, may be removed from the complement dictionary during construction. - This will occur if ``ev`` is not compatible with an exponent vector mod ``q-1``. + Determine if the exponent vector, ``ev``, may be removed from the complement dictionary during construction. + This will occur if ``ev`` is not compatible with an exponent vector mod `q-1`. INPUT: - - ``ev`` -- an exponent vector modulo ``p - 1`` - - ``p`` -- the prime such that ev is an exponent vector modulo ``p-1`` - - ``q`` -- a prime, distinct from ``p``, that is a key in the ``complement_ev_dict`` - - ``complement_ev_dict`` -- a dictionary of dictionaries, whose keys are primes - ``complement_ev_dict[q]`` is a dictionary whose keys are exponent vectors modulo ``q-1`` - and whose values are lists of complementary exponent vectors modulo ``q-1`` + - ``ev`` -- an exponent vector modulo `p-1` + - ``p`` -- the prime such that ``ev`` is an exponent vector modulo `p-1` + - ``q`` -- a prime, distinct from `p`, that is a key in the ``complement_ev_dict`` + - ``complement_ev_dict`` -- a dictionary of dictionaries, whose keys are primes. + ``complement_ev_dict[q]`` is a dictionary whose keys are exponent vectors modulo `q-1` + and whose values are lists of complementary exponent vectors modulo `q-1` OUTPUT: @@ -2072,19 +2087,35 @@ def drop_vector(ev, p, q, complement_ev_dict): .. NOTE:: - - If ``ev`` is not compatible with any of the vectors modulo ``q-1``, then it can no longer correspond to a solution + - If ``ev`` is not compatible with any of the vectors modulo `q-1`, then it can no longer correspond to a solution of the `S`-unit equation. It returns ``True`` to indicate that it should be removed. EXAMPLES:: sage: from sage.rings.number_field.S_unit_solver import drop_vector - sage: drop_vector((1, 2, 5), 7, 11, {11: {(1, 1, 3): [(1, 1, 3),(2, 3, 4)]}}) + sage: drop_vector((1, 2, 5), 7, 11, {11: {(1, 1, 3): [(1, 1, 3), (2, 3, 4)]}}) True :: - sage: P={3: {(1, 0, 0): [(1, 0, 0), (0, 1, 0)], (0, 1, 0): [(1, 0, 0), (0, 1, 0)]}, 7: {(0, 3, 4): [(0, 1, 2), (0, 3, 4), (0, 5, 0)], (1, 2, 4): [(1, 0, 4), (1, 4, 2), (1, 2, 0)], (0, 1, 2): [(0, 1, 2), (0, 3, 4), (0, 5, 0)], (0, 5, 4): [(1, 0, 0), (1, 4, 4), (1, 2, 2)], (1, 4, 2): [(1, 2, 4), (1, 4, 0), (1, 0, 2)], (1, 0, 4): [(1, 2, 4), (1, 4, 0), (1, 0, 2)], (0, 3, 2): [(1, 0, 0), (1, 4, 4), (1, 2, 2)], (1, 0, 0): [(0, 5, 4), (0, 3, 2), (0, 1, 0)], (1, 2, 0): [(1, 2, 4), (1, 4, 0), (1, 0, 2)], (0, 1, 0): [(1, 0, 0), (1, 4, 4), (1, 2, 2)], (0, 5, 0): [(0, 1, 2), (0, 3, 4), (0, 5, 0)], (1, 2, 2): [(0, 5, 4), (0, 3, 2), (0, 1, 0)], (1, 4, 0): [(1, 0, 4), (1, 4, 2), (1, 2, 0)], (1, 0, 2): [(1, 0, 4), (1, 4, 2), (1, 2, 0)], (1, 4, 4): [(0, 5, 4), (0, 3, 2), (0, 1, 0)]}} - sage: drop_vector((0,1,0),3,7,P) + sage: P = {3: {(1, 0, 0): [(1, 0, 0), (0, 1, 0)], + ....: (0, 1, 0): [(1, 0, 0), (0, 1, 0)]}, + ....: 7: {(0, 3, 4): [(0, 1, 2), (0, 3, 4), (0, 5, 0)], + ....: (1, 2, 4): [(1, 0, 4), (1, 4, 2), (1, 2, 0)], + ....: (0, 1, 2): [(0, 1, 2), (0, 3, 4), (0, 5, 0)], + ....: (0, 5, 4): [(1, 0, 0), (1, 4, 4), (1, 2, 2)], + ....: (1, 4, 2): [(1, 2, 4), (1, 4, 0), (1, 0, 2)], + ....: (1, 0, 4): [(1, 2, 4), (1, 4, 0), (1, 0, 2)], + ....: (0, 3, 2): [(1, 0, 0), (1, 4, 4), (1, 2, 2)], + ....: (1, 0, 0): [(0, 5, 4), (0, 3, 2), (0, 1, 0)], + ....: (1, 2, 0): [(1, 2, 4), (1, 4, 0), (1, 0, 2)], + ....: (0, 1, 0): [(1, 0, 0), (1, 4, 4), (1, 2, 2)], + ....: (0, 5, 0): [(0, 1, 2), (0, 3, 4), (0, 5, 0)], + ....: (1, 2, 2): [(0, 5, 4), (0, 3, 2), (0, 1, 0)], + ....: (1, 4, 0): [(1, 0, 4), (1, 4, 2), (1, 2, 0)], + ....: (1, 0, 2): [(1, 0, 4), (1, 4, 2), (1, 2, 0)], + ....: (1, 4, 4): [(0, 5, 4), (0, 3, 2), (0, 1, 0)]}} + sage: drop_vector((0, 1, 0), 3, 7, P) False """ # returns True if it is OK to drop exp_vec given the current comp_exp_vec dictionary associated to some q. @@ -2105,7 +2136,7 @@ def drop_vector(ev, p, q, complement_ev_dict): def construct_complement_dictionaries(split_primes_list, SUK, verbose=False): r""" - A function to construct the complement exponent vector dictionaries. + Construct the complement exponent vector dictionaries. INPUT: @@ -2116,15 +2147,15 @@ def construct_complement_dictionaries(split_primes_list, SUK, verbose=False): OUTPUT: A dictionary of dictionaries. The keys coincide with the primes in ``split_primes_list`` - For each ``q``, ``comp_exp_vec[q]`` is a dictionary whose keys are exponent vectors modulo ``q-1``, - and whose values are lists of exponent vectors modulo ``q-1`` + For each `q`, ``comp_exp_vec[q]`` is a dictionary whose keys are exponent vectors modulo `q-1`, + and whose values are lists of exponent vectors modulo `q-1` - If ``w`` is an exponent vector in ``comp_exp_vec[q][v]``, then the residue field vectors modulo ``q`` for - ``v`` and ``w`` sum to ``[1,1,...,1]`` + If `w` is an exponent vector in ``comp_exp_vec[q][v]``, then the residue field vectors modulo `q` for + `v` and `w` sum to ``[1,1,...,1]`` .. NOTE:: - - The data of ``comp_exp_vec`` will later be lifted to `\mathbb{Z}` to look for true `S`-Unit equation solutions. + - The data of ``comp_exp_vec`` will later be lifted to `\ZZ` to look for true `S`-Unit equation solutions. - During construction, the various dictionaries are compared to each other several times to eliminate as many mod `q` solutions as possible. - The authors acknowledge a helpful discussion with Norman Danner which helped formulate this code. @@ -2155,7 +2186,8 @@ def construct_complement_dictionaries(split_primes_list, SUK, verbose=False): ....: (1, 4, 0): [(1, 0, 4), (1, 4, 2), (1, 2, 0)], ....: (1, 4, 2): [(1, 2, 4), (1, 4, 0), (1, 0, 2)], ....: (1, 4, 4): [(0, 5, 4), (0, 3, 2), (0, 1, 0)]}} - sage: all(set(actual[p][vec]) == set(expected[p][vec]) for p in [3,7] for vec in expected[p]) + sage: all(set(actual[p][vec]) == set(expected[p][vec]) + ....: for p in [3, 7] for vec in expected[p]) True """ # We initialize some dictionaries. @@ -2318,7 +2350,7 @@ def epsilon_q(a, i): def compatible_vectors_check(a0, a1, g, l): r""" - Given exponent vectors with respect to two moduli, determines if they are compatible. + Given exponent vectors with respect to two moduli, determine if they are compatible. INPUT: @@ -2329,7 +2361,7 @@ def compatible_vectors_check(a0, a1, g, l): OUTPUT: - True if there is an integer exponent vector a satisfying + ``True`` if there is an integer exponent vector a satisfying .. MATH:: @@ -2339,7 +2371,7 @@ def compatible_vectors_check(a0, a1, g, l): a[1:] &== a1[1:] \mod m_1 \end{aligned} - and False otherwise. + and ``False`` otherwise. .. NOTE:: @@ -2363,14 +2395,14 @@ def compatible_vectors_check(a0, a1, g, l): def compatible_vectors(a, m0, m1, g): r""" - Given an exponent vector ``a`` modulo ``m0``, returns an iterator over the exponent vectors for the modulus ``m1``, such that a lift to the lcm modulus exists. + Given an exponent vector ``a`` modulo ``m0``, return an iterator over the exponent vectors for the modulus ``m1``, such that a lift to the lcm modulus exists. INPUT: - ``a`` -- an exponent vector for the modulus ``m0`` - ``m0`` -- a positive integer (specifying the modulus for ``a``) - ``m1`` -- a positive integer (specifying the alternate modulus) - - ``g`` -- the gcd of m0 and m1 + - ``g`` -- the gcd of ``m0`` and ``m1`` OUTPUT: @@ -2386,13 +2418,13 @@ def compatible_vectors(a, m0, m1, g): sage: a = (3, 1, 8, 1) sage: list(compatible_vectors(a, 18, 12, gcd(18,12))) [(3, 1, 2, 1), - (3, 1, 2, 7), - (3, 1, 8, 1), - (3, 1, 8, 7), - (3, 7, 2, 1), - (3, 7, 2, 7), - (3, 7, 8, 1), - (3, 7, 8, 7)] + (3, 1, 2, 7), + (3, 1, 8, 1), + (3, 1, 8, 7), + (3, 7, 2, 1), + (3, 7, 2, 7), + (3, 7, 8, 1), + (3, 7, 8, 7)] The order of the moduli matters. :: @@ -2408,7 +2440,7 @@ def compatible_vectors(a, m0, m1, g): def compatible_systems(split_prime_list, complement_exp_vec_dict): r""" - Given dictionaries of complement exponent vectors for various primes that split in K, compute all possible compatible systems. + Given dictionaries of complement exponent vectors for various primes that split in `K`, compute all possible compatible systems. INPUT: @@ -2421,21 +2453,21 @@ def compatible_systems(split_prime_list, complement_exp_vec_dict): .. NOTE:: - - For any ``q`` in ``split_prime_list``, ``complement_exp_vec_dict[q]`` is a dictionary whose keys are exponent vectors modulo ``q-1`` - and whose values are lists of exponent vectors modulo ``q-1`` which are complementary to the key. + - For any `q` in ``split_prime_list``, ``complement_exp_vec_dict[q]`` is a dictionary whose keys are exponent vectors modulo `q-1` + and whose values are lists of exponent vectors modulo `q-1` which are complementary to the key. - - an item in system_list has the form ``[ [v0, w0], [v1, w1], ..., [vk, wk] ]``, where:: + - An item in ``system_list`` has the form ``[ [v0, w0], [v1, w1], ..., [vk, wk] ]``, where:: - - ``qj = split_prime_list[j]`` - - ``vj`` and ``wj`` are complementary exponent vectors modulo ``qj - 1`` - - the pairs are all simultaneously compatible. + - ``qj = split_prime_list[j]`` + - ``vj`` and ``wj`` are complementary exponent vectors modulo ``qj - 1`` + - the pairs are all simultaneously compatible. - Let ``H = lcm( qj - 1 : qj in split_primes_list )``. Then for any compatible system, there is at most one pair of integer exponent vectors ``[v, w]`` such that:: - - every entry of ``v`` and ``w`` is bounded in absolute value by ``H`` - - for any ``qj``, ``v`` and ``vj`` agree modulo ``(qj - 1)`` - - for any ``qj``, ``w`` and ``wj`` agree modulo ``(qj - 1)`` + - every entry of ``v`` and ``w`` is bounded in absolute value by ``H`` + - for any ``qj``, ``v`` and ``vj`` agree modulo ``(qj - 1)`` + - for any ``qj``, ``w`` and ``wj`` agree modulo ``(qj - 1)`` EXAMPLES:: @@ -2535,14 +2567,14 @@ def compatible_system_lift(compatible_system, split_primes_list): def solutions_from_systems(SUK, bound, cs_list, split_primes_list): r""" - Lifts compatible systems to the integers and returns the S-unit equation solutions the lifts yield. + Lift compatible systems to the integers and return the `S`-unit equation solutions that the lifts yield. INPUT: - ``SUK`` -- the group of `S`-units where we search for solutions - ``bound`` -- a bound for the entries of all entries of all lifts - ``cs_list`` -- a list of compatible systems of exponent vectors modulo `q-1` for - various primes `q` + various primes `q` - ``split_primes_list`` -- a list of primes giving the moduli of the exponent vectors in ``cs_list`` OUTPUT: @@ -2565,11 +2597,11 @@ def solutions_from_systems(SUK, bound, cs_list, split_primes_list): Given a single compatible system, a solution can be found. :: sage: from sage.rings.number_field.S_unit_solver import solutions_from_systems - sage: K. = NumberField(x^2-15) + sage: K. = NumberField(x^2 - 15) sage: SUK = K.S_unit_group(S=K.primes_above(2)) sage: split_primes_list = [7, 17] sage: a_compatible_system = [[[(0, 0, 5), (0, 0, 5)], [(0, 0, 15), (0, 0, 15)]]] - sage: solutions_from_systems( SUK, 20, a_compatible_system, split_primes_list ) + sage: solutions_from_systems(SUK, 20, a_compatible_system, split_primes_list) [((0, 0, -1), (0, 0, -1), 1/2, 1/2)] """ solutions = [] @@ -2591,19 +2623,19 @@ def solutions_from_systems(SUK, bound, cs_list, split_primes_list): def clean_sfs(sfs_list): r""" - Given a list of S-unit equation solutions, remove trivial redundancies. + Given a list of `S`-unit equation solutions, remove trivial redundancies. INPUT: - - ``sfs_list`` -- a list of solutions to the S-unit equation + - ``sfs_list`` -- a list of solutions to the `S`-unit equation OUTPUT: - A list of solutions to the S-unit equation + A list of solutions to the `S`-unit equation .. NOTE:: - The function looks for cases where ``x + y = 1`` and ``y + x = 1`` appear\ + The function looks for cases where `x + y = 1` and `y + x = 1` appear as separate solutions, and removes one. EXAMPLES: @@ -2627,37 +2659,38 @@ def clean_sfs(sfs_list): def sieve_below_bound(K, S, bound=10, bump=10, split_primes_list=[], verbose=False): r""" - Return all solutions to the S-unit equation ``x + y = 1`` over K with exponents below the given bound. + Return all solutions to the `S`-unit equation `x + y = 1` over `K` with exponents below the given bound. INPUT: - ``K`` -- a number field (an absolute extension of the rationals) - - ``S`` -- a list of finite primes of ``K`` + - ``S`` -- a list of finite primes of `K` - ``bound`` -- a positive integer upper bound for exponents, solutions with exponents having absolute value below this bound will be found (default: 10) - ``bump`` -- a positive integer by which the minimum LCM will be increased if not enough split primes are found in sieving step (default: 10) - - ``split_primes_list`` -- a list of rational primes that split completely in the extension K/Q, used for sieving. For complete list of solutions should have lcm of {(p_i-1)} for primes p_i greater than bound (default: []) - - ``verbose`` -- an optional parameter allowing the user to print information during the sieving process (default: False) + - ``split_primes_list`` -- a list of rational primes that split completely in the extension `K/\QQ`, used for sieving. + For complete list of solutions should have lcm of `\{(p_i-1)\} for primes `p_i` greater than bound (default: ``[]``) + - ``verbose`` -- an optional parameter allowing the user to print information during the sieving process (default: ``False``) OUTPUT: - A list of tuples ``[( A_1, B_1, x_1, y_1), (A_2, B_2, x_2, y_2), ... ( A_n, B_n, x_n, y_n)]`` such that: + A list of tuples `[(A_1, B_1, x_1, y_1), (A_2, B_2, x_2, y_2), \dots (A_n, B_n, x_n, y_n)]` such that: - 1. The first two entries are tuples ``A_i = (a_0, a_1, ... , a_t)`` and ``B_i = (b_0, b_1, ... , b_t)`` of exponents. - 2. The last two entries are ``S``-units ``x_i`` and ``y_i`` in ``K`` with ``x_i + y_i = 1``. - 3. If the default generators for the ``S``-units of ``K`` are ``(rho_0, rho_1, ... , rho_t)``, then these satisfy ``x_i = \prod(rho_i)^(a_i)`` and ``y_i = \prod(rho_i)^(b_i)``. + 1. The first two entries are tuples `A_i = (a_0, a_1, \dots, a_t)` and `B_i = (b_0, b_1, \dots, b_t)` of exponents. + 2. The last two entries are `S`-units `x_i` and `y_i` in `K` with `x_i + y_i = 1`. + 3. If the default generators for the `S`-units of `K` are `(\rho_0, \rho_1, \dots, \rho_t)`, + then these satisfy `x_i = \prod(\rho_i)^{(a_i)}` and `y_i = \prod(\rho_i)^{(b_i)}`. EXAMPLES:: sage: from sage.rings.number_field.S_unit_solver import sieve_below_bound, eq_up_to_order - sage: K. = NumberField(x^2+x+1) - sage: SUK = UnitGroup(K,S=tuple(K.primes_above(3))) + sage: K. = NumberField(x^2 + x + 1) + sage: SUK = UnitGroup(K, S=tuple(K.primes_above(3))) sage: S = SUK.primes() sage: sols = sieve_below_bound(K, S, 10) - sage: expected = [ - ....: ((1, -1), (0, -1), 1/3*xi + 2/3, -1/3*xi + 1/3), - ....: ((0, 1), (4, 0), xi + 2, -xi - 1), - ....: ((2, 0), (5, 1), xi, -xi + 1), - ....: ((1, 0), (5, 0), xi + 1, -xi)] + sage: expected = [((1, -1), (0, -1), 1/3*xi + 2/3, -1/3*xi + 1/3), + ....: ((0, 1), (4, 0), xi + 2, -xi - 1), + ....: ((2, 0), (5, 1), xi, -xi + 1), + ....: ((1, 0), (5, 0), xi + 1, -xi)] sage: eq_up_to_order(sols, expected) True """ @@ -2687,42 +2720,41 @@ def sieve_below_bound(K, S, bound=10, bump=10, split_primes_list=[], verbose=Fal def solve_S_unit_equation(K, S, prec=106, include_exponents=True, include_bound=False, proof=None, verbose=False): r""" - Return all solutions to the S-unit equation ``x + y = 1`` over K. + Return all solutions to the `S`-unit equation `x + y = 1` over `K`. INPUT: - ``K`` -- a number field (an absolute extension of the rationals) - - ``S`` -- a list of finite primes of ``K`` + - ``S`` -- a list of finite primes of `K` - ``prec`` -- precision used for computations in real, complex, and p-adic fields (default: 106) - - ``include_exponents`` -- whether to include the exponent vectors in the returned value (default: True). - - ``include_bound`` -- whether to return the final computed bound (default: False) - - ``verbose`` -- whether to print information during the sieving step (default: False) + - ``include_exponents`` -- whether to include the exponent vectors in the returned value (default: ``True``). + - ``include_bound`` -- whether to return the final computed bound (default: ``False``) + - ``verbose`` -- whether to print information during the sieving step (default: ``False``) OUTPUT: - A list of tuples ``[( A_1, B_1, x_1, y_1), (A_2, B_2, x_2, y_2), ... ( A_n, B_n, x_n, y_n)]`` such that: + A list of tuples `[(A_1, B_1, x_1, y_1), (A_2, B_2, x_2, y_2), \dots (A_n, B_n, x_n, y_n)]` such that: - 1. The first two entries are tuples ``A_i = (a_0, a_1, ... , a_t)`` and ``B_i = (b_0, b_1, ... , b_t)`` of exponents. These will be omitted if ``include_exponents`` is ``False``. - 2. The last two entries are ``S``-units ``x_i`` and ``y_i`` in ``K`` with ``x_i + y_i = 1``. - 3. If the default generators for the ``S``-units of ``K`` are ``(rho_0, rho_1, ... , rho_t)``, then these satisfy ``x_i = \prod(rho_i)^(a_i)`` and ``y_i = \prod(rho_i)^(b_i)``. + 1. The first two entries are tuples `A_i = (a_0, a_1, \dots, a_t)` and `B_i = (b_0, b_1, \dots, b_t)` of exponents. These will be omitted if ``include_exponents`` is ``False``. + 2. The last two entries are `S`-units `x_i` and `y_i` in `K` with `x_i + y_i = 1`. + 3. If the default generators for the `S`-units of `K` are `(\rho_0, \rho_1, \dots, \rho_t)``, then these satisfy `x_i = \prod(\rho_i)^{(a_i)}` and `y_i = \prod(\rho_i)^{(b_i)}`. If ``include_bound``, will return a pair ``(sols, bound)`` where ``sols`` is as above and ``bound`` is the bound used for the entries in the exponent vectors. EXAMPLES:: sage: from sage.rings.number_field.S_unit_solver import solve_S_unit_equation, eq_up_to_order - sage: K. = NumberField(x^2+x+1) + sage: K. = NumberField(x^2 + x + 1) sage: S = K.primes_above(3) sage: sols = solve_S_unit_equation(K, S, 200) - sage: expected = [ - ....: ((0, 1), (4, 0), xi + 2, -xi - 1), - ....: ((1, -1), (0, -1), 1/3*xi + 2/3, -1/3*xi + 1/3), - ....: ((1, 0), (5, 0), xi + 1, -xi), - ....: ((2, 0), (5, 1), xi, -xi + 1)] + sage: expected = [((0, 1), (4, 0), xi + 2, -xi - 1), + ....: ((1, -1), (0, -1), 1/3*xi + 2/3, -1/3*xi + 1/3), + ....: ((1, 0), (5, 0), xi + 1, -xi), + ....: ((2, 0), (5, 1), xi, -xi + 1)] sage: eq_up_to_order(sols, expected) True - In order to see the bound as well use the optional parameter ``include_bound``:: + In order to see the bound as well, use the optional parameter ``include_bound``:: sage: solutions, bound = solve_S_unit_equation(K, S, 100, include_bound=True) sage: bound @@ -2731,7 +2763,8 @@ def solve_S_unit_equation(K, S, prec=106, include_exponents=True, include_bound= You can omit the exponent vectors:: sage: sols = solve_S_unit_equation(K, S, 200, include_exponents=False) - sage: expected = [(xi + 2, -xi - 1), (1/3*xi + 2/3, -1/3*xi + 1/3), (-xi, xi + 1), (-xi + 1, xi)] + sage: expected = [(xi + 2, -xi - 1), (1/3*xi + 2/3, -1/3*xi + 1/3), + ....: (-xi, xi + 1), (-xi + 1, xi)] sage: set(frozenset(a) for a in sols) == set(frozenset(b) for b in expected) True @@ -2740,11 +2773,12 @@ def solve_S_unit_equation(K, S, prec=106, include_exponents=True, include_bound= sage: solve_S_unit_equation(K, [3], 200) Traceback (most recent call last): ... - ValueError: S must consist only of prime ideals, or a single element from which a prime ideal can be constructed. + ValueError: S must consist only of prime ideals, + or a single element from which a prime ideal can be constructed. We check the case that the rank is 0:: - sage: K. = NumberField(x^2+x+1) + sage: K. = NumberField(x^2 + x + 1) sage: solve_S_unit_equation(K, []) [((1,), (5,), xi + 1, -xi)] """ @@ -2799,8 +2833,8 @@ def solve_S_unit_equation(K, S, prec=106, include_exponents=True, include_bound= def eq_up_to_order(A, B): """ - If A and B are lists of four-tuples ``[a0,a1,a2,a3]`` and ``[b0,b1,b2,b3]``, - checks that there is some reordering so that either ``ai=bi`` for all ``i`` or + If ``A`` and ``B`` are lists of four-tuples ``[a0,a1,a2,a3]`` and ``[b0,b1,b2,b3]``, + check that there is some reordering so that either ``ai=bi`` for all ``i`` or ``a0==b1``, ``a1==b0``, ``a2==b3``, ``a3==b2``. The entries must be hashable. @@ -2808,14 +2842,14 @@ def eq_up_to_order(A, B): EXAMPLES:: sage: from sage.rings.number_field.S_unit_solver import eq_up_to_order - sage: L = [(1,2,3,4),(5,6,7,8)] - sage: L1 = [L[1],L[0]] - sage: L2 = [(2,1,4,3),(6,5,8,7)] + sage: L = [(1,2,3,4), (5,6,7,8)] + sage: L1 = [L[1], L[0]] + sage: L2 = [(2,1,4,3), (6,5,8,7)] sage: eq_up_to_order(L, L1) True sage: eq_up_to_order(L, L2) True - sage: eq_up_to_order(L, [(1,2,4,3),(5,6,8,7)]) + sage: eq_up_to_order(L, [(1,2,4,3), (5,6,8,7)]) False """ # does not look very optimal diff --git a/src/sage/rings/number_field/bdd_height.py b/src/sage/rings/number_field/bdd_height.py index d0f37a2b192..fdb2bee52e0 100644 --- a/src/sage/rings/number_field/bdd_height.py +++ b/src/sage/rings/number_field/bdd_height.py @@ -279,9 +279,9 @@ def integer_points_in_polytope(matrix, interval_radius): Return the set of integer points in the polytope obtained by acting on a cube by a linear transformation. - Given an r-by-r matrix ``matrix`` and a real number ``interval_radius``, + Given an `r`-by-`r` matrix ``matrix`` and a real number ``interval_radius``, this function finds all integer lattice points in the polytope obtained by - transforming the cube [-interval_radius,interval_radius]^r via the linear + transforming the cube ``[-interval_radius, interval_radius]^r`` via the linear map induced by ``matrix``. INPUT: @@ -296,37 +296,38 @@ def integer_points_in_polytope(matrix, interval_radius): EXAMPLES: - Stretch the interval [-1,1] by a factor of 2 and find the integers in the + Stretch the interval `[-1,1]` by a factor of 2 and find the integers in the resulting interval:: sage: from sage.rings.number_field.bdd_height import integer_points_in_polytope sage: m = matrix([2]) sage: r = 1 - sage: integer_points_in_polytope(m,r) + sage: integer_points_in_polytope(m, r) [(-2), (-1), (0), (1), (2)] Integer points inside a parallelogram:: sage: from sage.rings.number_field.bdd_height import integer_points_in_polytope - sage: m = matrix([[1, 2],[3, 4]]) + sage: m = matrix([[1, 2], [3, 4]]) sage: r = RealField()(1.3) - sage: integer_points_in_polytope(m,r) - [(-3, -7), (-2, -5), (-2, -4), (-1, -3), (-1, -2), (-1, -1), (0, -1), (0, 0), (0, 1), (1, 1), (1, 2), (1, 3), (2, 4), (2, 5), (3, 7)] + sage: integer_points_in_polytope(m, r) + [(-3, -7), (-2, -5), (-2, -4), (-1, -3), (-1, -2), (-1, -1), (0, -1), + (0, 0), (0, 1), (1, 1), (1, 2), (1, 3), (2, 4), (2, 5), (3, 7)] Integer points inside a parallelepiped:: sage: from sage.rings.number_field.bdd_height import integer_points_in_polytope - sage: m = matrix([[1.2,3.7,0.2],[-5.3,-.43,3],[1.2,4.7,-2.1]]) + sage: m = matrix([[1.2,3.7,0.2], [-5.3,-.43,3], [1.2,4.7,-2.1]]) sage: r = 2.2 - sage: L = integer_points_in_polytope(m,r) + sage: L = integer_points_in_polytope(m, r) sage: len(L) 4143 If ``interval_radius`` is 0, the output should include only the zero tuple:: sage: from sage.rings.number_field.bdd_height import integer_points_in_polytope - sage: m = matrix([[1,2,3,7],[4,5,6,2],[7,8,9,3],[0,3,4,5]]) - sage: integer_points_in_polytope(m,0) + sage: m = matrix([[1,2,3,7], [4,5,6,2], [7,8,9,3], [0,3,4,5]]) + sage: integer_points_in_polytope(m, 0) [(0, 0, 0, 0)] """ T = matrix @@ -350,15 +351,15 @@ def bdd_height(K, height_bound, tolerance=1e-2, precision=53): multiplicative height at most ``height_bound``. The function can only be called for number fields `K` with positive unit - rank. An error will occur if `K` is `QQ` or an imaginary quadratic field. + rank. An error will occur if `K` is `\QQ` or an imaginary quadratic field. - This algorithm computes 2 lists: L containing elements x in `K` such that - H_k(x) <= B, and a list L' containing elements x in `K` that, due to + This algorithm computes 2 lists: `L`, containing elements `x` in `K` such that + `H_k(x) \leq B`, and a list `L'` containing elements `x` in `K` that, due to floating point issues, may be slightly larger then the bound. This can be controlled by lowering the tolerance. - In current implementation both lists (L,L') are merged and returned in + In current implementation both lists `(L,L')` are merged and returned in form of iterator. ALGORITHM: @@ -376,7 +377,7 @@ def bdd_height(K, height_bound, tolerance=1e-2, precision=53): OUTPUT: - - an iterator of number field elements + an iterator of number field elements EXAMPLES: @@ -384,35 +385,35 @@ def bdd_height(K, height_bound, tolerance=1e-2, precision=53): sage: from sage.rings.number_field.bdd_height import bdd_height sage: K. = NumberField(x^5 - x + 7) - sage: list(bdd_height(K,-3)) + sage: list(bdd_height(K, -3)) [] The only nonzero elements of height 1 are the roots of unity:: sage: from sage.rings.number_field.bdd_height import bdd_height sage: K. = QuadraticField(3) - sage: list(bdd_height(K,1)) + sage: list(bdd_height(K, 1)) [0, -1, 1] :: sage: from sage.rings.number_field.bdd_height import bdd_height sage: K. = QuadraticField(36865) - sage: len(list(bdd_height(K,101))) # long time (4 s) + sage: len(list(bdd_height(K, 101))) # long time (4 s) 131 :: sage: from sage.rings.number_field.bdd_height import bdd_height sage: K. = NumberField(x^6 + 2) - sage: len(list(bdd_height(K,60))) # long time (5 s) + sage: len(list(bdd_height(K, 60))) # long time (5 s) 1899 :: sage: from sage.rings.number_field.bdd_height import bdd_height sage: K. = NumberField(x^4 - x^3 - 3*x^2 + x + 1) - sage: len(list(bdd_height(K,10))) + sage: len(list(bdd_height(K, 10))) 99 TESTS: @@ -454,14 +455,14 @@ def rational_in(x, y): def delta_approximation(x, delta): r""" - Compute a rational number in range `(x-delta, x+delta)` + Compute a rational number in range `(x-\delta, x+\delta)` """ return rational_in(x - delta, x + delta) def vector_delta_approximation(v, delta): r""" Compute a rational vector `w=(w_1, ..., w_n)` - such that `|v_i-w_i|=QuadraticField(-23) - sage: OK=K.ring_of_integers() - sage: C=OK.class_group() - sage: P2a,P2b=[P for P,e in (2*OK).factor()] - sage: c = C(P2a); c - Fractional ideal class (2, 1/2*w - 1/2) - sage: c.gens() - (2, 1/2*w - 1/2) + sage: K. = QuadraticField(-23) + sage: OK = K.ring_of_integers() + sage: C = OK.class_group() + sage: P2a, P2b = [P for P, e in (2*OK).factor()] + sage: c = C(P2a); c + Fractional ideal class (2, 1/2*w - 1/2) + sage: c.gens() + (2, 1/2*w - 1/2) """ def __init__(self, parent, element, ideal=None): """ - Returns the ideal class of this fractional ideal. + Return the ideal class of this fractional ideal. EXAMPLES:: @@ -108,7 +107,8 @@ def _mul_(self, other): EXAMPLES:: sage: G = NumberField(x^2 + 23,'a').class_group(); G - Class group of order 3 with structure C3 of Number Field in a with defining polynomial x^2 + 23 + Class group of order 3 with structure C3 of + Number Field in a with defining polynomial x^2 + 23 sage: I = G.0; I Fractional ideal class (2, 1/2*a - 1/2) sage: I*I # indirect doctest @@ -135,7 +135,8 @@ def _div_(self, other): EXAMPLES:: sage: G = NumberField(x^2 + 23,'a').class_group(); G - Class group of order 3 with structure C3 of Number Field in a with defining polynomial x^2 + 23 + Class group of order 3 with structure C3 of + Number Field in a with defining polynomial x^2 + 23 sage: I = G.0; I Fractional ideal class (2, 1/2*a - 1/2) sage: I*I # indirect doctest @@ -154,7 +155,7 @@ def __pow__(self, n): EXAMPLES:: sage: K. = NumberField(x^3 - 3*x + 8) - sage: C=K.class_group() + sage: C = K.class_group() sage: c = C(2, a) sage: c^2 Fractional ideal class (4, a) @@ -192,15 +193,15 @@ def inverse(self): def is_principal(self): r""" - Returns True iff this ideal class is the trivial (principal) class + Return ``True`` iff this ideal class is the trivial (principal) class. EXAMPLES:: - sage: K.=QuadraticField(-23) - sage: OK=K.ring_of_integers() - sage: C=OK.class_group() - sage: P2a,P2b=[P for P,e in (2*OK).factor()] - sage: c=C(P2a) + sage: K. = QuadraticField(-23) + sage: OK = K.ring_of_integers() + sage: C = OK.class_group() + sage: P2a, P2b = [P for P, e in (2*OK).factor()] + sage: c = C(P2a) sage: c.is_principal() False sage: (c^2).is_principal() @@ -218,8 +219,8 @@ def reduce(self): EXAMPLES:: sage: k. = NumberField(x^2 + 20072); G = k.class_group(); G - Class group of order 76 with structure C38 x C2 - of Number Field in a with defining polynomial x^2 + 20072 + Class group of order 76 with structure C38 x C2 of + Number Field in a with defining polynomial x^2 + 20072 sage: I = (G.0)^11; I Fractional ideal class (33, 1/2*a + 8) sage: J = G(I.ideal()^5); J @@ -237,11 +238,11 @@ def ideal(self): EXAMPLES:: - sage: K.=QuadraticField(-23) - sage: OK=K.ring_of_integers() - sage: C=OK.class_group() - sage: P2a,P2b=[P for P,e in (2*OK).factor()] - sage: c=C(P2a); c + sage: K. = QuadraticField(-23) + sage: OK = K.ring_of_integers() + sage: C = OK.class_group() + sage: P2a, P2b = [P for P, e in (2*OK).factor()] + sage: c = C(P2a); c Fractional ideal class (2, 1/2*w - 1/2) sage: c.ideal() Fractional ideal (2, 1/2*w - 1/2) @@ -254,31 +255,31 @@ def representative_prime(self, norm_bound=1000): INPUT: - ``norm_bound`` (positive integer) -- upper bound on the norm of primes tested. + - ``norm_bound`` -- (positive integer) upper bound on the norm of primes tested. EXAMPLES:: - sage: K. = NumberField(x^2+31) + sage: K. = NumberField(x^2 + 31) sage: K.class_number() 3 sage: Cl = K.class_group() sage: [c.representative_prime() for c in Cl] [Fractional ideal (3), - Fractional ideal (2, 1/2*a + 1/2), - Fractional ideal (2, 1/2*a - 1/2)] + Fractional ideal (2, 1/2*a + 1/2), + Fractional ideal (2, 1/2*a - 1/2)] - sage: K. = NumberField(x^2+223) + sage: K. = NumberField(x^2 + 223) sage: K.class_number() 7 sage: Cl = K.class_group() sage: [c.representative_prime() for c in Cl] [Fractional ideal (3), - Fractional ideal (2, 1/2*a + 1/2), - Fractional ideal (17, 1/2*a + 7/2), - Fractional ideal (7, 1/2*a - 1/2), - Fractional ideal (7, 1/2*a + 1/2), - Fractional ideal (17, 1/2*a + 27/2), - Fractional ideal (2, 1/2*a - 1/2)] + Fractional ideal (2, 1/2*a + 1/2), + Fractional ideal (17, 1/2*a + 7/2), + Fractional ideal (7, 1/2*a - 1/2), + Fractional ideal (7, 1/2*a + 1/2), + Fractional ideal (17, 1/2*a + 27/2), + Fractional ideal (2, 1/2*a - 1/2)] """ if self.value().is_prime(): return self.value() @@ -297,14 +298,14 @@ def representative_prime(self, norm_bound=1000): def gens(self): r""" Return generators for a representative ideal in this - (S-)ideal class. + (`S`-)ideal class. EXAMPLES:: - sage: K.=QuadraticField(-23) + sage: K. = QuadraticField(-23) sage: OK = K.ring_of_integers() sage: C = OK.class_group() - sage: P2a,P2b=[P for P,e in (2*OK).factor()] + sage: P2a, P2b = [P for P, e in (2*OK).factor()] sage: c = C(P2a); c Fractional ideal class (2, 1/2*w - 1/2) sage: c.gens() @@ -315,48 +316,47 @@ def gens(self): class SFractionalIdealClass(FractionalIdealClass): r""" - An S-fractional ideal class in a number field for a tuple of primes S. - - EXAMPLES:: + An `S`-fractional ideal class in a number field for a tuple `S` of primes. - sage: K. = QuadraticField(-14) - sage: I = K.ideal(2,a) - sage: S = (I,) - sage: CS = K.S_class_group(S) - sage: J = K.ideal(7,a) - sage: G = K.ideal(3,a+1) - sage: CS(I) - Trivial S-ideal class - sage: CS(J) - Trivial S-ideal class - sage: CS(G) - Fractional S-ideal class (3, a + 1) + EXAMPLES:: - EXAMPLES:: + sage: K. = QuadraticField(-14) + sage: I = K.ideal(2, a) + sage: S = (I,) + sage: CS = K.S_class_group(S) + sage: J = K.ideal(7, a) + sage: G = K.ideal(3, a + 1) + sage: CS(I) + Trivial S-ideal class + sage: CS(J) + Trivial S-ideal class + sage: CS(G) + Fractional S-ideal class (3, a + 1) - sage: K. = QuadraticField(-14) - sage: I = K.ideal(2,a) - sage: S = (I,) - sage: CS = K.S_class_group(S) - sage: J = K.ideal(7,a) - sage: G = K.ideal(3,a+1) - sage: CS(I).ideal() - Fractional ideal (2, a) - sage: CS(J).ideal() - Fractional ideal (7, a) - sage: CS(G).ideal() - Fractional ideal (3, a + 1) + :: + sage: K. = QuadraticField(-14) + sage: I = K.ideal(2, a) + sage: S = (I,) + sage: CS = K.S_class_group(S) + sage: J = K.ideal(7, a) + sage: G = K.ideal(3, a + 1) + sage: CS(I).ideal() + Fractional ideal (2, a) + sage: CS(J).ideal() + Fractional ideal (7, a) + sage: CS(G).ideal() + Fractional ideal (3, a + 1) - EXAMPLES:: + :: - sage: K. = QuadraticField(-14) - sage: I = K.ideal(2,a) - sage: S = (I,) - sage: CS = K.S_class_group(S) - sage: G = K.ideal(3,a+1) - sage: CS(G).inverse() - Fractional S-ideal class (3, a + 2) + sage: K. = QuadraticField(-14) + sage: I = K.ideal(2, a) + sage: S = (I,) + sage: CS = K.S_class_group(S) + sage: G = K.ideal(3, a + 1) + sage: CS(G).inverse() + Fractional S-ideal class (3, a + 2) TESTS:: @@ -376,7 +376,7 @@ class SFractionalIdealClass(FractionalIdealClass): def _repr_(self): r""" - Returns a string representation of the S-ideal class of this fractional ideal. + Return a string representation of the `S`-ideal class of this fractional ideal. EXAMPLES:: @@ -403,7 +403,8 @@ class ClassGroup(AbelianGroupWithValues_class): sage: K. = NumberField(x^2 + 23) sage: G = K.class_group(); G - Class group of order 3 with structure C3 of Number Field in a with defining polynomial x^2 + 23 + Class group of order 3 with structure C3 of + Number Field in a with defining polynomial x^2 + 23 sage: G.category() Category of finite enumerated commutative groups @@ -482,7 +483,7 @@ def _ideal_log(self, ideal): EXAMPLES:: - sage: K. = NumberField(x^2 + 23,'a') + sage: K. = NumberField(x^2 + 23, 'a') sage: G = K.class_group() sage: g = G.an_element() sage: G._ideal_log(g.ideal()) @@ -494,7 +495,7 @@ def _ideal_log(self, ideal): def gens_ideals(self): r""" - Return generating ideals for the (S-)class group. + Return generating ideals for the (`S`-)class group. This is an alias for :meth:`gens_values`. @@ -581,7 +582,7 @@ def _iter_inner(self, i0, k): def _repr_(self): r""" - Return string representation of self. + Return string representation of ``self``. EXAMPLES:: @@ -597,12 +598,13 @@ def _repr_(self): def number_field(self): r""" - Return the number field that this (S-)class group is attached to. + Return the number field that this (`S`-)class group is attached to. EXAMPLES:: sage: C = NumberField(x^2 + 23, 'w').class_group(); C - Class group of order 3 with structure C3 of Number Field in w with defining polynomial x^2 + 23 + Class group of order 3 with structure C3 of + Number Field in w with defining polynomial x^2 + 23 sage: C.number_field() Number Field in w with defining polynomial x^2 + 23 @@ -616,7 +618,7 @@ def number_field(self): class SClassGroup(ClassGroup): r""" - The S-class group of a number field. + The `S`-class group of a number field. EXAMPLES:: @@ -627,7 +629,8 @@ class SClassGroup(ClassGroup): sage: K. = QuadraticField(-974) sage: CS = K.S_class_group(K.primes_above(2)); CS - S-class group of order 18 with structure C6 x C3 of Number Field in a with defining polynomial x^2 + 974 with a = 31.20897306865447?*I + S-class group of order 18 with structure C6 x C3 of + Number Field in a with defining polynomial x^2 + 974 with a = 31.20897306865447?*I sage: CS.gen(0) # random Fractional S-ideal class (3, a + 2) sage: CS.gen(1) # random @@ -637,7 +640,7 @@ class SClassGroup(ClassGroup): def __init__(self, gens_orders, names, number_field, gens, S, proof=True): r""" - Create an S-class group. + Create an `S`-class group. EXAMPLES:: @@ -663,13 +666,15 @@ def S(self): EXAMPLES:: sage: K. = QuadraticField(-14) - sage: I = K.ideal(2,a) + sage: I = K.ideal(2, a) sage: S = (I,) sage: CS = K.S_class_group(S);CS - S-class group of order 2 with structure C2 of Number Field in a with defining polynomial x^2 + 14 with a = 3.741657386773942?*I + S-class group of order 2 with structure C2 of + Number Field in a with defining polynomial x^2 + 14 with a = 3.741657386773942?*I sage: T = tuple() sage: CT = K.S_class_group(T);CT - S-class group of order 4 with structure C4 of Number Field in a with defining polynomial x^2 + 14 with a = 3.741657386773942?*I + S-class group of order 4 with structure C4 of + Number Field in a with defining polynomial x^2 + 14 with a = 3.741657386773942?*I sage: CS.S() (Fractional ideal (2, a),) sage: CT.S() diff --git a/src/sage/rings/number_field/galois_group.py b/src/sage/rings/number_field/galois_group.py index 1bf6189b7d9..7dbb4d24c91 100644 --- a/src/sage/rings/number_field/galois_group.py +++ b/src/sage/rings/number_field/galois_group.py @@ -49,7 +49,8 @@ class GaloisGroup_v1(SageObject): sage: G = GaloisGroup_v1(K.absolute_polynomial().galois_group(pari_group=True), K); G ...DeprecationWarning: GaloisGroup_v1 is deprecated; please use GaloisGroup_v2 See https://github.com/sagemath/sage/issues/28782 for details. - Galois group PARI group [6, -1, 2, "S3"] of degree 3 of the Number Field in a with defining polynomial x^3 - 2 with a = 1.259921049894873? + Galois group PARI group [6, -1, 2, "S3"] of degree 3 of the + Number Field in a with defining polynomial x^3 - 2 with a = 1.259921049894873? sage: G.order() 6 sage: G.group() @@ -69,7 +70,8 @@ def __init__(self, group, number_field): sage: GaloisGroup_v1(K.absolute_polynomial().galois_group(pari_group=True), K) ...DeprecationWarning: GaloisGroup_v1 is deprecated; please use GaloisGroup_v2 See https://github.com/sagemath/sage/issues/28782 for details. - Galois group PARI group [4, 1, 2, "E(4) = 2[x]2"] of degree 4 of the Number Field in a0 with defining polynomial x^2 + 1 over its base field + Galois group PARI group [4, 1, 2, "E(4) = 2[x]2"] of degree 4 of the + Number Field in a0 with defining polynomial x^2 + 1 over its base field """ deprecation(28782, "GaloisGroup_v1 is deprecated; please use GaloisGroup_v2") self.__group = group @@ -178,7 +180,8 @@ def order(self): sage: G = GaloisGroup_v1(K.absolute_polynomial().galois_group(pari_group=True), K); G ...DeprecationWarning: GaloisGroup_v1 is deprecated; please use GaloisGroup_v2 See https://github.com/sagemath/sage/issues/28782 for details. - Galois group PARI group [20, -1, 3, "F(5) = 5:4"] of degree 5 of the Number Field in theta_1 with defining polynomial x^5 + 2 + Galois group PARI group [20, -1, 3, "F(5) = 5:4"] of degree 5 of the + Number Field in theta_1 with defining polynomial x^5 + 2 sage: G.order() 20 """ @@ -195,7 +198,8 @@ def number_field(self): sage: G = GaloisGroup_v1(K.absolute_polynomial().galois_group(pari_group=True), K); G ...DeprecationWarning: GaloisGroup_v1 is deprecated; please use GaloisGroup_v2 See https://github.com/sagemath/sage/issues/28782 for details. - Galois group PARI group [12, -1, 3, "D(6) = S(3)[x]2"] of degree 6 of the Number Field in t with defining polynomial x^6 + 2 + Galois group PARI group [12, -1, 3, "D(6) = S(3)[x]2"] of degree 6 of the + Number Field in t with defining polynomial x^6 + 2 sage: G.number_field() Number Field in t with defining polynomial x^6 + 2 """ @@ -208,10 +212,10 @@ class GaloisGroup_v2(GaloisGroup_perm): .. NOTE:: - We define the Galois group of a non-normal field K to be the - Galois group of its Galois closure L, and elements are stored as - permutations of the roots of the defining polynomial of L, *not* as - permutations of the roots (in L) of the defining polynomial of K. The + We define the Galois group of a non-normal field `K` to be the + Galois group of its Galois closure `L`, and elements are stored as + permutations of the roots of the defining polynomial of `L`, *not* as + permutations of the roots (in `L`) of the defining polynomial of `K`. The latter would probably be preferable, but is harder to implement. Thus the permutation group that is returned is always simply-transitive. @@ -222,7 +226,8 @@ class GaloisGroup_v2(GaloisGroup_perm): sage: G = NumberField(x^3 - x - 1, 'a').galois_closure('b').galois_group() sage: G.subgroup([G([(1,2,3),(4,5,6)])]) - Subgroup generated by [(1,2,3)(4,5,6)] of (Galois group 6T2 ([3]2) with order 6 of x^6 - 6*x^4 + 9*x^2 + 23) + Subgroup generated by [(1,2,3)(4,5,6)] of + (Galois group 6T2 ([3]2) with order 6 of x^6 - 6*x^4 + 9*x^2 + 23) Subgroups can be specified using generators (:trac:`26816`):: @@ -314,7 +319,7 @@ def _pol_galgp(self, algorithm=None): def group(self): """ - While GaloisGroup_v1 is being deprecated, this provides public access to the Pari/GAP group + While :class:`GaloisGroup_v1` is being deprecated, this provides public access to the PARI/GAP group in order to keep all aspects of that API. EXAMPLES:: @@ -325,7 +330,8 @@ def group(self): ...DeprecationWarning: the different Galois types have been merged into one class See https://github.com/sagemath/sage/issues/28782 for details. sage: G.group() - ...DeprecationWarning: the group method is deprecated; you can use _pol_galgp if you really need it + ...DeprecationWarning: the group method is deprecated; + you can use _pol_galgp if you really need it See https://github.com/sagemath/sage/issues/28782 for details. PARI group [6, -1, 2, "S3"] of degree 3 """ @@ -379,7 +385,7 @@ def easy_order(self, algorithm=None): @cached_method(key=_alg_key) def transitive_number(self, algorithm=None, recompute=False): """ - Regardless of the value of ``gc_numbering``, this gives the transitive number + Regardless of the value of ``gc_numbering``, give the transitive number for the action on the roots of the defining polynomial of the original number field, not the Galois closure. @@ -413,7 +419,7 @@ def transitive_number(self, algorithm=None, recompute=False): def pari_label(self): """ - Return the label assigned by Pari for this Galois group, an attempt at giving a human readable description of the group. + Return the label assigned by PARI for this Galois group, an attempt at giving a human readable description of the group. EXAMPLES:: @@ -430,7 +436,7 @@ def pari_label(self): @cached_method def signature(self): """ - Return 1 if contained in the alternating group, -1 otherwise. + Return `1` if contained in the alternating group, `-1` otherwise. EXAMPLES:: @@ -455,7 +461,7 @@ def signature(self): @lazy_attribute def _gcdata(self): """ - Return the galois closure, together with the embedding of the top field into it + Return the Galois closure, together with the embedding of the top field into it EXAMPLES:: @@ -506,7 +512,7 @@ def _gcdata(self): @lazy_attribute def _pari_data(self): """ - Return the corresponding Pari Galois group structure. + Return the corresponding PARI Galois group structure. EXAMPLES:: @@ -548,7 +554,7 @@ def _elts(self): @lazy_attribute def _gens(self): """ - Computes the generators as permutations. + Compute the generators as permutations. EXAMPLES:: @@ -641,7 +647,7 @@ def _element_constructor_(self, x, check=True): def is_galois(self): r""" - Whether the underlying number field is Galois + Whether the underlying number field is Galois. EXAMPLES:: @@ -697,7 +703,7 @@ def number_field(self): def list(self): r""" - List of the elements of self. + List of the elements of ``self``. EXAMPLES:: @@ -708,12 +714,12 @@ def list(self): def unrank(self, i): r""" - Return the ``i``-th element of ``self``. + Return the `i`-th element of ``self``. INPUT: - - ``i`` -- integer between ``0`` and ``n-1`` where - ``n`` is the cardinality of this set + - ``i`` -- integer between `0` and `n-1` where + `n` is the cardinality of this set EXAMPLES:: @@ -777,22 +783,23 @@ def _ramgroups(self, P): def decomposition_group(self, P): r""" - Decomposition group of a prime ideal P, i.e. the subgroup of elements - that map P to itself. This is the same as the Galois group of the - extension of local fields obtained by completing at P. + Decomposition group of a prime ideal `P`, i.e., the subgroup of elements + that map `P` to itself. This is the same as the Galois group of the + extension of local fields obtained by completing at `P`. - This function will raise an error if P is not prime or the given number + This function will raise an error if `P` is not prime or the given number field is not Galois. - P can also be an infinite prime, i.e. an embedding into `\RR` or `\CC`. + `P` can also be an infinite prime, i.e., an embedding into `\RR` or `\CC`. EXAMPLES:: - sage: K. = NumberField(x^4 - 2*x^2 + 2,'b').galois_closure() + sage: K. = NumberField(x^4 - 2*x^2 + 2, 'b').galois_closure() sage: P = K.ideal([17, a^2]) sage: G = K.galois_group() sage: G.decomposition_group(P) - Subgroup generated by [(1,8)(2,7)(3,6)(4,5)] of (Galois group 8T4 ([4]2) with order 8 of x^8 - 20*x^6 + 104*x^4 - 40*x^2 + 1156) + Subgroup generated by [(1,8)(2,7)(3,6)(4,5)] of + (Galois group 8T4 ([4]2) with order 8 of x^8 - 20*x^6 + 104*x^4 - 40*x^2 + 1156) sage: G.decomposition_group(P^2) Traceback (most recent call last): ... @@ -804,7 +811,7 @@ def decomposition_group(self, P): An example with an infinite place:: - sage: L. = NumberField(x^3 - 2,'a').galois_closure(); G=L.galois_group() + sage: L. = NumberField(x^3 - 2,'a').galois_closure(); G = L.galois_group() sage: x = L.places()[0] sage: G.decomposition_group(x).order() 2 @@ -822,8 +829,8 @@ def decomposition_group(self, P): def complex_conjugation(self, P=None): """ - Return the unique element of self corresponding to complex conjugation, - for a specified embedding P into the complex numbers. If P is not + Return the unique element of ``self`` corresponding to complex conjugation, + for a specified embedding `P` into the complex numbers. If `P` is not specified, use the "standard" embedding, whenever that is well-defined. EXAMPLES:: @@ -838,7 +845,7 @@ def complex_conjugation(self, P=None): An example where the field is not CM, so complex conjugation really depends on the choice of embedding:: - sage: L = NumberField(x^6 + 40*x^3 + 1372,'a') + sage: L = NumberField(x^6 + 40*x^3 + 1372, 'a') sage: G = L.galois_group() sage: [G.complex_conjugation(x) for x in L.places()] [(1,3)(2,6)(4,5), (1,5)(2,4)(3,6), (1,2)(3,4)(5,6)] @@ -865,17 +872,18 @@ def complex_conjugation(self, P=None): def ramification_group(self, P, v): """ - Return the vth ramification group of self for the prime P, i.e. the set - of elements s of self such that s acts trivially modulo P^(v+1). This + Return the `v`-th ramification group of ``self`` for the prime `P`, i.e., the set + of elements `s` of ``self`` such that `s` acts trivially modulo `P^{(v+1)}`. This is only defined for Galois fields. EXAMPLES:: - sage: K. = NumberField(x^3 - 3,'a').galois_closure() + sage: K. = NumberField(x^3 - 3, 'a').galois_closure() sage: G=K.galois_group() sage: P = K.primes_above(3)[0] sage: G.ramification_group(P, 3) - Subgroup generated by [(1,2,4)(3,5,6)] of (Galois group 6T2 ([3]2) with order 6 of x^6 + 243) + Subgroup generated by [(1,2,4)(3,5,6)] of + (Galois group 6T2 ([3]2) with order 6 of x^6 + 243) sage: G.ramification_group(P, 5) Subgroup generated by [()] of (Galois group 6T2 ([3]2) with order 6 of x^6 + 243) """ @@ -891,12 +899,12 @@ def ramification_group(self, P, v): def inertia_group(self, P): """ - Return the inertia group of the prime P, i.e. the group of elements acting - trivially modulo P. This is just the 0th ramification group of P. + Return the inertia group of the prime `P`, i.e., the group of elements acting + trivially modulo `P`. This is just the 0th ramification group of `P`. EXAMPLES:: - sage: K. = NumberField(x^2 - 3,'a') + sage: K. = NumberField(x^2 - 3, 'a') sage: G = K.galois_group() sage: G.inertia_group(K.primes_above(2)[0]) Subgroup generated by [(1,2)] of (Galois group 2T1 (S2) with order 2 of x^2 - 3) @@ -909,8 +917,8 @@ def inertia_group(self, P): def ramification_breaks(self, P): r""" - Return the set of ramification breaks of the prime ideal P, i.e. the - set of indices i such that the ramification group `G_{i+1} \ne G_{i}`. + Return the set of ramification breaks of the prime ideal `P`, i.e., the + set of indices `i` such that the ramification group `G_{i+1} \ne G_{i}`. This is only defined for Galois fields. EXAMPLES:: @@ -920,7 +928,9 @@ def ramification_breaks(self, P): sage: P = K.primes_above(2)[0] sage: G.ramification_breaks(P) {1, 3, 5} - sage: min( [ G.ramification_group(P, i).order() / G.ramification_group(P, i+1).order() for i in G.ramification_breaks(P)] ) + sage: min(G.ramification_group(P, i).order() + ....: / G.ramification_group(P, i + 1).order() + ....: for i in G.ramification_breaks(P)) 2 """ if not self.is_galois(): @@ -934,17 +944,18 @@ def ramification_breaks(self, P): def artin_symbol(self, P): r""" Return the Artin symbol `\left(\frac{K / - \QQ}{\mathfrak{P}}\right)`, where K is the number field of self, + \QQ}{\mathfrak{P}}\right)`, where `K` is the number field of ``self``, and `\mathfrak{P}` is an unramified prime ideal. This is the unique - element s of the decomposition group of `\mathfrak{P}` such that `s(x) = x^p \bmod - \mathfrak{P}`, where p is the residue characteristic of `\mathfrak{P}`. + element `s` of the decomposition group of `\mathfrak{P}` such that `s(x) = x^p \bmod + \mathfrak{P}`, where `p` is the residue characteristic of `\mathfrak{P}`. EXAMPLES:: sage: K. = NumberField(x^4 - 2*x^2 + 2, 'a').galois_closure() sage: G = K.galois_group() sage: [G.artin_symbol(P) for P in K.primes_above(7)] - [(1,4)(2,3)(5,8)(6,7), (1,4)(2,3)(5,8)(6,7), (1,5)(2,6)(3,7)(4,8), (1,5)(2,6)(3,7)(4,8)] + [(1,4)(2,3)(5,8)(6,7), (1,4)(2,3)(5,8)(6,7), + (1,5)(2,6)(3,7)(4,8), (1,5)(2,6)(3,7)(4,8)] sage: G.artin_symbol(17) Traceback (most recent call last): ... @@ -990,7 +1001,7 @@ class GaloisGroup_subgroup(GaloisSubgroup_perm): - ``category`` -- the category for this object - - ``canonicalize`` -- if true, sorts and removes duplicates + - ``canonicalize`` -- if ``True``, sorts and removes duplicates - ``check`` -- whether to check that generators actually lie in the ambient group @@ -999,9 +1010,10 @@ class GaloisGroup_subgroup(GaloisSubgroup_perm): sage: from sage.rings.number_field.galois_group import GaloisGroup_subgroup sage: G = NumberField(x^3 - x - 1, 'a').galois_closure('b').galois_group() sage: GaloisGroup_subgroup( G, [G([(1,2,3),(4,5,6)])]) - Subgroup generated by [(1,2,3)(4,5,6)] of (Galois group 6T2 ([3]2) with order 6 of x^6 - 6*x^4 + 9*x^2 + 23) + Subgroup generated by [(1,2,3)(4,5,6)] of + (Galois group 6T2 ([3]2) with order 6 of x^6 - 6*x^4 + 9*x^2 + 23) - sage: K. = NumberField(x^6-3*x^2-1) + sage: K. = NumberField(x^6 - 3*x^2 - 1) sage: L. = K.galois_closure() sage: G = L.galois_group() sage: P = L.primes_above(3)[0] @@ -1012,7 +1024,8 @@ class GaloisGroup_subgroup(GaloisSubgroup_perm): sage: G = NumberField(x^3 - x - 1, 'a').galois_closure('b').galois_group() sage: H = G.subgroup([G([(1,2,3),(4,5,6)])]) sage: H - Subgroup generated by [(1,2,3)(4,5,6)] of (Galois group 6T2 ([3]2) with order 6 of x^6 - 6*x^4 + 9*x^2 + 23) + Subgroup generated by [(1,2,3)(4,5,6)] of + (Galois group 6T2 ([3]2) with order 6 of x^6 - 6*x^4 + 9*x^2 + 23) TESTS: @@ -1030,7 +1043,7 @@ class GaloisGroup_subgroup(GaloisSubgroup_perm): @lazy_attribute def _pari_data(self): """ - Access to Pari information for the ambient Galois group. + Access to PARI information for the ambient Galois group. EXAMPLES:: @@ -1052,7 +1065,7 @@ def fixed_field(self, name=None, polred=None, threshold=None): - ``name`` -- a variable name for the new field. - ``polred`` -- whether to optimize the generator of the newly created field - for a simpler polynomial, using pari's polredbest. + for a simpler polynomial, using PARI's :pari:`polredbest`. Defaults to ``True`` when the degree of the fixed field is at most 8. - ``threshold`` -- positive number; polred only performed if the cost is at most this threshold @@ -1077,28 +1090,32 @@ def fixed_field(self, name=None, polred=None, threshold=None): sage: sigma, tau = G.gens() sage: H = G.subgroup([tau]) sage: H.fixed_field(polred=False) - (Number Field in a0 with defining polynomial x^2 + 84375 with a0 = 5*ac^5 + 25*ac^3, + (Number Field in a0 with defining polynomial x^2 + 84375 + with a0 = 5*ac^5 + 25*ac^3, Ring morphism: - From: Number Field in a0 with defining polynomial x^2 + 84375 with a0 = 5*ac^5 + 25*ac^3 + From: Number Field in a0 with defining polynomial x^2 + 84375 + with a0 = 5*ac^5 + 25*ac^3 To: Number Field in ac with defining polynomial x^10 + 10*x^8 + 25*x^6 + 3375 Defn: a0 |--> 5*ac^5 + 25*ac^3) sage: H.fixed_field(polred=True) - (Number Field in a0 with defining polynomial x^2 - x + 4 with a0 = -1/30*ac^5 - 1/6*ac^3 + 1/2, + (Number Field in a0 with defining polynomial x^2 - x + 4 + with a0 = -1/30*ac^5 - 1/6*ac^3 + 1/2, Ring morphism: - From: Number Field in a0 with defining polynomial x^2 - x + 4 with a0 = -1/30*ac^5 - 1/6*ac^3 + 1/2 + From: Number Field in a0 with defining polynomial x^2 - x + 4 + with a0 = -1/30*ac^5 - 1/6*ac^3 + 1/2 To: Number Field in ac with defining polynomial x^10 + 10*x^8 + 25*x^6 + 3375 Defn: a0 |--> -1/30*ac^5 - 1/6*ac^3 + 1/2) sage: G.splitting_field() Number Field in ac with defining polynomial x^10 + 10*x^8 + 25*x^6 + 3375 - An embedding is returned also if the subgroup is trivial (:trac:`26817`):: sage: H = G.subgroup([]) sage: H.fixed_field() (Number Field in ac with defining polynomial x^10 + 10*x^8 + 25*x^6 + 3375, - Identity endomorphism of Number Field in ac with defining polynomial x^10 + 10*x^8 + 25*x^6 + 3375) + Identity endomorphism of + Number Field in ac with defining polynomial x^10 + 10*x^8 + 25*x^6 + 3375) """ G = self._ambient_group L = G._galois_closure @@ -1151,14 +1168,15 @@ class GaloisGroupElement(PermutationGroupElement): @cached_method def as_hom(self): r""" - Return the homomorphism L -> L corresponding to self, where L is the + Return the homomorphism `L \to L` corresponding to ``self``, where `L` is the Galois closure of the ambient number field. EXAMPLES:: sage: G = QuadraticField(-7,'w').galois_group() sage: G[1].as_hom() - Ring endomorphism of Number Field in w with defining polynomial x^2 + 7 with w = 2.645751311064591?*I + Ring endomorphism of Number Field in w with defining polynomial x^2 + 7 + with w = 2.645751311064591?*I Defn: w |--> -w TESTS: @@ -1206,8 +1224,8 @@ def __call__(self, x): def ramification_degree(self, P): """ - Return the greatest value of v such that s acts trivially modulo P^v. - Should only be used if P is prime and s is in the decomposition group of P. + Return the greatest value of `v` such that `s` acts trivially modulo `P^v`. + Should only be used if `P` is prime and `s` is in the decomposition group of `P`. EXAMPLES:: diff --git a/src/sage/rings/number_field/homset.py b/src/sage/rings/number_field/homset.py index 6353353afe1..ac3726c0896 100644 --- a/src/sage/rings/number_field/homset.py +++ b/src/sage/rings/number_field/homset.py @@ -177,7 +177,7 @@ def order(self): sage: End(k).order() 1 - sage: K. = NumberField( [x^3 + 2, x^2 + x + 1] ) + sage: K. = NumberField([x^3 + 2, x^2 + x + 1]) sage: End(K).order() 6 """ @@ -188,7 +188,7 @@ def order(self): @cached_method def list(self): """ - Return a list of all the elements of self. + Return a list of all the elements of ``self``. EXAMPLES:: @@ -261,13 +261,14 @@ class RelativeNumberFieldHomset(NumberFieldHomset): sage: L. = CyclotomicField(3).extension(x^3 - 2) sage: phi = L.hom([cuberoot2 * zeta3]); phi - Relative number field endomorphism of Number Field in cuberoot2 with defining polynomial x^3 - 2 over its base field + Relative number field endomorphism of + Number Field in cuberoot2 with defining polynomial x^3 - 2 over its base field Defn: cuberoot2 |--> zeta3*cuberoot2 zeta3 |--> zeta3 sage: phi(cuberoot2 + zeta3) zeta3*cuberoot2 + zeta3 - In fact, this phi is a generator for the Kummer Galois group of this + In fact, this ``phi`` is a generator for the Kummer Galois group of this cyclic extension:: sage: phi(phi(cuberoot2 + zeta3)) @@ -422,7 +423,7 @@ def _from_im(self, im_gen, base_map, check=True): @cached_method def default_base_hom(self): r""" - Pick an embedding of the base field of self into the codomain of this + Pick an embedding of the base field of ``self`` into the codomain of this homset. This is done in an essentially arbitrary way. EXAMPLES:: @@ -468,7 +469,7 @@ def default_base_hom(self): @cached_method def list(self): """ - Return a list of all the elements of self (for which the domain + Return a list of all the elements of ``self`` (for which the domain is a relative number field). EXAMPLES:: @@ -476,11 +477,13 @@ def list(self): sage: K. = NumberField([x^2 + x + 1, x^3 + 2]) sage: End(K).list() [ - Relative number field endomorphism of Number Field in a with defining polynomial x^2 + x + 1 over its base field + Relative number field endomorphism of + Number Field in a with defining polynomial x^2 + x + 1 over its base field Defn: a |--> a b |--> b, ... - Relative number field endomorphism of Number Field in a with defining polynomial x^2 + x + 1 over its base field + Relative number field endomorphism of + Number Field in a with defining polynomial x^2 + x + 1 over its base field Defn: a |--> a b |--> -b*a - b ] @@ -574,7 +577,7 @@ def _element_constructor_(self, x, check=True): @cached_method def list(self): """ - Return a list of all the elements of self (for which the domain + Return a list of all the elements of ``self`` (for which the domain is a cyclotomic field). EXAMPLES:: diff --git a/src/sage/rings/number_field/maps.py b/src/sage/rings/number_field/maps.py index 68d03c73af3..7a6d0fcbb2f 100644 --- a/src/sage/rings/number_field/maps.py +++ b/src/sage/rings/number_field/maps.py @@ -11,12 +11,16 @@ sage: from_K, to_K = K.structure() sage: from_K Isomorphism map: - From: Number Field in a with defining polynomial x^6 - 3*x^5 + 6*x^4 - 11*x^3 + 12*x^2 + 3*x + 1 - To: Number Field in cuberoot2 with defining polynomial x^3 - 2 over its base field + From: Number Field in a with defining polynomial + x^6 - 3*x^5 + 6*x^4 - 11*x^3 + 12*x^2 + 3*x + 1 + To: Number Field in cuberoot2 with defining polynomial + x^3 - 2 over its base field sage: to_K Isomorphism map: - From: Number Field in cuberoot2 with defining polynomial x^3 - 2 over its base field - To: Number Field in a with defining polynomial x^6 - 3*x^5 + 6*x^4 - 11*x^3 + 12*x^2 + 3*x + 1 + From: Number Field in cuberoot2 with defining polynomial + x^3 - 2 over its base field + To: Number Field in a with defining polynomial + x^6 - 3*x^5 + 6*x^4 - 11*x^3 + 12*x^2 + 3*x + 1 """ #***************************************************************************** @@ -118,9 +122,11 @@ class MapVectorSpaceToNumberField(NumberFieldIsomorphism): (True, True) sage: fr.domain(), to.codomain() - (Vector space of dimension 4 over Rational Field, Vector space of dimension 4 over Rational Field) + (Vector space of dimension 4 over Rational Field, + Vector space of dimension 4 over Rational Field) sage: to.domain(), fr.codomain() - (Number Field in a with defining polynomial x^4 + 3*x + 1, Number Field in a with defining polynomial x^4 + 3*x + 1) + (Number Field in a with defining polynomial x^4 + 3*x + 1, + Number Field in a with defining polynomial x^4 + 3*x + 1) sage: fr * to Composite map: From: Number Field in a with defining polynomial x^4 + 3*x + 1 @@ -243,8 +249,10 @@ class MapRelativeVectorSpaceToRelativeNumberField(NumberFieldIsomorphism): Vector space of dimension 2 over Number Field in b0 with defining polynomial x^2 + 1 sage: fr Isomorphism map: - From: Vector space of dimension 2 over Number Field in b0 with defining polynomial x^2 + 1 - To: Number Field in a with defining polynomial x^2 - b0*x + 1 over its base field + From: Vector space of dimension 2 + over Number Field in b0 with defining polynomial x^2 + 1 + To: Number Field in a + with defining polynomial x^2 - b0*x + 1 over its base field sage: type(fr) @@ -380,7 +388,8 @@ class NameChangeMap(NumberFieldIsomorphism): From: Number Field in a with defining polynomial x^2 - 3 To: Number Field in b with defining polynomial x^2 - 3 sage: type(from_L), type(to_L) - (, ) + (, + ) """ def __init__(self, K, L): r""" @@ -391,7 +400,8 @@ def __init__(self, K, L): sage: L.structure() (Isomorphism given by variable name change map: From: Number Field in c with defining polynomial x^2 - 3 over its base field - To: Number Field in a with defining polynomial x^2 - 3 over its base field, Isomorphism given by variable name change map: + To: Number Field in a with defining polynomial x^2 - 3 over its base field, + Isomorphism given by variable name change map: From: Number Field in a with defining polynomial x^2 - 3 over its base field To: Number Field in c with defining polynomial x^2 - 3 over its base field) """ diff --git a/src/sage/rings/number_field/morphism.py b/src/sage/rings/number_field/morphism.py index 174252dad61..946eb529556 100644 --- a/src/sage/rings/number_field/morphism.py +++ b/src/sage/rings/number_field/morphism.py @@ -86,17 +86,17 @@ def __invert__(self): def preimage(self, y): r""" - Computes a preimage of `y` in the domain, provided one exists. - Raises a ValueError if `y` has no preimage. + Compute a preimage of `y` in the domain, provided one exists. + Raises a :class:`ValueError` if `y` has no preimage. INPUT: - - `y` -- an element of the codomain of self. + - ``y`` -- an element of the codomain of ``self``. OUTPUT: Returns the preimage of `y` in the domain, if one exists. - Raises a ValueError if `y` has no preimage. + Raises a :class:`ValueError` if `y` has no preimage. EXAMPLES:: @@ -113,9 +113,9 @@ def preimage(self, y): :: sage: F. = QuadraticField(23) - sage: G. = F.extension(x^3+5) + sage: G. = F.extension(x^3 + 5) sage: f = F.embeddings(G)[0] - sage: f.preimage(a^3+2*b+3) + sage: f.preimage(a^3 + 2*b + 3) 2*b - 2 """ # Throughout this method I am using the convention that self is a homomorphism from the number field K to the number field L @@ -155,7 +155,8 @@ def __init__(self, parent, abs_hom): sage: K. = NumberField( [x^3 + 2, x^2 + x + 1] ) sage: f = K.hom(-a*b - a, K); f - Relative number field endomorphism of Number Field in a with defining polynomial x^3 + 2 over its base field + Relative number field endomorphism of + Number Field in a with defining polynomial x^3 + 2 over its base field Defn: a |--> (-b - 1)*a b |--> b sage: type(f) @@ -174,10 +175,11 @@ def abs_hom(self): EXAMPLES:: - sage: K. = NumberField( [x^3 + 2, x^2 + x + 1] ) + sage: K. = NumberField([x^3 + 2, x^2 + x + 1]) sage: K.hom(a, K).abs_hom() Ring morphism: - From: Number Field in a with defining polynomial x^6 - 3*x^5 + 6*x^4 - 3*x^3 - 9*x + 9 + From: Number Field in a with defining polynomial + x^6 - 3*x^5 + 6*x^4 - 3*x^3 - 9*x + 9 To: Number Field in a with defining polynomial x^3 + 2 over its base field Defn: a |--> a - b """ @@ -202,7 +204,7 @@ def im_gens(self): EXAMPLES:: - sage: K. = NumberField( [x^3 + 2, x^2 + x + 1] ) + sage: K. = NumberField([x^3 + 2, x^2 + x + 1]) sage: K.hom(a, K).im_gens() [a, b] """ @@ -229,7 +231,7 @@ def _repr_defn(self): EXAMPLES:: - sage: K. = NumberField( [x^3 + 2, x^2 + x + 1] ) + sage: K. = NumberField([x^3 + 2, x^2 + x + 1]) sage: K.hom(a, K)._repr_defn() 'a |--> a\nb |--> b' """ @@ -248,7 +250,7 @@ def _call_(self, x): EXAMPLES:: - sage: K. = NumberField( [x^3 + 2, x^2 + x + 1] ) + sage: K. = NumberField([x^3 + 2, x^2 + x + 1]) sage: K.hom(a*b, K)(17 + 3*a + 2*b) # indirect doctest 3*b*a + 2*b + 17 """ diff --git a/src/sage/rings/number_field/number_field.py b/src/sage/rings/number_field/number_field.py index 1627b841c30..a7468b88aba 100644 --- a/src/sage/rings/number_field/number_field.py +++ b/src/sage/rings/number_field/number_field.py @@ -208,7 +208,7 @@ def proof_flag(t): """ Used for easily determining the correct proof flag to use. - Return t if t is not ``None``, otherwise return the system-wide + Return ``t`` if ``t`` is not ``None``, otherwise return the system-wide proof-flag for number fields (default: ``True``). EXAMPLES:: @@ -262,30 +262,30 @@ def NumberField(polynomial, name=None, check=True, names=None, embedding=None, INPUT: - - ``polynomial`` - a polynomial over `\QQ` or a number field, or a list - of such polynomials. - - ``names`` (or ``name``) - a string or a list of strings, the names of - the generators - - ``check`` - a boolean (default: ``True``); do type checking and - irreducibility checking. - - ``embedding`` - ``None``, an element, or a list of elements, the - images of the generators in an ambient field (default: ``None``) - - ``latex_names`` (or ``latex_name``) - ``None``, a string, or a - list of strings (default: ``None``), how the generators are printed - for latex output - - ``assume_disc_small`` -- a boolean (default: ``False``); if ``True``, - assume that no square of a prime greater than PARI's primelimit - (which should be 500000); only applies for absolute fields at - present. - - ``maximize_at_primes`` -- ``None`` or a list of primes (default: - ``None``); if not ``None``, then the maximal order is computed by - maximizing only at the primes in this list, which completely avoids - having to factor the discriminant, but of course can lead to wrong - results; only applies for absolute fields at present. - - ``structure`` -- ``None``, a list or an instance of - :class:`structure.NumberFieldStructure` (default: ``None``), - internally used to pass in additional structural information, e.g., - about the field from which this field is created as a subfield. + - ``polynomial`` -- a polynomial over `\QQ` or a number field, or a list + of such polynomials. + - ``names`` (or ``name``) - a string or a list of strings, the names of + the generators + - ``check`` -- a boolean (default: ``True``); do type checking and + irreducibility checking. + - ``embedding`` -- ``None``, an element, or a list of elements, the + images of the generators in an ambient field (default: ``None``) + - ``latex_names`` (or ``latex_name``) - ``None``, a string, or a + list of strings (default: ``None``), how the generators are printed + for latex output + - ``assume_disc_small`` -- a boolean (default: ``False``); if ``True``, + assume that no square of a prime greater than PARI's primelimit + (which should be 500000); only applies for absolute fields at + present. + - ``maximize_at_primes`` -- ``None`` or a list of primes (default: + ``None``); if not ``None``, then the maximal order is computed by + maximizing only at the primes in this list, which completely avoids + having to factor the discriminant, but of course can lead to wrong + results; only applies for absolute fields at present. + - ``structure`` -- ``None``, a list or an instance of + :class:`structure.NumberFieldStructure` (default: ``None``), + internally used to pass in additional structural information, e.g., + about the field from which this field is created as a subfield. We accept ``implementation`` and ``prec`` attributes for compatibility with :class:`~sage.categories.pushout.AlgebraicExtensionFunctor` @@ -294,7 +294,7 @@ def NumberField(polynomial, name=None, check=True, names=None, embedding=None, EXAMPLES:: sage: z = QQ['z'].0 - sage: K = NumberField(z^2 - 2,'s'); K + sage: K = NumberField(z^2 - 2, 's'); K Number Field in s with defining polynomial z^2 - 2 sage: s = K.0; s s @@ -307,7 +307,7 @@ def NumberField(polynomial, name=None, check=True, names=None, embedding=None, sage: K. = NumberField(x^2 - 2) sage: R. = K[] - sage: L. = K.extension(t^3+t+a); L + sage: L. = K.extension(t^3 + t + a); L Number Field in b with defining polynomial t^3 + t + a over its base field sage: L.absolute_field('c') Number Field in c with defining polynomial x^6 + 2*x^4 + x^2 - 2 @@ -357,13 +357,14 @@ def NumberField(polynomial, name=None, check=True, names=None, embedding=None, for arithmetic and deduce relations with other number fields which would not be valid for an abstract number field. :: - sage: K. = NumberField(x^3-2, embedding=1.2) + sage: K. = NumberField(x^3 - 2, embedding=1.2) sage: RR.coerce_map_from(K) Composite map: From: Number Field in a with defining polynomial x^3 - 2 with a = 1.259921049894873? To: Real Field with 53 bits of precision Defn: Generic morphism: - From: Number Field in a with defining polynomial x^3 - 2 with a = 1.259921049894873? + From: Number Field in a with defining polynomial x^3 - 2 + with a = 1.259921049894873? To: Real Lazy Field Defn: a -> 1.259921049894873? then @@ -378,7 +379,7 @@ def NumberField(polynomial, name=None, check=True, names=None, embedding=None, 1/3*a^2 - 1/3*a + 1/3 sage: RR(b) 0.442493334024442 - sage: L. = NumberField(x^6-2, embedding=1.1) + sage: L. = NumberField(x^6 - 2, embedding=1.1) sage: L(a) b^2 sage: a + b @@ -400,7 +401,8 @@ def NumberField(polynomial, name=None, check=True, names=None, embedding=None, sage: f = polygen(L)^3 - 2 sage: K. = NumberField(x^3-2, embedding=f.roots()[0][0]) sage: a + L(1) - 4 + 2*5^2 + 2*5^3 + 3*5^4 + 5^5 + 4*5^6 + 2*5^8 + 3*5^9 + 4*5^12 + 4*5^14 + 4*5^15 + 3*5^16 + 5^17 + 5^18 + 2*5^19 + O(5^20) + 4 + 2*5^2 + 2*5^3 + 3*5^4 + 5^5 + 4*5^6 + 2*5^8 + 3*5^9 + 4*5^12 + + 4*5^14 + 4*5^15 + 3*5^16 + 5^17 + 5^18 + 2*5^19 + O(5^20) sage: L. = NumberField(x^6-x^2+1/10, embedding=1) sage: K. = NumberField(x^3-x+1/10, embedding=b^2) sage: a+b @@ -410,7 +412,8 @@ def NumberField(polynomial, name=None, check=True, names=None, embedding=None, sage: K.coerce_embedding() Generic morphism: From: Number Field in a with defining polynomial x^3 - x + 1/10 with a = b^2 - To: Number Field in b with defining polynomial x^6 - x^2 + 1/10 with b = 0.9724449978911874? + To: Number Field in b with defining polynomial x^6 - x^2 + 1/10 + with b = 0.9724449978911874? Defn: a -> b^2 The ``QuadraticField`` and ``CyclotomicField`` constructors @@ -429,7 +432,7 @@ def NumberField(polynomial, name=None, check=True, names=None, embedding=None, Note that the codomain of the embedding must be ``QQbar`` or ``AA`` for this to work (see :trac:`20184`):: - sage: N. = NumberField(x^3+2,embedding=1) + sage: N. = NumberField(x^3 + 2,embedding=1) sage: 1 < g False sage: g > 1 @@ -440,7 +443,7 @@ def NumberField(polynomial, name=None, check=True, names=None, embedding=None, If no embedding is specified or is complex, the comparison is not returning something meaningful.:: - sage: N. = NumberField(x^3+2) + sage: N. = NumberField(x^3 + 2) sage: 1 < g False sage: g > 1 @@ -505,7 +508,7 @@ def NumberField(polynomial, name=None, check=True, names=None, embedding=None, :: - sage: W1 = NumberField(x^2+1,'a') + sage: W1 = NumberField(x^2 + 1,'a') sage: K. = CyclotomicField(5)[] sage: W. = NumberField(x^2 + 1); W Number Field in a with defining polynomial x^2 + 1 over its base field @@ -513,8 +516,8 @@ def NumberField(polynomial, name=None, check=True, names=None, embedding=None, The following has been fixed in :trac:`8800`:: sage: P. = QQ[] - sage: K. = NumberField(x^3-5,embedding=0) - sage: L. = K.extension(x^2+a) + sage: K. = NumberField(x^3 - 5,embedding=0) + sage: L. = K.extension(x^2 + a) sage: F, R = L.construction() sage: F(R) == L # indirect doctest True @@ -534,7 +537,8 @@ def NumberField(polynomial, name=None, check=True, names=None, embedding=None, Another problem that was found while working on :trac:`11670`, ``maximize_at_primes`` and ``assume_disc_small`` were lost when pickling:: - sage: K. = NumberField(x^3-2, assume_disc_small=True, maximize_at_primes=[2], latex_name='\\alpha', embedding=2^(1/3)) + sage: K. = NumberField(x^3 - 2, assume_disc_small=True, maximize_at_primes=[2], + ....: latex_name='\\alpha', embedding=2^(1/3)) sage: L = loads(dumps(K)) sage: L._assume_disc_small True @@ -585,27 +589,27 @@ class NumberFieldFactory(UniqueFactory): INPUT: - - ``polynomial`` - a polynomial over `\QQ` or a number field. - - ``name`` - a string (default: ``'a'``), the name of the generator - - ``check`` - a boolean (default: ``True``); do type checking and - irreducibility checking. - - ``embedding`` - ``None`` or an element, the images of the generator - in an ambient field (default: ``None``) - - ``latex_name`` - ``None`` or a string (default: ``None``), how the - generator is printed for latex output - - ``assume_disc_small`` -- a boolean (default: ``False``); if ``True``, - assume that no square of a prime greater than PARI's primelimit - (which should be 500000); only applies for absolute fields at - present. - - ``maximize_at_primes`` -- ``None`` or a list of primes (default: - ``None``); if not ``None``, then the maximal order is computed by - maximizing only at the primes in this list, which completely avoids - having to factor the discriminant, but of course can lead to wrong - results; only applies for absolute fields at present. - - ``structure`` -- ``None`` or an instance of - :class:`structure.NumberFieldStructure` (default: ``None``), - internally used to pass in additional structural information, e.g., - about the field from which this field is created as a subfield. + - ``polynomial`` -- a polynomial over `\QQ` or a number field. + - ``name`` -- a string (default: ``'a'``), the name of the generator + - ``check`` -- a boolean (default: ``True``); do type checking and + irreducibility checking. + - ``embedding`` -- ``None`` or an element, the images of the generator + in an ambient field (default: ``None``) + - ``latex_name`` -- ``None`` or a string (default: ``None``), how the + generator is printed for latex output + - ``assume_disc_small`` -- a boolean (default: ``False``); if ``True``, + assume that no square of a prime greater than PARI's primelimit + (which should be 500000); only applies for absolute fields at + present. + - ``maximize_at_primes`` -- ``None`` or a list of primes (default: + ``None``); if not ``None``, then the maximal order is computed by + maximizing only at the primes in this list, which completely avoids + having to factor the discriminant, but of course can lead to wrong + results; only applies for absolute fields at present. + - ``structure`` -- ``None`` or an instance of + :class:`structure.NumberFieldStructure` (default: ``None``), + internally used to pass in additional structural information, e.g., + about the field from which this field is created as a subfield. TESTS:: @@ -722,20 +726,20 @@ def NumberFieldTower(polynomials, names, check=True, embeddings=None, latex_name INPUT: - - ``polynomials`` - a list of polynomials. Each entry must be polynomial + - ``polynomials`` -- a list of polynomials. Each entry must be polynomial which is irreducible over the number field generated by the roots of the following entries. - - ``names`` - a list of strings or a string, the names of the generators of + - ``names`` -- a list of strings or a string, the names of the generators of the relative number fields. If a single string, then names are generated from that string. - - ``check`` - a boolean (default: ``True``), whether to check that the + - ``check`` -- a boolean (default: ``True``), whether to check that the polynomials are irreducible - - ``embeddings`` - a list of elements or ``None`` (default: ``None``), + - ``embeddings`` -- a list of elements or ``None`` (default: ``None``), embeddings of the relative number fields in an ambient field. - - ``latex_names`` - a list of strings or ``None`` (default: ``None``), names + - ``latex_names`` -- a list of strings or ``None`` (default: ``None``), names used to print the generators for latex output. - ``assume_disc_small`` -- a boolean (default: ``False``); if ``True``, - assume that no square of a prime greater than PARI's primelimit + assume that no square of a prime greater than PARI's ``primelimit`` (which should be 500000); only applies for absolute fields at present. - ``maximize_at_primes`` -- ``None`` or a list of primes (default: @@ -811,7 +815,8 @@ def NumberFieldTower(polynomials, names, check=True, embeddings=None, latex_name LaTeX versions of generator names can be specified either as:: - sage: K = NumberField([x^3 - 2, x^3 - 3, x^3 - 5], names=['a', 'b', 'c'], latex_names=[r'\alpha', r'\beta', r'\gamma']) + sage: K = NumberField([x^3 - 2, x^3 - 3, x^3 - 5], names=['a', 'b', 'c'], + ....: latex_names=[r'\alpha', r'\beta', r'\gamma']) sage: K.inject_variables(verbose=False) sage: latex(a + b + c) \alpha + \beta + \gamma @@ -882,16 +887,16 @@ def QuadraticField(D, name='a', check=True, embedding=True, latex_name='sqrt', * INPUT: - - ``D`` - a rational number + - ``D`` -- a rational number - - ``name`` - variable name (default: 'a') + - ``name`` -- variable name (default: 'a') - - ``check`` - bool (default: ``True``) + - ``check`` -- bool (default: ``True``) - - ``embedding`` - bool or square root of D in an - ambient field (default: ``True``) + - ``embedding`` -- bool or square root of `D` in an + ambient field (default: ``True``) - - ``latex_name`` - latex variable name (default: \sqrt{D}) + - ``latex_name`` -- latex variable name (default: `\sqrt{D}`) OUTPUT: A number field defined by a quadratic polynomial. Unless @@ -1004,7 +1009,7 @@ def QuadraticField(D, name='a', check=True, embedding=True, latex_name='sqrt', * def GaussianField(): r""" - The field QQ[i]. + The field `\QQ[i]`. TESTS:: @@ -1022,8 +1027,8 @@ def GaussianField(): def is_AbsoluteNumberField(x): - """ - Return True if x is an absolute number field. + r""" + Return ``True`` if ``x`` is an absolute number field. EXAMPLES:: @@ -1046,7 +1051,7 @@ def is_AbsoluteNumberField(x): def is_QuadraticField(x) -> bool: r""" - Return True if x is of the quadratic *number* field type. + Return ``True`` if ``x`` is of the quadratic *number* field type. This function is deprecated. Use :func:`isinstance` with :class:`~sage.rings.abc.NumberField_quadratic` instead. @@ -1086,14 +1091,14 @@ class CyclotomicFieldFactory(UniqueFactory): INPUT: - - ``n`` - a nonnegative integer, default:``0`` + - ``n`` -- a nonnegative integer, default: ``0`` - - ``names`` - name of generator (optional - defaults to zetan) + - ``names`` -- name of generator (optional - defaults to zetan) - - ``bracket`` - Defines the brackets in the case of ``n==0``, and + - ``bracket`` -- Defines the brackets in the case of ``n==0``, and is ignored otherwise. Can be any even length string, with ``"()"`` being the default. - - ``embedding`` - bool or n-th root of unity in an + - ``embedding`` -- bool or `n`-th root of unity in an ambient field (default True) EXAMPLES: @@ -1240,8 +1245,8 @@ def create_object(self, version, key, **extra_args): def is_CyclotomicField(x) -> bool: """ - Return True if x is a cyclotomic field, i.e., of the special - cyclotomic field class. This function does not return True for a + Return ``True`` if x is a cyclotomic field, i.e., of the special + cyclotomic field class. This function does not return ``True`` for a number field that just happens to be isomorphic to a cyclotomic field. @@ -1278,9 +1283,9 @@ def is_CyclotomicField(x) -> bool: class NumberField_generic(WithEqualityById, number_field_base.NumberField): - """ + r""" Generic class for number fields defined by an irreducible - polynomial over `\\QQ`. + polynomial over `\QQ`. EXAMPLES:: @@ -1332,7 +1337,7 @@ class NumberField_generic(WithEqualityById, number_field_base.NumberField): sage: K. = QuadraticField(2) sage: R. = K[] - sage: L. = K.extension(x^2+1) + sage: L. = K.extension(x^2 + 1) sage: M. = L.absolute_field() sage: M == L False @@ -1341,8 +1346,8 @@ class NumberField_generic(WithEqualityById, number_field_base.NumberField): sage: R. = QQ[] sage: R. = QQ[] - sage: K. = NumberField(x^2+1) - sage: L. = NumberField(y^2+1) + sage: K. = NumberField(x^2 + 1) + sage: L. = NumberField(y^2 + 1) sage: K == L False sage: hash(K) == hash(L) @@ -1365,7 +1370,7 @@ class NumberField_generic(WithEqualityById, number_field_base.NumberField): This example illustrates the issue resolved in :trac:`18942`:: - sage: F. = NumberField(x^2+x+1) + sage: F. = NumberField(x^2 + x + 1) sage: xx = polygen(F) sage: ps = [p for p, _ in F(7).factor()] sage: for mu in ps: @@ -1407,7 +1412,7 @@ def __init__(self, polynomial, name, latex_name, ... ValueError: defining polynomial (x^2 - 1) must be irreducible - If you use check=False, you avoid checking irreducibility of the + If you use ``check=False``, you avoid checking irreducibility of the defining polynomial, which can save time. :: @@ -1438,7 +1443,7 @@ def __init__(self, polynomial, name, latex_name, Number Field in a with defining polynomial x^4 + 23 sage: NumberField(QQ['x'].0^4 + 23, 'a') Number Field in a with defining polynomial x^4 + 23 - sage: NumberField(GF(7)['x'].0^4 + 23, 'a') + sage: NumberField(GF(7)['x'].0^4 + 23, 'a') # optional - sage.rings.finite_rings Traceback (most recent call last): ... TypeError: polynomial must be defined over rational field @@ -1533,7 +1538,7 @@ def _magma_polynomial_(self, magma): EXAMPLES:: sage: R. = QQ[] # optional - magma - sage: K. = NumberField(x^3+2) # optional - magma + sage: K. = NumberField(x^3 + 2) # optional - magma sage: K._magma_polynomial_(magma) # optional - magma x^3 + 2 sage: magma2=Magma() # optional - magma @@ -1595,8 +1600,8 @@ def construction(self): EXAMPLES:: - sage: K.=NumberField(x^3+x^2+1,embedding=CC.gen()) - sage: F,R = K.construction() + sage: K. = NumberField(x^3 + x^2 + 1,embedding=CC.gen()) + sage: F, R = K.construction() sage: F AlgebraicExtensionFunctor sage: R @@ -1611,11 +1616,11 @@ def construction(self): TESTS:: - sage: K. = NumberField(x^3+x+1) + sage: K. = NumberField(x^3 + x + 1) sage: R. = ZZ[] - sage: a+t # indirect doctest + sage: a + t # indirect doctest t + a - sage: (a+t).parent() + sage: (a + t).parent() Univariate Polynomial Ring in t over Number Field in a with defining polynomial x^3 + x + 1 The construction works for non-absolute number fields as well:: @@ -1760,8 +1765,8 @@ def _element_constructor_(self, x, check=True): Check that :trac:`30961` is fixed:: sage: QQi = i.parent() - sage: x = SR.var('x') - sage: QQi((x, x)) + sage: x = SR.var('x') # optional - sage.symbolic + sage: QQi((x, x)) # optional - sage.symbolic Traceback (most recent call last): ... TypeError: unable to convert x to a rational @@ -1847,6 +1852,7 @@ def _convert_non_number_field_element(self, x): EXAMPLES:: + sage: x = polygen(QQ, 'x') sage: K. = NumberField(x^3 + 2/3) sage: K._convert_non_number_field_element(-7/8) -7/8 @@ -1862,17 +1868,17 @@ def _convert_non_number_field_element(self, x): will convert to the number field, e.g., this one in characteristic 7:: - sage: f = GF(7)['y']([1,2,3]); f + sage: f = GF(7)['y']([1,2,3]); f # optional - sage.rings.finite_rings 3*y^2 + 2*y + 1 - sage: K._convert_non_number_field_element(f) + sage: K._convert_non_number_field_element(f) # optional - sage.rings.finite_rings 3*a^2 + 2*a + 1 But not this one over a field of order 27:: - sage: F27. = GF(27) - sage: f = F27['z']([g^2, 2*g, 1]); f + sage: F27. = GF(27) # optional - sage.rings.finite_rings + sage: f = F27['z']([g^2, 2*g, 1]); f # optional - sage.rings.finite_rings z^2 + 2*g*z + g^2 - sage: K._convert_non_number_field_element(f) + sage: K._convert_non_number_field_element(f) # optional - sage.rings.finite_rings Traceback (most recent call last): ... TypeError: unable to convert g^2 to a rational @@ -1887,16 +1893,16 @@ def _convert_non_number_field_element(self, x): We can convert symbolic expressions:: - sage: I = sqrt(-1); parent(I) + sage: I = sqrt(-1); parent(I) # optional - sage.symbolic Symbolic Ring - sage: GaussianIntegers()(2 + I) + sage: GaussianIntegers()(2 + I) # optional - sage.symbolic I + 2 - sage: K1 = QuadraticField(3) - sage: K2 = QuadraticField(5) - sage: (K,) = K1.composite_fields(K2, preserve_embedding=True) - sage: K(sqrt(3) + sqrt(5)) + sage: K1 = QuadraticField(3) # optional - sage.symbolic + sage: K2 = QuadraticField(5) # optional - sage.symbolic + sage: (K,) = K1.composite_fields(K2, preserve_embedding=True) # optional - sage.symbolic + sage: K(sqrt(3) + sqrt(5)) # optional - sage.symbolic -1/2*a0^3 + 8*a0 - sage: K(sqrt(-3)*I) + sage: K(sqrt(-3)*I) # optional - sage.symbolic 1/4*a0^3 - 7/2*a0 """ if isinstance(x, (int, Rational, Integer, pari_gen, list)): @@ -2020,12 +2026,19 @@ def _Hom_(self, codomain, category=None): sage: K.Hom(K) # indirect doctest Automorphism group of Number Field in i with defining polynomial x^2 + 1 sage: Hom(K, QuadraticField(-1, 'b')) - Set of field embeddings from Number Field in i with defining polynomial x^2 + 1 to Number Field in b with defining polynomial x^2 + 1 with b = 1*I + Set of field embeddings + from Number Field in i with defining polynomial x^2 + 1 + to Number Field in b with defining polynomial x^2 + 1 with b = 1*I CHECKME: handling of the case where codomain is not a number field? - sage: Hom(K, VectorSpace(QQ,3)) - Set of Morphisms from Number Field in i with defining polynomial x^2 + 1 to Vector space of dimension 3 over Rational Field in Category of commutative additive groups + :: + + sage: Hom(K, VectorSpace(QQ,3)) + Set of Morphisms + from Number Field in i with defining polynomial x^2 + 1 + to Vector space of dimension 3 over Rational Field + in Category of commutative additive groups TESTS: @@ -2148,27 +2161,25 @@ def random_element(self, num_bound=None, den_bound=None, INPUT: - - ``num_bound`` - Bound on numerator of the coefficients of - the resulting element - - - ``den_bound`` - Bound on denominators of the coefficients - of the resulting element + - ``num_bound`` -- Bound on numerator of the coefficients of + the resulting element - - ``integral_coefficients`` (default: ``False``) - If ``True``, then - the resulting element will have integral - coefficients. This option overrides any - value of `den_bound`. + - ``den_bound`` -- Bound on denominators of the coefficients + of the resulting element - - ``distribution`` - Distribution to use for the coefficients - of the resulting element + - ``integral_coefficients`` -- (default: ``False``) If ``True``, then + the resulting element will have integral + coefficients. This option overrides any + value of ``den_bound``. - OUTPUT: + - ``distribution`` -- Distribution to use for the coefficients + of the resulting element - - Element of this number field + OUTPUT: Element of this number field EXAMPLES:: - sage: K. = NumberField(x^8+1) + sage: K. = NumberField(x^8 + 1) sage: K.random_element().parent() is K True @@ -2181,7 +2192,7 @@ def random_element(self, num_bound=None, den_bound=None, sage: while not K.random_element().is_prime(): ....: pass - sage: K. = NumberField([x^2-2,x^2-3,x^2-5]) + sage: K. = NumberField([x^2 - 2, x^2 - 3, x^2 - 5]) sage: K.random_element().parent() is K True @@ -2190,7 +2201,7 @@ def random_element(self, num_bound=None, den_bound=None, sage: while not K.random_element().is_prime(): # long time ....: pass - sage: K. = NumberField(x^5-2) + sage: K. = NumberField(x^5 - 2) sage: p = K.random_element(integral_coefficients=True) sage: p.is_integral() True @@ -2199,12 +2210,12 @@ def random_element(self, num_bound=None, den_bound=None, TESTS:: - sage: K. = NumberField(x^5-2) + sage: K. = NumberField(x^5 - 2) sage: K.random_element(-1) Traceback (most recent call last): ... TypeError: x must be < y - sage: K.random_element(5,0) + sage: K.random_element(5, 0) Traceback (most recent call last): ... TypeError: x must be < y @@ -2224,19 +2235,19 @@ def subfield(self, alpha, name=None, names=None): r""" Return a number field `K` isomorphic to `\QQ(\alpha)` (if this is an absolute number field) or `L(\alpha)` (if this - is a relative extension `M/L`) and a map from K to self that - sends the generator of K to alpha. + is a relative extension `M/L`) and a map from `K` to ``self`` that + sends the generator of `K` to ``alpha``. INPUT: - - ``alpha`` - an element of self, or something that - coerces to an element of self. + - ``alpha`` -- an element of ``self``, or something that + coerces to an element of ``self``. OUTPUT: - - ``K`` - a number field - - ``from_K`` - a homomorphism from K to self that - sends the generator of K to alpha. + - ``K`` -- a number field + - ``from_K`` -- a homomorphism from `K` to ``self`` that + sends the generator of `K` to ``alpha``. EXAMPLES:: @@ -2265,7 +2276,7 @@ def subfield(self, alpha, name=None, names=None): Subfields inherit embeddings:: sage: K. = CyclotomicField(5) - sage: L, K_from_L = K.subfield(z-z^2-z^3+z^4) + sage: L, K_from_L = K.subfield(z - z^2 - z^3 + z^4) sage: L Number Field in z0 with defining polynomial x^2 - 5 with z0 = 2.236067977499790? sage: CLF_from_K = K.coerce_embedding(); CLF_from_K @@ -2275,7 +2286,8 @@ def subfield(self, alpha, name=None, names=None): Defn: z -> 0.309016994374948? + 0.951056516295154?*I sage: CLF_from_L = L.coerce_embedding(); CLF_from_L Generic morphism: - From: Number Field in z0 with defining polynomial x^2 - 5 with z0 = 2.236067977499790? + From: Number Field in z0 with defining polynomial x^2 - 5 + with z0 = 2.236067977499790? To: Complex Lazy Field Defn: z0 -> 2.236067977499790? @@ -2319,9 +2331,9 @@ def subfield(self, alpha, name=None, names=None): def change_generator(self, alpha, name=None, names=None): r""" - Given the number field self, construct another isomorphic number - field `K` generated by the element alpha of self, along - with isomorphisms from `K` to self and from self to + Given the number field ``self``, construct another isomorphic number + field `K` generated by the element ``alpha`` of ``self``, along + with isomorphisms from `K` to ``self`` and from ``self`` to `K`. EXAMPLES:: @@ -2333,13 +2345,15 @@ def change_generator(self, alpha, name=None, names=None): Number Field in i0 with defining polynomial x^2 - 6*x + 37/4 with i0 = 1/2*i + 3 sage: from_K Ring morphism: - From: Number Field in i0 with defining polynomial x^2 - 6*x + 37/4 with i0 = 1/2*i + 3 + From: Number Field in i0 with defining polynomial x^2 - 6*x + 37/4 + with i0 = 1/2*i + 3 To: Number Field in i with defining polynomial x^2 + 1 Defn: i0 |--> 1/2*i + 3 sage: to_K Ring morphism: From: Number Field in i with defining polynomial x^2 + 1 - To: Number Field in i0 with defining polynomial x^2 - 6*x + 37/4 with i0 = 1/2*i + 3 + To: Number Field in i0 with defining polynomial x^2 - 6*x + 37/4 + with i0 = 1/2*i + 3 Defn: i |--> 2*i0 - 6 We can also do @@ -2357,7 +2371,7 @@ def change_generator(self, alpha, name=None, names=None): sage: to_K(i) 2*c - 6 - Note that the image is indeed a square root of -1. + Note that the image is indeed a square root of `-1`. :: @@ -2396,9 +2410,9 @@ def subfield_from_elements(self, alpha, name=None, polred=True, threshold=None): INPUT: - - ``alpha`` - list of elements in this number field + - ``alpha`` -- list of elements in this number field - - ``name`` - a name for the generator of the new number field + - ``name`` -- a name for the generator of the new number field - ``polred`` (boolean, default ``True``) - whether to optimize the generator of the newly created field @@ -2408,11 +2422,11 @@ def subfield_from_elements(self, alpha, name=None, polred=True, threshold=None): OUTPUT: a triple ``(field, beta, hom)`` where - - ``field`` - a subfield of this number field + - ``field`` -- a subfield of this number field - - ``beta`` - a list of elements of ``field`` corresponding to ``alpha`` + - ``beta`` -- a list of elements of ``field`` corresponding to ``alpha`` - - ``hom`` - inclusion homomorphism from ``field`` to ``self`` + - ``hom`` -- inclusion homomorphism from ``field`` to ``self`` EXAMPLES:: @@ -2680,7 +2694,7 @@ def absolute_field(self, names): def is_isomorphic(self, other, isomorphism_maps=False) -> bool: """ - Return True if self is isomorphic as a number field to other. + Return ``True`` if ``self`` is isomorphic as a number field to ``other``. EXAMPLES:: @@ -2740,43 +2754,43 @@ def is_isomorphic(self, other, isomorphism_maps=False) -> bool: def is_totally_real(self): """ - Return True if self is totally real, and False otherwise. + Return ``True`` if ``self`` is totally real, and ``False`` otherwise. - Totally real means that every isomorphic embedding of self into the + Totally real means that every isomorphic embedding of ``self`` into the complex numbers has image contained in the real numbers. EXAMPLES:: - sage: NumberField(x^2+2, 'alpha').is_totally_real() + sage: NumberField(x^2 + 2, 'alpha').is_totally_real() False - sage: NumberField(x^2-2, 'alpha').is_totally_real() + sage: NumberField(x^2 - 2, 'alpha').is_totally_real() True - sage: NumberField(x^4-2, 'alpha').is_totally_real() + sage: NumberField(x^4 - 2, 'alpha').is_totally_real() False """ return self.signature()[1] == 0 def is_totally_imaginary(self): """ - Return True if self is totally imaginary, and False otherwise. + Return ``True`` if self is totally imaginary, and ``False`` otherwise. - Totally imaginary means that no isomorphic embedding of self into + Totally imaginary means that no isomorphic embedding of ``self`` into the complex numbers has image contained in the real numbers. EXAMPLES:: - sage: NumberField(x^2+2, 'alpha').is_totally_imaginary() + sage: NumberField(x^2 + 2, 'alpha').is_totally_imaginary() True - sage: NumberField(x^2-2, 'alpha').is_totally_imaginary() + sage: NumberField(x^2 - 2, 'alpha').is_totally_imaginary() False - sage: NumberField(x^4-2, 'alpha').is_totally_imaginary() + sage: NumberField(x^4 - 2, 'alpha').is_totally_imaginary() False """ return self.signature()[0] == 0 def is_CM(self): r""" - Return True if self is a CM field (i.e. a totally imaginary + Return ``True`` if self is a CM field (i.e. a totally imaginary quadratic extension of a totally real field). EXAMPLES:: @@ -2799,7 +2813,7 @@ def is_CM(self): sage: F. = NumberField(x^3 - 2) sage: F.is_CM() False - sage: F. = NumberField(x^4-x^3-3*x^2+x+1) + sage: F. = NumberField(x^4 - x^3 - 3*x^2 + x + 1) sage: F.is_CM() False @@ -2833,8 +2847,8 @@ def is_CM(self): :: - sage: E_0. = NumberField(x^7 - 4*x^6 - 4*x^5 + 10*x^4 + 4*x^3 - \ - 6*x^2 - x + 1) + sage: E_0. = NumberField(x^7 - 4*x^6 - 4*x^5 + 10*x^4 + 4*x^3 + ....: - 6*x^2 - x + 1) sage: E_0.is_totally_real() True sage: E. = E_0.extension(x^2 + 1) @@ -2899,12 +2913,12 @@ def is_CM(self): def complex_conjugation(self): """ - Return the complex conjugation of self. + Return the complex conjugation of ``self``. This is only well-defined for fields contained in CM fields (i.e. for totally real fields and CM fields). Recall that a CM field is a totally imaginary quadratic extension of a totally - real field. For other fields, a ValueError is raised. + real field. For other fields, a :class:`ValueError` is raised. EXAMPLES:: @@ -2991,45 +3005,58 @@ def complex_conjugation(self): def maximal_totally_real_subfield(self): """ - Return the maximal totally real subfield of self together with an embedding of it into self. + Return the maximal totally real subfield of ``self`` together with an embedding of it into ``self``. EXAMPLES:: sage: F. = QuadraticField(11) sage: F.maximal_totally_real_subfield() [Number Field in a with defining polynomial x^2 - 11 with a = 3.316624790355400?, - Identity endomorphism of Number Field in a with defining polynomial x^2 - 11 with a = 3.316624790355400?] + Identity endomorphism of + Number Field in a with defining polynomial x^2 - 11 with a = 3.316624790355400?] sage: F. = QuadraticField(-15) sage: F.maximal_totally_real_subfield() [Rational Field, Natural morphism: From: Rational Field - To: Number Field in a with defining polynomial x^2 + 15 with a = 3.872983346207417?*I] + To: Number Field in a with defining polynomial x^2 + 15 + with a = 3.872983346207417?*I] sage: F. = CyclotomicField(29) sage: F.maximal_totally_real_subfield() - (Number Field in a0 with defining polynomial x^14 + x^13 - 13*x^12 - 12*x^11 + 66*x^10 + 55*x^9 - 165*x^8 - 120*x^7 + 210*x^6 + 126*x^5 - 126*x^4 - 56*x^3 + 28*x^2 + 7*x - 1 with a0 = 1.953241111420174?, + (Number Field in a0 with defining polynomial x^14 + x^13 - 13*x^12 - 12*x^11 + + 66*x^10 + 55*x^9 - 165*x^8 - 120*x^7 + 210*x^6 + 126*x^5 - 126*x^4 + - 56*x^3 + 28*x^2 + 7*x - 1 with a0 = 1.953241111420174?, Ring morphism: - From: Number Field in a0 with defining polynomial x^14 + x^13 - 13*x^12 - 12*x^11 + 66*x^10 + 55*x^9 - 165*x^8 - 120*x^7 + 210*x^6 + 126*x^5 - 126*x^4 - 56*x^3 + 28*x^2 + 7*x - 1 with a0 = 1.953241111420174? + From: Number Field in a0 with defining polynomial x^14 + x^13 - 13*x^12 - 12*x^11 + + 66*x^10 + 55*x^9 - 165*x^8 - 120*x^7 + 210*x^6 + 126*x^5 - 126*x^4 + - 56*x^3 + 28*x^2 + 7*x - 1 with a0 = 1.953241111420174? To: Cyclotomic Field of order 29 and degree 28 - Defn: a0 |--> -a^27 - a^26 - a^25 - a^24 - a^23 - a^22 - a^21 - a^20 - a^19 - a^18 - a^17 - a^16 - a^15 - a^14 - a^13 - a^12 - a^11 - a^10 - a^9 - a^8 - a^7 - a^6 - a^5 - a^4 - a^3 - a^2 - 1) + Defn: a0 |--> -a^27 - a^26 - a^25 - a^24 - a^23 - a^22 - a^21 - a^20 - a^19 + - a^18 - a^17 - a^16 - a^15 - a^14 - a^13 - a^12 - a^11 - a^10 + - a^9 - a^8 - a^7 - a^6 - a^5 - a^4 - a^3 - a^2 - 1) sage: F. = NumberField(x^3 - 2) sage: F.maximal_totally_real_subfield() - [Rational Field, Coercion map: + [Rational Field, + Coercion map: From: Rational Field To: Number Field in a with defining polynomial x^3 - 2] sage: F. = NumberField(x^4 - x^3 - x^2 + x + 1) sage: F.maximal_totally_real_subfield() - [Rational Field, Coercion map: + [Rational Field, + Coercion map: From: Rational Field To: Number Field in a with defining polynomial x^4 - x^3 - x^2 + x + 1] sage: F. = NumberField(x^4 - x^3 + 2*x^2 + x + 1) sage: F.maximal_totally_real_subfield() - [Number Field in a1 with defining polynomial x^2 - x - 1, Ring morphism: + [Number Field in a1 with defining polynomial x^2 - x - 1, + Ring morphism: From: Number Field in a1 with defining polynomial x^2 - x - 1 To: Number Field in a with defining polynomial x^4 - x^3 + 2*x^2 + x + 1 Defn: a1 |--> -1/2*a^3 - 1/2] - sage: F. = NumberField(x^4-4*x^2-x+1) + sage: F. = NumberField(x^4 - 4*x^2 - x + 1) sage: F.maximal_totally_real_subfield() - [Number Field in a with defining polynomial x^4 - 4*x^2 - x + 1, Identity endomorphism of Number Field in a with defining polynomial x^4 - 4*x^2 - x + 1] + [Number Field in a with defining polynomial x^4 - 4*x^2 - x + 1, + Identity endomorphism of + Number Field in a with defining polynomial x^4 - 4*x^2 - x + 1] An example of a relative extension where the base field is not the maximal totally real subfield. @@ -3039,17 +3066,21 @@ def maximal_totally_real_subfield(self): sage: y = polygen(E_0) sage: E. = E_0.extension(y^2 - E_0.gen() / 2) sage: E.maximal_totally_real_subfield() - [Number Field in z1 with defining polynomial x^2 - 2*x - 5, Composite map: + [Number Field in z1 with defining polynomial x^2 - 2*x - 5, + Composite map: From: Number Field in z1 with defining polynomial x^2 - 2*x - 5 To: Number Field in z with defining polynomial x^2 - 1/2*a over its base field Defn: Ring morphism: From: Number Field in z1 with defining polynomial x^2 - 2*x - 5 - To: Number Field in z with defining polynomial x^4 - 2*x^3 + x^2 + 6*x + 3 + To: Number Field in z with defining + polynomial x^4 - 2*x^3 + x^2 + 6*x + 3 Defn: z1 |--> -1/3*z^3 + 1/3*z^2 + z - 1 then Isomorphism map: - From: Number Field in z with defining polynomial x^4 - 2*x^3 + x^2 + 6*x + 3 - To: Number Field in z with defining polynomial x^2 - 1/2*a over its base field] + From: Number Field in z with defining + polynomial x^4 - 2*x^3 + x^2 + 6*x + 3 + To: Number Field in z with defining + polynomial x^2 - 1/2*a over its base field] """ @@ -3099,7 +3130,7 @@ def maximal_totally_real_subfield(self): def complex_embeddings(self, prec=53): r""" Return all homomorphisms of this number field into the approximate - complex field with precision prec. + complex field with precision ``prec``. This always embeds into an MPFR based complex field. If you want embeddings into the 53-bit double precision, which is @@ -3138,9 +3169,9 @@ def complex_embeddings(self, prec=53): def real_embeddings(self, prec=53): r""" Return all homomorphisms of this number field into the approximate - real field with precision prec. + real field with precision ``prec``. - If prec is 53 (the default), then the real double field is + If ``prec`` is 53 (the default), then the real double field is used; otherwise the arbitrary precision (but slow) real field is used. If you want embeddings into the 53-bit double precision, which is faster, use ``self.embeddings(RDF)``. @@ -3179,7 +3210,7 @@ def real_embeddings(self, prec=53): As this is a numerical function, the number of embeddings may be incorrect if the precision is too low:: - sage: K = NumberField(x^2+2*10^1000*x + 10^2000+1, 'a') + sage: K = NumberField(x^2 + 2*10^1000*x + 10^2000+1, 'a') sage: len(K.real_embeddings()) 2 sage: len(K.real_embeddings(100)) @@ -3198,10 +3229,10 @@ def specified_complex_embedding(self): Return the embedding of this field into the complex numbers which has been specified. - Fields created with the ``QuadraticField`` or - ``CyclotomicField`` constructors come with an implicit + Fields created with the :func:`QuadraticField` or + :func:`CyclotomicField` constructors come with an implicit embedding. To get one of these fields without the embedding, use - the generic ``NumberField`` constructor. + the generic :class:`NumberField` constructor. EXAMPLES:: @@ -3215,7 +3246,8 @@ def specified_complex_embedding(self): sage: QuadraticField(3, 'a').specified_complex_embedding() Generic morphism: - From: Number Field in a with defining polynomial x^2 - 3 with a = 1.732050807568878? + From: Number Field in a with defining polynomial x^2 - 3 + with a = 1.732050807568878? To: Real Lazy Field Defn: a -> 1.732050807568878? @@ -3230,33 +3262,41 @@ def specified_complex_embedding(self): Most fields don't implicitly have embeddings unless explicitly specified:: - sage: NumberField(x^2-2, 'a').specified_complex_embedding() is None + sage: NumberField(x^2 - 2, 'a').specified_complex_embedding() is None True - sage: NumberField(x^3-x+5, 'a').specified_complex_embedding() is None + sage: NumberField(x^3 - x + 5, 'a').specified_complex_embedding() is None True - sage: NumberField(x^3-x+5, 'a', embedding=2).specified_complex_embedding() + sage: NumberField(x^3 - x + 5, 'a', embedding=2).specified_complex_embedding() Generic morphism: - From: Number Field in a with defining polynomial x^3 - x + 5 with a = -1.904160859134921? + From: Number Field in a with defining polynomial x^3 - x + 5 + with a = -1.904160859134921? To: Real Lazy Field Defn: a -> -1.904160859134921? - sage: NumberField(x^3-x+5, 'a', embedding=CDF.0).specified_complex_embedding() + sage: NumberField(x^3 - x + 5, 'a', embedding=CDF.0).specified_complex_embedding() Generic morphism: - From: Number Field in a with defining polynomial x^3 - x + 5 with a = 0.952080429567461? + 1.311248044077123?*I + From: Number Field in a with defining polynomial x^3 - x + 5 + with a = 0.952080429567461? + 1.311248044077123?*I To: Complex Lazy Field Defn: a -> 0.952080429567461? + 1.311248044077123?*I This function only returns complex embeddings:: - sage: K. = NumberField(x^2-2, embedding=Qp(7)(2).sqrt()) - sage: K.specified_complex_embedding() is None + sage: K. = NumberField(x^2 - 2, embedding=Qp(7)(2).sqrt()) # optional - sage.rings.padics + sage: K.specified_complex_embedding() is None # optional - sage.rings.padics True - sage: K.gen_embedding() - 3 + 7 + 2*7^2 + 6*7^3 + 7^4 + 2*7^5 + 7^6 + 2*7^7 + 4*7^8 + 6*7^9 + 6*7^10 + 2*7^11 + 7^12 + 7^13 + 2*7^15 + 7^16 + 7^17 + 4*7^18 + 6*7^19 + O(7^20) - sage: K.coerce_embedding() + sage: K.gen_embedding() # optional - sage.rings.padics + 3 + 7 + 2*7^2 + 6*7^3 + 7^4 + 2*7^5 + 7^6 + 2*7^7 + 4*7^8 + 6*7^9 + 6*7^10 + + 2*7^11 + 7^12 + 7^13 + 2*7^15 + 7^16 + 7^17 + 4*7^18 + 6*7^19 + O(7^20) + sage: K.coerce_embedding() # optional - sage.rings.padics Generic morphism: - From: Number Field in a with defining polynomial x^2 - 2 with a = 3 + 7 + 2*7^2 + 6*7^3 + 7^4 + 2*7^5 + 7^6 + 2*7^7 + 4*7^8 + 6*7^9 + 6*7^10 + 2*7^11 + 7^12 + 7^13 + 2*7^15 + 7^16 + 7^17 + 4*7^18 + 6*7^19 + O(7^20) + From: Number Field in a with defining polynomial x^2 - 2 + with a = 3 + 7 + 2*7^2 + 6*7^3 + 7^4 + 2*7^5 + 7^6 + 2*7^7 + 4*7^8 + + 6*7^9 + 6*7^10 + 2*7^11 + 7^12 + 7^13 + 2*7^15 + 7^16 + + 7^17 + 4*7^18 + 6*7^19 + O(7^20) To: 7-adic Field with capped relative precision 20 - Defn: a -> 3 + 7 + 2*7^2 + 6*7^3 + 7^4 + 2*7^5 + 7^6 + 2*7^7 + 4*7^8 + 6*7^9 + 6*7^10 + 2*7^11 + 7^12 + 7^13 + 2*7^15 + 7^16 + 7^17 + 4*7^18 + 6*7^19 + O(7^20) + Defn: a -> 3 + 7 + 2*7^2 + 6*7^3 + 7^4 + 2*7^5 + 7^6 + 2*7^7 + 4*7^8 + + 6*7^9 + 6*7^10 + 2*7^11 + 7^12 + 7^13 + 2*7^15 + 7^16 + + 7^17 + 4*7^18 + 6*7^19 + O(7^20) """ embedding = self.coerce_embedding() if embedding is not None and embedding.codomain()._is_numerical(): @@ -3266,13 +3306,13 @@ def specified_complex_embedding(self): def gen_embedding(self): """ If an embedding has been specified, return the image of the - generator under that embedding. Otherwise return None. + generator under that embedding. Otherwise return ``None``. EXAMPLES:: sage: QuadraticField(-7, 'a').gen_embedding() 2.645751311064591?*I - sage: NumberField(x^2+7, 'a').gen_embedding() # None + sage: NumberField(x^2 + 7, 'a').gen_embedding() # None """ embedding = self.coerce_embedding() if embedding is None: @@ -3282,14 +3322,14 @@ def gen_embedding(self): def algebraic_closure(self): """ - Return the algebraic closure of self (which is QQbar). + Return the algebraic closure of ``self`` (which is ``QQbar``). EXAMPLES:: sage: K. = QuadraticField(-1) sage: K.algebraic_closure() Algebraic Field - sage: K. = NumberField(x^3-2) + sage: K. = NumberField(x^3 - 2) sage: K.algebraic_closure() Algebraic Field sage: K = CyclotomicField(23) @@ -3303,12 +3343,13 @@ def algebraic_closure(self): def conductor(self, check_abelian=True): r""" Computes the conductor of the abelian field `K`. - If check_abelian is set to false and the field is not an + If ``check_abelian`` is set to ``False`` and the field is not an abelian extension of `\QQ`, the output is not meaningful. INPUT: - - ``check_abelian`` - a boolean (default: ``True``); check to see that this is an abelian extension of `\QQ` + - ``check_abelian`` -- a boolean (default: ``True``); check to see + that this is an abelian extension of `\QQ` OUTPUT: @@ -3342,7 +3383,7 @@ def conductor(self, check_abelian=True): ALGORITHM: For odd primes, it is easy to compute from the ramification - index because the p-Sylow subgroup is cyclic. For p=2, there + index because the `p`-Sylow subgroup is cyclic. For `p=2`, there are two choices for a given ramification index. They can be distinguished by the parity of the exponent in the discriminant of a 2-adic completion. @@ -3375,35 +3416,33 @@ def conductor(self, check_abelian=True): def dirichlet_group(self): r""" - Given a abelian field `K`, this computes and returns the + Given a abelian field `K`, compute and return the set of all Dirichlet characters corresponding to the - characters of the Galois group of `K/\mathbb{Q}`. - - The output is random if the field is not abelian + characters of the Galois group of `K/\QQ`. - OUTPUT: + The output is random if the field is not abelian. - - a list of Dirichlet characters + OUTPUT: a list of Dirichlet characters EXAMPLES:: - sage: K. = NumberField(x^3+x^2-36*x-4) + sage: K. = NumberField(x^3 + x^2 - 36*x - 4) sage: K.conductor() 109 sage: K.dirichlet_group() [Dirichlet character modulo 109 of conductor 1 mapping 6 |--> 1, - Dirichlet character modulo 109 of conductor 109 mapping 6 |--> zeta3, - Dirichlet character modulo 109 of conductor 109 mapping 6 |--> -zeta3 - 1] + Dirichlet character modulo 109 of conductor 109 mapping 6 |--> zeta3, + Dirichlet character modulo 109 of conductor 109 mapping 6 |--> -zeta3 - 1] sage: K = CyclotomicField(44) sage: L = K.subfields(5)[0][0] sage: X = L.dirichlet_group() sage: X [Dirichlet character modulo 11 of conductor 1 mapping 2 |--> 1, - Dirichlet character modulo 11 of conductor 11 mapping 2 |--> zeta5, - Dirichlet character modulo 11 of conductor 11 mapping 2 |--> zeta5^2, - Dirichlet character modulo 11 of conductor 11 mapping 2 |--> zeta5^3, - Dirichlet character modulo 11 of conductor 11 mapping 2 |--> -zeta5^3 - zeta5^2 - zeta5 - 1] + Dirichlet character modulo 11 of conductor 11 mapping 2 |--> zeta5, + Dirichlet character modulo 11 of conductor 11 mapping 2 |--> zeta5^2, + Dirichlet character modulo 11 of conductor 11 mapping 2 |--> zeta5^3, + Dirichlet character modulo 11 of conductor 11 mapping 2 |--> -zeta5^3 - zeta5^2 - zeta5 - 1] sage: X[4]^2 Dirichlet character modulo 11 of conductor 11 mapping 2 |--> zeta5^3 sage: X[4]^2 in X @@ -3515,7 +3554,7 @@ def _fractional_ideal_class_(self): This function is required by the general ring/ideal machinery. The value defined here is the default value for all number fields *except* relative number fields; this function is overridden by - one of the same name on class NumberField_relative. + one of the same name in class :class:`NumberField_relative`. EXAMPLES:: @@ -3526,15 +3565,15 @@ def _fractional_ideal_class_(self): def ideal(self, *gens, **kwds): """ - K.ideal() returns a fractional ideal of the field, except for the - zero ideal which is not a fractional ideal. + Return a fractional ideal of the field, except for the + zero ideal, which is not a fractional ideal. EXAMPLES:: - sage: K.=NumberField(x^2+1) + sage: K. = NumberField(x^2 + 1) sage: K.ideal(2) Fractional ideal (2) - sage: K.ideal(2+i) + sage: K.ideal(2 + i) Fractional ideal (i + 2) sage: K.ideal(0) Ideal (0) of Number Field in i with defining polynomial x^2 + 1 @@ -3545,7 +3584,7 @@ def ideal(self, *gens, **kwds): sage: x = polygen(QQ) sage: K. = NumberField(x^6 - x^5 - 5*x^4 + 4*x^3 + 6*x^2 - 3*x - 1) - sage: K.ideal(1,1) + sage: K.ideal(1, 1) Fractional ideal (1) """ try: @@ -3562,9 +3601,9 @@ def idealchinese(self, ideals, residues): INPUT: - - ``ideals`` - a list of ideals of the number field. + - ``ideals`` -- a list of ideals of the number field. - - ``residues`` - a list of elements of the number field. + - ``residues`` -- a list of elements of the number field. OUTPUT: @@ -3580,25 +3619,25 @@ def idealchinese(self, ideals, residues): This is the example from the pari page on ``idealchinese``:: - sage: K. = NumberField(sqrt(2).minpoly()) - sage: ideals = [K.ideal(4),K.ideal(3)] - sage: residues = [sqrt2,1] - sage: r = K.idealchinese(ideals,residues); r + sage: K. = NumberField(sqrt(2).minpoly()) # optional - sage.symbolic + sage: ideals = [K.ideal(4), K.ideal(3)] # optional - sage.symbolic + sage: residues = [sqrt2, 1] # optional - sage.symbolic + sage: r = K.idealchinese(ideals, residues); r # optional - sage.symbolic -3*sqrt2 + 4 - sage: all((r - a) in I for I,a in zip(ideals,residues)) + sage: all((r - a) in I for I, a in zip(ideals, residues)) # optional - sage.symbolic True The result may be non-integral if the results are non-integral:: - sage: K. = NumberField(sqrt(2).minpoly()) - sage: ideals = [K.ideal(4),K.ideal(21)] - sage: residues = [1/sqrt2,1] - sage: r = K.idealchinese(ideals,residues); r + sage: K. = NumberField(sqrt(2).minpoly()) # optional - sage.symbolic + sage: ideals = [K.ideal(4), K.ideal(21)] # optional - sage.symbolic + sage: residues = [1/sqrt2, 1] # optional - sage.symbolic + sage: r = K.idealchinese(ideals, residues); r # optional - sage.symbolic -63/2*sqrt2 - 20 - sage: all( - ....: (r-a).valuation(P) >= k - ....: for I,a in zip(ideals,residues) - ....: for P,k in I.factor() + sage: all( # optional - sage.symbolic + ....: (r - a).valuation(P) >= k + ....: for I, a in zip(ideals, residues) + ....: for P, k in I.factor() ....: ) True """ @@ -3614,22 +3653,22 @@ def idealchinese(self, ideals, residues): def fractional_ideal(self, *gens, **kwds): r""" - Return the ideal in `\mathcal{O}_K` generated by gens. - This overrides the ``sage.rings.ring.Field`` method to - use the ``sage.rings.ring.Ring`` one instead, since + Return the ideal in `\mathcal{O}_K` generated by ``gens``. + This overrides the :class:`sage.rings.ring.Field` method to + use the :class:`sage.rings.ring.Ring` one instead, since we're not really concerned with ideals in a field but in its ring of integers. INPUT: - - ``gens`` - a list of generators, or a number field + - ``gens`` -- a list of generators, or a number field ideal. EXAMPLES:: - sage: K. = NumberField(x^3-2) + sage: K. = NumberField(x^3 - 2) sage: K.fractional_ideal([1/a]) Fractional ideal (1/2*a^2) @@ -3668,16 +3707,14 @@ def fractional_ideal(self, *gens, **kwds): return self._fractional_ideal_class_()(self, gens, **kwds) def ideals_of_bdd_norm(self, bound): - """ - All integral ideals of bounded norm. + r""" + Return all integral ideals of bounded norm. INPUT: + - ``bound`` -- a positive integer - - ``bound`` - a positive integer - - - OUTPUT: A dict of all integral ideals I such that Norm(I) <= bound, + OUTPUT: A dict of all integral ideals `I` such that Norm(`I`) `\leq` ``bound``, keyed by norm. EXAMPLES:: @@ -3726,19 +3763,19 @@ def ideals_of_bdd_norm(self, bound): def primes_above(self, x, degree=None): r""" - Return prime ideals of self lying over x. + Return prime ideals of ``self`` lying over `x`. INPUT: - - ``x``: usually an element or ideal of self. It - should be such that self.ideal(x) is sensible. This excludes x=0. + - ``x``: usually an element or ideal of ``self``. It + should be such that ``self.ideal(x)`` is sensible. This excludes `x=0`. - ``degree`` (default: ``None``): ``None`` or an integer. - If ``None``, find all primes above x of any degree. If an - integer, find all primes above x such that the resulting + If ``None``, find all primes above `x` of any degree. If an + integer, find all primes above `x` such that the resulting residue field has exactly this degree. - OUTPUT: A list of prime ideals of self lying over x. If degree + OUTPUT: A list of prime ideals of ``self`` lying over `x`. If ``degree`` is specified and no such ideal exists, returns the empty list. The output is sorted by residue degree first, then by underlying prime (or equivalently, by norm). @@ -3772,7 +3809,7 @@ def primes_above(self, x, degree=None): sage: [ P3.norm() for P3 in P3s ] [3] - The ideal (3) is totally ramified in F, so there is no degree 2 + The ideal `(3)` is totally ramified in `F`, so there is no degree 2 prime above 3:: sage: F.primes_above(3, degree=2) @@ -3811,7 +3848,7 @@ def primes_above(self, x, degree=None): sage: K.primes_above(I, degree=4) == [Q] True - It doesn't make sense to factor the ideal (0), so this raises an error:: + It doesn't make sense to factor the ideal `(0)`, so this raises an error:: sage: F.prime_above(0) Traceback (most recent call last): @@ -3829,20 +3866,20 @@ def primes_above(self, x, degree=None): def prime_above(self, x, degree=None): r""" - Return a prime ideal of self lying over x. + Return a prime ideal of ``self`` lying over `x`. INPUT: - - ``x``: usually an element or ideal of self. It - should be such that self.ideal(x) is sensible. This excludes x=0. + - ``x``: usually an element or ideal of ``self``. It + should be such that ``self.ideal(x)`` is sensible. This excludes `x=0`. - ``degree`` (default: ``None``): ``None`` or an integer. - If one, find a prime above x of any degree. If an integer, find a - prime above x such that the resulting residue field has exactly + If one, find a prime above `x` of any degree. If an integer, find a + prime above `x` such that the resulting residue field has exactly this degree. - OUTPUT: A prime ideal of self lying over x. If degree is specified - and no such ideal exists, raises a ValueError. + OUTPUT: A prime ideal of ``self`` lying over `x`. If ``degree`` is specified + and no such ideal exists, raises a :class:`ValueError`. EXAMPLES:: @@ -3873,8 +3910,8 @@ def prime_above(self, x, degree=None): sage: P3.norm() 3 - The ideal (3) is totally ramified in F, so there is no degree 2 - prime above 3:: + The ideal `(3)` is totally ramified in `F`, so there is no degree 2 + prime above `3`:: sage: F.prime_above(3, degree=2) Traceback (most recent call last): @@ -3905,7 +3942,7 @@ def prime_above(self, x, degree=None): sage: G.prime_above(7) Fractional ideal (b + 2) - It doesn't make sense to factor the ideal (0):: + It doesn't make sense to factor the ideal `(0)`:: sage: F.prime_above(0) Traceback (most recent call last): @@ -3945,10 +3982,11 @@ def primes_of_bounded_norm(self, B): sage: K. = QuadraticField(-1) sage: K.primes_of_bounded_norm(10) - [Fractional ideal (i + 1), Fractional ideal (-i - 2), Fractional ideal (2*i + 1), Fractional ideal (3)] + [Fractional ideal (i + 1), Fractional ideal (-i - 2), + Fractional ideal (2*i + 1), Fractional ideal (3)] sage: K.primes_of_bounded_norm(1) [] - sage: K. = NumberField(x^3-2) + sage: K. = NumberField(x^3 - 2) sage: P = K.primes_of_bounded_norm(30) sage: P [Fractional ideal (a), @@ -4054,17 +4092,15 @@ def primes_of_degree_one_iter(self, num_integer_primes=10000, max_iterations=100 INPUT: + - ``num_integer_primes (default: 10000)`` - an + integer. We try to find primes of absolute norm no greater than the + ``num_integer_primes``-th prime number. For example, if + ``num_integer_primes`` is 2, the largest norm found will be 3, since + the second prime is 3. - - ``num_integer_primes (default: 10000)`` - an - integer. We try to find primes of absolute norm no greater than the - num_integer_primes-th prime number. For example, if - num_integer_primes is 2, the largest norm found will be 3, since - the second prime is 3. - - - ``max_iterations (default: 100)`` - an integer. We - test max_iterations integers to find small primes before raising - StopIteration. - + - ``max_iterations (default: 100)`` - an integer. We + test ``max_iterations`` integers to find small primes before raising + :class:`StopIteration`. EXAMPLES:: @@ -4072,10 +4108,12 @@ def primes_of_degree_one_iter(self, num_integer_primes=10000, max_iterations=100 sage: it = K.primes_of_degree_one_iter() sage: Ps = [ next(it) for i in range(3) ] sage: Ps # random - [Fractional ideal (z^3 + z + 1), Fractional ideal (3*z^3 - z^2 + z - 1), Fractional ideal (2*z^3 - 3*z^2 + z - 2)] - sage: [ P.norm() for P in Ps ] # random + [Fractional ideal (z^3 + z + 1), + Fractional ideal (3*z^3 - z^2 + z - 1), + Fractional ideal (2*z^3 - 3*z^2 + z - 2)] + sage: [P.norm() for P in Ps] # random [11, 31, 41] - sage: [ P.residue_class_degree() for P in Ps ] + sage: [P.residue_class_degree() for P in Ps] [1, 1, 1] """ from sage.rings.number_field.small_primes_of_degree_one import Small_primes_of_degree_one_iter @@ -4083,13 +4121,13 @@ def primes_of_degree_one_iter(self, num_integer_primes=10000, max_iterations=100 def primes_of_degree_one_list(self, n, num_integer_primes=10000, max_iterations=100): r""" - Return a list of n prime ideals of absolute degree one and small + Return a list of `n` prime ideals of absolute degree one and small norm. .. warning:: It is possible that there are no primes of `K` of - absolute degree one of small prime norm, and it possible + absolute degree one of small prime norm, and it is possible that this algorithm will not find any primes of small norm. See module :mod:`sage.rings.number_field.small_primes_of_degree_one` @@ -4097,25 +4135,27 @@ def primes_of_degree_one_list(self, n, num_integer_primes=10000, max_iterations= INPUT: - - ``num_integer_primes (default: 10000)`` - an - integer. We try to find primes of absolute norm no greater than the - num_integer_primes-th prime number. For example, if - num_integer_primes is 2, the largest norm found will be 3, since - the second prime is 3. + - ``num_integer_primes`` -- (default: 10000) an + integer. We try to find primes of absolute norm no greater than the + ``num_integer_primes``-th prime number. For example, if + ``num_integer_primes`` is 2, the largest norm found will be 3, since + the second prime is 3. - - ``max_iterations (default: 100)`` - an integer. We - test max_iterations integers to find small primes before raising - ``StopIteration``. + - ``max_iterations`` -- (default: 100) an integer. We + test ``max_iterations`` integers to find small primes before raising + :class:`StopIteration`. EXAMPLES:: sage: K. = CyclotomicField(10) sage: Ps = K.primes_of_degree_one_list(3) sage: Ps # random output - [Fractional ideal (-z^3 - z^2 + 1), Fractional ideal (2*z^3 - 2*z^2 + 2*z - 3), Fractional ideal (2*z^3 - 3*z^2 + z - 2)] - sage: [ P.norm() for P in Ps ] + [Fractional ideal (-z^3 - z^2 + 1), + Fractional ideal (2*z^3 - 2*z^2 + 2*z - 3), + Fractional ideal (2*z^3 - 3*z^2 + z - 2)] + sage: [P.norm() for P in Ps] [11, 31, 41] - sage: [ P.residue_class_degree() for P in Ps ] + sage: [P.residue_class_degree() for P in Ps] [1, 1, 1] """ it = self.primes_of_degree_one_iter() @@ -4131,7 +4171,7 @@ def completely_split_primes(self, B=200): OUTPUT: - A list of all primes ``p < B`` which split completely in ``K``. + A list of all primes `p < B` which split completely in ``K``. EXAMPLES:: @@ -4158,7 +4198,7 @@ def _is_valid_homomorphism_(self, codomain, im_gens, base_map=None): images of generators. To do this we just check that the elements of the image of the - given generator (im_gens always has length 1) satisfies the + given generator (``im_gens`` always has length 1) satisfies the relation of the defining poly of this field. EXAMPLES:: @@ -4307,7 +4347,7 @@ def pari_nf(self, important=True): INPUT: - ``important`` -- boolean (default: ``True``). If ``False``, - raise a ``RuntimeError`` if we need to do a difficult + raise a :class:`RuntimeError` if we need to do a difficult discriminant factorization. This is useful when an integral basis is not strictly required, such as for factoring polynomials over this number field. @@ -4352,7 +4392,7 @@ def pari_nf(self, important=True): RuntimeError: Unable to factor discriminant with trial division Next, we illustrate the ``maximize_at_primes`` and ``assume_disc_small`` - parameters of the ``NumberField`` constructor. The following would take + parameters of the :class:`NumberField` constructor. The following would take a very long time without the ``maximize_at_primes`` option:: sage: K. = NumberField(x^2 - p*q, maximize_at_primes=[p]) @@ -4375,10 +4415,10 @@ def pari_nf(self, important=True): return self._pari_nf def pari_zk(self): - """ + r""" Integral basis of the PARI number field corresponding to this field. - This is the same as pari_nf().getattr('zk'), but much faster. + This is the same as ``pari_nf().getattr('zk')``, but much faster. EXAMPLES:: @@ -4476,7 +4516,7 @@ def pari_bnf(self, proof=None, units=True): def pari_rnfnorm_data(self, L, proof=True): """ Return the PARI :pari:`rnfisnorminit` data corresponding to the - extension L/self. + extension `L` / ``self``. EXAMPLES:: @@ -4500,18 +4540,17 @@ def pari_rnfnorm_data(self, L, proof=True): def _gap_init_(self): """ - Create a gap object representing self and return its name + Create a GAP object representing ``self`` and return its name. EXAMPLES:: sage: z = QQ['z'].0 sage: K. = NumberField(z^2 - 2) - sage: K._gap_init_() # the following variable name $sage1 represents the F.base_ring() in gap and is somehow random + sage: K._gap_init_() # the following variable name $sage1 represents the F.base_ring() in gap and is somehow random # optional - sage.libs.gap 'CallFuncList(function() local z,E; z:=Indeterminate($sage1,"z"); E:=AlgebraicExtension($sage1,z^2 - 2,"zeta"); return E; end,[])' - sage: k = gap(K) - sage: k + sage: k = gap(K); k # optional - sage.libs.gap - sage: k.GeneratorsOfDivisionRing() + sage: k.GeneratorsOfDivisionRing() # optional - sage.libs.gap [ zeta ] The following tests that it is possible to use a defining @@ -4521,11 +4560,11 @@ def _gap_init_(self): sage: P. = QQ[] sage: L. = NumberField(E^3 - 2) - sage: l = gap(L); l + sage: l = gap(L); l # optional - sage.libs.gap - sage: l.GeneratorsOfField() + sage: l.GeneratorsOfField() # optional - sage.libs.gap [ tau ] - sage: gap(tau)^3 + sage: gap(tau)^3 # optional - sage.libs.gap !2 """ if not self.is_absolute(): @@ -4558,14 +4597,12 @@ def class_group(self, proof=None, names='c'): INPUT: + - ``proof`` -- if ``True`` then compute the class group + provably correctly. Default is ``True``. Call :func:`number_field_proof` to + change this default globally. - - ``proof`` - if True then compute the class group - provably correctly. Default is True. Call number_field_proof to - change this default globally. - - - ``names`` - names of the generators of this class - group. - + - ``names`` -- names of the generators of this class + group. OUTPUT: The class group of this number field. @@ -4573,7 +4610,8 @@ def class_group(self, proof=None, names='c'): sage: K. = NumberField(x^2 + 23) sage: G = K.class_group(); G - Class group of order 3 with structure C3 of Number Field in a with defining polynomial x^2 + 23 + Class group of order 3 with structure C3 of + Number Field in a with defining polynomial x^2 + 23 sage: G.0 Fractional ideal class (2, 1/2*a - 1/2) sage: G.gens() @@ -4594,7 +4632,8 @@ def class_group(self, proof=None, names='c'): sage: k. = NumberField(x^2 + 20072) sage: G = k.class_group(); G - Class group of order 76 with structure C38 x C2 of Number Field in a with defining polynomial x^2 + 20072 + Class group of order 76 with structure C38 x C2 of + Number Field in a with defining polynomial x^2 + 20072 sage: G.0 # random Fractional ideal class (41, a + 10) sage: G.0^38 @@ -4635,10 +4674,8 @@ def class_number(self, proof=None): INPUT: - - - ``proof`` - bool (default: ``True`` unless you called - number_field_proof) - + - ``proof`` -- bool (default: ``True`` unless you called + ``number_field_proof``) EXAMPLES:: @@ -4658,17 +4695,15 @@ def S_class_group(self, S, proof=None, names='c'): INPUT: - - ``S`` - a set of primes of the base field + - ``S`` -- a set of primes of the base field - - ``proof`` - if False, assume the GRH in computing the class group. - Default is True. Call ``number_field_proof`` to change this + - ``proof`` -- if False, assume the GRH in computing the class group. + Default is ``True``. Call ``number_field_proof`` to change this default globally. - - ``names`` - names of the generators of this class group. - - OUTPUT: + - ``names`` -- names of the generators of this class group. - The S-class group of this number field. + OUTPUT: The S-class group of this number field. EXAMPLES: @@ -4676,7 +4711,8 @@ def S_class_group(self, S, proof=None, names='c'): sage: K. = QuadraticField(-5) sage: K.S_class_group([]) - S-class group of order 2 with structure C2 of Number Field in a with defining polynomial x^2 + 5 with a = 2.236067977499790?*I + S-class group of order 2 with structure C2 of Number Field in a + with defining polynomial x^2 + 5 with a = 2.236067977499790?*I When we include the prime `(2, a+1)`, the S-class group becomes trivial:: @@ -4687,15 +4723,18 @@ def S_class_group(self, S, proof=None, names='c'): TESTS:: sage: K. = QuadraticField(-14) - sage: I = K.ideal(2,a) + sage: I = K.ideal(2, a) sage: S = (I,) - sage: CS = K.S_class_group(S);CS - S-class group of order 2 with structure C2 of Number Field in a with defining polynomial x^2 + 14 with a = 3.741657386773942?*I + sage: CS = K.S_class_group(S); CS + S-class group of order 2 with structure C2 of Number Field in a + with defining polynomial x^2 + 14 with a = 3.741657386773942?*I sage: T = tuple() - sage: CT = K.S_class_group(T);CT - S-class group of order 4 with structure C4 of Number Field in a with defining polynomial x^2 + 14 with a = 3.741657386773942?*I + sage: CT = K.S_class_group(T); CT + S-class group of order 4 with structure C4 of Number Field in a + with defining polynomial x^2 + 14 with a = 3.741657386773942?*I sage: K.class_group() - Class group of order 4 with structure C4 of Number Field in a with defining polynomial x^2 + 14 with a = 3.741657386773942?*I + Class group of order 4 with structure C4 of Number Field in a + with defining polynomial x^2 + 14 with a = 3.741657386773942?*I """ proof = proof_flag(proof) if all(P.is_principal() for P in S): @@ -4716,19 +4755,18 @@ def S_units(self, S, proof=True): - ``proof`` -- if ``False``, assume the GRH in computing the class group - OUTPUT: - - A list of generators of the unit group. + OUTPUT: A list of generators of the unit group. .. note:: - For more functionality see the S_unit_group() function. + For more functionality see the function :func:`S_unit_group`. EXAMPLES:: sage: K. = QuadraticField(-3) sage: K.unit_group() - Unit group with structure C6 of Number Field in a with defining polynomial x^2 + 3 with a = 1.732050807568878?*I + Unit group with structure C6 of Number Field in a + with defining polynomial x^2 + 3 with a = 1.732050807568878?*I sage: K.S_units([]) # random [1/2*a + 1/2] sage: K.S_units([])[0].multiplicative_order() @@ -4754,7 +4792,7 @@ def S_units(self, S, proof=True): This checks that the multiple entries issue at :trac:`9341` is fixed:: sage: _. = QQ[] - sage: K. = NumberField(t-1) + sage: K. = NumberField(t - 1) sage: I = K.ideal(2) sage: K.S_units([I]) [2, -1] @@ -4772,17 +4810,15 @@ def _S_class_group_and_units(self, S, proof=True): INPUT: - - ``S`` - a tuple of prime ideals of self + - ``S`` -- a tuple of prime ideals of ``self`` - - ``proof`` - if False, assume the GRH in computing the class group + - ``proof`` -- if ``False``, assume the GRH in computing the class group OUTPUT: - - ``units, clgp_gens``, where: - - - ``units`` - A list of generators of the unit group. + - ``units`` -- A list of generators of the unit group. - - ``clgp_gens`` - A list of generators of the `S`-class group. + - ``clgp_gens`` -- A list of generators of the `S`-class group. Each generator is represented as a pair ``(gen, order)``, where ``gen`` is a fractional ideal of self and ``order`` is its order in the `S`-class group. @@ -4893,9 +4929,9 @@ def selmer_generators(self, S, m, proof=True, orders=False): - ``m`` -- a positive integer - - ``proof`` -- if False, assume the GRH in computing the class group + - ``proof`` -- if ``False``, assume the GRH in computing the class group - - ``orders`` (default False) -- if True, output two lists, the + - ``orders`` -- (default: ``False``) if ``True``, output two lists, the generators and their orders OUTPUT: @@ -4925,7 +4961,7 @@ def selmer_generators(self, S, m, proof=True, orders=False): :meth:`NumberField_generic.selmer_space`, which gives additional output when `m=p` is prime: as well as generators, - it gives an abstract vector space over `GF(p)` isomorphic to + it gives an abstract vector space over `\GF{p}` isomorphic to `K(S,p)` and maps implementing the isomorphism between this space and `K(S,p)` as a subgroup of `K^*/(K^*)^p`. @@ -4980,8 +5016,8 @@ def selmer_generators(self, S, m, proof=True, orders=False): TESTS:: sage: K. = QuadraticField(-5) - sage: P2 = K.ideal(2, -a+1) - sage: P3 = K.ideal(3, a+1) + sage: P2 = K.ideal(2, -a + 1) + sage: P3 = K.ideal(3, a + 1) sage: P5 = K.ideal(a) sage: S = K.selmer_generators([P2, P3, P5], 3) sage: S in ([2, a + 1, a], [2, a + 1, -a], [2, -a - 1, a], [2, -a - 1, -a]) or S @@ -5088,9 +5124,9 @@ def selmer_group_iterator(self, S, m, proof=True): [1, 2, -1, -2] sage: list(K.selmer_group_iterator((), 4)) [1, 4, -1, -4] - sage: list(K.selmer_group_iterator([K.ideal(2, -a+1)], 2)) + sage: list(K.selmer_group_iterator([K.ideal(2, -a + 1)], 2)) [1, -1, 2, -2] - sage: list(K.selmer_group_iterator([K.ideal(2, -a+1), K.ideal(3, a+1)], 2)) + sage: list(K.selmer_group_iterator([K.ideal(2, -a + 1), K.ideal(3, a + 1)], 2)) [1, -1, -a - 1, a + 1, 2, -2, -2*a - 2, 2*a + 2] Examples over `\QQ` (as a number field):: @@ -5201,7 +5237,7 @@ def selmer_space(self, S, p, proof=None): ....: if not v: ....: continue ....: a = fromKS2(v) - ....: print((a,K.extension(x^2-a, 'roota').relative_discriminant().factor())) + ....: print((a, K.extension(x^2 - a, 'roota').relative_discriminant().factor())) (2, (Fractional ideal (2, a + 1))^4) (-1, 1) (-2, (Fractional ideal (2, a + 1))^4) @@ -5356,12 +5392,15 @@ def composite_fields(self, other, names=None, both_maps=False, preserve_embeddin sage: L. = NumberField([x^3 - 5, x^2 + 3]) sage: CyclotomicField(3, 'w').composite_fields(L, both_maps=True) - [(Number Field in a with defining polynomial x^3 - 5 over its base field, Ring morphism: - From: Cyclotomic Field of order 3 and degree 2 - To: Number Field in a with defining polynomial x^3 - 5 over its base field - Defn: w |--> -1/2*b - 1/2, Relative number field endomorphism of Number Field in a with defining polynomial x^3 - 5 over its base field - Defn: a |--> a - b |--> b, None)] + [(Number Field in a with defining polynomial x^3 - 5 over its base field, + Ring morphism: + From: Cyclotomic Field of order 3 and degree 2 + To: Number Field in a with defining polynomial x^3 - 5 over its base field + Defn: w |--> -1/2*b - 1/2, + Relative number field endomorphism of Number Field in a with defining polynomial x^3 - 5 over its base field + Defn: a |--> a + b |--> b, + None)] Number fields defined by non-monic and non-integral polynomials are supported (:trac:`252`):: @@ -5420,7 +5459,8 @@ def composite_fields(self, other, names=None, both_maps=False, preserve_embeddin sage: A. = NumberField(x^3 - 7, embedding=CC(-0.95+1.65*I)) sage: B. = NumberField(y^9 - 7, embedding=CC(-1.16+0.42*I)) sage: A.composite_fields(B) - [Number Field in b with defining polynomial y^9 - 7 with b = -1.166502297945062? + 0.4245721146551276?*I] + [Number Field in b with defining polynomial y^9 - 7 + with b = -1.166502297945062? + 0.4245721146551276?*I] """ if not isinstance(other, NumberField_generic): raise TypeError("other must be a number field.") @@ -5602,7 +5642,7 @@ def absolute_degree(self): return self.polynomial().degree() def degree(self): - """ + r""" Return the degree of this number field. EXAMPLES:: @@ -5664,8 +5704,8 @@ def different(self): def discriminant(self, v=None): """ Return the discriminant of the ring of integers of the number - field, or if v is specified, the determinant of the trace pairing - on the elements of the list v. + field, or if ``v`` is specified, the determinant of the trace pairing + on the elements of the list ``v``. INPUT: @@ -5673,7 +5713,7 @@ def discriminant(self, v=None): OUTPUT: - Integer if `v` is omitted, and Rational otherwise. + Integer if ``v`` is omitted, and Rational otherwise. EXAMPLES:: @@ -5700,7 +5740,7 @@ def discriminant(self, v=None): def disc(self, v=None): """ - Shortcut for self.discriminant. + Shortcut for :meth:`discriminant`. EXAMPLES:: @@ -5736,7 +5776,7 @@ def elements_of_norm(self, n, proof=None) -> list: INPUT: - - `n` -- integer + - ``n`` -- integer - ``proof`` -- boolean (default: ``True``, unless you called :meth:`proof.number_field` and set it otherwise) @@ -5748,7 +5788,7 @@ def elements_of_norm(self, n, proof=None) -> list: EXAMPLES:: - sage: K. = NumberField(x^2+1) + sage: K. = NumberField(x^2 + 1) sage: K.elements_of_norm(3) [] sage: K.elements_of_norm(50) @@ -5789,7 +5829,7 @@ def extension(self, poly, name=None, names=None, latex_name=None, latex_names=No sage: m. = k.extension(y^2 + 2); m Number Field in b with defining polynomial y^2 + 2 over its base field - Note that b is a root of `y^2 + 2`:: + Note that `b` is a root of `y^2 + 2`:: sage: b.minpoly() x^2 + 2 @@ -5864,7 +5904,8 @@ def factor(self, n): sage: K.factor(1+a) Fractional ideal (a + 1) sage: K.factor(1+a/5) - (Fractional ideal (a + 1)) * (Fractional ideal (-a - 2))^-1 * (Fractional ideal (2*a + 1))^-1 * (Fractional ideal (-2*a + 3)) + (Fractional ideal (a + 1)) * (Fractional ideal (-a - 2))^-1 + * (Fractional ideal (2*a + 1))^-1 * (Fractional ideal (-2*a + 3)) An example over a relative number field:: @@ -5876,7 +5917,7 @@ def factor(self, n): sage: f.value() == a+1 True - It doesn't make sense to factor the ideal (0), so this raises an error:: + It doesn't make sense to factor the ideal `(0)`, so this raises an error:: sage: L.factor(0) Traceback (most recent call last): @@ -5916,7 +5957,9 @@ def prime_factors(self, x): sage: K. = NumberField(x^2 + 23) sage: K.prime_factors(w + 1) - [Fractional ideal (2, 1/2*w - 1/2), Fractional ideal (2, 1/2*w + 1/2), Fractional ideal (3, 1/2*w + 1/2)] + [Fractional ideal (2, 1/2*w - 1/2), + Fractional ideal (2, 1/2*w + 1/2), + Fractional ideal (3, 1/2*w + 1/2)] """ return self.ideal(x).prime_factors() @@ -5941,7 +5984,8 @@ def decomposition_type(self, p): EXAMPLES:: sage: R. = ZZ[] - sage: K. = NumberField(x^20 + 3*x^18 + 15*x^16 + 28*x^14 + 237*x^12 + 579*x^10 + 1114*x^8 + 1470*x^6 + 2304*x^4 + 1296*x^2 + 729) + sage: K. = NumberField(x^20 + 3*x^18 + 15*x^16 + 28*x^14 + 237*x^12 + 579*x^10 + ....: + 1114*x^8 + 1470*x^6 + 2304*x^4 + 1296*x^2 + 729) sage: K.is_galois() True sage: K.discriminant().factor() @@ -5955,7 +5999,8 @@ def decomposition_type(self, p): This example is only ramified at 11:: - sage: K. = NumberField(x^24 + 11^2*(90*x^12 - 640*x^8 + 2280*x^6 - 512*x^4 +2432/11*x^2 - 11)) + sage: K. = NumberField(x^24 + 11^2*(90*x^12 - 640*x^8 + 2280*x^6 + ....: - 512*x^4 + 2432/11*x^2 - 11)) sage: K.discriminant().factor() -1 * 11^43 sage: K.decomposition_type(11) @@ -5976,7 +6021,8 @@ def decomposition_type(self, p): It also works for relative extensions:: sage: K. = QuadraticField(-143) - sage: M. = K.extension(x^10 - 6*x^8 + (a + 12)*x^6 + (-7/2*a - 89/2)*x^4 + (13/2*a - 77/2)*x^2 + 25) + sage: M. = K.extension(x^10 - 6*x^8 + (a + 12)*x^6 + (-7/2*a - 89/2)*x^4 + ....: + (13/2*a - 77/2)*x^2 + 25) There is a unique prime above `11` and above `13` in `K`, each of which is unramified in `M`:: @@ -6027,7 +6073,7 @@ def gen(self, n=0): INPUT: - - ``n`` - must be 0 (the default), or an exception is + - ``n`` -- must be 0 (the default), or an exception is raised. @@ -6088,7 +6134,7 @@ def _generator_matrix(self): def is_field(self, proof=True): """ - Return True since a number field is a field. + Return ``True`` since a number field is a field. EXAMPLES:: @@ -6100,7 +6146,7 @@ def is_field(self, proof=True): @cached_method def is_galois(self): r""" - Return True if this number field is a Galois extension of + Return ``True`` if this number field is a Galois extension of `\QQ`. EXAMPLES:: @@ -6109,9 +6155,15 @@ def is_galois(self): True sage: NumberField(x^3 + 2, 'a').is_galois() False - sage: NumberField(x^15 + x^14 - 14*x^13 - 13*x^12 + 78*x^11 + 66*x^10 - 220*x^9 - 165*x^8 + 330*x^7 + 210*x^6 - 252*x^5 - 126*x^4 + 84*x^3 + 28*x^2 - 8*x - 1, 'a').is_galois() + sage: K = NumberField(x^15 + x^14 - 14*x^13 - 13*x^12 + 78*x^11 + 66*x^10 + ....: - 220*x^9 - 165*x^8 + 330*x^7 + 210*x^6 - 252*x^5 + ....: - 126*x^4 + 84*x^3 + 28*x^2 - 8*x - 1, 'a') + sage: K.is_galois() True - sage: NumberField(x^15 + x^14 - 14*x^13 - 13*x^12 + 78*x^11 + 66*x^10 - 220*x^9 - 165*x^8 + 330*x^7 + 210*x^6 - 252*x^5 - 126*x^4 + 84*x^3 + 28*x^2 - 8*x - 10, 'a').is_galois() + sage: K = NumberField(x^15 + x^14 - 14*x^13 - 13*x^12 + 78*x^11 + 66*x^10 + ....: - 220*x^9 - 165*x^8 + 330*x^7 + 210*x^6 - 252*x^5 + ....: - 126*x^4 + 84*x^3 + 28*x^2 - 8*x - 10, 'a') + sage: K.is_galois() False """ return self.galois_group().is_galois() @@ -6119,7 +6171,7 @@ def is_galois(self): @cached_method def is_abelian(self): r""" - Return True if this number field is an abelian Galois extension of + Return ``True`` if this number field is an abelian Galois extension of `\QQ`. EXAMPLES:: @@ -6156,23 +6208,23 @@ def galois_group(self, type=None, algorithm='pari', names=None, gc_numbering=Non INPUT: - - ``type`` - Deprecated; the different versions of Galois groups have been - merged in :trac:`28782`. + - ``type`` -- Deprecated; the different versions of Galois groups have been + merged in :trac:`28782`. - - ``algorithm`` - 'pari', 'gap', 'kash', 'magma'. (default: 'pari'; - for degrees between 12 and 15 default is 'gap', and - when the degree is >= 16 it is 'kash'.) + - ``algorithm`` -- ``'pari'``, ``'gap'``, ``'kash'``, ``'magma'``. (default: ``'pari'``; + for degrees between 12 and 15 default is ``'gap'``, and + when the degree is >= 16 it is ``'kash'``.) - - ``names`` - a string giving a name for the generator of the Galois - closure of self, when this field is not Galois. + - ``names`` -- a string giving a name for the generator of the Galois + closure of ``self``, when this field is not Galois. - - ``gc_numbering`` -- if ``True``, permutations will be written - in terms of the action on the roots of a defining polynomial - for the Galois closure, rather than the defining polynomial for - the original number field. This is significantly faster; - but not the standard way of presenting Galois groups. - The default currently depends on the algorithm (``True`` for ``'pari'``, - ``False`` for ``'magma'``) and may change in the future. + - ``gc_numbering`` -- if ``True``, permutations will be written + in terms of the action on the roots of a defining polynomial + for the Galois closure, rather than the defining polynomial for + the original number field. This is significantly faster; + but not the standard way of presenting Galois groups. + The default currently depends on the algorithm (``True`` for ``'pari'``, + ``False`` for ``'magma'``) and may change in the future. The resulting group will only compute with automorphisms when necessary, so certain functions (such as :meth:`sage.rings.number_field.galois_group.GaloisGroup_v2.order`) @@ -6183,7 +6235,7 @@ def galois_group(self, type=None, algorithm='pari', names=None, gc_numbering=Non EXAMPLES:: - sage: k. = NumberField(x^2 - 14) # a Galois extension + sage: k. = NumberField(x^2 - 14) # a Galois extension sage: G = k.galois_group(); G Galois group 2T1 (S2) with order 2 of x^2 - 14 sage: G.gen(0) @@ -6200,7 +6252,8 @@ def galois_group(self, type=None, algorithm='pari', names=None, gc_numbering=Non (1,2,3)(4,5,6) sage: NumberField(x^3 + 2*x + 1, 'a').galois_group(algorithm='magma') # optional - magma - Galois group Transitive group number 2 of degree 3 of the Number Field in a with defining polynomial x^3 + 2*x + 1 + Galois group Transitive group number 2 of degree 3 + of the Number Field in a with defining polynomial x^3 + 2*x + 1 EXPLICIT GALOIS GROUP: We compute the Galois group as an explicit group of automorphisms of the Galois closure of a field. @@ -6237,7 +6290,8 @@ def galois_group(self, type=None, algorithm='pari', names=None, gc_numbering=Non sage: R. = PolynomialRing(K) sage: L = K.extension(t^5-t+a, 'b') sage: L.galois_group() - ...DeprecationWarning: Use .absolute_field().galois_group() if you want the Galois group of the absolute field + ...DeprecationWarning: Use .absolute_field().galois_group() + if you want the Galois group of the absolute field See https://github.com/sagemath/sage/issues/28782 for details. Galois group 10T22 (S(5)[x]2) with order 240 of t^5 - t + a @@ -6261,7 +6315,7 @@ def galois_group(self, type=None, algorithm='pari', names=None, gc_numbering=Non def _normalize_prime_list(self, v): """ - Internal function to convert into a tuple of primes either None or + Internal function to convert into a tuple of primes either ``None`` or a single prime or a list. EXAMPLES:: @@ -6323,13 +6377,13 @@ def power_basis(self): def integral_basis(self, v=None): """ - Return a list containing a ZZ-basis for the full ring of integers + Return a list containing a ``ZZ``-basis for the full ring of integers of this number field. INPUT: - - ``v`` - None, a prime, or a list of primes. See the - documentation for self.maximal_order. + - ``v`` -- ``None``, a prime, or a list of primes. See the + documentation for :meth:`maximal_order`. EXAMPLES:: @@ -6347,7 +6401,7 @@ def integral_basis(self, v=None): sage: K.integral_basis() [1, 1/2*a^2 + 1/2*a, a^2] - ALGORITHM: Uses the pari library (via _pari_integral_basis). + ALGORITHM: Uses the PARI library (via :pari:`_pari_integral_basis`). """ return self.maximal_order(v=v).basis() @@ -6358,11 +6412,11 @@ def _pari_integral_basis(self, v=None, important=True): INPUT: - - ``v`` -- None, a prime, or a list of primes. See the - documentation for self.maximal_order. + - ``v`` -- ``None``, a prime, or a list of primes. See the + documentation for :meth:``maximal_order``. - ``important`` -- boolean (default: ``True``). If ``False``, - raise a ``RuntimeError`` if we need to do a difficult + raise a :class:`RuntimeError` if we need to do a difficult discriminant factorization. This is useful when an integral basis is not strictly required. @@ -6450,11 +6504,14 @@ def reduced_basis(self, prec=None): EXAMPLES:: - sage: F. = NumberField(x^6-7*x^4-x^3+11*x^2+x-1) + sage: F. = NumberField(x^6 - 7*x^4 - x^3 + 11*x^2 + x - 1) sage: F.maximal_order().basis() [1/2*t^5 + 1/2*t^4 + 1/2*t^2 + 1/2, t, t^2, t^3, t^4, t^5] sage: F.reduced_basis() - [-1, -1/2*t^5 + 1/2*t^4 + 3*t^3 - 3/2*t^2 - 4*t - 1/2, t, 1/2*t^5 + 1/2*t^4 - 4*t^3 - 5/2*t^2 + 7*t + 1/2, 1/2*t^5 - 1/2*t^4 - 2*t^3 + 3/2*t^2 - 1/2, 1/2*t^5 - 1/2*t^4 - 3*t^3 + 5/2*t^2 + 4*t - 5/2] + [-1, -1/2*t^5 + 1/2*t^4 + 3*t^3 - 3/2*t^2 - 4*t - 1/2, t, + 1/2*t^5 + 1/2*t^4 - 4*t^3 - 5/2*t^2 + 7*t + 1/2, + 1/2*t^5 - 1/2*t^4 - 2*t^3 + 3/2*t^2 - 1/2, + 1/2*t^5 - 1/2*t^4 - 3*t^3 + 5/2*t^2 + 4*t - 5/2] sage: CyclotomicField(12).reduced_basis() [1, zeta12^2, zeta12, zeta12^3] @@ -6504,9 +6561,9 @@ def reduced_gram_matrix(self, prec=None): to calculate the Minkowski embedding. (See NOTE below.) OUTPUT: The Gram matrix `[\langle x_i,x_j \rangle]` of an LLL reduced - basis for the maximal order of self, where the integral basis for - self is given by `\{x_0, \dots, x_{n-1}\}`. Here `\langle , \rangle` is - the usual inner product on `\RR^n`, and self is embedded in `\RR^n` by + basis for the maximal order of ``self``, where the integral basis for + ``self`` is given by `\{x_0, \dots, x_{n-1}\}`. Here `\langle , \rangle` is + the usual inner product on `\RR^n`, and ``self`` is embedded in `\RR^n` by the Minkowski embedding. See the docstring for :meth:`NumberField_absolute.minkowski_embedding` for more information. @@ -6517,16 +6574,16 @@ def reduced_gram_matrix(self, prec=None): approximations, and so the result is only as good as the precision promised by PARI. In particular, in this case, the returned matrix will *not* be integral, and may not - have enough precision to recover the correct gram matrix + have enough precision to recover the correct Gram matrix (which is known to be integral for theoretical - reasons). Thus the need for the prec flag above. + reasons). Thus the need for the ``prec`` parameter above. If the following run-time error occurs: "PariError: not a definite - matrix in lllgram (42)" try increasing the prec parameter, + matrix in lllgram (42)", try increasing the ``prec`` parameter, EXAMPLES:: - sage: F. = NumberField(x^6-7*x^4-x^3+11*x^2+x-1) + sage: F. = NumberField(x^6 - 7*x^4 - x^3 + 11*x^2 + x - 1) sage: F.reduced_gram_matrix() [ 6 3 0 2 0 1] [ 3 9 0 1 0 -2] @@ -6534,7 +6591,8 @@ def reduced_gram_matrix(self, prec=None): [ 2 1 6 16 -3 3] [ 0 0 -2 -3 16 6] [ 1 -2 3 3 6 19] - sage: Matrix(6, [(x*y).trace() for x in F.integral_basis() for y in F.integral_basis()]) + sage: Matrix(6, [(x*y).trace() + ....: for x in F.integral_basis() for y in F.integral_basis()]) [2550 133 259 664 1368 3421] [ 133 14 3 54 30 233] [ 259 3 54 30 233 217] @@ -6545,7 +6603,7 @@ def reduced_gram_matrix(self, prec=None): :: sage: x = polygen(QQ) - sage: F. = NumberField(x^4+x^2+712312*x+131001238) + sage: F. = NumberField(x^4 + x^2 + 712312*x + 131001238) sage: F.reduced_gram_matrix(prec=128) [ 4.0000000000000000000000000000000000000 0.00000000000000000000000000000000000000 -1.9999999999999999999999999999999999037 -0.99999999999999999999999999999999383702] [ 0.00000000000000000000000000000000000000 46721.539331563218381658483353092335550 -11488.910026551724275122749703614966768 -418.12718083977141198754424579680468382] @@ -6604,10 +6662,10 @@ def _positive_integral_elements_with_trace(self, C): EXAMPLES:: - sage: K. = NumberField(ZZ['x'].0^2-2) + sage: K. = NumberField(ZZ['x'].0^2 - 2) sage: K._positive_integral_elements_with_trace([0,5]) [alpha + 2, -alpha + 2, 2, 1] - sage: L. = NumberField(ZZ['x'].0^2+1) + sage: L. = NumberField(ZZ['x'].0^2 + 1) sage: L._positive_integral_elements_with_trace([5,11]) Traceback (most recent call last): ... @@ -6644,12 +6702,12 @@ def narrow_class_group(self, proof=None): INPUT: - - ``proof`` - default: ``None`` (use the global proof + - ``proof`` -- default: ``None`` (use the global proof setting, which defaults to ``True``). EXAMPLES:: - sage: NumberField(x^3+x+9, 'a').narrow_class_group() + sage: NumberField(x^3 + x + 9, 'a').narrow_class_group() Multiplicative Abelian group isomorphic to C2 TESTS:: @@ -6707,7 +6765,7 @@ def absolute_polynomial_ntl(self): return self.polynomial_ntl() def polynomial_ntl(self): - """ + r""" Return defining polynomial of this number field as a pair, an ntl polynomial and a denominator. @@ -6728,11 +6786,10 @@ def polynomial_ntl(self): return (self.__polynomial_ntl, self.__denominator_ntl) def polynomial(self): - """ + r""" Return the defining polynomial of this number field. - This is exactly the same as - ``self.defining_polynomial()``. + This is exactly the same as :meth:`defining_polynomial`. EXAMPLES:: @@ -6742,10 +6799,10 @@ def polynomial(self): return self.__polynomial def defining_polynomial(self): # do not overload this -- overload polynomial instead - """ + r""" Return the defining polynomial of this number field. - This is exactly the same as ``self.polynomial()``. + This is exactly the same as :meth:`polynomial`. EXAMPLES:: @@ -6761,7 +6818,7 @@ def defining_polynomial(self): # do not overload this -- overload polynomial i return self.polynomial() def polynomial_ring(self): - """ + r""" Return the polynomial ring that we view this number field as being a quotient of (by a principal ideal). @@ -6779,12 +6836,13 @@ def polynomial_ring(self): sage: M. = NumberField([y^3 + 97, y^2 + 1]); M Number Field in a0 with defining polynomial y^3 + 97 over its base field sage: M.polynomial_ring() - Univariate Polynomial Ring in y over Number Field in a1 with defining polynomial y^2 + 1 + Univariate Polynomial Ring in y over + Number Field in a1 with defining polynomial y^2 + 1 """ return self.relative_polynomial().parent() def polynomial_quotient_ring(self): - """ + r""" Return the polynomial quotient ring isomorphic to this number field. @@ -6792,12 +6850,13 @@ def polynomial_quotient_ring(self): sage: K = NumberField(x^3 + 2*x - 5, 'alpha') sage: K.polynomial_quotient_ring() - Univariate Quotient Polynomial Ring in alpha over Rational Field with modulus x^3 + 2*x - 5 + Univariate Quotient Polynomial Ring in alpha over Rational Field + with modulus x^3 + 2*x - 5 """ return self.polynomial_ring().quotient(self.relative_polynomial(), self.variable_name()) def regulator(self, proof=None): - """ + r""" Return the regulator of this number field. Note that PARI computes the regulator to higher precision than the @@ -6805,13 +6864,13 @@ def regulator(self, proof=None): INPUT: - - ``proof`` - default: ``True``, unless you set it otherwise. + - ``proof`` -- default: ``True``, unless you set it otherwise. EXAMPLES:: - sage: NumberField(x^2-2, 'a').regulator() + sage: NumberField(x^2 - 2, 'a').regulator() 0.881373587019543 - sage: NumberField(x^4+x^3+x^2+x+1, 'a').regulator() + sage: NumberField(x^4 + x^3 + x^2 + x + 1, 'a').regulator() 0.962423650119207 """ proof = proof_flag(proof) @@ -6824,30 +6883,27 @@ def regulator(self, proof=None): return self.__regulator def residue_field(self, prime, names=None, check=True): - """ + r""" Return the residue field of this number field at a given prime, ie `O_K / p O_K`. INPUT: + - ``prime`` -- a prime ideal of the maximal order in + this number field, or an element of the field which generates a + principal prime ideal. - - ``prime`` - a prime ideal of the maximal order in - this number field, or an element of the field which generates a - principal prime ideal. - - - ``names`` - the name of the variable in the residue - field - - - ``check`` - whether or not to check the primality of - prime. + - ``names`` -- the name of the variable in the residue + field + - ``check`` -- whether or not to check the primality of ``prime``. OUTPUT: The residue field at this prime. EXAMPLES:: sage: R. = QQ[] - sage: K. = NumberField(x^4+3*x^2-17) + sage: K. = NumberField(x^4 + 3*x^2 - 17) sage: P = K.ideal(61).factor()[0][0] sage: K.residue_field(P) Residue field in abar of Fractional ideal (61, a^2 + 30) @@ -6894,8 +6950,8 @@ def residue_field(self, prime, names=None, check=True): return ResidueField(prime, names=names, check=False) def signature(self): - """ - Return (r1, r2), where r1 and r2 are the number of real embeddings + r""" + Return `(r_1, r_2)`, where `r_1` and `r_2` are the number of real embeddings and pairs of complex embeddings of this field, respectively. EXAMPLES:: @@ -6909,14 +6965,14 @@ def signature(self): return (ZZ(r1), ZZ(r2)) def trace_pairing(self, v): - """ + r""" Return the matrix of the trace pairing on the elements of the list - `v`. + ``v``. EXAMPLES:: sage: K. = NumberField(x^2 + 3) - sage: K.trace_pairing([1,zeta3]) + sage: K.trace_pairing([1, zeta3]) [ 2 0] [ 0 -6] """ @@ -6931,31 +6987,31 @@ def trace_pairing(self, v): def uniformizer(self, P, others="positive"): """ - Return an element of self with valuation 1 at the prime ideal P. + Return an element of ``self`` with valuation 1 at the prime ideal `P`. INPUT: - - ``self`` - a number field + - ``self`` -- a number field - - ``P`` - a prime ideal of self + - ``P`` -- a prime ideal of ``self`` - - ``others`` - either "positive" (default), in which + - ``others`` -- either ``"positive"`` (default), in which case the element will have non-negative valuation at all other - primes of self, or "negative", in which case the element will have - non-positive valuation at all other primes of self. + primes of ``self``, or ``"negative"``, in which case the element will have + non-positive valuation at all other primes of ``self``. .. note:: - When P is principal (e.g. always when self has class number - one) the result may or may not be a generator of P! + When `P` is principal (e.g., always when ``self`` has class number + one) the result may or may not be a generator of `P`! EXAMPLES:: sage: K. = NumberField(x^2 + 5); K Number Field in a with defining polynomial x^2 + 5 - sage: P,Q = K.ideal(3).prime_factors() + sage: P, Q = K.ideal(3).prime_factors() sage: P Fractional ideal (3, a + 1) sage: pi = K.uniformizer(P); pi @@ -6970,11 +7026,11 @@ def uniformizer(self, P, others="positive"): :: sage: K = CyclotomicField(9) - sage: Plist=K.ideal(17).prime_factors() + sage: Plist = K.ideal(17).prime_factors() sage: pilist = [K.uniformizer(P) for P in Plist] sage: [pi.is_integral() for pi in pilist] [True, True, True] - sage: [pi.valuation(P) for pi,P in zip(pilist,Plist)] + sage: [pi.valuation(P) for pi, P in zip(pilist, Plist)] [1, 1, 1] sage: [ pilist[i] in Plist[i] for i in range(len(Plist)) ] [True, True, True] @@ -6997,7 +7053,7 @@ def uniformizer(self, P, others="positive"): Use PARI. More precisely, use the second component of :pari:`idealprimedec` in the "positive" case. Use :pari:`idealappr` - with exponent of -1 and invert the result in the "negative" + with exponent of `-1` and invert the result in the "negative" case. TESTS: @@ -7029,11 +7085,11 @@ def units(self, proof=None): INPUT: - - ``proof`` (bool, default True) flag passed to ``pari``. + - ``proof`` (bool, default ``True``) flag passed to PARI. .. note:: - For more functionality see the unit_group() function. + For more functionality see :meth:`unit_group`. .. SEEALSO:: @@ -7111,7 +7167,7 @@ def unit_group(self, proof=None): INPUT: - - ``proof`` (bool, default True) flag passed to ``pari``. + - ``proof`` (bool, default ``True``) flag passed to PARI. .. note:: @@ -7129,7 +7185,8 @@ def unit_group(self, proof=None): sage: A = x^4 - 10*x^3 + 20*5*x^2 - 15*5^2*x + 11*5^3 sage: K = NumberField(A, 'a') sage: U = K.unit_group(); U - Unit group with structure C10 x Z of Number Field in a with defining polynomial x^4 - 10*x^3 + 100*x^2 - 375*x + 1375 + Unit group with structure C10 x Z of Number Field in a + with defining polynomial x^4 - 10*x^3 + 100*x^2 - 375*x + 1375 sage: U.gens() (u0, u1) sage: U.gens_values() # random @@ -7149,11 +7206,20 @@ def unit_group(self, proof=None): ... sage: U = K.unit_group(proof=False) sage: U - Unit group with structure C2 x Z x Z x Z x Z x Z x Z x Z x Z of Number Field in a with defining polynomial x^17 + 3 + Unit group with structure C2 x Z x Z x Z x Z x Z x Z x Z x Z of + Number Field in a with defining polynomial x^17 + 3 sage: U.gens() (u0, u1, u2, u3, u4, u5, u6, u7, u8) sage: U.gens_values() # result not independently verified - [-1, -a^9 - a + 1, -a^16 + a^15 - a^14 + a^12 - a^11 + a^10 + a^8 - a^7 + 2*a^6 - a^4 + 3*a^3 - 2*a^2 + 2*a - 1, 2*a^16 - a^14 - a^13 + 3*a^12 - 2*a^10 + a^9 + 3*a^8 - 3*a^6 + 3*a^5 + 3*a^4 - 2*a^3 - 2*a^2 + 3*a + 4, a^15 + a^14 + 2*a^11 + a^10 - a^9 + a^8 + 2*a^7 - a^5 + 2*a^3 - a^2 - 3*a + 1, -a^16 - a^15 - a^14 - a^13 - a^12 - a^11 - a^10 - a^9 - a^8 - a^7 - a^6 - a^5 - a^4 - a^3 - a^2 + 2, -2*a^16 + 3*a^15 - 3*a^14 + 3*a^13 - 3*a^12 + a^11 - a^9 + 3*a^8 - 4*a^7 + 5*a^6 - 6*a^5 + 4*a^4 - 3*a^3 + 2*a^2 + 2*a - 4, a^15 - a^12 + a^10 - a^9 - 2*a^8 + 3*a^7 + a^6 - 3*a^5 + a^4 + 4*a^3 - 3*a^2 - 2*a + 2, 2*a^16 + a^15 - a^11 - 3*a^10 - 4*a^9 - 4*a^8 - 4*a^7 - 5*a^6 - 7*a^5 - 8*a^4 - 6*a^3 - 5*a^2 - 6*a - 7] + [-1, + -a^9 - a + 1, + -a^16 + a^15 - a^14 + a^12 - a^11 + a^10 + a^8 - a^7 + 2*a^6 - a^4 + 3*a^3 - 2*a^2 + 2*a - 1, + 2*a^16 - a^14 - a^13 + 3*a^12 - 2*a^10 + a^9 + 3*a^8 - 3*a^6 + 3*a^5 + 3*a^4 - 2*a^3 - 2*a^2 + 3*a + 4, + a^15 + a^14 + 2*a^11 + a^10 - a^9 + a^8 + 2*a^7 - a^5 + 2*a^3 - a^2 - 3*a + 1, + -a^16 - a^15 - a^14 - a^13 - a^12 - a^11 - a^10 - a^9 - a^8 - a^7 - a^6 - a^5 - a^4 - a^3 - a^2 + 2, + -2*a^16 + 3*a^15 - 3*a^14 + 3*a^13 - 3*a^12 + a^11 - a^9 + 3*a^8 - 4*a^7 + 5*a^6 - 6*a^5 + 4*a^4 - 3*a^3 + 2*a^2 + 2*a - 4, + a^15 - a^12 + a^10 - a^9 - 2*a^8 + 3*a^7 + a^6 - 3*a^5 + a^4 + 4*a^3 - 3*a^2 - 2*a + 2, + 2*a^16 + a^15 - a^11 - 3*a^10 - 4*a^9 - 4*a^8 - 4*a^7 - 5*a^6 - 7*a^5 - 8*a^4 - 6*a^3 - 5*a^2 - 6*a - 7] """ proof = proof_flag(proof) @@ -7177,7 +7243,7 @@ def unit_group(self, proof=None): def S_unit_group(self, proof=None, S=None): """ - Return the S-unit group (including torsion) of this number field. + Return the `S`-unit group (including torsion) of this number field. ALGORITHM: Uses PARI's :pari:`bnfsunit` command. @@ -7185,10 +7251,10 @@ def S_unit_group(self, proof=None, S=None): - ``proof`` (bool, default True) flag passed to ``pari``. - - ``S`` - list or tuple of prime ideals, or an ideal, or a single + - ``S`` -- list or tuple of prime ideals, or an ideal, or a single ideal or element from which an ideal can be constructed, in - which case the support is used. If None, the global unit - group is constructed; otherwise, the S-unit group is + which case the support is used. If ``None``, the global unit + group is constructed; otherwise, the `S`-unit group is constructed. .. note:: @@ -7200,17 +7266,22 @@ def S_unit_group(self, proof=None, S=None): sage: x = polygen(QQ) sage: K. = NumberField(x^4 - 10*x^3 + 20*5*x^2 - 15*5^2*x + 11*5^3) sage: U = K.S_unit_group(S=a); U - S-unit group with structure C10 x Z x Z x Z of Number Field in a with defining polynomial x^4 - 10*x^3 + 100*x^2 - 375*x + 1375 with S = (Fractional ideal (5, 1/275*a^3 + 4/55*a^2 - 5/11*a + 5), Fractional ideal (11, 1/275*a^3 + 4/55*a^2 - 5/11*a + 9)) + S-unit group with structure C10 x Z x Z x Z of + Number Field in a with defining polynomial x^4 - 10*x^3 + 100*x^2 - 375*x + 1375 + with S = (Fractional ideal (5, 1/275*a^3 + 4/55*a^2 - 5/11*a + 5), + Fractional ideal (11, 1/275*a^3 + 4/55*a^2 - 5/11*a + 9)) sage: U.gens() (u0, u1, u2, u3) sage: U.gens_values() # random - [-1/275*a^3 + 7/55*a^2 - 6/11*a + 4, 1/275*a^3 + 4/55*a^2 - 5/11*a + 3, 1/275*a^3 + 4/55*a^2 - 5/11*a + 5, -14/275*a^3 + 21/55*a^2 - 29/11*a + 6] + [-1/275*a^3 + 7/55*a^2 - 6/11*a + 4, 1/275*a^3 + 4/55*a^2 - 5/11*a + 3, + 1/275*a^3 + 4/55*a^2 - 5/11*a + 5, -14/275*a^3 + 21/55*a^2 - 29/11*a + 6] sage: U.invariants() (10, 0, 0, 0) sage: [u.multiplicative_order() for u in U.gens()] [10, +Infinity, +Infinity, +Infinity] sage: U.primes() - (Fractional ideal (5, 1/275*a^3 + 4/55*a^2 - 5/11*a + 5), Fractional ideal (11, 1/275*a^3 + 4/55*a^2 - 5/11*a + 9)) + (Fractional ideal (5, 1/275*a^3 + 4/55*a^2 - 5/11*a + 5), + Fractional ideal (11, 1/275*a^3 + 4/55*a^2 - 5/11*a + 9)) With the default value of `S`, the S-unit group is the same as the global unit group:: @@ -7226,20 +7297,20 @@ def S_unit_group(self, proof=None, S=None): sage: K. = NumberField(x^3 + 3) sage: U = K.S_unit_group(proof=False, S=K.ideal(6).prime_factors()); U - S-unit group with structure C2 x Z x Z x Z x Z of Number Field in a with defining polynomial x^3 + 3 with S = (Fractional ideal (-a^2 + a - 1), Fractional ideal (a + 1), Fractional ideal (a)) + S-unit group with structure C2 x Z x Z x Z x Z of Number Field in a with defining polynomial x^3 + 3 + with S = (Fractional ideal (-a^2 + a - 1), Fractional ideal (a + 1), Fractional ideal (a)) sage: K. = NumberField(x^3 + 3) sage: U = K.S_unit_group(proof=False, S=K.ideal(6)); U - S-unit group with structure C2 x Z x Z x Z x Z of Number Field in a with defining polynomial x^3 + 3 with S = (Fractional ideal (-a^2 + a - 1), Fractional ideal (a + 1), Fractional ideal (a)) + S-unit group with structure C2 x Z x Z x Z x Z of Number Field in a with defining polynomial x^3 + 3 + with S = (Fractional ideal (-a^2 + a - 1), Fractional ideal (a + 1), Fractional ideal (a)) sage: K. = NumberField(x^3 + 3) sage: U = K.S_unit_group(proof=False, S=6); U - S-unit group with structure C2 x Z x Z x Z x Z of Number Field in a with defining polynomial x^3 + 3 with S = (Fractional ideal (-a^2 + a - 1), Fractional ideal (a + 1), Fractional ideal (a)) - - sage: U - S-unit group with structure C2 x Z x Z x Z x Z of Number Field in a with defining polynomial x^3 + 3 with S = (Fractional ideal (-a^2 + a - 1), Fractional ideal (a + 1), Fractional ideal (a)) + S-unit group with structure C2 x Z x Z x Z x Z of Number Field in a with defining polynomial x^3 + 3 + with S = (Fractional ideal (-a^2 + a - 1), Fractional ideal (a + 1), Fractional ideal (a)) sage: U.primes() (Fractional ideal (-a^2 + a - 1), - Fractional ideal (a + 1), - Fractional ideal (a)) + Fractional ideal (a + 1), + Fractional ideal (a)) sage: U.gens() (u0, u1, u2, u3, u4) sage: U.gens_values() @@ -7303,7 +7374,7 @@ def S_unit_group(self, proof=None, S=None): def S_unit_solutions(self, S=[], prec=106, include_exponents=False, include_bound=False, proof=None): r""" - Return all solutions to the S-unit equation ``x + y = 1`` over K. + Return all solutions to the `S`-unit equation `x + y = 1` over ``self``. INPUT: @@ -7315,19 +7386,24 @@ def S_unit_solutions(self, S=[], prec=106, include_exponents=False, include_boun OUTPUT: - A list of tuples ``[( A_1, B_1, x_1, y_1), (A_2, B_2, x_2, y_2), ... ( A_n, B_n, x_n, y_n)]`` such that: + A list `[(A_1, B_1, x_1, y_1), (A_2, B_2, x_2, y_2), \dots, (A_n, B_n, x_n, y_n)]` of tuples such that: + + 1. The first two entries are tuples `A_i = (a_0, a_1, \dots, a_t)` and `B_i = (b_0, b_1, \dots, b_t)` of exponents. + These will be omitted if ``include_exponents`` is ``False``. + + 2. The last two entries are `S`-units `x_i` and `y_i` in ``self`` with `x_i + y_i = 1`. - 1. The first two entries are tuples ``A_i = (a_0, a_1, ... , a_t)`` and ``B_i = (b_0, b_1, ... , b_t)`` of exponents. These will be omitted if ``include_exponents`` is ``False``. - 2. The last two entries are ``S``-units ``x_i`` and ``y_i`` in ``K`` with ``x_i + y_i = 1``. - 3. If the default generators for the ``S``-units of ``K`` are ``(rho_0, rho_1, ... , rho_t)``, then these satisfy ``x_i = \prod(rho_i)^(a_i)`` and ``y_i = \prod(rho_i)^(b_i)``. + 3. If the default generators for the `S`-units of ``self`` are `(\rho_0, \rho_1, \dots, \rho_t)``, + then these satisfy `x_i = \prod(\rho_i)^{(a_i)}` and `y_i = \prod(\rho_i)^{(b_i)}`. - If ``include_bound``, will return a pair ``(sols, bound)`` where ``sols`` is as above and ``bound`` is the bound used for the entries in the exponent vectors. + If ``include_bound`` is ``True``, will return a pair ``(sols, bound)`` where ``sols`` is as above + and ``bound`` is the bound used for the entries in the exponent vectors. EXAMPLES:: - sage: K. = NumberField(x^2+x+1) + sage: K. = NumberField(x^2 + x + 1) sage: S = K.primes_above(3) - sage: K.S_unit_solutions(S) # random, due to ordering + sage: K.S_unit_solutions(S) # random, due to ordering [(xi + 2, -xi - 1), (1/3*xi + 2/3, -1/3*xi + 1/3), (-xi, xi + 1), (-xi + 1, xi)] You can get the exponent vectors:: @@ -7349,14 +7425,14 @@ def S_unit_solutions(self, S=[], prec=106, include_exponents=False, include_boun def zeta(self, n=2, all=False): """ - Return one, or a list of all, primitive n-th root of unity in this field. + Return one, or a list of all, primitive `n`-th root of unity in this field. INPUT: - - ``n`` -- positive integer + - ``n`` -- positive integer - ``all`` -- boolean. If ``False`` (default), return a primitive - `n`-th root of unity in this field, or raise a ``ValueError`` + `n`-th root of unity in this field, or raise a :class:`ValueError` exception if there are none. If ``True``, return a list of all primitive `n`-th roots of unity in this field (possibly empty). @@ -7392,7 +7468,7 @@ def zeta(self, n=2, all=False): :: sage: r. = QQ[] - sage: K. = NumberField(x^2+1) + sage: K. = NumberField(x^2 + 1) sage: K.zeta(4) b sage: K.zeta(4,all=True) @@ -7401,7 +7477,7 @@ def zeta(self, n=2, all=False): Traceback (most recent call last): ... ValueError: there are no 3rd roots of unity in self - sage: K.zeta(3,all=True) + sage: K.zeta(3, all=True) [] Number fields defined by non-monic and non-integral @@ -7465,10 +7541,10 @@ def zeta_order(self): EXAMPLES:: - sage: F. = NumberField(x**22+3) + sage: F. = NumberField(x^22 + 3) sage: F.zeta_order() 6 - sage: F. = NumberField(x**2-7) + sage: F. = NumberField(x^2 - 7) sage: F.zeta_order() 2 @@ -7510,13 +7586,13 @@ def primitive_root_of_unity(self): EXAMPLES:: - sage: K. = NumberField(x^2+1) + sage: K. = NumberField(x^2 + 1) sage: z = K.primitive_root_of_unity(); z i sage: z.multiplicative_order() 4 - sage: K. = NumberField(x^2+x+1) + sage: K. = NumberField(x^2 + x + 1) sage: z = K.primitive_root_of_unity(); z a + 1 sage: z.multiplicative_order() @@ -7581,10 +7657,10 @@ def roots_of_unity(self): EXAMPLES:: - sage: K. = NumberField(x^2+1) + sage: K. = NumberField(x^2 + 1) sage: zs = K.roots_of_unity(); zs [b, -1, -b, 1] - sage: [ z**K.number_of_roots_of_unity() for z in zs ] + sage: [z**K.number_of_roots_of_unity() for z in zs] [1, 1, 1, 1] """ z = self.primitive_root_of_unity() @@ -7593,13 +7669,13 @@ def roots_of_unity(self): def zeta_coefficients(self, n): """ - Compute the first n coefficients of the Dedekind zeta function of + Compute the first `n` coefficients of the Dedekind zeta function of this field as a Dirichlet series. EXAMPLES:: sage: x = QQ['x'].0 - sage: NumberField(x^2+1, 'a').zeta_coefficients(10) + sage: NumberField(x^2 + 1, 'a').zeta_coefficients(10) [1, 1, 0, 1, 2, 0, 0, 1, 1, 2] """ return self.pari_nf().dirzetak(n) @@ -7614,11 +7690,11 @@ def solve_CRT(self, reslist, Ilist, check=True): - ``Ilist`` -- a list of integral ideals, assumed pairwise coprime - - ``check`` (boolean, default True) -- if True, result is checked + - ``check`` -- (boolean, default ``True``) if ``True``, result is checked OUTPUT: - An integral element x such that x-reslist[i] is in Ilist[i] for all i. + An integral element `x` such that ``x - reslist[i]`` is in ``Ilist[i]`` for all `i`. .. note:: @@ -7627,17 +7703,17 @@ def solve_CRT(self, reslist, Ilist, check=True): EXAMPLES:: - sage: K. = NumberField(x^2-10) + sage: K. = NumberField(x^2 - 10) sage: Ilist = [K.primes_above(p)[0] for p in prime_range(10)] - sage: b = K.solve_CRT([1,2,3,4],Ilist,True) - sage: all(b-i-1 in Ilist[i] for i in range(4)) + sage: b = K.solve_CRT([1,2,3,4], Ilist, True) + sage: all(b - i - 1 in Ilist[i] for i in range(4)) True sage: Ilist = [K.ideal(a), K.ideal(2)] - sage: K.solve_CRT([0,1],Ilist,True) + sage: K.solve_CRT([0,1], Ilist, True) Traceback (most recent call last): ... ArithmeticError: ideals in solve_CRT() must be pairwise coprime - sage: Ilist[0]+Ilist[1] + sage: Ilist[0] + Ilist[1] Fractional ideal (2, a) """ n = len(reslist) @@ -7690,7 +7766,8 @@ def valuation(self, prime): sage: K.valuation(5) Traceback (most recent call last): ... - ValueError: The valuation Gauss valuation induced by 5-adic valuation does not approximate a unique extension of 5-adic valuation with respect to x^2 + 1 + ValueError: The valuation Gauss valuation induced by 5-adic valuation does not + approximate a unique extension of 5-adic valuation with respect to x^2 + 1 The valuation can also be selected by giving a valuation on the base ring that extends uniquely:: @@ -7703,7 +7780,8 @@ def valuation(self, prime): sage: K.valuation(ZZ.valuation(5)) Traceback (most recent call last): ... - ValueError: The valuation Gauss valuation induced by 5-adic valuation does not approximate a unique extension of 5-adic valuation with respect to x^2 + 1 + ValueError: The valuation Gauss valuation induced by 5-adic valuation does not + approximate a unique extension of 5-adic valuation with respect to x^2 + 1 For a number field which is of the form `K[x]/(G)`, you can specify a valuation by providing a discrete pseudo-valuation on `K[x]` which sends @@ -7711,15 +7789,16 @@ def valuation(self, prime): valuation we care about in the above example:: sage: R. = QQ[] - sage: v = K.valuation(GaussValuation(R, QQ.valuation(5)).augmentation(x + 2, infinity)) - sage: w = K.valuation(GaussValuation(R, QQ.valuation(5)).augmentation(x + 1/2, infinity)) + sage: G5 = GaussValuation(R, QQ.valuation(5)) + sage: v = K.valuation(G5.augmentation(x + 2, infinity)) + sage: w = K.valuation(G5.augmentation(x + 1/2, infinity)) sage: v == w False Note that you get the same valuation, even if you write down the pseudo-valuation differently:: - sage: ww = K.valuation(GaussValuation(R, QQ.valuation(5)).augmentation(x + 3, infinity)) + sage: ww = K.valuation(G5.augmentation(x + 3, infinity)) sage: w is ww True @@ -7729,7 +7808,7 @@ def valuation(self, prime): completion, i.e., if it is not possible to write down one of the factors within the number field:: - sage: v = GaussValuation(R, QQ.valuation(5)).augmentation(x + 3, 1) + sage: v = G5.augmentation(x + 3, 1) sage: K.valuation(v) [ 5-adic valuation, v(x + 3) = 1 ]-adic valuation @@ -7823,30 +7902,30 @@ def maximal_order(self, v=None, assume_maximal='non-maximal-non-unique'): INPUT: - - ``v`` - ``None``, a prime, or a list of integer primes (default: ``None``) + - ``v`` -- ``None``, a prime, or a list of integer primes (default: ``None``) - - if ``None``, return the maximal order. + - if ``None``, return the maximal order. - - if a prime `p`, return an order that is `p`-maximal. + - if a prime `p`, return an order that is `p`-maximal. - - if a list, return an order that is maximal at each prime of these primes + - if a list, return an order that is maximal at each prime of these primes - - ``assume_maximal`` - ``True``, ``False``, ``None``, or + - ``assume_maximal`` -- ``True``, ``False``, ``None``, or ``"non-maximal-non-unique"`` (default: ``"non-maximal-non-unique"``) ignored when ``v`` is ``None``; otherwise, controls whether we assume that the order :meth:`order.is_maximal` outside of ``v``. - - if ``True``, the order is assumed to be maximal at all primes. + - if ``True``, the order is assumed to be maximal at all primes. - - if ``False``, the order is assumed to be non-maximal at some prime - not in ``v``. + - if ``False``, the order is assumed to be non-maximal at some prime + not in ``v``. - - if ``None``, no assumptions are made about primes not in ``v``. + - if ``None``, no assumptions are made about primes not in ``v``. - - if ``"non-maximal-non-unique"`` (deprecated), like ``False``, - however, the order is not a unique parent, so creating the same - order later does typically not poison caches with the information - that the order is not maximal. + - if ``"non-maximal-non-unique"`` (deprecated), like ``False``, + however, the order is not a unique parent, so creating the same + order later does typically not poison caches with the information + that the order is not maximal. EXAMPLES: @@ -7919,7 +7998,8 @@ def maximal_order(self, v=None, assume_maximal='non-maximal-non-unique'): sage: K.maximal_order(v=2, assume_maximal=False) Traceback (most recent call last): ... - ValueError: cannot assume this order to be non-maximal because we already found it to be a maximal order + ValueError: cannot assume this order to be non-maximal + because we already found it to be a maximal order TESTS: @@ -7934,7 +8014,8 @@ def maximal_order(self, v=None, assume_maximal='non-maximal-non-unique'): sage: K. = NumberField([x^4 + 1, x^4 - 3]) sage: K.maximal_order() - Maximal Relative Order in Number Field in a with defining polynomial x^4 + 1 over its base field + Maximal Relative Order in + Number Field in a with defining polynomial x^4 + 1 over its base field An example with nontrivial ``v``:: @@ -7962,7 +8043,7 @@ def maximal_order(self, v=None, assume_maximal='non-maximal-non-unique'): class NumberField_absolute(NumberField_generic): def __init__(self, polynomial, name, latex_name=None, check=True, embedding=None, assume_disc_small=False, maximize_at_primes=None, structure=None): - """ + r""" Function to initialize an absolute number field. EXAMPLES:: @@ -7982,7 +8063,7 @@ def __init__(self, polynomial, name, latex_name=None, check=True, embedding=None self._init_embedding_approx() def _coerce_from_other_number_field(self, x): - """ + r""" Coerce a number field element x into this number field. Unless `x` is in ``QQ``, this requires ``x.parent()`` and @@ -8018,7 +8099,9 @@ def _coerce_from_other_number_field(self, x): sage: K._coerce_from_other_number_field(b) Traceback (most recent call last): ... - TypeError: No compatible natural embeddings found for Number Field in a with defining polynomial x^3 + 2 and Number Field in b with defining polynomial x^2 + 1 + TypeError: No compatible natural embeddings found for + Number Field in a with defining polynomial x^3 + 2 and + Number Field in b with defining polynomial x^2 + 1 Two number fields both containing `i`:: @@ -8045,7 +8128,9 @@ def _coerce_from_other_number_field(self, x): sage: L(1/2*a^3 + 5/2*a) Traceback (most recent call last): ... - TypeError: No compatible natural embeddings found for Number Field in b with defining polynomial x^4 + 8*x^2 + 4 and Number Field in a with defining polynomial x^4 + 6*x^2 + 1 + TypeError: No compatible natural embeddings found for + Number Field in b with defining polynomial x^4 + 8*x^2 + 4 and + Number Field in a with defining polynomial x^4 + 6*x^2 + 1 Embeddings can also be `p`-adic:: @@ -8063,7 +8148,8 @@ def _coerce_from_other_number_field(self, x): sage: L(a) Traceback (most recent call last): ... - ValueError: cannot convert a to Number Field in b with defining polynomial x^3 - 4*x + 1 with b = 1.860805853111704? (using the specified embeddings) + ValueError: cannot convert a to Number Field in b with defining polynomial x^3 - 4*x + 1 + with b = 1.860805853111704? (using the specified embeddings) Subfields automatically come with an embedding:: @@ -8216,7 +8302,7 @@ def _coerce_from_other_number_field(self, x): raise ValueError("cannot convert %s to %s (using the specified embeddings)" % (x, K)) def _coerce_map_from_(self, R): - """ + r""" Canonical coercion of a ring R into self. Currently any ring coercing into the base ring canonically coerces @@ -8322,8 +8408,8 @@ def _coerce_map_from_(self, R): return None def base_field(self): - """ - Return the base field of self, which is always ``QQ``. + r""" + Return the base field of ``self``, which is always ``QQ``. EXAMPLES:: @@ -8334,8 +8420,8 @@ def base_field(self): return QQ def is_absolute(self): - """ - Return ``True`` since self is an absolute field. + r""" + Return ``True`` since ``self`` is an absolute field. EXAMPLES:: @@ -8348,7 +8434,7 @@ def is_absolute(self): def absolute_polynomial(self): r""" Return absolute polynomial that defines this absolute field. This - is the same as ``self.polynomial()``. + is the same as :meth:`polynomial`. EXAMPLES:: @@ -8377,10 +8463,10 @@ def absolute_generator(self): return self.gen() def optimized_representation(self, name=None, both_maps=True): - """ - Return a field isomorphic to self with a better defining polynomial + r""" + Return a field isomorphic to ``self`` with a better defining polynomial if possible, along with field isomorphisms from the new field to - self and from self to the new field. + ``self`` and from ``self`` to the new field. EXAMPLES: We construct a compositum of 3 quadratic fields, then find an optimized representation and transform elements back and @@ -8392,8 +8478,7 @@ def optimized_representation(self, name=None, both_maps=True): Number Field in b with defining polynomial x^8 + 40*x^6 + 352*x^4 + 960*x^2 + 576 sage: L, from_L, to_L = K.optimized_representation() sage: L # your answer may different, since algorithm is random - Number Field in b1 with defining polynomial x^8 + 4*x^6 + 7*x^4 + - 36*x^2 + 81 + Number Field in b1 with defining polynomial x^8 + 4*x^6 + 7*x^4 + 36*x^2 + 81 sage: to_L(K.0) # random 4/189*b1^7 + 1/63*b1^6 + 1/27*b1^5 - 2/9*b1^4 - 5/27*b1^3 - 8/9*b1^2 + 3/7*b1 - 3/7 sage: from_L(L.0) # random @@ -8479,8 +8564,8 @@ def optimized_representation(self, name=None, both_maps=True): def optimized_subfields(self, degree=0, name=None, both_maps=True): """ Return optimized representations of many (but *not* necessarily - all!) subfields of self of the given degree, or of all possible degrees if - degree is 0. + all!) subfields of ``self`` of the given ``degree``, or of all possible degrees if + ``degree`` is 0. EXAMPLES:: @@ -8506,10 +8591,12 @@ def optimized_subfields(self, degree=0, name=None, both_maps=True): sage: from_M # may be slightly random Ring morphism: From: Number Field in b2 with defining polynomial x^4 - 5*x^2 + 25 - To: Number Field in a1 with defining polynomial x^8 + 40*x^6 + 352*x^4 + 960*x^2 + 576 - Defn: b2 |--> -5/1152*a1^7 + 1/96*a1^6 - 97/576*a1^5 + 17/48*a1^4 - 95/72*a1^3 + 17/12*a1^2 - 53/24*a1 - 1 + To: Number Field in a1 with defining polynomial + x^8 + 40*x^6 + 352*x^4 + 960*x^2 + 576 + Defn: b2 |--> -5/1152*a1^7 + 1/96*a1^6 - 97/576*a1^5 + 17/48*a1^4 + - 95/72*a1^3 + 17/12*a1^2 - 53/24*a1 - 1 - The to_M map is None, since there is no map from K to M:: + The ``to_M`` map is ``None``, since there is no map from `K` to `M`:: sage: to_M @@ -8517,7 +8604,8 @@ def optimized_subfields(self, degree=0, name=None, both_maps=True): rather large element of `K`:: sage: from_M(M.0) # random - -5/1152*a1^7 + 1/96*a1^6 - 97/576*a1^5 + 17/48*a1^4 - 95/72*a1^3 + 17/12*a1^2 - 53/24*a1 - 1 + -5/1152*a1^7 + 1/96*a1^6 - 97/576*a1^5 + 17/48*a1^4 + - 95/72*a1^3 + 17/12*a1^2 - 53/24*a1 - 1 Nevertheless, that large-ish element lies in a degree 4 subfield:: @@ -8570,18 +8658,16 @@ def optimized_subfields(self, degree=0, name=None, both_maps=True): def change_names(self, names): r""" - Return number field isomorphic to self but with the given generator + Return number field isomorphic to ``self`` but with the given generator name. INPUT: + - ``names`` -- should be exactly one variable name. - - ``names`` - should be exactly one variable name. - - - Also, ``K.structure()`` returns from_K and to_K, - where from_K is an isomorphism from K to self and to_K is an - isomorphism from self to K. + Also, ``K.structure()`` returns ``from_K`` and ``to_K``, + where ``from_K`` is an isomorphism from `K` to ``self`` and ``to_K`` is an + isomorphism from ``self`` to `K`. EXAMPLES:: @@ -8601,9 +8687,9 @@ def change_names(self, names): def subfields(self, degree=0, name=None): """ - Return all subfields of self of the given degree, - or of all possible degrees if degree is 0. The subfields are returned as - absolute fields together with an embedding into self. For the case of the + Return all subfields of ``self`` of the given ``degree``, + or of all possible degrees if ``degree`` is 0. The subfields are returned as + absolute fields together with an embedding into ``self``. For the case of the field itself, the reverse isomorphism is also provided. EXAMPLES:: @@ -8674,7 +8760,7 @@ def subfields(self, degree=0, name=None): def _subfields_helper(self, degree=0, name=None, both_maps=True, optimize=False): """ - Internal function: common code for optimized_subfields() and subfields(). + Internal function: common code for :meth:`optimized_subfields` and :meth:`subfields`. TESTS: @@ -8789,17 +8875,17 @@ def order(self, *args, **kwds): INPUT: - - ``gens`` - list of elements in this number field; if no generators + - ``gens`` -- list of elements in this number field; if no generators are given, just returns the cardinality of this number field (`\infty`) for consistency. - - ``check_is_integral`` - bool (default: ``True``), whether to check + - ``check_is_integral`` -- bool (default: ``True``), whether to check that each generator is integral. - - ``check_rank`` - bool (default: ``True``), whether to check that the + - ``check_rank`` -- bool (default: ``True``), whether to check that the ring generated by ``gens`` is of full rank. - - ``allow_subfield`` - bool (default: ``False``), if ``True`` and the + - ``allow_subfield`` -- bool (default: ``False``), if ``True`` and the generators do not generate an order, i.e., they generate a subring of smaller rank, instead of raising an error, return an order in a smaller number field. @@ -8888,8 +8974,8 @@ def _order(self, gens, **kwds): @cached_method(key=lambda self, base, basis, map: (base or self.base_ring(), basis, map)) def free_module(self, base=None, basis=None, map=True): - """ - Return a vector space V and isomorphisms self --> V and V --> self. + r""" + Return a vector space `V` and isomorphisms ``self`` `\to` `V` and `V` `\to` ``self``. INPUT: @@ -8902,16 +8988,13 @@ def free_module(self, base=None, basis=None, map=True): - ``maps`` -- boolean (default ``True``), whether to return `R`-linear maps to and from `V` - OUTPUT: + - `V` - a vector space over the rational numbers - - ``V`` - a vector space over the rational numbers - - - ``from_V`` - an isomorphism from V to self (if requested) - - - ``to_V`` - an isomorphism from self to V (if requested) + - ``from_V`` -- an isomorphism from `V` to ``self`` (if requested) + - ``to_V`` -- an isomorphism from ``self`` to `V` (if requested) EXAMPLES:: @@ -8952,7 +9035,7 @@ def absolute_vector_space(self, *args, **kwds): and in the other direction. For an absolute extension this is identical to - ``self.vector_space()``. + :meth:`vector_space`. EXAMPLES:: @@ -8970,12 +9053,12 @@ def absolute_vector_space(self, *args, **kwds): def _galois_closure_and_embedding(self, names=None): r""" - Return number field `K` that is the Galois closure of self and an - embedding of self into `K`. + Return number field `K` that is the Galois closure of ``self`` and an + embedding of ``self`` into `K`. INPUT: - - ``names`` - variable name for Galois closure + - ``names`` -- variable name for Galois closure .. warning:: @@ -9020,15 +9103,15 @@ def _galois_closure_and_embedding(self, names=None): def galois_closure(self, names=None, map=False): """ - Return number field `K` that is the Galois closure of self, + Return number field `K` that is the Galois closure of ``self``, i.e., is generated by all roots of the defining polynomial of - self, and possibly an embedding of self into `K`. + ``self``, and possibly an embedding of ``self`` into `K`. INPUT: - - ``names`` - variable name for Galois closure + - ``names`` -- variable name for Galois closure - - ``map`` - (default: ``False``) also return an embedding of self into `K` + - ``map`` -- (default: ``False``) also return an embedding of ``self`` into `K` EXAMPLES:: @@ -9062,7 +9145,9 @@ def galois_closure(self, names=None, map=False): sage: K. = NumberField(cyclotomic_polynomial(23)) sage: L. = K.galois_closure() sage: L - Number Field in z with defining polynomial x^22 + x^21 + x^20 + x^19 + x^18 + x^17 + x^16 + x^15 + x^14 + x^13 + x^12 + x^11 + x^10 + x^9 + x^8 + x^7 + x^6 + x^5 + x^4 + x^3 + x^2 + x + 1 + Number Field in z with defining polynomial + x^22 + x^21 + x^20 + x^19 + x^18 + x^17 + x^16 + x^15 + x^14 + x^13 + x^12 + + x^11 + x^10 + x^9 + x^8 + x^7 + x^6 + x^5 + x^4 + x^3 + x^2 + x + 1 TESTS: @@ -9083,7 +9168,7 @@ def galois_closure(self, names=None, map=False): def automorphisms(self): r""" - Compute all Galois automorphisms of self. + Compute all Galois automorphisms of ``self``. This uses PARI's :pari:`nfgaloisconj` and is much faster than root finding for many fields. @@ -9108,7 +9193,10 @@ def automorphisms(self): `L` is the Galois closure of `K`:: - sage: L = NumberField(x^24 - 84*x^22 + 2814*x^20 - 15880*x^18 - 409563*x^16 - 8543892*x^14 + 25518202*x^12 + 32831026956*x^10 - 672691027218*x^8 - 4985379093428*x^6 + 320854419319140*x^4 + 817662865724712*x^2 + 513191437605441, 'a') + sage: L = NumberField(x^24 - 84*x^22 + 2814*x^20 - 15880*x^18 - 409563*x^16 + ....: - 8543892*x^14 + 25518202*x^12 + 32831026956*x^10 + ....: - 672691027218*x^8 - 4985379093428*x^6 + 320854419319140*x^4 + ....: + 817662865724712*x^2 + 513191437605441, 'a') sage: len(L.automorphisms()) 24 @@ -9135,11 +9223,11 @@ def automorphisms(self): @cached_method def embeddings(self, K): """ - Compute all field embeddings of this field into the field K (which need + Compute all field embeddings of this field into the field `K` (which need not even be a number field, e.g., it could be the complex numbers). - This will return an identical result when given K as input again. + This will return an identical result when given `K` as input again. - If possible, the most natural embedding of this field into K + If possible, the most natural embedding of this field into `K` is put first in the list. INPUT: @@ -9166,11 +9254,13 @@ def embeddings(self, K): sage: L.embeddings(K) [ Ring morphism: - From: Number Field in a with defining polynomial x^2 + 7 with a = 2.645751311064591?*I + From: Number Field in a with defining polynomial x^2 + 7 + with a = 2.645751311064591?*I To: Cyclotomic Field of order 7 and degree 6 Defn: a |--> 2*zeta7^4 + 2*zeta7^2 + 2*zeta7 + 1, Ring morphism: - From: Number Field in a with defining polynomial x^2 + 7 with a = 2.645751311064591?*I + From: Number Field in a with defining polynomial x^2 + 7 + with a = 2.645751311064591?*I To: Cyclotomic Field of order 7 and degree 6 Defn: a |--> -2*zeta7^4 - 2*zeta7^2 - 2*zeta7 - 1 ] @@ -9226,22 +9316,22 @@ def embeddings(self, K): def minkowski_embedding(self, B=None, prec=None): r""" Return an nxn matrix over RDF whose columns are the images of the - basis `\{1, \alpha, \dots, \alpha^{n-1}\}` of self over + basis `\{1, \alpha, \dots, \alpha^{n-1}\}` of ``self`` over `\QQ` (as vector spaces), where here - `\alpha` is the generator of self over - `\QQ`, i.e. self.gen(0). If B is not None, return - the images of the vectors in B as the columns instead. If prec is - not None, use RealField(prec) instead of RDF. + `\alpha` is the generator of ``self`` over + `\QQ`, i.e. ``self.gen(0)``. If `B` is not ``None``, return + the images of the vectors in `B` as the columns instead. If ``prec`` is + not ``None``, use ``RealField(prec)`` instead of ``RDF``. This embedding is the so-called "Minkowski embedding" of a number field in `\RR^n`: given the `n` embeddings - `\sigma_1, \dots, \sigma_n` of self in + `\sigma_1, \dots, \sigma_n` of ``self`` in `\CC`, write `\sigma_1, \dots, \sigma_r` for the real embeddings, and `\sigma_{r+1}, \dots, \sigma_{r+s}` for choices of one of each pair of complex conjugate embeddings (in our case, we simply choose the one where the image of `\alpha` has positive - real part). Here `(r,s)` is the signature of self. Then the + real part). Here `(r,s)` is the signature of ``self``. Then the Minkowski embedding is given by .. MATH:: @@ -9252,9 +9342,9 @@ def minkowski_embedding(self, B=None, prec=None): \sqrt{2}\Re(\sigma_{r+s}(x)), \sqrt{2}\Im(\sigma_{r+s}(x))) - Equivalently, this is an embedding of self in `\RR^n` so + Equivalently, this is an embedding of ``self`` in `\RR^n` so that the usual norm on `\RR^n` coincides with - `|x| = \sum_i |\sigma_i(x)|^2` on self. + `|x| = \sum_i |\sigma_i(x)|^2` on ``self``. .. TODO:: @@ -9263,7 +9353,7 @@ def minkowski_embedding(self, B=None, prec=None): EXAMPLES:: - sage: F. = NumberField(x^3+2) + sage: F. = NumberField(x^3 + 2) sage: F.minkowski_embedding() [ 1.00000000000000 -1.25992104989487 1.58740105196820] [ 1.41421356237... 0.8908987181... -1.12246204830...] @@ -9321,7 +9411,7 @@ def logarithmic_embedding(self, prec=53): OUTPUT: - - the morphism of ``self`` under the logarithmic embedding in the category Set. + the morphism of ``self`` under the logarithmic embedding in the category Set. EXAMPLES:: @@ -9380,71 +9470,71 @@ def closure_map(x, prec=53): def places(self, all_complex=False, prec=None): r""" - Return the collection of all infinite places of self. + Return the collection of all infinite places of ``self``. By default, this returns the set of real places as - homomorphisms into RIF first, followed by a choice of one of - each pair of complex conjugate homomorphisms into CIF. + homomorphisms into ``RIF`` first, followed by a choice of one of + each pair of complex conjugate homomorphisms into ``CIF``. - On the other hand, if prec is not None, we simply return places - into RealField(prec) and ComplexField(prec) (or RDF, CDF if - prec=53). One can also use ``prec=infinity``, which returns embeddings + On the other hand, if ``prec`` is not ``None``, we simply return places + into ``RealField(prec)`` and ``ComplexField(prec)`` (or ``RDF``, ``CDF`` if + ``prec=53``). One can also use ``prec=infinity``, which returns embeddings into the field `\overline{\QQ}` of algebraic numbers (or its subfield `\mathbb{A}` of algebraic reals); this permits exact computation, but can be extremely slow. - There is an optional flag all_complex, which defaults to False. If - all_complex is True, then the real embeddings are returned as - embeddings into CIF instead of RIF. + There is an optional flag ``all_complex``, which defaults to ``False``. If + ``all_complex`` is ``True``, then the real embeddings are returned as + embeddings into ``CIF`` instead of ``RIF``. EXAMPLES:: - sage: F. = NumberField(x^3-100*x+1) ; F.places() + sage: F. = NumberField(x^3 - 100*x + 1); F.places() [Ring morphism: - From: Number Field in alpha with defining polynomial x^3 - 100*x + 1 - To: Real Field with 106 bits of precision - Defn: alpha |--> -10.00499625499181184573367219280, - Ring morphism: - From: Number Field in alpha with defining polynomial x^3 - 100*x + 1 - To: Real Field with 106 bits of precision - Defn: alpha |--> 0.01000001000003000012000055000273, - Ring morphism: - From: Number Field in alpha with defining polynomial x^3 - 100*x + 1 - To: Real Field with 106 bits of precision - Defn: alpha |--> 9.994996244991781845613530439509] + From: Number Field in alpha with defining polynomial x^3 - 100*x + 1 + To: Real Field with 106 bits of precision + Defn: alpha |--> -10.00499625499181184573367219280, + Ring morphism: + From: Number Field in alpha with defining polynomial x^3 - 100*x + 1 + To: Real Field with 106 bits of precision + Defn: alpha |--> 0.01000001000003000012000055000273, + Ring morphism: + From: Number Field in alpha with defining polynomial x^3 - 100*x + 1 + To: Real Field with 106 bits of precision + Defn: alpha |--> 9.994996244991781845613530439509] :: - sage: F. = NumberField(x^3+7) ; F.places() + sage: F. = NumberField(x^3 + 7); F.places() [Ring morphism: - From: Number Field in alpha with defining polynomial x^3 + 7 - To: Real Field with 106 bits of precision - Defn: alpha |--> -1.912931182772389101199116839549, - Ring morphism: - From: Number Field in alpha with defining polynomial x^3 + 7 - To: Complex Field with 53 bits of precision - Defn: alpha |--> 0.956465591386195 + 1.65664699997230*I] + From: Number Field in alpha with defining polynomial x^3 + 7 + To: Real Field with 106 bits of precision + Defn: alpha |--> -1.912931182772389101199116839549, + Ring morphism: + From: Number Field in alpha with defining polynomial x^3 + 7 + To: Complex Field with 53 bits of precision + Defn: alpha |--> 0.956465591386195 + 1.65664699997230*I] :: - sage: F. = NumberField(x^3+7) ; F.places(all_complex=True) + sage: F. = NumberField(x^3 + 7) ; F.places(all_complex=True) [Ring morphism: - From: Number Field in alpha with defining polynomial x^3 + 7 - To: Complex Field with 53 bits of precision - Defn: alpha |--> -1.91293118277239, - Ring morphism: - From: Number Field in alpha with defining polynomial x^3 + 7 - To: Complex Field with 53 bits of precision - Defn: alpha |--> 0.956465591386195 + 1.65664699997230*I] + From: Number Field in alpha with defining polynomial x^3 + 7 + To: Complex Field with 53 bits of precision + Defn: alpha |--> -1.91293118277239, + Ring morphism: + From: Number Field in alpha with defining polynomial x^3 + 7 + To: Complex Field with 53 bits of precision + Defn: alpha |--> 0.956465591386195 + 1.65664699997230*I] sage: F.places(prec=10) [Ring morphism: - From: Number Field in alpha with defining polynomial x^3 + 7 - To: Real Field with 10 bits of precision - Defn: alpha |--> -1.9, - Ring morphism: - From: Number Field in alpha with defining polynomial x^3 + 7 - To: Complex Field with 10 bits of precision - Defn: alpha |--> 0.96 + 1.7*I] + From: Number Field in alpha with defining polynomial x^3 + 7 + To: Real Field with 10 bits of precision + Defn: alpha |--> -1.9, + Ring morphism: + From: Number Field in alpha with defining polynomial x^3 + 7 + To: Complex Field with 10 bits of precision + Defn: alpha |--> 0.96 + 1.7*I] """ if prec is None: R = RIF @@ -9522,18 +9612,18 @@ def abs_val(self, v, iota, prec=None): EXAMPLES:: - sage: K. = NumberField(x^3-3) + sage: K. = NumberField(x^3 - 3) sage: phi_real = K.places()[0] sage: phi_complex = K.places()[1] sage: v_fin = tuple(K.primes_above(3))[0] - sage: K.abs_val(phi_real,xi^2) + sage: K.abs_val(phi_real, xi^2) 2.08008382305190 - sage: K.abs_val(phi_complex,xi^2) + sage: K.abs_val(phi_complex, xi^2) 4.32674871092223 - sage: K.abs_val(v_fin,xi^2) + sage: K.abs_val(v_fin, xi^2) 0.111111111111111 Check that :trac:`28345` is fixed:: @@ -9559,17 +9649,17 @@ def abs_val(self, v, iota, prec=None): def relativize(self, alpha, names, structure=None): r""" - Given an element in self or an embedding of a subfield into self, - return a relative number field `K` isomorphic to self that is relative - over the absolute field `\QQ(\alpha)` or the domain of `alpha`, along - with isomorphisms from `K` to self and from self to `K`. + Given an element in ``self`` or an embedding of a subfield into ``self``, + return a relative number field `K` isomorphic to ``self`` that is relative + over the absolute field `\QQ(\alpha)` or the domain of `\alpha`, along + with isomorphisms from `K` to ``self`` and from ``self`` to `K`. INPUT: - - ``alpha`` - an element of self or an embedding of a subfield into - self - - ``names`` - 2-tuple of names of generator for output field K and the - subfield QQ(alpha) names[0] generators K and names[1] QQ(alpha). + - ``alpha`` -- an element of ``self`` or an embedding of a subfield into + ``self`` + - ``names`` -- 2-tuple of names of generator for output field `K` and the + subfield `\QQ(\alpha)` - ``structure`` -- an instance of :class:`structure.NumberFieldStructure` or ``None`` (default: ``None``), if ``None``, then the resulting field's :meth:`structure` @@ -9578,17 +9668,18 @@ def relativize(self, alpha, names, structure=None): OUTPUT: - K -- relative number field + `K` -- relative number field - Also, ``K.structure()`` returns from_K and to_K, where - from_K is an isomorphism from K to self and to_K is an isomorphism - from self to K. + Also, ``K.structure()`` returns ``from_K`` and ``to_K``, where + ``from_K`` is an isomorphism from `K` to ``self`` and ``to_K`` is an isomorphism + from ``self`` to `K`. EXAMPLES:: sage: K. = NumberField(x^10 - 2) sage: L. = K.relativize(a^4 + a^2 + 2); L - Number Field in c with defining polynomial x^2 - 1/5*d^4 + 8/5*d^3 - 23/5*d^2 + 7*d - 18/5 over its base field + Number Field in c with defining polynomial + x^2 - 1/5*d^4 + 8/5*d^3 - 23/5*d^2 + 7*d - 18/5 over its base field sage: c.absolute_minpoly() x^10 - 2 sage: d.absolute_minpoly() @@ -9693,7 +9784,8 @@ def relativize(self, alpha, names, structure=None): sage: K. = CyclotomicField(16) sage: L, L_into_K, _ = K.subfields(4)[0]; L - Number Field in z0 with defining polynomial x^4 + 16 with z0 = 1.414213562373095? + 1.414213562373095?*I + Number Field in z0 with defining polynomial x^4 + 16 + with z0 = 1.414213562373095? + 1.414213562373095?*I sage: F, F_into_L, _ = L.subfields(2)[0]; F Number Field in z0_0 with defining polynomial x^2 + 64 with z0_0 = 8*I @@ -9820,7 +9912,7 @@ def relativize(self, alpha, names, structure=None): def absolute_degree(self): """ - A synonym for degree. + A synonym for :meth:`degree`. EXAMPLES:: @@ -9832,7 +9924,7 @@ def absolute_degree(self): def relative_degree(self): """ - A synonym for degree. + A synonym for :meth:`degree`. EXAMPLES:: @@ -9844,7 +9936,7 @@ def relative_degree(self): def relative_polynomial(self): """ - A synonym for polynomial. + A synonym for :meth:`polynomial`. EXAMPLES:: @@ -9856,7 +9948,7 @@ def relative_polynomial(self): def relative_vector_space(self, *args, **kwds): """ - A synonym for vector_space. + A synonym for :meth:`vector_space`. EXAMPLES:: @@ -9874,7 +9966,7 @@ def relative_vector_space(self, *args, **kwds): def absolute_discriminant(self): """ - A synonym for discriminant. + A synonym for :meth:`discriminant`. EXAMPLES:: @@ -9886,7 +9978,7 @@ def absolute_discriminant(self): def relative_discriminant(self): """ - A synonym for discriminant. + A synonym for :meth:`discriminant`. EXAMPLES:: @@ -9898,7 +9990,7 @@ def relative_discriminant(self): def absolute_different(self): """ - A synonym for different. + A synonym for :meth:`different`. EXAMPLES:: @@ -9910,7 +10002,7 @@ def absolute_different(self): def relative_different(self): """ - A synonym for different. + A synonym for :meth:`different`. EXAMPLES:: @@ -9922,64 +10014,64 @@ def relative_different(self): def hilbert_symbol(self, a, b, P=None): r""" - Return the Hilbert symbol `(a,b)_P` for a prime P of self - and non-zero elements a and b of self. + Return the Hilbert symbol `(a,b)_P` for a prime `P` of ``self`` + and non-zero elements `a` and `b` of ``self``. - If P is omitted, return the global Hilbert symbol `(a,b)` instead. + If `P` is omitted, return the global Hilbert symbol `(a,b)` instead. INPUT: - - ``a``, ``b`` -- elements of self + - ``a``, ``b`` -- elements of ``self`` - - ``P`` -- (default: ``None``) If `P` is ``None``, compute the global - symbol. Otherwise, `P` should be either a prime ideal of self + - ``P`` -- (default: ``None``) If ``None``, compute the global + symbol. Otherwise, `P` should be either a prime ideal of ``self`` (which may also be given as a generator or set of generators) or a real or complex embedding. OUTPUT: - If a or b is zero, returns 0. + If `a` or `b` is zero, returns 0. - If a and b are non-zero and P is specified, returns - the Hilbert symbol `(a,b)_P`, which is 1 if the equation + If `a` and `b` are non-zero and `P` is specified, returns + the Hilbert symbol `(a,b)_P`, which is `1` if the equation `a x^2 + b y^2 = 1` has a solution in the completion of - self at P, and is -1 otherwise. + ``self`` at `P`, and is `-1` otherwise. - If a and b are non-zero and P is unspecified, returns 1 - if the equation has a solution in self and -1 otherwise. + If `a` and `b` are non-zero and `P` is unspecified, returns `1` + if the equation has a solution in ``self`` and `-1` otherwise. EXAMPLES: Some global examples:: sage: K. = NumberField(x^2 - 23) - sage: K.hilbert_symbol(0, a+5) + sage: K.hilbert_symbol(0, a + 5) 0 sage: K.hilbert_symbol(a, 0) 0 - sage: K.hilbert_symbol(-a, a+1) + sage: K.hilbert_symbol(-a, a + 1) 1 - sage: K.hilbert_symbol(-a, a+2) + sage: K.hilbert_symbol(-a, a + 2) -1 - sage: K.hilbert_symbol(a, a+5) + sage: K.hilbert_symbol(a, a + 5) -1 That the latter two are unsolvable should be visible in local obstructions. For the first, this is a prime ideal above 19. For the second, the ramified prime above 23:: - sage: K.hilbert_symbol(-a, a+2, a+2) + sage: K.hilbert_symbol(-a, a + 2, a + 2) -1 - sage: K.hilbert_symbol(a, a+5, K.ideal(23).factor()[0][0]) + sage: K.hilbert_symbol(a, a + 5, K.ideal(23).factor()[0][0]) -1 More local examples:: sage: K.hilbert_symbol(a, 0, K.ideal(5)) 0 - sage: K.hilbert_symbol(a, a+5, K.ideal(5)) + sage: K.hilbert_symbol(a, a + 5, K.ideal(5)) 1 - sage: K.hilbert_symbol(a+1, 13, (a+6)*K.maximal_order()) + sage: K.hilbert_symbol(a + 1, 13, (a+6)*K.maximal_order()) -1 sage: [emb1, emb2] = K.embeddings(AA) sage: K.hilbert_symbol(a, -1, emb1) @@ -9991,10 +10083,10 @@ def hilbert_symbol(self, a, b, P=None): sage: K. = NumberField(x^5 - 23) sage: pi = 2*a^4 + 3*a^3 + 4*a^2 + 15*a + 11 - sage: K.hilbert_symbol(a, a+5, pi) + sage: K.hilbert_symbol(a, a + 5, pi) 1 sage: rho = 2*a^4 + 3*a^3 + 4*a^2 + 15*a + 11 - sage: K.hilbert_symbol(a, a+5, rho) + sage: K.hilbert_symbol(a, a + 5, rho) 1 This also works for non-principal ideals:: @@ -10003,9 +10095,9 @@ def hilbert_symbol(self, a, b, P=None): sage: P = K.ideal(3).factor()[0][0] sage: P.gens_reduced() # random, could be the other factor (3, a + 1) - sage: K.hilbert_symbol(a, a+3, P) + sage: K.hilbert_symbol(a, a + 3, P) 1 - sage: K.hilbert_symbol(a, a+3, [3, a+1]) + sage: K.hilbert_symbol(a, a + 3, [3, a+1]) 1 Primes above 2:: @@ -10013,11 +10105,11 @@ def hilbert_symbol(self, a, b, P=None): sage: K. = NumberField(x^5 - 23) sage: O = K.maximal_order() sage: p = [p[0] for p in (2*O).factor() if p[0].norm() == 16][0] - sage: K.hilbert_symbol(a, a+5, p) + sage: K.hilbert_symbol(a, a + 5, p) 1 sage: K.hilbert_symbol(a, 2, p) 1 - sage: K.hilbert_symbol(-1, a-2, p) + sage: K.hilbert_symbol(-1, a - 2, p) -1 Various real fields are allowed:: @@ -10037,36 +10129,40 @@ def hilbert_symbol(self, a, b, P=None): Traceback (most recent call last): ... ValueError: Possibly real place (=Ring morphism: - From: Number Field in a with defining polynomial x^2 - 5 with a = 2.236067977499790? + From: Number Field in a with defining polynomial x^2 - 5 + with a = 2.236067977499790? To: Complex Field with 53 bits of precision - Defn: a |--> -2.23606797749979) given as complex embedding in hilbert_symbol. Is it real or complex? + Defn: a |--> -2.23606797749979) + given as complex embedding in hilbert_symbol. Is it real or complex? sage: K.hilbert_symbol(-1, -1, K.embeddings(QQbar)[0]) Traceback (most recent call last): ... ValueError: Possibly real place (=Ring morphism: - From: Number Field in a with defining polynomial x^2 - 5 with a = 2.236067977499790? + From: Number Field in a with defining polynomial x^2 - 5 + with a = 2.236067977499790? To: Algebraic Field - Defn: a |--> -2.236067977499790?) given as complex embedding in hilbert_symbol. Is it real or complex? + Defn: a |--> -2.236067977499790?) + given as complex embedding in hilbert_symbol. Is it real or complex? sage: K. = QuadraticField(-5) sage: K.hilbert_symbol(-1, -1, K.embeddings(CDF)[0]) 1 sage: K.hilbert_symbol(-1, -1, K.embeddings(QQbar)[0]) 1 - a and b do not have to be integral or coprime:: + `a` and `b` do not have to be integral or coprime:: sage: K. = QuadraticField(-1) sage: O = K.maximal_order() sage: K.hilbert_symbol(1/2, 1/6, 3*O) 1 - sage: p = 1+i + sage: p = 1 + i sage: K.hilbert_symbol(p, p, p) 1 sage: K.hilbert_symbol(p, 3*p, p) -1 sage: K.hilbert_symbol(3, p, p) -1 - sage: K.hilbert_symbol(1/3, 1/5, 1+i) + sage: K.hilbert_symbol(1/3, 1/5, 1 + i) 1 sage: L = QuadraticField(5, 'a') sage: L.hilbert_symbol(-3, -1/2, 2) @@ -10074,24 +10170,24 @@ def hilbert_symbol(self, a, b, P=None): Various other examples:: - sage: K. = NumberField(x^3+x+1) - sage: K.hilbert_symbol(-6912, 24, -a^2-a-2) + sage: K. = NumberField(x^3 + x + 1) + sage: K.hilbert_symbol(-6912, 24, -a^2 - a - 2) 1 - sage: K. = NumberField(x^5-23) + sage: K. = NumberField(x^5 - 23) sage: P = K.ideal(-1105*a^4 + 1541*a^3 - 795*a^2 - 2993*a + 11853) sage: Q = K.ideal(-7*a^4 + 13*a^3 - 13*a^2 - 2*a + 50) sage: b = -a+5 - sage: K.hilbert_symbol(a,b,P) + sage: K.hilbert_symbol(a, b, P) 1 - sage: K.hilbert_symbol(a,b,Q) + sage: K.hilbert_symbol(a, b, Q) 1 - sage: K. = NumberField(x^5-23) + sage: K. = NumberField(x^5 - 23) sage: P = K.ideal(-1105*a^4 + 1541*a^3 - 795*a^2 - 2993*a + 11853) - sage: K.hilbert_symbol(a, a+5, P) + sage: K.hilbert_symbol(a, a + 5, P) 1 sage: K.hilbert_symbol(a, 2, P) 1 - sage: K.hilbert_symbol(a+5, 2, P) + sage: K.hilbert_symbol(a + 5, 2, P) -1 sage: K. = NumberField(x^3 - 4*x + 2) sage: K.hilbert_symbol(2, -2, K.primes_above(2)[0]) @@ -10149,13 +10245,13 @@ def hilbert_symbol(self, a, b, P=None): def hilbert_symbol_negative_at_S(self, S, b, check=True): """ - Return `a` such that the hilbert conductor of `a` and `b` is `S`. + Return `a` such that the Hilbert conductor of `a` and `b` is `S`. INPUT: - ``S`` -- a list of places (or prime ideals) of even cardinality - ``b`` -- a non-zero rational number which is a non-square locally - at every place in S. + at every place in `S`. - ``check`` -- bool (default: ``True``) perform additional checks on the input and confirm the output @@ -10192,7 +10288,7 @@ def hilbert_symbol_negative_at_S(self, S, b, check=True): sage: [k.hilbert_symbol(a, b, p) for p in S] [-1, -1, -1, -1] - Note that the closely related hilbert conductor + Note that the closely related Hilbert conductor takes only the finite places into account:: sage: k.hilbert_conductor(a, b) @@ -10324,7 +10420,7 @@ def phi(x): def hilbert_conductor(self, a, b): """ - This is the product of all (finite) primes where the Hilbert symbol is -1. + This is the product of all (finite) primes where the Hilbert symbol is `-1`. What is the same, this is the (reduced) discriminant of the quaternion algebra `(a,b)` over a number field. @@ -10334,17 +10430,17 @@ def hilbert_conductor(self, a, b): OUTPUT: - - squarefree ideal of the ring of integers of ``self`` + squarefree ideal of the ring of integers of ``self`` EXAMPLES:: - sage: F. = NumberField(x^2-x-1) - sage: F.hilbert_conductor(2*a,F(-1)) + sage: F. = NumberField(x^2 - x - 1) + sage: F.hilbert_conductor(2*a, F(-1)) Fractional ideal (2) - sage: K. = NumberField(x^3-4*x+2) - sage: K.hilbert_conductor(K(2),K(-2)) + sage: K. = NumberField(x^3 - 4*x + 2) + sage: K.hilbert_conductor(K(2), K(-2)) Fractional ideal (1) - sage: K.hilbert_conductor(K(2*b),K(-2)) + sage: K.hilbert_conductor(K(2*b), K(-2)) Fractional ideal (b^2 + b - 2) AUTHOR: @@ -10363,13 +10459,13 @@ def elements_of_bounded_height(self, **kwds): Return an iterator over the elements of ``self`` with relative multiplicative height at most ``bound``. - This algorithm computes 2 lists: L containing elements x in `K` such that - H_k(x) <= B, and a list L' containing elements x in `K` that, due to + This algorithm computes 2 lists: `L` containing elements `x` in `K` such that + `H_k(x) \leq B`, and a list `L'` containing elements `x` in `K` that, due to floating point issues, - may be slightly larger then the bound. This can be controlled + may be slightly larger than the bound. This can be controlled by lowering the tolerance. - In current implementation both lists (L,L') are merged and returned in + In the current implementation, both lists `(L,L')` are merged and returned in form of iterator. ALGORITHM: @@ -10381,15 +10477,15 @@ def elements_of_bounded_height(self, **kwds): kwds: - - ``bound`` - a real number + - ``bound`` -- a real number - - ``tolerance`` - (default: 0.01) a rational number in (0,1] + - ``tolerance`` -- (default: 0.01) a rational number in `(0,1]` - - ``precision`` - (default: 53) a positive integer + - ``precision`` -- (default: 53) a positive integer OUTPUT: - - an iterator of number field elements + an iterator of number field elements EXAMPLES: @@ -10542,8 +10638,8 @@ class NumberField_cyclotomic(NumberField_absolute, sage.rings.abc.NumberField_cy """ Create a cyclotomic extension of the rational field. - The command CyclotomicField(n) creates the n-th cyclotomic field, - obtained by adjoining an n-th root of unity to the rational field. + The command ``CyclotomicField(n)`` creates the `n`-th cyclotomic field, + obtained by adjoining an `n`-th root of unity to the rational field. EXAMPLES:: @@ -10568,26 +10664,26 @@ class NumberField_cyclotomic(NumberField_absolute, sage.rings.abc.NumberField_cy :: - sage: cf12 = CyclotomicField( 12 ) + sage: cf12 = CyclotomicField(12) sage: z12 = cf12.0 - sage: cf6 = CyclotomicField( 6 ) + sage: cf6 = CyclotomicField(6) sage: z6 = cf6.0 - sage: FF = Frac( cf12['x'] ) + sage: FF = Frac(cf12['x']) sage: x = FF.0 sage: z6*x^3/(z6 + x) zeta12^2*x^3/(x + zeta12^2) :: - sage: cf6 = CyclotomicField(6) ; z6 = cf6.gen(0) - sage: cf3 = CyclotomicField(3) ; z3 = cf3.gen(0) + sage: cf6 = CyclotomicField(6); z6 = cf6.gen(0) + sage: cf3 = CyclotomicField(3); z3 = cf3.gen(0) sage: cf3(z6) zeta3 + 1 sage: cf6(z3) zeta6 - 1 sage: type(cf6(z3)) - sage: cf1 = CyclotomicField(1) ; z1 = cf1.0 + sage: cf1 = CyclotomicField(1); z1 = cf1.0 sage: cf3(z1) 1 sage: type(cf3(z1)) @@ -10595,7 +10691,7 @@ class NumberField_cyclotomic(NumberField_absolute, sage.rings.abc.NumberField_cy """ def __init__(self, n, names, embedding=None, assume_disc_small=False, maximize_at_primes=None): """ - A cyclotomic field, i.e., a field obtained by adjoining an n-th + A cyclotomic field, i.e., a field obtained by adjoining an `n`-th root of unity to the rational numbers. EXAMPLES:: @@ -10752,10 +10848,10 @@ def _magma_init_(self, magma): EXAMPLES:: - sage: K=CyclotomicField(7,'z') # optional - magma + sage: K = CyclotomicField(7,'z') sage: K._magma_init_(magma) # optional - magma 'SageCreateWithNames(CyclotomicField(7),["z"])' - sage: K=CyclotomicField(7,'zeta') # optional - magma + sage: K = CyclotomicField(7,'zeta') sage: K._magma_init_(magma) # optional - magma 'SageCreateWithNames(CyclotomicField(7),["zeta"])' """ @@ -10830,7 +10926,7 @@ def _repr_(self): def _n(self): """ - Return the n used to create this cyclotomic field. + Return the `n` used to create this cyclotomic field. EXAMPLES:: @@ -10882,7 +10978,7 @@ def _latex_(self): def _coerce_map_from_(self, K): r""" - Return a coercion map from `K` to ``self``, or None. + Return a coercion map from `K` to ``self``, or ``None``. The cyclotomic field `\QQ(\zeta_n)` coerces into the cyclotomic field `\QQ(\zeta_m)` if and only if `n' \mid m`, @@ -10948,27 +11044,32 @@ def _coerce_map_from_(self, K): Check that custom embeddings are respected (:trac:`13765`):: - sage: z105 = CDF(exp(2*pi*I/105)) - sage: Ka. = CyclotomicField(105, embedding=z105^11) - sage: Kb. = CyclotomicField(35, embedding=z105^6) - sage: Ka.coerce_map_from(Kb) + sage: z105 = CDF(exp(2*pi*I/105)) # optional - sage.symbolic + sage: Ka. = CyclotomicField(105, embedding=z105^11) # optional - sage.symbolic + sage: Kb. = CyclotomicField(35, embedding=z105^6) # optional - sage.symbolic + sage: Ka.coerce_map_from(Kb) # optional - sage.symbolic Generic morphism: From: Cyclotomic Field of order 35 and degree 24 To: Cyclotomic Field of order 105 and degree 48 - Defn: b -> -a^44 - a^42 + a^39 + a^37 + a^35 - a^29 - a^27 - a^25 + a^24 - a^23 + a^22 - a^21 + a^20 + a^18 + a^16 - a^12 - a^10 - a^8 - a^6 + a^5 + a^3 + a - sage: CC(b) + Defn: b -> -a^44 - a^42 + a^39 + a^37 + a^35 - a^29 - a^27 - a^25 + a^24 + - a^23 + a^22 - a^21 + a^20 + a^18 + a^16 - a^12 - a^10 + - a^8 - a^6 + a^5 + a^3 + a + sage: CC(b) # optional - sage.symbolic 0.936234870639737 + 0.351374824081343*I - sage: CC(-a^44 - a^42 + a^39 + a^37 + a^35 - a^29 - a^27 - a^25 + a^24 - a^23 + a^22 - a^21 + a^20 + a^18 + a^16 - a^12 - a^10 - a^8 - a^6 + a^5 + a^3 + a) + sage: CC(-a^44 - a^42 + a^39 + a^37 + a^35 - a^29 - a^27 - a^25 + a^24 # optional - sage.symbolic + ....: - a^23 + a^22 - a^21 + a^20 + a^18 + a^16 - a^12 - a^10 + ....: - a^8 - a^6 + a^5 + a^3 + a) 0.936234870639731 + 0.351374824081341*I - sage: z15 = CDF(exp(2*pi*I/15)) - sage: CyclotomicField(15).coerce_map_from(CyclotomicField(6, embedding=-z15^5)) + sage: z15 = CDF(exp(2*pi*I/15)) # optional - sage.symbolic + sage: K6 = CyclotomicField(6, embedding=-z15^5) # optional - sage.symbolic + sage: CyclotomicField(15).coerce_map_from(K6) # optional - sage.symbolic Generic morphism: From: Cyclotomic Field of order 6 and degree 2 To: Cyclotomic Field of order 15 and degree 8 Defn: zeta6 -> -zeta15^5 - sage: CyclotomicField(15, embedding=z15^4).coerce_map_from(CyclotomicField(6, embedding=-z15^5)) + sage: CyclotomicField(15, embedding=z15^4).coerce_map_from(K6) # optional - sage.symbolic Generic morphism: From: Cyclotomic Field of order 6 and degree 2 To: Cyclotomic Field of order 15 and degree 8 @@ -11016,13 +11117,13 @@ def _coerce_map_from_(self, K): def _log_gen(self, x): """ - Return an integer `e` such that `self.gen()^e == x`, or `None` + Return an integer `e` such that `self.gen()^e == x`, or ``None`` if no such integer exists. This is primarily used to construct embedding-respecting coercions. If `x` is complex, the result is either an integer `e` such - that the absolute value of `self.gen()^e-x` is small or - `None` if no such `e` is found. + that the absolute value of ``self.gen()^e - x`` is small or + ``None`` if no such `e` is found. EXAMPLES:: @@ -11032,30 +11133,33 @@ def _log_gen(self, x): sage: K._log_gen(CDF(a^4)) 4 - sage: zeta105 = CC(exp(2*pi*i/105)) - sage: K. = CyclotomicField(105, embedding=zeta105^13) - sage: zeta105^13, CC(a) - (0.712376096951345 + 0.701797902883992*I, 0.712376096951345 + 0.701797902883991*I) - sage: K._log_gen(zeta105^26) + sage: zeta105 = CC(exp(2*pi*i/105)) # optional - sage.symbolic + sage: K. = CyclotomicField(105, embedding=zeta105^13) # optional - sage.symbolic + sage: zeta105^13, CC(a) # optional - sage.symbolic + (0.712376096951345 + 0.701797902883992*I, + 0.712376096951345 + 0.701797902883991*I) + sage: K._log_gen(zeta105^26) # optional - sage.symbolic 2 - sage: K._log_gen(zeta105) + sage: K._log_gen(zeta105) # optional - sage.symbolic 97 - sage: zeta105, CC(a^97) - (0.998210129767735 + 0.0598041539450342*I, 0.998210129767736 + 0.0598041539450313*I) - sage: K._log_gen(zeta105^3) + sage: zeta105, CC(a^97) # optional - sage.symbolic + (0.998210129767735 + 0.0598041539450342*I, + 0.998210129767736 + 0.0598041539450313*I) + sage: K._log_gen(zeta105^3) # optional - sage.symbolic 81 - sage: zeta105^3, CC(a)^81 - (0.983929588598630 + 0.178556894798637*I, 0.983929588598631 + 0.178556894798635*I) + sage: zeta105^3, CC(a)^81 # optional - sage.symbolic + (0.983929588598630 + 0.178556894798637*I, + 0.983929588598631 + 0.178556894798635*I) sage: K. = CyclotomicField(5, embedding=None) sage: K._log_gen(CDF(.5, -.8)) is None True - sage: zeta5 = cyclotomic_polynomial(5).change_ring(Qp(11)).roots()[0][0] - sage: zeta5 ^ 5 + sage: zeta5 = cyclotomic_polynomial(5).change_ring(Qp(11)).roots()[0][0] # optional - sage.rings.padics + sage: zeta5 ^ 5 # optional - sage.rings.padics 1 + O(11^20) - sage: K. = CyclotomicField(5, embedding=zeta5^2) - sage: K._log_gen(zeta5) + sage: K. = CyclotomicField(5, embedding=zeta5^2) # optional - sage.rings.padics + sage: K._log_gen(zeta5) # optional - sage.rings.padics 3 sage: K60. = CyclotomicField(60) @@ -11103,20 +11207,19 @@ def _log_gen(self, x): gen_pow_e *= gen def _element_constructor_(self, x, check=True): - """ + r""" Create an element of this cyclotomic field from `x`. EXAMPLES: The following example illustrates coercion from the - cyclotomic field Q(zeta_42) to the cyclotomic field Q(zeta_6), in + cyclotomic field `\QQ(\zeta_{42})` to the cyclotomic field `\QQ(\zeta_6)`, in a case where such coercion is defined:: sage: k42 = CyclotomicField(42) sage: k6 = CyclotomicField(6) sage: a = k42.gen(0) - sage: b = a^7 - sage: b + sage: b = a^7; b zeta42^7 sage: k6(b) # indirect doctest zeta6 @@ -11136,9 +11239,9 @@ def _element_constructor_(self, x, check=True): sage: CF(E(5)) zeta10^2 - Coercion of GAP cyclotomic elements is also supported:: + Coercion of GAP cyclotomic elements is also supported:: - sage: CyclotomicField(18)(gap('E(3)')) # indirect doctest + sage: CyclotomicField(18)(gap('E(3)')) # indirect doctest # optional - sage.libs.gap zeta18^3 - 1 Converting from rings of integers:: @@ -11171,21 +11274,21 @@ def _element_constructor_(self, x, check=True): def _coerce_from_other_cyclotomic_field(self, x, only_canonical=False): """ - Coerce an element x of a cyclotomic field into self, if at all + Coerce an element `x` of a cyclotomic field into ``self``, if at all possible. INPUT: - - ``x`` - number field element + - ``x`` -- number field element - - ``only_canonical`` - bool (default: ``False``); Attempt - to work, even in some cases when x is not in a subfield of the - cyclotomics (as long as x is a root of unity). + - ``only_canonical`` -- bool (default: ``False``); Attempt + to work, even in some cases when `x` is not in a subfield of the + cyclotomics (as long as `x` is a root of unity). EXAMPLES:: - sage: K = CyclotomicField(24) ; L = CyclotomicField(48) - sage: L._coerce_from_other_cyclotomic_field(K.0+1) + sage: K = CyclotomicField(24); L = CyclotomicField(48) + sage: L._coerce_from_other_cyclotomic_field(K.0 + 1) zeta48^2 + 1 sage: K(L.0**2) zeta24 @@ -11232,12 +11335,11 @@ def _coerce_from_gap(self, x): EXAMPLES:: sage: k5. = CyclotomicField(5) - sage: w = libgap.eval('E(5)^7 + 3') - sage: w + sage: w = libgap.eval('E(5)^7 + 3'); w # optional - sage.libs.gap -3*E(5)-2*E(5)^2-3*E(5)^3-3*E(5)^4 - sage: z^7 + 3 + sage: z^7 + 3 # optional - sage.libs.gap z^2 + 3 - sage: k5(w) # indirect doctest + sage: k5(w) # indirect doctest # optional - sage.libs.gap z^2 + 3 It may be that GAP uses a name for the generator of the cyclotomic field. @@ -11245,28 +11347,28 @@ def _coerce_from_gap(self, x): sage: F = CyclotomicField(8) sage: z = F.gen() - sage: a = libgap(z+1/z); a + sage: a = libgap(z + 1/z); a # optional - sage.libs.gap E(8)-E(8)^3 - sage: F(a) + sage: F(a) # optional - sage.libs.gap -zeta8^3 + zeta8 Matrices over cyclotomic fields are correctly dealt with it as well:: - sage: b = libgap.eval('[[E(4), 1], [0, 1+E(8)-E(8)^3]]') - sage: matrix(F, b) + sage: b = libgap.eval('[[E(4), 1], [0, 1+E(8)-E(8)^3]]') # optional - sage.libs.gap + sage: matrix(F, b) # optional - sage.libs.gap [ zeta8^2 1] [ 0 -zeta8^3 + zeta8 + 1] It also works with the old pexpect interface to GAP:: - sage: a = gap(z + 1/z) - sage: b = gap(Matrix(F,[[z^2,1],[0,a+1]])); b + sage: a = gap(z + 1/z) # optional - sage.libs.gap + sage: b = gap(Matrix(F,[[z^2,1],[0,a+1]])); b # optional - sage.libs.gap [ [ E(4), 1 ], [ 0, 1+E(8)-E(8)^3 ] ] - sage: b[1,2] + sage: b[1,2] # optional - sage.libs.gap 1 - sage: F(b[1,2]) + sage: F(b[1,2]) # optional - sage.libs.gap 1 - sage: matrix(F, b) + sage: matrix(F, b) # optional - sage.libs.gap [ zeta8^2 1] [ 0 -zeta8^3 + zeta8 + 1] """ @@ -11278,10 +11380,10 @@ def _coerce_from_gap(self, x): def _Hom_(self, codomain, cat=None): """ - Return homset of homomorphisms from the cyclotomic field self to + Return homset of homomorphisms from the cyclotomic field ``self`` to the number field codomain. - The cat option is currently ignored. + The ``cat`` option is currently ignored. EXAMPLES: @@ -11293,7 +11395,9 @@ def _Hom_(self, codomain, cat=None): sage: K. = NumberField(x^2 + 3); K Number Field in a with defining polynomial x^2 + 3 sage: CyclotomicField(3).Hom(K) # indirect doctest - Set of field embeddings from Cyclotomic Field of order 3 and degree 2 to Number Field in a with defining polynomial x^2 + 3 + Set of field embeddings + from Cyclotomic Field of order 3 and degree 2 + to Number Field in a with defining polynomial x^2 + 3 sage: End(CyclotomicField(21)) Automorphism group of Cyclotomic Field of order 21 and degree 12 """ @@ -11305,7 +11409,7 @@ def _Hom_(self, codomain, cat=None): def is_galois(self): """ - Return True since all cyclotomic fields are automatically Galois. + Return ``True`` since all cyclotomic fields are automatically Galois. EXAMPLES:: @@ -11316,7 +11420,7 @@ def is_galois(self): def is_abelian(self): """ - Return True since all cyclotomic fields are automatically abelian. + Return ``True`` since all cyclotomic fields are automatically abelian. EXAMPLES:: @@ -11327,8 +11431,8 @@ def is_abelian(self): def is_isomorphic(self, other): """ - Return True if the cyclotomic field self is isomorphic as a number - field to other. + Return ``True`` if the cyclotomic field ``self`` is isomorphic as a number + field to ``other``. EXAMPLES:: @@ -11336,7 +11440,7 @@ def is_isomorphic(self, other): True sage: CyclotomicField(11).is_isomorphic(CyclotomicField(23)) False - sage: CyclotomicField(3).is_isomorphic(NumberField(x^2 + x +1, 'a')) + sage: CyclotomicField(3).is_isomorphic(NumberField(x^2 + x + 1, 'a')) True sage: CyclotomicField(18).is_isomorphic(CyclotomicField(9)) True @@ -11346,7 +11450,7 @@ def is_isomorphic(self, other): Check :trac:`14300`:: sage: K = CyclotomicField(4) - sage: N = K.extension(x^2-5, 'z') + sage: N = K.extension(x^2 - 5, 'z') sage: K.is_isomorphic(N) False sage: K.is_isomorphic(CyclotomicField(8)) @@ -11359,8 +11463,8 @@ def is_isomorphic(self, other): def complex_embedding(self, prec=53): r""" Return the embedding of this cyclotomic field into the approximate - complex field with precision prec obtained by sending the generator - `\zeta` of self to exp(2\*pi\*i/n), where `n` is + complex field with precision ``prec`` obtained by sending the generator + `\zeta` of ``self`` to exp(2\*pi\*i/n), where `n` is the multiplicative order of `\zeta`. EXAMPLES:: @@ -11372,8 +11476,8 @@ def complex_embedding(self, prec=53): To: Complex Field with 53 bits of precision Defn: zeta4 |--> 6.12323399573677e-17 + 1.00000000000000*I - Note in the example above that the way zeta is computed (using sin - and cosine in MPFR) means that only the prec bits of the number + Note in the example above that the way zeta is computed (using sine + and cosine in MPFR) means that only the ``prec`` bits of the number after the decimal point are valid. :: @@ -11395,7 +11499,7 @@ def complex_embedding(self, prec=53): @cached_method def embeddings(self, K): r""" - Compute all field embeddings of this field into the field ``K``. + Compute all field embeddings of this field into the field `K`. INPUT: @@ -11408,7 +11512,7 @@ def embeddings(self, K): From: Cyclotomic Field of order 5 and degree 4 To: Complex Field with 53 bits of precision Defn: zeta5 |--> -0.809016994374947 + 0.587785252292473*I - sage: CyclotomicField(5).embeddings(Qp(11, 4, print_mode='digits'))[1] + sage: CyclotomicField(5).embeddings(Qp(11, 4, print_mode='digits'))[1] # optional - sage.rings.padics Ring morphism: From: Cyclotomic Field of order 5 and degree 4 To: 11-adic Field with capped relative precision 4 @@ -11435,7 +11539,7 @@ def embeddings(self, K): def complex_embeddings(self, prec=53): r""" Return all embeddings of this cyclotomic field into the approximate - complex field with precision prec. + complex field with precision ``prec``. If you want 53-bit double precision, which is faster but less reliable, then do ``self.embeddings(CDF)``. @@ -11468,7 +11572,7 @@ def complex_embeddings(self, prec=53): def real_embeddings(self, prec=53): r""" Return all embeddings of this cyclotomic field into the approximate - real field with precision prec. + real field with precision ``prec``. Mostly, of course, there are no such embeddings. @@ -11488,12 +11592,12 @@ def real_embeddings(self, prec=53): return self.embeddings(K) def signature(self): - """ - Return (r1, r2), where r1 and r2 are the number of real embeddings + r""" + Return `(r_1, r_2)`, where `r_1` and `r_2` are the number of real embeddings and pairs of complex embeddings of this cyclotomic field, respectively. - Trivial since, apart from QQ, cyclotomic fields are totally + Trivial since, apart from `\QQ`, cyclotomic fields are totally complex. EXAMPLES:: @@ -11511,7 +11615,7 @@ def signature(self): def different(self): """ - Return the different ideal of the cyclotomic field self. + Return the different ideal of the cyclotomic field ``self``. EXAMPLES:: @@ -11543,20 +11647,17 @@ def different(self): def discriminant(self, v=None): """ Return the discriminant of the ring of integers of the cyclotomic - field self, or if v is specified, the determinant of the trace - pairing on the elements of the list v. + field ``self``, or if ``v`` is specified, the determinant of the trace + pairing on the elements of the list ``v``. Uses the formula for the discriminant of a prime power cyclotomic field and Hilbert Theorem 88 on the discriminant of composita. INPUT: + - ``v`` -- (optional) list of elements of this number field - - ``v (optional)`` - list of element of this number - field - - - OUTPUT: Integer if v is omitted, and Rational otherwise. + OUTPUT: Integer if ``v`` is omitted, and Rational otherwise. EXAMPLES:: @@ -11652,8 +11753,8 @@ def zeta_order(self): return self.__zeta_order def _multiplicative_order_table(self): - """ - Return a dictionary that maps powers of zeta to their order. This + r""" + Return a dictionary that maps powers of `\zeta` to their order. This makes computing the orders of the elements of finite order in this field faster. @@ -11684,7 +11785,7 @@ def zeta(self, n=None, all=False): Return an element of multiplicative order `n` in this cyclotomic field. - If there is no such element, raise a ``ValueError``. + If there is no such element, raise a :class:`ValueError`. INPUT: @@ -11968,27 +12069,26 @@ def _polymake_init_(self): def discriminant(self, v=None): """ Return the discriminant of the ring of integers of the number - field, or if v is specified, the determinant of the trace pairing - on the elements of the list v. + field, or if ``v`` is specified, the determinant of the trace pairing + on the elements of the list ``v``. INPUT: - - ``v (optional)`` - list of element of this number - field + - ``v`` -- (optional) list of element of this number field - OUTPUT: Integer if v is omitted, and Rational otherwise. + OUTPUT: Integer if ``v`` is omitted, and Rational otherwise. EXAMPLES:: - sage: K. = NumberField(x^2+1) + sage: K. = NumberField(x^2 + 1) sage: K.discriminant() -4 - sage: K. = NumberField(x^2+5) + sage: K. = NumberField(x^2 + 5) sage: K.discriminant() -20 - sage: K. = NumberField(x^2-5) + sage: K. = NumberField(x^2 - 5) sage: K.discriminant() 5 """ @@ -12006,7 +12106,7 @@ def discriminant(self, v=None): def is_galois(self): """ - Return True since all quadratic fields are automatically Galois. + Return ``True`` since all quadratic fields are automatically Galois. EXAMPLES:: @@ -12017,7 +12117,7 @@ def is_galois(self): def class_number(self, proof=None): r""" - Return the size of the class group of self. + Return the size of the class group of ``self``. INPUT: @@ -12042,7 +12142,8 @@ def class_number(self, proof=None): These are all the primes so that the class number of `\QQ(\sqrt{-p})` is `1`:: - sage: [d for d in prime_range(2,300) if not is_square(d) and QuadraticField(-d,'a').class_number() == 1] + sage: [d for d in prime_range(2,300) + ....: if not is_square(d) and QuadraticField(-d,'a').class_number() == 1] [2, 3, 7, 11, 19, 43, 67, 163] It is an open problem to *prove* that there are infinity many @@ -12051,7 +12152,8 @@ def class_number(self, proof=None): :: - sage: len([d for d in range(2,200) if not is_square(d) and QuadraticField(d,'a').class_number() == 1]) + sage: len([d for d in range(2,200) + ....: if not is_square(d) and QuadraticField(d,'a').class_number() == 1]) 121 TESTS:: @@ -12102,7 +12204,9 @@ def hilbert_class_field_defining_polynomial(self, name='x'): sage: K.class_number() 21 sage: K.hilbert_class_field_defining_polynomial(name='z') - z^21 + 6*z^20 + 9*z^19 - 4*z^18 + 33*z^17 + 140*z^16 + 220*z^15 + 243*z^14 + 297*z^13 + 461*z^12 + 658*z^11 + 743*z^10 + 722*z^9 + 681*z^8 + 619*z^7 + 522*z^6 + 405*z^5 + 261*z^4 + 119*z^3 + 35*z^2 + 7*z + 1 + z^21 + 6*z^20 + 9*z^19 - 4*z^18 + 33*z^17 + 140*z^16 + 220*z^15 + 243*z^14 + + 297*z^13 + 461*z^12 + 658*z^11 + 743*z^10 + 722*z^9 + 681*z^8 + 619*z^7 + + 522*z^6 + 405*z^5 + 261*z^4 + 119*z^3 + 35*z^2 + 7*z + 1 """ f = pari(self.discriminant()).quadhilbert() return QQ[name](f) @@ -12125,7 +12229,8 @@ def hilbert_class_field(self, names): sage: L = K.hilbert_class_field('b'); L Number Field in b with defining polynomial x^3 - x^2 + 1 over its base field sage: L.absolute_field('c') - Number Field in c with defining polynomial x^6 - 2*x^5 + 70*x^4 - 90*x^3 + 1631*x^2 - 1196*x + 12743 + Number Field in c with defining polynomial + x^6 - 2*x^5 + 70*x^4 - 90*x^3 + 1631*x^2 - 1196*x + 12743 sage: K.hilbert_class_field_defining_polynomial() x^3 - x^2 + 1 """ @@ -12161,7 +12266,7 @@ def number_of_roots_of_unity(self): """ Return the number of roots of unity in this quadratic field. - This is always 2 except when d is -3 or -4. + This is always 2 except when `d` is `-3` or `-4`. EXAMPLES:: @@ -12204,7 +12309,7 @@ def order_of_conductor(self, f): def is_fundamental_discriminant(D): r""" - Return True if the integer `D` is a fundamental + Return ``True`` if the integer `D` is a fundamental discriminant, i.e., if `D \cong 0,1\pmod{4}`, and `D\neq 0, 1` and either (1) `D` is square free or (2) we have `D\cong 0\pmod{4}` with @@ -12215,10 +12320,12 @@ def is_fundamental_discriminant(D): sage: [D for D in range(-15,15) if is_fundamental_discriminant(D)] ... - DeprecationWarning: is_fundamental_discriminant(D) is deprecated; please use D.is_fundamental_discriminant() + DeprecationWarning: is_fundamental_discriminant(D) is deprecated; + please use D.is_fundamental_discriminant() ... [-15, -11, -8, -7, -4, -3, 5, 8, 12, 13] - sage: [D for D in range(-15,15) if not is_square(D) and QuadraticField(D,'a').disc() == D] + sage: [D for D in range(-15,15) + ....: if not is_square(D) and QuadraticField(D,'a').disc() == D] [-15, -11, -8, -7, -4, -3, 5, 8, 12, 13] """ deprecation(35147, "is_fundamental_discriminant(D) is deprecated; please use D.is_fundamental_discriminant()") @@ -12292,19 +12399,19 @@ def put_natural_embedding_first(v): sage: K. = CyclotomicField(7) sage: embs = K.embeddings(K) - sage: [e(a) for e in embs] # random - there is no natural sort order + sage: [e(a) for e in embs] # random - there is no natural sort order [a, a^2, a^3, a^4, a^5, -a^5 - a^4 - a^3 - a^2 - a - 1] - sage: id = [ e for e in embs if e(a) == a ][0]; id + sage: id = [e for e in embs if e(a) == a][0]; id Ring endomorphism of Cyclotomic Field of order 7 and degree 6 Defn: a |--> a sage: permuted_embs = list(embs); permuted_embs.remove(id); permuted_embs.append(id) - sage: [e(a) for e in permuted_embs] # random - but natural map is not first + sage: [e(a) for e in permuted_embs] # random - but natural map is not first [a^2, a^3, a^4, a^5, -a^5 - a^4 - a^3 - a^2 - a - 1, a] sage: permuted_embs[0] != a True sage: from sage.rings.number_field.number_field import put_natural_embedding_first sage: put_natural_embedding_first(permuted_embs) - sage: [e(a) for e in permuted_embs] # random - but natural map is first + sage: [e(a) for e in permuted_embs] # random - but natural map is first [a, a^3, a^4, a^5, -a^5 - a^4 - a^3 - a^2 - a - 1, a^2] sage: permuted_embs[0] == id True @@ -12322,15 +12429,15 @@ def put_natural_embedding_first(v): def refine_embedding(e, prec=None): r""" Given an embedding from a number field to either `\RR` or - `\CC`, returns an equivalent embedding with higher precision. + `\CC`, return an equivalent embedding with higher precision. INPUT: - - ``e`` - an embedding of a number field into either - RR or CC (with some precision) + - ``e`` -- an embedding of a number field into either + `\RR` or `\CC` (with some precision) - - ``prec`` - (default None) the desired precision; if None, - current precision is doubled; if Infinity, the equivalent + - ``prec`` -- (default ``None``) the desired precision; if ``None``, + current precision is doubled; if ``Infinity``, the equivalent embedding into either ``QQbar`` or ``AA`` is returned. EXAMPLES:: @@ -12346,7 +12453,7 @@ def refine_embedding(e, prec=None): An example where we extend a real embedding into ``AA``:: - sage: K. = NumberField(x^3-2) + sage: K. = NumberField(x^3 - 2) sage: K.signature() (1, 1) sage: e = K.embeddings(RR)[0]; e @@ -12354,7 +12461,7 @@ def refine_embedding(e, prec=None): From: Number Field in a with defining polynomial x^3 - 2 To: Real Field with 53 bits of precision Defn: a |--> 1.25992104989487 - sage: e = refine_embedding(e,Infinity); e + sage: e = refine_embedding(e, Infinity); e Ring morphism: From: Number Field in a with defining polynomial x^3 - 2 To: Algebraic Real Field @@ -12366,7 +12473,7 @@ def refine_embedding(e, prec=None): 1.2599210498948731647672106072782283505702515 sage: _^3 2.0000000000000000000000000000000000000000000 - sage: RealField(200)(e(a^2-3*a+7)) + sage: RealField(200)(e(a^2 - 3*a + 7)) 4.8076379022835799804500738174376232086807389337953290695624 Complex embeddings can be extended into ``QQbar``:: @@ -12382,7 +12489,8 @@ def refine_embedding(e, prec=None): To: Algebraic Field Defn: a |--> -0.6299605249474365? - 1.091123635971722?*I sage: ComplexField(200)(e(a)) - -0.62996052494743658238360530363911417528512573235075399004099 - 1.0911236359717214035600726141898088813258733387403009407036*I + -0.62996052494743658238360530363911417528512573235075399004099 + - 1.0911236359717214035600726141898088813258733387403009407036*I sage: e(a)^3 2 @@ -12398,7 +12506,8 @@ def refine_embedding(e, prec=None): Ring morphism: From: Cyclotomic Field of order 7 and degree 6 To: Complex Field with 300 bits of precision - Defn: zeta7 |--> 0.623489801858733530525004884004239810632274730896402105365549439096853652456487284575942507 + 0.781831482468029808708444526674057750232334518708687528980634958045091731633936441700868007*I + Defn: zeta7 |--> 0.623489801858733530525004884004239810632274730896402105365549439096853652456487284575942507 + + 0.781831482468029808708444526674057750232334518708687528980634958045091731633936441700868007*I sage: refine_embedding(x, infinity) Ring morphism: From: Cyclotomic Field of order 7 and degree 6 @@ -12460,11 +12569,11 @@ def refine_embedding(e, prec=None): def is_real_place(v): r""" - Return ``True`` if ``v`` is real, ``False`` if ``v`` is complex + Return ``True`` if `v` is real, ``False`` if `v` is complex INPUT: - - ``v`` -- an infinite place of ``K`` + - ``v`` -- an infinite place of ``self`` OUTPUT: @@ -12472,7 +12581,7 @@ def is_real_place(v): EXAMPLES:: - sage: K. = NumberField(x^3-3) + sage: K. = NumberField(x^3 - 3) sage: phi_real = K.places()[0] sage: phi_complex = K.places()[1] sage: v_fin = tuple(K.primes_above(3))[0] @@ -12505,7 +12614,7 @@ def _splitting_classes_gens_(K, m, d): r""" Given a number field `K` of conductor `m` and degree `d`, this returns a set of multiplicative generators of the - subgroup of `(\mathbb{Z}/m\mathbb{Z})^{\times}` + subgroup of `(\ZZ/m\ZZ)^{\times}` containing exactly the classes that contain the primes splitting completely in `K`. diff --git a/src/sage/rings/number_field/number_field_base.pyx b/src/sage/rings/number_field/number_field_base.pyx index dd9a8b9d550..0a4e0beb664 100644 --- a/src/sage/rings/number_field/number_field_base.pyx +++ b/src/sage/rings/number_field/number_field_base.pyx @@ -1,3 +1,4 @@ +# sage.doctest: optional - sage.rings.number_field """ Base class for all number fields @@ -11,7 +12,7 @@ TESTS:: def is_NumberField(x): """ - Return True if ``x`` is of number field type. + Return ``True`` if ``x`` is of number field type. This function is deprecated. @@ -144,7 +145,7 @@ cdef class NumberField(Field): def ring_of_integers(self, *args, **kwds): r""" - Synonym for ``self.maximal_order(...)``. + Synonym for :meth:`maximal_order`. EXAMPLES:: @@ -156,7 +157,7 @@ cdef class NumberField(Field): def OK(self, *args, **kwds): r""" - Synonym for ``self.maximal_order(...)``. + Synonym for :meth:`maximal_order`. EXAMPLES:: @@ -166,7 +167,7 @@ cdef class NumberField(Field): return self.maximal_order(*args, **kwds) def maximal_order(self): - """ + r""" Return the maximal order, i.e., the ring of integers of this number field. @@ -178,8 +179,8 @@ cdef class NumberField(Field): raise NotImplementedError def is_absolute(self): - """ - Return True if self is viewed as a single extension over Q. + r""" + Return ``True`` if ``self`` is viewed as a single extension over `\QQ`. EXAMPLES:: @@ -196,8 +197,8 @@ cdef class NumberField(Field): raise NotImplementedError def signature(self): - """ - Return (r1, r2), where r1 and r2 are the number of real embeddings + r""" + Return `(r_1, r_2)`, where `r_1` and `r_2` are the number of real embeddings and pairs of complex embeddings of this field, respectively. EXAMPLES:: @@ -233,9 +234,9 @@ cdef class NumberField(Field): r""" Return the Minkowski bound associated to this number field. - This is a bound B so that every integral ideal is equivalent + This is a bound `B` so that every integral ideal is equivalent modulo principal fractional ideals to an integral ideal of - norm at most B. + norm at most `B`. .. SEEALSO:: @@ -308,9 +309,9 @@ cdef class NumberField(Field): r""" Return the Bach bound associated to this number field. - Assuming the General Riemann Hypothesis, this is a bound B so + Assuming the General Riemann Hypothesis, this is a bound `B` so that every integral ideal is equivalent modulo principal - fractional ideals to an integral ideal of norm at most B. + fractional ideals to an integral ideal of norm at most `B`. .. SEEALSO:: @@ -344,7 +345,8 @@ cdef class NumberField(Field): sage: K.bach_bound().n() 191669.304126267 - The bound of course also works for the rational numbers: + The bound of course also works for the rational numbers:: + sage: QQ.minkowski_bound() 1 """ @@ -419,7 +421,7 @@ cdef class NumberField(Field): If a real embedding is not specified, this method will result in an error:: - sage: N. = NumberField(x^3+2) + sage: N. = NumberField(x^3 + 2) sage: N._get_embedding_approx(1) Traceback (most recent call last): ... @@ -447,7 +449,7 @@ cdef class NumberField(Field): def _matrix_charpoly(self, M, var): r""" - Use PARI to compute the characteristic polynomial of self as a + Use PARI to compute the characteristic polynomial of ``self`` as a polynomial over the base ring. EXAMPLES:: diff --git a/src/sage/rings/number_field/number_field_element.pyx b/src/sage/rings/number_field/number_field_element.pyx index d80c87ea00c..e249bab8fa1 100644 --- a/src/sage/rings/number_field/number_field_element.pyx +++ b/src/sage/rings/number_field/number_field_element.pyx @@ -101,7 +101,7 @@ TUNE_CHARPOLY_NF = 25 def is_NumberFieldElement(x): """ - Return True if x is of type NumberFieldElement, i.e., an element of + Return ``True`` if `x` is of type :class:`NumberFieldElement`, i.e., an element of a number field. EXAMPLES:: @@ -162,10 +162,10 @@ def __create__NumberFieldElement_version1(parent, cls, poly): def _inverse_mod_generic(elt, I): r""" - Return an inverse of elt modulo the given ideal. This is a separate - function called from each of the OrderElement_xxx classes, since + Return an inverse of ``elt`` modulo the given ideal. This is a separate + function called from each of the ``OrderElement_xxx`` classes, since otherwise we'd have to have the same code three times over (there - is no OrderElement_generic class - no multiple inheritance). See + is no ``OrderElement_generic`` class - no multiple inheritance). See :trac:`4190`. EXAMPLES:: @@ -246,9 +246,9 @@ cdef class NumberFieldElement(NumberFieldElement_base): INPUT: - - ``parent`` - a number field + - ``parent`` -- a number field - - ``f`` - defines an element of a number field. + - ``f`` -- defines an element of a number field. EXAMPLES: @@ -532,10 +532,9 @@ cdef class NumberFieldElement(NumberFieldElement_base): sage: f = gap(F) sage: f.GeneratorsOfDivisionRing() [ E(8) ] - sage: p = F.gen()^2+2*F.gen()-3 - sage: p + sage: p = F.gen()^2 + 2*F.gen() - 3; p zeta8^2 + 2*zeta8 - 3 - sage: p._gap_init_() # The variable name $sage2 belongs to the gap(F) and is somehow random + sage: p._gap_init_() # The variable name $sage2 belongs to the gap(F) and is somehow random 'GeneratorsOfField($sage2)[1]^2 + 2*GeneratorsOfField($sage2)[1] - 3' sage: gap(p._gap_init_()) -3+2*E(8)+E(8)^2 @@ -574,19 +573,19 @@ cdef class NumberFieldElement(NumberFieldElement_base): EXAMPLES:: sage: F = CyclotomicField(8) - sage: F.gen()._libgap_() + sage: F.gen()._libgap_() # optional - sage.libs.gap E(8) - sage: libgap(F.gen()) # syntactic sugar + sage: libgap(F.gen()) # syntactic sugar # optional - sage.libs.gap E(8) - sage: E8 = F.gen() - sage: libgap(E8 + 3/2*E8^2 + 100*E8^7) + sage: E8 = F.gen() # optional - sage.libs.gap + sage: libgap(E8 + 3/2*E8^2 + 100*E8^7) # optional - sage.libs.gap E(8)+3/2*E(8)^2-100*E(8)^3 - sage: type(_) + sage: type(_) # optional - sage.libs.gap Check that :trac:`15276` is fixed:: - sage: for n in range(2,20): + sage: for n in range(2,20): # optional - sage.libs.gap ....: K = CyclotomicField(n) ....: assert K(libgap(K.gen())) == K.gen(), "n = {}".format(n) ....: assert K(libgap(K.one())) == K.one(), "n = {}".format(n) @@ -613,13 +612,13 @@ cdef class NumberFieldElement(NumberFieldElement_base): TESTS: sage: K. = NumberField(x^3 + 2) - sage: K.zero()._pari_polynomial('x') + sage: K.zero()._pari_polynomial('x') # optional - sage.libs.pari 0 - sage: K.one()._pari_polynomial() + sage: K.one()._pari_polynomial() # optional - sage.libs.pari 1 - sage: (a + 1)._pari_polynomial() + sage: (a + 1)._pari_polynomial() # optional - sage.libs.pari y + 1 - sage: a._pari_polynomial('c') + sage: a._pari_polynomial('c') # optional - sage.libs.pari c """ f = pari(self._coefficients()).Polrev() @@ -643,20 +642,20 @@ cdef class NumberFieldElement(NumberFieldElement_base): EXAMPLES:: sage: K. = NumberField(x^3 + 2) - sage: K(1).__pari__() + sage: K(1).__pari__() # optional - sage.libs.pari Mod(1, y^3 + 2) - sage: (a + 2).__pari__() + sage: (a + 2).__pari__() # optional - sage.libs.pari Mod(y + 2, y^3 + 2) sage: L. = K.extension(x^2 + 2) - sage: (b + a).__pari__() + sage: (b + a).__pari__() # optional - sage.libs.pari Mod(24/101*y^5 - 9/101*y^4 + 160/101*y^3 - 156/101*y^2 + 397/101*y + 364/101, y^6 + 6*y^4 - 4*y^3 + 12*y^2 + 24*y + 12) :: sage: k. = QuadraticField(-1) - sage: j.__pari__('j') + sage: j.__pari__('j') # optional - sage.libs.pari Mod(j, j^2 + 1) - sage: pari(j) + sage: pari(j) # optional - sage.libs.pari Mod(y, y^2 + 1) By default the variable name is 'y'. This allows 'x' to be used @@ -665,7 +664,7 @@ cdef class NumberFieldElement(NumberFieldElement_base): sage: P. = PolynomialRing(QQ) sage: K. = NumberField(a^2 + 1) sage: R. = PolynomialRing(K) - sage: pari(b*x) + sage: pari(b*x) # optional - sage.libs.pari Mod(y, y^2 + 1)*x In PARI many variable names are reserved, for example ``theta`` @@ -673,25 +672,25 @@ cdef class NumberFieldElement(NumberFieldElement_base): sage: R. = PolynomialRing(QQ) sage: K. = NumberField(theta^2 + 1) - sage: theta.__pari__('theta') + sage: theta.__pari__('theta') # optional - sage.libs.pari Traceback (most recent call last): ... PariError: theta already exists with incompatible valence - sage: theta.__pari__() + sage: theta.__pari__() # optional - sage.libs.pari Mod(y, y^2 + 1) sage: k. = QuadraticField(-1) - sage: I.__pari__('I') + sage: I.__pari__('I') # optional - sage.libs.pari Traceback (most recent call last): ... PariError: I already exists with incompatible valence Instead, request the variable be named different for the coercion:: - sage: pari(I) + sage: pari(I) # optional - sage.libs.pari Mod(y, y^2 + 1) - sage: I.__pari__('i') + sage: I.__pari__('i') # optional - sage.libs.pari Mod(i, i^2 + 1) - sage: I.__pari__('II') + sage: I.__pari__('II') # optional - sage.libs.pari Mod(II, II^2 + 1) Examples with relative number fields, which always yield an @@ -699,13 +698,13 @@ cdef class NumberFieldElement(NumberFieldElement_base): sage: y = QQ['y'].gen() sage: k. = NumberField([y^2 - 7, y^3 - 2]) - sage: pari(j) + sage: pari(j) # optional - sage.libs.pari Mod(42/5515*y^5 - 9/11030*y^4 - 196/1103*y^3 + 273/5515*y^2 + 10281/5515*y + 4459/11030, y^6 - 21*y^4 + 4*y^3 + 147*y^2 + 84*y - 339) sage: j^2 7 - sage: pari(j)^2 + sage: pari(j)^2 # optional - sage.libs.pari Mod(7, y^6 - 21*y^4 + 4*y^3 + 147*y^2 + 84*y - 339) - sage: (j^2).__pari__('x') + sage: (j^2).__pari__('x') # optional - sage.libs.pari Mod(7, x^6 - 21*x^4 + 4*x^3 + 147*x^2 + 84*x - 339) A tower of three number fields:: @@ -714,11 +713,11 @@ cdef class NumberFieldElement(NumberFieldElement_base): sage: K. = NumberField(x^2 + 2) sage: L. = NumberField(polygen(K)^2 + a) sage: M. = NumberField(polygen(L)^3 + b) - sage: L(b).__pari__() + sage: L(b).__pari__() # optional - sage.libs.pari Mod(y, y^4 + 2) - sage: M(b).__pari__('c') + sage: M(b).__pari__('c') # optional - sage.libs.pari Mod(-c^3, c^12 + 2) - sage: c.__pari__('c') + sage: c.__pari__('c') # optional - sage.libs.pari Mod(c, c^12 + 2) """ f = self._pari_polynomial(name) @@ -740,9 +739,9 @@ cdef class NumberFieldElement(NumberFieldElement_base): EXAMPLES:: sage: K. = NumberField(x^5 - x - 1) - sage: ((1 + 1/3*a)^4)._pari_init_() + sage: ((1 + 1/3*a)^4)._pari_init_() # optional - sage.libs.pari 'Mod(1/81*y^4 + 4/27*y^3 + 2/3*y^2 + 4/3*y + 1, y^5 - y - 1)' - sage: ((1 + 1/3*a)^4)._pari_init_('a') + sage: ((1 + 1/3*a)^4)._pari_init_('a') # optional - sage.libs.pari 'Mod(1/81*a^4 + 4/27*a^3 + 2/3*a^2 + 4/3*a + 1, a^5 - a - 1)' Note that _pari_init_ can fail because of reserved words in @@ -752,7 +751,7 @@ cdef class NumberFieldElement(NumberFieldElement_base): sage: K. = NumberField(x^5 - x - 1) sage: b = (1/2 - 2/3*theta)^3; b -8/27*theta^3 + 2/3*theta^2 - 1/2*theta + 1/8 - sage: b._pari_init_('theta') + sage: b._pari_init_('theta') # optional - sage.libs.pari Traceback (most recent call last): ... PariError: theta already exists with incompatible valence @@ -760,7 +759,7 @@ cdef class NumberFieldElement(NumberFieldElement_base): Fortunately pari_init returns everything in terms of y by default:: - sage: pari(b) + sage: pari(b) # optional - sage.libs.pari Mod(-8/27*y^3 + 2/3*y^2 - 1/2*y + 1/8, y^5 - y - 1) """ return repr(self.__pari__(name=name)) @@ -796,7 +795,7 @@ cdef class NumberFieldElement(NumberFieldElement_base): ... IndexError: index must be between 0 and degree minus 1 - The list method implicitly calls ``__getitem__``:: + The :func:`list` function implicitly calls :meth:`__getitem__`:: sage: list(c) [8/27, -16/15, 32/25, -64/125] @@ -904,15 +903,15 @@ cdef class NumberFieldElement(NumberFieldElement_base): def _random_element(self, num_bound=None, den_bound=None, distribution=None): """ - Return a new random element with the same parent as self. + Return a new random element with the same parent as ``self``. INPUT: - - ``num_bound`` - Bound for the numerator of coefficients of result + - ``num_bound`` -- Bound for the numerator of coefficients of result - - ``den_bound`` - Bound for the denominator of coefficients of result + - ``den_bound`` -- Bound for the denominator of coefficients of result - - ``distribution`` - Distribution to use for coefficients of result + - ``distribution`` -- Distribution to use for coefficients of result EXAMPLES:: @@ -1268,9 +1267,9 @@ cdef class NumberFieldElement(NumberFieldElement_base): 4 sage: (-b).round() -4 - sage: (b+1/2).round() + sage: (b + 1/2).round() 5 - sage: (-b-1/2).round() + sage: (-b - 1/2).round() -5 This function always succeeds even if a tremendous precision is needed:: @@ -1321,9 +1320,9 @@ cdef class NumberFieldElement(NumberFieldElement_base): INPUT: - - ``prec`` - (default: None) integer bits of precision + - ``prec`` -- (default: None) integer bits of precision - - ``i`` - (default: None) integer, which embedding to + - ``i`` -- (default: None) integer, which embedding to use @@ -1334,19 +1333,19 @@ cdef class NumberFieldElement(NumberFieldElement_base): 1.00000000000000 sage: abs(z^2 + 17*z - 3) 16.0604426799931 - sage: K. = NumberField(x^3+17) + sage: K. = NumberField(x^3 + 17) sage: abs(a) 2.57128159065824 sage: a.abs(prec=100) 2.5712815906582353554531872087 - sage: a.abs(prec=100,i=1) + sage: a.abs(prec=100, i=1) 2.5712815906582353554531872087 sage: a.abs(100, 2) 2.5712815906582353554531872087 Here's one where the absolute value depends on the embedding:: - sage: K. = NumberField(x^2-2) + sage: K. = NumberField(x^2 - 2) sage: a = 1 + b sage: a.abs(i=0) 0.414213562373095 @@ -1406,10 +1405,10 @@ cdef class NumberFieldElement(NumberFieldElement_base): INPUT: - - ``P`` - a prime ideal of the parent of self + - ``P`` -- a prime ideal of the parent of ``self`` - ``prec`` (int) -- desired floating point precision (default: - default RealField precision). + default :class:`RealField` precision). OUTPUT: @@ -1421,7 +1420,7 @@ cdef class NumberFieldElement(NumberFieldElement_base): EXAMPLES:: - sage: K. = NumberField(x^2+5) + sage: K. = NumberField(x^2 + 5) sage: [1/K(2).abs_non_arch(P) for P in K.primes_above(2)] [2.00000000000000] sage: [1/K(3).abs_non_arch(P) for P in K.primes_above(3)] @@ -1431,7 +1430,7 @@ cdef class NumberFieldElement(NumberFieldElement_base): A relative example:: - sage: L. = K.extension(x^2-5) + sage: L. = K.extension(x^2 - 5) sage: [b.abs_non_arch(P) for P in L.primes_above(b)] [0.447213595499958, 0.447213595499958] """ @@ -1449,9 +1448,9 @@ cdef class NumberFieldElement(NumberFieldElement_base): def coordinates_in_terms_of_powers(self): r""" - Let `\alpha` be self. Return a callable object (of type + Let `\alpha` be ``self``. Return a callable object (of type :class:`~CoordinateFunction`) that takes any element of the - parent of self in `\QQ(\alpha)` and writes it in terms of the + parent of ``self`` in `\QQ(\alpha)` and writes it in terms of the powers of `\alpha`: `1, \alpha, \alpha^2, ...`. (NOT CACHED). @@ -1478,7 +1477,7 @@ cdef class NumberFieldElement(NumberFieldElement_base): sage: c((1+beta)^10) [54, 162, 189] - This function works even if self only generates a subfield of this + This function works even if ``self`` only generates a subfield of this number field. :: @@ -1514,25 +1513,29 @@ cdef class NumberFieldElement(NumberFieldElement_base): INPUT: - - ``prec`` - integer (default: 53) bits of precision + - ``prec`` -- integer (default: 53) bits of precision EXAMPLES:: sage: k. = NumberField(x^3 - 2) sage: a.complex_embeddings() - [-0.629960524947437 - 1.09112363597172*I, -0.629960524947437 + 1.09112363597172*I, 1.25992104989487] + [-0.629960524947437 - 1.09112363597172*I, + -0.629960524947437 + 1.09112363597172*I, + 1.25992104989487] sage: a.complex_embeddings(10) [-0.63 - 1.1*I, -0.63 + 1.1*I, 1.3] sage: a.complex_embeddings(100) - [-0.62996052494743658238360530364 - 1.0911236359717214035600726142*I, -0.62996052494743658238360530364 + 1.0911236359717214035600726142*I, 1.2599210498948731647672106073] + [-0.62996052494743658238360530364 - 1.0911236359717214035600726142*I, + -0.62996052494743658238360530364 + 1.0911236359717214035600726142*I, + 1.2599210498948731647672106073] """ phi = self.number_field().complex_embeddings(prec) return [f(self) for f in phi] def complex_embedding(self, prec=53, i=0): """ - Return the i-th embedding of self in the complex numbers, to the + Return the `i`-th embedding of ``self`` in the complex numbers, to the given precision. EXAMPLES:: @@ -1583,35 +1586,36 @@ cdef class NumberFieldElement(NumberFieldElement_base): def is_norm(self, L, element=False, proof=True): r""" - Determine whether self is the relative norm of an element - of L/K, where K is self.parent(). + Determine whether ``self`` is the relative norm of an element + of `L/K`, where `K` is ``self.parent()``. INPUT: - - L -- a number field containing K=self.parent() - - element -- True or False, whether to also output an element - of which self is a norm - - proof -- If True, then the output is correct unconditionally. - If False, then the output is correct under GRH. + - ``L`` -- a number field containing `K` = ``self.parent()``. + - ``element`` -- ``True`` or ``False``, whether to also output an element + of which ``self`` is a norm. + - ``proof`` -- If ``True``, then the output is correct unconditionally. + If ``False``, then the output is correct under GRH. OUTPUT: - If element is False, then the output is a boolean B, which is - True if and only if self is the relative norm of an element of L - to K. - If element is False, then the output is a pair (B, x), where - B is as above. If B is True, then x is an element of L such that - self == x.norm(K). Otherwise, x is None. + If ``element`` is ``False``, then the output is a boolean `B`, which is + ``True`` if and only if ``self`` is the relative norm of an element of `L` + to `K`. + + If ``element`` is ``True``, then the output is a pair `(B, x)`, where + `B` is as above. If `B` is ``True``, then `x` is an element of `L` such that + ``self == x.norm(K)``. Otherwise, `x` is ``None``. ALGORITHM: - Uses PARI's :pari:`rnfisnorm`. See self._rnfisnorm(). + Uses PARI's :pari:`rnfisnorm`. See :meth:`_rnfisnorm`. EXAMPLES:: - sage: K. = NumberField(x^3+5) + sage: K. = NumberField(x^3 + 5) sage: Q. = K[] - sage: L = K.extension(X^2+X+beta, 'gamma') + sage: L = K.extension(X^2 + X + beta, 'gamma') sage: (beta/2).is_norm(L) False sage: beta.is_norm(L) @@ -1637,14 +1641,15 @@ cdef class NumberFieldElement(NumberFieldElement_base): sage: (a/2).is_norm(L) Traceback (most recent call last): ... - NotImplementedError: is_norm is not implemented unconditionally for norms from non-Galois number fields + NotImplementedError: is_norm is not implemented unconditionally + for norms from non-Galois number fields sage: (a/2).is_norm(L, proof=False) False sage: K. = NumberField(x^3 + x + 1) sage: Q. = K[] sage: L. = NumberField(X^4 + a) - sage: t, u = (-a).is_norm(L, element=True); u # random (not unique) + sage: t, u = (-a).is_norm(L, element=True); u # random (not unique) b^3 + 1 sage: t and u.norm(K) == -a True @@ -1654,7 +1659,8 @@ cdef class NumberFieldElement(NumberFieldElement_base): sage: L. = CyclotomicField(24); L Cyclotomic Field of order 24 and degree 8 sage: K = L.subfield(z24^3, 'z8')[0]; K - Number Field in z8 with defining polynomial x^4 + 1 with z8 = 0.7071067811865475? + 0.7071067811865475?*I + Number Field in z8 with defining polynomial x^4 + 1 + with z8 = 0.7071067811865475? + 0.7071067811865475?*I sage: flag, c = K(-7).is_norm(K, element=True); flag True sage: c.norm(K) @@ -1711,41 +1717,41 @@ cdef class NumberFieldElement(NumberFieldElement_base): def _rnfisnorm(self, L, proof=True, extra_primes=0): r""" - Gives the output of the PARI function rnfisnorm. + Give the output of the PARI function :pari:`rnfisnorm`. - This tries to decide whether the number field element self is - the norm of some x in the extension L/K (with K = self.parent()). + This tries to decide whether the number field element ``self`` is + the norm of some `x` in the extension `L/K` (with `K` = ``self.parent()``). - The output is a pair (x, q), where self = Norm(x)*q. The - algorithm looks for a solution x that is an S-integer, with S - a list of places of L containing at least the ramified primes, - the generators of the class group of L, as well as those primes + The output is a pair `(x, q)`, where ``self`` = ``Norm(x)*q``. The + algorithm looks for a solution `x` that is an `S`-integer, with `S` + a list of places of `L` containing at least the ramified primes, + the generators of the class group of `L`, as well as those primes dividing self. - If L/K is Galois, then this is enough; otherwise, - extra_primes is used to add more primes to S: all the places - above the primes p <= extra_primes (resp. p|extra_primes) if - extra_primes > 0 (resp. extra_primes < 0). + If `L/K` is Galois, then this is enough; otherwise, + ``extra_primes`` is used to add more primes to `S`: all the places + above the primes `p \leq ` ``extra_primes`` (resp., `p \mid` ``extra_primes``) if + ``extra_primes`` > 0 (resp., ``extra_primes`` < 0). - The answer is guaranteed (i.e., self is a norm iff q = 1) if the - field is Galois, or, under GRH, if S contains all primes less - than 12log^2|\disc(M)|, where M is the normal closure of L/K. + The answer is guaranteed (i.e., ``self`` is a norm iff `q = 1`) if the + field is Galois, or, under GRH, if `S` contains all primes less + than `12 \log^2|\disc(M)|`, where `M` is the normal closure of `L/K`. INPUT: - - L -- a relative number field with base field self.parent() - - proof -- whether to certify outputs of PARI init functions. - If false, truth of the output depends on GRH. - - extra_primes -- an integer as explained above. + - `L` -- a relative number field with base field ``self.parent()`` + - ``proof`` -- whether to certify outputs of PARI init functions. + If ``False``, truth of the output depends on GRH. + - ``extra_primes`` -- an integer as explained above. OUTPUT: - A pair (x, q) with x in L and q in K as explained above - such that self == x.norm(K)*q. + A pair `(x, q)` with `x` in `L` and `q` in `K` as explained above + such that ``self == x.norm(K)*q``. ALGORITHM: - Uses PARI's rnfisnorm. + Uses PARI's :pari:`rnfisnorm`. EXAMPLES:: @@ -1839,14 +1845,14 @@ cdef class NumberFieldElement(NumberFieldElement_base): Verify that :trac:`13005` has been fixed:: - sage: K. = NumberField(x^2-5) + sage: K. = NumberField(x^2 - 5) sage: RR(K(1)) 1.00000000000000 sage: RR(a) Traceback (most recent call last): ... TypeError: Unable to coerce a to a rational - sage: K. = NumberField(x^3+2, embedding=-1.25) + sage: K. = NumberField(x^3 + 2, embedding=-1.25) sage: RR(a) -1.25992104989487 sage: RealField(prec=100)(a) @@ -1956,17 +1962,17 @@ cdef class NumberFieldElement(NumberFieldElement_base): OUTPUT: - (Factorization) If all the prime ideals in the support are - principal, the output is a Factorization as a product of prime + (:class:`Factorization`) If all the prime ideals in the support are + principal, the output is a :class:`Factorization` as a product of prime elements raised to appropriate powers, with an appropriate unit factor. - Raise ValueError if the factorization of the - ideal (self) contains a non-principal prime ideal. + Raise :class:`ValueError` if the factorization of the + ideal (``self``) contains a non-principal prime ideal. EXAMPLES:: - sage: K. = NumberField(x^2+1) + sage: K. = NumberField(x^2 + 1) sage: (6*i + 6).factor() (-i) * (i + 1)^3 * 3 @@ -2021,8 +2027,8 @@ cdef class NumberFieldElement(NumberFieldElement_base): EXAMPLES:: - sage: K. = NumberField(x^2+1) - sage: (1+i).is_prime() + sage: K. = NumberField(x^2 + 1) + sage: (1 + i).is_prime() True sage: ((1+i)/2).is_prime() False @@ -2046,7 +2052,7 @@ cdef class NumberFieldElement(NumberFieldElement_base): - A generator of the ideal ``(self, other)``. If the parent is a number field, this always returns 0 or 1. For maximal orders, - this raises ``ArithmeticError`` if the ideal is not principal. + this raises :class:`ArithmeticError` if the ideal is not principal. EXAMPLES:: @@ -2067,7 +2073,8 @@ cdef class NumberFieldElement(NumberFieldElement_base): sage: R(1).gcd(R(4*i)) Traceback (most recent call last): ... - NotImplementedError: gcd() for Order in Number Field in i with defining polynomial x^2 + 1 with i = 1*I is not implemented + NotImplementedError: gcd() for Order in Number Field in i + with defining polynomial x^2 + 1 with i = 1*I is not implemented The following field has class number 3, but if the ideal ``(self, other)`` happens to be principal, this still works:: @@ -2111,13 +2118,13 @@ cdef class NumberFieldElement(NumberFieldElement_base): def is_totally_positive(self): """ - Returns True if self is positive for all real embeddings of its + Return ``True`` if ``self`` is positive for all real embeddings of its parent number field. We do nothing at complex places, so e.g. any - element of a totally complex number field will return True. + element of a totally complex number field will return ``True``. EXAMPLES:: - sage: F. = NumberField(x^3-3*x-1) + sage: F. = NumberField(x^3 - 3*x - 1) sage: b.is_totally_positive() False sage: (b^2).is_totally_positive() @@ -2132,19 +2139,19 @@ cdef class NumberFieldElement(NumberFieldElement_base): sage: a = 30122754096401; b = 21300003689580 sage: (a/b)^2 > 2 True - sage: (a/b+sqrt2).is_totally_positive() + sage: (a/b + sqrt2).is_totally_positive() True sage: r = RealField(3020)(2).sqrt()*2^3000 sage: a = floor(r)/2^3000 sage: b = ceil(r)/2^3000 - sage: (a+sqrt2).is_totally_positive() + sage: (a + sqrt2).is_totally_positive() False - sage: (b+sqrt2).is_totally_positive() + sage: (b + sqrt2).is_totally_positive() True Check that 0 is handled correctly:: - sage: K. = NumberField(x^5+4*x+1) + sage: K. = NumberField(x^5 + 4*x + 1) sage: K(0).is_totally_positive() False """ @@ -2155,14 +2162,14 @@ cdef class NumberFieldElement(NumberFieldElement_base): def is_square(self, root=False): """ - Return True if self is a square in its parent number field and - otherwise return False. + Return ``True`` if ``self`` is a square in its parent number field and + otherwise return ``False``. INPUT: - - ``root`` - if True, also return a square root (or - None if self is not a perfect square) + - ``root`` -- if ``True``, also return a square root (or + ``None`` if ``self`` is not a perfect square) EXAMPLES:: @@ -2185,7 +2192,7 @@ cdef class NumberFieldElement(NumberFieldElement_base): (True, 2/3*b + 5) sage: is_square(c) True - sage: is_square(c+1) + sage: is_square(c + 1) False TESTS: @@ -2273,7 +2280,7 @@ cdef class NumberFieldElement(NumberFieldElement_base): Using the ``extend`` keyword:: sage: K = QuadraticField(-5) - sage: z = K(-7).sqrt(extend=True); z + sage: z = K(-7).sqrt(extend=True); z # optional - sage.symbolic sqrt(-7) sage: CyclotomicField(4)(4).sqrt(extend=False) 2 @@ -2284,9 +2291,10 @@ cdef class NumberFieldElement(NumberFieldElement_base): sage: K(-7).sqrt(extend=False) Traceback (most recent call last): ... - ValueError: -7 not a square in Number Field in a with defining polynomial x^2 + 5 with a = 2.236067977499790?*I + ValueError: -7 not a square in Number Field in a + with defining polynomial x^2 + 5 with a = 2.236067977499790?*I - ALGORITHM: Use PARI to factor `x^2` - ``self`` in `K`. + ALGORITHM: Use PARI to factor `x^2` `-` ``self`` in `K`. """ # For now, use pari's factoring abilities K = self.number_field() @@ -2338,11 +2346,11 @@ cdef class NumberFieldElement(NumberFieldElement_base): def is_nth_power(self, n): r""" - Return True if ``self`` is an `n`'th power in its parent `K`. + Return ``True`` if ``self`` is an `n`'th power in its parent `K`. EXAMPLES:: - sage: K. = NumberField(x^4-7) + sage: K. = NumberField(x^4 - 7) sage: K(7).is_nth_power(2) True sage: K(7).is_nth_power(4) @@ -2373,12 +2381,12 @@ cdef class NumberFieldElement(NumberFieldElement_base): If the exponent is not integral, perform this operation in the symbolic ring:: - sage: sqrt2^(1/5) + sage: sqrt2^(1/5) # optional - sage.symbolic 2^(1/10) - sage: sqrt2^sqrt2 + sage: sqrt2^sqrt2 # optional - sage.symbolic 2^(1/2*sqrt(2)) - Sage follows Python's convention 0^0 = 1:: + Sage follows Python's convention `0^0 = 1`:: sage: a = K(0)^0; a 1 @@ -2393,10 +2401,10 @@ cdef class NumberFieldElement(NumberFieldElement_base): Test :trac:`14895`:: sage: K. = QuadraticField(2) - sage: 2^sqrt2 + sage: 2^sqrt2 # optional - sage.symbolic 2^sqrt(2) sage: K. = NumberField(x^2+1) - sage: 2^a + sage: 2^a # optional - sage.symbolic Traceback (most recent call last): ... TypeError: no canonical coercion from Number Field in a with defining polynomial x^2 + 1 to Symbolic Ring @@ -2638,7 +2646,7 @@ cdef class NumberFieldElement(NumberFieldElement_base): def __bool__(self): """ - Return True if this number field element is nonzero. + Return ``True`` if this number field element is nonzero. EXAMPLES:: @@ -2751,7 +2759,7 @@ cdef class NumberFieldElement(NumberFieldElement_base): def __invert__(self): """ - Returns the multiplicative inverse of self in the number field. + Return the multiplicative inverse of self in the number field. EXAMPLES:: @@ -2885,15 +2893,15 @@ cdef class NumberFieldElement(NumberFieldElement_base): EXAMPLES:: sage: K. = QuadraticField(2) - sage: SR(a) # indirect doctest + sage: SR(a) # indirect doctest # optional - sage.symbolic sqrt(2) - sage: SR(3*a-5) # indirect doctest + sage: SR(3*a-5) # indirect doctest # optional - sage.symbolic 3*sqrt(2) - 5 sage: K. = QuadraticField(2, embedding=-1.4) - sage: SR(a) # indirect doctest + sage: SR(a) # indirect doctest # optional - sage.symbolic -sqrt(2) sage: K. = NumberField(x^2 - 2) - sage: SR(a) # indirect doctest + sage: SR(a) # indirect doctest # optional - sage.symbolic Traceback (most recent call last): ... TypeError: an embedding into RR or CC must be specified @@ -2901,29 +2909,29 @@ cdef class NumberFieldElement(NumberFieldElement_base): Now a more complicated example:: sage: K. = NumberField(x^3 + x - 1, embedding=0.68) - sage: b = SR(a); b # indirect doctest + sage: b = SR(a); b # indirect doctest # optional - 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() + sage: (b^3 + b - 1).canonicalize_radical() # optional - sage.symbolic 0 Make sure we got the right one:: sage: CC(a) 0.682327803828019 - sage: CC(b) + sage: CC(b) # optional - sage.symbolic 0.682327803828019 Special case for cyclotomic fields:: sage: K. = CyclotomicField(19) - sage: SR(zeta) # indirect doctest + sage: SR(zeta) # indirect doctest # optional - sage.symbolic e^(2/19*I*pi) sage: CC(zeta) 0.945817241700635 + 0.324699469204683*I - sage: CC(SR(zeta)) + sage: CC(SR(zeta)) # optional - sage.symbolic 0.945817241700635 + 0.324699469204683*I - sage: SR(zeta^5 + 2) + sage: SR(zeta^5 + 2) # optional - sage.symbolic e^(10/19*I*pi) + 2 For degree greater than 5, sometimes Galois theory prevents a @@ -2932,22 +2940,22 @@ cdef class NumberFieldElement(NumberFieldElement_base): printed as a numerical approximation:: sage: K. = NumberField(x^5-x+1, embedding=-1) - sage: SR(a) + sage: SR(a) # optional - sage.symbolic -1.167303978261419? :: sage: K. = NumberField(x^6-x^3-1, embedding=1) - sage: SR(a) + sage: SR(a) # optional - 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: SR(a) + sage: SR(a) # optional - sage.symbolic 0.3319890295845093?*I - sage: SR(a^5+3*a) + sage: SR(a^5+3*a) # optional - sage.symbolic I Conversely, some elements are too complicated to be written in @@ -2959,10 +2967,11 @@ cdef class NumberFieldElement(NumberFieldElement_base): sage: K. = NumberField(QQ['x']([6, -65, 163, -185, 81, -15, 1]), embedding=4.9) sage: b = a + a^3 - sage: SR(b.minpoly()).solve(SR('x'), explicit_solutions=True) + sage: SR(b.minpoly()).solve(SR('x'), explicit_solutions=True) # optional - sage.symbolic [] - sage: SR(b) - 1/8*(sqrt(4*(1/9*sqrt(109)*sqrt(3) + 2)^(1/3) - 4/3/(1/9*sqrt(109)*sqrt(3) + 2)^(1/3) + 17) + 5)^3 + 1/2*sqrt(4*(1/9*sqrt(109)*sqrt(3) + 2)^(1/3) - 4/3/(1/9*sqrt(109)*sqrt(3) + 2)^(1/3) + 17) + 5/2 + sage: SR(b) # optional - sage.symbolic + 1/8*(sqrt(4*(1/9*sqrt(109)*sqrt(3) + 2)^(1/3) - 4/3/(1/9*sqrt(109)*sqrt(3) + 2)^(1/3) + 17) + 5)^3 + + 1/2*sqrt(4*(1/9*sqrt(109)*sqrt(3) + 2)^(1/3) - 4/3/(1/9*sqrt(109)*sqrt(3) + 2)^(1/3) + 17) + 5/2 TESTS: @@ -2972,7 +2981,7 @@ cdef class NumberFieldElement(NumberFieldElement_base): sage: p = x^8 + x^7 - 9*x^6 - 3*x^5 - 6*x^4 + x^3 - 14*x^2 + 2*x + 2 sage: rt = sorted(p.roots(AA, multiplicities=False))[1] sage: K. = NumberField(p, embedding=rt) - sage: SR(a) + sage: SR(a) # optional - sage.symbolic -0.3056815681115094? """ @@ -3012,7 +3021,7 @@ cdef class NumberFieldElement(NumberFieldElement_base): def galois_conjugates(self, K): r""" Return all Gal(Qbar/Q)-conjugates of this number field element in - the field K. + the field `K`. EXAMPLES: @@ -3068,7 +3077,7 @@ cdef class NumberFieldElement(NumberFieldElement_base): This is only well-defined for fields contained in CM fields (i.e. for totally real fields and CM fields). Recall that a CM field is a totally imaginary quadratic extension of a totally - real field. For other fields, a ValueError is raised. + real field. For other fields, a :class:`ValueError` is raised. EXAMPLES:: @@ -3090,7 +3099,7 @@ cdef class NumberFieldElement(NumberFieldElement_base): sage: j.conjugate() -j - Raise a ValueError if the field is not contained in a CM field. + Raise a :class:`ValueError` if the field is not contained in a CM field. :: @@ -3098,7 +3107,8 @@ cdef class NumberFieldElement(NumberFieldElement_base): sage: b.conjugate() Traceback (most recent call last): ... - ValueError: Complex conjugation is only well-defined for fields contained in CM fields. + ValueError: Complex conjugation is only well-defined + for fields contained in CM fields. An example of a non-quadratic totally real field. @@ -3300,7 +3310,7 @@ cdef class NumberFieldElement(NumberFieldElement_base): sage: a.multiplicative_order() 3 - You can be evil with this so be careful. That's why the function + You can be evil with this, so be careful. That's why the function name begins with an underscore. :: @@ -3326,7 +3336,7 @@ cdef class NumberFieldElement(NumberFieldElement_base): +Infinity sage: x = polygen(QQ) - sage: K.=NumberField(x^40 - x^20 + 4) + sage: K. = NumberField(x^40 - x^20 + 4) sage: u = 1/4*a^30 + 1/4*a^10 + 1/2 sage: u.multiplicative_order() 6 @@ -3374,8 +3384,8 @@ cdef class NumberFieldElement(NumberFieldElement_base): def additive_order(self): r""" - Return the additive order of this element (i.e. infinity if - self != 0, 1 if self == 0) + Return the additive order of this element (i.e., infinity if + ``self != 0`` and 1 if ``self == 0``) EXAMPLES:: @@ -3384,7 +3394,7 @@ cdef class NumberFieldElement(NumberFieldElement_base): +Infinity sage: K(0).additive_order() 1 - sage: K.ring_of_integers().characteristic() # implicit doctest + sage: K.ring_of_integers().characteristic() # implicit doctest 0 """ if not self: return ZZ.one() @@ -3413,7 +3423,7 @@ cdef class NumberFieldElement(NumberFieldElement_base): cpdef bint is_rational(self): r""" - Test whether this number field element is a rational number + Test whether this number field element is a rational number. .. SEEALSO:: @@ -3438,7 +3448,7 @@ cdef class NumberFieldElement(NumberFieldElement_base): def is_integer(self): r""" - Test whether this number field element is an integer + Test whether this number field element is an integer. .. SEEALSO:: @@ -3462,21 +3472,21 @@ cdef class NumberFieldElement(NumberFieldElement_base): return ZZX_deg(self.__numerator) <= 0 and ZZ_IsOne(self.__denominator) == 1 def trace(self, K=None): - """ + r""" Return the absolute or relative trace of this number field element. - If K is given then K must be a subfield of the parent L of self, in - which case the trace is the relative trace from L to K. In all - other cases, the trace is the absolute trace down to QQ. + If `K` is given, then `K` must be a subfield of the parent `L` of ``self``, in + which case the trace is the relative trace from `L` to `K`. In all + other cases, the trace is the absolute trace down to `\QQ`. EXAMPLES:: - sage: K. = NumberField(x^3 -132/7*x^2 + x + 1); K + sage: K. = NumberField(x^3 - 132/7*x^2 + x + 1); K Number Field in a with defining polynomial x^3 - 132/7*x^2 + x + 1 sage: a.trace() 132/7 - sage: (a+1).trace() == a.trace() + 3 + sage: (a + 1).trace() == a.trace() + 3 True If we are in an order, the trace is an integer:: @@ -3488,7 +3498,7 @@ cdef class NumberFieldElement(NumberFieldElement_base): TESTS:: - sage: F. = CyclotomicField(5) ; t = 3*z**3 + 4*z**2 + 2 + sage: F. = CyclotomicField(5); t = 3*z**3 + 4*z**2 + 2 sage: t.trace(F) 3*z^3 + 4*z^2 + 2 """ @@ -3498,12 +3508,12 @@ cdef class NumberFieldElement(NumberFieldElement_base): return self.matrix(K).trace() def norm(self, K=None): - """ + r""" Return the absolute or relative norm of this number field element. - If K is given then K must be a subfield of the parent L of self, in - which case the norm is the relative norm from L to K. In all other - cases, the norm is the absolute norm down to QQ. + If `K` is given, then `K` must be a subfield of the parent `L` of ``self``, in + which case the norm is the relative norm from `L` to `K`. In all other + cases, the norm is the absolute norm down to `\QQ`. EXAMPLES:: @@ -3530,21 +3540,21 @@ cdef class NumberFieldElement(NumberFieldElement_base): 1 sage: a a - sage: (a+b+c).norm() + sage: (a + b + c).norm() 121 - sage: (a+b+c).norm(L) + sage: (a + b + c).norm(L) 2*c*b - 7 - sage: (a+b+c).norm(M) + sage: (a + b + c).norm(M) -11 We illustrate that norm is compatible with towers:: - sage: z = (a+b+c).norm(L); z.norm(M) + sage: z = (a + b + c).norm(L); z.norm(M) -11 If we are in an order, the norm is an integer:: - sage: K. = NumberField(x^3-2) + sage: K. = NumberField(x^3 - 2) sage: a.norm().parent() Rational Field sage: R = K.ring_of_integers() @@ -3612,7 +3622,7 @@ cdef class NumberFieldElement(NumberFieldElement_base): def vector(self): """ - Return vector representation of self in terms of the basis for the + Return vector representation of ``self`` in terms of the basis for the ambient number field. EXAMPLES:: @@ -3656,11 +3666,11 @@ cdef class NumberFieldElement(NumberFieldElement_base): EXAMPLES:: - sage: K. = NumberField(x^2+3) + sage: K. = NumberField(x^2 + 3) sage: a.minpoly('x') x^2 + 3 sage: R. = K['X'] - sage: L. = K.extension(X^2-(22 + a)) + sage: L. = K.extension(X^2 - (22 + a)) sage: b.minpoly('t') t^2 - a - 22 sage: b.absolute_minpoly('t') @@ -3693,8 +3703,8 @@ cdef class NumberFieldElement(NumberFieldElement_base): An example in a relative extension:: - sage: K. = NumberField([x^2+1, x^2+3]) - sage: (a+b).is_integral() + sage: K. = NumberField([x^2 + 1, x^2 + 3]) + sage: (a + b).is_integral() True sage: ((a-b)/2).is_integral() False @@ -3703,24 +3713,24 @@ cdef class NumberFieldElement(NumberFieldElement_base): def matrix(self, base=None): r""" - If base is None, return the matrix of right multiplication by the + If ``base`` is ``None``, return the matrix of right multiplication by the element on the power basis `1, x, x^2, \ldots, x^{d-1}` for the number field. Thus the *rows* of this matrix give the images of each of the `x^i`. - If base is not None, then base must be either a field that embeds - in the parent of self or a morphism to the parent of self, in which - case this function returns the matrix of multiplication by self on + If ``base`` is not ``None``, then ``base`` must be either a field that embeds + in the parent of ``self`` or a morphism to the parent of ``self``, in which + case this function returns the matrix of multiplication by ``self`` on the power basis, where we view the parent field as a field over - base. + ``base``. - Specifying base as the base field over which the parent of self - is a relative extension is equivalent to base being None + Specifying ``base`` as the base field over which the parent of ``self`` + is a relative extension is equivalent to ``base`` being ``None``. INPUT: - - ``base`` - field or morphism + - ``base`` -- field or morphism EXAMPLES: @@ -3790,7 +3800,7 @@ cdef class NumberFieldElement(NumberFieldElement_base): TESTS:: - sage: F. = CyclotomicField(5) ; t = 3*z**3 + 4*z**2 + 2 + sage: F. = CyclotomicField(5); t = 3*z**3 + 4*z**2 + 2 sage: t.matrix(F) [3*z^3 + 4*z^2 + 2] sage: x = QQ['x'].gen() @@ -3837,7 +3847,7 @@ cdef class NumberFieldElement(NumberFieldElement_base): def valuation(self, P): """ - Return the valuation of ``self`` at a given prime ideal ``P``. + Return the valuation of ``self`` at a given prime ideal `P`. INPUT: @@ -3845,12 +3855,12 @@ cdef class NumberFieldElement(NumberFieldElement_base): .. NOTE:: - The function ``ord()`` is an alias for ``valuation()``. + The method :meth:`ord` is an alias for :meth:`valuation`. EXAMPLES:: sage: R. = QQ[] - sage: K. = NumberField(x^4+3*x^2-17) + sage: K. = NumberField(x^4 + 3*x^2 - 17) sage: P = K.ideal(61).factor()[0][0] sage: b = a^2 + 30 sage: b.valuation(P) @@ -3908,29 +3918,29 @@ cdef class NumberFieldElement(NumberFieldElement_base): def local_height(self, P, prec=None, weighted=False): r""" - Returns the local height of self at a given prime ideal `P`. + Returns the local height of ``self`` at a given prime ideal `P`. INPUT: - - ``P`` - a prime ideal of the parent of self + - ``P`` -- a prime ideal of the parent of ``self`` - ``prec`` (int) -- desired floating point precision (default: - default RealField precision). + default :class:`RealField` precision). - - ``weighted`` (bool, default False) -- if True, apply local + - ``weighted`` (bool, default ``False``) -- if ``True``, apply local degree weighting. OUTPUT: (real) The local height of this number field element at the - place `P`. If ``weighted`` is True, this is multiplied by the + place `P`. If ``weighted`` is ``True``, this is multiplied by the local degree (as required for global heights). EXAMPLES:: sage: R. = QQ[] - sage: K. = NumberField(x^4+3*x^2-17) + sage: K. = NumberField(x^4 + 3*x^2 - 17) sage: P = K.ideal(61).factor()[0][0] sage: b = 1/(a^2 + 30) sage: b.local_height(P) @@ -3948,7 +3958,7 @@ cdef class NumberFieldElement(NumberFieldElement_base): sage: PK. = K[] sage: L. = NumberField(y^2 + a) - sage: L(1/4).local_height(L.ideal(2, c-a+1)) + sage: L(1/4).local_height(L.ideal(2, c - a + 1)) 1.38629436111989 """ if self.valuation(P) >= 0: ## includes the case self=0 @@ -3965,36 +3975,35 @@ cdef class NumberFieldElement(NumberFieldElement_base): def local_height_arch(self, i, prec=None, weighted=False): r""" - Returns the local height of self at the `i`'th infinite place. + Returns the local height of ``self`` at the `i`'th infinite place. INPUT: - - - ``i`` (int) - an integer in ``range(r+s)`` where `(r,s)` is the - signature of the parent field (so `n=r+2s` is the degree). + - ``i`` (int) -- an integer in ``range(r+s)`` where `(r,s)` is the + signature of the parent field (so `n=r+2s` is the degree). - ``prec`` (int) -- desired floating point precision (default: - default RealField precision). + default :class:`RealField` precision). - - ``weighted`` (bool, default False) -- if True, apply local + - ``weighted`` (bool, default ``False``) -- if ``True``, apply local degree weighting, i.e. double the value for complex places. OUTPUT: (real) The archimedean local height of this number field element at the `i`'th infinite place. If ``weighted`` is - True, this is multiplied by the local degree (as required for + ``True``, this is multiplied by the local degree (as required for global heights), i.e. 1 for real places and 2 for complex places. EXAMPLES:: sage: R. = QQ[] - sage: K. = NumberField(x^4+3*x^2-17) + sage: K. = NumberField(x^4 + 3*x^2 - 17) sage: [p.codomain() for p in K.places()] [Real Field with 106 bits of precision, - Real Field with 106 bits of precision, - Complex Field with 53 bits of precision] + Real Field with 106 bits of precision, + Complex Field with 53 bits of precision] sage: [a.local_height_arch(i) for i in range(3)] [0.5301924545717755083366563897519, 0.5301924545717755083366563897519, @@ -4047,7 +4056,7 @@ cdef class NumberFieldElement(NumberFieldElement_base): EXAMPLES:: sage: R. = QQ[] - sage: K. = NumberField(x^4+3*x^2-17) + sage: K. = NumberField(x^4 + 3*x^2 - 17) sage: b = a/6 sage: b.global_height_non_arch() 7.16703787691222 @@ -4080,12 +4089,12 @@ cdef class NumberFieldElement(NumberFieldElement_base): def global_height_arch(self, prec=None): """ - Returns the total archimedean component of the height of self. + Returns the total archimedean component of the height of ``self``. INPUT: - ``prec`` (int) -- desired floating point precision (default: - default RealField precision). + default :class:`RealField` precision). OUTPUT: @@ -4096,7 +4105,7 @@ cdef class NumberFieldElement(NumberFieldElement_base): EXAMPLES:: sage: R. = QQ[] - sage: K. = NumberField(x^4+3*x^2-17) + sage: K. = NumberField(x^4 + 3*x^2 - 17) sage: b = a/2 sage: b.global_height_arch() 0.38653407379277... @@ -4112,7 +4121,7 @@ cdef class NumberFieldElement(NumberFieldElement_base): INPUT: - ``prec`` (int) -- desired floating point precision (default: - default RealField precision). + default :class:`RealField` precision). OUTPUT: @@ -4171,7 +4180,7 @@ cdef class NumberFieldElement(NumberFieldElement_base): EXAMPLES:: - sage: K. = NumberField(x^2+5) + sage: K. = NumberField(x^2 + 5) sage: b = (1+a)/2 sage: b.norm() 3/2 @@ -4202,7 +4211,7 @@ cdef class NumberFieldElement(NumberFieldElement_base): EXAMPLES:: - sage: K. = NumberField(x^2+5) + sage: K. = NumberField(x^2 + 5) sage: b = (1+a)/2 sage: b.norm() 3/2 @@ -4223,7 +4232,7 @@ cdef class NumberFieldElement(NumberFieldElement_base): """ Return the support of this number field element. - OUTPUT: A sorted list of the primes ideals at which this number + OUTPUT: A sorted list of the prime ideals at which this number field element has nonzero valuation. An error is raised if the element is zero. @@ -4259,12 +4268,12 @@ cdef class NumberFieldElement(NumberFieldElement_base): def _matrix_over_base(self, L): """ - Return the matrix of self over the base field L. + Return the matrix of ``self`` over the base field `L`. EXAMPLES:: - sage: K. = NumberField(ZZ['x'].0^3-2, 'a') - sage: L. = K.extension(ZZ['x'].0^2+3, 'b') + sage: K. = NumberField(ZZ['x'].0^3 - 2, 'a') + sage: L. = K.extension(ZZ['x'].0^2 + 3, 'b') sage: L(a)._matrix_over_base(K) == L(a).matrix() True """ @@ -4277,12 +4286,12 @@ cdef class NumberFieldElement(NumberFieldElement_base): def _matrix_over_base_morphism(self, phi): """ - Return the matrix of self over a specified base, where phi gives a - map from the specified base to self.parent(). + Return the matrix of ``self`` over a specified base, where ``phi`` gives a + map from the specified base to ``self.parent()``. EXAMPLES:: - sage: F. = NumberField(ZZ['x'].0^5-2) + sage: F. = NumberField(ZZ['x'].0^5 - 2) sage: h = Hom(QQ,F)([1]) sage: alpha._matrix_over_base_morphism(h) == alpha.matrix() True @@ -4330,7 +4339,7 @@ cdef class NumberFieldElement(NumberFieldElement_base): def list(self): """ - Return the list of coefficients of self written in terms of a power + Return the list of coefficients of ``self`` written in terms of a power basis. EXAMPLES:: @@ -4343,17 +4352,19 @@ cdef class NumberFieldElement(NumberFieldElement_base): raise NotImplementedError def inverse_mod(self, I): - """ - Returns the inverse of self mod the integral ideal I. + r""" + Returns the inverse of ``self`` mod the integral ideal `I`. INPUT: - - ``I`` - may be an ideal of self.parent(), or an element or list - of elements of self.parent() generating a nonzero ideal. A ValueError - is raised if I is non-integral or zero. A ZeroDivisionError is - raised if I + (x) != (1). + - ``I`` -- may be an ideal of ``self.parent()``, or an element or list + of elements of ``self.parent()`` generating a nonzero ideal. A :class:`ValueError` + is raised if `I` is non-integral or zero. A :class:`ZeroDivisionError` is + raised if `I + (x) \neq (1)`. + + .. NOTE:: - NOTE: It's not implemented yet for non-integral elements. + It's not implemented yet for non-integral elements. EXAMPLES:: @@ -4388,27 +4399,30 @@ cdef class NumberFieldElement(NumberFieldElement_base): def residue_symbol(self, P, m, check=True): r""" - The m-th power residue symbol for an element self and proper ideal P. + The `m`-th power residue symbol for an element ``self`` and proper ideal `P`. .. MATH:: \left(\frac{\alpha}{\mathbf{P}}\right) \equiv \alpha^{\frac{N(\mathbf{P})-1}{m}} \operatorname{mod} \mathbf{P} - .. NOTE:: accepts m=1, in which case returns 1 + .. NOTE:: accepts `m=1`, in which case returns 1 .. NOTE:: can also be called for an ideal from sage.rings.number_field_ideal.residue_symbol .. NOTE:: self is coerced into the number field of the ideal P - .. NOTE:: if m=2, self is an integer, and P is an ideal of a number field of absolute degree 1 (i.e. it is a copy of the rationals), then this calls kronecker_symbol, which is implemented using GMP. + .. NOTE:: + + if `m=2`, ``self`` is an integer, and `P` is an ideal of a number field of absolute degree 1 (i.e. it is a copy of the rationals), + then this calls :func:`kronecker_symbol`, which is implemented using GMP. INPUT: - - ``P`` - proper ideal of the number field (or an extension) + - ``P`` -- proper ideal of the number field (or an extension) - - ``m`` - positive integer + - ``m`` -- positive integer OUTPUT: - - an m-th root of unity in the number field + - an `m`-th root of unity in the number field EXAMPLES: @@ -4417,7 +4431,7 @@ cdef class NumberFieldElement(NumberFieldElement_base): sage: K. = NumberField(x - 1) sage: K(11).residue_symbol(K.ideal(17),2) -1 - sage: kronecker_symbol(11,17) + sage: kronecker_symbol(11, 17) -1 The result depends on the number field of the ideal:: @@ -4453,17 +4467,17 @@ cdef class NumberFieldElement(NumberFieldElement_base): INPUT: - - ``K`` (number field, default \QQ) -- a subfield of the + - ``K`` (number field, default `\QQ`) -- a subfield of the parent number field `L` of ``self`` - ``d`` (positive integer, default 2) -- an integer at least 2 OUTPUT: - A list, possibly empty, of elements of ``K`` equal to ``self`` + A list, possibly empty, of elements of `K` equal to ``self`` modulo `d`'th powers, i.e. the preimages of ``self`` under the map `K^*/(K^*)^d \rightarrow L^*/(L^*)^d` where `L` is the - parent of ``self``. A ``ValueError`` is raised if `K` does + parent of ``self``. A :class:`ValueError` is raised if `K` does not embed into `L`. ALGORITHM: @@ -4621,7 +4635,7 @@ cdef class NumberFieldElement_absolute(NumberFieldElement): INPUT: - - ``magma`` - a Magma interpreter + - ``magma`` -- a Magma interpreter OUTPUT: MagmaElement that has parent the Magma object corresponding @@ -4688,19 +4702,25 @@ cdef class NumberFieldElement_absolute(NumberFieldElement): EXAMPLES:: sage: x = ZZ['x'].0 - sage: f = x^10 - 5*x^9 + 15*x^8 - 68*x^7 + 81*x^6 - 221*x^5 + 141*x^4 - 242*x^3 - 13*x^2 - 33*x - 135 + sage: f = (x^10 - 5*x^9 + 15*x^8 - 68*x^7 + 81*x^6 - 221*x^5 + ....: + 141*x^4 - 242*x^3 - 13*x^2 - 33*x - 135) sage: K. = NumberField(f, 'a') sage: a.absolute_charpoly() - x^10 - 5*x^9 + 15*x^8 - 68*x^7 + 81*x^6 - 221*x^5 + 141*x^4 - 242*x^3 - 13*x^2 - 33*x - 135 + x^10 - 5*x^9 + 15*x^8 - 68*x^7 + 81*x^6 - 221*x^5 + + 141*x^4 - 242*x^3 - 13*x^2 - 33*x - 135 sage: a.absolute_charpoly('y') - y^10 - 5*y^9 + 15*y^8 - 68*y^7 + 81*y^6 - 221*y^5 + 141*y^4 - 242*y^3 - 13*y^2 - 33*y - 135 - sage: b = -79/9995*a^9 + 52/9995*a^8 + 271/9995*a^7 + 1663/9995*a^6 + 13204/9995*a^5 + 5573/9995*a^4 + 8435/1999*a^3 - 3116/9995*a^2 + 7734/1999*a + 1620/1999 + y^10 - 5*y^9 + 15*y^8 - 68*y^7 + 81*y^6 - 221*y^5 + + 141*y^4 - 242*y^3 - 13*y^2 - 33*y - 135 + sage: b = (-79/9995*a^9 + 52/9995*a^8 + 271/9995*a^7 + 1663/9995*a^6 + ....: + 13204/9995*a^5 + 5573/9995*a^4 + 8435/1999*a^3 + ....: - 3116/9995*a^2 + 7734/1999*a + 1620/1999) sage: b.absolute_charpoly() - x^10 + 10*x^9 + 25*x^8 - 80*x^7 - 438*x^6 + 80*x^5 + 2950*x^4 + 1520*x^3 - 10439*x^2 - 5130*x + 18225 + x^10 + 10*x^9 + 25*x^8 - 80*x^7 - 438*x^6 + 80*x^5 + + 2950*x^4 + 1520*x^3 - 10439*x^2 - 5130*x + 18225 sage: b.absolute_minpoly() x^5 + 5*x^4 - 40*x^2 - 19*x + 135 - sage: b.absolute_minpoly(algorithm='pari') == b.absolute_minpoly(algorithm='sage') + sage: b.absolute_minpoly(algorithm='pari') == b.absolute_minpoly(algorithm='sage') # optional - sage.libs.pari True """ return self.minpoly(var, algorithm) @@ -4708,18 +4728,18 @@ cdef class NumberFieldElement_absolute(NumberFieldElement): def charpoly(self, var='x', algorithm=None): r""" The characteristic polynomial of this element, over - `\QQ` if self is an element of a field, and over - `\ZZ` is self is an element of an order. + `\QQ` if ``self`` is an element of a field, and over + `\ZZ` is ``self`` is an element of an order. - This is the same as ``self.absolute_charpoly`` since + This is the same as :meth:`absolute_charpoly` since this is an element of an absolute extension. - The optional argument algorithm controls how the - characteristic polynomial is computed: 'pari' uses PARI, - 'sage' uses charpoly for Sage matrices. The default value - None means that 'pari' is used for small degrees (up to the - value of the constant TUNE_CHARPOLY_NF, currently at 25), - otherwise 'sage' is used. The constant TUNE_CHARPOLY_NF + The optional argument ``algorithm`` controls how the + characteristic polynomial is computed: ``'pari'`` uses PARI, + ``'sage'`` uses ``charpoly`` for Sage matrices. The default value + ``None`` means that ``'pari'`` is used for small degrees (up to the + value of the constant ``TUNE_CHARPOLY_NF``, currently at 25), + otherwise ``'sage'`` is used. The constant ``TUNE_CHARPOLY_NF`` should give reasonable performance on all architectures; however, if you feel the need to customize it to your own machine, see :trac:`5213` for a tuning script. @@ -4731,7 +4751,7 @@ cdef class NumberFieldElement_absolute(NumberFieldElement): :: sage: R. = QQ[] - sage: K. = NumberField(x^3-2) + sage: K. = NumberField(x^3 - 2) sage: a.charpoly('x') x^3 - 2 sage: a.charpoly('y').parent() @@ -4745,7 +4765,7 @@ cdef class NumberFieldElement_absolute(NumberFieldElement): sage: R(a).charpoly().parent() Univariate Polynomial Ring in x over Integer Ring - sage: R(a).charpoly(algorithm='pari') == R(a).charpoly(algorithm='sage') + sage: R(a).charpoly(algorithm='pari') == R(a).charpoly(algorithm='sage') # optional - sage.libs.pari True """ if algorithm is None: @@ -4763,7 +4783,7 @@ cdef class NumberFieldElement_absolute(NumberFieldElement): """ Return the minimal polynomial of this number field element. - For the meaning of the optional argument algorithm, see charpoly(). + For the meaning of the optional argument ``algorithm``, see :meth:`charpoly`. EXAMPLES: @@ -4772,7 +4792,7 @@ cdef class NumberFieldElement_absolute(NumberFieldElement): :: sage: R. = QQ[] - sage: K. = NumberField(x^3-2) + sage: K. = NumberField(x^3 - 2) sage: a.minpoly('x') x^3 - 2 sage: a.minpoly('y').parent() @@ -4793,14 +4813,14 @@ cdef class NumberFieldElement_absolute(NumberFieldElement): return self.charpoly(var, algorithm).radical() # square free part of charpoly def list(self): - """ - Return the list of coefficients of self written in terms of a power + r""" + Return the list of coefficients of ``self`` written in terms of a power basis. EXAMPLES:: sage: K. = CyclotomicField(3) - sage: (2+3/5*z).list() + sage: (2 + 3/5*z).list() [2, 3/5] sage: (5*z).list() [0, 5] @@ -4813,9 +4833,9 @@ cdef class NumberFieldElement_absolute(NumberFieldElement): return v + [z]*(n - len(v)) def lift(self, var='x'): - """ - Return an element of QQ[x], where this number field element - lives in QQ[x]/(f(x)). + r""" + Return an element of `\QQ[x]`, where this number field element + lives in `\QQ[x]/(f(x))`. EXAMPLES:: @@ -4836,29 +4856,29 @@ cdef class NumberFieldElement_absolute(NumberFieldElement): The algorithm first checks that ``self`` is not a strictly complex number. Then if ``self`` is not zero, by approximation - more and more precise, the method answers True if the - number is positive. Using `RealInterval`, the result is + more and more precise, the method answers ``True`` if the + number is positive. Using :class:`RealInterval`, the result is guaranteed to be correct. - For CyclotomicField, the embedding is the natural one - sending `zetan` on `cos(2*pi/n)`. + For :class:`CyclotomicField`, the embedding is the natural one + sending ``zetan`` on `\cos(2*\pi/n)`. EXAMPLES:: sage: K. = CyclotomicField(3) - sage: (a+a^2).is_real_positive() + sage: (a + a^2).is_real_positive() False - sage: (-a-a^2).is_real_positive() + sage: (-a - a^2).is_real_positive() True sage: K. = CyclotomicField(1000) - sage: (a+a^(-1)).is_real_positive() + sage: (a + a^(-1)).is_real_positive() True sage: K. = CyclotomicField(1009) sage: d = a^252 - sage: (d+d.conjugate()).is_real_positive() + sage: (d + d.conjugate()).is_real_positive() True sage: d = a^253 - sage: (d+d.conjugate()).is_real_positive() + sage: (d + d.conjugate()).is_real_positive() False sage: K. = QuadraticField(3) sage: a.is_real_positive() @@ -4866,7 +4886,7 @@ cdef class NumberFieldElement_absolute(NumberFieldElement): sage: K. = QuadraticField(-3) sage: a.is_real_positive() False - sage: (a-a).is_real_positive() + sage: (a - a).is_real_positive() False """ if self != self.conjugate() or self.is_zero(): @@ -4901,7 +4921,7 @@ cdef class NumberFieldElement_relative(NumberFieldElement): def __getitem__(self, n): """ - Return the n-th coefficient of this relative number field element, written + Return the `n`-th coefficient of this relative number field element, written as a polynomial in the generator. Note that `n` must be between 0 and `d-1`, where @@ -4951,7 +4971,7 @@ cdef class NumberFieldElement_relative(NumberFieldElement): def list(self): """ - Return the list of coefficients of self written in terms of a power + Return the list of coefficients of ``self`` written in terms of a power basis. EXAMPLES:: @@ -4968,8 +4988,8 @@ cdef class NumberFieldElement_relative(NumberFieldElement): def lift(self, var='x'): """ - Return an element of K[x], where this number field element - lives in the relative number field K[x]/(f(x)). + Return an element of `K[x]`, where this number field element + lives in the relative number field `K[x]/(f(x))`. EXAMPLES:: @@ -5001,7 +5021,7 @@ cdef class NumberFieldElement_relative(NumberFieldElement): def _latex_(self): r""" - Returns the latex representation for this element. + Return the latex representation for this element. EXAMPLES:: @@ -5068,12 +5088,12 @@ cdef class NumberFieldElement_relative(NumberFieldElement): We construct a relative extension and find the characteristic polynomial over `\QQ`. - The optional argument algorithm controls how the - characteristic polynomial is computed: 'pari' uses PARI, - 'sage' uses charpoly for Sage matrices. The default value - None means that 'pari' is used for small degrees (up to the - value of the constant TUNE_CHARPOLY_NF, currently at 25), - otherwise 'sage' is used. The constant TUNE_CHARPOLY_NF + The optional argument ``algorithm`` controls how the + characteristic polynomial is computed: ``'pari'`` uses PARI, + ``'sage'`` uses ``charpoly`` for Sage matrices. The default value + ``None`` means that ``'pari'`` is used for small degrees (up to the + value of the constant ``TUNE_CHARPOLY_NF``, currently at 25), + otherwise ``'sage'`` is used. The constant ``TUNE_CHARPOLY_NF`` should give reasonable performance on all architectures; however, if you feel the need to customize it to your own machine, see :trac:`5213` for a tuning script. @@ -5096,7 +5116,7 @@ cdef class NumberFieldElement_relative(NumberFieldElement): sage: a.absolute_charpoly('y') y^9 + 51*y^6 + 867*y^3 + 4913 - sage: a.absolute_charpoly(algorithm='pari') == a.absolute_charpoly(algorithm='sage') + sage: a.absolute_charpoly(algorithm='pari') == a.absolute_charpoly(algorithm='sage') # optional - sage.libs.pari True """ if algorithm is None: @@ -5134,7 +5154,8 @@ cdef class NumberFieldElement_relative(NumberFieldElement): sage: L(a).absolute_minpoly() x^2 + 2 sage: L(b).absolute_charpoly() - x^8 + 4000*x^7 + 6000004*x^6 + 4000012000*x^5 + 1000012000006*x^4 + 4000012000*x^3 + 6000004*x^2 + 4000*x + 1 + x^8 + 4000*x^7 + 6000004*x^6 + 4000012000*x^5 + 1000012000006*x^4 + + 4000012000*x^3 + 6000004*x^2 + 4000*x + 1 sage: L(b).absolute_minpoly() x^2 + 1000*x + 1 """ @@ -5142,13 +5163,11 @@ cdef class NumberFieldElement_relative(NumberFieldElement): def valuation(self, P): """ - Returns the valuation of self at a given prime ideal P. + Return the valuation of ``self`` at a given prime ideal `P`. INPUT: - - - ``P`` - a prime ideal of relative number field which is the parent of self - + - ``P`` -- a prime ideal of relative number field which is the parent of ``self`` EXAMPLES:: @@ -5202,7 +5221,7 @@ cdef class OrderElement_absolute(NumberFieldElement_absolute): cdef _new(self): """ Quickly creates a new initialized NumberFieldElement with the same - parent as self. + parent as ``self``. EXAMPLES: @@ -5222,7 +5241,7 @@ cdef class OrderElement_absolute(NumberFieldElement_absolute): cdef number_field(self): r""" - Return the number field of self. Only accessible from Cython. + Return the number field of ``self``. Only accessible from Cython. EXAMPLES:: @@ -5236,16 +5255,14 @@ cdef class OrderElement_absolute(NumberFieldElement_absolute): def inverse_mod(self, I): r""" - Return an inverse of self modulo the given ideal. + Return an inverse of ``self`` modulo the given ideal. INPUT: - - - ``I`` - may be an ideal of self.parent(), or an - element or list of elements of self.parent() generating a nonzero - ideal. A ValueError is raised if I is non-integral or is zero. - A ZeroDivisionError is raised if I + (x) != (1). - + - ``I`` -- may be an ideal of ``self.parent()``, or an + element or list of elements of ``self.parent()`` generating a nonzero + ideal. A :class:`ValueError` is raised if `I` is non-integral or is zero. + A :class:`ZeroDivisionError` is raised if `I + (x) \neq (1)`. EXAMPLES:: @@ -5273,7 +5290,7 @@ cdef class OrderElement_absolute(NumberFieldElement_absolute): EXAMPLES:: - sage: K = NumberField(x^3 -x + 2, 'a') + sage: K = NumberField(x^3 - x + 2, 'a') sage: OK = K.ring_of_integers() sage: a = OK(K.gen()) sage: (~a).parent() is K @@ -5364,15 +5381,15 @@ cdef class OrderElement_relative(NumberFieldElement_relative): def inverse_mod(self, I): r""" - Return an inverse of self modulo the given ideal. + Return an inverse of ``self`` modulo the given ideal. INPUT: - - ``I`` - may be an ideal of self.parent(), or an - element or list of elements of self.parent() generating a nonzero - ideal. A ValueError is raised if I is non-integral or is zero. - A ZeroDivisionError is raised if I + (x) != (1). + - ``I`` -- may be an ideal of ``self.parent()``, or an + element or list of elements of ``self.parent()`` generating a nonzero + ideal. A :class:`ValueError` is raised if `I` is non-integral or is zero. + A :class:`ZeroDivisionError` is raised if `I + (x) \neq (1)`. EXAMPLES:: @@ -5392,8 +5409,8 @@ cdef class OrderElement_relative(NumberFieldElement_relative): r""" The characteristic polynomial of this order element over its base ring. - This special implementation works around bug \#4738. At this - time the base ring of relative order elements is ZZ; it should + This special implementation works around :trac:`4738`. At this + time the base ring of relative order elements is `\ZZ`; it should be the ring of integers of the base field. EXAMPLES:: @@ -5405,7 +5422,8 @@ cdef class OrderElement_relative(NumberFieldElement_relative): sage: charpoly(OK.1) x^2 + b*x + 1 sage: charpoly(OK.1).parent() - Univariate Polynomial Ring in x over Maximal Order in Number Field in b with defining polynomial x^2 - 3 + Univariate Polynomial Ring in x over + Maximal Order in Number Field in b with defining polynomial x^2 - 3 sage: [ charpoly(t) for t in OK.basis() ] [x^2 - 2*x + 1, x^2 + b*x + 1, x^2 - x + 1, x^2 + 1] """ @@ -5416,8 +5434,8 @@ cdef class OrderElement_relative(NumberFieldElement_relative): r""" The minimal polynomial of this order element over its base ring. - This special implementation works around bug \#4738. At this - time the base ring of relative order elements is ZZ; it should + This special implementation works around :trac:`4738`. At this + time the base ring of relative order elements is `\ZZ`; it should be the ring of integers of the base field. EXAMPLES:: @@ -5429,7 +5447,8 @@ cdef class OrderElement_relative(NumberFieldElement_relative): sage: minpoly(OK.1) x^2 + b*x + 1 sage: charpoly(OK.1).parent() - Univariate Polynomial Ring in x over Maximal Order in Number Field in b with defining polynomial x^2 - 3 + Univariate Polynomial Ring in x over + Maximal Order in Number Field in b with defining polynomial x^2 - 3 sage: _, u, _, v = OK.basis() sage: t = 2*u - v; t -b @@ -5449,7 +5468,7 @@ cdef class OrderElement_relative(NumberFieldElement_relative): def absolute_charpoly(self, var='x'): r""" - The absolute characteristic polynomial of this order element over ZZ. + The absolute characteristic polynomial of this order element over `\ZZ`. EXAMPLES:: @@ -5472,7 +5491,7 @@ cdef class OrderElement_relative(NumberFieldElement_relative): def absolute_minpoly(self, var='x'): r""" - The absolute minimal polynomial of this order element over ZZ. + The absolute minimal polynomial of this order element over `\ZZ`. EXAMPLES:: diff --git a/src/sage/rings/number_field/number_field_element_base.pyx b/src/sage/rings/number_field/number_field_element_base.pyx index 5385833f1d4..c4938237a6d 100644 --- a/src/sage/rings/number_field/number_field_element_base.pyx +++ b/src/sage/rings/number_field/number_field_element_base.pyx @@ -20,8 +20,8 @@ cdef class NumberFieldElement_base(FieldElement): EXAMPLES:: - sage: k. = NumberField(x^3 + x + 1) - sage: isinstance(a, sage.rings.number_field.number_field_element_base.NumberFieldElement_base) + sage: k. = NumberField(x^3 + x + 1) # optional - sage.rings.number_field + sage: isinstance(a, sage.rings.number_field.number_field_element_base.NumberFieldElement_base) # optional - sage.rings.number_field True By design, there is a unique direct subclass:: diff --git a/src/sage/rings/number_field/number_field_element_quadratic.pyx b/src/sage/rings/number_field/number_field_element_quadratic.pyx index bcba57457e5..062e15b238d 100644 --- a/src/sage/rings/number_field/number_field_element_quadratic.pyx +++ b/src/sage/rings/number_field/number_field_element_quadratic.pyx @@ -7,7 +7,7 @@ r""" Optimized Quadratic Number Field Elements -This file defines a Cython class ``NumberFieldElement_quadratic`` to speed up +This file defines a Cython class :class:`NumberFieldElement_quadratic` to speed up computations in quadratic extensions of `\QQ`. AUTHORS: @@ -101,11 +101,11 @@ def __make_NumberFieldElement_quadratic1(parent, cls, a, b, denom): cdef class NumberFieldElement_quadratic(NumberFieldElement_absolute): r""" - A NumberFieldElement_quadratic object gives an efficient representation of + A :class:`NumberFieldElement_quadratic` object gives an efficient representation of an element of a quadratic extension of `\QQ`. Elements are represented internally as triples `(a, b, c)` of integers, - where `{\rm gcd}(a, b, c) = 1` and `c > 0`, representing the element `(a + + where `\gcd(a, b, c) = 1` and `c > 0`, representing the element `(a + b \sqrt{D}) / c`. Note that if the discriminant `D` is `1 \bmod 4`, integral elements do not necessarily have `c = 1`. @@ -116,19 +116,19 @@ cdef class NumberFieldElement_quadratic(NumberFieldElement_absolute): We set up some fields:: - sage: K. = NumberField(x^2+23) + sage: K. = NumberField(x^2 + 23) sage: a.parts() (0, 1) - sage: F. = NumberField(x^2-x+7) + sage: F. = NumberField(x^2 - x + 7) sage: b.parts() (1/2, 3/2) - We construct elements of these fields in various ways - firstly, from + We construct elements of these fields in various ways -- firstly, from polynomials:: - sage: NumberFieldElement_quadratic_sqrt(K, x-1) + sage: NumberFieldElement_quadratic_sqrt(K, x - 1) a - 1 - sage: NumberFieldElement_quadratic(F, x-1) + sage: NumberFieldElement_quadratic(F, x - 1) b - 1 From triples of Integers:: @@ -142,11 +142,11 @@ cdef class NumberFieldElement_quadratic(NumberFieldElement_absolute): From pairs of Rationals:: - sage: NumberFieldElement_quadratic_sqrt(K, (1/2,1/3)) + sage: NumberFieldElement_quadratic_sqrt(K, (1/2, 1/3)) 1/3*a + 1/2 - sage: NumberFieldElement_quadratic(F, (1/2,1/3)) + sage: NumberFieldElement_quadratic(F, (1/2, 1/3)) 2/9*b + 7/18 - sage: NumberFieldElement_quadratic(F, (1/2,1/3)).parts() + sage: NumberFieldElement_quadratic(F, (1/2, 1/3)).parts() (1/2, 1/3) Direct from Rationals:: @@ -158,7 +158,7 @@ cdef class NumberFieldElement_quadratic(NumberFieldElement_absolute): This checks a bug when converting from lists:: - sage: w = CyclotomicField(3)([1/2,1]) + sage: w = CyclotomicField(3)([1/2, 1]) sage: w == w.__invert__().__invert__() True """ @@ -294,9 +294,9 @@ cdef class NumberFieldElement_quadratic(NumberFieldElement_absolute): EXAMPLES:: sage: K. = QuadraticField(-1) - sage: (1/3 + a/2)._sympy_() + sage: (1/3 + a/2)._sympy_() # optional - sympy 1/3 + I/2 - sage: type(_) + sage: type(_) # optional - sympy """ a = self.parent().gen() @@ -313,7 +313,7 @@ cdef class NumberFieldElement_quadratic(NumberFieldElement_absolute): EXAMPLES:: sage: K. = QuadraticField(5) - sage: polymake(3+2*sqrt5) # optional - jupymake + sage: polymake(3 + 2*sqrt5) # optional - jupymake 3+2r5 sage: polymake(2**100/7 - 2*sqrt5/3**50) # optional - jupymake 1267650600228229401496703205376/7-2/717897987691852588770249r5 @@ -892,7 +892,7 @@ cdef class NumberFieldElement_quadratic(NumberFieldElement_absolute): cpdef tuple parts(self): r""" - This function returns a pair of rationals `a` and `b` such that self `= + Return a pair of rationals `a` and `b` such that ``self`` `= a+b\sqrt{D}`. This is much closer to the internal storage format of the @@ -902,19 +902,19 @@ cdef class NumberFieldElement_quadratic(NumberFieldElement_absolute): EXAMPLES:: - sage: K. = NumberField(x^2-13) + sage: K. = NumberField(x^2 - 13) sage: K.discriminant() 13 sage: a.parts() (0, 1) - sage: (a/2-4).parts() + sage: (a/2 - 4).parts() (-4, 1/2) - sage: K. = NumberField(x^2-7) + sage: K. = NumberField(x^2 - 7) sage: K.discriminant() 28 sage: a.parts() (0, 1) - sage: K. = NumberField(x^2-x+7) + sage: K. = NumberField(x^2 - x + 7) sage: a.parts() (1/2, 3/2) sage: a._coefficients() @@ -943,7 +943,7 @@ cdef class NumberFieldElement_quadratic(NumberFieldElement_absolute): def sign(self): r""" - Returns the sign of self (0 if zero, +1 if positive and -1 if negative). + Returns the sign of ``self`` (`0` if zero, `+1` if positive, and `-1` if negative). EXAMPLES:: @@ -1235,7 +1235,7 @@ cdef class NumberFieldElement_quadratic(NumberFieldElement_absolute): sage: K. = QuadraticField(2) sage: sqrt2.continued_fraction_list() ((1,), (2,)) - sage: (1/2+sqrt2/3).continued_fraction_list() + sage: (1/2 + sqrt2/3).continued_fraction_list() ((0, 1, 33), (1, 32)) For rational entries a pair of tuples is also returned but the second @@ -1755,7 +1755,7 @@ cdef class NumberFieldElement_quadratic(NumberFieldElement_absolute): sage: K. = QuadraticField(3) sage: sqrt3.is_rational() False - sage: (sqrt3-1/2).is_rational() + sage: (sqrt3 - 1/2).is_rational() False sage: K(0).is_rational() True @@ -1780,7 +1780,7 @@ cdef class NumberFieldElement_quadratic(NumberFieldElement_absolute): sage: K. = QuadraticField(3) sage: sqrt3.is_integer() False - sage: (sqrt3-1/2).is_integer() + sage: (sqrt3 - 1/2).is_integer() False sage: K(0).is_integer() True @@ -1848,7 +1848,7 @@ cdef class NumberFieldElement_quadratic(NumberFieldElement_absolute): 1/2*sqrt3 sage: a.real() -1/2 - sage: SR(a) + sage: SR(a) # optional - sage.symbolic 1/2*I*sqrt(3) - 1/2 sage: bool(QQbar(I)*QQbar(a.imag()) + QQbar(a.real()) == QQbar(a)) True @@ -1938,7 +1938,7 @@ cdef class NumberFieldElement_quadratic(NumberFieldElement_absolute): r""" Return the denominator of ``self``. - This is the LCM of the denominators of the coefficients of `self``, and + This is the LCM of the denominators of the coefficients of ``self``, and thus it may well be `> 1` even when the element is an algebraic integer. EXAMPLES:: @@ -1950,7 +1950,7 @@ cdef class NumberFieldElement_quadratic(NumberFieldElement_absolute): sage: b.is_integral() True - sage: K. = NumberField(x^2-x+7) + sage: K. = NumberField(x^2 - x + 7) sage: c.denominator() 1 """ @@ -1970,7 +1970,7 @@ cdef class NumberFieldElement_quadratic(NumberFieldElement_absolute): EXAMPLES:: - sage: K. = NumberField(x^2+x+41) + sage: K. = NumberField(x^2 + x + 41) sage: b = (2*a+1)/6 sage: b.denominator() 6 @@ -1988,7 +1988,7 @@ cdef class NumberFieldElement_quadratic(NumberFieldElement_absolute): """ EXAMPLES:: - sage: K. = NumberField(x^2+x+41) + sage: K. = NumberField(x^2 + x + 41) sage: a.trace() -1 sage: a.matrix() @@ -1997,14 +1997,14 @@ cdef class NumberFieldElement_quadratic(NumberFieldElement_absolute): The trace is additive:: - sage: K. = NumberField(x^2+7) - sage: (a+1).trace() + sage: K. = NumberField(x^2 + 7) + sage: (a + 1).trace() 2 sage: K(3).trace() 6 - sage: (a+4).trace() + sage: (a + 4).trace() 8 - sage: (a/3+1).trace() + sage: (a/3 + 1).trace() 2 """ # trace = 2*self.a / self.denom @@ -2023,24 +2023,24 @@ cdef class NumberFieldElement_quadratic(NumberFieldElement_absolute): Return the norm of ``self``. If the second argument is ``None``, this is the - norm down to `\QQ`. Otherwise, return the norm down to K (which had + norm down to `\QQ`. Otherwise, return the norm down to `K` (which had better be either `\QQ` or this number field). EXAMPLES:: - sage: K. = NumberField(x^2-x+3) + sage: K. = NumberField(x^2 - x + 3) sage: a.norm() 3 sage: a.matrix() [ 0 1] [-3 1] - sage: K. = NumberField(x^2+5) - sage: (1+a).norm() + sage: K. = NumberField(x^2 + 5) + sage: (1 + a).norm() 6 The norm is multiplicative:: - sage: K. = NumberField(x^2-3) + sage: K. = NumberField(x^2 - 3) sage: a.norm() -3 sage: K(3).norm() @@ -2136,15 +2136,15 @@ cdef class NumberFieldElement_quadratic(NumberFieldElement_absolute): INPUT: - ``var`` -- the minimal polynomial is defined over a polynomial ring - in a variable with this name. If not specified this defaults to ``x`` + in a variable with this name. If not specified, this defaults to ``'x'`` - ``algorithm`` -- for compatibility with general number field elements; ignored EXAMPLES:: - sage: K. = NumberField(x^2-x+13) + sage: K. = NumberField(x^2 - x + 13) sage: a.charpoly() x^2 - x + 13 - sage: b = 3-a/2 + sage: b = 3 - a/2 sage: f = b.charpoly(); f x^2 - 11/2*x + 43/4 sage: f(b) @@ -2160,18 +2160,17 @@ cdef class NumberFieldElement_quadratic(NumberFieldElement_absolute): INPUT: - ``var`` -- the minimal polynomial is defined over a polynomial ring - in a variable with this name. If not specified this defaults to ``x`` + in a variable with this name. If not specified, this defaults to ``'x'`` - ``algorithm`` -- for compatibility with general number field elements: and ignored - EXAMPLES:: - sage: K. = NumberField(x^2+13) + sage: K. = NumberField(x^2 + 13) sage: a.minpoly() x^2 + 13 sage: a.minpoly('T') T^2 + 13 - sage: (a+1/2-a).minpoly() + sage: (a + 1/2 - a).minpoly() x - 1/2 """ if self.is_rational(): @@ -2208,18 +2207,18 @@ cdef class NumberFieldElement_quadratic(NumberFieldElement_absolute): def floor(self): r""" - Returns the floor of x. + Returns the floor of ``self``. EXAMPLES:: - sage: K. = QuadraticField(2,name='sqrt2') + sage: K. = QuadraticField(2, name='sqrt2') sage: sqrt2.floor() 1 sage: (-sqrt2).floor() -2 sage: (13/197 + 3702/123*sqrt2).floor() 42 - sage: (13/197-3702/123*sqrt2).floor() + sage: (13/197 - 3702/123*sqrt2).floor() -43 TESTS:: @@ -2274,7 +2273,7 @@ cdef class NumberFieldElement_quadratic(NumberFieldElement_absolute): def ceil(self): r""" - Returns the ceil. + Return the ceil. EXAMPLES:: @@ -2353,7 +2352,7 @@ cdef class NumberFieldElement_quadratic(NumberFieldElement_absolute): cdef class NumberFieldElement_quadratic_sqrt(NumberFieldElement_quadratic): r""" - A NumberFieldElement_quadratic object gives an efficient representation of + A :class:`NumberFieldElement_quadratic_sqrt` object gives an efficient representation of an element of a quadratic extension of `\QQ` for the case when :func:`is_sqrt_disc()` is ``True``. """ @@ -2361,12 +2360,12 @@ cdef class NumberFieldElement_quadratic_sqrt(NumberFieldElement_quadratic): r""" Return the denominator of ``self``. - This is the LCM of the denominators of the coefficients of `self``, and + This is the LCM of the denominators of the coefficients of ``self``, and thus it may well be `> 1` even when the element is an algebraic integer. EXAMPLES:: - sage: K. = NumberField(x^2+x+41) + sage: K. = NumberField(x^2 + x + 41) sage: a.denominator() 1 sage: b = (2*a+1)/6 @@ -2481,11 +2480,11 @@ cdef class NumberFieldElement_gaussian(NumberFieldElement_quadratic_sqrt): r""" EXAMPLES:: - sage: SR(1 + 2*i) + sage: SR(1 + 2*i) # optional - sage.symbolic 2*I + 1 sage: K. = QuadraticField(-1, embedding=CC(0,-1)) - sage: SR(1 + mi) + sage: SR(1 + mi) # optional - sage.symbolic -I + 1 """ from sage.symbolic.constants import I @@ -2591,7 +2590,7 @@ cdef class NumberFieldElement_gaussian(NumberFieldElement_quadratic_sqrt): EXAMPLES:: - sage: I.log() + sage: I.log() # optional - sage.symbolic 1/2*I*pi """ from sage.symbolic.ring import SR @@ -2666,7 +2665,7 @@ cdef class OrderElement_quadratic(NumberFieldElement_quadratic): INPUT: - ``var`` -- the minimal polynomial is defined over a polynomial ring - in a variable with this name. If not specified this defaults to ``x`` + in a variable with this name. If not specified, this defaults to ``'x'`` - ``algorithm`` -- for compatibility with general number field elements; ignored @@ -2692,10 +2691,9 @@ cdef class OrderElement_quadratic(NumberFieldElement_quadratic): INPUT: - ``var`` -- the minimal polynomial is defined over a polynomial ring - in a variable with this name. If not specified this defaults to ``x`` + in a variable with this name. If not specified, this defaults to ``'x'`` - ``algorithm`` -- for compatibility with general number field elements; ignored - EXAMPLES:: sage: K. = NumberField(x^2 + 163) @@ -2779,16 +2777,14 @@ cdef class OrderElement_quadratic(NumberFieldElement_quadratic): def inverse_mod(self, I): r""" - Return an inverse of self modulo the given ideal. + Return an inverse of ``self`` modulo the given ideal. INPUT: - - - ``I`` - may be an ideal of self.parent(), or an - element or list of elements of self.parent() generating a nonzero - ideal. A ValueError is raised if I is non-integral or is zero. - A ZeroDivisionError is raised if I + (x) != (1). - + - ``I`` -- may be an ideal of ``self.parent()``, or an + element or list of elements of ``self.parent()`` generating a nonzero + ideal. A :class:`ValueError` is raised if `I` is non-integral or is zero. + A :class:`ZeroDivisionError` is raised if `I + (x) \neq (1)`. EXAMPLES:: @@ -2838,12 +2834,12 @@ cdef class OrderElement_quadratic(NumberFieldElement_quadratic): r""" Return the denominator of ``self``. - This is the LCM of the denominators of the coefficients of `self``, and + This is the LCM of the denominators of the coefficients of ``self``, and thus it may well be `> 1` even when the element is an algebraic integer. EXAMPLES:: - sage: K. = NumberField(x^2-27) + sage: K. = NumberField(x^2 - 27) sage: R = K.ring_of_integers() sage: aa = R.gen(1) sage: aa.denominator() @@ -2871,7 +2867,7 @@ cdef class OrderElement_quadratic(NumberFieldElement_quadratic): cdef class Z_to_quadratic_field_element(Morphism): """ Morphism that coerces from integers to elements of a quadratic number - field K. + field `K`. EXAMPLES:: @@ -2973,7 +2969,7 @@ cdef class Z_to_quadratic_field_element(Morphism): cdef class Q_to_quadratic_field_element(Morphism): """ Morphism that coerces from rationals to elements of a quadratic number - field K. + field `K`. EXAMPLES:: diff --git a/src/sage/rings/number_field/number_field_ideal.py b/src/sage/rings/number_field/number_field_ideal.py index afdf29c52f5..ce1e8bce645 100644 --- a/src/sage/rings/number_field/number_field_ideal.py +++ b/src/sage/rings/number_field/number_field_ideal.py @@ -1,3 +1,4 @@ +# sage.doctest: optional - sage.libs.pari """ Number Field Ideals @@ -11,7 +12,9 @@ NumberFieldFractionalIdeal now used for all except the 0 ideal - Radoslav Kirov and Alyson Deines (2010-06-22): - prime_to_S_part, is_S_unit, is_S_integral + prime_to_S_part, is_S_unit, is_S_integral + +TESTS: We test that pickling works:: @@ -69,9 +72,9 @@ def __init__(self, field, gens, coerce=True): """ INPUT: - - ``field`` - a number field + - ``field`` -- a number field - - ``x`` - a list of NumberFieldElements belonging to the field + - ``x`` -- a list of :class:`NumberFieldElement` objects belonging to the field EXAMPLES:: @@ -95,7 +98,7 @@ def __init__(self, field, gens, coerce=True): TESTS: - Check that _pari_prime is set when initializing from a PARI + Check that ``_pari_prime`` is set when initializing from a PARI prime ideal:: sage: K.ideal(pari(K).idealprimedec(5)[0])._pari_prime @@ -143,10 +146,10 @@ def _magma_init_(self, magma): INPUT: - - ``magma`` - a Magma interpreter + - ``magma`` -- a Magma interpreter - OUTPUT: MagmaElement corresponding to this ideal. + OUTPUT: :class:`MagmaElement` corresponding to this ideal. EXAMPLES:: @@ -258,9 +261,9 @@ def _richcmp_(self, other, op): def _mul_(self, other): """ - Returns the product of self and other. + Return the product of ``self`` and ``other``. - This is implemented by just calling pari to do the multiplication. + This is implemented by just calling PARI to do the multiplication. EXAMPLES:: @@ -291,37 +294,39 @@ def _mul_(self, other): def coordinates(self, x): r""" - Returns the coordinate vector of `x` with respect to this ideal. + Return the coordinate vector of `x` with respect to this ideal. INPUT: - ``x`` -- an element of the number field (or ring of integers) of this ideal. + + - ``x`` -- an element of the number field (or ring of integers) of this ideal. OUTPUT: - List giving the coordinates of `x` with respect to the integral basis - of the ideal. In general this will be a vector of - rationals; it will consist of integers if and only if `x` - is in the ideal. + + List giving the coordinates of `x` with respect to the integral basis + of the ideal. In general this will be a vector of + rationals; it will consist of integers if and only if `x` + is in the ideal. AUTHOR: John Cremona 2008-10-31 ALGORITHM: Uses linear algebra. - Provides simpler implementations for ``_contains_()``, - ``is_integral()`` and ``smallest_integer()``. + Provides simpler implementations for :meth:`_contains_`, + :meth:`is_integral` and :meth:`smallest_integer`. EXAMPLES:: sage: K. = QuadraticField(-1) - sage: I = K.ideal(7+3*i) + sage: I = K.ideal(7 + 3*i) sage: Ibasis = I.integral_basis(); Ibasis [58, i + 41] - sage: a = 23-14*i + sage: a = 23 - 14*i sage: acoords = I.coordinates(a); acoords (597/58, -14) sage: sum([Ibasis[j]*acoords[j] for j in range(2)]) == a True - sage: b = 123+456*i + sage: b = 123 + 456*i sage: bcoords = I.coordinates(b); bcoords (-18573/58, 456) sage: sum([Ibasis[j]*bcoords[j] for j in range(2)]) == b @@ -343,7 +348,7 @@ def coordinates(self, x): def _contains_(self, x): """ - Return True if x is an element of this ideal. + Return ``True`` if `x` is an element of this ideal. This function is called (indirectly) when the ``in`` operator is used. @@ -490,7 +495,7 @@ def _repr_short(self): def _gens_repr(self): """ - Returns tuple of generators to be used for printing this number + Return tuple of generators to be used for printing this number field ideal. The gens are reduced only if the absolute value of the norm of the discriminant of the defining polynomial is at most sage.rings.number_field.number_field_ideal.SMALL_DISC. @@ -526,7 +531,7 @@ def _gens_repr(self): def __pari__(self): """ - Returns PARI Hermite Normal Form representations of this + Return PARI Hermite Normal Form representations of this ideal. EXAMPLES:: @@ -541,7 +546,7 @@ def __pari__(self): def _pari_init_(self): """ - Returns self in PARI Hermite Normal Form as a string + Return self in PARI Hermite Normal Form as a string EXAMPLES:: @@ -577,7 +582,7 @@ def pari_hnf(self): @cached_method def basis(self): r""" - Return a basis for this ideal viewed as a `\ZZ` -module. + Return a basis for this ideal viewed as a `\ZZ`-module. OUTPUT: @@ -589,7 +594,8 @@ def basis(self): sage: K. = CyclotomicField(7) sage: I = K.factor(11)[0][0] sage: I.basis() # warning -- choice of basis can be somewhat random - [11, 11*z, 11*z^2, z^3 + 5*z^2 + 4*z + 10, z^4 + z^2 + z + 5, z^5 + z^4 + z^3 + 2*z^2 + 6*z + 5] + [11, 11*z, 11*z^2, z^3 + 5*z^2 + 4*z + 10, + z^4 + z^2 + z + 5, z^5 + z^4 + z^3 + 2*z^2 + 6*z + 5] An example of a non-integral ideal.:: @@ -597,7 +603,9 @@ def basis(self): sage: J # warning -- choice of generators can be somewhat random Fractional ideal (2/11*z^5 + 2/11*z^4 + 3/11*z^3 + 2/11) sage: J.basis() # warning -- choice of basis can be somewhat random - [1, z, z^2, 1/11*z^3 + 7/11*z^2 + 6/11*z + 10/11, 1/11*z^4 + 1/11*z^2 + 1/11*z + 7/11, 1/11*z^5 + 1/11*z^4 + 1/11*z^3 + 2/11*z^2 + 8/11*z + 7/11] + [1, z, z^2, 1/11*z^3 + 7/11*z^2 + 6/11*z + 10/11, + 1/11*z^4 + 1/11*z^2 + 1/11*z + 7/11, + 1/11*z^5 + 1/11*z^4 + 1/11*z^3 + 2/11*z^2 + 8/11*z + 7/11] Number fields defined by non-monic and non-integral polynomials are supported (:trac:`252`):: @@ -734,7 +742,7 @@ def gens_reduced(self, proof=None): Express this ideal in terms of at most two generators, and one if possible. - This function indirectly uses ``bnfisprincipal``, so set + This function indirectly uses :pari:`bnfisprincipal`, so set ``proof=True`` if you want to prove correctness (which *is* the default). @@ -744,12 +752,12 @@ def gens_reduced(self, proof=None): sage: K. = NumberField(x^2 + 5) sage: K.ideal(0).gens_reduced() (0,) - sage: J = K.ideal([a+2, 9]) + sage: J = K.ideal([a + 2, 9]) sage: J.gens() (a + 2, 9) sage: J.gens_reduced() # random sign (a + 2,) - sage: K.ideal([a+2, 3]).gens_reduced() + sage: K.ideal([a + 2, 3]).gens_reduced() (3, a + 2) TESTS:: @@ -804,12 +812,12 @@ def gens_two(self): sage: R. = PolynomialRing(QQ) sage: K. = NumberField(x^2 + 5) - sage: J = K.ideal([a+2, 9]) + sage: J = K.ideal([a + 2, 9]) sage: J.gens() (a + 2, 9) sage: J.gens_two() (9, a + 2) - sage: K.ideal([a+5, a+8]).gens_two() + sage: K.ideal([a + 5, a + 8]).gens_two() (3, a + 2) sage: K.ideal(0).gens_two() (0, 0) @@ -855,7 +863,7 @@ def integral_basis(self): sage: R. = PolynomialRing(QQ) sage: K. = NumberField(x^2 + 1) - sage: J = K.ideal(i+1) + sage: J = K.ideal(i + 1) sage: J.integral_basis() [2, i + 1] """ @@ -870,11 +878,11 @@ def integral_split(self): EXAMPLES:: sage: R. = PolynomialRing(QQ) - sage: K. = NumberField(x^2-5) + sage: K. = NumberField(x^2 - 5) sage: I = K.ideal(2/(5+a)) sage: I.is_integral() False - sage: J,d = I.integral_split() + sage: J, d = I.integral_split() sage: J Fractional ideal (-1/2*a + 5/2) sage: J.is_integral() @@ -904,20 +912,20 @@ def integral_split(self): def intersection(self, other): r""" - Return the intersection of self and other. + Return the intersection of ``self`` and ``other``. EXAMPLES:: sage: K. = QuadraticField(-11) sage: p = K.ideal((a + 1)/2); q = K.ideal((a + 3)/2) - sage: p.intersection(q) == q.intersection(p) == K.ideal(a-2) + sage: p.intersection(q) == q.intersection(p) == K.ideal(a - 2) True An example with non-principal ideals:: sage: L. = NumberField(x^3 - 7) sage: p = L.ideal(a^2 + a + 1, 2) - sage: q = L.ideal(a+1) + sage: q = L.ideal(a + 1) sage: p.intersection(q) == L.ideal(8, 2*a + 2) True @@ -948,12 +956,12 @@ def intersection(self, other): def is_integral(self): """ - Return True if this ideal is integral. + Return ``True`` if this ideal is integral. EXAMPLES:: sage: R. = PolynomialRing(QQ) - sage: K. = NumberField(x^5-x+1) + sage: K. = NumberField(x^5 - x + 1) sage: K.ideal(a).is_integral() True sage: (K.ideal(1) / (3*a+1)).is_integral() @@ -968,8 +976,8 @@ def is_integral(self): def is_maximal(self): """ - Return True if this ideal is maximal. This is equivalent to - self being prime and nonzero. + Return ``True`` if this ideal is maximal. This is equivalent to + ``self`` being prime and nonzero. EXAMPLES:: @@ -984,7 +992,7 @@ def is_maximal(self): def is_prime(self): """ - Return True if this ideal is prime. + Return ``True`` if this ideal is prime. EXAMPLES:: @@ -1031,11 +1039,11 @@ def is_prime(self): def pari_prime(self): r""" - Returns a PARI prime ideal corresponding to the ideal ``self``. + Return a PARI prime ideal corresponding to the ideal ``self``. INPUT: - - ``self`` - a prime ideal. + - ``self`` -- a prime ideal. OUTPUT: a PARI "prime ideal", i.e. a five-component vector `[p,a,e,f,b]` representing the prime ideal `p O_K + a O_K`, `e`, `f` as usual, `a` as @@ -1129,7 +1137,7 @@ def _cache_bnfisprincipal(self, proof=None, gens=False): def is_principal(self, proof=None): r""" - Return True if this ideal is principal. + Return ``True`` if this ideal is principal. Since it uses the PARI method :pari:`bnfisprincipal`, specify ``proof=True`` (this is the default setting) to prove the correctness @@ -1191,7 +1199,8 @@ def ideal_class_log(self, proof=None): 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 Number Field in a with defining polynomial x^3 - x + 1 over its base field + Class group of order 18 with structure C6 x C3 of + Number Field in a with defining polynomial x^3 - x + 1 over its base field sage: K.primes_above(7)[0].ideal_class_log() # random [1, 2] """ @@ -1238,10 +1247,10 @@ def S_ideal_class_log(self, S): def is_zero(self): """ - Return True iff self is the zero ideal + Return ``True`` iff ``self`` is the zero ideal - Note that `(0)` is a ``NumberFieldIdeal``, not a - ``NumberFieldFractionalIdeal``. + Note that `(0)` is a :class:`NumberFieldIdeal`, not a + :class:`NumberFieldFractionalIdeal`. EXAMPLES:: @@ -1249,7 +1258,7 @@ def is_zero(self): Number Field in a with defining polynomial x^2 + 2 sage: K.ideal(3).is_zero() False - sage: I=K.ideal(0); I.is_zero() + sage: I = K.ideal(0); I.is_zero() True sage: I Ideal (0) of Number Field in a with defining polynomial x^2 + 2 @@ -1283,7 +1292,7 @@ def norm(self): def absolute_norm(self): """ - A synonym for norm. + A synonym for :meth:`norm`. EXAMPLES:: @@ -1295,7 +1304,7 @@ def absolute_norm(self): def relative_norm(self): """ - A synonym for norm. + A synonym for :meth:`norm`. EXAMPLES:: @@ -1307,7 +1316,7 @@ def relative_norm(self): def absolute_ramification_index(self): """ - A synonym for ramification_index. + A synonym for :meth:`ramification_index`. EXAMPLES:: @@ -1319,7 +1328,7 @@ def absolute_ramification_index(self): def relative_ramification_index(self): """ - A synonym for ramification_index. + A synonym for :meth:`ramification_index`. EXAMPLES:: @@ -1339,7 +1348,7 @@ def number_field(self): Number Field in a with defining polynomial x^2 + 2 sage: K.ideal(3).number_field() Number Field in a with defining polynomial x^2 + 2 - sage: K.ideal(0).number_field() # not tested (not implemented) + sage: K.ideal(0).number_field() # not tested (not implemented) Number Field in a with defining polynomial x^2 + 2 """ return self.ring() @@ -1352,8 +1361,8 @@ def smallest_integer(self): EXAMPLES:: sage: R. = PolynomialRing(QQ) - sage: K. = NumberField(x^2+6) - sage: I = K.ideal([4,a])/7; I + sage: K. = NumberField(x^2 + 6) + sage: I = K.ideal([4, a])/7; I Fractional ideal (2/7, 1/7*a) sage: I.smallest_integer() 2 @@ -1413,7 +1422,7 @@ def valuation(self, p): (integer) The valuation of this fractional ideal at the prime `\mathfrak{p}`. If `\mathfrak{p}` is not prime, raise a - ValueError. + :class:`ValueError`. EXAMPLES:: @@ -1430,7 +1439,8 @@ def valuation(self, p): sage: i.valuation(0) Traceback (most recent call last): ... - ValueError: p (= Ideal (0) of Number Field in a with defining polynomial x^5 + 2) must be nonzero + ValueError: p (= Ideal (0) of Number Field in a + with defining polynomial x^5 + 2) must be nonzero sage: K.ideal(0).valuation(K.factor(2)[0][0]) +Infinity """ @@ -1447,11 +1457,10 @@ def valuation(self, p): def decomposition_group(self): r""" - Return the decomposition group of self, as a subset of the - automorphism group of the number field of self. Raises an - error if the field isn't Galois. See the decomposition_group - method of the ``GaloisGroup_v2`` class for further examples - and doctests. + Return the decomposition group of ``self``, as a subset of the + automorphism group of the number field of ``self``. Raises an + error if the field isn't Galois. See the :meth:`GaloisGroup_v2.decomposition_group` + method for further examples and doctests. EXAMPLES:: @@ -1462,11 +1471,11 @@ def decomposition_group(self): def ramification_group(self, v): r""" - Return the `v`'th ramification group of self, i.e. the set of - elements `s` of the Galois group of the number field of self + Return the `v`'th ramification group of ``self``, i.e. the set of + elements `s` of the Galois group of the number field of ``self`` (which we assume is Galois) such that `s` acts trivially modulo the `(v+1)`'st power of self. See the - ramification_group method of the ``GaloisGroup`` class for + :meth:`GaloisGroup.ramification_group` method for further examples and doctests. EXAMPLES:: @@ -1481,11 +1490,11 @@ def ramification_group(self, v): def inertia_group(self): r""" - Return the inertia group of self, i.e. the set of elements s of the - Galois group of the number field of self (which we assume is Galois) - such that s acts trivially modulo self. This is the same as the 0th - ramification group of self. See the inertia_group method of the - ``GaloisGroup_v2`` class for further examples and doctests. + Return the inertia group of ``self``, i.e. the set of elements `s` of the + Galois group of the number field of ``self`` (which we assume is Galois) + such that `s` acts trivially modulo ``self``. This is the same as the 0th + ramification group of ``self``. See the + :meth:`GaloisGroup_v2.inertia_group` method further examples and doctests. EXAMPLES:: @@ -1512,23 +1521,23 @@ def random_element(self, *args, **kwds): EXAMPLES:: sage: K. = NumberField(x^3 + 2) - sage: I = K.ideal(1-a) + sage: I = K.ideal(1 - a) sage: I.random_element() # random output -a^2 - a - 19 sage: I.random_element(distribution="uniform") # random output a^2 - 2*a - 8 - sage: I.random_element(-30,30) # random output + sage: I.random_element(-30, 30) # random output -7*a^2 - 17*a - 75 sage: I.random_element(-100, 200).is_integral() True - sage: I.random_element(-30,30).parent() is K + sage: I.random_element(-30, 30).parent() is K True A relative example:: sage: K. = NumberField([x^2 + 2, x^2 + 1000*x + 1]) - sage: I = K.ideal(1-a) - sage: I.random_element() # random output + sage: I = K.ideal(1 - a) + sage: I.random_element() # random output 17/500002*a^3 + 737253/250001*a^2 - 1494505893/500002*a + 752473260/250001 sage: I.random_element().is_integral() True @@ -1543,14 +1552,14 @@ def random_element(self, *args, **kwds): def artin_symbol(self): r""" - Return the Artin symbol `( K / \QQ, P)`, where `K` is the - number field of `P` =self. This is the unique element `s` of + Return the Artin symbol `(K / \QQ, P)`, where `K` is the + number field of `P` = ``self``. This is the unique element `s` of the decomposition group of `P` such that `s(x) = x^p \pmod{P}` where `p` is the residue characteristic of `P`. (Here `P` - (self) should be prime and unramified.) + (``self``) should be prime and unramified.) - See the ``artin_symbol`` method of the ``GaloisGroup_v2`` - class for further documentation and examples. + See the :meth:`GaloisGroup_v2.artin_symbol` method + for further documentation and examples. EXAMPLES:: @@ -1561,23 +1570,26 @@ class for further documentation and examples. def residue_symbol(self, e, m, check=True): r""" - The m-th power residue symbol for an element e and the proper ideal. + The `m`-th power residue symbol for an element `e` and the proper ideal. .. MATH:: \left(\frac{\alpha}{\mathbf{P}}\right) \equiv \alpha^{\frac{N(\mathbf{P})-1}{m}} \operatorname{mod} \mathbf{P} - .. note:: accepts m=1, in which case returns 1 + .. note:: accepts `m=1`, in which case returns 1 .. note:: can also be called for an element from sage.rings.number_field_element.residue_symbol - .. note:: e is coerced into the number field of self + .. note:: `e` is coerced into the number field of ``self`` - .. note:: if m=2, e is an integer, and self.number_field() has absolute degree 1 (i.e. it is a copy of the rationals), then this calls kronecker_symbol, which is implemented using GMP. + .. note:: + + if `m=2`, `e` is an integer, and ``self.number_field()`` has absolute degree 1 (i.e. it is a copy of the rationals), + then this calls :func:`kronecker_symbol`, which is implemented using GMP. INPUT: - - ``e`` - element of the number field + - ``e`` -- element of the number field - - ``m`` - positive integer + - ``m`` -- positive integer OUTPUT: @@ -1594,13 +1606,13 @@ def residue_symbol(self, e, m, check=True): Cubic Residue:: sage: K. = NumberField(x^2 - x + 1) - sage: K.ideal(17).residue_symbol(w^2 + 3,3) + sage: K.ideal(17).residue_symbol(w^2 + 3, 3) -w - The field must contain the m-th roots of unity:: + The field must contain the `m`-th roots of unity:: sage: K. = NumberField(x^2 - x + 1) - sage: K.ideal(17).residue_symbol(w^2 + 3,5) + sage: K.ideal(17).residue_symbol(w^2 + 3, 5) Traceback (most recent call last): ... ValueError: The residue symbol to that power is not defined for the number field @@ -1735,7 +1747,7 @@ def basis_to_module(B, K): def is_NumberFieldIdeal(x): """ - Return True if x is an ideal of a number field. + Return ``True`` if `x` is an ideal of a number field. EXAMPLES:: @@ -1814,7 +1826,7 @@ def __repr__(self): EXAMPLES:: - sage: K.=NumberField(x^2+5) + sage: K. = NumberField(x^2 + 5) sage: I = K.ideal([2,1+a]); I Fractional ideal (2, a + 1) sage: type(I) @@ -1824,7 +1836,7 @@ def __repr__(self): def divides(self, other): """ - Returns True if this ideal divides other and False otherwise. + Return ``True`` if this ideal divides other and False otherwise. EXAMPLES:: @@ -1854,11 +1866,13 @@ def factor(self): sage: I = K.ideal(19); I Fractional ideal (19) sage: F = I.factor(); F - (Fractional ideal (19, 1/2*a^2 + a - 17/2)) * (Fractional ideal (19, 1/2*a^2 - a - 17/2)) + (Fractional ideal (19, 1/2*a^2 + a - 17/2)) + * (Fractional ideal (19, 1/2*a^2 - a - 17/2)) sage: type(F) sage: list(F) - [(Fractional ideal (19, 1/2*a^2 + a - 17/2), 1), (Fractional ideal (19, 1/2*a^2 - a - 17/2), 1)] + [(Fractional ideal (19, 1/2*a^2 + a - 17/2), 1), + (Fractional ideal (19, 1/2*a^2 - a - 17/2), 1)] sage: F.prod() Fractional ideal (19) @@ -1893,18 +1907,21 @@ def factor(self): def prime_factors(self): """ - Return a list of the prime ideal factors of self + Return a list of the prime ideal factors of ``self``. OUTPUT: - list -- list of prime ideals (a new list is returned - each time this function is called) + + list of prime ideals (a new list is returned + each time this function is called) EXAMPLES:: sage: K. = NumberField(x^2 + 23) sage: I = ideal(w+1) sage: I.prime_factors() - [Fractional ideal (2, 1/2*w - 1/2), Fractional ideal (2, 1/2*w + 1/2), Fractional ideal (3, 1/2*w + 1/2)] + [Fractional ideal (2, 1/2*w - 1/2), + Fractional ideal (2, 1/2*w + 1/2), + Fractional ideal (3, 1/2*w + 1/2)] """ return [x[0] for x in self.factor()] @@ -1912,7 +1929,7 @@ def prime_factors(self): def _div_(self, other): """ - Return the quotient self / other. + Return the quotient ``self`` / ``other``. EXAMPLES:: @@ -1932,7 +1949,7 @@ def _div_(self, other): def __invert__(self): """ - Return the multiplicative inverse of self. Call with ~self. + Return the multiplicative inverse of ``self``. Call with ``~self``. EXAMPLES:: @@ -1955,8 +1972,8 @@ def __invert__(self): def is_maximal(self): """ - Return True if this ideal is maximal. This is equivalent to - self being prime, since it is nonzero. + Return ``True`` if this ideal is maximal. This is equivalent to + ``self`` being prime, since it is nonzero. EXAMPLES:: @@ -1971,7 +1988,7 @@ def is_maximal(self): def is_trivial(self, proof=None): """ - Returns True if this is a trivial ideal. + Return ``True`` if this is a trivial ideal. EXAMPLES:: @@ -1990,7 +2007,7 @@ def is_trivial(self, proof=None): def ramification_index(self): r""" Return the ramification index of this fractional ideal, - assuming it is prime. Otherwise, raise a ValueError. + assuming it is prime. Otherwise, raise a :class:`ValueError`. The ramification index is the power of this prime appearing in the factorization of the prime in `\ZZ` that this prime lies @@ -2015,8 +2032,8 @@ def ramification_index(self): def reduce(self, f): r""" - Return the canonical reduction of the element of `f` modulo the ideal - `I` (=self). This is an element of `R` (the ring of integers of the + Return the canonical reduction of the element `f` modulo the ideal + `I` (= ``self``). This is an element of `R` (the ring of integers of the number field) that is equivalent modulo `I` to `f`. An error is raised if this fractional ideal is not integral or @@ -2024,22 +2041,23 @@ def reduce(self, f): INPUT: - - ``f`` - an integral element of the number field + - ``f`` -- an integral element of the number field OUTPUT: - An integral element `g`, such that `f - g` belongs to the ideal self + An integral element `g`, such that `f - g` belongs to the ideal ``self`` and such that `g` is a canonical reduced representative of the coset - `f + I` (`I` =self) as described in the ``residues`` function, namely an integral element with coordinates `(r_0, \dots,r_{n-1})`, where: + `f + I` (where `I` = ``self``) as described in the method :meth:`residues`, + namely an integral element with coordinates `(r_0, \dots,r_{n-1})`, where: - `r_i` is reduced modulo `d_i` - - `d_i = b_i[i]`, with `{b_0, b_1, \dots, b_n}` HNF basis - of the ideal self. + - `d_i = b_i[i]`, with `\{b_0, b_1, \dots, b_n\}` HNF basis + of the ideal ``self``. .. note:: The reduced element `g` is not necessarily small. To get a - small `g` use the method ``small_residue``. + small `g` use the method :meth:`small_residue`. EXAMPLES:: @@ -2060,7 +2078,7 @@ def reduce(self, f): True The reduced element does not necessarily have smaller norm (use - ``small_residue`` for that) + :meth:`small_residue` for that) :: @@ -2127,31 +2145,32 @@ def residues(self): - `r_i` is reduced modulo `d_i` - - `d_i = b_i[i]`, with `{b_0, b_1, \dots, b_n}` HNF basis + - `d_i = b_i[i]`, with `\{b_0, b_1, \dots, b_n\}` HNF basis of the ideal. AUTHOR: John Cremona (modified by Maite Aranes) EXAMPLES:: - sage: K.=NumberField(x^2+1) - sage: res = K.ideal(2).residues(); res + sage: K.=NumberField(x^2 + 1) + sage: res = K.ideal(2).residues(); res xmrange_iter([[0, 1], [0, 1]], at 0x...>) sage: list(res) [0, i, 1, i + 1] - sage: list(K.ideal(2+i).residues()) + sage: list(K.ideal(2 + i).residues()) [-2*i, -i, 0, i, 2*i] sage: list(K.ideal(i).residues()) [0] - sage: I = K.ideal(3+6*i) - sage: reps=I.residues() + sage: I = K.ideal(3 + 6*i) + sage: reps = I.residues() sage: len(list(reps)) == I.norm() True - sage: all(r == s or not (r-s) in I for r in reps for s in reps) # long time (6s on sage.math, 2011) + sage: all(r == s or not (r-s) in I # long time (6s on sage.math, 2011) + ....: for r in reps for s in reps) True - sage: K. = NumberField(x^3-10) - sage: I = K.ideal(a-1) + sage: K. = NumberField(x^3 - 10) + sage: I = K.ideal(a - 1) sage: len(list(I.residues())) == I.norm() True @@ -2176,45 +2195,45 @@ def residues(self): def invertible_residues(self, reduce=True): r""" - Returns a iterator through a list of invertible residues + Return an iterator through a list of invertible residues modulo this integral ideal. An error is raised if this fractional ideal is not integral. INPUT: - - ``reduce`` - bool. If True (default), use ``small_residue`` to get + - ``reduce`` -- bool. If ``True`` (default), use ``small_residue`` to get small representatives of the residues. OUTPUT: - - An iterator through a list of invertible residues modulo this ideal - `I`, i.e. a list of elements in the ring of integers `R` representing - the elements of `(R/I)^*`. + An iterator through a list of invertible residues modulo this ideal + `I`, i.e. a list of elements in the ring of integers `R` representing + the elements of `(R/I)^*`. ALGORITHM: Use :pari:`idealstar` to find the group structure and generators of the multiplicative group modulo the ideal. EXAMPLES:: - sage: K.=NumberField(x^2+1) - sage: ires = K.ideal(2).invertible_residues(); ires + sage: K. = NumberField(x^2 + 1) + sage: ires = K.ideal(2).invertible_residues(); ires xmrange_iter([[0, 1]], at 0x...>) sage: list(ires) [1, -i] - sage: list(K.ideal(2+i).invertible_residues()) + sage: list(K.ideal(2 + i).invertible_residues()) [1, 2, 4, 3] sage: list(K.ideal(i).residues()) [0] sage: list(K.ideal(i).invertible_residues()) [1] - sage: I = K.ideal(3+6*i) - sage: units=I.invertible_residues() - sage: len(list(units))==I.euler_phi() + sage: I = K.ideal(3 + 6*i) + sage: units = I.invertible_residues() + sage: len(list(units)) == I.euler_phi() True - sage: K. = NumberField(x^3-10) - sage: I = K.ideal(a-1) + sage: K. = NumberField(x^3 - 10) + sage: I = K.ideal(a - 1) sage: len(list(I.invertible_residues())) == I.euler_phi() True @@ -2236,38 +2255,38 @@ def invertible_residues(self, reduce=True): def invertible_residues_mod(self, subgp_gens=[], reduce=True): r""" - Returns a iterator through a list of representatives for the invertible + Return a iterator through a list of representatives for the invertible residues modulo this integral ideal, modulo the subgroup generated by the elements in the list ``subgp_gens``. INPUT: - - ``subgp_gens`` - either None or a list of elements of the number - field of self. These need not be integral, but should be coprime to - the ideal self. If the list is empty or None, the function returns + - ``subgp_gens`` -- either ``None`` or a list of elements of the number + field of ``self``. These need not be integral, but should be coprime to + the ideal ``self``. If the list is empty or ``None``, the function returns an iterator through a list of representatives for the invertible - residues modulo the integral ideal self. + residues modulo the integral ideal ``self``. - - ``reduce`` - bool. If True (default), use ``small_residues`` to + - ``reduce`` -- bool. If ``True`` (default), use ``small_residues`` to get small representatives of the residues. .. note:: - See also invertible_residues() for a simpler version without the subgroup. + See also :meth:`invertible_residues` for a simpler version without the subgroup. OUTPUT: - - An iterator through a list of representatives for the invertible - residues modulo self and modulo the group generated by - ``subgp_gens``, i.e. a list of elements in the ring of integers `R` - representing the elements of `(R/I)^*/U`, where `I` is this ideal and - `U` is the subgroup of `(R/I)^*` generated by ``subgp_gens``. + An iterator through a list of representatives for the invertible + residues modulo ``self`` and modulo the group generated by + ``subgp_gens``, i.e. a list of elements in the ring of integers `R` + representing the elements of `(R/I)^*/U`, where `I` is this ideal and + `U` is the subgroup of `(R/I)^*` generated by ``subgp_gens``. EXAMPLES: :: - sage: k. = NumberField(x^2 +23) + sage: k. = NumberField(x^2 + 23) sage: I = k.ideal(a) sage: list(I.invertible_residues_mod([-1])) [1, 5, 2, 10, 4, 20, 8, 17, 16, 11, 9] @@ -2280,8 +2299,8 @@ def invertible_residues_mod(self, subgp_gens=[], reduce=True): :: - sage: K. = NumberField(x^3-10) - sage: I = K.ideal(a-1) + sage: K. = NumberField(x^3 - 10) + sage: I = K.ideal(a - 1) sage: len(list(I.invertible_residues_mod([]))) == I.euler_phi() True @@ -2337,7 +2356,7 @@ def denominator(self): EXAMPLES:: - sage: K.=NumberField(x^2+1) + 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() @@ -2367,7 +2386,7 @@ def numerator(self): EXAMPLES:: - sage: K.=NumberField(x^2+1) + 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() @@ -2390,7 +2409,7 @@ def numerator(self): def is_coprime(self, other): """ - Returns True if this ideal is coprime to the other, else False. + Return ``True`` if this ideal is coprime to ``other``, else ``False``. INPUT: @@ -2399,7 +2418,7 @@ def is_coprime(self, other): OUTPUT: - True if self and other are coprime, else False. + ``True`` if ``self`` and ``other`` are coprime, else ``False``. .. note:: @@ -2410,16 +2429,16 @@ def is_coprime(self, other): EXAMPLES:: - sage: K.=NumberField(x^2+1) - sage: I = K.ideal(2+i) - sage: J = K.ideal(2-i) + sage: K. = NumberField(x^2 + 1) + sage: I = K.ideal(2 + i) + sage: J = K.ideal(2 - i) sage: I.is_coprime(J) True sage: (I^-1).is_coprime(J^3) True sage: I.is_coprime(5) False - sage: I.is_coprime(6+i) + sage: I.is_coprime(6 + i) True See :trac:`4536`:: @@ -2457,22 +2476,24 @@ def is_coprime(self, other): def idealcoprime(self, J): """ - Returns l such that l*self is coprime to J. + Return `l` such that ``l*self`` is coprime to `J`. INPUT: - - ``J`` - another integral ideal of the same field as self, which must also be integral. + - ``J`` -- another integral ideal of the same field as ``self``, which must also be integral. OUTPUT: - - ``l`` - an element such that l*self is coprime to the ideal J + an element `l` such that ``l*self`` is coprime to the ideal `J` - TODO: Extend the implementation to non-integral ideals. + .. TODO:: + + Extend the implementation to non-integral ideals. EXAMPLES:: sage: k. = NumberField(x^2 + 23) - sage: A = k.ideal(a+1) + sage: A = k.ideal(a + 1) sage: B = k.ideal(3) sage: A.is_coprime(B) False @@ -2490,7 +2511,7 @@ def idealcoprime(self, J): depends on the PARI version:: sage: k. = NumberField(x^2 + 23) - sage: A = k.ideal(a+1) + sage: A = k.ideal(a + 1) sage: B = k.ideal(3) sage: lam = A.idealcoprime(B) sage: lam in (-1/6*a + 1/6, 1/6*a - 1/6) @@ -2507,15 +2528,15 @@ def idealcoprime(self, J): def small_residue(self, f): r""" - Given an element `f` of the ambient number field, returns an - element `g` such that `f - g` belongs to the ideal self (which + Given an element `f` of the ambient number field, return an + element `g` such that `f - g` belongs to the ideal ``self`` (which must be integral), and `g` is small. .. note:: The reduced representative returned is not uniquely determined. - ALGORITHM: Uses Pari function :pari:`nfeltreduce`. + ALGORITHM: Uses PARI function :pari:`nfeltreduce`. EXAMPLES: @@ -2541,13 +2562,13 @@ def small_residue(self, f): def _pari_bid_(self, flag=1): """ - Returns the pari structure ``bid`` associated to the ideal self. + Return the PARI structure ``bid`` associated to the ideal ``self``. INPUT: - - ``flag`` - when flag=2 it computes the generators of the group - `(O_K/I)^*`, which takes more time. By default - flag=1 (no generators are computed). + - ``flag`` -- when ``flag=2`` it computes the generators of the group + `(O_K/I)^*`, which takes more time. By default + ``flag=1`` (no generators are computed). OUTPUT: @@ -2579,15 +2600,15 @@ def _pari_bid_(self, flag=1): def idealstar(self, flag=1): r""" - Returns the finite abelian group `(O_K/I)^*`, where I is the ideal self - of the number field K, and `O_K` is the ring of integers of K. + Return the finite abelian group `(O_K/I)^*`, where `I` is the ideal ``self`` + of the number field `K`, and `O_K` is the ring of integers of `K`. INPUT: - ``flag`` (int default 1) -- when ``flag`` =2, it also computes the generators of the group `(O_K/I)^*`, which takes more time. By default ``flag`` =1 (no generators are - computed). In both cases the special pari structure ``bid`` + computed). In both cases the special PARI structure ``bid`` is computed as well. If ``flag`` =0 (deprecated) it computes only the group structure of `(O_K/I)^*` (with generators) and not the special ``bid`` structure. @@ -2598,10 +2619,10 @@ def idealstar(self, flag=1): .. note:: - Uses the pari function :pari:`idealstar`. The pari function outputs + Uses the PARI function :pari:`idealstar`. The PARI function outputs a special ``bid`` structure which is stored in the internal - field ``_bid`` of the ideal (when flag=1,2). The special structure - ``bid`` is used in the pari function :pari:`ideallog` + field ``_bid`` of the ideal (when ``flag`` = 1,2). The special structure + ``bid`` is used in the PARI function :pari:`ideallog` to compute discrete logarithms. EXAMPLES:: @@ -2647,32 +2668,32 @@ def idealstar(self, flag=1): def ideallog(self, x, gens=None, check=True): r""" - Returns the discrete logarithm of x with respect to the generators - given in the ``bid`` structure of the ideal self, or with respect to + Return the discrete logarithm of `x` with respect to the generators + given in the ``bid`` structure of the ideal ``self``, or with respect to the generators ``gens`` if these are given. INPUT: - - ``x`` - a non-zero element of the number field of self, + - ``x`` -- a non-zero element of the number field of ``self``, which must have valuation equal to 0 at all prime ideals in - the support of the ideal self. - - ``gens`` - a list of elements of the number field which generate `(R + the support of the ideal ``self``. + - ``gens`` -- a list of elements of the number field which generate `(R / I)^*`, where `R` is the ring of integers of the field and `I` is this ideal, or ``None``. If ``None``, use the generators calculated by :meth:`~idealstar`. - - ``check`` - if True, do a consistency check on the results. Ignored - if ``gens`` is None. + - ``check`` -- if ``True``, do a consistency check on the results. Ignored + if ``gens`` is ``None``. OUTPUT: - - ``l`` - a list of non-negative integers `(x_i)` such that `x = - \prod_i g_i^{x_i}` in `(R/I)^*`, where `x_i` are the generators, and - the list `(x_i)` is lexicographically minimal with respect to this - requirement. If the `x_i` generate independent cyclic factors of - order `d_i`, as is the case for the default generators calculated by - :meth:`~idealstar`, this just means that `0 \le x_i < d_i`. + a list of non-negative integers `(x_i)` such that `x = + \prod_i g_i^{x_i}` in `(R/I)^*`, where `x_i` are the generators, and + the list `(x_i)` is lexicographically minimal with respect to this + requirement. If the `x_i` generate independent cyclic factors of + order `d_i`, as is the case for the default generators calculated by + :meth:`~idealstar`, this just means that `0 \le x_i < d_i`. - A ``ValueError`` will be raised if the elements specified in ``gens`` + A :class:`ValueError` will be raised if the elements specified in ``gens`` do not in fact generate the unit group (even if the element `x` is in the subgroup they generate). @@ -2681,7 +2702,7 @@ def ideallog(self, x, gens=None, check=True): sage: k. = NumberField(x^3 - 11) sage: A = k.ideal(5) sage: G = A.idealstar(2) - sage: l = A.ideallog(a^2 +3) + sage: l = A.ideallog(a^2 + 3) sage: r = G(l).value() sage: (a^2 + 3) - r in A True @@ -2692,16 +2713,16 @@ def ideallog(self, x, gens=None, check=True): sage: K. = NumberField(x^2 - 7) sage: I = K.ideal(17) - sage: I.ideallog(a + 7, [1+a, 2]) + sage: I.ideallog(a + 7, [1 + a, 2]) [10, 3] - sage: I.ideallog(a + 7, [2, 1+a]) + sage: I.ideallog(a + 7, [2, 1 + a]) [0, 118] sage: L. = NumberField(x^4 - x^3 - 7*x^2 + 3*x + 2) sage: J = L.ideal(-b^3 - b^2 - 2) sage: u = -14*b^3 + 21*b^2 + b - 1 sage: v = 4*b^2 + 2*b - 1 - sage: J.ideallog(5+2*b, [u, v], check=True) + sage: J.ideallog(5 + 2*b, [u, v], check=True) [4, 13] A non-example:: @@ -2709,10 +2730,11 @@ def ideallog(self, x, gens=None, check=True): sage: I.ideallog(a + 7, [2]) Traceback (most recent call last): ... - ValueError: Given elements do not generate unit group -- they generate a subgroup of index 36 + ValueError: Given elements do not generate unit group -- + they generate a subgroup of index 36 - ALGORITHM: Uses Pari function :pari:`ideallog`, and (if ``gens`` is not - None) a Hermite normal form calculation to express the result in terms + ALGORITHM: Uses PARI function :pari:`ideallog`, and (if ``gens`` is not + ``None``) a Hermite normal form calculation to express the result in terms of the generators ``gens``. """ # sanitise input @@ -2770,7 +2792,7 @@ def ideallog(self, x, gens=None, check=True): def element_1_mod(self, other): r""" - Returns an element `r` in this ideal such that `1-r` is in other + Return an element `r` in this ideal such that `1-r` is in ``other`` An error is raised if either ideal is not integral of if they are not coprime. @@ -2782,29 +2804,29 @@ def element_1_mod(self, other): OUTPUT: - An element `r` of the ideal self such that `1-r` is in the ideal other + An element `r` of the ideal self such that `1-r` is in the ideal ``other`` AUTHOR: Maite Aranes (modified to use PARI's :pari:`idealaddtoone` by Francis Clarke) EXAMPLES:: - sage: K. = NumberField(x^3-2) - sage: A = K.ideal(a+1); A; A.norm() + sage: K. = NumberField(x^3 - 2) + sage: A = K.ideal(a + 1); A; A.norm() Fractional ideal (a + 1) 3 - sage: B = K.ideal(a^2-4*a+2); B; B.norm() + sage: B = K.ideal(a^2 - 4*a + 2); B; B.norm() Fractional ideal (a^2 - 4*a + 2) 68 sage: r = A.element_1_mod(B); r -33 sage: r in A True - sage: 1-r in B + sage: 1 - r in B True TESTS:: - sage: K. = NumberField(x^3-2) + sage: K. = NumberField(x^3 - 2) sage: A = K.ideal(a+1) sage: B = K.ideal(a^2-4*a+1); B; B.norm() Fractional ideal (a^2 - 4*a + 1) @@ -2839,7 +2861,7 @@ def element_1_mod(self, other): def euler_phi(self): r""" - Returns the Euler `\varphi`-function of this integral ideal. + Return the Euler `\varphi`-function of this integral ideal. This is the order of the multiplicative group of the quotient modulo the ideal. @@ -2848,8 +2870,8 @@ def euler_phi(self): EXAMPLES:: - sage: K.=NumberField(x^2+1) - sage: I = K.ideal(2+i) + sage: K. = NumberField(x^2 + 1) + sage: I = K.ideal(2 + i) sage: [r for r in I.residues() if I.is_coprime(r)] [-2*i, -i, i, 2*i] sage: I.euler_phi() @@ -2859,7 +2881,7 @@ def euler_phi(self): 100 sage: len([r for r in J.residues() if J.is_coprime(r)]) 100 - sage: J = K.ideal(3-2*i) + sage: J = K.ideal(3 - 2*i) sage: I.is_coprime(J) True sage: I.euler_phi()*J.euler_phi() == (I*J).euler_phi() @@ -2876,7 +2898,7 @@ def euler_phi(self): def prime_to_S_part(self, S): r""" Return the part of this fractional ideal which is coprime to - the prime ideals in the list ``S``. + the prime ideals in the list `S`. .. NOTE:: @@ -2886,7 +2908,7 @@ def prime_to_S_part(self, S): INPUT: - - `S` -- a list of prime ideals + - ``S`` -- a list of prime ideals OUTPUT: @@ -2896,18 +2918,20 @@ def prime_to_S_part(self, S): EXAMPLES:: - sage: K. = NumberField(x^2-23) + sage: K. = NumberField(x^2 - 23) sage: I = K.ideal(24) - sage: S = [K.ideal(-a+5),K.ideal(5)] + sage: S = [K.ideal(-a + 5), K.ideal(5)] sage: I.prime_to_S_part(S) Fractional ideal (3) sage: J = K.ideal(15) sage: J.prime_to_S_part(S) Fractional ideal (3) - sage: K. = NumberField(x^5-23) + sage: K. = NumberField(x^5 - 23) sage: I = K.ideal(24) - sage: S = [K.ideal(15161*a^4 + 28383*a^3 + 53135*a^2 + 99478*a + 186250),K.ideal(2*a^4 + 3*a^3 + 4*a^2 + 15*a + 11), K.ideal(101)] + sage: S = [K.ideal(15161*a^4 + 28383*a^3 + 53135*a^2 + 99478*a + 186250), + ....: K.ideal(2*a^4 + 3*a^3 + 4*a^2 + 15*a + 11), + ....: K.ideal(101)] sage: I.prime_to_S_part(S) Fractional ideal (24) """ @@ -2919,11 +2943,11 @@ def prime_to_S_part(self, S): def is_S_unit(self, S): r""" - Return True if this fractional ideal is a unit with respect to the list of primes ``S``. + Return ``True`` if this fractional ideal is a unit with respect to the list of primes `S`. INPUT: - - `S` - a list of prime ideals (not checked if they are + - ``S`` -- a list of prime ideals (not checked if they are indeed prime). .. note:: @@ -2934,8 +2958,8 @@ def is_S_unit(self, S): OUTPUT: - True, if the ideal is an `S`-unit: that is, if the valuations of - the ideal at all primes not in `S` are zero. False, otherwise. + ``True``, if the ideal is an `S`-unit: that is, if the valuations of + the ideal at all primes not in `S` are zero. ``False``, otherwise. EXAMPLES:: @@ -2949,11 +2973,11 @@ def is_S_unit(self, S): def is_S_integral(self, S): r""" - Return True if this fractional ideal is integral with respect to the list of primes ``S``. + Return ``True`` if this fractional ideal is integral with respect to the list of primes `S`. INPUT: - - `S` - a list of prime ideals (not checked if they are indeed + - `S` -- a list of prime ideals (not checked if they are indeed prime). .. note:: @@ -2964,8 +2988,8 @@ def is_S_integral(self, S): OUTPUT: - True, if the ideal is `S`-integral: that is, if the valuations - of the ideal at all primes not in `S` are non-negative. False, + ``True``, if the ideal is `S`-integral: that is, if the valuations + of the ideal at all primes not in `S` are non-negative. ``False``, otherwise. EXAMPLES:: @@ -2987,7 +3011,7 @@ def is_S_integral(self, S): def prime_to_idealM_part(self, M): r""" Version for integral ideals of the ``prime_to_m_part`` function over `\ZZ`. - Returns the largest divisor of self that is coprime to the ideal ``M``. + Return the largest divisor of ``self`` that is coprime to the ideal `M`. INPUT: @@ -2995,14 +3019,14 @@ def prime_to_idealM_part(self, M): OUTPUT: - An ideal which is the largest divisor of self that is coprime to `M`. + An ideal which is the largest divisor of ``self`` that is coprime to `M`. AUTHOR: Maite Aranes EXAMPLES:: sage: k. = NumberField(x^2 + 23) - sage: I = k.ideal(a+1) + sage: I = k.ideal(a + 1) sage: M = k.ideal(2, 1/2*a - 1/2) sage: J = I.prime_to_idealM_part(M); J Fractional ideal (12, 1/2*a + 13/2) @@ -3041,9 +3065,9 @@ def _p_quotient(self, p): OUTPUT: - - ``V`` -- a vector space of characteristic ``p`` + - `V` -- a vector space of characteristic `p` - ``quo`` -- a partially defined quotient homomorphism from the - ambient number field to ``V`` + ambient number field to `V` - ``lift`` -- a section of ``quo``. EXAMPLES:: @@ -3062,7 +3086,7 @@ def _p_quotient(self, p): sage: K. = NumberField(x^2 + 1); O = K.maximal_order() sage: I = K.factor(5)[0][0] - sage: Q,quo,lift = I._p_quotient(5) + sage: Q, quo, lift = I._p_quotient(5) sage: lift(quo(i)) 3 sage: lift(quo(i)) - i in I @@ -3078,9 +3102,14 @@ def _p_quotient(self, p): Basis matrix: [1 3] sage: quo - Partially defined quotient map from Number Field in i with defining polynomial x^2 + 1 to an explicit vector space representation for the quotient of the ring of integers by (p,I) for the ideal I=Fractional ideal (-i - 2). + Partially defined quotient map + from Number Field in i with defining polynomial x^2 + 1 + to an explicit vector space representation for the quotient of + the ring of integers by (p,I) for the ideal I=Fractional ideal (-i - 2). sage: lift - Lifting map to Gaussian Integers in Number Field in i with defining polynomial x^2 + 1 from quotient of integers by Fractional ideal (-i - 2) + Lifting map + to Gaussian Integers in Number Field in i with defining polynomial x^2 + 1 + from quotient of integers by Fractional ideal (-i - 2) """ return quotient_char_p(self, p) @@ -3091,7 +3120,7 @@ def residue_field(self, names=None): EXAMPLES:: - sage: K. = NumberField(x^3-7) + sage: K. = NumberField(x^3 - 7) sage: P = K.ideal(29).factor()[0][0] sage: P.residue_field() Residue field in abar of Fractional ideal (2*a^2 + 3*a - 10) @@ -3100,7 +3129,7 @@ def residue_field(self, names=None): Another example:: - sage: K. = NumberField(x^3-7) + sage: K. = NumberField(x^3 - 7) sage: P = K.ideal(389).factor()[0][0]; P Fractional ideal (389, a^2 - 44*a - 9) sage: P.residue_class_degree() @@ -3124,11 +3153,12 @@ def residue_field(self, names=None): has been fixed:: sage: K. = NumberField(x^2 + 1) - sage: P1, P2 = [g[0] for g in K.factor(5)]; (P1,P2) + sage: P1, P2 = [g[0] for g in K.factor(5)]; P1, P2 (Fractional ideal (-i - 2), Fractional ideal (2*i + 1)) sage: a = 1/(1+2*i) - sage: F1, F2 = [g.residue_field() for g in [P1,P2]]; (F1,F2) - (Residue field of Fractional ideal (-i - 2), Residue field of Fractional ideal (2*i + 1)) + sage: F1, F2 = [g.residue_field() for g in [P1, P2]]; F1, F2 + (Residue field of Fractional ideal (-i - 2), + Residue field of Fractional ideal (2*i + 1)) sage: a.valuation(P1) 0 sage: F1(i/7) @@ -3140,7 +3170,8 @@ def residue_field(self, names=None): sage: F2(a) Traceback (most recent call last): ... - ZeroDivisionError: Cannot reduce field element -2/5*i + 1/5 modulo Fractional ideal (2*i + 1): it has negative valuation + ZeroDivisionError: Cannot reduce field element -2/5*i + 1/5 + modulo Fractional ideal (2*i + 1): it has negative valuation An example with a relative number field:: @@ -3170,7 +3201,7 @@ def residue_field(self, names=None): def residue_class_degree(self): r""" Return the residue class degree of this fractional ideal, - assuming it is prime. Otherwise, raise a ValueError. + assuming it is prime. Otherwise, raise a :class:`ValueError`. The residue class degree of a prime ideal `I` is the degree of the extension `O_K/I` of its prime subfield. @@ -3180,7 +3211,9 @@ def residue_class_degree(self): sage: K. = NumberField(x^5 + 2); K Number Field in a with defining polynomial x^5 + 2 sage: f = K.factor(19); f - (Fractional ideal (a^2 + a - 3)) * (Fractional ideal (2*a^4 + a^2 - 2*a + 1)) * (Fractional ideal (a^2 + a - 1)) + (Fractional ideal (a^2 + a - 3)) + * (Fractional ideal (2*a^4 + a^2 - 2*a + 1)) + * (Fractional ideal (a^2 + a - 1)) sage: [i.residue_class_degree() for i, _ in f] [2, 2, 1] """ @@ -3189,7 +3222,7 @@ def residue_class_degree(self): def ray_class_number(self): r""" Return the order of the ray class group modulo this ideal. This is a - wrapper around Pari's :pari:`bnrclassno` function. + wrapper around PARI's :pari:`bnrclassno` function. EXAMPLES:: @@ -3210,7 +3243,7 @@ def ray_class_number(self): def is_NumberFieldFractionalIdeal(x): """ - Return True if x is a fractional ideal of a number field. + Return ``True`` if `x` is a fractional ideal of a number field. EXAMPLES:: diff --git a/src/sage/rings/number_field/number_field_ideal_rel.py b/src/sage/rings/number_field/number_field_ideal_rel.py index 1292219f843..c465ecf438a 100644 --- a/src/sage/rings/number_field/number_field_ideal_rel.py +++ b/src/sage/rings/number_field/number_field_ideal_rel.py @@ -93,7 +93,7 @@ def _richcmp_(self, other, op): def _contains_(self, x): """ - Return True if x is an element of this ideal. + Return ``True`` if `x` is an element of this ideal. This function is called (indirectly) when the ``in`` operator is used. @@ -154,10 +154,10 @@ def absolute_ideal(self, names = 'a'): Fractional ideal (13) Now a non-trivial ideal in `L` that is principal in the - subfield `K`. Since the optional 'names' argument is not - passed, the generators of the absolute ideal J are returned - in terms of the default field generator 'a'. This does not agree - with the generator 'm' of the absolute field F defined above:: + subfield `K`. Since the optional ``names`` argument is not + passed, the generators of the absolute ideal `J` are returned + in terms of the default field generator `a`. This does not agree + with the generator `m` of the absolute field `F` defined above:: sage: J = L.ideal(b); J Fractional ideal (b) @@ -170,7 +170,7 @@ def absolute_ideal(self, names = 'a'): sage: J.absolute_ideal().norm() 4 - Now pass 'm' as the name for the generator of the absolute field:: + Now pass `m` as the name for the generator of the absolute field:: sage: J.absolute_ideal('m') Fractional ideal (m^2) @@ -202,7 +202,7 @@ def absolute_ideal(self, names = 'a'): def _from_absolute_ideal(self, id): r""" - Convert the absolute ideal id to a relative number field ideal. + Convert the absolute ideal ``id`` to a relative number field ideal. WARNING: This is an internal helper function. @@ -291,7 +291,7 @@ def gens_reduced(self): def __invert__(self): """ - Return the multiplicative inverse of self. Call with ~self. + Return the multiplicative inverse of ``self``. Call with ``~self``. EXAMPLES:: @@ -308,8 +308,8 @@ def __invert__(self): def is_principal(self, proof=None): """ - Return True if this ideal is principal. If so, set - self.__reduced_generators, with length one. + Return ``True`` if this ideal is principal. If so, set + ``self.__reduced_generators``, with length one. EXAMPLES:: @@ -334,7 +334,7 @@ def is_principal(self, proof=None): def is_zero(self): r""" - Return True if this is the zero ideal. + Return ``True`` if this is the zero ideal. EXAMPLES:: @@ -371,7 +371,7 @@ def relative_norm(self): EXAMPLES:: sage: R. = QQ[] - sage: K. = NumberField(x^2+6) + sage: K. = NumberField(x^2 + 6) sage: L. = K.extension(K['x'].gen()^4 + a) sage: N = L.ideal(b).relative_norm(); N Fractional ideal (-a) @@ -420,7 +420,8 @@ def norm(self): sage: K.ideal(2).norm() Traceback (most recent call last): ... - NotImplementedError: For a fractional ideal in a relative number field you must use relative_norm or absolute_norm as appropriate + NotImplementedError: For a fractional ideal in a relative number field + you must use relative_norm or absolute_norm as appropriate """ raise NotImplementedError("For a fractional ideal in a relative number field you must use relative_norm or absolute_norm as appropriate") @@ -431,12 +432,12 @@ def ideal_below(self): EXAMPLES:: sage: R. = QQ[] - sage: K. = NumberField(x^2+6) + sage: K. = NumberField(x^2 + 6) sage: L. = K.extension(K['x'].gen()^4 + a) sage: N = L.ideal(b) sage: M = N.ideal_below(); M == K.ideal([-a]) True - sage: Np = L.ideal( [ L(t) for t in M.gens() ]) + sage: Np = L.ideal([L(t) for t in M.gens()]) sage: Np.ideal_below() == M True sage: M.parent() @@ -496,7 +497,7 @@ def ideal_below(self): sage: K0.ideal([-a0 + 1]) == K0.ideal([-a0 + 5]) False - It works when the base_field is itself a relative number field:: + It works when the base field is itself a relative number field:: sage: PQ. = QQ[] sage: F. = NumberFieldTower([X^2 - 2, X^2 - 3]) @@ -534,9 +535,11 @@ def factor(self): sage: K. = QQ.extension([x^2 + 11, x^2 - 5]) sage: K.factor(5) - (Fractional ideal (5, (-1/4*b - 1/4)*a + 1/4*b - 3/4))^2 * (Fractional ideal (5, (-1/4*b - 1/4)*a + 1/4*b - 7/4))^2 + (Fractional ideal (5, (-1/4*b - 1/4)*a + 1/4*b - 3/4))^2 + * (Fractional ideal (5, (-1/4*b - 1/4)*a + 1/4*b - 7/4))^2 sage: K.ideal(5).factor() - (Fractional ideal (5, (-1/4*b - 1/4)*a + 1/4*b - 3/4))^2 * (Fractional ideal (5, (-1/4*b - 1/4)*a + 1/4*b - 7/4))^2 + (Fractional ideal (5, (-1/4*b - 1/4)*a + 1/4*b - 3/4))^2 + * (Fractional ideal (5, (-1/4*b - 1/4)*a + 1/4*b - 7/4))^2 sage: K.ideal(5).prime_factors() [Fractional ideal (5, (-1/4*b - 1/4)*a + 1/4*b - 3/4), Fractional ideal (5, (-1/4*b - 1/4)*a + 1/4*b - 7/4)] @@ -564,13 +567,13 @@ def factor(self): def integral_basis(self): r""" - Return a basis for self as a `\ZZ`-module. + Return a basis for ``self`` as a `\ZZ`-module. EXAMPLES:: sage: K. = NumberField([x^2 + 1, x^2 - 3]) sage: I = K.ideal(17*b - 3*a) - sage: x = I.integral_basis(); x # random + sage: x = I.integral_basis(); x # random [438, -b*a + 309, 219*a - 219*b, 156*a - 154*b] The exact results are somewhat unpredictable, hence the ``# random`` @@ -624,7 +627,7 @@ def is_prime(self): def is_integral(self): """ - Return True if this ideal is integral. + Return ``True`` if this ideal is integral. EXAMPLES:: @@ -640,15 +643,15 @@ def is_integral(self): def absolute_ramification_index(self): """ Return the absolute ramification index of this fractional ideal, - assuming it is prime. Otherwise, raise a ValueError. + assuming it is prime. Otherwise, raise a :class:`ValueError`. The absolute ramification index is the power of this prime appearing in the factorization of the rational prime that this prime lies over. - Use relative_ramification_index to obtain the power of this + Use :meth:`relative_ramification_index` to obtain the power of this prime occurring in the factorization of the prime ideal - of the base field that this prime lies over. + of the base field that this prime lies over. EXAMPLES:: @@ -671,13 +674,13 @@ def absolute_ramification_index(self): def relative_ramification_index(self): """ Return the relative ramification index of this fractional ideal, - assuming it is prime. Otherwise, raise a ValueError. + assuming it is prime. Otherwise, raise a :class:`ValueError`. The relative ramification index is the power of this prime appearing in the factorization of the prime ideal of the base field that this prime lies over. - Use absolute_ramification_index to obtain the power of this + Use :meth:`absolute_ramification_index` to obtain the power of this prime occurring in the factorization of the rational prime that this prime lies over. @@ -705,7 +708,7 @@ def relative_ramification_index(self): def ramification_index(self): r""" - For ideals in relative number fields, ``ramification_index`` + For ideals in relative number fields, :meth:`ramification_index` is deliberately not implemented in order to avoid ambiguity. Either :meth:`~relative_ramification_index` or :meth:`~absolute_ramification_index` should be used instead. @@ -762,7 +765,7 @@ def residues(self): def element_1_mod(self, other): r""" - Returns an element `r` in this ideal such that `1-r` is in other. + Returns an element `r` in this ideal such that `1-r` is in ``other``. An error is raised if either ideal is not integral of if they are not coprime. @@ -774,7 +777,7 @@ def element_1_mod(self, other): OUTPUT: an element `r` of the ideal self such that `1-r` is in the - ideal other. + ideal ``other``. EXAMPLES:: @@ -820,7 +823,7 @@ def smallest_integer(self): def valuation(self, p): r""" - Return the valuation of this fractional ideal at ``p``. + Return the valuation of this fractional ideal at `\mathfrak{p}`. INPUT: @@ -830,7 +833,7 @@ def valuation(self, p): (integer) The valuation of this fractional ideal at the prime `\mathfrak{p}`. If `\mathfrak{p}` is not prime, raise a - ValueError. + :class:`ValueError`. EXAMPLES:: @@ -858,7 +861,7 @@ def valuation(self, p): def is_NumberFieldFractionalIdeal_rel(x): """ - Return True if x is a fractional ideal of a relative number field. + Return ``True`` if `x` is a fractional ideal of a relative number field. EXAMPLES:: @@ -874,7 +877,7 @@ def is_NumberFieldFractionalIdeal_rel(x): sage: is_NumberFieldFractionalIdeal_rel(I) False sage: R. = QQ[] - sage: K. = NumberField(x^2+6) + sage: K. = NumberField(x^2 + 6) sage: L. = K.extension(K['x'].gen()^4 + a) sage: I = L.ideal(b); I Fractional ideal (6, b) diff --git a/src/sage/rings/number_field/number_field_morphisms.pyx b/src/sage/rings/number_field/number_field_morphisms.pyx index 34a51a97c62..2838370c327 100644 --- a/src/sage/rings/number_field/number_field_morphisms.pyx +++ b/src/sage/rings/number_field/number_field_morphisms.pyx @@ -150,7 +150,7 @@ cdef class NumberFieldEmbedding(Morphism): def gen_image(self): """ - Returns the image of the generator under this embedding. + Return the image of the generator under this embedding. EXAMPLES:: @@ -177,15 +177,15 @@ cdef class EmbeddedNumberFieldMorphism(NumberFieldEmbedding): EXAMPLES:: - sage: K. = NumberField(x^2+1,embedding=QQbar(I)) - sage: L. = NumberField(x^2+1,embedding=-QQbar(I)) + sage: K. = NumberField(x^2 + 1, embedding=QQbar(I)) + sage: L. = NumberField(x^2 + 1, embedding=-QQbar(I)) sage: from sage.rings.number_field.number_field_morphisms import EmbeddedNumberFieldMorphism - sage: EmbeddedNumberFieldMorphism(K,L,CDF) + sage: EmbeddedNumberFieldMorphism(K, L, CDF) Generic morphism: From: Number Field in i with defining polynomial x^2 + 1 with i = I To: Number Field in i with defining polynomial x^2 + 1 with i = -I Defn: i -> -i - sage: EmbeddedNumberFieldMorphism(K,L,QQbar) + sage: EmbeddedNumberFieldMorphism(K, L, QQbar) Generic morphism: From: Number Field in i with defining polynomial x^2 + 1 with i = I To: Number Field in i with defining polynomial x^2 + 1 with i = -I @@ -225,7 +225,9 @@ cdef class EmbeddedNumberFieldMorphism(NumberFieldEmbedding): sage: F1.gen() + F2.gen() Traceback (most recent call last): ... - TypeError: unsupported operand parent(s) for +: 'Number Field in a with defining polynomial x^3 + 2 with a = -1.259921049894873?' and 'Number Field in a with defining polynomial x^3 + 2 with a = 0.6299605249474365? + 1.091123635971722?*I' + TypeError: unsupported operand parent(s) for +: + 'Number Field in a with defining polynomial x^3 + 2 with a = -1.259921049894873?' and + 'Number Field in a with defining polynomial x^3 + 2 with a = 0.6299605249474365? + 1.091123635971722?*I' The following was fixed to raise a ``TypeError`` in :trac:`15331`:: @@ -272,13 +274,13 @@ cdef class EmbeddedNumberFieldMorphism(NumberFieldEmbedding): EXAMPLES:: sage: from sage.rings.number_field.number_field_morphisms import EmbeddedNumberFieldMorphism - sage: K. = NumberField(x^2-700, embedding=25) - sage: L. = NumberField(x^6-700, embedding=3) + sage: K. = NumberField(x^2 - 700, embedding=25) + sage: L. = NumberField(x^6 - 700, embedding=3) sage: f = EmbeddedNumberFieldMorphism(K, L) - sage: f(2*a-1) + sage: f(2*a - 1) 2*b^3 - 1 sage: g = f.section() - sage: g(2*b^3-1) + sage: g(2*b^3 - 1) 2*a - 1 """ return EmbeddedNumberFieldConversion(self.codomain(), self.domain(), self.ambient_field) @@ -340,12 +342,12 @@ cdef class EmbeddedNumberFieldConversion(Map): cpdef matching_root(poly, target, ambient_field=None, margin=1, max_prec=None): """ - Given a polynomial and a target, this function chooses the root that - target best approximates as compared in ambient_field. + Given a polynomial and a ``target``, choose the root that + ``target`` best approximates as compared in ``ambient_field``. - If the parent of target is exact, the equality is required, otherwise + If the parent of ``target`` is exact, the equality is required, otherwise find closest root (with respect to the ``abs`` function) in the - ambient field to the target, and return the root of poly (if any) that + ambient field to the ``target``, and return the root of ``poly`` (if any) that approximates it best. EXAMPLES:: @@ -403,11 +405,11 @@ cpdef matching_root(poly, target, ambient_field=None, margin=1, max_prec=None): cpdef closest(target, values, margin=1): """ - This is a utility function that returns the item in values closest to - target (with respect to the ``abs`` function). If margin is greater - than 1, and x and y are the first and second closest elements to target, - then only return x if x is margin times closer to target than y, i.e. - margin * abs(target-x) < abs(target-y). + This is a utility function that returns the item in ``values`` closest to + target (with respect to the ``abs`` function). If ``margin`` is greater + than 1, and `x` and `y` are the first and second closest elements to ``target``, + then only return `x` if `x` is ``margin`` times closer to ``target`` than `y`, i.e. + ``margin * abs(target-x) < abs(target-y)``. TESTS:: @@ -560,7 +562,7 @@ cdef class CyclotomicFieldEmbedding(NumberFieldEmbedding): """ Specialized class for converting cyclotomic field elements into a cyclotomic field of higher order. All the real work is done by - _lift_cyclotomic_element. + :meth:`_lift_cyclotomic_element`. """ cdef ratio diff --git a/src/sage/rings/number_field/number_field_rel.py b/src/sage/rings/number_field/number_field_rel.py index 88284bf8ed0..7405a08b4bb 100644 --- a/src/sage/rings/number_field/number_field_rel.py +++ b/src/sage/rings/number_field/number_field_rel.py @@ -157,7 +157,7 @@ class NumberField_relative(NumberField_generic): sage: K. = NumberField(x^3 - 2) sage: t = polygen(K) - sage: L. = K.extension(t^2+t+a); L + sage: L. = K.extension(t^2 + t + a); L Number Field in b with defining polynomial x^2 + x + a over its base field TESTS:: @@ -324,17 +324,17 @@ def __init__(self, base, polynomial, name, def change_names(self, names): r""" - Return relative number field isomorphic to self but with the + Return relative number field isomorphic to ``self`` but with the given generator names. INPUT: - ``names`` -- number of names should be at most the number of - generators of self, i.e., the number of steps in the tower + generators of ``self``, i.e., the number of steps in the tower of relative fields. Also, ``K.structure()`` returns ``from_K`` and ``to_K``, where - from_K is an isomorphism from `K` to self and ``to_K`` is an + ``from_K`` is an isomorphism from `K` to ``self`` and ``to_K`` is an isomorphism from self to `K`. EXAMPLES:: @@ -366,14 +366,19 @@ def change_names(self, names): sage: PF. = F[] sage: K. = F.extension(Y^2 - (1 + a)*(a + b)*a*b) sage: L. = K.change_names(); L - Number Field in m with defining polynomial x^2 + (-2*r - 3)*n - 2*r - 6 over its base field + Number Field in m with defining polynomial + x^2 + (-2*r - 3)*n - 2*r - 6 over its base field sage: L.structure() (Isomorphism given by variable name change map: - From: Number Field in m with defining polynomial x^2 + (-2*r - 3)*n - 2*r - 6 over its base field - To: Number Field in c with defining polynomial Y^2 + (-2*b - 3)*a - 2*b - 6 over its base field, + From: Number Field in m with defining polynomial + x^2 + (-2*r - 3)*n - 2*r - 6 over its base field + To: Number Field in c with defining polynomial + Y^2 + (-2*b - 3)*a - 2*b - 6 over its base field, Isomorphism given by variable name change map: - From: Number Field in c with defining polynomial Y^2 + (-2*b - 3)*a - 2*b - 6 over its base field - To: Number Field in m with defining polynomial x^2 + (-2*r - 3)*n - 2*r - 6 over its base field) + From: Number Field in c with defining polynomial + Y^2 + (-2*b - 3)*a - 2*b - 6 over its base field + To: Number Field in m with defining polynomial + x^2 + (-2*r - 3)*n - 2*r - 6 over its base field) """ if len(names) == 0: names = self.variable_names() @@ -387,9 +392,9 @@ def change_names(self, names): def subfields(self, degree=0, name=None): """ - Return all subfields of this relative number field self of the given degree, + Return all subfields of this relative number field ``self`` of the given degree, or of all possible degrees if degree is 0. The subfields are returned as - absolute fields together with an embedding into self. For the case of the + absolute fields together with an embedding into ``self``. For the case of the field itself, the reverse isomorphism is also provided. EXAMPLES:: @@ -400,27 +405,42 @@ def subfields(self, degree=0, name=None): sage: K. = F.extension(Y^2 - (1 + a)*(a + b)*a*b) sage: K.subfields(2) [ - (Number Field in c0 with defining polynomial x^2 - 24*x + 96, Ring morphism: - From: Number Field in c0 with defining polynomial x^2 - 24*x + 96 - To: Number Field in c with defining polynomial Y^2 + (-2*b - 3)*a - 2*b - 6 over its base field - Defn: c0 |--> -4*b + 12, None), - (Number Field in c1 with defining polynomial x^2 - 24*x + 120, Ring morphism: - From: Number Field in c1 with defining polynomial x^2 - 24*x + 120 - To: Number Field in c with defining polynomial Y^2 + (-2*b - 3)*a - 2*b - 6 over its base field - Defn: c1 |--> 2*b*a + 12, None), - (Number Field in c2 with defining polynomial x^2 - 24*x + 72, Ring morphism: - From: Number Field in c2 with defining polynomial x^2 - 24*x + 72 - To: Number Field in c with defining polynomial Y^2 + (-2*b - 3)*a - 2*b - 6 over its base field - Defn: c2 |--> -6*a + 12, None) + (Number Field in c0 with defining polynomial x^2 - 24*x + 96, + Ring morphism: + From: Number Field in c0 with defining polynomial x^2 - 24*x + 96 + To: Number Field in c with defining polynomial + Y^2 + (-2*b - 3)*a - 2*b - 6 over its base field + Defn: c0 |--> -4*b + 12, + None), + (Number Field in c1 with defining polynomial x^2 - 24*x + 120, + Ring morphism: + From: Number Field in c1 with defining polynomial x^2 - 24*x + 120 + To: Number Field in c with defining polynomial + Y^2 + (-2*b - 3)*a - 2*b - 6 over its base field + Defn: c1 |--> 2*b*a + 12, + None), + (Number Field in c2 with defining polynomial x^2 - 24*x + 72, + Ring morphism: + From: Number Field in c2 with defining polynomial x^2 - 24*x + 72 + To: Number Field in c with defining polynomial + Y^2 + (-2*b - 3)*a - 2*b - 6 over its base field + Defn: c2 |--> -6*a + 12, + None) ] sage: K.subfields(8, 'w') [ - (Number Field in w0 with defining polynomial x^8 - 12*x^6 + 36*x^4 - 36*x^2 + 9, Ring morphism: - From: Number Field in w0 with defining polynomial x^8 - 12*x^6 + 36*x^4 - 36*x^2 + 9 - To: Number Field in c with defining polynomial Y^2 + (-2*b - 3)*a - 2*b - 6 over its base field - Defn: w0 |--> (-1/2*b*a + 1/2*b + 1/2)*c, Relative number field morphism: - From: Number Field in c with defining polynomial Y^2 + (-2*b - 3)*a - 2*b - 6 over its base field - To: Number Field in w0 with defining polynomial x^8 - 12*x^6 + 36*x^4 - 36*x^2 + 9 + (Number Field in w0 with defining polynomial x^8 - 12*x^6 + 36*x^4 - 36*x^2 + 9, + Ring morphism: + From: Number Field in w0 with defining polynomial + x^8 - 12*x^6 + 36*x^4 - 36*x^2 + 9 + To: Number Field in c with defining polynomial + Y^2 + (-2*b - 3)*a - 2*b - 6 over its base field + Defn: w0 |--> (-1/2*b*a + 1/2*b + 1/2)*c, + Relative number field morphism: + From: Number Field in c with defining polynomial + Y^2 + (-2*b - 3)*a - 2*b - 6 over its base field + To: Number Field in w0 with defining polynomial + x^8 - 12*x^6 + 36*x^4 - 36*x^2 + 9 Defn: c |--> -1/3*w0^7 + 4*w0^5 - 12*w0^3 + 11*w0 a |--> 1/3*w0^6 - 10/3*w0^4 + 5*w0^2 b |--> -2/3*w0^6 + 7*w0^4 - 14*w0^2 + 6) @@ -444,7 +464,7 @@ def subfields(self, degree=0, name=None): def is_absolute(self): r""" - Returns False, since this is not an absolute field. + Return ``False``, since this is not an absolute field. EXAMPLES:: @@ -550,57 +570,62 @@ def galois_closure(self, names=None): sage: K. = NumberField([x^4 + 3, x^2 + 2]); K Number Field in a with defining polynomial x^4 + 3 over its base field sage: K.galois_closure('c') - Number Field in c with defining polynomial x^16 + 16*x^14 + 28*x^12 + 784*x^10 + 19846*x^8 - 595280*x^6 + 2744476*x^4 + 3212848*x^2 + 29953729 + Number Field in c with defining polynomial x^16 + 16*x^14 + 28*x^12 + + 784*x^10 + 19846*x^8 - 595280*x^6 + 2744476*x^4 + 3212848*x^2 + 29953729 """ return self.absolute_field('a').galois_closure(names=names) def composite_fields(self, other, names=None, both_maps=False, preserve_embedding=True): """ - List of all possible composite number fields formed from self and - other, together with (optionally) embeddings into the compositum; - see the documentation for both_maps below. + List of all possible composite number fields formed from ``self`` and + ``other``, together with (optionally) embeddings into the compositum; + see the documentation for ``both_maps`` below. Since relative fields do not have ambient embeddings, - preserve_embedding has no effect. In every case all possible + ``preserve_embedding`` has no effect. In every case all possible composite number fields are returned. INPUT: - - ``other`` - a number field + - ``other`` -- a number field - - ``names`` - generator name for composite fields + - ``names`` -- generator name for composite fields - - ``both_maps`` - (default: False) if True, return quadruples - (F, self_into_F, other_into_F, k) such that self_into_F maps self into - F, other_into_F maps other into F. For relative number fields k is - always None. - - ``preserve_embedding`` - (default: True) has no effect, but is kept - for compatibility with the absolute version of this function. In every + - ``both_maps`` -- (default: ``False``) if ``True``, return quadruples + (`F`, ``self_into_F, ``other_into_F``, `k`) such that ``self_into_F`` maps ``self`` into + `F`, ``other_into_F`` maps ``other`` into `F`. For relative number fields, `k` is + always ``None``. + + - ``preserve_embedding`` -- (default: ``True``) has no effect, but is kept + for compatibility with the absolute version of this method. In every case the list of all possible compositums is returned. OUTPUT: - - ``list`` - list of the composite fields, possibly with maps. - + list of the composite fields, possibly with maps. EXAMPLES:: sage: K. = NumberField([x^2 + 5, x^2 - 2]) sage: L. = NumberField([x^2 + 5, x^2 - 3]) sage: K.composite_fields(L, 'e') - [Number Field in e with defining polynomial x^8 - 24*x^6 + 464*x^4 + 3840*x^2 + 25600] + [Number Field in e with defining polynomial + x^8 - 24*x^6 + 464*x^4 + 3840*x^2 + 25600] sage: K.composite_fields(L, 'e', both_maps=True) - [[Number Field in e with defining polynomial x^8 - 24*x^6 + 464*x^4 + 3840*x^2 + 25600, + [[Number Field in e with defining polynomial + x^8 - 24*x^6 + 464*x^4 + 3840*x^2 + 25600, Relative number field morphism: - From: Number Field in a with defining polynomial x^2 + 5 over its base field - To: Number Field in e with defining polynomial x^8 - 24*x^6 + 464*x^4 + 3840*x^2 + 25600 - Defn: a |--> -9/66560*e^7 + 11/4160*e^5 - 241/4160*e^3 - 101/104*e - b |--> -21/166400*e^7 + 73/20800*e^5 - 779/10400*e^3 + 7/260*e, + From: Number Field in a with defining polynomial x^2 + 5 over its base field + To: Number Field in e with defining polynomial + x^8 - 24*x^6 + 464*x^4 + 3840*x^2 + 25600 + Defn: a |--> -9/66560*e^7 + 11/4160*e^5 - 241/4160*e^3 - 101/104*e + b |--> -21/166400*e^7 + 73/20800*e^5 - 779/10400*e^3 + 7/260*e, Relative number field morphism: - From: Number Field in c with defining polynomial x^2 + 5 over its base field - To: Number Field in e with defining polynomial x^8 - 24*x^6 + 464*x^4 + 3840*x^2 + 25600 - Defn: c |--> -9/66560*e^7 + 11/4160*e^5 - 241/4160*e^3 - 101/104*e - d |--> -3/25600*e^7 + 7/1600*e^5 - 147/1600*e^3 + 1/40*e, + From: Number Field in c with defining polynomial x^2 + 5 over its base field + To: Number Field in e with defining polynomial + x^8 - 24*x^6 + 464*x^4 + 3840*x^2 + 25600 + Defn: c |--> -9/66560*e^7 + 11/4160*e^5 - 241/4160*e^3 - 101/104*e + d |--> -3/25600*e^7 + 7/1600*e^5 - 147/1600*e^3 + 1/40*e, None]] """ if not isinstance(other, NumberField_generic): @@ -674,7 +699,8 @@ def degree(self): sage: K.degree() Traceback (most recent call last): ... - NotImplementedError: For a relative number field you must use relative_degree or absolute_degree as appropriate + NotImplementedError: For a relative number field + you must use relative_degree or absolute_degree as appropriate """ raise NotImplementedError("For a relative number field you must use relative_degree or absolute_degree as appropriate") @@ -1127,23 +1153,25 @@ def _pari_base_nf(self): def is_galois(self): r""" - For a relative number field, ``is_galois()`` is deliberately not + For a relative number field, :meth:`is_galois` is deliberately not implemented, since it is not clear whether this would mean "Galois over - `\QQ`" or "Galois over the given base field". Use either ``is_galois_absolute()`` or ``is_galois_relative()`` respectively. + `\QQ`" or "Galois over the given base field". + Use either :meth:`is_galois_absolute` or :meth:`is_galois_relative`, respectively. EXAMPLES:: - sage: k. =NumberField([x^3 - 2, x^2 + x + 1]) + sage: k. = NumberField([x^3 - 2, x^2 + x + 1]) sage: k.is_galois() Traceback (most recent call last): ... - NotImplementedError: For a relative number field L you must use either L.is_galois_relative() or L.is_galois_absolute() as appropriate + NotImplementedError: For a relative number field L you must use + either L.is_galois_relative() or L.is_galois_absolute() as appropriate """ raise NotImplementedError("For a relative number field L you must use either L.is_galois_relative() or L.is_galois_absolute() as appropriate") def is_galois_relative(self): r""" - Return True if for this relative extension `L/K`, `L` is a + Return ``True`` if for this relative extension `L/K`, `L` is a Galois extension of `K`. EXAMPLES:: @@ -1172,7 +1200,7 @@ def is_galois_relative(self): def is_galois_absolute(self): r""" - Return True if for this relative extension `L/K`, `L` is a Galois extension of `\QQ`. + Return ``True`` if for this relative extension `L/K`, `L` is a Galois extension of `\QQ`. EXAMPLES:: @@ -1187,7 +1215,7 @@ def is_galois_absolute(self): def is_isomorphic_relative(self, other, base_isom=None): r""" - For this relative extension `L/K` and another relative extension `M/K`, return True + For this relative extension `L/K` and another relative extension `M/K`, return ``True`` if there is a `K`-linear isomorphism from `L` to `M`. More generally, ``other`` can be a relative extension `M/K^\prime` with ``base_isom`` an isomorphism from `K` to `K^\prime`. @@ -1210,7 +1238,7 @@ def is_isomorphic_relative(self, other, base_isom=None): False If we have two extensions over different, but isomorphic, bases, we can compare them by - letting ``base_isom`` be an isomorphism from self's base field to other's base field:: + letting ``base_isom`` be an isomorphism from ``self``'s base field to ``other``'s base field:: sage: Kcyc. = CyclotomicField(9) sage: Rcyc. = PolynomialRing(Kcyc) @@ -1227,12 +1255,14 @@ def is_isomorphic_relative(self, other, base_isom=None): sage: L2.is_isomorphic_relative(L1cyc, base_isom=phi2) True - Omitting ``base_isom`` raises a ValueError when the base fields are not identical:: + Omitting ``base_isom`` raises a :class:`ValueError` when the base fields are not identical:: sage: L1.is_isomorphic_relative(L1cyc) Traceback (most recent call last): ... - ValueError: other does not have the same base field as self, so an isomorphism from self's base_field to other's base_field must be provided using the base_isom parameter. + ValueError: other does not have the same base field as self, + so an isomorphism from self's base_field to other's base_field + must be provided using the base_isom parameter. The parameter ``base_isom`` can also be used to check if the relative extensions are Galois conjugate:: @@ -1265,7 +1295,7 @@ def is_isomorphic_relative(self, other, base_isom=None): def is_CM_extension(self): """ - Return True is this is a CM extension, i.e. a totally imaginary + Return ``True`` is this is a CM extension, i.e. a totally imaginary quadratic extension of a totally real field. EXAMPLES:: @@ -1283,7 +1313,7 @@ def is_CM_extension(self): sage: K.is_CM_extension() False - A CM field K such that K/F is not a CM extension + A CM field `K` such that `K/F` is not a CM extension :: @@ -1362,8 +1392,8 @@ def free_module(self, base=None, basis=None, map=True): def relative_vector_space(self, base=None, *args, **kwds): """ - Return vector space over the base field of self and isomorphisms - from the vector space to self and in the other direction. + Return vector space over the base field of ``self`` and isomorphisms + from the vector space to ``self`` and in the other direction. EXAMPLES:: @@ -1425,7 +1455,7 @@ def absolute_vector_space(self, base=None, *args, **kwds): def vector_space(self, *args, **kwds): r""" - For a relative number field, ``vector_space()`` is + For a relative number field, :meth:`vector_space` is deliberately not implemented, so that a user cannot confuse :meth:`~relative_vector_space` with :meth:`~absolute_vector_space`. @@ -1435,7 +1465,8 @@ def vector_space(self, *args, **kwds): sage: K.vector_space() Traceback (most recent call last): ... - NotImplementedError: For a relative number field L you must use either L.relative_vector_space() or L.absolute_vector_space() as appropriate + NotImplementedError: For a relative number field L you must use either + L.relative_vector_space() or L.absolute_vector_space() as appropriate """ raise NotImplementedError("For a relative number field L you must use either L.relative_vector_space() or L.absolute_vector_space() as appropriate") @@ -1669,8 +1700,8 @@ def pari_relative_polynomial(self): Return the PARI relative polynomial associated to this number field. - This is always a polynomial in x and y, suitable for PARI's - rnfinit function. Notice that if this is a relative extension + This is always a polynomial in `x` and `y`, suitable for PARI's + :pari:`rnfinit` function. Notice that if this is a relative extension of a relative extension, the base field is the absolute base field. @@ -1690,8 +1721,8 @@ def pari_relative_polynomial(self): return self._pari_relative_structure()[0] def number_of_roots_of_unity(self): - """ - Return number of roots of unity in this relative field. + r""" + Return the number of roots of unity in this relative field. EXAMPLES:: @@ -1702,7 +1733,7 @@ def number_of_roots_of_unity(self): return self.absolute_field('a').number_of_roots_of_unity() def roots_of_unity(self): - """ + r""" Return all the roots of unity in this relative field, primitive or not. EXAMPLES:: @@ -1767,14 +1798,16 @@ def absolute_field(self, names): sage: from_L, to_L = L.structure() sage: from_L Isomorphism map: - From: Number Field in c with defining polynomial x^8 + 8*x^6 + 30*x^4 - 40*x^2 + 49 + From: Number Field in c with defining polynomial + x^8 + 8*x^6 + 30*x^4 - 40*x^2 + 49 To: Number Field in a with defining polynomial x^4 + 3 over its base field sage: from_L(c) a - b sage: to_L Isomorphism map: From: Number Field in a with defining polynomial x^4 + 3 over its base field - To: Number Field in c with defining polynomial x^8 + 8*x^6 + 30*x^4 - 40*x^2 + 49 + To: Number Field in c with defining polynomial + x^8 + 8*x^6 + 30*x^4 - 40*x^2 + 49 sage: to_L(a) -5/182*c^7 - 87/364*c^5 - 185/182*c^3 + 323/364*c sage: to_L(b) @@ -1860,7 +1893,7 @@ def relative_polynomial(self): sage: K.relative_polynomial() x^2 + x + 1 - Use absolute polynomial for a polynomial that defines the absolute + Use :meth:`absolute_polynomial` for a polynomial that defines the absolute extension.:: sage: K.absolute_polynomial() @@ -1872,7 +1905,7 @@ def defining_polynomial(self): """ Return the defining polynomial of this relative number field. - This is exactly the same as ``relative_polynomial()``. + This is exactly the same as :meth:`relative_polynomial`. EXAMPLES:: @@ -1887,7 +1920,7 @@ def defining_polynomial(self): def polynomial(self): """ - For a relative number field, ``polynomial()`` is deliberately + For a relative number field, :meth:`polynomial` is deliberately not implemented. Either :meth:`~relative_polynomial` or :meth:`~absolute_polynomial` must be used. @@ -1897,7 +1930,8 @@ def polynomial(self): sage: K.polynomial() Traceback (most recent call last): ... - NotImplementedError: For a relative number field L you must use either L.relative_polynomial() or L.absolute_polynomial() as appropriate + NotImplementedError: For a relative number field L you must use either + L.relative_polynomial() or L.absolute_polynomial() as appropriate """ raise NotImplementedError("For a relative number field L you must use either L.relative_polynomial() or L.absolute_polynomial() as appropriate") @@ -1953,7 +1987,7 @@ def embeddings(self, K): EXAMPLES:: - sage: K. = NumberField([x^3 - 2, x^2+1]) + sage: K. = NumberField([x^3 - 2, x^2 + 1]) sage: f = K.embeddings(ComplexField(58)); f [ Relative number field morphism: @@ -1995,8 +2029,8 @@ def embeddings(self, K): def automorphisms(self): r""" - Compute all Galois automorphisms of self over the base field. This is - different than computing the embeddings of self into self; there, + Compute all Galois automorphisms of ``self`` over the base field. This is + different from computing the embeddings of ``self`` into ``self``; there, automorphisms that do not fix the base field are considered. EXAMPLES:: @@ -2005,10 +2039,12 @@ def automorphisms(self): Number Field in a with defining polynomial x^2 + 10000 over its base field sage: K.automorphisms() [ - Relative number field endomorphism of Number Field in a with defining polynomial x^2 + 10000 over its base field + Relative number field endomorphism of Number Field in a + with defining polynomial x^2 + 10000 over its base field Defn: a |--> a b |--> b, - Relative number field endomorphism of Number Field in a with defining polynomial x^2 + 10000 over its base field + Relative number field endomorphism of Number Field in a + with defining polynomial x^2 + 10000 over its base field Defn: a |--> -a b |--> b ] @@ -2022,10 +2058,12 @@ def automorphisms(self): Number Field in b with defining polynomial x^2 + x + 50 over its base field sage: L.automorphisms() [ - Relative number field endomorphism of Number Field in b with defining polynomial x^2 + x + 50 over its base field + Relative number field endomorphism of Number Field in b + with defining polynomial x^2 + x + 50 over its base field Defn: b |--> b a |--> a, - Relative number field endomorphism of Number Field in b with defining polynomial x^2 + x + 50 over its base field + Relative number field endomorphism of Number Field in b + with defining polynomial x^2 + x + 50 over its base field Defn: b |--> -b - 1 a |--> a ] @@ -2041,11 +2079,13 @@ def automorphisms(self): sage: K. = F.extension(Y^2 - (1 + a)*(a + b)*a*b) sage: K.automorphisms() [ - Relative number field endomorphism of Number Field in c with defining polynomial Y^2 + (-2*b - 3)*a - 2*b - 6 over its base field + Relative number field endomorphism of Number Field in c + with defining polynomial Y^2 + (-2*b - 3)*a - 2*b - 6 over its base field Defn: c |--> c a |--> a b |--> b, - Relative number field endomorphism of Number Field in c with defining polynomial Y^2 + (-2*b - 3)*a - 2*b - 6 over its base field + Relative number field endomorphism of Number Field in c + with defining polynomial Y^2 + (-2*b - 3)*a - 2*b - 6 over its base field Defn: c |--> -c a |--> a b |--> b @@ -2083,7 +2123,7 @@ def logarithmic_embedding(self, prec=53): OUTPUT: - - the morphism of ``self`` under the logarithmic embedding in the category Set. + the morphism of ``self`` under the logarithmic embedding in the category Set. EXAMPLES:: @@ -2139,44 +2179,44 @@ def closure_map(x, prec=53): def places(self, all_complex=False, prec=None): """ - Return the collection of all infinite places of self. + Return the collection of all infinite places of ``self``. By default, this returns the set of real places as - homomorphisms into RIF first, followed by a choice of one of - each pair of complex conjugate homomorphisms into CIF. + homomorphisms into ``RIF`` first, followed by a choice of one of + each pair of complex conjugate homomorphisms into ``CIF``. - On the other hand, if prec is not None, we simply return places - into RealField(prec) and ComplexField(prec) (or RDF, CDF if - prec=53). + On the other hand, if ``prec`` is not ``None``, we simply return places + into ``RealField(prec)`` and ``ComplexField(prec)`` (or ``RDF``, ``CDF`` if + ``prec=53``). - There is an optional flag all_complex, which defaults to False. If - all_complex is True, then the real embeddings are returned as - embeddings into CIF instead of RIF. + There is an optional flag ``all_complex``, which defaults to ``False``. If + ``all_complex`` is ``True``, then the real embeddings are returned as + embeddings into ``CIF`` instead of ``RIF``. EXAMPLES:: sage: L. = NumberFieldTower([x^2 - 5, x^3 + x + 3]) sage: L.places() [Relative number field morphism: - From: Number Field in b with defining polynomial x^2 - 5 over its base field - To: Real Field with 106 bits of precision - Defn: b |--> -2.236067977499789696409173668937 - c |--> -1.213411662762229634132131377426, - Relative number field morphism: - From: Number Field in b with defining polynomial x^2 - 5 over its base field - To: Real Field with 106 bits of precision - Defn: b |--> 2.236067977499789696411548005367 - c |--> -1.213411662762229634130492421800, - Relative number field morphism: - From: Number Field in b with defining polynomial x^2 - 5 over its base field - To: Complex Field with 53 bits of precision - Defn: b |--> -2.23606797749979 ...e-1...*I - c |--> 0.606705831381... - 1.45061224918844*I, - Relative number field morphism: - From: Number Field in b with defining polynomial x^2 - 5 over its base field - To: Complex Field with 53 bits of precision - Defn: b |--> 2.23606797749979 - 4.44089209850063e-16*I - c |--> 0.606705831381115 - 1.45061224918844*I] + From: Number Field in b with defining polynomial x^2 - 5 over its base field + To: Real Field with 106 bits of precision + Defn: b |--> -2.236067977499789696409173668937 + c |--> -1.213411662762229634132131377426, + Relative number field morphism: + From: Number Field in b with defining polynomial x^2 - 5 over its base field + To: Real Field with 106 bits of precision + Defn: b |--> 2.236067977499789696411548005367 + c |--> -1.213411662762229634130492421800, + Relative number field morphism: + From: Number Field in b with defining polynomial x^2 - 5 over its base field + To: Complex Field with 53 bits of precision + Defn: b |--> -2.23606797749979 ...e-1...*I + c |--> 0.606705831381... - 1.45061224918844*I, + Relative number field morphism: + From: Number Field in b with defining polynomial x^2 - 5 over its base field + To: Complex Field with 53 bits of precision + Defn: b |--> 2.23606797749979 - 4.44089209850063e-16*I + c |--> 0.606705831381115 - 1.45061224918844*I] """ L = self.absolute_field('a') pl = L.places(all_complex, prec) @@ -2186,7 +2226,7 @@ def absolute_different(self): r""" Return the absolute different of this relative number field `L`, as an ideal of `L`. To get the relative different of `L/K`, use - ``L.relative_different()``. + :meth:`relative_different`. EXAMPLES:: @@ -2204,7 +2244,7 @@ def relative_different(self): r""" Return the relative different of this extension `L/K` as an ideal of `L`. If you want the absolute different of - `L/\QQ`, use ``L.absolute_different()``. + `L/\QQ`, use :meth:`absolute_different`. EXAMPLES:: @@ -2230,7 +2270,8 @@ def different(self): sage: K.different() Traceback (most recent call last): ... - NotImplementedError: For a relative number field you must use relative_different or absolute_different as appropriate + NotImplementedError: For a relative number field you must use + relative_different or absolute_different as appropriate """ raise NotImplementedError("For a relative number field you must use relative_different or absolute_different as appropriate") @@ -2309,7 +2350,8 @@ def discriminant(self): sage: K.discriminant() Traceback (most recent call last): ... - NotImplementedError: For a relative number field you must use relative_discriminant or absolute_discriminant as appropriate + NotImplementedError: For a relative number field you must use + relative_discriminant or absolute_discriminant as appropriate """ raise NotImplementedError("For a relative number field you must use relative_discriminant or absolute_discriminant as appropriate") @@ -2325,7 +2367,8 @@ def disc(self): sage: K.disc() Traceback (most recent call last): ... - NotImplementedError: For a relative number field you must use relative_discriminant or absolute_discriminant as appropriate + NotImplementedError: For a relative number field you must use + relative_discriminant or absolute_discriminant as appropriate """ raise NotImplementedError("For a relative number field you must use relative_discriminant or absolute_discriminant as appropriate") @@ -2336,25 +2379,26 @@ def order(self, *gens, **kwds): INPUT: - - ``gens`` -- list of elements of self; if no generators are given, just - returns the cardinality of this number field (oo) for consistency. - - ``check_is_integral`` -- bool (default: True), whether to check that each + - ``gens`` -- list of elements of ``self``; if no generators are given, just + returns the cardinality of this number field (`\infty`) for consistency. + - ``check_is_integral`` -- bool (default: ``True``), whether to check that each generator is integral. - - ``check_rank`` -- bool (default: True), whether to check that the ring - generated by gens is of full rank. - - ``allow_subfield`` -- bool (default: False), if True and the generators + - ``check_rank`` -- bool (default: ``True``), whether to check that the ring + generated by ``gens`` is of full rank. + - ``allow_subfield`` -- bool (default: ``False``), if ``True`` and the generators do not generate an order, i.e., they generate a subring of smaller rank, instead of raising an error, return an order in a smaller number field. - The check_is_integral and check_rank inputs must be given as + The ``check_is_integral`` and ``check_rank`` inputs must be given as explicit keyword arguments. EXAMPLES:: sage: P. = QQ[2^(1/2), 2^(1/3), 3^(1/2)] sage: R = P.order([a,b,c]); R - Relative Order in Number Field in sqrt2 with defining polynomial x^2 - 2 over its base field + Relative Order in Number Field in sqrt2 + with defining polynomial x^2 - 2 over its base field The base ring of an order in a relative extension is still `\ZZ`.:: @@ -2364,7 +2408,7 @@ def order(self, *gens, **kwds): One must give enough generators to generate a ring of finite index in the maximal order:: - sage: P.order([a,b]) + sage: P.order([a, b]) Traceback (most recent call last): ... ValueError: the rank of the span of gens is wrong @@ -2389,7 +2433,7 @@ def is_free(self, proof=None): EXAMPLES:: sage: x = polygen(QQ) - sage: K. = NumberField(x^2+6) + sage: K. = NumberField(x^2 + 6) sage: x = polygen(K) sage: L. = K.extension(x^2 + 3) # extend by x^2+3 sage: L.is_free() @@ -2424,7 +2468,7 @@ def _factor_univariate_polynomial(self, poly, **kwargs): def lift_to_base(self, element): """ Lift an element of this extension into the base field if possible, - or raise a ValueError if it is not possible. + or raise a :class:`ValueError` if it is not possible. EXAMPLES:: @@ -2474,21 +2518,21 @@ def lift_to_base(self, element): def relativize(self, alpha, names): r""" - Given an element in self or an embedding of a subfield into self, - return a relative number field `K` isomorphic to self that is relative + Given an element in ``self`` or an embedding of a subfield into ``self``, + return a relative number field `K` isomorphic to ``self`` that is relative over the absolute field `\QQ(\alpha)` or the domain of `\alpha`, along - with isomorphisms from `K` to self and from self to `K`. + with isomorphisms from `K` to ``self`` and from ``self`` to `K`. INPUT: - - ``alpha`` -- an element of self, or an embedding of a subfield into self + - ``alpha`` -- an element of ``self``, or an embedding of a subfield into ``self`` - ``names`` -- name of generator for output field `K`. OUTPUT: `K` -- a relative number field Also, ``K.structure()`` returns ``from_K`` and ``to_K``, where - ``from_K`` is an isomorphism from `K` to self and ``to_K`` is - an isomorphism from self to `K`. + ``from_K`` is an isomorphism from `K` to ``self`` and ``to_K`` is + an isomorphism from ``self`` to `K`. EXAMPLES:: @@ -2500,7 +2544,8 @@ def relativize(self, alpha, names): sage: w^2 -3 sage: L - Number Field in z with defining polynomial x^4 + (-2*w + 4)*x^2 + 4*w + 1 over its base field + Number Field in z with defining polynomial + x^4 + (-2*w + 4)*x^2 + 4*w + 1 over its base field sage: L.base_field() Number Field in w with defining polynomial x^2 + 3 @@ -2517,7 +2562,8 @@ def relativize(self, alpha, names): sage: L_over_K = L.relativize(K_into_L, 'c'); L_over_K Number Field in c with defining polynomial x^2 + a0_0 over its base field sage: L_over_K_to_L, L_to_L_over_K = L_over_K.structure() - sage: M_over_L_over_K = M.relativize(L_into_M * L_over_K_to_L, 'd'); M_over_L_over_K + sage: M_over_L_over_K = M.relativize(L_into_M * L_over_K_to_L, 'd') + sage: M_over_L_over_K Number Field in d with defining polynomial x^2 + c over its base field sage: M_over_L_over_K.base_field() is L_over_K True @@ -2567,25 +2613,24 @@ def relativize(self, alpha, names): def uniformizer(self, P, others = "positive"): """ - Returns an element of self with valuation 1 at the prime ideal P. + Returns an element of ``self`` with valuation 1 at the prime ideal `P`. INPUT: + - ``self`` -- a number field - - ``self`` - a number field - - - ``P`` - a prime ideal of self + - ``P`` -- a prime ideal of ``self`` - - ``others`` - either "positive" (default), in which + - ``others`` -- either ``"positive"`` (default), in which case the element will have non-negative valuation at all other - primes of self, or "negative", in which case the element will have - non-positive valuation at all other primes of self. + primes of ``self``, or ``"negative"``, in which case the element will have + non-positive valuation at all other primes of ``self``. .. note:: - When P is principal (e.g. always when self has class number - one) the result may or may not be a generator of P! + When `P` is principal (e.g., always when ``self`` has class number + one), the result may or may not be a generator of `P`! EXAMPLES:: diff --git a/src/sage/rings/number_field/order.py b/src/sage/rings/number_field/order.py index 288e4dc83c5..5dff61c7f68 100644 --- a/src/sage/rings/number_field/order.py +++ b/src/sage/rings/number_field/order.py @@ -16,7 +16,7 @@ We compute a basis for an order in a relative extension that is generated by 2 elements:: - sage: K. = NumberField([x^2 + 1, x^2 - 3]); O = K.order([3*a,2*b]) + sage: K. = NumberField([x^2 + 1, x^2 - 3]); O = K.order([3*a, 2*b]) sage: O.basis() [1, 3*a - 2*b, -6*b*a + 6, 3*a] @@ -24,12 +24,14 @@ sage: K. = NumberField((x+1)^10 + 17) sage: K.maximal_order() - Maximal Order in Number Field in a with defining polynomial x^10 + 10*x^9 + 45*x^8 + 120*x^7 + 210*x^6 + 252*x^5 + 210*x^4 + 120*x^3 + 45*x^2 + 10*x + 18 + Maximal Order in Number Field in a with defining polynomial x^10 + 10*x^9 + + 45*x^8 + 120*x^7 + 210*x^6 + 252*x^5 + 210*x^4 + 120*x^3 + 45*x^2 + 10*x + 18 We compute a suborder, which has index a power of 17 in the maximal order:: sage: O = K.order(17*a); O - Order in Number Field in a with defining polynomial x^10 + 10*x^9 + 45*x^8 + 120*x^7 + 210*x^6 + 252*x^5 + 210*x^4 + 120*x^3 + 45*x^2 + 10*x + 18 + Order in Number Field in a with defining polynomial x^10 + 10*x^9 + + 45*x^8 + 120*x^7 + 210*x^6 + 252*x^5 + 210*x^4 + 120*x^3 + 45*x^2 + 10*x + 18 sage: m = O.index_in(K.maximal_order()); m 23453165165327788911665591944416226304630809183732482257 sage: factor(m) @@ -262,7 +264,8 @@ class RelativeOrderFactory(OrderFactory): sage: R. = K[] sage: L. = K.extension(j^2 - 2) sage: L.order([i, j]) - Relative Order in Number Field in j with defining polynomial j^2 - 2 over its base field + Relative Order in Number Field in j + with defining polynomial j^2 - 2 over its base field """ @@ -321,7 +324,7 @@ def create_object(self, version, key, is_maximal=None, is_maximal_at=()): def is_NumberFieldOrder(R): r""" - Return True if R is either an order in a number field or is the ring `\ZZ` of integers. + Return ``True`` if `R` is either an order in a number field or is the ring `\ZZ` of integers. EXAMPLES:: @@ -341,7 +344,7 @@ def is_NumberFieldOrder(R): def EquationOrder(f, names, **kwds): r""" Return the equation order generated by a root of the irreducible - polynomial f or list of polynomials `f` (to construct a relative + polynomial `f` or list ``f`` of polynomials (to construct a relative equation order). IMPORTANT: Note that the generators of the returned order need @@ -350,9 +353,10 @@ def EquationOrder(f, names, **kwds): EXAMPLES:: - sage: O. = EquationOrder([x^2+1, x^2+2]) + sage: O. = EquationOrder([x^2 + 1, x^2 + 2]) sage: O - Relative Order in Number Field in a with defining polynomial x^2 + 1 over its base field + Relative Order in Number Field in a + with defining polynomial x^2 + 1 over its base field sage: O.0 -b*a - 1 sage: O.1 @@ -365,7 +369,7 @@ def EquationOrder(f, names, **kwds): ... ValueError: each generator must be integral - sage: R = EquationOrder( [x^3 + x + 1, x^2 + 1/2], 'alpha'); R + sage: R = EquationOrder([x^3 + x + 1, x^2 + 1/2], 'alpha'); R Traceback (most recent call last): ... ValueError: each generator must be integral @@ -468,7 +472,8 @@ def ideal(self, *args, **kwds): sage: R.ideal(2/3 + 7*a, a) Traceback (most recent call last): ... - ValueError: ideal must be integral; use fractional_ideal to create a non-integral ideal. + ValueError: ideal must be integral; + use fractional_ideal to create a non-integral ideal. sage: R.ideal(7*a, 77 + 28*a) Fractional ideal (7) sage: R = K.order(4*a) @@ -589,7 +594,7 @@ def is_noetherian(self): return True def is_integrally_closed(self): - """ + r""" Return ``True`` if this ring is integrally closed, i.e., is equal to the maximal order. @@ -609,7 +614,7 @@ def is_integrally_closed(self): return self.is_maximal() def krull_dimension(self): - """ + r""" Return the Krull dimension of this order, which is 1. EXAMPLES:: @@ -625,16 +630,18 @@ def krull_dimension(self): return ZZ(1) def integral_closure(self): - """ + r""" Return the integral closure of this order. EXAMPLES:: sage: K. = QuadraticField(5) sage: O2 = K.order(2*a); O2 - Order in Number Field in a with defining polynomial x^2 - 5 with a = 2.236067977499790? + Order in Number Field in a with defining polynomial x^2 - 5 + with a = 2.236067977499790? sage: O2.integral_closure() - Maximal Order in Number Field in a with defining polynomial x^2 - 5 with a = 2.236067977499790? + Maximal Order in Number Field in a with defining polynomial x^2 - 5 + with a = 2.236067977499790? sage: OK = K.maximal_order() sage: OK is OK.integral_closure() True @@ -674,7 +681,7 @@ def gen(self, i): return self.basis()[i] def ngens(self): - """ + r""" Return the number of module generators of this order. EXAMPLES:: @@ -722,7 +729,7 @@ def coordinates(self, x): Uses linear algebra. The change-of-basis matrix is cached. Provides simpler implementations for - ``_contains_()``, ``is_integral()`` and ``smallest_integer()``. + :meth:`_contains_`, :meth:`is_integral` and :meth:`smallest_integer`. EXAMPLES:: @@ -779,7 +786,7 @@ def free_module(self): [ 0 0 1] An example in a relative extension. Notice that the module is - a `\ZZ`-module in the absolute_field associated to the relative + a `\ZZ`-module in the absolute field associated to the relative field:: sage: K. = NumberField([x^2 + 1, x^2 + 2]) @@ -805,7 +812,7 @@ def free_module(self): @cached_method def ring_generators(self): """ - Return generators for self as a ring. + Return generators for ``self`` as a ring. EXAMPLES:: @@ -829,7 +836,9 @@ def ring_generators(self): sage: K. = NumberField([x^2 + x + 1, x^3 - 3]) sage: O = K.maximal_order() sage: O.ring_generators() - [(-5/3*b^2 + 3*b - 2)*a - 7/3*b^2 + b + 3, (-5*b^2 - 9)*a - 5*b^2 - b, (-6*b^2 - 11)*a - 6*b^2 - b] + [(-5/3*b^2 + 3*b - 2)*a - 7/3*b^2 + b + 3, + (-5*b^2 - 9)*a - 5*b^2 - b, + (-6*b^2 - 11)*a - 6*b^2 - b] """ K = self._K n = [] @@ -868,8 +877,8 @@ def _defining_names(self): def zeta(self, n=2, all=False): r""" - Return a primitive n-th root of unity in this order, if it - contains one. If all is True, return all of them. + Return a primitive `n`-th root of unity in this order, if it + contains one. If ``all`` is ``True``, return all of them. EXAMPLES:: @@ -915,10 +924,10 @@ def number_field(self): def ambient(self): r""" - Return the ambient number field that contains self. + Return the ambient number field that contains ``self``. - This is the same as ``self.number_field()`` and - ``self.fraction_field()`` + This is the same as :meth:`number_field` and + :meth:`fraction_field` EXAMPLES:: @@ -935,12 +944,12 @@ def ambient(self): def residue_field(self, prime, names=None, check=False): """ - Return the residue field of this order at a given prime, ie `O/pO`. + Return the residue field of this order at a given prime, i.e., `O/pO`. INPUT: - ``prime`` -- a prime ideal of the maximal order in this number field. - - ``names`` -- the name of the variable in the residue field + - ``names`` -- the name of the variable in the residue field. - ``check`` -- whether or not to check the primality of prime. OUTPUT: @@ -950,7 +959,7 @@ def residue_field(self, prime, names=None, check=False): EXAMPLES:: sage: R. = QQ[] - sage: K. = NumberField(x^4+3*x^2-17) + sage: K. = NumberField(x^4 + 3*x^2 - 17) sage: P = K.ideal(61).factor()[0][0] sage: OK = K.maximal_order() sage: OK.residue_field(P) @@ -1002,7 +1011,7 @@ def rank(self): `\ZZ`-module, or the degree of the ambient number field that contains this order. - This is a synonym for ``degree()``. + This is a synonym for :meth:`degree`. EXAMPLES:: @@ -1036,7 +1045,8 @@ def class_number(self, proof=None): sage: ZZ[11*2^(1/3)].class_number() Traceback (most recent call last): ... - NotImplementedError: computation of class numbers of non-maximal orders not in quadratic fields is not implemented + NotImplementedError: computation of class numbers of non-maximal orders + not in quadratic fields is not implemented """ if not self.is_maximal(): @@ -1058,7 +1068,8 @@ def class_group(self, proof=None, names='c'): sage: O = k.maximal_order(); O Maximal Order in Number Field in a with defining polynomial x^2 + 5077 sage: O.class_group() - Class group of order 22 with structure C22 of Number Field in a with defining polynomial x^2 + 5077 + Class group of order 22 with structure C22 of + Number Field in a with defining polynomial x^2 + 5077 """ if self.is_maximal(): return self.number_field().class_group(proof=proof, names=names) @@ -1067,8 +1078,8 @@ def class_group(self, proof=None, names='c'): def is_suborder(self, other): """ - Return True if self and other are both orders in the - same ambient number field and self is a subset of other. + Return ``True`` if ``self`` and ``other`` are both orders in the + same ambient number field and ``self`` is a subset of ``other``. EXAMPLES:: @@ -1088,13 +1099,13 @@ def is_suborder(self, other): sage: W2. = NumberField(x^2 + 1) sage: P5 = W2.order(5*j) - This is False because the ambient number fields are not equal.:: + This is ``False`` because the ambient number fields are not equal.:: sage: O5.is_suborder(P5) False - We create a field that contains (in no natural way!) W, - and of course again is_suborder returns False:: + We create a field that contains (in no natural way!) `W`, + and of course again :meth:`is_suborder` returns False:: sage: K. = NumberField(x^4 + 1) sage: M = K.order(5*z) @@ -1250,7 +1261,8 @@ def random_element(self, *args, **kwds): sage: K. = CyclotomicField(17) sage: OK = K.ring_of_integers() sage: OK.random_element() # random output - z^15 - z^11 - z^10 - 4*z^9 + z^8 + 2*z^7 + z^6 - 2*z^5 - z^4 - 445*z^3 - 2*z^2 - 15*z - 2 + z^15 - z^11 - z^10 - 4*z^9 + z^8 + 2*z^7 + z^6 + - 2*z^5 - z^4 - 445*z^3 - 2*z^2 - 15*z - 2 sage: OK.random_element().is_integral() True sage: OK.random_element().parent() is OK @@ -1287,7 +1299,7 @@ def random_element(self, *args, **kwds): def absolute_degree(self): r""" - Return the absolute degree of this order, ie the degree of this order over `\ZZ`. + Return the absolute degree of this order, i.e., the degree of this order over `\ZZ`. EXAMPLES:: @@ -1300,11 +1312,11 @@ def absolute_degree(self): def valuation(self, p): r""" - Return the ``p``-adic valuation on this order. + Return the `p`-adic valuation on this order. EXAMPLES: - The valuation can be specified with an integer ``prime`` that is + The valuation can be specified with an integer prime `p` that is completely ramified or unramified:: sage: K. = NumberField(x^2 + 1) @@ -1320,12 +1332,13 @@ def valuation(self, p): sage: GaussianIntegers().valuation(3) 3-adic valuation - A ``prime`` that factors into pairwise distinct factors, results in an error:: + A prime `p` that factors into pairwise distinct factors, results in an error:: sage: GaussianIntegers().valuation(5) Traceback (most recent call last): ... - ValueError: The valuation Gauss valuation induced by 5-adic valuation does not approximate a unique extension of 5-adic valuation with respect to x^2 + 1 + ValueError: The valuation Gauss valuation induced by 5-adic valuation does not + approximate a unique extension of 5-adic valuation with respect to x^2 + 1 The valuation can also be selected by giving a valuation on the base ring that extends uniquely:: @@ -1338,15 +1351,17 @@ def valuation(self, p): sage: GaussianIntegers().valuation(ZZ.valuation(5)) Traceback (most recent call last): ... - ValueError: The valuation Gauss valuation induced by 5-adic valuation does not approximate a unique extension of 5-adic valuation with respect to x^2 + 1 + ValueError: The valuation Gauss valuation induced by 5-adic valuation does not + approximate a unique extension of 5-adic valuation with respect to x^2 + 1 If the fraction field is of the form `K[x]/(G)`, you can specify a valuation by providing a discrete pseudo-valuation on `K[x]` which sends `G` to infinity:: sage: R. = QQ[] - sage: v = GaussianIntegers().valuation(GaussValuation(R, QQ.valuation(5)).augmentation(x + 2, infinity)) - sage: w = GaussianIntegers().valuation(GaussValuation(R, QQ.valuation(5)).augmentation(x + 1/2, infinity)) + sage: GV5 = GaussValuation(R, QQ.valuation(5)) + sage: v = GaussianIntegers().valuation(GV5.augmentation(x + 2, infinity)) + sage: w = GaussianIntegers().valuation(GV5.augmentation(x + 1/2, infinity)) sage: v == w False @@ -1441,7 +1456,7 @@ def __init__(self, K, module_rep): sage: from sage.rings.number_field.order import * sage: x = polygen(QQ) - sage: K. = NumberField(x^3+2) + sage: K. = NumberField(x^3 + 2) sage: V, from_v, to_v = K.vector_space() sage: M = span([to_v(a^2), to_v(a), to_v(1)],ZZ) sage: O = AbsoluteOrder(K, M); O @@ -1665,7 +1680,7 @@ def is_maximal(self, p=None): INPUT: - ``p`` -- an integer prime or ``None`` (default: ``None``); if - set, return whether this order is maximal at the prime ``p``. + set, return whether this order is maximal at the prime `p`. EXAMPLES:: @@ -1694,7 +1709,7 @@ def is_maximal(self, p=None): An example involving a relative order:: sage: K. = NumberField([x^2 + 1, x^2 - 3]) - sage: O = K.order([3*a,2*b]) + sage: O = K.order([3*a, 2*b]) sage: O.is_maximal() False @@ -1886,10 +1901,10 @@ def change_names(self, names): def index_in(self, other): """ - Return the index of self in other. + Return the index of ``self`` in ``other``. This is a lattice index, - so it is a rational number if self is not contained in other. + so it is a rational number if ``self`` is not contained in ``other``. INPUT: @@ -2061,7 +2076,7 @@ class Order_relative(Order): """ A relative order in a number field. - A relative order is an order in some relative number field + A relative order is an order in some relative number field. Invariants of this order may be computed with respect to the contained order. @@ -2163,7 +2178,8 @@ def absolute_order(self, names='z'): EXAMPLES:: sage: R = EquationOrder([x^2 + 1, x^2 - 5], 'i,g'); R - Relative Order in Number Field in i with defining polynomial x^2 + 1 over its base field + Relative Order in Number Field in i + with defining polynomial x^2 + 1 over its base field sage: R.basis() [1, 6*i - g, -g*i + 2, 7*i - g] @@ -2173,11 +2189,12 @@ def absolute_order(self, names='z'): [1, 5/12*z^3 + 1/6*z, 1/2*z^2, 1/2*z^3] We compute a relative order in alpha0, alpha1, then make the - number field that contains the absolute order be called + generator of the number field that contains the absolute order be called gamma.:: - sage: R = EquationOrder( [x^2 + 2, x^2 - 3], 'alpha'); R - Relative Order in Number Field in alpha0 with defining polynomial x^2 + 2 over its base field + sage: R = EquationOrder([x^2 + 2, x^2 - 3], 'alpha'); R + Relative Order in Number Field in alpha0 + with defining polynomial x^2 + 2 over its base field sage: R.absolute_order('gamma') Order in Number Field in gamma with defining polynomial x^4 - 2*x^2 + 25 sage: R.absolute_order('gamma').basis() @@ -2294,7 +2311,7 @@ def is_maximal(self, p=None): INPUT: - ``p`` -- an integer prime or ``None`` (default: ``None``); if - set, return whether this order is maximal at the prime ``p``. + set, return whether this order is maximal at the prime `p`. EXAMPLES:: @@ -2425,8 +2442,8 @@ def _assume_maximal(self, is_maximal=True, p=None): def absolute_discriminant(self): """ - Return the absolute discriminant of self, which is the discriminant - of the absolute order associated to self. + Return the absolute discriminant of ``self``, which is the discriminant + of the absolute order associated to ``self``. OUTPUT: @@ -2446,13 +2463,13 @@ def absolute_discriminant(self): def is_suborder(self, other): """ - Return True if self is a subset of the order other. + Return ``True`` if ``self`` is a subset of the order ``other``. EXAMPLES:: sage: K. = NumberField([x^2 + 1, x^3 + 2]) - sage: R1 = K.order([a,b]) - sage: R2 = K.order([2*a,b]) + sage: R1 = K.order([a, b]) + sage: R2 = K.order([2*a, b]) sage: R3 = K.order([a + b, b + 2*a]) sage: R1.is_suborder(R2) False @@ -2469,10 +2486,10 @@ def is_suborder(self, other): def index_in(self, other): """ - Return the index of self in other. + Return the index of ``self`` in ``other``. This is a lattice index, - so it is a rational number if self is not contained in other. + so it is a rational number if ``self`` is not contained in ``other``. INPUT: @@ -2521,13 +2538,13 @@ def absolute_order_from_ring_generators(gens, check_is_integral=True, INPUT: - ``gens`` -- list of integral elements of an absolute order. - - ``check_is_integral`` -- bool (default: True), whether to check that each + - ``check_is_integral`` -- bool (default: ``True``), whether to check that each generator is integral. - - ``check_rank`` -- bool (default: True), whether to check that the ring - generated by gens is of full rank. - - ``is_maximal`` -- bool (or None); set if maximality of the generated order is + - ``check_rank`` -- bool (default: ``True``), whether to check that the ring + generated by ``gens`` is of full rank. + - ``is_maximal`` -- bool (or ``None``); set if maximality of the generated order is known - - ``allow_subfield`` -- bool (default: False), if True and the generators do + - ``allow_subfield`` -- bool (default: ``False``), if ``True`` and the generators do not generate an order, i.e., they generate a subring of smaller rank, instead of raising an error, return an order in a smaller number field. @@ -2543,7 +2560,7 @@ def absolute_order_from_ring_generators(gens, check_is_integral=True, sage: from sage.rings.number_field.order import absolute_order_from_ring_generators sage: absolute_order_from_ring_generators([a]) Order in Number Field in a with defining polynomial x^4 - 5 - sage: absolute_order_from_ring_generators([3*a, 2, 6*a+1]) + sage: absolute_order_from_ring_generators([3*a, 2, 6*a + 1]) Order in Number Field in a with defining polynomial x^4 - 5 If one of the inputs is non-integral, it is an error.:: @@ -2553,7 +2570,7 @@ def absolute_order_from_ring_generators(gens, check_is_integral=True, ... ValueError: each generator must be integral - If the gens do not generate an order, i.e., generate a ring of full + If the ``gens`` do not generate an order, i.e., generate a ring of full rank, then it is an error.:: sage: absolute_order_from_ring_generators([a^2]) @@ -2587,16 +2604,16 @@ def absolute_order_from_module_generators(gens, check_integral=True, check_rank=True, check_is_ring=True, is_maximal=None, allow_subfield=False, is_maximal_at=()): - """ + r""" INPUT: - ``gens`` -- list of elements of an absolute number field that generates an - order in that number field as a ZZ *module*. - - ``check_integral`` -- check that each gen is integral - - ``check_rank`` -- check that the gens span a module of the correct rank + order in that number field as a `\ZZ`-*module*. + - ``check_integral`` -- check that each generator is integral + - ``check_rank`` -- check that the ``gens`` span a module of the correct rank - ``check_is_ring`` -- check that the module is closed under multiplication (this is very expensive) - - ``is_maximal`` -- bool (or None); set if maximality of the generated order is known + - ``is_maximal`` -- bool (or ``None``); set if maximality of the generated order is known - ``is_maximal_at`` -- a tuple of primes where this order is known to be maximal OUTPUT: @@ -2641,11 +2658,13 @@ def absolute_order_from_module_generators(gens, off various check flags:: sage: k. = NumberField(x^2 + 1) - sage: R = absolute_order_from_module_generators([2, 2*i], check_is_ring=False); R + sage: R = absolute_order_from_module_generators([2, 2*i], + ....: check_is_ring=False); R Order in Number Field in i with defining polynomial x^2 + 1 sage: R.basis() [2, 2*i] - sage: R = absolute_order_from_module_generators([k(1)], check_rank=False); R + sage: R = absolute_order_from_module_generators([k(1)], + ....: check_rank=False); R Order in Number Field in i with defining polynomial x^2 + 1 sage: R.basis() [1] @@ -2654,25 +2673,31 @@ def absolute_order_from_module_generators(gens, that, we will find that the rank is wrong or that the order is not closed under multiplication:: - sage: absolute_order_from_module_generators([1/2, i], check_integral=False) + sage: absolute_order_from_module_generators([1/2, i], + ....: check_integral=False) Traceback (most recent call last): ... ValueError: the module span of the gens is not closed under multiplication. - sage: R = absolute_order_from_module_generators([1/2, i], check_is_ring=False, check_integral=False); R + sage: R = absolute_order_from_module_generators([1/2, i], + ....: check_is_ring=False, + ....: check_integral=False); R Order in Number Field in i with defining polynomial x^2 + 1 sage: R.basis() [1/2, i] We turn off all check flags and make a really messed up order:: - sage: R = absolute_order_from_module_generators([1/2, i], check_is_ring=False, check_integral=False, check_rank=False); R + sage: R = absolute_order_from_module_generators([1/2, i], + ....: check_is_ring=False, + ....: check_integral=False, + ....: check_rank=False); R Order in Number Field in i with defining polynomial x^2 + 1 sage: R.basis() [1/2, i] An order that lives in a subfield:: - sage: F. = NumberField(x**4+3) + sage: F. = NumberField(x**4 + 3) sage: F.order([alpha**2], allow_subfield=True) Order in Number Field in beta with defining polynomial ... with beta = ... """ @@ -2733,12 +2758,12 @@ def relative_order_from_ring_generators(gens, INPUT: - ``gens`` -- list of integral elements of an absolute order. - - ``check_is_integral`` -- bool (default: True), whether to check that each + - ``check_is_integral`` -- bool (default: ``True``), whether to check that each generator is integral. - - ``check_rank`` -- bool (default: True), whether to check that the ring - generated by gens is of full rank. - - ``is_maximal`` -- bool (or None); set if maximality of the generated order is - known + - ``check_rank`` -- bool (default: ``True``), whether to check that the ring + generated by ``gens`` is of full rank. + - ``is_maximal`` -- bool (or ``None``); set if maximality of the generated order is + known. EXAMPLES: @@ -2749,7 +2774,8 @@ def relative_order_from_ring_generators(gens, sage: K. = NumberField([x^2 + 1, x^2 - 17]) sage: R = K.base_field().maximal_order() sage: S = relative_order_from_ring_generators([i,a]); S - Relative Order in Number Field in i with defining polynomial x^2 + 1 over its base field + Relative Order in Number Field in i + with defining polynomial x^2 + 1 over its base field Basis for the relative order, which is obtained by computing the algebra generated by i and a:: @@ -2816,13 +2842,14 @@ def EisensteinIntegers(names="omega"): This is the ring of all complex numbers of the form `a + b \omega` with `a` and `b` integers and - `omega = (-1 + \sqrt{-3})/2`. + `\omega = (-1 + \sqrt{-3})/2`. EXAMPLES:: sage: R. = EisensteinIntegers() sage: R - Eisenstein Integers in Number Field in omega with defining polynomial x^2 + x + 1 with omega = -0.50000000000000000? + 0.866025403784439?*I + Eisenstein Integers in Number Field in omega with defining polynomial x^2 + x + 1 + with omega = -0.50000000000000000? + 0.866025403784439?*I sage: factor(3 + omega) (-1) * (-omega - 3) sage: CC(omega) diff --git a/src/sage/rings/number_field/selmer_group.py b/src/sage/rings/number_field/selmer_group.py index 487550ef4d5..a80f1a66163 100644 --- a/src/sage/rings/number_field/selmer_group.py +++ b/src/sage/rings/number_field/selmer_group.py @@ -353,23 +353,23 @@ class is a ``p``'th power; def pSelmerGroup(K, S, p, proof=None, debug=False): r""" - Return the ``p``-Selmer group `K(S,p)` of the number field ``K`` - with respect to the prime ideals in ``S`` + Return the `p`-Selmer group `K(S,p)` of the number field `K` + with respect to the prime ideals in ``S``. INPUT: - - ``K`` (number field) -- a number field, or `\QQ`. + - ``K`` -- a number field or `\QQ`. - - ``S`` (list) -- a list of prime ideals in ``K``, or prime - numbers when ``K`` is `\QQ`. + - ``S`` -- a list of prime ideals in `K`, or prime + numbers when `K` is `\QQ`. - - ``p`` (prime) -- a prime number. + - ``p`` -- a prime number. - - ``proof`` - if True then compute the class group provably - correctly. Default is True. Call :meth:`proof.number_field` to + - ``proof`` -- if ``True``, compute the class group provably + correctly. Default is ``True``. Call :meth:`proof.number_field` to change this default globally. - - ``debug`` (boolean, default ``False``) -- debug flag. + - ``debug`` -- (boolean, default ``False``) debug flag. OUTPUT: diff --git a/src/sage/rings/number_field/small_primes_of_degree_one.py b/src/sage/rings/number_field/small_primes_of_degree_one.py index facd5207a1c..b5cb57bb2df 100644 --- a/src/sage/rings/number_field/small_primes_of_degree_one.py +++ b/src/sage/rings/number_field/small_primes_of_degree_one.py @@ -108,17 +108,17 @@ class Small_primes_of_degree_one_iter(): INPUT: - - ``field`` -- a ``NumberField``. + - ``field`` -- a :class:`NumberField`. - - ``num_integer_primes`` (default: 10000) -- an integer. We try to find + - ``num_integer_primes`` -- (default: 10000) an integer. We try to find primes of absolute norm no greater than the ``num_integer_primes``-th prime number. For example, if ``num_integer_primes`` is 2, the largest norm found will be 3, since the second prime is 3. - - ``max_iterations`` (default: 100) -- an integer. We test + - ``max_iterations`` -- (default: 100) an integer. We test ``max_iterations`` integers to find small primes before raising - ``StopIteration``. + :class:`StopIteration`. AUTHOR: diff --git a/src/sage/rings/number_field/structure.py b/src/sage/rings/number_field/structure.py index 52e6ed6d503..72091140d9a 100644 --- a/src/sage/rings/number_field/structure.py +++ b/src/sage/rings/number_field/structure.py @@ -14,8 +14,10 @@ identical because `M` carries additional information:: sage: L.structure() - (Identity endomorphism of Number Field in a with defining polynomial x^2 - 2 with a = 1.414213562373095?, - Identity endomorphism of Number Field in a with defining polynomial x^2 - 2 with a = 1.414213562373095?) + (Identity endomorphism of + Number Field in a with defining polynomial x^2 - 2 with a = 1.414213562373095?, + Identity endomorphism of + Number Field in a with defining polynomial x^2 - 2 with a = 1.414213562373095?) sage: M.structure() (Isomorphism given by variable name change map: From: Number Field in a with defining polynomial x^2 - 2 @@ -26,7 +28,7 @@ This used to cause trouble with caching and made (absolute) number fields not unique when they should have been. The underlying technical problem is that the -morphisms returned by ``structure()`` can only be defined once the fields in +morphisms returned by :meth:`structure` can only be defined once the fields in question have been created. Therefore, these morphisms cannot be part of a key which uniquely identifies a number field. @@ -72,7 +74,7 @@ class NumberFieldStructure(UniqueRepresentation): True sage: R. = QQ[] - sage: K. = NumberField(x^2+1) + sage: K. = NumberField(x^2 + 1) sage: L = K.change_names('j').change_names('i') sage: K is L # K and L differ in "structure", one is the "name-change" of the other False diff --git a/src/sage/rings/number_field/totallyreal.pyx b/src/sage/rings/number_field/totallyreal.pyx index ecb8236260c..ecd563fb3cf 100644 --- a/src/sage/rings/number_field/totallyreal.pyx +++ b/src/sage/rings/number_field/totallyreal.pyx @@ -45,7 +45,8 @@ fields of discriminant `\le 50`. [40, x^2 - 10], [41, x^2 - x - 10], [44, x^2 - 11]] - sage: [ d for d in range(5,50) if (is_squarefree(d) and d%4 == 1) or (d%4 == 0 and is_squarefree(d/4)) ] + sage: [d for d in range(5,50) + ....: if (is_squarefree(d) and d%4 == 1) or (d%4 == 0 and is_squarefree(d/4))] [5, 8, 12, 13, 17, 20, 21, 24, 28, 29, 33, 37, 40, 41, 44] Next, we compute all totally real quintic fields of discriminant `\le 10^5`:: @@ -116,15 +117,15 @@ from sage.rings.number_field.totallyreal_data cimport tr_data cpdef double odlyzko_bound_totallyreal(int n): r""" This function returns the unconditional Odlyzko bound for the root - discriminant of a totally real number field of degree n. + discriminant of a totally real number field of degree `n`. .. NOTE:: - The bounds for n > 50 are not necessarily optimal. + The bounds for `n > 50` are not necessarily optimal. INPUT: - - n (integer) the degree + - ``n`` -- (integer) the degree OUTPUT: @@ -132,7 +133,8 @@ cpdef double odlyzko_bound_totallyreal(int n): EXAMPLES:: - sage: [sage.rings.number_field.totallyreal.odlyzko_bound_totallyreal(n) for n in range(1,5)] + sage: from sage.rings.number_field.totallyreal import odlyzko_bound_totallyreal + sage: [odlyzko_bound_totallyreal(n) for n in range(1, 5)] [1.0, 2.223, 3.61, 5.067] AUTHORS: @@ -164,7 +166,7 @@ def enumerate_totallyreal_fields_prim(n, B, a = [], verbose=0, return_seqs=False just_print=False, return_pari_objects=True): r""" - This function enumerates primitive totally real fields of degree + Enumerate primitive totally real fields of degree `n>1` with discriminant `d \leq B`; optionally one can specify the first few coefficients, where the sequence `a` corresponds to @@ -183,26 +185,26 @@ def enumerate_totallyreal_fields_prim(n, B, a = [], verbose=0, return_seqs=False - ``n`` -- (integer) the degree - ``B`` -- (integer) the discriminant bound - - ``a`` -- (list, default: []) the coefficient list to begin with + - ``a`` -- (list, default: ``[]``) the coefficient list to begin with - ``verbose`` -- (integer or string, default: 0) if ``verbose == 1`` (or ``2``), then print to the screen (really) verbosely; if verbose is a string, then print verbosely to the file specified by verbose. - - ``return_seqs`` -- (boolean, default False) If ``True``, then return + - ``return_seqs`` -- (boolean, default ``False``) If ``True``, then return the polynomials as sequences (for easier exporting to a file). - - ``phc`` -- boolean or integer (default: False) - - ``keep_fields`` -- (boolean or integer, default: False) If - ``keep_fields`` is True, then keep fields up to ``B*log(B)``; if + - ``phc`` -- boolean or integer (default: ``False``) + - ``keep_fields`` -- (boolean or integer, default: ``False``) If + ``keep_fields`` is ``True``, then keep fields up to ``B*log(B)``; if ``keep_fields`` is an integer, then keep fields up to that integer. - ``t_2`` -- (boolean or integer, default: False) If ``t_2 = T``, then keep only polynomials with t_2 norm >= T. - - ``just_print`` -- (boolean, default: False): if ``just_print`` is not - False, instead of creating a sorted list of totally real number + - ``just_print`` -- (boolean, default: ``False``): if ``just_print`` is not + ``False``, instead of creating a sorted list of totally real number fields, we simply write each totally real field we find to the file whose filename is given by ``just_print``. In this case, we don't return anything. - - ``return_pari_objects`` -- (boolean, default: True) if + - ``return_pari_objects`` -- (boolean, default: ``True``) if both ``return_seqs`` and ``return_pari_objects`` are ``False`` then - it returns the elements as Sage objects; otherwise it returns pari + it returns the elements as Sage objects; otherwise it returns PARI objects. OUTPUT: @@ -479,7 +481,7 @@ def enumerate_totallyreal_fields_prim(n, B, a = [], verbose=0, return_seqs=False def weed_fields(S, Py_ssize_t lenS=0): r""" Function used internally by the :func:`~enumerate_totallyreal_fields_prim` - routine. (Weeds the fields listed by [discriminant, polynomial] + routine. (Weeds the fields listed by ``[discriminant, polynomial]`` for isomorphism classes.) Returns the size of the resulting list. EXAMPLES:: diff --git a/src/sage/rings/number_field/totallyreal_data.pyx b/src/sage/rings/number_field/totallyreal_data.pyx index adc52e6cfab..c0d865db02c 100644 --- a/src/sage/rings/number_field/totallyreal_data.pyx +++ b/src/sage/rings/number_field/totallyreal_data.pyx @@ -51,9 +51,9 @@ from libc.math cimport lrint, floor, ceil, fabs, round def hermite_constant(n): r""" - This function returns the nth Hermite constant + Return the `n`-th Hermite constant. - The nth Hermite constant (typically denoted `\gamma_n`), is defined + The `n`-th Hermite constant (typically denoted `\gamma_n`), is defined to be .. MATH:: @@ -67,11 +67,11 @@ def hermite_constant(n): INPUT: - - n -- integer + - ``n`` -- integer OUTPUT: - - (an upper bound for) the Hermite constant gamma_n + (an upper bound for) the Hermite constant `\gamma_n` EXAMPLES:: @@ -197,12 +197,14 @@ cdef void newton_in_intervals(int *f, int *df, int n, double *beta, cpdef lagrange_degree_3(int n, int an1, int an2, int an3): r""" Private function. Solves the equations which arise in the Lagrange multiplier - for degree 3: for each 1 <= r <= n-2, we solve + for degree 3: for each `1 \leq r \leq n-2`, we solve - r*x^i + (n-1-r)*y^i + z^i = s_i (i = 1,2,3) + .. MATH:: + + r*x^i + (n-1-r)\cdot y^i + z^i = s_i \quad (i = 1,2,3) - where the s_i are the power sums determined by the coefficients a. - We output the largest value of z which occurs. + where the `s_i` are the power sums determined by the coefficients `a`. + We output the largest value of `z` which occurs. We use a precomputed elimination ideal. EXAMPLES:: @@ -323,7 +325,7 @@ for i from 0 <= i < 46: def int_has_small_square_divisor(sage.rings.integer.Integer d): r""" - Returns the largest a such that a^2 divides d and a has prime divisors < 200. + Return the largest `a` such that `a^2` divides `d` and `a` has prime divisors `< 200`. EXAMPLES:: @@ -452,7 +454,7 @@ cdef class tr_data: We do not give a complete description here. For more information, see the attached functions; all of these are used internally by the - functions in totallyreal.py, so see that file for examples and + functions in :mod:`.totallyreal`, so see that file for examples and further documentation. """ @@ -584,9 +586,9 @@ cdef class tr_data: def increment(self, verbose=False, haltk=0, phc=False): r""" - This function 'increments' the totally real data to the next + 'Increment' the totally real data to the next value which satisfies the bounds essentially given by Rolle's - theorem, and returns the next polynomial as a sequence of + theorem, and return the next polynomial as a sequence of integers. The default or usual case just increments the constant @@ -598,10 +600,10 @@ cdef class tr_data: INPUT: - - verbose -- boolean to print verbosely computational details - - haltk -- integer, the level at which to halt the inductive + - ``verbose`` -- boolean to print verbosely computational details + - ``haltk`` -- integer, the level at which to halt the inductive coefficient bounds - - phc -- boolean, if PHCPACK is available, use it when k == n-5 to + - ``phc`` -- boolean, if PHCPACK is available, use it when `k = n-5` to compute an improved Lagrange multiplier bound OUTPUT: @@ -912,7 +914,7 @@ cdef class tr_data: def printa(self): """ - Print relevant data for self. + Print relevant data for ``self``. EXAMPLES:: diff --git a/src/sage/rings/number_field/totallyreal_phc.py b/src/sage/rings/number_field/totallyreal_phc.py index 59467e5af40..f53358ad7dd 100644 --- a/src/sage/rings/number_field/totallyreal_phc.py +++ b/src/sage/rings/number_field/totallyreal_phc.py @@ -3,8 +3,7 @@ AUTHORS: - -- John Voight (2007-10-10): - * Zeroth attempt. +- John Voight (2007-10-10): Zeroth attempt. """ # **************************************************************************** @@ -23,14 +22,14 @@ def coefficients_to_power_sums(n, m, a): r""" - Takes the list a, representing a list of initial coefficients of - a (monic) polynomial of degree n, and returns the power sums - of the roots of f up to (m-1)th powers. + Take the list ``a``, representing a list of initial coefficients of + a (monic) polynomial of degree `n`, and return the power sums + of the roots of `f` up to `(m-1)`-th powers. INPUT: - - n -- integer, the degree - - a -- list of integers, the coefficients + - ``n`` -- integer, the degree + - ``a`` -- list of integers, the coefficients OUTPUT: diff --git a/src/sage/rings/number_field/totallyreal_rel.py b/src/sage/rings/number_field/totallyreal_rel.py index 07477c46f8f..20abe5ba445 100644 --- a/src/sage/rings/number_field/totallyreal_rel.py +++ b/src/sage/rings/number_field/totallyreal_rel.py @@ -13,7 +13,7 @@ :: sage: ZZx = ZZ['x'] - sage: F. = NumberField(x^2-2) + sage: F. = NumberField(x^2 - 2) sage: enumerate_totallyreal_fields_rel(F, 2, 2000) [[1600, x^4 - 6*x^2 + 4, xF^2 + xF - 1]] @@ -24,7 +24,7 @@ :: - sage: F. = NumberField(x^2-5) + sage: F. = NumberField(x^2 - 5) sage: ls = enumerate_totallyreal_fields_rel(F, 2, 10^4) sage: ls # random (the second factor is platform-dependent) [[725, x^4 - x^3 - 3*x^2 + x + 1, xF^2 + (-1/2*t - 7/2)*xF + 1], @@ -111,30 +111,32 @@ def integral_elements_in_box(K, C): r""" Return all integral elements of the totally real field `K` whose embeddings lie *numerically* within the bounds specified by the - list `C`. The output is architecture dependent, and one may want - to expand the bounds that define C by some epsilon. + list ``C``. The output is architecture dependent, and one may want + to expand the bounds that define ``C`` by some epsilon. INPUT: - - `K` -- a totally real number field - - `C` -- a list [[lower, upper], ...] of lower and upper bounds, + - ``K`` -- a totally real number field + - ``C`` -- a list ``[[lower, upper], ...]`` of lower and upper bounds, for each embedding EXAMPLES:: sage: x = polygen(QQ) - sage: K. = NumberField(x^2-2) + sage: K. = NumberField(x^2 - 2) sage: eps = 10e-6 - sage: C = [[0-eps,5+eps],[0-eps,10+eps]] + sage: C = [[0-eps, 5+eps], [0-eps, 10+eps]] sage: ls = sage.rings.number_field.totallyreal_rel.integral_elements_in_box(K, C) - sage: sorted([ a.trace() for a in ls ]) + sage: sorted(a.trace() for a in ls) [0, 2, 4, 4, 4, 6, 6, 6, 6, 8, 8, 8, 10, 10, 10, 10, 12, 12, 14] sage: len(ls) 19 sage: v = sage.rings.number_field.totallyreal_rel.integral_elements_in_box(K, C) sage: sorted(v) - [0, -alpha + 2, 1, -alpha + 3, 2, 3, alpha + 2, 4, alpha + 3, 5, alpha + 4, 2*alpha + 3, alpha + 5, 2*alpha + 4, alpha + 6, 2*alpha + 5, 2*alpha + 6, 3*alpha + 5, 2*alpha + 7] + [0, -alpha + 2, 1, -alpha + 3, 2, 3, alpha + 2, 4, alpha + 3, 5, alpha + 4, + 2*alpha + 3, alpha + 5, 2*alpha + 4, alpha + 6, 2*alpha + 5, 2*alpha + 6, + 3*alpha + 5, 2*alpha + 7] A cubic field:: @@ -148,7 +150,8 @@ def integral_elements_in_box(K, C): below, and sometimes it isn't):: sage: sorted(v) - [-1/2*a + 2, 1/4*a^2 + 1/2*a, 0, 1, 2, 3, 4,...-1/4*a^2 - 1/2*a + 5, 1/2*a + 3, -1/4*a^2 + 5] + [-1/2*a + 2, 1/4*a^2 + 1/2*a, 0, 1, 2, 3, 4,...-1/4*a^2 - 1/2*a + 5, + 1/2*a + 3, -1/4*a^2 + 5] """ d = K.degree() Foo = K.real_embeddings() @@ -243,18 +246,18 @@ def __init__(self, F, m, B, a=None): - ``F`` -- number field, the base field - ``m`` -- integer, the relative degree - ``B`` -- integer, the discriminant bound - - ``a`` -- list (default: []), the coefficient list to begin with, + - ``a`` -- list (default: ``[]``), the coefficient list to begin with, corresponding to ``a[len(a)]*x^n + ... + a[0]x^(n-len(a))``. OUTPUT: the data initialized to begin enumeration of totally real fields - with base field F, degree n, discriminant bounded by B, and starting - with coefficients a. + with base field `F`, degree `n`, discriminant bounded by `B`, and starting + with coefficients `a`. EXAMPLES:: - sage: F. = NumberField(x^2-2) + sage: F. = NumberField(x^2 - 2) sage: T = sage.rings.number_field.totallyreal_rel.tr_data_rel(F, 2, 2000) """ if a is None: # don't make the stupid noob mistake of putting a=[] @@ -352,10 +355,10 @@ def __init__(self, F, m, B, a=None): def incr(self, f_out, verbose=False, haltk=0): r""" - This function 'increments' the totally real data to the next + 'Increment' the totally real data to the next value which satisfies the bounds essentially given by Rolle's - theorem, and returns the next polynomial in the sequence - f_out. + theorem, and return the next polynomial in the sequence + ``f_out``. The default or usual case just increments the constant coefficient; then inductively, if this is outside of the @@ -368,7 +371,7 @@ def incr(self, f_out, verbose=False, haltk=0): - ``f_out`` -- an integer sequence, to be written with the coefficients of the next polynomial - - ``verbose`` -- boolean or nonnegative integer (default: False) + - ``verbose`` -- boolean or nonnegative integer (default: ``False``) print verbosely computational details. It prints extra information if ``verbose`` is set to ``2`` or more - ``haltk`` -- integer, the level at which to halt the inductive @@ -662,26 +665,26 @@ def enumerate_totallyreal_fields_rel(F, m, B, a=[], verbose=0, - ``F`` -- number field, the base field - ``m`` -- integer, the degree - ``B`` -- integer, the discriminant bound - - ``a`` -- list (default: []), the coefficient list to begin with + - ``a`` -- list (default: ``[]``), the coefficient list to begin with - ``verbose`` -- boolean or nonnegative integer or string (default: 0) give a verbose description of the computations being performed. If ``verbose`` is set to ``2`` or more then it outputs some extra information. If ``verbose`` is a string then it outputs to a file specified by ``verbose`` - - ``return_seqs`` -- (boolean, default False) If ``True``, then return + - ``return_seqs`` -- (boolean, default ``False``) If ``True``, then return the polynomials as sequences (for easier exporting to a file). This also returns a list of four numbers, as explained in the OUTPUT section below. - - ``return_pari_objects`` -- (boolean, default: True) if + - ``return_pari_objects`` -- (boolean, default: ``True``) if both ``return_seqs`` and ``return_pari_objects`` are ``False`` then - it returns the elements as Sage objects; otherwise it returns pari + it returns the elements as Sage objects; otherwise it returns PARI objects. OUTPUT: - the list of fields with entries ``[d,fabs,f]``, where ``d`` is the discriminant, ``fabs`` is an absolute defining polynomial, and ``f`` - is a defining polynomial relative to ``F``, sorted by discriminant. + is a defining polynomial relative to `F`, sorted by discriminant. - if ``return_seqs`` is ``True``, then the first field of the list is a list containing the count of four items as explained below @@ -691,12 +694,12 @@ def enumerate_totallyreal_fields_rel(F, m, B, a=[], verbose=0, discriminant having a large enough square divisor - the third entry is the number of irreducible polynomials - the fourth entry is the number of irreducible polynomials with - discriminant at most ``B`` + discriminant at most `B` EXAMPLES:: sage: ZZx = ZZ['x'] - sage: F. = NumberField(x^2-2) + sage: F. = NumberField(x^2 - 2) sage: enumerate_totallyreal_fields_rel(F, 1, 2000) [[1, [-2, 0, 1], xF - 1]] sage: enumerate_totallyreal_fields_rel(F, 2, 2000) @@ -902,7 +905,7 @@ def enumerate_totallyreal_fields_rel(F, m, B, a=[], verbose=0, def enumerate_totallyreal_fields_all(n, B, verbose=0, return_seqs=False, return_pari_objects=True): r""" - Enumerates *all* totally real fields of degree ``n`` with discriminant + Enumerate *all* totally real fields of degree ``n`` with discriminant at most ``B``, primitive or otherwise. INPUT: @@ -911,16 +914,16 @@ def enumerate_totallyreal_fields_all(n, B, verbose=0, return_seqs=False, - ``B`` -- integer, the discriminant bound - ``verbose`` -- boolean or nonnegative integer or string (default: 0) give a verbose description of the computations being performed. If - ``verbose`` is set to ``2`` or more then it outputs some extra - information. If ``verbose`` is a string then it outputs to a file + ``verbose`` is set to ``2`` or more, it outputs some extra + information. If ``verbose`` is a string, it outputs to a file specified by ``verbose`` - - ``return_seqs`` -- (boolean, default False) If ``True``, then return + - ``return_seqs`` -- (boolean, default ``False``) If ``True``, then return the polynomials as sequences (for easier exporting to a file). This also returns a list of four numbers, as explained in the OUTPUT section below. - ``return_pari_objects`` -- (boolean, default: True) if both ``return_seqs`` and ``return_pari_objects`` are ``False`` then it - returns the elements as Sage objects; otherwise it returns pari + returns the elements as Sage objects; otherwise it returns PARI objects. EXAMPLES:: diff --git a/src/sage/rings/number_field/unit_group.py b/src/sage/rings/number_field/unit_group.py index d8f9b7a9c2f..42c3933219b 100644 --- a/src/sage/rings/number_field/unit_group.py +++ b/src/sage/rings/number_field/unit_group.py @@ -4,9 +4,10 @@ EXAMPLES:: sage: x = polygen(QQ) - sage: K. = NumberField(x^4-8*x^2+36) + sage: K. = NumberField(x^4 - 8*x^2 + 36) sage: UK = UnitGroup(K); UK - Unit group with structure C4 x Z of Number Field in a with defining polynomial x^4 - 8*x^2 + 36 + Unit group with structure C4 x Z of + Number Field in a with defining polynomial x^4 - 8*x^2 + 36 The first generator is a primitive root of unity in the field:: @@ -36,12 +37,12 @@ 1 sage: UK(-1) u0^2 - sage: [UK(u) for u in (x^4-1).roots(K, multiplicities=False)] + sage: [UK(u) for u in (x^4 - 1).roots(K, multiplicities=False)] [1, u0^2, u0, u0^3] sage: UK.fundamental_units() # random [1/24*a^3 + 1/4*a^2 - 1/12*a - 1] - sage: torsion_gen = UK.torsion_generator(); torsion_gen + sage: torsion_gen = UK.torsion_generator(); torsion_gen u0 sage: torsion_gen.value() 1/12*a^3 - 1/6*a @@ -63,20 +64,22 @@ sage: all(UK.log(u^k) == (0,k) for k in range(10)) True - sage: K. = NumberField(x^5-2,'a') + sage: K. = NumberField(x^5 - 2,'a') sage: UK = UnitGroup(K) sage: UK.rank() 2 sage: UK.fundamental_units() [a^3 + a^2 - 1, a - 1] -S-unit groups may be constructed, where S is a set of primes:: +`S`-unit groups may be constructed, where `S` is a set of primes:: - sage: K. = NumberField(x^6+2) + sage: K. = NumberField(x^6 + 2) sage: S = K.ideal(3).prime_factors(); S [Fractional ideal (3, a + 1), Fractional ideal (3, a - 1)] sage: SUK = UnitGroup(K,S=tuple(S)); SUK - S-unit group with structure C2 x Z x Z x Z x Z of Number Field in a with defining polynomial x^6 + 2 with S = (Fractional ideal (3, a + 1), Fractional ideal (3, a - 1)) + S-unit group with structure C2 x Z x Z x Z x Z of + Number Field in a with defining polynomial x^6 + 2 + with S = (Fractional ideal (3, a + 1), Fractional ideal (3, a - 1)) sage: SUK.primes() (Fractional ideal (3, a + 1), Fractional ideal (3, a - 1)) sage: SUK.rank() @@ -94,7 +97,8 @@ sage: L. = NumberField([x^2 + x + 1, x^4 + 1]) sage: UL = L.unit_group(); UL - Unit group with structure C24 x Z x Z x Z of Number Field in a with defining polynomial x^2 + x + 1 over its base field + Unit group with structure C24 x Z x Z x Z of + Number Field in a with defining polynomial x^2 + x + 1 over its base field sage: UL.gens_values() # random [-b^3*a - b^3, -b^3*a + b, (-b^3 - b^2 - b)*a - b - 1, (-b^3 - 1)*a - b^2 + b - 1] sage: UL.zeta_order() @@ -132,7 +136,8 @@ sage: PF. = F[] sage: K. = F.extension(Y^2 - (1 + a)*(a + b)*a*b) sage: K.unit_group() - Unit group with structure C2 x Z x Z x Z x Z x Z x Z x Z of Number Field in c with defining polynomial Y^2 + (-2*b - 3)*a - 2*b - 6 over its base field + Unit group with structure C2 x Z x Z x Z x Z x Z x Z x Z of Number Field in c + with defining polynomial Y^2 + (-2*b - 3)*a - 2*b - 6 over its base field TESTS:: @@ -169,7 +174,7 @@ class UnitGroup(AbelianGroupWithValues_class): """ - The unit group or an S-unit group of a number field. + The unit group or an `S`-unit group of a number field. TESTS:: @@ -229,17 +234,17 @@ def __init__(self, number_field, proof=True, S=None): INPUT: - - ``number_field`` - a number field - - ``proof`` - boolean (default True): proof flag - - ``S`` - tuple of prime ideals, or an ideal, or a single + - ``number_field`` -- a number field + - ``proof`` -- boolean (default ``True``): proof flag + - ``S`` -- tuple of prime ideals, or an ideal, or a single ideal or element from which an ideal can be constructed, in - which case the support is used. If None, the global unit - group is constructed; otherwise, the S-unit group is + which case the support is used. If ``None``, the global unit + group is constructed; otherwise, the `S`-unit group is constructed. - The proof flag is passed to pari via the ``pari_bnf()`` function + The ``proof`` flag is passed to PARI via the :pari:`pari_bnf` function which computes the unit group. See the documentation for the - number_field module. + ``number_field`` module. EXAMPLES:: @@ -268,7 +273,8 @@ def __init__(self, number_field, proof=True, S=None): sage: UK.gens_values() # random [-z^11, z^5 + z^3, z^6 + z^5, z^9 + z^7 + z^5, z^9 + z^5 + z^4 + 1, z^5 + z] sage: SUK = UnitGroup(K,S=2); SUK - S-unit group with structure C26 x Z x Z x Z x Z x Z x Z of Cyclotomic Field of order 13 and degree 12 with S = (Fractional ideal (2),) + S-unit group with structure C26 x Z x Z x Z x Z x Z x Z of + Cyclotomic Field of order 13 and degree 12 with S = (Fractional ideal (2),) TESTS: @@ -278,9 +284,12 @@ def __init__(self, number_field, proof=True, S=None): sage: K. = NumberField(7/9*x^3 + 7/3*x^2 - 56*x + 123) sage: K.unit_group() - Unit group with structure C2 x Z x Z of Number Field in a with defining polynomial 7/9*x^3 + 7/3*x^2 - 56*x + 123 + Unit group with structure C2 x Z x Z of + Number Field in a with defining polynomial 7/9*x^3 + 7/3*x^2 - 56*x + 123 sage: UnitGroup(K, S=tuple(K.primes_above(7))) - S-unit group with structure C2 x Z x Z x Z of Number Field in a with defining polynomial 7/9*x^3 + 7/3*x^2 - 56*x + 123 with S = (Fractional ideal (...),) + S-unit group with structure C2 x Z x Z x Z of + Number Field in a with defining polynomial 7/9*x^3 + 7/3*x^2 - 56*x + 123 + with S = (Fractional ideal (...),) sage: K.primes_above(7)[0] in (7/225*a^2 - 7/75*a - 42/25, 28/225*a^2 + 77/75*a - 133/25) True @@ -416,7 +425,7 @@ def rank(self): sage: K. = CyclotomicField(13) sage: UnitGroup(K).rank() 5 - sage: SUK = UnitGroup(K,S=2); SUK.rank() + sage: SUK = UnitGroup(K, S=2); SUK.rank() 6 """ return self.ngens()-1 @@ -433,8 +442,10 @@ def _repr_(self): Unit group with structure C2 x Z of Number Field in a with defining polynomial x^3 - 2 sage: U._repr_() 'Unit group with structure C2 x Z of Number Field in a with defining polynomial x^3 - 2' - sage: UnitGroup(NumberField(x^3 - 2, 'a'),S=2) - S-unit group with structure C2 x Z x Z of Number Field in a with defining polynomial x^3 - 2 with S = (Fractional ideal (a),) + sage: UnitGroup(NumberField(x^3 - 2, 'a'), S=2) + S-unit group with structure C2 x Z x Z of + Number Field in a with defining polynomial x^3 - 2 + with S = (Fractional ideal (a),) """ if self.__S: return 'S-unit group with structure %s of %s with S = %s'%( @@ -466,7 +477,7 @@ def roots_of_unity(self): EXAMPLES:: sage: x = polygen(QQ) - sage: K. = NumberField(x^2+1) + sage: K. = NumberField(x^2 + 1) sage: U = UnitGroup(K) sage: zs = U.roots_of_unity(); zs [b, -1, -b, 1] @@ -509,7 +520,7 @@ def zeta_order(self): def zeta(self, n=2, all=False): """ - Return one, or a list of all, primitive n-th root of unity in this unit group. + Return one, or a list of all, primitive `n`-th root of unity in this unit group. EXAMPLES:: @@ -532,7 +543,7 @@ def zeta(self, n=2, all=False): ValueError: n (=4) does not divide order of generator sage: r. = QQ[] - sage: K. = NumberField(x^2+1) + sage: K. = NumberField(x^2 + 1) sage: U = UnitGroup(K) sage: U.zeta(4) b @@ -542,7 +553,7 @@ def zeta(self, n=2, all=False): Traceback (most recent call last): ... ValueError: n (=3) does not divide order of generator - sage: U.zeta(3,all=True) + sage: U.zeta(3, all=True) [] """ @@ -580,7 +591,8 @@ def number_field(self): EXAMPLES:: sage: U = UnitGroup(QuadraticField(-23, 'w')); U - Unit group with structure C2 of Number Field in w with defining polynomial x^2 + 23 with w = 4.795831523312720?*I + Unit group with structure C2 of + Number Field in w with defining polynomial x^2 + 23 with w = 4.795831523312720?*I sage: U.number_field() Number Field in w with defining polynomial x^2 + 23 with w = 4.795831523312720?*I """ @@ -596,7 +608,9 @@ def primes(self): sage: S = tuple(K.ideal(3).prime_factors()); S (Fractional ideal (3, 1/2*a - 1/2), Fractional ideal (3, 1/2*a + 1/2)) sage: U = UnitGroup(K,S=tuple(S)); U - S-unit group with structure C2 x Z x Z of Number Field in a with defining polynomial x^2 + 23 with a = 4.795831523312720?*I with S = (Fractional ideal (3, 1/2*a - 1/2), Fractional ideal (3, 1/2*a + 1/2)) + S-unit group with structure C2 x Z x Z of + Number Field in a with defining polynomial x^2 + 23 with a = 4.795831523312720?*I + with S = (Fractional ideal (3, 1/2*a - 1/2), Fractional ideal (3, 1/2*a + 1/2)) sage: U.primes() == S True """ @@ -604,16 +618,16 @@ def primes(self): def log(self, u): r""" - Return the exponents of the unit ``u`` with respect to group generators. + Return the exponents of the unit `u` with respect to group generators. INPUT: - ``u`` -- Any object from which an element of the unit group's number field `K` may be constructed; an error is raised if an element of `K` - cannot be constructed from u, or if the element constructed is not a + cannot be constructed from `u`, or if the element constructed is not a unit. - OUTPUT: a list of integers giving the exponents of ``u`` with + OUTPUT: a list of integers giving the exponents of `u` with respect to the unit group's basis. EXAMPLES:: @@ -630,16 +644,18 @@ def log(self, u): (0, 0, 0, 0, 0, 1)] sage: vec = [65,6,7,8,9,10] sage: unit = UK.exp(vec); unit # random - -253576*z^11 + 7003*z^10 - 395532*z^9 - 35275*z^8 - 500326*z^7 - 35275*z^6 - 395532*z^5 + 7003*z^4 - 253576*z^3 - 59925*z - 59925 + -253576*z^11 + 7003*z^10 - 395532*z^9 - 35275*z^8 - 500326*z^7 - 35275*z^6 + - 395532*z^5 + 7003*z^4 - 253576*z^3 - 59925*z - 59925 sage: UK.log(unit) (13, 6, 7, 8, 9, 10) An S-unit example:: - sage: SUK = UnitGroup(K,S=2) + sage: SUK = UnitGroup(K, S=2) sage: v = (3,1,4,1,5,9,2) sage: u = SUK.exp(v); u - 8732*z^11 - 15496*z^10 - 51840*z^9 - 68804*z^8 - 51840*z^7 - 15496*z^6 + 8732*z^5 - 34216*z^3 - 64312*z^2 - 64312*z - 34216 + 8732*z^11 - 15496*z^10 - 51840*z^9 - 68804*z^8 - 51840*z^7 - 15496*z^6 + + 8732*z^5 - 34216*z^3 - 64312*z^2 - 64312*z - 34216 sage: SUK.log(u) (3, 1, 4, 1, 5, 9, 2) sage: SUK.log(u) == v @@ -655,10 +671,10 @@ def exp(self, exponents): - ``u`` -- Any object from which an element of the unit group's number field `K` may be constructed; an error is - raised if an element of `K` cannot be constructed from u, or + raised if an element of `K` cannot be constructed from `u`, or if the element constructed is not a unit. - OUTPUT: a list of integers giving the exponents of ``u`` with + OUTPUT: a list of integers giving the exponents of `u` with respect to the unit group's basis. EXAMPLES:: @@ -686,7 +702,8 @@ def exp(self, exponents): sage: SUK = UnitGroup(K,S=2) sage: v = (3,1,4,1,5,9,2) sage: u = SUK.exp(v); u - 8732*z^11 - 15496*z^10 - 51840*z^9 - 68804*z^8 - 51840*z^7 - 15496*z^6 + 8732*z^5 - 34216*z^3 - 64312*z^2 - 64312*z - 34216 + 8732*z^11 - 15496*z^10 - 51840*z^9 - 68804*z^8 - 51840*z^7 - 15496*z^6 + + 8732*z^5 - 34216*z^3 - 64312*z^2 - 64312*z - 34216 sage: SUK.log(u) (3, 1, 4, 1, 5, 9, 2) sage: SUK.log(u) == v diff --git a/src/sage/rings/numbers_abc.py b/src/sage/rings/numbers_abc.py index 478a0b36408..6bbcddccf40 100644 --- a/src/sage/rings/numbers_abc.py +++ b/src/sage/rings/numbers_abc.py @@ -57,10 +57,10 @@ def register_sage_classes(): Because we do this, NumPy's ``isscalar()`` recognizes Sage types:: - sage: from numpy import isscalar - sage: isscalar(3.141) + sage: from numpy import isscalar # optional - numpy + sage: isscalar(3.141) # optional - numpy True - sage: isscalar(4/17) + sage: isscalar(4/17) # optional - numpy True """ from sage.misc.superseded import deprecation diff --git a/src/sage/rings/padics/CR_template.pxi b/src/sage/rings/padics/CR_template.pxi index 73f87ed27e9..cb57bb2cb48 100644 --- a/src/sage/rings/padics/CR_template.pxi +++ b/src/sage/rings/padics/CR_template.pxi @@ -2,14 +2,14 @@ Capped relative template for complete discrete valuation rings and their fraction fields In order to use this template you need to write a linkage file and gluing file. -For an example see mpz_linkage.pxi (linkage file) and padic_capped_relative_element.pyx (gluing file). +For an example see ``mpz_linkage.pxi`` (linkage file) and ``padic_capped_relative_element.pyx`` (gluing file). -The linkage file implements a common API that is then used in the class CRElement defined here. -See the documentation of mpz_linkage.pxi for the functions needed. +The linkage file implements a common API that is then used in the class :class:`CRElement` defined here. +See the documentation of ``mpz_linkage.pxi`` for the functions needed. The gluing file does the following: -- ctypedef's celement to be the appropriate type (e.g. mpz_t) +- ``ctypedef``'s ``celement`` to be the appropriate type (e.g. ``mpz_t``) - includes the linkage file - includes this template - defines a concrete class inheriting from ``CRElement``, and implements @@ -423,7 +423,7 @@ cdef class CRElement(pAdicTemplateElement): def __invert__(self): r""" - Returns the multiplicative inverse of this element. + Return the multiplicative inverse of this element. .. NOTE:: @@ -882,7 +882,7 @@ cdef class CRElement(pAdicTemplateElement): def add_bigoh(self, absprec): """ - Returns a new element with absolute precision decreased to + Return a new element with absolute precision decreased to ``absprec``. INPUT: @@ -891,7 +891,7 @@ cdef class CRElement(pAdicTemplateElement): OUTPUT: - an equal element with precision set to the minimum of ``self's`` + an equal element with precision set to the minimum of ``self``'s precision and ``absprec`` EXAMPLES:: @@ -959,7 +959,7 @@ cdef class CRElement(pAdicTemplateElement): cpdef bint _is_exact_zero(self) except -1: """ - Returns true if this element is exactly zero. + Return ``True`` if this element is exactly zero. EXAMPLES:: @@ -975,7 +975,7 @@ cdef class CRElement(pAdicTemplateElement): cpdef bint _is_inexact_zero(self) except -1: """ - Returns True if this element is indistinguishable from zero + Return ``True`` if this element is indistinguishable from zero but has finite precision. EXAMPLES:: @@ -992,10 +992,10 @@ cdef class CRElement(pAdicTemplateElement): def is_zero(self, absprec = None): r""" - Determines whether this element is zero modulo + Determine whether this element is zero modulo `\pi^{\mbox{absprec}}`. - If ``absprec is None``, returns ``True`` if this element is + If ``absprec`` is ``None``, returns ``True`` if this element is indistinguishable from zero. INPUT: @@ -1037,7 +1037,7 @@ cdef class CRElement(pAdicTemplateElement): def __bool__(self): """ - Returns True if self is distinguishable from zero. + Return ``True`` if ``self`` is distinguishable from zero. For most applications, explicitly specifying the power of p modulo which the element is supposed to be nonzero is @@ -1053,10 +1053,10 @@ cdef class CRElement(pAdicTemplateElement): def is_equal_to(self, _right, absprec=None): r""" - Returns whether self is equal to right modulo + Return whether ``self`` is equal to ``right`` modulo `\pi^{\mbox{absprec}}`. - If ``absprec is None``, returns True if self and right are + If ``absprec`` is ``None``, returns ``True`` if ``self`` and ``right`` are equal to the minimum of their precisions. INPUT: @@ -1390,10 +1390,10 @@ cdef class CRElement(pAdicTemplateElement): def precision_relative(self): """ - Returns the relative precision of this element. + Return the relative precision of this element. This is the power of the maximal ideal modulo which the unit - part of self is defined. + part of ``self`` is defined. EXAMPLES:: @@ -1417,7 +1417,7 @@ cdef class CRElement(pAdicTemplateElement): cpdef pAdicTemplateElement unit_part(self): r""" - Returns `u`, where this element is `\pi^v u`. + Return `u`, where this element is `\pi^v u`. EXAMPLES:: @@ -1461,7 +1461,7 @@ cdef class CRElement(pAdicTemplateElement): cdef long valuation_c(self): """ - Returns the valuation of this element. + Return the valuation of this element. If self is an exact zero, returns ``maxordp``, which is defined as ``(1L << (sizeof(long) * 8 - 2))-1``. @@ -1480,16 +1480,16 @@ cdef class CRElement(pAdicTemplateElement): cpdef val_unit(self, p=None): """ - Returns a pair ``(self.valuation(), self.unit_part())``. + Return a pair ``(self.valuation(), self.unit_part())``. INPUT: - - ``p`` -- a prime (default: ``None``). If specified, will make sure that p==self.parent().prime() + - ``p`` -- a prime (default: ``None``). If specified, will make sure that ``p == self.parent().prime()`` .. NOTE:: The optional argument ``p`` is used for consistency with the - valuation methods on integer and rational. + valuation methods on integers and rationals. EXAMPLES:: @@ -1707,7 +1707,7 @@ cdef class pAdicConvert_CR_ZZ(RingMap): returns the smallest non-negative integer approximation to its input which is accurate up to the precision. - Raises a ``ValueError``, if the input is not in the closure of the image of + Raises a :class:`ValueError`, if the input is not in the closure of the image of the integers. EXAMPLES:: @@ -2113,7 +2113,7 @@ cdef class pAdicConvert_QQ_CR(Morphism): def section(self): """ - Returns the map back to the rationals that returns the smallest + Return the map back to the rationals that returns the smallest non-negative integer approximation to its input which is accurate up to the precision. @@ -2130,8 +2130,8 @@ cdef class pAdicConvert_QQ_CR(Morphism): return self._section cdef class pAdicCoercion_CR_frac_field(RingHomomorphism): - """ - The canonical inclusion of Zq into its fraction field. + r""" + The canonical inclusion of `\ZZ_q` into its fraction field. EXAMPLES:: @@ -2246,7 +2246,7 @@ cdef class pAdicCoercion_CR_frac_field(RingHomomorphism): def section(self): """ - Returns a map back to the ring that converts elements of + Return a map back to the ring that converts elements of non-negative valuation. EXAMPLES:: @@ -2356,8 +2356,8 @@ cdef class pAdicCoercion_CR_frac_field(RingHomomorphism): cdef class pAdicConvert_CR_frac_field(Morphism): - """ - The section of the inclusion from `\ZZ_q`` to its fraction field. + r""" + The section of the inclusion from `\ZZ_q` to its fraction field. EXAMPLES:: diff --git a/src/sage/rings/padics/FM_template.pxi b/src/sage/rings/padics/FM_template.pxi index df7bd8bdf38..ea7d4055660 100644 --- a/src/sage/rings/padics/FM_template.pxi +++ b/src/sage/rings/padics/FM_template.pxi @@ -2,19 +2,19 @@ Fixed modulus template for complete discrete valuation rings In order to use this template you need to write a linkage file and -gluing file. For an example see mpz_linkage.pxi (linkage file) and -padic_fixed_modulus_element.pyx (gluing file). +gluing file. For an example see ``mpz_linkage.pxi`` (linkage file) and +``padic_fixed_modulus_element.pyx`` (gluing file). The linkage file implements a common API that is then used in the -class FMElement defined here. See sage/libs/linkages/padics/API.pxi +class :class:`FMElement` defined here. See ``sage/libs/linkages/padics/API.pxi`` for the functions needed. The gluing file does the following: -- ctypedef's celement to be the appropriate type (e.g. mpz_t) +- ``ctypedef``'s ``celement`` to be the appropriate type (e.g. ``mpz_t``) - includes the linkage file - includes this template -- defines a concrete class inheriting from FMElement, and implements +- defines a concrete class inheriting from :class:`FMElement`, and implements any desired extra methods AUTHORS: @@ -463,7 +463,7 @@ cdef class FMElement(pAdicTemplateElement): def add_bigoh(self, absprec): """ - Returns a new element truncated modulo `\pi^{\mbox{absprec}}`. + Return a new element truncated modulo `\pi^{\mbox{absprec}}`. INPUT: @@ -471,7 +471,7 @@ cdef class FMElement(pAdicTemplateElement): OUTPUT: - - a new element truncated modulo `\pi^{\mbox{absprec}}`. + a new element truncated modulo `\pi^{\mbox{absprec}}`. EXAMPLES:: @@ -525,7 +525,7 @@ cdef class FMElement(pAdicTemplateElement): cpdef bint _is_inexact_zero(self) except -1: """ - Returns True if self is indistinguishable from zero. + Return ``True`` if self is indistinguishable from zero. EXAMPLES:: @@ -539,7 +539,7 @@ cdef class FMElement(pAdicTemplateElement): def is_zero(self, absprec = None): r""" - Returns whether self is zero modulo `\pi^{\mbox{absprec}}`. + Returns whether ``self`` is zero modulo `\pi^{\mbox{absprec}}`. INPUT: @@ -582,13 +582,13 @@ cdef class FMElement(pAdicTemplateElement): def is_equal_to(self, _right, absprec=None): r""" - Returns whether this element is equal to ``right`` modulo `p^{\mbox{absprec}}`. + Return whether this element is equal to ``right`` modulo `p^{\mbox{absprec}}`. If ``absprec`` is ``None``, returns if ``self == 0``. INPUT: - - ``right`` -- a p-adic element with the same parent + - ``right`` -- a `p`-adic element with the same parent - ``absprec`` -- a positive integer or ``None`` (default: ``None``) EXAMPLES:: @@ -780,9 +780,9 @@ cdef class FMElement(pAdicTemplateElement): cpdef pAdicTemplateElement unit_part(FMElement self): r""" - Returns the unit part of self. + Return the unit part of ``self``. - If the valuation of self is positive, then the high digits of the + If the valuation of ``self`` is positive, then the high digits of the result will be zero. EXAMPLES:: @@ -805,7 +805,7 @@ cdef class FMElement(pAdicTemplateElement): cdef long valuation_c(self): """ - Returns the valuation of this element. + Return the valuation of this element. TESTS:: @@ -836,10 +836,10 @@ cdef class FMElement(pAdicTemplateElement): cpdef val_unit(self): """ - Returns a 2-tuple, the first element set to the valuation of - self, and the second to the unit part of self. + Return a 2-tuple, the first element set to the valuation of + ``self``, and the second to the unit part of ``self``. - If self == 0, then the unit part is O(p^self.parent().precision_cap()). + If ``self == 0``, then the unit part is ``O(p^self.parent().precision_cap())``. EXAMPLES:: @@ -868,8 +868,8 @@ cdef class FMElement(pAdicTemplateElement): return chash(self.value, 0, self.prime_pow.ram_prec_cap, self.prime_pow) cdef class pAdicCoercion_ZZ_FM(RingHomomorphism): - """ - The canonical inclusion from ZZ to a fixed modulus ring. + r""" + The canonical inclusion from `\ZZ` to a fixed modulus ring. EXAMPLES:: @@ -993,8 +993,8 @@ cdef class pAdicCoercion_ZZ_FM(RingHomomorphism): return ans def section(self): - """ - Returns a map back to ZZ that approximates an element of this + r""" + Returns a map back to `\ZZ` that approximates an element of this `p`-adic ring by an integer. EXAMPLES:: @@ -1010,11 +1010,11 @@ cdef class pAdicCoercion_ZZ_FM(RingHomomorphism): return self._section cdef class pAdicConvert_FM_ZZ(RingMap): - """ - The map from a fixed modulus ring back to ZZ that returns the smallest + r""" + The map from a fixed modulus ring back to `\ZZ` that returns the smallest non-negative integer approximation to its input which is accurate up to the precision. - If the input is not in the closure of the image of ZZ, raises a ValueError. + If the input is not in the closure of the image of `\ZZ`, raises a :class:`ValueError`. EXAMPLES:: @@ -1057,9 +1057,9 @@ cdef class pAdicConvert_FM_ZZ(RingMap): return ans cdef class pAdicConvert_QQ_FM(Morphism): - """ - The inclusion map from QQ to a fixed modulus ring that is defined - on all elements with non-negative p-adic valuation. + r""" + The inclusion map from `\QQ` to a fixed modulus ring that is defined + on all elements with non-negative `p`-adic valuation. EXAMPLES:: @@ -1175,8 +1175,8 @@ cdef class pAdicConvert_QQ_FM(Morphism): return ans cdef class pAdicCoercion_FM_frac_field(RingHomomorphism): - """ - The canonical inclusion of Zq into its fraction field. + r""" + The canonical inclusion of `\ZZ_q` into its fraction field. EXAMPLES:: @@ -1282,7 +1282,7 @@ cdef class pAdicCoercion_FM_frac_field(RingHomomorphism): def section(self): """ - Returns a map back to the ring that converts elements of + Return a map back to the ring that converts elements of non-negative valuation. EXAMPLES:: @@ -1388,7 +1388,7 @@ cdef class pAdicCoercion_FM_frac_field(RingHomomorphism): cdef class pAdicConvert_FM_frac_field(Morphism): r""" - The section of the inclusion from `\ZZ_q`` to its fraction field. + The section of the inclusion from `\ZZ_q` to its fraction field. EXAMPLES:: diff --git a/src/sage/rings/padics/FP_template.pxi b/src/sage/rings/padics/FP_template.pxi index befd8ee01fb..57ec619b278 100644 --- a/src/sage/rings/padics/FP_template.pxi +++ b/src/sage/rings/padics/FP_template.pxi @@ -2,19 +2,19 @@ Floating point template for complete discrete valuation rings In order to use this template you need to write a linkage file and -gluing file. For an example see mpz_linkage.pxi (linkage file) and -padic_floating_point_element.pyx (gluing file). +gluing file. For an example see ``mpz_linkage.pxi`` (linkage file) and +``padic_floating_point_element.pyx`` (gluing file). The linkage file implements a common API that is then used in the -class FPElement defined here. See sage/libs/linkages/padics/API.pxi +class :class:`FPElement` defined here. See ``sage/libs/linkages/padics/API.pxi`` for the functions needed. The gluing file does the following: -- ctypedef's celement to be the appropriate type (e.g. mpz_t) +- ``ctypedef``'s ``celement`` to be the appropriate type (e.g. ``mpz_t``) - includes the linkage file - includes this template -- defines a concrete class inheriting from FPElement, and implements +- defines a concrete class inheriting from :class:`FPElement`, and implements any desired extra methods AUTHORS: @@ -795,7 +795,7 @@ cdef class FPElement(pAdicTemplateElement): def add_bigoh(self, absprec): """ - Returns a new element truncated modulo `\pi^{\mbox{absprec}}`. + Return a new element truncated modulo `\pi^{\mbox{absprec}}`. INPUT: @@ -803,7 +803,7 @@ cdef class FPElement(pAdicTemplateElement): OUTPUT: - - a new element truncated modulo `\pi^{\mbox{absprec}}`. + a new element truncated modulo `\pi^{\mbox{absprec}}`. EXAMPLES:: @@ -851,7 +851,7 @@ cdef class FPElement(pAdicTemplateElement): cpdef bint _is_inexact_zero(self) except -1: """ - Returns True if self is indistinguishable from zero. + Return ``True`` if self is indistinguishable from zero. EXAMPLES:: @@ -865,7 +865,7 @@ cdef class FPElement(pAdicTemplateElement): def is_zero(self, absprec = None): r""" - Returns whether self is zero modulo `\pi^{\mbox{absprec}}`. + Returns whether ``self`` is zero modulo `\pi^{\mbox{absprec}}`. INPUT: @@ -897,7 +897,7 @@ cdef class FPElement(pAdicTemplateElement): """ Return ``True`` if this element is distinguishable from zero. - For most applications, explicitly specifying the power of p + For most applications, explicitly specifying the power of `p` modulo which the element is supposed to be nonzero is preferable. EXAMPLES:: @@ -910,14 +910,14 @@ cdef class FPElement(pAdicTemplateElement): def is_equal_to(self, _right, absprec=None): r""" - Returns whether this element is equal to ``right`` modulo `p^{\mbox{absprec}}`. + Return whether this element is equal to ``right`` modulo `p^{\mbox{absprec}}`. - If ``absprec`` is ``None``, determines whether self and right + If ``absprec`` is ``None``, determines whether ``self`` and ``right`` have the same value. INPUT: - - ``right`` -- a p-adic element with the same parent + - ``right`` -- a `p`-adic element with the same parent - ``absprec`` -- a positive integer or ``None`` (default: ``None``) EXAMPLES:: @@ -1137,7 +1137,7 @@ cdef class FPElement(pAdicTemplateElement): cpdef pAdicTemplateElement unit_part(FPElement self): r""" - Returns the unit part of this element. + Return the unit part of this element. If the valuation of this element is positive, then the high digits of the result will be zero. @@ -1167,7 +1167,7 @@ cdef class FPElement(pAdicTemplateElement): cdef long valuation_c(self): """ - Returns the valuation of this element. + Return the valuation of this element. If this element is an exact zero, returns ``maxordp``, which is defined as ``(1L << (sizeof(long) * 8 - 2))-1``. @@ -1204,7 +1204,7 @@ cdef class FPElement(pAdicTemplateElement): cpdef val_unit(self, p=None): """ - Returns a 2-tuple, the first element set to the valuation of + Return a 2-tuple, the first element set to the valuation of this element, and the second to the unit part. If this element is either zero or infinity, raises an error. @@ -1380,8 +1380,8 @@ cdef class pAdicCoercion_ZZ_FP(RingHomomorphism): return ans def section(self): - """ - Returns a map back to ZZ that approximates an element of this + r""" + Returns a map back to `\ZZ` that approximates an element of this `p`-adic ring by an integer. EXAMPLES:: @@ -1398,11 +1398,11 @@ cdef class pAdicCoercion_ZZ_FP(RingHomomorphism): cdef class pAdicConvert_FP_ZZ(RingMap): - """ - The map from a floating point ring back to ZZ that returns the smallest + r""" + The map from a floating point ring back to `\ZZ` that returns the smallest non-negative integer approximation to its input which is accurate up to the precision. - If the input is not in the closure of the image of ZZ, raises a ValueError. + If the input is not in the closure of the image of `\ZZ`, raises a :class:`ValueError`. EXAMPLES:: @@ -1602,7 +1602,7 @@ cdef class pAdicCoercion_QQ_FP(RingHomomorphism): def section(self): """ - Returns a map back to the rationals that approximates an element by + Return a map back to the rationals that approximates an element by a rational number. EXAMPLES:: @@ -1669,8 +1669,8 @@ cdef class pAdicConvert_FP_QQ(RingMap): return ans cdef class pAdicConvert_QQ_FP(Morphism): - """ - The inclusion map from QQ to a floating point ring. + r""" + The inclusion map from `\QQ` to a floating point ring. EXAMPLES:: @@ -1908,7 +1908,7 @@ cdef class pAdicCoercion_FP_frac_field(RingHomomorphism): def section(self): r""" - Returns a map back to the ring that converts elements of + Return a map back to the ring that converts elements of non-negative valuation. EXAMPLES:: diff --git a/src/sage/rings/padics/eisenstein_extension_generic.py b/src/sage/rings/padics/eisenstein_extension_generic.py index 4f68e63ffae..84c3c1980a9 100644 --- a/src/sage/rings/padics/eisenstein_extension_generic.py +++ b/src/sage/rings/padics/eisenstein_extension_generic.py @@ -26,7 +26,7 @@ class EisensteinExtensionGeneric(pAdicExtensionGeneric): def __init__(self, poly, prec, print_mode, names, element_class): """ - Initializes self. + Initializes ``self``. EXAMPLES:: @@ -74,7 +74,7 @@ def absolute_e(self): def inertia_subring(self): """ - Returns the inertia subring. + Return the inertia subring. Since an Eisenstein extension is totally ramified, this is just the ground field. @@ -83,7 +83,7 @@ def inertia_subring(self): sage: A = Zp(7,10) sage: S. = A[] - sage: B. = A.ext(x^2+7) + sage: B. = A.ext(x^2 + 7) sage: B.inertia_subring() 7-adic Ring with capped relative precision 10 """ @@ -91,21 +91,21 @@ def inertia_subring(self): def residue_class_field(self): """ - Returns the residue class field. + Return the residue class field. INPUT: - - self -- a p-adic ring + - ``self`` -- a p-adic ring OUTPUT: - - the residue field + the residue field EXAMPLES:: sage: A = Zp(7,10) sage: S. = A[] - sage: B. = A.ext(x^2+7) + sage: B. = A.ext(x^2 + 7) sage: B.residue_class_field() Finite Field of size 7 """ @@ -113,7 +113,7 @@ def residue_class_field(self): def residue_ring(self, n): """ - Return the quotient of the ring of integers by the nth power of its maximal ideal. + Return the quotient of the ring of integers by the `n`-th power of its maximal ideal. EXAMPLES:: @@ -162,13 +162,13 @@ def residue_ring(self, n): def gen(self, n=0): """ - Returns a generator for self as an extension of its ground ring. + Return a generator for ``self`` as an extension of its ground ring. EXAMPLES:: sage: A = Zp(7,10) sage: S. = A[] - sage: B. = A.ext(x^2+7) + sage: B. = A.ext(x^2 + 7) sage: B.gen() t + O(t^21) """ @@ -178,14 +178,14 @@ def gen(self, n=0): def uniformizer_pow(self, n): """ - Returns the nth power of the uniformizer of self (as an - element of self). + Return the `n`-th power of the uniformizer of ``self`` (as an + element of ``self``). EXAMPLES:: sage: A = Zp(7,10) sage: S. = A[] - sage: B. = A.ext(x^2+7) + sage: B. = A.ext(x^2 + 7) sage: B.uniformizer_pow(5) t^5 + O(t^25) """ @@ -196,14 +196,14 @@ def uniformizer_pow(self, n): def uniformizer(self): """ - Returns the uniformizer of self, ie a generator for the unique + Return the uniformizer of ``self``, i.e., a generator for the unique maximal ideal. EXAMPLES:: sage: A = Zp(7,10) sage: S. = A[] - sage: B. = A.ext(x^2+7) + sage: B. = A.ext(x^2 + 7) sage: B.uniformizer() t + O(t^21) """ @@ -211,7 +211,7 @@ def uniformizer(self): def _uniformizer_print(self): """ - Returns a string representation of how the uniformizer of self + Return a string representation of how the uniformizer of self prints. Mainly for internal use. EXAMPLES:: diff --git a/src/sage/rings/padics/factory.py b/src/sage/rings/padics/factory.py index fae673de284..25e5c796cc2 100644 --- a/src/sage/rings/padics/factory.py +++ b/src/sage/rings/padics/factory.py @@ -161,7 +161,7 @@ def _canonicalize_show_prec(type, print_mode, show_prec=None): def get_key_base(p, prec, type, print_mode, names, ram_name, print_pos, print_sep, print_alphabet, print_max_terms, show_prec, check, valid_types, label=None): r""" - This implements create_key for Zp and Qp: moving it here prevents code duplication. + This implements ``create_key`` for ``Zp`` and ``Qp``: moving it here prevents code duplication. It fills in unspecified values and checks for contradictions in the input. It also standardizes irrelevant options so that duplicate parents are not created. @@ -468,7 +468,9 @@ class Qp_class(UniqueFactory): sage: R = Qp(5, print_mode='series'); a = R(70700); a 3*5^2 + 3*5^4 + 2*5^5 + 4*5^6 + O(5^22) sage: b = R(-70700); b - 2*5^2 + 4*5^3 + 5^4 + 2*5^5 + 4*5^7 + 4*5^8 + 4*5^9 + 4*5^10 + 4*5^11 + 4*5^12 + 4*5^13 + 4*5^14 + 4*5^15 + 4*5^16 + 4*5^17 + 4*5^18 + 4*5^19 + 4*5^20 + 4*5^21 + O(5^22) + 2*5^2 + 4*5^3 + 5^4 + 2*5^5 + 4*5^7 + 4*5^8 + 4*5^9 + 4*5^10 + 4*5^11 + + 4*5^12 + 4*5^13 + 4*5^14 + 4*5^15 + 4*5^16 + 4*5^17 + 4*5^18 + + 4*5^19 + 4*5^20 + 4*5^21 + O(5^22) *print_pos* controls whether negatives can be used in the coefficients of powers of `p`. :: @@ -832,7 +834,7 @@ def Qq(q, prec = None, type = 'capped-rel', modulus = None, names=None, - ``q`` -- integer, list, tuple or ``Factorization`` object. If ``q`` is an integer, it is the prime power `q` in `\QQ_q`. If ``q`` is a - ``Factorization`` object, it is the factorization of the prime power `q`. + :class:`Factorization` object, it is the factorization of the prime power `q`. As a tuple it is the pair ``(p, n)``, and as a list it is a single element list ``[(p, n)]``. @@ -860,7 +862,7 @@ def Qq(q, prec = None, type = 'capped-rel', modulus = None, names=None, - ``res_name`` -- string (defaults to ``None``, which corresponds to adding a ``'0'`` to the end of the name). Controls how elements of - the reside field print. + the residue field print. - ``print_pos`` -- bool (default ``None``) Whether to only use positive integers in the representations of elements. See PRINTING below. @@ -1012,9 +1014,15 @@ def Qq(q, prec = None, type = 'capped-rel', modulus = None, names=None, sage: R. = Qq(9, 20, 'capped-rel', print_mode='series'); (1+2*a)^4 2 + (2*a + 2)*3 + (2*a + 1)*3^2 + O(3^20) sage: -3*(1+2*a)^4 - 3 + a*3^2 + 3^3 + (2*a + 2)*3^4 + (2*a + 2)*3^5 + (2*a + 2)*3^6 + (2*a + 2)*3^7 + (2*a + 2)*3^8 + (2*a + 2)*3^9 + (2*a + 2)*3^10 + (2*a + 2)*3^11 + (2*a + 2)*3^12 + (2*a + 2)*3^13 + (2*a + 2)*3^14 + (2*a + 2)*3^15 + (2*a + 2)*3^16 + (2*a + 2)*3^17 + (2*a + 2)*3^18 + (2*a + 2)*3^19 + (2*a + 2)*3^20 + O(3^21) + 3 + a*3^2 + 3^3 + (2*a + 2)*3^4 + (2*a + 2)*3^5 + (2*a + 2)*3^6 + (2*a + 2)*3^7 + + (2*a + 2)*3^8 + (2*a + 2)*3^9 + (2*a + 2)*3^10 + (2*a + 2)*3^11 + + (2*a + 2)*3^12 + (2*a + 2)*3^13 + (2*a + 2)*3^14 + (2*a + 2)*3^15 + + (2*a + 2)*3^16 + (2*a + 2)*3^17 + (2*a + 2)*3^18 + (2*a + 2)*3^19 + + (2*a + 2)*3^20 + O(3^21) sage: ~(3*a+18) - (a + 2)*3^-1 + 1 + 2*3 + (a + 1)*3^2 + 3^3 + 2*3^4 + (a + 1)*3^5 + 3^6 + 2*3^7 + (a + 1)*3^8 + 3^9 + 2*3^10 + (a + 1)*3^11 + 3^12 + 2*3^13 + (a + 1)*3^14 + 3^15 + 2*3^16 + (a + 1)*3^17 + 3^18 + O(3^19) + (a + 2)*3^-1 + 1 + 2*3 + (a + 1)*3^2 + 3^3 + 2*3^4 + (a + 1)*3^5 + 3^6 + 2*3^7 + + (a + 1)*3^8 + 3^9 + 2*3^10 + (a + 1)*3^11 + 3^12 + 2*3^13 + (a + 1)*3^14 + + 3^15 + 2*3^16 + (a + 1)*3^17 + 3^18 + O(3^19) *print_pos* controls whether negatives can be used in the coefficients of powers of `p`. :: @@ -1074,7 +1082,8 @@ def Qq(q, prec = None, type = 'capped-rel', modulus = None, names=None, *print_pos* controls whether to use a balanced representation or not. :: - sage: S. = Qq(9, 7, print_mode='val-unit', print_pos=False); b = (1+3*a)^9 - 1; b + sage: S. = Qq(9, 7, print_mode='val-unit', print_pos=False) + sage: b = (1+3*a)^9 - 1; b 3^3 * (15 - 17*a) + O(3^7) sage: ~b 3^-3 * (-40 + a) + O(3) @@ -1082,15 +1091,19 @@ def Qq(q, prec = None, type = 'capped-rel', modulus = None, names=None, *ram_name* affects how the prime is printed. :: sage: A. = Qp(next_prime(10^6), print_mode='val-unit')[] - sage: T. = Qq(next_prime(10^6)^3, 4, print_mode='val-unit', ram_name='p', modulus=x^3+385831*x^2+106556*x+321036); b = ~(next_prime(10^6)^2*(a^2 + a - 4)); b - p^-2 * (503009563508519137754940 + 704413692798200940253892*a + 968097057817740999537581*a^2) + O(p^2) + sage: T. = Qq(next_prime(10^6)^3, 4, print_mode='val-unit', ram_name='p', + ....: modulus=x^3+385831*x^2+106556*x+321036) + sage: b = ~(next_prime(10^6)^2*(a^2 + a - 4)); b + p^-2 * (503009563508519137754940 + 704413692798200940253892*a + + 968097057817740999537581*a^2) + O(p^2) sage: b * (a^2 + a - 4) p^-2 * 1 + O(p^2) *print_max_terse_terms* controls how many terms of the polynomial appear in the unit part. :: - sage: U. = Qq(17^4, 6, print_mode='val-unit', print_max_terse_terms=3); b = ~(17*(a^3-a+14)); b + sage: U. = Qq(17^4, 6, print_mode='val-unit', print_max_terse_terms=3) + sage: b = ~(17*(a^3-a+14)); b 17^-1 * (22110411 + 11317400*a + 20656972*a^2 + ...) + O(17^5) sage: b*17*(a^3-a+14) 1 + O(17^6) @@ -1176,7 +1189,8 @@ def Qq(q, prec = None, type = 'capped-rel', modulus = None, names=None, series, but more compactly. :: sage: R. = Qq(125); (a+5)^6 - (4*a^2 + 3*a + 4) + (3*a^2 + 2*a)*5 + (a^2 + a + 1)*5^2 + (3*a + 2)*5^3 + (3*a^2 + a + 3)*5^4 + (2*a^2 + 3*a + 2)*5^5 + O(5^20) + (4*a^2 + 3*a + 4) + (3*a^2 + 2*a)*5 + (a^2 + a + 1)*5^2 + (3*a + 2)*5^3 + + (3*a^2 + a + 3)*5^4 + (2*a^2 + 3*a + 2)*5^5 + O(5^20) sage: R. = Qq(125, print_mode='bars', prec=8); repr((a+5)^6) '...[2, 3, 2]|[3, 1, 3]|[2, 3]|[1, 1, 1]|[0, 2, 3]|[4, 3, 4]' sage: repr((a-5)^6) @@ -1267,14 +1281,16 @@ def Qq(q, prec = None, type = 'capped-rel', modulus = None, names=None, sage: p = next_prime(2^123) sage: k = Qp(p) sage: R. = k[] - sage: K = Qq([(p, 5)], modulus=x^5+x+4, names='a', ram_name='p', print_pos=False, check=False) + sage: K = Qq([(p, 5)], modulus=x^5+x+4, names='a', ram_name='p', + ....: print_pos=False, check=False) sage: K.0^5 (-a - 4) + O(p^20) In tests on ``sage.math.washington.edu``, the creation of ``K`` as above took an average of 1.58ms, while:: - sage: K = Qq(p^5, modulus=x^5+x+4, names='a', ram_name='p', print_pos=False, check=True) + sage: K = Qq(p^5, modulus=x^5+x+4, names='a', ram_name='p', + ....: print_pos=False, check=True) took an average of 24.5ms. Of course, with smaller primes these savings disappear. @@ -1368,7 +1384,7 @@ def QpCR(p, prec = None, *args, **kwds): r""" A shortcut function to create capped relative `p`-adic fields. - Same functionality as ``Qp``. See documentation for ``Qp`` for a + Same functionality as :func:`Qp`. See documentation for :func:`Qp` for a description of the input parameters. EXAMPLES:: @@ -1382,7 +1398,7 @@ def QpFP(p, prec = None, *args, **kwds): r""" A shortcut function to create floating point `p`-adic fields. - Same functionality as ``Qp``. See documentation for ``Qp`` for a + Same functionality as :func:`Qp`. See documentation for :func:`Qp` for a description of the input parameters. EXAMPLES:: @@ -1397,7 +1413,7 @@ def QqCR(q, prec = None, *args, **kwds): A shortcut function to create capped relative unramified `p`-adic fields. - Same functionality as ``Qq``. See documentation for ``Qq`` for a + Same functionality as :func:`Qq`. See documentation for :func:`Qq` for a description of the input parameters. EXAMPLES:: @@ -1412,7 +1428,7 @@ def QqFP(q, prec = None, *args, **kwds): A shortcut function to create floating point unramified `p`-adic fields. - Same functionality as ``Qq``. See documentation for ``Qq`` for a + Same functionality as :func:`Qq`. See documentation for :func:`Qq` for a description of the input parameters. EXAMPLES:: @@ -1486,22 +1502,22 @@ class Zp_class(UniqueFactory): - ``prec`` -- integer (default: ``20``) the precision cap of the ring. In the lattice capped case, ``prec`` can either be a pair (``relative_cap``, ``absolute_cap``) or an integer - (understood at relative cap). + (understood as relative cap). In the relaxed case, ``prec`` can be either a pair (``default_prec``, ``halting_prec``) or an integer - (understood at default precision). + (understood as default precision). Except for the fixed modulus and floating point cases, individual elements keep track of their own precision. See TYPES and PRECISION below. - ``type`` -- string (default: ``'capped-rel'``) Valid types are ``'capped-rel'``, ``'capped-abs'``, ``'fixed-mod'``, - ``'floating-point'``, ``'lattice-cap'``, ``'lattice-float'``, ``'relaxed'`` - See TYPES and PRECISION below + ``'floating-point'``, ``'lattice-cap'``, ``'lattice-float'``, ``'relaxed'``. + See TYPES and PRECISION below. - ``print_mode`` -- string (default: ``None``). Valid modes are ``'series'``, ``'val-unit'``, ``'terse'``, ``'digits'``, and - ``'bars'``. See PRINTING below + ``'bars'``. See PRINTING below. - ``names`` -- string or tuple (defaults to a string representation of `p`). What to use whenever `p` is printed. @@ -1630,7 +1646,7 @@ class Zp_class(UniqueFactory): There are many different ways to print `p`-adic elements. The way elements of a given ring print is controlled by options passed in at the creation of the ring. There are five basic - printing modes (series, val-unit, terse, digits and bars), as + printing modes (``'series'``, ``'val-unit'``, ``'terse'``, ``'digits'`` and ``'bars'``), as well as various options that either hide some information in the print representation or sometimes make print representations more compact. Note that the printing options @@ -1641,7 +1657,9 @@ class Zp_class(UniqueFactory): sage: R = Zp(5, print_mode='series'); a = R(70700); a 3*5^2 + 3*5^4 + 2*5^5 + 4*5^6 + O(5^22) sage: b = R(-70700); b - 2*5^2 + 4*5^3 + 5^4 + 2*5^5 + 4*5^7 + 4*5^8 + 4*5^9 + 4*5^10 + 4*5^11 + 4*5^12 + 4*5^13 + 4*5^14 + 4*5^15 + 4*5^16 + 4*5^17 + 4*5^18 + 4*5^19 + 4*5^20 + 4*5^21 + O(5^22) + 2*5^2 + 4*5^3 + 5^4 + 2*5^5 + 4*5^7 + 4*5^8 + 4*5^9 + 4*5^10 + 4*5^11 + + 4*5^12 + 4*5^13 + 4*5^14 + 4*5^15 + 4*5^16 + 4*5^17 + 4*5^18 + + 4*5^19 + 4*5^20 + 4*5^21 + O(5^22) *print_pos* controls whether negatives can be used in the coefficients of powers of `p`. :: @@ -1768,12 +1786,13 @@ class Zp_class(UniqueFactory): greater than 9. Defaults to ('0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z'):: - sage: T = Zp(5, print_mode='digits', print_alphabet=('1','2','3','4','5')); repr(T(-70700)) + sage: T = Zp(5, print_mode='digits', print_alphabet=('1','2','3','4','5')) + sage: repr(T(-70700)) '...5555555555555551325311' *show_prec* determines how the precision is printed. - It can be either 'none' (or equivalently ``False``), 'dots' - (or equivalently ``True``) or 'bigoh'. + It can be either ``'none'`` (or equivalently ``False``), ``'dots'`` + (or equivalently ``True``) or ``'bigoh'``. The default is ``False`` for the ``'floating-point'`` and ``'fixed-mod'`` types and ``True`` for all other types. :: @@ -1802,7 +1821,7 @@ class Zp_class(UniqueFactory): *print_pos* controls whether the digits can be negative. :: - sage: S = Zp(5, print_mode='bars',print_pos=False); b = S(-70700); repr(b) + sage: S = Zp(5, print_mode='bars', print_pos=False); b = S(-70700); repr(b) '...-1|0|2|2|-1|2|0|0' *print_max_terms* limits the number of digits that are printed. :: @@ -1835,7 +1854,7 @@ class Zp_class(UniqueFactory): EXAMPLES: - We allow non-prime `p`, but only if ``check = False``. Note that some + We allow non-prime `p`, but only if ``check=False``. Note that some features will not work. :: sage: K = Zp(15, check=False); a = K(999); a @@ -1857,7 +1876,8 @@ class Zp_class(UniqueFactory): It works even with a fairly huge cap:: sage: Zp(next_prime(10^50), 100000) - 100000000000000000000000000000000000000000000000151-adic Ring with capped relative precision 100000 + 100000000000000000000000000000000000000000000000151-adic Ring + with capped relative precision 100000 We create each type of ring:: @@ -1917,7 +1937,7 @@ def create_key(self, p, prec = None, type = 'capped-rel', print_mode = None, r""" Creates a key from input parameters for ``Zp``. - See the documentation for ``Zp`` for more information. + See the documentation for :func:`Zp` for more information. TESTS:: @@ -1955,7 +1975,7 @@ def create_object(self, version, key): r""" Creates an object using a given key. - See the documentation for ``Zp`` for more information. + See the documentation for :func:`Zp` for more information. TESTS:: @@ -2025,7 +2045,7 @@ def Zq(q, prec = None, type = 'capped-rel', modulus = None, names=None, INPUT: - ``q`` -- integer, list or tuple: the prime power in `\QQ_q`. Or a - factorization object, single element list ``[(p, n)]`` where ``p`` is + :class:`Factorization` object, single element list ``[(p, n)]`` where ``p`` is a prime and ``n`` a positive integer, or the pair ``(p, n)``. - ``prec`` -- integer (default: ``20``) the precision cap of the @@ -2034,9 +2054,9 @@ def Zq(q, prec = None, type = 'capped-rel', modulus = None, names=None, - ``type`` -- string (default: ``'capped-rel'``) Valid types are ``'capped-abs'``, ``'capped-rel'``, ``'fixed-mod'``, and - ``'floating-point'``. See TYPES and PRECISION below + ``'floating-point'``. See TYPES and PRECISION below. - - modulus -- polynomial (default None) A polynomial defining an + - ``modulus`` -- polynomial (default None) A polynomial defining an unramified extension of `\ZZ_p`. See MODULUS below. - ``names`` -- string or tuple (``None`` is only allowed when @@ -2047,12 +2067,12 @@ def Zq(q, prec = None, type = 'capped-rel', modulus = None, names=None, ``'val-unit'``, ``'terse'``, and ``'bars'``. See PRINTING below. - ``ram_name`` -- string (defaults to string representation of `p` if - None). ``ram_name`` controls how the prime is printed. See PRINTING + ``None``). ``ram_name`` controls how the prime is printed. See PRINTING below. - ``res_name`` -- string (defaults to ``None``, which corresponds to adding a ``'0'`` to the end of the name). Controls how - elements of the reside field print. + elements of the residue field print. - ``print_pos`` -- bool (default ``None``) Whether to only use positive integers in the representations of elements. See @@ -2077,12 +2097,12 @@ def Zq(q, prec = None, type = 'capped-rel', modulus = None, names=None, - ``check`` -- bool (default ``True``) whether to check inputs. - - ``implementation`` -- string (default ``FLINT``) which - implementation to use. ``NTL`` is the other option. + - ``implementation`` -- string (default ``'FLINT'``) which + implementation to use. ``'NTL'`` is the other option. OUTPUT: - - The corresponding unramified `p`-adic ring. + The corresponding unramified `p`-adic ring. TYPES AND PRECISION: @@ -2284,7 +2304,7 @@ def Zq(q, prec = None, type = 'capped-rel', modulus = None, names=None, '(...)*2 + (...)*2^2 + (...)*2^3 + (...)*2^4 + (...)*2^5 + (...)*2^6 + (...)*2^7 + O(2^8)' *show_prec* determines how the precision is printed. - It can be either 'none' (or equivalently ``False``), 'bigoh' + It can be either ``'none'`` (or equivalently ``False``), ``'bigoh'`` (or equivalently ``True``). The default is ``False`` for the ``'floating-point'`` and ``'fixed-mod'`` types and ``True`` for all other types. :: @@ -2317,19 +2337,23 @@ def Zq(q, prec = None, type = 'capped-rel', modulus = None, names=None, *ram_name* affects how the prime is printed. :: sage: A. = Zp(next_prime(10^6), print_mode='val-unit')[] - sage: T. = Zq(next_prime(10^6)^3, 4, print_mode='val-unit', ram_name='p', modulus=x^3+385831*x^2+106556*x+321036); b = (next_prime(10^6)^2*(a^2 + a - 4)^4); b - p^2 * (87996187118837557387483 + 246348888344392418464080*a + 1353538653775332610349*a^2) + O(p^6) + sage: T. = Zq(next_prime(10^6)^3, 4, print_mode='val-unit', ram_name='p', + ....: modulus=x^3+385831*x^2+106556*x+321036) + sage: b = next_prime(10^6)^2*(a^2 + a - 4)^4; b + p^2 * (87996187118837557387483 + 246348888344392418464080*a + 1353538653775332610349*a^2) + + O(p^6) sage: b * (a^2 + a - 4)^-4 p^2 * 1 + O(p^6) *print_max_terse_terms* controls how many terms of the polynomial appear in the unit part. :: - sage: U. = Zq(17^4, 6, print_mode='val-unit', print_max_terse_terms=3); b = (17*(a^3-a+14)^6); b + sage: U. = Zq(17^4, 6, print_mode='val-unit', print_max_terse_terms=3) + sage: b = 17*(a^3-a+14)^6; b 17 * (12131797 + 12076378*a + 10809706*a^2 + ...) + O(17^7) *show_prec* determines how the precision is printed. - It can be either 'none' (or equivalently ``False``), 'bigoh' + It can be either ``'none'`` (or equivalently ``False``), ``'bigoh'`` (or equivalently ``True``). The default is ``False`` for the ``'floating-point'`` and ``'fixed-mod'`` types and ``True`` for all other types. :: @@ -2386,7 +2410,7 @@ def Zq(q, prec = None, type = 'capped-rel', modulus = None, names=None, 106251/5^6 + 49994/5^5*a + ... + O(5^14) *show_prec* determines how the precision is printed. - It can be either 'none' (or equivalently ``False``), 'bigoh' + It can be either ``'none'`` (or equivalently ``False``), ``'bigoh'`` (or equivalently ``True``). The default is ``False`` for the ``'floating-point'`` and ``'fixed-mod'`` types and ``True`` for all other types. :: @@ -2410,7 +2434,8 @@ def Zq(q, prec = None, type = 'capped-rel', modulus = None, names=None, but more compactly. :: sage: R. = Zq(125); (a+5)^6 - (4*a^2 + 3*a + 4) + (3*a^2 + 2*a)*5 + (a^2 + a + 1)*5^2 + (3*a + 2)*5^3 + (3*a^2 + a + 3)*5^4 + (2*a^2 + 3*a + 2)*5^5 + O(5^20) + (4*a^2 + 3*a + 4) + (3*a^2 + 2*a)*5 + (a^2 + a + 1)*5^2 + (3*a + 2)*5^3 + + (3*a^2 + a + 3)*5^4 + (2*a^2 + 3*a + 2)*5^5 + O(5^20) sage: R. = Zq(125, print_mode='bars', prec=8); repr((a+5)^6) '...[2, 3, 2]|[3, 1, 3]|[2, 3]|[1, 1, 1]|[0, 2, 3]|[4, 3, 4]' sage: repr((a-5)^6) @@ -2464,8 +2489,8 @@ def Zq(q, prec = None, type = 'capped-rel', modulus = None, names=None, '...[...][...][...][...][][...][...]' *show_prec* determines how the precision is printed. - It can be either 'none' (or equivalently ``False``), 'dots' - (or equivalently ``True``) or 'bigoh'. + It can be either ``'none'`` (or equivalently ``False``), ``'dots'`` + (or equivalently ``True``) or ``'bigoh'``. The default is ``False`` for the ``'floating-point'`` and ``'fixed-mod'`` types and ``True`` for all other types. :: @@ -2481,7 +2506,7 @@ def Zq(q, prec = None, type = 'capped-rel', modulus = None, names=None, EXAMPLES: - Unlike for ``Zp``, you can't create ``Zq(N)`` when ``N`` is not a prime power. + Unlike for :func:`Zp`, you can't create ``Zq(N)`` when ``N`` is not a prime power. However, you can use ``check=False`` to pass in a pair in order to not have to factor. If you do so, you need to use names explicitly @@ -2490,14 +2515,16 @@ def Zq(q, prec = None, type = 'capped-rel', modulus = None, names=None, sage: p = next_prime(2^123) sage: k = Zp(p) sage: R. = k[] - sage: K = Zq([(p, 5)], modulus=x^5+x+4, names='a', ram_name='p', print_pos=False, check=False) + sage: K = Zq([(p, 5)], modulus=x^5+x+4, names='a', ram_name='p', + ....: print_pos=False, check=False) sage: K.0^5 (-a - 4) + O(p^20) In tests on sage.math, the creation of ``K`` as above took an average of 1.58ms, while:: - sage: K = Zq(p^5, modulus=x^5+x+4, names='a', ram_name='p', print_pos=False, check=True) + sage: K = Zq(p^5, modulus=x^5+x+4, names='a', ram_name='p', + ....: print_pos=False, check=True) took an average of 24.5ms. Of course, with smaller primes these savings disappear. @@ -2576,7 +2603,7 @@ def ZpCR(p, prec = None, *args, **kwds): r""" A shortcut function to create capped relative `p`-adic rings. - Same functionality as ``Zp``. See documentation for ``Zp`` for a + Same functionality as :func:`Zp`. See documentation for :func:`Zp` for a description of the input parameters. EXAMPLES:: @@ -2616,7 +2643,7 @@ def ZpFP(p, prec = None, *args, **kwds): r""" A shortcut function to create floating point `p`-adic rings. - Same functionality as ``Zp``. See documentation for ``Zp`` for a + Same functionality as :func:`Zp`. See documentation for :func:`Zp` for a description of the input parameters. EXAMPLES:: @@ -2630,7 +2657,7 @@ def ZqCR(q, prec = None, *args, **kwds): r""" A shortcut function to create capped relative unramified `p`-adic rings. - Same functionality as ``Zq``. See documentation for ``Zq`` for a + Same functionality as :func:`Zq`. See documentation for :func:`Zq` for a description of the input parameters. EXAMPLES:: @@ -2670,7 +2697,7 @@ def ZqFP(q, prec = None, *args, **kwds): r""" A shortcut function to create floating point unramified `p`-adic rings. - Same functionality as ``Zq``. See documentation for ``Zq`` for a + Same functionality as :func:`Zq`. See documentation for :func:`Zq` for a description of the input parameters. EXAMPLES:: @@ -3110,7 +3137,7 @@ def ZpER(p, prec=None, halt=None, secure=False, *args, **kwds): sage: a == aa False - This annoying situation, where the output of `a == aa` may change + This annoying situation, where the output of ``a == aa`` may change depending on previous computations, cannot occur when the parent is created with ``secure=True``. Indeed, in this case, if the equality cannot be decided, an error @@ -3202,7 +3229,7 @@ class pAdicExtension_class(UniqueFactory): sage: R = Zp(5,3) sage: S. = ZZ[] - sage: W. = pAdicExtension(R, x^4-15) + sage: W. = pAdicExtension(R, x^4 - 15) sage: W 5-adic Eisenstein Extension Ring in w defined by x^4 - 15 sage: W.precision_cap() @@ -3215,9 +3242,9 @@ def create_key_and_extra_args(self, base, modulus, prec = None, print_mode = Non print_max_unram_terms = None, print_max_terse_terms = None, show_prec = None, check = True, unram = False, implementation='FLINT'): r""" - Creates a key from input parameters for pAdicExtension. + Creates a key from input parameters for :class:`pAdicExtension`. - See the documentation for ``Qq`` for more information. + See the documentation for :func:`Qq` for more information. TESTS:: @@ -3362,7 +3389,7 @@ def create_object(self, version, key, approx_modulus=None, shift_seed=None): r""" Creates an object using a given key. - See the documentation for pAdicExtension for more information. + See the documentation for :class:`pAdicExtension` for more information. TESTS:: @@ -3425,11 +3452,12 @@ def split(poly, prec): sage: k = Qp(13) sage: x = polygen(k) - sage: f = x^2+1 + sage: f = x^2 + 1 sage: sage.rings.padics.factory.split(f, 10) Traceback (most recent call last): ... - NotImplementedError: Extensions by general polynomials not yet supported. Please use an unramified or Eisenstein polynomial. + NotImplementedError: Extensions by general polynomials not yet supported. + Please use an unramified or Eisenstein polynomial. TESTS: @@ -3463,24 +3491,24 @@ def truncate_to_prec(poly, R, absprec): def krasner_check(poly, prec): r""" - Returns True iff poly determines a unique isomorphism class of - extensions at precision prec. + Return ``True`` iff ``poly`` determines a unique isomorphism class of + extensions at precision ``prec``. - Currently just returns True (thus allowing extensions that are not + Currently just returns ``True`` (thus allowing extensions that are not defined to high enough precision in order to specify them up to isomorphism). This will change in the future. EXAMPLES:: sage: from sage.rings.padics.factory import krasner_check - sage: krasner_check(1,2) #this is a stupid example. + sage: krasner_check(1,2) # this is a stupid example. True """ return True #This needs to be implemented def is_eisenstein(poly): r""" - Returns True iff this monic polynomial is Eisenstein. + Return ``True`` iff this monic polynomial is Eisenstein. A polynomial is Eisenstein if it is monic, the constant term has valuation 1 and all other terms have positive valuation. @@ -3508,7 +3536,7 @@ def is_eisenstein(poly): def is_unramified(poly): r""" - Returns true iff this monic polynomial is unramified. + Return ``True`` iff this monic polynomial is unramified. A polynomial is unramified if its reduction modulo the maximal ideal is irreducible. diff --git a/src/sage/rings/padics/generic_nodes.py b/src/sage/rings/padics/generic_nodes.py index f84a5387b2a..062bc28d8f8 100644 --- a/src/sage/rings/padics/generic_nodes.py +++ b/src/sage/rings/padics/generic_nodes.py @@ -272,7 +272,7 @@ class pAdicLatticeGeneric(pAdicGeneric): INPUT: - - `p` -- the underlying prime number + - ``p`` -- the underlying prime number - ``prec`` -- the precision @@ -616,7 +616,7 @@ def convert_multiple(self, *elts): 6 As a consequence, if we convert ``x`` and ``y`` separately, we - loose some precision:: + lose some precision:: sage: R2 = ZpLC(2, label='copy') sage: x2 = R2(x); y2 = R2(y) @@ -706,7 +706,7 @@ class pAdicRelaxedGeneric(pAdicGeneric): INPUT: - - `p` -- the underlying prime number + - ``p`` -- the underlying prime number - ``prec`` -- the default precision @@ -777,7 +777,7 @@ def is_relaxed(self): def is_secure(self): r""" Return ``False`` if this `p`-adic relaxed ring is not secure - (i.e. if indistinguishable elements at the working precision + (i.e., if indistinguishable elements at the working precision are considered as equal); ``True`` otherwise (in which case, an error is raised when equality cannot be decided). @@ -1135,7 +1135,8 @@ def random_element(self, integral=False, prec=None): sage: b = R.random_element(prec=15) sage: b # random - 2 + 3*5^2 + 5^3 + 3*5^4 + 5^5 + 3*5^6 + 3*5^8 + 3*5^9 + 4*5^10 + 5^11 + 4*5^12 + 5^13 + 2*5^14 + O(5^15) + 2 + 3*5^2 + 5^3 + 3*5^4 + 5^5 + 3*5^6 + 3*5^8 + 3*5^9 + 4*5^10 + + 5^11 + 4*5^12 + 5^13 + 2*5^14 + O(5^15) sage: b.precision_absolute() 15 """ @@ -1393,11 +1394,11 @@ class pAdicFloatingPointFieldGeneric(pAdicFieldGeneric, FloatingPointFieldGeneri class pAdicRingBaseGeneric(pAdicBaseGeneric, pAdicRingGeneric): def construction(self, forbid_frac_field=False): """ - Return the functorial construction of self, namely, - completion of the rational numbers with respect a given prime. + Return the functorial construction of ``self``, namely, + completion of the rational numbers with respect to a given prime. Also preserves other information that makes this field unique - (e.g. precision, rounding, print mode). + (e.g., precision, rounding, print mode). INPUT: @@ -1441,11 +1442,11 @@ def construction(self, forbid_frac_field=False): def random_element(self, algorithm='default'): r""" - Return a random element of self, optionally using the - algorithm argument to decide how it generates the + Return a random element of ``self``, optionally using the + ``algorithm`` argument to decide how it generates the element. Algorithms currently implemented: - - default: Choose `a_i`, `i >= 0`, randomly between `0` and + - ``'default'``: Choose `a_i`, `i \geq 0`, randomly between `0` and `p-1` until a nonzero choice is made. Then continue choosing `a_i` randomly between `0` and `p-1` until we reach precision_cap, and return `\sum a_i p^i`. @@ -1484,7 +1485,7 @@ def random_element(self, algorithm='default'): class pAdicFieldBaseGeneric(pAdicBaseGeneric, pAdicFieldGeneric): def composite(self, subfield1, subfield2): r""" - Return the composite of two subfields of self, i.e., the + Return the composite of two subfields of ``self``, i.e., the largest subfield containing both INPUT: @@ -1495,7 +1496,7 @@ def composite(self, subfield1, subfield2): OUTPUT: - - the composite of subfield1 and subfield2 + the composite of ``subfield1`` and ``subfield2`` EXAMPLES:: @@ -1509,7 +1510,7 @@ def composite(self, subfield1, subfield2): def subfields_of_degree(self, n): r""" - Return the number of subfields of self of degree `n` + Return the number of subfields of ``self`` of degree `n` INPUT: @@ -1518,7 +1519,7 @@ def subfields_of_degree(self, n): OUTPUT: - - integer -- the number of subfields of degree ``n`` over self.base_ring() + integer -- the number of subfields of degree `n` over ``self.base_ring()`` EXAMPLES:: @@ -1533,7 +1534,7 @@ def subfields_of_degree(self, n): def subfield(self, list): r""" - Return the subfield generated by the elements in list + Return the subfield generated by the elements in ``list`` INPUT: @@ -1542,7 +1543,7 @@ def subfield(self, list): OUTPUT: - - the subfield of ``self`` generated by the elements of list + the subfield of ``self`` generated by the elements of ``list`` EXAMPLES:: @@ -1560,7 +1561,7 @@ def construction(self, forbid_frac_field=False): completion of the rational numbers with respect a given prime. Also preserves other information that makes this field unique - (e.g. precision, rounding, print mode). + (e.g., precision, rounding, print mode). INPUT: diff --git a/src/sage/rings/padics/lattice_precision.py b/src/sage/rings/padics/lattice_precision.py index 810d9de650c..c855e3bd25c 100644 --- a/src/sage/rings/padics/lattice_precision.py +++ b/src/sage/rings/padics/lattice_precision.py @@ -60,7 +60,7 @@ class pRational: r""" This class implements rational numbers viewed as elements of ``Qp``. In particular, it provides additional methods which are specific to - ``p``-adics (as ``p``-adic valuation). + `p`-adics (as `p`-adic valuation). Only for internal use. @@ -72,8 +72,8 @@ class pRational: - ``exponent`` -- an integer (default: 0) - - ``valuation`` -- an integer or None (default: ``None``), - the ``p``-adic valuation of this element + - ``valuation`` -- an integer or ``None`` (default: ``None``), + the `p`-adic valuation of this element If not ``None``, this method trusts the given value to the attribute ``valuation``. @@ -259,7 +259,7 @@ def valuation(self): def is_p_power(self): r""" - Return true if this element is a power of `p`. + Return ``True`` if this element is a power of `p`. TESTS:: @@ -279,7 +279,7 @@ def is_p_power(self): def is_zero(self): r""" - Return true if this element vanishes. + Return ``True`` if this element vanishes. TESTS:: @@ -503,7 +503,7 @@ def unit_part(self): def xgcd(self, other): r""" Return the gcd of ``self`` and ``other`` together with two - element ``u`` and ``v`` such that ``u*self + v*other = gcd``. + elements ``u`` and ``v`` such that ``u*self + v*other = gcd``. The ``gcd`` is normalized so that it is a power of `p`. @@ -1483,20 +1483,20 @@ def timings(self, action=None): INPUT: - - ``action`` -- ``None`` (the default), ``add``, ``mark``, ``del``, - ``partial reduce`` or ``full reduce``; if not None, return the + - ``action`` -- ``None`` (the default), ``'add'``, ``'mark'``, ``'del'``, + ``'partial reduce'`` or ``'full reduce'``; if not ``None``, return the cumulated timing corresponding to this action; otherwise, return a dictionary Here are the meanings of the keywords above: - - ``add``: time spent in adding new columns to the precision matrix + - ``'add'``: time spent in adding new columns to the precision matrix (corresponding to the creation of new elements) - - ``mark``: time spent in marking elements for deletion - - ``del``: time spent in deleting columns of the precision matrix + - ``'mark'``: time spent in marking elements for deletion + - ``'del'``: time spent in deleting columns of the precision matrix and re-echelonizing the matrix - - ``partial reduce``: time spent in partial Hermite reduction - - ``full reduce``: time spent in full Hermite reduction. + - ``'partial reduce'``: time spent in partial Hermite reduction + - ``'full reduce'``: time spent in full Hermite reduction. EXAMPLES:: @@ -2860,8 +2860,8 @@ def __repr__(self): def list_of_padics(elements): r""" - Convert a list of p-adic composed elements (such as polynomials, matrices) - to a list of weak references of their p-adic coefficients. + Convert a list of `p`-adic composed elements (such as polynomials, matrices) + to a list of weak references of their `p`-adic coefficients. This is a helper function for the method :meth:`precision_lattice`. diff --git a/src/sage/rings/padics/local_generic.py b/src/sage/rings/padics/local_generic.py index 6db8866aff8..83d77282c2a 100644 --- a/src/sage/rings/padics/local_generic.py +++ b/src/sage/rings/padics/local_generic.py @@ -1,3 +1,4 @@ +# sage.doctest: optional - sage.rings.padics r""" Local Generic diff --git a/src/sage/rings/padics/local_generic_element.pyx b/src/sage/rings/padics/local_generic_element.pyx index e7b9ba76b80..8df39a52363 100644 --- a/src/sage/rings/padics/local_generic_element.pyx +++ b/src/sage/rings/padics/local_generic_element.pyx @@ -1,4 +1,4 @@ -# -*- coding: utf-8 -*- +# sage.doctest: optional - sage.rings.padics """ Local Generic Element diff --git a/src/sage/rings/padics/misc.py b/src/sage/rings/padics/misc.py index 71f9e80ed99..d3c3a72083d 100644 --- a/src/sage/rings/padics/misc.py +++ b/src/sage/rings/padics/misc.py @@ -71,9 +71,9 @@ def gauss_sum(a, p, f, prec=20, factored=False, algorithm='pari', parent=None): - ``prec`` -- positive integer (optional, 20 by default) - - ``factored`` - boolean (optional, False by default) + - ``factored`` -- boolean (optional, ``False`` by default) - - ``algorithm`` - flag passed to p-adic Gamma function (optional, "pari" by default) + - ``algorithm`` -- flag passed to p-adic Gamma function (optional, ``"pari"`` by default) OUTPUT: @@ -91,25 +91,25 @@ def gauss_sum(a, p, f, prec=20, factored=False, algorithm='pari', parent=None): In this example, we verify that `g_3(0) = -1`:: sage: from sage.rings.padics.misc import gauss_sum - sage: -gauss_sum(0,3,1) + sage: -gauss_sum(0, 3, 1) # optional - sage.rings.padics 1 + O(pi^40) Next, we verify that `g_5(a) g_5(-a) = 5 (-1)^a`:: sage: from sage.rings.padics.misc import gauss_sum - sage: gauss_sum(2,5,1)^2-5 + sage: gauss_sum(2,5,1)^2 - 5 # optional - sage.rings.padics O(pi^84) - sage: gauss_sum(1,5,1)*gauss_sum(3,5,1)+5 + sage: gauss_sum(1,5,1)*gauss_sum(3,5,1) + 5 # optional - sage.rings.padics O(pi^84) Finally, we compute a non-trivial value:: sage: from sage.rings.padics.misc import gauss_sum - sage: gauss_sum(2,13,2) + sage: gauss_sum(2,13,2) # optional - sage.rings.padics 6*pi^2 + 7*pi^14 + 11*pi^26 + 3*pi^62 + 6*pi^74 + 3*pi^86 + 5*pi^98 + pi^110 + 7*pi^134 + 9*pi^146 + 4*pi^158 + 6*pi^170 + 4*pi^194 + pi^206 + 6*pi^218 + 9*pi^230 + O(pi^242) - sage: gauss_sum(2,13,2,prec=5,factored=True) + sage: gauss_sum(2,13,2, prec=5, factored=True) # optional - sage.rings.padics (2, 6 + 6*13 + 10*13^2 + O(13^5)) .. SEEALSO:: diff --git a/src/sage/rings/padics/morphism.pyx b/src/sage/rings/padics/morphism.pyx index 407bc146990..ab64f3c5cae 100644 --- a/src/sage/rings/padics/morphism.pyx +++ b/src/sage/rings/padics/morphism.pyx @@ -29,13 +29,13 @@ from sage.categories.morphism cimport Morphism cdef class FrobeniusEndomorphism_padics(RingHomomorphism): """ - A class implementing Frobenius endomorphisms on padic fields. + A class implementing Frobenius endomorphisms on p-adic fields. """ def __init__ (self,domain,n=1): """ INPUT: - - ``domain`` -- an unramified padic field + - ``domain`` -- an unramified p-adic field - ``n`` -- an integer (default: 1) @@ -271,8 +271,8 @@ cdef class FrobeniusEndomorphism_padics(RingHomomorphism): def is_injective(self): """ - Return true since any power of the Frobenius endomorphism - over an unramified padic field is always injective. + Return ``True`` since any power of the Frobenius endomorphism + over an unramified p-adic field is always injective. EXAMPLES:: @@ -286,8 +286,8 @@ cdef class FrobeniusEndomorphism_padics(RingHomomorphism): def is_surjective(self): """ - Return true since any power of the Frobenius endomorphism - over an unramified padic field is always surjective. + Return ``True`` since any power of the Frobenius endomorphism + over an unramified p-adic field is always surjective. EXAMPLES:: @@ -301,7 +301,7 @@ cdef class FrobeniusEndomorphism_padics(RingHomomorphism): def is_identity(self): """ - Return true if this morphism is the identity morphism. + Return ``True`` if this morphism is the identity morphism. EXAMPLES:: @@ -335,7 +335,7 @@ cdef class FrobeniusEndomorphism_padics(RingHomomorphism): cpdef _richcmp_(left, right, int op): """ - Compare ``left'' and ``right'' + Compare ``left`` and ``right`` EXAMPLES:: diff --git a/src/sage/rings/padics/padic_ZZ_pX_CA_element.pyx b/src/sage/rings/padics/padic_ZZ_pX_CA_element.pyx index a159aa14c9b..ce11925e3a1 100644 --- a/src/sage/rings/padics/padic_ZZ_pX_CA_element.pyx +++ b/src/sage/rings/padics/padic_ZZ_pX_CA_element.pyx @@ -56,7 +56,7 @@ element contains the following data: ``prime_pow.get_top_context`` -- obtain an ``ntl_ZZ_pContext_class`` corresponding to `p^n`. The capdiv version divides by ``prime_pow.e`` as appropriate. - ``top_context`` corresponds to `p^{prec_cap}`. + ``top_context`` corresponds to `p^{\texttt{prec\_cap}}`. + ``prime_pow.restore_context``, ``prime_pow.restore_context_capdiv``, diff --git a/src/sage/rings/padics/padic_ZZ_pX_CR_element.pyx b/src/sage/rings/padics/padic_ZZ_pX_CR_element.pyx index 3d744acd62c..82982a40045 100644 --- a/src/sage/rings/padics/padic_ZZ_pX_CR_element.pyx +++ b/src/sage/rings/padics/padic_ZZ_pX_CR_element.pyx @@ -10,14 +10,14 @@ r""" This file implements elements of Eisenstein and unramified extensions of `\ZZ_p` and `\QQ_p` with capped relative precision. -For the parent class see padic_extension_leaves.pyx. +For the parent class see :mod:`sage.rings.padics.padic_extension_leaves`. The underlying implementation is through NTL's ``ZZ_pX`` class. Each element contains the following data: - ``ordp`` (``long``) -- A power of the uniformizer to scale the unit by. For unramified extensions this uniformizer is `p`, for Eisenstein - extensions it is not. A value equal to the maximum value of a long + extensions it is not. A value equal to the maximum value of a ``long`` indicates that the element is an exact zero. - ``relprec`` (``long``) -- A signed integer giving the precision to @@ -39,14 +39,14 @@ element contains the following data: may not actually be a unit. This ``ZZ_pX`` is created with global ntl modulus determined by the absolute value of ``relprec``. If ``relprec`` is 0, ``unit`` **is not initialized**, or destructed if - normalized and found to be zero. Otherwise, let `r` be relprec and + normalized and found to be zero. Otherwise, let `r` be ``relprec`` and `e` be the ramification index over `\QQ_p` or `\ZZ_p`. Then the modulus of unit is given by `p^{ceil(r/e)}`. Note that all kinds of problems arise if you try to mix moduli. ``ZZ_pX_conv_modulus`` gives a semi-safe way to convert between different moduli without having to pass through ``ZZX``. -- ``prime_pow`` (some subclass of ``PowComputer_ZZ_pX``) -- a class, +- ``prime_pow`` (some subclass of :class:`PowComputer_ZZ_pX`) -- a class, identical among all elements with the same parent, holding common data. @@ -57,7 +57,7 @@ element contains the following data: + ``prime_pow.f`` -- The inertia degree + ``prime_pow.prec_cap`` -- the unramified precision cap. For - Eisenstein extensions this is the smallest power of p that is + Eisenstein extensions this is the smallest power of `p` that is zero. + ``prime_pow.ram_prec_cap`` -- the ramified precision cap. For @@ -67,14 +67,14 @@ element contains the following data: + ``prime_pow.pow_ZZ_tmp``, prime_pow.pow_mpz_t_tmp``, ``prime_pow.pow_Integer`` -- functions for accessing powers of `p`. The first two return pointers. See - ``sage/rings/padics/pow_computer_ext`` for examples and important + :mod:`sage.rings.padics.pow_computer_ext` for examples and important warnings. + ``prime_pow.get_context``, ``prime_pow.get_context_capdiv``, ``prime_pow.get_top_context`` -- obtain an ``ntl_ZZ_pContext_class`` corresponding to `p^n`. The capdiv version divides by ``prime_pow.e`` as appropriate. - ``top_context`` corresponds to `p^{prec_cap}`. + ``top_context`` corresponds to `p^{\texttt{prec\_cap}}`. + ``prime_pow.restore_context``, ``prime_pow.restore_context_capdiv``, @@ -726,7 +726,7 @@ cdef class pAdicZZpXCRElement(pAdicZZpXElement): cdef int _set_from_mpz_rel(self, mpz_t x, long relprec) except -1: """ - Sets ``self`` from an ``mpz_t`` with relative precision bounded by ``relprec``. + Set ``self`` from an ``mpz_t`` with relative precision bounded by ``relprec``. EXAMPLES:: @@ -772,7 +772,7 @@ cdef class pAdicZZpXCRElement(pAdicZZpXElement): cdef int _set_from_mpz_both(self, mpz_t x, long absprec, long relprec) except -1: """ - Sets ``self`` from an ``mpz_t`` with relative precision bounded by ``relprec`` + Set ``self`` from an ``mpz_t`` with relative precision bounded by ``relprec`` and absolute precision bounded by ``absprec``. EXAMPLES:: @@ -1256,7 +1256,7 @@ cdef class pAdicZZpXCRElement(pAdicZZpXElement): If ``relprec`` is negative, will set ``self.relprec`` to be negative (indicating unnormalized unit) - Returns`` True`` iff ``self.relprec = 0``, ie ``self`` was set to an + Returns ``True`` iff ``self.relprec = 0``, ie ``self`` was set to an inexact zero. Note that this will wipe out anything in ``self.unit``. Be @@ -1538,7 +1538,7 @@ cdef class pAdicZZpXCRElement(pAdicZZpXElement): cdef int _cmp_units(left, pAdicGenericElement right) except -2: """ - For units ``left`` and ``right``, returns 0 if they are equal up to + For units ``left`` and ``right``, return 0 if they are equal up to the lesser of the two precisions, or 1 if they are not. EXAMPLES:: @@ -2056,7 +2056,7 @@ cdef class pAdicZZpXCRElement(pAdicZZpXElement): cpdef _add_(self, _right): """ - Computes the sum of ``self`` and ``right``. + Compute the sum of ``self`` and ``right``. EXAMPLES:: @@ -2350,7 +2350,7 @@ cdef class pAdicZZpXCRElement(pAdicZZpXElement): is indistinguishable from zero. If this element is an inexact zero of valuation less than ``absprec``, - raises a ``PrecisionError``. + raises a :class:`PrecisionError`. EXAMPLES:: @@ -2660,9 +2660,11 @@ cdef class pAdicZZpXCRElement(pAdicZZpXElement): sage: a = W(345, 17); a 4*w^5 + 3*w^7 + w^9 + 3*w^10 + 2*w^11 + 4*w^12 + w^13 + 2*w^14 + 2*w^15 + O(w^17) sage: b = a.lift_to_precision(19); b - 4*w^5 + 3*w^7 + w^9 + 3*w^10 + 2*w^11 + 4*w^12 + w^13 + 2*w^14 + 2*w^15 + w^17 + 2*w^18 + O(w^19) + 4*w^5 + 3*w^7 + w^9 + 3*w^10 + 2*w^11 + 4*w^12 + w^13 + 2*w^14 + 2*w^15 + + w^17 + 2*w^18 + O(w^19) sage: c = a.lift_to_precision(24); c - 4*w^5 + 3*w^7 + w^9 + 3*w^10 + 2*w^11 + 4*w^12 + w^13 + 2*w^14 + 2*w^15 + w^17 + 2*w^18 + 4*w^19 + 4*w^20 + 2*w^21 + 4*w^23 + O(w^24) + 4*w^5 + 3*w^7 + w^9 + 3*w^10 + 2*w^11 + 4*w^12 + w^13 + 2*w^14 + 2*w^15 + + w^17 + 2*w^18 + 4*w^19 + 4*w^20 + 2*w^21 + 4*w^23 + O(w^24) sage: a._ntl_rep() [19 35 118 60 121] sage: b._ntl_rep() @@ -2718,7 +2720,7 @@ cdef class pAdicZZpXCRElement(pAdicZZpXElement): def expansion(self, n = None, lift_mode = 'simple'): """ - Return a list giving a series representation of self. + Return a list giving a series representation of ``self``. - If ``lift_mode == 'simple'`` or ``'smallest'``, the returned list will consist of integers (in the Eisenstein case) or a @@ -2838,7 +2840,7 @@ cdef class pAdicZZpXCRElement(pAdicZZpXElement): the power basis `1, x, x^2, \ldots, x^{d-1}` for this extension field. Thus the *rows* of this matrix give the images of each of the `x^i`. The entries of the matrices are - IntegerMod elements, defined modulo `p^{N / e}` where `N` is + :class:`IntegerMod` elements, defined modulo `p^{N / e}` where `N` is the absolute precision of this element (unless this element is zero to arbitrary precision; in that case the entries are integer zeros.) @@ -2954,7 +2956,11 @@ cdef class pAdicZZpXCRElement(pAdicZZpXElement): sage: E = a.teichmuller_expansion(); E 5-adic expansion of a + O(5^4) (teichmuller) sage: list(E) - [a + (2*a^3 + 2*a^2 + 3*a + 4)*5 + (4*a^3 + 3*a^2 + 3*a + 2)*5^2 + (4*a^2 + 2*a + 2)*5^3 + O(5^4), (3*a^3 + 3*a^2 + 2*a + 1) + (a^3 + 4*a^2 + 1)*5 + (a^2 + 4*a + 4)*5^2 + O(5^3), (4*a^3 + 2*a^2 + a + 1) + (2*a^3 + 2*a^2 + 2*a + 4)*5 + O(5^2), (a^3 + a^2 + a + 4) + O(5)] + [a + (2*a^3 + 2*a^2 + 3*a + 4)*5 + (4*a^3 + 3*a^2 + 3*a + 2)*5^2 + + (4*a^2 + 2*a + 2)*5^3 + O(5^4), + (3*a^3 + 3*a^2 + 2*a + 1) + (a^3 + 4*a^2 + 1)*5 + (a^2 + 4*a + 4)*5^2 + O(5^3), + (4*a^3 + 2*a^2 + a + 1) + (2*a^3 + 2*a^2 + 2*a + 4)*5 + O(5^2), + (a^3 + a^2 + a + 4) + O(5)] sage: sum([c * 5^i for i, c in enumerate(E)]) a + O(5^4) sage: all(c^625 == c for c in E) @@ -2964,14 +2970,17 @@ cdef class pAdicZZpXCRElement(pAdicZZpXElement): sage: f = x^3 - 98*x + 7 sage: W. = ZpCR(7,3).ext(f) sage: b = (1+w)^5; L = b.teichmuller_expansion(); L - [1 + O(w^9), 5 + 5*w^3 + w^6 + 4*w^7 + O(w^8), 3 + 3*w^3 + O(w^7), 3 + 3*w^3 + O(w^6), O(w^5), 4 + 5*w^3 + O(w^4), 3 + O(w^3), 6 + O(w^2), 6 + O(w)] + [1 + O(w^9), 5 + 5*w^3 + w^6 + 4*w^7 + O(w^8), 3 + 3*w^3 + O(w^7), + 3 + 3*w^3 + O(w^6), O(w^5), 4 + 5*w^3 + O(w^4), 3 + O(w^3), + 6 + O(w^2), 6 + O(w)] sage: sum([w^i*L[i] for i in range(9)]) == b True sage: all(L[i]^(7^3) == L[i] for i in range(9)) True sage: L = W(3).teichmuller_expansion(); L - [3 + 3*w^3 + w^7 + O(w^9), O(w^8), O(w^7), 4 + 5*w^3 + O(w^6), O(w^5), O(w^4), 3 + O(w^3), 6 + O(w^2)] + [3 + 3*w^3 + w^7 + O(w^9), O(w^8), O(w^7), 4 + 5*w^3 + O(w^6), + O(w^5), O(w^4), 3 + O(w^3), 6 + O(w^2)] sage: sum([w^i*L[i] for i in range(len(L))]) 3 + O(w^9) """ @@ -3039,7 +3048,7 @@ cdef class pAdicZZpXCRElement(pAdicZZpXElement): sage: S. = R[] sage: f = x^5 + 77*x^3 - 98*x^2 - 7 sage: W. = R.ext(f) - sage: y = W.teichmuller(3, 15); y #indirect doctest + sage: y = W.teichmuller(3, 15); y # indirect doctest 3 + 4*w^5 + 2*w^8 + 6*w^10 + w^11 + 6*w^12 + 5*w^13 + 4*w^14 + O(w^15) sage: y^7 == y @@ -3081,7 +3090,7 @@ cdef class pAdicZZpXCRElement(pAdicZZpXElement): def precision_absolute(self): """ - Return the absolute precision of this element, ie the power of the + Return the absolute precision of this element, i.e., the power of the uniformizer modulo which this element is defined. EXAMPLES:: @@ -3116,7 +3125,7 @@ cdef class pAdicZZpXCRElement(pAdicZZpXElement): def precision_relative(self): """ - Return the relative precision of this element, ie the power of the + Return the relative precision of this element, i.e., the power of the uniformizer modulo which the unit part of ``self`` is defined. EXAMPLES:: @@ -3149,7 +3158,7 @@ cdef class pAdicZZpXCRElement(pAdicZZpXElement): cdef long valuation_c(self): """ - Return the valuation of this element + Return the valuation of this element. EXAMPLES:: @@ -3173,7 +3182,7 @@ cdef class pAdicZZpXCRElement(pAdicZZpXElement): cpdef pAdicZZpXCRElement unit_part(self): """ - Return the unit part of this element, ie ``self / uniformizer^(self.valuation())`` + Return the unit part of this element, ie ``self / uniformizer^(self.valuation())``. EXAMPLES:: @@ -3222,7 +3231,7 @@ cdef class pAdicZZpXCRElement(pAdicZZpXElement): otherwise they will be in the interval `[(1-p)/2, p/2]`. Note that zeros are truncated from the returned list, so you - must use the ``valuation()`` function to completely recover ``self``. + must use the method :meth:`valuation` to completely recover ``self``. EXAMPLES:: diff --git a/src/sage/rings/padics/padic_ZZ_pX_FM_element.pyx b/src/sage/rings/padics/padic_ZZ_pX_FM_element.pyx index 548a8e635d2..2f8db3f78f6 100644 --- a/src/sage/rings/padics/padic_ZZ_pX_FM_element.pyx +++ b/src/sage/rings/padics/padic_ZZ_pX_FM_element.pyx @@ -20,7 +20,7 @@ element contains the following data: This ``ZZ_pX`` is created with global ntl modulus determined by the parent's precision cap and shared among all elements. -- ``prime_pow`` (some subclass of ``PowComputer_ZZ_pX``) -- a class, +- ``prime_pow`` (some subclass of :class:`PowComputer_ZZ_pX`) -- a class, identical among all elements with the same parent, holding common data. @@ -48,7 +48,7 @@ element contains the following data: ``prime_pow.get_top_context`` -- obtain an ``ntl_ZZ_pContext_class`` corresponding to `p^n`. The capdiv version divides by ``prime_pow.e`` as appropriate. - ``top_context`` corresponds to `p^{prec_cap}`. + ``top_context`` corresponds to `p^{\texttt{prec\_cap}}`. * ``prime_pow.restore_context``, ``prime_pow.restore_context_capdiv``, diff --git a/src/sage/rings/padics/padic_base_leaves.py b/src/sage/rings/padics/padic_base_leaves.py index 3c382fd292b..99823338bc4 100644 --- a/src/sage/rings/padics/padic_base_leaves.py +++ b/src/sage/rings/padics/padic_base_leaves.py @@ -32,8 +32,8 @@ 22 The number of times that `p` divides the element is called the -valuation, and can be accessed with the functions ``valuation()`` and -``ordp()``: +valuation, and can be accessed with the methods :meth:`valuation` and +:meth:`ordp`: sage: a.valuation() 2 @@ -111,7 +111,7 @@ 1 + 2*5^2 + 5^3 `p`-adic rings and fields should be created using the creation -functions ``Zp`` and ``Qp`` as above. This will ensure that there is +functions :func:`Zp` and :func:`Qp` as above. This will ensure that there is only one instance of `\ZZ_p` and `\QQ_p` of a given type, `p`, print mode and precision. It also saves typing very long class names.:: @@ -347,7 +347,7 @@ def __init__(self, p, prec, print_mode, names): def _coerce_map_from_(self, R): """ - Returns ``True`` if there is a coerce map from ``R`` to ``self``. + Return ``True`` if there is a coerce map from ``R`` to ``self``. EXAMPLES:: @@ -446,7 +446,7 @@ def __init__(self, p, prec, print_mode, names): def _coerce_map_from_(self, R): """ - Returns ``True`` if there is a coerce map from ``R`` to ``self``. + Return ``True`` if there is a coerce map from ``R`` to ``self``. EXAMPLES:: @@ -478,7 +478,7 @@ def _coerce_map_from_(self, R): def _convert_map_from_(self, R): """ - Finds conversion maps from R to this ring. + Finds conversion maps from ``R`` to this ring. EXAMPLES:: @@ -548,7 +548,7 @@ def __init__(self, p, prec, print_mode, names): def _coerce_map_from_(self, R): """ - Returns ``True`` if there is a coerce map from ``R`` to ``self``. + Return ``True`` if there is a coerce map from ``R`` to ``self``. EXAMPLES:: @@ -653,7 +653,7 @@ def __init__(self, p, prec, print_mode, names): def _coerce_map_from_(self, R): """ - Returns ``True`` if there is a coerce map from ``R`` to ``self``. + Return ``True`` if there is a coerce map from ``R`` to ``self``. EXAMPLES:: @@ -711,11 +711,11 @@ def _convert_map_from_(self, R): def random_element(self, algorithm='default'): r""" - Returns a random element of ``self``, optionally using the ``algorithm`` + Return a random element of ``self``, optionally using the ``algorithm`` argument to decide how it generates the element. Algorithms currently implemented: - - default: Choose an integer `k` using the standard + - ``'default'``: Choose an integer `k` using the standard distribution on the integers. Then choose an integer `a` uniformly in the range `0 \le a < p^N` where `N` is the precision cap of ``self``. Return ``self(p^k * a, absprec = @@ -778,7 +778,7 @@ def __init__(self, p, prec, print_mode, names): def _coerce_map_from_(self, R): """ - Returns ``True`` if there is a coerce map from ``R`` to ``self``. + Return ``True`` if there is a coerce map from ``R`` to ``self``. EXAMPLES:: @@ -858,7 +858,8 @@ class pAdicRingLattice(pAdicLatticeGeneric, pAdicRingBaseGeneric): EXAMPLES:: sage: R = ZpLC(next_prime(10^60)) # indirect doctest - doctest:...: FutureWarning: This class/method/function is marked as experimental. It, its functionality or its interface might change without a formal deprecation. + doctest:...: FutureWarning: This class/method/function is marked as experimental. + It, its functionality or its interface might change without a formal deprecation. See https://github.com/sagemath/sage/issues/23505 for details. sage: type(R) @@ -937,7 +938,8 @@ def random_element(self, prec=None): sage: R = ZpLC(2) sage: R.random_element() # random - 2^3 + 2^4 + 2^5 + 2^6 + 2^7 + 2^10 + 2^11 + 2^14 + 2^15 + 2^16 + 2^17 + 2^18 + 2^19 + 2^21 + O(2^23) + 2^3 + 2^4 + 2^5 + 2^6 + 2^7 + 2^10 + 2^11 + 2^14 + 2^15 + 2^16 + + 2^17 + 2^18 + 2^19 + 2^21 + O(2^23) sage: R.random_element(prec=10) # random 1 + 2^3 + 2^4 + 2^7 + O(2^10) @@ -987,7 +989,8 @@ class pAdicFieldLattice(pAdicLatticeGeneric, pAdicFieldBaseGeneric): EXAMPLES:: sage: R = QpLC(next_prime(10^60)) # indirect doctest - doctest:...: FutureWarning: This class/method/function is marked as experimental. It, its functionality or its interface might change without a formal deprecation. + doctest:...: FutureWarning: This class/method/function is marked as experimental. + It, its functionality or its interface might change without a formal deprecation. See https://github.com/sagemath/sage/issues/23505 for details. sage: type(R) @@ -1062,7 +1065,7 @@ def random_element(self, prec=None, integral=False): - ``prec`` -- an integer or ``None`` (the default): the absolute precision of the generated random element - - ``integral`` -- a boolean (default: ``False``); if true + - ``integral`` -- a boolean (default: ``False``); if ``True``, return an element in the ring of integers EXAMPLES:: @@ -1071,7 +1074,8 @@ def random_element(self, prec=None, integral=False): sage: K.random_element() # not tested, known bug (see :trac:`32126`) 2^-8 + 2^-7 + 2^-6 + 2^-5 + 2^-3 + 1 + 2^2 + 2^3 + 2^5 + O(2^12) sage: K.random_element(integral=True) # random - 2^3 + 2^4 + 2^5 + 2^6 + 2^7 + 2^10 + 2^11 + 2^14 + 2^15 + 2^16 + 2^17 + 2^18 + 2^19 + O(2^20) + 2^3 + 2^4 + 2^5 + 2^6 + 2^7 + 2^10 + 2^11 + 2^14 + 2^15 + 2^16 + + 2^17 + 2^18 + 2^19 + O(2^20) sage: K.random_element(prec=10) # random 2^(-3) + 1 + 2 + 2^4 + 2^8 + O(2^10) diff --git a/src/sage/rings/padics/padic_extension_leaves.py b/src/sage/rings/padics/padic_extension_leaves.py index f17c6ed5428..ed171e833e4 100644 --- a/src/sage/rings/padics/padic_extension_leaves.py +++ b/src/sage/rings/padics/padic_extension_leaves.py @@ -1,7 +1,7 @@ -""" +r""" `p`-adic Extension Leaves -The final classes for extensions of Zp and Qp (ie classes that are not +The final classes for extensions of `\ZZ_p` and `\QQ_p` (i.e., classes that are not just designed to be inherited from). AUTHORS: @@ -93,8 +93,8 @@ class UnramifiedExtensionRingCappedRelative(UnramifiedExtensionGeneric, pAdicCap sage: TestSuite(R).run(skip='_test_log',max_runs=4) """ def __init__(self, exact_modulus, poly, prec, print_mode, shift_seed, names, implementation='FLINT'): - """ - A capped relative representation of Zq. + r""" + A capped relative representation of `\ZZ_q`. INPUT: @@ -102,7 +102,7 @@ def __init__(self, exact_modulus, poly, prec, print_mode, shift_seed, names, imp This could be a polynomial with integer coefficients, for example, while ``poly`` has coefficients in a `p`-adic ring. - - ``poly`` -- t polynomial with coefficients in :meth:`base_ring` + - ``poly`` -- the polynomial with coefficients in :meth:`base_ring` defining this extension - ``prec`` -- the precision cap of this ring @@ -152,7 +152,7 @@ class UnramifiedExtensionFieldCappedRelative(UnramifiedExtensionGeneric, pAdicCa """ def __init__(self, exact_modulus, poly, prec, print_mode, shift_seed, names, implementation='FLINT'): r""" - A representation of Qq. + A representation of `\QQ_q`. INPUT: @@ -237,21 +237,21 @@ class UnramifiedExtensionRingCappedAbsolute(UnramifiedExtensionGeneric, pAdicCap sage: TestSuite(R).run(skip='_test_log',max_runs=4) """ def __init__(self, exact_modulus, poly, prec, print_mode, shift_seed, names, implementation='FLINT'): - """ - A capped absolute representation of Zq. + r""" + A capped absolute representation of `ZZ_q`. INPUT: - ``exact_modulus`` -- the original polynomial defining the extension. This could be a polynomial with integer coefficients, for example, - while poly has coefficients in a `p`-adic ring. + while ``poly`` has coefficients in a `p`-adic ring. - ``poly`` -- the polynomial with coefficients in :meth:`base_ring` defining this extension - ``prec`` -- the precision cap of this ring - - ``print_mode`` -- A dictionary of print options + - ``print_mode`` -- a dictionary of print options - ``shift_seed`` -- unused @@ -358,14 +358,14 @@ class UnramifiedExtensionRingFloatingPoint(UnramifiedExtensionGeneric, pAdicFloa True """ def __init__(self, exact_modulus, poly, prec, print_mode, shift_seed, names, implementation='FLINT'): - """ - A floating point representation of Zq. + r""" + A floating point representation of `\ZZ_q`. INPUT: - ``exact_modulus`` -- the original polynomial defining the extension. This could be a polynomial with integer coefficients, for example, - while ``poly`` has coefficients in Zp. + while ``poly`` has coefficients in `\ZZ_p`. - ``poly`` -- the polynomial with coefficients in :meth:`base_ring` defining this extension @@ -415,8 +415,8 @@ class UnramifiedExtensionFieldFloatingPoint(UnramifiedExtensionGeneric, pAdicFlo True """ def __init__(self, exact_modulus, poly, prec, print_mode, shift_seed, names, implementation='FLINT'): - """ - A representation of Qq. + r""" + A representation of `\QQ_q`. INPUT: @@ -484,8 +484,8 @@ class EisensteinExtensionRingCappedRelative(EisensteinExtensionGeneric, pAdicCap sage: TestSuite(R).run(skip='_test_log',max_runs=4) """ def __init__(self, exact_modulus, poly, prec, print_mode, shift_seed, names, implementation='NTL'): - """ - A capped relative representation of an eisenstein extension of Zp. + r""" + A capped relative representation of an Eisenstein extension of `\ZZ_p`. INPUT: @@ -539,8 +539,8 @@ class EisensteinExtensionFieldCappedRelative(EisensteinExtensionGeneric, pAdicCa sage: TestSuite(R).run(skip='_test_log',max_runs=4) """ def __init__(self, exact_modulus, poly, prec, print_mode, shift_seed, names, implementation='NTL'): - """ - A capped relative representation of an eisenstein extension of Qp. + r""" + A capped relative representation of an Eisenstein extension of `\QQ_p`. INPUT: @@ -595,8 +595,8 @@ class EisensteinExtensionRingCappedAbsolute(EisensteinExtensionGeneric, pAdicCap sage: TestSuite(R).run(skip='_test_log',max_runs=4) """ def __init__(self, exact_modulus, poly, prec, print_mode, shift_seed, names, implementation): - """ - A capped absolute representation of an eisenstein extension of Zp. + r""" + A capped absolute representation of an Eisenstein extension of `\ZZ_p`. INPUT: @@ -650,8 +650,8 @@ class EisensteinExtensionRingFixedMod(EisensteinExtensionGeneric, pAdicFixedModR sage: TestSuite(R).run(skip='_test_log',max_runs=4) """ def __init__(self, exact_modulus, poly, prec, print_mode, shift_seed, names, implementation='NTL'): - """ - A fixed modulus representation of an eisenstein extension of Zp. + r""" + A fixed modulus representation of an eisenstein extension of `\ZZ_p`. INPUT: @@ -706,7 +706,8 @@ def fraction_field(self): sage: R.fraction_field() Traceback (most recent call last): ... - TypeError: This implementation of the p-adic ring does not support fields of fractions. + TypeError: This implementation of the p-adic ring + does not support fields of fractions. """ raise TypeError("This implementation of the p-adic ring does not support fields of fractions.") diff --git a/src/sage/rings/padics/padic_generic.py b/src/sage/rings/padics/padic_generic.py index bde23bea380..b7caad54122 100644 --- a/src/sage/rings/padics/padic_generic.py +++ b/src/sage/rings/padics/padic_generic.py @@ -1,3 +1,4 @@ +# sage.doctest: optional - sage.rings.padics r""" `p`-adic Generic diff --git a/src/sage/rings/padics/padic_generic_element.pyx b/src/sage/rings/padics/padic_generic_element.pyx index 081c086f5af..534538e28ff 100644 --- a/src/sage/rings/padics/padic_generic_element.pyx +++ b/src/sage/rings/padics/padic_generic_element.pyx @@ -46,7 +46,7 @@ cdef long maxordp = (1L << (sizeof(long) * 8 - 2)) - 1 cdef class pAdicGenericElement(LocalGenericElement): cpdef _richcmp_(left, right, int op): - """ + r""" First compare valuations, then compare normalized residue of unit part. @@ -173,7 +173,7 @@ cdef class pAdicGenericElement(LocalGenericElement): cpdef bint _is_exact_zero(self) except -1: """ - Returns True if self is exactly zero. Since + Return ``True`` if self is exactly zero. Since non-capped-relative elements cannot be exact, this function always returns False. @@ -186,7 +186,7 @@ cdef class pAdicGenericElement(LocalGenericElement): cpdef bint _is_inexact_zero(self) except -1: """ - Returns True if self is indistinguishable from zero, but not + Return ``True`` if self is indistinguishable from zero, but not exactly zero. EXAMPLES:: @@ -198,7 +198,7 @@ cdef class pAdicGenericElement(LocalGenericElement): cpdef bint _is_zero_rep(self) except -1: """ - Returns True is self is indistinguishable from zero. + Return ``True`` is self is indistinguishable from zero. EXAMPLES:: @@ -534,7 +534,7 @@ cdef class pAdicGenericElement(LocalGenericElement): def str(self, mode=None): """ - Returns a string representation of self. + Return a string representation of ``self``. EXAMPLES:: @@ -545,7 +545,7 @@ cdef class pAdicGenericElement(LocalGenericElement): def _repr_(self, mode=None, do_latex=False): r""" - Returns a string representation of this element. + Return a string representation of this element. INPUT: @@ -570,8 +570,8 @@ cdef class pAdicGenericElement(LocalGenericElement): def additive_order(self, prec=None): r""" - Returns the additive order of this element truncated - at precision ``prec`` + Return the additive order of this element truncated + at precision ``prec``. INPUT: @@ -606,11 +606,11 @@ cdef class pAdicGenericElement(LocalGenericElement): the desired precision on the result; if ``None``, the precision is derived from the precision on the input - - ``algorithm`` -- ``direct``, ``series``, ``newton`` or + - ``algorithm`` -- ``'direct'``, ``'series'``, ``'newton'`` or ``None`` (default) The direct algorithm computes the Artin-Hasse exponential - of ``x``, namely ``AH(x)`` as + of `x`, namely ``AH(x)`` as .. MATH:: @@ -622,7 +622,7 @@ cdef class pAdicGenericElement(LocalGenericElement): The series algorithm computes the series defining the Artin-Hasse exponential and evaluates it. - The ``Newton`` algorithm solves the equation + The ``'newton'`` algorithm solves the equation .. MATH:: @@ -631,11 +631,11 @@ cdef class pAdicGenericElement(LocalGenericElement): using a Newton scheme. It runs roughly as fast as the computation of the logarithm. - By default, we use the direct algorithm if a fast algorithm for + By default, we use the ``'direct'`` algorithm if a fast algorithm for computing the exponential is available. - If not, we use the Newton algorithm if a fast algorithm for + If not, we use the ``'newton'`` algorithm if a fast algorithm for computing the logarithm is available. - Otherwise we switch to the series algorithm. + Otherwise we switch to the ``'series'`` algorithm. OUTPUT: @@ -849,11 +849,11 @@ cdef class pAdicGenericElement(LocalGenericElement): AH(x) = \exp(x + \frac{x^p}{p} + \frac{x^{p^2}}{p^2} + \dots) - at enough precision and the plug the input element in it. + at enough precision and then plugs in the input element. INPUT: - - ``prec`` -- an integer, this precision at which the + - ``prec`` -- an integer, the precision at which the result should be computed EXAMPLES:: @@ -889,8 +889,8 @@ cdef class pAdicGenericElement(LocalGenericElement): r""" Return the Artin-Hasse exponential of this element. - If ``x`` denotes the input element, its Artin-Hasse exponential - is computed by solving the following equation in ``y`` + If `x` denotes the input element, its Artin-Hasse exponential + is computed by solving the following equation in `y` .. MATH:: @@ -903,7 +903,7 @@ cdef class pAdicGenericElement(LocalGenericElement): INPUT: - - ``prec`` -- an integer, this precision at which the + - ``prec`` -- an integer, the precision at which the result should be computed EXAMPLES:: @@ -972,7 +972,7 @@ cdef class pAdicGenericElement(LocalGenericElement): INPUT: - - ``name`` -- string (default: ``x``): the name of the variable + - ``name`` -- string (default: ``'x'``): the name of the variable - ``base`` -- a ring (default: the base ring of the parent): the base ring over which the minimal polynomial is computed @@ -1035,13 +1035,13 @@ cdef class pAdicGenericElement(LocalGenericElement): def norm(self, base=None): """ - Returns the norm of this `p`-adic element over ``base``. + Return the norm of this `p`-adic element over ``base``. .. WARNING:: This is not the `p`-adic absolute value. This is a field theoretic norm down to a base ring. If you want the - `p`-adic absolute value, use the ``abs()`` function + `p`-adic absolute value, use the method :meth:`abs` instead. INPUT: @@ -1135,22 +1135,23 @@ cdef class pAdicGenericElement(LocalGenericElement): irreducible, and indeed usually won't be if this number is a good approximation to an algebraic number of degree less than `n`. - ALGORITHM: Uses the PARI C-library ``algdep`` command. + ALGORITHM: Uses the PARI C-library :pari:`algdep` command. INPUT: - - ``self`` -- a p-adic element + - ``self`` -- a `p`-adic element - ``n`` -- an integer OUTPUT: - polynomial -- degree n polynomial approximately satisfied by self + polynomial -- degree `n` polynomial approximately satisfied by ``self`` EXAMPLES:: sage: K = Qp(3,20,'capped-rel','series'); R = Zp(3,20,'capped-rel','series') sage: a = K(7/19); a - 1 + 2*3 + 3^2 + 3^3 + 2*3^4 + 2*3^5 + 3^8 + 2*3^9 + 3^11 + 3^12 + 2*3^15 + 2*3^16 + 3^17 + 2*3^19 + O(3^20) + 1 + 2*3 + 3^2 + 3^3 + 2*3^4 + 2*3^5 + 3^8 + 2*3^9 + 3^11 + 3^12 + + 2*3^15 + 2*3^16 + 3^17 + 2*3^19 + O(3^20) sage: a.algdep(1) 19*x - 7 sage: K2 = Qp(7,20,'capped-rel') @@ -1160,7 +1161,8 @@ cdef class pAdicGenericElement(LocalGenericElement): sage: b = K2.zeta(); b.algdep(4) x^4 - x^3 + x^2 - x + 1 sage: a = R(7/19); a - 1 + 2*3 + 3^2 + 3^3 + 2*3^4 + 2*3^5 + 3^8 + 2*3^9 + 3^11 + 3^12 + 2*3^15 + 2*3^16 + 3^17 + 2*3^19 + O(3^20) + 1 + 2*3 + 3^2 + 3^3 + 2*3^4 + 2*3^5 + 3^8 + 2*3^9 + 3^11 + 3^12 + + 2*3^15 + 2*3^16 + 3^17 + 2*3^19 + O(3^20) sage: a.algdep(1) 19*x - 7 sage: R2 = Zp(7,20,'capped-rel') @@ -1181,7 +1183,7 @@ cdef class pAdicGenericElement(LocalGenericElement): be irreducible, and indeed usually won't be if this number is a good approximation to an algebraic number of degree less than `n`. - ALGORITHM: Uses the PARI C-library algdep command. + ALGORITHM: Uses the PARI C-library :pari:`algdep` command. INPUT: @@ -1190,13 +1192,14 @@ cdef class pAdicGenericElement(LocalGenericElement): OUTPUT: - polynomial -- degree n polynomial approximately satisfied by self + polynomial -- degree `n` polynomial approximately satisfied by ``self`` EXAMPLES:: sage: K = Qp(3,20,'capped-rel','series'); R = Zp(3,20,'capped-rel','series') sage: a = K(7/19); a - 1 + 2*3 + 3^2 + 3^3 + 2*3^4 + 2*3^5 + 3^8 + 2*3^9 + 3^11 + 3^12 + 2*3^15 + 2*3^16 + 3^17 + 2*3^19 + O(3^20) + 1 + 2*3 + 3^2 + 3^3 + 2*3^4 + 2*3^5 + 3^8 + 2*3^9 + 3^11 + 3^12 + + 2*3^15 + 2*3^16 + 3^17 + 2*3^19 + O(3^20) sage: a.algebraic_dependency(1) 19*x - 7 sage: K2 = Qp(7,20,'capped-rel') @@ -1206,7 +1209,8 @@ cdef class pAdicGenericElement(LocalGenericElement): sage: b = K2.zeta(); b.algebraic_dependency(4) x^4 - x^3 + x^2 - x + 1 sage: a = R(7/19); a - 1 + 2*3 + 3^2 + 3^3 + 2*3^4 + 2*3^5 + 3^8 + 2*3^9 + 3^11 + 3^12 + 2*3^15 + 2*3^16 + 3^17 + 2*3^19 + O(3^20) + 1 + 2*3 + 3^2 + 3^3 + 2*3^4 + 2*3^5 + 3^8 + 2*3^9 + 3^11 + 3^12 + + 2*3^15 + 2*3^16 + 3^17 + 2*3^19 + O(3^20) sage: a.algebraic_dependency(1) 19*x - 7 sage: R2 = Zp(7,20,'capped-rel') @@ -1239,7 +1243,7 @@ cdef class pAdicGenericElement(LocalGenericElement): OUTPUT: - A ``p``-- adic integer. + A `p`-adic integer. .. NOTE:: @@ -1301,9 +1305,9 @@ cdef class pAdicGenericElement(LocalGenericElement): INPUT: - ``algorithm`` -- string. Can be set to ``'pari'`` to call - the pari function, or ``'sage'`` to call the function - implemented in sage. The default is ``'pari'`` since - pari is about 10 times faster than sage. + the PARI function, or ``'sage'`` to call the function + implemented in Sage. The default is ``'pari'`` since + PARI is about 10 times faster than Sage. OUTPUT: @@ -1315,7 +1319,7 @@ cdef class pAdicGenericElement(LocalGenericElement): Villegas (http://www.ma.utexas.edu/cnt/cnt-frames.html). William Stein sped it up for GP (http://sage.math.washington.edu/home/wstein/www/home/wbhart/pari-2.4.2.alpha/src/basemath/trans2.c). - The 'sage' version uses dwork_expansion() to compute the + The ``'sage'`` version uses dwork_expansion() to compute the `p`-adic gamma function of self as in [RV2007]_ section 6.2. EXAMPLES: @@ -1732,7 +1736,7 @@ cdef class pAdicGenericElement(LocalGenericElement): INPUT: - - ``self`` -- a p-adic element + - ``self`` -- a `p`-adic element EXAMPLES:: @@ -1900,17 +1904,17 @@ cdef class pAdicGenericElement(LocalGenericElement): def multiplicative_order(self, prec = None): r""" - Returns the multiplicative order of self, where self is + Returns the multiplicative order of ``self``, where ``self`` is considered to be one if it is one modulo `p^{\mbox{prec}}`. INPUT: - - ``self`` -- a p-adic element + - ``self`` -- a `p`-adic element - ``prec`` -- an integer OUTPUT: - - integer -- the multiplicative order of self + - integer -- the multiplicative order of ``self`` EXAMPLES:: @@ -1996,22 +2000,22 @@ cdef class pAdicGenericElement(LocalGenericElement): return infinity def valuation(self, p = None): - """ - Returns the valuation of this element. + r""" + Return the valuation of this element. INPUT: - - ``self`` -- a p-adic element - - ``p`` -- a prime (default: None). If specified, will make sure that p==self.parent().prime() + - ``self`` -- a `p`-adic element + - ``p`` -- a prime (default: ``None``). If specified, will make sure that ``p == self.parent().prime()`` .. NOTE:: - The optional argument p is used for consistency with the valuation - methods on integer and rational. + The optional argument `p` is used for consistency with the valuation + methods on integers and rationals. OUTPUT: - integer -- the valuation of self + integer -- the valuation of ``self`` EXAMPLES:: @@ -2109,7 +2113,7 @@ cdef class pAdicGenericElement(LocalGenericElement): raise NotImplementedError cpdef val_unit(self): - """ + r""" Return ``(self.valuation(), self.unit_part())``. To be overridden in derived classes. @@ -2122,21 +2126,21 @@ cdef class pAdicGenericElement(LocalGenericElement): def ordp(self, p = None): r""" - Returns the valuation of self, normalized so that the valuation of `p` is 1 + Return the valuation of ``self``, normalized so that the valuation of `p` is 1. INPUT: - - ``self`` -- a p-adic element + - ``self`` -- a `p`-adic element - ``p`` -- a prime (default: ``None``). If specified, will make sure that ``p == self.parent().prime()`` .. NOTE:: - The optional argument p is used for consistency with the valuation - methods on integer and rational. + The optional argument `p` is used for consistency with the valuation + methods on integers and rationals. OUTPUT: - integer -- the valuation of self, normalized so that the valuation of `p` is 1 + integer -- the valuation of ``self``, normalized so that the valuation of `p` is 1 EXAMPLES:: @@ -2162,7 +2166,7 @@ cdef class pAdicGenericElement(LocalGenericElement): def is_prime(self): """ - Return whether this element is prime in its parent + Return whether this element is prime in its parent. EXAMPLES:: @@ -2192,9 +2196,9 @@ cdef class pAdicGenericElement(LocalGenericElement): def rational_reconstruction(self): r""" - Returns a rational approximation to this `p`-adic number + Returns a rational approximation to this `p`-adic number. - This will raise an ArithmeticError if there are no valid + This will raise an :class:`ArithmeticError` if there are no valid approximations to the unit part with numerator and denominator bounded by ``sqrt(p^absprec / 2)``. @@ -2204,7 +2208,7 @@ cdef class pAdicGenericElement(LocalGenericElement): OUTPUT: - rational -- an approximation to self + rational -- an approximation to ``self`` EXAMPLES:: @@ -2245,7 +2249,7 @@ cdef class pAdicGenericElement(LocalGenericElement): def _number_field_(self, K): r""" - Return an element of K approximating this p-adic number. + Return an element of `K` approximating this `p`-adic number. INPUT: @@ -2546,7 +2550,7 @@ cdef class pAdicGenericElement(LocalGenericElement): the same as the input (default) or if it should change to the fraction field of the input. - - ``algorithm`` -- ``generic``, ``binary_splitting`` or ``None`` (default) + - ``algorithm`` -- ``'generic'``, ``'binary_splitting'`` or ``None`` (default) The generic algorithm evaluates naively the series defining the log, namely @@ -2556,10 +2560,10 @@ cdef class pAdicGenericElement(LocalGenericElement): Its binary complexity is quadratic with respect to the precision. - The binary splitting algorithm is faster, it has a quasi-linear + The ``'binary_splitting'`` algorithm is faster, it has a quasi-linear complexity. - By default, we use the binary splitting if it is available. Otherwise - we switch to the generic algorithm. + By default, we use ``'binary_splitting'`` if it is available. Otherwise + we switch to the ``'generic'`` algorithm. .. NOTE:: @@ -2573,7 +2577,7 @@ cdef class pAdicGenericElement(LocalGenericElement): .. TODO:: There is a soft-linear time algorithm for logarithm described - by Dan Berstein at + by Dan Bernstein at http://cr.yp.to/lineartime/multapps-20041007.pdf EXAMPLES:: @@ -2656,15 +2660,19 @@ cdef class pAdicGenericElement(LocalGenericElement): sage: b.log(p_branch=w) w + O(w^20) sage: b.log(pi_branch=0) - 3*w^2 + 2*w^4 + 2*w^6 + 3*w^8 + 4*w^10 + w^13 + w^14 + 2*w^15 + 2*w^16 + w^18 + 4*w^19 + O(w^20) + 3*w^2 + 2*w^4 + 2*w^6 + 3*w^8 + 4*w^10 + w^13 + w^14 + 2*w^15 + + 2*w^16 + w^18 + 4*w^19 + O(w^20) sage: b.unit_part().log() - 3*w^2 + 2*w^4 + 2*w^6 + 3*w^8 + 4*w^10 + w^13 + w^14 + 2*w^15 + 2*w^16 + w^18 + 4*w^19 + O(w^20) + 3*w^2 + 2*w^4 + 2*w^6 + 3*w^8 + 4*w^10 + w^13 + w^14 + 2*w^15 + + 2*w^16 + w^18 + 4*w^19 + O(w^20) sage: y = w^2 * 4*w^7; y 4*w^9 + O(w^29) sage: y.log(p_branch=0) - 2*w^2 + 2*w^4 + 2*w^6 + 2*w^8 + w^10 + w^12 + 4*w^13 + 4*w^14 + 3*w^15 + 4*w^16 + 4*w^17 + w^18 + 4*w^19 + O(w^20) + 2*w^2 + 2*w^4 + 2*w^6 + 2*w^8 + w^10 + w^12 + 4*w^13 + 4*w^14 + 3*w^15 + + 4*w^16 + 4*w^17 + w^18 + 4*w^19 + O(w^20) sage: y.log(p_branch=w) - w + 2*w^2 + 2*w^4 + 4*w^5 + 2*w^6 + 2*w^7 + 2*w^8 + 4*w^9 + w^10 + 3*w^11 + w^12 + 4*w^14 + 4*w^16 + 2*w^17 + w^19 + O(w^20) + w + 2*w^2 + 2*w^4 + 4*w^5 + 2*w^6 + 2*w^7 + 2*w^8 + 4*w^9 + w^10 + + 3*w^11 + w^12 + 4*w^14 + 4*w^16 + 2*w^17 + w^19 + O(w^20) Check that log is multiplicative:: @@ -2677,7 +2685,8 @@ cdef class pAdicGenericElement(LocalGenericElement): sage: A. = R.ext(g) sage: b = 1 + 5*(1 + a^2) + 5^3*(3 + 2*a) sage: b.log() - (a^2 + 1)*5 + (3*a^2 + 4*a + 2)*5^2 + (3*a^2 + 2*a)*5^3 + (3*a^2 + 2*a + 2)*5^4 + O(5^5) + (a^2 + 1)*5 + (3*a^2 + 4*a + 2)*5^2 + (3*a^2 + 2*a)*5^3 + + (3*a^2 + 2*a + 2)*5^4 + O(5^5) Check that log is multiplicative:: @@ -2685,7 +2694,7 @@ cdef class pAdicGenericElement(LocalGenericElement): sage: b.log() + c.log() - (b*c).log() O(5^5) - We illustrate the effect of the precision argument:: + We illustrate the effect of the ``precision`` argument:: sage: R = ZpCA(7,10) sage: x = R(41152263); x @@ -2723,7 +2732,8 @@ cdef class pAdicGenericElement(LocalGenericElement): sage: w.log(p_branch=2) Traceback (most recent call last): ... - ValueError: logarithm is not integral, use change_frac=True to obtain a result in the fraction field + ValueError: logarithm is not integral, use change_frac=True + to obtain a result in the fraction field sage: w.log(p_branch=2, change_frac=True) 2*w^-3 + O(w^24) @@ -3148,10 +3158,10 @@ cdef class pAdicGenericElement(LocalGenericElement): - ``aprec`` -- an integer or ``None`` (default: ``None``); if specified, computes only up to the indicated precision - - ``algorithm`` -- ``generic``, ``binary_splitting``, ``newton`` + - ``algorithm`` -- ``'generic'``, ``'binary_splitting'``, ``'newton'`` or ``None`` (default) - The generic algorithm evaluates naively the series defining the + The ``'generic'`` algorithm evaluates naively the series defining the exponential, namely .. MATH:: @@ -3160,17 +3170,17 @@ cdef class pAdicGenericElement(LocalGenericElement): Its binary complexity is quadratic with respect to the precision. - The binary splitting algorithm is faster, it has a quasi-linear + The ``'binary_splitting'`` algorithm is faster, it has a quasi-linear complexity. - The ``Newton`` algorithms solve the equation `\log(x) =` ``self`` + The ``'newton'`` algorithms solve the equation `\log(x) =` ``self`` using a Newton scheme. It runs roughly as fast as the computation of the logarithm. - By default, we use the binary splitting if it is available. - If it is not, we use the Newton algorithm if a fast algorithm for + By default, we use the ``'binary_splitting'`` if it is available. + If it is not, we use the ``'newton'`` algorithm if a fast algorithm for computing the logarithm is available. - Otherwise we switch to the generic algorithm. + Otherwise we switch to the ``'generic'`` algorithm. EXAMPLES: @@ -3194,7 +3204,8 @@ cdef class pAdicGenericElement(LocalGenericElement): exponentials:: sage: R = Zp(5,10) - sage: e = R(2*5 + 2*5**2 + 4*5**3 + 3*5**4 + 5**5 + 3*5**7 + 2*5**8 + 4*5**9).add_bigoh(10); e + sage: e = R(2*5 + 2*5**2 + 4*5**3 + 3*5**4 + ....: + 5**5 + 3*5**7 + 2*5**8 + 4*5**9).add_bigoh(10); e 2*5 + 2*5^2 + 4*5^3 + 3*5^4 + 5^5 + 3*5^7 + 2*5^8 + 4*5^9 + O(5^10) sage: e.exp()*R.teichmuller(4) 4 + 2*5 + 3*5^3 + O(5^10) @@ -3202,7 +3213,8 @@ cdef class pAdicGenericElement(LocalGenericElement): :: sage: K = Qp(5,10) - sage: e = K(2*5 + 2*5**2 + 4*5**3 + 3*5**4 + 5**5 + 3*5**7 + 2*5**8 + 4*5**9).add_bigoh(10); e + sage: e = K(2*5 + 2*5**2 + 4*5**3 + 3*5**4 + ....: + 5**5 + 3*5**7 + 2*5**8 + 4*5**9).add_bigoh(10); e 2*5 + 2*5^2 + 4*5^3 + 3*5^4 + 5^5 + 3*5^7 + 2*5^8 + 4*5^9 + O(5^10) sage: e.exp()*K.teichmuller(4) 4 + 2*5 + 3*5^3 + O(5^10) @@ -3373,15 +3385,15 @@ cdef class pAdicGenericElement(LocalGenericElement): - ``extend`` -- a boolean (default: ``True``); if ``True``, return a square root in an extension if necessary; if ``False`` and no root - exists in the given ring or field, raise a ValueError. + exists in the given ring or field, raise a :class:`ValueError`. - ``all`` -- a boolean (default: ``False``); if ``True``, return a list of all square roots. - ``algorithm`` -- ``"pari"``, ``"sage"`` or ``None`` (default: ``None``); Sage provides an implementation for any extension of - `Q_p` whereas only square roots over `Q_p` is implemented in Pari; - the default is ``"pari"`` if the ground field is `Q_p`, ``"sage"`` + `\QQ_p`, whereas only square roots over `\QQ_p` are implemented in PARI; + the default is ``"pari"`` if the ground field is `\QQ_p`, ``"sage"`` otherwise. OUTPUT: @@ -3426,7 +3438,8 @@ cdef class pAdicGenericElement(LocalGenericElement): sage: R. = Zq(2^10, 10) sage: u = 1 + 8*t sage: u.square_root() - 1 + t*2^2 + t^2*2^3 + t^2*2^4 + (t^4 + t^3 + t^2)*2^5 + (t^4 + t^2)*2^6 + (t^5 + t^2)*2^7 + (t^6 + t^5 + t^4 + t^2)*2^8 + O(2^9) + 1 + t*2^2 + t^2*2^3 + t^2*2^4 + (t^4 + t^3 + t^2)*2^5 + (t^4 + t^2)*2^6 + + (t^5 + t^2)*2^7 + (t^6 + t^5 + t^4 + t^2)*2^8 + O(2^9) sage: R. = Zp(2).extension(x^3 - 2) sage: u = R(1 + a^4 + a^5 + a^7 + a^8, 10); u @@ -3566,14 +3579,14 @@ cdef class pAdicGenericElement(LocalGenericElement): def nth_root(self, n, all=False): """ - Return the nth root of this element. + Return the `n`-th root of this element. INPUT: - ``n`` -- an integer - ``all`` -- a boolean (default: ``False``): if ``True``, - return all ntn roots of this element, instead of just one. + return all `n`-th roots of this element, instead of just one. EXAMPLES:: @@ -3593,7 +3606,7 @@ cdef class pAdicGenericElement(LocalGenericElement): When `n` is divisible by the underlying prime `p`, we are losing precision (which is consistent with the fact - that raising to the pth power increases precision):: + that raising to the `p`-th power increases precision):: sage: z = x.nth_root(5); z 1 + 5^2 + 3*5^3 + 2*5^4 + 5^5 + 3*5^7 + 2*5^8 + O(5^9) @@ -3610,7 +3623,7 @@ cdef class pAdicGenericElement(LocalGenericElement): sage: R(5).nth_root(7, all=True) [pi + O(pi^141)] - An error is raised if the given element is not a nth power + An error is raised if the given element is not an `n`-th power in the ring:: sage: R(5).nth_root(11) @@ -3632,7 +3645,7 @@ cdef class pAdicGenericElement(LocalGenericElement): sage: K = Qp(29) sage: x = polygen(K) - sage: L. = K.extension(x^2 -29) + sage: L. = K.extension(x^2 - 29) sage: L(4).nth_root(2) 2 + O(a^40) @@ -4036,8 +4049,8 @@ cdef class pAdicGenericElement(LocalGenericElement): return Rational(K.prime())**(-self.valuation()) cpdef bint _is_base_elt(self, p) except -1: - """ - Return ``True`` if this element is an element of Zp or Qp (rather than + r""" + Return ``True`` if this element is an element of `\ZZ_p` or `\QQ_p` (rather than an extension). INPUT: @@ -4148,7 +4161,7 @@ cdef class pAdicGenericElement(LocalGenericElement): - ``n`` -- a non-negative integer - ``p_branch`` -- an element in the base ring or its fraction field; the implementation will choose the branch of the - logarithm which sends `p` to ``branch`` + logarithm which sends `p` to ``p_branch`` EXAMPLES: @@ -4480,7 +4493,7 @@ cpdef dwork_mahler_coeffs(R, int bd=20): INPUT: - - ``R`` -- p-adic ring in which to compute + - ``R`` -- `p`-adic ring in which to compute - ``bd`` -- integer. Number of terms in the expansion to use OUTPUT: @@ -4494,9 +4507,11 @@ cpdef dwork_mahler_coeffs(R, int bd=20): sage: v = dwork_mahler_coeffs(R) sage: x = R(1/7) sage: evaluate_dwork_mahler(v, x, 3, 20, 1) - 2 + 2*3 + 3^2 + 3^3 + 3^4 + 3^5 + 2*3^6 + 2*3^7 + 2*3^8 + 2*3^9 + 2*3^11 + 2*3^12 + 3^13 + 3^14 + 2*3^16 + 3^17 + 3^19 + O(3^20) - sage: x.dwork_expansion(a=1) # Same result - 2 + 2*3 + 3^2 + 3^3 + 3^4 + 3^5 + 2*3^6 + 2*3^7 + 2*3^8 + 2*3^9 + 2*3^11 + 2*3^12 + 3^13 + 3^14 + 2*3^16 + 3^17 + 3^19 + O(3^20) + 2 + 2*3 + 3^2 + 3^3 + 3^4 + 3^5 + 2*3^6 + 2*3^7 + 2*3^8 + 2*3^9 + 2*3^11 + + 2*3^12 + 3^13 + 3^14 + 2*3^16 + 3^17 + 3^19 + O(3^20) + sage: x.dwork_expansion(a=1) # Same result + 2 + 2*3 + 3^2 + 3^3 + 3^4 + 3^5 + 2*3^6 + 2*3^7 + 2*3^8 + 2*3^9 + 2*3^11 + + 2*3^12 + 3^13 + 3^14 + 2*3^16 + 3^17 + 3^19 + O(3^20) """ from sage.rings.padics.factory import Qp cdef int i @@ -4528,9 +4543,11 @@ cpdef evaluate_dwork_mahler(v, x, long long p, int bd, long long a): sage: v = dwork_mahler_coeffs(R) sage: x = R(1/7) sage: evaluate_dwork_mahler(v, x, 3, 20, 1) - 2 + 2*3 + 3^2 + 3^3 + 3^4 + 3^5 + 2*3^6 + 2*3^7 + 2*3^8 + 2*3^9 + 2*3^11 + 2*3^12 + 3^13 + 3^14 + 2*3^16 + 3^17 + 3^19 + O(3^20) - sage: x.dwork_expansion(a=1) # Same result - 2 + 2*3 + 3^2 + 3^3 + 3^4 + 3^5 + 2*3^6 + 2*3^7 + 2*3^8 + 2*3^9 + 2*3^11 + 2*3^12 + 3^13 + 3^14 + 2*3^16 + 3^17 + 3^19 + O(3^20) + 2 + 2*3 + 3^2 + 3^3 + 3^4 + 3^5 + 2*3^6 + 2*3^7 + 2*3^8 + 2*3^9 + 2*3^11 + + 2*3^12 + 3^13 + 3^14 + 2*3^16 + 3^17 + 3^19 + O(3^20) + sage: x.dwork_expansion(a=1) # Same result + 2 + 2*3 + 3^2 + 3^3 + 3^4 + 3^5 + 2*3^6 + 2*3^7 + 2*3^8 + 2*3^9 + 2*3^11 + + 2*3^12 + 3^13 + 3^14 + 2*3^16 + 3^17 + 3^19 + O(3^20) """ cdef int k bd -= 1 @@ -4569,16 +4586,16 @@ cpdef gauss_table(long long p, int f, int prec, bint use_longs): INPUT: - - `p` - prime - - `f`, `prec` - positive integers - - `use_longs` - boolean; if True, computations are done in C long long + - ``p`` - prime + - ``f``, ``prec`` - positive integers + - ``use_longs`` - boolean; if ``True``, computations are done in C ``long long`` integers rather than Sage `p`-adics, and the results are returned as a Python array rather than a list. OUTPUT: A list of length `q-1=p^f-1`. The entries are `p`-adic units created with - absolute precision `prec`. + absolute precision ``prec``. EXAMPLES:: diff --git a/src/sage/rings/padics/padic_printing.pyx b/src/sage/rings/padics/padic_printing.pyx index bd4715a7859..344a1e544a7 100644 --- a/src/sage/rings/padics/padic_printing.pyx +++ b/src/sage/rings/padics/padic_printing.pyx @@ -48,16 +48,16 @@ cdef enum print_modes: def pAdicPrinter(ring, options={}): """ - Creates a pAdicPrinter. + Create a :class:`pAdicPrinter`. INPUT: - - ring -- a p-adic ring or field. + - ring -- a p-adic ring or field. - - options -- a dictionary, with keys in 'mode', 'pos', - 'ram_name', 'unram_name', 'var_name', 'max_ram_terms', - 'max_unram_terms', 'max_terse_terms', 'sep', 'alphabet'; see - pAdicPrinter_class for the meanings of these keywords. + - options -- a dictionary, with keys in ``'mode'``, ``'pos'``, + ``'ram_name'``, ``'unram_name'``, ``'var_name'``, ``'max_ram_terms'``, + ``'max_unram_terms'``, ``'max_terse_terms'``, ``'sep'``, ``'alphabet'``; see + :class:`pAdicPrinter_class` for the meanings of these keywords. EXAMPLES:: @@ -76,7 +76,7 @@ class pAdicPrinterDefaults(SageObject): This class stores global defaults for p-adic printing. """ def __init__(self, mode = 'series', pos = True, max_ram_terms = -1, max_unram_terms = -1, max_terse_terms = -1, sep = "|", alphabet = None): - """ + r""" Instances of this class store global defaults used in determining printing options during the creation of p-adic rings and fields. One instance stored in padic_printing @@ -109,13 +109,13 @@ class pAdicPrinterDefaults(SageObject): self._alphabet = alphabet def mode(self, mode=None): - """ + r""" Set the default printing mode. - mode=None returns the current value. + ``mode=None`` returns the current value. - The allowed values for mode are: 'val-unit', 'series', - 'terse', 'digits' and 'bars'. + The allowed values for mode are: ``'val-unit'``, ``'series'``, + ``'terse'``, ``'digits'`` and ``'bars'``. EXAMPLES:: @@ -150,10 +150,10 @@ class pAdicPrinterDefaults(SageObject): raise ValueError("invalid printing mode") def allow_negatives(self, neg = None): - """ + r""" Controls whether or not to display a balanced representation. - neg=None returns the current value. + ``neg=None`` returns the current value. EXAMPLES:: @@ -172,13 +172,13 @@ class pAdicPrinterDefaults(SageObject): self._pos = not neg def max_series_terms(self, max = None): - """ + r""" Controls the maximum number of terms shown when printing in - 'series', 'digits' or 'bars' mode. + ``'series'``, ``'digits'`` or ``'bars'`` mode. - max=None returns the current value. + ``max=None`` returns the current value. - max=-1 encodes 'no limit.' + ``max=-1`` encodes 'no limit.' EXAMPLES:: @@ -197,14 +197,14 @@ class pAdicPrinterDefaults(SageObject): self._max_ram_terms = int(max) def max_unram_terms(self, max = None): - """ + r""" For rings with non-prime residue fields, controls how many - terms appear in the coefficient of each pi^n when printing in - 'series' or 'bar' modes. + terms appear in the coefficient of each ``pi^n`` when printing in + ``'series'`` or ``'bar'`` modes. - max=None returns the current value. + ``max=None`` returns the current value. - max=-1 encodes 'no limit.' + ``max=-1`` encodes 'no limit.' EXAMPLES:: @@ -222,13 +222,13 @@ class pAdicPrinterDefaults(SageObject): self._max_unram_terms = int(max) def max_poly_terms(self, max = None): - """ + r""" Controls the number of terms appearing when printing - polynomial representations in 'terse' or 'val-unit' modes. + polynomial representations in ``'terse'`` or ``'val-unit'`` modes. - max=None returns the current value. + ``max=None`` returns the current value. - max=-1 encodes 'no limit.' + ``max=-1`` encodes 'no limit.' EXAMPLES:: @@ -248,10 +248,10 @@ class pAdicPrinterDefaults(SageObject): self._max_terse_terms = int(max) def sep(self, sep = None): - """ - Controls the separator used in 'bars' mode. + r""" + Controls the separator used in ``'bars'`` mode. - sep=None returns the current value. + ``sep=None`` returns the current value. EXAMPLES:: @@ -271,13 +271,13 @@ class pAdicPrinterDefaults(SageObject): self._sep = str(sep) def alphabet(self, alphabet = None): - """ + r""" Controls the alphabet used to translate p-adic digits into - strings (so that no separator need be used in 'digits' mode). + strings (so that no separator need be used in ``'digits'`` mode). - alphabet should be passed in as a list or tuple. + ``alphabet`` should be passed in as a list or tuple. - alphabet=None returns the current value. + ``alphabet=None`` returns the current value. EXAMPLES:: @@ -305,11 +305,11 @@ cdef class pAdicPrinter_class(SageObject): """ def __init__(self, ring, mode, pos, ram_name, unram_name, var_name, max_ram_terms, max_unram_terms, max_terse_terms, sep, alphabet, show_prec): """ - Initializes a pAdicPrinter. + Initializes a :class:`pAdicPrinter`. INPUT: - - ring -- the ring or field to which this pAdicPrinter is + - ring -- the ring or field to which this :class:`pAdicPrinter` is attached. - mode -- The allowed values for mode are: 'val-unit', @@ -514,14 +514,14 @@ cdef class pAdicPrinter_class(SageObject): def richcmp_modes(pAdicPrinter_class self, pAdicPrinter_class other, int op): """ - Return a comparison of the printing modes of self and other. + Return a comparison of the printing modes of ``self`` and ``other``. Return 0 if and only if all relevant modes are equal - (max_unram_terms is irrelevant if the ring is totally ramified - over the base for example). This does not check if the rings are + (``max_unram_terms`` is irrelevant if the ring is totally ramified + over the base, for example). This does not check if the rings are equal (to prevent infinite recursion in the comparison functions of p-adic rings), but it does check if the primes - are the same (since the prime affects whether pos is + are the same (since the prime affects whether ``pos`` is relevant). EXAMPLES:: @@ -531,7 +531,7 @@ cdef class pAdicPrinter_class(SageObject): sage: R._printer == S._printer True sage: R = Qp(7) - sage: S = Qp(7,print_mode='val-unit') + sage: S = Qp(7, print_mode='val-unit') sage: R == S False sage: R._printer < S._printer @@ -636,7 +636,7 @@ cdef class pAdicPrinter_class(SageObject): def dict(self): """ - Returns a dictionary storing all of self's printing options. + Return a dictionary storing all of ``self``'s printing options. EXAMPLES:: @@ -849,10 +849,10 @@ cdef class pAdicPrinter_class(SageObject): INPUT: - - elt -- a p-adic element of the appropriate ring to print. + - ``elt`` -- a p-adic element of the appropriate ring to print. - - do_latex -- whether to return a latex representation or - a normal one. + - ``do_latex`` -- whether to return a latex representation or + a normal one. EXAMPLES:: diff --git a/src/sage/rings/padics/unramified_extension_generic.py b/src/sage/rings/padics/unramified_extension_generic.py index 7973ed814c3..5bc08a7a54f 100644 --- a/src/sage/rings/padics/unramified_extension_generic.py +++ b/src/sage/rings/padics/unramified_extension_generic.py @@ -26,21 +26,21 @@ class UnramifiedExtensionGeneric(pAdicExtensionGeneric): - """ - An unramified extension of Qp or Zp. + r""" + An unramified extension of `\QQ_p` or `\ZZ_p`. """ def __init__(self, poly, prec, print_mode, names, element_class): """ - Initializes self + Initializes ``self``. INPUT: - - poly -- Polynomial defining this extension. - - prec -- The precision cap - - print_mode -- a dictionary with print options - - names -- a 4-tuple, (variable_name, residue_name, - unramified_subextension_variable_name, uniformizer_name) - - element_class -- the class for elements of this unramified extension. + - ``poly`` -- Polynomial defining this extension. + - ``prec`` -- The precision cap + - ``print_mode`` -- a dictionary with print options + - ``names`` -- a 4-tuple, (``variable_name``, ``residue_name``, + ``unramified_subextension_variable_name``, ``uniformizer_name``) + - ``element_class`` -- the class for elements of this unramified extension. EXAMPLES:: @@ -76,7 +76,7 @@ def _extension_type(self): def absolute_f(self): """ Return the degree of the residue field of this ring/field - over its prime subfield + over its prime subfield. EXAMPLES:: @@ -113,7 +113,7 @@ def residue_class_field(self): def residue_ring(self, n): """ - Return the quotient of the ring of integers by the nth power of its maximal ideal. + Return the quotient of the ring of integers by the `n`-th power of its maximal ideal. EXAMPLES:: @@ -135,11 +135,11 @@ def residue_ring(self, n): def discriminant(self, K=None): """ - Returns the discriminant of self over the subring K. + Return the discriminant of ``self`` over the subring `K`. INPUT: - - K -- a subring/subfield (defaults to the base ring). + - ``K`` -- a subring/subfield (defaults to the base ring). EXAMPLES:: @@ -174,13 +174,13 @@ def discriminant(self, K=None): def is_galois(self, K=None): """ - Returns True if this extension is Galois. + Return ``True`` if this extension is Galois. Every unramified extension is Galois. INPUT: - - K -- a subring/subfield (defaults to the base ring). + - ``K`` -- a subring/subfield (defaults to the base ring). EXAMPLES:: @@ -193,7 +193,7 @@ def is_galois(self, K=None): def gen(self, n=0): """ - Returns a generator for this unramified extension. + Return a generator for this unramified extension. This is an element that satisfies the polynomial defining this extension. Such an element will reduce to a generator of the @@ -211,7 +211,7 @@ def gen(self, n=0): @cached_method def _frob_gen(self, arithmetic = True): """ - Returns frobenius of the generator for this unramified extension + Return frobenius of the generator for this unramified extension EXAMPLES:: @@ -233,7 +233,7 @@ def _frob_gen(self, arithmetic = True): def uniformizer_pow(self, n): """ - Returns the nth power of the uniformizer of self (as an element of self). + Return the `n`-th power of the uniformizer of ``self`` (as an element of ``self``). EXAMPLES:: @@ -244,8 +244,8 @@ def uniformizer_pow(self, n): return self(self.prime_pow(n)) def uniformizer(self): - """ - Returns a uniformizer for this extension. + r""" + Return a uniformizer for this extension. Since this extension is unramified, a uniformizer for the ground ring will also be a uniformizer for this extension. @@ -259,8 +259,8 @@ def uniformizer(self): return self(self.ground_ring().uniformizer()) def _uniformizer_print(self): - """ - Returns how the uniformizer is supposed to print. + r""" + Return how the uniformizer is supposed to print. EXAMPLES:: @@ -270,8 +270,8 @@ def _uniformizer_print(self): return self.ground_ring()._uniformizer_print() def _unram_print(self): - """ - Returns how the generator prints. + r""" + Return how the generator prints. EXAMPLES:: @@ -282,20 +282,19 @@ def _unram_print(self): def has_pth_root(self): r""" - Returns whether or not `\ZZ_p` has a primitive `p^{\mbox{th}}` root of unity. + Return whether or not `\ZZ_p` has a primitive `p`-th root of unity. - Since adjoining a `p^{\mbox{th}}` root of unity yields a - totally ramified extension, self will contain one if and only + Since adjoining a `p`-th root of unity yields a + totally ramified extension, ``self`` will contain one if and only if the ground ring does. INPUT: - - self -- a p-adic ring + - ``self`` -- a `p`-adic ring OUTPUT: - - boolean -- whether self has primitive `p^{\mbox{th}}` - root of unity. + boolean -- whether ``self`` has primitive `p`-th root of unity. EXAMPLES:: @@ -308,12 +307,12 @@ def has_pth_root(self): def has_root_of_unity(self, n): r""" - Return whether or not `\ZZ_p` has a primitive `n^{\mbox{th}}` + Return whether or not `\ZZ_p` has a primitive `n`-th root of unity. INPUT: - - ``self`` -- a p-adic ring + - ``self`` -- a `p`-adic ring - ``n`` -- an integer OUTPUT: diff --git a/src/sage/rings/polynomial/flatten.py b/src/sage/rings/polynomial/flatten.py index 4ffe29f9ebe..84c38e52ee5 100644 --- a/src/sage/rings/polynomial/flatten.py +++ b/src/sage/rings/polynomial/flatten.py @@ -10,7 +10,10 @@ sage: from sage.rings.polynomial.flatten import FlatteningMorphism sage: phi = FlatteningMorphism(R); phi Flattening morphism: - From: Univariate Polynomial Ring in X over Multivariate Polynomial Ring in s, t over Univariate Polynomial Ring in y over Univariate Polynomial Ring in x over Rational Field + From: Univariate Polynomial Ring in X + over Multivariate Polynomial Ring in s, t + over Univariate Polynomial Ring in y + over Univariate Polynomial Ring in x over Rational Field To: Multivariate Polynomial Ring in x, y, s, t, X over Rational Field sage: phi('x*y*s + t*X').parent() Multivariate Polynomial Ring in x, y, s, t, X over Rational Field @@ -108,36 +111,36 @@ def __init__(self, domain): :: - sage: K. = NumberField(x^3 - 2) - sage: R = K['x','y']['a','b'] + sage: K. = NumberField(x^3 - 2) # optional - sage.rings.number_field + sage: R = K['x','y']['a','b'] # optional - sage.rings.number_field sage: from sage.rings.polynomial.flatten import FlatteningMorphism - sage: f = FlatteningMorphism(R) - sage: f(R('v*a*x^2 + b^2 + 1/v*y')) + sage: f = FlatteningMorphism(R) # optional - sage.rings.number_field + sage: f(R('v*a*x^2 + b^2 + 1/v*y')) # optional - sage.rings.number_field v*x^2*a + b^2 + (1/2*v^2)*y :: - sage: R = QQbar['x','y']['a','b'] + sage: R = QQbar['x','y']['a','b'] # optional - sage.rings.number_field sage: from sage.rings.polynomial.flatten import FlatteningMorphism - sage: f = FlatteningMorphism(R) - sage: f(R('QQbar(sqrt(2))*a*x^2 + b^2 + QQbar(I)*y')) + sage: f = FlatteningMorphism(R) # optional - sage.rings.number_field + sage: f(R('QQbar(sqrt(2))*a*x^2 + b^2 + QQbar(I)*y')) # optional - sage.rings.number_field 1.414213562373095?*x^2*a + b^2 + I*y :: - sage: R. = PolynomialRing(QQbar,1) + sage: R. = PolynomialRing(QQbar, 1) # optional - sage.rings.number_field sage: from sage.rings.polynomial.flatten import FlatteningMorphism - sage: f = FlatteningMorphism(R) - sage: f.domain(), f.codomain() + sage: f = FlatteningMorphism(R) # optional - sage.rings.number_field + sage: f.domain(), f.codomain() # optional - sage.rings.number_field (Multivariate Polynomial Ring in z over Algebraic Field, Multivariate Polynomial Ring in z over Algebraic Field) :: - sage: R. = PolynomialRing(QQbar) + sage: R. = PolynomialRing(QQbar) # optional - sage.rings.number_field sage: from sage.rings.polynomial.flatten import FlatteningMorphism - sage: f = FlatteningMorphism(R) - sage: f.domain(), f.codomain() + sage: f = FlatteningMorphism(R) # optional - sage.rings.number_field + sage: f.domain(), f.codomain() # optional - sage.rings.number_field (Univariate Polynomial Ring in z over Algebraic Field, Univariate Polynomial Ring in z over Algebraic Field) @@ -243,7 +246,8 @@ def section(self): sage: h.section() Unflattening morphism: From: Multivariate Polynomial Ring in a, b, c, x, y, z over Rational Field - To: Multivariate Polynomial Ring in x, y, z over Multivariate Polynomial Ring in a, b, c over Rational Field + To: Multivariate Polynomial Ring in x, y, z + over Multivariate Polynomial Ring in a, b, c over Rational Field :: @@ -252,7 +256,8 @@ def section(self): sage: FlatteningMorphism(R).section() Unflattening morphism: From: Multivariate Polynomial Ring in a, b, c over Integer Ring - To: Univariate Polynomial Ring in c over Univariate Polynomial Ring in b over Univariate Polynomial Ring in a over Integer Ring + To: Univariate Polynomial Ring in c over Univariate Polynomial Ring in b + over Univariate Polynomial Ring in a over Integer Ring """ return UnflatteningMorphism(self.codomain(), self.domain()) @@ -268,7 +273,8 @@ def inverse(self): sage: f.inverse() Unflattening morphism: From: Multivariate Polynomial Ring in x, y, u, v over Rational Field - To: Multivariate Polynomial Ring in u, v over Multivariate Polynomial Ring in x, y over Rational Field + To: Multivariate Polynomial Ring in u, v + over Multivariate Polynomial Ring in x, y over Rational Field """ return self.section() @@ -286,7 +292,8 @@ class UnflatteningMorphism(Morphism): sage: g = f(R('x^2 + c*y^2 - z^2'));g x^2 + c*y^2 - z^2 sage: g.parent() - Multivariate Polynomial Ring in x, y, z over Univariate Polynomial Ring in c over Rational Field + Multivariate Polynomial Ring in x, y, z + over Univariate Polynomial Ring in c over Rational Field :: @@ -296,7 +303,8 @@ class UnflatteningMorphism(Morphism): sage: UnflatteningMorphism(R, S) Unflattening morphism: From: Multivariate Polynomial Ring in a, b, x, y over Rational Field - To: Multivariate Polynomial Ring in x, y over Multivariate Polynomial Ring in a, b over Rational Field + To: Multivariate Polynomial Ring in x, y + over Multivariate Polynomial Ring in a, b over Rational Field """ def __init__(self, domain, codomain): @@ -366,8 +374,10 @@ def _call_(self, p): TESTS:: sage: from sage.rings.polynomial.flatten import FlatteningMorphism - sage: for R in [ZZ['x']['y']['a,b,c'], GF(4)['x','y']['a','b'], - ....: AA['x']['a','b']['y'], QQbar['a1','a2']['t']['X','Y']]: + sage: rings = [ZZ['x']['y']['a,b,c']] + sage: rings += [GF(4)['x','y']['a','b']] # optional - sage.rings.finite_rings + sage: rings += [AA['x']['a','b']['y'], QQbar['a1','a2']['t']['X','Y']] # optional - sage.rings.number_field + sage: for R in rings: ....: f = FlatteningMorphism(R) ....: g = f.section() ....: for _ in range(10): @@ -423,8 +433,9 @@ class SpecializationMorphism(Morphism): sage: from sage.rings.polynomial.flatten import SpecializationMorphism sage: xi = SpecializationMorphism(S, {c:0}); xi Specialization morphism: - From: Univariate Polynomial Ring in z over Univariate Polynomial Ring in c over Rational Field - To: Univariate Polynomial Ring in z over Rational Field + From: Univariate Polynomial Ring in z + over Univariate Polynomial Ring in c over Rational Field + To: Univariate Polynomial Ring in z over Rational Field sage: xi(z^2+c) z^2 @@ -437,8 +448,11 @@ class SpecializationMorphism(Morphism): sage: from sage.rings.polynomial.flatten import SpecializationMorphism sage: xi = SpecializationMorphism(S, D); xi Specialization morphism: - From: Multivariate Polynomial Ring in x, y, z over Multivariate Polynomial Ring in a, b, c over Multivariate Polynomial Ring in u, v over Rational Field - To: Multivariate Polynomial Ring in y, z over Univariate Polynomial Ring in c over Univariate Polynomial Ring in v over Rational Field + From: Multivariate Polynomial Ring in x, y, z + over Multivariate Polynomial Ring in a, b, c + over Multivariate Polynomial Ring in u, v over Rational Field + To: Multivariate Polynomial Ring in y, z over Univariate Polynomial Ring in c + over Univariate Polynomial Ring in v over Rational Field sage: xi(a*(x*z+y^2)*u+b*v*u*(x*z+y^2)*y^2*c+c*y^2*z^2) 2*v*c*y^4 + c*y^2*z^2 + y^2 """ @@ -655,8 +669,10 @@ def __init__(self, domain, D): sage: phi = FractionSpecializationMorphism(Frac(S), {c:3}) sage: phi Fraction Specialization morphism: - From: Fraction Field of Multivariate Polynomial Ring in x, y over Multivariate Polynomial Ring in a, c over Rational Field - To: Fraction Field of Multivariate Polynomial Ring in x, y over Univariate Polynomial Ring in a over Rational Field + From: Fraction Field of Multivariate Polynomial Ring in x, y + over Multivariate Polynomial Ring in a, c over Rational Field + To: Fraction Field of Multivariate Polynomial Ring in x, y + over Univariate Polynomial Ring in a over Rational Field """ if not is_FractionField(domain): raise TypeError("domain must be a fraction field") diff --git a/src/sage/rings/polynomial/hilbert.pyx b/src/sage/rings/polynomial/hilbert.pyx index 01cb166b7fb..864e2766407 100644 --- a/src/sage/rings/polynomial/hilbert.pyx +++ b/src/sage/rings/polynomial/hilbert.pyx @@ -442,16 +442,16 @@ def first_hilbert_series(I, grading=None, return_grading=False): sage: I = singular.ideal(['x^2','y^2','z^2']) sage: first_hilbert_series(I) -t^6 + 3*t^4 - 3*t^2 + 1 - sage: first_hilbert_series(I,return_grading=True) + sage: first_hilbert_series(I, return_grading=True) (-t^6 + 3*t^4 - 3*t^2 + 1, (1, 1, 1)) - sage: first_hilbert_series(I,grading=(1,2,3)) + sage: first_hilbert_series(I, grading=(1,2,3)) -t^12 + t^10 + t^8 - t^4 - t^2 + 1 TESTS: We test against some corner cases:: - sage: R.=PolynomialRing(QQ) + sage: R. = PolynomialRing(QQ) sage: I = 0*R sage: first_hilbert_series(I) 1 @@ -559,18 +559,19 @@ def hilbert_poincare_series(I, grading=None): sage: from sage.rings.polynomial.hilbert import hilbert_poincare_series sage: R = PolynomialRing(QQ,'x',9) - sage: I = [m.lm() for m in ((matrix(R,3,R.gens())^2).list()*R).groebner_basis()]*R + sage: I = [m.lm() + ....: for m in ((matrix(R, 3, R.gens())^2).list() * R).groebner_basis()] * R sage: hilbert_poincare_series(I) (t^7 - 3*t^6 + 2*t^5 + 2*t^4 - 2*t^3 + 6*t^2 + 5*t + 1)/(t^4 - 4*t^3 + 6*t^2 - 4*t + 1) - sage: hilbert_poincare_series((R*R.gens())^2, grading=range(1,10)) + sage: hilbert_poincare_series((R * R.gens())^2, grading=range(1,10)) t^9 + t^8 + t^7 + t^6 + t^5 + t^4 + t^3 + t^2 + t + 1 The following example is taken from :trac:`20145`:: - sage: n=4;m=11;P = PolynomialRing(QQ,n*m,"x"); x = P.gens(); M = Matrix(n,x) + sage: n=4; m=11; P = PolynomialRing(QQ, n*m, "x"); x = P.gens(); M = Matrix(n, x) sage: from sage.rings.polynomial.hilbert import first_hilbert_series sage: I = P.ideal(M.minors(2)) - sage: J = P*[m.lm() for m in I.groebner_basis()] + sage: J = P * [m.lm() for m in I.groebner_basis()] sage: hilbert_poincare_series(J).numerator() 120*t^3 + 135*t^2 + 30*t + 1 sage: hilbert_poincare_series(J).denominator().factor() @@ -578,7 +579,7 @@ def hilbert_poincare_series(I, grading=None): This example exceeded the capabilities of Singular before version 4.2.1p2. In Singular 4.3.1, it works correctly on 64-bit, but on 32-bit, it prints overflow warnings - and omits some terms. + and omits some terms:: sage: J.hilbert_numerator(algorithm='singular') 120*t^33 - 3465*t^32 + 48180*t^31 - 429374*t^30 + 2753520*t^29 - 13522410*t^28 + 52832780*t^27 - 168384150*t^26 + 445188744*t^25 - 987193350*t^24 + 1847488500*t^23 + 1372406746*t^22 - 403422496*t^21 - 8403314*t^20 - 471656596*t^19 + 1806623746*t^18 + 752776200*t^17 + 752776200*t^16 - 1580830020*t^15 + 1673936550*t^14 - 1294246800*t^13 + 786893250*t^12 - 382391100*t^11 + 146679390*t^10 - 42299400*t^9 + 7837830*t^8 - 172260*t^7 - 468930*t^6 + 183744*t^5 - 39270*t^4 + 5060*t^3 - 330*t^2 + 1 # 64-bit diff --git a/src/sage/rings/polynomial/ideal.py b/src/sage/rings/polynomial/ideal.py index 857718c9a10..d84264e9d69 100644 --- a/src/sage/rings/polynomial/ideal.py +++ b/src/sage/rings/polynomial/ideal.py @@ -26,28 +26,29 @@ class Ideal_1poly_field(Ideal_pid): """ def residue_class_degree(self): """ - Returns the degree of the generator of this ideal. + Return the degree of the generator of this ideal. This function is included for compatibility with ideals in rings of integers of number fields. EXAMPLES:: - sage: R. = GF(5)[] - sage: P = R.ideal(t^4 + t + 1) - sage: P.residue_class_degree() + sage: R. = GF(5)[] # optional - sage.rings.finite_rings + sage: P = R.ideal(t^4 + t + 1) # optional - sage.rings.finite_rings + sage: P.residue_class_degree() # optional - sage.rings.finite_rings 4 """ return self.gen().degree() def residue_field(self, names=None, check=True): r""" - If this ideal is `P \subset F_p[t]`, returns the quotient `F_p[t]/P`. + If this ideal is `P \subset F_p[t]`, return the quotient `F_p[t]/P`. EXAMPLES:: - sage: R. = GF(17)[]; P = R.ideal(t^3 + 2*t + 9) - sage: k. = P.residue_field(); k - Residue field in a of Principal ideal (t^3 + 2*t + 9) of Univariate Polynomial Ring in t over Finite Field of size 17 + sage: R. = GF(17)[]; P = R.ideal(t^3 + 2*t + 9) # optional - sage.rings.finite_rings + sage: k. = P.residue_field(); k # optional - sage.rings.finite_rings + Residue field in a of Principal ideal (t^3 + 2*t + 9) of + Univariate Polynomial Ring in t over Finite Field of size 17 """ if check: if not self.ring().base_ring().is_finite(): @@ -74,11 +75,11 @@ def groebner_basis(self, algorithm=None): sage: R. = QQ[] sage: I = R.ideal([x^2 - 1, x^3 - 1]) - sage: G = I.groebner_basis(); G + sage: G = I.groebner_basis(); G # optional - sage.libs.singular [x - 1] - sage: type(G) + sage: type(G) # optional - sage.libs.singular - sage: list(G) + sage: list(G) # optional - sage.libs.singular [x - 1] """ gb = self.gens_reduced() diff --git a/src/sage/rings/polynomial/infinite_polynomial_element.py b/src/sage/rings/polynomial/infinite_polynomial_element.py index c7d43e31d1b..cad5877fd0f 100644 --- a/src/sage/rings/polynomial/infinite_polynomial_element.py +++ b/src/sage/rings/polynomial/infinite_polynomial_element.py @@ -18,7 +18,7 @@ x_3 sage: b y_4 - sage: c = a*b+a^3-2*b^4 + sage: c = a*b + a^3 - 2*b^4 sage: c x_3^3 + x_3*y_4 - 2*y_4^4 @@ -48,8 +48,8 @@ There is a permutation action on Infinite Polynomial Rings by permuting the indices of the variables:: - sage: P = Permutation(((4,5),(2,3))) - sage: c^P + sage: P = Permutation(((4,5),(2,3))) # optional - sage.combinat + sage: c^P # optional - sage.combinat x_2^3 + x_2*y_5 - 2*y_5^4 Note that ``P(0)==0``, and thus variables of index zero are invariant @@ -80,7 +80,7 @@ sage: C. = InfinitePolynomialRing(B,order='degrevlex') sage: C Infinite polynomial ring in b, c over Infinite polynomial ring in a over Integer Ring - sage: 1/2*b_1*a[4]+c[3] + sage: 1/2*b_1*a[4] + c[3] 1/2*a_4*b_1 + c_3 """ @@ -299,15 +299,16 @@ def polynomial(self): EXAMPLES:: - sage: X. = InfinitePolynomialRing(GF(7)) - sage: p = x[2]*y[1]+3*y[0] - sage: p + sage: X. = InfinitePolynomialRing(GF(7)) # optional - sage.rings.finite_rings + sage: p = x[2]*y[1] + 3*y[0] # optional - sage.rings.finite_rings + sage: p # optional - sage.rings.finite_rings x_2*y_1 + 3*y_0 - sage: p.polynomial() + sage: p.polynomial() # optional - sage.rings.finite_rings x_2*y_1 + 3*y_0 - sage: p.polynomial().parent() - Multivariate Polynomial Ring in x_2, x_1, x_0, y_2, y_1, y_0 over Finite Field of size 7 - sage: p.parent() + sage: p.polynomial().parent() # optional - sage.rings.finite_rings + Multivariate Polynomial Ring in x_2, x_1, x_0, y_2, y_1, y_0 + over Finite Field of size 7 + sage: p.parent() # optional - sage.rings.finite_rings Infinite polynomial ring in x, y over Finite Field of size 7 """ @@ -402,7 +403,7 @@ def subs(self, fixed=None, **kwargs): INPUT: - - ``fixed`` -- (optional) ``dict`` with ``{variable:value}`` pairs + - ``fixed`` -- (optional) ``dict`` with ``{variable: value}`` pairs - ``**kwargs`` -- named parameters OUTPUT: @@ -439,13 +440,13 @@ def subs(self, fixed=None, **kwargs): The substitution can also handle matrices:: - sage: M = matrix([[1,0],[0,2]]) - sage: N = matrix([[0,3],[4,0]]) - sage: g = x[0]^2 + 3*x[1] - sage: g.subs({'x_0': M}) + sage: M = matrix([[1,0], [0,2]]) # optional - sage.modules + sage: N = matrix([[0,3], [4,0]]) # optional - sage.modules + sage: g = x[0]^2 + 3*x[1] # optional - sage.modules + sage: g.subs({'x_0': M}) # optional - sage.modules [3*x_1 + 1 0] [ 0 3*x_1 + 4] - sage: g.subs({x[0]: M, x[1]: N}) + sage: g.subs({x[0]: M, x[1]: N}) # optional - sage.modules [ 1 9] [12 4] @@ -454,11 +455,11 @@ def subs(self, fixed=None, **kwargs): sage: R. = InfinitePolynomialRing(QQ) sage: f = x[0] - sage: f.subs({x[0]:1}) + sage: f.subs({x[0]: 1}) 1 sage: f.subs(x_0=5) 5 - sage: f.subs({x[0]:1}, x_0=5) + sage: f.subs({x[0]: 1}, x_0=5) 1 TESTS:: @@ -487,7 +488,7 @@ def ring(self): EXAMPLES:: sage: X. = InfinitePolynomialRing(ZZ,implementation='sparse') - sage: p = x[100]*y[1]^3*x[1]^2+2*x[10]*y[30] + sage: p = x[100]*y[1]^3*x[1]^2 + 2*x[10]*y[30] sage: p.ring() Infinite polynomial ring in x, y over Integer Ring @@ -502,7 +503,7 @@ def is_unit(self): sage: R1. = InfinitePolynomialRing(ZZ) sage: R2. = InfinitePolynomialRing(QQ) - sage: (1+x[2]).is_unit() + sage: (1 + x[2]).is_unit() False sage: R1(1).is_unit() True @@ -510,7 +511,7 @@ def is_unit(self): False sage: R2(2).is_unit() True - sage: (1+a[2]).is_unit() + sage: (1 + a[2]).is_unit() False Check that :trac:`22454` is fixed:: @@ -539,10 +540,10 @@ def is_nilpotent(self): EXAMPLES:: - sage: R. = InfinitePolynomialRing(QQbar) - sage: (x[0]+x[1]).is_nilpotent() + sage: R. = InfinitePolynomialRing(QQbar) # optional - sage.rings.number_field + sage: (x[0] + x[1]).is_nilpotent() # optional - sage.rings.number_field False - sage: R(0).is_nilpotent() + sage: R(0).is_nilpotent() # optional - sage.rings.number_field True sage: _. = InfinitePolynomialRing(Zmod(4)) sage: (2*x[0]).is_nilpotent() @@ -586,7 +587,7 @@ def max_index(self): EXAMPLES:: sage: X. = InfinitePolynomialRing(QQ) - sage: p=x[1]^2+y[2]^2+x[1]*x[2]*y[3]+x[1]*y[4] + sage: p = x[1]^2 + y[2]^2 + x[1]*x[2]*y[3] + x[1]*y[4] sage: p.max_index() 4 sage: x[0].max_index() @@ -633,7 +634,7 @@ def _div_(self, x): Division by an integer over `\ZZ`:: sage: R. = InfinitePolynomialRing(ZZ, implementation='sparse') - sage: p = x[3]+x[2] + sage: p = x[3] + x[2] sage: q = p/2 sage: q 1/2*x_3 + 1/2*x_2 @@ -647,7 +648,7 @@ def _div_(self, x): 1/x_1 sage: (x[0]/x[0]) x_0/x_0 - sage: qt = 1/x[2]+2/x[1]; qt + sage: qt = 1/x[2] + 2/x[1]; qt (2*x_2 + x_1)/(x_2*x_1) sage: qt.parent() Fraction Field of Infinite polynomial ring in x over Rational Field @@ -655,7 +656,7 @@ def _div_(self, x): sage: z = 1/(x[2]*(x[1]+x[2]))+1/(x[1]*(x[1]+x[2])) sage: z.parent() Fraction Field of Infinite polynomial ring in x over Rational Field - sage: factor(z) + sage: factor(z) # optional - sage.libs.singular x_1^-1 * x_2^-1 """ if not x.variables(): @@ -700,7 +701,7 @@ def lm(self): EXAMPLES:: sage: X. = InfinitePolynomialRing(QQ) - sage: p = 2*x[10]*y[30]+x[10]*y[1]^3*x[1]^2 + sage: p = 2*x[10]*y[30] + x[10]*y[1]^3*x[1]^2 sage: p.lm() x_10*x_1^2*y_1^3 @@ -722,7 +723,7 @@ def lc(self): EXAMPLES:: sage: X. = InfinitePolynomialRing(QQ) - sage: p = 2*x[10]*y[30]+3*x[10]*y[1]^3*x[1]^2 + sage: p = 2*x[10]*y[30] + 3*x[10]*y[1]^3*x[1]^2 sage: p.lc() 3 @@ -742,7 +743,7 @@ def lt(self): EXAMPLES:: sage: X. = InfinitePolynomialRing(QQ) - sage: p = 2*x[10]*y[30]+3*x[10]*y[1]^3*x[1]^2 + sage: p = 2*x[10]*y[30] + 3*x[10]*y[1]^3*x[1]^2 sage: p.lt() 3*x_10*x_1^2*y_1^3 @@ -762,7 +763,7 @@ def tail(self): EXAMPLES:: sage: X. = InfinitePolynomialRing(QQ) - sage: p = 2*x[10]*y[30]+3*x[10]*y[1]^3*x[1]^2 + sage: p = 2*x[10]*y[30] + 3*x[10]*y[1]^3*x[1]^2 sage: p.tail() 2*x_10*y_30 @@ -811,7 +812,7 @@ def footprint(self): EXAMPLES:: sage: X. = InfinitePolynomialRing(QQ) - sage: p = x[30]*y[1]^3*x[1]^2+2*x[10]*y[30] + sage: p = x[30]*y[1]^3*x[1]^2 + 2*x[10]*y[30] sage: sorted(p.footprint().items()) [(1, [2, 3]), (30, [1, 0])] @@ -863,7 +864,7 @@ def symmetric_cancellation_order(self, other): INPUT: - self, other -- two Infinite Polynomials + ``self``, ``other`` -- two Infinite Polynomials ASSUMPTION: @@ -895,11 +896,11 @@ def symmetric_cancellation_order(self, other): sage: X. = InfinitePolynomialRing(QQ) sage: (x[2]*x[1]).symmetric_cancellation_order(x[2]^2) (None, 1, 1) - sage: (x[2]*x[1]).symmetric_cancellation_order(x[2]*x[3]*y[1]) + sage: (x[2]*x[1]).symmetric_cancellation_order(x[2]*x[3]*y[1]) # optional - sage.combinat (-1, [2, 3, 1], y_1) - sage: (x[2]*x[1]*y[1]).symmetric_cancellation_order(x[2]*x[3]*y[1]) + sage: (x[2]*x[1]*y[1]).symmetric_cancellation_order(x[2]*x[3]*y[1]) # optional - sage.combinat (None, 1, 1) - sage: (x[2]*x[1]*y[1]).symmetric_cancellation_order(x[2]*x[3]*y[2]) + sage: (x[2]*x[1]*y[1]).symmetric_cancellation_order(x[2]*x[3]*y[2]) # optional - sage.combinat (-1, [2, 3, 1], 1) """ @@ -1085,7 +1086,7 @@ def reduce(self, I, tailreduce=False, report=None): EXAMPLES:: sage: X. = InfinitePolynomialRing(QQ) - sage: p = y[1]^2*y[3]+y[2]*x[3]^3 + sage: p = y[1]^2*y[3] + y[2]*x[3]^3 sage: p.reduce([y[2]*x[1]^2]) x_3^3*y_2 + y_3*y_1^2 @@ -1111,7 +1112,7 @@ def reduce(self, I, tailreduce=False, report=None): Last, we demonstrate the ``report`` option:: - sage: p=x[1]^2+y[2]^2+x[1]*x[2]*y[3]+x[1]*y[4] + sage: p = x[1]^2 + y[2]^2 + x[1]*x[2]*y[3] + x[1]*y[4] sage: p.reduce(I, tailreduce=True, report=True) :T[2]:> > @@ -1200,7 +1201,7 @@ def gcd(self, x): EXAMPLES:: sage: R.=InfinitePolynomialRing(QQ) - sage: p1=x[0]+x[1]**2 + sage: p1=x[0] + x[1]**2 sage: gcd(p1,p1+3) 1 sage: gcd(p1,p1)==p1 @@ -1232,9 +1233,11 @@ class InfinitePolynomial_sparse(InfinitePolynomial): sage: p a*b_100 + 1/2*c_4 sage: p.parent() - Infinite polynomial ring in b, c over Univariate Polynomial Ring in a over Rational Field + Infinite polynomial ring in b, c + over Univariate Polynomial Ring in a over Rational Field sage: p.polynomial().parent() - Multivariate Polynomial Ring in b_100, b_0, c_4, c_0 over Univariate Polynomial Ring in a over Rational Field + Multivariate Polynomial Ring in b_100, b_0, c_4, c_0 + over Univariate Polynomial Ring in a over Rational Field """ @@ -1255,8 +1258,8 @@ def __call__(self, *args, **kwargs): sage: a(x_1=x[100]) x_100 + x_0 - sage: M = matrix([[1,1],[2,0]]) - sage: a(x_1=M) + sage: M = matrix([[1,1], [2,0]]) # optional - sage.modules + sage: a(x_1=M) # optional - sage.modules [x_0 + 1 1] [ 2 x_0] """ @@ -1384,10 +1387,10 @@ def __pow__(self, n): EXAMPLES:: - sage: X. = InfinitePolynomialRing(QQ,implementation='sparse') - sage: p = x[10]*y[2]+2*x[1]*y[3] - sage: P = Permutation(((1,2),(3,4,5))) - sage: p^P # indirect doctest + sage: X. = InfinitePolynomialRing(QQ, implementation='sparse') + sage: p = x[10]*y[2] + 2*x[1]*y[3] + sage: P = Permutation(((1,2),(3,4,5))) # optional - sage.combinat + sage: p^P # indirect doctest # optional - sage.combinat x_10*y_1 + 2*x_2*y_4 """ @@ -1471,16 +1474,16 @@ def _richcmp_(self, x, op): Two infinite polynomial rings in different implementation and order:: - sage: Y = InfinitePolynomialRing(QQ,['x','y'],order='deglex',implementation='dense') + sage: Y = InfinitePolynomialRing(QQ,['x','y'],order='deglex', implementation='dense') sage: x[2] == Y(x[2]) # indirect doctest True An example in which a previous version had failed:: - sage: X. = InfinitePolynomialRing(GF(3), order='degrevlex', implementation='sparse') - sage: p = Y('x_3*x_0^2 + x_0*y_3*y_0') - sage: q = Y('x_1*x_0^2 + x_0*y_1*y_0') - sage: p < q # indirect doctest + sage: X. = InfinitePolynomialRing(GF(3), order='degrevlex', implementation='sparse') # optional - sage.rings.finite_rings + sage: p = Y('x_3*x_0^2 + x_0*y_3*y_0') # optional - sage.rings.finite_rings + sage: q = Y('x_1*x_0^2 + x_0*y_1*y_0') # optional - sage.rings.finite_rings + sage: p < q # indirect doctest # optional - sage.rings.finite_rings False """ @@ -1523,9 +1526,6 @@ class InfinitePolynomial_dense(InfinitePolynomial): Of course, one should not directly invoke this class, but rather construct elements of ``A`` in the usual way. - This class inherits from - :class:`~sage.rings.polynomial.infinite_polynomial_element.InfinitePolynomial_sparse`. See - there for a description of the methods. """ def __call__(self, *args, **kwargs): @@ -1534,7 +1534,7 @@ def __call__(self, *args, **kwargs): sage: X. = InfinitePolynomialRing(QQ) sage: a = x[0] + x[1] - sage: a(x_0=2,x_1=x[1]) + sage: a(x_0=2, x_1=x[1]) x_1 + 2 sage: _.parent() Infinite polynomial ring in x over Rational Field @@ -1569,7 +1569,7 @@ def _richcmp_(self, x, op): A classical and an infinite polynomial ring:: - sage: X. = InfinitePolynomialRing(ZZ,order='degrevlex') + sage: X. = InfinitePolynomialRing(ZZ, order='degrevlex') sage: Y. = QQ[] sage: x[3] == x_3 True @@ -1577,16 +1577,16 @@ def _richcmp_(self, x, op): Two infinite polynomial rings with different order and implementation:: - sage: Y = InfinitePolynomialRing(QQ,['x','y'],order='deglex',implementation='sparse') + sage: Y = InfinitePolynomialRing(QQ,['x','y'], order='deglex', implementation='sparse') sage: x[2] == Y(x[2]) True An example in which a previous version had failed:: - sage: X. = InfinitePolynomialRing(GF(3), order='degrevlex', implementation='dense') - sage: p = Y('x_3*x_0^2 + x_0*y_3*y_0') - sage: q = Y('x_1*x_0^2 + x_0*y_1*y_0') - sage: p < q + sage: X. = InfinitePolynomialRing(GF(3), order='degrevlex', implementation='dense') # optional - sage.rings.finite_rings + sage: p = Y('x_3*x_0^2 + x_0*y_3*y_0') # optional - sage.rings.finite_rings + sage: q = Y('x_1*x_0^2 + x_0*y_1*y_0') # optional - sage.rings.finite_rings + sage: p < q # optional - sage.rings.finite_rings False """ @@ -1664,9 +1664,9 @@ def __pow__(self, n): sage: X. = InfinitePolynomialRing(QQ) sage: x[10]^3 x_10^3 - sage: p = x[10]*y[2]+2*x[1]*y[3] - sage: P = Permutation(((1,2),(3,4,5))) - sage: p^P + sage: p = x[10]*y[2] + 2*x[1]*y[3] + sage: P = Permutation(((1,2),(3,4,5))) # optional - sage.combinat + sage: p^P # optional - sage.combinat x_10*y_1 + 2*x_2*y_4 """ diff --git a/src/sage/rings/polynomial/infinite_polynomial_ring.py b/src/sage/rings/polynomial/infinite_polynomial_ring.py index 8e3ba4156e9..b9318c36d49 100644 --- a/src/sage/rings/polynomial/infinite_polynomial_ring.py +++ b/src/sage/rings/polynomial/infinite_polynomial_ring.py @@ -71,11 +71,12 @@ sage: g2 = 3*beta[1]; g2 3*beta_1 sage: A.polynomial_ring() - Multivariate Polynomial Ring in alpha_5, alpha_4, alpha_3, alpha_2, alpha_1, alpha_0, beta_5, beta_4, beta_3, beta_2, beta_1, beta_0 over Rational Field + Multivariate Polynomial Ring in alpha_5, alpha_4, alpha_3, alpha_2, alpha_1, alpha_0, + beta_5, beta_4, beta_3, beta_2, beta_1, beta_0 over Rational Field Of course, we provide the usual polynomial arithmetic:: - sage: f+g + sage: f + g x_5 + 3*y_1 + 2 sage: p = x[10]^2*(f+g); p x_10^2*x_5 + 3*x_10^2*y_1 + 2*x_10^2 @@ -85,10 +86,10 @@ There is a permutation action on the variables, by permuting positive variable indices:: - sage: P = Permutation(((10,1))) - sage: p^P + sage: P = Permutation(((10,1))) # optional - sage.combinat + sage: p^P # optional - sage.combinat x_5*x_1^2 + 3*x_1^2*y_10 + 2*x_1^2 - sage: p2^P + sage: p2^P # optional - sage.combinat alpha_5*alpha_1^2 + 3*alpha_1^2*beta_10 + 2*alpha_1^2 Note that `x_0^P = x_0`, since the permutations only change *positive* @@ -101,8 +102,8 @@ multiplication by ring elements and permutation of variables. If the base ring is a field, one can compute Symmetric Groebner Bases:: - sage: J = A*(alpha[1]*beta[2]) - sage: J.groebner_basis() + sage: J = A * (alpha[1]*beta[2]) + sage: J.groebner_basis() # optional - sage.combinat [alpha_1*beta_2, alpha_2*beta_1] For more details, see :class:`~sage.rings.polynomial.symmetric_ideal.SymmetricIdeal`. @@ -126,7 +127,8 @@ sage: A. = ZZ[] sage: B. = InfinitePolynomialRing(A, order='degrevlex') sage: B - Infinite polynomial ring in b, c, d over Multivariate Polynomial Ring in a_3, a_1 over Integer Ring + Infinite polynomial ring in b, c, d over + Multivariate Polynomial Ring in a_3, a_1 over Integer Ring It is no problem if one generator of the Infinite Polynomial Ring is called ``x`` and one variable of the base ring is also called @@ -144,7 +146,8 @@ :: sage: Y - Infinite polynomial ring in x, z over Multivariate Polynomial Ring in x, y_1 over Integer Ring + Infinite polynomial ring in x, z over + Multivariate Polynomial Ring in x, y_1 over Integer Ring The variable ``x`` of ``X`` can still be interpreted in ``Y``, although the first generator of ``Y`` is called ``x`` as well:: @@ -171,7 +174,7 @@ Traceback (most recent call last): ... CoercionException: Overlapping variables (('z', 'y'),['y_1']) are incompatible - sage: X. = PolynomialRing(ZZ,order='lex') + sage: X. = PolynomialRing(ZZ, order='lex') sage: # y_1 and y_2 would be in opposite order in an Infinite Polynomial Ring sage: Y. = InfinitePolynomialRing(X) Traceback (most recent call last): @@ -184,10 +187,10 @@ construction available:: sage: X. = InfinitePolynomialRing(ZZ) - sage: Y. = InfinitePolynomialRing(X,order='degrevlex') + sage: Y. = InfinitePolynomialRing(X, order='degrevlex') sage: Y Infinite polynomial ring in z over Infinite polynomial ring in x, y over Integer Ring - sage: Y. = InfinitePolynomialRing(X,implementation='sparse') + sage: Y. = InfinitePolynomialRing(X, implementation='sparse') sage: Y Infinite polynomial ring in z over Infinite polynomial ring in x, y over Integer Ring @@ -203,18 +206,18 @@ sage: x[2]/2+(5/3)*a[3]*x[4] + 1 5/3*a_3*x_4 + 1/2*x_2 + 1 - sage: R. = InfinitePolynomialRing(ZZ,implementation='sparse') + sage: R. = InfinitePolynomialRing(ZZ, implementation='sparse') sage: X. = InfinitePolynomialRing(R) sage: x[2]/2+(5/3)*a[3]*x[4] + 1 5/3*a_3*x_4 + 1/2*x_2 + 1 - sage: R. = InfinitePolynomialRing(ZZ,implementation='sparse') - sage: X. = InfinitePolynomialRing(R,implementation='sparse') + sage: R. = InfinitePolynomialRing(ZZ, implementation='sparse') + sage: X. = InfinitePolynomialRing(R, implementation='sparse') sage: x[2]/2+(5/3)*a[3]*x[4] + 1 5/3*a_3*x_4 + 1/2*x_2 + 1 sage: R. = InfinitePolynomialRing(ZZ) - sage: X. = InfinitePolynomialRing(R,implementation='sparse') + sage: X. = InfinitePolynomialRing(R, implementation='sparse') sage: x[2]/2+(5/3)*a[3]*x[4] + 1 5/3*a_3*x_4 + 1/2*x_2 + 1 @@ -309,11 +312,13 @@ def create_key(self, R, names=('x',), order='lex', implementation='dense'): (InfPoly{[y1], "lex", "dense"}(FractionField(...)), Integer Ring) sage: _[0].all [FractionField, InfPoly{[y1], "lex", "dense"}] - sage: InfinitePolynomialRing.create_key(QQ, names=['beta'], order='deglex', implementation='sparse') + sage: InfinitePolynomialRing.create_key(QQ, names=['beta'], order='deglex', + ....: implementation='sparse') (InfPoly{[beta], "deglex", "sparse"}(FractionField(...)), Integer Ring) sage: _[0].all [FractionField, InfPoly{[beta], "deglex", "sparse"}] - sage: InfinitePolynomialRing.create_key(QQ, names=['x','y'], implementation='dense') + sage: InfinitePolynomialRing.create_key(QQ, names=['x','y'], + ....: implementation='dense') (InfPoly{[x,y], "lex", "dense"}(FractionField(...)), Integer Ring) sage: _[0].all [FractionField, InfPoly{[x,y], "lex", "dense"}] @@ -805,8 +810,8 @@ def construction(self): EXAMPLES:: - sage: R. = InfinitePolynomialRing(GF(5)) - sage: R.construction() + sage: R. = InfinitePolynomialRing(GF(5)) # optional - sage.rings.finite_rings + sage: R.construction() # optional - sage.rings.finite_rings [InfPoly{[x,y], "lex", "dense"}, Finite Field of size 5] """ @@ -1104,10 +1109,10 @@ def is_noetherian(self): TESTS:: - sage: R = InfinitePolynomialRing(GF(2)) - sage: R + sage: R = InfinitePolynomialRing(GF(2)) # optional - sage.rings.finite_rings + sage: R # optional - sage.rings.finite_rings Infinite polynomial ring in x over Finite Field of size 2 - sage: R.is_noetherian() + sage: R.is_noetherian() # optional - sage.rings.finite_rings False sage: R. = InfinitePolynomialRing(QQ) @@ -1131,10 +1136,10 @@ def is_field(self, *args, **kwds): TESTS:: - sage: R = InfinitePolynomialRing(GF(2)) - sage: R + sage: R = InfinitePolynomialRing(GF(2)) # optional - sage.rings.finite_rings + sage: R # optional - sage.rings.finite_rings Infinite polynomial ring in x over Finite Field of size 2 - sage: R.is_field() + sage: R.is_field() # optional - sage.rings.finite_rings False :trac:`9443`:: @@ -1225,8 +1230,8 @@ def gen(self, i=None): x_1 sage: X.gen() is X.gen(0) True - sage: XX = InfinitePolynomialRing(GF(5)) - sage: XX.gen(0) is XX.gen() + sage: XX = InfinitePolynomialRing(GF(5)) # optional - sage.rings.finite_rings + sage: XX.gen(0) is XX.gen() # optional - sage.rings.finite_rings True """ if i is not None and i > len(self._names): @@ -1292,10 +1297,10 @@ def characteristic(self): EXAMPLES:: - sage: X. = InfinitePolynomialRing(GF(25,'a')) - sage: X + sage: X. = InfinitePolynomialRing(GF(25,'a')) # optional - sage.rings.finite_rings + sage: X # optional - sage.rings.finite_rings Infinite polynomial ring in x, y over Finite Field in a of size 5^2 - sage: X.characteristic() + sage: X.characteristic() # optional - sage.rings.finite_rings 5 """ @@ -1344,8 +1349,8 @@ def order(self): EXAMPLES:: - sage: R. = InfinitePolynomialRing(GF(2)) - sage: R.order() + sage: R. = InfinitePolynomialRing(GF(2)) # optional - sage.rings.finite_rings + sage: R.order() # optional - sage.rings.finite_rings +Infinity """ from sage.rings.infinity import Infinity @@ -1358,8 +1363,8 @@ def key_basis(self): EXAMPLES:: - sage: R. = InfinitePolynomialRing(GF(2)) - sage: R.key_basis() + sage: R. = InfinitePolynomialRing(GF(2)) # optional - sage.rings.finite_rings + sage: R.key_basis() # optional - sage.rings.finite_rings Key polynomial basis over Finite Field of size 2 """ from sage.combinat.key_polynomial import KeyPolynomialBasis @@ -1567,8 +1572,8 @@ def construction(self): EXAMPLES:: - sage: R. = InfinitePolynomialRing(GF(5)) - sage: R.construction() + sage: R. = InfinitePolynomialRing(GF(5)) # optional - sage.rings.finite_rings + sage: R.construction() # optional - sage.rings.finite_rings [InfPoly{[x,y], "lex", "dense"}, Finite Field of size 5] """ return [InfinitePolynomialFunctor(self._names, self._order, 'dense'), self._base] @@ -1641,7 +1646,8 @@ def polynomial_ring(self): Multivariate Polynomial Ring in xx_0, yy_0 over Integer Ring sage: a = yy[3] sage: X.polynomial_ring() - Multivariate Polynomial Ring in xx_3, xx_2, xx_1, xx_0, yy_3, yy_2, yy_1, yy_0 over Integer Ring + Multivariate Polynomial Ring in xx_3, xx_2, xx_1, xx_0, yy_3, yy_2, yy_1, yy_0 + over Integer Ring """ return self._P diff --git a/src/sage/rings/polynomial/laurent_polynomial.pyx b/src/sage/rings/polynomial/laurent_polynomial.pyx index b597397c9e5..e2333c59bb3 100644 --- a/src/sage/rings/polynomial/laurent_polynomial.pyx +++ b/src/sage/rings/polynomial/laurent_polynomial.pyx @@ -179,14 +179,14 @@ cdef class LaurentPolynomial(CommutativeAlgebraElement): sage: R. = LaurentPolynomialRing(QQ) sage: a = x^2 + 3*x^3 + 5*x^-1 - sage: a.change_ring(GF(3)) + sage: a.change_ring(GF(3)) # optional - sage.rings.finite_rings 2*x^-1 + x^2 Check that :trac:`22277` is fixed:: sage: R. = LaurentPolynomialRing(QQ) sage: a = 2*x^2 + 3*x^3 + 4*x^-1 - sage: a.change_ring(GF(3)) + sage: a.change_ring(GF(3)) # optional - sage.rings.finite_rings -x^2 + x^-1 """ return self._parent.change_ring(R)(self) @@ -255,38 +255,40 @@ cdef class LaurentPolynomial(CommutativeAlgebraElement): EXAMPLES:: - sage: k. = GF(9) - sage: R. = LaurentPolynomialRing(k) - sage: f = x*a + a - sage: f.map_coefficients(lambda a : a + 1) + sage: k. = GF(9) # optional - sage.rings.finite_rings + sage: R. = LaurentPolynomialRing(k) # optional - sage.rings.finite_rings + sage: f = x*a + a # optional - sage.rings.finite_rings + sage: f.map_coefficients(lambda a: a + 1) # optional - sage.rings.finite_rings (a + 1) + (a + 1)*x - sage: R. = LaurentPolynomialRing(k, 2) - sage: f = x*a + 2*x^3*y*a + a - sage: f.map_coefficients(lambda a : a + 1) + sage: R. = LaurentPolynomialRing(k, 2) # optional - sage.rings.finite_rings + sage: f = x*a + 2*x^3*y*a + a # optional - sage.rings.finite_rings + sage: f.map_coefficients(lambda a: a + 1) # optional - sage.rings.finite_rings (2*a + 1)*x^3*y + (a + 1)*x + a + 1 Examples with different base ring:: - sage: R. = GF(9); S. = GF(81) - sage: h = Hom(R,S)[0]; h + sage: R. = GF(9); S. = GF(81) # optional - sage.rings.finite_rings + sage: h = Hom(R, S)[0]; h # optional - sage.rings.finite_rings Ring morphism: From: Finite Field in r of size 3^2 To: Finite Field in s of size 3^4 Defn: r |--> 2*s^3 + 2*s^2 + 1 - sage: T. = LaurentPolynomialRing(R, 2) - sage: f = r*X+Y - sage: g = f.map_coefficients(h); g + sage: T. = LaurentPolynomialRing(R, 2) # optional - sage.rings.finite_rings + sage: f = r*X + Y # optional - sage.rings.finite_rings + sage: g = f.map_coefficients(h); g # optional - sage.rings.finite_rings (2*s^3 + 2*s^2 + 1)*X + Y - sage: g.parent() - Multivariate Laurent Polynomial Ring in X, Y over Finite Field in s of size 3^4 - sage: h = lambda x: x.trace() - sage: g = f.map_coefficients(h); g + sage: g.parent() # optional - sage.rings.finite_rings + Multivariate Laurent Polynomial Ring in X, Y + over Finite Field in s of size 3^4 + sage: h = lambda x: x.trace() # optional - sage.rings.finite_rings + sage: g = f.map_coefficients(h); g # optional - sage.rings.finite_rings X - Y - sage: g.parent() - Multivariate Laurent Polynomial Ring in X, Y over Finite Field in r of size 3^2 - sage: g = f.map_coefficients(h, new_base_ring=GF(3)); g + sage: g.parent() # optional - sage.rings.finite_rings + Multivariate Laurent Polynomial Ring in X, Y + over Finite Field in r of size 3^2 + sage: g = f.map_coefficients(h, new_base_ring=GF(3)); g # optional - sage.rings.finite_rings X - Y - sage: g.parent() + sage: g.parent() # optional - sage.rings.finite_rings Multivariate Laurent Polynomial Ring in X, Y over Finite Field of size 3 """ @@ -331,13 +333,13 @@ cdef class LaurentPolynomial_univariate(LaurentPolynomial): :: - sage: S. = LaurentPolynomialRing(GF(5)) - sage: T. = PolynomialRing(pAdicRing(5)) - sage: S(t) + sage: S. = LaurentPolynomialRing(GF(5)) # optional - sage.rings.finite_rings sage.rings.padics + sage: T. = PolynomialRing(pAdicRing(5)) # optional - sage.rings.finite_rings sage.rings.padics + sage: S(t) # optional - sage.rings.finite_rings sage.rings.padics s - sage: parent(S(t)) + sage: parent(S(t)) # optional - sage.rings.finite_rings sage.rings.padics Univariate Laurent Polynomial Ring in s over Finite Field of size 5 - sage: parent(S(t)[1]) + sage: parent(S(t)[1]) # optional - sage.rings.finite_rings sage.rings.padics Finite Field of size 5 :: @@ -387,7 +389,7 @@ cdef class LaurentPolynomial_univariate(LaurentPolynomial): sage: Pxy = PolynomialRing(QQ, "x,y") sage: Paxb = PolynomialRing(QQ, "a,x,b") sage: Qx = PolynomialRing(ZZ, "x") - sage: Rx = PolynomialRing(GF(2), "x") + sage: Rx = PolynomialRing(GF(2), "x") # optional - sage.rings.finite_rings sage: p1 = Lx.gen() sage: p2 = Lx.zero() sage: p3 = Lx.one() @@ -395,8 +397,10 @@ cdef class LaurentPolynomial_univariate(LaurentPolynomial): sage: p5 = Lx.gen()**3 + 2*Lx.gen()**2 sage: p6 = Lx.gen() >> 2 - sage: for P,x in [(Px, Px.gen()), (Qx, Qx.gen()), (Rx, Rx.gen()), - ....: (Pxy, Pxy.gen(0)), (Paxb, Paxb.gen(1))]: + sage: Pxes = [(Px, Px.gen()), (Qx, Qx.gen()), + ....: (Pxy, Pxy.gen(0)), (Paxb, Paxb.gen(1))] + sage: Pxes += [(Rx, Rx.gen())] # optional - sage.rings.finite_rings + sage: for P, x in Pxes: ....: assert P(p1) == x and parent(P(p1)) is P ....: assert P(p2) == P.zero() and parent(P(p2)) is P ....: assert P(p3) == P.one() and parent(P(p3)) is P @@ -511,12 +515,12 @@ cdef class LaurentPolynomial_univariate(LaurentPolynomial): You can specify a map on the base ring:: sage: Zx. = ZZ[] - sage: K. = NumberField(x^2 + 1) - sage: cc = K.hom([-i]) - sage: R. = LaurentPolynomialRing(K) - sage: H = Hom(R, R) - sage: phi = H([t^-2], base_map=cc) - sage: phi(i*t) + sage: K. = NumberField(x^2 + 1) # optional - sage.rings.number_field + sage: cc = K.hom([-i]) # optional - sage.rings.number_field + sage: R. = LaurentPolynomialRing(K) # optional - sage.rings.number_field + sage: H = Hom(R, R) # optional - sage.rings.number_field + sage: phi = H([t^-2], base_map=cc) # optional - sage.rings.number_field + sage: phi(i*t) # optional - sage.rings.number_field -i*t^-2 """ x = im_gens[0] @@ -605,9 +609,9 @@ cdef class LaurentPolynomial_univariate(LaurentPolynomial): Verify that :trac:`6656` has been fixed:: - sage: R.=PolynomialRing(QQ) - sage: T.=LaurentPolynomialRing(R) - sage: y = a*x+b*x + sage: R. = PolynomialRing(QQ) + sage: T. = LaurentPolynomialRing(R) + sage: y = a*x + b*x sage: y._latex_() '\\left(a + b\\right)x' sage: latex(y) @@ -813,20 +817,20 @@ cdef class LaurentPolynomial_univariate(LaurentPolynomial): sage: R. = LaurentPolynomialRing(QQ) sage: f = x^3 + 2/x - sage: g = f._symbolic_(SR); g + sage: g = f._symbolic_(SR); g # optional - sage.symbolic (x^4 + 2)/x - sage: g(x=2) + sage: g(x=2) # optional - sage.symbolic 9 - sage: g = SR(f) - sage: g(x=2) + sage: g = SR(f) # optional - sage.symbolic + sage: g(x=2) # optional - sage.symbolic 9 Since :trac:`24072` the symbolic ring does not accept positive characteristic:: - sage: R. = LaurentPolynomialRing(GF(7)) - sage: SR(2*w^3 + 1) + sage: R. = LaurentPolynomialRing(GF(7)) # optional - sage.rings.finite_rings + sage: SR(2*w^3 + 1) # optional - sage.rings.finite_rings sage.symbolic Traceback (most recent call last): ... TypeError: positive characteristic not allowed in symbolic computations @@ -1046,10 +1050,10 @@ cdef class LaurentPolynomial_univariate(LaurentPolynomial): """ EXAMPLES:: - sage: R. = LaurentPolynomialRing(GF(2)) - sage: f = 1/x^3 + x + x^2 + 3*x^4 - sage: g = 1 - x + x^2 - x^4 - sage: f*g + sage: R. = LaurentPolynomialRing(GF(2)) # optional - sage.rings.finite_rings + sage: f = 1/x^3 + x + x^2 + 3*x^4 # optional - sage.rings.finite_rings + sage: g = 1 - x + x^2 - x^4 # optional - sage.rings.finite_rings + sage: f*g # optional - sage.rings.finite_rings x^-3 + x^-2 + x^-1 + x^8 """ cdef LaurentPolynomial_univariate right = right_r @@ -2076,7 +2080,7 @@ cdef class LaurentPolynomial_mpair(LaurentPolynomial): """ TESTS:: - sage: R = LaurentPolynomialRing(QQ,2,'x') + sage: R = LaurentPolynomialRing(QQ, 2, 'x') sage: R. = LaurentPolynomialRing(QQ) sage: loads(dumps(x1)) == x1 # indirect doctest True @@ -2179,12 +2183,12 @@ cdef class LaurentPolynomial_mpair(LaurentPolynomial): check compatibility with :trac:`26105`:: - sage: F. = GF(4) - sage: LF. = LaurentPolynomialRing(F) - sage: rho = LF.hom([b,a], base_map=F.frobenius_endomorphism()) - sage: s = t*~a + b +~t*(b**-3)*a**2; rs = rho(s); rs + sage: F. = GF(4) # optional - sage.rings.finite_rings + sage: LF. = LaurentPolynomialRing(F) # optional - sage.rings.finite_rings + sage: rho = LF.hom([b,a], base_map=F.frobenius_endomorphism()) # optional - sage.rings.finite_rings + sage: s = t*~a + b +~t*(b**-3)*a**2; rs = rho(s); rs # optional - sage.rings.finite_rings a + (t + 1)*b^-1 + t*a^-3*b^2 - sage: s == rho(rs) + sage: s == rho(rs) # optional - sage.rings.finite_rings True """ p = self._poly @@ -2670,7 +2674,7 @@ cdef class LaurentPolynomial_mpair(LaurentPolynomial): EXAMPLES:: - sage: L. = LaurentPolynomialRing(QQ,order='degrevlex') + sage: L. = LaurentPolynomialRing(QQ, order='degrevlex') sage: f = 4*x^7*z^-1 + 3*x^3*y + 2*x^4*z^-2 + x^6*y^-7 sage: f.coefficients() [4, 3, 2, 1] @@ -2980,11 +2984,11 @@ cdef class LaurentPolynomial_mpair(LaurentPolynomial): EXAMPLES:: sage: R. = LaurentPolynomialRing(QQ) - sage: (s^2-t^2).quo_rem(s-t) + sage: (s^2 - t^2).quo_rem(s - t) (s + t, 0) - sage: (s^-2-t^2).quo_rem(s-t) + sage: (s^-2 - t^2).quo_rem(s - t) (s + t, -s^2 + s^-2) - sage: (s^-2-t^2).quo_rem(s^-1-t) + sage: (s^-2 - t^2).quo_rem(s^-1 - t) (t + s^-1, 0) TESTS: @@ -3059,7 +3063,7 @@ cdef class LaurentPolynomial_mpair(LaurentPolynomial): EXAMPLES:: sage: L. = LaurentPolynomialRing(QQ) - sage: a = w^2*z^-1+3; a + sage: a = w^2*z^-1 + 3; a w^2*z^-1 + 3 sage: e = a.exponents() sage: e.sort(); e @@ -3105,7 +3109,7 @@ cdef class LaurentPolynomial_mpair(LaurentPolynomial): OUTPUT: - Returns True if self contains a monomial including the inverse of + Return ``True`` if ``self`` contains a monomial including the inverse of ``self.parent().gen(i)``, False otherwise. EXAMPLES:: @@ -3130,7 +3134,7 @@ cdef class LaurentPolynomial_mpair(LaurentPolynomial): def has_any_inverse(self): """ - Returns True if self contains any monomials with a negative exponent, False otherwise. + Return ``True`` if ``self`` contains any monomials with a negative exponent, False otherwise. EXAMPLES:: @@ -3294,13 +3298,13 @@ cdef class LaurentPolynomial_mpair(LaurentPolynomial): sage: R. = LaurentPolynomialRing(QQ) sage: f = x^3 + y/x - sage: g = f._symbolic_(SR); g + sage: g = f._symbolic_(SR); g # optional - sage.symbolic (x^4 + y)/x - sage: g(x=2,y=2) + sage: g(x=2, y=2) # optional - sage.symbolic 9 - sage: g = SR(f) - sage: g(x=2,y=2) + sage: g = SR(f) # optional - sage.symbolic + sage: g(x=2, y=2) # optional - sage.symbolic 9 """ d = {repr(g): R.var(g) for g in self._parent.gens()} @@ -3323,7 +3327,7 @@ cdef class LaurentPolynomial_mpair(LaurentPolynomial): sage: R = LaurentPolynomialRing(ZZ,'x, y') sage: x, y = R.gens() - sage: t = x**4*y+x*y+y+x**(-1)+y**(-3) + sage: t = x**4*y + x*y + y + x**(-1) + y**(-3) sage: t.derivative(x, x) 12*x^2*y + 2*x^-3 sage: t.derivative(y, 2) @@ -3398,7 +3402,7 @@ cdef class LaurentPolynomial_mpair(LaurentPolynomial): sage: f = (x^3 + y^-3)*z sage: f.is_univariate() False - sage: g = f(1,y,4) + sage: g = f(1, y, 4) sage: g.is_univariate() True sage: R(1).is_univariate() @@ -3408,7 +3412,7 @@ cdef class LaurentPolynomial_mpair(LaurentPolynomial): def univariate_polynomial(self, R=None): """ - Returns a univariate polynomial associated to this + Return a univariate polynomial associated to this multivariate polynomial. INPUT: @@ -3428,7 +3432,7 @@ cdef class LaurentPolynomial_mpair(LaurentPolynomial): Traceback (most recent call last): ... TypeError: polynomial must involve at most one variable - sage: g = f(10,y); g + sage: g = f(10, y); g 700*y^2 + 305 - 2*y^-1 sage: h = g.univariate_polynomial(); h -2*y^-1 + 305 + 700*y^2 @@ -3465,7 +3469,7 @@ cdef class LaurentPolynomial_mpair(LaurentPolynomial): def factor(self): """ - Returns a Laurent monomial (the unit part of the factorization) and a factored multi-polynomial. + Return a Laurent monomial (the unit part of the factorization) and a factored multi-polynomial. EXAMPLES:: @@ -3524,7 +3528,7 @@ cdef class LaurentPolynomial_mpair(LaurentPolynomial): EXAMPLES:: sage: L. = LaurentPolynomialRing(QQ) - sage: p = (1 + x*y + z^-3) + sage: p = 1 + x*y + z^-3 sage: (p**2).is_square() True sage: (p**2).is_square(root=True) @@ -3578,14 +3582,14 @@ cdef class LaurentPolynomial_mpair(LaurentPolynomial): sage: p = x^-2*y + x*y^-2 sage: p.rescale_vars({0: 2, 1: 3}) 2/9*x*y^-2 + 3/4*x^-2*y - sage: F = GF(2) - sage: p.rescale_vars({0: 3, 1: 7}, new_ring=L.change_ring(F)) + sage: F = GF(2) # optional - sage.rings.finite_rings + sage: p.rescale_vars({0: 3, 1: 7}, new_ring=L.change_ring(F)) # optional - sage.rings.finite_rings x*y^-2 + x^-2*y Test for :trac:`30331`:: - sage: F. = CyclotomicField(3) - sage: p.rescale_vars({0: 2, 1: z}, new_ring=L.change_ring(F)) + sage: F. = CyclotomicField(3) # optional - sage.rings.number_field + sage: p.rescale_vars({0: 2, 1: z}, new_ring=L.change_ring(F)) # optional - sage.rings.number_field 2*z*x*y^-2 + 1/4*z*x^-2*y """ cdef int i @@ -3638,10 +3642,11 @@ cdef class LaurentPolynomial_mpair(LaurentPolynomial): sage: L. = LaurentPolynomialRing(QQ, 2) sage: p = 2*x^2 + y - x*y - sage: p.toric_coordinate_change(Matrix([[1,-3],[1,1]])) + sage: p.toric_coordinate_change(Matrix([[1,-3], [1,1]])) 2*x^2*y^2 - x^-2*y^2 + x^-3*y - sage: F = GF(2) - sage: p.toric_coordinate_change(Matrix([[1,-3],[1,1]]), new_ring=L.change_ring(F)) + sage: F = GF(2) # optional - sage.rings.finite_rings + sage: p.toric_coordinate_change(Matrix([[1,-3], [1,1]]), # optional - sage.rings.finite_rings + ....: new_ring=L.change_ring(F)) x^-2*y^2 + x^-3*y """ diff --git a/src/sage/rings/polynomial/laurent_polynomial_ideal.py b/src/sage/rings/polynomial/laurent_polynomial_ideal.py index 0168a56e267..2289b69e111 100644 --- a/src/sage/rings/polynomial/laurent_polynomial_ideal.py +++ b/src/sage/rings/polynomial/laurent_polynomial_ideal.py @@ -55,10 +55,12 @@ def __init__(self, ring, gens, coerce=True, hint=None): sage: R. = LaurentPolynomialRing(IntegerRing(), 2, order='lex') sage: R.ideal([x, y]) - Ideal (x, y) of Multivariate Laurent Polynomial Ring in x, y over Integer Ring - sage: R. = LaurentPolynomialRing(GF(3), 2) - sage: R.ideal([x0^2, x1^-3]) - Ideal (x0^2, x1^-3) of Multivariate Laurent Polynomial Ring in x0, x1 over Finite Field of size 3 + Ideal (x, y) of Multivariate Laurent Polynomial Ring in x, y + over Integer Ring + sage: R. = LaurentPolynomialRing(GF(3), 2) # optional - sage.rings.finite_rings + sage: R.ideal([x0^2, x1^-3]) # optional - sage.rings.finite_rings + Ideal (x0^2, x1^-3) of Multivariate Laurent Polynomial Ring in x0, x1 + over Finite Field of size 3 sage: P. = LaurentPolynomialRing(QQ, 2) sage: I = P.ideal([~x + ~y - 1]) @@ -70,19 +72,20 @@ def __init__(self, ring, gens, coerce=True, hint=None): True sage: P. = LaurentPolynomialRing(QQ, 3) - sage: I1 = P.ideal([x*y*z+x*y+2*y^2, x+z]) - sage: I2 = P.ideal([x*y*z+x*y+2*y^2+x+z, x+z]) + sage: I1 = P.ideal([x*y*z + x*y + 2*y^2, x + z]) + sage: I2 = P.ideal([x*y*z + x*y + 2*y^2 + x + z, x + z]) sage: I1 == I2 True - sage: I3 = P.ideal([x*y*z+x*y+2*y^2+x+z, x+z, y]) + sage: I3 = P.ideal([x*y*z + x*y + 2*y^2 + x + z, x + z, y]) sage: I1 < I3 True sage: I1.minimal_associated_primes() - (Ideal (-1/2*z^2 + y - 1/2*z, x + z) of Multivariate Laurent Polynomial Ring in x, y, z over Rational Field,) + (Ideal (-1/2*z^2 + y - 1/2*z, x + z) of Multivariate + Laurent Polynomial Ring in x, y, z over Rational Field,) - sage: K. = CyclotomicField(4) - sage: J = I1.base_extend(K) - sage: J.base_ring() + sage: K. = CyclotomicField(4) # optional - sage.rings.number_field + sage: J = I1.base_extend(K) # optional - sage.rings.number_field + sage: J.base_ring() # optional - sage.rings.number_field Cyclotomic Field of order 4 and degree 2 """ Ideal_generic.__init__(self, ring, gens, coerce=coerce) @@ -207,10 +210,11 @@ def change_ring(self, R, hint=None): EXAMPLES:: sage: P. = LaurentPolynomialRing(QQ, 2) - sage: I = P.ideal([x+y]) + sage: I = P.ideal([x + y]) sage: Q. = LaurentPolynomialRing(QQ, 3) sage: I.change_ring(Q) - Ideal (x + y) of Multivariate Laurent Polynomial Ring in x, y, z over Rational Field + Ideal (x + y) of Multivariate Laurent Polynomial Ring in x, y, z + over Rational Field """ return R.ideal(self.gens(), hint=hint) @@ -223,10 +227,11 @@ def base_extend(self, F): EXAMPLES:: sage: P. = LaurentPolynomialRing(QQ, 2) - sage: I = P.ideal([x+y]) - sage: K. = CyclotomicField(3) - sage: I.base_extend(K) - Ideal (x + y) of Multivariate Laurent Polynomial Ring in x, y over Cyclotomic Field of order 3 and degree 2 + sage: I = P.ideal([x + y]) + sage: K. = CyclotomicField(3) # optional - sage.rings.number_field + sage: I.base_extend(K) # optional - sage.rings.number_field + Ideal (x + y) of Multivariate Laurent Polynomial Ring in x, y + over Cyclotomic Field of order 3 and degree 2 """ ring = self.ring() return self.change_ring(ring.change_ring(F), hint=self._hint) @@ -241,12 +246,14 @@ def apply_map(self, f, new_ring=None, new_base_ring=None, apply_to_hint=None): EXAMPLES:: sage: P. = LaurentPolynomialRing(QQ, 2) - sage: I = P.ideal([x+1, y-1]) - sage: I.apply_map(lambda z: z+2) - Ideal (x + 3, y + 1) of Multivariate Laurent Polynomial Ring in x, y over Rational Field - sage: K. = CyclotomicField(4) - sage: I.apply_map(lambda z: z+2, new_base_ring=K) - Ideal (x + 3, y + 1) of Multivariate Laurent Polynomial Ring in x, y over Cyclotomic Field of order 4 and degree 2 + sage: I = P.ideal([x + 1, y - 1]) + sage: I.apply_map(lambda z: z + 2) + Ideal (x + 3, y + 1) of Multivariate Laurent Polynomial Ring in x, y + over Rational Field + sage: K. = CyclotomicField(4) # optional - sage.rings.number_field + sage: I.apply_map(lambda z: z + 2, new_base_ring=K) # optional - sage.rings.number_field + Ideal (x + 3, y + 1) of Multivariate Laurent Polynomial Ring in x, y + over Cyclotomic Field of order 4 and degree 2 """ ring = self.ring() if new_ring is not None: @@ -269,16 +276,18 @@ def apply_coeff_map(self, f, new_base_ring=None, forward_hint=True): EXAMPLES:: - sage: K. = CyclotomicField(3) - sage: P. = LaurentPolynomialRing(K, 2) - sage: I = P.ideal([x+z, y-z]) - sage: h = K.hom([z^2]) - sage: I.apply_coeff_map(h) - Ideal (x - z - 1, y + z + 1) of Multivariate Laurent Polynomial Ring in x, y over Cyclotomic Field of order 3 and degree 2 - sage: K1. = CyclotomicField(12) - sage: h1 = K.hom([z1^4]) - sage: I.apply_coeff_map(h1, new_base_ring=K1) - Ideal (x + z1^2 - 1, y - z1^2 + 1) of Multivariate Laurent Polynomial Ring in x, y over Cyclotomic Field of order 12 and degree 4 + sage: K. = CyclotomicField(3) # optional - sage.rings.number_field + sage: P. = LaurentPolynomialRing(K, 2) # optional - sage.rings.number_field + sage: I = P.ideal([x + z, y - z]) # optional - sage.rings.number_field + sage: h = K.hom([z^2]) # optional - sage.rings.number_field + sage: I.apply_coeff_map(h) # optional - sage.rings.number_field + Ideal (x - z - 1, y + z + 1) of Multivariate Laurent Polynomial Ring + in x, y over Cyclotomic Field of order 3 and degree 2 + sage: K1. = CyclotomicField(12) # optional - sage.rings.number_field + sage: h1 = K.hom([z1^4]) # optional - sage.rings.number_field + sage: I.apply_coeff_map(h1, new_base_ring=K1) # optional - sage.rings.number_field + Ideal (x + z1^2 - 1, y - z1^2 + 1) of Multivariate Laurent Polynomial Ring + in x, y over Cyclotomic Field of order 12 and degree 4 """ ring = self.ring() if new_base_ring is None: @@ -301,12 +310,13 @@ def toric_coordinate_change(self, M, forward_hint=True): EXAMPLES:: - sage: K. = CyclotomicField(3) - sage: P. = LaurentPolynomialRing(K, 2) - sage: I = P.ideal([x+1, y-1]) - sage: M = Matrix([[2,1],[1,-3]]) - sage: I.toric_coordinate_change(M) - Ideal (x^2*y + 1, -1 + x*y^-3) of Multivariate Laurent Polynomial Ring in x, y over Cyclotomic Field of order 3 and degree 2 + sage: K. = CyclotomicField(3) # optional - sage.rings.number_field + sage: P. = LaurentPolynomialRing(K, 2) # optional - sage.rings.number_field + sage: I = P.ideal([x + 1, y - 1]) # optional - sage.rings.number_field + sage: M = Matrix([[2,1], [1,-3]]) # optional - sage.rings.number_field + sage: I.toric_coordinate_change(M) # optional - sage.rings.number_field + Ideal (x^2*y + 1, -1 + x*y^-3) of Multivariate Laurent Polynomial Ring + in x, y over Cyclotomic Field of order 3 and degree 2 """ if forward_hint: R = self.ring() @@ -357,10 +367,12 @@ def normalize_gens(self): sage: P. = LaurentPolynomialRing(QQ, 2) sage: I = P.ideal([~x+y]) sage: J = P.ideal([y+1]) - sage: I+J - Ideal (y + x^-1, y + 1) of Multivariate Laurent Polynomial Ring in x, y over Rational Field - sage: (I+J).normalize_gens() - Ideal (x - 1, y + 1) of Multivariate Laurent Polynomial Ring in x, y over Rational Field + sage: I + J + Ideal (y + x^-1, y + 1) of Multivariate Laurent Polynomial Ring + in x, y over Rational Field + sage: (I + J).normalize_gens() + Ideal (x - 1, y + 1) of Multivariate Laurent Polynomial Ring + in x, y over Rational Field """ return self.ring().ideal(self.groebner_basis(), hint=self._hint) @@ -381,7 +393,8 @@ def polynomial_ideal(self, saturate=True): sage: P. = LaurentPolynomialRing(QQ, 2) sage: I = P.ideal([x^2*y + 3*x*y^2]) sage: I.polynomial_ideal() - Ideal (x + 3*y) of Multivariate Polynomial Ring in x, y over Rational Field + Ideal (x + 3*y) of Multivariate Polynomial Ring in x, y + over Rational Field """ if self._poly_ideal is not None and (self._saturated or not saturate): return self._poly_ideal @@ -416,9 +429,9 @@ def groebner_basis(self, saturate=True): EXAMPLES:: sage: P. = LaurentPolynomialRing(QQ, 2) - sage: I = P.ideal([x+y]) - sage: J = P.ideal([y+1]) - sage: (I+J).groebner_basis() + sage: I = P.ideal([x + y]) + sage: J = P.ideal([y + 1]) + sage: (I + J).groebner_basis() (x - 1, y + 1) """ l = self.polynomial_ideal(saturate=saturate).groebner_basis() @@ -470,10 +483,12 @@ def associated_primes(self): sage: P. = LaurentPolynomialRing(QQ, 3) sage: p = z^2 + 1; q = z^3 + 2 - sage: I = P.ideal((p*q^2, y-z^2)) + sage: I = P.ideal((p*q^2, y - z^2)) sage: tuple(sorted(I.associated_primes(), key=str)) - (Ideal (y + 1, z^2 + 1) of Multivariate Laurent Polynomial Ring in x, y, z over Rational Field, - Ideal (z^2 - y, y*z + 2, y^2 + 2*z) of Multivariate Laurent Polynomial Ring in x, y, z over Rational Field) + (Ideal (y + 1, z^2 + 1) of + Multivariate Laurent Polynomial Ring in x, y, z over Rational Field, + Ideal (z^2 - y, y*z + 2, y^2 + 2*z) of + Multivariate Laurent Polynomial Ring in x, y, z over Rational Field) """ l = self.polynomial_ideal(saturate=False).associated_primes() l2 = [self.ring().ideal(I.gens(), hint=I) for I in l] @@ -490,10 +505,12 @@ def minimal_associated_primes(self, saturate=False): sage: P. = LaurentPolynomialRing(QQ, 3) sage: p = z^2 + 1; q = z^3 + 2 - sage: I = P.ideal((p*q^2, y-z^2)) + sage: I = P.ideal((p*q^2, y - z^2)) sage: tuple(sorted(I.minimal_associated_primes(), key=str)) - (Ideal (z^2 + 1, -z^2 + y) of Multivariate Laurent Polynomial Ring in x, y, z over Rational Field, - Ideal (z^3 + 2, -z^2 + y) of Multivariate Laurent Polynomial Ring in x, y, z over Rational Field) + (Ideal (z^2 + 1, -z^2 + y) of + Multivariate Laurent Polynomial Ring in x, y, z over Rational Field, + Ideal (z^3 + 2, -z^2 + y) of + Multivariate Laurent Polynomial Ring in x, y, z over Rational Field) """ l = self.polynomial_ideal(saturate=saturate).minimal_associated_primes() l2 = [self.ring().ideal(I.gens(), hint=I) for I in l] @@ -508,7 +525,8 @@ def radical(self): sage: P. = LaurentPolynomialRing(QQ, 3) sage: I = P.ideal(((x+1)^2, (y+1)^3, ((x+1)*z)^4 + (y+1)^3 + 10*(x+1)^2)) sage: I.radical() - Ideal (y + 1, x + 1) of Multivariate Laurent Polynomial Ring in x, y, z over Rational Field + Ideal (y + 1, x + 1) of Multivariate Laurent Polynomial Ring in x, y, z + over Rational Field """ J = self.polynomial_ideal().radical() return self.ring().ideal(J.gens()) diff --git a/src/sage/rings/polynomial/laurent_polynomial_ring.py b/src/sage/rings/polynomial/laurent_polynomial_ring.py index aaa1166b9d2..9acef1841a1 100644 --- a/src/sage/rings/polynomial/laurent_polynomial_ring.py +++ b/src/sage/rings/polynomial/laurent_polynomial_ring.py @@ -50,7 +50,7 @@ def is_LaurentPolynomialRing(R): """ - Returns True if and only if R is a Laurent polynomial ring. + Return ``True`` if and only if R is a Laurent polynomial ring. EXAMPLES:: @@ -88,7 +88,7 @@ def LaurentPolynomialRing(base_ring, *args, **kwds): 3. ``LaurentPolynomialRing(base_ring, name, n, order='degrevlex')`` 4. ``LaurentPolynomialRing(base_ring, n, name, order='degrevlex')`` - The optional arguments sparse and order *must* be explicitly + The optional arguments ``sparse`` and ``order`` *must* be explicitly named, and the other arguments must be given positionally. INPUT: @@ -101,10 +101,10 @@ def LaurentPolynomialRing(base_ring, *args, **kwds): - ``order`` -- string or :class:`~sage.rings.polynomial.term_order.TermOrder`, e.g., - - ``'degrevlex'`` (default) -- degree reverse lexicographic - - ``'lex'`` -- lexicographic - - ``'deglex'`` -- degree lexicographic - - ``TermOrder('deglex',3) + TermOrder('deglex',3)`` -- block ordering + - ``'degrevlex'`` (default) -- degree reverse lexicographic + - ``'lex'`` -- lexicographic + - ``'deglex'`` -- degree lexicographic + - ``TermOrder('deglex',3) + TermOrder('deglex',3)`` -- block ordering OUTPUT: @@ -120,7 +120,7 @@ def LaurentPolynomialRing(base_ring, *args, **kwds): :: - sage: R. = LaurentPolynomialRing(QQ,2); R + sage: R. = LaurentPolynomialRing(QQ, 2); R Multivariate Laurent Polynomial Ring in x, y over Rational Field sage: f = x^2 - 2*y^-2 @@ -162,8 +162,9 @@ def LaurentPolynomialRing(base_ring, *args, **kwds): sage: R. = LaurentPolynomialRing(QQ, sparse=True); R Univariate Laurent Polynomial Ring in abc over Rational Field - sage: R. = LaurentPolynomialRing(PolynomialRing(GF(7),'k')); R - Univariate Laurent Polynomial Ring in w over Univariate Polynomial Ring in k over Finite Field of size 7 + sage: R. = LaurentPolynomialRing(PolynomialRing(GF(7),'k')); R # optional - sage.rings.finite_rings + Univariate Laurent Polynomial Ring in w over + Univariate Polynomial Ring in k over Finite Field of size 7 Rings with different variables are different:: @@ -210,10 +211,12 @@ def LaurentPolynomialRing(base_ring, *args, **kwds): :: sage: LaurentPolynomialRing(QQ, 'x', 10) - Multivariate Laurent Polynomial Ring in x0, x1, x2, x3, x4, x5, x6, x7, x8, x9 over Rational Field + Multivariate Laurent Polynomial Ring in x0, x1, x2, x3, x4, x5, x6, x7, x8, x9 + over Rational Field - sage: LaurentPolynomialRing(GF(7), 'y', 5) - Multivariate Laurent Polynomial Ring in y0, y1, y2, y3, y4 over Finite Field of size 7 + sage: LaurentPolynomialRing(GF(7), 'y', 5) # optional - sage.rings.finite_rings + Multivariate Laurent Polynomial Ring in y0, y1, y2, y3, y4 + over Finite Field of size 7 sage: LaurentPolynomialRing(QQ, 'y', 3, sparse=True) Multivariate Laurent Polynomial Ring in y0, y1, y2 over Rational Field @@ -222,11 +225,12 @@ def LaurentPolynomialRing(base_ring, *args, **kwds): :meth:`~sage.structure.category_object.CategoryObject.inject_variables` method, all those variable names are available for interactive use:: - sage: R = LaurentPolynomialRing(GF(7),15,'w'); R - Multivariate Laurent Polynomial Ring in w0, w1, w2, w3, w4, w5, w6, w7, w8, w9, w10, w11, w12, w13, w14 over Finite Field of size 7 - sage: R.inject_variables() + sage: R = LaurentPolynomialRing(GF(7), 15, 'w'); R # optional - sage.rings.finite_rings + Multivariate Laurent Polynomial Ring in w0, w1, w2, w3, w4, w5, w6, w7, + w8, w9, w10, w11, w12, w13, w14 over Finite Field of size 7 + sage: R.inject_variables() # optional - sage.rings.finite_rings Defining w0, w1, w2, w3, w4, w5, w6, w7, w8, w9, w10, w11, w12, w13, w14 - sage: (w0 + 2*w8 + w13)^2 + sage: (w0 + 2*w8 + w13)^2 # optional - sage.rings.finite_rings w0^2 + 4*w0*w8 + 4*w8^2 + 2*w0*w13 + 4*w8*w13 + w13^2 """ from sage.rings.polynomial.polynomial_ring import is_PolynomialRing diff --git a/src/sage/rings/polynomial/laurent_polynomial_ring_base.py b/src/sage/rings/polynomial/laurent_polynomial_ring_base.py index 82394e3930c..93d8f9a4fc0 100644 --- a/src/sage/rings/polynomial/laurent_polynomial_ring_base.py +++ b/src/sage/rings/polynomial/laurent_polynomial_ring_base.py @@ -40,7 +40,10 @@ class LaurentPolynomialRing_generic(CommutativeRing, Parent): sage: R. = LaurentPolynomialRing(QQ) sage: R.category() - Join of Category of unique factorization domains and Category of commutative algebras over (number fields and quotient fields and metric spaces) and Category of infinite sets + Join of Category of unique factorization domains + and Category of commutative algebras + over (number fields and quotient fields and metric spaces) + and Category of infinite sets sage: TestSuite(R).run() """ @@ -48,7 +51,7 @@ def __init__(self, R): """ EXAMPLES:: - sage: R = LaurentPolynomialRing(QQ,2,'x') + sage: R = LaurentPolynomialRing(QQ, 2, 'x') sage: R == loads(dumps(R)) True """ @@ -65,9 +68,9 @@ def ngens(self): EXAMPLES:: - sage: LaurentPolynomialRing(QQ,2,'x').ngens() + sage: LaurentPolynomialRing(QQ, 2, 'x').ngens() 2 - sage: LaurentPolynomialRing(QQ,1,'x').ngens() + sage: LaurentPolynomialRing(QQ, 1, 'x').ngens() 1 """ return self._n @@ -79,16 +82,16 @@ def gen(self, i=0): EXAMPLES:: - sage: LaurentPolynomialRing(QQ,2,'x').gen() + sage: LaurentPolynomialRing(QQ, 2, 'x').gen() x0 - sage: LaurentPolynomialRing(QQ,2,'x').gen(0) + sage: LaurentPolynomialRing(QQ, 2, 'x').gen(0) x0 - sage: LaurentPolynomialRing(QQ,2,'x').gen(1) + sage: LaurentPolynomialRing(QQ, 2, 'x').gen(1) x1 TESTS:: - sage: LaurentPolynomialRing(QQ,2,'x').gen(3) + sage: LaurentPolynomialRing(QQ, 2, 'x').gen(3) Traceback (most recent call last): ... ValueError: generator not defined @@ -136,28 +139,29 @@ def variable_names_recursive(self, depth=infinity): def is_integral_domain(self, proof=True): """ - Returns True if self is an integral domain. + Return ``True`` if self is an integral domain. EXAMPLES:: - sage: LaurentPolynomialRing(QQ,2,'x').is_integral_domain() + sage: LaurentPolynomialRing(QQ, 2, 'x').is_integral_domain() True The following used to fail; see :trac:`7530`:: sage: L = LaurentPolynomialRing(ZZ, 'X') sage: L['Y'] - Univariate Polynomial Ring in Y over Univariate Laurent Polynomial Ring in X over Integer Ring + Univariate Polynomial Ring in Y over + Univariate Laurent Polynomial Ring in X over Integer Ring """ return self.base_ring().is_integral_domain(proof) def is_noetherian(self): """ - Returns True if self is Noetherian. + Return ``True`` if self is Noetherian. EXAMPLES:: - sage: LaurentPolynomialRing(QQ,2,'x').is_noetherian() + sage: LaurentPolynomialRing(QQ, 2, 'x').is_noetherian() Traceback (most recent call last): ... NotImplementedError @@ -170,9 +174,9 @@ def construction(self): EXAMPLES:: - sage: LaurentPolynomialRing(QQ,2,'x,y').construction() + sage: LaurentPolynomialRing(QQ, 2, 'x,y').construction() (LaurentPolynomialFunctor, - Univariate Laurent Polynomial Ring in x over Rational Field) + Univariate Laurent Polynomial Ring in x over Rational Field) """ from sage.categories.pushout import LaurentPolynomialFunctor @@ -195,11 +199,9 @@ def completion(self, p=None, prec=20, extras=None): EXAMPLES:: - sage: P. = LaurentPolynomialRing(QQ) - sage: P + sage: P. = LaurentPolynomialRing(QQ); P Univariate Laurent Polynomial Ring in x over Rational Field - sage: PP = P.completion(x) - sage: PP + sage: PP = P.completion(x); PP Laurent Series Ring in x over Rational Field sage: f = 1 - 1/x sage: PP(f) @@ -344,7 +346,7 @@ def _latex_(self): r""" EXAMPLES:: - sage: latex(LaurentPolynomialRing(QQ,2,'x')) + sage: latex(LaurentPolynomialRing(QQ, 2, 'x')) \Bold{Q}[x_{0}^{\pm 1}, x_{1}^{\pm 1}] """ from sage.misc.latex import latex @@ -356,7 +358,7 @@ def _ideal_class_(self, n=0): """ EXAMPLES:: - sage: LaurentPolynomialRing(QQ,2,'x')._ideal_class_() + sage: LaurentPolynomialRing(QQ, 2, 'x')._ideal_class_() Traceback (most recent call last): ... NotImplementedError @@ -368,7 +370,7 @@ def ideal(self, *args, **kwds): """ EXAMPLES:: - sage: LaurentPolynomialRing(QQ,2,'x').ideal([1]) + sage: LaurentPolynomialRing(QQ, 2, 'x').ideal([1]) Ideal (1) of Multivariate Laurent Polynomial Ring in x0, x1 over Rational Field TESTS: @@ -415,7 +417,7 @@ def term_order(self): EXAMPLES:: - sage: LaurentPolynomialRing(QQ,2,'x').term_order() + sage: LaurentPolynomialRing(QQ, 2, 'x').term_order() Degree reverse lexicographic term order """ @@ -425,7 +427,7 @@ def is_finite(self): """ EXAMPLES:: - sage: LaurentPolynomialRing(QQ,2,'x').is_finite() + sage: LaurentPolynomialRing(QQ, 2, 'x').is_finite() False """ @@ -435,7 +437,7 @@ def is_field(self, proof = True): """ EXAMPLES:: - sage: LaurentPolynomialRing(QQ,2,'x').is_field() + sage: LaurentPolynomialRing(QQ, 2, 'x').is_field() False """ return False @@ -446,9 +448,9 @@ def polynomial_ring(self): EXAMPLES:: - sage: LaurentPolynomialRing(QQ,2,'x').polynomial_ring() + sage: LaurentPolynomialRing(QQ, 2, 'x').polynomial_ring() Multivariate Polynomial Ring in x0, x1 over Rational Field - sage: LaurentPolynomialRing(QQ,1,'x').polynomial_ring() + sage: LaurentPolynomialRing(QQ, 1, 'x').polynomial_ring() Multivariate Polynomial Ring in x over Rational Field """ return self._R @@ -459,7 +461,7 @@ def characteristic(self): EXAMPLES:: - sage: LaurentPolynomialRing(QQ,2,'x').characteristic() + sage: LaurentPolynomialRing(QQ, 2, 'x').characteristic() 0 sage: LaurentPolynomialRing(GF(3), 2, 'x').characteristic() # optional - sage.libs.pari 3 @@ -471,7 +473,7 @@ def krull_dimension(self): """ EXAMPLES:: - sage: LaurentPolynomialRing(QQ,2,'x').krull_dimension() + sage: LaurentPolynomialRing(QQ, 2, 'x').krull_dimension() Traceback (most recent call last): ... NotImplementedError @@ -482,7 +484,7 @@ def random_element(self, low_degree = -2, high_degree = 2, terms = 5, choose_deg """ EXAMPLES:: - sage: LaurentPolynomialRing(QQ,2,'x').random_element() + sage: LaurentPolynomialRing(QQ, 2, 'x').random_element() Traceback (most recent call last): ... NotImplementedError @@ -491,13 +493,13 @@ def random_element(self, low_degree = -2, high_degree = 2, terms = 5, choose_deg def is_exact(self): """ - Returns True if the base ring is exact. + Return ``True`` if the base ring is exact. EXAMPLES:: - sage: LaurentPolynomialRing(QQ,2,'x').is_exact() + sage: LaurentPolynomialRing(QQ, 2, 'x').is_exact() True - sage: LaurentPolynomialRing(RDF,2,'x').is_exact() + sage: LaurentPolynomialRing(RDF, 2, 'x').is_exact() False """ return self.base_ring().is_exact() @@ -506,7 +508,7 @@ def change_ring(self, base_ring=None, names=None, sparse=False, order=None): """ EXAMPLES:: - sage: R = LaurentPolynomialRing(QQ,2,'x') + sage: R = LaurentPolynomialRing(QQ, 2, 'x') sage: R.change_ring(ZZ) Multivariate Laurent Polynomial Ring in x0, x1 over Integer Ring diff --git a/src/sage/rings/polynomial/multi_polynomial.pyx b/src/sage/rings/polynomial/multi_polynomial.pyx index 28d4265dc82..52cf994aa27 100644 --- a/src/sage/rings/polynomial/multi_polynomial.pyx +++ b/src/sage/rings/polynomial/multi_polynomial.pyx @@ -122,7 +122,7 @@ cdef class MPolynomial(CommutativePolynomial): _number_field_ = _scalar_conversion def __int__(self): - """ + r""" TESTS:: sage: type(RR['x,y']) @@ -153,7 +153,7 @@ cdef class MPolynomial(CommutativePolynomial): return self._scalar_conversion(int) def __float__(self): - """ + r""" TESTS:: sage: float(RR['x,y'](0)) # indirect doctest @@ -166,7 +166,7 @@ cdef class MPolynomial(CommutativePolynomial): return self._scalar_conversion(float) def _rational_(self): - """ + r""" TESTS:: sage: QQ(RR['x,y'](0.5)) # indirect doctest @@ -180,18 +180,18 @@ cdef class MPolynomial(CommutativePolynomial): return self._scalar_conversion(QQ) def _symbolic_(self, R): - """ + r""" EXAMPLES:: sage: R. = QQ[] sage: f = x^3 + y - sage: g = f._symbolic_(SR); g + sage: g = f._symbolic_(SR); g # optional - sage.symbolic x^3 + y - sage: g(x=2,y=2) + sage: g(x=2, y=2) # optional - sage.symbolic 10 - sage: g = SR(f) - sage: g(x=2,y=2) + sage: g = SR(f) # optional - sage.symbolic + sage: g(x=2, y=2) # optional - sage.symbolic 10 """ d = dict([(repr(g), R.var(g)) for g in self.parent().gens()]) @@ -214,23 +214,23 @@ cdef class MPolynomial(CommutativePolynomial): EXAMPLES:: - sage: R. = PolynomialRing(QQ,3,order='degrevlex') - sage: f=23*x^6*y^7 + x^3*y+6*x^7*z + sage: R. = PolynomialRing(QQ, 3, order='degrevlex') + sage: f = 23*x^6*y^7 + x^3*y+6*x^7*z sage: f.coefficients() [23, 6, 1] - sage: R. = PolynomialRing(QQ,3,order='lex') - sage: f=23*x^6*y^7 + x^3*y+6*x^7*z + sage: R. = PolynomialRing(QQ, 3, order='lex') + sage: f = 23*x^6*y^7 + x^3*y+6*x^7*z sage: f.coefficients() [6, 23, 1] Test the same stuff with base ring `\ZZ` -- different implementation:: - sage: R. = PolynomialRing(ZZ,3,order='degrevlex') - sage: f=23*x^6*y^7 + x^3*y+6*x^7*z + sage: R. = PolynomialRing(ZZ, 3, order='degrevlex') + sage: f = 23*x^6*y^7 + x^3*y+6*x^7*z sage: f.coefficients() [23, 6, 1] - sage: R. = PolynomialRing(ZZ,3,order='lex') - sage: f=23*x^6*y^7 + x^3*y+6*x^7*z + sage: R. = PolynomialRing(ZZ, 3, order='lex') + sage: f = 23*x^6*y^7 + x^3*y+6*x^7*z sage: f.coefficients() [6, 23, 1] @@ -242,10 +242,10 @@ cdef class MPolynomial(CommutativePolynomial): return [d[i] for i in self.exponents()] def truncate(self, var, n): - """ - Returns a new multivariate polynomial obtained from self by + r""" + Returns a new multivariate polynomial obtained from ``self`` by deleting all terms that involve the given variable to a power - at least n. + at least ``n``. """ cdef int ind R = self.parent() @@ -259,8 +259,8 @@ cdef class MPolynomial(CommutativePolynomial): return R(dict([(k, c) for k, c in d.iteritems() if k[ind] < n])) def _fast_callable_(self, etb): - """ - Given an ExpressionTreeBuilder, return an Expression representing + r""" + Given an :class:`ExpressionTreeBuilder`, return an :class:`Expression` representing this value. EXAMPLES:: @@ -303,10 +303,10 @@ cdef class MPolynomial(CommutativePolynomial): def derivative(self, *args): r""" The formal derivative of this polynomial, with respect to - variables supplied in args. + variables supplied in ``args``. Multiple variables and iteration counts may be supplied; see - documentation for the global derivative() function for more details. + documentation for the global function :func:`derivative` for more details. .. SEEALSO:: :meth:`._derivative` @@ -314,13 +314,13 @@ cdef class MPolynomial(CommutativePolynomial): Polynomials implemented via Singular:: - sage: R. = PolynomialRing(FiniteField(5)) - sage: f = x^3*y^5 + x^7*y - sage: type(f) + sage: R. = PolynomialRing(FiniteField(5)) # optional - sage.rings.finite_rings + sage: f = x^3*y^5 + x^7*y # optional - sage.rings.finite_rings + sage: type(f) # optional - sage.rings.finite_rings - sage: f.derivative(x) + sage: f.derivative(x) # optional - sage.rings.finite_rings 2*x^6*y - 2*x^2*y^5 - sage: f.derivative(y) + sage: f.derivative(y) # optional - sage.rings.finite_rings x^7 Generic multivariate polynomials:: @@ -347,21 +347,21 @@ cdef class MPolynomial(CommutativePolynomial): Polynomials over the symbolic ring (just for fun....):: - sage: x = var("x") - sage: S. = PolynomialRing(SR) - sage: f = u*v*x - sage: f.derivative(x) == u*v + sage: x = var("x") # optional - sage.symbolic + sage: S. = PolynomialRing(SR) # optional - sage.symbolic + sage: f = u*v*x # optional - sage.symbolic + sage: f.derivative(x) == u*v # optional - sage.symbolic True - sage: f.derivative(u) == v*x + sage: f.derivative(u) == v*x # optional - sage.symbolic True """ return multi_derivative(self, args) def polynomial(self, var): - """ - Let var be one of the variables of the parent of self. This - returns self viewed as a univariate polynomial in var over the + r""" + Let ``var`` be one of the variables of the parent of ``self``. This + returns ``self`` viewed as a univariate polynomial in ``var`` over the polynomial ring generated by all the other variables of the parent. EXAMPLES:: @@ -371,7 +371,8 @@ cdef class MPolynomial(CommutativePolynomial): sage: f.polynomial(x) x^3 + (17*w^3 + 3*w)*x + w^5 + z^5 sage: parent(f.polynomial(x)) - Univariate Polynomial Ring in x over Multivariate Polynomial Ring in w, z over Rational Field + Univariate Polynomial Ring in x + over Multivariate Polynomial Ring in w, z over Rational Field sage: f.polynomial(w) w^5 + 17*x*w^3 + 3*x*w + z^5 + x^3 @@ -387,11 +388,11 @@ cdef class MPolynomial(CommutativePolynomial): z^5 + x*w*k*z + w^5 + 17*x*w^3 + x^3 + 3*x*w + 5 sage: f.polynomial(k) x*w*z*k + w^5 + z^5 + 17*x*w^3 + x^3 + 3*x*w + 5 - sage: R.=GF(5)[] - sage: f=x^2+x+y - sage: f.polynomial(x) + sage: R. = GF(5)[] # optional - sage.rings.finite_rings + sage: f = x^2 + x + y # optional - sage.rings.finite_rings + sage: f.polynomial(x) # optional - sage.rings.finite_rings x^2 + x + y - sage: f.polynomial(y) + sage: f.polynomial(y) # optional - sage.rings.finite_rings y + x^2 + x """ cdef int ind @@ -444,8 +445,8 @@ cdef class MPolynomial(CommutativePolynomial): TESTS:: - sage: R = Qp(7)['x,y,z,t,p']; S = ZZ['x,z,t']['p'] - sage: R(S.0) + sage: R = Qp(7)['x,y,z,t,p']; S = ZZ['x,z,t']['p'] # optional - sage.rings.padics + sage: R(S.0) # optional - sage.rings.padics p sage: R = QQ['x,y,z,t,p']; S = ZZ['x']['y,z,t']['p'] sage: z = S.base_ring().gen(1) @@ -455,8 +456,8 @@ cdef class MPolynomial(CommutativePolynomial): sage: z = S.base_ring().gen(1); p = S.0; x = S.base_ring().base_ring().gen() sage: R(z+p) z + p - sage: R = Qp(7)['x,y,z,p']; S = ZZ['x']['y,z,t']['p'] # shouldn't work, but should throw a better error - sage: R(S.0) + sage: R = Qp(7)['x,y,z,p']; S = ZZ['x']['y,z,t']['p'] # shouldn't work, but should throw a better error # optional - sage.rings.padics + sage: R(S.0) # optional - sage.rings.padics p See :trac:`2601`:: @@ -528,7 +529,7 @@ cdef class MPolynomial(CommutativePolynomial): return D cdef long _hash_c(self) except -1: - """ + r""" This hash incorporates the variable name in an effort to respect the obvious inclusions into multi-variable polynomial rings. @@ -559,9 +560,9 @@ cdef class MPolynomial(CommutativePolynomial): Verify that :trac:`16251` has been resolved, i.e., polynomials with unhashable coefficients are unhashable:: - sage: K. = Qq(9) - sage: R. = K[] - sage: hash(t) + sage: K. = Qq(9) # optional - sage.rings.padics + sage: R. = K[] # optional - sage.rings.padics + sage: hash(t) # optional - sage.rings.padics Traceback (most recent call last): ... TypeError: unhashable type: 'sage.rings.padics.qadic_flint_CR.qAdicCappedRelativeElement' @@ -597,7 +598,7 @@ cdef class MPolynomial(CommutativePolynomial): def args(self): r""" - Returns the named of the arguments of self, in the + Returns the names of the arguments of ``self``, in the order they are accepted from call. EXAMPLES:: @@ -689,9 +690,9 @@ cdef class MPolynomial(CommutativePolynomial): In particular, this can be surprising in positive characteristic:: - sage: R. = GF(2)[] - sage: f = x + 1 - sage: f.homogenize(x) + sage: R. = GF(2)[] # optional - sage.rings.finite_rings + sage: f = x + 1 # optional - sage.rings.finite_rings + sage: f.homogenize(x) # optional - sage.rings.finite_rings 0 TESTS:: @@ -738,7 +739,7 @@ cdef class MPolynomial(CommutativePolynomial): def is_homogeneous(self): r""" - Return ``True`` if self is a homogeneous polynomial. + Return ``True`` if ``self`` is a homogeneous polynomial. TESTS:: @@ -773,7 +774,7 @@ cdef class MPolynomial(CommutativePolynomial): return True def homogeneous_components(self): - """ + r""" Return the homogeneous components of this polynomial. OUTPUT: @@ -808,21 +809,21 @@ cdef class MPolynomial(CommutativePolynomial): return {k: self._parent(d[k]) for k in d} cpdef _mod_(self, other): - """ + r""" EXAMPLES:: sage: R. = PolynomialRing(QQ) sage: f = (x^2*y + 2*x - 3) sage: g = (x + 1)*f - sage: g % f + sage: g % f # optional - sage.libs.singular 0 - sage: (g+1) % f + sage: (g+1) % f # optional - sage.libs.singular 1 sage: M = x*y sage: N = x^2*y^3 - sage: M.divides(N) + sage: M.divides(N) # optional - sage.libs.singular True """ try: @@ -834,7 +835,7 @@ cdef class MPolynomial(CommutativePolynomial): return r def change_ring(self, R): - """ + r""" Return a copy of this polynomial but with coefficients in ``R``, if at all possible. @@ -846,21 +847,21 @@ cdef class MPolynomial(CommutativePolynomial): sage: R. = QQ[] sage: f = x^3 + 3/5*y + 1 - sage: f.change_ring(GF(7)) + sage: f.change_ring(GF(7)) # optional - sage.rings.finite_rings x^3 + 2*y + 1 :: - sage: R. = GF(9,'a')[] - sage: (x+2*y).change_ring(GF(3)) + sage: R. = GF(9,'a')[] # optional - sage.rings.finite_rings + sage: (x+2*y).change_ring(GF(3)) # optional - sage.rings.finite_rings x - y :: - sage: K. = CyclotomicField(3) - sage: R. = K[] - sage: f = x^2 + z*y - sage: f.change_ring(K.embeddings(CC)[1]) + sage: K. = CyclotomicField(3) # optional - sage.rings.number_field + sage: R. = K[] # optional - sage.rings.number_field + sage: f = x^2 + z*y # optional - sage.rings.number_field + sage: f.change_ring(K.embeddings(CC)[1]) # optional - sage.rings.number_field x^2 + (-0.500000000000000 - 0.866025403784438*I)*y TESTS: @@ -868,7 +869,7 @@ cdef class MPolynomial(CommutativePolynomial): Check that :trac:`25022` is fixed:: sage: K. = ZZ[] - sage: (x*y).change_ring(SR).monomials() + sage: (x*y).change_ring(SR).monomials() # optional - sage.rings.number_field sage.symbolic [x*y] """ if isinstance(R, Map): @@ -892,47 +893,51 @@ cdef class MPolynomial(CommutativePolynomial): sage: R. = QQ[] sage: p = (x+y+z)**2 - 3 * (x+y)*(x+z)*(y+z) - sage: p.is_symmetric() + sage: p.is_symmetric() # optional - sage.groups True - sage: (x + y - z).is_symmetric() + sage: (x + y - z).is_symmetric() # optional - sage.groups False - sage: R.one().is_symmetric() + sage: R.one().is_symmetric() # optional - sage.groups True sage: p = (x-y)*(y-z)*(z-x) - sage: p.is_symmetric() + sage: p.is_symmetric() # optional - sage.groups False - sage: p.is_symmetric(AlternatingGroup(3)) + sage: p.is_symmetric(AlternatingGroup(3)) # optional - sage.groups True sage: R. = QQ[] - sage: ((x + y)**2).is_symmetric() + sage: ((x + y)**2).is_symmetric() # optional - sage.groups True - sage: R.one().is_symmetric() + sage: R.one().is_symmetric() # optional - sage.groups True - sage: (x + 2*y).is_symmetric() + sage: (x + 2*y).is_symmetric() # optional - sage.groups False An example with a GAP permutation group (here the quaternions):: sage: R = PolynomialRing(QQ, 'x', 8) sage: x = R.gens() - sage: p = sum(prod(x[i] for i in e) for e in [(0,1,2), (0,1,7), (0,2,7), (1,2,7), (3,4,5), (3,4,6), (3,5,6), (4,5,6)]) - sage: p.is_symmetric(libgap.TransitiveGroup(8, 5)) + sage: p = sum(prod(x[i] for i in e) + ....: for e in [(0,1,2), (0,1,7), (0,2,7), (1,2,7), + ....: (3,4,5), (3,4,6), (3,5,6), (4,5,6)]) + sage: p.is_symmetric(libgap.TransitiveGroup(8, 5)) # optional - sage.groups True - sage: p = sum(prod(x[i] for i in e) for e in [(0,1,2), (0,1,7), (0,2,7), (1,2,7), (3,4,5), (3,4,6), (3,5,6)]) - sage: p.is_symmetric(libgap.TransitiveGroup(8, 5)) + sage: p = sum(prod(x[i] for i in e) + ....: for e in [(0,1,2), (0,1,7), (0,2,7), (1,2,7), + ....: (3,4,5), (3,4,6), (3,5,6)]) + sage: p.is_symmetric(libgap.TransitiveGroup(8, 5)) # optional - sage.groups False TESTS:: sage: R = PolynomialRing(QQ, 'x', 3) - sage: R.one().is_symmetric(3) + sage: R.one().is_symmetric(3) # optional - sage.groups Traceback (most recent call last): ... ValueError: argument must be a permutation group - sage: R.one().is_symmetric(SymmetricGroup(4)) + sage: R.one().is_symmetric(SymmetricGroup(4)) # optional - sage.groups Traceback (most recent call last): ... ValueError: invalid data to initialize a permutation @@ -963,7 +968,7 @@ cdef class MPolynomial(CommutativePolynomial): for e, coeff in coeffs.items() for g in gens) def _gap_(self, gap): - """ + r""" Return a representation of ``self`` in the GAP interface INPUT: @@ -975,39 +980,39 @@ cdef class MPolynomial(CommutativePolynomial): Multivariate polynomial over integers:: sage: R. = ZZ[] - sage: gap(-x*y + 3*z) # indirect doctest + sage: gap(-x*y + 3*z) # indirect doctest # optional - sage.libs.gap -x*y+3*z - sage: gap(R.zero()) # indirect doctest + sage: gap(R.zero()) # indirect doctest # optional - sage.libs.gap 0 - sage: (x+y+z)._gap_(libgap) + sage: (x+y+z)._gap_(libgap) # optional - sage.libs.gap x+y+z - sage: g = gap(x - y + 3*x*y*z) - sage: R(g) + sage: g = gap(x - y + 3*x*y*z) # optional - sage.libs.gap + sage: R(g) # optional - sage.libs.gap 3*x*y*z + x - y - sage: g = libgap(5*x - y*z) - sage: R(g) + sage: g = libgap(5*x - y*z) # optional - sage.libs.gap + sage: R(g) # optional - sage.libs.gap -y*z + 5*x Multivariate polynomial over a cyclotomic field:: - sage: F. = CyclotomicField(8) - sage: P. = F[] - sage: p = zeta + zeta^2*x + zeta^3*y + (1+zeta)*x*y - sage: gap(p) # indirect doctest + sage: F. = CyclotomicField(8) # optional - sage.rings.number_field + sage: P. = F[] # optional - sage.rings.number_field + sage: p = zeta + zeta^2*x + zeta^3*y + (1+zeta)*x*y # optional - sage.rings.number_field + sage: gap(p) # indirect doctest # optional - sage.libs.gap sage.rings.number_field (1+E(8))*x*y+E(4)*x+E(8)^3*y+E(8) - sage: libgap(p) # indirect doctest + sage: libgap(p) # indirect doctest # optional - sage.libs.gap sage.rings.number_field (1+E(8))*x*y+E(4)*x+E(8)^3*y+E(8) Multivariate polynomial over a polynomial ring over a cyclotomic field:: - sage: S. = F[] - sage: P. = S[] - sage: p = zeta + zeta^2*x*z + zeta^3*y*z^2 + (1+zeta)*x*y*z - sage: gap(p) # indirect doctest + sage: S. = F[] # optional - sage.rings.number_field + sage: P. = S[] # optional - sage.rings.number_field + sage: p = zeta + zeta^2*x*z + zeta^3*y*z^2 + (1+zeta)*x*y*z # optional - sage.rings.number_field + sage: gap(p) # indirect doctest # optional - sage.libs.gap sage.rings.number_field ((1+E(8))*z)*x*y+E(4)*z*x+E(8)^3*z^2*y+E(8) - sage: libgap(p) # indirect doctest + sage: libgap(p) # indirect doctest # optional - sage.libs.gap sage.rings.number_field ((1+E(8))*z)*x*y+E(4)*z*x+E(8)^3*z^2*y+E(8) """ R = gap(self.parent()) @@ -1019,27 +1024,27 @@ cdef class MPolynomial(CommutativePolynomial): TESTS:: sage: R. = ZZ[] - sage: libgap(-x*y + 3*z) # indirect doctest + sage: libgap(-x*y + 3*z) # indirect doctest # optional - sage.libs.gap -x*y+3*z - sage: libgap(R.zero()) # indirect doctest + sage: libgap(R.zero()) # indirect doctest # optional - sage.libs.gap 0 """ from sage.libs.gap.libgap import libgap return self._gap_(libgap) def _magma_init_(self, magma): - """ - Returns a Magma string representation of self valid in the + r""" + Returns a Magma string representation of ``self`` valid in the given magma session. EXAMPLES:: - sage: k. = GF(25); R. = k[] - sage: f = y*x^2*b + x*(b+1) + 1 - sage: magma = Magma() # so var names same below - sage: magma(f) # optional - magma + sage: k. = GF(25); R. = k[] # optional - sage.rings.finite_rings + sage: f = y*x^2*b + x*(b+1) + 1 # optional - sage.rings.finite_rings + sage: magma = Magma() # so var names same below # optional - sage.rings.finite_rings + sage: magma(f) # optional - magma # optional - sage.rings.finite_rings b*x^2*y + b^22*x + 1 - sage: f._magma_init_(magma) # optional - magma + sage: f._magma_init_(magma) # optional - magma # optional - sage.rings.finite_rings '_sage_[...]!((_sage_[...]!(_sage_[...]))*_sage_[...]^2*_sage_[...]+(_sage_[...]!(_sage_[...] + 1))*_sage_[...]+(_sage_[...]!(1))*1)' A more complicated nested example:: @@ -1069,13 +1074,13 @@ cdef class MPolynomial(CommutativePolynomial): TESTS:: - sage: R. = GF(101)['e,i'][] - sage: f = R('e*i') * x + y^2 - sage: f._giac_init_() + sage: R. = GF(101)['e,i'][] # optional - sage.rings.finite_rings + sage: f = R('e*i') * x + y^2 # optional - sage.rings.finite_rings + sage: f._giac_init_() # optional - sage.rings.finite_rings '((1)*1)*sageVARy^2+((1)*sageVARe*sageVARi)*sageVARx' - sage: giac(f) + sage: giac(f) # optional - sage.rings.finite_rings sageVARy^2+sageVARe*sageVARi*sageVARx - sage: giac(R.zero()) + sage: giac(R.zero()) # optional - sage.rings.finite_rings 0 """ g = ['sageVAR' + x for x in self.parent().variable_names()] @@ -1091,7 +1096,7 @@ cdef class MPolynomial(CommutativePolynomial): EXAMPLES:: - sage: P. = PolynomialRing(ZZ,3) + sage: P. = PolynomialRing(ZZ, 3) sage: f = x*y + 1 sage: f.gradient() [y, x, 0] @@ -1107,32 +1112,33 @@ cdef class MPolynomial(CommutativePolynomial): sage: R. = QQ[] sage: f = x^3 + y^3 + z^3 sage: f.jacobian_ideal() - Ideal (3*x^2, 3*y^2, 3*z^2) of Multivariate Polynomial Ring in x, y, z over Rational Field + Ideal (3*x^2, 3*y^2, 3*z^2) of + Multivariate Polynomial Ring in x, y, z over Rational Field """ return self.parent().ideal(self.gradient()) def newton_polytope(self): - """ + r""" Return the Newton polytope of this polynomial. EXAMPLES:: sage: R. = QQ[] sage: f = 1 + x*y + x^3 + y^3 - sage: P = f.newton_polytope() - sage: P + sage: P = f.newton_polytope() # optional - sage.geometry.polyhedron + sage: P # optional - sage.geometry.polyhedron A 2-dimensional polyhedron in ZZ^2 defined as the convex hull of 3 vertices - sage: P.is_simple() + sage: P.is_simple() # optional - sage.geometry.polyhedron True TESTS:: sage: R. = QQ[] - sage: R(0).newton_polytope() + sage: R(0).newton_polytope() # optional - sage.geometry.polyhedron The empty polyhedron in ZZ^0 - sage: R(1).newton_polytope() + sage: R(1).newton_polytope() # optional - sage.geometry.polyhedron A 0-dimensional polyhedron in ZZ^2 defined as the convex hull of 1 vertex - sage: R(x^2+y^2).newton_polytope().integral_points() + sage: R(x^2+y^2).newton_polytope().integral_points() # optional - sage.geometry.polyhedron ((0, 2), (1, 1), (2, 0)) """ from sage.geometry.polyhedron.constructor import Polyhedron @@ -1141,8 +1147,8 @@ cdef class MPolynomial(CommutativePolynomial): return P def __iter__(self): - """ - Facilitates iterating over the monomials of self, + r""" + Facilitates iterating over the monomials of ``self``, returning tuples of the form ``(coeff, mon)`` for each non-zero monomial. @@ -1160,13 +1166,13 @@ cdef class MPolynomial(CommutativePolynomial): yield (coeff, self.monomial(exp)) def iterator_exp_coeff(self, as_ETuples=True): - """ + r""" Iterate over ``self`` as pairs of ((E)Tuple, coefficient). INPUT: - - ``as_ETuples`` -- (default: ``True``) if ``True`` iterate over - pairs whose first element is an ETuple, otherwise as a tuples + - ``as_ETuples`` -- (default: ``True``) if ``True``, iterate over + pairs whose first element is an :class:`ETuple`, otherwise as a tuples EXAMPLES:: @@ -1186,8 +1192,8 @@ cdef class MPolynomial(CommutativePolynomial): yield (exp, self.monomial_coefficient(exp)) def content(self): - """ - Returns the content of this polynomial. Here, we define content as + r""" + Return the content of this polynomial. Here, we define content as the gcd of the coefficients in the base ring. .. SEEALSO:: @@ -1218,7 +1224,7 @@ cdef class MPolynomial(CommutativePolynomial): return gcd(self.coefficients()) def content_ideal(self): - """ + r""" Return the content ideal of this polynomial, defined as the ideal generated by its coefficients. @@ -1246,17 +1252,17 @@ cdef class MPolynomial(CommutativePolynomial): EXAMPLES:: - sage: R.=ZZ[] + sage: R. = ZZ[] sage: x.is_generator() True - sage: (x+y-y).is_generator() + sage: (x + y - y).is_generator() True sage: (x*y).is_generator() False - sage: R.=QQ[] + sage: R. = QQ[] sage: x.is_generator() True - sage: (x+y-y).is_generator() + sage: (x + y - y).is_generator() True sage: (x*y).is_generator() False @@ -1264,50 +1270,50 @@ cdef class MPolynomial(CommutativePolynomial): return (self in self.parent().gens()) def map_coefficients(self, f, new_base_ring=None): - """ + r""" Returns the polynomial obtained by applying ``f`` to the non-zero - coefficients of self. + coefficients of ``self``. If ``f`` is a :class:`sage.categories.map.Map`, then the resulting polynomial will be defined over the codomain of ``f``. Otherwise, the - resulting polynomial will be over the same ring as self. Set + resulting polynomial will be over the same ring as ``self``. Set ``new_base_ring`` to override this behaviour. INPUT: - - ``f`` -- a callable that will be applied to the coefficients of self. + - ``f`` -- a callable that will be applied to the coefficients of ``self``. - ``new_base_ring`` (optional) -- if given, the resulting polynomial will be defined over this ring. EXAMPLES:: - sage: k. = GF(9); R. = k[]; f = x*a + 2*x^3*y*a + a - sage: f.map_coefficients(lambda a : a + 1) + sage: k. = GF(9); R. = k[]; f = x*a + 2*x^3*y*a + a # optional - sage.rings.finite_rings + sage: f.map_coefficients(lambda a: a + 1) # optional - sage.rings.finite_rings (-a + 1)*x^3*y + (a + 1)*x + (a + 1) Examples with different base ring:: - sage: R. = GF(9); S. = GF(81) - sage: h = Hom(R,S)[0]; h + sage: R. = GF(9); S. = GF(81) # optional - sage.rings.finite_rings + sage: h = Hom(R,S)[0]; h # optional - sage.rings.finite_rings Ring morphism: From: Finite Field in r of size 3^2 To: Finite Field in s of size 3^4 Defn: r |--> 2*s^3 + 2*s^2 + 1 - sage: T. = R[] - sage: f = r*X+Y - sage: g = f.map_coefficients(h); g + sage: T. = R[] # optional - sage.rings.finite_rings + sage: f = r*X + Y # optional - sage.rings.finite_rings + sage: g = f.map_coefficients(h); g # optional - sage.rings.finite_rings (-s^3 - s^2 + 1)*X + Y - sage: g.parent() + sage: g.parent() # optional - sage.rings.finite_rings Multivariate Polynomial Ring in X, Y over Finite Field in s of size 3^4 - sage: h = lambda x: x.trace() - sage: g = f.map_coefficients(h); g + sage: h = lambda x: x.trace() # optional - sage.rings.finite_rings + sage: g = f.map_coefficients(h); g # optional - sage.rings.finite_rings X - Y - sage: g.parent() + sage: g.parent() # optional - sage.rings.finite_rings Multivariate Polynomial Ring in X, Y over Finite Field in r of size 3^2 - sage: g = f.map_coefficients(h, new_base_ring=GF(3)); g + sage: g = f.map_coefficients(h, new_base_ring=GF(3)); g # optional - sage.rings.finite_rings X - Y - sage: g.parent() + sage: g.parent() # optional - sage.rings.finite_rings Multivariate Polynomial Ring in X, Y over Finite Field of size 3 """ @@ -1331,10 +1337,10 @@ cdef class MPolynomial(CommutativePolynomial): EXAMPLES:: - sage: k. = GF(9) - sage: R. = PolynomialRing(k) - sage: f = (x-a)*(y-a) - sage: f._norm_over_nonprime_finite_field() + sage: k. = GF(9) # optional - sage.rings.finite_rings + sage: R. = PolynomialRing(k) # optional - sage.rings.finite_rings + sage: f = (x-a) * (y-a) # optional - sage.rings.finite_rings + sage: f._norm_over_nonprime_finite_field() # optional - sage.rings.finite_rings x^2*y^2 - x^2*y - x*y^2 - x^2 + x*y - y^2 + x + y + 1 """ P = self.parent() @@ -1347,8 +1353,8 @@ cdef class MPolynomial(CommutativePolynomial): return prod(v).change_ring(k.prime_subfield()) def sylvester_matrix(self, right, variable = None): - """ - Given two nonzero polynomials self and right, returns the Sylvester + r""" + Given two nonzero polynomials ``self`` and ``right``, return the Sylvester matrix of the polynomials with respect to a given variable. Note that the Sylvester matrix is not defined if one of the polynomials @@ -1356,22 +1362,22 @@ cdef class MPolynomial(CommutativePolynomial): INPUT: - - self , right: multivariate polynomials - - variable: optional, compute the Sylvester matrix with respect to this - variable. If variable is not provided, the first variable of the + - ``self``, ``right`` -- multivariate polynomials + - ``variable`` -- optional, compute the Sylvester matrix with respect to this + variable. If ``variable`` is not provided, the first variable of the polynomial ring is used. OUTPUT: - - The Sylvester matrix of self and right. + - The Sylvester matrix of ``self`` and ``right``. EXAMPLES:: sage: R. = PolynomialRing(ZZ) sage: f = (y + 1)*x + 3*x**2 sage: g = (y + 2)*x + 4*x**2 - sage: M = f.sylvester_matrix(g, x) - sage: M + sage: M = f.sylvester_matrix(g, x) # optional - sage.modules + sage: M # optional - sage.modules [ 3 y + 1 0 0] [ 0 3 y + 1 0] [ 4 y + 2 0 0] @@ -1380,18 +1386,18 @@ cdef class MPolynomial(CommutativePolynomial): If the polynomials share a non-constant common factor then the determinant of the Sylvester matrix will be zero:: - sage: M.determinant() + sage: M.determinant() # optional - sage.modules 0 - sage: f.sylvester_matrix(1 + g, x).determinant() + sage: f.sylvester_matrix(1 + g, x).determinant() # optional - sage.modules y^2 - y + 7 - If both polynomials are of positive degree with respect to variable, the + If both polynomials are of positive degree with respect to ``variable``, the determinant of the Sylvester matrix is the resultant:: sage: f = R.random_element(4) or (x^2 * y^2) sage: g = R.random_element(4) or (x^2 * y^2) - sage: f.sylvester_matrix(g, x).determinant() == f.resultant(g, x) + sage: f.sylvester_matrix(g, x).determinant() == f.resultant(g, x) # optional - sage.modules True TESTS: @@ -1400,7 +1406,7 @@ cdef class MPolynomial(CommutativePolynomial): sage: f = x + y sage: g = x + y - sage: f.sylvester_matrix(g) + sage: f.sylvester_matrix(g) # optional - sage.modules [1 y] [1 y] @@ -1412,45 +1418,47 @@ cdef class MPolynomial(CommutativePolynomial): sage: g = x + y sage: R. = GF(25, 'a')[] sage: h = x + y - sage: f.sylvester_matrix(g, 'x') + sage: f.sylvester_matrix(g, 'x') # optional - sage.modules [1 y] [1 y] - sage: g.sylvester_matrix(h, 'x') + sage: g.sylvester_matrix(h, 'x') # optional - sage.modules [1 y] [1 y] - sage: f.sylvester_matrix(h, 'x') + sage: f.sylvester_matrix(h, 'x') # optional - sage.modules Traceback (most recent call last): ... - TypeError: no common canonical parent for objects with parents: 'Multivariate Polynomial Ring in x, y over Rational Field' and 'Multivariate Polynomial Ring in x, y over Finite Field in a of size 5^2' + TypeError: no common canonical parent for objects with parents: + 'Multivariate Polynomial Ring in x, y over Rational Field' and + 'Multivariate Polynomial Ring in x, y over Finite Field in a of size 5^2' sage: K. = QQ[] sage: f = x + y sage: L. = QQ[] sage: g = x + z - sage: f.sylvester_matrix(g) + sage: f.sylvester_matrix(g) # optional - sage.modules [1 y] [1 z] Corner cases:: - sage: K.=QQ[] - sage: f = x^2+1 + sage: K.=QQ[] + sage: f = x^2 + 1 sage: g = K(0) - sage: f.sylvester_matrix(g) + sage: f.sylvester_matrix(g) # optional - sage.modules Traceback (most recent call last): ... ValueError: The Sylvester matrix is not defined for zero polynomials - sage: g.sylvester_matrix(f) + sage: g.sylvester_matrix(f) # optional - sage.modules Traceback (most recent call last): ... ValueError: The Sylvester matrix is not defined for zero polynomials - sage: g.sylvester_matrix(g) + sage: g.sylvester_matrix(g) # optional - sage.modules Traceback (most recent call last): ... ValueError: The Sylvester matrix is not defined for zero polynomials - sage: K(3).sylvester_matrix(x^2) + sage: K(3).sylvester_matrix(x^2) # optional - sage.modules [3 0] [0 3] - sage: K(3).sylvester_matrix(K(4)) + sage: K(3).sylvester_matrix(K(4)) # optional - sage.modules [] """ @@ -1500,53 +1508,49 @@ cdef class MPolynomial(CommutativePolynomial): return M def discriminant(self,variable): - """ - Returns the discriminant of self with respect to the given variable. + r""" + Returns the discriminant of ``self`` with respect to the given variable. INPUT: - - ``variable`` - The variable with respect to which we compute - the discriminant - - OUTPUT: - - - An element of the base ring of the polynomial ring. + - ``variable`` - The variable with respect to which we compute + the discriminant + OUTPUT: An element of the base ring of the polynomial ring. EXAMPLES:: - sage: R.=QQ[] - sage: f=4*x*y^2 + 1/4*x*y*z + 3/2*x*z^2 - 1/2*z^2 - sage: f.discriminant(x) + sage: R. = QQ[] + sage: f = 4*x*y^2 + 1/4*x*y*z + 3/2*x*z^2 - 1/2*z^2 + sage: f.discriminant(x) # optional - sage.libs.singular 1 - sage: f.discriminant(y) + sage: f.discriminant(y) # optional - sage.libs.singular -383/16*x^2*z^2 + 8*x*z^2 - sage: f.discriminant(z) + sage: f.discriminant(z) # optional - sage.libs.singular -383/16*x^2*y^2 + 8*x*y^2 Note that, unlike the univariate case, the result lives in the same ring as the polynomial:: - sage: R.=QQ[] - sage: f=x^5*y+3*x^2*y^2-2*x+y-1 - sage: f.discriminant(y) + sage: R. = QQ[] + sage: f = x^5*y + 3*x^2*y^2 - 2*x + y - 1 + sage: f.discriminant(y) # optional - sage.libs.singular x^10 + 2*x^5 + 24*x^3 + 12*x^2 + 1 - sage: f.polynomial(y).discriminant() + sage: f.polynomial(y).discriminant() # optional - sage.libs.singular x^10 + 2*x^5 + 24*x^3 + 12*x^2 + 1 - sage: f.discriminant(y).parent()==f.polynomial(y).discriminant().parent() + sage: f.discriminant(y).parent() == f.polynomial(y).discriminant().parent() # optional - sage.libs.singular False TESTS: Test polynomials over QQbar (:trac:`25265`):: - sage: R.=QQbar[] - sage: f=x^5*y+3*x^2*y^2-2*x+y-1 - sage: f.discriminant(y) + sage: R. = QQbar[] # optional - sage.rings.number_field + sage: f = x^5*y + 3*x^2*y^2 - 2*x + y - 1 # optional - sage.rings.number_field + sage: f.discriminant(y) # optional - sage.rings.number_field x^10 + 2*x^5 + 24*x^3 + 12*x^2 + 1 - AUTHOR: - Miguel Marco + AUTHOR: Miguel Marco """ if self.is_zero(): return self.parent().zero() @@ -1595,7 +1599,7 @@ cdef class MPolynomial(CommutativePolynomial): def macaulay_resultant(self, *args): r""" - This is an implementation of the Macaulay Resultant. It computes + This is an implementation of the Macaulay resultant. It computes the resultant of universal polynomials as well as polynomials with constant coefficients. This is a project done in sage days 55. It's based on the implementation in Maple by @@ -1610,36 +1614,36 @@ cdef class MPolynomial(CommutativePolynomial): INPUT: - ``args`` -- a list of `n-1` homogeneous polynomials in `n` variables. - works when ``args[0]`` is the list of polynomials, - or ``args`` is itself the list of polynomials + works when ``args[0]`` is the list of polynomials, + or ``args`` is itself the list of polynomials OUTPUT: - - the macaulay resultant + - the Macaulay resultant EXAMPLES: The number of polynomials has to match the number of variables:: - sage: R. = PolynomialRing(QQ,3) - sage: y.macaulay_resultant(x+z) + sage: R. = PolynomialRing(QQ, 3) + sage: y.macaulay_resultant(x + z) # optional - sage.modules Traceback (most recent call last): ... TypeError: number of polynomials(= 2) must equal number of variables (= 3) The polynomials need to be all homogeneous:: - sage: R. = PolynomialRing(QQ,3) - sage: y.macaulay_resultant([x+z, z+x^3]) + sage: R. = PolynomialRing(QQ, 3) + sage: y.macaulay_resultant([x + z, z + x^3]) # optional - sage.modules Traceback (most recent call last): ... TypeError: resultant for non-homogeneous polynomials is not supported All polynomials must be in the same ring:: - sage: R. = PolynomialRing(QQ,3) + sage: R. = PolynomialRing(QQ, 3) sage: S. = PolynomialRing(QQ, 2) - sage: y.macaulay_resultant(z+x,z) + sage: y.macaulay_resultant(z + x, z) # optional - sage.modules Traceback (most recent call last): ... TypeError: not all inputs are polynomials in the calling ring @@ -1647,15 +1651,19 @@ cdef class MPolynomial(CommutativePolynomial): The following example recreates Proposition 2.10 in Ch.3 of Using Algebraic Geometry:: sage: K. = PolynomialRing(ZZ, 2) - sage: flist,R = K._macaulay_resultant_universal_polynomials([1,1,2]) - sage: flist[0].macaulay_resultant(flist[1:]) - u2^2*u4^2*u6 - 2*u1*u2*u4*u5*u6 + u1^2*u5^2*u6 - u2^2*u3*u4*u7 + u1*u2*u3*u5*u7 + u0*u2*u4*u5*u7 - u0*u1*u5^2*u7 + u1*u2*u3*u4*u8 - u0*u2*u4^2*u8 - u1^2*u3*u5*u8 + u0*u1*u4*u5*u8 + u2^2*u3^2*u9 - 2*u0*u2*u3*u5*u9 + u0^2*u5^2*u9 - u1*u2*u3^2*u10 + u0*u2*u3*u4*u10 + u0*u1*u3*u5*u10 - u0^2*u4*u5*u10 + u1^2*u3^2*u11 - 2*u0*u1*u3*u4*u11 + u0^2*u4^2*u11 + sage: flist, R = K._macaulay_resultant_universal_polynomials([1,1,2]) + sage: flist[0].macaulay_resultant(flist[1:]) # optional - sage.modules + u2^2*u4^2*u6 - 2*u1*u2*u4*u5*u6 + u1^2*u5^2*u6 - u2^2*u3*u4*u7 + u1*u2*u3*u5*u7 + + u0*u2*u4*u5*u7 - u0*u1*u5^2*u7 + u1*u2*u3*u4*u8 - u0*u2*u4^2*u8 - u1^2*u3*u5*u8 + + u0*u1*u4*u5*u8 + u2^2*u3^2*u9 - 2*u0*u2*u3*u5*u9 + u0^2*u5^2*u9 + - u1*u2*u3^2*u10 + u0*u2*u3*u4*u10 + u0*u1*u3*u5*u10 - u0^2*u4*u5*u10 + + u1^2*u3^2*u11 - 2*u0*u1*u3*u4*u11 + u0^2*u4^2*u11 - The following example degenerates into the determinant of a `3*3` matrix:: + The following example degenerates into the determinant of a `3\times 3` matrix:: sage: K. = PolynomialRing(ZZ, 2) - sage: flist,R = K._macaulay_resultant_universal_polynomials([1,1,1]) - sage: flist[0].macaulay_resultant(flist[1:]) + sage: flist, R = K._macaulay_resultant_universal_polynomials([1,1,1]) + sage: flist[0].macaulay_resultant(flist[1:]) # optional - sage.modules -u2*u4*u6 + u1*u5*u6 + u2*u3*u7 - u0*u5*u7 - u1*u3*u8 + u0*u4*u8 The following example is by Patrick Ingram (:arxiv:`1310.4114`):: @@ -1665,56 +1673,56 @@ cdef class MPolynomial(CommutativePolynomial): sage: f0 = y0*x2^2 - x0^2 + 2*x1*x2 sage: f1 = y1*x2^2 - x1^2 + 2*x0*x2 sage: f2 = x0*x1 - x2^2 - sage: f0.macaulay_resultant(f1,f2) + sage: f0.macaulay_resultant(f1, f2) # optional - sage.modules y0^2*y1^2 - 4*y0^3 - 4*y1^3 + 18*y0*y1 - 27 a simple example with constant rational coefficients:: - sage: R. = PolynomialRing(QQ,4) - sage: w.macaulay_resultant([z,y,x]) + sage: R. = PolynomialRing(QQ, 4) + sage: w.macaulay_resultant([z, y, x]) # optional - sage.modules 1 an example where the resultant vanishes:: - sage: R. = PolynomialRing(QQ,3) - sage: (x+y).macaulay_resultant([y^2,x]) + sage: R. = PolynomialRing(QQ, 3) + sage: (x + y).macaulay_resultant([y^2, x]) # optional - sage.modules 0 an example of bad reduction at a prime ``p = 5``:: - sage: R. = PolynomialRing(QQ,3) - sage: y.macaulay_resultant([x^3+25*y^2*x,5*z]) + sage: R. = PolynomialRing(QQ, 3) + sage: y.macaulay_resultant([x^3 + 25*y^2*x, 5*z]) # optional - sage.modules 125 The input can given as an unpacked list of polynomials:: - sage: R. = PolynomialRing(QQ,3) - sage: y.macaulay_resultant(x^3+25*y^2*x,5*z) + sage: R. = PolynomialRing(QQ, 3) + sage: y.macaulay_resultant(x^3 + 25*y^2*x, 5*z) # optional - sage.modules 125 an example when the coefficients live in a finite field:: - sage: F = FiniteField(11) - sage: R. = PolynomialRing(F,4) - sage: z.macaulay_resultant([x^3,5*y,w]) + sage: F = FiniteField(11) # optional - sage.rings.finite_rings + sage: R. = PolynomialRing(F, 4) # optional - sage.rings.finite_rings + sage: z.macaulay_resultant([x^3, 5*y, w]) # optional - sage.rings.finite_rings sage.modules 4 example when the denominator in the algorithm vanishes(in this case the resultant is the constant term of the quotient of char polynomials of numerator/denominator):: - sage: R. = PolynomialRing(QQ,3) - sage: y.macaulay_resultant([x+z, z^2]) + sage: R. = PolynomialRing(QQ, 3) + sage: y.macaulay_resultant([x + z, z^2]) # optional - sage.modules -1 - when there are only 2 polynomials, macaulay resultant degenerates to the traditional resultant:: + When there are only 2 polynomials, the Macaulay resultant degenerates to the traditional resultant:: - sage: R. = PolynomialRing(QQ,1) - sage: f = x^2+1; g = x^5+1 + sage: R. = PolynomialRing(QQ, 1) + sage: f = x^2 + 1; g = x^5 + 1 sage: fh = f.homogenize() sage: gh = g.homogenize() sage: RH = fh.parent() - sage: f.resultant(g) == fh.macaulay_resultant(gh) + sage: f.resultant(g) == fh.macaulay_resultant(gh) # optional - sage.modules True """ @@ -1723,12 +1731,12 @@ cdef class MPolynomial(CommutativePolynomial): return self.parent().macaulay_resultant(self, *args) def denominator(self): - """ - Return a denominator of self. + r""" + Return a denominator of ``self``. - First, the lcm of the denominators of the entries of self + First, the lcm of the denominators of the entries of ``self`` is computed and returned. If this computation fails, the - unit of the parent of self is returned. + unit of the parent of ``self`` is returned. Note that some subclasses may implement its own denominator function. @@ -1755,10 +1763,10 @@ cdef class MPolynomial(CommutativePolynomial): :: - sage: R. = NumberField(symbolic_expression(x^2+3) ,'a')['x,y'] - sage: f = (1/17)*x^19 + (1/6)*y - (2/3)*x + 1/3; f + sage: R. = NumberField(symbolic_expression(x^2+3),'a')['x,y'] # optional - sage.rings.number_field sage.symbolic + sage: f = (1/17)*x^19 + (1/6)*y - (2/3)*x + 1/3; f # optional - sage.rings.number_field sage.symbolic 1/17*x^19 - 2/3*x + 1/6*y + 1/3 - sage: f.denominator() + sage: f.denominator() # optional - sage.rings.number_field sage.symbolic 102 Finally, we try to compute the denominator of a polynomial with @@ -1776,18 +1784,18 @@ cdef class MPolynomial(CommutativePolynomial): Check that the denominator is an element over the base whenever the base has no denominator function. This closes :trac:`9063`:: - sage: R. = GF(5)[] - sage: x = R(0) - sage: x.denominator() + sage: R. = GF(5)[] # optional - sage.rings.finite_rings + sage: x = R(0) # optional - sage.rings.finite_rings + sage: x.denominator() # optional - sage.rings.finite_rings 1 - sage: type(x.denominator()) + sage: type(x.denominator()) # optional - sage.rings.finite_rings - sage: type(a.denominator()) + sage: type(a.denominator()) # optional - sage.rings.finite_rings sage: from sage.rings.polynomial.multi_polynomial_element import MPolynomial - sage: isinstance(a / b, MPolynomial) + sage: isinstance(a / b, MPolynomial) # optional - sage.rings.finite_rings False - sage: isinstance(a.numerator() / a.denominator(), MPolynomial) + sage: isinstance(a.numerator() / a.denominator(), MPolynomial) # optional - sage.rings.finite_rings True """ if self.degree() == -1: @@ -1802,8 +1810,8 @@ cdef class MPolynomial(CommutativePolynomial): return self.base_ring().one() def numerator(self): - """ - Return a numerator of self computed as self * self.denominator() + r""" + Return a numerator of ``self``, computed as ``self * self.denominator()``. Note that some subclasses may implement its own numerator function. @@ -1811,13 +1819,13 @@ cdef class MPolynomial(CommutativePolynomial): .. warning:: This is not the numerator of the rational function - defined by self, which would always be self since self is a + defined by ``self``, which would always be self since ``self`` is a polynomial. EXAMPLES: First we compute the numerator of a polynomial with - integer coefficients, which is of course self. + integer coefficients, which is of course ``self``. :: @@ -1832,12 +1840,12 @@ cdef class MPolynomial(CommutativePolynomial): :: - sage: R. = NumberField(symbolic_expression(x^2+3) ,'a')['x,y'] - sage: f = (1/17)*y^19 - (2/3)*x + 1/3; f + sage: R. = NumberField(symbolic_expression(x^2+3), 'a')['x,y'] # optional - sage.rings.number_field sage.symbolic + sage: f = (1/17)*y^19 - (2/3)*x + 1/3; f # optional - sage.rings.number_field sage.symbolic 1/17*y^19 - 2/3*x + 1/3 - sage: f.numerator() + sage: f.numerator() # optional - sage.rings.number_field sage.symbolic 3*y^19 - 34*x + 17 - sage: f == f.numerator() + sage: f == f.numerator() # optional - sage.rings.number_field sage.symbolic False We try to compute the numerator of a polynomial with coefficients in @@ -1845,36 +1853,36 @@ cdef class MPolynomial(CommutativePolynomial): :: - sage: K. = GF(3)['x, y, z'] - sage: f = 2*x*z + 2*z^2 + 2*y + 1; f + sage: K. = GF(3)['x, y, z'] # optional - sage.rings.finite_rings + sage: f = 2*x*z + 2*z^2 + 2*y + 1; f # optional - sage.rings.finite_rings -x*z - z^2 - y + 1 - sage: f.numerator() + sage: f.numerator() # optional - sage.rings.finite_rings -x*z - z^2 - y + 1 We check that the computation the numerator and denominator - are valid + are valid. :: - sage: K=NumberField(symbolic_expression('x^3+2'),'a')['x']['s,t'] - sage: f=K.random_element() - sage: f.numerator() / f.denominator() == f + sage: K = NumberField(symbolic_expression('x^3+2'), 'a')['x']['s,t'] # optional - sage.rings.number_field sage.symbolic + sage: f = K.random_element() # optional - sage.rings.number_field sage.symbolic + sage: f.numerator() / f.denominator() == f # optional - sage.rings.number_field sage.symbolic True - sage: R=RR['x,y,z'] - sage: f=R.random_element() + sage: R = RR['x,y,z'] + sage: f = R.random_element() sage: f.numerator() / f.denominator() == f True """ return self * self.denominator() def lift(self, I): - """ - given an ideal ``I = (f_1,...,f_r)`` and some ``g (== self)`` in ``I``, - find ``s_1,...,s_r`` such that ``g = s_1 f_1 + ... + s_r f_r``. + r""" + Given an ideal `I = (f_1,\dots,f_r)` that contains ``self``, + find `s_1,\dots,s_r` such that ``self`` `= s_1 f_1 + ... + s_r f_r`. EXAMPLES:: - sage: A. = PolynomialRing(CC,2,order='degrevlex') + sage: A. = PolynomialRing(CC, 2, order='degrevlex') sage: I = A.ideal([x^10 + x^9*y^2, y^8 - x^2*y^7 ]) sage: f = x*y^13 + y^12 sage: M = f.lift(I) @@ -1886,25 +1894,26 @@ cdef class MPolynomial(CommutativePolynomial): raise NotImplementedError def inverse_mod(self, I): - """ - Returns an inverse of self modulo the polynomial ideal `I`, + r""" + Returns an inverse of ``self`` modulo the polynomial ideal `I`, namely a multivariate polynomial `f` such that ``self * f - 1`` belongs to `I`. INPUT: - - ``I`` -- an ideal of the polynomial ring in which self lives + + - ``I`` -- an ideal of the polynomial ring in which ``self`` lives OUTPUT: - - a multivariate polynomial representing the inverse of ``f`` modulo ``I`` + a multivariate polynomial representing the inverse of ``f`` modulo `I` EXAMPLES:: sage: R. = QQ[] sage: I = R.ideal(x2**2 + x1 - 2, x1**2 - 1) - sage: f = x1 + 3*x2^2; g = f.inverse_mod(I); g + sage: f = x1 + 3*x2^2; g = f.inverse_mod(I); g # optional - sage.libs.singular 1/16*x1 + 3/16 - sage: (f*g).reduce(I) + sage: (f*g).reduce(I) # optional - sage.libs.singular 1 Test a non-invertible element:: @@ -1912,7 +1921,7 @@ cdef class MPolynomial(CommutativePolynomial): sage: R. = QQ[] sage: I = R.ideal(x2**2 + x1 - 2, x1**2 - 1) sage: f = x1 + x2 - sage: f.inverse_mod(I) + sage: f.inverse_mod(I) # optional - sage.libs.singular Traceback (most recent call last): ... ArithmeticError: element is non-invertible @@ -1926,7 +1935,7 @@ cdef class MPolynomial(CommutativePolynomial): raise ArithmeticError("element is non-invertible") def weighted_degree(self, *weights): - """ + r""" Return the weighted degree of ``self``, which is the maximum weighted degree of all monomials in ``self``; the weighted degree of a monomial is the sum of all powers of the variables in the monomial, each power @@ -1945,42 +1954,42 @@ cdef class MPolynomial(CommutativePolynomial): EXAMPLES:: - sage: R. = GF(7)[] - sage: p = x^3 + y + x*z^2 - sage: p.weighted_degree({z:0, x:1, y:2}) + sage: R. = GF(7)[] # optional - sage.rings.finite_rings + sage: p = x^3 + y + x*z^2 # optional - sage.rings.finite_rings + sage: p.weighted_degree({z:0, x:1, y:2}) # optional - sage.rings.finite_rings 3 - sage: p.weighted_degree(1, 2, 0) + sage: p.weighted_degree(1, 2, 0) # optional - sage.rings.finite_rings 3 - sage: p.weighted_degree((1, 4, 2)) + sage: p.weighted_degree((1, 4, 2)) # optional - sage.rings.finite_rings 5 - sage: p.weighted_degree((1, 4, 1)) + sage: p.weighted_degree((1, 4, 1)) # optional - sage.rings.finite_rings 4 - sage: p.weighted_degree(2**64, 2**50, 2**128) + sage: p.weighted_degree(2**64, 2**50, 2**128) # optional - sage.rings.finite_rings 680564733841876926945195958937245974528 - sage: q = R.random_element(100, 20) #random - sage: q.weighted_degree(1, 1, 1) == q.total_degree() + sage: q = R.random_element(100, 20) #random # optional - sage.rings.finite_rings + sage: q.weighted_degree(1, 1, 1) == q.total_degree() # optional - sage.rings.finite_rings True You may also work with negative weights :: - sage: p.weighted_degree(-1, -2, -1) + sage: p.weighted_degree(-1, -2, -1) # optional - sage.rings.finite_rings -2 Note that only integer weights are allowed :: - sage: p.weighted_degree(x,1,1) + sage: p.weighted_degree(x, 1, 1) # optional - sage.rings.finite_rings Traceback (most recent call last): ... TypeError: unable to convert non-constant polynomial x to Integer Ring - sage: p.weighted_degree(2/1,1,1) + sage: p.weighted_degree(2/1, 1, 1) # optional - sage.rings.finite_rings 6 - The ``weighted_degree`` coincides with the ``degree`` of a weighted - polynomial ring, but the later is faster. + The :meth:`weighted_degree` coincides with the :meth:`degree` of a weighted + polynomial ring, but the latter is faster. :: @@ -2034,7 +2043,7 @@ cdef class MPolynomial(CommutativePolynomial): return deg def gcd(self, other): - """ + r""" Return a greatest common divisor of this polynomial and ``other``. INPUT: @@ -2048,7 +2057,7 @@ cdef class MPolynomial(CommutativePolynomial): sage: r = x*y - (2*z-1)/(z^2+z+1) * x + y/z sage: p = r * (x + z*y - 1/z^2) sage: q = r * (x*y*z + 1) - sage: gcd(p,q) + sage: gcd(p, q) (z^3 + z^2 + z)*x*y + (-2*z^2 + z)*x + (z^2 + z + 1)*y Polynomials over polynomial rings are converted to a simpler polynomial @@ -2056,21 +2065,23 @@ cdef class MPolynomial(CommutativePolynomial): sage: A. = ZZ[] sage: B. = A[] - sage: r = x*y*z*t+1 + sage: r = x*y*z*t + 1 sage: p = r * (x - y + z - t + 1) sage: q = r * (x*z - y*t) - sage: gcd(p,q) + sage: gcd(p, q) z*t*x*y + 1 sage: _.parent() - Multivariate Polynomial Ring in x, y over Multivariate Polynomial Ring in z, t over Integer Ring + Multivariate Polynomial Ring in x, y over + Multivariate Polynomial Ring in z, t over Integer Ring Some multivariate polynomial rings have no gcd implementation:: - sage: R. =GaussianIntegers()[] + sage: R. = GaussianIntegers()[] sage: x.gcd(x) Traceback (most recent call last): ... - NotImplementedError: GCD is not implemented for multivariate polynomials over Gaussian Integers in Number Field in I with defining polynomial x^2 + 1 with I = 1*I + NotImplementedError: GCD is not implemented for multivariate polynomials over + Gaussian Integers in Number Field in I with defining polynomial x^2 + 1 with I = 1*I TESTS:: @@ -2159,11 +2170,11 @@ cdef class MPolynomial(CommutativePolynomial): def is_square(self, root=False): r""" - Test whether this polynomial is a square root. + Test whether this polynomial is a square. INPUT: - - ``root`` - if set to ``True`` return a pair ``(True, root)`` + - ``root`` - if set to ``True``, return a pair ``(True, root)`` where ``root`` is a square root or ``(False, None)`` if it is not a square. @@ -2196,7 +2207,7 @@ cdef class MPolynomial(CommutativePolynomial): - ``D`` -- dictionary (optional) - - ``phi`` -- SpecializationMorphism (optional) + - ``phi`` -- :class:`SpecializationMorphism` (optional) OUTPUT: a new polynomial @@ -2273,11 +2284,11 @@ cdef class MPolynomial(CommutativePolynomial): keywords: - - ``prec`` -- integer, sets the precision (default:300) + - ``prec`` -- integer, sets the precision (default: 300) - - ``return_conjugation`` -- boolean. Returns element of `SL(2, \ZZ)` (default:True) + - ``return_conjugation`` -- boolean. Returns element of `SL(2, \ZZ)` (default: True) - - ``error_limit`` -- sets the error tolerance (default:0.000001) + - ``error_limit`` -- sets the error tolerance (default: 0.000001) - ``smallest_coeffs`` -- (default: True), boolean, whether to find the model with smallest coefficients @@ -2285,16 +2296,18 @@ cdef class MPolynomial(CommutativePolynomial): - ``norm_type`` -- either ``'norm'`` or ``'height'``. What type of norm to use for smallest coefficients - - ``emb`` -- (optional) embedding of based field into CC + - ``emb`` -- (optional) embedding of based field into ``CC`` OUTPUT: - - a polynomial (reduced binary form) + - a polynomial (reduced binary form) + + - a matrix (element of `SL(2, \ZZ)`) - - a matrix (element of `SL(2, \ZZ)`) + .. TODO:: - TODO: When Newton's Method doesn't converge to a root in the upper half plane. - Now we just return z0. It would be better to modify and find the unique root + When Newton's Method doesn't converge to a root in the upper half plane. + Now we just return `z_0`. It would be better to modify and find the unique root in the upper half plane. EXAMPLES:: @@ -2302,7 +2315,7 @@ cdef class MPolynomial(CommutativePolynomial): sage: R. = PolynomialRing(QQ) sage: f = 19*x^8 - 262*x^7*h + 1507*x^6*h^2 - 4784*x^5*h^3 + 9202*x^4*h^4\ -10962*x^3*h^5 + 7844*x^2*h^6 - 3040*x*h^7 + 475*h^8 - sage: f.reduced_form(prec=200, smallest_coeffs=False) + sage: f.reduced_form(prec=200, smallest_coeffs=False) # optional - sage.modules ( -x^8 - 2*x^7*h + 7*x^6*h^2 + 16*x^5*h^3 + 2*x^4*h^4 - 2*x^3*h^5 + 4*x^2*h^6 - 5*h^8, @@ -2315,7 +2328,7 @@ cdef class MPolynomial(CommutativePolynomial): sage: R. = PolynomialRing(QQ) sage: f = x^3 + 378666*x^2*y - 12444444*x*y^2 + 1234567890*y^3 sage: j = f * (x-545*y)^9 - sage: j.reduced_form(prec=200, smallest_coeffs=False) + sage: j.reduced_form(prec=200, smallest_coeffs=False) # optional - sage.modules Traceback (most recent call last): ... ValueError: cannot have a root with multiplicity >= 12/2 @@ -2324,7 +2337,7 @@ cdef class MPolynomial(CommutativePolynomial): sage: R. = PolynomialRing(QQ) sage: F = x^6 + 3*x^5*y - 8*x^4*y^2 - 2*x^3*y^3 - 44*x^2*y^4 - 8*x*y^5 - sage: F.reduced_form(smallest_coeffs=False, prec=400) + sage: F.reduced_form(smallest_coeffs=False, prec=400) # optional - sage.modules Traceback (most recent call last): ... ArithmeticError: Newton's method converged to z not in the upper half plane @@ -2333,7 +2346,7 @@ cdef class MPolynomial(CommutativePolynomial): sage: R. = PolynomialRing(QQ) sage: F = 5*x^2*y - 5*x*y^2 - 30*y^3 - sage: F.reduced_form(smallest_coeffs=False) + sage: F.reduced_form(smallest_coeffs=False) # optional - sage.modules ( [1 1] 5*x^2*y + 5*x*y^2 - 30*y^3, [0 1] @@ -2342,12 +2355,14 @@ cdef class MPolynomial(CommutativePolynomial): An example where precision needs to be increased:: sage: R. = PolynomialRing(QQ) - sage: F=-16*x^7 - 114*x^6*y - 345*x^5*y^2 - 599*x^4*y^3 - 666*x^3*y^4 - 481*x^2*y^5 - 207*x*y^6 - 40*y^7 - sage: F.reduced_form(prec=50, smallest_coeffs=False) + sage: F = (-16*x^7 - 114*x^6*y - 345*x^5*y^2 - 599*x^4*y^3 + ....: - 666*x^3*y^4 - 481*x^2*y^5 - 207*x*y^6 - 40*y^7) + sage: F.reduced_form(prec=50, smallest_coeffs=False) # optional - sage.modules Traceback (most recent call last): ... - ValueError: accuracy of Newton's root not within tolerance(0.000012... > 1e-06), increase precision - sage: F.reduced_form(prec=100, smallest_coeffs=False) + ValueError: accuracy of Newton's root not within tolerance(0.000012... > 1e-06), + increase precision + sage: F.reduced_form(prec=100, smallest_coeffs=False) # optional - sage.modules ( [-1 -1] -x^5*y^2 - 24*x^3*y^4 - 3*x^2*y^5 - 2*x*y^6 + 16*y^7, [ 1 0] @@ -2357,14 +2372,14 @@ cdef class MPolynomial(CommutativePolynomial): sage: R. = PolynomialRing(QQ) sage: F = - 8*x^4 - 3933*x^3*y - 725085*x^2*y^2 - 59411592*x*y^3 - 1825511633*y^4 - sage: F.reduced_form(return_conjugation=False) + sage: F.reduced_form(return_conjugation=False) # optional - sage.modules x^4 + 9*x^3*y - 3*x*y^3 - 8*y^4 :: sage: R. = QQ[] sage: F = -2*x^3 + 2*x^2*y + 3*x*y^2 + 127*y^3 - sage: F.reduced_form() + sage: F.reduced_form() # optional - sage.modules ( [1 4] -2*x^3 - 22*x^2*y - 77*x*y^2 + 43*y^3, [0 1] @@ -2374,7 +2389,7 @@ cdef class MPolynomial(CommutativePolynomial): sage: R. = QQ[] sage: F = -2*x^3 + 2*x^2*y + 3*x*y^2 + 127*y^3 - sage: F.reduced_form(norm_type='height') + sage: F.reduced_form(norm_type='height') # optional - sage.modules ( [5 4] -58*x^3 - 47*x^2*y + 52*x*y^2 + 43*y^3, [1 1] @@ -2384,7 +2399,7 @@ cdef class MPolynomial(CommutativePolynomial): sage: R. = PolynomialRing(QQ) sage: F = x^4 + x^3*y*z + y^2*z - sage: F.reduced_form() + sage: F.reduced_form() # optional - sage.modules Traceback (most recent call last): ... ValueError: (=x^3*y*z + x^4 + y^2*z) must have two variables @@ -2393,7 +2408,7 @@ cdef class MPolynomial(CommutativePolynomial): sage: R. = PolynomialRing(ZZ) sage: F = - 8*x^6 - 3933*x^3*y - 725085*x^2*y^2 - 59411592*x*y^3 - 99*y^6 - sage: F.reduced_form(return_conjugation=False) + sage: F.reduced_form(return_conjugation=False) # optional - sage.modules Traceback (most recent call last): ... ValueError: (=-8*x^6 - 99*y^6 - 3933*x^3*y - 725085*x^2*y^2 - @@ -2402,11 +2417,12 @@ cdef class MPolynomial(CommutativePolynomial): :: sage: R. = PolynomialRing(RR) - sage: F = 217.992172373276*x^3 + 96023.1505442490*x^2*y + 1.40987971253579e7*x*y^2\ - + 6.90016027113216e8*y^3 - sage: F.reduced_form(smallest_coeffs=False) # tol 1e-8 + sage: F = (217.992172373276*x^3 + 96023.1505442490*x^2*y + ....: + 1.40987971253579e7*x*y^2 + 6.90016027113216e8*y^3) + sage: F.reduced_form(smallest_coeffs=False) # tol 1e-8 # optional - sage.modules ( - -39.5673942565918*x^3 + 111.874026298523*x^2*y + 231.052762985229*x*y^2 - 138.380829811096*y^3, + -39.5673942565918*x^3 + 111.874026298523*x^2*y + + 231.052762985229*x*y^2 - 138.380829811096*y^3, [-147 -148] [ 1 1] @@ -2415,12 +2431,16 @@ cdef class MPolynomial(CommutativePolynomial): :: sage: R. = PolynomialRing(CC) - sage: F = (0.759099196558145 + 0.845425869641446*CC.0)*x^3 + (84.8317207268542 + 93.8840848648033*CC.0)*x^2*y\ - + (3159.07040755858 + 3475.33037377779*CC.0)*x*y^2 + (39202.5965389079 + 42882.5139724962*CC.0)*y^3 - sage: F.reduced_form(smallest_coeffs=False) # tol 1e-11 + sage: F = ((0.759099196558145 + 0.845425869641446*CC.0)*x^3 + ....: + (84.8317207268542 + 93.8840848648033*CC.0)*x^2*y + ....: + (3159.07040755858 + 3475.33037377779*CC.0)*x*y^2 + ....: + (39202.5965389079 + 42882.5139724962*CC.0)*y^3) + sage: F.reduced_form(smallest_coeffs=False) # tol 1e-11 # optional - sage.modules ( - (-0.759099196558145 - 0.845425869641446*I)*x^3 + (-0.571709908900118 - 0.0418133346027929*I)*x^2*y - + (0.856525964330103 - 0.0721403997649759*I)*x*y^2 + (-0.965531044130330 + 0.754252314465703*I)*y^3, + (-0.759099196558145 - 0.845425869641446*I)*x^3 + + (-0.571709908900118 - 0.0418133346027929*I)*x^2*y + + (0.856525964330103 - 0.0721403997649759*I)*x*y^2 + + (-0.965531044130330 + 0.754252314465703*I)*y^3, [-1 37] [ 0 -1] @@ -2507,16 +2527,16 @@ cdef class MPolynomial(CommutativePolynomial): EXAMPLES:: - sage: R. = QQbar[] - sage: (x+y).is_unit() + sage: R. = QQbar[] # optional - sage.rings.number_field + sage: (x + y).is_unit() # optional - sage.rings.number_field False - sage: R(0).is_unit() + sage: R(0).is_unit() # optional - sage.rings.number_field False - sage: R(-1).is_unit() + sage: R(-1).is_unit() # optional - sage.rings.number_field True - sage: R(-1 + x).is_unit() + sage: R(-1 + x).is_unit() # optional - sage.rings.number_field False - sage: R(2).is_unit() + sage: R(2).is_unit() # optional - sage.rings.number_field True Check that :trac:`22454` is fixed:: @@ -2553,18 +2573,18 @@ cdef class MPolynomial(CommutativePolynomial): EXAMPLES:: - sage: R. = QQbar[] - sage: (x+y).is_nilpotent() + sage: R. = QQbar[] # optional - sage.rings.number_field + sage: (x + y).is_nilpotent() # optional - sage.rings.number_field False - sage: R(0).is_nilpotent() + sage: R(0).is_nilpotent() # optional - sage.rings.number_field True sage: _. = Zmod(4)[] sage: (2*x).is_nilpotent() True - sage: (2+y*x).is_nilpotent() + sage: (2 + y*x).is_nilpotent() False sage: _. = Zmod(36)[] - sage: (4+6*x).is_nilpotent() + sage: (4 + 6*x).is_nilpotent() False sage: (6*x + 12*y + 18*x*y + 24*(x^2+y^2)).is_nilpotent() True @@ -2585,8 +2605,8 @@ cdef class MPolynomial(CommutativePolynomial): TESTS:: - sage: R. = QQbar[] - sage: (x + y)._test_subs() + sage: R. = QQbar[] # optional - sage.rings.number_field + sage: (x + y)._test_subs() # optional - sage.rings.number_field """ if tester is None: tester = self._tester(**options) @@ -2865,11 +2885,12 @@ cdef class MPolynomial_libsingular(MPolynomial): EXAMPLES:: + sage: from sage.rings.polynomial.multi_polynomial import MPolynomial_libsingular sage: R1. = QQ[] - sage: isinstance(x, sage.rings.polynomial.multi_polynomial.MPolynomial_libsingular) + sage: isinstance(x, MPolynomial_libsingular) False sage: R2. = QQ[] - sage: isinstance(y, sage.rings.polynomial.multi_polynomial.MPolynomial_libsingular) + sage: isinstance(y, MPolynomial_libsingular) # optional - sage.libs.singular True By design, there is a unique direct subclass:: diff --git a/src/sage/rings/polynomial/multi_polynomial_element.py b/src/sage/rings/polynomial/multi_polynomial_element.py index 08cc3dee4d0..f270ea6ee78 100644 --- a/src/sage/rings/polynomial/multi_polynomial_element.py +++ b/src/sage/rings/polynomial/multi_polynomial_element.py @@ -31,8 +31,10 @@ We verify Lagrange's four squares identity:: - sage: R. = QQbar[] - sage: (a0^2 + a1^2 + a2^2 + a3^2)*(b0^2 + b1^2 + b2^2 + b3^2) == (a0*b0 - a1*b1 - a2*b2 - a3*b3)^2 + (a0*b1 + a1*b0 + a2*b3 - a3*b2)^2 + (a0*b2 - a1*b3 + a2*b0 + a3*b1)^2 + (a0*b3 + a1*b2 - a2*b1 + a3*b0)^2 + sage: R. = QQbar[] # optional - sage.rings.number_field + sage: ((a0^2 + a1^2 + a2^2 + a3^2) * (b0^2 + b1^2 + b2^2 + b3^2) == # optional - sage.rings.number_field + ....: (a0*b0 - a1*b1 - a2*b2 - a3*b3)^2 + (a0*b1 + a1*b0 + a2*b3 - a3*b2)^2 + ....: + (a0*b2 - a1*b3 + a2*b0 + a3*b1)^2 + (a0*b3 + a1*b2 - a2*b1 + a3*b0)^2) True """ #***************************************************************************** @@ -92,12 +94,12 @@ def __init__(self, parent, x): """ EXAMPLES:: - sage: K. = NumberField(x^3 - 2) - sage: L. = K.extension(x^3 - 3) - sage: S. = L.extension(x^2 - 2) - sage: S + sage: K. = NumberField(x^3 - 2) # optional - sage.rings.number_field + sage: L. = K.extension(x^3 - 3) # optional - sage.rings.number_field + sage: S. = L.extension(x^2 - 2) # optional - sage.rings.number_field + sage: S # optional - sage.rings.number_field Number Field in sqrt2 with defining polynomial x^2 - 2 over its base field - sage: P. = PolynomialRing(S) # indirect doctest + sage: P. = PolynomialRing(S) # indirect doctest # optional - sage.rings.number_field """ CommutativeRingElement.__init__(self, parent) self.__element = x @@ -106,8 +108,8 @@ def _repr_(self): """ EXAMPLES:: - sage: P. = PolynomialRing(QQbar) - sage: x + QQbar(sqrt(2) - 1/2*I) # indirect doctest + sage: P. = PolynomialRing(QQbar) # optional - sage.rings.number_field + sage: x + QQbar(sqrt(2) - 1/2*I) # indirect doctest # optional - sage.rings.number_field x + 1.414213562373095? - 0.50000000000000000?*I """ return "%s"%self.__element @@ -184,15 +186,15 @@ def _richcmp_(self, right, op): EXAMPLES:: - sage: R.=PolynomialRing(QQbar,3,order='lex') - sage: x^1*y^2 > y^3*z^4 + sage: R. = PolynomialRing(QQbar, 3, order='lex') # optional - sage.rings.number_field + sage: x^1*y^2 > y^3*z^4 # optional - sage.rings.number_field True - sage: x^3*y^2*z^4 < x^3*y^2*z^1 + sage: x^3*y^2*z^4 < x^3*y^2*z^1 # optional - sage.rings.number_field False :: - sage: R.=PolynomialRing(CC,3,order='deglex') + sage: R. = PolynomialRing(CC, 3, order='deglex') sage: x^1*y^2*z^3 > x^3*y^2*z^0 True sage: x^1*y^2*z^4 < x^1*y^1*z^5 @@ -200,10 +202,10 @@ def _richcmp_(self, right, op): :: - sage: R.=PolynomialRing(QQbar,3,order='degrevlex') - sage: x^1*y^5*z^2 > x^4*y^1*z^3 + sage: R. = PolynomialRing(QQbar, 3, order='degrevlex') # optional - sage.rings.number_field + sage: x^1*y^5*z^2 > x^4*y^1*z^3 # optional - sage.rings.number_field True - sage: x^4*y^7*z^1 < x^4*y^2*z^3 + sage: x^4*y^7*z^1 < x^4*y^2*z^3 # optional - sage.rings.number_field False """ return self.__element.rich_compare(right.__element, op, @@ -213,9 +215,9 @@ def _im_gens_(self, codomain, im_gens, base_map=None): """ EXAMPLES:: - sage: R. = PolynomialRing(QQbar, 2) - sage: f = R.hom([y,x], R) - sage: f(x^2 + 3*y^5) # indirect doctest + sage: R. = PolynomialRing(QQbar, 2) # optional - sage.rings.number_field + sage: f = R.hom([y, x], R) # optional - sage.rings.number_field + sage: f(x^2 + 3*y^5) # indirect doctest # optional - sage.rings.number_field 3*x^5 + y^2 You can specify a map on the base ring:: @@ -272,10 +274,10 @@ def __neg__(self): EXAMPLES:: - sage: R. = QQbar[] - sage: -x + sage: R. = QQbar[] # optional - sage.rings.number_field + sage: -x # optional - sage.rings.number_field -x - sage: -(y-1) + sage: -(y-1) # optional - sage.rings.number_field -y + 1 """ return self.__class__(self.parent(), -self.__element) @@ -286,8 +288,8 @@ def _add_(self, right): EXAMPLES:: - sage: R. = QQbar[] - sage: x + y + sage: R. = QQbar[] # optional - sage.rings.number_field + sage: x + y # optional - sage.rings.number_field x + y """ elt = self.__element + right.__element @@ -300,8 +302,8 @@ def _sub_(self, right): EXAMPLES:: - sage: R. = QQbar[] - sage: x - y + sage: R. = QQbar[] # optional - sage.rings.number_field + sage: x - y # optional - sage.rings.number_field x - y """ elt = self.__element - right.__element @@ -314,8 +316,8 @@ def _mul_(self, right): EXAMPLES:: - sage: R. = QQbar[] - sage: x * y + sage: R. = QQbar[] # optional - sage.rings.number_field + sage: x * y # optional - sage.rings.number_field x*y """ elt = self.__element * right.__element @@ -334,9 +336,9 @@ def _lmul_(self, a): :: - sage: R. = QQbar[] - sage: f = (x + y) - sage: 3*f + sage: R. = QQbar[] # optional - sage.rings.number_field + sage: f = (x + y) # optional - sage.rings.number_field + sage: 3 * f # optional - sage.rings.number_field 3*x + 3*y """ elt = self.__element.scalar_lmult(a) @@ -355,9 +357,9 @@ def _rmul_(self, a): :: - sage: R. = QQbar[] - sage: f = (x + y) - sage: f*3 + sage: R. = QQbar[] # optional - sage.rings.number_field + sage: f = (x + y) # optional - sage.rings.number_field + sage: f * 3 # optional - sage.rings.number_field 3*x + 3*y """ elt = self.__element.scalar_rmult(a) @@ -388,8 +390,8 @@ def _div_(self, right): Ensure that :trac:`13704` is fixed.:: - sage: R.=PolynomialRing(QQ) - sage: S.=PolynomialRing(R) + sage: R. = PolynomialRing(QQ) + sage: S. = PolynomialRing(R) sage: x/S(2) 1/2*x """ @@ -420,15 +422,15 @@ def change_ring(self, R): sage: R. = QQ[] sage: f = x^2 + 5*y - sage: f.change_ring(GF(5)) + sage: f.change_ring(GF(5)) # optional - sage.rings.finite_rings x^2 :: - sage: K. = CyclotomicField(5) - sage: R. = K[] - sage: f = x^2 + w*y - sage: f.change_ring(K.embeddings(QQbar)[1]) + sage: K. = CyclotomicField(5) # optional - sage.rings.number_field + sage: R. = K[] # optional - sage.rings.number_field + sage: f = x^2 + w*y # optional - sage.rings.number_field + sage: f.change_ring(K.embeddings(QQbar)[1]) # optional - sage.rings.number_field x^2 + (-0.8090169943749474? + 0.5877852522924731?*I)*y """ if isinstance(R, Morphism): @@ -449,10 +451,10 @@ def __init__(self, parent, x): """ EXAMPLES:: - sage: R, x = PolynomialRing(QQbar, 10, 'x').objgens() - sage: x + sage: R, x = PolynomialRing(QQbar, 10, 'x').objgens() # optional - sage.rings.number_field + sage: x # optional - sage.rings.number_field (x0, x1, x2, x3, x4, x5, x6, x7, x8, x9) - sage: loads(dumps(x)) == x + sage: loads(dumps(x)) == x # optional - sage.rings.number_field True """ if not isinstance(x, polydict.PolyDict): @@ -482,12 +484,12 @@ def _repr_(self): """ EXAMPLES:: - sage: R.=QQbar[] - sage: repr(-x^2-y+1) # indirect doc-test + sage: R. = QQbar[] # optional - sage.rings.number_field + sage: repr(-x^2 - y + 1) # indirect doctest # optional - sage.rings.number_field '-x^2 - y + 1' - sage: K.=QuadraticField(-1) - sage: R.=K[] - sage: repr(-I*y-x^2) # indirect doc-test + sage: K. = QuadraticField(-1) # optional - sage.rings.number_field + sage: R. = K[] # optional - sage.rings.number_field + sage: repr(-I*y - x^2) # indirect doctest # optional - sage.rings.number_field '-x^2 + (-I)*y' """ try: @@ -503,12 +505,12 @@ def _latex_(self): r""" EXAMPLES:: - sage: R.=QQbar[] - sage: latex(-x^2-y+1) + sage: R. = QQbar[] # optional - sage.rings.number_field + sage: latex(-x^2 - y + 1) # optional - sage.rings.number_field -x^{2} - y + 1 - sage: K.=QuadraticField(-1) - sage: R.=K[] - sage: latex(-I*y+I*x^2) + sage: K. = QuadraticField(-1) # optional - sage.rings.number_field + sage: R. = K[] # optional - sage.rings.number_field + sage: latex(-I*y + I*x^2) # optional - sage.rings.number_field \left(\sqrt{-1}\right) x^{2} + \left(-\sqrt{-1}\right) y """ try: @@ -523,9 +525,9 @@ def _repr_with_changed_varnames(self, varnames): """ EXAMPLES:: - sage: R.=QQbar[] - sage: f=-x^2-y+1 - sage: f._repr_with_changed_varnames(['jack','jill']) + sage: R. = QQbar[] # optional - sage.rings.number_field + sage: f = -x^2 - y + 1 # optional - sage.rings.number_field + sage: f._repr_with_changed_varnames(['jack', 'jill']) # optional - sage.rings.number_field '-jack^2 - jill + 1' """ try: @@ -540,8 +542,8 @@ def _macaulay2_(self, macaulay2=None): """ EXAMPLES:: - sage: R = GF(13)['a,b']['c,d'] - sage: macaulay2(R('a^2 + c')) # optional - macaulay2 + sage: R = GF(13)['a,b']['c,d'] # optional - sage.rings.finite_rings + sage: macaulay2(R('a^2 + c')) # optional - macaulay2 sage.rings.finite_rings 2 c + a @@ -550,7 +552,7 @@ def _macaulay2_(self, macaulay2=None): Elements of the base ring are coerced to the polynomial ring correctly:: - sage: macaulay2(R('a^2')).ring()._operator('===', R) # optional - macaulay2 + sage: macaulay2(R('a^2')).ring()._operator('===', R) # optional - macaulay2 sage.rings.finite_rings true """ if macaulay2 is None: @@ -568,20 +570,20 @@ def degrees(self): EXAMPLES:: - sage: R.=PolynomialRing(QQbar) - sage: f = 3*x^2 - 2*y + 7*x^2*y^2 + 5 - sage: f.degrees() + sage: R. = PolynomialRing(QQbar) # optional - sage.rings.number_field + sage: f = 3*x^2 - 2*y + 7*x^2*y^2 + 5 # optional - sage.rings.number_field + sage: f.degrees() # optional - sage.rings.number_field (2, 2, 0) - sage: f = x^2+z^2 - sage: f.degrees() + sage: f = x^2 + z^2 # optional - sage.rings.number_field + sage: f.degrees() # optional - sage.rings.number_field (2, 0, 2) - sage: f.total_degree() # this simply illustrates that total degree is not the sum of the degrees + sage: f.total_degree() # this simply illustrates that total degree is not the sum of the degrees # optional - sage.rings.number_field 2 - sage: R.=PolynomialRing(QQbar) - sage: f=(1-x)*(1+y+z+x^3)^5 - sage: f.degrees() + sage: R. = PolynomialRing(QQbar) # optional - sage.rings.number_field + sage: f = (1-x) * (1+y+z+x^3)^5 # optional - sage.rings.number_field + sage: f.degrees() # optional - sage.rings.number_field (16, 5, 5, 0) - sage: R(0).degrees() + sage: R(0).degrees() # optional - sage.rings.number_field (0, 0, 0, 0) """ if not self: @@ -591,17 +593,17 @@ def degrees(self): def degree(self, x=None, std_grading=False): """ - Return the degree of self in x, where x must be one of the - generators for the parent of self. + Return the degree of ``self`` in ``x``, where ``x`` must be one of the + generators for the parent of ``self``. INPUT: - ``x`` - multivariate polynomial (a generator of the parent - of self). If ``x`` is not specified (or is None), return - the total degree, which is the maximum degree of any - monomial. Note that a weighted term ordering alters the - grading of the generators of the ring; see the tests below. - To avoid this behavior, set the optional argument ``std_grading=True``. + of ``self``). If ``x`` is not specified (or is None), return + the total degree, which is the maximum degree of any + monomial. Note that a weighted term ordering alters the + grading of the generators of the ring; see the tests below. + To avoid this behavior, set the optional argument ``std_grading=True``. OUTPUT: integer @@ -623,15 +625,15 @@ def degree(self, x=None, std_grading=False): :: - sage: R = PolynomialRing(QQ,'x,y',order=TermOrder('wdeglex',(2,3))) + sage: R = PolynomialRing(QQ, 'x,y', order=TermOrder('wdeglex',(2,3))) sage: x,y = R.gens() sage: x.degree() 2 sage: y.degree() 3 - sage: x.degree(y),x.degree(x),y.degree(x),y.degree(y) + sage: x.degree(y), x.degree(x), y.degree(x), y.degree(y) (0, 1, 0, 1) - sage: f = (x^2*y+x*y^2) + sage: f = x^2*y + x*y^2 sage: f.degree(x) 2 sage: f.degree(y) @@ -641,7 +643,7 @@ def degree(self, x=None, std_grading=False): sage: f.degree(std_grading=True) 3 - Note that if ``x`` is not a generator of the parent of self, + Note that if ``x`` is not a generator of the parent of ``self``, for example if it is a generator of a polynomial algebra which maps naturally to this one, then it is converted to an element of this algebra. (This fixes the problem reported in @@ -659,37 +661,37 @@ def degree(self, x=None, std_grading=False): ... TypeError: x must canonically coerce to parent - sage: GF(3037000453)['x','y'].gen(0).degree(x^2) + sage: GF(3037000453)['x','y'].gen(0).degree(x^2) # optional - sage.rings.finite_rings Traceback (most recent call last): ... TypeError: x must be one of the generators of the parent TESTS:: - sage: R = PolynomialRing(GF(2)['t'],'x,y',order=TermOrder('wdeglex',(2,3))) - sage: x,y = R.gens() - sage: x.degree() + sage: R = PolynomialRing(GF(2)['t'], 'x,y', order=TermOrder('wdeglex', (2,3))) # optional - sage.rings.finite_rings + sage: x, y = R.gens() # optional - sage.rings.finite_rings + sage: x.degree() # optional - sage.rings.finite_rings 2 - sage: y.degree() + sage: y.degree() # optional - sage.rings.finite_rings 3 - sage: x.degree(y),x.degree(x),y.degree(x),y.degree(y) + sage: x.degree(y), x.degree(x), y.degree(x), y.degree(y) # optional - sage.rings.finite_rings (0, 1, 0, 1) - sage: f = (x^2*y+x*y^2) - sage: f.degree(x) + sage: f = (x^2*y + x*y^2) # optional - sage.rings.finite_rings + sage: f.degree(x) # optional - sage.rings.finite_rings 2 - sage: f.degree(y) + sage: f.degree(y) # optional - sage.rings.finite_rings 2 - sage: f.degree() + sage: f.degree() # optional - sage.rings.finite_rings 8 - sage: f.degree(std_grading=True) + sage: f.degree(std_grading=True) # optional - sage.rings.finite_rings 3 - sage: R(0).degree() + sage: R(0).degree() # optional - sage.rings.finite_rings -1 Degree of zero polynomial for other implementation :trac:`20048` :: - sage: R. = GF(3037000453)[] - sage: R.zero().degree(x) + sage: R. = GF(3037000453)[] # optional - sage.rings.finite_rings + sage: R.zero().degree(x) # optional - sage.rings.finite_rings -1 """ if x is None: @@ -710,37 +712,37 @@ def degree(self, x=None, std_grading=False): def total_degree(self): """ - Return the total degree of self, which is the maximum degree of any - monomial in self. + Return the total degree of ``self``, which is the maximum degree of any + monomial in ``self``. EXAMPLES:: - sage: R. = QQbar[] - sage: f=2*x*y^3*z^2 - sage: f.total_degree() + sage: R. = QQbar[] # optional - sage.rings.number_field + sage: f = 2*x*y^3*z^2 # optional - sage.rings.number_field + sage: f.total_degree() # optional - sage.rings.number_field 6 - sage: f=4*x^2*y^2*z^3 - sage: f.total_degree() + sage: f = 4*x^2*y^2*z^3 # optional - sage.rings.number_field + sage: f.total_degree() # optional - sage.rings.number_field 7 - sage: f=99*x^6*y^3*z^9 - sage: f.total_degree() + sage: f = 99*x^6*y^3*z^9 # optional - sage.rings.number_field + sage: f.total_degree() # optional - sage.rings.number_field 18 - sage: f=x*y^3*z^6+3*x^2 - sage: f.total_degree() + sage: f = x*y^3*z^6 + 3*x^2 # optional - sage.rings.number_field + sage: f.total_degree() # optional - sage.rings.number_field 10 - sage: f=z^3+8*x^4*y^5*z - sage: f.total_degree() + sage: f = z^3 + 8*x^4*y^5*z # optional - sage.rings.number_field + sage: f.total_degree() # optional - sage.rings.number_field 10 - sage: f=z^9+10*x^4+y^8*x^2 - sage: f.total_degree() + sage: f = z^9 + 10*x^4 + y^8*x^2 # optional - sage.rings.number_field + sage: f.total_degree() # optional - sage.rings.number_field 10 """ return self.degree() def monomial_coefficient(self, mon): """ - Return the coefficient in the base ring of the monomial mon in - self, where mon must have the same parent as self. + Return the coefficient in the base ring of the monomial ``mon`` in + ``self``, where ``mon`` must have the same parent as ``self``. This function contrasts with the function ``coefficient`` which returns the coefficient of a @@ -761,43 +763,35 @@ def monomial_coefficient(self, mon): EXAMPLES: - The parent of the return is a member of the base ring. - :: - sage: R.=QQbar[] - - The parent of the return is a member of the base ring. - - :: - - sage: f = 2 * x * y - sage: c = f.monomial_coefficient(x*y); c + sage: R. = QQbar[] # optional - sage.rings.number_field + sage: f = 2 * x * y # optional - sage.rings.number_field + sage: c = f.monomial_coefficient(x*y); c # optional - sage.rings.number_field 2 - sage: c.parent() + sage: c.parent() # optional - sage.rings.number_field Algebraic Field :: - sage: f = y^2 + y^2*x - x^9 - 7*x + 5*x*y - sage: f.monomial_coefficient(y^2) + sage: f = y^2 + y^2*x - x^9 - 7*x + 5*x*y # optional - sage.rings.number_field + sage: f.monomial_coefficient(y^2) # optional - sage.rings.number_field 1 - sage: f.monomial_coefficient(x*y) + sage: f.monomial_coefficient(x*y) # optional - sage.rings.number_field 5 - sage: f.monomial_coefficient(x^9) + sage: f.monomial_coefficient(x^9) # optional - sage.rings.number_field -1 - sage: f.monomial_coefficient(x^10) + sage: f.monomial_coefficient(x^10) # optional - sage.rings.number_field 0 :: - sage: var('a') - a - sage: K. = NumberField(a^2+a+1) - sage: P. = K[] - sage: f=(a*x-1)*((a+1)*y-1); f + sage: a = polygen(ZZ, 'a') + sage: K. = NumberField(a^2 + a + 1) # optional - sage.rings.number_field + sage: P. = K[] # optional - sage.rings.number_field + sage: f = (a*x - 1) * ((a+1)*y - 1); f # optional - sage.rings.number_field -x*y + (-a)*x + (-a - 1)*y + 1 - sage: f.monomial_coefficient(x) + sage: f.monomial_coefficient(x) # optional - sage.rings.number_field -a """ if parent(mon) is not self.parent(): @@ -819,23 +813,23 @@ def __iter__(self): EXAMPLES:: - sage: R. = PolynomialRing(QQbar, order='lex') - sage: f = (x^1*y^5*z^2 + x^2*z + x^4*y^1*z^3) - sage: list(f) + sage: R. = PolynomialRing(QQbar, order='lex') # optional - sage.rings.number_field + sage: f = (x^1*y^5*z^2 + x^2*z + x^4*y^1*z^3) # optional - sage.rings.number_field + sage: list(f) # optional - sage.rings.number_field [(1, x^4*y*z^3), (1, x^2*z), (1, x*y^5*z^2)] :: - sage: R. = PolynomialRing(QQbar, order='deglex') - sage: f = (x^1*y^5*z^2 + x^2*z + x^4*y^1*z^3) - sage: list(f) + sage: R. = PolynomialRing(QQbar, order='deglex') # optional - sage.rings.number_field + sage: f = (x^1*y^5*z^2 + x^2*z + x^4*y^1*z^3) # optional - sage.rings.number_field + sage: list(f) # optional - sage.rings.number_field [(1, x^4*y*z^3), (1, x*y^5*z^2), (1, x^2*z)] :: - sage: R. = PolynomialRing(QQbar, order='degrevlex') - sage: f = (x^1*y^5*z^2 + x^2*z + x^4*y^1*z^3) - sage: list(f) + sage: R. = PolynomialRing(QQbar, order='degrevlex') # optional - sage.rings.number_field + sage: f = (x^1*y^5*z^2 + x^2*z + x^4*y^1*z^3) # optional - sage.rings.number_field + sage: list(f) # optional - sage.rings.number_field [(1, x*y^5*z^2), (1, x^4*y*z^3), (1, x^2*z)] :: @@ -866,22 +860,22 @@ def __getitem__(self, x): EXAMPLES:: - sage: R. = PolynomialRing(QQbar, 2) - sage: f = -10*x^3*y + 17*x*y - sage: f[3,1] + sage: R. = PolynomialRing(QQbar, 2) # optional - sage.rings.number_field + sage: f = -10*x^3*y + 17*x*y # optional - sage.rings.number_field + sage: f[3,1] # optional - sage.rings.number_field -10 - sage: f[1,1] + sage: f[1,1] # optional - sage.rings.number_field 17 - sage: f[0,1] + sage: f[0,1] # optional - sage.rings.number_field 0 :: - sage: R. = PolynomialRing(QQbar,1); R + sage: R. = PolynomialRing(QQbar, 1); R # optional - sage.rings.number_field Multivariate Polynomial Ring in x over Algebraic Field - sage: f = 5*x^2 + 3; f + sage: f = 5*x^2 + 3; f # optional - sage.rings.number_field 5*x^2 + 3 - sage: f[2] + sage: f[2] # optional - sage.rings.number_field 5 """ if isinstance(x, MPolynomial): @@ -907,14 +901,14 @@ def iterator_exp_coeff(self, as_ETuples=True): EXAMPLES:: - sage: R. = PolynomialRing(QQbar, order='lex') - sage: f = (x^1*y^5*z^2 + x^2*z + x^4*y^1*z^3) - sage: list(f.iterator_exp_coeff()) + sage: R. = PolynomialRing(QQbar, order='lex') # optional - sage.rings.number_field + sage: f = (x^1*y^5*z^2 + x^2*z + x^4*y^1*z^3) # optional - sage.rings.number_field + sage: list(f.iterator_exp_coeff()) # optional - sage.rings.number_field [((4, 1, 3), 1), ((2, 0, 1), 1), ((1, 5, 2), 1)] - sage: R. = PolynomialRing(QQbar, order='deglex') - sage: f = (x^1*y^5*z^2 + x^2*z + x^4*y^1*z^3) - sage: list(f.iterator_exp_coeff(as_ETuples=False)) + sage: R. = PolynomialRing(QQbar, order='deglex') # optional - sage.rings.number_field + sage: f = (x^1*y^5*z^2 + x^2*z + x^4*y^1*z^3) # optional - sage.rings.number_field + sage: list(f.iterator_exp_coeff(as_ETuples=False)) # optional - sage.rings.number_field [((4, 1, 3), 1), ((1, 5, 2), 1), ((2, 0, 1), 1)] """ elt = self.element() @@ -950,7 +944,7 @@ def coefficient(self, degrees): - a monomial (very fast, but not as flexible) - OUTPUT: element of the parent of self + OUTPUT: element of the parent of ``self`` .. SEEALSO:: @@ -959,38 +953,38 @@ def coefficient(self, degrees): EXAMPLES:: - sage: R. = QQbar[] - sage: f = 2 * x * y - sage: c = f.coefficient({x:1,y:1}); c + sage: R. = QQbar[] # optional - sage.rings.number_field + sage: f = 2 * x * y # optional - sage.rings.number_field + sage: c = f.coefficient({x: 1, y: 1}); c # optional - sage.rings.number_field 2 - sage: c.parent() + sage: c.parent() # optional - sage.rings.number_field Multivariate Polynomial Ring in x, y over Algebraic Field - sage: c in PolynomialRing(QQbar, 2, names = ['x','y']) + sage: c in PolynomialRing(QQbar, 2, names=['x', 'y']) # optional - sage.rings.number_field True - sage: f = y^2 - x^9 - 7*x + 5*x*y - sage: f.coefficient({y:1}) + sage: f = y^2 - x^9 - 7*x + 5*x*y # optional - sage.rings.number_field + sage: f.coefficient({y: 1}) # optional - sage.rings.number_field 5*x - sage: f.coefficient({y:0}) + sage: f.coefficient({y: 0}) # optional - sage.rings.number_field -x^9 + (-7)*x - sage: f.coefficient({x:0,y:0}) + sage: f.coefficient({x: 0, y: 0}) # optional - sage.rings.number_field 0 - sage: f=(1+y+y^2)*(1+x+x^2) - sage: f.coefficient({x:0}) + sage: f = (1+y+y^2) * (1+x+x^2) # optional - sage.rings.number_field + sage: f.coefficient({x: 0}) # optional - sage.rings.number_field y^2 + y + 1 - sage: f.coefficient([0,None]) + sage: f.coefficient([0, None]) # optional - sage.rings.number_field y^2 + y + 1 - sage: f.coefficient(x) + sage: f.coefficient(x) # optional - sage.rings.number_field y^2 + y + 1 sage: # Be aware that this may not be what you think! sage: # The physical appearance of the variable x is deceiving -- particularly if the exponent would be a variable. - sage: f.coefficient(x^0) # outputs the full polynomial + sage: f.coefficient(x^0) # outputs the full polynomial # optional - sage.rings.number_field x^2*y^2 + x^2*y + x*y^2 + x^2 + x*y + y^2 + x + y + 1 :: sage: R. = RR[] - sage: f=x*y+5 - sage: c=f.coefficient({x:0,y:0}); c + sage: f = x*y + 5 + sage: c = f.coefficient({x: 0, y: 0}); c 5.00000000000000 sage: parent(c) Multivariate Polynomial Ring in x, y over Real Field with 53 bits of precision @@ -1025,36 +1019,34 @@ def global_height(self, prec=None): INPUT: - ``prec`` -- desired floating point precision (default: - default RealField precision). - - OUTPUT: + default :class:`RealField` precision). - - a real number. + OUTPUT: a real number. EXAMPLES:: - sage: R. = PolynomialRing(QQbar, 2) - sage: f = QQbar(i)*x^2 + 3*x*y - sage: f.global_height() + sage: R. = PolynomialRing(QQbar, 2) # optional - sage.rings.number_field + sage: f = QQbar(i)*x^2 + 3*x*y # optional - sage.rings.number_field + sage: f.global_height() # optional - sage.rings.number_field 1.09861228866811 Scaling should not change the result:: - sage: R. = PolynomialRing(QQbar, 2) - sage: f = 1/25*x^2 + 25/3*x + 1 + QQbar(sqrt(2))*y^2 - sage: f.global_height() + sage: R. = PolynomialRing(QQbar, 2) # optional - sage.rings.number_field + sage: f = 1/25*x^2 + 25/3*x + 1 + QQbar(sqrt(2))*y^2 # optional - sage.rings.number_field sage.symbolic + sage: f.global_height() # optional - sage.rings.number_field sage.symbolic 6.43775164973640 - sage: g = 100 * f - sage: g.global_height() + sage: g = 100 * f # optional - sage.rings.number_field sage.symbolic + sage: g.global_height() # optional - sage.rings.number_field sage.symbolic 6.43775164973640 :: sage: R. = QQ[] - sage: K. = NumberField(x^2 + 1) - sage: Q. = PolynomialRing(K, implementation='generic') - sage: f = 12*q - sage: f.global_height() + sage: K. = NumberField(x^2 + 1) # optional - sage.rings.number_field + sage: Q. = PolynomialRing(K, implementation='generic') # optional - sage.rings.number_field + sage: f = 12 * q # optional - sage.rings.number_field + sage: f.global_height() # optional - sage.rings.number_field 0.000000000000000 :: @@ -1107,9 +1099,7 @@ def local_height(self, v, prec=None): - ``prec`` -- desired floating point precision (default: default RealField precision). - OUTPUT: - - - a real number. + OUTPUT: a real number. EXAMPLES:: @@ -1121,11 +1111,11 @@ def local_height(self, v, prec=None): :: sage: R. = QQ[] - sage: K. = NumberField(x^2 - 5) - sage: T. = PolynomialRing(K, implementation='generic') - sage: I = K.ideal(3) - sage: f = 1/3*t*w + 3 - sage: f.local_height(I) + sage: K. = NumberField(x^2 - 5) # optional - sage.rings.number_field + sage: T. = PolynomialRing(K, implementation='generic') # optional - sage.rings.number_field + sage: I = K.ideal(3) # optional - sage.rings.number_field + sage: f = 1/3*t*w + 3 # optional - sage.rings.number_field + sage: f.local_height(I) # optional - sage.rings.number_field sage.symbolic 1.09861228866811 :: @@ -1157,11 +1147,9 @@ def local_height_arch(self, i, prec=None): - ``i`` -- an integer. - ``prec`` -- desired floating point precision (default: - default RealField precision). + default :class:`RealField` precision). - OUTPUT: - - - a real number. + OUTPUT: a real number. EXAMPLES:: @@ -1173,10 +1161,10 @@ def local_height_arch(self, i, prec=None): :: sage: R. = QQ[] - sage: K. = NumberField(x^2 - 5) - sage: T. = PolynomialRing(K, implementation='generic') - sage: f = 1/2*t*w + 3 - sage: f.local_height_arch(1, prec=52) + sage: K. = NumberField(x^2 - 5) # optional - sage.rings.number_field + sage: T. = PolynomialRing(K, implementation='generic') # optional - sage.rings.number_field + sage: f = 1/2*t*w + 3 # optional - sage.rings.number_field + sage: f.local_height_arch(1, prec=52) # optional - sage.rings.number_field 1.09861228866811 :: @@ -1208,9 +1196,9 @@ def _exponents(self): EXAMPLES:: - sage: R. = PolynomialRing(QQbar, 3) - sage: f = a^3 + b + 2*b^2 - sage: f._exponents + sage: R. = PolynomialRing(QQbar, 3) # optional - sage.rings.number_field + sage: f = a^3 + b + 2*b^2 # optional - sage.rings.number_field + sage: f._exponents # optional - sage.rings.number_field [(3, 0, 0), (0, 2, 0), (0, 1, 0)] """ return sorted(self.element().dict(), key=self.parent().term_order().sortkey, reverse=True) @@ -1230,29 +1218,29 @@ def exponents(self, as_ETuples=True): EXAMPLES:: - sage: R. = PolynomialRing(QQbar, 3) - sage: f = a^3 + b + 2*b^2 - sage: f.exponents() + sage: R. = PolynomialRing(QQbar, 3) # optional - sage.rings.number_field + sage: f = a^3 + b + 2*b^2 # optional - sage.rings.number_field + sage: f.exponents() # optional - sage.rings.number_field [(3, 0, 0), (0, 2, 0), (0, 1, 0)] By default the list of exponents is a list of ETuples:: - sage: type(f.exponents()[0]) + sage: type(f.exponents()[0]) # optional - sage.rings.number_field - sage: type(f.exponents(as_ETuples=False)[0]) + sage: type(f.exponents(as_ETuples=False)[0]) # optional - sage.rings.number_field <... 'tuple'> TESTS: Check that we can mutate the list and not change the result:: - sage: R. = PolynomialRing(QQbar, 3) - sage: f = a^3 + b + 2*b^2 - sage: E = f.exponents(); E + sage: R. = PolynomialRing(QQbar, 3) # optional - sage.rings.number_field + sage: f = a^3 + b + 2*b^2 # optional - sage.rings.number_field + sage: E = f.exponents(); E # optional - sage.rings.number_field [(3, 0, 0), (0, 2, 0), (0, 1, 0)] - sage: E.pop() + sage: E.pop() # optional - sage.rings.number_field (0, 1, 0) - sage: E != f.exponents() + sage: E != f.exponents() # optional - sage.rings.number_field True """ if as_ETuples: @@ -1280,22 +1268,22 @@ def inverse_of_unit(self): def is_homogeneous(self): """ - Return True if self is a homogeneous polynomial. + Return ``True`` if ``self`` is a homogeneous polynomial. EXAMPLES:: - sage: R. = QQbar[] - sage: (x+y).is_homogeneous() + sage: R. = QQbar[] # optional - sage.rings.number_field + sage: (x + y).is_homogeneous() # optional - sage.rings.number_field True - sage: (x.parent()(0)).is_homogeneous() + sage: (x.parent()(0)).is_homogeneous() # optional - sage.rings.number_field True - sage: (x+y^2).is_homogeneous() + sage: (x + y^2).is_homogeneous() # optional - sage.rings.number_field False - sage: (x^2 + y^2).is_homogeneous() + sage: (x^2 + y^2).is_homogeneous() # optional - sage.rings.number_field True - sage: (x^2 + y^2*x).is_homogeneous() + sage: (x^2 + y^2*x).is_homogeneous() # optional - sage.rings.number_field False - sage: (x^2*y + y^2*x).is_homogeneous() + sage: (x^2*y + y^2*x).is_homogeneous() # optional - sage.rings.number_field True """ return self.element().is_homogeneous() @@ -1317,11 +1305,11 @@ def _homogenize(self, var): EXAMPLES:: - sage: P. = QQbar[] - sage: f = x^2 + y + 1 + 5*x*y^1 - sage: g = f.homogenize('z'); g # indirect doctest + sage: P. = QQbar[] # optional - sage.rings.number_field + sage: f = x^2 + y + 1 + 5*x*y^1 # optional - sage.rings.number_field + sage: g = f.homogenize('z'); g # indirect doctest # optional - sage.rings.number_field x^2 + 5*x*y + y*z + z^2 - sage: g.parent() + sage: g.parent() # optional - sage.rings.number_field Multivariate Polynomial Ring in x, y, z over Algebraic Field SEE: ``self.homogenize`` @@ -1339,12 +1327,12 @@ def is_generator(self): EXAMPLES:: - sage: R.=QQbar[] - sage: x.is_generator() + sage: R. = QQbar[] # optional - sage.rings.number_field + sage: x.is_generator() # optional - sage.rings.number_field True - sage: (x+y-y).is_generator() + sage: (x + y - y).is_generator() # optional - sage.rings.number_field True - sage: (x*y).is_generator() + sage: (x*y).is_generator() # optional - sage.rings.number_field False """ elt = self.element() @@ -1362,21 +1350,21 @@ def is_monomial(self): EXAMPLES:: - sage: R.=QQbar[] - sage: x.is_monomial() + sage: R. = QQbar[] # optional - sage.rings.number_field + sage: x.is_monomial() # optional - sage.rings.number_field True - sage: (x+2*y).is_monomial() + sage: (x + 2*y).is_monomial() # optional - sage.rings.number_field False - sage: (2*x).is_monomial() + sage: (2*x).is_monomial() # optional - sage.rings.number_field False - sage: (x*y).is_monomial() + sage: (x*y).is_monomial() # optional - sage.rings.number_field True - To allow a non-1 leading coefficient, use is_term():: + To allow a non-1 leading coefficient, use :meth:`is_term`:: - sage: (2*x*y).is_term() + sage: (2*x*y).is_term() # optional - sage.rings.number_field True - sage: (2*x*y).is_monomial() + sage: (2*x*y).is_monomial() # optional - sage.rings.number_field False """ return len(self.element()) == 1 and self.element().coefficients()[0] == 1 @@ -1391,31 +1379,31 @@ def is_term(self): EXAMPLES:: - sage: R.=QQbar[] - sage: x.is_term() + sage: R. = QQbar[] # optional - sage.rings.number_field + sage: x.is_term() # optional - sage.rings.number_field True - sage: (x+2*y).is_term() + sage: (x + 2*y).is_term() # optional - sage.rings.number_field False - sage: (2*x).is_term() + sage: (2*x).is_term() # optional - sage.rings.number_field True - sage: (7*x^5*y).is_term() + sage: (7*x^5*y).is_term() # optional - sage.rings.number_field True - To require leading coefficient 1, use is_monomial():: + To require leading coefficient 1, use :meth:`is_monomial`:: - sage: (2*x*y).is_monomial() + sage: (2*x*y).is_monomial() # optional - sage.rings.number_field False - sage: (2*x*y).is_term() + sage: (2*x*y).is_term() # optional - sage.rings.number_field True """ return len(self.element()) == 1 def subs(self, fixed=None, **kw): """ - Fixes some given variables in a given multivariate polynomial and - returns the changed multivariate polynomials. The polynomial itself - is not affected. The variable,value pairs for fixing are to be - provided as a dictionary of the form {variable:value}. + Fix some given variables in a given multivariate polynomial and + return the changed multivariate polynomials. The polynomial itself + is not affected. The variable, value pairs for fixing are to be + provided as a dictionary of the form ``{variable: value}``. This is a special case of evaluating the polynomial with some of the variables constants and the others the original variables. @@ -1428,15 +1416,15 @@ def subs(self, fixed=None, **kw): - ``**kw`` - named parameters - OUTPUT: new MPolynomial + OUTPUT: new :class:`MPolynomial` EXAMPLES:: - sage: R. = QQbar[] - sage: f = x^2 + y + x^2*y^2 + 5 - sage: f((5,y)) + sage: R. = QQbar[] # optional - sage.rings.number_field + sage: f = x^2 + y + x^2*y^2 + 5 # optional - sage.rings.number_field + sage: f((5, y)) # optional - sage.rings.number_field 25*y^2 + y + 30 - sage: f.subs({x:5}) + sage: f.subs({x: 5}) # optional - sage.rings.number_field 25*y^2 + y + 30 """ variables = list(self.parent().gens()) @@ -1449,29 +1437,28 @@ def subs(self, fixed=None, **kw): def monomials(self): """ - Returns the list of monomials in self. The returned list is - decreasingly ordered by the term ordering of self.parent(). + Return the list of monomials in ``self``. The returned list is + decreasingly ordered by the term ordering of ``self.parent()``. - OUTPUT: list of MPolynomials representing Monomials + OUTPUT: list of :class:`MPolynomial` instances, representing monomials EXAMPLES:: - sage: R. = QQbar[] - sage: f = 3*x^2 - 2*y + 7*x^2*y^2 + 5 - sage: f.monomials() + sage: R. = QQbar[] # optional - sage.rings.number_field + sage: f = 3*x^2 - 2*y + 7*x^2*y^2 + 5 # optional - sage.rings.number_field + sage: f.monomials() # optional - sage.rings.number_field [x^2*y^2, x^2, y, 1] :: - sage: R. = QQbar[] - sage: F = ((fx*gy - fy*gx)^3) - sage: F + sage: R. = QQbar[] # optional - sage.rings.number_field + sage: F = (fx*gy - fy*gx)^3; F # optional - sage.rings.number_field -fy^3*gx^3 + 3*fx*fy^2*gx^2*gy + (-3)*fx^2*fy*gx*gy^2 + fx^3*gy^3 - sage: F.monomials() + sage: F.monomials() # optional - sage.rings.number_field [fy^3*gx^3, fx*fy^2*gx^2*gy, fx^2*fy*gx*gy^2, fx^3*gy^3] - sage: F.coefficients() + sage: F.coefficients() # optional - sage.rings.number_field [-1, 3, -3, 1] - sage: sum(map(mul,zip(F.coefficients(),F.monomials()))) == F + sage: sum(map(mul, zip(F.coefficients(), F.monomials()))) == F # optional - sage.rings.number_field True """ ring = self.parent() @@ -1485,12 +1472,12 @@ def constant_coefficient(self): EXAMPLES:: - sage: R. = QQbar[] - sage: f = 3*x^2 - 2*y + 7*x^2*y^2 + 5 - sage: f.constant_coefficient() + sage: R. = QQbar[] # optional - sage.rings.number_field + sage: f = 3*x^2 - 2*y + 7*x^2*y^2 + 5 # optional - sage.rings.number_field + sage: f.constant_coefficient() # optional - sage.rings.number_field 5 - sage: f = 3*x^2 - sage: f.constant_coefficient() + sage: f = 3*x^2 # optional - sage.rings.number_field + sage: f.constant_coefficient() # optional - sage.rings.number_field 0 """ #v = (0,)*int(self.parent().ngens()) @@ -1502,21 +1489,21 @@ def constant_coefficient(self): def is_univariate(self): """ - Returns True if this multivariate polynomial is univariate and + Return ``True`` if this multivariate polynomial is univariate and False otherwise. EXAMPLES:: - sage: R. = QQbar[] - sage: f = 3*x^2 - 2*y + 7*x^2*y^2 + 5 - sage: f.is_univariate() + sage: R. = QQbar[] # optional - sage.rings.number_field + sage: f = 3*x^2 - 2*y + 7*x^2*y^2 + 5 # optional - sage.rings.number_field + sage: f.is_univariate() # optional - sage.rings.number_field False - sage: g = f.subs({x:10}); g + sage: g = f.subs({x: 10}); g # optional - sage.rings.number_field 700*y^2 + (-2)*y + 305 - sage: g.is_univariate() + sage: g.is_univariate() # optional - sage.rings.number_field True - sage: f = x^0 - sage: f.is_univariate() + sage: f = x^0 # optional - sage.rings.number_field + sage: f.is_univariate() # optional - sage.rings.number_field True """ mons = self.element().dict() @@ -1539,27 +1526,27 @@ def univariate_polynomial(self, R=None): INPUT: - - ``R`` - (default: None) PolynomialRing + - ``R`` - (default: None) :class:`PolynomialRing` If this polynomial is not in at most one variable, then a - ValueError exception is raised. This is checked using the - is_univariate() method. The new Polynomial is over the same base - ring as the given MPolynomial. + :class:`ValueError` exception is raised. This is checked using the + method :meth:`is_univariate`. The new :class:`Polynomial` is over the same base + ring as the given :class:`MPolynomial`. EXAMPLES:: - sage: R. = QQbar[] - sage: f = 3*x^2 - 2*y + 7*x^2*y^2 + 5 - sage: f.univariate_polynomial() + sage: R. = QQbar[] # optional - sage.rings.number_field + sage: f = 3*x^2 - 2*y + 7*x^2*y^2 + 5 # optional - sage.rings.number_field + sage: f.univariate_polynomial() # optional - sage.rings.number_field Traceback (most recent call last): ... TypeError: polynomial must involve at most one variable - sage: g = f.subs({x:10}); g + sage: g = f.subs({x: 10}); g # optional - sage.rings.number_field 700*y^2 + (-2)*y + 305 - sage: g.univariate_polynomial () + sage: g.univariate_polynomial() # optional - sage.rings.number_field 700*y^2 - 2*y + 305 - sage: g.univariate_polynomial(PolynomialRing(QQ,'z')) + sage: g.univariate_polynomial(PolynomialRing(QQ, 'z')) # optional - sage.rings.number_field 700*z^2 - 2*z + 305 TESTS:: @@ -1614,13 +1601,13 @@ def variables(self): EXAMPLES:: - sage: R. = QQbar[] - sage: f = 3*x^2 - 2*y + 7*x^2*y^2 + 5 - sage: f.variables() + sage: R. = QQbar[] # optional - sage.rings.number_field + sage: f = 3*x^2 - 2*y + 7*x^2*y^2 + 5 # optional - sage.rings.number_field + sage: f.variables() # optional - sage.rings.number_field (x, y) - sage: g = f.subs({x:10}); g + sage: g = f.subs({x: 10}); g # optional - sage.rings.number_field 700*y^2 + (-2)*y + 305 - sage: g.variables() + sage: g.variables() # optional - sage.rings.number_field (y,) TESTS: @@ -1635,32 +1622,32 @@ def variables(self): def variable(self,i): """ - Returns `i`-th variable occurring in this polynomial. + Return the `i`-th variable occurring in this polynomial. EXAMPLES:: - sage: R. = QQbar[] - sage: f = 3*x^2 - 2*y + 7*x^2*y^2 + 5 - sage: f.variable(0) + sage: R. = QQbar[] # optional - sage.rings.number_field + sage: f = 3*x^2 - 2*y + 7*x^2*y^2 + 5 # optional - sage.rings.number_field + sage: f.variable(0) # optional - sage.rings.number_field x - sage: f.variable(1) + sage: f.variable(1) # optional - sage.rings.number_field y """ return self.variables()[int(i)] def nvariables(self): """ - Number of variables in this polynomial + Return the number of variables in this polynomial. EXAMPLES:: - sage: R. = QQbar[] - sage: f = 3*x^2 - 2*y + 7*x^2*y^2 + 5 - sage: f.nvariables () + sage: R. = QQbar[] # optional - sage.rings.number_field + sage: f = 3*x^2 - 2*y + 7*x^2*y^2 + 5 # optional - sage.rings.number_field + sage: f.nvariables() # optional - sage.rings.number_field 2 - sage: g = f.subs({x:10}); g + sage: g = f.subs({x: 10}); g # optional - sage.rings.number_field 700*y^2 + (-2)*y + 305 - sage: g.nvariables () + sage: g.nvariables() # optional - sage.rings.number_field 1 """ return len(self.degrees().nonzero_positions()) @@ -1671,32 +1658,32 @@ def is_constant(self): EXAMPLES:: - sage: R. = QQbar[] - sage: f = 3*x^2 - 2*y + 7*x^2*y^2 + 5 - sage: f.is_constant() + sage: R. = QQbar[] # optional - sage.rings.number_field + sage: f = 3*x^2 - 2*y + 7*x^2*y^2 + 5 # optional - sage.rings.number_field + sage: f.is_constant() # optional - sage.rings.number_field False - sage: g = 10*x^0 - sage: g.is_constant() + sage: g = 10*x^0 # optional - sage.rings.number_field + sage: g.is_constant() # optional - sage.rings.number_field True """ return self.element().is_constant() def lm(self): """ - Returns the lead monomial of self with respect to the term order of - self.parent(). + Return the lead monomial of ``self`` with respect to the term order of + ``self.parent()``. EXAMPLES:: - sage: R.=PolynomialRing(GF(7),3,order='lex') - sage: (x^1*y^2 + y^3*z^4).lm() + sage: R. = PolynomialRing(GF(7), 3, order='lex') # optional - sage.rings.finite_rings + sage: (x^1*y^2 + y^3*z^4).lm() # optional - sage.rings.finite_rings x*y^2 - sage: (x^3*y^2*z^4 + x^3*y^2*z^1).lm() + sage: (x^3*y^2*z^4 + x^3*y^2*z^1).lm() # optional - sage.rings.finite_rings x^3*y^2*z^4 :: - sage: R.=PolynomialRing(CC,3,order='deglex') + sage: R. = PolynomialRing(CC, 3, order='deglex') sage: (x^1*y^2*z^3 + x^3*y^2*z^0).lm() x*y^2*z^3 sage: (x^1*y^2*z^4 + x^1*y^1*z^5).lm() @@ -1704,18 +1691,18 @@ def lm(self): :: - sage: R.=PolynomialRing(QQbar,3,order='degrevlex') - sage: (x^1*y^5*z^2 + x^4*y^1*z^3).lm() + sage: R. = PolynomialRing(QQbar, 3, order='degrevlex') # optional - sage.rings.number_field + sage: (x^1*y^5*z^2 + x^4*y^1*z^3).lm() # optional - sage.rings.number_field x*y^5*z^2 - sage: (x^4*y^7*z^1 + x^4*y^2*z^3).lm() + sage: (x^4*y^7*z^1 + x^4*y^2*z^3).lm() # optional - sage.rings.number_field x^4*y^7*z TESTS:: sage: from sage.rings.polynomial.multi_polynomial_ring import MPolynomialRing_polydict - sage: R.=MPolynomialRing_polydict(GF(2),2,order='lex') - sage: f=x+y - sage: f.lm() + sage: R. = MPolynomialRing_polydict(GF(2), 2, order='lex') # optional - sage.rings.finite_rings + sage: f = x + y # optional - sage.rings.finite_rings + sage: f.lm() # optional - sage.rings.finite_rings x """ @@ -1732,14 +1719,14 @@ def lm(self): def lc(self): """ - Returns the leading coefficient of self i.e., - self.coefficient(self.lm()) + Returns the leading coefficient of ``self``, i.e., + ``self.coefficient(self.lm())`` EXAMPLES:: - sage: R.=QQbar[] - sage: f=3*x^2-y^2-x*y - sage: f.lc() + sage: R. = QQbar[] # optional - sage.rings.number_field + sage: f = 3*x^2 - y^2 - x*y # optional - sage.rings.number_field + sage: f.lc() # optional - sage.rings.number_field 3 """ try: @@ -1754,27 +1741,27 @@ def lc(self): def lt(self): r""" - Returns the leading term of self i.e., self.lc()\*self.lm(). The + Return the leading term of ``self`` i.e., ``self.lc()*self.lm()``. The notion of "leading term" depends on the ordering defined in the parent ring. EXAMPLES:: - sage: R.=PolynomialRing(QQbar) - sage: f=3*x^2-y^2-x*y - sage: f.lt() + sage: R. = PolynomialRing(QQbar) # optional - sage.rings.number_field + sage: f = 3*x^2 - y^2 - x*y # optional - sage.rings.number_field + sage: f.lt() # optional - sage.rings.number_field 3*x^2 - sage: R.=PolynomialRing(QQbar,order="invlex") - sage: f=3*x^2-y^2-x*y - sage: f.lt() + sage: R. = PolynomialRing(QQbar, order="invlex") # optional - sage.rings.number_field + sage: f = 3*x^2 - y^2 - x*y # optional - sage.rings.number_field + sage: f.lt() # optional - sage.rings.number_field -y^2 TESTS:: sage: from sage.rings.polynomial.multi_polynomial_ring import MPolynomialRing_polydict - sage: R.=MPolynomialRing_polydict(GF(2),2,order='lex') - sage: f=x+y - sage: f.lt() + sage: R. = MPolynomialRing_polydict(GF(2), 2, order='lex') # optional - sage.rings.finite_rings + sage: f = x + y # optional - sage.rings.finite_rings + sage: f.lt() # optional - sage.rings.finite_rings x """ try: @@ -1809,7 +1796,7 @@ def __ne__(self, right): def __bool__(self): """ - Return True if self != 0 + Return ``True`` if self != 0 .. note:: @@ -1819,7 +1806,7 @@ def __bool__(self): def _floordiv_(self, right): r""" - Quotient of division of self by other. This is denoted //. + Quotient of division of ``self`` by other. This is denoted //. .. note:: @@ -1828,14 +1815,14 @@ def _floordiv_(self, right): EXAMPLES:: - sage: R.=QQbar[] - sage: 2*x*y//y + sage: R. = QQbar[] # optional - sage.rings.number_field + sage: 2*x*y//y # optional - sage.rings.number_field 2*x - sage: 2*x//y + sage: 2*x//y # optional - sage.rings.number_field 0 - sage: 2*x//4 + sage: 2*x//4 # optional - sage.rings.number_field 1/2*x - sage: type(0//y) + sage: type(0//y) # optional - sage.rings.number_field """ # handle division by monomials without using Singular @@ -1856,7 +1843,7 @@ def _derivative(self, var=None): r""" Differentiates ``self`` with respect to variable ``var``. - If ``var`` is not one of the generators of this ring, _derivative(var) + If ``var`` is not one of the generators of this ring, ``_derivative(var)`` is called recursively on each coefficient of this polynomial. .. SEEALSO:: @@ -1865,24 +1852,26 @@ def _derivative(self, var=None): EXAMPLES:: - sage: R. = PowerSeriesRing(QQbar) - sage: S. = PolynomialRing(R) - sage: f = (t^2 + O(t^3))*x^2*y^3 + (37*t^4 + O(t^5))*x^3 - sage: f.parent() - Multivariate Polynomial Ring in x, y over Power Series Ring in t over Algebraic Field - sage: f._derivative(x) # with respect to x + sage: R. = PowerSeriesRing(QQbar) # optional - sage.rings.number_field + sage: S. = PolynomialRing(R) # optional - sage.rings.number_field + sage: f = (t^2 + O(t^3))*x^2*y^3 + (37*t^4 + O(t^5))*x^3 # optional - sage.rings.number_field + sage: f.parent() # optional - sage.rings.number_field + Multivariate Polynomial Ring in x, y + over Power Series Ring in t over Algebraic Field + sage: f._derivative(x) # with respect to x # optional - sage.rings.number_field (2*t^2 + O(t^3))*x*y^3 + (111*t^4 + O(t^5))*x^2 - sage: f._derivative(x).parent() - Multivariate Polynomial Ring in x, y over Power Series Ring in t over Algebraic Field - sage: f._derivative(y) # with respect to y + sage: f._derivative(x).parent() # optional - sage.rings.number_field + Multivariate Polynomial Ring in x, y + over Power Series Ring in t over Algebraic Field + sage: f._derivative(y) # with respect to y # optional - sage.rings.number_field (3*t^2 + O(t^3))*x^2*y^2 - sage: f._derivative(t) # with respect to t (recurses into base ring) + sage: f._derivative(t) # with respect to t (recurses into base ring) # optional - sage.rings.number_field (2*t + O(t^2))*x^2*y^3 + (148*t^3 + O(t^4))*x^3 - sage: f._derivative(x)._derivative(y) # with respect to x and then y + sage: f._derivative(x)._derivative(y) # with respect to x and then y # optional - sage.rings.number_field (6*t^2 + O(t^3))*x*y^2 - sage: f.derivative(y, 3) # with respect to y three times + sage: f.derivative(y, 3) # with respect to y three times # optional - sage.rings.number_field (6*t^2 + O(t^3))*x^2 - sage: f._derivative() # can't figure out the variable + sage: f._derivative() # can't figure out the variable # optional - sage.rings.number_field Traceback (most recent call last): ... ValueError: must specify which variable to differentiate with respect to @@ -1915,7 +1904,7 @@ def integral(self, var=None): The integral is always chosen so the constant term is 0. - If ``var`` is not one of the generators of this ring, integral(var) + If ``var`` is not one of the generators of this ring, ``integral(var)`` is called recursively on each coefficient of this polynomial. EXAMPLES: @@ -1932,28 +1921,31 @@ def integral(self, var=None): sage: R = ZZ['x']['y, z'] sage: y, z = R.gens() sage: R.an_element().integral(y).parent() - Multivariate Polynomial Ring in y, z over Univariate Polynomial Ring in x over Rational Field + Multivariate Polynomial Ring in y, z + over Univariate Polynomial Ring in x over Rational Field On polynomials with coefficients in power series:: - sage: R. = PowerSeriesRing(QQbar) - sage: S. = PolynomialRing(R) - sage: f = (t^2 + O(t^3))*x^2*y^3 + (37*t^4 + O(t^5))*x^3 - sage: f.parent() - Multivariate Polynomial Ring in x, y over Power Series Ring in t over Algebraic Field - sage: f.integral(x) # with respect to x + sage: R. = PowerSeriesRing(QQbar) # optional - sage.rings.number_field + sage: S. = PolynomialRing(R) # optional - sage.rings.number_field + sage: f = (t^2 + O(t^3))*x^2*y^3 + (37*t^4 + O(t^5))*x^3 # optional - sage.rings.number_field + sage: f.parent() # optional - sage.rings.number_field + Multivariate Polynomial Ring in x, y + over Power Series Ring in t over Algebraic Field + sage: f.integral(x) # with respect to x # optional - sage.rings.number_field (1/3*t^2 + O(t^3))*x^3*y^3 + (37/4*t^4 + O(t^5))*x^4 - sage: f.integral(x).parent() - Multivariate Polynomial Ring in x, y over Power Series Ring in t over Algebraic Field + sage: f.integral(x).parent() # optional - sage.rings.number_field + Multivariate Polynomial Ring in x, y + over Power Series Ring in t over Algebraic Field - sage: f.integral(y) # with respect to y + sage: f.integral(y) # with respect to y # optional - sage.rings.number_field (1/4*t^2 + O(t^3))*x^2*y^4 + (37*t^4 + O(t^5))*x^3*y - sage: f.integral(t) # with respect to t (recurses into base ring) + sage: f.integral(t) # with respect to t (recurses into base ring) # optional - sage.rings.number_field (1/3*t^3 + O(t^4))*x^2*y^3 + (37/5*t^5 + O(t^6))*x^3 TESTS:: - sage: f.integral() # can't figure out the variable + sage: f.integral() # can't figure out the variable # optional - sage.rings.number_field Traceback (most recent call last): ... ValueError: must specify which variable to integrate with respect to @@ -2005,7 +1997,7 @@ def factor(self, proof=None): INPUT: - - ``proof'' - insist on provably correct results (default: ``True`` + - ``proof`` - insist on provably correct results (default: ``True`` unless explicitly disabled for the ``"polynomial"`` subsystem with :class:`sage.structure.proof.proof.WithProof`.) @@ -2044,8 +2036,8 @@ def factor(self, proof=None): Check that we can factor over the algebraic field (:trac:`25390`):: - sage: R. = PolynomialRing(QQbar) - sage: factor(x^2 + y^2) + sage: R. = PolynomialRing(QQbar) # optional - sage.rings.number_field + sage: factor(x^2 + y^2) # optional - sage.rings.number_field (x + (-1*I)*y) * (x + 1*I*y) Check that the global proof flag for polynomials is honored:: @@ -2095,12 +2087,12 @@ def factor(self, proof=None): We check a case that failed with an exception at some point:: - sage: k. = GF(4) - sage: R. = k[] - sage: l. = R.quo(v^3 + v + 1) - sage: R. = l[] - sage: f = y^3 + x^3 + (u + 1)*x - sage: f.factor() + sage: k. = GF(4) # optional - sage.rings.finite_rings + sage: R. = k[] # optional - sage.rings.finite_rings + sage: l. = R.quo(v^3 + v + 1) # optional - sage.rings.finite_rings + sage: R. = l[] # optional - sage.rings.finite_rings + sage: f = y^3 + x^3 + (u + 1)*x # optional - sage.rings.finite_rings + sage: f.factor() # optional - sage.rings.finite_rings x^3 + y^3 + (u + 1)*x """ @@ -2159,15 +2151,15 @@ def factor(self, proof=None): @handle_AA_and_QQbar def lift(self,I): """ - given an ideal I = (f_1,...,f_r) and some g (== self) in I, find - s_1,...,s_r such that g = s_1 f_1 + ... + s_r f_r + Given an ideal `I = (f_1,...,f_r)` and some `g` (= ``self``) in `I`, find + `s_1,...,s_r` such that `g = s_1 f_1 + ... + s_r f_r`. ALGORITHM: Use Singular. EXAMPLES:: - sage: A. = PolynomialRing(CC,2,order='degrevlex') - sage: I = A.ideal([x^10 + x^9*y^2, y^8 - x^2*y^7 ]) + sage: A. = PolynomialRing(CC, 2, order='degrevlex') + sage: I = A.ideal([x^10 + x^9*y^2, y^8 - x^2*y^7]) sage: f = x*y^13 + y^12 sage: M = f.lift(I) sage: M @@ -2177,13 +2169,13 @@ def lift(self,I): TESTS: - Check that this method works over QQbar (:trac:`25351`):: + Check that this method works over ``QQbar`` (:trac:`25351`):: - sage: A. = QQbar[] - sage: I = A.ideal([x^2 + y^2 - 1, x^2 - y^2]) - sage: f = 2*x^2 - 1 - sage: M = f.lift(I) - sage: sum( map( mul , zip( M, I.gens() ) ) ) == f + sage: A. = QQbar[] # optional - sage.rings.number_field + sage: I = A.ideal([x^2 + y^2 - 1, x^2 - y^2]) # optional - sage.rings.number_field + sage: f = 2*x^2 - 1 # optional - sage.rings.number_field + sage: M = f.lift(I) # optional - sage.rings.number_field + sage: sum(map(mul, zip(M, I.gens()))) == f # optional - sage.rings.number_field True """ fs = self._singular_() @@ -2199,7 +2191,7 @@ def lift(self,I): @handle_AA_and_QQbar def quo_rem(self, right): """ - Returns quotient and remainder of self and right. + Returns quotient and remainder of ``self`` and ``right``. EXAMPLES:: @@ -2224,11 +2216,11 @@ def quo_rem(self, right): TESTS: - Check that this method works over QQbar (:trac:`25351`):: + Check that this method works over ``QQbar`` (:trac:`25351`):: - sage: R. = QQbar[] - sage: f = y*x^2 + x + 1 - sage: f.quo_rem(x) + sage: R. = QQbar[] # optional - sage.rings.number_field + sage: f = y*x^2 + x + 1 # optional - sage.rings.number_field + sage: f.quo_rem(x) # optional - sage.rings.number_field (x*y + 1, 1) """ R = self.parent() @@ -2270,9 +2262,9 @@ def resultant(self, other, variable=None): sage: P. = PolynomialRing(QQ, 2) sage: a = x + y sage: b = x^3 - y^3 - sage: a.resultant(b) + sage: a.resultant(b) # optional - sage.libs.singular -2*y^3 - sage: a.resultant(b, y) + sage: a.resultant(b, y) # optional - sage.libs.singular 2*x^3 TESTS:: @@ -2281,15 +2273,15 @@ def resultant(self, other, variable=None): sage: P. = MPolynomialRing_polydict_domain(QQ, 2, order='degrevlex') sage: a = x + y sage: b = x^3 - y^3 - sage: a.resultant(b) + sage: a.resultant(b) # optional - sage.libs.singular -2*y^3 - sage: a.resultant(b, y) + sage: a.resultant(b, y) # optional - sage.libs.singular 2*x^3 Check that :trac:`15061` is fixed:: - sage: R. = AA[] - sage: (x^2 + 1).resultant(x^2 - y) + sage: R. = AA[] # optional - sage.rings.number_field + sage: (x^2 + 1).resultant(x^2 - y) # optional - sage.rings.number_field y^2 + 2*y + 1 Test for :trac:`2693`:: @@ -2297,17 +2289,17 @@ def resultant(self, other, variable=None): sage: R. = RR[] sage: p = x + y sage: q = x*y - sage: p.resultant(q) + sage: p.resultant(q) # optional - sage.libs.singular -y^2 Check that this method works over QQbar (:trac:`25351`):: - sage: P. = QQbar[] - sage: a = x + y - sage: b = x^3 - y^3 - sage: a.resultant(b) + sage: P. = QQbar[] # optional - sage.rings.number_field + sage: a = x + y # optional - sage.rings.number_field + sage: b = x^3 - y^3 # optional - sage.rings.number_field + sage: a.resultant(b) # optional - sage.rings.number_field (-2)*y^3 - sage: a.resultant(b, y) + sage: a.resultant(b, y) # optional - sage.rings.number_field 2*x^3 """ R = self.parent() @@ -2337,13 +2329,13 @@ def subresultants(self, other, variable=None): EXAMPLES:: - sage: R. = QQbar[] - sage: p = (y^2 + 6)*(x - 1) - y*(x^2 + 1) - sage: q = (x^2 + 6)*(y - 1) - x*(y^2 + 1) - sage: p.subresultants(q, y) + sage: R. = QQbar[] # optional - sage.rings.number_field + sage: p = (y^2 + 6)*(x - 1) - y*(x^2 + 1) # optional - sage.rings.number_field + sage: q = (x^2 + 6)*(y - 1) - x*(y^2 + 1) # optional - sage.rings.number_field + sage: p.subresultants(q, y) # optional - sage.rings.number_field [2*x^6 + (-22)*x^5 + 102*x^4 + (-274)*x^3 + 488*x^2 + (-552)*x + 288, -x^3 - x^2*y + 6*x^2 + 5*x*y + (-11)*x + (-6)*y + 6] - sage: p.subresultants(q, x) + sage: p.subresultants(q, x) # optional - sage.rings.number_field [2*y^6 + (-22)*y^5 + 102*y^4 + (-274)*y^3 + 488*y^2 + (-552)*y + 288, x*y^2 + y^3 + (-5)*x*y + (-6)*y^2 + 6*x + 11*y - 6] @@ -2367,48 +2359,48 @@ def reduce(self, I): EXAMPLES:: - sage: P. = QQbar[] - sage: f1 = -2 * x^2 + x^3 - sage: f2 = -2 * y + x* y - sage: f3 = -x^2 + y^2 - sage: F = Ideal([f1,f2,f3]) - sage: g = x*y - 3*x*y^2 - sage: g.reduce(F) + sage: P. = QQbar[] # optional - sage.rings.number_field + sage: f1 = -2 * x^2 + x^3 # optional - sage.rings.number_field + sage: f2 = -2 * y + x * y # optional - sage.rings.number_field + sage: f3 = -x^2 + y^2 # optional - sage.rings.number_field + sage: F = Ideal([f1, f2, f3]) # optional - sage.rings.number_field + sage: g = x*y - 3*x*y^2 # optional - sage.rings.number_field + sage: g.reduce(F) # optional - sage.rings.number_field (-6)*y^2 + 2*y - sage: g.reduce(F.gens()) + sage: g.reduce(F.gens()) # optional - sage.rings.number_field (-6)*y^2 + 2*y :: - sage: f = 3*x - sage: f.reduce([2*x,y]) + sage: f = 3*x # optional - sage.rings.number_field + sage: f.reduce([2*x, y]) # optional - sage.rings.number_field 0 :: - sage: k. = CyclotomicField(3) - sage: A. = PolynomialRing(k) - sage: J = [ y9 + y12] - sage: f = y9 - y12; f.reduce(J) + sage: k. = CyclotomicField(3) # optional - sage.rings.number_field + sage: A. = PolynomialRing(k) # optional - sage.rings.number_field + sage: J = [y9 + y12] # optional - sage.rings.number_field + sage: f = y9 - y12; f.reduce(J) # optional - sage.rings.number_field -2*y12 - sage: f = y13*y15; f.reduce(J) + sage: f = y13*y15; f.reduce(J) # optional - sage.rings.number_field y13*y15 - sage: f = y13*y15 + y9 - y12; f.reduce(J) + sage: f = y13*y15 + y9 - y12; f.reduce(J) # optional - sage.rings.number_field y13*y15 - 2*y12 Make sure the remainder returns the correct type, fixing :trac:`13903`:: - sage: R.=PolynomialRing(Qp(5),2, order='lex') - sage: G=[y1^2 + y2^2, y1*y2 + y2^2, y2^3] - sage: type((y2^3).reduce(G)) + sage: R. = PolynomialRing(Qp(5), 2, order='lex') # optional - sage.rings.padics + sage: G = [y1^2 + y2^2, y1*y2 + y2^2, y2^3] # optional - sage.rings.padics + sage: type((y2^3).reduce(G)) # optional - sage.rings.padics TESTS: Verify that :trac:`34105` is fixed:: - sage: R. = AA[] - sage: x.reduce(R.zero_ideal()) + sage: R. = AA[] # optional - sage.rings.number_field + sage: x.reduce(R.zero_ideal()) # optional - sage.rings.number_field x """ from sage.rings.polynomial.multi_polynomial_ideal import MPolynomialIdeal @@ -2455,30 +2447,28 @@ def reduce(self, I): def degree_lowest_rational_function(r, x): r""" - Return the difference of valuations of r with respect to variable x. + Return the difference of valuations of ``r`` with respect to variable ``x``. INPUT: - ``r`` -- a multivariate rational function - - ``x`` -- a multivariate polynomial ring generator x - - OUTPUT: + - ``x`` -- a multivariate polynomial ring generator - - ``integer`` -- the difference val_x(p) - val_x(q) where r = p/q + OUTPUT: integer -- the difference `val_x(p) - val_x(q)` where `r = p/q` .. NOTE:: This function should be made a method of the - FractionFieldElement class. + :class:`FractionFieldElement` class. EXAMPLES:: - sage: R1 = PolynomialRing(FiniteField(5), 3, names = ["a","b","c"]) - sage: F = FractionField(R1) - sage: a,b,c = R1.gens() - sage: f = 3*a*b^2*c^3+4*a*b*c - sage: g = a^2*b*c^2+2*a^2*b^4*c^7 + sage: R1 = PolynomialRing(FiniteField(5), 3, names=["a", "b", "c"]) # optional - sage.rings.finite_rings + sage: F = FractionField(R1) # optional - sage.rings.finite_rings + sage: a,b,c = R1.gens() # optional - sage.rings.finite_rings + sage: f = 3*a*b^2*c^3 + 4*a*b*c # optional - sage.rings.finite_rings + sage: g = a^2*b*c^2 + 2*a^2*b^4*c^7 # optional - sage.rings.finite_rings Consider the quotient `f/g = \frac{4 + 3 bc^{2}}{ac + 2 ab^{3}c^{6}}` (note the @@ -2486,13 +2476,13 @@ def degree_lowest_rational_function(r, x): :: - sage: r = f/g; r + sage: r = f/g; r # optional - sage.rings.finite_rings (-2*b*c^2 - 1)/(2*a*b^3*c^6 + a*c) - sage: degree_lowest_rational_function(r,a) + sage: degree_lowest_rational_function(r, a) # optional - sage.rings.finite_rings -1 - sage: degree_lowest_rational_function(r,b) + sage: degree_lowest_rational_function(r, b) # optional - sage.rings.finite_rings 0 - sage: degree_lowest_rational_function(r,c) + sage: degree_lowest_rational_function(r, c) # optional - sage.rings.finite_rings -1 """ from sage.rings.fraction_field import FractionField diff --git a/src/sage/rings/polynomial/multi_polynomial_ideal.py b/src/sage/rings/polynomial/multi_polynomial_ideal.py index 49d603599e3..47f14f96229 100644 --- a/src/sage/rings/polynomial/multi_polynomial_ideal.py +++ b/src/sage/rings/polynomial/multi_polynomial_ideal.py @@ -1,3 +1,4 @@ +# sage.doctest: optional - sage.libs.singular r""" Ideals in multivariate polynomial rings @@ -11,7 +12,7 @@ EXAMPLES: We compute a Groebner basis for some given ideal. The type returned by -the ``groebner_basis`` method is ``PolynomialSequence``, i.e. it is not a +the ``groebner_basis`` method is ``PolynomialSequence``, i.e., it is not a :class:`MPolynomialIdeal`:: sage: x,y,z = QQ['x,y,z'].gens() @@ -144,42 +145,43 @@ surprising as there are 4 equations in 3 unknowns). :: sage: P. = PolynomialRing(ZZ,order='lex') - sage: I = ideal(-y^2 - 3*y + z^2 + 3, -2*y*z + z^2 + 2*z + 1, \ - x*z + y*z + z^2, -3*x*y + 2*y*z + 6*z^2) + sage: I = ideal(-y^2 - 3*y + z^2 + 3, -2*y*z + z^2 + 2*z + 1, + ....: x*z + y*z + z^2, -3*x*y + 2*y*z + 6*z^2) sage: I.change_ring(P.change_ring(QQ)).groebner_basis() [1] - However, when we compute the Groebner basis of I (defined over + However, when we compute the Groebner basis of `I` (defined over `\ZZ`), we note that there is a certain integer in the ideal which is not 1. :: sage: I.groebner_basis() - [x + y + 57119*z + 4, y^2 + 3*y + 17220, y*z + ..., 2*y + 158864, z^2 + 17223, 2*z + 41856, 164878] + [x + y + 57119*z + 4, y^2 + 3*y + 17220, y*z + ..., + 2*y + 158864, z^2 + 17223, 2*z + 41856, 164878] Now for each prime `p` dividing this integer 164878, the Groebner - basis of I modulo `p` will be non-trivial and will thus give a + basis of `I` modulo `p` will be non-trivial and will thus give a solution of the original system modulo `p`. :: sage: factor(164878) 2 * 7 * 11777 - sage: I.change_ring(P.change_ring( GF(2) )).groebner_basis() + sage: I.change_ring(P.change_ring(GF(2))).groebner_basis() # optional - sage.rings.finite_rings [x + y + z, y^2 + y, y*z + y, z^2 + 1] - sage: I.change_ring(P.change_ring( GF(7) )).groebner_basis() + sage: I.change_ring(P.change_ring(GF(7))).groebner_basis() # optional - sage.rings.finite_rings [x - 1, y + 3, z - 2] - sage: I.change_ring(P.change_ring( GF(11777 ))).groebner_basis() + sage: I.change_ring(P.change_ring(GF(11777))).groebner_basis() # optional - sage.rings.finite_rings [x + 5633, y - 3007, z - 2626] The Groebner basis modulo any product of the prime factors is also non-trivial:: - sage: I.change_ring(P.change_ring( IntegerModRing(2*7) )).groebner_basis() + sage: I.change_ring(P.change_ring(IntegerModRing(2 * 7))).groebner_basis() [x + 9*y + 13*z, y^2 + 3*y, y*z + 7*y + 6, 2*y + 6, z^2 + 3, 2*z + 10] Modulo any other prime the Groebner basis is trivial so there are no other solutions. For example:: - sage: I.change_ring( P.change_ring( GF(3) ) ).groebner_basis() + sage: I.change_ring(P.change_ring(GF(3))).groebner_basis() # optional - sage.rings.finite_rings [1] TESTS:: @@ -301,7 +303,7 @@ def __call__(self, *args, **kwds): def is_MPolynomialIdeal(x): """ - Return ``True`` if the provided argument ``x`` is an ideal in the + Return ``True`` if the provided argument ``x`` is an ideal in a multivariate polynomial ring. INPUT: @@ -341,9 +343,9 @@ def _magma_init_(self, magma): EXAMPLES:: - sage: R. = PolynomialRing(GF(127),10) - sage: I = sage.rings.ideal.Cyclic(R,4) # indirect doctest - sage: magma(I) # optional - magma + sage: R. = PolynomialRing(GF(127),10) # optional - sage.rings.finite_rings + sage: I = sage.rings.ideal.Cyclic(R,4) # indirect doctest # optional - sage.rings.finite_rings + sage: magma(I) # optional - magma # optional - sage.rings.finite_rings Ideal of Polynomial ring of rank 10 over GF(127) Order: Graded Reverse Lexicographical Variables: a, b, c, d, e, f, g, h, i, j @@ -378,18 +380,18 @@ def _groebner_basis_magma(self, deg_bound=None, prot=False, magma=magma_default) EXAMPLES:: - sage: R. = PolynomialRing(GF(127),10) - sage: I = sage.rings.ideal.Cyclic(R,6) - sage: gb = I.groebner_basis('magma:GroebnerBasis') # indirect doctest; optional - magma - sage: len(gb) # optional - magma + sage: R. = PolynomialRing(GF(127), 10) # optional - sage.rings.finite_rings + sage: I = sage.rings.ideal.Cyclic(R, 6) # optional - sage.rings.finite_rings + sage: gb = I.groebner_basis('magma:GroebnerBasis') # indirect doctest; optional - magma sage.rings.finite_rings + sage: len(gb) # optional - magma # optional - sage.rings.finite_rings 45 We may also pass a degree bound to Magma:: - sage: R. = PolynomialRing(GF(127),10) - sage: I = sage.rings.ideal.Cyclic(R,6) - sage: gb = I.groebner_basis('magma:GroebnerBasis', deg_bound=4) # indirect doctest; optional - magma - sage: len(gb) # optional - magma + sage: R. = PolynomialRing(GF(127), 10) # optional - sage.rings.finite_rings + sage: I = sage.rings.ideal.Cyclic(R, 6) # optional - sage.rings.finite_rings + sage: gb = I.groebner_basis('magma:GroebnerBasis', deg_bound=4) # indirect doctest; optional - magma # optional - sage.rings.finite_rings + sage: len(gb) # optional - magma # optional - sage.rings.finite_rings 5 """ R = self.ring() @@ -726,7 +728,7 @@ def complete_primary_decomposition(self, algorithm="sy"): `b^n \in Q` for some `n \in \ZZ`. If `Q` is a primary ideal of the ring `R`, then the radical - ideal `P` of `Q` (i.e. the ideal consisting of all `a \in R` + ideal `P` of `Q` (i.e., the ideal consisting of all `a \in R` with a^n \in Q` for some `n \in \ZZ`), is called the associated prime of `Q`. @@ -760,7 +762,7 @@ def complete_primary_decomposition(self, algorithm="sy"): sage: R. = PolynomialRing(QQ, 3, order='lex') sage: p = z^2 + 1; q = z^3 + 2 - sage: I = (p*q^2, y-z^2)*R + sage: I = (p*q^2, y - z^2) * R sage: pd = I.complete_primary_decomposition(); sorted(pd, key=str) [(Ideal (z^2 + 1, y + 1) of Multivariate Polynomial Ring in x, y, z over Rational Field, Ideal (z^2 + 1, y + 1) of Multivariate Polynomial Ring in x, y, z over Rational Field), @@ -839,8 +841,8 @@ def primary_decomposition(self, algorithm='sy'): `b^n \in Q` for some `n \in \ZZ`. If `Q` is a primary ideal of the ring `R`, then the radical - ideal `P` of `Q` (i.e. the ideal consisting of all `a \in R` - with a^n \in Q` for some `n \in \ZZ`), is called the + ideal `P` of `Q` (i.e., the ideal consisting of all `a \in R` + with `a^n \in Q` for some `n \in \ZZ`), is called the associated prime of `Q`. If `I` is a proper ideal of a Noetherian ring `R`, then there @@ -872,15 +874,17 @@ def primary_decomposition(self, algorithm='sy'): sage: R. = PolynomialRing(QQ, 3, order='lex') sage: p = z^2 + 1; q = z^3 + 2 - sage: I = (p*q^2, y-z^2)*R + sage: I = (p*q^2, y - z^2) * R sage: pd = I.primary_decomposition(); sorted(pd, key=str) - [Ideal (z^2 + 1, y + 1) of Multivariate Polynomial Ring in x, y, z over Rational Field, - Ideal (z^6 + 4*z^3 + 4, y - z^2) of Multivariate Polynomial Ring in x, y, z over Rational Field] + [Ideal (z^2 + 1, y + 1) + of Multivariate Polynomial Ring in x, y, z over Rational Field, + Ideal (z^6 + 4*z^3 + 4, y - z^2) + of Multivariate Polynomial Ring in x, y, z over Rational Field] :: sage: from functools import reduce - sage: reduce(lambda Qi,Qj: Qi.intersection(Qj), pd) == I + sage: reduce(lambda Qi, Qj: Qi.intersection(Qj), pd) == I True ALGORITHM: @@ -929,22 +933,20 @@ def associated_primes(self, algorithm='sy'): INPUT: - - ``algorithm`` - string: - - - ``'sy'`` - (default) use the Shimoyama-Yokoyama algorithm + - ``algorithm`` -- string: - - ``'gtz'`` - use the Gianni-Trager-Zacharias algorithm + - ``'sy'`` -- (default) use the Shimoyama-Yokoyama algorithm + - ``'gtz'`` -- use the Gianni-Trager-Zacharias algorithm - OUTPUT: - - ``list`` - a list of associated primes + OUTPUT: a list of associated primes EXAMPLES:: sage: R. = PolynomialRing(QQ, 3, order='lex') sage: p = z^2 + 1; q = z^3 + 2 - sage: I = (p*q^2, y-z^2)*R + sage: I = (p*q^2, y - z^2) * R sage: pd = I.associated_primes(); sorted(pd, key=str) [Ideal (z^2 + 1, y + 1) of Multivariate Polynomial Ring in x, y, z over Rational Field, Ideal (z^3 + 2, y - z^2) of Multivariate Polynomial Ring in x, y, z over Rational Field] @@ -968,19 +970,19 @@ def is_prime(self, **kwds): INPUT: - keyword arguments are passed on to - ``complete_primary_decomposition``; in this way you can + :meth:`complete_primary_decomposition`; in this way you can specify the algorithm to use. EXAMPLES:: sage: R. = PolynomialRing(QQ, 2) - sage: I = (x^2 - y^2 - 1)*R + sage: I = (x^2 - y^2 - 1) * R sage: I.is_prime() True sage: (I^2).is_prime() False - sage: J = (x^2 - y^2)*R + sage: J = (x^2 - y^2) * R sage: J.is_prime() False sage: (J^3).is_prime() @@ -994,9 +996,12 @@ def is_prime(self, **kwds): fraction field is not the quotient ring itself:: sage: Q = R.quotient(I); Q - Quotient of Multivariate Polynomial Ring in x, y over Rational Field by the ideal (x^2 - y^2 - 1) + Quotient of Multivariate Polynomial Ring in x, y over Rational Field + by the ideal (x^2 - y^2 - 1) sage: Q.fraction_field() - Fraction Field of Quotient of Multivariate Polynomial Ring in x, y over Rational Field by the ideal (x^2 - y^2 - 1) + Fraction Field of + Quotient of Multivariate Polynomial Ring in x, y over Rational Field + by the ideal (x^2 - y^2 - 1) """ if not self.ring().base_ring().is_field(): raise NotImplementedError @@ -1016,7 +1021,7 @@ def triangular_decomposition(self, algorithm=None, singular=singular_default): sets. This requires that the given basis is reduced w.r.t. to the - lexicographical monomial ordering. If the basis of self does + lexicographical monomial ordering. If the basis of ``self`` does not have this property, the required Groebner basis is computed implicitly. @@ -1026,14 +1031,14 @@ def triangular_decomposition(self, algorithm=None, singular=singular_default): ALGORITHMS: - - ``singular:triangL`` - decomposition of self into triangular + - ``"singular:triangL"`` - decomposition of ``self`` into triangular systems (Lazard). - - ``singular:triangLfak`` - decomp. of self into tri. systems + - ``"singular:triangLfak"`` - decomposition of ``self`` into triangular systems plus factorization. - - ``singular:triangM`` - decomposition of self into - triangular systems (Moeller). + - ``"singular:triangM"`` - decomposition of ``self`` into + triangular systems (Moeller). OUTPUT: a list `T` of lists `t` such that the variety of ``self`` is the union of the varieties of `t` in `L` and each @@ -1041,23 +1046,38 @@ def triangular_decomposition(self, algorithm=None, singular=singular_default): EXAMPLES:: - sage: P. = PolynomialRing(QQ,5,order='lex') + sage: P. = PolynomialRing(QQ, 5, order='lex'); P.rename("P") sage: I = sage.rings.ideal.Cyclic(P) sage: GB = Ideal(I.groebner_basis('libsingular:stdfglm')) sage: GB.triangular_decomposition('singular:triangLfak') - [Ideal (a - 1, b - 1, c - 1, d^2 + 3*d + 1, e + d + 3) of Multivariate Polynomial Ring in e, d, c, b, a over Rational Field, - Ideal (a - 1, b - 1, c^2 + 3*c + 1, d + c + 3, e - 1) of Multivariate Polynomial Ring in e, d, c, b, a over Rational Field, - Ideal (a - 1, b^2 + 3*b + 1, c + b + 3, d - 1, e - 1) of Multivariate Polynomial Ring in e, d, c, b, a over Rational Field, - Ideal (a - 1, b^4 + b^3 + b^2 + b + 1, -c + b^2, -d + b^3, e + b^3 + b^2 + b + 1) of Multivariate Polynomial Ring in e, d, c, b, a over Rational Field, - Ideal (a^2 + 3*a + 1, b - 1, c - 1, d - 1, e + a + 3) of Multivariate Polynomial Ring in e, d, c, b, a over Rational Field, - Ideal (a^2 + 3*a + 1, b + a + 3, c - 1, d - 1, e - 1) of Multivariate Polynomial Ring in e, d, c, b, a over Rational Field, - Ideal (a^4 - 4*a^3 + 6*a^2 + a + 1, -11*b^2 + 6*b*a^3 - 26*b*a^2 + 41*b*a - 4*b - 8*a^3 + 31*a^2 - 40*a - 24, 11*c + 3*a^3 - 13*a^2 + 26*a - 2, 11*d + 3*a^3 - 13*a^2 + 26*a - 2, -11*e - 11*b + 6*a^3 - 26*a^2 + 41*a - 4) of Multivariate Polynomial Ring in e, d, c, b, a over Rational Field, - Ideal (a^4 + a^3 + a^2 + a + 1, b - 1, c + a^3 + a^2 + a + 1, -d + a^3, -e + a^2) of Multivariate Polynomial Ring in e, d, c, b, a over Rational Field, - Ideal (a^4 + a^3 + a^2 + a + 1, b - a, c - a, d^2 + 3*d*a + a^2, e + d + 3*a) of Multivariate Polynomial Ring in e, d, c, b, a over Rational Field, - Ideal (a^4 + a^3 + a^2 + a + 1, b - a, c^2 + 3*c*a + a^2, d + c + 3*a, e - a) of Multivariate Polynomial Ring in e, d, c, b, a over Rational Field, - Ideal (a^4 + a^3 + a^2 + a + 1, b^2 + 3*b*a + a^2, c + b + 3*a, d - a, e - a) of Multivariate Polynomial Ring in e, d, c, b, a over Rational Field, - Ideal (a^4 + a^3 + a^2 + a + 1, b^3 + b^2*a + b^2 + b*a^2 + b*a + b + a^3 + a^2 + a + 1, c + b^2*a^3 + b^2*a^2 + b^2*a + b^2, -d + b^2*a^2 + b^2*a + b^2 + b*a^2 + b*a + a^2, -e + b^2*a^3 - b*a^2 - b*a - b - a^2 - a) of Multivariate Polynomial Ring in e, d, c, b, a over Rational Field, - Ideal (a^4 + a^3 + 6*a^2 - 4*a + 1, -11*b^2 + 6*b*a^3 + 10*b*a^2 + 39*b*a + 2*b + 16*a^3 + 23*a^2 + 104*a - 24, 11*c + 3*a^3 + 5*a^2 + 25*a + 1, 11*d + 3*a^3 + 5*a^2 + 25*a + 1, -11*e - 11*b + 6*a^3 + 10*a^2 + 39*a + 2) of Multivariate Polynomial Ring in e, d, c, b, a over Rational Field] + [Ideal (a - 1, b - 1, c - 1, d^2 + 3*d + 1, e + d + 3) of P, + Ideal (a - 1, b - 1, c^2 + 3*c + 1, d + c + 3, e - 1) of P, + Ideal (a - 1, b^2 + 3*b + 1, c + b + 3, d - 1, e - 1) of P, + Ideal (a - 1, b^4 + b^3 + b^2 + b + 1, -c + b^2, -d + b^3, + e + b^3 + b^2 + b + 1) of P, + Ideal (a^2 + 3*a + 1, b - 1, c - 1, d - 1, e + a + 3) of P, + Ideal (a^2 + 3*a + 1, b + a + 3, c - 1, d - 1, e - 1) of P, + Ideal (a^4 - 4*a^3 + 6*a^2 + a + 1, + -11*b^2 + 6*b*a^3 - 26*b*a^2 + 41*b*a - 4*b - 8*a^3 + 31*a^2 - 40*a - 24, + 11*c + 3*a^3 - 13*a^2 + 26*a - 2, 11*d + 3*a^3 - 13*a^2 + 26*a - 2, + -11*e - 11*b + 6*a^3 - 26*a^2 + 41*a - 4) of P, + Ideal (a^4 + a^3 + a^2 + a + 1, + b - 1, c + a^3 + a^2 + a + 1, -d + a^3, -e + a^2) of P, + Ideal (a^4 + a^3 + a^2 + a + 1, + b - a, c - a, d^2 + 3*d*a + a^2, e + d + 3*a) of P, + Ideal (a^4 + a^3 + a^2 + a + 1, + b - a, c^2 + 3*c*a + a^2, d + c + 3*a, e - a) of P, + Ideal (a^4 + a^3 + a^2 + a + 1, + b^2 + 3*b*a + a^2, c + b + 3*a, d - a, e - a) of P, + Ideal (a^4 + a^3 + a^2 + a + 1, + b^3 + b^2*a + b^2 + b*a^2 + b*a + b + a^3 + a^2 + a + 1, + c + b^2*a^3 + b^2*a^2 + b^2*a + b^2, + -d + b^2*a^2 + b^2*a + b^2 + b*a^2 + b*a + a^2, + -e + b^2*a^3 - b*a^2 - b*a - b - a^2 - a) of P, + Ideal (a^4 + a^3 + 6*a^2 - 4*a + 1, + -11*b^2 + 6*b*a^3 + 10*b*a^2 + 39*b*a + 2*b + 16*a^3 + 23*a^2 + 104*a - 24, + 11*c + 3*a^3 + 5*a^2 + 25*a + 1, 11*d + 3*a^3 + 5*a^2 + 25*a + 1, + -11*e - 11*b + 6*a^3 + 10*a^2 + 39*a + 2) of P] sage: R. = PolynomialRing(QQ, 2, order='lex') sage: f1 = 1/2*((x1^2 + 2*x1 - 4)*x2^2 + 2*(x1^2 + x1)*x2 + x1^2) @@ -1067,7 +1087,8 @@ def triangular_decomposition(self, algorithm=None, singular=singular_default): [Ideal (x2, x1^2) of Multivariate Polynomial Ring in x1, x2 over Rational Field, Ideal (x2, x1^2) of Multivariate Polynomial Ring in x1, x2 over Rational Field, Ideal (x2, x1^2) of Multivariate Polynomial Ring in x1, x2 over Rational Field, - Ideal (x2^4 + 4*x2^3 - 6*x2^2 - 20*x2 + 5, 8*x1 - x2^3 + x2^2 + 13*x2 - 5) of Multivariate Polynomial Ring in x1, x2 over Rational Field] + Ideal (x2^4 + 4*x2^3 - 6*x2^2 - 20*x2 + 5, 8*x1 - x2^3 + x2^2 + 13*x2 - 5) + of Multivariate Polynomial Ring in x1, x2 over Rational Field] TESTS:: @@ -1078,9 +1099,9 @@ def triangular_decomposition(self, algorithm=None, singular=singular_default): Check that this method works over QQbar (:trac:`25351`):: - sage: R. = QQbar[] - sage: J = Ideal(x^2+y^2-2, y^2-1) - sage: J.triangular_decomposition() + sage: R. = QQbar[] # optional - sage.rings.number_field + sage: J = Ideal(x^2 + y^2 - 2, y^2 - 1) # optional - sage.rings.number_field + sage: J.triangular_decomposition() # optional - sage.rings.number_field [Ideal (y^2 - 1, x^2 - 1) of Multivariate Polynomial Ring in x, y over Algebraic Field] """ P = self.ring() @@ -1136,9 +1157,9 @@ def dimension(self, singular=singular_default): EXAMPLES:: - sage: P. = PolynomialRing(GF(32003),order='degrevlex') - sage: I = ideal(x^2-y,x^3) - sage: I.dimension() + sage: P. = PolynomialRing(GF(32003), order='degrevlex') # optional - sage.rings.finite_rings + sage: I = ideal(x^2 - y, x^3) # optional - sage.rings.finite_rings + sage: I.dimension() # optional - sage.rings.finite_rings 1 If the ideal is the total ring, the dimension is `-1` by convention. @@ -1150,22 +1171,22 @@ def dimension(self, singular=singular_default): EXAMPLES:: - sage: R. = PolynomialRing(GF(2147483659^2),order='lex') - sage: I = R.ideal([x*y,x*y+1]) - sage: I.dimension() + sage: R. = PolynomialRing(GF(2147483659^2), order='lex') # optional - sage.rings.finite_rings + sage: I = R.ideal([x*y, x*y + 1]) # optional - sage.rings.finite_rings + sage: I.dimension() # optional - sage.rings.finite_rings verbose 0 (...: multi_polynomial_ideal.py, dimension) Warning: falling back to very slow toy implementation. -1 - sage: I=ideal([x*(x*y+1),y*(x*y+1)]) - sage: I.dimension() + sage: I=ideal([x*(x*y+1), y*(x*y+1)]) # optional - sage.rings.finite_rings + sage: I.dimension() # optional - sage.rings.finite_rings verbose 0 (...: multi_polynomial_ideal.py, dimension) Warning: falling back to very slow toy implementation. 1 - sage: I = R.ideal([x^3*y,x*y^2]) - sage: I.dimension() + sage: I = R.ideal([x^3*y, x*y^2]) # optional - sage.rings.finite_rings + sage: I.dimension() # optional - sage.rings.finite_rings verbose 0 (...: multi_polynomial_ideal.py, dimension) Warning: falling back to very slow toy implementation. 1 - sage: R. = PolynomialRing(GF(2147483659^2),order='lex') - sage: I = R.ideal(0) - sage: I.dimension() + sage: R. = PolynomialRing(GF(2147483659^2), order='lex') # optional - sage.rings.finite_rings + sage: I = R.ideal(0) # optional - sage.rings.finite_rings + sage: I.dimension() # optional - sage.rings.finite_rings verbose 0 (...: multi_polynomial_ideal.py, dimension) Warning: falling back to very slow toy implementation. 2 @@ -1177,9 +1198,9 @@ def dimension(self, singular=singular_default): Check that this method works over QQbar (:trac:`25351`):: - sage: P. = QQbar[] - sage: I = ideal(x^2-y,x^3-QQbar(-1)) - sage: I.dimension() + sage: P. = QQbar[] # optional - sage.rings.number_field + sage: I = ideal(x^2-y, x^3-QQbar(-1)) # optional - sage.rings.number_field + sage: I.dimension() # optional - sage.rings.number_field 1 .. NOTE:: @@ -1251,7 +1272,7 @@ def dimension(self, singular=singular_default): def vector_space_dimension(self): """ Return the vector space dimension of the ring modulo this ideal. If - the ideal is not zero-dimensional, a TypeError is raised. + the ideal is not zero-dimensional, a :class:`TypeError` is raised. ALGORITHM: @@ -1278,19 +1299,19 @@ def vector_space_dimension(self): Due to integer overflow, the result is correct only modulo ``2^32``, see :trac:`8586`:: - sage: P. = PolynomialRing(GF(32003),3) - sage: sage.rings.ideal.FieldIdeal(P).vector_space_dimension() # known bug + sage: P. = PolynomialRing(GF(32003), 3) # optional - sage.rings.finite_rings + sage: sage.rings.ideal.FieldIdeal(P).vector_space_dimension() # known bug # optional - sage.rings.finite_rings 32777216864027 TESTS: Check that this method works over QQbar (:trac:`25351`):: - sage: P. = QQbar[] - sage: I = ideal(x^2-y,x^3-QQbar(-1),z-y) - sage: I.dimension() + sage: P. = QQbar[] # optional - sage.rings.number_field + sage: I = ideal(x^2-y,x^3-QQbar(-1),z-y) # optional - sage.rings.number_field + sage: I.dimension() # optional - sage.rings.number_field 0 - sage: I.vector_space_dimension() + sage: I.vector_space_dimension() # optional - sage.rings.number_field 3 """ @@ -1327,12 +1348,12 @@ def _groebner_basis_ginv(self, algorithm="TQ", criteria='CritPartially', divisio sage: P. = PolynomialRing(QQ,order='degrevlex') sage: I = sage.rings.ideal.Katsura(P) - sage: I.groebner_basis(algorithm='ginv') # optional - ginv + sage: I.groebner_basis(algorithm='ginv') # optional - ginv [z^3 - 79/210*z^2 + 1/30*y + 1/70*z, y^2 - 3/5*z^2 - 1/5*y + 1/5*z, y*z + 6/5*z^2 - 1/10*y - 2/5*z, x + 2*y + 2*z - 1] - sage: P. = PolynomialRing(GF(127),order='degrevlex') - sage: I = sage.rings.ideal.Katsura(P) - sage: I.groebner_basis(algorithm='ginv') # optional - ginv + sage: P. = PolynomialRing(GF(127), order='degrevlex') # optional - sage.rings.finite_rings + sage: I = sage.rings.ideal.Katsura(P) # optional - sage.rings.finite_rings + sage: I.groebner_basis(algorithm='ginv') # optional - ginv # optional - sage.rings.finite_rings ... [z^3 + 22*z^2 - 55*y + 49*z, y^2 - 26*z^2 - 51*y + 51*z, y*z + 52*z^2 + 38*y + 25*z, x + 2*y + 2*z - 1] @@ -1575,9 +1596,9 @@ def genus(self): Check that this method works over QQbar (:trac:`25351`):: - sage: P. = QQbar[] - sage: I = ideal(y^3*z + x^3*y + x*z^3) - sage: I.genus() + sage: P. = QQbar[] # optional - sage.rings.number_field + sage: I = ideal(y^3*z + x^3*y + x*z^3) # optional - sage.rings.number_field + sage: I.genus() # optional - sage.rings.number_field 3 """ from sage.libs.singular.function_factory import ff @@ -1601,22 +1622,23 @@ def intersection(self, *others): The following simple example illustrates that the product need not equal the intersection. :: - sage: I = (x^2, y)*R - sage: J = (y^2, x)*R + sage: I = (x^2, y) * R + sage: J = (y^2, x) * R sage: K = I.intersection(J); K Ideal (y^2, x*y, x^2) of Multivariate Polynomial Ring in x, y over Rational Field sage: IJ = I*J; IJ - Ideal (x^2*y^2, x^3, y^3, x*y) of Multivariate Polynomial Ring in x, y over Rational Field + Ideal (x^2*y^2, x^3, y^3, x*y) + of Multivariate Polynomial Ring in x, y over Rational Field sage: IJ == K False Intersection of several ideals:: sage: R. = PolynomialRing(QQ, 3, order='lex') - sage: I1 = x*R - sage: I2 = y*R - sage: I3 = (x, y)*R - sage: I4 = (x^2 + x*y*z, y^2 - z^3*y, z^3 + y^5*x*z)*R + sage: I1 = x * R + sage: I2 = y * R + sage: I3 = (x, y) * R + sage: I4 = (x^2 + x*y*z, y^2 - z^3*y, z^3 + y^5*x*z) * R sage: I1.intersection(I2, I3, I4).groebner_basis() [x^2*y + x*y*z^4, x*y^2 - x*y*z^3, x*y*z^20 - x*y*z^3] @@ -1635,10 +1657,10 @@ def intersection(self, *others): Check that this method works over QQbar (:trac:`25351`):: - sage: R. = QQbar[] - sage: I = x*R - sage: J = y*R - sage: I.intersection(J) + sage: R. = QQbar[] # optional - sage.rings.number_field + sage: I = x*R # optional - sage.rings.number_field + sage: J = y*R # optional - sage.rings.number_field + sage: I.intersection(J) # optional - sage.rings.number_field Ideal (x*y) of Multivariate Polynomial Ring in x, y over Algebraic Field """ R = self.ring() @@ -1665,10 +1687,12 @@ def minimal_associated_primes(self): sage: R. = PolynomialRing(QQ, 3, 'xyz') sage: p = z^2 + 1; q = z^3 + 2 - sage: I = (p*q^2, y-z^2)*R + sage: I = (p*q^2, y - z^2) * R sage: sorted(I.minimal_associated_primes(), key=str) - [Ideal (z^2 + 1, -z^2 + y) of Multivariate Polynomial Ring in x, y, z over Rational Field, - Ideal (z^3 + 2, -z^2 + y) of Multivariate Polynomial Ring in x, y, z over Rational Field] + [Ideal (z^2 + 1, -z^2 + y) + of Multivariate Polynomial Ring in x, y, z over Rational Field, + Ideal (z^3 + 2, -z^2 + y) + of Multivariate Polynomial Ring in x, y, z over Rational Field] ALGORITHM: @@ -1692,7 +1716,7 @@ def radical(self): This is an obviously not radical ideal:: sage: R. = PolynomialRing(QQ, 3) - sage: I = (x^2, y^3, (x*z)^4 + y^3 + 10*x^2)*R + sage: I = (x^2, y^3, (x*z)^4 + y^3 + 10*x^2) * R sage: I.radical() Ideal (y, x) of Multivariate Polynomial Ring in x, y, z over Rational Field @@ -1704,9 +1728,10 @@ def radical(self): This is the example from the Singular manual:: sage: p = z^2 + 1; q = z^3 + 2 - sage: I = (p*q^2, y-z^2)*R + sage: I = (p*q^2, y - z^2) * R sage: I.radical() - Ideal (z^2 - y, y^2*z + y*z + 2*y + 2) of Multivariate Polynomial Ring in x, y, z over Rational Field + Ideal (z^2 - y, y^2*z + y*z + 2*y + 2) + of Multivariate Polynomial Ring in x, y, z over Rational Field .. NOTE:: @@ -1716,11 +1741,12 @@ def radical(self): :: - sage: R. = PolynomialRing(GF(37), 3) - sage: p = z^2 + 1; q = z^3 + 2 - sage: I = (p*q^2, y - z^2)*R - sage: I.radical() - Ideal (z^2 - y, y^2*z + y*z + 2*y + 2) of Multivariate Polynomial Ring in x, y, z over Finite Field of size 37 + sage: R. = PolynomialRing(GF(37), 3) # optional - sage.rings.finite_rings + sage: p = z^2 + 1; q = z^3 + 2 # optional - sage.rings.finite_rings + sage: I = (p*q^2, y - z^2) * R # optional - sage.rings.finite_rings + sage: I.radical() # optional - sage.rings.finite_rings + Ideal (z^2 - y, y^2*z + y*z + 2*y + 2) + of Multivariate Polynomial Ring in x, y, z over Finite Field of size 37 """ from sage.libs.singular.function_factory import ff radical = ff.primdec__lib.radical @@ -1743,22 +1769,22 @@ def integral_closure(self, p=0, r=True, singular=singular_default): Return the integral closure of `I, ..., I^p`, where `sI` is an ideal in the polynomial ring `R=k[x(1),...x(n)]`. If `p` is not given, or `p=0`, compute the closure of all powers up to - the maximum degree in t occurring in the closure of `R[It]` + the maximum degree in `t` occurring in the closure of `R[It]` (so this is the last power whose closure is not just the sum/product of the smaller). If `r` is given and ``r is - True``, ``I.integral_closure()`` starts with a check whether I + True``, ``I.integral_closure()`` starts with a check whether `I` is already a radical ideal. INPUT: - - ``p`` - powers of I (default: 0) + - ``p`` - powers of `I` (default: 0) - - ``r`` - check whether self is a radical ideal first (default: ``True``) + - ``r`` - check whether ``self`` is a radical ideal first (default: ``True``) EXAMPLES:: sage: R. = QQ[] - sage: I = ideal([x^2,x*y^4,y^5]) + sage: I = ideal([x^2, x*y^4, y^5]) sage: I.integral_closure() [x^2, x*y^4, y^5, x*y^3] @@ -1803,16 +1829,16 @@ def syzygy_module(self): Check that this method works over QQbar (:trac:`25351`):: - sage: R. = QQbar[] - sage: f = 2*x^2 + y - sage: g = y - sage: h = 2*f + g - sage: I = Ideal([f,g,h]) - sage: M = I.syzygy_module(); M + sage: R. = QQbar[] # optional - sage.rings.number_field + sage: f = 2*x^2 + y # optional - sage.rings.number_field + sage: g = y # optional - sage.rings.number_field + sage: h = 2*f + g # optional - sage.rings.number_field + sage: I = Ideal([f,g,h]) # optional - sage.rings.number_field + sage: M = I.syzygy_module(); M # optional - sage.rings.number_field [ -2 -1 1] [ -y 2*x^2 + y 0] - sage: G = vector(I.gens()) - sage: M*G + sage: G = vector(I.gens()) # optional - sage.rings.number_field + sage: M*G # optional - sage.rings.number_field (0, 0) """ from sage.libs.singular.function_factory import ff @@ -1904,50 +1930,50 @@ def graded_free_resolution(self, *args, **kwds): @libsingular_gb_standard_options def interreduced_basis(self): r""" - If this ideal is spanned by `(f_1, ..., f_n)` this method - returns `(g_1, ..., g_s)` such that: + If this ideal is spanned by `(f_1, ..., f_n)`, + return `(g_1, ..., g_s)` such that: - `(f_1,...,f_n) = (g_1,...,g_s)` - - `LT(g_i) != LT(g_j)` for all `i != j` + - `LT(g_i) \neq LT(g_j)` for all `i \neq j` - `LT(g_i)` does not divide `m` for all monomials `m` of - `\{g_1,...,g_{i-1},g_{i+1},...,g_s\}` + `\{g_1,...,g_{i-1},g_{i+1},...,g_s\}` - - `LC(g_i) == 1` for all `i` if the coefficient ring is a field. + - `LC(g_i) = 1` for all `i` if the coefficient ring is a field. EXAMPLES:: sage: R. = PolynomialRing(QQ) - sage: I = Ideal([z*x+y^3,z+y^3,z+x*y]) + sage: I = Ideal([z*x + y^3, z + y^3, z + x*y]) sage: I.interreduced_basis() [y^3 + z, x*y + z, x*z - z] Note that tail reduction for local orderings is not well-defined:: sage: R. = PolynomialRing(QQ,order='negdegrevlex') - sage: I = Ideal([z*x+y^3,z+y^3,z+x*y]) + sage: I = Ideal([z*x + y^3, z + y^3, z + x*y]) sage: I.interreduced_basis() [z + x*y, x*y - y^3, x^2*y - y^3] A fixed error with nonstandard base fields:: - sage: R.=QQ['t'] - sage: K.=R.fraction_field()['x,y'] - sage: I=t*x*K + sage: R. = QQ['t'] + sage: K. = R.fraction_field()['x,y'] + sage: I = t*x * K sage: I.interreduced_basis() [x] The interreduced basis of 0 is 0:: - sage: P. = GF(2)[] - sage: Ideal(P(0)).interreduced_basis() + sage: P. = GF(2)[] # optional - sage.rings.finite_rings + sage: Ideal(P(0)).interreduced_basis() # optional - sage.rings.finite_rings [0] ALGORITHM: - Uses Singular's interred command or + Uses Singular's ``interred`` command or :func:`sage.rings.polynomial.toy_buchberger.inter_reduction` if conversion to Singular fails. @@ -1955,9 +1981,9 @@ def interreduced_basis(self): Check that this method works over QQbar (:trac:`25351`):: - sage: R. = QQbar[] - sage: I = Ideal([z*x+y^3,z+y^3,z+x*y]) - sage: I.interreduced_basis() + sage: R. = QQbar[] # optional - sage.rings.number_field + sage: I = Ideal([z*x + y^3, z + y^3, z + x*y]) # optional - sage.rings.number_field + sage: I.interreduced_basis() # optional - sage.rings.number_field [y^3 + z, x*y + z, x*z - z] """ return self.basis.reduced() @@ -1985,44 +2011,63 @@ def basis_is_groebner(self, singular=singular_default): EXAMPLES:: - sage: R. = PolynomialRing(GF(127),10) - sage: I = sage.rings.ideal.Cyclic(R,4) - sage: I.basis_is_groebner() + sage: R. = PolynomialRing(GF(127), 10) # optional - sage.rings.finite_rings + sage: I = sage.rings.ideal.Cyclic(R, 4) # optional - sage.rings.finite_rings + sage: I.basis_is_groebner() # optional - sage.rings.finite_rings False - sage: I2 = Ideal(I.groebner_basis()) - sage: I2.basis_is_groebner() + sage: I2 = Ideal(I.groebner_basis()) # optional - sage.rings.finite_rings + sage: I2.basis_is_groebner() # optional - sage.rings.finite_rings True A more complicated example:: - sage: R. = PolynomialRing(GF(7583)) - sage: l = [u6 + u5 + u4 + u3 + u2 - 3791*h, \ - U6 + U5 + U4 + U3 + U2 - 3791*h, \ - U2*u2 - h^2, U3*u3 - h^2, U4*u4 - h^2, \ - U5*u4 + U5*u3 + U4*u3 + U5*u2 + U4*u2 + U3*u2 - 3791*U5*h - 3791*U4*h - 3791*U3*h - 3791*U2*h - 2842*h^2, \ - U4*u5 + U3*u5 + U2*u5 + U3*u4 + U2*u4 + U2*u3 - 3791*u5*h - 3791*u4*h - 3791*u3*h - 3791*u2*h - 2842*h^2, \ - U5*u5 - h^2, U4*U2*u3 + U5*U3*u2 + U4*U3*u2 + U3^2*u2 - 3791*U5*U3*h - 3791*U4*U3*h - 3791*U3^2*h - 3791*U5*U2*h \ - - 3791*U4*U2*h + U3*U2*h - 3791*U2^2*h - 3791*U4*u3*h - 3791*U4*u2*h - 3791*U3*u2*h - 2843*U5*h^2 + 1897*U4*h^2 - 946*U3*h^2 - 947*U2*h^2 + 2370*h^3, \ - U3*u5*u4 + U2*u5*u4 + U3*u4^2 + U2*u4^2 + U2*u4*u3 - 3791*u5*u4*h - 3791*u4^2*h - 3791*u4*u3*h - 3791*u4*u2*h + u5*h^2 - 2842*u4*h^2, \ - U2*u5*u4*u3 + U2*u4^2*u3 + U2*u4*u3^2 - 3791*u5*u4*u3*h - 3791*u4^2*u3*h - 3791*u4*u3^2*h - 3791*u4*u3*u2*h + u5*u4*h^2 + u4^2*h^2 + u5*u3*h^2 - 2842*u4*u3*h^2, \ - U5^2*U4*u3 + U5*U4^2*u3 + U5^2*U4*u2 + U5*U4^2*u2 + U5^2*U3*u2 + 2*U5*U4*U3*u2 + U5*U3^2*u2 - 3791*U5^2*U4*h - 3791*U5*U4^2*h - 3791*U5^2*U3*h \ - + U5*U4*U3*h - 3791*U5*U3^2*h - 3791*U5^2*U2*h + U5*U4*U2*h + U5*U3*U2*h - 3791*U5*U2^2*h - 3791*U5*U3*u2*h - 2842*U5^2*h^2 + 1897*U5*U4*h^2 \ - - U4^2*h^2 - 947*U5*U3*h^2 - U4*U3*h^2 - 948*U5*U2*h^2 - U4*U2*h^2 - 1422*U5*h^3 + 3791*U4*h^3, \ - u5*u4*u3*u2*h + u4^2*u3*u2*h + u4*u3^2*u2*h + u4*u3*u2^2*h + 2*u5*u4*u3*h^2 + 2*u4^2*u3*h^2 + 2*u4*u3^2*h^2 + 2*u5*u4*u2*h^2 + 2*u4^2*u2*h^2 \ - + 2*u5*u3*u2*h^2 + 1899*u4*u3*u2*h^2, \ - U5^2*U4*U3*u2 + U5*U4^2*U3*u2 + U5*U4*U3^2*u2 - 3791*U5^2*U4*U3*h - 3791*U5*U4^2*U3*h - 3791*U5*U4*U3^2*h - 3791*U5*U4*U3*U2*h \ - + 3791*U5*U4*U3*u2*h + U5^2*U4*h^2 + U5*U4^2*h^2 + U5^2*U3*h^2 - U4^2*U3*h^2 - U5*U3^2*h^2 - U4*U3^2*h^2 - U5*U4*U2*h^2 \ - - U5*U3*U2*h^2 - U4*U3*U2*h^2 + 3791*U5*U4*h^3 + 3791*U5*U3*h^3 + 3791*U4*U3*h^3, \ - u4^2*u3*u2*h^2 + 1515*u5*u3^2*u2*h^2 + u4*u3^2*u2*h^2 + 1515*u5*u4*u2^2*h^2 + 1515*u5*u3*u2^2*h^2 + u4*u3*u2^2*h^2 \ - + 1521*u5*u4*u3*h^3 - 3028*u4^2*u3*h^3 - 3028*u4*u3^2*h^3 + 1521*u5*u4*u2*h^3 - 3028*u4^2*u2*h^3 + 1521*u5*u3*u2*h^3 + 3420*u4*u3*u2*h^3, \ - U5^2*U4*U3*U2*h + U5*U4^2*U3*U2*h + U5*U4*U3^2*U2*h + U5*U4*U3*U2^2*h + 2*U5^2*U4*U3*h^2 + 2*U5*U4^2*U3*h^2 + 2*U5*U4*U3^2*h^2 \ - + 2*U5^2*U4*U2*h^2 + 2*U5*U4^2*U2*h^2 + 2*U5^2*U3*U2*h^2 - 2*U4^2*U3*U2*h^2 - 2*U5*U3^2*U2*h^2 - 2*U4*U3^2*U2*h^2 \ - - 2*U5*U4*U2^2*h^2 - 2*U5*U3*U2^2*h^2 - 2*U4*U3*U2^2*h^2 - U5*U4*U3*h^3 - U5*U4*U2*h^3 - U5*U3*U2*h^3 - U4*U3*U2*h^3] - - sage: Ideal(l).basis_is_groebner() + sage: R. = PolynomialRing(GF(7583)) # optional - sage.rings.finite_rings + sage: l = [u6 + u5 + u4 + u3 + u2 - 3791*h, # optional - sage.rings.finite_rings + ....: U6 + U5 + U4 + U3 + U2 - 3791*h, + ....: U2*u2 - h^2, U3*u3 - h^2, U4*u4 - h^2, + ....: U5*u4 + U5*u3 + U4*u3 + U5*u2 + U4*u2 + U3*u2 - 3791*U5*h + ....: - 3791*U4*h - 3791*U3*h - 3791*U2*h - 2842*h^2, + ....: U4*u5 + U3*u5 + U2*u5 + U3*u4 + U2*u4 + U2*u3 - 3791*u5*h + ....: - 3791*u4*h - 3791*u3*h - 3791*u2*h - 2842*h^2, + ....: U5*u5 - h^2, U4*U2*u3 + U5*U3*u2 + U4*U3*u2 + U3^2*u2 - 3791*U5*U3*h + ....: - 3791*U4*U3*h - 3791*U3^2*h - 3791*U5*U2*h- 3791*U4*U2*h + U3*U2*h + ....: - 3791*U2^2*h - 3791*U4*u3*h - 3791*U4*u2*h - 3791*U3*u2*h + ....: - 2843*U5*h^2 + 1897*U4*h^2 - 946*U3*h^2 - 947*U2*h^2 + 2370*h^3, + ....: U3*u5*u4 + U2*u5*u4 + U3*u4^2 + U2*u4^2 + U2*u4*u3 - 3791*u5*u4*h + ....: - 3791*u4^2*h - 3791*u4*u3*h - 3791*u4*u2*h + u5*h^2 - 2842*u4*h^2, + ....: U2*u5*u4*u3 + U2*u4^2*u3 + U2*u4*u3^2 - 3791*u5*u4*u3*h + ....: - 3791*u4^2*u3*h - 3791*u4*u3^2*h - 3791*u4*u3*u2*h + u5*u4*h^2 + ....: + u4^2*h^2 + u5*u3*h^2 - 2842*u4*u3*h^2, + ....: U5^2*U4*u3 + U5*U4^2*u3 + U5^2*U4*u2 + U5*U4^2*u2 + U5^2*U3*u2 + ....: + 2*U5*U4*U3*u2 + U5*U3^2*u2 - 3791*U5^2*U4*h - 3791*U5*U4^2*h + ....: - 3791*U5^2*U3*h + U5*U4*U3*h - 3791*U5*U3^2*h - 3791*U5^2*U2*h + ....: + U5*U4*U2*h+ U5*U3*U2*h - 3791*U5*U2^2*h - 3791*U5*U3*u2*h + ....: - 2842*U5^2*h^2 + 1897*U5*U4*h^2 - U4^2*h^2 - 947*U5*U3*h^2 + ....: - U4*U3*h^2 - 948*U5*U2*h^2 - U4*U2*h^2 - 1422*U5*h^3 + 3791*U4*h^3, + ....: u5*u4*u3*u2*h + u4^2*u3*u2*h + u4*u3^2*u2*h + u4*u3*u2^2*h + ....: + 2*u5*u4*u3*h^2 + 2*u4^2*u3*h^2 + 2*u4*u3^2*h^2 + 2*u5*u4*u2*h^2 + ....: + 2*u4^2*u2*h^2 + 2*u5*u3*u2*h^2 + 1899*u4*u3*u2*h^2, + ....: U5^2*U4*U3*u2 + U5*U4^2*U3*u2 + U5*U4*U3^2*u2 - 3791*U5^2*U4*U3*h + ....: - 3791*U5*U4^2*U3*h - 3791*U5*U4*U3^2*h - 3791*U5*U4*U3*U2*h + ....: + 3791*U5*U4*U3*u2*h + U5^2*U4*h^2 + U5*U4^2*h^2 + U5^2*U3*h^2 + ....: - U4^2*U3*h^2 - U5*U3^2*h^2 - U4*U3^2*h^2 - U5*U4*U2*h^2 - U5*U3*U2*h^2 + ....: - U4*U3*U2*h^2 + 3791*U5*U4*h^3 + 3791*U5*U3*h^3 + 3791*U4*U3*h^3, + ....: u4^2*u3*u2*h^2 + 1515*u5*u3^2*u2*h^2 + u4*u3^2*u2*h^2 + ....: + 1515*u5*u4*u2^2*h^2 + 1515*u5*u3*u2^2*h^2 + u4*u3*u2^2*h^2 + ....: + 1521*u5*u4*u3*h^3 - 3028*u4^2*u3*h^3 - 3028*u4*u3^2*h^3 + ....: + 1521*u5*u4*u2*h^3 - 3028*u4^2*u2*h^3 + 1521*u5*u3*u2*h^3 + ....: + 3420*u4*u3*u2*h^3, + ....: U5^2*U4*U3*U2*h + U5*U4^2*U3*U2*h + U5*U4*U3^2*U2*h + U5*U4*U3*U2^2*h + ....: + 2*U5^2*U4*U3*h^2 + 2*U5*U4^2*U3*h^2 + 2*U5*U4*U3^2*h^2 + ....: + 2*U5^2*U4*U2*h^2 + 2*U5*U4^2*U2*h^2 + 2*U5^2*U3*U2*h^2 + ....: - 2*U4^2*U3*U2*h^2 - 2*U5*U3^2*U2*h^2 - 2*U4*U3^2*U2*h^2 + ....: - 2*U5*U4*U2^2*h^2 - 2*U5*U3*U2^2*h^2 - 2*U4*U3*U2^2*h^2 + ....: - U5*U4*U3*h^3 - U5*U4*U2*h^3 - U5*U3*U2*h^3 - U4*U3*U2*h^3] + + sage: Ideal(l).basis_is_groebner() # optional - sage.rings.finite_rings False - sage: gb = Ideal(l).groebner_basis() - sage: Ideal(gb).basis_is_groebner() + sage: gb = Ideal(l).groebner_basis() # optional - sage.rings.finite_rings + sage: Ideal(gb).basis_is_groebner() # optional - sage.rings.finite_rings True .. NOTE:: @@ -2031,21 +2076,21 @@ def basis_is_groebner(self, singular=singular_default): this method: 'The result may have no meaning if the second argument (``self``) is not a standard basis'. I (malb) believe this refers to the mathematical fact that the - results may have no meaning if self is no standard basis, + results may have no meaning if ``self`` is no standard basis, i.e., Singular doesn't 'add' any additional 'nonsense' to the result. So we may actually use reduce to determine if - self is a Groebner basis. + ``self`` is a Groebner basis. TESTS: Check that this method works over QQbar (:trac:`25351`):: - sage: R. = QQbar[] - sage: I = sage.rings.ideal.Cyclic(R,4) - sage: I.basis_is_groebner() + sage: R. = QQbar[] # optional - sage.rings.number_field + sage: I = sage.rings.ideal.Cyclic(R,4) # optional - sage.rings.number_field + sage: I.basis_is_groebner() # optional - sage.rings.number_field False - sage: I2 = Ideal(I.groebner_basis()) - sage: I2.basis_is_groebner() + sage: I2 = Ideal(I.groebner_basis()) # optional - sage.rings.number_field + sage: I2.basis_is_groebner() # optional - sage.rings.number_field True """ from sage.matrix.constructor import matrix @@ -2095,25 +2140,25 @@ def transformed_basis(self, algorithm="gwalk", other_ring=None, singular=singula - ``algorithm`` - see below for options. - - ``other_ring`` - only valid for algorithm 'fglm', if - provided conversion will be performed to this + - ``other_ring`` - only valid for ``algorithm='fglm'``; if + provided, conversion will be performed to this ring. Otherwise a lex Groebner basis will be returned. ALGORITHMS: - - ``fglm`` - FGLM algorithm. The input ideal must be given with a reduced + - ``"fglm"`` - FGLM algorithm. The input ideal must be given with a reduced Groebner Basis of a zero-dimensional ideal - - ``gwalk`` - Groebner Walk algorithm (*default*) + - ``"gwalk"`` - Groebner Walk algorithm (*default*) - - ``awalk1`` - 'first alternative' algorithm + - ``"awalk1"`` - 'first alternative' algorithm - - ``awalk2`` - 'second alternative' algorithm + - ``"awalk2"`` - 'second alternative' algorithm - - ``twalk`` - Tran algorithm + - ``"twalk"`` - Tran algorithm - - ``fwalk`` - Fractal Walk algorithm + - ``"fwalk"`` - Fractal Walk algorithm EXAMPLES:: @@ -2124,21 +2169,22 @@ def transformed_basis(self, algorithm="gwalk", other_ring=None, singular=singula sage: J = Ideal(I.transformed_basis('fglm',S)) sage: J Ideal (z^4 + y^3 - y, x^2 + y^3, x*y^3 - y^3, y^4 + y^3) - of Multivariate Polynomial Ring in z, x, y over Rational Field + of Multivariate Polynomial Ring in z, x, y over Rational Field :: - sage: R.=PolynomialRing(GF(32003),3,order='lex') - sage: I=Ideal([y^3+x*y*z+y^2*z+x*z^3,3+x*y+x^2*y+y^2*z]) - sage: I.transformed_basis('gwalk') + sage: R. = PolynomialRing(GF(32003), 3, order='lex') # optional - sage.rings.finite_rings + sage: I = Ideal([y^3 + x*y*z + y^2*z + x*z^3, 3 + x*y + x^2*y + y^2*z]) # optional - sage.rings.finite_rings + sage: I.transformed_basis('gwalk') # optional - sage.rings.finite_rings [z*y^2 + y*x^2 + y*x + 3, - z*x + 8297*y^8*x^2 + 8297*y^8*x + 3556*y^7 - 8297*y^6*x^4 + 15409*y^6*x^3 - 8297*y^6*x^2 - - 8297*y^5*x^5 + 15409*y^5*x^4 - 8297*y^5*x^3 + 3556*y^5*x^2 + 3556*y^5*x + 3556*y^4*x^3 - + 3556*y^4*x^2 - 10668*y^4 - 10668*y^3*x - 8297*y^2*x^9 - 1185*y^2*x^8 + 14224*y^2*x^7 - - 1185*y^2*x^6 - 8297*y^2*x^5 - 14223*y*x^7 - 10666*y*x^6 - 10666*y*x^5 - 14223*y*x^4 - + x^5 + 2*x^4 + x^3, - y^9 - y^7*x^2 - y^7*x - y^6*x^3 - y^6*x^2 - 3*y^6 - 3*y^5*x - y^3*x^7 - 3*y^3*x^6 - - 3*y^3*x^5 - y^3*x^4 - 9*y^2*x^5 - 18*y^2*x^4 - 9*y^2*x^3 - 27*y*x^3 - 27*y*x^2 - 27*x] + z*x + 8297*y^8*x^2 + 8297*y^8*x + 3556*y^7 - 8297*y^6*x^4 + 15409*y^6*x^3 + - 8297*y^6*x^2 - 8297*y^5*x^5 + 15409*y^5*x^4 - 8297*y^5*x^3 + 3556*y^5*x^2 + + 3556*y^5*x + 3556*y^4*x^3 + 3556*y^4*x^2 - 10668*y^4 - 10668*y^3*x + - 8297*y^2*x^9 - 1185*y^2*x^8 + 14224*y^2*x^7 - 1185*y^2*x^6 - 8297*y^2*x^5 + - 14223*y*x^7 - 10666*y*x^6 - 10666*y*x^5 - 14223*y*x^4 + x^5 + 2*x^4 + x^3, + y^9 - y^7*x^2 - y^7*x - y^6*x^3 - y^6*x^2 - 3*y^6 - 3*y^5*x - y^3*x^7 + - 3*y^3*x^6 - 3*y^3*x^5 - y^3*x^4 - 9*y^2*x^5 - 18*y^2*x^4 - 9*y^2*x^3 + - 27*y*x^3 - 27*y*x^2 - 27*x] ALGORITHM: @@ -2149,12 +2195,12 @@ def transformed_basis(self, algorithm="gwalk", other_ring=None, singular=singula Check that this method works over QQbar (:trac:`25351`). We are not currently able to specify other_ring, due to the limitations of @handle_AA_and_QQbar:: - sage: R. = QQbar[] - sage: I = Ideal([y^3+x^2,x^2*y+x^2, x^3-x^2, z^4-x^2-y]) - sage: I = Ideal(I.groebner_basis()) - sage: S. = PolynomialRing(QQbar,3,order='lex') - sage: J = Ideal(I.transformed_basis('fglm',other_ring=S)) # known bug - sage: J # known bug + sage: R. = QQbar[] # optional - sage.rings.number_field + sage: I = Ideal([y^3 + x^2, x^2*y + x^2, x^3 - x^2, z^4 - x^2 - y]) # optional - sage.rings.number_field + sage: I = Ideal(I.groebner_basis()) # optional - sage.rings.number_field + sage: S. = PolynomialRing(QQbar, 3, order='lex') # optional - sage.rings.number_field + sage: J = Ideal(I.transformed_basis('fglm', other_ring=S)) # known bug # optional - sage.rings.number_field + sage: J # known bug # optional - sage.rings.number_field """ from sage.rings.polynomial.multi_polynomial_sequence import PolynomialSequence R = self.ring() @@ -2199,7 +2245,7 @@ def elimination_ideal(self, variables, algorithm=None, *args, **kwds): - ``variables`` -- a list or tuple of variables in ``self.ring()`` - ``algorithm`` - determines the algorithm to use, see below - for available algorithms. + for available algorithms. ALGORITHMS: @@ -2214,10 +2260,10 @@ def elimination_ideal(self, variables, algorithm=None, *args, **kwds): EXAMPLES:: sage: R. = PolynomialRing(QQ,5) - sage: I = R * [x-t,y-t^2,z-t^3,s-x+y^3] - sage: J = I.elimination_ideal([t,s]); J - Ideal (y^2 - x*z, x*y - z, x^2 - y) of Multivariate - Polynomial Ring in x, y, t, s, z over Rational Field + sage: I = R * [x - t, y - t^2, z - t^3, s - x + y^3] + sage: J = I.elimination_ideal([t, s]); J + Ideal (y^2 - x*z, x*y - z, x^2 - y) + of Multivariate Polynomial Ring in x, y, t, s, z over Rational Field You can use Giac to compute the elimination ideal:: @@ -2241,12 +2287,12 @@ def elimination_ideal(self, variables, algorithm=None, *args, **kwds): Check that this method works over QQbar (:trac:`25351`):: - sage: R. = QQbar[] - sage: I = R * [x-t,y-t^2,z-t^3,s-x+y^3] - sage: J = I.elimination_ideal([t,s]); J + sage: R. = QQbar[] # optional - sage.rings.number_field + sage: I = R * [x - t, y - t^2, z - t^3, s - x + y^3] # optional - sage.rings.number_field + sage: J = I.elimination_ideal([t, s]); J # optional - sage.rings.number_field Ideal (y^2 - x*z, x*y - z, x^2 - y) of Multivariate Polynomial Ring in x, y, t, s, z over Algebraic Field - sage: print("possible output from giac", flush=True); I.elimination_ideal([t, s], algorithm="giac") == J + sage: print("possible output from giac", flush=True); I.elimination_ideal([t, s], algorithm="giac") == J # optional - sage.rings.number_field possible output... True @@ -2316,15 +2362,15 @@ def quotient(self, J): EXAMPLES:: - sage: R. = PolynomialRing(GF(181),3) - sage: I = Ideal([x^2+x*y*z,y^2-z^3*y,z^3+y^5*x*z]) - sage: J = Ideal([x]) - sage: Q = I.quotient(J) - sage: y*z + x in I + sage: R. = PolynomialRing(GF(181), 3) # optional - sage.rings.finite_rings + sage: I = Ideal([x^2 + x*y*z, y^2 - z^3*y, z^3 + y^5*x*z]) # optional - sage.rings.finite_rings + sage: J = Ideal([x]) # optional - sage.rings.finite_rings + sage: Q = I.quotient(J) # optional - sage.rings.finite_rings + sage: y*z + x in I # optional - sage.rings.finite_rings False - sage: x in J + sage: x in J # optional - sage.rings.finite_rings True - sage: x * (y*z + x) in I + sage: x * (y*z + x) in I # optional - sage.rings.finite_rings True TESTS: @@ -2339,10 +2385,10 @@ def quotient(self, J): Check that this method works over QQbar (:trac:`25351`):: - sage: R. = QQbar[] - sage: I = ideal(x,z) - sage: J = ideal(R(1)) - sage: I.quotient(J) + sage: R. = QQbar[] # optional - sage.rings.number_field + sage: I = ideal(x, z) # optional - sage.rings.number_field + sage: J = ideal(R(1)) # optional - sage.rings.number_field + sage: I.quotient(J) # optional - sage.rings.number_field Ideal (z, x) of Multivariate Polynomial Ring in x, y, z over Algebraic Field Check that :trac:`12803` is fixed:: @@ -2379,9 +2425,7 @@ def saturation(self, other): - ``other`` -- another ideal in the same ring - OUTPUT: - - - a pair (ideal, integer) + OUTPUT: a pair (ideal, integer) EXAMPLES:: @@ -2395,10 +2439,10 @@ def saturation(self, other): Check that this method works over QQbar (:trac:`25351`):: - sage: R. = QQbar[] - sage: I = R.ideal(x^5*z^3, x*y*z, y*z^4) - sage: J = R.ideal(z) - sage: I.saturation(other = J) + sage: R. = QQbar[] # optional - sage.rings.number_field + sage: I = R.ideal(x^5*z^3, x*y*z, y*z^4) # optional - sage.rings.number_field + sage: J = R.ideal(z) # optional - sage.rings.number_field + sage: I.saturation(other = J) # optional - sage.rings.number_field (Ideal (y, x^5) of Multivariate Polynomial Ring in x, y, z over Algebraic Field, 4) """ from sage.libs.singular.function_factory import ff @@ -2412,7 +2456,7 @@ def variety(self, ring=None, *, algorithm="triangular_decomposition", proof=True r""" Return the variety of this ideal. - Given a zero-dimensional ideal `I` (== ``self``) of a + Given a zero-dimensional ideal `I` (= ``self``) of a polynomial ring `P` whose order is lexicographic, return the variety of `I` as a list of dictionaries with ``(variable, value)`` pairs. By default, the variety of the ideal over its @@ -2448,41 +2492,41 @@ def variety(self, ring=None, *, algorithm="triangular_decomposition", proof=True EXAMPLES:: - sage: K. = GF(27) # this example is from the MAGMA handbook - sage: P. = PolynomialRing(K, 2, order='lex') - sage: I = Ideal([ x^8 + y + 2, y^6 + x*y^5 + x^2 ]) - sage: I = Ideal(I.groebner_basis()); I - Ideal (x - y^47 - y^45 + y^44 - y^43 + y^41 - y^39 - y^38 - - y^37 - y^36 + y^35 - y^34 - y^33 + y^32 - y^31 + y^30 + - y^28 + y^27 + y^26 + y^25 - y^23 + y^22 + y^21 - y^19 - - y^18 - y^16 + y^15 + y^13 + y^12 - y^10 + y^9 + y^8 + y^7 - - y^6 + y^4 + y^3 + y^2 + y - 1, y^48 + y^41 - y^40 + y^37 - - y^36 - y^33 + y^32 - y^29 + y^28 - y^25 + y^24 + y^2 + y - + 1) of Multivariate Polynomial Ring in x, y over Finite - Field in w of size 3^3 - - sage: V = I.variety(); - sage: sorted(V, key=str) + sage: K. = GF(27) # this example is from the MAGMA handbook # optional - sage.rings.finite_rings + sage: P. = PolynomialRing(K, 2, order='lex') # optional - sage.rings.finite_rings + sage: I = Ideal([x^8 + y + 2, y^6 + x*y^5 + x^2]) # optional - sage.rings.finite_rings + sage: I = Ideal(I.groebner_basis()); I # optional - sage.rings.finite_rings + Ideal (x - y^47 - y^45 + y^44 - y^43 + y^41 - y^39 - y^38 - y^37 - y^36 + + y^35 - y^34 - y^33 + y^32 - y^31 + y^30 + y^28 + y^27 + y^26 + + y^25 - y^23 + y^22 + y^21 - y^19 - y^18 - y^16 + y^15 + y^13 + + y^12 - y^10 + y^9 + y^8 + y^7 - y^6 + y^4 + y^3 + y^2 + y - 1, + y^48 + y^41 - y^40 + y^37 - y^36 - y^33 + y^32 - y^29 + y^28 + - y^25 + y^24 + y^2 + y + 1) + of Multivariate Polynomial Ring in x, y over Finite Field in w of size 3^3 + + sage: V = I.variety(); # optional - sage.rings.finite_rings + sage: sorted(V, key=str) # optional - sage.rings.finite_rings [{y: w^2 + 2*w, x: 2*w + 2}, {y: w^2 + 2, x: 2*w}, {y: w^2 + w, x: 2*w + 1}] - sage: [f.subs(v) for f in I.gens() for v in V] # check that all polynomials vanish + sage: [f.subs(v) # check that all polynomials vanish # optional - sage.rings.finite_rings + ....: for f in I.gens() for v in V] [0, 0, 0, 0, 0, 0] - sage: [I.subs(v).is_zero() for v in V] # same test, but nicer syntax + sage: [I.subs(v).is_zero() for v in V] # same test, but nicer syntax # optional - sage.rings.finite_rings [True, True, True] However, we only account for solutions in the ground field and not in the algebraic closure:: - sage: I.vector_space_dimension() + sage: I.vector_space_dimension() # optional - sage.rings.finite_rings 48 Here we compute the points of intersection of a hyperbola and a circle, in several fields:: sage: K. = PolynomialRing(QQ, 2, order='lex') - sage: I = Ideal([ x*y - 1, (x-2)^2 + (y-1)^2 - 1]) + sage: I = Ideal([x*y - 1, (x-2)^2 + (y-1)^2 - 1]) sage: I = Ideal(I.groebner_basis()); I Ideal (x + y^3 - 2*y^2 + 4*y - 4, y^4 - 2*y^3 + 4*y^2 - 4*y + 1) - of Multivariate Polynomial Ring in x, y over Rational Field + of Multivariate Polynomial Ring in x, y over Rational Field These two curves have one rational intersection:: @@ -2494,7 +2538,7 @@ def variety(self, ring=None, *, algorithm="triangular_decomposition", proof=True sage: sorted(I.variety(ring=RR), key=str) [{y: 0.361103080528647, x: 2.76929235423863}, {y: 1.00000000000000, x: 1.00000000000000}] - sage: I.variety(ring=AA) + sage: I.variety(ring=AA) # optional - sage.rings.number_field [{y: 1, x: 1}, {y: 0.3611030805286474?, x: 2.769292354238632?}] @@ -2507,7 +2551,7 @@ def variety(self, ring=None, *, algorithm="triangular_decomposition", proof=True x: 0.11535382288068... + 0.58974280502220...*I}, {y: 0.36110308052864..., x: 2.7692923542386...}, {y: 1.00000000000000, x: 1.00000000000000}] - sage: sorted(I.variety(ring=QQbar), key=str) + sage: sorted(I.variety(ring=QQbar), key=str) # optional - sage.rings.number_field [{y: 0.3194484597356763? + 1.633170240915238?*I, x: 0.11535382288068429? - 0.5897428050222055?*I}, {y: 0.3194484597356763? - 1.633170240915238?*I, @@ -2519,7 +2563,7 @@ def variety(self, ring=None, *, algorithm="triangular_decomposition", proof=True to compute the variety. See :mod:`~sage.rings.polynomial.msolve` for more information. :: - sage: I.variety(RBF, algorithm='msolve', proof=False) # optional - msolve + sage: I.variety(RBF, algorithm='msolve', proof=False) # optional - msolve [{x: [2.76929235423863 +/- 2.08e-15], y: [0.361103080528647 +/- 4.53e-16]}, {x: 1.000000000000000, y: 1.000000000000000}] @@ -2542,9 +2586,9 @@ def variety(self, ring=None, *, algorithm="triangular_decomposition", proof=True If the ground field's characteristic is too large for Singular, we resort to a toy implementation:: - sage: R. = PolynomialRing(GF(2147483659^3),order='lex') - sage: I=ideal([x^3-2*y^2,3*x+y^4]) - sage: I.variety() + sage: R. = PolynomialRing(GF(2147483659^3), order='lex') # optional - sage.rings.finite_rings + sage: I = ideal([x^3 - 2*y^2, 3*x + y^4]) # optional - sage.rings.finite_rings + sage: I.variety() # optional - sage.rings.finite_rings verbose 0 (...: multi_polynomial_ideal.py, groebner_basis) Warning: falling back to very slow toy implementation. verbose 0 (...: multi_polynomial_ideal.py, dimension) Warning: falling back to very slow toy implementation. verbose 0 (...: multi_polynomial_ideal.py, variety) Warning: falling back to very slow toy implementation. @@ -2556,21 +2600,23 @@ def variety(self, ring=None, *, algorithm="triangular_decomposition", proof=True or even generator names as strings, when provided as keys:: sage: K. = QQ[] - sage: I = ideal([x^2+2*y-5,x+y+3]) - sage: v = I.variety(AA)[0]; v[x], v[y] + sage: I = ideal([x^2 + 2*y - 5, x + y + 3]) + sage: v = I.variety(AA)[0]; v[x], v[y] # optional - sage.rings.number_field (4.464101615137755?, -7.464101615137755?) - sage: list(v)[0].parent() + sage: list(v)[0].parent() # optional - sage.rings.number_field Multivariate Polynomial Ring in x, y over Algebraic Real Field - sage: v[x] + sage: v[x] # optional - sage.rings.number_field 4.464101615137755? - sage: v["y"] + sage: v["y"] # optional - sage.rings.number_field -7.464101615137755? - msolve also works over finite fields:: + ``msolve`` also works over finite fields:: - sage: R. = PolynomialRing(GF(536870909), 2, order='lex') - sage: I = Ideal([ x^2 - 1, y^2 - 1 ]) - sage: sorted(I.variety(algorithm='msolve', proof=False), key=str) # optional - msolve + sage: R. = PolynomialRing(GF(536870909), 2, order='lex') # optional - sage.rings.finite_rings + sage: I = Ideal([x^2 - 1, y^2 - 1]) # optional - sage.rings.finite_rings + sage: sorted(I.variety(algorithm='msolve', # optional - msolve # optional - sage.rings.finite_rings + ....: proof=False), + ....: key=str) [{x: 1, y: 1}, {x: 1, y: 536870908}, {x: 536870908, y: 1}, @@ -2579,9 +2625,9 @@ def variety(self, ring=None, *, algorithm="triangular_decomposition", proof=True but may fail in small characteristic, especially with ideals of high degree with respect to the characteristic:: - sage: R. = PolynomialRing(GF(3), 2, order='lex') - sage: I = Ideal([ x^2 - 1, y^2 - 1 ]) - sage: I.variety(algorithm='msolve', proof=False) # optional - msolve + sage: R. = PolynomialRing(GF(3), 2, order='lex') # optional - sage.rings.finite_rings + sage: I = Ideal([x^2 - 1, y^2 - 1]) # optional - sage.rings.finite_rings + sage: I.variety(algorithm='msolve', proof=False) # optional - msolve # optional - sage.rings.finite_rings Traceback (most recent call last): ... NotImplementedError: characteristic 3 too small @@ -2616,20 +2662,20 @@ def _variety_triangular_decomposition(self, ring): TESTS:: - sage: K. = GF(27) - sage: P. = PolynomialRing(K, 2, order='lex') - sage: I = Ideal([ x^8 + y + 2, y^6 + x*y^5 + x^2 ]) + sage: K. = GF(27) # optional - sage.rings.finite_rings + sage: P. = PolynomialRing(K, 2, order='lex') # optional - sage.rings.finite_rings + sage: I = Ideal([ x^8 + y + 2, y^6 + x*y^5 + x^2 ]) # optional - sage.rings.finite_rings Testing the robustness of the Singular interface:: - sage: T = I.triangular_decomposition('singular:triangLfak') - sage: sorted(I.variety(), key=str) + sage: T = I.triangular_decomposition('singular:triangLfak') # optional - sage.rings.finite_rings + sage: sorted(I.variety(), key=str) # optional - sage.rings.finite_rings [{y: w^2 + 2*w, x: 2*w + 2}, {y: w^2 + 2, x: 2*w}, {y: w^2 + w, x: 2*w + 1}] Testing that a bug is indeed fixed :: - sage: R = PolynomialRing(GF(2), 30, ['x%d'%(i+1) for i in range(30)], order='lex') - sage: R.inject_variables() + sage: R = PolynomialRing(GF(2), 30, ['x%d'%(i+1) for i in range(30)], order='lex') # optional - sage.rings.finite_rings + sage: R.inject_variables() # optional - sage.rings.finite_rings Defining... sage: I = Ideal([x1 + 1, x2, x3 + 1, x5*x10 + x10 + x18, x5*x11 + x11, \ x5*x18, x6, x7 + 1, x9, x10*x11 + x10 + x18, x10*x18 + x18, \ @@ -2640,10 +2686,10 @@ def _variety_triangular_decomposition(self, ring): x11^2 + x11, x12^2 + x12, x13^2 + x13, x14^2 + x14, x15^2 + x15, \ x16^2 + x16, x17^2 + x17, x18^2 + x18, x19^2 + x19, x20^2 + x20, \ x21^2 + x21, x22^2 + x22, x23^2 + x23, x24^2 + x24, x25^2 + x25, \ - x26^2 + x26, x27^2 + x27, x28^2 + x28, x29^2 + x29, x30^2 + x30]) + x26^2 + x26, x27^2 + x27, x28^2 + x28, x29^2 + x29, x30^2 + x30]) # optional - sage.rings.finite_rings sage: I.basis_is_groebner() True - sage: sorted("".join(str(V[g]) for g in R.gens()) for V in I.variety()) # long time (6s on sage.math, 2011) + sage: sorted("".join(str(V[g]) for g in R.gens()) for V in I.variety()) # long time (6s on sage.math, 2011) # optional - sage.rings.finite_rings ['101000100000000110001000100110', '101000100000000110001000101110', '101000100100000101001000100110', @@ -2696,7 +2742,7 @@ def _variety_triangular_decomposition(self, ring): sage: R. = PolynomialRing(QQ, order='lex') sage: I = R.ideal(c^2-2, b-c, a) - sage: I.variety(QQbar) + sage: I.variety(QQbar) # optional - sage.rings.number_field [...a: 0...] An early version of :trac:`25351` broke this method by adding the @@ -2704,13 +2750,13 @@ def _variety_triangular_decomposition(self, ring): that this circle and this hyperbola have two real intersections and two more complex ones:: - sage: K. = PolynomialRing(AA) - sage: I = Ideal([ x*y - 1, (x-2)^2 + (y-1)^2 - 1]) - sage: len(I.variety()) + sage: K. = PolynomialRing(AA) # optional - sage.rings.number_field + sage: I = Ideal([ x*y - 1, (x-2)^2 + (y-1)^2 - 1]) # optional - sage.rings.number_field + sage: len(I.variety()) # optional - sage.rings.number_field 2 - sage: K. = PolynomialRing(QQbar) - sage: I = Ideal([ x*y - 1, (x-2)^2 + (y-1)^2 - 1]) - sage: len(I.variety()) + sage: K. = PolynomialRing(QQbar) # optional - sage.rings.number_field + sage: I = Ideal([ x*y - 1, (x-2)^2 + (y-1)^2 - 1]) # optional - sage.rings.number_field + sage: len(I.variety()) # optional - sage.rings.number_field 4 """ @@ -2789,38 +2835,40 @@ def hilbert_polynomial(self, algorithm='sage'): `R = \bigoplus_d R_d` (which is ``self.ring()``) be a graded commutative algebra over a field `K`. The *Hilbert polynomial* is the unique polynomial `HP(t)` with rational coefficients - such that `HP(d) = dim_K R_d` for all but finitely many + such that `HP(d) = \dim_K R_d` for all but finitely many positive integers `d`. EXAMPLES:: sage: P. = PolynomialRing(QQ) sage: I = Ideal([x^3*y^2 + 3*x^2*y^2*z + y^3*z^2 + z^5]) - sage: I.hilbert_polynomial() + sage: I.hilbert_polynomial() # optional - sage.libs.flint 5*t - 5 Of course, the Hilbert polynomial of a zero-dimensional ideal is zero:: - sage: J0 = Ideal([x^3*y^2 + 3*x^2*y^2*z + y^3*z^2 + z^5, y^3-2*x*z^2+x*y,x^4+x*y-y*z^2]) + sage: J0 = Ideal([x^3*y^2 + 3*x^2*y^2*z + y^3*z^2 + z^5, + ....: y^3 - 2*x*z^2 + x*y, x^4 + x*y - y*z^2]) sage: J = P*[m.lm() for m in J0.groebner_basis()] sage: J.dimension() 0 - sage: J.hilbert_polynomial() + sage: J.hilbert_polynomial() # optional - sage.libs.flint 0 It is possible to request a computation using the Singular library:: - sage: I.hilbert_polynomial(algorithm = 'singular') == I.hilbert_polynomial() + sage: I.hilbert_polynomial(algorithm='singular') == I.hilbert_polynomial() # optional - sage.libs.flint sage.libs.singular True - sage: J.hilbert_polynomial(algorithm = 'singular') == J.hilbert_polynomial() + sage: J.hilbert_polynomial(algorithm='singular') == J.hilbert_polynomial() # optional - sage.libs.flint sage.libs.singular True Here is a bigger examples:: - sage: n = 4; m = 11; P = PolynomialRing(QQ, n * m, "x"); x = P.gens(); M = Matrix(n, x) + sage: n = 4; m = 11; P = PolynomialRing(QQ, n * m, "x"); x = P.gens() + sage: M = Matrix(n, x) sage: Minors = P.ideal(M.minors(2)) - sage: hp = Minors.hilbert_polynomial(); hp + sage: hp = Minors.hilbert_polynomial(); hp # optional - sage.libs.flint 1/21772800*t^13 + 61/21772800*t^12 + 1661/21772800*t^11 + 26681/21772800*t^10 + 93841/7257600*t^9 + 685421/7257600*t^8 + 1524809/3110400*t^7 + 39780323/21772800*t^6 + 6638071/1360800*t^5 @@ -2831,7 +2879,7 @@ def hilbert_polynomial(self, algorithm='sage'): with Singular. We don't test it here, as it has a side-effect on other tests that is not understood yet (see :trac:`26300`):: - sage: Minors.hilbert_polynomial(algorithm = 'singular') # not tested + sage: Minors.hilbert_polynomial(algorithm='singular') # not tested # optional - sage.libs.singular Traceback (most recent call last): ... RuntimeError: error in Singular function call 'hilbPoly': @@ -2842,9 +2890,10 @@ def hilbert_polynomial(self, algorithm='sage'): Note that in this example, the Hilbert polynomial gives the coefficients of the Hilbert-Poincaré series in all degrees:: - sage: P = PowerSeriesRing(QQ, 't', default_prec = 50) - sage: hs = Minors.hilbert_series() - sage: list(P(hs.numerator()) / P(hs.denominator())) == [hp(t = k) for k in range(50)] + sage: P = PowerSeriesRing(QQ, 't', default_prec=50) + sage: hs = Minors.hilbert_series() # optional - sage.libs.flint + sage: list(P(hs.numerator()) / P(hs.denominator())) == [hp(t=k) # optional - sage.libs.flint + ....: for k in range(50)] True TESTS: @@ -2853,23 +2902,23 @@ def hilbert_polynomial(self, algorithm='sage'): sage: P. = PolynomialRing(QQ) sage: I = Ideal([x^3, x*y^2, y^4, x^2*y*z, y^3*z, x^2*z^2, x*y*z^2, x*z^3]) - sage: I.hilbert_polynomial(algorithm='singular') + sage: I.hilbert_polynomial(algorithm='singular') # optional - sage.libs.singular 3 - sage: I.hilbert_polynomial() + sage: I.hilbert_polynomial() # optional - sage.libs.flint 3 - Check that this method works over QQbar (:trac:`25351`):: + Check that this method works over ``QQbar`` (:trac:`25351`):: - sage: P. = QQbar[] - sage: I = Ideal([x^3*y^2 + 3*x^2*y^2*z + y^3*z^2 + z^5]) - sage: I.hilbert_polynomial() + sage: P. = QQbar[] # optional - sage.rings.number_field + sage: I = Ideal([x^3*y^2 + 3*x^2*y^2*z + y^3*z^2 + z^5]) # optional - sage.rings.number_field + sage: I.hilbert_polynomial() # optional - sage.rings.number_field 5*t - 5 Check for :trac:`33597`:: sage: R. = QQ[] sage: I = R.ideal([X^2*Y^3, X*Z]) - sage: I.hilbert_polynomial() + sage: I.hilbert_polynomial() # optional - sage.libs.flint t + 5 """ if not self.is_homogeneous(): @@ -2915,13 +2964,13 @@ def hilbert_series(self, grading=None, algorithm='sage'): Let `I` (which is ``self``) be a homogeneous ideal and `R = \bigoplus_d R_d` (which is ``self.ring()``) be a graded commutative algebra over a field `K`. Then the - *Hilbert function* is defined as `H(d) = dim_K R_d` and + *Hilbert function* is defined as `H(d) = \dim_K R_d` and the *Hilbert series* of `I` is defined as the formal power series `HS(t) = \sum_{d=0}^{\infty} H(d) t^d`. This power series can be expressed as `HS(t) = Q(t) / (1-t)^n` where `Q(t)` is a polynomial - over `Z` and `n` the number of variables in `R`. + over `\ZZ` and `n` the number of variables in `R`. This method returns `Q(t) / (1-t)^n`, normalised so that the leading monomial of the numerator is positive. @@ -2932,48 +2981,48 @@ def hilbert_series(self, grading=None, algorithm='sage'): sage: P. = PolynomialRing(QQ) sage: I = Ideal([x^3*y^2 + 3*x^2*y^2*z + y^3*z^2 + z^5]) - sage: I.hilbert_series() + sage: I.hilbert_series() # optional - sage.libs.flint (t^4 + t^3 + t^2 + t + 1)/(t^2 - 2*t + 1) sage: R. = PolynomialRing(QQ) - sage: J = R.ideal([a^2*b,a*b^2]) - sage: J.hilbert_series() + sage: J = R.ideal([a^2*b, a*b^2]) + sage: J.hilbert_series() # optional - sage.libs.flint (t^3 - t^2 - t - 1)/(t - 1) - sage: J.hilbert_series(grading=(10,3)) + sage: J.hilbert_series(grading=(10,3)) # optional - sage.libs.flint (t^25 + t^24 + t^23 - t^15 - t^14 - t^13 - t^12 - t^11 - t^10 - t^9 - t^8 - t^7 - t^6 - t^5 - t^4 - t^3 - t^2 - t - 1)/(t^12 + t^11 + t^10 - t^2 - t - 1) sage: K = R.ideal([a^2*b^3, a*b^4 + a^3*b^2]) - sage: K.hilbert_series(grading=[1,2]) + sage: K.hilbert_series(grading=[1,2]) # optional - sage.libs.flint (t^11 + t^8 - t^6 - t^5 - t^4 - t^3 - t^2 - t - 1)/(t^2 - 1) - sage: K.hilbert_series(grading=[2,1]) + sage: K.hilbert_series(grading=[2,1]) # optional - sage.libs.flint (2*t^7 - t^6 - t^4 - t^2 - 1)/(t - 1) TESTS:: - sage: I.hilbert_series() == I.hilbert_series(algorithm = 'singular') + sage: I.hilbert_series() == I.hilbert_series(algorithm='singular') # optional - sage.libs.flint sage.libs.singular True - sage: J.hilbert_series() == J.hilbert_series(algorithm = 'singular') + sage: J.hilbert_series() == J.hilbert_series(algorithm='singular') # optional - sage.libs.flint sage.libs.singular True - sage: J.hilbert_series(grading = (10,3)) == J.hilbert_series(grading = (10,3), algorithm = 'singular') + sage: J.hilbert_series(grading=(10,3)) == J.hilbert_series(grading=(10,3), algorithm='singular') # optional - sage.libs.flint sage.libs.singular True - sage: K.hilbert_series(grading = (1,2)) == K.hilbert_series(grading = (1,2), algorithm = 'singular') + sage: K.hilbert_series(grading=(1,2)) == K.hilbert_series(grading=(1,2), algorithm='singular') # optional - sage.libs.flint sage.libs.singular True - sage: K.hilbert_series(grading = (2,1)) == K.hilbert_series(grading = (2,1), algorithm = 'singular') + sage: K.hilbert_series(grading=(2,1)) == K.hilbert_series(grading=(2,1), algorithm='singular') # optional - sage.libs.flint sage.libs.singular True sage: P. = PolynomialRing(QQ) sage: I = Ideal([x^3*y^2 + 3*x^2*y^2*z + y^3*z^2 + z^5]) - sage: I.hilbert_series(grading=5) + sage: I.hilbert_series(grading=5) # optional - sage.libs.flint Traceback (most recent call last): ... TypeError: grading must be a list or a tuple of integers Check that this method works over QQbar (:trac:`25351`):: - sage: P. = QQbar[] - sage: I = Ideal([x^3*y^2 + 3*x^2*y^2*z + y^3*z^2 + z^5]) - sage: I.hilbert_series() + sage: P. = QQbar[] # optional - sage.rings.number_field + sage: I = Ideal([x^3*y^2 + 3*x^2*y^2*z + y^3*z^2 + z^5]) # optional - sage.rings.number_field + sage: I.hilbert_series() # optional - sage.rings.number_field (t^4 + t^3 + t^2 + t + 1)/(t^2 - 2*t + 1) """ if not self.is_homogeneous(): @@ -3016,13 +3065,13 @@ def hilbert_numerator(self, grading = None, algorithm = 'sage'): Let `I` (which is ``self``) be a homogeneous ideal and `R = \bigoplus_d R_d` (which is ``self.ring()``) be a graded commutative algebra over a field `K`. Then the - *Hilbert function* is defined as `H(d) = dim_K R_d` and + *Hilbert function* is defined as `H(d) = \dim_K R_d` and the *Hilbert series* of `I` is defined as the formal power series `HS(t) = \sum_{d=0}^{\infty} H(d) t^d`. This power series can be expressed as `HS(t) = Q(t) / (1-t)^n` where `Q(t)` is a polynomial - over `Z` and `n` the number of variables in `R`. This + over `\ZZ` and `n` the number of variables in `R`. This method returns `Q(t)`, the numerator; hence the name, ``hilbert_numerator``. An optional ``grading`` can be given, in which case the graded (or weighted) Hilbert numerator is given. @@ -3031,29 +3080,29 @@ def hilbert_numerator(self, grading = None, algorithm = 'sage'): sage: P. = PolynomialRing(QQ) sage: I = Ideal([x^3*y^2 + 3*x^2*y^2*z + y^3*z^2 + z^5]) - sage: I.hilbert_numerator() + sage: I.hilbert_numerator() # optional - sage.libs.flint -t^5 + 1 sage: R. = PolynomialRing(QQ) - sage: J = R.ideal([a^2*b,a*b^2]) - sage: J.hilbert_numerator() + sage: J = R.ideal([a^2*b, a*b^2]) + sage: J.hilbert_numerator() # optional - sage.libs.flint t^4 - 2*t^3 + 1 - sage: J.hilbert_numerator(grading=(10,3)) + sage: J.hilbert_numerator(grading=(10,3)) # optional - sage.libs.flint t^26 - t^23 - t^16 + 1 TESTS:: - sage: I.hilbert_numerator() == I.hilbert_numerator(algorithm = 'singular') + sage: I.hilbert_numerator() == I.hilbert_numerator(algorithm='singular') # optional - sage.libs.flint sage.libs.singular True - sage: J.hilbert_numerator() == J.hilbert_numerator(algorithm = 'singular') + sage: J.hilbert_numerator() == J.hilbert_numerator(algorithm='singular') # optional - sage.libs.flint sage.libs.singular True - sage: J.hilbert_numerator(grading=(10,3)) == J.hilbert_numerator(grading=(10,3), algorithm = 'singular') + sage: J.hilbert_numerator(grading=(10,3)) == J.hilbert_numerator(grading=(10,3), algorithm='singular') # optional - sage.libs.flint sage.libs.singular True Check that this method works over QQbar (:trac:`25351`):: - sage: P. = QQbar[] - sage: I = Ideal([x^3*y^2 + 3*x^2*y^2*z + y^3*z^2 + z^5]) - sage: I.hilbert_numerator() + sage: P. = QQbar[] # optional - sage.rings.number_field + sage: I = Ideal([x^3*y^2 + 3*x^2*y^2*z + y^3*z^2 + z^5]) # optional - sage.rings.number_field + sage: I.hilbert_numerator() # optional - sage.rings.number_field -t^5 + 1 Our two algorithms should always agree; not tested until @@ -3191,7 +3240,7 @@ def normal_basis(self, degree=None, algorithm='libsingular', EXAMPLES:: sage: R. = PolynomialRing(QQ) - sage: I = R.ideal(x^2+y^2+z^2-4, x^2+2*y^2-5, x*z-1) + sage: I = R.ideal(x^2 + y^2 + z^2 - 4, x^2 + 2*y^2 - 5, x*z - 1) sage: I.normal_basis() [y*z^2, z^2, y*z, z, x*y, y, x, 1] sage: I.normal_basis(algorithm='singular') @@ -3201,7 +3250,7 @@ def normal_basis(self, degree=None, algorithm='libsingular', particularly useful when the quotient ring is not finite-dimensional as a vector space. :: - sage: J = R.ideal(x^2+y^2+z^2-4, x^2+2*y^2-5) + sage: J = R.ideal(x^2 + y^2 + z^2 - 4, x^2 + 2*y^2 - 5) sage: J.dimension() 1 sage: [J.normal_basis(d) for d in (0..3)] @@ -3223,19 +3272,19 @@ def normal_basis(self, degree=None, algorithm='libsingular', Check that this method works over QQbar (:trac:`25351`):: - sage: R. = QQbar[] - sage: I = R.ideal(x^2+y^2+z^2-4, x^2+2*y^2-5, x*z-1) - sage: I.normal_basis() + sage: R. = QQbar[] # optional - sage.rings.number_field + sage: I = R.ideal(x^2+y^2+z^2-4, x^2+2*y^2-5, x*z-1) # optional - sage.rings.number_field + sage: I.normal_basis() # optional - sage.rings.number_field [y*z^2, z^2, y*z, z, x*y, y, x, 1] - sage: J = R.ideal(x^2+y^2+z^2-4, x^2+2*y^2-5) - sage: [J.normal_basis(d) for d in (0..3)] + sage: J = R.ideal(x^2+y^2+z^2-4, x^2+2*y^2-5) # optional - sage.rings.number_field + sage: [J.normal_basis(d) for d in (0..3)] # optional - sage.rings.number_field [[1], [z, y, x], [z^2, y*z, x*z, x*y], [z^3, y*z^2, x*z^2, x*y*z]] Check the option ``algorithm="singular"`` with a weighted term order:: sage: T = TermOrder('wdegrevlex', (1, 2, 3)) - sage: S. = PolynomialRing(GF(2), order=T) - sage: S.ideal(x^6 + y^3 + z^2).normal_basis(6, algorithm='singular') + sage: S. = PolynomialRing(GF(2), order=T) # optional - sage.rings.finite_rings + sage: S.ideal(x^6 + y^3 + z^2).normal_basis(6, algorithm='singular') # optional - sage.rings.finite_rings [x^4*y, x^2*y^2, y^3, x^3*z, x*y*z, z^2] """ from sage.rings.polynomial.multi_polynomial_sequence import PolynomialSequence @@ -3315,14 +3364,14 @@ def _groebner_basis_macaulay2(self, strategy=None): Over finite fields, Macaulay2 supports different algorithms to compute Gröbner bases:: - sage: R = PolynomialRing(GF(101), 'x', 4) - sage: I = sage.rings.ideal.Cyclic(R) - sage: gb1 = I.groebner_basis('macaulay2:gb') # optional - macaulay2 - sage: I = sage.rings.ideal.Cyclic(R) - sage: gb2 = I.groebner_basis('macaulay2:mgb') # optional - macaulay2 - sage: I = sage.rings.ideal.Cyclic(R) - sage: gb3 = I.groebner_basis('macaulay2:f4') # optional - macaulay2 - sage: gb1 == gb2 == gb3 # optional - macaulay2 + sage: R = PolynomialRing(GF(101), 'x', 4) # optional - sage.rings.finite_rings + sage: I = sage.rings.ideal.Cyclic(R) # optional - sage.rings.finite_rings + sage: gb1 = I.groebner_basis('macaulay2:gb') # optional - macaulay2 # optional - sage.rings.finite_rings + sage: I = sage.rings.ideal.Cyclic(R) # optional - sage.rings.finite_rings + sage: gb2 = I.groebner_basis('macaulay2:mgb') # optional - macaulay2 # optional - sage.rings.finite_rings + sage: I = sage.rings.ideal.Cyclic(R) # optional - sage.rings.finite_rings + sage: gb3 = I.groebner_basis('macaulay2:f4') # optional - macaulay2 # optional - sage.rings.finite_rings + sage: gb1 == gb2 == gb3 # optional - macaulay2 # optional - sage.rings.finite_rings True TESTS:: @@ -3380,26 +3429,32 @@ def __init__(self, ring, gens, coerce=True, side = "left"): - ``gens`` - the generators of this ideal - ``coerce`` (optional - default True) - generators are coerced into the ring before creating the ideal - - ``side`` - optional string, either "left" (default) - or "twosided"; defines whether this ideal is left + - ``side`` - optional string, either ``"left"`` (default) + or ``"twosided"``; defines whether this ideal is left of two-sided. EXAMPLES:: - sage: A. = FreeAlgebra(QQ, 3) - sage: H = A.g_algebra({y*x:x*y-z, z*x:x*z+2*x, z*y:y*z-2*y}) - sage: H.inject_variables() + sage: A. = FreeAlgebra(QQ, 3) # optional - sage.combinat sage.modules + sage: H = A.g_algebra({y*x: x*y-z, z*x: x*z+2*x, z*y: y*z-2*y}) # optional - sage.combinat sage.modules + sage: H.inject_variables() # optional - sage.combinat sage.modules Defining x, y, z - sage: I = H.ideal([y^2, x^2, z^2-H.one()],coerce=False) # indirect doctest - sage: I #random - Left Ideal (y^2, x^2, z^2 - 1) of Noncommutative Multivariate Polynomial Ring in x, y, z over Rational Field, nc-relations: {z*x: x*z + 2*x, z*y: y*z - 2*y, y*x: x*y - z} - sage: sorted(I.gens(),key=str) + sage: I = H.ideal([y^2, x^2, z^2 - H.one()], # indirect doctest # optional - sage.combinat sage.modules + ....: coerce=False) + sage: I # random # optional - sage.combinat sage.modules + Left Ideal (y^2, x^2, z^2 - 1) of + Noncommutative Multivariate Polynomial Ring in x, y, z over Rational Field, + nc-relations: {z*x: x*z + 2*x, z*y: y*z - 2*y, y*x: x*y - z} + sage: sorted(I.gens(), key=str) # optional - sage.combinat sage.modules [x^2, y^2, z^2 - 1] - sage: H.ideal([y^2, x^2, z^2-H.one()], side="twosided") #random - Twosided Ideal (y^2, x^2, z^2 - 1) of Noncommutative Multivariate Polynomial Ring in x, y, z over Rational Field, nc-relations: {z*x: x*z + 2*x, z*y: y*z - 2*y, y*x: x*y - z} - sage: sorted(H.ideal([y^2, x^2, z^2-H.one()], side="twosided").gens(),key=str) + sage: H.ideal([y^2, x^2, z^2 - H.one()], side="twosided") # random # optional - sage.combinat sage.modules + Twosided Ideal (y^2, x^2, z^2 - 1) of + Noncommutative Multivariate Polynomial Ring in x, y, z over Rational Field, + nc-relations: {z*x: x*z + 2*x, z*y: y*z - 2*y, y*x: x*y - z} + sage: sorted(H.ideal([y^2, x^2, z^2 - H.one()], side="twosided").gens(), # optional - sage.combinat sage.modules + ....: key=str) [x^2, y^2, z^2 - 1] - sage: H.ideal([y^2, x^2, z^2-H.one()], side="right") + sage: H.ideal([y^2, x^2, z^2 - H.one()], side="right") # optional - sage.combinat sage.modules Traceback (most recent call last): ... ValueError: Only left and two-sided ideals are allowed. @@ -3424,14 +3479,15 @@ def __call_singular(self, cmd, arg = None): EXAMPLES:: - sage: A. = FreeAlgebra(QQ, 3) - sage: H = A.g_algebra({y*x:x*y-z, z*x:x*z+2*x, z*y:y*z-2*y}) - sage: H.inject_variables() + sage: A. = FreeAlgebra(QQ, 3) # optional - sage.combinat sage.modules + sage: H = A.g_algebra({y*x: x*y-z, z*x: x*z+2*x, z*y: y*z-2*y}) # optional - sage.combinat sage.modules + sage: H.inject_variables() # optional - sage.combinat sage.modules Defining x, y, z - sage: id = H.ideal(x + y, y + z) - sage: id.std() # indirect doctest # random - Left Ideal (z, y, x) of Noncommutative Multivariate Polynomial Ring in x, y, z over Rational Field, nc-relations: {z*x: x*z + 2*x, z*y: y*z - 2*y, y*x: x*y - z} - sage: sorted(id.std().gens(),key=str) + sage: id = H.ideal(x + y, y + z) # optional - sage.combinat sage.modules + sage: id.std() # indirect doctest # random # optional - sage.combinat sage.modules + Left Ideal (z, y, x) of Noncommutative Multivariate Polynomial Ring in x, y, z over Rational Field, + nc-relations: {z*x: x*z + 2*x, z*y: y*z - 2*y, y*x: x*y - z} + sage: sorted(id.std().gens(), key=str) # optional - sage.combinat sage.modules [x, y, z] """ from sage.libs.singular.function import singular_function @@ -3444,47 +3500,61 @@ def __call_singular(self, cmd, arg = None): @cached_method def std(self): r""" - Computes a GB of the ideal. It is two-sided if and only if the ideal is two-sided. + Compute a GB of the ideal. It is two-sided if and only if the ideal is two-sided. EXAMPLES:: - sage: A. = FreeAlgebra(QQ, 3) - sage: H = A.g_algebra({y*x:x*y-z, z*x:x*z+2*x, z*y:y*z-2*y}) - sage: H.inject_variables() + sage: A. = FreeAlgebra(QQ, 3) # optional - sage.combinat sage.modules + sage: H = A.g_algebra({y*x: x*y-z, z*x: x*z+2*x, z*y: y*z-2*y}) # optional - sage.combinat sage.modules + sage: H.inject_variables() # optional - sage.combinat sage.modules Defining x, y, z - sage: I = H.ideal([y^2, x^2, z^2-H.one()],coerce=False) - sage: I.std() #random - Left Ideal (z^2 - 1, y*z - y, x*z + x, y^2, 2*x*y - z - 1, x^2) of Noncommutative Multivariate Polynomial Ring in x, y, z over Rational Field, nc-relations: {z*x: x*z + 2*x, z*y: y*z - 2*y, y*x: x*y - z} - sage: sorted(I.std().gens(),key=str) + sage: I = H.ideal([y^2, x^2, z^2 - H.one()], coerce=False) # optional - sage.combinat sage.modules + sage: I.std() #random # optional - sage.combinat sage.modules + Left Ideal (z^2 - 1, y*z - y, x*z + x, y^2, 2*x*y - z - 1, x^2) of + Noncommutative Multivariate Polynomial Ring in x, y, z over Rational Field, + nc-relations: {z*x: x*z + 2*x, z*y: y*z - 2*y, y*x: x*y - z} + sage: sorted(I.std().gens(), key=str) # optional - sage.combinat sage.modules [2*x*y - z - 1, x*z + x, x^2, y*z - y, y^2, z^2 - 1] - If the ideal is a left ideal, then std returns a left + If the ideal is a left ideal, then :meth:`std` returns a left Groebner basis. But if it is a two-sided ideal, then - the output of std and :meth:`twostd` coincide:: - - sage: JL = H.ideal([x^3, y^3, z^3 - 4*z]) - sage: JL #random - Left Ideal (x^3, y^3, z^3 - 4*z) of Noncommutative Multivariate Polynomial Ring in x, y, z over Rational Field, nc-relations: {z*x: x*z + 2*x, z*y: y*z - 2*y, y*x: x*y - z} - sage: sorted(JL.gens(),key=str) + the output of :meth:`std` and :meth:`twostd` coincide:: + + sage: JL = H.ideal([x^3, y^3, z^3 - 4*z]) # optional - sage.combinat sage.modules + sage: JL #random # optional - sage.combinat sage.modules + Left Ideal (x^3, y^3, z^3 - 4*z) of + Noncommutative Multivariate Polynomial Ring in x, y, z over Rational Field, + nc-relations: {z*x: x*z + 2*x, z*y: y*z - 2*y, y*x: x*y - z} + sage: sorted(JL.gens(), key=str) # optional - sage.combinat sage.modules [x^3, y^3, z^3 - 4*z] - sage: JL.std() #random - Left Ideal (z^3 - 4*z, y*z^2 - 2*y*z, x*z^2 + 2*x*z, 2*x*y*z - z^2 - 2*z, y^3, x^3) of Noncommutative Multivariate Polynomial Ring in x, y, z over Rational Field, nc-relations: {z*x: x*z + 2*x, z*y: y*z - 2*y, y*x: x*y - z} - sage: sorted(JL.std().gens(),key=str) + sage: JL.std() # random # optional - sage.combinat sage.modules + Left Ideal (z^3 - 4*z, y*z^2 - 2*y*z, + x*z^2 + 2*x*z, 2*x*y*z - z^2 - 2*z, y^3, x^3) of + Noncommutative Multivariate Polynomial Ring in x, y, z over Rational Field, + nc-relations: {z*x: x*z + 2*x, z*y: y*z - 2*y, y*x: x*y - z} + sage: sorted(JL.std().gens(), key=str) # optional - sage.combinat sage.modules [2*x*y*z - z^2 - 2*z, x*z^2 + 2*x*z, x^3, y*z^2 - 2*y*z, y^3, z^3 - 4*z] - sage: JT = H.ideal([x^3, y^3, z^3 - 4*z], side='twosided') - sage: JT #random - Twosided Ideal (x^3, y^3, z^3 - 4*z) of Noncommutative Multivariate Polynomial Ring in x, y, z over Rational Field, nc-relations: {z*x: x*z + 2*x, z*y: y*z - 2*y, y*x: x*y - z} - sage: sorted(JT.gens(),key=str) + sage: JT = H.ideal([x^3, y^3, z^3 - 4*z], side='twosided') # optional - sage.combinat sage.modules + sage: JT #random # optional - sage.combinat sage.modules + Twosided Ideal (x^3, y^3, z^3 - 4*z) of + Noncommutative Multivariate Polynomial Ring in x, y, z over Rational Field, + nc-relations: {z*x: x*z + 2*x, z*y: y*z - 2*y, y*x: x*y - z} + sage: sorted(JT.gens(), key=str) # optional - sage.combinat sage.modules [x^3, y^3, z^3 - 4*z] - sage: JT.std() #random - Twosided Ideal (z^3 - 4*z, y*z^2 - 2*y*z, x*z^2 + 2*x*z, y^2*z - 2*y^2, 2*x*y*z - z^2 - 2*z, x^2*z + 2*x^2, y^3, x*y^2 - y*z, x^2*y - x*z - 2*x, x^3) of Noncommutative Multivariate Polynomial Ring in x, y, z over Rational Field, nc-relations: {z*x: x*z + 2*x, z*y: y*z - 2*y, y*x: x*y - z} - sage: sorted(JT.std().gens(),key=str) - [2*x*y*z - z^2 - 2*z, x*y^2 - y*z, x*z^2 + 2*x*z, x^2*y - x*z - 2*x, x^2*z + 2*x^2, x^3, y*z^2 - 2*y*z, y^2*z - 2*y^2, y^3, z^3 - 4*z] - sage: JT.std() == JL.twostd() + sage: JT.std() #random # optional - sage.combinat sage.modules + Twosided Ideal (z^3 - 4*z, y*z^2 - 2*y*z, x*z^2 + 2*x*z, + y^2*z - 2*y^2, 2*x*y*z - z^2 - 2*z, x^2*z + 2*x^2, + y^3, x*y^2 - y*z, x^2*y - x*z - 2*x, x^3) of + Noncommutative Multivariate Polynomial Ring in x, y, z over Rational Field, + nc-relations: {z*x: x*z + 2*x, z*y: y*z - 2*y, y*x: x*y - z} + sage: sorted(JT.std().gens(), key=str) # optional - sage.combinat sage.modules + [2*x*y*z - z^2 - 2*z, x*y^2 - y*z, x*z^2 + 2*x*z, x^2*y - x*z - 2*x, + x^2*z + 2*x^2, x^3, y*z^2 - 2*y*z, y^2*z - 2*y^2, y^3, z^3 - 4*z] + sage: JT.std() == JL.twostd() # optional - sage.combinat sage.modules True - ALGORITHM: Uses Singular's std command + ALGORITHM: Uses Singular's ``std`` command """ if self.side() == 'twosided': return self.twostd() @@ -3494,25 +3564,30 @@ def std(self): def elimination_ideal(self, variables): r""" Return the elimination ideal of this ideal with respect to the - variables given in "variables". + variables given in ``variables``. EXAMPLES:: - sage: A. = FreeAlgebra(QQ, 3) - sage: H = A.g_algebra({y*x:x*y-z, z*x:x*z+2*x, z*y:y*z-2*y}) - sage: H.inject_variables() + sage: A. = FreeAlgebra(QQ, 3) # optional - sage.combinat sage.modules + sage: H = A.g_algebra({y*x: x*y-z, z*x: x*z+2*x, z*y: y*z-2*y}) # optional - sage.combinat sage.modules + sage: H.inject_variables() # optional - sage.combinat sage.modules Defining x, y, z - sage: I = H.ideal([y^2, x^2, z^2-H.one()],coerce=False) - sage: I.elimination_ideal([x, z]) - Left Ideal (y^2) of Noncommutative Multivariate Polynomial Ring in x, y, z over Rational Field, nc-relations: {...} - sage: J = I.twostd() - sage: J - Twosided Ideal (z^2 - 1, y*z - y, x*z + x, y^2, 2*x*y - z - 1, x^2) of Noncommutative Multivariate Polynomial Ring in x, y, z over Rational Field, nc-relations: {...} - sage: J.elimination_ideal([x, z]) - Twosided Ideal (y^2) of Noncommutative Multivariate Polynomial Ring in x, y, z over Rational Field, nc-relations: {...} - - - ALGORITHM: Uses Singular's eliminate command + sage: I = H.ideal([y^2, x^2, z^2 - H.one()], coerce=False) # optional - sage.combinat sage.modules + sage: I.elimination_ideal([x, z]) # optional - sage.combinat sage.modules + Left Ideal (y^2) of + Noncommutative Multivariate Polynomial Ring in x, y, z over Rational Field, + nc-relations: {...} + sage: J = I.twostd(); J # optional - sage.combinat sage.modules + Twosided Ideal (z^2 - 1, y*z - y, x*z + x, y^2, 2*x*y - z - 1, x^2) of + Noncommutative Multivariate Polynomial Ring in x, y, z over Rational Field, + nc-relations: {...} + sage: J.elimination_ideal([x, z]) # optional - sage.combinat sage.modules + Twosided Ideal (y^2) of + Noncommutative Multivariate Polynomial Ring in x, y, z over Rational Field, + nc-relations: {...} + + + ALGORITHM: Uses Singular's ``eliminate`` command """ from sage.misc.misc_c import prod if self.side() == 'twosided': @@ -3525,21 +3600,22 @@ def elimination_ideal(self, variables): @cached_method def twostd(self): r""" - Computes a two-sided GB of the ideal (even if it is a left ideal). + Compute a two-sided GB of the ideal (even if it is a left ideal). EXAMPLES:: - sage: A. = FreeAlgebra(QQ, 3) - sage: H = A.g_algebra({y*x:x*y-z, z*x:x*z+2*x, z*y:y*z-2*y}) - sage: H.inject_variables() + sage: A. = FreeAlgebra(QQ, 3) # optional - sage.combinat sage.modules + sage: H = A.g_algebra({y*x: x*y-z, z*x: x*z+2*x, z*y: y*z-2*y}) # optional - sage.combinat sage.modules + sage: H.inject_variables() # optional - sage.combinat sage.modules Defining x, y, z - sage: I = H.ideal([y^2, x^2, z^2-H.one()],coerce=False) - sage: I.twostd() #random - Twosided Ideal (z^2 - 1, y*z - y, x*z + x, y^2, 2*x*y - z - 1, x^2) of Noncommutative Multivariate Polynomial Ring in x, y, z over Rational Field... - sage: sorted(I.twostd().gens(),key=str) + sage: I = H.ideal([y^2, x^2, z^2 - H.one()], coerce=False) # optional - sage.combinat sage.modules + sage: I.twostd() #random # optional - sage.combinat sage.modules + Twosided Ideal (z^2 - 1, y*z - y, x*z + x, y^2, 2*x*y - z - 1, x^2) of + Noncommutative Multivariate Polynomial Ring in x, y, z over Rational Field... + sage: sorted(I.twostd().gens(), key=str) # optional - sage.combinat sage.modules [2*x*y - z - 1, x*z + x, x^2, y*z - y, y^2, z^2 - 1] - ALGORITHM: Uses Singular's twostd command + ALGORITHM: Uses Singular's ``twostd`` command """ return self.ring().ideal( self.__call_singular('twostd'), side='twosided') # return self.__call_singular('twostd') @@ -3555,13 +3631,13 @@ def _groebner_strategy(self): EXAMPLES:: - sage: A. = FreeAlgebra(QQ, 3) - sage: H. = A.g_algebra({y*x:x*y-z, z*x:x*z+2*x, z*y:y*z-2*y}) - sage: I = H.ideal([y^2, x^2, z^2-H.one()],coerce=False) - sage: I._groebner_strategy() #random + sage: A. = FreeAlgebra(QQ, 3) # optional - sage.combinat sage.modules + sage: H. = A.g_algebra({y*x: x*y-z, z*x: x*z+2*x, z*y: y*z-2*y}) # optional - sage.combinat sage.modules + sage: I = H.ideal([y^2, x^2, z^2-H.one()], coerce=False) # optional - sage.combinat sage.modules + sage: I._groebner_strategy() # random # optional - sage.combinat sage.modules Groebner Strategy for ideal generated by 6 elements over - Noncommutative Multivariate Polynomial Ring in x, y, z over Rational - Field, nc-relations: {z*x: x*z + 2*x, z*y: y*z - 2*y, y*x: x*y - z} + Noncommutative Multivariate Polynomial Ring in x, y, z over Rational Field, + nc-relations: {z*x: x*z + 2*x, z*y: y*z - 2*y, y*x: x*y - z} .. NOTE:: @@ -3577,31 +3653,29 @@ def reduce(self,p): It returns 0 if and only if the element is in this ideal. In any case, this reduction is unique up to monomial orders. - NOTE: - - There are left and two-sided ideals. Hence, - EXAMPLES:: - sage: A. = FreeAlgebra(QQ, 3) - sage: H. = A.g_algebra({y*x:x*y-z, z*x:x*z+2*x, z*y:y*z-2*y}) - sage: I = H.ideal([y^2, x^2, z^2-H.one()],coerce=False, side='twosided') - sage: Q = H.quotient(I); Q #random - Quotient of Noncommutative Multivariate Polynomial Ring in x, y, z - over Rational Field, nc-relations: {z*x: x*z + 2*x, - z*y: y*z - 2*y, y*x: x*y - z} by the ideal (y^2, x^2, z^2 - 1) - sage: Q.2^2 == Q.one() # indirect doctest + sage: A. = FreeAlgebra(QQ, 3) # optional - sage.combinat sage.modules + sage: H. = A.g_algebra({y*x: x*y-z, z*x: x*z+2*x, z*y: y*z-2*y}) # optional - sage.combinat sage.modules + sage: I = H.ideal([y^2, x^2, z^2 - H.one()], # optional - sage.combinat sage.modules + ....: coerce=False, side='twosided') + sage: Q = H.quotient(I); Q #random # optional - sage.combinat sage.modules + Quotient of + Noncommutative Multivariate Polynomial Ring in x, y, z over Rational Field, + nc-relations: {z*x: x*z + 2*x, z*y: y*z - 2*y, y*x: x*y - z} + by the ideal (y^2, x^2, z^2 - 1) + sage: Q.2^2 == Q.one() # indirect doctest # optional - sage.combinat sage.modules True Here, we see that the relation that we just found in the quotient is actually a consequence of the given relations:: - sage: H.2^2-H.one() in I.std().gens() + sage: H.2^2 - H.one() in I.std().gens() # optional - sage.combinat sage.modules True Here is the corresponding direct test:: - sage: I.reduce(z^2) + sage: I.reduce(z^2) # optional - sage.combinat sage.modules 1 """ @@ -3613,21 +3687,26 @@ def _contains_(self,p): We define a left and a two-sided ideal:: - sage: A. = FreeAlgebra(QQ, 3) - sage: H. = A.g_algebra({y*x:x*y-z, z*x:x*z+2*x, z*y:y*z-2*y}) - sage: JL = H.ideal([x^3, y^3, z^3 - 4*z]) - sage: JL.std() #random - Left Ideal (z^3 - 4*z, y*z^2 - 2*y*z, x*z^2 + 2*x*z, 2*x*y*z - z^2 - 2*z, y^3, x^3) of Noncommutative Multivariate Polynomial Ring in x, y, z over Rational Field, nc-relations: {z*x: x*z + 2*x, z*y: y*z - 2*y, y*x: x*y - z} - sage: JT = H.ideal([x^3, y^3, z^3 - 4*z], side='twosided') - sage: JT.std() #random - Twosided Ideal (z^3 - 4*z, y*z^2 - 2*y*z, x*z^2 + 2*x*z, y^2*z - 2*y^2, 2*x*y*z - z^2 - 2*z, x^2*z + 2*x^2, y^3, x*y^2 - y*z, x^2*y - x*z - 2*x, x^3) of Noncommutative Multivariate Polynomial Ring in x, y, z over Rational Field, nc-relations: {z*x: x*z + 2*x, z*y: y*z - 2*y, y*x: x*y - z} + sage: A. = FreeAlgebra(QQ, 3) # optional - sage.combinat sage.modules + sage: H. = A.g_algebra({y*x: x*y-z, z*x: x*z+2*x, z*y: y*z-2*y}) # optional - sage.combinat sage.modules + sage: JL = H.ideal([x^3, y^3, z^3 - 4*z]) # optional - sage.combinat sage.modules + sage: JL.std() #random # optional - sage.combinat sage.modules + Left Ideal (z^3 - 4*z, y*z^2 - 2*y*z, x*z^2 + 2*x*z, 2*x*y*z - z^2 - 2*z, y^3, x^3) of + Noncommutative Multivariate Polynomial Ring in x, y, z over Rational Field, + nc-relations: {z*x: x*z + 2*x, z*y: y*z - 2*y, y*x: x*y - z} + sage: JT = H.ideal([x^3, y^3, z^3 - 4*z], side='twosided') # optional - sage.combinat sage.modules + sage: JT.std() #random # optional - sage.combinat sage.modules + Twosided Ideal (z^3 - 4*z, y*z^2 - 2*y*z, x*z^2 + 2*x*z, y^2*z - 2*y^2, 2*x*y*z - z^2 - 2*z, + x^2*z + 2*x^2, y^3, x*y^2 - y*z, x^2*y - x*z - 2*x, x^3) of + Noncommutative Multivariate Polynomial Ring in x, y, z over Rational Field, + nc-relations: {z*x: x*z + 2*x, z*y: y*z - 2*y, y*x: x*y - z} Apparently, ``x*y^2-y*z`` should be in the two-sided, but not in the left ideal:: - sage: x*y^2-y*z in JL #indirect doctest + sage: x*y^2-y*z in JL #indirect doctest # optional - sage.combinat sage.modules False - sage: x*y^2-y*z in JT + sage: x*y^2-y*z in JT # optional - sage.combinat sage.modules True """ @@ -3636,7 +3715,7 @@ def _contains_(self,p): @require_field def syzygy_module(self): r""" - Computes the first syzygy (i.e., the module of relations of the + Compute the first syzygy (i.e., the module of relations of the given generators) of the ideal. NOTE: @@ -3647,12 +3726,12 @@ def syzygy_module(self): EXAMPLES:: - sage: A. = FreeAlgebra(QQ, 3) - sage: H = A.g_algebra({y*x:x*y-z, z*x:x*z+2*x, z*y:y*z-2*y}) - sage: H.inject_variables() + sage: A. = FreeAlgebra(QQ, 3) # optional - sage.combinat sage.modules + sage: H = A.g_algebra({y*x: x*y-z, z*x: x*z+2*x, z*y: y*z-2*y}) # optional - sage.combinat sage.modules + sage: H.inject_variables() # optional - sage.combinat sage.modules Defining x, y, z - sage: I = H.ideal([y^2, x^2, z^2-H.one()],coerce=False) - sage: G = vector(I.gens()); G + sage: I = H.ideal([y^2, x^2, z^2-H.one()], coerce=False) # optional - sage.combinat sage.modules + sage: G = vector(I.gens()); G # optional - sage.combinat sage.modules d...: UserWarning: You are constructing a free module over a noncommutative ring. Sage does not have a concept of left/right and both sided modules, so be careful. @@ -3664,7 +3743,7 @@ def syzygy_module(self): It's also not guaranteed that all multiplications are done from the right side. (y^2, x^2, z^2 - 1) - sage: M = I.syzygy_module(); M + sage: M = I.syzygy_module(); M # optional - sage.combinat sage.modules [ -z^2 - 8*z - 15 0 y^2] [ 0 -z^2 + 8*z - 15 x^2] [ x^2*z^2 + 8*x^2*z + 15*x^2 -y^2*z^2 + 8*y^2*z - 15*y^2 -4*x*y*z + 2*z^2 + 2*z] @@ -3675,10 +3754,10 @@ def syzygy_module(self): [ x^4*z + 4*x^4 -x^2*y^2*z + 4*x^2*y^2 - 4*x*y*z^2 + 32*x*y*z - 6*z^3 - 64*x*y + 66*z^2 - 240*z + 288 0] [x^3*y^2*z + 4*x^3*y^2 + 18*x^2*y*z - 36*x*z^3 + 66*x^2*y - 432*x*z^2 - 1656*x*z - 2052*x -x*y^4*z + 4*x*y^4 - 8*y^3*z^2 + 62*y^3*z - 114*y^3 48*y*z^2 - 36*y*z] - sage: M*G + sage: M*G # optional - sage.combinat sage.modules (0, 0, 0, 0, 0, 0, 0, 0, 0) - ALGORITHM: Uses Singular's syz command + ALGORITHM: Uses Singular's ``syz`` command """ if self.side() == 'twosided': warn("The result of this Syzygy computation is one-sided (left)!") @@ -3702,12 +3781,12 @@ def res(self, length): EXAMPLES:: - sage: A. = FreeAlgebra(QQ, 3) - sage: H = A.g_algebra({y*x:x*y-z, z*x:x*z+2*x, z*y:y*z-2*y}) - sage: H.inject_variables() + sage: A. = FreeAlgebra(QQ, 3) # optional - sage.combinat sage.modules + sage: H = A.g_algebra({y*x: x*y-z, z*x: x*z+2*x, z*y: y*z-2*y}) # optional - sage.combinat sage.modules + sage: H.inject_variables() # optional - sage.combinat sage.modules Defining x, y, z - sage: I = H.ideal([y^2, x^2, z^2-H.one()],coerce=False) - sage: I.res(3) + sage: I = H.ideal([y^2, x^2, z^2-H.one()], coerce=False) # optional - sage.combinat sage.modules + sage: I.res(3) # optional - sage.combinat sage.modules """ if self.side() == 'twosided': @@ -3730,15 +3809,15 @@ def __init__(self, ring, gens, coerce=True): - ``gens`` - a list of generators for the ideal - - ``coerce`` - coerce elements to the ring ``ring``? + - ``coerce`` - whether to coerce elements to the ring ``ring`` EXAMPLES:: sage: R. = PolynomialRing(IntegerRing(), 2, order='lex') sage: R.ideal([x, y]) Ideal (x, y) of Multivariate Polynomial Ring in x, y over Integer Ring - sage: R. = GF(3)[] - sage: R.ideal([x0^2, x1^3]) + sage: R. = GF(3)[] # optional - sage.rings.finite_rings + sage: R.ideal([x0^2, x1^3]) # optional - sage.rings.finite_rings Ideal (x0^2, x1^3) of Multivariate Polynomial Ring in x0, x1 over Finite Field of size 3 """ Ideal_generic.__init__(self, ring, gens, coerce=coerce) @@ -3765,7 +3844,7 @@ def gens(self): EXAMPLES:: sage: P. = PolynomialRing(QQ,2) - sage: I = Ideal([x,y+1]); I + sage: I = Ideal([x, y + 1]); I Ideal (x, y + 1) of Multivariate Polynomial Ring in x, y over Rational Field sage: I.gens() [x, y + 1] @@ -3781,7 +3860,7 @@ def basis(self): EXAMPLES:: sage: P. = PolynomialRing(QQ,2) - sage: I = Ideal([x,y+1]) + sage: I = Ideal([x, y + 1]) sage: I.basis [x, y + 1] @@ -3824,22 +3903,22 @@ def __richcmp__(self, other, op): :: - sage: R. = GF(32003)[] - sage: I = R*[x^2 + x, y] - sage: J = R*[x + 1, y] - sage: J < I + sage: R. = GF(32003)[] # optional - sage.rings.finite_rings + sage: I = R*[x^2 + x, y] # optional - sage.rings.finite_rings + sage: J = R*[x + 1, y] # optional - sage.rings.finite_rings + sage: J < I # optional - sage.rings.finite_rings False - sage: I < J + sage: I < J # optional - sage.rings.finite_rings True :: - sage: R. = GF(32003)[] - sage: I = R*[x^2 + x, y] - sage: J = R*[x + 1, y] - sage: J > I + sage: R. = GF(32003)[] # optional - sage.rings.finite_rings + sage: I = R*[x^2 + x, y] # optional - sage.rings.finite_rings + sage: J = R*[x + 1, y] # optional - sage.rings.finite_rings + sage: J > I # optional - sage.rings.finite_rings True - sage: I > J + sage: I > J # optional - sage.rings.finite_rings False :: @@ -3858,8 +3937,8 @@ def __richcmp__(self, other, op): :: sage: R. = QQ[] - sage: I = (x^3 + y, y)*R - sage: J = (x^3 + y, y, y*x^3 + y^2)*R + sage: I = (x^3 + y, y) * R + sage: J = (x^3 + y, y, y*x^3 + y^2) * R sage: I == J True @@ -3877,15 +3956,15 @@ def __richcmp__(self, other, op): We test to make sure that pickling works with the cached Groebner basis:: - sage: R. = GF(32003)[] - sage: I = R*[x^2 + x, y] - sage: J = R*[x + 1, y] - sage: J >= I + sage: R. = GF(32003)[] # optional - sage.rings.finite_rings + sage: I = R*[x^2 + x, y] # optional - sage.rings.finite_rings + sage: J = R*[x + 1, y] # optional - sage.rings.finite_rings + sage: J >= I # optional - sage.rings.finite_rings True - sage: I >= J + sage: I >= J # optional - sage.rings.finite_rings False - sage: loads(dumps(I)).__getstate__() + sage: loads(dumps(I)).__getstate__() # optional - sage.rings.finite_rings (Monoid of ideals of Multivariate Polynomial Ring in x, y over Finite Field of size 32003, {'_Ideal_generic__gens': (x^2 + x, y), '_Ideal_generic__ring': Multivariate Polynomial Ring in x, y over Finite Field of size 32003, @@ -4059,7 +4138,7 @@ def groebner_basis(self, algorithm='', deg_bound=None, mult_bound=None, prot=Fal INPUT: - ``algorithm`` - determines the algorithm to use, see below - for available algorithms. + for available algorithms. - ``deg_bound`` - only compute to degree ``deg_bound``, that is, ignore all S-polynomials of higher degree. (default: @@ -4079,78 +4158,78 @@ def groebner_basis(self, algorithm='', deg_bound=None, mult_bound=None, prot=Fal :func:`set_verbose`. - ``*args`` - additional parameters passed to the respective - implementations + implementations - ``**kwds`` - additional keyword parameters passed to the - respective implementations + respective implementations ALGORITHMS: - '' + ``''`` autoselect (default) - 'singular:groebner' + ``'singular:groebner'`` Singular's ``groebner`` command - 'singular:std' + ``'singular:std'`` Singular's ``std`` command - 'singular:stdhilb' + ``'singular:stdhilb'`` Singular's ``stdhib`` command - 'singular:stdfglm' + ``'singular:stdfglm'`` Singular's ``stdfglm`` command - 'singular:slimgb' + ``'singular:slimgb'`` Singular's ``slimgb`` command - 'libsingular:groebner' + ``'libsingular:groebner'`` libSingular's ``groebner`` command - 'libsingular:std' + ``'libsingular:std'`` libSingular's ``std`` command - 'libsingular:slimgb' + ``'libsingular:slimgb'`` libSingular's ``slimgb`` command - 'libsingular:stdhilb' + ``'libsingular:stdhilb'`` libSingular's ``stdhib`` command - 'libsingular:stdfglm' + ``'libsingular:stdfglm'`` libSingular's ``stdfglm`` command - 'toy:buchberger' + ``'toy:buchberger'`` Sage's toy/educational buchberger without Buchberger criteria - 'toy:buchberger2' + ``'toy:buchberger2'`` Sage's toy/educational buchberger with Buchberger criteria - 'toy:d_basis' + ``'toy:d_basis'`` Sage's toy/educational algorithm for computation over PIDs - 'macaulay2:gb' + ``'macaulay2:gb'`` Macaulay2's ``gb`` command (if available) - 'macaulay2:f4' + ``'macaulay2:f4'`` Macaulay2's ``GroebnerBasis`` command with the strategy "F4" (if available) - 'macaulay2:mgb' + ``'macaulay2:mgb'`` Macaulay2's ``GroebnerBasis`` command with the strategy "MGB" (if available) - 'msolve' + ``'msolve'`` `optional package msolve <../spkg/msolve.html>`_ (degrevlex order, prime fields) - 'magma:GroebnerBasis' + ``'magma:GroebnerBasis'`` Magma's ``Groebnerbasis`` command (if available) - 'ginv:TQ', 'ginv:TQBlockHigh', 'ginv:TQBlockLow' and 'ginv:TQDegree' + ``'ginv:TQ'``, ``'ginv:TQBlockHigh'``, ``'ginv:TQBlockLow'`` and ``'ginv:TQDegree'`` One of GINV's implementations (if available) - 'giac:gbasis' + ``'giac:gbasis'`` Giac's ``gbasis`` command (if available) - If only a system is given - e.g. 'magma' - the default algorithm is + If only a system is given - e.g. ``'magma'`` - the default algorithm is chosen for that system. .. NOTE:: @@ -4158,7 +4237,7 @@ def groebner_basis(self, algorithm='', deg_bound=None, mult_bound=None, prot=Fal The Singular and libSingular versions of the respective algorithms are identical, but the former calls an external Singular process while the latter calls a C function, - i.e. the calling overhead is smaller. However, the + and thus the calling overhead is smaller. However, the libSingular interface does not support pretty printing of computation protocols. @@ -4222,9 +4301,9 @@ def groebner_basis(self, algorithm='', deg_bound=None, mult_bound=None, prot=Fal Giac's gbasis over `\QQ` can benefit from a probabilistic lifting and multi threaded operations:: - sage: A9=PolynomialRing(QQ,9,'x') - sage: I9=sage.rings.ideal.Katsura(A9) - sage: print("possible output from giac", flush=True); I9.groebner_basis("giac",proba_epsilon=1e-7) # long time (3s) + sage: A9 = PolynomialRing(QQ, 9, 'x') + sage: I9 = sage.rings.ideal.Katsura(A9) + sage: print("possible output from giac", flush=True); I9.groebner_basis("giac", proba_epsilon=1e-7) # long time (3s) possible output... Polynomial Sequence with 143 Polynomials in 9 Variables @@ -4251,41 +4330,41 @@ def groebner_basis(self, algorithm='', deg_bound=None, mult_bound=None, prot=Fal Here we use Macaulay2 with three different strategies over a finite field. :: - sage: R. = PolynomialRing(GF(101), 3) - sage: I = sage.rings.ideal.Katsura(R,3) # regenerate to prevent caching - sage: I.groebner_basis('macaulay2:gb') # optional - macaulay2 + sage: R. = PolynomialRing(GF(101), 3) # optional - sage.rings.finite_rings + sage: I = sage.rings.ideal.Katsura(R,3) # regenerate to prevent caching # optional - sage.rings.finite_rings + sage: I.groebner_basis('macaulay2:gb') # optional - macaulay2 # optional - sage.rings.finite_rings [c^3 + 28*c^2 - 37*b + 13*c, b^2 - 41*c^2 + 20*b - 20*c, b*c - 19*c^2 + 10*b + 40*c, a + 2*b + 2*c - 1] - sage: I = sage.rings.ideal.Katsura(R,3) # regenerate to prevent caching - sage: I.groebner_basis('macaulay2:f4') # optional - macaulay2 + sage: I = sage.rings.ideal.Katsura(R,3) # regenerate to prevent caching # optional - sage.rings.finite_rings + sage: I.groebner_basis('macaulay2:f4') # optional - macaulay2 # optional - sage.rings.finite_rings [c^3 + 28*c^2 - 37*b + 13*c, b^2 - 41*c^2 + 20*b - 20*c, b*c - 19*c^2 + 10*b + 40*c, a + 2*b + 2*c - 1] - sage: I = sage.rings.ideal.Katsura(R,3) # regenerate to prevent caching - sage: I.groebner_basis('macaulay2:mgb') # optional - macaulay2 + sage: I = sage.rings.ideal.Katsura(R,3) # regenerate to prevent caching # optional - sage.rings.finite_rings + sage: I.groebner_basis('macaulay2:mgb') # optional - macaulay2 # optional - sage.rings.finite_rings [c^3 + 28*c^2 - 37*b + 13*c, b^2 - 41*c^2 + 20*b - 20*c, b*c - 19*c^2 + 10*b + 40*c, a + 2*b + 2*c - 1] Over prime fields of small characteristic, we can also use the `optional package msolve <../spkg/msolve.html>`_:: - sage: R. = PolynomialRing(GF(101), 3) - sage: I = sage.rings.ideal.Katsura(R,3) # regenerate to prevent caching - sage: I.groebner_basis('msolve') # optional - msolve + sage: R. = PolynomialRing(GF(101), 3) # optional - sage.rings.finite_rings + sage: I = sage.rings.ideal.Katsura(R,3) # regenerate to prevent caching # optional - sage.rings.finite_rings + sage: I.groebner_basis('msolve') # optional - msolve # optional - sage.rings.finite_rings [a + 2*b + 2*c - 1, b*c - 19*c^2 + 10*b + 40*c, b^2 - 41*c^2 + 20*b - 20*c, c^3 + 28*c^2 - 37*b + 13*c] :: - sage: I = sage.rings.ideal.Katsura(P,3) # regenerate to prevent caching - sage: I.groebner_basis('magma:GroebnerBasis') # optional - magma + sage: I = sage.rings.ideal.Katsura(P,3) # regenerate to prevent caching # optional - sage.rings.finite_rings + sage: I.groebner_basis('magma:GroebnerBasis') # optional - magma # optional - sage.rings.finite_rings [a - 60*c^3 + 158/7*c^2 + 8/7*c - 1, b + 30*c^3 - 79/7*c^2 + 3/7*c, c^4 - 10/21*c^3 + 1/84*c^2 + 1/84*c] Singular and libSingular can compute Groebner basis with degree restrictions. :: sage: R. = QQ[] - sage: I = R*[x^3+y^2,x^2*y+1] + sage: I = R*[x^3 + y^2, x^2*y + 1] sage: I.groebner_basis(algorithm='singular') [x^3 + y^2, x^2*y + 1, y^3 - x] - sage: I.groebner_basis(algorithm='singular',deg_bound=2) + sage: I.groebner_basis(algorithm='singular', deg_bound=2) [x^3 + y^2, x^2*y + 1] sage: I.groebner_basis() [x^3 + y^2, x^2*y + 1, y^3 - x] @@ -4367,16 +4446,16 @@ def groebner_basis(self, algorithm='', deg_bound=None, mult_bound=None, prot=Fal Sage also supports local orderings:: - sage: P. = PolynomialRing(QQ,3,order='negdegrevlex') - sage: I = P * ( x*y*z + z^5, 2*x^2 + y^3 + z^7, 3*z^5 +y ^5 ) + sage: P. = PolynomialRing(QQ, 3, order='negdegrevlex') + sage: I = P * ( x*y*z + z^5, 2*x^2 + y^3 + z^7, 3*z^5 + y^5 ) sage: I.groebner_basis() [x^2 + 1/2*y^3, x*y*z + z^5, y^5 + 3*z^5, y^4*z - 2*x*z^5, z^6] We can represent every element in the ideal as a combination of the generators using the :meth:`~sage.rings.polynomial.multi_polynomial_element.MPolynomial_polydict.lift` method:: - sage: P. = PolynomialRing(QQ,3) - sage: I = P * ( x*y*z + z^5, 2*x^2 + y^3 + z^7, 3*z^5 +y ^5 ) + sage: P. = PolynomialRing(QQ, 3) + sage: I = P * ( x*y*z + z^5, 2*x^2 + y^3 + z^7, 3*z^5 + y^5 ) sage: J = Ideal(I.groebner_basis()) sage: f = sum(P.random_element(terms=2)*f for f in I.gens()) sage: f # random @@ -4448,54 +4527,54 @@ def groebner_basis(self, algorithm='', deg_bound=None, mult_bound=None, prot=Fal Check that this method works over QQbar (:trac:`25351`):: - sage: P. = PolynomialRing(QQbar,3, order='lex') - sage: I = sage.rings.ideal.Katsura(P,3) # regenerate to prevent caching - sage: I.groebner_basis() + sage: P. = PolynomialRing(QQbar, 3, order='lex') # optional - sage.rings.number_field + sage: I = sage.rings.ideal.Katsura(P,3) # regenerate to prevent caching # optional - sage.rings.number_field + sage: I.groebner_basis() # optional - sage.rings.number_field [a + (-60)*c^3 + 158/7*c^2 + 8/7*c - 1, b + 30*c^3 + (-79/7)*c^2 + 3/7*c, c^4 + (-10/21)*c^3 + 1/84*c^2 + 1/84*c] - sage: I = sage.rings.ideal.Katsura(P,3) # regenerate to prevent caching - sage: I.groebner_basis('libsingular:groebner') + sage: I = sage.rings.ideal.Katsura(P,3) # regenerate to prevent caching # optional - sage.rings.number_field + sage: I.groebner_basis('libsingular:groebner') # optional - sage.rings.number_field [a + (-60)*c^3 + 158/7*c^2 + 8/7*c - 1, b + 30*c^3 + (-79/7)*c^2 + 3/7*c, c^4 + (-10/21)*c^3 + 1/84*c^2 + 1/84*c] - sage: I = sage.rings.ideal.Katsura(P,3) # regenerate to prevent caching - sage: I.groebner_basis('libsingular:std') + sage: I = sage.rings.ideal.Katsura(P,3) # regenerate to prevent caching # optional - sage.rings.number_field + sage: I.groebner_basis('libsingular:std') # optional - sage.rings.number_field [a + (-60)*c^3 + 158/7*c^2 + 8/7*c - 1, b + 30*c^3 + (-79/7)*c^2 + 3/7*c, c^4 + (-10/21)*c^3 + 1/84*c^2 + 1/84*c] - sage: I = sage.rings.ideal.Katsura(P,3) # regenerate to prevent caching - sage: I.groebner_basis('libsingular:stdhilb') + sage: I = sage.rings.ideal.Katsura(P,3) # regenerate to prevent caching # optional - sage.rings.number_field + sage: I.groebner_basis('libsingular:stdhilb') # optional - sage.rings.number_field [a + (-60)*c^3 + 158/7*c^2 + 8/7*c - 1, b + 30*c^3 + (-79/7)*c^2 + 3/7*c, c^4 + (-10/21)*c^3 + 1/84*c^2 + 1/84*c] - sage: I = sage.rings.ideal.Katsura(P,3) # regenerate to prevent caching - sage: I.groebner_basis('libsingular:stdfglm') + sage: I = sage.rings.ideal.Katsura(P,3) # regenerate to prevent caching # optional - sage.rings.number_field + sage: I.groebner_basis('libsingular:stdfglm') # optional - sage.rings.number_field [a + (-60)*c^3 + 158/7*c^2 + 8/7*c - 1, b + 30*c^3 + (-79/7)*c^2 + 3/7*c, c^4 + (-10/21)*c^3 + 1/84*c^2 + 1/84*c] - sage: I = sage.rings.ideal.Katsura(P,3) # regenerate to prevent caching - sage: I.groebner_basis('libsingular:slimgb') + sage: I = sage.rings.ideal.Katsura(P,3) # regenerate to prevent caching # optional - sage.rings.number_field + sage: I.groebner_basis('libsingular:slimgb') # optional - sage.rings.number_field [a + (-60)*c^3 + 158/7*c^2 + 8/7*c - 1, b + 30*c^3 + (-79/7)*c^2 + 3/7*c, c^4 + (-10/21)*c^3 + 1/84*c^2 + 1/84*c] - sage: I = sage.rings.ideal.Katsura(P,3) # regenerate to prevent caching - sage: J = I.change_ring(P.change_ring(order='degrevlex')) - sage: gb = J.groebner_basis('giac') # random - sage: gb + sage: I = sage.rings.ideal.Katsura(P,3) # regenerate to prevent caching # optional - sage.rings.number_field + sage: J = I.change_ring(P.change_ring(order='degrevlex')) # optional - sage.rings.number_field + sage: gb = J.groebner_basis('giac') # random # optional - sage.rings.number_field + sage: gb # optional - sage.rings.number_field [c^3 + (-79/210)*c^2 + 1/30*b + 1/70*c, b^2 + (-3/5)*c^2 + (-1/5)*b + 1/5*c, b*c + 6/5*c^2 + (-1/10)*b + (-2/5)*c, a + 2*b + 2*c - 1] - sage: I = sage.rings.ideal.Katsura(P,3) # regenerate to prevent caching - sage: I.groebner_basis('toy:buchberger2') + sage: I = sage.rings.ideal.Katsura(P,3) # regenerate to prevent caching # optional - sage.rings.number_field + sage: I.groebner_basis('toy:buchberger2') # optional - sage.rings.number_field [a + (-60)*c^3 + 158/7*c^2 + 8/7*c - 1, b + 30*c^3 + (-79/7)*c^2 + 3/7*c, c^4 + (-10/21)*c^3 + 1/84*c^2 + 1/84*c] - sage: I = sage.rings.ideal.Katsura(P,3) # regenerate to prevent caching - sage: I.groebner_basis('macaulay2:gb') # optional - macaulay2 + sage: I = sage.rings.ideal.Katsura(P,3) # regenerate to prevent caching # optional - sage.rings.number_field + sage: I.groebner_basis('macaulay2:gb') # optional - macaulay2 # optional - sage.rings.number_field [a + (-60)*c^3 + 158/7*c^2 + 8/7*c - 1, b + 30*c^3 + (-79/7)*c^2 + 3/7*c, c^4 + (-10/21)*c^3 + 1/84*c^2 + 1/84*c] - sage: I = sage.rings.ideal.Katsura(P,3) # regenerate to prevent caching - sage: I.groebner_basis('magma:GroebnerBasis') # optional - magma + sage: I = sage.rings.ideal.Katsura(P,3) # regenerate to prevent caching # optional - sage.rings.number_field + sage: I.groebner_basis('magma:GroebnerBasis') # optional - magma # optional - sage.rings.number_field [a + (-60)*c^3 + 158/7*c^2 + 8/7*c - 1, b + 30*c^3 + (-79/7)*c^2 + 3/7*c, c^4 + (-10/21)*c^3 + 1/84*c^2 + 1/84*c] msolve currently supports the degrevlex order only:: - sage: R. = PolynomialRing(GF(101), 3, order='lex') - sage: I = sage.rings.ideal.Katsura(R,3) # regenerate to prevent caching - sage: I.groebner_basis('msolve') # optional - msolve + sage: R. = PolynomialRing(GF(101), 3, order='lex') # optional - sage.rings.finite_rings + sage: I = sage.rings.ideal.Katsura(R,3) # regenerate to prevent caching # optional - sage.rings.finite_rings + sage: I.groebner_basis('msolve') # optional - msolve # optional - sage.rings.finite_rings Traceback (most recent call last): ... NotImplementedError: msolve only supports the degrevlex order (use transformed_basis()) @@ -4717,27 +4796,32 @@ def subs(self, in_dict=None, **kwds): OUTPUT: A new ideal with modified generators. If possible, in the same - polynomial ring. Raises a ``TypeError`` if no common + polynomial ring. Raises a :class:`TypeError` if no common polynomial ring of the substituted generators can be found. EXAMPLES:: - sage: R. = PolynomialRing(ZZ,2,'xy') - sage: I = R.ideal(x^5+y^5, x^2 + y + x^2*y^2 + 5); I - Ideal (x^5 + y^5, x^2*y^2 + x^2 + y + 5) of Multivariate Polynomial Ring in x, y over Integer Ring + sage: R. = PolynomialRing(ZZ, 2, 'xy') + sage: I = R.ideal(x^5 + y^5, x^2 + y + x^2*y^2 + 5); I + Ideal (x^5 + y^5, x^2*y^2 + x^2 + y + 5) + of Multivariate Polynomial Ring in x, y over Integer Ring sage: I.subs(x=y) - Ideal (2*y^5, y^4 + y^2 + y + 5) of Multivariate Polynomial Ring in x, y over Integer Ring - sage: I.subs({x:y}) # same substitution but with dictionary - Ideal (2*y^5, y^4 + y^2 + y + 5) of Multivariate Polynomial Ring in x, y over Integer Ring + Ideal (2*y^5, y^4 + y^2 + y + 5) + of Multivariate Polynomial Ring in x, y over Integer Ring + sage: I.subs({x: y}) # same substitution but with dictionary + Ideal (2*y^5, y^4 + y^2 + y + 5) + of Multivariate Polynomial Ring in x, y over Integer Ring The new ideal can be in a different ring:: - sage: R. = PolynomialRing(QQ,2) - sage: S. = PolynomialRing(QQ,2) - sage: I = R.ideal(a^2+b^2+a-b+2); I - Ideal (a^2 + b^2 + a - b + 2) of Multivariate Polynomial Ring in a, b over Rational Field + sage: R. = PolynomialRing(QQ, 2) + sage: S. = PolynomialRing(QQ, 2) + sage: I = R.ideal(a^2 + b^2 + a - b + 2); I + Ideal (a^2 + b^2 + a - b + 2) + of Multivariate Polynomial Ring in a, b over Rational Field sage: I.subs(a=x, b=y) - Ideal (x^2 + y^2 + x - y + 2) of Multivariate Polynomial Ring in x, y over Rational Field + Ideal (x^2 + y^2 + x - y + 2) + of Multivariate Polynomial Ring in x, y over Rational Field The resulting ring need not be a multivariate polynomial ring:: @@ -4751,9 +4835,10 @@ def subs(self, in_dict=None, **kwds): Variables that are not substituted remain unchanged:: - sage: R. = PolynomialRing(QQ,2) - sage: I = R.ideal(x^2+y^2+x-y+2); I - Ideal (x^2 + y^2 + x - y + 2) of Multivariate Polynomial Ring in x, y over Rational Field + sage: R. = PolynomialRing(QQ, 2) + sage: I = R.ideal(x^2 + y^2 + x - y + 2); I + Ideal (x^2 + y^2 + x - y + 2) + of Multivariate Polynomial Ring in x, y over Rational Field sage: I.subs(x=1) Ideal (y^2 - y + 4) of Multivariate Polynomial Ring in x, y over Rational Field """ @@ -4775,7 +4860,7 @@ def reduce(self, f): EXAMPLES:: sage: R. = PolynomialRing(QQ, 2) - sage: I = (x^3 + y, y)*R + sage: I = (x^3 + y, y) * R sage: I.reduce(y) 0 sage: I.reduce(x^3) @@ -4783,7 +4868,7 @@ def reduce(self, f): sage: I.reduce(x - y) x - sage: I = (y^2 - (x^3 + x))*R + sage: I = (y^2 - (x^3 + x)) * R sage: I.reduce(x^3) y^2 - x sage: I.reduce(x^6) @@ -4813,7 +4898,7 @@ def _contains_(self, f): EXAMPLES:: sage: R. = QQ[] - sage: I = (x^3 + y, y)*R + sage: I = (x^3 + y, y) * R sage: x in I # indirect doctest False sage: y in I @@ -4842,28 +4927,28 @@ def homogenize(self, var='h'): EXAMPLES:: - sage: P. = PolynomialRing(GF(2)) - sage: I = Ideal([x^2*y + z + 1, x + y^2 + 1]); I + sage: P. = PolynomialRing(GF(2)) # optional - sage.rings.finite_rings + sage: I = Ideal([x^2*y + z + 1, x + y^2 + 1]); I # optional - sage.rings.finite_rings Ideal (x^2*y + z + 1, y^2 + x + 1) of Multivariate Polynomial Ring in x, y, z over Finite Field of size 2 :: - sage: I.homogenize() + sage: I.homogenize() # optional - sage.rings.finite_rings Ideal (x^2*y + z*h^2 + h^3, y^2 + x*h + h^2) of Multivariate Polynomial Ring in x, y, z, h over Finite Field of size 2 :: - sage: I.homogenize(y) + sage: I.homogenize(y) # optional - sage.rings.finite_rings Ideal (x^2*y + y^3 + y^2*z, x*y) of Multivariate Polynomial Ring in x, y, z over Finite Field of size 2 :: - sage: I = Ideal([x^2*y + z^3 + y^2*x, x + y^2 + 1]) - sage: I.homogenize() + sage: I = Ideal([x^2*y + z^3 + y^2*x, x + y^2 + 1]) # optional - sage.rings.finite_rings + sage: I.homogenize() # optional - sage.rings.finite_rings Ideal (x^2*y + x*y^2 + z^3, y^2 + x*h + h^2) of Multivariate Polynomial Ring in x, y, z, h over Finite Field of size 2 @@ -4875,7 +4960,7 @@ def homogenize(self, var='h'): def is_homogeneous(self): r""" Return ``True`` if this ideal is spanned by homogeneous - polynomials, i.e. if it is a homogeneous ideal. + polynomials, i.e., if it is a homogeneous ideal. EXAMPLES:: @@ -4939,51 +5024,51 @@ def degree_of_semi_regularity(self): We consider a homogeneous example:: sage: n = 8 - sage: K = GF(127) - sage: P = PolynomialRing(K,n,'x') - sage: s = [K.random_element() for _ in range(n)] - sage: L = [] - sage: for i in range(2*n): - ....: f = P.random_element(degree=2, terms=binomial(n,2)) + sage: K = GF(127) # optional - sage.rings.finite_rings + sage: P = PolynomialRing(K, n, 'x') # optional - sage.rings.finite_rings + sage: s = [K.random_element() for _ in range(n)] # optional - sage.rings.finite_rings + sage: L = [] # optional - sage.rings.finite_rings + sage: for i in range(2 * n): # optional - sage.rings.finite_rings + ....: f = P.random_element(degree=2, terms=binomial(n, 2)) ....: f -= f(*s) ....: L.append(f.homogenize()) - sage: I = Ideal(L) - sage: I.degree_of_semi_regularity() + sage: I = Ideal(L) # optional - sage.rings.finite_rings + sage: I.degree_of_semi_regularity() # optional - sage.rings.finite_rings 4 From this, we expect a Groebner basis computation to reach at most degree 4. For homogeneous systems this is equivalent to the largest degree in the Groebner basis:: - sage: max(f.degree() for f in I.groebner_basis()) + sage: max(f.degree() for f in I.groebner_basis()) # optional - sage.rings.finite_rings 4 We increase the number of polynomials and observe a decrease the degree of regularity:: - sage: for i in range(2*n): - ....: f = P.random_element(degree=2, terms=binomial(n,2)) + sage: for i in range(2 * n): # optional - sage.rings.finite_rings + ....: f = P.random_element(degree=2, terms=binomial(n, 2)) ....: f -= f(*s) ....: L.append(f.homogenize()) - sage: I = Ideal(L) - sage: I.degree_of_semi_regularity() + sage: I = Ideal(L) # optional - sage.rings.finite_rings + sage: I.degree_of_semi_regularity() # optional - sage.rings.finite_rings 3 - sage: max(f.degree() for f in I.groebner_basis()) + sage: max(f.degree() for f in I.groebner_basis()) # optional - sage.rings.finite_rings 3 The degree of regularity approaches 2 for quadratic systems as the number of polynomials approaches `n^2`:: - sage: for i in range((n-4)*n): - ....: f = P.random_element(degree=2, terms=binomial(n,2)) + sage: for i in range((n-4) * n): # optional - sage.rings.finite_rings + ....: f = P.random_element(degree=2, terms=binomial(n, 2)) ....: f -= f(*s) ....: L.append(f.homogenize()) - sage: I = Ideal(L) - sage: I.degree_of_semi_regularity() + sage: I = Ideal(L) # optional - sage.rings.finite_rings + sage: I.degree_of_semi_regularity() # optional - sage.rings.finite_rings 2 - sage: max(f.degree() for f in I.groebner_basis()) + sage: max(f.degree() for f in I.groebner_basis()) # optional - sage.rings.finite_rings 2 .. NOTE:: @@ -5018,59 +5103,59 @@ def plot(self, *args, **kwds): - ``self`` - a principal ideal in 2 variables - ``algorithm`` - set this to 'surf' if you want 'surf' to - plot the ideal (default: None) + plot the ideal (default: None) - ``*args`` - optional tuples ``(variable, minimum, maximum)`` - for plotting dimensions + for plotting dimensions - ``**kwds`` - optional keyword arguments passed on to - ``implicit_plot`` + ``implicit_plot`` EXAMPLES: Implicit plotting in 2-d:: - sage: R. = PolynomialRing(QQ,2) + sage: R. = PolynomialRing(QQ, 2) sage: I = R.ideal([y^3 - x^2]) - sage: I.plot() # cusp + sage: I.plot() # cusp # optional - sage.plot Graphics object consisting of 1 graphics primitive :: sage: I = R.ideal([y^2 - x^2 - 1]) - sage: I.plot((x,-3, 3), (y, -2, 2)) # hyperbola + sage: I.plot((x,-3, 3), (y, -2, 2)) # hyperbola # optional - sage.plot Graphics object consisting of 1 graphics primitive :: sage: I = R.ideal([y^2 + x^2*(1/4) - 1]) - sage: I.plot() # ellipse + sage: I.plot() # ellipse # optional - sage.plot Graphics object consisting of 1 graphics primitive :: sage: I = R.ideal([y^2-(x^2-1)*(x-2)]) - sage: I.plot() # elliptic curve + sage: I.plot() # elliptic curve # optional - sage.plot Graphics object consisting of 1 graphics primitive :: sage: f = ((x+3)^3 + 2*(x+3)^2 - y^2)*(x^3 - y^2)*((x-3)^3-2*(x-3)^2-y^2) sage: I = R.ideal(f) - sage: I.plot() # the Singular logo + sage: I.plot() # the Singular logo # optional - sage.plot Graphics object consisting of 1 graphics primitive :: - sage: R. = PolynomialRing(QQ,2) + sage: R. = PolynomialRing(QQ, 2) sage: I = R.ideal([x - 1]) - sage: I.plot((y, -2, 2)) # vertical line + sage: I.plot((y, -2, 2)) # vertical line # optional - sage.plot Graphics object consisting of 1 graphics primitive :: sage: I = R.ideal([-x^2*y + 1]) - sage: I.plot() # blow up + sage: I.plot() # blow up # optional - sage.plot Graphics object consisting of 1 graphics primitive """ @@ -5149,12 +5234,12 @@ def random_element(self, degree, compute_gb=False, *args, **kwds): We compute a uniformly random element up to the provided degree. :: - sage: P. = GF(127)[] - sage: I = sage.rings.ideal.Katsura(P) - sage: f = I.random_element(degree=4, compute_gb=True, terms=infinity) - sage: f.degree() <= 4 + sage: P. = GF(127)[] # optional - sage.rings.finite_rings + sage: I = sage.rings.ideal.Katsura(P) # optional - sage.rings.finite_rings + sage: f = I.random_element(degree=4, compute_gb=True, terms=infinity) # optional - sage.rings.finite_rings + sage: f.degree() <= 4 # optional - sage.rings.finite_rings True - sage: len(list(f)) <= 35 + sage: len(list(f)) <= 35 # optional - sage.rings.finite_rings True Note that sampling uniformly at random from the ideal at some large enough degree is @@ -5162,45 +5247,48 @@ def random_element(self, degree, compute_gb=False, *args, **kwds): basis if we can sample uniformly at random from an ideal:: sage: n = 3; d = 4 - sage: P = PolynomialRing(GF(127), n, 'x') - sage: I = sage.rings.ideal.Cyclic(P) + sage: P = PolynomialRing(GF(127), n, 'x') # optional - sage.rings.finite_rings + sage: I = sage.rings.ideal.Cyclic(P) # optional - sage.rings.finite_rings 1. We sample `n^d` uniformly random elements in the ideal:: - sage: F = Sequence(I.random_element(degree=d, compute_gb=True, terms=infinity) for _ in range(n^d)) + sage: F = Sequence(I.random_element(degree=d, compute_gb=True, # optional - sage.rings.finite_rings + ....: terms=infinity) + ....: for _ in range(n^d)) 2. We linearize and compute the echelon form:: - sage: A,v = F.coefficient_matrix() - sage: A.echelonize() + sage: A, v = F.coefficient_matrix() # optional - sage.rings.finite_rings + sage: A.echelonize() # optional - sage.rings.finite_rings 3. The result is the desired Gröbner basis:: - sage: G = Sequence((A*v).list()) - sage: G.is_groebner() - True - sage: Ideal(G) == I - True + sage: G = Sequence((A * v).list()) # optional - sage.rings.finite_rings + sage: G.is_groebner() # optional - sage.rings.finite_rings + True + sage: Ideal(G) == I # optional - sage.rings.finite_rings + True We return some element in the ideal with no guarantee on the distribution:: - sage: P = PolynomialRing(GF(127), 10, 'x') - sage: I = sage.rings.ideal.Katsura(P) - sage: f = I.random_element(degree=3) - sage: f # random + sage: P = PolynomialRing(GF(127), 10, 'x') # optional - sage.rings.finite_rings + sage: I = sage.rings.ideal.Katsura(P) # optional - sage.rings.finite_rings + sage: f = I.random_element(degree=3) # optional - sage.rings.finite_rings + sage: f # random # optional - sage.rings.finite_rings -25*x0^2*x1 + 14*x1^3 + 57*x0*x1*x2 + ... + 19*x7*x9 + 40*x8*x9 + 49*x1 - sage: f.degree() + sage: f.degree() # optional - sage.rings.finite_rings 3 We show that the default method does not sample uniformly at random from the ideal:: - sage: P. = GF(127)[] - sage: G = Sequence([x+7, y-2, z+110]) - sage: I = Ideal([sum(P.random_element() * g for g in G) for _ in range(4)]) - sage: all(I.random_element(degree=1) == 0 for _ in range(100)) + sage: P. = GF(127)[] # optional - sage.rings.finite_rings + sage: G = Sequence([x + 7, y - 2, z + 110]) # optional - sage.rings.finite_rings + sage: I = Ideal([sum(P.random_element() * g for g in G) # optional - sage.rings.finite_rings + ....: for _ in range(4)]) + sage: all(I.random_element(degree=1) == 0 for _ in range(100)) # optional - sage.rings.finite_rings True - If degree equals the degree of the generators a random linear + If ``degree`` equals the degree of the generators, a random linear combination of the generators is returned:: sage: P. = QQ[] @@ -5258,118 +5346,130 @@ def weil_restriction(self): If the input and the output ideals are radical, this is equivalent to the statement about algebraic varieties above. - OUTPUT: MPolynomial Ideal + OUTPUT: :class:`MPolynomialIdeal` EXAMPLES:: - sage: k. = GF(2^2) - sage: P. = PolynomialRing(k,2) - sage: I = Ideal([x*y + 1, a*x + 1]) - sage: I.variety() + sage: k. = GF(2^2) # optional - sage.rings.finite_rings + sage: P. = PolynomialRing(k, 2) # optional - sage.rings.finite_rings + sage: I = Ideal([x*y + 1, a*x + 1]) # optional - sage.rings.finite_rings + sage: I.variety() # optional - sage.rings.finite_rings [{y: a, x: a + 1}] - sage: J = I.weil_restriction() - sage: J + sage: J = I.weil_restriction() # optional - sage.rings.finite_rings + sage: J # optional - sage.rings.finite_rings Ideal (x0*y0 + x1*y1 + 1, x1*y0 + x0*y1 + x1*y1, x1 + 1, x0 + x1) of - Multivariate Polynomial Ring in x0, x1, y0, y1 over Finite Field of size - 2 - sage: J += sage.rings.ideal.FieldIdeal(J.ring()) # ensure radical ideal - sage: J.variety() + Multivariate Polynomial Ring in x0, x1, y0, y1 over Finite Field of size 2 + sage: J += sage.rings.ideal.FieldIdeal(J.ring()) # ensure radical ideal # optional - sage.rings.finite_rings + sage: J.variety() # optional - sage.rings.finite_rings [{y1: 1, y0: 0, x1: 1, x0: 1}] - sage: J.weil_restriction() # returns J - Ideal (x0*y0 + x1*y1 + 1, x1*y0 + x0*y1 + x1*y1, x1 + 1, x0 + x1, x0^2 + - x0, x1^2 + x1, y0^2 + y0, y1^2 + y1) of Multivariate Polynomial Ring in - x0, x1, y0, y1 over Finite Field of size 2 + sage: J.weil_restriction() # returns J # optional - sage.rings.finite_rings + Ideal (x0*y0 + x1*y1 + 1, x1*y0 + x0*y1 + x1*y1, x1 + 1, x0 + x1, + x0^2 + x0, x1^2 + x1, y0^2 + y0, y1^2 + y1) of Multivariate + Polynomial Ring in x0, x1, y0, y1 over Finite Field of size 2 - sage: k. = GF(3^5) - sage: P. = PolynomialRing(k) - sage: I = sage.rings.ideal.Katsura(P) - sage: I.dimension() + sage: k. = GF(3^5) # optional - sage.rings.finite_rings + sage: P. = PolynomialRing(k) # optional - sage.rings.finite_rings + sage: I = sage.rings.ideal.Katsura(P) # optional - sage.rings.finite_rings + sage: I.dimension() # optional - sage.rings.finite_rings 0 - sage: I.variety() + sage: I.variety() # optional - sage.rings.finite_rings [{z: 0, y: 0, x: 1}] - sage: J = I.weil_restriction(); J - Ideal (x0 - y0 - z0 - 1, x1 - y1 - z1, x2 - y2 - z2, x3 - y3 - z3, x4 - - y4 - z4, x0^2 + x2*x3 + x1*x4 - y0^2 - y2*y3 - y1*y4 - z0^2 - z2*z3 - - z1*z4 - x0, -x0*x1 - x2*x3 - x3^2 - x1*x4 + x2*x4 + y0*y1 + y2*y3 + y3^2 - + y1*y4 - y2*y4 + z0*z1 + z2*z3 + z3^2 + z1*z4 - z2*z4 - x1, x1^2 - - x0*x2 + x3^2 - x2*x4 + x3*x4 - y1^2 + y0*y2 - y3^2 + y2*y4 - y3*y4 - - z1^2 + z0*z2 - z3^2 + z2*z4 - z3*z4 - x2, -x1*x2 - x0*x3 - x3*x4 - x4^2 - + y1*y2 + y0*y3 + y3*y4 + y4^2 + z1*z2 + z0*z3 + z3*z4 + z4^2 - x3, x2^2 - - x1*x3 - x0*x4 + x4^2 - y2^2 + y1*y3 + y0*y4 - y4^2 - z2^2 + z1*z3 + - z0*z4 - z4^2 - x4, -x0*y0 + x4*y1 + x3*y2 + x2*y3 + x1*y4 - y0*z0 + - y4*z1 + y3*z2 + y2*z3 + y1*z4 - y0, -x1*y0 - x0*y1 - x4*y1 - x3*y2 + - x4*y2 - x2*y3 + x3*y3 - x1*y4 + x2*y4 - y1*z0 - y0*z1 - y4*z1 - y3*z2 + - y4*z2 - y2*z3 + y3*z3 - y1*z4 + y2*z4 - y1, -x2*y0 - x1*y1 - x0*y2 - - x4*y2 - x3*y3 + x4*y3 - x2*y4 + x3*y4 - y2*z0 - y1*z1 - y0*z2 - y4*z2 - - y3*z3 + y4*z3 - y2*z4 + y3*z4 - y2, -x3*y0 - x2*y1 - x1*y2 - x0*y3 - - x4*y3 - x3*y4 + x4*y4 - y3*z0 - y2*z1 - y1*z2 - y0*z3 - y4*z3 - y3*z4 + - y4*z4 - y3, -x4*y0 - x3*y1 - x2*y2 - x1*y3 - x0*y4 - x4*y4 - y4*z0 - - y3*z1 - y2*z2 - y1*z3 - y0*z4 - y4*z4 - y4) of Multivariate Polynomial - Ring in x0, x1, x2, x3, x4, y0, y1, y2, y3, y4, z0, z1, z2, z3, z4 over - Finite Field of size 3 - sage: J += sage.rings.ideal.FieldIdeal(J.ring()) # ensure radical ideal + sage: J = I.weil_restriction(); J # optional - sage.rings.finite_rings + Ideal (x0 - y0 - z0 - 1, + x1 - y1 - z1, x2 - y2 - z2, x3 - y3 - z3, x4 - y4 - z4, + x0^2 + x2*x3 + x1*x4 - y0^2 - y2*y3 - y1*y4 - z0^2 - z2*z3 - z1*z4 - x0, + -x0*x1 - x2*x3 - x3^2 - x1*x4 + x2*x4 + y0*y1 + y2*y3 + + y3^2 + y1*y4 - y2*y4 + z0*z1 + z2*z3 + z3^2 + z1*z4 - z2*z4 - x1, + x1^2 - x0*x2 + x3^2 - x2*x4 + x3*x4 - y1^2 + y0*y2 + - y3^2 + y2*y4 - y3*y4 - z1^2 + z0*z2 - z3^2 + z2*z4 - z3*z4 - x2, + -x1*x2 - x0*x3 - x3*x4 - x4^2 + + y1*y2 + y0*y3 + y3*y4 + y4^2 + z1*z2 + z0*z3 + z3*z4 + z4^2 - x3, + x2^2 - x1*x3 - x0*x4 + x4^2 - y2^2 + + y1*y3 + y0*y4 - y4^2 - z2^2 + z1*z3 + z0*z4 - z4^2 - x4, + -x0*y0 + x4*y1 + x3*y2 + x2*y3 + + x1*y4 - y0*z0 + y4*z1 + y3*z2 + y2*z3 + y1*z4 - y0, + -x1*y0 - x0*y1 - x4*y1 - x3*y2 + x4*y2 - x2*y3 + x3*y3 + - x1*y4 + x2*y4 - y1*z0 - y0*z1 - y4*z1 - y3*z2 + + y4*z2 - y2*z3 + y3*z3 - y1*z4 + y2*z4 - y1, + -x2*y0 - x1*y1 - x0*y2 - x4*y2 - x3*y3 + x4*y3 - x2*y4 + x3*y4 + - y2*z0 - y1*z1 - y0*z2 - y4*z2 - y3*z3 + y4*z3 - y2*z4 + y3*z4 - y2, + -x3*y0 - x2*y1 - x1*y2 - x0*y3 - x4*y3 - x3*y4 + x4*y4 + - y3*z0 - y2*z1 - y1*z2 - y0*z3 - y4*z3 - y3*z4 + y4*z4 - y3, + -x4*y0 - x3*y1 - x2*y2 - x1*y3 - x0*y4 - x4*y4 + - y4*z0 - y3*z1 - y2*z2 - y1*z3 - y0*z4 - y4*z4 - y4) + of Multivariate Polynomial Ring in x0, x1, x2, x3, x4, y0, y1, y2, y3, y4, + z0, z1, z2, z3, z4 over Finite Field of size 3 + sage: J += sage.rings.ideal.FieldIdeal(J.ring()) # ensure radical ideal # optional - sage.rings.finite_rings sage: from sage.doctest.fixtures import reproducible_repr - sage: print(reproducible_repr(J.variety())) - [{x0: 1, x1: 0, x2: 0, x3: 0, x4: 0, y0: 0, y1: 0, y2: 0, y3: 0, y4: 0, z0: 0, z1: 0, z2: 0, z3: 0, z4: 0}] + sage: print(reproducible_repr(J.variety())) # optional - sage.rings.finite_rings + [{x0: 1, x1: 0, x2: 0, x3: 0, x4: 0, + y0: 0, y1: 0, y2: 0, y3: 0, y4: 0, + z0: 0, z1: 0, z2: 0, z3: 0, z4: 0}] Weil restrictions are often used to study elliptic curves over extension fields so we give a simple example involving those:: - sage: K. = QuadraticField(1/3) - sage: E = EllipticCurve(K,[1,2,3,4,5]) + sage: K. = QuadraticField(1/3) # optional - sage.rings.number_field + sage: E = EllipticCurve(K, [1,2,3,4,5]) # optional - sage.rings.number_field We pick a point on ``E``:: - sage: p = E.lift_x(1); p + sage: p = E.lift_x(1); p # optional - sage.rings.number_field (1 : 2 : 1) - sage: I = E.defining_ideal(); I - Ideal (-x^3 - 2*x^2*z + x*y*z + y^2*z - 4*x*z^2 + 3*y*z^2 - 5*z^3) of Multivariate Polynomial Ring in x, y, z over Number Field in a with defining polynomial x^2 - 1/3 with a = 0.5773502691896258? + sage: I = E.defining_ideal(); I # optional - sage.rings.number_field + Ideal (-x^3 - 2*x^2*z + x*y*z + y^2*z - 4*x*z^2 + 3*y*z^2 - 5*z^3) + of Multivariate Polynomial Ring in x, y, z + over Number Field in a with defining polynomial x^2 - 1/3 + with a = 0.5773502691896258? Of course, the point ``p`` is a root of all generators of ``I``:: - sage: I.subs(x=1,y=2,z=1) - Ideal (0) of Multivariate Polynomial Ring in x, y, z over Number Field in a with defining polynomial x^2 - 1/3 with a = 0.5773502691896258? + sage: I.subs(x=1, y=2, z=1) # optional - sage.rings.number_field + Ideal (0) of Multivariate Polynomial Ring in x, y, z + over Number Field in a with defining polynomial x^2 - 1/3 + with a = 0.5773502691896258? ``I`` is also radical:: - sage: I.radical() == I + sage: I.radical() == I # optional - sage.rings.number_field True So we compute its Weil restriction:: - sage: J = I.weil_restriction() - sage: J - Ideal (-x0^3 - x0*x1^2 - 2*x0^2*z0 - 2/3*x1^2*z0 + x0*y0*z0 + y0^2*z0 + - 1/3*x1*y1*z0 + 1/3*y1^2*z0 - 4*x0*z0^2 + 3*y0*z0^2 - 5*z0^3 - - 4/3*x0*x1*z1 + 1/3*x1*y0*z1 + 1/3*x0*y1*z1 + 2/3*y0*y1*z1 - 8/3*x1*z0*z1 - + 2*y1*z0*z1 - 4/3*x0*z1^2 + y0*z1^2 - 5*z0*z1^2, -3*x0^2*x1 - 1/3*x1^3 - - 4*x0*x1*z0 + x1*y0*z0 + x0*y1*z0 + 2*y0*y1*z0 - 4*x1*z0^2 + 3*y1*z0^2 - - 2*x0^2*z1 - 2/3*x1^2*z1 + x0*y0*z1 + y0^2*z1 + 1/3*x1*y1*z1 + - 1/3*y1^2*z1 - 8*x0*z0*z1 + 6*y0*z0*z1 - 15*z0^2*z1 - 4/3*x1*z1^2 + - y1*z1^2 - 5/3*z1^3) of Multivariate Polynomial Ring in x0, x1, y0, y1, - z0, z1 over Rational Field + sage: J = I.weil_restriction() # optional - sage.rings.number_field + sage: J # optional - sage.rings.number_field + Ideal (-x0^3 - x0*x1^2 - 2*x0^2*z0 - 2/3*x1^2*z0 + x0*y0*z0 + y0^2*z0 + + 1/3*x1*y1*z0 + 1/3*y1^2*z0 - 4*x0*z0^2 + 3*y0*z0^2 - 5*z0^3 + - 4/3*x0*x1*z1 + 1/3*x1*y0*z1 + 1/3*x0*y1*z1 + 2/3*y0*y1*z1 + - 8/3*x1*z0*z1 + 2*y1*z0*z1 - 4/3*x0*z1^2 + y0*z1^2 - 5*z0*z1^2, + -3*x0^2*x1 - 1/3*x1^3 - 4*x0*x1*z0 + x1*y0*z0 + x0*y1*z0 + + 2*y0*y1*z0 - 4*x1*z0^2 + 3*y1*z0^2 - 2*x0^2*z1 - 2/3*x1^2*z1 + + x0*y0*z1 + y0^2*z1 + 1/3*x1*y1*z1 + 1/3*y1^2*z1 - 8*x0*z0*z1 + + 6*y0*z0*z1 - 15*z0^2*z1 - 4/3*x1*z1^2 + y1*z1^2 - 5/3*z1^3) + of Multivariate Polynomial Ring in x0, x1, y0, y1, z0, z1 over Rational Field We can check that the point ``p`` is still a root of all generators of ``J``:: - sage: J.subs(x0=1,y0=2,z0=1,x1=0,y1=0,z1=0) - Ideal (0, 0) of Multivariate Polynomial Ring in x0, x1, y0, y1, z0, z1 over Rational Field + sage: J.subs(x0=1, y0=2, z0=1, x1=0, y1=0, z1=0) # optional - sage.rings.number_field + Ideal (0, 0) of Multivariate Polynomial Ring in x0, x1, y0, y1, z0, z1 + over Rational Field Example for relative number fields:: sage: R. = QQ[] - sage: K. = NumberField(x^5-2) - sage: R. = K[] - sage: L. = K.extension(x^2+1) - sage: S. = L[] - sage: I = S.ideal([y^2-x^3-1]) - sage: I.weil_restriction() - Ideal (-x0^3 + 3*x0*x1^2 + y0^2 - y1^2 - 1, -3*x0^2*x1 + x1^3 + 2*y0*y1) - of Multivariate Polynomial Ring in x0, x1, y0, y1 over Number Field in w - with defining polynomial x^5 - 2 + sage: K. = NumberField(x^5 - 2) # optional - sage.rings.number_field + sage: R. = K[] # optional - sage.rings.number_field + sage: L. = K.extension(x^2 + 1) # optional - sage.rings.number_field + sage: S. = L[] # optional - sage.rings.number_field + sage: I = S.ideal([y^2 - x^3 - 1]) # optional - sage.rings.number_field + sage: I.weil_restriction() # optional - sage.rings.number_field + Ideal (-x0^3 + 3*x0*x1^2 + y0^2 - y1^2 - 1, -3*x0^2*x1 + x1^3 + 2*y0*y1) of + Multivariate Polynomial Ring in x0, x1, y0, y1 + over Number Field in w with defining polynomial x^5 - 2 .. NOTE:: @@ -5442,8 +5542,9 @@ class MPolynomialIdeal_quotient(MPolynomialIdeal): sage: Q. = QQ['x,y,z,w'].quotient(['x*y-z^2', 'y^2-w^2']) sage: I = ideal(x + y^2 + z - 1) sage: I - Ideal (w^2 + x + z - 1) of Quotient of Multivariate Polynomial Ring - in x, y, z, w over Rational Field by the ideal (x*y - z^2, y^2 - w^2) + Ideal (w^2 + x + z - 1) of Quotient + of Multivariate Polynomial Ring in x, y, z, w over Rational Field + by the ideal (x*y - z^2, y^2 - w^2) """ def reduce(self, f): r""" @@ -5454,9 +5555,9 @@ def reduce(self, f): EXAMPLES:: sage: R. = PolynomialRing(QQ, order='lex') - sage: I = R.ideal([T^2+U^2-1, V^2+W^2-1, X^2+Y^2+Z^2-1]) + sage: I = R.ideal([T^2 + U^2 - 1, V^2 + W^2 - 1, X^2 + Y^2 + Z^2 - 1]) sage: Q. = R.quotient(I) - sage: J = Q.ideal([u*v-x, u*w-y, t-z]) + sage: J = Q.ideal([u*v - x, u*w - y, t - z]) sage: J.reduce(t^2 - z^2) 0 sage: J.reduce(u^2) diff --git a/src/sage/rings/polynomial/multi_polynomial_libsingular.pyx b/src/sage/rings/polynomial/multi_polynomial_libsingular.pyx index 64f01724081..09367f626a4 100644 --- a/src/sage/rings/polynomial/multi_polynomial_libsingular.pyx +++ b/src/sage/rings/polynomial/multi_polynomial_libsingular.pyx @@ -370,7 +370,7 @@ cdef class MPolynomialRing_libsingular(MPolynomialRing_base): Traceback (most recent call last): ... NotImplementedError: polynomials over Ring of integers modulo 1 are not supported in Singular - sage: MPolynomialRing_libsingular(SR, 1, ["x"], "lex") + sage: MPolynomialRing_libsingular(SR, 1, ["x"], "lex") # optional - sage.symbolic Traceback (most recent call last): ... NotImplementedError: polynomials over Symbolic Ring are not supported in Singular @@ -468,7 +468,7 @@ cdef class MPolynomialRing_libsingular(MPolynomialRing_base): cpdef _coerce_map_from_(self, other): """ - Return True if and only if there exists a coercion map from + Return ``True`` if and only if there exists a coercion map from ``other`` to ``self``. TESTS:: diff --git a/src/sage/rings/polynomial/multi_polynomial_ring.py b/src/sage/rings/polynomial/multi_polynomial_ring.py index 239737eb500..acf72a9e175 100644 --- a/src/sage/rings/polynomial/multi_polynomial_ring.py +++ b/src/sage/rings/polynomial/multi_polynomial_ring.py @@ -27,13 +27,13 @@ We construct the Frobenius morphism on `\GF{5}[x,y,z]` over `\GF{5}`:: - sage: R. = GF(5)[] - sage: frob = R.hom([x^5, y^5, z^5]) - sage: frob(x^2 + 2*y - z^4) + sage: R. = GF(5)[] # optional - sage.rings.finite_rings + sage: frob = R.hom([x^5, y^5, z^5]) # optional - sage.rings.finite_rings + sage: frob(x^2 + 2*y - z^4) # optional - sage.rings.finite_rings -z^20 + x^10 + 2*y^5 - sage: frob((x + 2*y)^3) + sage: frob((x + 2*y)^3) # optional - sage.rings.finite_rings x^15 + x^10*y^5 + 2*x^5*y^10 - 2*y^15 - sage: (x^5 + 2*y^5)^3 + sage: (x^5 + 2*y^5)^3 # optional - sage.rings.finite_rings x^15 + x^10*y^5 + 2*x^5*y^10 - 2*y^15 We make a polynomial ring in one variable over a polynomial ring in @@ -46,7 +46,7 @@ TESTS:: - sage: PolynomialRing(GF(5), 3, 'xyz').objgens() + sage: PolynomialRing(GF(5), 3, 'xyz').objgens() # optional - sage.rings.finite_rings (Multivariate Polynomial Ring in x, y, z over Finite Field of size 5, (x, y, z)) """ @@ -203,7 +203,7 @@ def __call__(self, x=0, check=True): sage: R. = QQ[] sage: S. = ZZ[] - sage: T. = GF(7)[] + sage: T. = GF(7)[] # optional - sage.rings.finite_rings We convert from integer polynomials to rational polynomials, and back:: @@ -219,9 +219,9 @@ def __call__(self, x=0, check=True): :: - sage: f = R(T.0^2 - 4*T.1^3); f + sage: f = R(T.0^2 - 4*T.1^3); f # optional - sage.rings.finite_rings 3*y^3 + x^2 - sage: parent(f) + sage: parent(f) # optional - sage.rings.finite_rings Multivariate Polynomial Ring in x, y over Rational Field We dump and load the polynomial ring S:: @@ -241,24 +241,24 @@ def __call__(self, x=0, check=True): variable names:: sage: R. = PolynomialRing(QQ,2) - sage: S. = PolynomialRing(GF(7),2) + sage: S. = PolynomialRing(GF(7),2) # optional - sage.rings.finite_rings sage: f = x^2 + 2/3*y^3 - sage: S(f) + sage: S(f) # optional - sage.rings.finite_rings 3*b^3 + a^2 Conversion from symbolic variables:: - sage: x,y,z = var('x,y,z') - sage: R = QQ['x,y,z'] - sage: type(x) + sage: x,y,z = var('x,y,z') # optional - sage.symbolic + sage: R = QQ['x,y,z'] # optional - sage.symbolic + sage: type(x) # optional - sage.symbolic - sage: type(R(x)) + sage: type(R(x)) # optional - sage.symbolic - sage: f = R(x^3 + y^3 - z^3); f + sage: f = R(x^3 + y^3 - z^3); f # optional - sage.symbolic x^3 + y^3 - z^3 - sage: type(f) + sage: type(f) # optional - sage.symbolic - sage: parent(f) + sage: parent(f) # optional - sage.symbolic Multivariate Polynomial Ring in x, y, z over Rational Field A more complicated symbolic and computational mix. Behind the @@ -267,11 +267,11 @@ def __call__(self, x=0, check=True): :: sage: R = QQ['x,y,z'] - sage: f = (x^3 + y^3 - z^3)^10; f + sage: f = (x^3 + y^3 - z^3)^10; f # optional - sage.symbolic (x^3 + y^3 - z^3)^10 - sage: g = R(f); parent(g) + sage: g = R(f); parent(g) # optional - sage.symbolic Multivariate Polynomial Ring in x, y, z over Rational Field - sage: (f - g).expand() + sage: (f - g).expand() # optional - sage.symbolic 0 It intelligently handles conversions from polynomial rings in a subset @@ -279,12 +279,12 @@ def __call__(self, x=0, check=True): :: - sage: R = GF(5)['x,y,z'] + sage: R = GF(5)['x,y,z'] # optional - sage.rings.finite_rings sage: S = ZZ['y'] - sage: R(7*S.0) + sage: R(7*S.0) # optional - sage.rings.finite_rings 2*y sage: T = ZZ['x,z'] - sage: R(2*T.0 + 6*T.1 + T.0*T.1^2) + sage: R(2*T.0 + 6*T.1 + T.0*T.1^2) # optional - sage.rings.finite_rings x*z^2 + 2*x + z :: @@ -793,7 +793,7 @@ def monomial_divides(self, a, b): def monomial_pairwise_prime(self, h, g): r""" - Return True if ``h`` and ``g`` are pairwise prime. + Return ``True`` if ``h`` and ``g`` are pairwise prime. Both are treated as monomials. @@ -895,7 +895,7 @@ def sum(self, terms): r""" Return a sum of elements of this multipolynomial ring. - This is method is much faster than the Python builtin sum. + This is method is much faster than the Python builtin :func:`sum`. EXAMPLES:: @@ -906,7 +906,7 @@ def sum(self, terms): sage: S.sum([x*y, 2*x^2*z - 2*x*y, 1 + y + z]) (-x + 1)*y + (2*x^2 + 1)*z + 1 - Comparison with builtin sum:: + Comparison with builtin :func:`sum`:: sage: sum([x*y, 2*x^2*z - 2*x*y, 1 + y + z]) (-x + 1)*y + (2*x^2 + 1)*z + 1 diff --git a/src/sage/rings/polynomial/multi_polynomial_ring_base.pyx b/src/sage/rings/polynomial/multi_polynomial_ring_base.pyx index 70e1e7c861b..ce12783d73b 100644 --- a/src/sage/rings/polynomial/multi_polynomial_ring_base.pyx +++ b/src/sage/rings/polynomial/multi_polynomial_ring_base.pyx @@ -74,10 +74,10 @@ cdef class MPolynomialRing_base(sage.rings.ring.CommutativeRing): Check that :trac:`26958` is fixed:: - sage: from sage.rings.polynomial.multi_polynomial_libsingular import MPolynomialRing_libsingular - sage: class Foo(MPolynomialRing_libsingular): + sage: from sage.rings.polynomial.multi_polynomial_libsingular import MPolynomialRing_libsingular # optional - sage.libs.singular + sage: class Foo(MPolynomialRing_libsingular): # optional - sage.libs.singular ....: pass - sage: Foo(QQ, 2, ['x','y'], 'degrevlex') + sage: Foo(QQ, 2, ['x','y'], 'degrevlex') # optional - sage.libs.singular Multivariate Polynomial Ring in x, y over Rational Field """ if base_ring not in _CommutativeRings: @@ -133,14 +133,13 @@ cdef class MPolynomialRing_base(sage.rings.ring.CommutativeRing): sage: QQ['a','b']['x','y'].flattening_morphism() Flattening morphism: - From: Multivariate Polynomial Ring in x, y over Multivariate - Polynomial Ring in a, b over Rational Field - To: Multivariate Polynomial Ring in a, b, x, y over Rational - Field + From: Multivariate Polynomial Ring in x, y + over Multivariate Polynomial Ring in a, b over Rational Field + To: Multivariate Polynomial Ring in a, b, x, y over Rational Field sage: QQ['x,y'].flattening_morphism() - Identity endomorphism of Multivariate Polynomial Ring in x, y - over Rational Field + Identity endomorphism of + Multivariate Polynomial Ring in x, y over Rational Field """ base = self.base_ring() if is_MPolynomialRing(base) or polynomial_ring.is_PolynomialRing(base): @@ -151,7 +150,7 @@ cdef class MPolynomialRing_base(sage.rings.ring.CommutativeRing): def construction(self): """ - Returns a functor F and base ring R such that F(R) == self. + Returns a functor ``F`` and base ring ``R`` such that ``F(R) == self``. EXAMPLES:: @@ -238,7 +237,7 @@ cdef class MPolynomialRing_base(sage.rings.ring.CommutativeRing): sage: P. = PolynomialRing(ZZ) sage: P.completion([]) is P True - sage: P.completion(SR.var('x')) + sage: P.completion(SR.var('x')) # optional - sage.symbolic Traceback (most recent call last): ... TypeError: x is not an element of Multivariate Polynomial Ring @@ -284,7 +283,7 @@ cdef class MPolynomialRing_base(sage.rings.ring.CommutativeRing): def remove_var(self, *var, order=None): """ - Remove a variable or sequence of variables from self. + Remove a variable or sequence of variables from ``self``. If ``order`` is not specified, then the subring inherits the term order of the original ring, if possible. @@ -294,14 +293,14 @@ cdef class MPolynomialRing_base(sage.rings.ring.CommutativeRing): sage: P. = PolynomialRing(ZZ) sage: P.remove_var(z) Multivariate Polynomial Ring in x, y, w over Integer Ring - sage: P.remove_var(z,x) + sage: P.remove_var(z, x) Multivariate Polynomial Ring in y, w over Integer Ring - sage: P.remove_var(y,z,x) + sage: P.remove_var(y, z, x) Univariate Polynomial Ring in w over Integer Ring Removing all variables results in the base ring:: - sage: P.remove_var(y,z,x,w) + sage: P.remove_var(y, z, x, w) Integer Ring If possible, the term order is kept:: @@ -317,7 +316,7 @@ cdef class MPolynomialRing_base(sage.rings.ring.CommutativeRing): Be careful with block orders when removing variables:: sage: R. = PolynomialRing(ZZ, order='deglex(2),lex(3)') - sage: R.remove_var(x,y,z) + sage: R.remove_var(x, y, z) Traceback (most recent call last): ... ValueError: impossible to use the original term order (most @@ -345,18 +344,18 @@ cdef class MPolynomialRing_base(sage.rings.ring.CommutativeRing): def univariate_ring(self, x): """ Return a univariate polynomial ring whose base ring comprises all - but one variables of self. + but one variables of ``self``. INPUT: - - ``x`` -- a variable of self. + - ``x`` -- a variable of ``self``. EXAMPLES:: sage: P. = QQ[] sage: P.univariate_ring(y) - Univariate Polynomial Ring in y over Multivariate Polynomial - Ring in x, z over Rational Field + Univariate Polynomial Ring in y + over Multivariate Polynomial Ring in x, z over Rational Field """ return self.remove_var(x)[str(x)] @@ -368,9 +367,9 @@ cdef class MPolynomialRing_base(sage.rings.ring.CommutativeRing): This function can be called in two ways: - 1. interpolation(bound, points, values) + 1. ``interpolation(bound, points, values)`` - 2. interpolation(bound, function) + 2. ``interpolation(bound, function)`` INPUT: @@ -399,18 +398,16 @@ cdef class MPolynomialRing_base(sage.rings.ring.CommutativeRing): ....: return a^3*b + b + c^2 + 25 ....: sage: R. = PolynomialRing(QQ) - sage: R.interpolation(4, F) + sage: R.interpolation(4, F) # optional - sage.modules x^3*y + z^2 + y + 25 - sage: def F(a,b,c): ....: return a^3*b + b + c^2 + 25 ....: sage: R. = PolynomialRing(QQ) - sage: R.interpolation([3,1,2], F) + sage: R.interpolation([3,1,2], F) # optional - sage.modules x^3*y + z^2 + y + 25 - sage: def F(a,b,c): ....: return a^3*b + b + c^2 + 25 ....: @@ -419,7 +416,7 @@ cdef class MPolynomialRing_base(sage.rings.ring.CommutativeRing): ....: (2,7,0),(1,10,13),(0,0,1),(-1,1,0),(2,5,3),(1,1,1),(7,4,11), ....: (12,1,9),(1,1,3),(4,-1,2),(0,1,5),(5,1,3),(3,1,-2),(2,11,3), ....: (4,12,19),(3,1,1),(5,2,-3),(12,1,1),(2,3,4)] - sage: R.interpolation([3,1,2], points, [F(*x) for x in points]) + sage: R.interpolation([3,1,2], points, [F(*x) for x in points]) # optional - sage.modules x^3*y + z^2 + y + 25 ALGORITHM: @@ -438,7 +435,7 @@ cdef class MPolynomialRing_base(sage.rings.ring.CommutativeRing): without any notice that there are more. Lastly, the interpolation function for univariate polynomial rings - is called ``lagrange_polynomial()``. + is called :meth:`lagrange_polynomial`. .. WARNING:: @@ -447,14 +444,14 @@ cdef class MPolynomialRing_base(sage.rings.ring.CommutativeRing): the given bounds. In particular it will *not* notice or check whether the result yields the correct evaluation for other points as well. So if you give wrong bounds, you will get a wrong answer - without any warning. + without any warning. :: - sage: def F(a,b,c): - ....: return a^3*b + b + c^2 + 25 - ....: - sage: R. = PolynomialRing(QQ) - sage: R.interpolation(3,F) - 1/2*x^3 + x*y + z^2 - 1/2*x + y + 25 + sage: def F(a,b,c): + ....: return a^3*b + b + c^2 + 25 + ....: + sage: R. = PolynomialRing(QQ) + sage: R.interpolation(3, F) # optional - sage.modules + 1/2*x^3 + x*y + z^2 - 1/2*x + y + 25 .. SEEALSO:: @@ -583,13 +580,13 @@ cdef class MPolynomialRing_base(sage.rings.ring.CommutativeRing): implicitly calling ``_coerce_c_impl``:: sage: z = polygen(QQ, 'z') - sage: W.=NumberField(z^2+1) - sage: Q. = W[] - sage: W1 = FractionField (Q) - sage: S. = W1[] - sage: u + x + sage: W. = NumberField(z^2 + 1) # optional - sage.rings.number_field + sage: Q. = W[] # optional - sage.rings.number_field + sage: W1 = FractionField(Q) # optional - sage.rings.number_field + sage: S. = W1[] # optional - sage.rings.number_field + sage: u + x # optional - sage.rings.number_field x + u - sage: x + 1/u + sage: x + 1/u # optional - sage.rings.number_field x + 1/u """ try: @@ -679,7 +676,8 @@ cdef class MPolynomialRing_base(sage.rings.ring.CommutativeRing): EXAMPLES:: - sage: P. = PolynomialRing(QQ,order=TermOrder('degrevlex',1)+TermOrder('lex',2)) + sage: P. = PolynomialRing(QQ, order=TermOrder('degrevlex',1) + ....: + TermOrder('lex',2)) sage: print(P.repr_long()) Polynomial Ring Base Ring : Rational Field @@ -718,12 +716,12 @@ cdef class MPolynomialRing_base(sage.rings.ring.CommutativeRing): EXAMPLES:: sage: T. = ZZ[] - sage: K. = NumberField(t^2 + 1) - sage: R. = K[] - sage: Q5 = Qp(5); i5 = Q5(-1).sqrt() - sage: R._is_valid_homomorphism_(Q5, [Q5.teichmuller(2), Q5(6).log()]) # no coercion + sage: K. = NumberField(t^2 + 1) # optional - sage.rings.number_field + sage: R. = K[] # optional - sage.rings.number_field + sage: Q5 = Qp(5); i5 = Q5(-1).sqrt() # optional - sage.rings.number_field + sage: R._is_valid_homomorphism_(Q5, [Q5.teichmuller(2), Q5(6).log()]) # no coercion # optional - sage.rings.number_field False - sage: R._is_valid_homomorphism_(Q5, [Q5.teichmuller(2), Q5(6).log()], base_map=K.hom([i5])) + sage: R._is_valid_homomorphism_(Q5, [Q5.teichmuller(2), Q5(6).log()], base_map=K.hom([i5])) # optional - sage.rings.number_field True """ if base_map is None: @@ -740,33 +738,33 @@ cdef class MPolynomialRing_base(sage.rings.ring.CommutativeRing): EXAMPLES:: - sage: R. = PolynomialRing(GF(127),10) - sage: R._magma_init_(magma) # optional - magma + sage: R. = PolynomialRing(GF(127),10) # optional - sage.rings.finite_rings + sage: R._magma_init_(magma) # optional - magma # optional - sage.rings.finite_rings 'SageCreateWithNames(PolynomialRing(_sage_ref...,10,"grevlex"),["a","b","c","d","e","f","g","h","i","j"])' - sage: R. = PolynomialRing(QQ,3) - sage: magma(R) # optional - magma + sage: R. = PolynomialRing(QQ, 3) # optional - sage.rings.finite_rings + sage: magma(R) # optional - magma # optional - sage.rings.finite_rings Polynomial ring of rank 3 over Rational Field Order: Graded Reverse Lexicographical Variables: y, z, w A complicated nested example:: - sage: R. = PolynomialRing(GF(9,'a')); S. = R[]; S + sage: R. = PolynomialRing(GF(9,'a')); S. = R[]; S # optional - sage.rings.finite_rings Multivariate Polynomial Ring in T, W over Multivariate Polynomial Ring in a, b, c over Finite Field in a of size 3^2 - sage: magma(S) # optional - magma + sage: magma(S) # optional - magma # optional - sage.rings.finite_rings Polynomial ring of rank 2 over Polynomial ring of rank 3 over GF(3^2) Order: Graded Reverse Lexicographical Variables: T, W - sage: magma(PolynomialRing(GF(7),4, 'x')) # optional - magma + sage: magma(PolynomialRing(GF(7),4, 'x')) # optional - magma # optional - sage.rings.finite_rings Polynomial ring of rank 4 over GF(7) Order: Graded Reverse Lexicographical Variables: x0, x1, x2, x3 - sage: magma(PolynomialRing(GF(49,'a'),10, 'x')) # optional - magma + sage: magma(PolynomialRing(GF(49,'a'),10, 'x')) # optional - magma # optional - sage.rings.finite_rings Polynomial ring of rank 10 over GF(7^2) Order: Graded Reverse Lexicographical Variables: x0, x1, x2, x3, x4, x5, x6, x7, x8, x9 @@ -800,11 +798,11 @@ cdef class MPolynomialRing_base(sage.rings.ring.CommutativeRing): EXAMPLES:: - sage: F = CyclotomicField(8) - sage: P. = F[] - sage: gap(P) # indirect doctest + sage: F = CyclotomicField(8) # optional - sage.rings.number_field + sage: P. = F[] # optional - sage.rings.number_field + sage: gap(P) # indirect doctest # optional - sage.rings.number_field PolynomialRing( CF(8), ["x", "y"] ) - sage: libgap(P) + sage: libgap(P) # optional - sage.rings.number_field [x,y] """ L = ['"%s"' % t for t in self.variable_names()] @@ -862,8 +860,8 @@ cdef class MPolynomialRing_base(sage.rings.ring.CommutativeRing): sage: R = PolynomialRing(QQ, 'x', 3) sage: R.characteristic() 0 - sage: R = PolynomialRing(GF(7),'x', 20) - sage: R.characteristic() + sage: R = PolynomialRing(GF(7), 'x', 20) # optional - sage.rings.finite_rings + sage: R.characteristic() # optional - sage.rings.finite_rings 7 """ return self.base_ring().characteristic() @@ -1335,9 +1333,9 @@ cdef class MPolynomialRing_base(sage.rings.ring.CommutativeRing): def change_ring(self, base_ring=None, names=None, order=None): """ - Return a new multivariate polynomial ring which isomorphic to - self, but has a different ordering given by the parameter - 'order' or names given by the parameter 'names'. + Return a new multivariate polynomial ring which is isomorphic to + ``self``, but has a different ordering given by the parameter + ``order`` or names given by the parameter ``names``. INPUT: @@ -1347,11 +1345,11 @@ cdef class MPolynomialRing_base(sage.rings.ring.CommutativeRing): EXAMPLES:: - sage: P. = PolynomialRing(GF(127),3,order='lex') - sage: x > y^2 + sage: P. = PolynomialRing(GF(127), 3, order='lex') # optional - sage.rings.finite_rings + sage: x > y^2 # optional - sage.rings.finite_rings True - sage: Q. = P.change_ring(order='degrevlex') - sage: x > y^2 + sage: Q. = P.change_ring(order='degrevlex') # optional - sage.rings.finite_rings + sage: x > y^2 # optional - sage.rings.finite_rings False """ if base_ring is None: @@ -1406,7 +1404,7 @@ cdef class MPolynomialRing_base(sage.rings.ring.CommutativeRing): The number of such monomials equals `\binom{n+k-1}{k}` where `n` is the number of variables and `k` the degree:: - sage: len(mons) == binomial(3+2-1,2) + sage: len(mons) == binomial(3 + 2 - 1, 2) True """ deg_of_gens = [x.degree() for x in self.gens()] @@ -1527,7 +1525,7 @@ cdef class MPolynomialRing_base(sage.rings.ring.CommutativeRing): def macaulay_resultant(self, *args, **kwds): r""" - This is an implementation of the Macaulay Resultant. It computes + This is an implementation of the Macaulay resultant. It computes the resultant of universal polynomials as well as polynomials with constant coefficients. This is a project done in sage days 55. It's based on the implementation in Maple by @@ -1550,17 +1548,17 @@ cdef class MPolynomialRing_base(sage.rings.ring.CommutativeRing): INPUT: - ``args`` -- a list of `n` homogeneous polynomials in `n` variables. - works when ``args[0]`` is the list of polynomials, - or ``args`` is itself the list of polynomials + works when ``args[0]`` is the list of polynomials, + or ``args`` is itself the list of polynomials kwds: - ``sparse`` -- boolean (optional - default: ``False``) - if ``True`` function creates sparse matrices. + if ``True``, the function creates sparse matrices. OUTPUT: - - the macaulay resultant, an element of the base ring of ``self`` + - the Macaulay resultant, an element of the base ring of ``self`` .. TODO:: Working with sparse matrices should usually give faster results, @@ -1571,27 +1569,25 @@ cdef class MPolynomialRing_base(sage.rings.ring.CommutativeRing): The number of polynomials has to match the number of variables:: - sage: R. = PolynomialRing(QQ,3) - sage: R.macaulay_resultant([y,x+z]) + sage: R. = PolynomialRing(QQ, 3) + sage: R.macaulay_resultant([y, x + z]) # optional - sage.modules Traceback (most recent call last): ... - TypeError: number of polynomials(= 2) must equal number of - variables (= 3) + TypeError: number of polynomials(= 2) must equal number of variables (= 3) The polynomials need to be all homogeneous:: - sage: R. = PolynomialRing(QQ,3) - sage: R.macaulay_resultant([y, x+z, z+x^3]) + sage: R. = PolynomialRing(QQ, 3) + sage: R.macaulay_resultant([y, x + z, z + x^3]) # optional - sage.modules Traceback (most recent call last): ... - TypeError: resultant for non-homogeneous polynomials is - not supported + TypeError: resultant for non-homogeneous polynomials is not supported All polynomials must be in the same ring:: sage: S. = PolynomialRing(QQ, 2) sage: R. = PolynomialRing(QQ,3) - sage: S.macaulay_resultant([y, z+x]) + sage: S.macaulay_resultant([y, z+x]) # optional - sage.modules Traceback (most recent call last): ... TypeError: not all inputs are polynomials in the calling ring @@ -1599,8 +1595,8 @@ cdef class MPolynomialRing_base(sage.rings.ring.CommutativeRing): The following example recreates Proposition 2.10 in Ch.3 in [CLO2005]:: sage: K. = PolynomialRing(ZZ, 2) - sage: flist,R = K._macaulay_resultant_universal_polynomials([1,1,2]) - sage: R.macaulay_resultant(flist) + sage: flist, R = K._macaulay_resultant_universal_polynomials([1,1,2]) + sage: R.macaulay_resultant(flist) # optional - sage.modules u2^2*u4^2*u6 - 2*u1*u2*u4*u5*u6 + u1^2*u5^2*u6 - u2^2*u3*u4*u7 + u1*u2*u3*u5*u7 + u0*u2*u4*u5*u7 - u0*u1*u5^2*u7 + u1*u2*u3*u4*u8 - u0*u2*u4^2*u8 - u1^2*u3*u5*u8 + u0*u1*u4*u5*u8 + u2^2*u3^2*u9 - @@ -1609,11 +1605,11 @@ cdef class MPolynomialRing_base(sage.rings.ring.CommutativeRing): u1^2*u3^2*u11 - 2*u0*u1*u3*u4*u11 + u0^2*u4^2*u11 The following example degenerates into the determinant of - a `3*3` matrix:: + a `3\times 3` matrix:: sage: K. = PolynomialRing(ZZ, 2) sage: flist,R = K._macaulay_resultant_universal_polynomials([1,1,1]) - sage: R.macaulay_resultant(flist) + sage: R.macaulay_resultant(flist) # optional - sage.modules -u2*u4*u6 + u1*u5*u6 + u2*u3*u7 - u0*u5*u7 - u1*u3*u8 + u0*u4*u8 The following example is by Patrick Ingram (:arxiv:`1310.4114`):: @@ -1624,57 +1620,57 @@ cdef class MPolynomialRing_base(sage.rings.ring.CommutativeRing): sage: f1 = y1*x2^2 - x1^2 + 2*x0*x2 sage: f2 = x0*x1 - x2^2 sage: flist = [f0,f1,f2] - sage: R.macaulay_resultant([f0,f1,f2]) + sage: R.macaulay_resultant([f0,f1,f2]) # optional - sage.modules y0^2*y1^2 - 4*y0^3 - 4*y1^3 + 18*y0*y1 - 27 A simple example with constant rational coefficients:: - sage: R. = PolynomialRing(QQ,4) - sage: R.macaulay_resultant([w,z,y,x]) + sage: R. = PolynomialRing(QQ, 4) + sage: R.macaulay_resultant([w, z, y, x]) # optional - sage.modules 1 An example where the resultant vanishes:: - sage: R. = PolynomialRing(QQ,3) - sage: R.macaulay_resultant([x+y,y^2,x]) + sage: R. = PolynomialRing(QQ, 3) + sage: R.macaulay_resultant([x + y, y^2, x]) # optional - sage.modules 0 An example of bad reduction at a prime `p = 5`:: - sage: R. = PolynomialRing(QQ,3) - sage: R.macaulay_resultant([y,x^3+25*y^2*x,5*z]) + sage: R. = PolynomialRing(QQ, 3) + sage: R.macaulay_resultant([y, x^3 + 25*y^2*x, 5*z]) # optional - sage.modules 125 The input can given as an unpacked list of polynomials:: - sage: R. = PolynomialRing(QQ,3) - sage: R.macaulay_resultant(y,x^3+25*y^2*x,5*z) + sage: R. = PolynomialRing(QQ, 3) + sage: R.macaulay_resultant(y, x^3 + 25*y^2*x, 5*z) # optional - sage.modules 125 An example when the coefficients live in a finite field:: - sage: F = FiniteField(11) - sage: R. = PolynomialRing(F,4) - sage: R.macaulay_resultant([z,x^3,5*y,w]) + sage: F = FiniteField(11) # optional - sage.rings.finite_rings + sage: R. = PolynomialRing(F, 4) # optional - sage.rings.finite_rings + sage: R.macaulay_resultant([z, x^3, 5*y, w]) # optional - sage.modules sage.rings.finite_rings 4 Example when the denominator in the algorithm vanishes(in this case the resultant is the constant term of the quotient of char polynomials of numerator/denominator):: - sage: R. = PolynomialRing(QQ,3) - sage: R.macaulay_resultant([y, x+z, z^2]) + sage: R. = PolynomialRing(QQ, 3) + sage: R.macaulay_resultant([y, x + z, z^2]) # optional - sage.modules -1 - When there are only 2 polynomials, macaulay resultant degenerates + When there are only 2 polynomials, the Macaulay resultant degenerates to the traditional resultant:: - sage: R. = PolynomialRing(QQ,1) - sage: f = x^2+1; g = x^5+1 + sage: R. = PolynomialRing(QQ, 1) + sage: f = x^2 + 1; g = x^5 + 1 sage: fh = f.homogenize() sage: gh = g.homogenize() sage: RH = fh.parent() - sage: f.resultant(g) == RH.macaulay_resultant([fh,gh]) + sage: f.resultant(g) == RH.macaulay_resultant([fh, gh]) # optional - sage.modules True """ @@ -1754,9 +1750,9 @@ cdef class MPolynomialRing_base(sage.rings.ring.CommutativeRing): EXAMPLES:: sage: R = QQ['x,y,z'] - sage: W = R.weyl_algebra(); W + sage: W = R.weyl_algebra(); W # optional - sage.combinat sage.modules Differential Weyl algebra of polynomials in x, y, z over Rational Field - sage: W.polynomial_ring() == R + sage: W.polynomial_ring() == R # optional - sage.combinat sage.modules True """ from sage.algebras.weyl_algebra import DifferentialWeylAlgebra @@ -1773,8 +1769,8 @@ cdef class BooleanPolynomialRing_base(MPolynomialRing_base): EXAMPLES:: sage: from sage.rings.polynomial.multi_polynomial_ring_base import BooleanPolynomialRing_base - sage: R. = BooleanPolynomialRing() - sage: isinstance(R, BooleanPolynomialRing_base) + sage: R. = BooleanPolynomialRing() # optional - sage.rings.polynomial.pbori + sage: isinstance(R, BooleanPolynomialRing_base) # optional - sage.rings.polynomial.pbori True By design, there is only one direct implementation subclass:: diff --git a/src/sage/rings/polynomial/multi_polynomial_sequence.py b/src/sage/rings/polynomial/multi_polynomial_sequence.py index c4ad2530b58..8168439c2df 100644 --- a/src/sage/rings/polynomial/multi_polynomial_sequence.py +++ b/src/sage/rings/polynomial/multi_polynomial_sequence.py @@ -23,24 +23,24 @@ As an example consider a small scale variant of the AES:: - sage: sr = mq.SR(2,1,2,4,gf2=True,polybori=True) - sage: sr + sage: sr = mq.SR(2, 1, 2, 4, gf2=True, polybori=True) # optional - sage.rings.polynomial.pbori + sage: sr # optional - sage.rings.polynomial.pbori SR(2,1,2,4) We can construct a polynomial sequence for a random plaintext-ciphertext pair and study it:: - sage: set_random_seed(1) - sage: while True: # workaround (see :trac:`31891`) + sage: set_random_seed(1) # optional - sage.rings.polynomial.pbori + sage: while True: # workaround (see :trac:`31891`) # optional - sage.rings.polynomial.pbori ....: try: ....: F, s = sr.polynomial_system() ....: break ....: except ZeroDivisionError: ....: pass - sage: F + sage: F # optional - sage.rings.polynomial.pbori Polynomial Sequence with 112 Polynomials in 64 Variables - sage: r2 = F.part(2); r2 + sage: r2 = F.part(2); r2 # optional - sage.rings.polynomial.pbori (w200 + k100 + x100 + x102 + x103, w201 + k101 + x100 + x101 + x103 + 1, w202 + k102 + x100 + x101 + x102 + 1, @@ -76,7 +76,7 @@ We separate the system in independent subsystems:: - sage: C = Sequence(r2).connected_components(); C + sage: C = Sequence(r2).connected_components(); C # optional - sage.rings.polynomial.pbori [[w200 + k100 + x100 + x102 + x103, w201 + k101 + x100 + x101 + x103 + 1, w202 + k102 + x100 + x101 + x102 + 1, @@ -109,37 +109,37 @@ x110*w110 + x110*w111 + x110*w112 + x111*w112 + x112*w110 + x112*w111 + x112*w113 + x113*w111 + w112, x110*w111 + x111*w110 + x111*w112 + x112*w110 + x113*w111 + x113*w113 + w113, x110*w112 + x111*w111 + x112*w110 + x113*w113 + 1]] - sage: C[0].groebner_basis() + sage: C[0].groebner_basis() # optional - sage.rings.polynomial.pbori Polynomial Sequence with 30 Polynomials in 16 Variables and compute the coefficient matrix:: - sage: A,v = Sequence(r2).coefficient_matrix() - sage: A.rank() + sage: A,v = Sequence(r2).coefficient_matrix() # optional - sage.rings.polynomial.pbori + sage: A.rank() # optional - sage.rings.polynomial.pbori 32 Using these building blocks we can implement a simple XL algorithm easily:: - sage: sr = mq.SR(1,1,1,4, gf2=True, polybori=True, order='lex') - sage: while True: # workaround (see :trac:`31891`) + sage: sr = mq.SR(1,1,1,4, gf2=True, polybori=True, order='lex') # optional - sage.rings.polynomial.pbori + sage: while True: # workaround (see :trac:`31891`) # optional - sage.rings.polynomial.pbori ....: try: ....: F, s = sr.polynomial_system() ....: break ....: except ZeroDivisionError: ....: pass - sage: monomials = [a*b for a in F.variables() for b in F.variables() if a = PolynomialRing(GF(127),4) - sage: I = sage.rings.ideal.Katsura(P) + sage: P. = PolynomialRing(GF(127), 4) # optional - sage.rings.finite_rings + sage: I = sage.rings.ideal.Katsura(P) # optional - sage.rings.finite_rings If a list of tuples is provided, those form the parts:: - sage: F = Sequence([I.gens(),I.gens()], I.ring()); F # indirect doctest + sage: F = Sequence([I.gens(),I.gens()], I.ring()); F # indirect doctest # optional - sage.rings.finite_rings [a + 2*b + 2*c + 2*d - 1, a^2 + 2*b^2 + 2*c^2 + 2*d^2 - a, 2*a*b + 2*b*c + 2*c*d - b, @@ -234,12 +234,12 @@ def PolynomialSequence(arg1, arg2=None, immutable=False, cr=False, cr_str=None): a^2 + 2*b^2 + 2*c^2 + 2*d^2 - a, 2*a*b + 2*b*c + 2*c*d - b, b^2 + 2*a*c + 2*b*d - c] - sage: F.nparts() + sage: F.nparts() # optional - sage.rings.finite_rings 2 If an ideal is provided, the generators are used:: - sage: Sequence(I) + sage: Sequence(I) # optional - sage.rings.finite_rings [a + 2*b + 2*c + 2*d - 1, a^2 + 2*b^2 + 2*c^2 + 2*d^2 - a, 2*a*b + 2*b*c + 2*c*d - b, @@ -247,22 +247,22 @@ def PolynomialSequence(arg1, arg2=None, immutable=False, cr=False, cr_str=None): If a list of polynomials is provided, the system has only one part:: - sage: F = Sequence(I.gens(), I.ring()); F + sage: F = Sequence(I.gens(), I.ring()); F # optional - sage.rings.finite_rings [a + 2*b + 2*c + 2*d - 1, a^2 + 2*b^2 + 2*c^2 + 2*d^2 - a, 2*a*b + 2*b*c + 2*c*d - b, b^2 + 2*a*c + 2*b*d - c] - sage: F.nparts() + sage: F.nparts() # optional - sage.rings.finite_rings 1 We test that the ring is inferred correctly:: - sage: P. = GF(2)[] + sage: P. = GF(2)[] # optional - sage.rings.finite_rings sage: from sage.rings.polynomial.multi_polynomial_sequence import PolynomialSequence - sage: PolynomialSequence([1,x,y]).ring() + sage: PolynomialSequence([1,x,y]).ring() # optional - sage.rings.finite_rings Multivariate Polynomial Ring in x, y, z over Finite Field of size 2 - sage: PolynomialSequence([[1,x,y], [0]]).ring() + sage: PolynomialSequence([[1,x,y], [0]]).ring() # optional - sage.rings.finite_rings Multivariate Polynomial Ring in x, y, z over Finite Field of size 2 TESTS: @@ -271,10 +271,10 @@ def PolynomialSequence(arg1, arg2=None, immutable=False, cr=False, cr_str=None): characteristic 2 (see :trac:`19452`):: sage: from sage.rings.polynomial.multi_polynomial_sequence import PolynomialSequence - sage: F = GF(2) - sage: L. = PowerSeriesRing(F,'t') - sage: R. = PolynomialRing(L,'x,y') - sage: PolynomialSequence([0], R) + sage: F = GF(2) # optional - sage.rings.finite_rings + sage: L. = PowerSeriesRing(F,'t') # optional - sage.rings.finite_rings + sage: R. = PolynomialRing(L,'x,y') # optional - sage.rings.finite_rings + sage: PolynomialSequence([0], R) # optional - sage.rings.finite_rings [0] A PolynomialSequence can be created from an iterator (see :trac:`25989`):: @@ -386,22 +386,25 @@ def __init__(self, parts, ring, immutable=False, cr=False, cr_str=None): EXAMPLES:: - sage: P. = PolynomialRing(GF(127),4) - sage: I = sage.rings.ideal.Katsura(P) + sage: P. = PolynomialRing(GF(127), 4) # optional - sage.rings.finite_rings + sage: I = sage.rings.ideal.Katsura(P) # optional - sage.rings.finite_rings - sage: Sequence([I.gens()], I.ring()) # indirect doctest - [a + 2*b + 2*c + 2*d - 1, a^2 + 2*b^2 + 2*c^2 + 2*d^2 - a, 2*a*b + 2*b*c + 2*c*d - b, b^2 + 2*a*c + 2*b*d - c] + sage: Sequence([I.gens()], I.ring()) # indirect doctest # optional - sage.rings.finite_rings + [a + 2*b + 2*c + 2*d - 1, a^2 + 2*b^2 + 2*c^2 + 2*d^2 - a, + 2*a*b + 2*b*c + 2*c*d - b, b^2 + 2*a*c + 2*b*d - c] If an ideal is provided, the generators are used.:: - sage: Sequence(I) - [a + 2*b + 2*c + 2*d - 1, a^2 + 2*b^2 + 2*c^2 + 2*d^2 - a, 2*a*b + 2*b*c + 2*c*d - b, b^2 + 2*a*c + 2*b*d - c] + sage: Sequence(I) # optional - sage.rings.finite_rings + [a + 2*b + 2*c + 2*d - 1, a^2 + 2*b^2 + 2*c^2 + 2*d^2 - a, + 2*a*b + 2*b*c + 2*c*d - b, b^2 + 2*a*c + 2*b*d - c] If a list of polynomials is provided, the system has only one part.:: - sage: Sequence(I.gens(), I.ring()) - [a + 2*b + 2*c + 2*d - 1, a^2 + 2*b^2 + 2*c^2 + 2*d^2 - a, 2*a*b + 2*b*c + 2*c*d - b, b^2 + 2*a*c + 2*b*d - c] + sage: Sequence(I.gens(), I.ring()) # optional - sage.rings.finite_rings + [a + 2*b + 2*c + 2*d - 1, a^2 + 2*b^2 + 2*c^2 + 2*d^2 - a, + 2*a*b + 2*b*c + 2*c*d - b, b^2 + 2*a*c + 2*b*d - c] """ Sequence_generic.__init__(self, sum(parts,tuple()), ring, check=False, immutable=immutable, @@ -415,11 +418,11 @@ def __copy__(self): EXAMPLES:: - sage: sr = mq.SR(allow_zero_inversions=True) - sage: F,s = sr.polynomial_system() - sage: copy(F) # indirect doctest + sage: sr = mq.SR(allow_zero_inversions=True) # optional - sage.rings.polynomial.pbori + sage: F,s = sr.polynomial_system() # optional - sage.rings.polynomial.pbori + sage: copy(F) # indirect doctest # optional - sage.rings.polynomial.pbori Polynomial Sequence with 40 Polynomials in 20 Variables - sage: type(F) == type(copy(F)) + sage: type(F) == type(copy(F)) # optional - sage.rings.polynomial.pbori True """ return self.__class__(self._parts, self._ring, immutable=self.is_immutable()) @@ -430,9 +433,9 @@ def ring(self): EXAMPLES:: - sage: sr = mq.SR(allow_zero_inversions=True,gf2=True,order='block') - sage: F,s = sr.polynomial_system() - sage: print(F.ring().repr_long()) + sage: sr = mq.SR(allow_zero_inversions=True, gf2=True, order='block') # optional - sage.rings.polynomial.pbori + sage: F, s = sr.polynomial_system() # optional - sage.rings.polynomial.pbori + sage: print(F.ring().repr_long()) # optional - sage.rings.polynomial.pbori Polynomial Ring Base Ring : Finite Field of size 2 Size : 20 Variables @@ -451,9 +454,9 @@ def nparts(self): EXAMPLES:: - sage: sr = mq.SR(allow_zero_inversions=True) - sage: F,s = sr.polynomial_system() - sage: F.nparts() + sage: sr = mq.SR(allow_zero_inversions=True) # optional - sage.rings.polynomial.pbori + sage: F, s = sr.polynomial_system() # optional - sage.rings.polynomial.pbori + sage: F.nparts() # optional - sage.rings.polynomial.pbori 4 """ return len(self._parts) @@ -464,10 +467,10 @@ def parts(self): EXAMPLES:: - sage: sr = mq.SR(allow_zero_inversions=True) - sage: F,s = sr.polynomial_system() - sage: l = F.parts() - sage: len(l) + sage: sr = mq.SR(allow_zero_inversions=True) # optional - sage.rings.polynomial.pbori + sage: F, s = sr.polynomial_system() # optional - sage.rings.polynomial.pbori + sage: l = F.parts() # optional - sage.rings.polynomial.pbori + sage: len(l) # optional - sage.rings.polynomial.pbori 4 """ return tuple(self._parts) @@ -478,10 +481,10 @@ def part(self, i): EXAMPLES:: - sage: sr = mq.SR(allow_zero_inversions=True) - sage: F,s = sr.polynomial_system() - sage: R0 = F.part(1) - sage: R0 + sage: sr = mq.SR(allow_zero_inversions=True) # optional - sage.rings.polynomial.pbori + sage: F, s = sr.polynomial_system() # optional - sage.rings.polynomial.pbori + sage: R0 = F.part(1) # optional - sage.rings.polynomial.pbori + sage: R0 # optional - sage.rings.polynomial.pbori (k000^2 + k001, k001^2 + k002, k002^2 + k003, k003^2 + k000) """ return self._parts[i] @@ -492,14 +495,14 @@ def ideal(self): EXAMPLES:: - sage: sr = mq.SR(allow_zero_inversions=True) - sage: F,s = sr.polynomial_system() - sage: P = F.ring() - sage: I = F.ideal() - sage: J = I.elimination_ideal(P.gens()[4:-4]) - sage: J <= I + sage: sr = mq.SR(allow_zero_inversions=True) # optional - sage.rings.polynomial.pbori + sage: F, s = sr.polynomial_system() # optional - sage.rings.polynomial.pbori + sage: P = F.ring() # optional - sage.rings.polynomial.pbori + sage: I = F.ideal() # optional - sage.rings.polynomial.pbori + sage: J = I.elimination_ideal(P.gens()[4:-4]) # optional - sage.rings.polynomial.pbori + sage: J <= I # optional - sage.rings.polynomial.pbori True - sage: set(J.gens().variables()).issubset(P.gens()[:4] + P.gens()[-4:]) + sage: set(J.gens().variables()).issubset(P.gens()[:4] + P.gens()[-4:]) # optional - sage.rings.polynomial.pbori True """ return self._ring.ideal(tuple(self)) @@ -519,10 +522,10 @@ def groebner_basis(self, *args, **kwargs): EXAMPLES:: - sage: sr = mq.SR(allow_zero_inversions=True) - sage: F,s = sr.polynomial_system() - sage: gb = F.groebner_basis() - sage: Ideal(gb).basis_is_groebner() + sage: sr = mq.SR(allow_zero_inversions=True) # optional - sage.rings.polynomial.pbori + sage: F, s = sr.polynomial_system() # optional - sage.rings.polynomial.pbori + sage: gb = F.groebner_basis() # optional - sage.rings.polynomial.pbori + sage: Ideal(gb).basis_is_groebner() # optional - sage.rings.polynomial.pbori True TESTS: @@ -530,12 +533,12 @@ def groebner_basis(self, *args, **kwargs): Check that this method also works for boolean polynomials (:trac:`10680`):: - sage: B. = BooleanPolynomialRing() - sage: F0 = Sequence(map(lambda f: f.lm(),[a,b,c,d])) - sage: F0.groebner_basis() + sage: B. = BooleanPolynomialRing() # optional - sage.rings.polynomial.pbori + sage: F0 = Sequence(map(lambda f: f.lm(), [a,b,c,d])) # optional - sage.rings.polynomial.pbori + sage: F0.groebner_basis() # optional - sage.rings.polynomial.pbori [a, b, c, d] - sage: F1 = Sequence([a,b,c*d,d^2]) - sage: F1.groebner_basis() + sage: F1 = Sequence([a,b,c*d,d^2]) # optional - sage.rings.polynomial.pbori + sage: F1.groebner_basis() # optional - sage.rings.polynomial.pbori [a, b, d] """ return self.ideal().groebner_basis(*args, **kwargs) @@ -546,9 +549,9 @@ def monomials(self): EXAMPLES:: - sage: sr = mq.SR(allow_zero_inversions=True) - sage: F,s = sr.polynomial_system() - sage: len(F.monomials()) + sage: sr = mq.SR(allow_zero_inversions=True) # optional - sage.rings.polynomial.pbori + sage: F,s = sr.polynomial_system() # optional - sage.rings.polynomial.pbori + sage: len(F.monomials()) # optional - sage.rings.polynomial.pbori 49 """ M = set() @@ -563,9 +566,9 @@ def nmonomials(self): EXAMPLES:: - sage: sr = mq.SR(allow_zero_inversions=True) - sage: F,s = sr.polynomial_system() - sage: F.nmonomials() + sage: sr = mq.SR(allow_zero_inversions=True) # optional - sage.rings.polynomial.pbori + sage: F,s = sr.polynomial_system() # optional - sage.rings.polynomial.pbori + sage: F.nmonomials() # optional - sage.rings.polynomial.pbori 49 """ return len(self.monomials()) @@ -577,9 +580,9 @@ def variables(self): EXAMPLES:: - sage: sr = mq.SR(allow_zero_inversions=True) - sage: F,s = sr.polynomial_system() - sage: F.variables()[:10] + sage: sr = mq.SR(allow_zero_inversions=True) # optional - sage.rings.polynomial.pbori + sage: F,s = sr.polynomial_system() # optional - sage.rings.polynomial.pbori + sage: F.variables()[:10] # optional - sage.rings.polynomial.pbori (k003, k002, k001, k000, s003, s002, s001, s000, w103, w102) """ V = set() @@ -594,9 +597,9 @@ def nvariables(self): EXAMPLES:: - sage: sr = mq.SR(allow_zero_inversions=True) - sage: F,s = sr.polynomial_system() - sage: F.nvariables() + sage: sr = mq.SR(allow_zero_inversions=True) # optional - sage.rings.polynomial.pbori + sage: F,s = sr.polynomial_system() # optional - sage.rings.polynomial.pbori + sage: F.nvariables() # optional - sage.rings.polynomial.pbori 20 """ return len(self.variables()) @@ -637,11 +640,13 @@ def algebraic_dependence(self): :: - sage: R. = PolynomialRing(GF(7)) - sage: S = Sequence([x, (x^2 + y^2 - 1)^2, x*y - 2]) - sage: I = S.algebraic_dependence(); I - Ideal (2 - 3*T2 - T0^2 + 3*T2^2 - T0^2*T2 + T2^3 + 2*T0^4 - 2*T0^2*T2^2 + T2^4 - T0^4*T1 + T0^4*T2 - 2*T0^6 + 2*T0^4*T2^2 + T0^8) of Multivariate Polynomial Ring in T0, T1, T2 over Finite Field of size 7 - sage: [F(S) for F in I.gens()] + sage: R. = PolynomialRing(GF(7)) # optional - sage.rings.finite_rings + sage: S = Sequence([x, (x^2 + y^2 - 1)^2, x*y - 2]) # optional - sage.rings.finite_rings + sage: I = S.algebraic_dependence(); I # optional - sage.rings.finite_rings + Ideal (2 - 3*T2 - T0^2 + 3*T2^2 - T0^2*T2 + T2^3 + 2*T0^4 - 2*T0^2*T2^2 + + T2^4 - T0^4*T1 + T0^4*T2 - 2*T0^6 + 2*T0^4*T2^2 + T0^8) + of Multivariate Polynomial Ring in T0, T1, T2 over Finite Field of size 7 + sage: [F(S) for F in I.gens()] # optional - sage.rings.finite_rings [0] .. NOTE:: @@ -702,23 +707,23 @@ def coefficient_matrix(self, sparse=True): EXAMPLES:: - sage: P. = PolynomialRing(GF(127),4) - sage: I = sage.rings.ideal.Katsura(P) - sage: I.gens() + sage: P. = PolynomialRing(GF(127), 4) # optional - sage.rings.finite_rings + sage: I = sage.rings.ideal.Katsura(P) # optional - sage.rings.finite_rings + sage: I.gens() # optional - sage.rings.finite_rings [a + 2*b + 2*c + 2*d - 1, a^2 + 2*b^2 + 2*c^2 + 2*d^2 - a, 2*a*b + 2*b*c + 2*c*d - b, b^2 + 2*a*c + 2*b*d - c] - sage: F = Sequence(I) - sage: A,v = F.coefficient_matrix() - sage: A + sage: F = Sequence(I) # optional - sage.rings.finite_rings + sage: A,v = F.coefficient_matrix() # optional - sage.rings.finite_rings + sage: A # optional - sage.rings.finite_rings [ 0 0 0 0 0 0 0 0 0 1 2 2 2 126] [ 1 0 2 0 0 2 0 0 2 126 0 0 0 0] [ 0 2 0 0 2 0 0 2 0 0 126 0 0 0] [ 0 0 1 2 0 0 2 0 0 0 0 126 0 0] - sage: v + sage: v # optional - sage.rings.finite_rings [a^2] [a*b] [b^2] @@ -734,7 +739,7 @@ def coefficient_matrix(self, sparse=True): [ d] [ 1] - sage: A*v + sage: A*v # optional - sage.rings.finite_rings [ a + 2*b + 2*c + 2*d - 1] [a^2 + 2*b^2 + 2*c^2 + 2*d^2 - a] [ 2*a*b + 2*b*c + 2*c*d - b] @@ -764,20 +769,20 @@ def coefficient_matrix(self, sparse=True): def subs(self, *args, **kwargs): """ Substitute variables for every polynomial in this system and - return a new system. See ``MPolynomial.subs`` for calling + return a new system. See :meth:`MPolynomial.subs` for calling convention. INPUT: - - ``args`` - arguments to be passed to ``MPolynomial.subs`` - - ``kwargs`` - keyword arguments to be passed to ``MPolynomial.subs`` + - ``args`` - arguments to be passed to :meth:`MPolynomial.subs` + - ``kwargs`` - keyword arguments to be passed to :meth:`MPolynomial.subs` EXAMPLES:: - sage: sr = mq.SR(allow_zero_inversions=True) - sage: F,s = sr.polynomial_system(); F + sage: sr = mq.SR(allow_zero_inversions=True) # optional - sage.rings.polynomial.pbori + sage: F, s = sr.polynomial_system(); F # optional - sage.rings.polynomial.pbori Polynomial Sequence with 40 Polynomials in 20 Variables - sage: F = F.subs(s); F + sage: F = F.subs(s); F # optional - sage.rings.polynomial.pbori Polynomial Sequence with 40 Polynomials in 16 Variables """ return PolynomialSequence(self._ring, [tuple([f.subs(*args,**kwargs) for f in r]) for r in self._parts]) @@ -788,14 +793,14 @@ def _singular_(self): EXAMPLES:: - sage: P. = PolynomialRing(GF(127)) - sage: I = sage.rings.ideal.Katsura(P) - sage: F = Sequence(I); F + sage: P. = PolynomialRing(GF(127)) # optional - sage.rings.finite_rings + sage: I = sage.rings.ideal.Katsura(P) # optional - sage.rings.finite_rings + sage: F = Sequence(I); F # optional - sage.rings.finite_rings [a + 2*b + 2*c + 2*d - 1, a^2 + 2*b^2 + 2*c^2 + 2*d^2 - a, 2*a*b + 2*b*c + 2*c*d - b, b^2 + 2*a*c + 2*b*d - c] - sage: F._singular_() + sage: F._singular_() # optional - sage.rings.finite_rings a+2*b+2*c+2*d-1, a^2+2*b^2+2*c^2+2*d^2-a, 2*a*b+2*b*c+2*c*d-b, @@ -810,10 +815,10 @@ def _magma_init_(self, magma): EXAMPLES:: - sage: sr = mq.SR(allow_zero_inversions=True,gf2=True) - sage: F,s = sr.polynomial_system() - sage: F.set_immutable() - sage: magma(F) # indirect doctest; optional - magma + sage: sr = mq.SR(allow_zero_inversions=True, gf2=True) # optional - sage.rings.polynomial.pbori + sage: F,s = sr.polynomial_system() # optional - sage.rings.polynomial.pbori + sage: F.set_immutable() # optional - sage.rings.polynomial.pbori + sage: magma(F) # indirect doctest; optional - magma # optional - sage.rings.polynomial.pbori Ideal of Boolean polynomial ring of rank 20 over GF(2) Order: Graded Lexicographical (bit vector word) Variables: k100, k101, k102, k103, x100, x101, x102, x103, w100, w101, w102, w103, s000, s001, s002, s003, k000, k001, k002, k003 @@ -832,9 +837,9 @@ def _repr_(self): EXAMPLES:: - sage: P. = PolynomialRing(GF(127)) - sage: I = sage.rings.ideal.Katsura(P) - sage: F = Sequence(I); F # indirect doctest + sage: P. = PolynomialRing(GF(127)) # optional - sage.rings.finite_rings + sage: I = sage.rings.ideal.Katsura(P) # optional - sage.rings.finite_rings + sage: F = Sequence(I); F # indirect doctest # optional - sage.rings.finite_rings [a + 2*b + 2*c + 2*d - 1, a^2 + 2*b^2 + 2*c^2 + 2*d^2 - a, 2*a*b + 2*b*c + 2*c*d - b, @@ -843,8 +848,8 @@ def _repr_(self): If the system contains 20 or more polynomials, a short summary is printed:: - sage: sr = mq.SR(allow_zero_inversions=True,gf2=True) - sage: F,s = sr.polynomial_system(); F + sage: sr = mq.SR(allow_zero_inversions=True, gf2=True) # optional - sage.rings.polynomial.pbori + sage: F,s = sr.polynomial_system(); F # optional - sage.rings.polynomial.pbori Polynomial Sequence with 36 Polynomials in 20 Variables """ @@ -860,24 +865,24 @@ def __add__(self, right): EXAMPLES:: - sage: P. = PolynomialRing(GF(127)) - sage: I = sage.rings.ideal.Katsura(P) - sage: F = Sequence(I) - sage: F + [a^127 + a] + sage: P. = PolynomialRing(GF(127)) # optional - sage.rings.finite_rings + sage: I = sage.rings.ideal.Katsura(P) # optional - sage.rings.finite_rings + sage: F = Sequence(I) # optional - sage.rings.finite_rings + sage: F + [a^127 + a] # optional - sage.rings.finite_rings [a + 2*b + 2*c + 2*d - 1, a^2 + 2*b^2 + 2*c^2 + 2*d^2 - a, 2*a*b + 2*b*c + 2*c*d - b, b^2 + 2*a*c + 2*b*d - c, a^127 + a] - sage: F + P.ideal([a^127 + a]) + sage: F + P.ideal([a^127 + a]) # optional - sage.rings.finite_rings [a + 2*b + 2*c + 2*d - 1, a^2 + 2*b^2 + 2*c^2 + 2*d^2 - a, 2*a*b + 2*b*c + 2*c*d - b, b^2 + 2*a*c + 2*b*d - c, a^127 + a] - sage: F + Sequence([a^127 + a], P) + sage: F + Sequence([a^127 + a], P) # optional - sage.rings.finite_rings [a + 2*b + 2*c + 2*d - 1, a^2 + 2*b^2 + 2*c^2 + 2*d^2 - a, 2*a*b + 2*b*c + 2*c*d - b, @@ -904,35 +909,35 @@ def connection_graph(self): EXAMPLES:: - sage: B. = BooleanPolynomialRing() - sage: F = Sequence([x*y + y + 1, z + 1]) - sage: G = F.connection_graph(); G + sage: B. = BooleanPolynomialRing() # optional - sage.rings.polynomial.pbori + sage: F = Sequence([x*y + y + 1, z + 1]) # optional - sage.rings.polynomial.pbori + sage: G = F.connection_graph(); G # optional - sage.rings.polynomial.pbori Graph on 3 vertices - sage: G.is_connected() + sage: G.is_connected() # optional - sage.rings.polynomial.pbori False - sage: F = Sequence([x]) - sage: F.connection_graph() + sage: F = Sequence([x]) # optional - sage.rings.polynomial.pbori + sage: F.connection_graph() # optional - sage.rings.polynomial.pbori Graph on 1 vertex TESTS:: - sage: F = Sequence([], B) - sage: F.connection_graph() + sage: F = Sequence([], B) # optional - sage.rings.polynomial.pbori + sage: F.connection_graph() # optional - sage.rings.polynomial.pbori Graph on 0 vertices - sage: F = Sequence([1], B) - sage: F.connection_graph() + sage: F = Sequence([1], B) # optional - sage.rings.polynomial.pbori + sage: F.connection_graph() # optional - sage.rings.polynomial.pbori Graph on 0 vertices - sage: F = Sequence([x]) - sage: F.connection_graph() + sage: F = Sequence([x]) # optional - sage.rings.polynomial.pbori + sage: F.connection_graph() # optional - sage.rings.polynomial.pbori Graph on 1 vertex - sage: F = Sequence([x, y]) - sage: F.connection_graph() + sage: F = Sequence([x, y]) # optional - sage.rings.polynomial.pbori + sage: F.connection_graph() # optional - sage.rings.polynomial.pbori Graph on 2 vertices - sage: F = Sequence([x*y*z]) - sage: F.connection_graph().is_clique() + sage: F = Sequence([x*y*z]) # optional - sage.rings.polynomial.pbori + sage: F.connection_graph().is_clique() # optional - sage.rings.polynomial.pbori True - sage: F = Sequence([x*y, y*z]) - sage: F.connection_graph().is_clique() + sage: F = Sequence([x*y, y*z]) # optional - sage.rings.polynomial.pbori + sage: F.connection_graph().is_clique() # optional - sage.rings.polynomial.pbori False """ from sage.graphs.graph import Graph @@ -951,15 +956,15 @@ def connected_components(self): As an example consider one part of AES, which naturally splits into four subsystems which are independent:: - sage: sr = mq.SR(2,4,4,8,gf2=True,polybori=True) - sage: while True: # workaround (see :trac:`31891`) + sage: sr = mq.SR(2, 4, 4, 8, gf2=True, polybori=True) # optional - sage.rings.polynomial.pbori + sage: while True: # workaround (see :trac:`31891`) # optional - sage.rings.polynomial.pbori ....: try: ....: F, s = sr.polynomial_system() ....: break ....: except ZeroDivisionError: ....: pass - sage: Fz = Sequence(F.part(2)) - sage: Fz.connected_components() + sage: Fz = Sequence(F.part(2)) # optional - sage.rings.polynomial.pbori + sage: Fz.connected_components() # optional - sage.rings.polynomial.pbori [Polynomial Sequence with 128 Polynomials in 128 Variables, Polynomial Sequence with 128 Polynomials in 128 Variables, Polynomial Sequence with 128 Polynomials in 128 Variables, @@ -1005,9 +1010,9 @@ def _groebner_strategy(self): EXAMPLES:: - sage: P. = PolynomialRing(GF(127)) - sage: F = Sequence([x*y + z, y + z + 1]) - sage: F._groebner_strategy() + sage: P. = PolynomialRing(GF(127)) # optional - sage.rings.finite_rings + sage: F = Sequence([x*y + z, y + z + 1]) # optional - sage.rings.finite_rings + sage: F._groebner_strategy() # optional - sage.rings.finite_rings Groebner Strategy for ideal generated by 2 elements over Multivariate Polynomial Ring in x, y, z over Finite Field of size 127 """ @@ -1020,13 +1025,13 @@ def maximal_degree(self): EXAMPLES:: - sage: P. = PolynomialRing(GF(7)) - sage: F = Sequence([x*y + x, x]) - sage: F.maximal_degree() + sage: P. = PolynomialRing(GF(7)) # optional - sage.rings.finite_rings + sage: F = Sequence([x*y + x, x]) # optional - sage.rings.finite_rings + sage: F.maximal_degree() # optional - sage.rings.finite_rings 2 - sage: P. = PolynomialRing(GF(7)) - sage: F = Sequence([], universe=P) - sage: F.maximal_degree() + sage: P. = PolynomialRing(GF(7)) # optional - sage.rings.finite_rings + sage: F = Sequence([], universe=P) # optional - sage.rings.finite_rings + sage: F.maximal_degree() # optional - sage.rings.finite_rings -1 """ @@ -1039,15 +1044,15 @@ def __reduce__(self): """ TESTS:: - sage: P. = PolynomialRing(GF(127)) - sage: F = Sequence([x*y + z, y + z + 1]) - sage: loads(dumps(F)) == F # indirect doctest + sage: P. = PolynomialRing(GF(127)) # optional - sage.rings.finite_rings + sage: F = Sequence([x*y + z, y + z + 1]) # optional - sage.rings.finite_rings + sage: loads(dumps(F)) == F # indirect doctest # optional - sage.rings.finite_rings True We check that :trac:`26354` is fixed:: - sage: f = P.hom([y,z,x]) - sage: hash(f) == hash(loads(dumps(f))) + sage: f = P.hom([y,z,x]) # optional - sage.rings.finite_rings + sage: hash(f) == hash(loads(dumps(f))) # optional - sage.rings.finite_rings True """ @@ -1063,12 +1068,12 @@ def reduced(self): - `(f_1,...,f_n) = (g_1,...,g_s)` - - `LT(g_i) != LT(g_j)` for all `i != j` + - `LT(g_i) \neq LT(g_j)` for all `i \neq j` - `LT(g_i)` does not divide `m` for all monomials `m` of - `\{g_1,...,g_{i-1},g_{i+1},...,g_s\}` + `\{g_1,...,g_{i-1},g_{i+1},...,g_s\}` - - `LC(g_i) == 1` for all `i` if the coefficient ring is a field. + - `LC(g_i) = 1` for all `i` if the coefficient ring is a field. EXAMPLES:: @@ -1166,12 +1171,12 @@ def is_groebner(self, singular=singular): EXAMPLES:: - sage: R. = PolynomialRing(GF(127),10) - sage: I = sage.rings.ideal.Cyclic(R,4) - sage: I.basis.is_groebner() + sage: R. = PolynomialRing(GF(127), 10) # optional - sage.rings.finite_rings + sage: I = sage.rings.ideal.Cyclic(R, 4) # optional - sage.rings.finite_rings + sage: I.basis.is_groebner() # optional - sage.rings.finite_rings False - sage: I2 = Ideal(I.groebner_basis()) - sage: I2.basis.is_groebner() + sage: I2 = Ideal(I.groebner_basis()) # optional - sage.rings.finite_rings + sage: I2.basis.is_groebner() # optional - sage.rings.finite_rings True """ @@ -1203,64 +1208,64 @@ def eliminate_linear_variables(self, maxlength=Infinity, skip=None, return_reduc with linear leading terms which were used for reduction is also returned (default: ``False``). - - ```use_polybori`` - if ``True`` then ``polybori.ll.eliminate`` is - called. While this is typically faster what is implemented here, it + - ``use_polybori`` - if ``True`` then ``polybori.ll.eliminate`` is + called. While this is typically faster than what is implemented here, it is less flexible (``skip`` is not supported) and may increase the degree (default: ``False``) OUTPUT: - When ``return_reductors==True``, then a pair of sequences of + With ``return_reductors=True``, a pair of sequences of boolean polynomials are returned, along with the promises that: - 1. The union of the two sequences spans the - same boolean ideal as the argument of the method + 1. The union of the two sequences spans the + same boolean ideal as the argument of the method - 2. The second sequence only contains linear polynomials, and - it forms a reduced groebner basis (they all have pairwise - distinct leading variables, and the leading variable of a - polynomial does not occur anywhere in other polynomials). + 2. The second sequence only contains linear polynomials, and + it forms a reduced groebner basis (they all have pairwise + distinct leading variables, and the leading variable of a + polynomial does not occur anywhere in other polynomials). - 3. The leading variables of the second sequence do not occur - anywhere in the first sequence (these variables have been - eliminated). + 3. The leading variables of the second sequence do not occur + anywhere in the first sequence (these variables have been + eliminated). - When ``return_reductors==False``, only the first sequence is + With ``return_reductors=False``, only the first sequence is returned. EXAMPLES:: - sage: B. = BooleanPolynomialRing() - sage: F = Sequence([c + d + b + 1, a + c + d, a*b + c, b*c*d + c]) - sage: F.eliminate_linear_variables() # everything vanishes + sage: B. = BooleanPolynomialRing() # optional - sage.rings.polynomial.pbori + sage: F = Sequence([c + d + b + 1, a + c + d, a*b + c, b*c*d + c]) # optional - sage.rings.polynomial.pbori + sage: F.eliminate_linear_variables() # everything vanishes # optional - sage.rings.polynomial.pbori [] - sage: F.eliminate_linear_variables(maxlength=2) + sage: F.eliminate_linear_variables(maxlength=2) # optional - sage.rings.polynomial.pbori [b + c + d + 1, b*c + b*d + c, b*c*d + c] - sage: F.eliminate_linear_variables(skip=lambda lm,tail: str(lm)=='a') + sage: F.eliminate_linear_variables(skip=lambda lm,tail: str(lm)=='a') # optional - sage.rings.polynomial.pbori [a + c + d, a*c + a*d + a + c, c*d + c] - The list of reductors can be requested by setting 'return_reductors' to ``True``:: + The list of reductors can be requested by setting ``return_reductors`` to ``True``:: - sage: B. = BooleanPolynomialRing() - sage: F = Sequence([a + b + d, a + b + c]) - sage: F,R = F.eliminate_linear_variables(return_reductors=True) - sage: F + sage: B. = BooleanPolynomialRing() # optional - sage.rings.polynomial.pbori + sage: F = Sequence([a + b + d, a + b + c]) # optional - sage.rings.polynomial.pbori + sage: F, R = F.eliminate_linear_variables(return_reductors=True) # optional - sage.rings.polynomial.pbori + sage: F # optional - sage.rings.polynomial.pbori [] - sage: R + sage: R # optional - sage.rings.polynomial.pbori [a + b + d, c + d] - If the input system is detected to be inconsistent then [1] is returned + If the input system is detected to be inconsistent then ``[1]`` is returned, and the list of reductors is empty:: - sage: R. = BooleanPolynomialRing() - sage: S = Sequence([x*y*z+x*y+z*y+x*z, x+y+z+1, x+y+z]) - sage: S.eliminate_linear_variables() + sage: R. = BooleanPolynomialRing() # optional - sage.rings.polynomial.pbori + sage: S = Sequence([x*y*z + x*y + z*y + x*z, x + y + z + 1, x + y + z]) # optional - sage.rings.polynomial.pbori + sage: S.eliminate_linear_variables() # optional - sage.rings.polynomial.pbori [1] - sage: R. = BooleanPolynomialRing() - sage: S = Sequence([x*y*z+x*y+z*y+x*z, x+y+z+1, x+y+z]) - sage: S.eliminate_linear_variables(return_reductors=True) + sage: R. = BooleanPolynomialRing() # optional - sage.rings.polynomial.pbori + sage: S = Sequence([x*y*z + x*y + z*y + x*z, x + y + z + 1, x + y + z]) # optional - sage.rings.polynomial.pbori + sage: S.eliminate_linear_variables(return_reductors=True) # optional - sage.rings.polynomial.pbori ([1], []) @@ -1268,30 +1273,30 @@ def eliminate_linear_variables(self, maxlength=Infinity, skip=None, return_reduc The function should really dispose of linear equations (:trac:`13968`):: - sage: R. = BooleanPolynomialRing() - sage: S = Sequence([x+y+z+1, y+z]) - sage: S.eliminate_linear_variables(return_reductors=True) + sage: R. = BooleanPolynomialRing() # optional - sage.rings.polynomial.pbori + sage: S = Sequence([x + y + z + 1, y + z]) # optional - sage.rings.polynomial.pbori + sage: S.eliminate_linear_variables(return_reductors=True) # optional - sage.rings.polynomial.pbori ([], [x + 1, y + z]) The function should take care of linear variables created by previous substitution of linear variables :: - sage: R. = BooleanPolynomialRing() - sage: S = Sequence([x*y*z+x*y+z*y+x*z, x+y+z+1, x+y]) - sage: S.eliminate_linear_variables(return_reductors=True) + sage: R. = BooleanPolynomialRing() # optional - sage.rings.polynomial.pbori + sage: S = Sequence([x*y*z + x*y + z*y + x*z, x + y + z + 1, x + y]) # optional - sage.rings.polynomial.pbori + sage: S.eliminate_linear_variables(return_reductors=True) # optional - sage.rings.polynomial.pbori ([], [x + y, z + 1]) We test a case which would increase the degree with ``polybori=True``:: - sage: B. = BooleanPolynomialRing() - sage: f = a*d + a + b*d + c*d + 1 - sage: Sequence([f, a + b*c + c+d + 1]).eliminate_linear_variables() + sage: B. = BooleanPolynomialRing() # optional - sage.rings.polynomial.pbori + sage: f = a*d + a + b*d + c*d + 1 # optional - sage.rings.polynomial.pbori + sage: Sequence([f, a + b*c + c+d + 1]).eliminate_linear_variables() # optional - sage.rings.polynomial.pbori [a*d + a + b*d + c*d + 1, a + b*c + c + d + 1] - sage: B. = BooleanPolynomialRing() - sage: f = a*d + a + b*d + c*d + 1 - sage: Sequence([f, a + b*c + c+d + 1]).eliminate_linear_variables(use_polybori=True) + sage: B. = BooleanPolynomialRing() # optional - sage.rings.polynomial.pbori + sage: f = a*d + a + b*d + c*d + 1 # optional - sage.rings.polynomial.pbori + sage: Sequence([f, a + b*c + c+d + 1]).eliminate_linear_variables(use_polybori=True) # optional - sage.rings.polynomial.pbori [b*c*d + b*c + b*d + c + d] .. NOTE:: @@ -1372,15 +1377,15 @@ def _groebner_strategy(self): EXAMPLES:: - sage: P. = PolynomialRing(GF(2)) - sage: F = Sequence([x*y + z, y + z + 1]) - sage: F._groebner_strategy() + sage: P. = PolynomialRing(GF(2)) # optional - sage.rings.finite_rings + sage: F = Sequence([x*y + z, y + z + 1]) # optional - sage.rings.finite_rings + sage: F._groebner_strategy() # optional - sage.rings.finite_rings Groebner Strategy for ideal generated by 2 elements over Multivariate Polynomial Ring in x, y, z over Finite Field of size 2 - sage: P. = BooleanPolynomialRing() - sage: F = Sequence([x*y + z, y + z + 1]) - sage: F._groebner_strategy() + sage: P. = BooleanPolynomialRing() # optional - sage.rings.polynomial.pbori + sage: F = Sequence([x*y + z, y + z + 1]) # optional - sage.rings.polynomial.pbori + sage: F._groebner_strategy() # optional - sage.rings.polynomial.pbori """ from sage.rings.polynomial.multi_polynomial_ring_base import BooleanPolynomialRing_base @@ -1436,63 +1441,63 @@ def solve(self, algorithm='polybori', n=1, eliminate_linear_variables=True, ver Without argument, a single arbitrary solution is returned:: sage: from sage.doctest.fixtures import reproducible_repr - sage: R. = BooleanPolynomialRing() - sage: S = Sequence([x*y+z, y*z+x, x+y+z+1]) - sage: sol = S.solve() - sage: print(reproducible_repr(sol)) + sage: R. = BooleanPolynomialRing() # optional - sage.rings.polynomial.pbori + sage: S = Sequence([x*y + z, y*z + x, x + y + z + 1]) # optional - sage.rings.polynomial.pbori + sage: sol = S.solve() # optional - sage.rings.polynomial.pbori + sage: print(reproducible_repr(sol)) # optional - sage.rings.polynomial.pbori [{x: 0, y: 1, z: 0}] We check that it is actually a solution:: - sage: S.subs( sol[0] ) + sage: S.subs(sol[0]) # optional - sage.rings.polynomial.pbori [0, 0, 0] We obtain all solutions:: - sage: sols = S.solve(n=Infinity) - sage: print(reproducible_repr(sols)) + sage: sols = S.solve(n=Infinity) # optional - sage.rings.polynomial.pbori + sage: print(reproducible_repr(sols)) # optional - sage.rings.polynomial.pbori [{x: 0, y: 1, z: 0}, {x: 1, y: 1, z: 1}] - sage: [S.subs(x) for x in sols] + sage: [S.subs(x) for x in sols] # optional - sage.rings.polynomial.pbori [[0, 0, 0], [0, 0, 0]] We can force the use of exhaustive search if the optional package ``FES`` is present:: - sage: sol = S.solve(algorithm='exhaustive_search') # optional - FES - sage: print(reproducible_repr(sol)) # optional - FES + sage: sol = S.solve(algorithm='exhaustive_search') # optional - FES # optional - sage.rings.polynomial.pbori + sage: print(reproducible_repr(sol)) # optional - FES # optional - sage.rings.polynomial.pbori [{x: 1, y: 1, z: 1}] - sage: S.subs( sol[0] ) + sage: S.subs(sol[0]) # optional - FES # optional - sage.rings.polynomial.pbori [0, 0, 0] And we may use SAT-solvers if they are available:: - sage: sol = S.solve(algorithm='sat') # optional - pycryptosat - sage: print(reproducible_repr(sol)) # optional - pycryptosat + sage: sol = S.solve(algorithm='sat') # optional - pycryptosat # optional - sage.rings.polynomial.pbori + sage: print(reproducible_repr(sol)) # optional - pycryptosat # optional - sage.rings.polynomial.pbori [{x: 0, y: 1, z: 0}] - sage: S.subs( sol[0] ) + sage: S.subs(sol[0]) # optional - sage.rings.polynomial.pbori [0, 0, 0] TESTS: Make sure that variables not occurring in the equations are no problem:: - sage: R. = BooleanPolynomialRing() - sage: S = Sequence([x*y+z, y*z+x, x+y+z+1]) - sage: sols = S.solve(n=Infinity) - sage: [S.subs(x) for x in sols] + sage: R. = BooleanPolynomialRing() # optional - sage.rings.polynomial.pbori + sage: S = Sequence([x*y + z, y*z + x, x + y + z + 1]) # optional - sage.rings.polynomial.pbori + sage: sols = S.solve(n=Infinity) # optional - sage.rings.polynomial.pbori + sage: [S.subs(x) for x in sols] # optional - sage.rings.polynomial.pbori [[0, 0, 0], [0, 0, 0], [0, 0, 0], [0, 0, 0]] Not eliminating linear variables:: - sage: sols = S.solve(n=Infinity, eliminate_linear_variables=False) - sage: [S.subs(x) for x in sols] + sage: sols = S.solve(n=Infinity, eliminate_linear_variables=False) # optional - sage.rings.polynomial.pbori + sage: [S.subs(x) for x in sols] # optional - sage.rings.polynomial.pbori [[0, 0, 0], [0, 0, 0], [0, 0, 0], [0, 0, 0]] A tricky case where the linear equations are insatisfiable:: - sage: R. = BooleanPolynomialRing() - sage: S = Sequence([x*y*z+x*y+z*y+x*z, x+y+z+1, x+y+z]) - sage: S.solve() + sage: R. = BooleanPolynomialRing() # optional - sage.rings.polynomial.pbori + sage: S = Sequence([x*y*z + x*y + z*y + x*z, x + y + z + 1, x + y + z]) # optional - sage.rings.polynomial.pbori + sage: S.solve() # optional - sage.rings.polynomial.pbori [] """ @@ -1560,27 +1565,27 @@ def solve(self, algorithm='polybori', n=1, eliminate_linear_variables=True, ver return solutions def reduced(self): - """ - If this sequence is `(f_1, ..., f_n)` this method returns `(g_1, ..., g_s)` such that: + r""" + If this sequence is `f_1, ..., f_n`, return `g_1, ..., g_s` such that: - - ` = ` - - `LT(g_i) != LT(g_j)` for all `i != j`` + - `(f_1,...,f_n) = (g_1,...,g_s)` + - `LT(g_i) \neq LT(g_j)` for all `i \neq j` - `LT(g_i)` does not divide `m` for all monomials `m` of `{g_1,...,g_{i-1},g_{i+1},...,g_s}` EXAMPLES:: - sage: sr = mq.SR(1, 1, 1, 4, gf2=True, polybori=True) - sage: while True: # workaround (see :trac:`31891`) + sage: sr = mq.SR(1, 1, 1, 4, gf2=True, polybori=True) # optional - sage.rings.polynomial.pbori + sage: while True: # workaround (see :trac:`31891`) # optional - sage.rings.polynomial.pbori ....: try: ....: F, s = sr.polynomial_system() ....: break ....: except ZeroDivisionError: ....: pass - sage: g = F.reduced() - sage: len(g) == len(set(gi.lt() for gi in g)) + sage: g = F.reduced() # optional - sage.rings.polynomial.pbori + sage: len(g) == len(set(gi.lt() for gi in g)) # optional - sage.rings.polynomial.pbori True - sage: for i in range(len(g)): + sage: for i in range(len(g)): # optional - sage.rings.polynomial.pbori ....: for j in range(len(g)): ....: if i == j: ....: continue @@ -1618,27 +1623,27 @@ def weil_restriction(self): EXAMPLES:: - sage: k. = GF(2^2) - sage: P. = PolynomialRing(k,2) - sage: a = P.base_ring().gen() - sage: F = Sequence([x*y + 1, a*x + 1], P) - sage: F2 = F.weil_restriction() - sage: F2 + sage: k. = GF(2^2) # optional - sage.rings.finite_rings + sage: P. = PolynomialRing(k, 2) # optional - sage.rings.finite_rings + sage: a = P.base_ring().gen() # optional - sage.rings.finite_rings + sage: F = Sequence([x*y + 1, a*x + 1], P) # optional - sage.rings.finite_rings + sage: F2 = F.weil_restriction() # optional - sage.rings.finite_rings + sage: F2 # optional - sage.rings.finite_rings [x0*y0 + x1*y1 + 1, x1*y0 + x0*y1 + x1*y1, x1 + 1, x0 + x1, x0^2 + x0, - x1^2 + x1, y0^2 + y0, y1^2 + y1] + x1^2 + x1, y0^2 + y0, y1^2 + y1] Another bigger example for a small scale AES:: - sage: sr = mq.SR(1,1,1,4,gf2=False) - sage: while True: # workaround (see :trac:`31891`) + sage: sr = mq.SR(1, 1, 1, 4, gf2=False) # optional - sage.rings.polynomial.pbori + sage: while True: # workaround (see :trac:`31891`) # optional - sage.rings.polynomial.pbori ....: try: ....: F, s = sr.polynomial_system() ....: break ....: except ZeroDivisionError: ....: pass - sage: F + sage: F # optional - sage.rings.polynomial.pbori Polynomial Sequence with 40 Polynomials in 20 Variables - sage: F2 = F.weil_restriction(); F2 + sage: F2 = F.weil_restriction(); F2 # optional - sage.rings.polynomial.pbori Polynomial Sequence with 240 Polynomials in 80 Variables """ from sage.rings.ideal import FieldIdeal diff --git a/src/sage/rings/polynomial/ore_polynomial_element.pyx b/src/sage/rings/polynomial/ore_polynomial_element.pyx index 4db1a1652ff..d30478b4f48 100644 --- a/src/sage/rings/polynomial/ore_polynomial_element.pyx +++ b/src/sage/rings/polynomial/ore_polynomial_element.pyx @@ -164,48 +164,48 @@ cdef class OrePolynomial(AlgebraElement): Here is another example over a finite field:: - sage: k. = GF(5^3) - sage: Frob = k.frobenius_endomorphism() - sage: S. = k['x',Frob] - sage: a = x^4 + (4*t + 1)*x^3 + (t^2 + 3*t + 3)*x^2 + (3*t^2 + 2*t + 2)*x + (3*t^2 + 3*t + 1) - sage: b = (2*t^2 + 3)*x^2 + (3*t^2 + 1)*x + 4*t + 2 - sage: q,r = a.left_quo_rem(b) - sage: q + sage: k. = GF(5^3) # optional - sage.rings.finite_rings + sage: Frob = k.frobenius_endomorphism() # optional - sage.rings.finite_rings + sage: S. = k['x',Frob] # optional - sage.rings.finite_rings + sage: a = x^4 + (4*t + 1)*x^3 + (t^2 + 3*t + 3)*x^2 + (3*t^2 + 2*t + 2)*x + (3*t^2 + 3*t + 1) # optional - sage.rings.finite_rings + sage: b = (2*t^2 + 3)*x^2 + (3*t^2 + 1)*x + 4*t + 2 # optional - sage.rings.finite_rings + sage: q, r = a.left_quo_rem(b) # optional - sage.rings.finite_rings + sage: q # optional - sage.rings.finite_rings (4*t^2 + t + 1)*x^2 + (2*t^2 + 2*t + 2)*x + 2*t^2 + 4*t + 3 - sage: r + sage: r # optional - sage.rings.finite_rings (t + 2)*x + 3*t^2 + 2*t + 4 - sage: a == b*q + r + sage: a == b*q + r # optional - sage.rings.finite_rings True Once we have euclidean divisions, we have for free gcd and lcm (at least if the base ring is a field):: - sage: a = (x + t) * (x + t^2)^2 - sage: b = (x + t) * (t*x + t + 1) * (x + t^2) - sage: a.right_gcd(b) + sage: a = (x + t) * (x + t^2)^2 # optional - sage.rings.finite_rings + sage: b = (x + t) * (t*x + t + 1) * (x + t^2) # optional - sage.rings.finite_rings + sage: a.right_gcd(b) # optional - sage.rings.finite_rings x + t^2 - sage: a.left_gcd(b) + sage: a.left_gcd(b) # optional - sage.rings.finite_rings x + t The left lcm has the following meaning: given Ore polynomials `a` and `b`, their left lcm is the least degree polynomial `c = ua = vb` for some Ore polynomials `u, v`. Such a `c` always exist if the base ring is a field:: - sage: c = a.left_lcm(b); c + sage: c = a.left_lcm(b); c # optional - sage.rings.finite_rings x^5 + (4*t^2 + t + 3)*x^4 + (3*t^2 + 4*t)*x^3 + 2*t^2*x^2 + (2*t^2 + t)*x + 4*t^2 + 4 - sage: c.is_right_divisible_by(a) + sage: c.is_right_divisible_by(a) # optional - sage.rings.finite_rings True - sage: c.is_right_divisible_by(b) + sage: c.is_right_divisible_by(b) # optional - sage.rings.finite_rings True The right lcm is defined similarly as the least degree polynomial `c = au = bv` for some `u,v`:: - sage: d = a.right_lcm(b); d + sage: d = a.right_lcm(b); d # optional - sage.rings.finite_rings x^5 + (t^2 + 1)*x^4 + (3*t^2 + 3*t + 3)*x^3 + (3*t^2 + t + 2)*x^2 + (4*t^2 + 3*t)*x + 4*t + 4 - sage: d.is_left_divisible_by(a) + sage: d.is_left_divisible_by(a) # optional - sage.rings.finite_rings True - sage: d.is_left_divisible_by(b) + sage: d.is_left_divisible_by(b) # optional - sage.rings.finite_rings True .. SEEALSO:: @@ -291,10 +291,10 @@ cdef class OrePolynomial(AlgebraElement): EXAMPLES:: sage: from sage.rings.polynomial.ore_polynomial_element import OrePolynomialBaseringInjection - sage: k. = GF(5^3) - sage: Frob = k.frobenius_endomorphism() - sage: S. = k['x',Frob] - sage: OrePolynomialBaseringInjection(k, k['x', Frob]) #indirect doctest + sage: k. = GF(5^3) # optional - sage.rings.finite_rings + sage: Frob = k.frobenius_endomorphism() # optional - sage.rings.finite_rings + sage: S. = k['x',Frob] # optional - sage.rings.finite_rings + sage: OrePolynomialBaseringInjection(k, k['x', Frob]) #indirect doctest # optional - sage.rings.finite_rings Ore Polynomial base injection morphism: From: Finite Field in t of size 5^3 To: Ore Polynomial Ring in x over Finite Field in t of size 5^3 twisted by t |--> t^5 @@ -313,10 +313,10 @@ cdef class OrePolynomial(AlgebraElement): EXAMPLES:: sage: k. = GF(5^3) - sage: Frob = k.frobenius_endomorphism() - sage: S. = k['x',Frob] - sage: a = x + t - sage: a[1] = t + 1 + sage: Frob = k.frobenius_endomorphism() # optional - sage.rings.finite_rings + sage: S. = k['x',Frob] # optional - sage.rings.finite_rings + sage: a = x + t # optional - sage.rings.finite_rings + sage: a[1] = t + 1 # optional - sage.rings.finite_rings Traceback (most recent call last): ... IndexError: Ore polynomials are immutable @@ -484,26 +484,26 @@ cdef class OrePolynomial(AlgebraElement): EXAMPLES:: - sage: k. = GF(5^3) - sage: Frob = k.frobenius_endomorphism() - sage: S. = k['x',Frob] - sage: a = (3*t^2 + 3*t + 2)*x^3 + (2*t^2 + 3)*x^2 + (4*t^2 + t + 4)*x + 2*t^2 + 2 - sage: b = a.left_monic(); b + sage: k. = GF(5^3) # optional - sage.rings.finite_rings + sage: Frob = k.frobenius_endomorphism() # optional - sage.rings.finite_rings + sage: S. = k['x',Frob] # optional - sage.rings.finite_rings + sage: a = (3*t^2 + 3*t + 2)*x^3 + (2*t^2 + 3)*x^2 + (4*t^2 + t + 4)*x + 2*t^2 + 2 # optional - sage.rings.finite_rings + sage: b = a.left_monic(); b # optional - sage.rings.finite_rings x^3 + (4*t^2 + 3*t)*x^2 + (4*t + 2)*x + 2*t^2 + 4*t + 3 Check list:: - sage: b.degree() == a.degree() + sage: b.degree() == a.degree() # optional - sage.rings.finite_rings True - sage: b.is_left_divisible_by(a) + sage: b.is_left_divisible_by(a) # optional - sage.rings.finite_rings True - sage: twist = S.twisting_morphism(-a.degree()) - sage: a == b * twist(a.leading_coefficient()) + sage: twist = S.twisting_morphism(-a.degree()) # optional - sage.rings.finite_rings + sage: a == b * twist(a.leading_coefficient()) # optional - sage.rings.finite_rings True Note that `b` does not divide `a` on the right:: - sage: a.is_right_divisible_by(b) + sage: a.is_right_divisible_by(b) # optional - sage.rings.finite_rings False This function does not work if the leading coefficient is not a @@ -537,25 +537,25 @@ cdef class OrePolynomial(AlgebraElement): EXAMPLES:: - sage: k. = GF(5^3) - sage: Frob = k.frobenius_endomorphism() - sage: S. = k['x',Frob] - sage: a = (3*t^2 + 3*t + 2)*x^3 + (2*t^2 + 3)*x^2 + (4*t^2 + t + 4)*x + 2*t^2 + 2 - sage: b = a.right_monic(); b + sage: k. = GF(5^3) # optional - sage.rings.finite_rings + sage: Frob = k.frobenius_endomorphism() # optional - sage.rings.finite_rings + sage: S. = k['x',Frob] # optional - sage.rings.finite_rings + sage: a = (3*t^2 + 3*t + 2)*x^3 + (2*t^2 + 3)*x^2 + (4*t^2 + t + 4)*x + 2*t^2 + 2 # optional - sage.rings.finite_rings + sage: b = a.right_monic(); b # optional - sage.rings.finite_rings x^3 + (2*t^2 + 3*t + 4)*x^2 + (3*t^2 + 4*t + 1)*x + 2*t^2 + 4*t + 3 Check list:: - sage: b.degree() == a.degree() + sage: b.degree() == a.degree() # optional - sage.rings.finite_rings True - sage: b.is_right_divisible_by(a) + sage: b.is_right_divisible_by(a) # optional - sage.rings.finite_rings True - sage: a == a.leading_coefficient() * b + sage: a == a.leading_coefficient() * b # optional - sage.rings.finite_rings True Note that `b` does not divide `a` on the right:: - sage: a.is_left_divisible_by(b) + sage: a.is_left_divisible_by(b) # optional - sage.rings.finite_rings False This function does not work if the leading coefficient is not a @@ -635,14 +635,15 @@ cdef class OrePolynomial(AlgebraElement): EXAMPLES:: - sage: R. = GF(11)[] - sage: der = R.derivation() - sage: S. = R['x', der] - sage: f = t/x - sage: f + sage: R. = GF(11)[] # optional - sage.rings.finite_rings + sage: der = R.derivation() # optional - sage.rings.finite_rings + sage: S. = R['x', der] # optional - sage.rings.finite_rings + sage: f = t/x # optional - sage.rings.finite_rings + sage: f # optional - sage.rings.finite_rings (x + 10/t)^(-1) * t - sage: f.parent() - Ore Function Field in x over Fraction Field of Univariate Polynomial Ring in t over Finite Field of size 11 twisted by d/dt + sage: f.parent() # optional - sage.rings.finite_rings + Ore Function Field in x over + Fraction Field of Univariate Polynomial Ring in t over Finite Field of size 11 twisted by d/dt """ parent = self.parent().fraction_field() return parent(self) / parent(right) @@ -696,20 +697,20 @@ cdef class OrePolynomial(AlgebraElement): EXAMPLES:: - sage: k. = GF(5^3) - sage: Frob = k.frobenius_endomorphism() - sage: S. = k['x',Frob] - sage: a = x^2 + t*x + t^2 + 3 - sage: b = x^3 + (t + 1)*x^2 + 1 - sage: c = a*b - sage: c.is_right_divisible_by(a) + sage: k. = GF(5^3) # optional - sage.rings.finite_rings + sage: Frob = k.frobenius_endomorphism() # optional - sage.rings.finite_rings + sage: S. = k['x',Frob] # optional - sage.rings.finite_rings + sage: a = x^2 + t*x + t^2 + 3 # optional - sage.rings.finite_rings + sage: b = x^3 + (t + 1)*x^2 + 1 # optional - sage.rings.finite_rings + sage: c = a*b # optional - sage.rings.finite_rings + sage: c.is_right_divisible_by(a) # optional - sage.rings.finite_rings False - sage: c.is_right_divisible_by(b) + sage: c.is_right_divisible_by(b) # optional - sage.rings.finite_rings True Divisibility by `0` does not make sense:: - sage: c.is_right_divisible_by(S(0)) + sage: c.is_right_divisible_by(S(0)) # optional - sage.rings.finite_rings Traceback (most recent call last): ... ZeroDivisionError: division by zero is not valid @@ -745,20 +746,20 @@ cdef class OrePolynomial(AlgebraElement): EXAMPLES:: - sage: k. = GF(5^3) - sage: Frob = k.frobenius_endomorphism() - sage: S. = k['x',Frob] - sage: a = x^2 + t*x + t^2 + 3 - sage: b = x^3 + (t + 1)*x^2 + 1 - sage: c = a*b - sage: a.left_divides(c) + sage: k. = GF(5^3) # optional - sage.rings.finite_rings + sage: Frob = k.frobenius_endomorphism() # optional - sage.rings.finite_rings + sage: S. = k['x',Frob] # optional - sage.rings.finite_rings + sage: a = x^2 + t*x + t^2 + 3 # optional - sage.rings.finite_rings + sage: b = x^3 + (t + 1)*x^2 + 1 # optional - sage.rings.finite_rings + sage: c = a*b # optional - sage.rings.finite_rings + sage: a.left_divides(c) # optional - sage.rings.finite_rings True - sage: b.left_divides(c) + sage: b.left_divides(c) # optional - sage.rings.finite_rings False Divisibility by `0` does not make sense:: - sage: S(0).left_divides(c) + sage: S(0).left_divides(c) # optional - sage.rings.finite_rings Traceback (most recent call last): ... ZeroDivisionError: division by zero is not valid @@ -780,20 +781,20 @@ cdef class OrePolynomial(AlgebraElement): EXAMPLES:: - sage: k. = GF(5^3) - sage: Frob = k.frobenius_endomorphism() - sage: S. = k['x',Frob] - sage: a = x^2 + t*x + t^2 + 3 - sage: b = x^3 + (t + 1)*x^2 + 1 - sage: c = a*b - sage: a.right_divides(c) + sage: k. = GF(5^3) # optional - sage.rings.finite_rings + sage: Frob = k.frobenius_endomorphism() # optional - sage.rings.finite_rings + sage: S. = k['x',Frob] # optional - sage.rings.finite_rings + sage: a = x^2 + t*x + t^2 + 3 # optional - sage.rings.finite_rings + sage: b = x^3 + (t + 1)*x^2 + 1 # optional - sage.rings.finite_rings + sage: c = a*b # optional - sage.rings.finite_rings + sage: a.right_divides(c) # optional - sage.rings.finite_rings False - sage: b.right_divides(c) + sage: b.right_divides(c) # optional - sage.rings.finite_rings True Divisibility by `0` does not make sense:: - sage: S(0).right_divides(c) + sage: S(0).right_divides(c) # optional - sage.rings.finite_rings Traceback (most recent call last): ... ZeroDivisionError: division by zero is not valid @@ -858,21 +859,21 @@ cdef class OrePolynomial(AlgebraElement): EXAMPLES:: - sage: k. = GF(5^3) - sage: Frob = k.frobenius_endomorphism() - sage: S. = k['x',Frob] - sage: a = (x + t) * (x^2 + t*x + 1) - sage: b = 2 * (x + t) * (x^3 + (t+1)*x^2 + t^2) - sage: g,u,v = a.left_xgcd(b); g + sage: k. = GF(5^3) # optional - sage.rings.finite_rings + sage: Frob = k.frobenius_endomorphism() # optional - sage.rings.finite_rings + sage: S. = k['x',Frob] # optional - sage.rings.finite_rings + sage: a = (x + t) * (x^2 + t*x + 1) # optional - sage.rings.finite_rings + sage: b = 2 * (x + t) * (x^3 + (t+1)*x^2 + t^2) # optional - sage.rings.finite_rings + sage: g,u,v = a.left_xgcd(b); g # optional - sage.rings.finite_rings x + t - sage: a*u + b*v == g + sage: a*u + b*v == g # optional - sage.rings.finite_rings True Specifying ``monic=False``, we *can* get a nonmonic gcd:: - sage: g,u,v = a.left_xgcd(b, monic=False); g + sage: g,u,v = a.left_xgcd(b, monic=False); g # optional - sage.rings.finite_rings 2*t*x + 4*t + 2 - sage: a*u + b*v == g + sage: a*u + b*v == g # optional - sage.rings.finite_rings True The base ring must be a field:: @@ -961,13 +962,13 @@ cdef class OrePolynomial(AlgebraElement): EXAMPLES:: - sage: k. = GF(5^3) - sage: Frob = k.frobenius_endomorphism() - sage: S. = k['x',Frob] - sage: a = (3*t^2 + 3*t + 2)*x^3 + (2*t^2 + 3)*x^2 + (4*t^2 + t + 4)*x + 2*t^2 + 2 - sage: b = (3*t^2 + 4*t + 2)*x^2 + (2*t^2 + 4*t + 3)*x + 2*t^2 + t + 1 - sage: q,r = a.left_quo_rem(b) - sage: a == b*q + r + sage: k. = GF(5^3) # optional - sage.rings.finite_rings + sage: Frob = k.frobenius_endomorphism() # optional - sage.rings.finite_rings + sage: S. = k['x',Frob] # optional - sage.rings.finite_rings + sage: a = (3*t^2 + 3*t + 2)*x^3 + (2*t^2 + 3)*x^2 + (4*t^2 + t + 4)*x + 2*t^2 + 2 # optional - sage.rings.finite_rings + sage: b = (3*t^2 + 4*t + 2)*x^2 + (2*t^2 + 4*t + 3)*x + 2*t^2 + t + 1 # optional - sage.rings.finite_rings + sage: q,r = a.left_quo_rem(b) # optional - sage.rings.finite_rings + sage: a == b*q + r # optional - sage.rings.finite_rings True In the following example, Sage does not know the inverse @@ -1090,21 +1091,21 @@ cdef class OrePolynomial(AlgebraElement): EXAMPLES:: - sage: k. = GF(5^3) - sage: Frob = k.frobenius_endomorphism() - sage: S. = k['x',Frob] - sage: a = (x^2 + t*x + 1) * (x + t) - sage: b = 2 * (x^3 + (t+1)*x^2 + t^2) * (x + t) - sage: g,u,v = a.right_xgcd(b); g + sage: k. = GF(5^3) # optional - sage.rings.finite_rings + sage: Frob = k.frobenius_endomorphism() # optional - sage.rings.finite_rings + sage: S. = k['x',Frob] # optional - sage.rings.finite_rings + sage: a = (x^2 + t*x + 1) * (x + t) # optional - sage.rings.finite_rings + sage: b = 2 * (x^3 + (t+1)*x^2 + t^2) * (x + t) # optional - sage.rings.finite_rings + sage: g,u,v = a.right_xgcd(b); g # optional - sage.rings.finite_rings x + t - sage: u*a + v*b == g + sage: u*a + v*b == g # optional - sage.rings.finite_rings True Specifying ``monic=False``, we *can* get a nonmonic gcd:: - sage: g,u,v = a.right_xgcd(b,monic=False); g + sage: g,u,v = a.right_xgcd(b, monic=False); g # optional - sage.rings.finite_rings (4*t^2 + 4*t + 1)*x + 4*t^2 + 4*t + 3 - sage: u*a + v*b == g + sage: u*a + v*b == g # optional - sage.rings.finite_rings True The base ring must be a field:: @@ -1173,17 +1174,17 @@ cdef class OrePolynomial(AlgebraElement): EXAMPLES:: - sage: k. = GF(5^3) - sage: Frob = k.frobenius_endomorphism() - sage: S. = k['x',Frob] - sage: a = (x^2 + t*x + 1) * (x + t) - sage: b = 2 * (x^3 + (t+1)*x^2 + t^2) * (x + t) - sage: a.right_gcd(b) + sage: k. = GF(5^3) # optional - sage.rings.finite_rings + sage: Frob = k.frobenius_endomorphism() # optional - sage.rings.finite_rings + sage: S. = k['x',Frob] # optional - sage.rings.finite_rings + sage: a = (x^2 + t*x + 1) * (x + t) # optional - sage.rings.finite_rings + sage: b = 2 * (x^3 + (t+1)*x^2 + t^2) * (x + t) # optional - sage.rings.finite_rings + sage: a.right_gcd(b) # optional - sage.rings.finite_rings x + t Specifying ``monic=False``, we *can* get a nonmonic gcd:: - sage: a.right_gcd(b,monic=False) + sage: a.right_gcd(b,monic=False) # optional - sage.rings.finite_rings (4*t^2 + 4*t + 1)*x + 4*t^2 + 4*t + 3 The base ring need to be a field:: @@ -1240,22 +1241,22 @@ cdef class OrePolynomial(AlgebraElement): EXAMPLES:: - sage: k. = GF(5^3) - sage: Frob = k.frobenius_endomorphism() - sage: S. = k['x',Frob] - sage: a = (x + t) * (x^2 + t*x + 1) - sage: b = 2 * (x + t) * (x^3 + (t+1)*x^2 + t^2) - sage: a.left_gcd(b) + sage: k. = GF(5^3) # optional - sage.rings.finite_rings + sage: Frob = k.frobenius_endomorphism() # optional - sage.rings.finite_rings + sage: S. = k['x',Frob] # optional - sage.rings.finite_rings + sage: a = (x + t) * (x^2 + t*x + 1) # optional - sage.rings.finite_rings + sage: b = 2 * (x + t) * (x^3 + (t+1)*x^2 + t^2) # optional - sage.rings.finite_rings + sage: a.left_gcd(b) # optional - sage.rings.finite_rings x + t Specifying ``monic=False``, we *can* get a nonmonic gcd:: - sage: a.left_gcd(b,monic=False) + sage: a.left_gcd(b,monic=False) # optional - sage.rings.finite_rings 2*t*x + 4*t + 2 The base ring needs to be a field:: - sage: R. = QQ[] + sage: R. = QQ[] # optional - sage.rings.finite_rings sage: sigma = R.hom([t+1]) sage: S. = R['x',sigma] sage: a = (x + t) * (x^2 + t*x + 1) @@ -1301,23 +1302,23 @@ cdef class OrePolynomial(AlgebraElement): TESTS:: - sage: cython( # optional - sage.misc.cython + sage: cython( # optional - sage.misc.cython ....: ''' ....: from sage.rings.polynomial.ore_polynomial_element cimport OrePolynomial ....: def left_lcm_cofactor(OrePolynomial P, OrePolynomial Q): ....: return P._left_lcm_cofactor(Q) ....: ''') - sage: k. = GF(7^5) - sage: Frob = k.frobenius_endomorphism(3) - sage: S. = k['x', Frob] + sage: k. = GF(7^5) # optional - sage.rings.finite_rings + sage: Frob = k.frobenius_endomorphism(3) # optional - sage.rings.finite_rings + sage: S. = k['x', Frob] # optional - sage.rings.finite_rings - sage: D = S.random_element(degree=2) - sage: P = S.random_element(degree=2) * D - sage: Q = S.random_element(degree=2) * D - sage: L = P.left_lcm(Q) - sage: U = left_lcm_cofactor(P, Q) # optional - sage.misc.cython - sage: (U*P).right_monic() == L # optional - sage.misc.cython + sage: D = S.random_element(degree=2) # optional - sage.rings.finite_rings + sage: P = S.random_element(degree=2) * D # optional - sage.rings.finite_rings + sage: Q = S.random_element(degree=2) * D # optional - sage.rings.finite_rings + sage: L = P.left_lcm(Q) # optional - sage.rings.finite_rings + sage: U = left_lcm_cofactor(P, Q) # optional - sage.misc.cython sage.rings.finite_rings + sage: (U*P).right_monic() == L # optional - sage.misc.cython sage.rings.finite_rings True """ cdef OrePolynomial Q, R, T @@ -1344,18 +1345,18 @@ cdef class OrePolynomial(AlgebraElement): EXAMPLES:: - sage: k. = GF(5^3) - sage: Frob = k.frobenius_endomorphism() - sage: S. = k['x',Frob] - sage: P = (x + t^2) * (x + t) - sage: Q = 2 * (x^2 + t + 1) * (x * t) - sage: L, U, V = P.left_xlcm(Q) - sage: L + sage: k. = GF(5^3) # optional - sage.rings.finite_rings + sage: Frob = k.frobenius_endomorphism() # optional - sage.rings.finite_rings + sage: S. = k['x',Frob] # optional - sage.rings.finite_rings + sage: P = (x + t^2) * (x + t) # optional - sage.rings.finite_rings + sage: Q = 2 * (x^2 + t + 1) * (x * t) # optional - sage.rings.finite_rings + sage: L, U, V = P.left_xlcm(Q) # optional - sage.rings.finite_rings + sage: L # optional - sage.rings.finite_rings x^5 + (2*t^2 + t + 4)*x^4 + (3*t^2 + 4)*x^3 + (3*t^2 + 3*t + 2)*x^2 + (t^2 + t + 2)*x - sage: U*P == L + sage: U*P == L # optional - sage.rings.finite_rings True - sage: V*Q == L + sage: V*Q == L # optional - sage.rings.finite_rings True """ if self.base_ring() not in _Fields: @@ -1379,23 +1380,23 @@ cdef class OrePolynomial(AlgebraElement): TESTS:: - sage: cython( # optional - sage.misc.cython + sage: cython( # optional - sage.misc.cython ....: ''' ....: from sage.rings.polynomial.ore_polynomial_element cimport OrePolynomial ....: def right_lcm_cofactor(OrePolynomial P, OrePolynomial Q): ....: return P._right_lcm_cofactor(Q) ....: ''') - sage: k. = GF(7^5) - sage: Frob = k.frobenius_endomorphism(3) - sage: S. = k['x', Frob] + sage: k. = GF(7^5) # optional - sage.rings.finite_rings + sage: Frob = k.frobenius_endomorphism(3) # optional - sage.rings.finite_rings + sage: S. = k['x', Frob] # optional - sage.rings.finite_rings - sage: D = S.random_element(degree=2) - sage: P = D * S.random_element(degree=2) - sage: Q = D * S.random_element(degree=2) - sage: L = P.right_lcm(Q) - sage: U = right_lcm_cofactor(P, Q) # optional - sage.misc.cython - sage: (P*U).left_monic() == L # optional - sage.misc.cython + sage: D = S.random_element(degree=2) # optional - sage.rings.finite_rings + sage: P = D * S.random_element(degree=2) # optional - sage.rings.finite_rings + sage: Q = D * S.random_element(degree=2) # optional - sage.rings.finite_rings + sage: L = P.right_lcm(Q) # optional - sage.rings.finite_rings + sage: U = right_lcm_cofactor(P, Q) # optional - sage.misc.cython sage.rings.finite_rings + sage: (P*U).left_monic() == L # optional - sage.misc.cython sage.rings.finite_rings True """ cdef OrePolynomial Q, R, T @@ -1429,17 +1430,17 @@ cdef class OrePolynomial(AlgebraElement): EXAMPLES:: - sage: k. = GF(5^3) - sage: Frob = k.frobenius_endomorphism() - sage: S. = k['x',Frob] - sage: P = (x + t) * (x + t^2) - sage: Q = 2 * (x + t) * (x^2 + t + 1) - sage: L, U, V = P.right_xlcm(Q) - sage: L + sage: k. = GF(5^3) # optional - sage.rings.finite_rings + sage: Frob = k.frobenius_endomorphism() # optional - sage.rings.finite_rings + sage: S. = k['x',Frob] # optional - sage.rings.finite_rings + sage: P = (x + t) * (x + t^2) # optional - sage.rings.finite_rings + sage: Q = 2 * (x + t) * (x^2 + t + 1) # optional - sage.rings.finite_rings + sage: L, U, V = P.right_xlcm(Q) # optional - sage.rings.finite_rings + sage: L # optional - sage.rings.finite_rings x^4 + (2*t^2 + t + 2)*x^3 + (3*t^2 + 4*t + 1)*x^2 + (3*t^2 + 4*t + 1)*x + t^2 + 4 - sage: P*U == L + sage: P*U == L # optional - sage.rings.finite_rings True - sage: Q*V == L + sage: Q*V == L # optional - sage.rings.finite_rings True """ if self.base_ring() not in _Fields: @@ -1484,23 +1485,23 @@ cdef class OrePolynomial(AlgebraElement): EXAMPLES:: - sage: k. = GF(5^3) - sage: Frob = k.frobenius_endomorphism() - sage: S. = k['x',Frob] - sage: a = (x + t^2) * (x + t) - sage: b = 2 * (x^2 + t + 1) * (x * t) - sage: c = a.left_lcm(b); c + sage: k. = GF(5^3) # optional - sage.rings.finite_rings + sage: Frob = k.frobenius_endomorphism() # optional - sage.rings.finite_rings + sage: S. = k['x',Frob] # optional - sage.rings.finite_rings + sage: a = (x + t^2) * (x + t) # optional - sage.rings.finite_rings + sage: b = 2 * (x^2 + t + 1) * (x * t) # optional - sage.rings.finite_rings + sage: c = a.left_lcm(b); c # optional - sage.rings.finite_rings x^5 + (2*t^2 + t + 4)*x^4 + (3*t^2 + 4)*x^3 + (3*t^2 + 3*t + 2)*x^2 + (t^2 + t + 2)*x - sage: c.is_right_divisible_by(a) + sage: c.is_right_divisible_by(a) # optional - sage.rings.finite_rings True - sage: c.is_right_divisible_by(b) + sage: c.is_right_divisible_by(b) # optional - sage.rings.finite_rings True - sage: a.degree() + b.degree() == c.degree() + a.right_gcd(b).degree() + sage: a.degree() + b.degree() == c.degree() + a.right_gcd(b).degree() # optional - sage.rings.finite_rings True Specifying ``monic=False``, we *can* get a nonmonic gcd:: - sage: a.left_lcm(b,monic=False) + sage: a.left_lcm(b,monic=False) # optional - sage.rings.finite_rings (t^2 + t)*x^5 + (4*t^2 + 4*t + 1)*x^4 + (t + 1)*x^3 + (t^2 + 2)*x^2 + (3*t + 4)*x The base ring needs to be a field:: @@ -1554,23 +1555,23 @@ cdef class OrePolynomial(AlgebraElement): EXAMPLES:: - sage: k. = GF(5^3) - sage: Frob = k.frobenius_endomorphism() - sage: S. = k['x',Frob] - sage: a = (x + t) * (x + t^2) - sage: b = 2 * (x + t) * (x^2 + t + 1) - sage: c = a.right_lcm(b); c + sage: k. = GF(5^3) # optional - sage.rings.finite_rings + sage: Frob = k.frobenius_endomorphism() # optional - sage.rings.finite_rings + sage: S. = k['x',Frob] # optional - sage.rings.finite_rings + sage: a = (x + t) * (x + t^2) # optional - sage.rings.finite_rings + sage: b = 2 * (x + t) * (x^2 + t + 1) # optional - sage.rings.finite_rings + sage: c = a.right_lcm(b); c # optional - sage.rings.finite_rings x^4 + (2*t^2 + t + 2)*x^3 + (3*t^2 + 4*t + 1)*x^2 + (3*t^2 + 4*t + 1)*x + t^2 + 4 - sage: c.is_left_divisible_by(a) + sage: c.is_left_divisible_by(a) # optional - sage.rings.finite_rings True - sage: c.is_left_divisible_by(b) + sage: c.is_left_divisible_by(b) # optional - sage.rings.finite_rings True - sage: a.degree() + b.degree() == c.degree() + a.left_gcd(b).degree() + sage: a.degree() + b.degree() == c.degree() + a.left_gcd(b).degree() # optional - sage.rings.finite_rings True Specifying ``monic=False``, we *can* get a nonmonic gcd:: - sage: a.right_lcm(b,monic=False) + sage: a.right_lcm(b,monic=False) # optional - sage.rings.finite_rings 2*t*x^4 + (3*t + 1)*x^3 + (4*t^2 + 4*t + 3)*x^2 + (3*t^2 + 4*t + 2)*x + 3*t^2 + 2*t + 3 @@ -2052,12 +2053,12 @@ cdef class OrePolynomial(AlgebraElement): EXAMPLES:: - sage: k. = GF(5^3) - sage: Frob = k.frobenius_endomorphism() - sage: S. = k['x',Frob] - sage: a = 1 + t*x^2 - sage: b = x + 1 - sage: a.left_mod(b) + sage: k. = GF(5^3) # optional - sage.rings.finite_rings + sage: Frob = k.frobenius_endomorphism() # optional - sage.rings.finite_rings + sage: S. = k['x',Frob] # optional - sage.rings.finite_rings + sage: a = 1 + t*x^2 # optional - sage.rings.finite_rings + sage: b = x + 1 # optional - sage.rings.finite_rings + sage: a.left_mod(b) # optional - sage.rings.finite_rings 2*t^2 + 4*t """ _, r = self.left_quo_rem(other) @@ -2853,54 +2854,55 @@ cdef class OrePolynomial_generic_dense(OrePolynomial): EXAMPLES:: - sage: R. = GF(7)[] - sage: der = R.derivation() - sage: A. = R['d', der] + sage: R. = GF(7)[] # optional - sage.rings.finite_rings + sage: der = R.derivation() # optional - sage.rings.finite_rings + sage: A. = R['d', der] # optional - sage.rings.finite_rings - sage: L = d^3 + t*d^2 - sage: L.hilbert_shift(t) + sage: L = d^3 + t*d^2 # optional - sage.rings.finite_rings + sage: L.hilbert_shift(t) # optional - sage.rings.finite_rings d^3 + 4*t*d^2 + (5*t^2 + 3)*d + 2*t^3 + 4*t - sage: (d+t)^3 + t*(d+t)^2 + sage: (d+t)^3 + t*(d+t)^2 # optional - sage.rings.finite_rings d^3 + 4*t*d^2 + (5*t^2 + 3)*d + 2*t^3 + 4*t One can specify another variable name:: - sage: L.hilbert_shift(t, var='x') + sage: L.hilbert_shift(t, var='x') # optional - sage.rings.finite_rings x^3 + 4*t*x^2 + (5*t^2 + 3)*x + 2*t^3 + 4*t When the twisting morphism is not trivial, the output lies in a different Ore polynomial ring:: - sage: k. = GF(5^3) - sage: Frob = k.frobenius_endomorphism() - sage: S. = k['x', Frob] + sage: k. = GF(5^3) # optional - sage.rings.finite_rings + sage: Frob = k.frobenius_endomorphism() # optional - sage.rings.finite_rings + sage: S. = k['x', Frob] # optional - sage.rings.finite_rings - sage: P = x^2 + a*x + a^2 - sage: Q = P.hilbert_shift(a); Q + sage: P = x^2 + a*x + a^2 # optional - sage.rings.finite_rings + sage: Q = P.hilbert_shift(a); Q # optional - sage.rings.finite_rings x^2 + (2*a^2 + a + 4)*x + a^2 + 3*a + 4 - sage: Q.parent() - Ore Polynomial Ring in x over Finite Field in a of size 5^3 twisted by a |--> a^5 and a*([a |--> a^5] - id) - sage: Q.parent() is S + sage: Q.parent() # optional - sage.rings.finite_rings + Ore Polynomial Ring in x over + Finite Field in a of size 5^3 twisted by a |--> a^5 and a*([a |--> a^5] - id) + sage: Q.parent() is S # optional - sage.rings.finite_rings False This behavior ensures that the Hilbert shift by a fixed element defines an homomorphism of rings:: - sage: U = S.random_element(degree=5) - sage: V = S.random_element(degree=5) - sage: s = k.random_element() - sage: (U+V).hilbert_shift(s) == U.hilbert_shift(s) + V.hilbert_shift(s) + sage: U = S.random_element(degree=5) # optional - sage.rings.finite_rings + sage: V = S.random_element(degree=5) # optional - sage.rings.finite_rings + sage: s = k.random_element() # optional - sage.rings.finite_rings + sage: (U+V).hilbert_shift(s) == U.hilbert_shift(s) + V.hilbert_shift(s) # optional - sage.rings.finite_rings True - sage: (U*V).hilbert_shift(s) == U.hilbert_shift(s) * V.hilbert_shift(s) + sage: (U*V).hilbert_shift(s) == U.hilbert_shift(s) * V.hilbert_shift(s) # optional - sage.rings.finite_rings True We check that shifting by an element and then by its opposite gives back the initial Ore polynomial:: - sage: P = S.random_element(degree=10) - sage: s = k.random_element() - sage: P.hilbert_shift(s).hilbert_shift(-s) == P + sage: P = S.random_element(degree=10) # optional - sage.rings.finite_rings + sage: s = k.random_element() # optional - sage.rings.finite_rings + sage: P.hilbert_shift(s).hilbert_shift(-s) == P # optional - sage.rings.finite_rings True """ from sage.rings.polynomial.ore_polynomial_ring import OrePolynomialRing @@ -3002,7 +3004,8 @@ cdef class OrePolynomialBaseringInjection(Morphism): sage: S.coerce_map_from(S.base_ring()) #indirect doctest Ore Polynomial base injection morphism: From: Univariate Polynomial Ring in t over Rational Field - To: Ore Polynomial Ring in x over Univariate Polynomial Ring in t over Rational Field twisted by t |--> t + 1 + To: Ore Polynomial Ring in x over Univariate Polynomial Ring in t + over Rational Field twisted by t |--> t + 1 """ def __init__(self, domain, codomain): r""" @@ -3018,10 +3021,10 @@ cdef class OrePolynomialBaseringInjection(Morphism): TESTS:: sage: from sage.rings.polynomial.ore_polynomial_element import OrePolynomialBaseringInjection - sage: k. = GF(5^3) - sage: Frob = k.frobenius_endomorphism() - sage: S. = k['x',Frob] - sage: OrePolynomialBaseringInjection(k, k['x', Frob]) + sage: k. = GF(5^3) # optional - sage.rings.finite_rings + sage: Frob = k.frobenius_endomorphism() # optional - sage.rings.finite_rings + sage: S. = k['x',Frob] # optional - sage.rings.finite_rings + sage: OrePolynomialBaseringInjection(k, k['x', Frob]) # optional - sage.rings.finite_rings Ore Polynomial base injection morphism: From: Finite Field in t of size 5^3 To: Ore Polynomial Ring in x over Finite Field in t of size 5^3 twisted by t |--> t^5 @@ -3045,11 +3048,11 @@ cdef class OrePolynomialBaseringInjection(Morphism): EXAMPLES:: sage: from sage.rings.polynomial.ore_polynomial_element import OrePolynomialBaseringInjection - sage: k. = GF(5^3) - sage: Frob = k.frobenius_endomorphism() - sage: S. = k['x',Frob] - sage: m = OrePolynomialBaseringInjection(k, k['x', Frob]) - sage: m.an_element() + sage: k. = GF(5^3) # optional - sage.rings.finite_rings + sage: Frob = k.frobenius_endomorphism() # optional - sage.rings.finite_rings + sage: S. = k['x',Frob] # optional - sage.rings.finite_rings + sage: m = OrePolynomialBaseringInjection(k, k['x', Frob]) # optional - sage.rings.finite_rings + sage: m.an_element() # optional - sage.rings.finite_rings x """ return self._an_element @@ -3070,13 +3073,13 @@ cdef class OrePolynomialBaseringInjection(Morphism): TESTS:: sage: from sage.rings.polynomial.ore_polynomial_element import OrePolynomialBaseringInjection - sage: k. = GF(5^3) - sage: Frob = k.frobenius_endomorphism() - sage: S. = k['x',Frob] - sage: m = OrePolynomialBaseringInjection(k, k['x', Frob]) - sage: m(4) + sage: k. = GF(5^3) # optional - sage.rings.finite_rings + sage: Frob = k.frobenius_endomorphism() # optional - sage.rings.finite_rings + sage: S. = k['x',Frob] # optional - sage.rings.finite_rings + sage: m = OrePolynomialBaseringInjection(k, k['x', Frob]) # optional - sage.rings.finite_rings + sage: m(4) # optional - sage.rings.finite_rings 4 - sage: parent(m(4)) + sage: parent(m(4)) # optional - sage.rings.finite_rings Ore Polynomial Ring in x over Finite Field in t of size 5^3 twisted by t |--> t^5 """ try: @@ -3092,11 +3095,11 @@ cdef class OrePolynomialBaseringInjection(Morphism): TESTS:: sage: from sage.rings.polynomial.ore_polynomial_element import OrePolynomialBaseringInjection - sage: k. = GF(5^3) - sage: Frob = k.frobenius_endomorphism() - sage: S. = k['x',Frob] - sage: m = OrePolynomialBaseringInjection(k, k['x', Frob]) - sage: m.section() + sage: k. = GF(5^3) # optional - sage.rings.finite_rings + sage: Frob = k.frobenius_endomorphism() # optional - sage.rings.finite_rings + sage: S. = k['x',Frob] # optional - sage.rings.finite_rings + sage: m = OrePolynomialBaseringInjection(k, k['x', Frob]) # optional - sage.rings.finite_rings + sage: m.section() # optional - sage.rings.finite_rings Generic map: From: Ore Polynomial Ring in x over Finite Field in t of size 5^3 twisted by t |--> t^5 To: Finite Field in t of size 5^3 diff --git a/src/sage/rings/polynomial/padics/polynomial_padic.py b/src/sage/rings/polynomial/padics/polynomial_padic.py index 5dca5066033..b9c16923cc3 100644 --- a/src/sage/rings/polynomial/padics/polynomial_padic.py +++ b/src/sage/rings/polynomial/padics/polynomial_padic.py @@ -189,7 +189,8 @@ def factor(self): sage: factor(t^2) Traceback (most recent call last): ... - PrecisionError: p-adic factorization not well-defined since the discriminant is zero up to the requestion p-adic precision + PrecisionError: p-adic factorization not well-defined since + the discriminant is zero up to the requestion p-adic precision An example of factoring a constant polynomial (see :trac:`26669`):: @@ -254,8 +255,8 @@ def factor(self): def root_field(self, names, check_irreducible=True, **kwds): """ - Return the p-adic extension field generated by the roots of the irreducible - polynomial self. + Return the `p`-adic extension field generated by the roots of the irreducible + polynomial ``self``. INPUT: diff --git a/src/sage/rings/polynomial/padics/polynomial_padic_capped_relative_dense.py b/src/sage/rings/polynomial/padics/polynomial_padic_capped_relative_dense.py index cef06997537..204ae5c54f4 100644 --- a/src/sage/rings/polynomial/padics/polynomial_padic_capped_relative_dense.py +++ b/src/sage/rings/polynomial/padics/polynomial_padic_capped_relative_dense.py @@ -731,7 +731,7 @@ def _unsafe_mutate(self, n, value): def __pari__(self, variable=None): """ - Return ``self`` as a Pari object. + Return ``self`` as a PARI object. """ if variable is None: variable = self.parent().variable_name() @@ -749,7 +749,7 @@ def degree(self, secure=False): INPUT: - - secure -- a boolean (default: ``False``) + - ``secure`` -- a boolean (default: ``False``) If ``secure`` is ``True`` and the degree of this polynomial is not determined (because the leading coefficient is @@ -817,15 +817,15 @@ def precision_absolute(self, n=None): INPUT: - ``self`` -- a p-adic polynomial + - ``self`` -- a p-adic polynomial - n -- ``None`` or an integer (default ``None``). + - ``n`` -- ``None`` or an integer (default ``None``). OUTPUT: - If n == None, returns a list of absolute precisions of + If ``n`` is ``None``, returns a list of absolute precisions of coefficients. Otherwise, returns the absolute precision of - the coefficient of x^n. + the coefficient of `x^n`. EXAMPLES:: @@ -846,15 +846,15 @@ def precision_relative(self, n=None): INPUT: - ``self`` -- a p-adic polynomial + - ``self`` -- a p-adic polynomial - n -- ``None`` or an integer (default ``None``). + - ``n`` -- ``None`` or an integer (default ``None``). OUTPUT: - If n == None, returns a list of relative precisions of + If ``n`` is ``None``, returns a list of relative precisions of coefficients. Otherwise, returns the relative precision of - the coefficient of x^n. + the coefficient of `x^n`. EXAMPLES:: @@ -882,14 +882,14 @@ def valuation_of_coefficient(self, n=None): INPUT: - ``self`` -- a p-adic polynomial + - ``self`` -- a p-adic polynomial - n -- ``None`` or an integer (default ``None``). + - ``n`` -- ``None`` or an integer (default ``None``). OUTPUT: - If n == None, returns a list of valuations of coefficients. Otherwise, - returns the valuation of the coefficient of x^n. + If ``n`` is ``None``, returns a list of valuations of coefficients. Otherwise, + returns the valuation of the coefficient of `x^n`. EXAMPLES:: @@ -916,15 +916,15 @@ def valuation(self, val_of_var=None): INPUT: - ``self`` -- a p-adic polynomial + - ``self`` -- a p-adic polynomial - val_of_var -- ``None`` or a rational (default ``None``). + - ``val_of_var`` -- ``None`` or a rational (default ``None``). OUTPUT: - If val_of_var == None, returns the largest power of the + If ``val_of_var`` is ``None``, returns the largest power of the variable dividing self. Otherwise, returns the valuation of - ``self`` where the variable is assigned valuation val_of_var + ``self`` where the variable is assigned valuation ``val_of_var`` EXAMPLES:: @@ -997,7 +997,7 @@ def reverse(self, degree=None): def rescale(self, a): r""" - Return f(a*X) + Return `f(a\cdot x)`. .. TODO:: @@ -1085,7 +1085,7 @@ def _quo_rem_naive(self, right): def _quo_rem_list(self, right, secure): """ - An implementation of quo_rem using lists of coefficients. + An implementation of :meth:`quo_rem` using lists of coefficients. Faster than :meth:`_quo_rem_naive`. @@ -1138,7 +1138,7 @@ def newton_polygon(self): OUTPUT: - - a Newton polygon + - a :class:`NewtonPolygon` EXAMPLES:: diff --git a/src/sage/rings/polynomial/polydict.pyx b/src/sage/rings/polynomial/polydict.pyx index 3db1bb6c531..5bb858aa2df 100644 --- a/src/sage/rings/polynomial/polydict.pyx +++ b/src/sage/rings/polynomial/polydict.pyx @@ -782,7 +782,7 @@ cdef class PolyDict: Check that :trac:`29604` is fixed:: - sage: PolyDict({(1, 0): GF(2)(1)}).latex(['x', 'y']) + sage: PolyDict({(1, 0): GF(2)(1)}).latex(['x', 'y']) # optional - sage.rings.finite_rings 'x' """ if not self: @@ -1004,9 +1004,9 @@ cdef class PolyDict: sage: f + g PolyDict with representation {(1, 1): 3, (1, 2): 3, (1, 5): -3, (2, 1): 4, (2, 3): 0} - sage: K = GF(2) - sage: f = PolyDict({(1, 1): K(1)}) - sage: f + f + sage: K = GF(2) # optional - sage.rings.finite_rings + sage: f = PolyDict({(1, 1): K(1)}) # optional - sage.rings.finite_rings + sage: f + f # optional - sage.rings.finite_rings PolyDict with representation {(1, 1): 0} """ cdef dict D = self.__repn @@ -1074,9 +1074,9 @@ cdef class PolyDict: EXAMPLES:: sage: from sage.rings.polynomial.polydict import PolyDict - sage: x, y = FreeMonoid(2, 'x, y').gens() # a strange object to live in a polydict, but non-commutative! - sage: f = PolyDict({(2, 3): x}) - sage: f.scalar_rmult(y) + sage: x, y = FreeMonoid(2, 'x, y').gens() # a strange object to live in a polydict, but non-commutative! # optional - sage.groups + sage: f = PolyDict({(2, 3): x}) # optional - sage.groups + sage: f.scalar_rmult(y) # optional - sage.groups PolyDict with representation {(2, 3): x*y} sage: f = PolyDict({(2,3):2, (1, 2): 3, (2, 1): 4}) sage: f.scalar_rmult(-2) @@ -1096,9 +1096,9 @@ cdef class PolyDict: EXAMPLES:: sage: from sage.rings.polynomial.polydict import PolyDict - sage: x, y = FreeMonoid(2, 'x, y').gens() # a strange object to live in a polydict, but non-commutative! - sage: f = PolyDict({(2,3):x}) - sage: f.scalar_lmult(y) + sage: x, y = FreeMonoid(2, 'x, y').gens() # a strange object to live in a polydict, but non-commutative! # optional - sage.groups + sage: f = PolyDict({(2,3):x}) # optional - sage.groups + sage: f.scalar_lmult(y) # optional - sage.groups PolyDict with representation {(2, 3): y*x} sage: f = PolyDict({(2,3):2, (1,2):3, (2,1):4}) sage: f.scalar_lmult(-2) @@ -1125,9 +1125,9 @@ cdef class PolyDict: EXAMPLES:: sage: from sage.rings.polynomial.polydict import ETuple, PolyDict - sage: x, y = FreeMonoid(2, 'x, y').gens() # a strange object to live in a polydict, but non-commutative! - sage: f = PolyDict({(2, 3): x}) - sage: f.term_lmult(ETuple((1, 2)), y) + sage: x, y = FreeMonoid(2, 'x, y').gens() # a strange object to live in a polydict, but non-commutative! # optional - sage.groups + sage: f = PolyDict({(2, 3): x}) # optional - sage.groups + sage: f.term_lmult(ETuple((1, 2)), y) # optional - sage.groups PolyDict with representation {(3, 5): y*x} sage: f = PolyDict({(2,3): 2, (1,2): 3, (2,1): 4}) @@ -1154,9 +1154,9 @@ cdef class PolyDict: EXAMPLES:: sage: from sage.rings.polynomial.polydict import ETuple, PolyDict - sage: x, y = FreeMonoid(2, 'x, y').gens() # a strange object to live in a polydict, but non-commutative! - sage: f = PolyDict({(2, 3): x}) - sage: f.term_rmult(ETuple((1, 2)), y) + sage: x, y = FreeMonoid(2, 'x, y').gens() # a strange object to live in a polydict, but non-commutative! # optional - sage.groups + sage: f = PolyDict({(2, 3): x}) # optional - sage.groups + sage: f.term_rmult(ETuple((1, 2)), y) # optional - sage.groups PolyDict with representation {(3, 5): x*y} sage: f = PolyDict({(2, 3): 2, (1, 2): 3, (2, 1): 4}) diff --git a/src/sage/rings/polynomial/polynomial_element.pyx b/src/sage/rings/polynomial/polynomial_element.pyx index 9000c358b26..1d3ac46e9d1 100644 --- a/src/sage/rings/polynomial/polynomial_element.pyx +++ b/src/sage/rings/polynomial/polynomial_element.pyx @@ -139,7 +139,7 @@ from sage.misc.cachefunc import cached_method cpdef is_Polynomial(f): """ - Return True if f is of type univariate polynomial. + Return ``True`` if ``f`` is of type univariate polynomial. This function is deprecated. @@ -152,29 +152,30 @@ cpdef is_Polynomial(f): sage: from sage.rings.polynomial.polynomial_element import is_Polynomial sage: R. = ZZ[] sage: is_Polynomial(x^3 + x + 1) - doctest:...: DeprecationWarning: the function is_Polynomial is deprecated; use isinstance(x, sage.structure.element.Polynomial) instead + doctest:...: DeprecationWarning: the function is_Polynomial is deprecated; + use isinstance(x, sage.structure.element.Polynomial) instead See https://github.com/sagemath/sage/issues/32709 for details. True sage: S. = R[] - sage: f = y^3 + x*y -3*x; f + sage: f = y^3 + x*y - 3*x; f y^3 + x*y - 3*x sage: is_Polynomial(f) True - However this function does not return True for genuine multivariate + However this function does not return ``True`` for genuine multivariate polynomial type objects or symbolic polynomials, since those are not of the same data type as univariate polynomials:: sage: R. = QQ[] - sage: f = y^3 + x*y -3*x; f + sage: f = y^3 + x*y - 3*x; f y^3 + x*y - 3*x sage: is_Polynomial(f) False - sage: var('x,y') + sage: var('x,y') # optional - sage.symbolic (x, y) - sage: f = y^3 + x*y -3*x; f + sage: f = y^3 + x*y - 3*x; f # optional - sage.symbolic y^3 + x*y - 3*x - sage: is_Polynomial(f) + sage: is_Polynomial(f) # optional - sage.symbolic False """ from sage.misc.superseded import deprecation @@ -296,12 +297,12 @@ cdef class Polynomial(CommutativePolynomial): EXAMPLES:: - sage: R = GF(2)['x']['y'] - sage: R([0,1]).is_zero() + sage: R = GF(2)['x']['y'] # optional - sage.rings.finite_rings + sage: R([0,1]).is_zero() # optional - sage.rings.finite_rings False - sage: R([0]).is_zero() + sage: R([0]).is_zero() # optional - sage.rings.finite_rings True - sage: R([-1]).is_zero() + sage: R([-1]).is_zero() # optional - sage.rings.finite_rings False """ return self.degree() < 0 @@ -313,7 +314,7 @@ cdef class Polynomial(CommutativePolynomial): EXAMPLES:: sage: R. = QQ[] - sage: (x-3).is_one() + sage: (x - 3).is_one() False sage: R(1).is_one() True @@ -346,11 +347,11 @@ cdef class Polynomial(CommutativePolynomial): EXAMPLES:: - sage: x = polygen(GF(389)) - sage: plot(x^2 + 1, rgbcolor=(0,0,1)) + sage: x = polygen(GF(389)) # optional - sage.rings.finite_rings + sage: plot(x^2 + 1, rgbcolor=(0,0,1)) # optional - sage.rings.finite_rings sage.plot Graphics object consisting of 1 graphics primitive sage: x = polygen(QQ) - sage: plot(x^2 + 1, rgbcolor=(1,0,0)) + sage: plot(x^2 + 1, rgbcolor=(1,0,0)) # optional - sage.plot Graphics object consisting of 1 graphics primitive """ R = self.base_ring() @@ -412,9 +413,9 @@ cdef class Polynomial(CommutativePolynomial): def subs(self, *x, **kwds): r""" - Identical to self(\*x). + Identical to ``self(*x)``. - See the docstring for ``self.__call__``. + See the docstring for :meth:`__call__`. EXAMPLES:: @@ -486,12 +487,12 @@ cdef class Polynomial(CommutativePolynomial): We evaluate a polynomial over a quaternion algebra:: - sage: A. = QuaternionAlgebra(QQ, -1,-1) - sage: R. = PolynomialRing(A,sparse=True) - sage: f = i*j*w^5 - 13*i*w^2 + (i+j)*w + i - sage: f(i+j+1) + sage: A. = QuaternionAlgebra(QQ, -1, -1) # optional - sage.combinat sage.modules + sage: R. = PolynomialRing(A, sparse=True) # optional - sage.combinat sage.modules + sage: f = i*j*w^5 - 13*i*w^2 + (i+j)*w + i # optional - sage.combinat sage.modules + sage: f(i+j+1) # optional - sage.combinat sage.modules 24 + 26*i - 10*j - 25*k - sage: w = i+j+1; i*j*w^5 - 13*i*w^2 + (i+j)*w + i + sage: w = i+j+1; i*j*w^5 - 13*i*w^2 + (i+j)*w + i # optional - sage.combinat sage.modules 24 + 26*i - 10*j - 25*k The parent ring of the answer always "starts" with the parent of @@ -502,28 +503,28 @@ cdef class Polynomial(CommutativePolynomial): sage: R. = QQ[] sage: f = R(2/3) - sage: a = matrix(ZZ,2) - sage: b = f(a); b + sage: a = matrix(ZZ, 2) # optional - sage.combinat sage.modules + sage: b = f(a); b # optional - sage.combinat sage.modules [2/3 0] [ 0 2/3] - sage: b.parent() + sage: b.parent() # optional - sage.combinat sage.modules Full MatrixSpace of 2 by 2 dense matrices over Rational Field sage: f = R(1) - sage: b = f(a); b + sage: b = f(a); b # optional - sage.combinat sage.modules [1 0] [0 1] - sage: b.parent() + sage: b.parent() # optional - sage.combinat sage.modules Full MatrixSpace of 2 by 2 dense matrices over Rational Field :: - sage: R. = GF(17)[] - sage: f = w^3 + 3*w +2 - sage: f(5) + sage: R. = GF(17)[] # optional - sage.rings.finite_rings + sage: f = w^3 + 3*w +2 # optional - sage.rings.finite_rings + sage: f(5) # optional - sage.rings.finite_rings 6 - sage: f(w=5) + sage: f(w=5) # optional - sage.rings.finite_rings 6 - sage: f(x=10) # x isn't mentioned + sage: f(x=10) # x isn't mentioned # optional - sage.rings.finite_rings w^3 + 3*w + 2 Nested polynomial ring elements can be called like multivariate @@ -572,7 +573,7 @@ cdef class Polynomial(CommutativePolynomial): The following results in an element of the symbolic ring. :: - sage: f(x=sqrt(2)) + sage: f(x=sqrt(2)) # optional - sage.symbolic y^2 + sqrt(2)*y + sqrt(2) :: @@ -598,7 +599,7 @@ cdef class Polynomial(CommutativePolynomial): 3 sage: parent(f(0)) Rational Field - sage: parent(f(Qp(5)(0))) + sage: parent(f(Qp(5)(0))) # optional - sage.rings.padics 5-adic Field with capped relative precision 20 TESTS: @@ -677,8 +678,8 @@ cdef class Polynomial(CommutativePolynomial): sage: one(1, 1.).parent() Real Field with 53 bits of precision - sage: zero = GF(2)['x'](0) - sage: zero(1.).parent() # should raise an error + sage: zero = GF(2)['x'](0) # optional - sage.rings.finite_rings + sage: zero(1.).parent() # should raise an error # optional - sage.rings.finite_rings Traceback (most recent call last): ... TypeError: no common canonical parent for objects with parents: @@ -707,37 +708,37 @@ cdef class Polynomial(CommutativePolynomial): These were drastically slower prior to :trac:`33165`:: - sage: R. = GF(31337)[] - sage: f = R(list(range(100,201))) - sage: g = R(list(range(1,1001))) - sage: S. = R.quotient(f) - sage: g(y) + sage: R. = GF(31337)[] # optional - sage.rings.finite_rings + sage: f = R(list(range(100, 201))) # optional - sage.rings.finite_rings + sage: g = R(list(range(1, 1001))) # optional - sage.rings.finite_rings + sage: S. = R.quotient(f) # optional - sage.rings.finite_rings + sage: g(y) # optional - sage.rings.finite_rings 22537*y^99 + 4686*y^98 + 13285*y^97 + 4216*y^96 + ... + 6389*y^3 + 30062*y^2 + 13755*y + 11875 :: - sage: T. = GF(31337)[] - sage: g(z) + sage: T. = GF(31337)[] # optional - sage.rings.finite_rings + sage: g(z) # optional - sage.rings.finite_rings 1000*z^999 + 999*z^998 + 998*z^997 + 997*z^996 + ... + 5*z^4 + 4*z^3 + 3*z^2 + 2*z + 1 - sage: g(z^2) + sage: g(z^2) # optional - sage.rings.finite_rings 1000*z^1998 + 999*z^1996 + 998*z^1994 + 997*z^1992 + ... + 5*z^8 + 4*z^6 + 3*z^4 + 2*z^2 + 1 - sage: g(T([0,1])) + sage: g(T([0, 1])) # optional - sage.rings.finite_rings 1000*z^999 + 999*z^998 + 998*z^997 + 997*z^996 + ... + 5*z^4 + 4*z^3 + 3*z^2 + 2*z + 1 - sage: g(T.zero()) + sage: g(T.zero()) # optional - sage.rings.finite_rings 1 - sage: g(T(2)) + sage: g(T(2)) # optional - sage.rings.finite_rings 23069 :: - sage: U. = GF(31337)[] - sage: g(u) + sage: U. = GF(31337)[] # optional - sage.rings.finite_rings + sage: g(u) # optional - sage.rings.finite_rings 1000*u^999 + 999*u^998 + 998*u^997 + 997*u^996 + ... + 5*u^4 + 4*u^3 + 3*u^2 + 2*u + 1 - sage: g(u*v^2) + sage: g(u*v^2) # optional - sage.rings.finite_rings 1000*u^999*v^1998 + 999*u^998*v^1996 + 998*u^997*v^1994 + ... + 4*u^3*v^6 + 3*u^2*v^4 + 2*u*v^2 + 1 - sage: g(U.zero()) + sage: g(U.zero()) # optional - sage.rings.finite_rings 1 - sage: g(U(2)) + sage: g(U(2)) # optional - sage.rings.finite_rings -8268 Sparse tests for :trac:`33165`:: @@ -924,7 +925,8 @@ cdef class Polynomial(CommutativePolynomial): sage: (1 + x + x^2/2 + x^3/6 + x^4/24 + x^5/120).compose_trunc(1 + x, 2) Traceback (most recent call last): ... - NotImplementedError: truncated composition is not implemented for this subclass of polynomials + NotImplementedError: truncated composition is not implemented + for this subclass of polynomials """ raise NotImplementedError("truncated composition is not implemented " "for this subclass of polynomials") @@ -1084,7 +1086,7 @@ cdef class Polynomial(CommutativePolynomial): """ EXAMPLES:: - sage: P = PolynomialRing(ZZ,'x')(0) + sage: P = PolynomialRing(ZZ, 'x')(0) sage: bool(P) False sage: P = PolynomialRing(ZZ, 'x')([1,2,3]) @@ -1188,21 +1190,21 @@ cdef class Polynomial(CommutativePolynomial): EXAMPLES:: - sage: K. = Qq(4) - sage: R. = K[] - sage: f = x - sage: hash(f) + sage: K. = Qq(4) # optional - sage.rings.padics + sage: R. = K[] # optional - sage.rings.padics + sage: f = x # optional - sage.rings.padics + sage: hash(f) # optional - sage.rings.padics Traceback (most recent call last): ... TypeError: unhashable type: 'sage.rings.padics.qadic_flint_CR.qAdicCappedRelativeElement' - sage: f._cache_key() + sage: f._cache_key() # optional - sage.rings.padics (Univariate Polynomial Ring in x over 2-adic Unramified Extension Field in u defined by x^2 + x + 1, 0, 1 + O(2^20)) sage: @cached_function ....: def foo(t): return t ....: - sage: foo(x) + sage: foo(x) # optional - sage.rings.padics (1 + O(2^20))*x """ return (self._parent,) + tuple(self) @@ -1239,9 +1241,9 @@ cdef class Polynomial(CommutativePolynomial): Verify that :trac:`16251` has been resolved, i.e., polynomials with unhashable coefficients are unhashable:: - sage: K. = Qq(9) - sage: R. = K[] - sage: hash(t) + sage: K. = Qq(9) # optional - sage.rings.padics + sage: R. = K[] # optional - sage.rings.padics + sage: hash(t) # optional - sage.rings.padics Traceback (most recent call last): ... TypeError: unhashable type: 'sage.rings.padics.qadic_flint_CR.qAdicCappedRelativeElement' @@ -1295,11 +1297,11 @@ cdef class Polynomial(CommutativePolynomial): sage: f(x^2 + 3) # indirect doctest 28 - sage: K. = NumberField(x^2 + 1) - sage: cc = K.hom([-i]) - sage: S. = K[] - sage: phi = S.hom([y^2], base_map=cc) - sage: phi(i*y) + sage: K. = NumberField(x^2 + 1) # optional - sage.rings.number_field + sage: cc = K.hom([-i]) # optional - sage.rings.number_field + sage: S. = K[] # optional - sage.rings.number_field + sage: phi = S.hom([y^2], base_map=cc) # optional - sage.rings.number_field + sage: phi(i*y) # optional - sage.rings.number_field -i*y^2 """ a = im_gens[0] @@ -1328,9 +1330,9 @@ cdef class Polynomial(CommutativePolynomial): sage: a = QQ['x'](1/5) sage: QQ(a) 1/5 - sage: AA(a) + sage: AA(a) # optional - sage.rings.number_field 1/5 - sage: QQbar(a) + sage: QQbar(a) # optional - sage.rings.number_field 1/5 sage: RDF(a) 0.2 @@ -1353,30 +1355,30 @@ cdef class Polynomial(CommutativePolynomial): sage: complex(a) (0.2+0j) - sage: b = AA['x'](AA(2/3).sqrt()) - sage: AA(b) + sage: b = AA['x'](AA(2/3).sqrt()) # optional - sage.rings.number_field + sage: AA(b) # optional - sage.rings.number_field 0.8164965809277260? - sage: RR(b) + sage: RR(b) # optional - sage.rings.number_field 0.816496580927726 - sage: RBF(b) + sage: RBF(b) # optional - sage.rings.number_field [0.816496580927726 +/- 2.44e-16] - sage: RIF(b) + sage: RIF(b) # optional - sage.rings.number_field 0.8164965809277260? - sage: float(b) + sage: float(b) # optional - sage.rings.number_field 0.816496580927726 - sage: c = QQbar['x'](QQbar(-2/5).sqrt()) - sage: QQbar(c) + sage: c = QQbar['x'](QQbar(-2/5).sqrt()) # optional - sage.rings.number_field + sage: QQbar(c) # optional - sage.rings.number_field 0.6324555320336758?*I - sage: CDF(c) + sage: CDF(c) # optional - sage.rings.number_field 0.6324555320336758*I - sage: CC(c) + sage: CC(c) # optional - sage.rings.number_field 0.632455532033676*I - sage: CBF(c) # abs tol 1e-16 + sage: CBF(c) # abs tol 1e-16 # optional - sage.rings.number_field [0.6324555320336759 +/- 3.38e-17]*I - sage: CIF(c) + sage: CIF(c) # optional - sage.rings.number_field 0.6324555320336758?*I - sage: complex(c) + sage: complex(c) # optional - sage.rings.number_field 0.6324555320336758j sage: K. = Frac(RR['x']) @@ -1388,8 +1390,8 @@ cdef class Polynomial(CommutativePolynomial): TypeError: cannot convert nonconstant polynomial sage: x = polygen(QQ) - sage: A. = NumberField(x^3 - 2) - sage: A(A['x'](u)) + sage: A. = NumberField(x^3 - 2) # optional - sage.rings.number_field + sage: A(A['x'](u)) # optional - sage.rings.number_field u """ if self.degree() > 0: @@ -1431,8 +1433,8 @@ cdef class Polynomial(CommutativePolynomial): r""" EXAMPLES:: - sage: p = PolynomialRing(QQbar, 'x')(1+I) - sage: complex(p) + sage: p = PolynomialRing(QQbar, 'x')(1+I) # optional - sage.rings.number_field + sage: complex(p) # optional - sage.rings.number_field (1+1j) """ return self._scalar_conversion(complex) @@ -1457,20 +1459,20 @@ cdef class Polynomial(CommutativePolynomial): sage: R. = QQ[] sage: f = x^3 + x - sage: g = f._symbolic_(SR); g + sage: g = f._symbolic_(SR); g # optional - sage.symbolic x^3 + x - sage: g(x=2) + sage: g(x=2) # optional - sage.symbolic 10 - sage: g = SR(f) - sage: g(x=2) + sage: g = SR(f) # optional - sage.symbolic + sage: g(x=2) # optional - sage.symbolic 10 The polynomial has to be over a field of characteristic 0 (see :trac:`24072`):: - sage: R. = GF(7)[] - sage: f = SR(2*w^3 + 1); f + sage: R. = GF(7)[] # optional - sage.rings.finite_rings + sage: f = SR(2*w^3 + 1); f # optional - sage.rings.finite_rings sage.symbolic Traceback (most recent call last): ... TypeError: positive characteristic not allowed in symbolic computations @@ -1500,7 +1502,8 @@ cdef class Polynomial(CommutativePolynomial): sage: f.inverse_of_unit() Traceback (most recent call last): ... - ArithmeticError: x - 90283 is not a unit in Univariate Polynomial Ring in x over Rational Field + ArithmeticError: x - 90283 is not a unit + in Univariate Polynomial Ring in x over Rational Field sage: f = R(-90283); g = f.inverse_of_unit(); g -1/90283 sage: parent(g) @@ -1526,10 +1529,11 @@ cdef class Polynomial(CommutativePolynomial): def inverse_mod(a, m): """ - Inverts the polynomial a with respect to m, or raises a ValueError - if no such inverse exists. The parameter m may be either a single - polynomial or an ideal (for consistency with inverse_mod in other - rings). + Invert the polynomial ``a`` with respect to ``m``, or raise a :class:`ValueError` + if no such inverse exists. + + The parameter ``m`` may be either a single polynomial or an ideal + (for consistency with :meth:`inverse_mod` in other rings). .. SEEALSO:: @@ -1544,9 +1548,9 @@ cdef class Polynomial(CommutativePolynomial): -1/2*t^2 - 1/2*t + 1/2 sage: f * (t^2 + 1) % (t^3 + 1) 1 - sage: f = t.inverse_mod((t+1)^7); f + sage: f = t.inverse_mod((t + 1)^7); f -t^6 - 7*t^5 - 21*t^4 - 35*t^3 - 35*t^2 - 21*t - 7 - sage: (f * t) + (t+1)^7 + sage: (f * t) + (t + 1)^7 1 sage: t.inverse_mod(S.ideal((t + 1)^7)) == f True @@ -1557,28 +1561,30 @@ cdef class Polynomial(CommutativePolynomial): sage: R. = RDF[] sage: epsilon = RDF(1).ulp()*50 # Allow an error of up to 50 ulp - sage: f = inverse_mod(x^2 + 1, x^5 + x + 1); f # abs tol 1e-14 + sage: f = inverse_mod(x^2 + 1, x^5 + x + 1); f # abs tol 1e-14 # optional - sage.modules 0.4*x^4 - 0.2*x^3 - 0.4*x^2 + 0.2*x + 0.8 - sage: poly = f * (x^2 + 1) % (x^5 + x + 1) + sage: poly = f * (x^2 + 1) % (x^5 + x + 1) # optional - sage.modules sage: # Remove noisy zero terms: - sage: parent(poly)([ 0.0 if abs(c)<=epsilon else c for c in poly.coefficients(sparse=False) ]) + sage: parent(poly)([0.0 if abs(c) <= epsilon else c # optional - sage.modules + ....: for c in poly.coefficients(sparse=False)]) 1.0 - sage: f = inverse_mod(x^3 - x + 1, x - 2); f + sage: f = inverse_mod(x^3 - x + 1, x - 2); f # optional - sage.modules 0.14285714285714285 - sage: f * (x^3 - x + 1) % (x - 2) + sage: f * (x^3 - x + 1) % (x - 2) # optional - sage.modules 1.0 - sage: g = 5*x^3+x-7; m = x^4-12*x+13; f = inverse_mod(g, m); f + sage: g = 5*x^3 + x - 7; m = x^4 - 12*x + 13; f = inverse_mod(g, m); f # optional - sage.modules -0.0319636125...*x^3 - 0.0383269759...*x^2 - 0.0463050900...*x + 0.346479687... - sage: poly = f*g % m + sage: poly = f*g % m # optional - sage.modules sage: # Remove noisy zero terms: - sage: parent(poly)([ 0.0 if abs(c)<=epsilon else c for c in poly.coefficients(sparse=False) ]) # abs tol 1e-14 + sage: parent(poly)([0.0 if abs(c) <= epsilon else c # abs tol 1e-14 # optional - sage.modules + ....: for c in poly.coefficients(sparse=False)]) 1.0000000000000004 - ALGORITHM: Solve the system as + mt = 1, returning s as the inverse - of a mod m. + ALGORITHM: Solve the system `as + mt = 1`, returning `s` as the inverse + of `a` mod `m`. Uses the Euclidean algorithm for exact rings, and solves a linear - system for the coefficients of s and t for inexact rings (as the + system for the coefficients of `s` and `t` for inexact rings (as the Euclidean algorithm may not converge in that case). AUTHORS: @@ -1648,10 +1654,10 @@ cdef class Polynomial(CommutativePolynomial): EXAMPLES:: sage: x = polygen(ZZ) - sage: s = (1+x).inverse_series_trunc(5) + sage: s = (1 + x).inverse_series_trunc(5) sage: s x^4 - x^3 + x^2 - x + 1 - sage: s * (1+x) + sage: s * (1 + x) x^5 + 1 Note that the constant coefficient needs to be a unit:: @@ -1678,20 +1684,20 @@ cdef class Polynomial(CommutativePolynomial): Even noncommutative ones:: - sage: M = MatrixSpace(ZZ,2) - sage: x = polygen(M) - sage: p = M([1,2,3,4])*x^3 + M([-1,0,0,1])*x^2 + M([1,3,-1,0])*x + M.one() - sage: q = p.inverse_series_trunc(5) - sage: (p*q).truncate(5) == M.one() + sage: M = MatrixSpace(ZZ, 2) # optional - sage.modules + sage: x = polygen(M) # optional - sage.modules + sage: p = M([1,2,3,4])*x^3 + M([-1,0,0,1])*x^2 + M([1,3,-1,0])*x + M.one() # optional - sage.modules + sage: q = p.inverse_series_trunc(5) # optional - sage.modules + sage: (p*q).truncate(5) == M.one() # optional - sage.modules True - sage: q = p.inverse_series_trunc(13) - sage: (p*q).truncate(13) == M.one() + sage: q = p.inverse_series_trunc(13) # optional - sage.modules + sage: (p*q).truncate(13) == M.one() # optional - sage.modules True TESTS:: sage: x = polygen(ZZ['a','b']) - sage: (x+1).inverse_series_trunc(0) + sage: (x + 1).inverse_series_trunc(0) Traceback (most recent call last): ... ValueError: the precision must be positive, got 0 @@ -1739,8 +1745,8 @@ cdef class Polynomial(CommutativePolynomial): sage: Pol. = CBF[] sage: (x + x^3/6 + x^5/120).revert_series(6) ([0.075000000000000 +/- ...e-17])*x^5 + ([-0.166666666666667 +/- ...e-16])*x^3 + x - sage: Pol. = SR[] - sage: x.revert_series(6) + sage: Pol. = SR[] # optional - sage.symbolic + sage: x.revert_series(6) # optional - sage.symbolic Traceback (most recent call last): ... NotImplementedError: only implemented for certain base rings @@ -1752,7 +1758,7 @@ cdef class Polynomial(CommutativePolynomial): EXAMPLES:: sage: R. = ZZ[] - sage: (x - 4)*(x^2 - 8*x + 16) + sage: (x - 4) * (x^2 - 8*x + 16) x^3 - 12*x^2 + 48*x - 64 sage: C. = PowerSeriesRing(ZZ) sage: D. = PolynomialRing(C) @@ -1769,20 +1775,20 @@ cdef class Polynomial(CommutativePolynomial): TESTS:: - sage: Pol. = MatrixSpace(ZZ, 2)[] - sage: a = matrix([[1,0],[0,0]]) - sage: b = matrix([[1,2],[3,4]]) - sage: list((a*x)*(b*x + 1)) + sage: Pol. = MatrixSpace(ZZ, 2)[] # optional - sage.modules + sage: a = matrix([[1,0], [0,0]]) # optional - sage.modules + sage: b = matrix([[1,2], [3,4]]) # optional - sage.modules + sage: list((a*x)*(b*x + 1)) # optional - sage.modules [ [0 0] [1 0] [1 2] [0 0], [0 0], [0 0] ] - sage: list((b*x + 1)*(a*x)) + sage: list((b*x + 1)*(a*x)) # optional - sage.modules [ [0 0] [1 0] [1 0] [0 0], [0 0], [3 0] ] - sage: list((a*x + 1)*(b*x)) + sage: list((a*x + 1)*(b*x)) # optional - sage.modules [ [0 0] [1 2] [1 2] [0 0], [3 4], [0 0] @@ -1908,17 +1914,17 @@ cdef class Polynomial(CommutativePolynomial): EXAMPLES:: sage: x = polygen(QQ) - sage: p = 37 * (x-1)^3 * (x-2)^3 * (x-1/3)^7 * (x-3/7) + sage: p = 37 * (x - 1)^3 * (x - 2)^3 * (x - 1/3)^7 * (x - 3/7) sage: p.squarefree_decomposition() (37*x - 111/7) * (x^2 - 3*x + 2)^3 * (x - 1/3)^7 - sage: p = 37 * (x-2/3)^2 + sage: p = 37 * (x - 2/3)^2 sage: p.squarefree_decomposition() (37) * (x - 2/3)^2 - sage: x = polygen(GF(3)) - sage: x.squarefree_decomposition() + sage: x = polygen(GF(3)) # optional - sage.rings.finite_rings + sage: x.squarefree_decomposition() # optional - sage.rings.finite_rings x - sage: f = QQbar['x'](1) - sage: f.squarefree_decomposition() + sage: f = QQbar['x'](1) # optional - sage.rings.number_field + sage: f.squarefree_decomposition() # optional - sage.rings.number_field 1 """ @@ -1956,7 +1962,7 @@ cdef class Polynomial(CommutativePolynomial): sage: (x^4 + 2*x^3 - x^2 - 2*x + 1).is_square(root=True) (True, x^2 + x - 1) - sage: f = 12*(x+1)^2 * (x+3)^2 + sage: f = 12 * (x + 1)^2 * (x + 3)^2 sage: f.is_square() False sage: f.is_square(root=True) @@ -1968,7 +1974,7 @@ cdef class Polynomial(CommutativePolynomial): (True, 2*x^2 + 8*x + 6) sage: S. = PolynomialRing(RR) - sage: g = 12*(y+1)^2 * (y+3)^2 + sage: g = 12 * (y + 1)^2 * (y + 3)^2 sage: g.is_square() True @@ -2021,80 +2027,94 @@ cdef class Polynomial(CommutativePolynomial): contained within the given ring. - ``assume_squarefree`` (bool) -- Used for polynomials over - finite fields. If True, this polynomial is assumed to be + finite fields. If ``True``, this polynomial is assumed to be squarefree. EXAMPLES:: - sage: R. = GF(11)[] - sage: f = 7*x^7 + 8*x^6 + 4*x^5 + x^4 + 6*x^3 + 10*x^2 + 8*x + 5 - sage: f.any_root() + sage: R. = GF(11)[] # optional - sage.rings.finite_rings + sage: f = 7*x^7 + 8*x^6 + 4*x^5 + x^4 + 6*x^3 + 10*x^2 + 8*x + 5 # optional - sage.rings.finite_rings + sage: f.any_root() # optional - sage.rings.finite_rings 2 - sage: f.factor() + sage: f.factor() # optional - sage.rings.finite_rings (7) * (x + 9) * (x^6 + 10*x^4 + 6*x^3 + 5*x^2 + 2*x + 2) - sage: f = x^6 + 10*x^4 + 6*x^3 + 5*x^2 + 2*x + 2 - sage: f.any_root(GF(11^6, 'a')) + sage: f = x^6 + 10*x^4 + 6*x^3 + 5*x^2 + 2*x + 2 # optional - sage.rings.finite_rings + sage: f.any_root(GF(11^6, 'a')) # optional - sage.rings.finite_rings a^5 + a^4 + 7*a^3 + 2*a^2 + 10*a - sage: sorted(f.roots(GF(11^6, 'a'))) - [(10*a^5 + 2*a^4 + 8*a^3 + 9*a^2 + a, 1), (a^5 + a^4 + 7*a^3 + 2*a^2 + 10*a, 1), (9*a^5 + 5*a^4 + 10*a^3 + 8*a^2 + 3*a + 1, 1), (2*a^5 + 8*a^4 + 3*a^3 + 6*a + 2, 1), (a^5 + 3*a^4 + 8*a^3 + 2*a^2 + 3*a + 4, 1), (10*a^5 + 3*a^4 + 8*a^3 + a^2 + 10*a + 4, 1)] - sage: f.any_root(GF(11^6, 'a')) + sage: sorted(f.roots(GF(11^6, 'a'))) # optional - sage.rings.finite_rings + [(10*a^5 + 2*a^4 + 8*a^3 + 9*a^2 + a, 1), + (a^5 + a^4 + 7*a^3 + 2*a^2 + 10*a, 1), + (9*a^5 + 5*a^4 + 10*a^3 + 8*a^2 + 3*a + 1, 1), + (2*a^5 + 8*a^4 + 3*a^3 + 6*a + 2, 1), + (a^5 + 3*a^4 + 8*a^3 + 2*a^2 + 3*a + 4, 1), + (10*a^5 + 3*a^4 + 8*a^3 + a^2 + 10*a + 4, 1)] + sage: f.any_root(GF(11^6, 'a')) # optional - sage.rings.finite_rings a^5 + a^4 + 7*a^3 + 2*a^2 + 10*a - sage: g = (x-1)*(x^2 + 3*x + 9) * (x^5 + 5*x^4 + 8*x^3 + 5*x^2 + 3*x + 5) - sage: g.any_root(ring=GF(11^10, 'b'), degree=1) + sage: g = (x-1)*(x^2 + 3*x + 9) * (x^5 + 5*x^4 + 8*x^3 + 5*x^2 + 3*x + 5) # optional - sage.rings.finite_rings + sage: g.any_root(ring=GF(11^10, 'b'), degree=1) # optional - sage.rings.finite_rings 1 - sage: g.any_root(ring=GF(11^10, 'b'), degree=2) + sage: g.any_root(ring=GF(11^10, 'b'), degree=2) # optional - sage.rings.finite_rings 5*b^9 + 4*b^7 + 4*b^6 + 8*b^5 + 10*b^2 + 10*b + 5 - sage: g.any_root(ring=GF(11^10, 'b'), degree=5) + sage: g.any_root(ring=GF(11^10, 'b'), degree=5) # optional - sage.rings.finite_rings 5*b^9 + b^8 + 3*b^7 + 2*b^6 + b^5 + 4*b^4 + 3*b^3 + 7*b^2 + 10*b TESTS:: - sage: R. = GF(5)[] - sage: K. = GF(5^12) - sage: for _ in range(40): + sage: R. = GF(5)[] # optional - sage.rings.finite_rings + sage: K. = GF(5^12) # optional - sage.rings.finite_rings + sage: for _ in range(40): # optional - sage.rings.finite_rings ....: f = R.random_element(degree=4) ....: assert f(f.any_root(K)) == 0 Check that our Cantor-Zassenhaus implementation does not loop over finite fields of even characteristic (see :trac:`16162`):: - sage: K. = GF(2**8) - sage: x = polygen(K) - sage: r = (x**2+x+1).any_root() # used to loop - sage: r**2 + r + sage: K. = GF(2**8) # optional - sage.rings.finite_rings + sage: x = polygen(K) # optional - sage.rings.finite_rings + sage: r = (x**2+x+1).any_root() # used to loop # optional - sage.rings.finite_rings + sage: r**2 + r # optional - sage.rings.finite_rings 1 - sage: (x**2+a+1).any_root() + sage: (x**2+a+1).any_root() # optional - sage.rings.finite_rings a^7 + a^2 Also check that such computations can be interrupted:: - sage: K. = GF(2^8) - sage: x = polygen(K) - sage: pol = x^1000000 + x + a - sage: alarm(0.5); pol.any_root() + sage: K. = GF(2^8) # optional - sage.rings.finite_rings + sage: x = polygen(K) # optional - sage.rings.finite_rings + sage: pol = x^1000000 + x + a # optional - sage.rings.finite_rings + sage: alarm(0.5); pol.any_root() # optional - sage.rings.finite_rings Traceback (most recent call last): ... AlarmInterrupt Check root computation over large finite fields:: - sage: K. = GF(2**50) - sage: x = polygen(K) - sage: (x**10+x+a).any_root() - a^49 + a^47 + a^44 + a^42 + a^41 + a^39 + a^38 + a^37 + a^36 + a^34 + a^33 + a^29 + a^27 + a^26 + a^25 + a^23 + a^18 + a^13 + a^7 + a^5 + a^4 + a^3 + a^2 + a - sage: K. = GF(2**150) - sage: x = polygen(K) - sage: (x**10+x+a).any_root() - a^149 + a^148 + a^146 + a^144 + a^143 + a^140 + a^138 + a^136 + a^134 + a^132 + a^131 + a^130 + a^129 + a^127 + a^123 + a^120 + a^118 + a^114 + a^113 + a^112 + a^111 + a^108 + a^104 + a^103 + a^102 + a^99 + a^98 + a^94 + a^91 + a^90 + a^88 + a^79 + a^78 + a^75 + a^73 + a^72 + a^67 + a^65 + a^64 + a^63 + a^62 + a^61 + a^59 + a^57 + a^52 + a^50 + a^48 + a^47 + a^46 + a^45 + a^43 + a^41 + a^39 + a^37 + a^34 + a^31 + a^29 + a^27 + a^25 + a^23 + a^22 + a^20 + a^18 + a^16 + a^14 + a^11 + a^10 + a^8 + a^6 + a^5 + a^4 + a + 1 + sage: K. = GF(2**50) # optional - sage.rings.finite_rings + sage: x = polygen(K) # optional - sage.rings.finite_rings + sage: (x**10+x+a).any_root() # optional - sage.rings.finite_rings + a^49 + a^47 + a^44 + a^42 + a^41 + a^39 + a^38 + a^37 + a^36 + + a^34 + a^33 + a^29 + a^27 + a^26 + a^25 + a^23 + a^18 + + a^13 + a^7 + a^5 + a^4 + a^3 + a^2 + a + sage: K. = GF(2**150) # optional - sage.rings.finite_rings + sage: x = polygen(K) # optional - sage.rings.finite_rings + sage: (x**10+x+a).any_root() # optional - sage.rings.finite_rings + a^149 + a^148 + a^146 + a^144 + a^143 + a^140 + a^138 + a^136 + a^134 + + a^132 + a^131 + a^130 + a^129 + a^127 + a^123 + a^120 + a^118 + a^114 + + a^113 + a^112 + a^111 + a^108 + a^104 + a^103 + a^102 + a^99 + a^98 + + a^94 + a^91 + a^90 + a^88 + a^79 + a^78 + a^75 + a^73 + a^72 + a^67 + + a^65 + a^64 + a^63 + a^62 + a^61 + a^59 + a^57 + a^52 + a^50 + a^48 + + a^47 + a^46 + a^45 + a^43 + a^41 + a^39 + a^37 + a^34 + a^31 + a^29 + + a^27 + a^25 + a^23 + a^22 + a^20 + a^18 + a^16 + a^14 + a^11 + a^10 + + a^8 + a^6 + a^5 + a^4 + a + 1 Check that :trac:`21998` has been resolved:: - sage: K. = GF(2^4) - sage: R. = K[] - sage: f = x^2 + x + a^2 + a - sage: r = f.any_root() - sage: r^2 + r + sage: K. = GF(2^4) # optional - sage.rings.finite_rings + sage: R. = K[] # optional - sage.rings.finite_rings + sage: f = x^2 + x + a^2 + a # optional - sage.rings.finite_rings + sage: r = f.any_root() # optional - sage.rings.finite_rings + sage: r^2 + r # optional - sage.rings.finite_rings a^2 + a """ if self.base_ring().is_finite() and self.base_ring().is_field(): @@ -2288,9 +2308,9 @@ cdef class Polynomial(CommutativePolynomial): :: - sage: R. = PolynomialRing(GF(5^2, 'a'), 'x') - sage: f = x^3 + 4*x - sage: f / (x - 1) + sage: R. = PolynomialRing(GF(5^2, 'a'), 'x') # optional - sage.rings.finite_rings + sage: f = x^3 + 4*x # optional - sage.rings.finite_rings + sage: f / (x - 1) # optional - sage.rings.finite_rings x^2 + x Be careful about coercions (this used to be broken):: @@ -2305,21 +2325,21 @@ cdef class Polynomial(CommutativePolynomial): Check that :trac:`12217` is fixed:: - sage: P. = GF(5)[] - sage: x/0 + sage: P. = GF(5)[] # optional - sage.rings.finite_rings + sage: x/0 # optional - sage.rings.finite_rings Traceback (most recent call last): ... ZeroDivisionError: inverse of Mod(0, 5) does not exist - sage: P. = GF(25, 'a')[] - sage: x/5 + sage: P. = GF(25, 'a')[] # optional - sage.rings.finite_rings + sage: x/5 # optional - sage.rings.finite_rings Traceback (most recent call last): ... ZeroDivisionError: division by zero in finite field Check that :trac:`23611` is fixed:: - sage: int(1) / x + sage: int(1) / x # optional - sage.rings.finite_rings 1/x """ # Same parents => bypass coercion @@ -2352,10 +2372,10 @@ cdef class Polynomial(CommutativePolynomial): sage: f^3 x^3 - 3*x^2 + 3*x - 1 - sage: R = PolynomialRing(GF(2), 'x') - sage: f = R(x^9 + x^7 + x^6 + x^5 + x^4 + x^2 + x) - sage: h = R(x^10 + x^7 + x^6 + x^5 + x^4 + x^3 + x^2 + 1) - sage: pow(f, 2, h) + sage: R = PolynomialRing(GF(2), 'x') # optional - sage.rings.finite_rings + sage: f = R(x^9 + x^7 + x^6 + x^5 + x^4 + x^2 + x) # optional - sage.rings.finite_rings + sage: h = R(x^10 + x^7 + x^6 + x^5 + x^4 + x^3 + x^2 + 1) # optional - sage.rings.finite_rings + sage: pow(f, 2, h) # optional - sage.rings.finite_rings x^9 + x^8 + x^7 + x^5 + x^3 TESTS:: @@ -2382,46 +2402,46 @@ cdef class Polynomial(CommutativePolynomial): :: - sage: k = GF(5) - sage: D. = k[] - sage: l. = k.extension(x^2 + 2) - sage: R. = l[] - sage: f = t^4 + (2*x - 1)*t^3 + (2*x + 1)*t^2 + 3 - sage: h = t^4 - x*t^3 + (3*x + 1)*t^2 + 2*t + 2*x - 1 - sage: pow(f, 2, h) + sage: k = GF(5) # optional - sage.rings.finite_rings + sage: D. = k[] # optional - sage.rings.finite_rings + sage: l. = k.extension(x^2 + 2) # optional - sage.rings.finite_rings + sage: R. = l[] # optional - sage.rings.finite_rings + sage: f = t^4 + (2*x - 1)*t^3 + (2*x + 1)*t^2 + 3 # optional - sage.rings.finite_rings + sage: h = t^4 - x*t^3 + (3*x + 1)*t^2 + 2*t + 2*x - 1 # optional - sage.rings.finite_rings + sage: pow(f, 2, h) # optional - sage.rings.finite_rings 3*t^3 + (2*x + 3)*t^2 + (2*x + 2)*t + 2*x + 2 - sage: pow(f, 10**7, h) + sage: pow(f, 10**7, h) # optional - sage.rings.finite_rings 4*x*t^3 + 2*x*t^2 + 4*x*t + 4 Check that :trac:`18457` is fixed:: - sage: R. = PolynomialRing(GF(5), sparse=True) - sage: (1+x)^(5^10) # used to hang forever + sage: R. = PolynomialRing(GF(5), sparse=True) # optional - sage.rings.finite_rings + sage: (1+x)^(5^10) # used to hang forever # optional - sage.rings.finite_rings x^9765625 + 1 - sage: S. = GF(3)[] - sage: R1. = PolynomialRing(S, sparse=True) - sage: (1+x+t)^(3^10) + sage: S. = GF(3)[] # optional - sage.rings.finite_rings + sage: R1. = PolynomialRing(S, sparse=True) # optional - sage.rings.finite_rings + sage: (1+x+t)^(3^10) # optional - sage.rings.finite_rings x^59049 + t^59049 + 1 - sage: R2. = PolynomialRing(S, sparse=False) - sage: (1+x+t)^(3^10) + sage: R2. = PolynomialRing(S, sparse=False) # optional - sage.rings.finite_rings + sage: (1+x+t)^(3^10) # optional - sage.rings.finite_rings x^59049 + t^59049 + 1 Check that the algorithm used is indeed correct:: sage: from sage.arith.power import generic_power - sage: R1 = PolynomialRing(GF(8,'a'), 'x') - sage: R2 = PolynomialRing(GF(9,'b'), 'x', sparse=True) - sage: R3 = PolynomialRing(R2, 'y') - sage: R4 = PolynomialRing(R1, 'y', sparse=True) - sage: for d in range(20,40): # long time + sage: R1 = PolynomialRing(GF(8,'a'), 'x') # optional - sage.rings.finite_rings + sage: R2 = PolynomialRing(GF(9,'b'), 'x', sparse=True) # optional - sage.rings.finite_rings + sage: R3 = PolynomialRing(R2, 'y') # optional - sage.rings.finite_rings + sage: R4 = PolynomialRing(R1, 'y', sparse=True) # optional - sage.rings.finite_rings + sage: for d in range(20,40): # long time # optional - sage.rings.finite_rings ....: for R in [R1, R2, R3, R3]: ....: a = R.random_element() ....: assert a^d == generic_power(a, d) Test the powering modulo ``x^n`` (calling :meth:`power_trunc`):: - sage: R. = GF(3)[] - sage: pow(x + 1, 51, x^7) + sage: R. = GF(3)[] # optional - sage.rings.finite_rings + sage: pow(x + 1, 51, x^7) # optional - sage.rings.finite_rings x^6 + 2*x^3 + 1 sage: S. = QQ[] @@ -2432,10 +2452,10 @@ cdef class Polynomial(CommutativePolynomial): Check that fallback method is used when it is not possible to compute the characteristic of the base ring (:trac:`24308`):: - sage: kk. = GF(2)[] - sage: k. = kk.quo(a^2+a+1) - sage: K. = k[] - sage: (T*y)^21 + sage: kk. = GF(2)[] # optional - sage.rings.finite_rings + sage: k. = kk.quo(a^2+a+1) # optional - sage.rings.finite_rings + sage: K. = k[] # optional - sage.rings.finite_rings + sage: (T*y)^21 # optional - sage.rings.finite_rings T^21 """ if not isinstance(left, Polynomial): @@ -2522,25 +2542,23 @@ cdef class Polynomial(CommutativePolynomial): -1800*x^7 + 1590*x^6 - 1052*x^5 + 530*x^4 - 200*x^3 + 55*x^2 - 10*x + 1 sage: S. = R[] - sage: (x+y).power_trunc(5,5) + sage: (x + y).power_trunc(5,5) 5*x*y^4 + 10*x^2*y^3 + 10*x^3*y^2 + 5*x^4*y + x^5 - sage: ((x+y)^5).truncate(5) + sage: ((x + y)^5).truncate(5) 5*x*y^4 + 10*x^2*y^3 + 10*x^3*y^2 + 5*x^4*y + x^5 - sage: R. = GF(3)[] - sage: p = x^2 - x + 1 - sage: q = p.power_trunc(80, 20) - sage: q + sage: R. = GF(3)[] # optional - sage.rings.finite_rings + sage: p = x^2 - x + 1 # optional - sage.rings.finite_rings + sage: q = p.power_trunc(80, 20); q # optional - sage.rings.finite_rings x^19 + x^18 + ... + 2*x^4 + 2*x^3 + x + 1 - sage: (p^80).truncate(20) == q + sage: (p^80).truncate(20) == q # optional - sage.rings.finite_rings True - sage: R. = GF(7)[] - sage: p = (x^2 + x + 1).power_trunc(2^100, 100) - sage: p + sage: R. = GF(7)[] # optional - sage.rings.finite_rings + sage: p = (x^2 + x + 1).power_trunc(2^100, 100); p # optional - sage.rings.finite_rings 2*x^99 + x^98 + x^95 + 2*x^94 + ... + 3*x^2 + 2*x + 1 - sage: for i in range(100): + sage: for i in range(100): # optional - sage.rings.finite_rings ....: q1 = (x^2 + x + 1).power_trunc(2^100 + i, 100) ....: q2 = p * (x^2 + x + 1).power_trunc(i, 100) ....: q2 = q2.truncate(100) @@ -2630,10 +2648,10 @@ cdef class Polynomial(CommutativePolynomial): elements in the Sage library yet that do not implement ``__bool__``, so we have to create one artificially.):: - sage: class PatchedAlgebraicNumber(sage.rings.qqbar.AlgebraicNumber): + sage: class PatchedAlgebraicNumber(sage.rings.qqbar.AlgebraicNumber): # optional - sage.rings.number_field ....: def __bool__(self): raise NotImplementedError() - sage: R. = QQbar[] - sage: R([PatchedAlgebraicNumber(0), 1]) + sage: R. = QQbar[] # optional - sage.rings.number_field + sage: R([PatchedAlgebraicNumber(0), 1]) # optional - sage.rings.number_field x + 0 """ if name is None: @@ -2708,10 +2726,10 @@ cdef class Polynomial(CommutativePolynomial): :: - sage: C3. = CyclotomicField(3) - sage: R. = C3[] - sage: f = X^3 - omega*X - sage: latex(f) + sage: C3. = CyclotomicField(3) # optional - sage.rings.number_field + sage: R. = C3[] # optional - sage.rings.number_field + sage: f = X^3 - omega*X # optional - sage.rings.number_field + sage: latex(f) # optional - sage.rings.number_field X^{3} - \omega X sage: R. = RDF[] sage: latex(x+2) @@ -2724,9 +2742,9 @@ cdef class Polynomial(CommutativePolynomial): The following illustrates a (non-intentional) superfluity of parentheses - sage: K.=QuadraticField(-1) - sage: R.=K[] - sage: latex(I*x^2-I*x) + sage: K. = QuadraticField(-1) # optional - sage.rings.number_field + sage: R. = K[] # optional - sage.rings.number_field + sage: latex(I*x^2 - I*x) # optional - sage.rings.number_field \left(\sqrt{-1}\right) x^{2} + \left(-\sqrt{-1}\right) x """ s = " " @@ -2799,7 +2817,7 @@ cdef class Polynomial(CommutativePolynomial): # Verified R. = RR[] 3.1415926535897931*x - sage: sage_input(polygen(GF(7)) + 12, verify=True) + sage: sage_input(polygen(GF(7)) + 12, verify=True) # optional - sage.rings.finite_rings # Verified R. = GF(7)[] x + 5 @@ -2855,7 +2873,7 @@ cdef class Polynomial(CommutativePolynomial): cpdef _floordiv_(self, right): r""" - Quotient of division of self by other. This is denoted //. + Quotient of division of ``self`` by ``other``. This is denoted //. If self = quotient \* right + remainder, this function returns quotient. @@ -2878,7 +2896,7 @@ cdef class Polynomial(CommutativePolynomial): def __mod__(self, other): """ - Remainder of division of self by other. + Remainder of division of ``self`` by ``other``. EXAMPLES:: @@ -2893,7 +2911,7 @@ cdef class Polynomial(CommutativePolynomial): def mod(self, other): """ - Remainder of division of self by other. + Remainder of division of ``self`` by ``other``. EXAMPLES:: @@ -2908,14 +2926,14 @@ cdef class Polynomial(CommutativePolynomial): Check the problem reported at :trac:`12529` is fixed:: sage: gens = 'y a0 a1 a2 b0 b1 b2 c1 c2 d0 d1 d2 d3 d4 d5 d6 d7'.split() - sage: R = PolynomialRing(GF(8), 17, gens) - sage: R.inject_variables(verbose=False) - sage: A, B, C = a0 + a1*y + a2*y^2, b0 + b1*y + b2*y^2, c1*y + c2*y^2 - sage: D = d0 + d1*y + d2*y^2 + d3*y^3 + d4*y^4 + d5*y^5 + d6*y^6 + d7*y^7 - sage: F = D.subs({y: B}) - sage: G = A.subs({y: F}) + C - sage: g = G.mod(y^8 + y) - sage: g.degree(y) + sage: R = PolynomialRing(GF(8), 17, gens) # optional - sage.rings.finite_rings + sage: R.inject_variables(verbose=False) # optional - sage.rings.finite_rings + sage: A, B, C = a0 + a1*y + a2*y^2, b0 + b1*y + b2*y^2, c1*y + c2*y^2 # optional - sage.rings.finite_rings + sage: D = d0 + d1*y + d2*y^2 + d3*y^3 + d4*y^4 + d5*y^5 + d6*y^6 + d7*y^7 # optional - sage.rings.finite_rings + sage: F = D.subs({y: B}) # optional - sage.rings.finite_rings + sage: G = A.subs({y: F}) + C # optional - sage.rings.finite_rings + sage: g = G.mod(y^8 + y) # optional - sage.rings.finite_rings + sage: g.degree(y) # optional - sage.rings.finite_rings 7 """ return self % other @@ -2938,7 +2956,7 @@ cdef class Polynomial(CommutativePolynomial): cpdef _mul_generic(self, right): """ - Compute the product of self and right using the classical quadratic + Compute the product of ``self`` and ``right`` using the classical quadratic algorithm. This method is the default for inexact rings. For two polynomials of degree n and m this method needs @@ -2954,21 +2972,21 @@ cdef class Polynomial(CommutativePolynomial): Show the product in the symbolic ring:: - sage: L = SR['x'] - sage: var('a0,a1,b0,b1') + sage: L = SR['x'] # optional - sage.symbolic + sage: var('a0,a1,b0,b1') # optional - sage.symbolic (a0, a1, b0, b1) - sage: L([a0,a1])._mul_generic(L([b0,b1])) + sage: L([a0, a1])._mul_generic(L([b0, b1])) # optional - sage.symbolic a1*b1*x^2 + (a1*b0 + a0*b1)*x + a0*b0 A non-commutative example:: - sage: A. = QuaternionAlgebra(QQ, -1,-1) - sage: R. = PolynomialRing(A) - sage: f = i*w + j - sage: g = k*w + 1 - sage: f._mul_generic(g) + sage: A. = QuaternionAlgebra(QQ, -1,-1) # optional - sage.combinat sage.modules + sage: R. = PolynomialRing(A) # optional - sage.combinat sage.modules + sage: f = i*w + j # optional - sage.combinat sage.modules + sage: g = k*w + 1 # optional - sage.combinat sage.modules + sage: f._mul_generic(g) # optional - sage.combinat sage.modules -j*w^2 + 2*i*w + j - sage: g._mul_generic(f) + sage: g._mul_generic(f) # optional - sage.combinat sage.modules j*w^2 + j @@ -3098,7 +3116,7 @@ cdef class Polynomial(CommutativePolynomial): INPUT: - ``self`` - Polynomial - - ``right`` - Polynomial (over same base ring as self) + - ``right`` - Polynomial (over same base ring as ``self``) - ``K_threshold`` - (optional) Integer. A threshold to fall back to schoolbook algorithm. In the recursion, if one of the polynomials is of degree less that K_threshold then the classic quadratic @@ -3172,23 +3190,23 @@ cdef class Polynomial(CommutativePolynomial): Show the product in the symbolic ring:: - sage: L = SR['x'] - sage: var('a0,a1,b0,b1') + sage: L = SR['x'] # optional - sage.symbolic + sage: var('a0,a1,b0,b1') # optional - sage.symbolic (a0, a1, b0, b1) - sage: L([a0,a1])._mul_karatsuba(L([b0,b1]),0) + sage: L([a0, a1])._mul_karatsuba(L([b0, b1]), 0) # optional - sage.symbolic a1*b1*x^2 + ((a0 + a1)*(b0 + b1) - a0*b0 - a1*b1)*x + a0*b0 - sage: L([a0,a1])._mul_karatsuba(L([b0,b1]),2) + sage: L([a0, a1])._mul_karatsuba(L([b0, b1]), 2) # optional - sage.symbolic a1*b1*x^2 + (a1*b0 + a0*b1)*x + a0*b0 A noncommutative example:: - sage: A. = QuaternionAlgebra(QQ, -1,-1) - sage: R. = PolynomialRing(A) - sage: f = i*w + j - sage: g = k*w + 1 - sage: f._mul_karatsuba(g,0) + sage: A. = QuaternionAlgebra(QQ, -1,-1) # optional - sage.combinat sage.modules + sage: R. = PolynomialRing(A) # optional - sage.combinat sage.modules + sage: f = i*w + j # optional - sage.combinat sage.modules + sage: g = k*w + 1 # optional - sage.combinat sage.modules + sage: f._mul_karatsuba(g,0) # optional - sage.combinat sage.modules -j*w^2 + 2*i*w + j - sage: g._mul_karatsuba(f,0) + sage: g._mul_karatsuba(f,0) # optional - sage.combinat sage.modules j*w^2 + j TESTS:: @@ -3214,28 +3232,28 @@ cdef class Polynomial(CommutativePolynomial): Random tests for noncommutative rings:: - sage: A. = QuaternionAlgebra(QQ, -1,-1) - sage: R. = PolynomialRing(A) - sage: f = R.random_element(randint(10,100)) - sage: g = R.random_element(randint(10,100)) - sage: f._mul_generic(g) == f._mul_karatsuba(g,0) + sage: A. = QuaternionAlgebra(QQ, -1,-1) # optional - sage.combinat sage.modules + sage: R. = PolynomialRing(A) # optional - sage.combinat sage.modules + sage: f = R.random_element(randint(10,100)) # optional - sage.combinat sage.modules + sage: g = R.random_element(randint(10,100)) # optional - sage.combinat sage.modules + sage: f._mul_generic(g) == f._mul_karatsuba(g,0) # optional - sage.combinat sage.modules True - sage: f._mul_generic(g) == f._mul_karatsuba(g,16) + sage: f._mul_generic(g) == f._mul_karatsuba(g,16) # optional - sage.combinat sage.modules True - sage: g = R.random_element(0) - sage: f._mul_karatsuba(g,0) == f._mul_generic(g) + sage: g = R.random_element(0) # optional - sage.combinat sage.modules + sage: f._mul_karatsuba(g,0) == f._mul_generic(g) # optional - sage.combinat sage.modules True - sage: g._mul_karatsuba(f,0) == g._mul_generic(f) + sage: g._mul_karatsuba(f,0) == g._mul_generic(f) # optional - sage.combinat sage.modules True Polynomials over matrices:: - sage: K = PolynomialRing(MatrixSpace(QQ,2),'x') - sage: f = K.random_element(randint(5,10)) - sage: g = K.random_element(randint(5,10)) - sage: h1 = f._mul_generic(g) - sage: h2 = f._mul_karatsuba(g,randint(0,10)) - sage: h1 == h2 + sage: K = PolynomialRing(MatrixSpace(QQ, 2), 'x') # optional - sage.modules + sage: f = K.random_element(randint(5, 10)) # optional - sage.modules + sage: g = K.random_element(randint(5, 10)) # optional - sage.modules + sage: h1 = f._mul_generic(g) # optional - sage.modules + sage: h2 = f._mul_karatsuba(g,randint(0, 10)) # optional - sage.modules + sage: h1 == h2 # optional - sage.modules True """ if self.is_zero(): @@ -3284,32 +3302,32 @@ cdef class Polynomial(CommutativePolynomial): def base_ring(self): """ - Return the base ring of the parent of self. + Return the base ring of the parent of ``self``. EXAMPLES:: sage: R. = ZZ[] sage: x.base_ring() Integer Ring - sage: (2*x+3).base_ring() + sage: (2*x + 3).base_ring() Integer Ring """ return self._parent.base_ring() cpdef base_extend(self, R): """ - Return a copy of this polynomial but with coefficients in R, if - there is a natural map from coefficient ring of self to R. + Return a copy of this polynomial but with coefficients in ``R``, if + there is a natural map from the coefficient ring of ``self`` to ``R``. EXAMPLES:: sage: R. = QQ[] sage: f = x^3 - 17*x + 3 - sage: f.base_extend(GF(7)) + sage: f.base_extend(GF(7)) # optional - sage.rings.finite_rings Traceback (most recent call last): ... TypeError: no such base extension - sage: f.change_ring(GF(7)) + sage: f.change_ring(GF(7)) # optional - sage.rings.finite_rings x^3 + 4*x + 3 """ S = self._parent.base_extend(R) @@ -3342,17 +3360,17 @@ cdef class Polynomial(CommutativePolynomial): EXAMPLES:: - sage: K. = CyclotomicField(3) - sage: f = K.defining_polynomial() - sage: f.change_ring(GF(7)) + sage: K. = CyclotomicField(3) # optional - sage.rings.number_field + sage: f = K.defining_polynomial() # optional - sage.rings.number_field + sage: f.change_ring(GF(7)) # optional - sage.rings.finite_rings # optional - sage.rings.number_field x^2 + x + 1 :: - sage: K. = CyclotomicField(3) - sage: R. = K[] - sage: f = x^2 + z - sage: f.change_ring(K.embeddings(CC)[1]) + sage: K. = CyclotomicField(3) # optional - sage.rings.number_field + sage: R. = K[] # optional - sage.rings.number_field + sage: f = x^2 + z # optional - sage.rings.number_field + sage: f.change_ring(K.embeddings(CC)[1]) # optional - sage.rings.number_field x^2 - 0.500000000000000 - 0.866025403784438*I :: @@ -3367,17 +3385,17 @@ cdef class Polynomial(CommutativePolynomial): Check that :trac:`25022` is fixed:: sage: K. = ZZ[] - sage: x.change_ring(SR) == SR['x'].gen() + sage: x.change_ring(SR) == SR['x'].gen() # optional - sage.symbolic True sage: x.change_ring(ZZ['x']) == ZZ['x']['x'].gen() True Check that :trac:`28541` is fixed:: - sage: F. = GF(7^2) - sage: S. = F[] - sage: P = x^2 + a*x + a^2 - sage: P.change_ring(F.frobenius_endomorphism()) + sage: F. = GF(7^2) # optional - sage.rings.finite_rings + sage: S. = F[] # optional - sage.rings.finite_rings + sage: P = x^2 + a*x + a^2 # optional - sage.rings.finite_rings + sage: P.change_ring(F.frobenius_endomorphism()) # optional - sage.rings.finite_rings x^2 + (6*a + 1)*x + 6*a + 5 """ if isinstance(R, Map): @@ -3442,8 +3460,9 @@ cdef class Polynomial(CommutativePolynomial): def __copy__(self): """ - Return a "copy" of self. This is just self, since in Sage - polynomials are immutable this just returns self again. + Return a "copy" of ``self``. + + This is just ``self``, since in Sage polynomials are immutable. EXAMPLES: @@ -3464,7 +3483,7 @@ cdef class Polynomial(CommutativePolynomial): def degree(self, gen=None): """ Return the degree of this polynomial. The zero polynomial has - degree -1. + degree `-1`. EXAMPLES:: @@ -3521,20 +3540,20 @@ cdef class Polynomial(CommutativePolynomial): def denominator(self): """ - Return a denominator of self. + Return a denominator of ``self``. - First, the lcm of the denominators of the entries of self + First, the lcm of the denominators of the entries of ``self`` is computed and returned. If this computation fails, the - unit of the parent of self is returned. + unit of the parent of ``self`` is returned. Note that some subclasses may implement their own - denominator function. For example, see + :meth:`denominator` method. For example, see :class:`sage.rings.polynomial.polynomial_rational_flint.Polynomial_rational_flint` .. warning:: This is not the denominator of the rational function - defined by self, which would always be 1 since self is a + defined by ``self``, which would always be 1 since ``self`` is a polynomial. EXAMPLES: @@ -3562,7 +3581,7 @@ cdef class Polynomial(CommutativePolynomial): Finally, we try to compute the denominator of a polynomial with coefficients in the real numbers, which is a ring whose elements do - not have a denominator method. + not have a :meth:`denominator` method. :: @@ -3573,17 +3592,17 @@ cdef class Polynomial(CommutativePolynomial): 1.00000000000000 Check that the denominator is an element over the base whenever the base - has no denominator function. This closes :trac:`9063`. :: + has no :meth:`denominator` method. This closes :trac:`9063`. :: - sage: R. = GF(5)[] - sage: x = R(0) - sage: x.denominator() + sage: R. = GF(5)[] # optional - sage.rings.finite_rings + sage: x = R(0) # optional - sage.rings.finite_rings + sage: x.denominator() # optional - sage.rings.finite_rings 1 - sage: type(x.denominator()) + sage: type(x.denominator()) # optional - sage.rings.finite_rings - sage: isinstance(x.numerator() / x.denominator(), Polynomial) + sage: isinstance(x.numerator() / x.denominator(), Polynomial) # optional - sage.rings.finite_rings True - sage: isinstance(x.numerator() / R(1), Polynomial) + sage: isinstance(x.numerator() / R(1), Polynomial) # optional - sage.rings.finite_rings False TESTS: @@ -3609,7 +3628,7 @@ cdef class Polynomial(CommutativePolynomial): def numerator(self): """ - Return a numerator of self computed as self * self.denominator() + Return a numerator of ``self``, computed as ``self * self.denominator()`` Note that some subclasses may implement its own numerator function. For example, see @@ -3618,13 +3637,13 @@ cdef class Polynomial(CommutativePolynomial): .. warning:: This is not the numerator of the rational function - defined by self, which would always be self since self is a + defined by ``self``, which would always be ``self`` since ``self`` is a polynomial. EXAMPLES: First we compute the numerator of a polynomial with - integer coefficients, which is of course self. + integer coefficients, which is of course ``self``. :: @@ -3660,17 +3679,17 @@ cdef class Polynomial(CommutativePolynomial): sage: f.numerator() x + 0.300000000000000 - We check that the computation the numerator and denominator - are valid + We check that the computation of the numerator and denominator + are valid. :: - sage: K=NumberField(symbolic_expression('x^3+2'),'a')['s,t']['x'] - sage: f=K.random_element() - sage: f.numerator() / f.denominator() == f + sage: K = NumberField(symbolic_expression('x^3+2'), 'a')['s,t']['x'] # optional - sage.rings.number_field sage.symbolic + sage: f = K.random_element() # optional - sage.rings.number_field sage.symbolic + sage: f.numerator() / f.denominator() == f # optional - sage.rings.number_field sage.symbolic True - sage: R=RR['x'] - sage: f=R.random_element() + sage: R = RR['x'] + sage: f = R.random_element() sage: f.numerator() / f.denominator() == f True """ @@ -3679,10 +3698,10 @@ cdef class Polynomial(CommutativePolynomial): def derivative(self, *args): r""" The formal derivative of this polynomial, with respect to variables - supplied in args. + supplied in ``args``. Multiple variables and iteration counts may be supplied; see - documentation for the global derivative() function for more + documentation for the global :func:`derivative` function for more details. .. SEEALSO:: @@ -3780,17 +3799,17 @@ cdef class Polynomial(CommutativePolynomial): Check that :trac:`28147` is fixed:: - sage: R. = GF(65537)[] - sage: p = x^4 - 17*x^3 + 2*x^2 - x + 7 - sage: p.derivative() + sage: R. = GF(65537)[] # optional - sage.rings.finite_rings + sage: p = x^4 - 17*x^3 + 2*x^2 - x + 7 # optional - sage.rings.finite_rings + sage: p.derivative() # optional - sage.rings.finite_rings 4*x^3 + 65486*x^2 + 4*x + 65536 - sage: R. = GF(19^2)[] - sage: p = x^4 - 17*x^3 + 2*x^2 - x + 7 - sage: p.derivative() + sage: R. = GF(19^2)[] # optional - sage.rings.finite_rings + sage: p = x^4 - 17*x^3 + 2*x^2 - x + 7 # optional - sage.rings.finite_rings + sage: p.derivative() # optional - sage.rings.finite_rings 4*x^3 + 6*x^2 + 4*x + 18 - sage: R. = GF(2)[] - sage: p = x^4 + x^2 + x - sage: p.derivative() + sage: R. = GF(2)[] # optional - sage.rings.finite_rings + sage: p = x^4 + x^2 + x # optional - sage.rings.finite_rings + sage: p.derivative() # optional - sage.rings.finite_rings 1 sage: R. = Integers(77)[] @@ -3805,8 +3824,8 @@ cdef class Polynomial(CommutativePolynomial): ... ValueError: cannot differentiate with respect to 2*x - sage: y = var("y") - sage: f._derivative(y) + sage: y = var("y") # optional - sage.symbolic + sage: f._derivative(y) # optional - sage.symbolic Traceback (most recent call last): ... ValueError: cannot differentiate with respect to y @@ -3814,21 +3833,21 @@ cdef class Polynomial(CommutativePolynomial): Check that :trac:`26844` is fixed by :trac:`28147`:: - sage: A = PolynomialRing(GF(3), name='t') - sage: K = A.fraction_field() - sage: t = K.gen() - sage: t.derivative(t) + sage: A = PolynomialRing(GF(3), name='t') # optional - sage.rings.finite_rings + sage: K = A.fraction_field() # optional - sage.rings.finite_rings + sage: t = K.gen() # optional - sage.rings.finite_rings + sage: t.derivative(t) # optional - sage.rings.finite_rings 1 Check that :trac:`28187` is fixed:: - sage: R. = GF(65537)[] - sage: x._derivative(2*x) + sage: R. = GF(65537)[] # optional - sage.rings.finite_rings + sage: x._derivative(2*x) # optional - sage.rings.finite_rings Traceback (most recent call last): ... ValueError: cannot differentiate with respect to 2*x - sage: y = var('y') - sage: R.gen()._derivative(y) + sage: y = var('y') # optional - sage.symbolic + sage: R.gen()._derivative(y) # optional - sage.rings.finite_rings sage.symbolic Traceback (most recent call last): ... ValueError: cannot differentiate with respect to y @@ -3905,16 +3924,16 @@ cdef class Polynomial(CommutativePolynomial): This shows that the issue at :trac:`7711` is resolved:: - sage: P. = PolynomialRing(GF(2147483647)) - sage: Q. = PolynomialRing(P) - sage: p=x+y+z - sage: p.integral() + sage: P. = PolynomialRing(GF(2147483647)) # optional - sage.rings.finite_rings + sage: Q. = PolynomialRing(P) # optional - sage.rings.finite_rings + sage: p = x + y + z # optional - sage.rings.finite_rings + sage: p.integral() # optional - sage.rings.finite_rings -1073741823*y^2 + (x + z)*y - sage: P. = PolynomialRing(GF(next_prime(2147483647))) - sage: Q. = PolynomialRing(P) - sage: p=x+y+z - sage: p.integral() + sage: P. = PolynomialRing(GF(next_prime(2147483647))) # optional - sage.rings.finite_rings + sage: Q. = PolynomialRing(P) # optional - sage.rings.finite_rings + sage: p = x + y + z # optional - sage.rings.finite_rings + sage: p.integral() # optional - sage.rings.finite_rings 1073741830*y^2 + (x + z)*y A truly convoluted example:: @@ -3946,7 +3965,7 @@ cdef class Polynomial(CommutativePolynomial): sage: R. = QQ[] sage: t = PolynomialRing(R,'t').gen() - sage: f = x*t +5*t^2 + sage: f = x*t + 5*t^2 sage: f.integral(x) 5*x*t^2 + 1/2*x^2*t @@ -4032,14 +4051,14 @@ cdef class Polynomial(CommutativePolynomial): INPUT: - ``kwargs`` -- any keyword arguments are passed to the method - ``_factor_univariate_polynomial()`` of the base ring if it + :meth:`_factor_univariate_polynomial` of the base ring if it defines such a method. OUTPUT: - - A factorization of ``self`` over its parent into a unit and - irreducible factors. If the parent is a polynomial ring - over a field, these factors are monic. + A factorization of ``self`` over its parent into a unit and + irreducible factors. If the parent is a polynomial ring + over a field, these factors are monic. EXAMPLES: @@ -4047,38 +4066,39 @@ cdef class Polynomial(CommutativePolynomial): sage: x = QQ['x'].0 sage: f = (x^3 - 1)^2 - sage: f.factor() + sage: f.factor() # optional - sage.libs.pari (x - 1)^2 * (x^2 + x + 1)^2 Since `\QQ` is a field, the irreducible factors are monic:: sage: f = 10*x^5 - 1 - sage: f.factor() + sage: f.factor() # optional - sage.libs.pari (10) * (x^5 - 1/10) sage: f = 10*x^5 - 10 - sage: f.factor() + sage: f.factor() # optional - sage.libs.pari (10) * (x - 1) * (x^4 + x^3 + x^2 + x + 1) Over `\ZZ` the irreducible factors need not be monic:: sage: x = ZZ['x'].0 sage: f = 10*x^5 - 1 - sage: f.factor() + sage: f.factor() # optional - sage.libs.pari 10*x^5 - 1 We factor a non-monic polynomial over a finite field of 25 elements:: - sage: k. = GF(25) - sage: R. = k[] - sage: f = 2*x^10 + 2*x + 2*a - sage: F = f.factor(); F - (2) * (x + a + 2) * (x^2 + 3*x + 4*a + 4) * (x^2 + (a + 1)*x + a + 2) * (x^5 + (3*a + 4)*x^4 + (3*a + 3)*x^3 + 2*a*x^2 + (3*a + 1)*x + 3*a + 1) + sage: k. = GF(25) # optional - sage.rings.finite_rings + sage: R. = k[] # optional - sage.rings.finite_rings + sage: f = 2*x^10 + 2*x + 2*a # optional - sage.rings.finite_rings + sage: F = f.factor(); F # optional - sage.rings.finite_rings + (2) * (x + a + 2) * (x^2 + 3*x + 4*a + 4) * (x^2 + (a + 1)*x + a + 2) + * (x^5 + (3*a + 4)*x^4 + (3*a + 3)*x^3 + 2*a*x^2 + (3*a + 1)*x + 3*a + 1) Notice that the unit factor is included when we multiply `F` back out:: - sage: expand(F) + sage: expand(F) # optional - sage.rings.finite_rings 2*x^10 + 2*x + 2*a A new ring. In the example below, we set the special method @@ -4087,20 +4107,23 @@ cdef class Polynomial(CommutativePolynomial): used to easily extend polynomial factorization to work over new rings you introduce:: - sage: R. = PolynomialRing(IntegerModRing(4),implementation="NTL") - sage: (x^2).factor() + sage: R. = PolynomialRing(IntegerModRing(4), implementation="NTL") # optional - sage.libs.ntl + sage: (x^2).factor() # optional - sage.libs.ntl Traceback (most recent call last): ... - NotImplementedError: factorization of polynomials over rings with composite characteristic is not implemented - sage: R.base_ring()._factor_univariate_polynomial = lambda f: f.change_ring(ZZ).factor() - sage: (x^2).factor() + NotImplementedError: factorization of polynomials over rings with + composite characteristic is not implemented + sage: def my_factor(f): + ....: return f.change_ring(ZZ).factor() + sage: R.base_ring()._factor_univariate_polynomial = my_factor # optional - sage.libs.ntl + sage: (x^2).factor() # optional - sage.libs.ntl sage.libs.pari x^2 - sage: del R.base_ring()._factor_univariate_polynomial # clean up + sage: del R.base_ring()._factor_univariate_polynomial # clean up # optional - sage.libs.ntl Arbitrary precision real and complex factorization:: sage: R. = RealField(100)[] - sage: F = factor(x^2-3); F + sage: F = factor(x^2 - 3); F (x - 1.7320508075688772935274463415) * (x + 1.7320508075688772935274463415) sage: expand(F) x^2 - 3.0000000000000000000000000000 @@ -4108,11 +4131,11 @@ cdef class Polynomial(CommutativePolynomial): x^2 + 1.0000000000000000000000000000 sage: R. = ComplexField(100)[] - sage: F = factor(x^2+3); F + sage: F = factor(x^2 + 3); F (x - 1.7320508075688772935274463415*I) * (x + 1.7320508075688772935274463415*I) sage: expand(F) x^2 + 3.0000000000000000000000000000 - sage: factor(x^2+1) + sage: factor(x^2 + 1) (x - I) * (x + I) sage: f = R(I) * (x^2 + 1) ; f I*x^2 + I @@ -4123,24 +4146,26 @@ cdef class Polynomial(CommutativePolynomial): Over a number field:: - sage: K. = CyclotomicField(15) - sage: x = polygen(K) - sage: ((x^3 + z*x + 1)^3*(x - z)).factor() + sage: K. = CyclotomicField(15) # optional - sage.rings.number_field + sage: x = polygen(K) # optional - sage.rings.number_field + sage: ((x^3 + z*x + 1)^3 * (x - z)).factor() # optional - sage.rings.number_field (x - z) * (x^3 + z*x + 1)^3 - sage: cyclotomic_polynomial(12).change_ring(K).factor() + sage: cyclotomic_polynomial(12).change_ring(K).factor() # optional - sage.rings.number_field (x^2 - z^5 - 1) * (x^2 + z^5) - sage: ((x^3 + z*x + 1)^3*(x/(z+2) - 1/3)).factor() - (-1/331*z^7 + 3/331*z^6 - 6/331*z^5 + 11/331*z^4 - 21/331*z^3 + 41/331*z^2 - 82/331*z + 165/331) * (x - 1/3*z - 2/3) * (x^3 + z*x + 1)^3 + sage: ((x^3 + z*x + 1)^3 * (x/(z+2) - 1/3)).factor() # optional - sage.rings.number_field + (-1/331*z^7 + 3/331*z^6 - 6/331*z^5 + 11/331*z^4 + - 21/331*z^3 + 41/331*z^2 - 82/331*z + 165/331) + * (x - 1/3*z - 2/3) * (x^3 + z*x + 1)^3 Over a relative number field:: sage: x = polygen(QQ) - sage: K. = CyclotomicField(3) - sage: L. = K.extension(x^3 - 2) - sage: t = polygen(L, 't') - sage: f = (t^3 + t + a)*(t^5 + t + z); f + sage: K. = CyclotomicField(3) # optional - sage.rings.number_field + sage: L. = K.extension(x^3 - 2) # optional - sage.rings.number_field + sage: t = polygen(L, 't') # optional - sage.rings.number_field + sage: f = (t^3 + t + a) * (t^5 + t + z); f # optional - sage.rings.number_field t^8 + t^6 + a*t^5 + t^4 + z*t^3 + t^2 + (a + z)*t + z*a - sage: f.factor() + sage: f.factor() # optional - sage.rings.number_field (t^3 + t + a) * (t^5 + t + z) Over the real double field:: @@ -4168,33 +4193,42 @@ cdef class Polynomial(CommutativePolynomial): sage: f = (x^2 + 2*R(I))^3 sage: F = f.factor() sage: F # abs tol 3e-5 - (x - 1.0000138879287663 + 1.0000013435286879*I) * (x - 0.9999942196864997 + 0.9999873009803959*I) * (x - 0.9999918923847313 + 1.0000113554909125*I) * (x + 0.9999908759550227 - 1.0000069659624138*I) * (x + 0.9999985293216753 - 0.9999886153831807*I) * (x + 1.0000105947233 - 1.0000044186544053*I) + (x - 1.0000138879287663 + 1.0000013435286879*I) * (x - 0.9999942196864997 + 0.9999873009803959*I) * (x - 0.9999918923847313 + 1.0000113554909125*I) + * (x + 0.9999908759550227 - 1.0000069659624138*I) * (x + 0.9999985293216753 - 0.9999886153831807*I) * (x + 1.0000105947233 - 1.0000044186544053*I) sage: [f(t[0][0]).abs() for t in F] # abs tol 1e-13 - [1.979365054e-14, 1.97936298566e-14, 1.97936990747e-14, 3.6812407475e-14, 3.65211563729e-14, 3.65220890052e-14] + [1.979365054e-14, 1.97936298566e-14, 1.97936990747e-14, + 3.6812407475e-14, 3.65211563729e-14, 3.65220890052e-14] Factoring polynomials over `\ZZ/n\ZZ` for composite `n` is not implemented:: sage: R. = PolynomialRing(Integers(35)) - sage: f = (x^2+2*x+2)*(x^2+3*x+9) + sage: f = (x^2 + 2*x + 2) * (x^2 + 3*x + 9) sage: f.factor() Traceback (most recent call last): ... - NotImplementedError: factorization of polynomials over rings with composite characteristic is not implemented + NotImplementedError: factorization of polynomials over + rings with composite characteristic is not implemented Factoring polynomials over the algebraic numbers (see :trac:`8544`):: - sage: R. = QQbar[] - sage: (x^8-1).factor() - (x - 1) * (x - 0.7071067811865475? - 0.7071067811865475?*I) * (x - 0.7071067811865475? + 0.7071067811865475?*I) * (x - I) * (x + I) * (x + 0.7071067811865475? - 0.7071067811865475?*I) * (x + 0.7071067811865475? + 0.7071067811865475?*I) * (x + 1) + sage: R. = QQbar[] # optional - sage.rings.number_field + sage: (x^8 - 1).factor() # optional - sage.rings.number_field + (x - 1) * (x - 0.7071067811865475? - 0.7071067811865475?*I) + * (x - 0.7071067811865475? + 0.7071067811865475?*I) * (x - I) * (x + I) + * (x + 0.7071067811865475? - 0.7071067811865475?*I) + * (x + 0.7071067811865475? + 0.7071067811865475?*I) * (x + 1) Factoring polynomials over the algebraic reals (see :trac:`8544`):: - sage: R. = AA[] - sage: (x^8+1).factor() - (x^2 - 1.847759065022574?*x + 1.000000000000000?) * (x^2 - 0.7653668647301795?*x + 1.000000000000000?) * (x^2 + 0.7653668647301795?*x + 1.000000000000000?) * (x^2 + 1.847759065022574?*x + 1.000000000000000?) + sage: R. = AA[] # optional - sage.rings.number_field + sage: (x^8 + 1).factor() # optional - sage.rings.number_field + (x^2 - 1.847759065022574?*x + 1.000000000000000?) + * (x^2 - 0.7653668647301795?*x + 1.000000000000000?) + * (x^2 + 0.7653668647301795?*x + 1.000000000000000?) + * (x^2 + 1.847759065022574?*x + 1.000000000000000?) TESTS: @@ -4215,91 +4249,94 @@ cdef class Polynomial(CommutativePolynomial): sage: f = 8*x^9 + 42*x^6 + 6*x^3 - 1 sage: g = x^24 - 12*x^23 + 72*x^22 - 286*x^21 + 849*x^20 - 2022*x^19 + 4034*x^18 - 6894*x^17 + 10182*x^16 - 13048*x^15 + 14532*x^14 - 13974*x^13 + 11365*x^12 - 7578*x^11 + 4038*x^10 - 1766*x^9 + 762*x^8 - 408*x^7 + 236*x^6 - 126*x^5 + 69*x^4 - 38*x^3 + 18*x^2 - 6*x + 1 sage: assert g.is_irreducible() - sage: K. = NumberField(g) - sage: len(f.roots(K)) + sage: K. = NumberField(g) # optional - sage.rings.number_field + sage: len(f.roots(K)) # optional - sage.rings.number_field 9 sage: f.factor() (8) * (x^3 + 1/4) * (x^6 + 5*x^3 - 1/2) - sage: f.change_ring(K).factor() + sage: f.change_ring(K).factor() # optional - sage.rings.number_field (8) * (x - 3260097/3158212*a^22 + 35861067/3158212*a^21 - 197810817/3158212*a^20 + 722970825/3158212*a^19 - 1980508347/3158212*a^18 + 4374189477/3158212*a^17 - 4059860553/1579106*a^16 + 6442403031/1579106*a^15 - 17542341771/3158212*a^14 + 20537782665/3158212*a^13 - 20658463789/3158212*a^12 + 17502836649/3158212*a^11 - 11908953451/3158212*a^10 + 6086953981/3158212*a^9 - 559822335/789553*a^8 + 194545353/789553*a^7 - 505969453/3158212*a^6 + 338959407/3158212*a^5 - 155204647/3158212*a^4 + 79628015/3158212*a^3 - 57339525/3158212*a^2 + 26692783/3158212*a - 1636338/789553) * ... - sage: f = QQbar['x'](1) - sage: f.factor() + sage: f = QQbar['x'](1) # optional - sage.rings.number_field + sage: f.factor() # optional - sage.rings.number_field 1 Factorization also works even if the variable of the finite field is nefariously labeled `x`:: - sage: R. = GF(3^2, 'x')[] - sage: f = x^10 +7*x -13 - sage: G = f.factor(); G - (x + x) * (x + 2*x + 1) * (x^4 + (x + 2)*x^3 + (2*x + 2)*x + 2) * (x^4 + 2*x*x^3 + (x + 1)*x + 2) + sage: R. = GF(3^2, 'x')[] # optional - sage.rings.finite_rings + sage: f = x^10 +7*x -13 # optional - sage.rings.finite_rings + sage: G = f.factor(); G # optional - sage.rings.finite_rings + (x + x) * (x + 2*x + 1) * (x^4 + (x + 2)*x^3 + (2*x + 2)*x + 2) + * (x^4 + 2*x*x^3 + (x + 1)*x + 2) sage: prod(G) == f True :: - sage: R. = GF(9,'x')[] # purposely calling it x to test robustness - sage: f = x0^3 + x0 + 1 - sage: f.factor() + sage: R. = GF(9,'x')[] # purposely calling it x to test robustness # optional - sage.rings.finite_rings + sage: f = x0^3 + x0 + 1 # optional - sage.rings.finite_rings + sage: f.factor() # optional - sage.rings.finite_rings (x0 + 2) * (x0 + x) * (x0 + 2*x + 1) - sage: f = 0*x0 - sage: f.factor() + sage: f = 0*x0 # optional - sage.rings.finite_rings + sage: f.factor() # optional - sage.rings.finite_rings Traceback (most recent call last): ... ArithmeticError: factorization of 0 is not defined :: - sage: f = x0^0 - sage: f.factor() + sage: f = x0^0 # optional - sage.rings.finite_rings + sage: f.factor() # optional - sage.rings.finite_rings 1 Over a complicated number field:: sage: x = polygen(QQ, 'x') sage: f = x^6 + 10/7*x^5 - 867/49*x^4 - 76/245*x^3 + 3148/35*x^2 - 25944/245*x + 48771/1225 - sage: K. = NumberField(f) - sage: S. = K[] - sage: ff = S(f); ff + sage: K. = NumberField(f) # optional - sage.rings.number_field + sage: S. = K[] # optional - sage.rings.number_field + sage: ff = S(f); ff # optional - sage.rings.number_field T^6 + 10/7*T^5 - 867/49*T^4 - 76/245*T^3 + 3148/35*T^2 - 25944/245*T + 48771/1225 - sage: F = ff.factor() - sage: len(F) + sage: F = ff.factor() # optional - sage.rings.number_field + sage: len(F) # optional - sage.rings.number_field 4 - sage: F[:2] - [(T - a, 1), (T - 40085763200/924556084127*a^5 - 145475769880/924556084127*a^4 + 527617096480/924556084127*a^3 + 1289745809920/924556084127*a^2 - 3227142391585/924556084127*a - 401502691578/924556084127, 1)] - sage: expand(F) + sage: F[:2] # optional - sage.rings.number_field + [(T - a, 1), + (T - 40085763200/924556084127*a^5 - 145475769880/924556084127*a^4 + 527617096480/924556084127*a^3 + + 1289745809920/924556084127*a^2 - 3227142391585/924556084127*a - 401502691578/924556084127, 1)] + sage: expand(F) # optional - sage.rings.number_field T^6 + 10/7*T^5 - 867/49*T^4 - 76/245*T^3 + 3148/35*T^2 - 25944/245*T + 48771/1225 :: sage: f = x^2 - 1/3 - sage: K. = NumberField(f) - sage: A. = K[] - sage: A(x^2 - 1).factor() + sage: K. = NumberField(f) # optional - sage.rings.number_field + sage: A. = K[] # optional - sage.rings.number_field + sage: A(x^2 - 1).factor() # optional - sage.rings.number_field (T - 1) * (T + 1) :: - sage: A(3*x^2 - 1).factor() + sage: A(3*x^2 - 1).factor() # optional - sage.rings.number_field (3) * (T - a) * (T + a) :: - sage: A(x^2 - 1/3).factor() + sage: A(x^2 - 1/3).factor() # optional - sage.rings.number_field (T - a) * (T + a) Test that :trac:`10279` is fixed:: sage: R. = PolynomialRing(QQ) - sage: K. = NumberField(t^4 - t^2 + 1) - sage: pol = t^3 + (-4*a^3 + 2*a)*t^2 - 11/3*a^2*t + 2/3*a^3 - 4/3*a - sage: pol.factor() + sage: K. = NumberField(t^4 - t^2 + 1) # optional - sage.rings.number_field + sage: pol = t^3 + (-4*a^3 + 2*a)*t^2 - 11/3*a^2*t + 2/3*a^3 - 4/3*a # optional - sage.rings.number_field + sage: pol.factor() # optional - sage.rings.number_field (t - 2*a^3 + a) * (t - 4/3*a^3 + 2/3*a) * (t - 2/3*a^3 + 1/3*a) Test that this factorization really uses ``nffactor()`` internally:: sage: pari.default("debug", 3) - sage: F = pol.factor() + sage: F = pol.factor() # optional - sage.rings.number_field Entering nffactor: ... @@ -4308,55 +4345,55 @@ cdef class Polynomial(CommutativePolynomial): Test that :trac:`10369` is fixed:: sage: x = polygen(QQ) - sage: K. = NumberField(x^6 + x^5 + x^4 + x^3 + x^2 + x + 1) - sage: R. = PolynomialRing(K) + sage: K. = NumberField(x^6 + x^5 + x^4 + x^3 + x^2 + x + 1) # optional - sage.rings.number_field + sage: R. = PolynomialRing(K) # optional - sage.rings.number_field - sage: pol = (-1/7*a^5 - 1/7*a^4 - 1/7*a^3 - 1/7*a^2 - 2/7*a - 1/7)*t^10 + (4/7*a^5 - 2/7*a^4 - 2/7*a^3 - 2/7*a^2 - 2/7*a - 6/7)*t^9 + (90/49*a^5 + 152/49*a^4 + 18/49*a^3 + 24/49*a^2 + 30/49*a + 36/49)*t^8 + (-10/49*a^5 + 10/7*a^4 + 198/49*a^3 - 102/49*a^2 - 60/49*a - 26/49)*t^7 + (40/49*a^5 + 45/49*a^4 + 60/49*a^3 + 277/49*a^2 - 204/49*a - 78/49)*t^6 + (90/49*a^5 + 110/49*a^4 + 2*a^3 + 80/49*a^2 + 46/7*a - 30/7)*t^5 + (30/7*a^5 + 260/49*a^4 + 250/49*a^3 + 232/49*a^2 + 32/7*a + 8)*t^4 + (-184/49*a^5 - 58/49*a^4 - 52/49*a^3 - 66/49*a^2 - 72/49*a - 72/49)*t^3 + (18/49*a^5 - 32/49*a^4 + 10/49*a^3 + 4/49*a^2)*t^2 + (2/49*a^4 - 4/49*a^3 + 2/49*a^2)*t - sage: pol.factor() + sage: pol = (-1/7*a^5 - 1/7*a^4 - 1/7*a^3 - 1/7*a^2 - 2/7*a - 1/7)*t^10 + (4/7*a^5 - 2/7*a^4 - 2/7*a^3 - 2/7*a^2 - 2/7*a - 6/7)*t^9 + (90/49*a^5 + 152/49*a^4 + 18/49*a^3 + 24/49*a^2 + 30/49*a + 36/49)*t^8 + (-10/49*a^5 + 10/7*a^4 + 198/49*a^3 - 102/49*a^2 - 60/49*a - 26/49)*t^7 + (40/49*a^5 + 45/49*a^4 + 60/49*a^3 + 277/49*a^2 - 204/49*a - 78/49)*t^6 + (90/49*a^5 + 110/49*a^4 + 2*a^3 + 80/49*a^2 + 46/7*a - 30/7)*t^5 + (30/7*a^5 + 260/49*a^4 + 250/49*a^3 + 232/49*a^2 + 32/7*a + 8)*t^4 + (-184/49*a^5 - 58/49*a^4 - 52/49*a^3 - 66/49*a^2 - 72/49*a - 72/49)*t^3 + (18/49*a^5 - 32/49*a^4 + 10/49*a^3 + 4/49*a^2)*t^2 + (2/49*a^4 - 4/49*a^3 + 2/49*a^2)*t # optional - sage.rings.number_field + sage: pol.factor() # optional - sage.rings.number_field (-1/7*a^5 - 1/7*a^4 - 1/7*a^3 - 1/7*a^2 - 2/7*a - 1/7) * t * (t - a^5 - a^4 - a^3 - a^2 - a - 1)^4 * (t^5 + (-12/7*a^5 - 10/7*a^4 - 8/7*a^3 - 6/7*a^2 - 4/7*a - 2/7)*t^4 + (12/7*a^5 - 8/7*a^3 + 16/7*a^2 + 2/7*a + 20/7)*t^3 + (-20/7*a^5 - 20/7*a^3 - 20/7*a^2 + 4/7*a - 2)*t^2 + (12/7*a^5 + 12/7*a^3 + 2/7*a + 16/7)*t - 4/7*a^5 - 4/7*a^3 - 4/7*a - 2/7) - sage: pol = (1/7*a^2 - 1/7*a)*t^10 + (4/7*a - 6/7)*t^9 + (102/49*a^5 + 99/49*a^4 + 96/49*a^3 + 93/49*a^2 + 90/49*a + 150/49)*t^8 + (-160/49*a^5 - 36/49*a^4 - 48/49*a^3 - 8/7*a^2 - 60/49*a - 60/49)*t^7 + (30/49*a^5 - 55/49*a^4 + 20/49*a^3 + 5/49*a^2)*t^6 + (6/49*a^4 - 12/49*a^3 + 6/49*a^2)*t^5 - sage: pol.factor() + sage: pol = (1/7*a^2 - 1/7*a)*t^10 + (4/7*a - 6/7)*t^9 + (102/49*a^5 + 99/49*a^4 + 96/49*a^3 + 93/49*a^2 + 90/49*a + 150/49)*t^8 + (-160/49*a^5 - 36/49*a^4 - 48/49*a^3 - 8/7*a^2 - 60/49*a - 60/49)*t^7 + (30/49*a^5 - 55/49*a^4 + 20/49*a^3 + 5/49*a^2)*t^6 + (6/49*a^4 - 12/49*a^3 + 6/49*a^2)*t^5 # optional - sage.rings.number_field + sage: pol.factor() # optional - sage.rings.number_field (1/7*a^2 - 1/7*a) * t^5 * (t^5 + (-40/7*a^5 - 38/7*a^4 - 36/7*a^3 - 34/7*a^2 - 32/7*a - 30/7)*t^4 + (60/7*a^5 - 30/7*a^4 - 18/7*a^3 - 9/7*a^2 - 3/7*a)*t^3 + (60/7*a^4 - 40/7*a^3 - 16/7*a^2 - 4/7*a)*t^2 + (30/7*a^3 - 25/7*a^2 - 5/7*a)*t + 6/7*a^2 - 6/7*a) - sage: pol = x^10 + (4/7*a - 6/7)*x^9 + (9/49*a^2 - 3/7*a + 15/49)*x^8 + (8/343*a^3 - 32/343*a^2 + 40/343*a - 20/343)*x^7 + (5/2401*a^4 - 20/2401*a^3 + 40/2401*a^2 - 5/343*a + 15/2401)*x^6 + (-6/16807*a^4 + 12/16807*a^3 - 18/16807*a^2 + 12/16807*a - 6/16807)*x^5 - sage: pol.factor() + sage: pol = x^10 + (4/7*a - 6/7)*x^9 + (9/49*a^2 - 3/7*a + 15/49)*x^8 + (8/343*a^3 - 32/343*a^2 + 40/343*a - 20/343)*x^7 + (5/2401*a^4 - 20/2401*a^3 + 40/2401*a^2 - 5/343*a + 15/2401)*x^6 + (-6/16807*a^4 + 12/16807*a^3 - 18/16807*a^2 + 12/16807*a - 6/16807)*x^5 # optional - sage.rings.number_field + sage: pol.factor() # optional - sage.rings.number_field x^5 * (x^5 + (4/7*a - 6/7)*x^4 + (9/49*a^2 - 3/7*a + 15/49)*x^3 + (8/343*a^3 - 32/343*a^2 + 40/343*a - 20/343)*x^2 + (5/2401*a^4 - 20/2401*a^3 + 40/2401*a^2 - 5/343*a + 15/2401)*x - 6/16807*a^4 + 12/16807*a^3 - 18/16807*a^2 + 12/16807*a - 6/16807) Factoring over a number field over which we cannot factor the discriminant by trial division:: sage: x = polygen(QQ) - sage: K. = NumberField(x^16 - x - 6) - sage: R. = PolynomialRing(K) - sage: f = (x+a)^50 - (a-1)^50 - sage: len(factor(f)) + sage: K. = NumberField(x^16 - x - 6) # optional - sage.rings.number_field + sage: R. = PolynomialRing(K) # optional - sage.rings.number_field + sage: f = (x+a)^50 - (a-1)^50 # optional - sage.rings.number_field + sage: len(factor(f)) # optional - sage.rings.number_field 6 - sage: pari(K.discriminant()).factor(limit=10^6) + sage: pari(K.discriminant()).factor(limit=10^6) # optional - sage.rings.number_field [-1, 1; 3, 15; 23, 1; 887, 1; 12583, 1; 2354691439917211, 1] - sage: factor(K.discriminant()) + sage: factor(K.discriminant()) # optional - sage.rings.number_field -1 * 3^15 * 23 * 887 * 12583 * 6335047 * 371692813 Factoring over a number field over which we cannot factor the discriminant and over which `nffactor()` fails:: sage: p = next_prime(10^50); q = next_prime(10^51); n = p*q - sage: K. = QuadraticField(p*q) - sage: R. = PolynomialRing(K) - sage: K.pari_polynomial('a').nffactor("x^2+1") + sage: K. = QuadraticField(p*q) # optional - sage.rings.number_field + sage: R. = PolynomialRing(K) # optional - sage.rings.number_field + sage: K.pari_polynomial('a').nffactor("x^2+1") # optional - sage.rings.number_field Mat([x^2 + 1, 1]) - sage: factor(x^2 + 1) + sage: factor(x^2 + 1) # optional - sage.rings.number_field x^2 + 1 - sage: factor( (x - a) * (x + 2*a) ) + sage: factor((x - a) * (x + 2*a)) # optional - sage.rings.number_field (x - a) * (x + 2*a) A test where nffactor used to fail without a nf structure:: sage: x = polygen(QQ) - sage: K = NumberField([x^2-1099511627777, x^3-3],'a') - sage: x = polygen(K) - sage: f = x^3 - 3 - sage: factor(f) + sage: K = NumberField([x^2-1099511627777, x^3-3], 'a') # optional - sage.rings.number_field + sage: x = polygen(K) # optional - sage.rings.number_field + sage: f = x^3 - 3 # optional - sage.rings.number_field + sage: factor(f) # optional - sage.rings.number_field (x - a1) * (x^2 + a1*x + a1^2) We check that :trac:`7554` is fixed:: @@ -4373,7 +4410,7 @@ cdef class Polynomial(CommutativePolynomial): sage: P. = PolynomialRing(ZZ) sage: R. = PolynomialRing(FractionField(P)) - sage: p = (x - a)*(b*x + c)*(a*b*x + a*c) / (a + 2) + sage: p = (x - a) * (b*x + c) * (a*b*x + a*c) / (a + 2) sage: factor(p) (a/(a + 2)) * (x - a) * (b*x + c)^2 @@ -4538,31 +4575,33 @@ cdef class Polynomial(CommutativePolynomial): sage: R.=PolynomialRing(ZZ) sage: f = (2*x + 1) * (3*x^2 - 5)^2 - sage: f._factor_pari_helper(pari(f).factor()) + sage: f._factor_pari_helper(pari(f).factor()) # optional - sage.libs.pari (2*x + 1) * (3*x^2 - 5)^2 - sage: f._factor_pari_helper(pari(f).factor(), unit=11) + sage: f._factor_pari_helper(pari(f).factor(), unit=11) # optional - sage.libs.pari 11 * (2*x + 1) * (3*x^2 - 5)^2 - sage: (8*f)._factor_pari_helper(pari(f).factor()) + sage: (8*f)._factor_pari_helper(pari(f).factor()) # optional - sage.libs.pari 8 * (2*x + 1) * (3*x^2 - 5)^2 - sage: (8*f)._factor_pari_helper(pari(f).factor(), unit=11) + sage: (8*f)._factor_pari_helper(pari(f).factor(), unit=11) # optional - sage.libs.pari 88 * (2*x + 1) * (3*x^2 - 5)^2 - sage: QQ['x'](f)._factor_pari_helper(pari(f).factor()) + sage: QQ['x'](f)._factor_pari_helper(pari(f).factor()) # optional - sage.libs.pari (18) * (x + 1/2) * (x^2 - 5/3)^2 - sage: QQ['x'](f)._factor_pari_helper(pari(f).factor(), unit=11) + sage: QQ['x'](f)._factor_pari_helper(pari(f).factor(), unit=11) # optional - sage.libs.pari (198) * (x + 1/2) * (x^2 - 5/3)^2 - sage: f = prod((k^2*x^k + k)^(k-1) for k in primes(10)) - sage: F = f._factor_pari_helper(pari(f).factor()); F + sage: f = prod((k^2*x^k + k)^(k-1) for k in primes(10)) # optional - sage.libs.pari + sage: F = f._factor_pari_helper(pari(f).factor()); F # optional - sage.libs.pari 1323551250 * (2*x^2 + 1) * (3*x^3 + 1)^2 * (5*x^5 + 1)^4 * (7*x^7 + 1)^6 - sage: F.prod() == f + sage: F.prod() == f # optional - sage.libs.pari True - sage: QQ['x'](f)._factor_pari_helper(pari(f).factor()) + sage: QQ['x'](f)._factor_pari_helper(pari(f).factor()) # optional - sage.libs.pari (1751787911376562500) * (x^2 + 1/2) * (x^3 + 1/3)^2 * (x^5 + 1/5)^4 * (x^7 + 1/7)^6 - sage: g = GF(19)['x'](f) - sage: G = g._factor_pari_helper(pari(g).factor()); G - (4) * (x + 3) * (x + 16)^5 * (x + 11)^6 * (x^2 + 7*x + 9)^4 * (x^2 + 15*x + 9)^4 * (x^3 + 13)^2 * (x^6 + 8*x^5 + 7*x^4 + 18*x^3 + 11*x^2 + 12*x + 1)^6 - sage: G.prod() == g + sage: g = GF(19)['x'](f) # optional - sage.libs.pari + sage: G = g._factor_pari_helper(pari(g).factor()); G # optional - sage.libs.pari + (4) * (x + 3) * (x + 16)^5 * (x + 11)^6 * (x^2 + 7*x + 9)^4 + * (x^2 + 15*x + 9)^4 * (x^3 + 13)^2 + * (x^6 + 8*x^5 + 7*x^4 + 18*x^3 + 11*x^2 + 12*x + 1)^6 + sage: G.prod() == g # optional - sage.libs.pari True """ pols, exps = G @@ -4623,25 +4662,26 @@ cdef class Polynomial(CommutativePolynomial): EXAMPLES:: sage: R. = PolynomialRing(ZZ) - sage: K. = (x^3 + 2).splitting_field(); K - Number Field in a with defining polynomial x^6 + 3*x^5 + 6*x^4 + 11*x^3 + 12*x^2 - 3*x + 1 - sage: K. = (x^3 - 3*x + 1).splitting_field(); K + sage: K. = (x^3 + 2).splitting_field(); K # optional - sage.rings.number_field + Number Field in a with defining polynomial + x^6 + 3*x^5 + 6*x^4 + 11*x^3 + 12*x^2 - 3*x + 1 + sage: K. = (x^3 - 3*x + 1).splitting_field(); K # optional - sage.rings.number_field Number Field in a with defining polynomial x^3 - 3*x + 1 Relative situation:: sage: R. = PolynomialRing(QQ) - sage: K. = NumberField(x^3 + 2) - sage: S. = PolynomialRing(K) - sage: L. = (t^2 - a).splitting_field() - sage: L + sage: K. = NumberField(x^3 + 2) # optional - sage.rings.number_field + sage: S. = PolynomialRing(K) # optional - sage.rings.number_field + sage: L. = (t^2 - a).splitting_field() # optional - sage.rings.number_field + sage: L # optional - sage.rings.number_field Number Field in b with defining polynomial t^6 + 2 With ``map=True``, we also get the embedding of the base field into the splitting field:: - sage: L., phi = (t^2 - a).splitting_field(map=True) - sage: phi + sage: L., phi = (t^2 - a).splitting_field(map=True) # optional - sage.rings.number_field + sage: phi # optional - sage.rings.number_field Ring morphism: From: Number Field in a with defining polynomial x^3 + 2 To: Number Field in b with defining polynomial t^6 + 2 @@ -4649,14 +4689,14 @@ cdef class Polynomial(CommutativePolynomial): An example over a finite field:: - sage: P. = PolynomialRing(GF(7)) - sage: t = x^2 + 1 - sage: t.splitting_field('b') + sage: P. = PolynomialRing(GF(7)) # optional - sage.rings.finite_rings + sage: t = x^2 + 1 # optional - sage.rings.finite_rings + sage: t.splitting_field('b') # optional - sage.rings.finite_rings Finite Field in b of size 7^2 - sage: P. = PolynomialRing(GF(7^3, 'a')) - sage: t = x^2 + 1 - sage: t.splitting_field('b', map=True) + sage: P. = PolynomialRing(GF(7^3, 'a')) # optional - sage.rings.finite_rings + sage: t = x^2 + 1 # optional - sage.rings.finite_rings + sage: t.splitting_field('b', map=True) # optional - sage.rings.finite_rings (Finite Field in b of size 7^6, Ring morphism: From: Finite Field in a of size 7^3 @@ -4666,13 +4706,13 @@ cdef class Polynomial(CommutativePolynomial): If the extension is trivial and the generators have the same name, the map will be the identity:: - sage: t = 24*x^13 + 2*x^12 + 14 - sage: t.splitting_field('a', map=True) + sage: t = 24*x^13 + 2*x^12 + 14 # optional - sage.rings.finite_rings + sage: t.splitting_field('a', map=True) # optional - sage.rings.finite_rings (Finite Field in a of size 7^3, Identity endomorphism of Finite Field in a of size 7^3) - sage: t = x^56 - 14*x^3 - sage: t.splitting_field('b', map=True) + sage: t = x^56 - 14*x^3 # optional - sage.rings.finite_rings + sage: t.splitting_field('b', map=True) # optional - sage.rings.finite_rings (Finite Field in b of size 7^3, Ring morphism: From: Finite Field in a of size 7^3 @@ -4694,48 +4734,48 @@ cdef class Polynomial(CommutativePolynomial): ... NotImplementedError: splitting_field() is only implemented over number fields and finite fields - sage: P. = PolynomialRing(GF(11^5, 'a')) - sage: t = x^2 + 1 - sage: t.splitting_field('b') + sage: P. = PolynomialRing(GF(11^5, 'a')) # optional - sage.rings.finite_rings + sage: t = x^2 + 1 # optional - sage.rings.finite_rings + sage: t.splitting_field('b') # optional - sage.rings.finite_rings Finite Field in b of size 11^10 - sage: t = 24*x^13 + 2*x^12 + 14 - sage: t.splitting_field('b') + sage: t = 24*x^13 + 2*x^12 + 14 # optional - sage.rings.finite_rings + sage: t.splitting_field('b') # optional - sage.rings.finite_rings Finite Field in b of size 11^30 - sage: t = x^56 - 14*x^3 - sage: t.splitting_field('b') + sage: t = x^56 - 14*x^3 # optional - sage.rings.finite_rings + sage: t.splitting_field('b') # optional - sage.rings.finite_rings Finite Field in b of size 11^130 - sage: P. = PolynomialRing(GF(19^6, 'a')) - sage: t = -x^6 + x^2 + 1 - sage: t.splitting_field('b') + sage: P. = PolynomialRing(GF(19^6, 'a')) # optional - sage.rings.finite_rings + sage: t = -x^6 + x^2 + 1 # optional - sage.rings.finite_rings + sage: t.splitting_field('b') # optional - sage.rings.finite_rings Finite Field in b of size 19^6 - sage: t = 24*x^13 + 2*x^12 + 14 - sage: t.splitting_field('b') + sage: t = 24*x^13 + 2*x^12 + 14 # optional - sage.rings.finite_rings + sage: t.splitting_field('b') # optional - sage.rings.finite_rings Finite Field in b of size 19^18 - sage: t = x^56 - 14*x^3 - sage: t.splitting_field('b') + sage: t = x^56 - 14*x^3 # optional - sage.rings.finite_rings + sage: t.splitting_field('b') # optional - sage.rings.finite_rings Finite Field in b of size 19^156 - sage: P. = PolynomialRing(GF(83^6, 'a')) - sage: t = 2*x^14 - 5 + 6*x - sage: t.splitting_field('b') + sage: P. = PolynomialRing(GF(83^6, 'a')) # optional - sage.rings.finite_rings + sage: t = 2*x^14 - 5 + 6*x # optional - sage.rings.finite_rings + sage: t.splitting_field('b') # optional - sage.rings.finite_rings Finite Field in b of size 83^84 - sage: t = 24*x^13 + 2*x^12 + 14 - sage: t.splitting_field('b') + sage: t = 24*x^13 + 2*x^12 + 14 # optional - sage.rings.finite_rings + sage: t.splitting_field('b') # optional - sage.rings.finite_rings Finite Field in b of size 83^78 - sage: t = x^56 - 14*x^3 - sage: t.splitting_field('b') + sage: t = x^56 - 14*x^3 # optional - sage.rings.finite_rings + sage: t.splitting_field('b') # optional - sage.rings.finite_rings Finite Field in b of size 83^12 - sage: P. = PolynomialRing(GF(401^13, 'a')) - sage: t = 2*x^14 - 5 + 6*x - sage: t.splitting_field('b') + sage: P. = PolynomialRing(GF(401^13, 'a')) # optional - sage.rings.finite_rings + sage: t = 2*x^14 - 5 + 6*x # optional - sage.rings.finite_rings + sage: t.splitting_field('b') # optional - sage.rings.finite_rings Finite Field in b of size 401^104 - sage: t = 24*x^13 + 2*x^12 + 14 - sage: t.splitting_field('b') + sage: t = 24*x^13 + 2*x^12 + 14 # optional - sage.rings.finite_rings + sage: t.splitting_field('b') # optional - sage.rings.finite_rings Finite Field in b of size 401^156 - sage: t = x^56 - 14*x^3 - sage: t.splitting_field('b') + sage: t = x^56 - 14*x^3 # optional - sage.rings.finite_rings + sage: t.splitting_field('b') # optional - sage.rings.finite_rings Finite Field in b of size 401^52 sage: R. = QQ[] @@ -4792,7 +4832,7 @@ cdef class Polynomial(CommutativePolynomial): sage: R. = PolynomialRing(ZZ, sparse=True) sage: p = x^4 + 6*x^3 + x^2 - x + 2 sage: q = 2*x^2 - 3*x - 1 - sage: (quo,rem)=p.pseudo_quo_rem(q); quo,rem + sage: quo, rem = p.pseudo_quo_rem(q); quo, rem (4*x^2 + 30*x + 51, 175*x + 67) sage: 2^(4-2+1)*p == quo*q + rem True @@ -4800,9 +4840,10 @@ cdef class Polynomial(CommutativePolynomial): sage: S. = R[] sage: p = (-3*x^2 - x)*T^3 - 3*x*T^2 + (x^2 - x)*T + 2*x^2 + 3*x - 2 sage: q = (-x^2 - 4*x - 5)*T^2 + (6*x^2 + x + 1)*T + 2*x^2 - x - sage: quo,rem=p.pseudo_quo_rem(q); quo,rem + sage: quo, rem = p.pseudo_quo_rem(q); quo, rem ((3*x^4 + 13*x^3 + 19*x^2 + 5*x)*T + 18*x^4 + 12*x^3 + 16*x^2 + 16*x, - (-113*x^6 - 106*x^5 - 133*x^4 - 101*x^3 - 42*x^2 - 41*x)*T - 34*x^6 + 13*x^5 + 54*x^4 + 126*x^3 + 134*x^2 - 5*x - 50) + (-113*x^6 - 106*x^5 - 133*x^4 - 101*x^3 - 42*x^2 - 41*x)*T + - 34*x^6 + 13*x^5 + 54*x^4 + 126*x^3 + 134*x^2 - 5*x - 50) sage: (-x^2 - 4*x - 5)^(3-2+1) * p == quo*q + rem True """ @@ -4848,7 +4889,7 @@ cdef class Polynomial(CommutativePolynomial): The actual algorithm for computing greatest common divisors depends on the base ring underlying the polynomial ring. If the base ring - defines a method ``_gcd_univariate_polynomial``, then this method + defines a method :meth:`_gcd_univariate_polynomial`, then this method will be called (see examples below). EXAMPLES:: @@ -4864,20 +4905,22 @@ cdef class Polynomial(CommutativePolynomial): One can easily add gcd functionality to new rings by providing a method ``_gcd_univariate_polynomial``:: - sage: O = ZZ[-sqrt(5)] - sage: R. = O[] - sage: a = O.1 - sage: p = x + a - sage: q = x^2 - 5 - sage: p.gcd(q) + sage: O = ZZ[-sqrt(5)] # optional - sage.rings.number_field sage.symbolic + sage: R. = O[] # optional - sage.rings.number_field sage.symbolic + sage: a = O.1 # optional - sage.rings.number_field sage.symbolic + sage: p = x + a # optional - sage.rings.number_field sage.symbolic + sage: q = x^2 - 5 # optional - sage.rings.number_field sage.symbolic + sage: p.gcd(q) # optional - sage.rings.number_field sage.symbolic Traceback (most recent call last): ... - NotImplementedError: Order in Number Field in a with defining polynomial x^2 - 5 with a = -2.236067977499790? does not provide a gcd implementation for univariate polynomials - sage: S. = O.number_field()[] - sage: O._gcd_univariate_polynomial = lambda f,g : R(S(f).gcd(S(g))) - sage: p.gcd(q) + NotImplementedError: Order in Number Field in a + with defining polynomial x^2 - 5 with a = -2.236067977499790? + does not provide a gcd implementation for univariate polynomials + sage: S. = O.number_field()[] # optional - sage.rings.number_field sage.symbolic + sage: O._gcd_univariate_polynomial = lambda f, g: R(S(f).gcd(S(g))) # optional - sage.rings.number_field sage.symbolic + sage: p.gcd(q) # optional - sage.rings.number_field sage.symbolic x + a - sage: del O._gcd_univariate_polynomial + sage: del O._gcd_univariate_polynomial # optional - sage.rings.number_field sage.symbolic Use multivariate implementation for polynomials over polynomials rings:: @@ -4887,7 +4930,7 @@ cdef class Polynomial(CommutativePolynomial): sage: r = 2*x*y + z sage: p = r * (3*x*y*z - 1) sage: q = r * (x + y + z - 2) - sage: p.gcd(q) + sage: p.gcd(q) # optional - sage.libs.singular z + 2*x*y sage: R. = QQ[] @@ -4895,13 +4938,13 @@ cdef class Polynomial(CommutativePolynomial): sage: r = 2*x*y + 1 sage: p = r * (x - 1/2 * y) sage: q = r * (x*y^2 - x + 1/3) - sage: p.gcd(q) + sage: p.gcd(q) # optional - sage.libs.singular 2*x*y + 1 TESTS:: sage: Pol = QQ['x','y']['x'] - sage: Pol.one().gcd(1) + sage: Pol.one().gcd(1) # optional - sage.libs.singular 1 """ cdef Polynomial _other = other @@ -4924,15 +4967,15 @@ cdef class Polynomial(CommutativePolynomial): @coerce_binop def lcm(self, other): """ - Let f and g be two polynomials. Then this function returns the - monic least common multiple of f and g. + Let `f` and `g` be two polynomials. Then this function returns the + monic least common multiple of `f` and `g`. TESTS: Check that :trac:`32033` has been fixed:: - sage: R. = GF(3)[] - sage: lcm(R(0), R(0)) + sage: R. = GF(3)[] # optional - sage.rings.finite_rings + sage: lcm(R(0), R(0)) # optional - sage.rings.finite_rings 0 :: @@ -4951,8 +4994,8 @@ cdef class Polynomial(CommutativePolynomial): def _lcm(self, other): """ - Let f and g be two polynomials. Then this function returns the - monic least common multiple of f and g. + Let `f` and `g` be two polynomials. Then this function returns the + monic least common multiple of `f` and `g`. """ if self.is_zero() or other.is_zero(): P = self.parent() @@ -4975,7 +5018,7 @@ cdef class Polynomial(CommutativePolynomial): - (ring theory) A polynomial over a ring is primitive if its coefficients generate the unit ideal. - Calling `is_primitive` on a polynomial over an infinite field will + Calling :meth:`is_primitive` on a polynomial over an infinite field will raise an error. The additional inputs to this function are to speed up computation for @@ -4983,116 +5026,116 @@ cdef class Polynomial(CommutativePolynomial): INPUT: - - ``n`` (default: ``None``) - if provided, should equal - `q-1` where ``self.parent()`` is the field with `q` - elements; otherwise it will be computed. + - ``n`` (default: ``None``) - if provided, should equal + `q-1` where ``self.parent()`` is the field with `q` + elements; otherwise it will be computed. - - ``n_prime_divs`` (default: ``None``) - if provided, should - be a list of the prime divisors of ``n``; otherwise it - will be computed. + - ``n_prime_divs`` (default: ``None``) - if provided, should + be a list of the prime divisors of `n`; otherwise it + will be computed. .. NOTE:: - Computation of the prime divisors of ``n`` can dominate the running + Computation of the prime divisors of `n` can dominate the running time of this method, so performing this computation externally - (e.g. ``pdivs=n.prime_divisors()``) is a good idea for repeated calls - to is_primitive for polynomials of the same degree. + (e.g., ``pdivs = n.prime_divisors()``) is a good idea for repeated calls + to :meth:`is_primitive` for polynomials of the same degree. - Results may be incorrect if the wrong ``n`` and/or factorization are + Results may be incorrect if the wrong `n` and/or factorization are provided. - EXAMPLES:: + EXAMPLES: - Field semantics examples. + Field semantics examples. - :: + :: - sage: R. = GF(2)['x'] - sage: f = x^4+x^3+x^2+x+1 - sage: f.is_irreducible(), f.is_primitive() + sage: R. = GF(2)['x'] # optional - sage.rings.finite_rings + sage: f = x^4 + x^3 + x^2 + x + 1 # optional - sage.rings.finite_rings + sage: f.is_irreducible(), f.is_primitive() # optional - sage.rings.finite_rings (True, False) - sage: f = x^3+x+1 - sage: f.is_irreducible(), f.is_primitive() + sage: f = x^3 + x + 1 # optional - sage.rings.finite_rings + sage: f.is_irreducible(), f.is_primitive() # optional - sage.rings.finite_rings (True, True) - sage: R. = GF(3)[] - sage: f = x^3-x+1 - sage: f.is_irreducible(), f.is_primitive() + sage: R. = GF(3)[] # optional - sage.rings.finite_rings + sage: f = x^3 - x + 1 # optional - sage.rings.finite_rings + sage: f.is_irreducible(), f.is_primitive() # optional - sage.rings.finite_rings (True, True) - sage: f = x^2+1 - sage: f.is_irreducible(), f.is_primitive() + sage: f = x^2 + 1 # optional - sage.rings.finite_rings + sage: f.is_irreducible(), f.is_primitive() # optional - sage.rings.finite_rings (True, False) - sage: R. = GF(5)[] - sage: f = x^2+x+1 - sage: f.is_primitive() + sage: R. = GF(5)[] # optional - sage.rings.finite_rings + sage: f = x^2 + x + 1 # optional - sage.rings.finite_rings + sage: f.is_primitive() # optional - sage.rings.finite_rings False - sage: f = x^2-x+2 - sage: f.is_primitive() + sage: f = x^2 - x + 2 # optional - sage.rings.finite_rings + sage: f.is_primitive() # optional - sage.rings.finite_rings True - sage: x=polygen(QQ); f=x^2+1 + sage: x = polygen(QQ); f = x^2 + 1 sage: f.is_primitive() Traceback (most recent call last): ... NotImplementedError: is_primitive() not defined for polynomials over infinite fields. - Ring semantics examples. + Ring semantics examples. - :: + :: sage: x=polygen(ZZ) - sage: f = 5*x^2+2 + sage: f = 5*x^2 + 2 sage: f.is_primitive() True - sage: f = 5*x^2+5 + sage: f = 5*x^2 + 5 sage: f.is_primitive() False - sage: K=NumberField(x^2+5,'a') - sage: R=K.ring_of_integers() - sage: a=R.gen(1) - sage: a^2 + sage: K = NumberField(x^2 + 5, 'a') # optional - sage.rings.number_field + sage: R = K.ring_of_integers() # optional - sage.rings.number_field + sage: a = R.gen(1) # optional - sage.rings.number_field + sage: a^2 # optional - sage.rings.number_field -5 - sage: f=a*x+2 - sage: f.is_primitive() + sage: f = a*x + 2 # optional - sage.rings.number_field + sage: f.is_primitive() # optional - sage.rings.number_field True - sage: f=(1+a)*x+2 - sage: f.is_primitive() + sage: f = (1+a)*x + 2 # optional - sage.rings.number_field + sage: f.is_primitive() # optional - sage.rings.number_field False sage: x = polygen(Integers(10)) - sage: f = 5*x^2+2 + sage: f = 5*x^2 + 2 sage: #f.is_primitive() #BUG:: elsewhere in Sage, should return True - sage: f=4*x^2+2 + sage: f = 4*x^2 + 2 sage: #f.is_primitive() #BUG:: elsewhere in Sage, should return False TESTS:: - sage: R. = GF(2)['x'] - sage: f = x^4+x^3+x^2+x+1 - sage: f.is_primitive(15) + sage: R. = GF(2)['x'] # optional - sage.rings.finite_rings + sage: f = x^4 + x^3 + x^2 + x + 1 # optional - sage.rings.finite_rings + sage: f.is_primitive(15) # optional - sage.rings.finite_rings False - sage: f.is_primitive(15, [3,5]) + sage: f.is_primitive(15, [3,5]) # optional - sage.rings.finite_rings False - sage: f.is_primitive(n_prime_divs=[3,5]) + sage: f.is_primitive(n_prime_divs=[3,5]) # optional - sage.rings.finite_rings False - sage: f = x^3+x+1 - sage: f.is_primitive(7, [7]) + sage: f = x^3 + x + 1 # optional - sage.rings.finite_rings + sage: f.is_primitive(7, [7]) # optional - sage.rings.finite_rings True - sage: R. = GF(3)[] - sage: f = x^3-x+1 - sage: f.is_primitive(26, [2,13]) + sage: R. = GF(3)[] # optional - sage.rings.finite_rings + sage: f = x^3 - x + 1 # optional - sage.rings.finite_rings + sage: f.is_primitive(26, [2,13]) # optional - sage.rings.finite_rings True - sage: f = x^2+1 - sage: f.is_primitive(8, [2]) + sage: f = x^2 + 1 # optional - sage.rings.finite_rings + sage: f.is_primitive(8, [2]) # optional - sage.rings.finite_rings False - sage: R. = GF(5)[] - sage: f = x^2+x+1 - sage: f.is_primitive(24, [2,3]) + sage: R. = GF(5)[] # optional - sage.rings.finite_rings + sage: f = x^2 + x + 1 # optional - sage.rings.finite_rings + sage: f.is_primitive(24, [2,3]) # optional - sage.rings.finite_rings False - sage: f = x^2-x+2 - sage: f.is_primitive(24, [2,3]) + sage: f = x^2 - x + 2 # optional - sage.rings.finite_rings + sage: f.is_primitive(24, [2,3]) # optional - sage.rings.finite_rings True - sage: x=polygen(Integers(103)); f=x^2+1 - sage: f.is_primitive() + sage: x = polygen(Integers(103)); f = x^2 + 1 + sage: f.is_primitive() # optional - sage.rings.finite_rings False """ R = self.base_ring() @@ -5116,12 +5159,12 @@ cdef class Polynomial(CommutativePolynomial): def is_constant(self): """ - Return True if this is a constant polynomial. + Return ``True`` if this is a constant polynomial. OUTPUT: - - ``bool`` - True if and only if this polynomial is + - ``bool`` - ``True`` if and only if this polynomial is constant @@ -5139,14 +5182,14 @@ cdef class Polynomial(CommutativePolynomial): def is_monomial(self): """ - Return True if self is a monomial, i.e., a power of the generator. + Return ``True`` if ``self`` is a monomial, i.e., a power of the generator. EXAMPLES:: sage: R. = QQ[] sage: x.is_monomial() True - sage: (x+1).is_monomial() + sage: (x + 1).is_monomial() False sage: (x^2).is_monomial() True @@ -5158,15 +5201,15 @@ cdef class Polynomial(CommutativePolynomial): sage: (2*x^5).is_monomial() False - To allow a non-1 leading coefficient, use is_term():: + To allow a non-1 leading coefficient, use :meth:`is_term`:: sage: (2*x^5).is_term() True .. warning:: - The definition of is_monomial in Sage up to 4.7.1 was the - same as is_term, i.e., it allowed a coefficient not equal + The definition of :meth:`is_monomial` in Sage up to 4.7.1 was the + same as :meth:`is_term`, i.e., it allowed a coefficient not equal to 1. """ return len(self.exponents()) == 1 and self.leading_coefficient() == 1 @@ -5187,10 +5230,10 @@ cdef class Polynomial(CommutativePolynomial): True sage: (3*x^5).is_term() True - sage: (1+3*x^5).is_term() + sage: (1 + 3*x^5).is_term() False - To require that the coefficient is 1, use :meth:`is_monomial()` + To require that the coefficient is 1, use :meth:`is_monomial` instead:: sage: (3*x^5).is_monomial() @@ -5201,7 +5244,7 @@ cdef class Polynomial(CommutativePolynomial): def root_field(self, names, check_irreducible=True): """ Return the field generated by the roots of the irreducible - polynomial self. The output is either a number field, relative + polynomial ``self``. The output is either a number field, relative number field, a quotient of a polynomial ring over a field, or the fraction field of the base ring. @@ -5209,55 +5252,56 @@ cdef class Polynomial(CommutativePolynomial): sage: R. = QQ['x'] sage: f = x^3 + x + 17 - sage: f.root_field('a') + sage: f.root_field('a') # optional - sage.rings.number_field Number Field in a with defining polynomial x^3 + x + 17 :: sage: R. = QQ['x'] sage: f = x - 3 - sage: f.root_field('b') + sage: f.root_field('b') # optional - sage.rings.number_field Rational Field :: sage: R. = ZZ['x'] sage: f = x^3 + x + 17 - sage: f.root_field('b') + sage: f.root_field('b') # optional - sage.rings.number_field Number Field in b with defining polynomial x^3 + x + 17 :: sage: y = QQ['x'].0 - sage: L. = NumberField(y^3-2) - sage: R. = L['x'] - sage: f = x^3 + x + 17 - sage: f.root_field('c') + sage: L. = NumberField(y^3 - 2) # optional - sage.rings.number_field + sage: R. = L['x'] # optional - sage.rings.number_field + sage: f = x^3 + x + 17 # optional - sage.rings.number_field + sage: f.root_field('c') # optional - sage.rings.number_field Number Field in c with defining polynomial x^3 + x + 17 over its base field :: - sage: R. = PolynomialRing(GF(9,'a')) - sage: f = x^3 + x^2 + 8 - sage: K. = f.root_field(); K - Univariate Quotient Polynomial Ring in alpha over Finite Field in a of size 3^2 with modulus x^3 + x^2 + 2 - sage: alpha^2 + 1 + sage: R. = PolynomialRing(GF(9, 'a')) # optional - sage.rings.finite_rings + sage: f = x^3 + x^2 + 8 # optional - sage.rings.finite_rings + sage: K. = f.root_field(); K # optional - sage.rings.finite_rings + Univariate Quotient Polynomial Ring in alpha + over Finite Field in a of size 3^2 with modulus x^3 + x^2 + 2 + sage: alpha^2 + 1 # optional - sage.rings.finite_rings alpha^2 + 1 - sage: alpha^3 + alpha^2 + sage: alpha^3 + alpha^2 # optional - sage.rings.finite_rings 1 :: sage: R. = QQ[] sage: f = x^2 - sage: K. = f.root_field() + sage: K. = f.root_field() # optional - sage.libs.pari Traceback (most recent call last): ... ValueError: polynomial must be irreducible TESTS:: - sage: (PolynomialRing(Integers(31),name='x').0+5).root_field('a') + sage: (PolynomialRing(Integers(31), name='x').0 + 5).root_field('a') # optional - sage.rings.finite_rings Ring of integers modulo 31 """ R = self.base_ring() @@ -5284,24 +5328,23 @@ cdef class Polynomial(CommutativePolynomial): def sylvester_matrix(self, right, variable = None): """ - Return the Sylvester matrix of self and right. + Return the Sylvester matrix of ``self`` and ``right``. Note that the Sylvester matrix is not defined if one of the polynomials is zero. INPUT: - - right: a polynomial in the same ring as self. - - variable: optional, included for compatibility with the multivariate + - ``right`` -- a polynomial in the same ring as ``self``. + - ``variable`` -- optional, included for compatibility with the multivariate case only. The variable of the polynomials. EXAMPLES:: sage: R. = PolynomialRing(ZZ) - sage: f = (6*x + 47)*(7*x^2 - 2*x + 38) - sage: g = (6*x + 47)*(3*x^3 + 2*x + 1) - sage: M = f.sylvester_matrix(g) - sage: M + sage: f = (6*x + 47) * (7*x^2 - 2*x + 38) + sage: g = (6*x + 47) * (3*x^3 + 2*x + 1) + sage: M = f.sylvester_matrix(g); M # optional - sage.modules [ 42 317 134 1786 0 0 0] [ 0 42 317 134 1786 0 0] [ 0 0 42 317 134 1786 0] @@ -5313,24 +5356,24 @@ cdef class Polynomial(CommutativePolynomial): If the polynomials share a non-constant common factor then the determinant of the Sylvester matrix will be zero:: - sage: M.determinant() + sage: M.determinant() # optional - sage.modules 0 - If self and right are polynomials of positive degree, the determinant + If ``self`` and ``right`` are polynomials of positive degree, the determinant of the Sylvester matrix is the resultant of the polynomials.:: sage: h1 = R._random_nonzero_element() sage: h2 = R._random_nonzero_element() - sage: M1 = h1.sylvester_matrix(h2) - sage: M1.determinant() == h1.resultant(h2) + sage: M1 = h1.sylvester_matrix(h2) # optional - sage.modules + sage: M1.determinant() == h1.resultant(h2) # optional - sage.libs.pari sage.modules True The rank of the Sylvester matrix is related to the degree of the - gcd of self and right:: + gcd of ``self`` and ``right``:: - sage: f.gcd(g).degree() == f.degree() + g.degree() - M.rank() + sage: f.gcd(g).degree() == f.degree() + g.degree() - M.rank() # optional - sage.modules True - sage: h1.gcd(h2).degree() == h1.degree() + h2.degree() - M1.rank() + sage: h1.gcd(h2).degree() == h1.degree() + h2.degree() - M1.rank() # optional - sage.modules True TESTS: @@ -5338,65 +5381,69 @@ cdef class Polynomial(CommutativePolynomial): The variable is optional, but must be the same in both rings:: sage: K. = QQ['x'] - sage: f = x+1 + sage: f = x + 1 sage: g = QQ['y']([1, 0, 1]) - sage: f.sylvester_matrix(f, x) + sage: f.sylvester_matrix(f, x) # optional - sage.modules [1 1] [1 1] - sage: f.sylvester_matrix(g, x) + sage: f.sylvester_matrix(g, x) # optional - sage.modules Traceback (most recent call last): ... - TypeError: no common canonical parent for objects with parents: 'Univariate Polynomial Ring in x over Rational Field' and 'Univariate Polynomial Ring in y over Rational Field' + TypeError: no common canonical parent for objects with parents: + 'Univariate Polynomial Ring in x over Rational Field' and + 'Univariate Polynomial Ring in y over Rational Field' Polynomials must be defined over compatible base rings:: sage: f = QQ['x']([1, 0, 1]) sage: g = ZZ['x']([1, 0, 1]) - sage: h = GF(25, 'a')['x']([1, 0, 1]) - sage: f.sylvester_matrix(g) + sage: h = GF(25, 'a')['x']([1, 0, 1]) # optional - sage.rings.finite_rings + sage: f.sylvester_matrix(g) # optional - sage.modules [1 0 1 0] [0 1 0 1] [1 0 1 0] [0 1 0 1] - sage: g.sylvester_matrix(h) + sage: g.sylvester_matrix(h) # optional - sage.rings.finite_rings sage.modules [1 0 1 0] [0 1 0 1] [1 0 1 0] [0 1 0 1] - sage: f.sylvester_matrix(h) + sage: f.sylvester_matrix(h) # optional - sage.rings.finite_rings sage.modules Traceback (most recent call last): ... - TypeError: no common canonical parent for objects with parents: 'Univariate Polynomial Ring in x over Rational Field' and 'Univariate Polynomial Ring in x over Finite Field in a of size 5^2' + TypeError: no common canonical parent for objects with parents: + 'Univariate Polynomial Ring in x over Rational Field' and + 'Univariate Polynomial Ring in x over Finite Field in a of size 5^2' We can compute the sylvester matrix of a univariate and multivariate polynomial:: sage: K. = QQ['x,y'] sage: g = K.random_element() - sage: f.sylvester_matrix(g) == K(f).sylvester_matrix(g,x) + sage: f.sylvester_matrix(g) == K(f).sylvester_matrix(g, x) # optional - sage.modules True Corner cases:: - sage: K.=QQ[] - sage: f = x^2+1 + sage: K. = QQ[] + sage: f = x^2 + 1 sage: g = K(0) - sage: f.sylvester_matrix(g) + sage: f.sylvester_matrix(g) # optional - sage.modules Traceback (most recent call last): ... ValueError: The Sylvester matrix is not defined for zero polynomials - sage: g.sylvester_matrix(f) + sage: g.sylvester_matrix(f) # optional - sage.modules Traceback (most recent call last): ... ValueError: The Sylvester matrix is not defined for zero polynomials - sage: g.sylvester_matrix(g) + sage: g.sylvester_matrix(g) # optional - sage.modules Traceback (most recent call last): ... ValueError: The Sylvester matrix is not defined for zero polynomials - sage: K(3).sylvester_matrix(x^2) + sage: K(3).sylvester_matrix(x^2) # optional - sage.modules [3 0] [0 3] - sage: K(3).sylvester_matrix(K(4)) + sage: K(3).sylvester_matrix(K(4)) # optional - sage.modules [] """ @@ -5468,10 +5515,10 @@ cdef class Polynomial(CommutativePolynomial): EXAMPLES:: - sage: R. = PolynomialRing(GF(9,'a'), sparse=True) - sage: a = w._new_constant_poly(0, R); a + sage: R. = PolynomialRing(GF(9, 'a'), sparse=True) # optional - sage.rings.finite_rings + sage: a = w._new_constant_poly(0, R); a # optional - sage.rings.finite_rings 0 - sage: a.coefficients() + sage: a.coefficients() # optional - sage.rings.finite_rings [] """ t = type(self) @@ -5479,7 +5526,7 @@ cdef class Polynomial(CommutativePolynomial): def is_monic(self): """ - Returns True if this polynomial is monic. The zero polynomial is by + Returns ``True`` if this polynomial is monic. The zero polynomial is by definition not monic. EXAMPLES:: @@ -5506,7 +5553,7 @@ cdef class Polynomial(CommutativePolynomial): def is_unit(self): r""" - Return True if this polynomial is a unit. + Return ``True`` if this polynomial is a unit. EXAMPLES:: @@ -5514,12 +5561,12 @@ cdef class Polynomial(CommutativePolynomial): sage: b = a(2*191*236607587) sage: b.is_nilpotent() True - sage: R. = a[] - sage: f = 3 + b*x + b^2*x^2 - sage: f.is_unit() + sage: R. = a[] # optional - sage.libs.pari + sage: f = 3 + b*x + b^2*x^2 # optional - sage.libs.pari + sage: f.is_unit() # optional - sage.libs.pari True - sage: f = 3 + b*x + b^2*x^2 + 17*x^3 - sage: f.is_unit() + sage: f = 3 + b*x + b^2*x^2 + 17*x^3 # optional - sage.libs.pari + sage: f.is_unit() # optional - sage.libs.pari False EXERCISE (Atiyah-McDonald, Ch 1): Let `A[x]` be a @@ -5553,7 +5600,7 @@ cdef class Polynomial(CommutativePolynomial): def is_nilpotent(self): r""" - Return True if this polynomial is nilpotent. + Return ``True`` if this polynomial is nilpotent. EXAMPLES:: @@ -5588,7 +5635,7 @@ cdef class Polynomial(CommutativePolynomial): def is_gen(self): r""" - Return True if this polynomial is the distinguished generator of + Return ``True`` if this polynomial is the distinguished generator of the parent polynomial ring. EXAMPLES:: @@ -5599,8 +5646,8 @@ cdef class Polynomial(CommutativePolynomial): sage: R(x).is_gen() True - Important - this function doesn't return True if self equals the - generator; it returns True if self *is* the generator. + Important - this function doesn't return ``True`` if ``self`` equals the + generator; it returns ``True`` if ``self`` *is* the generator. :: @@ -5620,7 +5667,8 @@ cdef class Polynomial(CommutativePolynomial): Return the leading coefficient of this polynomial. OUTPUT: element of the base ring - This method is same as :meth:`leading_coefficient`. + + This method is the same as :meth:`leading_coefficient`. EXAMPLES:: @@ -5749,7 +5797,7 @@ cdef class Polynomial(CommutativePolynomial): EXAMPLES:: sage: _. = PolynomialRing(ZZ) - sage: f = x^4+2*x^2+1 + sage: f = x^4 + 2*x^2 + 1 sage: f.coefficients() [1, 2, 1] sage: f.coefficients(sparse=False) @@ -5771,11 +5819,9 @@ cdef class Polynomial(CommutativePolynomial): INPUT: - ``prec`` -- desired floating point precision (default: - default RealField precision). - - OUTPUT: + default :class:`RealField` precision). - - a real number. + OUTPUT: a real number. EXAMPLES:: @@ -5796,18 +5842,18 @@ cdef class Polynomial(CommutativePolynomial): :: - sage: R. = PolynomialRing(QQbar) - sage: f = QQbar(i)*x^2 + 3*x - sage: f.global_height() + sage: R. = PolynomialRing(QQbar) # optional - sage.rings.number_field + sage: f = QQbar(i)*x^2 + 3*x # optional - sage.rings.number_field + sage: f.global_height() # optional - sage.rings.number_field 1.09861228866811 :: sage: R. = PolynomialRing(QQ) - sage: K. = NumberField(x^2 + 5) - sage: T. = PolynomialRing(K) - sage: f = 1/1331 * t^2 + 5 * t + 7 - sage: f.global_height() + sage: K. = NumberField(x^2 + 5) # optional - sage.rings.number_field + sage: T. = PolynomialRing(K) # optional - sage.rings.number_field + sage: f = 1/1331 * t^2 + 5 * t + 7 # optional - sage.rings.number_field + sage: f.global_height() # optional - sage.rings.number_field 9.13959596745043 :: @@ -5857,11 +5903,9 @@ cdef class Polynomial(CommutativePolynomial): - ``v`` -- a prime or prime ideal of the base ring. - ``prec`` -- desired floating point precision (default: - default RealField precision). - - OUTPUT: + default :class:`RealField` precision). - - a real number. + OUTPUT: a real number. EXAMPLES:: @@ -5873,11 +5917,11 @@ cdef class Polynomial(CommutativePolynomial): :: sage: R. = QQ[] - sage: K. = NumberField(x^2 - 5) - sage: T. = K[] - sage: I = K.ideal(3) - sage: f = 1/3*t^2 + 3 - sage: f.local_height(I) + sage: K. = NumberField(x^2 - 5) # optional - sage.rings.number_field + sage: T. = K[] # optional - sage.rings.number_field + sage: I = K.ideal(3) # optional - sage.rings.number_field + sage: f = 1/3*t^2 + 3 # optional - sage.rings.number_field + sage: f.local_height(I) # optional - sage.rings.number_field 1.09861228866811 :: @@ -5909,11 +5953,9 @@ cdef class Polynomial(CommutativePolynomial): - ``i`` -- an integer. - ``prec`` -- desired floating point precision (default: - default RealField precision). + default :class:`RealField` precision). - OUTPUT: - - - a real number. + OUTPUT: a real number. EXAMPLES:: @@ -5925,10 +5967,10 @@ cdef class Polynomial(CommutativePolynomial): :: sage: R. = QQ[] - sage: K. = NumberField(x^2 - 5) - sage: T. = K[] - sage: f = 1/2*t^2 + 3 - sage: f.local_height_arch(1, prec=52) + sage: K. = NumberField(x^2 - 5) # optional - sage.rings.number_field + sage: T. = K[] # optional - sage.rings.number_field + sage: f = 1/2*t^2 + 3 # optional - sage.rings.number_field + sage: f.local_height_arch(1, prec=52) # optional - sage.rings.number_field 1.09861228866811 :: @@ -5959,7 +6001,7 @@ cdef class Polynomial(CommutativePolynomial): EXAMPLES:: sage: _. = PolynomialRing(ZZ) - sage: f = x^4+2*x^2+1 + sage: f = x^4 + 2*x^2 + 1 sage: f.exponents() [0, 2, 4] @@ -5983,7 +6025,7 @@ cdef class Polynomial(CommutativePolynomial): sage: v = f.list(); v [-1/3, 2, 0, -2/5] - Note that v is a list, it is mutable, and each call to the list + Note that ``v`` is a list, it is mutable, and each call to the :meth:`list` method returns a new list:: sage: type(v) @@ -5996,7 +6038,7 @@ cdef class Polynomial(CommutativePolynomial): sage: R. = QQ[] sage: S. = R[] - sage: f = y^3 + x*y -3*x; f + sage: f = y^3 + x*y - 3*x; f y^3 + x*y - 3*x sage: type(f) @@ -6026,7 +6068,7 @@ cdef class Polynomial(CommutativePolynomial): def padded_list(self, n=None): """ - Return list of coefficients of self up to (but not including) + Return list of coefficients of ``self`` up to (but not including) `q^n`. Includes 0's in the list on the right so that the list has length @@ -6086,15 +6128,11 @@ cdef class Polynomial(CommutativePolynomial): - ``m`` - a monomial - OUTPUT: - - Coefficient in base ring. + OUTPUT: Coefficient in base ring. EXAMPLES:: sage: P. = QQ[] - - The parent of the return is a member of the base ring. sage: f = 2 * x sage: c = f.monomial_coefficient(x); c 2 @@ -6145,11 +6183,11 @@ cdef class Polynomial(CommutativePolynomial): sage: f = - 1/2*x^2 + x^9 + 7*x + 5/11 sage: f.monomials() [x^9, x^2, x, 1] - sage: x = var('x') - sage: K. = NumberField(x**2 + 1) - sage: R. = QQ[] - sage: p = rho*y - sage: p.monomials() + sage: x = polygen(ZZ, 'x') + sage: K. = NumberField(x**2 + 1) # optional - sage.rings.number_field + sage: R. = QQ[] # optional - sage.rings.number_field + sage: p = rho * y # optional - sage.rings.number_field + sage: p.monomials() # optional - sage.rings.number_field [y] """ if self.is_zero(): @@ -6165,22 +6203,22 @@ cdef class Polynomial(CommutativePolynomial): polynomial, computed using the Newton-Raphson method. The Newton-Raphson method is an iterative root-finding algorithm. - For f(x) a polynomial, as is the case here, this is essentially the + For `f(x)` a polynomial, as is the case here, this is essentially the same as Horner's method. INPUT: - - ``n`` - an integer (=the number of iterations), + - ``n`` - an integer (the number of iterations), - - ``x0`` - an initial guess x0. + - ``x0`` - an initial guess `x_0`. OUTPUT: A list of numbers hopefully approximating a root of - f(x)=0. + `f(x)=0`. - If one of the iterates is a critical point of f then a - ZeroDivisionError exception is raised. + If one of the iterates is a critical point of `f`, a + :class:`ZeroDivisionError` exception is raised. EXAMPLES:: @@ -6205,17 +6243,17 @@ cdef class Polynomial(CommutativePolynomial): def polynomial(self, var): r""" - Let var be one of the variables of the parent of self. This returns - self viewed as a univariate polynomial in var over the polynomial + Let ``var`` be one of the variables of the parent of ``self``. This returns + ``self`` viewed as a univariate polynomial in ``var`` over the polynomial ring generated by all the other variables of the parent. - For univariate polynomials, if var is the generator of the parent + For univariate polynomials, if ``var`` is the generator of the parent ring, we return this polynomial, otherwise raise an error. EXAMPLES:: sage: R. = QQ[] - sage: (x+1).polynomial(x) + sage: (x + 1).polynomial(x) x + 1 TESTS:: @@ -6233,31 +6271,31 @@ cdef class Polynomial(CommutativePolynomial): def newton_slopes(self, p, lengths=False): """ - Return the `p`-adic slopes of the Newton polygon of self, + Return the `p`-adic slopes of the Newton polygon of ``self``, when this makes sense. OUTPUT: - If `lengths` is `False`, a list of rational numbers. If `lengths` is - `True`, a list of couples `(s,l)` where `s` is the slope and `l` the + If ``lengths`` is ``False``, a list of rational numbers. If ``lengths`` is + ``True``, a list of couples `(s,l)` where `s` is the slope and `l` the length of the corresponding segment in the Newton polygon. EXAMPLES:: sage: x = QQ['x'].0 sage: f = x^3 + 2 - sage: f.newton_slopes(2) + sage: f.newton_slopes(2) # optional - sage.libs.pari [1/3, 1/3, 1/3] sage: R. = PolynomialRing(ZZ, sparse=True) sage: p = x^5 + 6*x^2 + 4 - sage: p.newton_slopes(2) + sage: p.newton_slopes(2) # optional - sage.libs.pari [1/2, 1/2, 1/3, 1/3, 1/3] sage: p.newton_slopes(2, lengths=True) [(1/2, 2), (1/3, 3)] sage: (x^2^100 + 27).newton_slopes(3, lengths=True) [(3/1267650600228229401496703205376, 1267650600228229401496703205376)] - ALGORITHM: Uses PARI if `lengths` is `False`. + ALGORITHM: Uses PARI if ``lengths`` is ``False``. """ if not lengths: f = self.__pari__() @@ -6307,13 +6345,13 @@ cdef class Polynomial(CommutativePolynomial): EXAMPLES:: sage: Pol. = QQ[] - sage: x.dispersion_set(x + 1) + sage: x.dispersion_set(x + 1) # optional - sage.libs.pari [1] - sage: (x + 1).dispersion_set(x) + sage: (x + 1).dispersion_set(x) # optional - sage.libs.pari [] sage: pol = x^3 + x - 7 - sage: (pol*pol(x+3)^2).dispersion_set() + sage: (pol*pol(x+3)^2).dispersion_set() # optional - sage.libs.pari [0, 3] """ other = self if other is None else self._parent.coerce(other) @@ -6354,16 +6392,16 @@ cdef class Polynomial(CommutativePolynomial): EXAMPLES:: sage: Pol. = QQ[] - sage: x.dispersion(x + 1) + sage: x.dispersion(x + 1) # optional - sage.libs.pari 1 - sage: (x + 1).dispersion(x) + sage: (x + 1).dispersion(x) # optional - sage.libs.pari -Infinity - sage: Pol. = QQbar[] - sage: pol = Pol([sqrt(5), 1, 3/2]) - sage: pol.dispersion() + sage: Pol. = QQbar[] # optional - sage.libs.pari sage.rings.number_field + sage: pol = Pol([sqrt(5), 1, 3/2]) # optional - sage.libs.pari sage.rings.number_field sage.symbolic + sage: pol.dispersion() # optional - sage.libs.pari sage.rings.number_field sage.symbolic 0 - sage: (pol*pol(x+3)).dispersion() + sage: (pol*pol(x+3)).dispersion() # optional - sage.libs.pari sage.rings.number_field sage.symbolic 3 """ dispersions = self.dispersion_set(other) @@ -6384,7 +6422,7 @@ cdef class Polynomial(CommutativePolynomial): EXAMPLES:: sage: f = QQ['x']([0,1,2/3,3]) - sage: pari(f) + sage: pari(f) # optional - sage.libs.pari 3*x^3 + 2/3*x^2 + x :: @@ -6392,19 +6430,20 @@ cdef class Polynomial(CommutativePolynomial): sage: S. = QQ['a'] sage: R. = S['x'] sage: f = R([0, a]) + R([0, 0, 2/3]) - sage: pari(f) + sage: pari(f) # optional - sage.libs.pari 2/3*x^2 + a*x Polynomials over a number field work, provided that the variable is called 'x':: sage: x = polygen(QQ) - sage: K. = NumberField(x^2 + x + 1) - sage: R. = PolynomialRing(K) - sage: pol = (b + x)^3; pol + sage: K. = NumberField(x^2 + x + 1) # optional - sage.rings.number_field + sage: R. = PolynomialRing(K) # optional - sage.rings.number_field + sage: pol = (b + x)^3; pol # optional - sage.rings.number_field x^3 + 3*b*x^2 + (-3*b - 3)*x + 1 - sage: pari(pol) - Mod(1, y^2 + y + 1)*x^3 + Mod(3*y, y^2 + y + 1)*x^2 + Mod(-3*y - 3, y^2 + y + 1)*x + Mod(1, y^2 + y + 1) + sage: pari(pol) # optional - sage.libs.pari sage.rings.number_field + Mod(1, y^2 + y + 1)*x^3 + Mod(3*y, y^2 + y + 1)*x^2 + + Mod(-3*y - 3, y^2 + y + 1)*x + Mod(1, y^2 + y + 1) TESTS: @@ -6413,7 +6452,7 @@ cdef class Polynomial(CommutativePolynomial): sage: R. = QQ[] sage: S. = R[] sage: f = x^2 + a; g = y^3 + a - sage: pari(f) + sage: pari(f) # optional - sage.libs.pari Traceback (most recent call last): ... PariError: incorrect priority in gtopoly: variable x <= a @@ -6423,9 +6462,9 @@ cdef class Polynomial(CommutativePolynomial): sage: S. = QQ['a'] sage: R. = S['x'] - sage: pari(x^2 + 2*x) + sage: pari(x^2 + 2*x) # optional - sage.libs.pari x^2 + 2*x - sage: pari(a*x + 2*x^3) + sage: pari(a*x + 2*x^3) # optional - sage.libs.pari 2*x^3 + a*x Stacked polynomial rings, second with a multivariate ring on the @@ -6433,27 +6472,27 @@ cdef class Polynomial(CommutativePolynomial): sage: S. = ZZ['a', 'b'] sage: R. = S['x'] - sage: pari(x^2 + 2*x) + sage: pari(x^2 + 2*x) # optional - sage.libs.pari x^2 + 2*x - sage: pari(a*x + 2*b*x^3) + sage: pari(a*x + 2*b*x^3) # optional - sage.libs.pari 2*b*x^3 + a*x Stacked polynomial rings with exotic base rings:: - sage: S. = GF(7)['a', 'b'] - sage: R. = S['x'] - sage: pari(x^2 + 9*x) + sage: S. = GF(7)['a', 'b'] # optional - sage.rings.finite_rings + sage: R. = S['x'] # optional - sage.rings.finite_rings + sage: pari(x^2 + 9*x) # optional - sage.rings.finite_rings x^2 + 2*x - sage: pari(a*x + 9*b*x^3) + sage: pari(a*x + 9*b*x^3) # optional - sage.rings.finite_rings 2*b*x^3 + a*x :: sage: S. = Integers(8)['a'] sage: R. = S['x'] - sage: pari(x^2 + 2*x) + sage: pari(x^2 + 2*x) # optional - sage.libs.pari Mod(1, 8)*x^2 + Mod(2, 8)*x - sage: pari(a*x + 10*x^3) + sage: pari(a*x + 10*x^3) # optional - sage.libs.pari Mod(2, 8)*x^3 + Mod(1, 8)*a*x """ return self._pari_with_name(self._parent.variable_name()) @@ -6474,18 +6513,18 @@ cdef class Polynomial(CommutativePolynomial): sage: R. = PolynomialRing(ZZ) sage: pol = 2*x^2 + 7*x - 5 - sage: pol._pari_or_constant() + sage: pol._pari_or_constant() # optional - sage.libs.pari 2*x^2 + 7*x - 5 - sage: pol._pari_or_constant('a') + sage: pol._pari_or_constant('a') # optional - sage.libs.pari 2*a^2 + 7*a - 5 sage: pol = R(7) - sage: pol._pari_or_constant() + sage: pol._pari_or_constant() # optional - sage.libs.pari 7 - sage: pol._pari_or_constant().type() + sage: pol._pari_or_constant().type() # optional - sage.libs.pari 't_INT' - sage: pol.__pari__().type() + sage: pol.__pari__().type() # optional - sage.libs.pari 't_POL' - sage: PolynomialRing(IntegerModRing(101), 't')()._pari_or_constant() + sage: PolynomialRing(IntegerModRing(101), 't')()._pari_or_constant() # optional - sage.libs.pari Mod(0, 101) """ if self.is_constant(): @@ -6504,9 +6543,9 @@ cdef class Polynomial(CommutativePolynomial): EXAMPLES:: sage: R. = PolynomialRing(ZZ) - sage: (2*a^2 + a)._pari_with_name() + sage: (2*a^2 + a)._pari_with_name() # optional - sage.libs.pari 2*x^2 + x - sage: (2*a^2 + a)._pari_with_name('y') + sage: (2*a^2 + a)._pari_with_name('y') # optional - sage.libs.pari 2*y^2 + y """ vals = [x.__pari__() for x in self.list()] @@ -6521,7 +6560,7 @@ cdef class Polynomial(CommutativePolynomial): EXAMPLES:: - sage: magma = Magma() # new session + sage: magma = Magma() # new session # optional - magma sage: R. = ZZ[] sage: f = y^3 - 17*y + 5 sage: f._magma_init_(magma) # optional - magma @@ -6547,8 +6586,8 @@ cdef class Polynomial(CommutativePolynomial): A more complicated nested example:: - sage: k. = GF(9); R. = k[]; S. = R[] - sage: magma(a*W^20 + s*t/a) # optional - magma + sage: k. = GF(9); R. = k[]; S. = R[] # optional - sage.rings.finite_rings + sage: magma(a*W^20 + s*t/a) # optional - magma # optional - sage.rings.finite_rings a*W^20 + a^7*s*t """ # Get a reference to Magma version of parent. @@ -6569,33 +6608,33 @@ cdef class Polynomial(CommutativePolynomial): sage: R. = ZZ[] sage: f = y^3 - 17*y + 5 - sage: g = gap(f); g # indirect doctest + sage: g = gap(f); g # indirect doctest # optional - sage.libs.gap y^3-17*y+5 - sage: f._gap_init_() + sage: f._gap_init_() # optional - sage.libs.gap 'y^3 - 17*y + 5' sage: R. = ZZ[] - sage: gap(R) + sage: gap(R) # optional - sage.libs.gap PolynomialRing( Integers, ["z"] ) - sage: g + sage: g # optional - sage.libs.gap y^3-17*y+5 - sage: gap(z^2 + z) + sage: gap(z^2 + z) # optional - sage.libs.gap z^2+z - sage: libgap(z^2 + z) + sage: libgap(z^2 + z) # optional - sage.libs.gap z^2+z Coefficients in a finite field:: - sage: R. = GF(7)[] - sage: f = y^3 - 17*y + 5 - sage: g = gap(f); g + sage: R. = GF(7)[] # optional - sage.rings.finite_rings + sage: f = y^3 - 17*y + 5 # optional - sage.rings.finite_rings + sage: g = gap(f); g # optional - sage.libs.gap sage.rings.finite_rings y^3+Z(7)^4*y+Z(7)^5 - sage: h = libgap(f); h + sage: h = libgap(f); h # optional - sage.libs.gap sage.rings.finite_rings y^3+Z(7)^4*y+Z(7)^5 - sage: g.Factors() + sage: g.Factors() # optional - sage.libs.gap sage.rings.finite_rings [ y+Z(7)^0, y+Z(7)^0, y+Z(7)^5 ] - sage: h.Factors() + sage: h.Factors() # optional - sage.libs.gap sage.rings.finite_rings [ y+Z(7)^0, y+Z(7)^0, y+Z(7)^5 ] - sage: f.factor() + sage: f.factor() # optional - sage.libs.gap sage.rings.finite_rings (y + 5) * (y + 1)^2 """ R = gap(self._parent) @@ -6607,9 +6646,9 @@ cdef class Polynomial(CommutativePolynomial): TESTS:: sage: R. = ZZ[] - sage: libgap(-x^3 + 3*x) # indirect doctest + sage: libgap(-x^3 + 3*x) # indirect doctest # optional - sage.libs.gap -x^3+3*x - sage: libgap(R.zero()) # indirect doctest + sage: libgap(R.zero()) # indirect doctest # optional - sage.libs.gap 0 """ from sage.libs.gap.libgap import libgap @@ -6621,13 +6660,13 @@ cdef class Polynomial(CommutativePolynomial): TESTS:: - sage: R. = GF(101)['e,i'][] - sage: f = R('e*i') * x + x^2 - sage: f._giac_init_() + sage: R. = GF(101)['e,i'][] # optional - sage.rings.finite_rings + sage: f = R('e*i') * x + x^2 # optional - sage.rings.finite_rings + sage: f._giac_init_() # optional - sage.rings.finite_rings '((1)*1)*sageVARx^2+((1)*sageVARe*sageVARi)*sageVARx' - sage: giac(f) + sage: giac(f) # optional - sage.rings.finite_rings sageVARx^2+sageVARe*sageVARi*sageVARx - sage: giac(R.zero()) + sage: giac(R.zero()) # optional - sage.rings.finite_rings 0 """ g = 'sageVAR' + self.variable_name() @@ -6650,7 +6689,7 @@ cdef class Polynomial(CommutativePolynomial): ALGORITHM: - Uses PARI's ``polresultant`` function. For base rings that + Uses PARI's function :pari:`polresultant`. For base rings that are not supported by PARI, the resultant is computed as the determinant of the Sylvester matrix. @@ -6658,9 +6697,9 @@ cdef class Polynomial(CommutativePolynomial): sage: R. = QQ[] sage: f = x^3 + x + 1; g = x^3 - x - 1 - sage: r = f.resultant(g); r + sage: r = f.resultant(g); r # optional - sage.libs.pari -8 - sage: r.parent() is QQ + sage: r.parent() is QQ # optional - sage.libs.pari True We can compute resultants over univariate and multivariate @@ -6669,9 +6708,9 @@ cdef class Polynomial(CommutativePolynomial): sage: R. = QQ[] sage: S. = R[] sage: f = x^2 + a; g = x^3 + a - sage: r = f.resultant(g); r + sage: r = f.resultant(g); r # optional - sage.libs.pari a^3 + a^2 - sage: r.parent() is R + sage: r.parent() is R # optional - sage.libs.pari True :: @@ -6679,9 +6718,9 @@ cdef class Polynomial(CommutativePolynomial): sage: R. = QQ[] sage: S. = R[] sage: f = x^2 + a; g = x^3 + b - sage: r = f.resultant(g); r + sage: r = f.resultant(g); r # optional - sage.libs.pari a^3 + b^2 - sage: r.parent() is R + sage: r.parent() is R # optional - sage.libs.pari True TESTS:: @@ -6689,18 +6728,18 @@ cdef class Polynomial(CommutativePolynomial): sage: R. = QQ[] sage: S. = R[] sage: f = x^2 + a; g = y^3 + a - sage: h = f.resultant(g); h + sage: h = f.resultant(g); h # optional - sage.libs.pari y^3 - x^2 - sage: h.parent() is R + sage: h.parent() is R # optional - sage.libs.pari True Check that :trac:`13672` is fixed:: - sage: R. = GF(2)[] - sage: S. = R[] - sage: f = (t^2 + t)*x + t^2 + t - sage: g = (t + 1)*x + t^2 - sage: f.resultant(g) + sage: R. = GF(2)[] # optional - sage.rings.finite_rings + sage: S. = R[] # optional - sage.rings.finite_rings + sage: f = (t^2 + t)*x + t^2 + t # optional - sage.rings.finite_rings + sage: g = (t + 1)*x + t^2 # optional - sage.rings.finite_rings + sage: f.resultant(g) # optional - sage.rings.finite_rings t^4 + t Check that :trac:`15061` is fixed:: @@ -6709,23 +6748,23 @@ cdef class Polynomial(CommutativePolynomial): sage: F = R([1,1],2) sage: RP. = PolynomialRing(R) sage: P = x^2 - F - sage: P.resultant(P.derivative()) + sage: P.resultant(P.derivative()) # optional - sage.libs.pari -4 - 4*T + O(T^2) Check that :trac:`16360` is fixed:: sage: K. = FunctionField(QQ) sage: R. = K[] - sage: y.resultant(y+x) + sage: y.resultant(y + x) # optional - sage.libs.pari x sage: K. = FunctionField(QQ) sage: R. = K[] - sage: L. = K.extension(b^2-a) - sage: R. = L[] - sage: f=x^2-a - sage: g=x-b - sage: f.resultant(g) + sage: L. = K.extension(b^2 - a) # optional - sage.libs.singular + sage: R. = L[] # optional - sage.libs.singular + sage: f = x^2 - a # optional - sage.libs.singular + sage: g = x - b # optional - sage.libs.singular + sage: f.resultant(g) # optional - sage.libs.pari sage.libs.singular 0 Check that :trac:`17817` is fixed:: @@ -6736,7 +6775,7 @@ cdef class Polynomial(CommutativePolynomial): sage: S. = PolynomialRing(R,'y') sage: p = ((1/b^2*d^2+1/a)*x*y^2+a*b/c*y+e+x^2) sage: q = -4*c^2*y^3+1 - sage: p.resultant(q) + sage: p.resultant(q) # optional - sage.libs.pari (16*c^4)*x^6 + (48*c^4)*e*x^4 + (1/(b^6)*d^6 + 3/(a*b^4)*d^4 + (-12*a^3*b*c + 3)/(a^2*b^2)*d^2 + (-12*a^3*b*c + 1)/(a^3))*x^3 + (48*c^4)*e^2*x^2 + ((-12*a*c)/b*d^2*e + (-12*b*c)*e)*x + (16*c^4)*e^3 + (4*a^3*b^3)/c @@ -6745,7 +6784,7 @@ cdef class Polynomial(CommutativePolynomial): sage: R. = PolynomialRing(CDF) sage: f = R(1 - I*x + (0.5)*x^2 + (1.7)*x^3) sage: g = f.derivative() - sage: f.resultant(g) + sage: f.resultant(g) # optional - sage.libs.pari 133.92599999999996 + 37.56999999999999*I """ variable = self.variable_name() @@ -6769,8 +6808,8 @@ cdef class Polynomial(CommutativePolynomial): EXAMPLES:: sage: R. = ZZ[] - sage: f = x^8 + x^6 -3*x^4 -3*x^3 +8*x^2 +2*x -5 - sage: g = 3*x^6 +5*x^4 -4*x^2 -9*x +21 + sage: f = x^8 + x^6 - 3*x^4 - 3*x^3 + 8*x^2 + 2*x - 5 + sage: g = 3*x^6 + 5*x^4 - 4*x^2 - 9*x + 21 sage: f.subresultants(g) [260708, 9326*x - 12300, @@ -6848,8 +6887,8 @@ cdef class Polynomial(CommutativePolynomial): where the roots `a` and `b` are to be considered in the algebraic closure of the fraction field of the coefficients and counted with multiplicities. If the polynomials are not monic this quantity is - multiplied by `\\alpha_1^{deg(p_2)} \\alpha_2^{deg(p_1)}` where - `\\alpha_1` and `\\alpha_2` are the leading coefficients of `p_1` and + multiplied by `\alpha_1^{\deg(p_2)} \alpha_2^{\deg(p_1)}` where + `\alpha_1` and `\alpha_2` are the leading coefficients of `p_1` and `p_2` respectively. INPUT: @@ -6860,7 +6899,7 @@ cdef class Polynomial(CommutativePolynomial): - ``op`` -- ``operator.OP`` where ``OP=add`` or ``sub`` or ``mul`` or ``truediv``. - - ``algorithm`` -- can be "resultant" or "BFSS"; + - ``algorithm`` -- can be ``"resultant"`` or ``"BFSS"``; by default the former is used when the polynomials have few nonzero coefficients and small degrees or if the base ring is not `\ZZ` or `\QQ`. Otherwise the latter is used. @@ -6872,7 +6911,7 @@ cdef class Polynomial(CommutativePolynomial): ALGORITHM: The computation is straightforward using resultants. Indeed for the - composed sum it would be `Res_y(p1(x-y), p2(y))`. However, the method + composed sum it would be `Res_y(p_1(x-y), p_2(y))`. However, the method from [BFSS2006]_ using series expansions is asymptotically much faster. Note that the algorithm ``BFSS`` with polynomials with coefficients in @@ -6895,48 +6934,45 @@ cdef class Polynomial(CommutativePolynomial): sage: x = polygen(ZZ) sage: p1 = x^2 - 1 sage: p2 = x^4 - 1 - sage: p1.composed_op(p2, operator.add) + sage: p1.composed_op(p2, operator.add) # optional - sage.libs.singular x^8 - 4*x^6 + 4*x^4 - 16*x^2 - sage: p1.composed_op(p2, operator.mul) + sage: p1.composed_op(p2, operator.mul) # optional - sage.libs.singular x^8 - 2*x^4 + 1 - sage: p1.composed_op(p2, operator.truediv) + sage: p1.composed_op(p2, operator.truediv) # optional - sage.libs.singular x^8 - 2*x^4 + 1 This function works over any field. However for base rings other than `\ZZ` and `\QQ` only the resultant algorithm is available:: - sage: x = polygen(QQbar) - sage: p1 = x**2 - AA(2).sqrt() - sage: p2 = x**3 - AA(3).sqrt() - sage: r1 = p1.roots(multiplicities=False) - sage: r2 = p2.roots(multiplicities=False) - sage: p = p1.composed_op(p2, operator.add) - sage: p - x^6 - 4.242640687119285?*x^4 - 3.464101615137755?*x^3 + 6*x^2 - 14.69693845669907?*x + 0.1715728752538099? - sage: all(p(x+y).is_zero() for x in r1 for y in r2) - True - - sage: x = polygen(GF(2)) - sage: p1 = x**2 + x - 1 - sage: p2 = x**3 + x - 1 - sage: p_add = p1.composed_op(p2, operator.add) - sage: p_add + sage: x = polygen(QQbar) # optional - sage.rings.number_field + sage: p1 = x**2 - AA(2).sqrt() # optional - sage.rings.number_field + sage: p2 = x**3 - AA(3).sqrt() # optional - sage.rings.number_field + sage: r1 = p1.roots(multiplicities=False) # optional - sage.rings.number_field + sage: r2 = p2.roots(multiplicities=False) # optional - sage.rings.number_field + sage: p = p1.composed_op(p2, operator.add); p # optional - sage.rings.number_field + x^6 - 4.242640687119285?*x^4 - 3.464101615137755?*x^3 + 6*x^2 + - 14.69693845669907?*x + 0.1715728752538099? + sage: all(p(x+y).is_zero() for x in r1 for y in r2) # optional - sage.rings.number_field + True + + sage: x = polygen(GF(2)) # optional - sage.rings.finite_rings + sage: p1 = x**2 + x - 1 # optional - sage.rings.finite_rings + sage: p2 = x**3 + x - 1 # optional - sage.rings.finite_rings + sage: p_add = p1.composed_op(p2, operator.add); p_add # optional - sage.rings.finite_rings x^6 + x^5 + x^3 + x^2 + 1 - sage: p_mul = p1.composed_op(p2, operator.mul) - sage: p_mul + sage: p_mul = p1.composed_op(p2, operator.mul); p_mul # optional - sage.rings.finite_rings x^6 + x^4 + x^2 + x + 1 - sage: p_div = p1.composed_op(p2, operator.truediv) - sage: p_div + sage: p_div = p1.composed_op(p2, operator.truediv); p_div # optional - sage.rings.finite_rings x^6 + x^5 + x^4 + x^2 + 1 - sage: K = GF(2**6, 'a') - sage: r1 = p1.roots(K, multiplicities=False) - sage: r2 = p2.roots(K, multiplicities=False) - sage: all(p_add(x1+x2).is_zero() for x1 in r1 for x2 in r2) + sage: K = GF(2**6, 'a') # optional - sage.rings.finite_rings + sage: r1 = p1.roots(K, multiplicities=False) # optional - sage.rings.finite_rings + sage: r2 = p2.roots(K, multiplicities=False) # optional - sage.rings.finite_rings + sage: all(p_add(x1+x2).is_zero() for x1 in r1 for x2 in r2) # optional - sage.rings.finite_rings True - sage: all(p_mul(x1*x2).is_zero() for x1 in r1 for x2 in r2) + sage: all(p_mul(x1*x2).is_zero() for x1 in r1 for x2 in r2) # optional - sage.rings.finite_rings True - sage: all(p_div(x1/x2).is_zero() for x1 in r1 for x2 in r2) + sage: all(p_div(x1/x2).is_zero() for x1 in r1 for x2 in r2) # optional - sage.rings.finite_rings True TESTS: @@ -6944,7 +6980,7 @@ cdef class Polynomial(CommutativePolynomial): :: sage: y = polygen(ZZ) - sage: for p1 in [2*y^3 - y + 3, -y^5 - 2, 4*y - 3]: + sage: for p1 in [2*y^3 - y + 3, -y^5 - 2, 4*y - 3]: # optional - sage.libs.singular ....: for p2 in [5*y^2 - 7, -3*y - 1]: ....: for monic in [True,False]: ....: for op in [operator.add, operator.sub, operator.mul, operator.truediv]: @@ -7085,28 +7121,28 @@ cdef class Polynomial(CommutativePolynomial): The polynomial of degree `d^k` where `d` is the degree, whose roots are all `k`-fold products of roots of this polynomial. That is, `f*f*\dots*f` where this is `f` and - `f*f=` f.composed_op(f,operator.mul). + `f*f=` ``f.composed_op(f, operator.mul)``. EXAMPLES:: sage: R. = ZZ[] sage: x = polygen(R) - sage: f = (x-a)*(x-b)*(x-c) - sage: f.compose_power(2).factor() + sage: f = (x - a) * (x - b) * (x - c) + sage: f.compose_power(2).factor() # optional - sage.libs.singular sage.modules (x - c^2) * (x - b^2) * (x - a^2) * (x - b*c)^2 * (x - a*c)^2 * (x - a*b)^2 sage: x = polygen(QQ) - sage: f = x^2-2*x+2 + sage: f = x^2 - 2*x + 2 sage: f2 = f.compose_power(2); f2 x^4 - 4*x^3 + 8*x^2 - 16*x + 16 - sage: f2 == f.composed_op(f,operator.mul) + sage: f2 == f.composed_op(f, operator.mul) # optional - sage.libs.singular sage.modules True - sage: f3 = f.compose_power(3); f3 + sage: f3 = f.compose_power(3); f3 # optional - sage.libs.singular sage.modules x^8 - 8*x^7 + 32*x^6 - 64*x^5 + 128*x^4 - 512*x^3 + 2048*x^2 - 4096*x + 4096 - sage: f3 == f2.composed_op(f,operator.mul) + sage: f3 == f2.composed_op(f, operator.mul) # optional - sage.libs.singular sage.modules True - sage: f4 = f.compose_power(4) - sage: f4 == f3.composed_op(f,operator.mul) + sage: f4 = f.compose_power(4) # optional - sage.libs.singular sage.modules + sage: f4 == f3.composed_op(f, operator.mul) # optional - sage.libs.singular sage.modules True """ try: @@ -7146,33 +7182,33 @@ cdef class Polynomial(CommutativePolynomial): EXAMPLES:: - sage: f = cyclotomic_polynomial(30) - sage: f.adams_operator(7)==f + sage: f = cyclotomic_polynomial(30) # optional - sage.libs.pari + sage: f.adams_operator(7)==f # optional - sage.libs.pari True - sage: f.adams_operator(6) == cyclotomic_polynomial(5)**2 + sage: f.adams_operator(6) == cyclotomic_polynomial(5)**2 # optional - sage.libs.pari True - sage: f.adams_operator(10) == cyclotomic_polynomial(3)**4 + sage: f.adams_operator(10) == cyclotomic_polynomial(3)**4 # optional - sage.libs.pari True - sage: f.adams_operator(15) == cyclotomic_polynomial(2)**8 + sage: f.adams_operator(15) == cyclotomic_polynomial(2)**8 # optional - sage.libs.pari True - sage: f.adams_operator(30) == cyclotomic_polynomial(1)**8 + sage: f.adams_operator(30) == cyclotomic_polynomial(1)**8 # optional - sage.libs.pari True sage: x = polygen(QQ) - sage: f = x^2-2*x+2 - sage: f.adams_operator(10) + sage: f = x^2 - 2*x + 2 + sage: f.adams_operator(10) # optional - sage.libs.singular x^2 + 1024 - When f is monic the output will have leading coefficient + When ``self`` is monic, the output will have leading coefficient `\pm1` depending on the degree, but we can force it to be monic:: sage: R. = ZZ[] sage: x = polygen(R) - sage: f = (x-a)*(x-b)*(x-c) - sage: f.adams_operator(3).factor() + sage: f = (x - a) * (x - b) * (x - c) + sage: f.adams_operator(3).factor() # optional - sage.libs.singular (-1) * (x - c^3) * (x - b^3) * (x - a^3) - sage: f.adams_operator(3,monic=True).factor() + sage: f.adams_operator(3, monic=True).factor() # optional - sage.libs.singular (x - c^3) * (x - b^3) * (x - a^3) """ @@ -7191,12 +7227,12 @@ cdef class Polynomial(CommutativePolynomial): EXAMPLES:: sage: x = polygen(QQ) - sage: f = x^4-x+2 - sage: [f.symmetric_power(k) for k in range(5)] + sage: f = x^4 - x + 2 + sage: [f.symmetric_power(k) for k in range(5)] # optional - sage.libs.singular [x - 1, x^4 - x + 2, x^6 - 2*x^4 - x^3 - 4*x^2 + 8, x^4 - x^3 + 8, x - 2] - sage: f = x^5-2*x+2 - sage: [f.symmetric_power(k) for k in range(6)] + sage: f = x^5 - 2*x + 2 + sage: [f.symmetric_power(k) for k in range(6)] # optional - sage.libs.singular [x - 1, x^5 - 2*x + 2, x^10 + 2*x^8 - 4*x^6 - 8*x^5 - 8*x^4 - 8*x^3 + 16, @@ -7206,8 +7242,8 @@ cdef class Polynomial(CommutativePolynomial): sage: R. = ZZ[] sage: x = polygen(R) - sage: f = (x-a)*(x-b)*(x-c)*(x-d) - sage: [f.symmetric_power(k).factor() for k in range(5)] + sage: f = (x - a) * (x - b) * (x - c) * (x - d) + sage: [f.symmetric_power(k).factor() for k in range(5)] # optional - sage.libs.singular [x - 1, (-x + d) * (-x + c) * (-x + b) * (-x + a), (x - c*d) * (x - b*d) * (x - a*d) * (x - b*c) * (x - a*c) * (x - a*b), @@ -7282,8 +7318,8 @@ cdef class Polynomial(CommutativePolynomial): R_n := a_n^{2 n-2} \prod_{1 = QQ[] sage: f = x^3 + x + 1 - sage: d = f.discriminant(); d + sage: d = f.discriminant(); d # optional - sage.libs.pari -31 - sage: d.parent() is QQ + sage: d.parent() is QQ # optional - sage.libs.pari True - sage: EllipticCurve([1, 1]).discriminant()/16 + sage: EllipticCurve([1, 1]).discriminant()/16 # optional - sage.libs.pari -31 :: sage: R. = QQ[] sage: f = 2*x^3 + x + 1 - sage: d = f.discriminant(); d + sage: d = f.discriminant(); d # optional - sage.libs.pari -116 We can compute discriminants over univariate and multivariate @@ -7322,9 +7358,9 @@ cdef class Polynomial(CommutativePolynomial): sage: R. = QQ[] sage: S. = R[] sage: f = a*x + x + a + 1 - sage: d = f.discriminant(); d + sage: d = f.discriminant(); d # optional - sage.libs.pari 1 - sage: d.parent() is R + sage: d.parent() is R # optional - sage.libs.pari True :: @@ -7332,9 +7368,9 @@ cdef class Polynomial(CommutativePolynomial): sage: R. = QQ[] sage: S. = R[] sage: f = x^2 + a + b - sage: d = f.discriminant(); d + sage: d = f.discriminant(); d # optional - sage.libs.pari -4*a - 4*b - sage: d.parent() is R + sage: d.parent() is R # optional - sage.libs.pari True TESTS:: @@ -7342,41 +7378,41 @@ cdef class Polynomial(CommutativePolynomial): sage: R. = QQ[] sage: S. = R[] sage: f = x^2 + a - sage: f.discriminant() + sage: f.discriminant() # optional - sage.libs.pari 1 Check that :trac:`13672` is fixed:: - sage: R. = GF(5)[] - sage: S. = R[] - sage: f = x^10 + 2*x^6 + 2*x^5 + x + 2 - sage: (f-t).discriminant() + sage: R. = GF(5)[] # optional - sage.rings.finite_rings + sage: S. = R[] # optional - sage.rings.finite_rings + sage: f = x^10 + 2*x^6 + 2*x^5 + x + 2 # optional - sage.rings.finite_rings + sage: (f - t).discriminant() # optional - sage.rings.finite_rings 4*t^5 The following examples show that :trac:`11782` has been fixed:: - sage: var('x') + sage: var('x') # optional - sage.symbolic x - sage: ZZ.quo(81)['x'](3*x^2 + 3*x + 3).discriminant() + sage: ZZ.quo(81)['x'](3*x^2 + 3*x + 3).discriminant() # optional - sage.libs.pari sage.symbolic 54 - sage: ZZ.quo(9)['x'](2*x^3 + x^2 + x).discriminant() + sage: ZZ.quo(9)['x'](2*x^3 + x^2 + x).discriminant() # optional - sage.libs.pari sage.symbolic 2 This was fixed by :trac:`15422`:: - sage: R. = PolynomialRing(Qp(2)) - sage: (s^2).discriminant() + sage: R. = PolynomialRing(Qp(2)) # optional - sage.rings.padics + sage: (s^2).discriminant() # optional - sage.rings.padics 0 This was fixed by :trac:`16014`:: sage: PR. = QQ[] sage: PRmu. = PR[] - sage: E1 = diagonal_matrix(PR, [1, b^2, -b^2]) - sage: M = matrix(PR, [[1,-t1,x1-t1*y1],[t1,1,y1+t1*x1],[0,0,1]]) - sage: E1 = M.transpose()*E1*M - sage: E2 = E1.subs(t1=t2, x1=x2, y1=y2) - sage: det(mu*E1 + E2).discriminant().degrees() + sage: E1 = diagonal_matrix(PR, [1, b^2, -b^2]) # optional - sage.modules + sage: M = matrix(PR, [[1,-t1,x1-t1*y1], [t1,1,y1+t1*x1], [0,0,1]]) # optional - sage.modules + sage: E1 = M.transpose()*E1*M # optional - sage.modules + sage: E2 = E1.subs(t1=t2, x1=x2, y1=y2) # optional - sage.modules + sage: det(mu*E1 + E2).discriminant().degrees() # optional - sage.modules sage.libs.pari (24, 12, 12, 8, 8, 8, 8) This addresses an issue raised by :trac:`15061`:: @@ -7385,7 +7421,7 @@ cdef class Polynomial(CommutativePolynomial): sage: F = R([1,1],2) sage: RP. = PolynomialRing(R) sage: P = x^2 - F - sage: P.discriminant() + sage: P.discriminant() # optional - sage.libs.pari 4 + 4*T + O(T^2) """ # Late import to avoid cyclic dependencies: @@ -7424,7 +7460,7 @@ cdef class Polynomial(CommutativePolynomial): """ Return polynomial but with the coefficients reversed. - If an optional degree argument is given the coefficient list will be + If an optional ``degree`` argument is given, the coefficient list will be truncated or zero padded as necessary before reversing it. Assuming that the constant coefficient of ``self`` is nonzero, the reverse polynomial will have the specified degree. @@ -7432,7 +7468,7 @@ cdef class Polynomial(CommutativePolynomial): EXAMPLES:: sage: R. = ZZ[]; S. = R[] - sage: f = y^3 + x*y -3*x; f + sage: f = y^3 + x*y - 3*x; f y^3 + x*y - 3*x sage: f.reverse() -3*x*y^3 + x*y^2 + 1 @@ -7483,9 +7519,9 @@ cdef class Polynomial(CommutativePolynomial): - ``ring`` - the ring to find roots in - - ``multiplicities`` - bool (default: True) if True - return list of pairs (r, n), where r is the root and n is the - multiplicity. If False, just return the unique roots, with no + - ``multiplicities`` - bool (default: ``True``) if ``True`` + return list of pairs `(r, n)`, where `r` is the root and `n` is the + multiplicity. If ``False``, just return the unique roots, with no information about multiplicities. - ``algorithm`` - the root-finding algorithm to use. @@ -7514,7 +7550,7 @@ cdef class Polynomial(CommutativePolynomial): always ill-conditioned; there's a footnote at the end of the docstring about this. - If the output ring is a RealIntervalField or ComplexIntervalField + If the output ring is a :class:`RealIntervalField` or :class:`ComplexIntervalField` of a given precision, then the answer will always be correct (or an exception will be raised, if a case is not implemented). Each root will be contained in one of the returned intervals, and the @@ -7523,53 +7559,56 @@ cdef class Polynomial(CommutativePolynomial): At the end of this docstring (after the examples) is a description of all the cases implemented in this function, and the algorithms - used. That section also describes the possibilities for - "algorithm=", for the cases where multiple algorithms exist. + used. That section also describes the possibilities for the + ``algorithm`` keyword, for the cases where multiple algorithms exist. EXAMPLES:: sage: x = QQ['x'].0 sage: f = x^3 - 1 - sage: f.roots() + sage: f.roots() # optional - sage.libs.pari [(1, 1)] - sage: f.roots(ring=CC) # note -- low order bits slightly different on ppc. - [(1.00000000000000, 1), (-0.500000000000000 - 0.86602540378443...*I, 1), (-0.500000000000000 + 0.86602540378443...*I, 1)] + sage: f.roots(ring=CC) # ... - low order bits slightly different on ppc # optional - sage.libs.pari + [(1.00000000000000, 1), + (-0.500000000000000 - 0.86602540378443...*I, 1), + (-0.500000000000000 + 0.86602540378443...*I, 1)] sage: f = (x^3 - 1)^2 - sage: f.roots() + sage: f.roots() # optional - sage.libs.pari [(1, 2)] :: sage: f = -19*x + 884736 - sage: f.roots() + sage: f.roots() # optional - sage.libs.pari [(884736/19, 1)] - sage: (f^20).roots() + sage: (f^20).roots() # optional - sage.libs.pari [(884736/19, 20)] :: - sage: K. = CyclotomicField(3) - sage: f = K.defining_polynomial() - sage: f.roots(ring=GF(7)) + sage: K. = CyclotomicField(3) # optional - sage.rings.number_field + sage: f = K.defining_polynomial() # optional - sage.rings.number_field + sage: f.roots(ring=GF(7)) # optional - sage.rings.finite_rings sage.rings.number_field [(4, 1), (2, 1)] - sage: g = f.change_ring(GF(7)) - sage: g.roots() + sage: g = f.change_ring(GF(7)) # optional - sage.rings.finite_rings sage.rings.number_field + sage: g.roots() # optional - sage.rings.finite_rings sage.rings.number_field [(4, 1), (2, 1)] - sage: g.roots(multiplicities=False) + sage: g.roots(multiplicities=False) # optional - sage.rings.finite_rings sage.rings.number_field [4, 2] A new ring. In the example below, we add the special method - _roots_univariate_polynomial to the base ring, and observe + :meth:`_roots_univariate_polynomial` to the base ring, and observe that this method is called instead to find roots of polynomials over this ring. This facility can be used to easily extend root finding to work over new rings you introduce:: sage: R. = QQ[] - sage: (x^2 + 1).roots() + sage: (x^2 + 1).roots() # optional - sage.libs.pari [] - sage: g = lambda f, *args, **kwds: f.change_ring(CDF).roots() - sage: QQ._roots_univariate_polynomial = g + sage: def my_roots(f, *args, **kwds): + ....: return f.change_ring(CDF).roots() + sage: QQ._roots_univariate_polynomial = my_roots sage: (x^2 + 1).roots() # abs tol 1e-14 [(2.7755575615628914e-17 - 1.0*I, 1), (0.9999999999999997*I, 1)] sage: del QQ._roots_univariate_polynomial @@ -7578,30 +7617,34 @@ cdef class Polynomial(CommutativePolynomial): returned:: sage: x = RR['x'].0 - sage: f = x^3 -2 + sage: f = x^3 - 2 sage: f.roots() [(1.25992104989487, 1)] sage: f.factor() (x - 1.25992104989487) * (x^2 + 1.25992104989487*x + 1.58740105196820) sage: x = RealField(100)['x'].0 - sage: f = x^3 -2 + sage: f = x^3 - 2 sage: f.roots() [(1.2599210498948731647672106073, 1)] :: sage: x = CC['x'].0 - sage: f = x^3 -2 + sage: f = x^3 - 2 sage: f.roots() - [(1.25992104989487, 1), (-0.62996052494743... - 1.09112363597172*I, 1), (-0.62996052494743... + 1.09112363597172*I, 1)] - sage: f.roots(algorithm='pari') - [(1.25992104989487, 1), (-0.629960524947437 - 1.09112363597172*I, 1), (-0.629960524947437 + 1.09112363597172*I, 1)] + [(1.25992104989487, 1), + (-0.62996052494743... - 1.09112363597172*I, 1), + (-0.62996052494743... + 1.09112363597172*I, 1)] + sage: f.roots(algorithm='pari') # optional - sage.libs.pari + [(1.25992104989487, 1), + (-0.629960524947437 - 1.09112363597172*I, 1), + (-0.629960524947437 + 1.09112363597172*I, 1)] Another example showing that only roots in the base ring are returned:: sage: x = polygen(ZZ) - sage: f = (2*x-3) * (x-1) * (x+1) + sage: f = (2*x - 3) * (x - 1) * (x + 1) sage: f.roots() [(1, 1), (-1, 1)] sage: f.roots(ring=QQ) @@ -7611,7 +7654,7 @@ cdef class Polynomial(CommutativePolynomial): base ring:: sage: Pols. = QQ[] - sage: pol = (n - 1/2)^2*(n - 1)^2*(n-2) + sage: pol = (n - 1/2)^2 * (n - 1)^2 * (n - 2) sage: pol.roots(ZZ) [(2, 1), (1, 2)] @@ -7621,7 +7664,7 @@ cdef class Polynomial(CommutativePolynomial): sage: f = x^2 - 1e100 sage: f.roots() [(-1.00000000000000e50, 1), (1.00000000000000e50, 1)] - sage: f = x^10 - 2*(5*x-1)^2 + sage: f = x^10 - 2 * (5*x - 1)^2 sage: f.roots(multiplicities=False) [-1.6772670339941..., 0.19995479628..., 0.20004530611..., 1.5763035161844...] @@ -7629,10 +7672,10 @@ cdef class Polynomial(CommutativePolynomial): sage: x = CC['x'].0 sage: i = CC.0 - sage: f = (x - 1)*(x - i) + sage: f = (x - 1) * (x - i) sage: f.roots(multiplicities=False) [1.00000000000000, 1.00000000000000*I] - sage: g=(x-1.33+1.33*i)*(x-2.66-2.66*i) + sage: g = (x - 1.33 + 1.33*i) * (x - 2.66 - 2.66*i) sage: g.roots(multiplicities=False) [1.33000000000000 - 1.33000000000000*I, 2.66000000000000 + 2.66000000000000*I] @@ -7640,15 +7683,15 @@ cdef class Polynomial(CommutativePolynomial): sage: x = QQ['x'].0 sage: f = x^2 + 2 - sage: f.roots(SR) + sage: f.roots(SR) # optional - sage.symbolic [(-I*sqrt(2), 1), (I*sqrt(2), 1)] - sage: f.roots(SR, multiplicities=False) + sage: f.roots(SR, multiplicities=False) # optional - sage.symbolic [-I*sqrt(2), I*sqrt(2)] The roots of some polynomials cannot be described using radical expressions:: - sage: (x^5 - x + 1).roots(SR) + sage: (x^5 - x + 1).roots(SR) # optional - sage.symbolic [] For some other polynomials, no roots can be found at the moment @@ -7656,27 +7699,29 @@ cdef class Polynomial(CommutativePolynomial): these defects. Until that gets implemented, one such example is the following:: - sage: f = x^6-300*x^5+30361*x^4-1061610*x^3+1141893*x^2-915320*x+101724 + sage: f = x^6 - 300*x^5 + 30361*x^4 - 1061610*x^3 + 1141893*x^2 - 915320*x + 101724 sage: f.roots() [] A purely symbolic roots example:: - sage: X = var('X') - sage: f = expand((X-1)*(X-I)^3*(X^2 - sqrt(2))); f - X^6 - (3*I + 1)*X^5 - sqrt(2)*X^4 + (3*I - 3)*X^4 + (3*I + 1)*sqrt(2)*X^3 + (I + 3)*X^3 - (3*I - 3)*sqrt(2)*X^2 - I*X^2 - (I + 3)*sqrt(2)*X + I*sqrt(2) - sage: f.roots() + sage: X = var('X') # optional - sage.symbolic + sage: f = expand((X - 1) * (X - I)^3 * (X^2 - sqrt(2))); f # optional - sage.symbolic + X^6 - (3*I + 1)*X^5 - sqrt(2)*X^4 + (3*I - 3)*X^4 + (3*I + 1)*sqrt(2)*X^3 + + (I + 3)*X^3 - (3*I - 3)*sqrt(2)*X^2 - I*X^2 - (I + 3)*sqrt(2)*X + I*sqrt(2) + sage: f.roots() # optional - sage.symbolic [(I, 3), (-2^(1/4), 1), (2^(1/4), 1), (1, 1)] The same operation, performed over a polynomial ring with symbolic coefficients:: - sage: X = SR['X'].0 - sage: f = (X-1)*(X-I)^3*(X^2 - sqrt(2)); f - X^6 + (-3*I - 1)*X^5 + (-sqrt(2) + 3*I - 3)*X^4 + ((3*I + 1)*sqrt(2) + I + 3)*X^3 + (-(3*I - 3)*sqrt(2) - I)*X^2 + (-(I + 3)*sqrt(2))*X + I*sqrt(2) - sage: f.roots() + sage: X = SR['X'].0 # optional - sage.symbolic + sage: f = (X - 1) * (X - I)^3 * (X^2 - sqrt(2)); f # optional - sage.symbolic + X^6 + (-3*I - 1)*X^5 + (-sqrt(2) + 3*I - 3)*X^4 + ((3*I + 1)*sqrt(2) + I + 3)*X^3 + + (-(3*I - 3)*sqrt(2) - I)*X^2 + (-(I + 3)*sqrt(2))*X + I*sqrt(2) + sage: f.roots() # optional - sage.symbolic [(I, 3), (-2^(1/4), 1), (2^(1/4), 1), (1, 1)] - sage: f.roots(multiplicities=False) + sage: f.roots(multiplicities=False) # optional - sage.symbolic [I, -2^(1/4), 2^(1/4), 1] A couple of examples where the base ring does not have a @@ -7685,11 +7730,12 @@ cdef class Polynomial(CommutativePolynomial): sage: R = Integers(6) sage: S. = R['x'] - sage: p = x^2-1 + sage: p = x^2 - 1 sage: p.roots() Traceback (most recent call last): ... - NotImplementedError: root finding with multiplicities for this polynomial not implemented (try the multiplicities=False option) + NotImplementedError: root finding with multiplicities for this polynomial + not implemented (try the multiplicities=False option) sage: p.roots(multiplicities=False) [5, 1] sage: R = Integers(9) @@ -7706,9 +7752,11 @@ cdef class Polynomial(CommutativePolynomial): sage: f = R.cyclotomic_polynomial(5); f x^4 + x^3 + x^2 + x + 1.0 sage: f.roots(multiplicities=False) # abs tol 1e-9 - [-0.8090169943749469 - 0.5877852522924724*I, -0.8090169943749473 + 0.5877852522924724*I, 0.30901699437494773 - 0.951056516295154*I, 0.30901699437494756 + 0.9510565162951525*I] + [-0.8090169943749469 - 0.5877852522924724*I, -0.8090169943749473 + 0.5877852522924724*I, + 0.30901699437494773 - 0.951056516295154*I, 0.30901699437494756 + 0.9510565162951525*I] sage: [z^5 for z in f.roots(multiplicities=False)] # abs tol 2e-14 - [0.9999999999999957 - 1.2864981197413038e-15*I, 0.9999999999999976 + 3.062854959141552e-15*I, 1.0000000000000024 + 1.1331077795295987e-15*I, 0.9999999999999953 - 2.0212861992297117e-15*I] + [0.9999999999999957 - 1.2864981197413038e-15*I, 0.9999999999999976 + 3.062854959141552e-15*I, + 1.0000000000000024 + 1.1331077795295987e-15*I, 0.9999999999999953 - 2.0212861992297117e-15*I] sage: f = CDF['x']([1,2,3,4]); f 4.0*x^3 + 3.0*x^2 + 2.0*x + 1.0 sage: r = f.roots(multiplicities=False) @@ -7718,9 +7766,9 @@ cdef class Polynomial(CommutativePolynomial): Another example over RDF:: sage: x = RDF['x'].0 - sage: ((x^3 -1)).roots() # abs tol 4e-16 + sage: ((x^3 - 1)).roots() # abs tol 4e-16 [(1.0000000000000002, 1)] - sage: ((x^3 -1)).roots(multiplicities=False) # abs tol 4e-16 + sage: ((x^3 - 1)).roots(multiplicities=False) # abs tol 4e-16 [1.0000000000000002] More examples involving the complex double field:: @@ -7730,15 +7778,20 @@ cdef class Polynomial(CommutativePolynomial): sage: f = x^3 + 2*i; f x^3 + 2.0*I sage: f.roots() - [(-1.09112363597172... - 0.62996052494743...*I, 1), (...1.25992104989487...*I, 1), (1.09112363597172... - 0.62996052494743...*I, 1)] + [(-1.09112363597172... - 0.62996052494743...*I, 1), + (...1.25992104989487...*I, 1), + (1.09112363597172... - 0.62996052494743...*I, 1)] sage: f.roots(multiplicities=False) - [-1.09112363597172... - 0.62996052494743...*I, ...1.25992104989487...*I, 1.09112363597172... - 0.62996052494743...*I] + [-1.09112363597172... - 0.62996052494743...*I, ...1.25992104989487...*I, + 1.09112363597172... - 0.62996052494743...*I] sage: [abs(f(z)) for z in f.roots(multiplicities=False)] # abs tol 1e-14 [8.95090418262362e-16, 8.728374398092689e-16, 1.0235750533041806e-15] sage: f = i*x^3 + 2; f I*x^3 + 2.0 sage: f.roots() - [(-1.09112363597172... + 0.62996052494743...*I, 1), (...1.25992104989487...*I, 1), (1.09112363597172... + 0.62996052494743...*I, 1)] + [(-1.09112363597172... + 0.62996052494743...*I, 1), + (...1.25992104989487...*I, 1), + (1.09112363597172... + 0.62996052494743...*I, 1)] sage: abs(f(f.roots()[0][0])) # abs tol 1e-13 1.1102230246251565e-16 @@ -7753,14 +7806,19 @@ cdef class Polynomial(CommutativePolynomial): sage: f.roots(ring=RIF, multiplicities=False) [-0.6180339887498948482045868343657?, 1.6180339887498948482045868343657?] sage: f.roots(ring=RealIntervalField(150)) - [(-0.6180339887498948482045868343656381177203091798057628621354486227?, 1), (1.618033988749894848204586834365638117720309179805762862135448623?, 1)] - sage: f.roots(ring=AA) + [(-0.6180339887498948482045868343656381177203091798057628621354486227?, 1), + (1.618033988749894848204586834365638117720309179805762862135448623?, 1)] + sage: f.roots(ring=AA) # optional - sage.rings.number_field [(-0.618033988749895?, 1), (1.618033988749895?, 1)] sage: f = f^2 * (x - 1) sage: f.roots(ring=RIF) - [(-0.6180339887498948482045868343657?, 2), (1.0000000000000000000000000000000?, 1), (1.6180339887498948482045868343657?, 2)] + [(-0.6180339887498948482045868343657?, 2), + (1.0000000000000000000000000000000?, 1), + (1.6180339887498948482045868343657?, 2)] sage: f.roots(ring=RIF, multiplicities=False) - [-0.6180339887498948482045868343657?, 1.0000000000000000000000000000000?, 1.6180339887498948482045868343657?] + [-0.6180339887498948482045868343657?, + 1.0000000000000000000000000000000?, + 1.6180339887498948482045868343657?] Examples using complex root isolation:: @@ -7769,15 +7827,19 @@ cdef class Polynomial(CommutativePolynomial): sage: p.roots() [] sage: p.roots(ring=CIF) - [(1.167303978261419?, 1), (-0.764884433600585? - 0.352471546031727?*I, 1), (-0.764884433600585? + 0.352471546031727?*I, 1), (0.181232444469876? - 1.083954101317711?*I, 1), (0.181232444469876? + 1.083954101317711?*I, 1)] + [(1.167303978261419?, 1), + (-0.764884433600585? - 0.352471546031727?*I, 1), + (-0.764884433600585? + 0.352471546031727?*I, 1), + (0.181232444469876? - 1.083954101317711?*I, 1), + (0.181232444469876? + 1.083954101317711?*I, 1)] sage: p.roots(ring=ComplexIntervalField(200)) [(1.167303978261418684256045899854842180720560371525489039140082?, 1), (-0.76488443360058472602982318770854173032899665194736756700778? - 0.35247154603172624931794709140258105439420648082424733283770?*I, 1), (-0.76488443360058472602982318770854173032899665194736756700778? + 0.35247154603172624931794709140258105439420648082424733283770?*I, 1), (0.18123244446987538390180023778112063996871646618462304743774? - 1.08395410131771066843034449298076657427364024315511565430114?*I, 1), (0.18123244446987538390180023778112063996871646618462304743774? + 1.08395410131771066843034449298076657427364024315511565430114?*I, 1)] - sage: rts = p.roots(ring=QQbar); rts + sage: rts = p.roots(ring=QQbar); rts # optional - sage.rings.number_field [(1.167303978261419?, 1), (-0.7648844336005847? - 0.3524715460317263?*I, 1), (-0.7648844336005847? + 0.3524715460317263?*I, 1), (0.1812324444698754? - 1.083954101317711?*I, 1), (0.1812324444698754? + 1.083954101317711?*I, 1)] - sage: p.roots(ring=AA) + sage: p.roots(ring=AA) # optional - sage.rings.number_field [(1.167303978261419?, 1)] sage: p = (x - rts[4][0])^2 * (3*x^2 + x + 1) - sage: p.roots(ring=QQbar) + sage: p.roots(ring=QQbar) # optional - sage.rings.number_field [(-0.1666666666666667? - 0.552770798392567?*I, 1), (-0.1666666666666667? + 0.552770798392567?*I, 1), (0.1812324444698754? + 1.083954101317711?*I, 2)] sage: p.roots(ring=CIF) [(-0.1666666666666667? - 0.552770798392567?*I, 1), (-0.1666666666666667? + 0.552770798392567?*I, 1), (0.1812324444698754? + 1.083954101317711?*I, 2)] @@ -7799,35 +7861,44 @@ cdef class Polynomial(CommutativePolynomial): Note that coefficients in a number field with defining polynomial `x^2 + 1` are considered to be Gaussian rationals (with the - generator mapping to +I), if you ask for complex roots. + generator mapping to `+I`), if you ask for complex roots. :: - sage: K. = QuadraticField(-1) - sage: y = polygen(K) - sage: p = y^4 - 2 - im - sage: p.roots(ring=CC) - [(-1.2146389322441... - 0.14142505258239...*I, 1), (-0.14142505258239... + 1.2146389322441...*I, 1), (0.14142505258239... - 1.2146389322441...*I, 1), (1.2146389322441... + 0.14142505258239...*I, 1)] - sage: p = p^2 * (y^2 - 2) - sage: p.roots(ring=CIF) - [(-1.414213562373095?, 1), (1.414213562373095?, 1), (-1.214638932244183? - 0.141425052582394?*I, 2), (-0.141425052582394? + 1.214638932244183?*I, 2), (0.141425052582394? - 1.214638932244183?*I, 2), (1.214638932244183? + 0.141425052582394?*I, 2)] + sage: K. = QuadraticField(-1) # optional - sage.rings.number_field + sage: y = polygen(K) # optional - sage.rings.number_field + sage: p = y^4 - 2 - im # optional - sage.rings.number_field + sage: p.roots(ring=CC) # optional - sage.rings.number_field + [(-1.2146389322441... - 0.14142505258239...*I, 1), + (-0.14142505258239... + 1.2146389322441...*I, 1), + (0.14142505258239... - 1.2146389322441...*I, 1), + (1.2146389322441... + 0.14142505258239...*I, 1)] + sage: p = p^2 * (y^2 - 2) # optional - sage.rings.number_field + sage: p.roots(ring=CIF) # optional - sage.rings.number_field + [(-1.414213562373095?, 1), (1.414213562373095?, 1), + (-1.214638932244183? - 0.141425052582394?*I, 2), + (-0.141425052582394? + 1.214638932244183?*I, 2), + (0.141425052582394? - 1.214638932244183?*I, 2), + (1.214638932244183? + 0.141425052582394?*I, 2)] Note that one should not use NumPy when wanting high precision output as it does not support any of the high precision types:: sage: R. = RealField(200)[] - sage: f = x^2 - R(pi) - sage: f.roots() - [(-1.7724538509055160272981674833411451827975494561223871282138, 1), (1.7724538509055160272981674833411451827975494561223871282138, 1)] - sage: f.roots(algorithm='numpy') - doctest... UserWarning: NumPy does not support arbitrary precision arithmetic. The roots found will likely have less precision than you expect. + sage: f = x^2 - R(pi) # optional - sage.symbolic + sage: f.roots() # optional - sage.symbolic + [(-1.7724538509055160272981674833411451827975494561223871282138, 1), + (1.7724538509055160272981674833411451827975494561223871282138, 1)] + sage: f.roots(algorithm='numpy') # optional - numpy sage.symbolic + doctest... UserWarning: NumPy does not support arbitrary precision arithmetic. + The roots found will likely have less precision than you expect. [(-1.77245385090551..., 1), (1.77245385090551..., 1)] We can also find roots over number fields:: - sage: K. = CyclotomicField(15) - sage: R. = PolynomialRing(K) - sage: (x^2 + x + 1).roots() + sage: K. = CyclotomicField(15) # optional - sage.rings.number_field + sage: R. = PolynomialRing(K) # optional - sage.rings.number_field + sage: (x^2 + x + 1).roots() # optional - sage.rings.number_field [(z^5, 1), (-z^5 - 1, 1)] There are many combinations of floating-point input and output @@ -7863,22 +7934,23 @@ cdef class Polynomial(CommutativePolynomial): Note that we can find the roots of a polynomial with algebraic coefficients:: - sage: rt2 = sqrt(AA(2)) - sage: rt3 = sqrt(AA(3)) - sage: x = polygen(AA) - sage: f = (x - rt2) * (x - rt3); f - x^2 - 3.146264369941973?*x + 2.449489742783178? - sage: rts = f.roots(); rts + sage: rt2 = sqrt(AA(2)) # optional - sage.rings.number_field + sage: rt3 = sqrt(AA(3)) # optional - sage.rings.number_field + sage: x = polygen(AA) # optional - sage.rings.number_field + sage: f = (x - rt2) * (x - rt3); f # optional - sage.rings.number_field + x^2 - 3.146264369941973?*x + 2.449489742783178? + sage: rts = f.roots(); rts # optional - sage.rings.number_field [(1.414213562373095?, 1), (1.732050807568878?, 1)] - sage: rts[0][0] == rt2 + sage: rts[0][0] == rt2 # optional - sage.rings.number_field True - sage: f.roots(ring=RealIntervalField(150)) - [(1.414213562373095048801688724209698078569671875376948073176679738?, 1), (1.732050807568877293527446341505872366942805253810380628055806980?, 1)] + sage: f.roots(ring=RealIntervalField(150)) # optional - sage.rings.number_field + [(1.414213562373095048801688724209698078569671875376948073176679738?, 1), + (1.732050807568877293527446341505872366942805253810380628055806980?, 1)] We can handle polynomials with huge coefficients. This number doesn't even fit in an IEEE double-precision float, but - RR and CC allow a much larger range of floating-point numbers:: + ``RR`` and ``CC`` allow a much larger range of floating-point numbers:: sage: bigc = 2^1500 sage: CDF(bigc) @@ -7891,62 +7963,62 @@ cdef class Polynomial(CommutativePolynomial): sage: x = polygen(QQ) sage: p = x + bigc - sage: p.roots(ring=RR, algorithm='numpy') + sage: p.roots(ring=RR, algorithm='numpy') # optional - numpy Traceback (most recent call last): ... LinAlgError: Array must not contain infs or NaNs - sage: p.roots(ring=RR, algorithm='pari') + sage: p.roots(ring=RR, algorithm='pari') # optional - sage.libs.pari [(-3.50746621104340e451, 1)] - sage: p.roots(ring=AA) + sage: p.roots(ring=AA) # optional - sage.rings.number_field [(-3.5074662110434039?e451, 1)] - sage: p.roots(ring=QQbar) + sage: p.roots(ring=QQbar) # optional - sage.rings.number_field [(-3.5074662110434039?e451, 1)] sage: p = bigc*x + 1 sage: p.roots(ring=RR) [(-2.85106096489671e-452, 1)] - sage: p.roots(ring=AA) + sage: p.roots(ring=AA) # optional - sage.rings.number_field [(-2.8510609648967059?e-452, 1)] - sage: p.roots(ring=QQbar) + sage: p.roots(ring=QQbar) # optional - sage.rings.number_field [(-2.8510609648967059?e-452, 1)] sage: p = x^2 - bigc sage: p.roots(ring=RR) [(-5.92238652153286e225, 1), (5.92238652153286e225, 1)] - sage: p.roots(ring=QQbar) + sage: p.roots(ring=QQbar) # optional - sage.rings.number_field [(-5.9223865215328558?e225, 1), (5.9223865215328558?e225, 1)] Check that :trac:`30522` is fixed:: - sage: PolynomialRing(SR, names="x")("x^2").roots() + sage: PolynomialRing(SR, names="x")("x^2").roots() # optional - sage.symbolic [(0, 2)] Check that :trac:`30523` is fixed:: - sage: PolynomialRing(SR, names="x")("x^2 + q").roots() + sage: PolynomialRing(SR, names="x")("x^2 + q").roots() # optional - sage.symbolic [(-sqrt(-q), 1), (sqrt(-q), 1)] - Algorithms used: + ALGORITHM: - For brevity, we will use RR to mean any RealField of any precision; - similarly for RIF, CC, and CIF. Since Sage has no specific + For brevity, we will use ``RR`` to mean any :class:`RealField` of any precision; + similarly for ``RIF``, ``CC``, and ``CIF``. Since Sage has no specific implementation of Gaussian rationals (or of number fields with embedding, at all), when we refer to Gaussian rationals below we will accept any number field with defining polynomial `x^2+1`, mapping the field generator to +I. - We call the base ring of the polynomial K, and the ring given by - the ring= argument L. (If ring= is not specified, then L is the - same as K.) - - If K and L are floating-point (RDF, CDF, RR, or CC), then a - floating-point root-finder is used. If L is RDF or CDF then we - default to using NumPy's roots(); otherwise, we use PARI's - polroots(). This choice can be overridden with - algorithm='pari' or algorithm='numpy'. If the algorithm is - unspecified and NumPy's roots() algorithm fails, then we fall - back to pari (numpy will fail if some coefficient is infinite, + We call the base ring of the polynomial `K`, and the ring given by + the ``ring`` argument `L`. (If ``ring`` is not specified, then `L` is the + same as `K`.) + + If `K` and `L` are floating-point (``RDF``, ``CDF``, ``RR``, or ``CC``), then a + floating-point root-finder is used. If `L` is ``RDF`` or ``CDF``, then we + default to using NumPy's :func:`roots`; otherwise, we use PARI's + function :pari:`polroots`. This choice can be overridden with + ``algorithm='pari'`` or ``algorithm='numpy'``. If the algorithm is + unspecified and NumPy's :func:`roots` algorithm fails, then we fall + back to PARI (NumPy will fail if some coefficient is infinite, for instance). - If L is SR (or one of its subrings), then the roots will be radical + If `L` is ``SR`` (or one of its subrings), then the roots will be radical expressions, computed as the solutions of a symbolic polynomial expression. At the moment this delegates to :meth:`sage.symbolic.expression.Expression.solve` @@ -7955,47 +8027,47 @@ cdef class Polynomial(CommutativePolynomial): Once :trac:`17516` gets implemented, all possible radical solutions should become available. - If L is AA or RIF, and K is ZZ, QQ, or AA, then the root isolation - algorithm sage.rings.polynomial.real_roots.real_roots() is used. - (You can call real_roots() directly to get more control than this + If `L` is ``AA`` or ``RIF``, and `K` is ``ZZ``, ``QQ``, or ``AA``, then the root isolation + algorithm :func:`sage.rings.polynomial.real_roots.real_roots` is used. + (You can call :func:`real_roots` directly to get more control than this method gives.) - If L is QQbar or CIF, and K is ZZ, QQ, AA, QQbar, or the Gaussian + If `L` is ``QQbar`` or ``CIF``, and `K` is ``ZZ``, ``QQ``, ``AA``, ``QQbar``, or the Gaussian rationals, then the root isolation algorithm - sage.rings.polynomial.complex_roots.complex_roots() is used. (You - can call complex_roots() directly to get more control than this + :func:`sage.rings.polynomial.complex_roots.complex_roots` is used. (You + can call :func:`complex_roots` directly to get more control than this method gives.) - If L is AA and K is QQbar or the Gaussian rationals, then - complex_roots() is used (as above) to find roots in QQbar, then + If `L` is ``AA`` and `K` is ``QQbar`` or the Gaussian rationals, then + :func:`complex_roots` is used (as above) to find roots in ``QQbar``, then these roots are filtered to select only the real roots. - If L is floating-point and K is not, then we attempt to change the - polynomial ring to L (using .change_ring()) (or, if L is complex - and K is not, to the corresponding real field). Then we use either - PARI or numpy as specified above. + If `L` is floating-point and `K` is not, then we attempt to change the + polynomial ring to `L` (using :meth:`change_ring`) (or, if `L` is complex + and `K` is not, to the corresponding real field). Then we use either + PARI or NumPy as specified above. - For all other cases where K is different than L, we attempt to use - .change_ring(L). When that fails but L is a subring of K, we also - attempt to compute the roots over K and filter the ones belonging - to L. + For all other cases where `K` is different from `L`, we attempt to use + ``.change_ring(L)``. When that fails but `L` is a subring of `K`, we also + attempt to compute the roots over `K` and filter the ones belonging + to `L`. - The next method, which is used if K is an integral domain, is to + The next method, which is used if `K` is an integral domain, is to attempt to factor the polynomial. If this succeeds, then for every - degree-one factor a\*x+b, we add -b/a as a root (as long as this + degree-one factor `ax+b`, we add `-b/a` as a root (as long as this quotient is actually in the desired ring). - If factoring over K is not implemented (or K is not an integral - domain), and K is finite, then we find the roots by enumerating all - elements of K and checking whether the polynomial evaluates to zero + If factoring over `K` is not implemented (or `K` is not an integral + domain), and `K` is finite, then we find the roots by enumerating all + elements of `K` and checking whether the polynomial evaluates to zero at that value. .. NOTE:: We mentioned above that polynomials with multiple roots are - always ill-conditioned; if your input is given to n bits of - precision, you should not expect more than n/k good bits - for a k-fold root. (You can get solutions that make the + always ill-conditioned; if your input is given to `n` bits of + precision, you should not expect more than `n/k` good bits + for a `k`-fold root. (You can get solutions that make the polynomial evaluate to a number very close to zero; basically the problem is that with a multiple root, there are many such numbers, and it's difficult to choose between @@ -8013,9 +8085,9 @@ cdef class Polynomial(CommutativePolynomial): TESTS:: - sage: K. = CyclotomicField(2) - sage: R. = K[] - sage: factor(x^3-1) + sage: K. = CyclotomicField(2) # optional - sage.rings.number_field + sage: R. = K[] # optional - sage.rings.number_field + sage: factor(x^3 - 1) # optional - sage.rings.number_field (x - 1) * (x^2 + x + 1) This shows that the issue from :trac:`6237` is fixed:: @@ -8023,9 +8095,11 @@ cdef class Polynomial(CommutativePolynomial): sage: R. = QQ[] sage: g = -27*u^14 - 32*u^9 sage: g.roots(CDF, multiplicities=False) # abs tol 2e-15 - [-1.0345637159435719, 0.0, -0.3196977699902601 - 0.9839285635706636*I, -0.3196977699902601 + 0.9839285635706636*I, 0.8369796279620465 - 0.6081012947885318*I, 0.8369796279620465 + 0.6081012947885318*I] + [-1.0345637159435719, 0.0, -0.3196977699902601 - 0.9839285635706636*I, -0.3196977699902601 + 0.9839285635706636*I, + 0.8369796279620465 - 0.6081012947885318*I, 0.8369796279620465 + 0.6081012947885318*I] sage: g.roots(CDF) # abs tol 2e-15 - [(-1.0345637159435719, 1), (0.0, 9), (-0.3196977699902601 - 0.9839285635706636*I, 1), (-0.3196977699902601 + 0.9839285635706636*I, 1), (0.8369796279620465 - 0.6081012947885318*I, 1), (0.8369796279620465 + 0.6081012947885318*I, 1)] + [(-1.0345637159435719, 1), (0.0, 9), (-0.3196977699902601 - 0.9839285635706636*I, 1), (-0.3196977699902601 + 0.9839285635706636*I, 1), + (0.8369796279620465 - 0.6081012947885318*I, 1), (0.8369796279620465 + 0.6081012947885318*I, 1)] This shows that the issue at :trac:`2418` is fixed:: @@ -8038,13 +8112,13 @@ cdef class Polynomial(CommutativePolynomial): This shows that the issue at :trac:`10901` is fixed:: - sage: a = var('a'); R. = SR[] - sage: f = x - a - sage: f.roots(RR) + sage: a = var('a'); R. = SR[] # optional - sage.symbolic + sage: f = x - a # optional - sage.symbolic + sage: f.roots(RR) # optional - sage.symbolic Traceback (most recent call last): ... TypeError: cannot evaluate symbolic expression to a numeric value - sage: f.roots(CC) + sage: f.roots(CC) # optional - sage.symbolic Traceback (most recent call last): ... TypeError: cannot evaluate symbolic expression to a numeric value @@ -8054,19 +8128,19 @@ cdef class Polynomial(CommutativePolynomial): sage: R. = ZZ[] sage: pol = (x - 1)^2 - sage: pol.roots(Qp(3,5)) + sage: pol.roots(Qp(3, 5)) # optional - sage.rings.padics [(1 + O(3^5), 2)] We lose precision if we first change coefficients to `\QQ_p`:: - sage: pol.change_ring(Qp(3,5)).roots() + sage: pol.change_ring(Qp(3, 5)).roots() # optional - sage.rings.padics [(1 + O(3^3), 2)] - sage: (pol - 3^6).roots(Qp(3,5)) + sage: (pol - 3^6).roots(Qp(3, 5)) # optional - sage.rings.padics [(1 + 2*3^3 + 2*3^4 + O(3^5), 1), (1 + 3^3 + O(3^5), 1)] - sage: r = pol.roots(Zp(3,5), multiplicities=False); r + sage: r = pol.roots(Zp(3, 5), multiplicities=False); r # optional - sage.rings.padics [1 + O(3^5)] - sage: parent(r[0]) + sage: parent(r[0]) # optional - sage.rings.padics 3-adic Ring with capped relative precision 5 Spurious crash with pari-2.5.5, see :trac:`16165`:: @@ -8095,7 +8169,7 @@ cdef class Polynomial(CommutativePolynomial): Test that roots in fixed modulus p-adic fields work (:trac:`17598`):: - sage: len(cyclotomic_polynomial(3).roots(ZpFM(739, 566))) + sage: len(cyclotomic_polynomial(3).roots(ZpFM(739, 566))) # optional - sage.rings.padics 2 Check that :trac:`26421` is fixed:: @@ -8109,8 +8183,8 @@ cdef class Polynomial(CommutativePolynomial): Check that :trac:`31040` is fixed:: sage: R. = QQ[] - sage: K. = Qq(3).extension(x^2 + 1) - sage: (x^2 + 1).roots(K) + sage: K. = Qq(3).extension(x^2 + 1) # optional - sage.rings.padics + sage: (x^2 + 1).roots(K) # optional - sage.rings.padics [(a + O(3^20), 1), (2*a + 2*a*3 + 2*a*3^2 + 2*a*3^3 + 2*a*3^4 + 2*a*3^5 + 2*a*3^6 + 2*a*3^7 + 2*a*3^8 + 2*a*3^9 + 2*a*3^10 + 2*a*3^11 + 2*a*3^12 + 2*a*3^13 + 2*a*3^14 + 2*a*3^15 + 2*a*3^16 + 2*a*3^17 + 2*a*3^18 + 2*a*3^19 + O(3^20), 1)] @@ -8395,11 +8469,11 @@ cdef class Polynomial(CommutativePolynomial): sage: R. = ZZ[] sage: pol = 20*x^3 - 50*x^2 + 20*x - sage: F = pol.factor(); F + sage: F = pol.factor(); F # optional - sage.libs.pari 2 * 5 * (x - 2) * x * (2*x - 1) - sage: pol._roots_from_factorization(F, multiplicities=True) + sage: pol._roots_from_factorization(F, multiplicities=True) # optional - sage.libs.pari [(2, 1), (0, 1)] - sage: pol.change_ring(QQ)._roots_from_factorization(F, multiplicities=False) + sage: pol.change_ring(QQ)._roots_from_factorization(F, multiplicities=False) # optional - sage.libs.pari [2, 0, 1/2] """ seq = [] @@ -8428,15 +8502,15 @@ cdef class Polynomial(CommutativePolynomial): TESTS:: sage: Pols. = QQ[] - sage: pol = (n - 1/2)^2*(n - 1)^2*(n-2) - sage: rts = pol.roots(ZZ, multiplicities=False); rts + sage: pol = (n - 1/2)^2 * (n - 1)^2 * (n - 2) + sage: rts = pol.roots(ZZ, multiplicities=False); rts # optional - sage.libs.pari [2, 1] - sage: rts[0].parent() + sage: rts[0].parent() # optional - sage.libs.pari Integer Ring sage: Pols_x. = QQ[] sage: Pols_xy. = Pols_x[] - sage: ((y - 1)*(y - x))._roots_in_subring(QQ, True, None) + sage: ((y - 1)*(y - x))._roots_in_subring(QQ, True, None) # optional - sage.libs.singular [(1, 1)] """ K = self._parent.base_ring() @@ -8462,9 +8536,9 @@ cdef class Polynomial(CommutativePolynomial): """ Return the real roots of this polynomial, without multiplicities. - Calls self.roots(ring=RR), unless this is a polynomial with + Calls ``self.roots(ring=RR)``, unless this is a polynomial with floating-point real coefficients, in which case it calls - self.roots(). + ``self.roots()``. EXAMPLES:: @@ -8496,7 +8570,7 @@ cdef class Polynomial(CommutativePolynomial): Return the complex roots of this polynomial, without multiplicities. - Calls self.roots(ring=CC), unless this is a polynomial with + Calls ``self.roots(ring=CC)``, unless this is a polynomial with floating-point coefficients, in which case it is uses the appropriate precision from the input coefficients. @@ -8540,50 +8614,50 @@ cdef class Polynomial(CommutativePolynomial): def number_of_roots_in_interval(self, a=None, b=None): r""" Return the number of roots of this polynomial in the interval - [a,b], counted without multiplicity. The endpoints a, b default to - -Infinity, Infinity (which are also valid input values). + `[a,b]`, counted without multiplicity. The endpoints `a`, `b` default to + ``-Infinity``, ``Infinity`` (which are also valid input values). Calls the PARI routine :pari:`polsturm`. Note that as of version 2.8, PARI includes the left endpoint of the interval (and no longer uses Sturm's algorithm on exact - inputs). polsturm requires a polynomial with real + inputs). :pari:`polsturm` requires a polynomial with real coefficients; in case PARI returns an error, we try again - after taking the GCD of `self` with its complex conjugate. + after taking the GCD of ``self`` with its complex conjugate. EXAMPLES:: sage: R. = PolynomialRing(ZZ) - sage: pol = (x-1)^2 * (x-2)^2 * (x-3) - sage: pol.number_of_roots_in_interval(1, 2) + sage: pol = (x - 1)^2 * (x - 2)^2 * (x - 3) + sage: pol.number_of_roots_in_interval(1, 2) # optional - sage.libs.pari 2 - sage: pol.number_of_roots_in_interval(1.01, 2) + sage: pol.number_of_roots_in_interval(1.01, 2) # optional - sage.libs.pari 1 - sage: pol.number_of_roots_in_interval(None, 2) + sage: pol.number_of_roots_in_interval(None, 2) # optional - sage.libs.pari 2 - sage: pol.number_of_roots_in_interval(1, Infinity) + sage: pol.number_of_roots_in_interval(1, Infinity) # optional - sage.libs.pari 3 - sage: pol.number_of_roots_in_interval() + sage: pol.number_of_roots_in_interval() # optional - sage.libs.pari 3 - sage: pol = (x-1)*(x-2)*(x-3) + sage: pol = (x - 1) * (x - 2) * (x - 3) sage: pol2 = pol.change_ring(CC) - sage: pol2.number_of_roots_in_interval() + sage: pol2.number_of_roots_in_interval() # optional - sage.libs.pari 3 sage: R. = PolynomialRing(CC) - sage: pol = (x-1)*(x-CC(I)) - sage: pol.number_of_roots_in_interval(0,2) + sage: pol = (x - 1) * (x - CC(I)) + sage: pol.number_of_roots_in_interval(0, 2) # optional - sage.libs.pari 1 TESTS:: sage: R. = PolynomialRing(ZZ) - sage: pol = (x-1)^2 * (x-2)^2 * (x-3) - sage: pol.number_of_roots_in_interval(1, 2) + sage: pol = (x - 1)^2 * (x - 2)^2 * (x - 3) + sage: pol.number_of_roots_in_interval(1, 2) # optional - sage.libs.pari 2 sage: pol = chebyshev_T(5,x) - sage: pol.number_of_roots_in_interval(-1,2) + sage: pol.number_of_roots_in_interval(-1, 2) # optional - sage.libs.pari 5 - sage: pol.number_of_roots_in_interval(0,2) + sage: pol.number_of_roots_in_interval(0, 2) # optional - sage.libs.pari 3 """ @@ -8612,40 +8686,40 @@ cdef class Polynomial(CommutativePolynomial): EXAMPLES:: sage: R. = PolynomialRing(ZZ) - sage: pol = (x-1)^2 * (x-2)^2 * (x-3) - sage: pol.number_of_real_roots() + sage: pol = (x - 1)^2 * (x - 2)^2 * (x - 3) + sage: pol.number_of_real_roots() # optional - sage.libs.pari 3 - sage: pol = (x-1)*(x-2)*(x-3) + sage: pol = (x - 1) * (x - 2) * (x - 3) sage: pol2 = pol.change_ring(CC) - sage: pol2.number_of_real_roots() + sage: pol2.number_of_real_roots() # optional - sage.libs.pari 3 sage: R. = PolynomialRing(CC) - sage: pol = (x-1)*(x-CC(I)) - sage: pol.number_of_real_roots() + sage: pol = (x - 1) * (x - CC(I)) + sage: pol.number_of_real_roots() # optional - sage.libs.pari 1 """ return self.number_of_roots_in_interval() def all_roots_in_interval(self, a=None, b=None): r""" - Return True if the roots of this polynomial are all real and + Return ``True`` if the roots of this polynomial are all real and contained in the given interval. EXAMPLES:: sage: R. = PolynomialRing(ZZ) - sage: pol = (x-1)^2 * (x-2)^2 * (x-3) - sage: pol.all_roots_in_interval(1, 3) + sage: pol = (x - 1)^2 * (x - 2)^2 * (x - 3) + sage: pol.all_roots_in_interval(1, 3) # optional - sage.libs.pari True - sage: pol.all_roots_in_interval(1.01, 3) + sage: pol.all_roots_in_interval(1.01, 3) # optional - sage.libs.pari False - sage: pol = chebyshev_T(5,x) - sage: pol.all_roots_in_interval(-1,1) + sage: pol = chebyshev_T(5, x) + sage: pol.all_roots_in_interval(-1, 1) # optional - sage.libs.pari True - sage: pol = chebyshev_T(5,x/2) - sage: pol.all_roots_in_interval(-1,1) + sage: pol = chebyshev_T(5, x/2) + sage: pol.all_roots_in_interval(-1, 1) # optional - sage.libs.pari False - sage: pol.all_roots_in_interval() + sage: pol.all_roots_in_interval() # optional - sage.libs.pari True """ pol = self // self.gcd(self.derivative()) @@ -8653,16 +8727,16 @@ cdef class Polynomial(CommutativePolynomial): def is_real_rooted(self): r""" - Return True if the roots of this polynomial are all real. + Return ``True`` if the roots of this polynomial are all real. EXAMPLES:: sage: R. = PolynomialRing(ZZ) sage: pol = chebyshev_T(5, x) - sage: pol.is_real_rooted() + sage: pol.is_real_rooted() # optional - sage.libs.pari True sage: pol = x^2 + 1 - sage: pol.is_real_rooted() + sage: pol.is_real_rooted() # optional - sage.libs.pari False """ return self.all_roots_in_interval() @@ -8693,7 +8767,7 @@ cdef class Polynomial(CommutativePolynomial): EXAMPLES:: sage: pol. = PolynomialRing(Rationals()) - sage: u = x^2+x-1 + sage: u = x^2 + x - 1 sage: u.reciprocal_transform() x^4 + x^3 + x^2 + x + 1 sage: u.reciprocal_transform(R=x-1) @@ -8743,22 +8817,22 @@ cdef class Polynomial(CommutativePolynomial): We check that this function works for rings that have a coercion to the reals:: - sage: K. = NumberField(x^2-2,embedding=1.4) - sage: u = x^4 + a*x^3 + 3*x^2 + 2*a*x + 4 - sage: u.trace_polynomial() + sage: K. = NumberField(x^2 - 2, embedding=1.4) # optional - sage.rings.number_field + sage: u = x^4 + a*x^3 + 3*x^2 + 2*a*x + 4 # optional - sage.rings.number_field + sage: u.trace_polynomial() # optional - sage.rings.number_field (x^2 + a*x - 1, 1, 2) - sage: (u*(x^2-2)).trace_polynomial() + sage: (u*(x^2-2)).trace_polynomial() # optional - sage.rings.number_field (x^2 + a*x - 1, x^2 - 2, 2) - sage: (u*(x^2-2)^2).trace_polynomial() + sage: (u*(x^2-2)^2).trace_polynomial() # optional - sage.rings.number_field (x^4 + a*x^3 - 9*x^2 - 8*a*x + 8, 1, 2) - sage: (u*(x^2-2)^3).trace_polynomial() + sage: (u*(x^2-2)^3).trace_polynomial() # optional - sage.rings.number_field (x^4 + a*x^3 - 9*x^2 - 8*a*x + 8, x^2 - 2, 2) - sage: u = x^4 + a*x^3 + 3*x^2 + 4*a*x + 16 - sage: u.trace_polynomial() + sage: u = x^4 + a*x^3 + 3*x^2 + 4*a*x + 16 # optional - sage.rings.number_field + sage: u.trace_polynomial() # optional - sage.rings.number_field (x^2 + a*x - 5, 1, 4) - sage: (u*(x-2)).trace_polynomial() + sage: (u*(x-2)).trace_polynomial() # optional - sage.rings.number_field (x^2 + a*x - 5, x - 2, 4) - sage: (u*(x+2)).trace_polynomial() + sage: (u*(x+2)).trace_polynomial() # optional - sage.rings.number_field (x^2 + a*x - 5, x + 2, 4) TESTS: @@ -8805,7 +8879,7 @@ cdef class Polynomial(CommutativePolynomial): def is_weil_polynomial(self, return_q=False): r""" - Return True if this is a Weil polynomial. + Return ``True`` if this is a Weil polynomial. This polynomial must have rational or integer coefficients. @@ -8814,8 +8888,8 @@ cdef class Polynomial(CommutativePolynomial): - ``self`` -- polynomial with rational or integer coefficients - ``return_q`` -- (default ``False``) if ``True``, return a second value `q` - which is the prime power with respect to which this is `q`-Weil, - or 0 if there is no such value. + which is the prime power with respect to which this is `q`-Weil, + or 0 if there is no such value. EXAMPLES:: @@ -8823,20 +8897,20 @@ cdef class Polynomial(CommutativePolynomial): sage: P0 = x^4 + 5*x^3 + 15*x^2 + 25*x + 25 sage: P1 = x^4 + 25*x^3 + 15*x^2 + 5*x + 25 sage: P2 = x^4 + 5*x^3 + 25*x^2 + 25*x + 25 - sage: P0.is_weil_polynomial(return_q=True) + sage: P0.is_weil_polynomial(return_q=True) # optional - sage.libs.pari (True, 5) - sage: P0.is_weil_polynomial(return_q=False) + sage: P0.is_weil_polynomial(return_q=False) # optional - sage.libs.pari True - sage: P1.is_weil_polynomial(return_q=True) + sage: P1.is_weil_polynomial(return_q=True) # optional - sage.libs.pari (False, 0) - sage: P1.is_weil_polynomial(return_q=False) + sage: P1.is_weil_polynomial(return_q=False) # optional - sage.libs.pari False - sage: P2.is_weil_polynomial() + sage: P2.is_weil_polynomial() # optional - sage.libs.pari False .. SEEALSO:: - Polynomial rings have a method `weil_polynomials` to compute sets of Weil + Polynomial rings have a method :meth:`weil_polynomials` to compute sets of Weil polynomials. This computation uses the iterator :class:`sage.rings.polynomial.weil.weil_polynomials.WeilPolynomials`. @@ -8846,7 +8920,7 @@ cdef class Polynomial(CommutativePolynomial): sage: P. = QQ[] sage: u = t^10 + 4*t^9 + 8*t^8 + 18*t^7 + 81*t^6 + 272*t^5 + 567*t^4 + 882*t^3 + 2744*t^2 + 9604*t + 16807 - sage: u.is_weil_polynomial() + sage: u.is_weil_polynomial() # optional - sage.libs.pari True AUTHORS: @@ -8962,21 +9036,21 @@ cdef class Polynomial(CommutativePolynomial): The actual algorithm for computing the extended gcd depends on the base ring underlying the polynomial ring. If the base ring defines - a method ``_xgcd_univariate_polynomial``, then this method will be + a method :meth:`_xgcd_univariate_polynomial`, then this method will be called (see examples below). EXAMPLES:: - sage: R. = QQbar[] - sage: (2*x^2).gcd(2*x) + sage: R. = QQbar[] # optional - sage.rings.number_field + sage: (2*x^2).gcd(2*x) # optional - sage.rings.number_field x - sage: R.zero().gcd(0) + sage: R.zero().gcd(0) # optional - sage.rings.number_field 0 - sage: (2*x).gcd(0) + sage: (2*x).gcd(0) # optional - sage.rings.number_field x One can easily add xgcd functionality to new rings by providing a - method ``_xgcd_univariate_polynomial``:: + method :meth:`_xgcd_univariate_polynomial`:: sage: R. = QQ[] sage: S. = R[] @@ -8985,12 +9059,13 @@ cdef class Polynomial(CommutativePolynomial): sage: h1.xgcd(h2) Traceback (most recent call last): ... - NotImplementedError: Univariate Polynomial Ring in x over Rational Field does not provide an xgcd implementation for univariate polynomials + NotImplementedError: Univariate Polynomial Ring in x over Rational Field + does not provide an xgcd implementation for univariate polynomials sage: T. = QQ[] - sage: def poor_xgcd(f,g): + sage: def poor_xgcd(f, g): ....: ret = S(T(f).gcd(g)) - ....: if ret == f: return ret,S.one(),S.zero() - ....: if ret == g: return ret,S.zero(),S.one() + ....: if ret == f: return ret, S.one(), S.zero() + ....: if ret == g: return ret, S.zero(), S.one() ....: raise NotImplementedError sage: R._xgcd_univariate_polynomial = poor_xgcd sage: h1.xgcd(h2) @@ -9028,10 +9103,10 @@ cdef class Polynomial(CommutativePolynomial): sage: z = PolynomialRing(QQ, 'z').gen() sage: p = -z**16 - z**15 - z**14 + z**13 + z**12 + z**11 - z**5 - z**4 - z**3 + z**2 + z + 1 sage: m = z**21 - sage: n, d = p.rational_reconstruction(m) - sage: print((n ,d)) - (z^4 + 2*z^3 + 3*z^2 + 2*z + 1, z^10 + z^9 + z^8 + z^7 + z^6 + z^5 + z^4 + z^3 + z^2 + z + 1) - sage: print(((p*d - n) % m ).is_zero()) + sage: n, d = p.rational_reconstruction(m); n, d + (z^4 + 2*z^3 + 3*z^2 + 2*z + 1, + z^10 + z^9 + z^8 + z^7 + z^6 + z^5 + z^4 + z^3 + z^2 + z + 1) + sage: ((p*d - n) % m).is_zero() True Over `\ZZ[z]`:: @@ -9039,27 +9114,25 @@ cdef class Polynomial(CommutativePolynomial): sage: z = PolynomialRing(ZZ, 'z').gen() sage: p = -z**16 - z**15 - z**14 + z**13 + z**12 + z**11 - z**5 - z**4 - z**3 + z**2 + z + 1 sage: m = z**21 - sage: n, d = p.rational_reconstruction(m) - sage: print((n ,d)) - (z^4 + 2*z^3 + 3*z^2 + 2*z + 1, z^10 + z^9 + z^8 + z^7 + z^6 + z^5 + z^4 + z^3 + z^2 + z + 1) - sage: print(((p*d - n) % m ).is_zero()) + sage: n, d = p.rational_reconstruction(m); n, d + (z^4 + 2*z^3 + 3*z^2 + 2*z + 1, + z^10 + z^9 + z^8 + z^7 + z^6 + z^5 + z^4 + z^3 + z^2 + z + 1) + sage: ((p*d - n) % m).is_zero() True - Over an integral domain ``d`` might not be monic:: + Over an integral domain, ``d`` might not be monic:: - sage: P = PolynomialRing(ZZ,'x') + sage: P = PolynomialRing(ZZ, 'x') sage: x = P.gen() sage: p = 7*x^5 - 10*x^4 + 16*x^3 - 32*x^2 + 128*x + 256 sage: m = x^5 - sage: n, d = p.rational_reconstruction(m, 3, 2) - sage: print((n ,d)) + sage: n, d = p.rational_reconstruction(m, 3, 2); n, d (-32*x^3 + 384*x^2 + 2304*x + 2048, 5*x + 8) - sage: print(((p*d - n) % m ).is_zero()) + sage: ((p*d - n) % m).is_zero() True - sage: n, d = p.rational_reconstruction(m, 4, 0) - sage: print((n ,d)) + sage: n, d = p.rational_reconstruction(m, 4, 0); n, d (-10*x^4 + 16*x^3 - 32*x^2 + 128*x + 256, 1) - sage: print(((p*d - n) % m ).is_zero()) + sage: ((p*d - n) % m).is_zero() True Over `\QQ(t)[z]`:: @@ -9071,17 +9144,17 @@ cdef class Polynomial(CommutativePolynomial): sage: # p = (1 + t^2*z + z^4) / (1 - t*z) sage: p = (1 + t^2*z + z^4)*(1 - t*z).inverse_mod(z^9) sage: m = z^9 - sage: n, d = p.rational_reconstruction(m) - sage: print((n ,d)) + sage: n, d = p.rational_reconstruction(m); n, d (-1/t*z^4 - t*z - 1/t, z - 1/t) - sage: print(((p*d - n) % m ).is_zero()) + sage: ((p*d - n) % m).is_zero() True sage: w = PowerSeriesRing(P.fraction_field(), 'w').gen() sage: n = -10*t^2*z^4 + (-t^2 + t - 1)*z^3 + (-t - 8)*z^2 + z + 2*t^2 - t sage: d = z^4 + (2*t + 4)*z^3 + (-t + 5)*z^2 + (t^2 + 2)*z + t^2 + 2*t + 1 sage: prec = 9 - sage: nc, dc = Pz((n.subs(z = w)/d.subs(z = w) + O(w^prec)).list()).rational_reconstruction(z^prec) - sage: print( (nc, dc) == (n, d) ) + sage: x = n.subs(z=w)/d.subs(z=w) + O(w^prec) + sage: nc, dc = Pz(x.list()).rational_reconstruction(z^prec) + sage: (nc, dc) == (n, d) True Over `\QQ[t][z]`:: @@ -9092,70 +9165,63 @@ cdef class Polynomial(CommutativePolynomial): sage: # p = (1 + t^2*z + z^4) / (1 - t*z) mod z^9 sage: p = (1 + t^2*z + z^4) * sum((t*z)**i for i in range(9)) sage: m = z^9 - sage: n, d = p.rational_reconstruction(m,) - sage: print((n ,d)) + sage: n, d = p.rational_reconstruction(m,); n, d (-z^4 - t^2*z - 1, t*z - 1) - sage: print(((p*d - n) % m ).is_zero()) + sage: ((p*d - n) % m).is_zero() True Over `\QQ_5`:: - sage: x = PolynomialRing(Qp(5),'x').gen() - sage: p = 4*x^5 + 3*x^4 + 2*x^3 + 2*x^2 + 4*x + 2 - sage: m = x^6 - sage: n, d = p.rational_reconstruction(m, 3, 2) - sage: print(((p*d - n) % m ).is_zero()) + sage: x = PolynomialRing(Qp(5), 'x').gen() # optional - sage.rings.padics + sage: p = 4*x^5 + 3*x^4 + 2*x^3 + 2*x^2 + 4*x + 2 # optional - sage.rings.padics + sage: m = x^6 # optional - sage.rings.padics + sage: n, d = p.rational_reconstruction(m, 3, 2) # optional - sage.rings.padics + sage: ((p*d - n) % m).is_zero() # optional - sage.rings.padics True Can also be used to obtain known Padé approximations:: sage: z = PowerSeriesRing(QQ, 'z').gen() - sage: P = PolynomialRing(QQ,'x') + sage: P = PolynomialRing(QQ, 'x') sage: x = P.gen() - sage: p = P(exp(z).list()) + sage: p = P(z.exp().list()) sage: m = x^5 - sage: n, d = p.rational_reconstruction(m, 4, 0) - sage: print((n ,d)) + sage: n, d = p.rational_reconstruction(m, 4, 0); n, d (1/24*x^4 + 1/6*x^3 + 1/2*x^2 + x + 1, 1) - sage: print(((p*d - n) % m ).is_zero()) + sage: ((p*d - n) % m).is_zero() True sage: m = x^3 - sage: n, d = p.rational_reconstruction(m, 1, 1) - sage: print((n ,d)) + sage: n, d = p.rational_reconstruction(m, 1, 1); n, d (-x - 2, x - 2) - sage: print(((p*d - n) % m ).is_zero()) + sage: ((p*d - n) % m).is_zero() True sage: p = P(log(1-z).list()) sage: m = x^9 - sage: n, d = p.rational_reconstruction(m, 4, 4) - sage: print((n ,d)) + sage: n, d = p.rational_reconstruction(m, 4, 4); n, d (25/6*x^4 - 130/3*x^3 + 105*x^2 - 70*x, x^4 - 20*x^3 + 90*x^2 - 140*x + 70) - sage: print(((p*d - n) % m ).is_zero()) + sage: ((p*d - n) % m).is_zero() True sage: p = P(sqrt(1+z).list()) sage: m = x^6 - sage: n, d = p.rational_reconstruction(m, 3, 2) - sage: print((n ,d)) + sage: n, d = p.rational_reconstruction(m, 3, 2); n, d (1/6*x^3 + 3*x^2 + 8*x + 16/3, x^2 + 16/3*x + 16/3) - sage: print(((p*d - n) % m ).is_zero()) + sage: ((p*d - n) % m).is_zero() True - sage: p = P(exp(2*z).list()) + sage: p = P((2*z).exp().list()) sage: m = x^7 - sage: n, d = p.rational_reconstruction(m, 3, 3) - sage: print((n ,d)) + sage: n, d = p.rational_reconstruction(m, 3, 3); n, d (-x^3 - 6*x^2 - 15*x - 15, x^3 - 6*x^2 + 15*x - 15) - sage: print(((p*d - n) % m ).is_zero()) + sage: ((p*d - n) % m).is_zero() True Over `\RR[z]`:: sage: z = PowerSeriesRing(RR, 'z').gen() - sage: P = PolynomialRing(RR,'x') + sage: P = PolynomialRing(RR, 'x') sage: x = P.gen() - sage: p = P(exp(2*z).list()) + sage: p = P((2*z).exp().list()) sage: m = x^7 - sage: n, d = p.rational_reconstruction(m, 3, 3) - sage: print((n ,d)) # absolute tolerance 1e-10 + sage: n, d = p.rational_reconstruction(m, 3, 3); n, d # absolute tolerance 1e-10 (-x^3 - 6.0*x^2 - 15.0*x - 15.0, x^3 - 6.0*x^2 + 15.0*x - 15.0) .. SEEALSO:: @@ -9266,20 +9332,20 @@ cdef class Polynomial(CommutativePolynomial): `\infty`. If a prime (or non-prime) `p` is given, then the valuation - is the largest power of `p` which divides self. + is the largest power of `p` which divides ``self``. - The valuation at `\infty` is -self.degree(). + The valuation at `\infty` is ``-self.degree()``. EXAMPLES:: sage: P. = ZZ[] - sage: (x^2+x).valuation() + sage: (x^2 + x).valuation() 1 - sage: (x^2+x).valuation(x+1) + sage: (x^2 + x).valuation(x + 1) 1 - sage: (x^2+1).valuation() + sage: (x^2 + 1).valuation() 0 - sage: (x^3+1).valuation(infinity) + sage: (x^3 + 1).valuation(infinity) -3 sage: P(0).valuation() +Infinity @@ -9321,21 +9387,21 @@ cdef class Polynomial(CommutativePolynomial): def ord(self, p=None): r""" - This is the same as the valuation of self at p. See the - documentation for ``self.valuation``. + This is the same as the valuation of ``self`` at `p`. See the + documentation for :meth:`valuation`. EXAMPLES:: sage: R. = ZZ[] - sage: (x^2+x).ord(x+1) + sage: (x^2 + x).ord(x + 1) 1 """ return self.valuation(p) def add_bigoh(self, prec): r""" - Return the power series of precision at most prec got by adding - `O(q^\text{prec})` to self, where q is its variable. + Return the power series of precision at most ``prec`` got by adding + `O(q^\text{prec})` to self, where `q` is its variable. EXAMPLES:: @@ -9358,11 +9424,11 @@ cdef class Polynomial(CommutativePolynomial): EXAMPLES:: sage: R. = ZZ[] - sage: (x^3 + 1).is_irreducible() + sage: (x^3 + 1).is_irreducible() # optional - sage.libs.pari False - sage: (x^2 - 1).is_irreducible() + sage: (x^2 - 1).is_irreducible() # optional - sage.libs.pari False - sage: (x^3 + 2).is_irreducible() + sage: (x^3 + 2).is_irreducible() # optional - sage.libs.pari True sage: R(0).is_irreducible() False @@ -9371,31 +9437,31 @@ cdef class Polynomial(CommutativePolynomial): polynomial in `\QQ[x]`, but not in `\ZZ[x]`:: sage: R. = ZZ[] - sage: R(2*x).is_irreducible() + sage: R(2*x).is_irreducible() # optional - sage.libs.pari False sage: R. = QQ[] - sage: R(2*x).is_irreducible() + sage: R(2*x).is_irreducible() # optional - sage.libs.pari True TESTS:: - sage: F. = NumberField(x^2-5) - sage: Fx. = PolynomialRing(F) - sage: f = Fx([2*t - 5, 5*t - 10, 3*t - 6, -t, -t + 2, 1]) - sage: f.is_irreducible() + sage: F. = NumberField(x^2 - 5) # optional - sage.rings.number_field + sage: Fx. = PolynomialRing(F) # optional - sage.rings.number_field + sage: f = Fx([2*t - 5, 5*t - 10, 3*t - 6, -t, -t + 2, 1]) # optional - sage.rings.number_field + sage: f.is_irreducible() # optional - sage.rings.number_field False - sage: f = Fx([2*t - 3, 5*t - 10, 3*t - 6, -t, -t + 2, 1]) - sage: f.is_irreducible() + sage: f = Fx([2*t - 3, 5*t - 10, 3*t - 6, -t, -t + 2, 1]) # optional - sage.rings.number_field + sage: f.is_irreducible() # optional - sage.rings.number_field True If the base ring implements `_is_irreducible_univariate_polynomial`, then this method gets used instead of the generic algorithm which just factors the input:: - sage: R. = QQbar[] - sage: hasattr(QQbar, "_is_irreducible_univariate_polynomial") + sage: R. = QQbar[] # optional - sage.rings.number_field + sage: hasattr(QQbar, "_is_irreducible_univariate_polynomial") # optional - sage.rings.number_field True - sage: (x^2 + 1).is_irreducible() + sage: (x^2 + 1).is_irreducible() # optional - sage.rings.number_field False Constants can be irreducible if they are not units:: @@ -9403,17 +9469,17 @@ cdef class Polynomial(CommutativePolynomial): sage: R. = ZZ[] sage: R(1).is_irreducible() False - sage: R(4).is_irreducible() + sage: R(4).is_irreducible() # optional - sage.libs.pari False - sage: R(5).is_irreducible() + sage: R(5).is_irreducible() # optional - sage.libs.pari True Check that caching works:: sage: R. = ZZ[] - sage: x.is_irreducible() + sage: x.is_irreducible() # optional - sage.libs.pari True - sage: x.is_irreducible.cache + sage: x.is_irreducible.cache # optional - sage.libs.pari True @@ -9513,13 +9579,13 @@ cdef class Polynomial(CommutativePolynomial): cpdef Polynomial truncate(self, long n): r""" - Return the polynomial of degree ` < n` which is equivalent + Return the polynomial of degree `< n` which is equivalent to self modulo `x^n`. EXAMPLES:: sage: R. = ZZ[]; S. = PolynomialRing(R, sparse=True) - sage: f = y^3 + x*y -3*x; f + sage: f = y^3 + x*y - 3*x; f y^3 + x*y - 3*x sage: f.truncate(2) x*y - 3*x @@ -9538,7 +9604,7 @@ cdef class Polynomial(CommutativePolynomial): @cached_method def is_squarefree(self): """ - Return False if this polynomial is not square-free, i.e., if there is a + Return ``False`` if this polynomial is not square-free, i.e., if there is a non-unit `g` in the polynomial ring such that `g^2` divides ``self``. .. WARNING:: @@ -9550,78 +9616,79 @@ cdef class Polynomial(CommutativePolynomial): EXAMPLES:: sage: R. = QQ[] - sage: f = (x-1)*(x-2)*(x^2-5)*(x^17-3); f + sage: f = (x-1) * (x-2) * (x^2-5) * (x^17-3); f x^21 - 3*x^20 - 3*x^19 + 15*x^18 - 10*x^17 - 3*x^4 + 9*x^3 + 9*x^2 - 45*x + 30 sage: f.is_squarefree() True - sage: (f*(x^2-5)).is_squarefree() + sage: (f * (x^2-5)).is_squarefree() False A generic implementation is available, which relies on gcd computations:: sage: R. = ZZ[] - sage: (2*x).is_squarefree() + sage: (2*x).is_squarefree() # optional - sage.libs.pari True - sage: (4*x).is_squarefree() + sage: (4*x).is_squarefree() # optional - sage.libs.pari False - sage: (2*x^2).is_squarefree() + sage: (2*x^2).is_squarefree() # optional - sage.libs.pari False - sage: R(0).is_squarefree() + sage: R(0).is_squarefree() # optional - sage.libs.pari False - sage: S. = QQ[] - sage: R. = S[] - sage: (2*x*y).is_squarefree() + sage: S. = QQ[] # optional - sage.libs.pari + sage: R. = S[] # optional - sage.libs.pari + sage: (2*x*y).is_squarefree() # optional - sage.libs.pari True - sage: (2*x*y^2).is_squarefree() + sage: (2*x*y^2).is_squarefree() # optional - sage.libs.pari False In positive characteristic, we compute the square-free decomposition or a full factorization, depending on which is available:: - sage: K. = FunctionField(GF(3)) - sage: R. = K[] - sage: (x^3-x).is_squarefree() + sage: K. = FunctionField(GF(3)) # optional - sage.rings.finite_rings + sage: R. = K[] # optional - sage.rings.finite_rings + sage: (x^3 - x).is_squarefree() # optional - sage.rings.finite_rings True - sage: (x^3-1).is_squarefree() + sage: (x^3 - 1).is_squarefree() # optional - sage.rings.finite_rings False - sage: (x^3+t).is_squarefree() + sage: (x^3 + t).is_squarefree() # optional - sage.rings.finite_rings True - sage: (x^3+t^3).is_squarefree() + sage: (x^3 + t^3).is_squarefree() # optional - sage.rings.finite_rings False In the following example, `t^2` is a unit in the base field:: - sage: R(t^2).is_squarefree() + sage: R(t^2).is_squarefree() # optional - sage.rings.finite_rings True This method is not consistent with :meth:`.squarefree_decomposition`:: sage: R. = ZZ[] sage: f = 4 * x - sage: f.is_squarefree() + sage: f.is_squarefree() # optional - sage.rings.finite_rings False - sage: f.squarefree_decomposition() + sage: f.squarefree_decomposition() # optional - sage.rings.finite_rings (4) * x If you want this method equally not to consider the content, you can remove it as in the following example:: sage: c = f.content() - sage: (f/c).is_squarefree() + sage: (f/c).is_squarefree() # optional - sage.rings.finite_rings True If the base ring is not an integral domain, the question is not mathematically well-defined:: sage: R. = IntegerModRing(9)[] - sage: pol = (x + 3)*(x + 6); pol + sage: pol = (x + 3) * (x + 6); pol x^2 sage: pol.is_squarefree() Traceback (most recent call last): ... - TypeError: is_squarefree() is not defined for polynomials over Ring of integers modulo 9 + TypeError: is_squarefree() is not defined for + polynomials over Ring of integers modulo 9 TESTS: @@ -9638,15 +9705,15 @@ cdef class Polynomial(CommutativePolynomial): then this method gets used instead of the generic algorithm in :meth:`_is_squarefree_generic`:: - sage: R. = QQbar[] - sage: (x^2).is_squarefree() + sage: R. = QQbar[] # optional - sage.rings.number_field + sage: (x^2).is_squarefree() # optional - sage.rings.number_field False - sage: hasattr(QQbar, '_is_squarefree_univariate_polynomial') + sage: hasattr(QQbar, '_is_squarefree_univariate_polynomial') # optional - sage.rings.number_field False - sage: QQbar._is_squarefree_univariate_polynomial = lambda self: True - sage: (x^2).is_squarefree() + sage: QQbar._is_squarefree_univariate_polynomial = lambda self: True # optional - sage.rings.number_field + sage: (x^2).is_squarefree() # optional - sage.rings.number_field True - sage: del(QQbar._is_squarefree_univariate_polynomial) + sage: del(QQbar._is_squarefree_univariate_polynomial) # optional - sage.rings.number_field """ B = self._parent.base_ring() @@ -9666,10 +9733,10 @@ cdef class Polynomial(CommutativePolynomial): EXAMPLES:: - sage: R. = QQbar[] - sage: (x^2*(x + 1)).is_squarefree() # indirect doctest + sage: R. = QQbar[] # optional - sage.rings.number_field + sage: (x^2*(x + 1)).is_squarefree() # indirect doctest # optional - sage.rings.number_field False - sage: (x*(x+1)).is_squarefree() # indirect doctest + sage: (x*(x+1)).is_squarefree() # indirect doctest # optional - sage.rings.number_field True """ @@ -9701,12 +9768,12 @@ cdef class Polynomial(CommutativePolynomial): def radical(self): """ - Return the radical of self. + Return the radical of ``self``. Over a field, this is the product of - the distinct irreducible factors of self. (This is also sometimes - called the "square-free part" of self, but that term is ambiguous; - it is sometimes used to mean the quotient of self by its maximal + the distinct irreducible factors of ``self``. (This is also sometimes + called the "square-free part" of ``self``, but that term is ambiguous; + it is sometimes used to mean the quotient of ``self`` by its maximal square factor.) EXAMPLES:: @@ -9720,8 +9787,8 @@ cdef class Polynomial(CommutativePolynomial): If self has a factor of multiplicity divisible by the characteristic (see :trac:`8736`):: - sage: P. = GF(2)[] - sage: (x^3 + x^2).radical() + sage: P. = GF(2)[] # optional - sage.rings.finite_rings + sage: (x^3 + x^2).radical() # optional - sage.rings.finite_rings x^2 + x """ P = self._parent @@ -9847,13 +9914,13 @@ cdef class Polynomial(CommutativePolynomial): 2 sage: R(0).number_of_terms() 0 - sage: f = (x+1)^100 + sage: f = (x + 1)^100 sage: f.number_of_terms() 101 - sage: S = GF(5)['y'] - sage: S(f).number_of_terms() + sage: S = GF(5)['y'] # optional - sage.rings.finite_rings + sage: S(f).number_of_terms() # optional - sage.rings.finite_rings 5 - sage: cyclotomic_polynomial(105).number_of_terms() + sage: cyclotomic_polynomial(105).number_of_terms() # optional - sage.rings.finite_rings 33 The method :meth:`hamming_weight` is an alias:: @@ -9877,29 +9944,29 @@ cdef class Polynomial(CommutativePolynomial): If ``f`` is a :class:`sage.categories.map.Map`, then the resulting polynomial will be defined over the codomain of ``f``. Otherwise, the - resulting polynomial will be over the same ring as self. Set + resulting polynomial will be over the same ring as ``self``. Set ``new_base_ring`` to override this behaviour. INPUT: - - ``f`` -- a callable that will be applied to the coefficients of self. + - ``f`` -- a callable that will be applied to the coefficients of ``self``. - ``new_base_ring`` (optional) -- if given, the resulting polynomial will be defined over this ring. EXAMPLES:: - sage: R. = SR[] - sage: f = (1+I)*x^2 + 3*x - I - sage: f.map_coefficients(lambda z: z.conjugate()) + sage: R. = SR[] # optional - sage.symbolic + sage: f = (1+I)*x^2 + 3*x - I # optional - sage.symbolic + sage: f.map_coefficients(lambda z: z.conjugate()) # optional - sage.symbolic (-I + 1)*x^2 + 3*x + I sage: R. = ZZ[] sage: f = x^2 + 2 sage: f.map_coefficients(lambda a: a + 42) 43*x^2 + 44 - sage: R. = PolynomialRing(SR, sparse=True) - sage: f = (1+I)*x^(2^32) - I - sage: f.map_coefficients(lambda z: z.conjugate()) + sage: R. = PolynomialRing(SR, sparse=True) # optional - sage.symbolic + sage: f = (1+I)*x^(2^32) - I # optional - sage.symbolic + sage: f.map_coefficients(lambda z: z.conjugate()) # optional - sage.symbolic (-I + 1)*x^4294967296 + I sage: R. = PolynomialRing(ZZ, sparse=True) sage: f = x^(2^32) + 2 @@ -9909,21 +9976,21 @@ cdef class Polynomial(CommutativePolynomial): Examples with different base ring:: sage: R. = ZZ[] - sage: k = GF(2) - sage: residue = lambda x: k(x) - sage: f = 4*x^2+x+3 - sage: g = f.map_coefficients(residue); g + sage: k = GF(2) # optional - sage.rings.finite_rings + sage: residue = lambda x: k(x) # optional - sage.rings.finite_rings + sage: f = 4*x^2 + x + 3 # optional - sage.rings.finite_rings + sage: g = f.map_coefficients(residue); g # optional - sage.rings.finite_rings x + 1 - sage: g.parent() + sage: g.parent() # optional - sage.rings.finite_rings Univariate Polynomial Ring in x over Integer Ring - sage: g = f.map_coefficients(residue, new_base_ring = k); g + sage: g = f.map_coefficients(residue, new_base_ring=k); g # optional - sage.rings.finite_rings x + 1 - sage: g.parent() + sage: g.parent() # optional - sage.rings.finite_rings Univariate Polynomial Ring in x over Finite Field of size 2 (using GF2X) - sage: residue = k.coerce_map_from(ZZ) - sage: g = f.map_coefficients(residue); g + sage: residue = k.coerce_map_from(ZZ) # optional - sage.rings.finite_rings + sage: g = f.map_coefficients(residue); g # optional - sage.rings.finite_rings x + 1 - sage: g.parent() + sage: g.parent() # optional - sage.rings.finite_rings Univariate Polynomial Ring in x over Finite Field of size 2 (using GF2X) """ R = self._parent @@ -9954,14 +10021,14 @@ cdef class Polynomial(CommutativePolynomial): INPUT: - ``certificate`` -- boolean, default to ``False``. Only works with - ``algorithm`` set to "pari". + ``algorithm`` set to ``"pari"``. - - ``algorithm`` -- either "pari" or "sage" (default is "pari") + - ``algorithm`` -- either ``"pari"`` or ``"sage"`` (default is ``"pari"``) ALGORITHM: The native algorithm implemented in Sage uses the first - algorithm of [BD1989]_. The algorithm in pari (using + algorithm of [BD1989]_. The algorithm in PARI (using :pari:`poliscyclo`) is more subtle since it does compute the inverse of the Euler `\phi` function to determine the `n` such that the polynomial is the `n`-th cyclotomic polynomial. @@ -9971,38 +10038,40 @@ cdef class Polynomial(CommutativePolynomial): Quick tests:: sage: P. = ZZ['x'] - sage: (x - 1).is_cyclotomic() + sage: (x - 1).is_cyclotomic() # optional - sage.libs.pari True - sage: (x + 1).is_cyclotomic() + sage: (x + 1).is_cyclotomic() # optional - sage.libs.pari True - sage: (x^2 - 1).is_cyclotomic() + sage: (x^2 - 1).is_cyclotomic() # optional - sage.libs.pari False - sage: (x^2 + x + 1).is_cyclotomic(certificate=True) + sage: (x^2 + x + 1).is_cyclotomic(certificate=True) # optional - sage.libs.pari 3 - sage: (x^2 + 2*x + 1).is_cyclotomic(certificate=True) + sage: (x^2 + 2*x + 1).is_cyclotomic(certificate=True) # optional - sage.libs.pari 0 Test first 100 cyclotomic polynomials:: - sage: all(cyclotomic_polynomial(i).is_cyclotomic() for i in range(1,101)) + sage: all(cyclotomic_polynomial(i).is_cyclotomic() for i in range(1, 101)) # optional - sage.libs.pari True Some more tests:: - sage: (x^16 + x^14 - x^10 + x^8 - x^6 + x^2 + 1).is_cyclotomic(algorithm="pari") + sage: f = x^16 + x^14 - x^10 + x^8 - x^6 + x^2 + 1 + sage: f.is_cyclotomic(algorithm="pari") # optional - sage.libs.pari False - sage: (x^16 + x^14 - x^10 + x^8 - x^6 + x^2 + 1).is_cyclotomic(algorithm="sage") + sage: f.is_cyclotomic(algorithm="sage") # optional - sage.libs.pari False - sage: (x^16 + x^14 - x^10 - x^8 - x^6 + x^2 + 1).is_cyclotomic(algorithm="pari") + sage: g = x^16 + x^14 - x^10 - x^8 - x^6 + x^2 + 1 + sage: g.is_cyclotomic(algorithm="pari") # optional - sage.libs.pari True - sage: (x^16 + x^14 - x^10 - x^8 - x^6 + x^2 + 1).is_cyclotomic(algorithm="sage") + sage: g.is_cyclotomic(algorithm="sage") # optional - sage.libs.pari True sage: y = polygen(QQ) - sage: (y/2 - 1/2).is_cyclotomic() + sage: (y/2 - 1/2).is_cyclotomic() # optional - sage.libs.pari False - sage: (2*(y/2 - 1/2)).is_cyclotomic() + sage: (2*(y/2 - 1/2)).is_cyclotomic() # optional - sage.libs.pari True Invalid arguments:: @@ -10014,8 +10083,8 @@ cdef class Polynomial(CommutativePolynomial): Test using other rings:: - sage: z = polygen(GF(5)) - sage: (z - 1).is_cyclotomic() + sage: z = polygen(GF(5)) # optional - sage.rings.finite_rings + sage: (z - 1).is_cyclotomic() # optional - sage.rings.finite_rings Traceback (most recent call last): ... NotImplementedError: not implemented in non-zero characteristic @@ -10023,28 +10092,28 @@ cdef class Polynomial(CommutativePolynomial): TESTS:: sage: R = ZZ['x'] - sage: for _ in range(20): + sage: for _ in range(20): # optional - sage.libs.pari ....: p = R.random_element(degree=randint(10,20)) ....: ans_pari = p.is_cyclotomic(algorithm="pari") ....: ans_sage = p.is_cyclotomic(algorithm="sage") ....: assert ans_pari == ans_sage, "problem with p={}".format(p) - sage: for d in range(2,20): + sage: for d in range(2, 20): # optional - sage.libs.pari ....: p = cyclotomic_polynomial(d) ....: assert p.is_cyclotomic(algorithm="pari"), "pari problem with p={}".format(p) ....: assert p.is_cyclotomic(algorithm="sage"), "sage problem with p={}".format(p) Test the output type when ``certificate=True``:: - sage: type((x^2 - 2).is_cyclotomic(certificate=True)) + sage: type((x^2 - 2).is_cyclotomic(certificate=True)) # optional - sage.libs.pari - sage: type((x -1).is_cyclotomic(certificate=True)) + sage: type((x - 1).is_cyclotomic(certificate=True)) # optional - sage.libs.pari Check that the arguments are forwarded when the input is not a polynomial with coefficients in `\ZZ`:: sage: x = polygen(QQ) - sage: (x-1).is_cyclotomic(certificate=True) + sage: (x - 1).is_cyclotomic(certificate=True) # optional - sage.libs.pari 1 """ S = self.base_ring() @@ -10121,20 +10190,20 @@ cdef class Polynomial(CommutativePolynomial): EXAMPLES:: sage: x = polygen(ZZ) - sage: (x^5 - 1).is_cyclotomic_product() + sage: (x^5 - 1).is_cyclotomic_product() # optional - sage.libs.pari True - sage: (x^5 + x^4 - x^2 + 1).is_cyclotomic_product() + sage: (x^5 + x^4 - x^2 + 1).is_cyclotomic_product() # optional - sage.libs.pari False - sage: p = prod(cyclotomic_polynomial(i) for i in [2,5,7,12]) - sage: p.is_cyclotomic_product() + sage: p = prod(cyclotomic_polynomial(i) for i in [2, 5, 7, 12]) # optional - sage.libs.pari + sage: p.is_cyclotomic_product() # optional - sage.libs.pari True - sage: (x^5 - 1/3).is_cyclotomic_product() + sage: (x^5 - 1/3).is_cyclotomic_product() # optional - sage.libs.pari False sage: x = polygen(Zmod(5)) - sage: (x-1).is_cyclotomic_product() + sage: (x - 1).is_cyclotomic_product() # optional - sage.libs.pari Traceback (most recent call last): ... NotImplementedError: not implemented in non-zero characteristic @@ -10235,12 +10304,12 @@ cdef class Polynomial(CommutativePolynomial): def has_cyclotomic_factor(self): r""" - Return True if the given polynomial has a nontrivial cyclotomic factor. + Return ``True`` if the given polynomial has a nontrivial cyclotomic factor. The algorithm assumes that the polynomial has rational coefficients. If the polynomial is known to be irreducible, it may be slightly more - efficient to call `is_cyclotomic` instead. + efficient to call :meth:`is_cyclotomic` instead. .. SEEALSO:: @@ -10251,12 +10320,12 @@ cdef class Polynomial(CommutativePolynomial): EXAMPLES:: sage: pol. = PolynomialRing(Rationals()) - sage: u = x^5-1; u.has_cyclotomic_factor() + sage: u = x^5 - 1; u.has_cyclotomic_factor() True - sage: u = x^5-2; u.has_cyclotomic_factor() + sage: u = x^5 - 2; u.has_cyclotomic_factor() False - sage: u = pol(cyclotomic_polynomial(7)) * pol.random_element() #random - sage: u.has_cyclotomic_factor() # random + sage: u = pol(cyclotomic_polynomial(7)) * pol.random_element() # random # optional - sage.libs.pari + sage: u.has_cyclotomic_factor() # random # optional - sage.libs.pari True """ if not QQ.has_coerce_map_from(self.base_ring()): @@ -10347,9 +10416,9 @@ cdef class Polynomial(CommutativePolynomial): In positive characteristic, the degree can drop in this case:: - sage: R. = GF(2)[] - sage: f = x + 1 - sage: f.homogenize(x) + sage: R. = GF(2)[] # optional - sage.rings.finite_rings + sage: f = x + 1 # optional - sage.rings.finite_rings + sage: f.homogenize(x) # optional - sage.rings.finite_rings 0 For compatibility with the multivariate case, the parameter ``var`` can @@ -10392,7 +10461,7 @@ cdef class Polynomial(CommutativePolynomial): True sage: P(0).is_homogeneous() True - sage: (x+1).is_homogeneous() + sage: (x + 1).is_homogeneous() False """ return len(self.exponents()) < 2 @@ -10405,7 +10474,7 @@ cdef class Polynomial(CommutativePolynomial): series. This method works only when the base ring is an integral domain. Moreover, for polynomial whose coefficient of lower degree is different from 1, the elements of the base - ring should have a method ``nth_root`` implemented. + ring should have a method :meth:`nth_root` implemented. EXAMPLES:: @@ -10426,43 +10495,43 @@ cdef class Polynomial(CommutativePolynomial): sage: a.nth_root(2) 1/56*x^3 + 103/336*x^2 + 365/252*x + 25/12 - sage: K. = QuadraticField(2) - sage: R. = K[] - sage: a = (x + sqrt2)^3 * ((1+sqrt2)*x - 1/sqrt2)^6 - sage: b = a.nth_root(3); b + sage: K. = QuadraticField(2) # optional - sage.rings.number_field + sage: R. = K[] # optional - sage.rings.number_field + sage: a = (x + sqrt2)^3 * ((1+sqrt2)*x - 1/sqrt2)^6 # optional - sage.rings.number_field + sage: b = a.nth_root(3); b # optional - sage.rings.number_field (2*sqrt2 + 3)*x^3 + (2*sqrt2 + 2)*x^2 + (-2*sqrt2 - 3/2)*x + 1/2*sqrt2 - sage: b^3 == a + sage: b^3 == a # optional - sage.rings.number_field True - sage: R. = QQbar[] - sage: p = x**3 + QQbar(2).sqrt() * x - QQbar(3).sqrt() - sage: r = (p**5).nth_root(5) - sage: r * p[0] == p * r[0] + sage: R. = QQbar[] # optional - sage.rings.number_field + sage: p = x**3 + QQbar(2).sqrt() * x - QQbar(3).sqrt() # optional - sage.rings.number_field + sage: r = (p**5).nth_root(5) # optional - sage.rings.number_field + sage: r * p[0] == p * r[0] # optional - sage.rings.number_field True - sage: p = (x+1)^20 + x^20 - sage: p.nth_root(20) + sage: p = (x+1)^20 + x^20 # optional - sage.rings.number_field + sage: p.nth_root(20) # optional - sage.rings.number_field Traceback (most recent call last): ... ValueError: not a 20th power - sage: z = GF(4).gen() - sage: R. = GF(4)[] - sage: p = z*x**4 + 2*x - 1 - sage: r = (p**15).nth_root(15) - sage: r * p[0] == p * r[0] + sage: z = GF(4).gen() # optional - sage.rings.finite_rings + sage: R. = GF(4)[] # optional - sage.rings.finite_rings + sage: p = z*x**4 + 2*x - 1 # optional - sage.rings.finite_rings + sage: r = (p**15).nth_root(15) # optional - sage.rings.finite_rings + sage: r * p[0] == p * r[0] # optional - sage.rings.finite_rings True - sage: ((x+1)**2).nth_root(2) + sage: ((x+1)**2).nth_root(2) # optional - sage.rings.finite_rings x + 1 - sage: ((x+1)**4).nth_root(4) + sage: ((x+1)**4).nth_root(4) # optional - sage.rings.finite_rings x + 1 - sage: ((x+1)**12).nth_root(12) + sage: ((x+1)**12).nth_root(12) # optional - sage.rings.finite_rings x + 1 - sage: (x^4 + x^3 + 1).nth_root(2) + sage: (x^4 + x^3 + 1).nth_root(2) # optional - sage.rings.finite_rings Traceback (most recent call last): ... ValueError: not a 2nd power - sage: p = (x+1)^17 + x^17 - sage: r = p.nth_root(17) + sage: p = (x+1)^17 + x^17 # optional - sage.rings.finite_rings + sage: r = p.nth_root(17) # optional - sage.rings.finite_rings Traceback (most recent call last): ... ValueError: not a 17th power @@ -10479,14 +10548,14 @@ cdef class Polynomial(CommutativePolynomial): example with a non-trivial coefficient of lowest degree raises an error:: sage: R. = QQ[] - sage: R2 = R.quotient(x**2 + 1) - sage: x = R2.gen() - sage: R3. = R2[] - sage: (y**2 - 2*y + 1).nth_root(2) + sage: R2 = R.quotient(x**2 + 1) # optional - sage.libs.pari + sage: x = R2.gen() # optional - sage.libs.pari + sage: R3. = R2[] # optional - sage.libs.pari + sage: (y**2 - 2*y + 1).nth_root(2) # optional - sage.libs.pari -y + 1 - sage: (y**3).nth_root(3) + sage: (y**3).nth_root(3) # optional - sage.libs.pari y - sage: (y**2 + x).nth_root(2) + sage: (y**2 + x).nth_root(2) # optional - sage.libs.pari Traceback (most recent call last): ... AttributeError: ... has no attribute 'nth_root' @@ -10522,7 +10591,7 @@ cdef class Polynomial(CommutativePolynomial): Some random tests:: - sage: for R in [QQ['x'], GF(4)['x']]: + sage: for R in [QQ['x'], GF(4)['x']]: # optional - sage.rings.finite_rings ....: for _ in range(30): ....: p = R.random_element(degree=randint(10,20)) ....: n = ZZ.random_element(2,20) @@ -10606,10 +10675,10 @@ cdef class Polynomial(CommutativePolynomial): sage: R.one()._nth_root_series(3, 5) 1 - sage: R. = QQbar[] - sage: p = 2 + 3*x^2 - sage: q = p._nth_root_series(3, 20) - sage: (q**3).truncate(20) + sage: R. = QQbar[] # optional - sage.rings.number_field + sage: p = 2 + 3*x^2 # optional - sage.rings.number_field + sage: q = p._nth_root_series(3, 20) # optional - sage.rings.number_field + sage: (q**3).truncate(20) # optional - sage.rings.number_field 3*x^2 + 2 The exponent must be invertible in the base ring:: @@ -10631,12 +10700,12 @@ cdef class Polynomial(CommutativePolynomial): Finite characteristic:: - sage: R. = GF(2)[] - sage: (1 + x)._nth_root_series(3, 10) + sage: R. = GF(2)[] # optional - sage.rings.finite_rings + sage: (1 + x)._nth_root_series(3, 10) # optional - sage.rings.finite_rings x^9 + x^8 + x^3 + x^2 + x + 1 - sage: (1 + x^2)._nth_root_series(2, 10) + sage: (1 + x^2)._nth_root_series(2, 10) # optional - sage.rings.finite_rings x + 1 - sage: (1 + x)._nth_root_series(2, 10) + sage: (1 + x)._nth_root_series(2, 10) # optional - sage.rings.finite_rings Traceback (most recent call last): ... ValueError: not a 2nd power @@ -10715,7 +10784,7 @@ cdef class Polynomial(CommutativePolynomial): @coerce_binop def divides(self, p): r""" - Return `True` if this polynomial divides `p`. + Return ``True`` if this polynomial divides `p`. This method is only implemented for polynomials over an integral domain. @@ -10749,21 +10818,21 @@ cdef class Polynomial(CommutativePolynomial): TESTS:: - sage: R. = PolynomialRing(ZZ, implementation="NTL") - sage: (2*x + 1).divides(4*x**2 + 1) + sage: R. = PolynomialRing(ZZ, implementation="NTL") # optional - sage.libs.ntl + sage: (2*x + 1).divides(4*x**2 + 1) # optional - sage.libs.ntl False - sage: K. = GF(4) - sage: R. = K[] - sage: S. = R[] - sage: p = ((3*z + 2)*x + 2*z - 1) * y + 2*x + z - sage: q = y^2 + z*y*x + 2*y + z - sage: p.divides(q), p.divides(p*q) + sage: K. = GF(4) # optional - sage.rings.finite_rings + sage: R. = K[] # optional - sage.rings.finite_rings + sage: S. = R[] # optional - sage.rings.finite_rings + sage: p = ((3*z + 2)*x + 2*z - 1) * y + 2*x + z # optional - sage.rings.finite_rings + sage: q = y^2 + z*y*x + 2*y + z # optional - sage.rings.finite_rings + sage: p.divides(q), p.divides(p*q) # optional - sage.rings.finite_rings (False, True) - sage: R. = GF(2)[] - sage: S. = R[] - sage: p = (x+y+1) * z + x*y - sage: q = (y^2-x^2) * z^2 + z + x-y - sage: p.divides(q), p.divides(p*q) + sage: R. = GF(2)[] # optional - sage.rings.finite_rings + sage: S. = R[] # optional - sage.rings.finite_rings + sage: p = (x+y+1) * z + x*y # optional - sage.rings.finite_rings + sage: q = (y^2-x^2) * z^2 + z + x-y # optional - sage.rings.finite_rings + sage: p.divides(q), p.divides(p*q) # optional - sage.rings.finite_rings (False, True) """ if not self.base_ring().is_integral_domain(): @@ -10799,7 +10868,7 @@ cdef class Polynomial(CommutativePolynomial): - ``D`` -- dictionary (optional) - - ``phi`` -- SpecializationMorphism (optional) + - ``phi`` -- :class:`SpecializationMorphism` (optional) OUTPUT: a new polynomial @@ -11002,8 +11071,8 @@ cdef list do_schoolbook_product(list x, list y, Py_ssize_t deg): INPUT: - - ``x``, ``y``: lists of coefficients - - ``deg``: degree at which the output should be truncated, + - ``x``, ``y`` -- lists of coefficients + - ``deg`` -- degree at which the output should be truncated, negative values mean not to truncate at all TESTS: @@ -11241,7 +11310,7 @@ cdef class Polynomial_generic_dense(Polynomial): sage: R. = QQ[] sage: S = R['y'] - sage: S((x^2, 2, 1+x)) + sage: S((x^2, 2, 1 + x)) (x + 1)*y^2 + 2*y + x^2 """ def __init__(self, parent, x=None, int check=1, is_gen=False, int construct=0, **kwds): @@ -11362,14 +11431,14 @@ cdef class Polynomial_generic_dense(Polynomial): EXAMPLES:: - sage: R. = SR[] - sage: R(0).is_term() + sage: R. = SR[] # optional - sage.symbolic + sage: R(0).is_term() # optional - sage.symbolic False - sage: R(1).is_term() + sage: R(1).is_term() # optional - sage.symbolic True - sage: (3*x^5).is_term() + sage: (3*x^5).is_term() # optional - sage.symbolic True - sage: (1+3*x^5).is_term() + sage: (1 + 3*x^5).is_term() # optional - sage.symbolic False """ if not self.__coeffs: @@ -11493,30 +11562,30 @@ cdef class Polynomial_generic_dense(Polynomial): EXAMPLES:: - sage: R. = QQbar[] - sage: f = (1+2*x)^3 + 3*x; f + sage: R. = QQbar[] # optional - sage.rings.number_field + sage: f = (1+2*x)^3 + 3*x; f # optional - sage.rings.number_field 8*x^3 + 12*x^2 + 9*x + 1 - sage: g = f // (1+2*x); g + sage: g = f // (1+2*x); g # optional - sage.rings.number_field 4*x^2 + 4*x + 5/2 - sage: f - g * (1+2*x) + sage: f - g * (1+2*x) # optional - sage.rings.number_field -3/2 - sage: f.quo_rem(1+2*x) + sage: f.quo_rem(1+2*x) # optional - sage.rings.number_field (4*x^2 + 4*x + 5/2, -3/2) TESTS: Check that :trac:`13048` and :trac:`2034` are fixed:: - sage: R. = QQbar[] - sage: x // x + sage: R. = QQbar[] # optional - sage.rings.number_field + sage: x // x # optional - sage.rings.number_field 1 - sage: x // 1 + sage: x // 1 # optional - sage.rings.number_field x - sage: x // int(1) + sage: x // int(1) # optional - sage.rings.number_field x - sage: x //= int(1); x + sage: x //= int(1); x # optional - sage.rings.number_field x - sage: int(1) // x # check that this doesn't segfault + sage: int(1) // x # check that this doesn't segfault # optional - sage.rings.number_field Traceback (most recent call last): ... AttributeError: type object 'int' has no attribute 'base_ring' @@ -11609,8 +11678,7 @@ cdef class Polynomial_generic_dense(Polynomial): """ Return the constant coefficient of this polynomial. - OUTPUT: - element of base ring + OUTPUT: element of base ring EXAMPLES:: @@ -11631,10 +11699,10 @@ cdef class Polynomial_generic_dense(Polynomial): EXAMPLES:: - sage: R. = GF(17)[] - sage: f = (1+2*x)^3 + 3*x; f + sage: R. = GF(17)[] # optional - sage.rings.finite_rings + sage: f = (1+2*x)^3 + 3*x; f # optional - sage.rings.finite_rings 8*x^3 + 12*x^2 + 9*x + 1 - sage: f.list() + sage: f.list() # optional - sage.rings.finite_rings [1, 9, 12, 8] """ if copy: @@ -11711,8 +11779,8 @@ cdef class Polynomial_generic_dense(Polynomial): Return the quotient and remainder of the Euclidean division of ``self`` and ``other``. - Raises a ``ZerodivisionError`` if ``other`` is zero. Raises an - ``ArithmeticError`` if the division is not exact. + Raises a :class:`ZeroDivisionError` if ``other`` is zero. Raises an + :class:`ArithmeticError` if the division is not exact. EXAMPLES:: @@ -11727,7 +11795,8 @@ cdef class Polynomial_generic_dense(Polynomial): sage: f.quo_rem(g) Traceback (most recent call last): ... - ArithmeticError: division non exact (consider coercing to polynomials over the fraction field) + ArithmeticError: division non exact (consider coercing + to polynomials over the fraction field) sage: g = 0 sage: f.quo_rem(g) Traceback (most recent call last): @@ -11737,12 +11806,12 @@ cdef class Polynomial_generic_dense(Polynomial): Polynomials over noncommutative rings are also allowed (after :trac:`34733`):: - sage: HH = QuaternionAlgebra(QQ, -1, -1) - sage: P. = HH[] - sage: f = P.random_element(5) - sage: g = P.random_element((0, 5)) - sage: q, r = f.quo_rem(g) - sage: f == q*g + r + sage: HH = QuaternionAlgebra(QQ, -1, -1) # optional - sage.combinat sage.modules + sage: P. = HH[] # optional - sage.combinat sage.modules + sage: f = P.random_element(5) # optional - sage.combinat sage.modules + sage: g = P.random_element((0, 5)) # optional - sage.combinat sage.modules + sage: q, r = f.quo_rem(g) # optional - sage.combinat sage.modules + sage: f == q*g + r # optional - sage.combinat sage.modules True TESTS: @@ -11812,19 +11881,19 @@ cdef class Polynomial_generic_dense(Polynomial): cpdef Polynomial truncate(self, long n): r""" - Return the polynomial of degree ` < n` which is equivalent + Return the polynomial of degree `< n` which is equivalent to self modulo `x^n`. EXAMPLES:: sage: S. = QQ['t']['q'] - sage: f = (1+q^10+q^11+q^12).truncate(11); f + sage: f = (1 + q^10 + q^11 + q^12).truncate(11); f q^10 + 1 - sage: f = (1+q^10+q^100).truncate(50); f + sage: f = (1 + q^10 + q^100).truncate(50); f q^10 + 1 sage: f.degree() 10 - sage: f = (1+q^10+q^100).truncate(500); f + sage: f = (1 + q^10 + q^100).truncate(500); f q^100 + q^10 + 1 TESTS: @@ -11874,13 +11943,13 @@ def universal_discriminant(n): EXAMPLES:: sage: from sage.rings.polynomial.polynomial_element import universal_discriminant - sage: universal_discriminant(1) + sage: universal_discriminant(1) # optional - sage.libs.pari 1 - sage: universal_discriminant(2) + sage: universal_discriminant(2) # optional - sage.libs.pari a1^2 - 4*a0*a2 - sage: universal_discriminant(3) + sage: universal_discriminant(3) # optional - sage.libs.pari a1^2*a2^2 - 4*a0*a2^3 - 4*a1^3*a3 + 18*a0*a1*a2*a3 - 27*a0^2*a3^2 - sage: universal_discriminant(4).degrees() + sage: universal_discriminant(4).degrees() # optional - sage.libs.pari (3, 4, 4, 4, 3) .. SEEALSO:: @@ -11902,7 +11971,7 @@ cpdef Polynomial generic_power_trunc(Polynomial p, Integer n, long prec): - ``n`` - an integer (of type :class:`sage.rings.integer.Integer`) - - ``prec`` - a precision (should fit into a C long) + - ``prec`` - a precision (should fit into a C ``long``) TESTS: @@ -11910,7 +11979,7 @@ cpdef Polynomial generic_power_trunc(Polynomial p, Integer n, long prec): sage: from sage.rings.polynomial.polynomial_element import generic_power_trunc - sage: for S in [ZZ, GF(3)]: # known bug # not tested (see :trac:`32075`) + sage: for S in [ZZ, GF(3)]: # known bug # not tested (see :trac:`32075`) # optional - sage.rings.finite_rings ....: R = PolynomialRing(S, 'x') ....: for _ in range(100): ....: p = R.random_element() @@ -12010,9 +12079,9 @@ cdef class Polynomial_generic_dense_inexact(Polynomial_generic_dense): Coefficients indistinguishable from 0 are not removed. - sage: R = Zp(5) - sage: S. = R[] - sage: S([1,R(0,20)]) + sage: R = Zp(5) # optional - sage.rings.padics + sage: S. = R[] # optional - sage.rings.padics + sage: S([1, R(0, 20)]) # optional - sage.rings.padics O(5^20)*x + 1 + O(5^20) """ cdef list x = self.__coeffs @@ -12030,43 +12099,41 @@ cdef class Polynomial_generic_dense_inexact(Polynomial_generic_dense): r""" INPUT: - - secure -- a boolean (default: False) + - ``secure`` -- a boolean (default: ``False``) - OUTPUT: - - The degree of self. + OUTPUT: The degree of ``self``. - If ``secure`` is True and the degree of this polynomial + If ``secure`` is ``True`` and the degree of this polynomial is not determined (because the leading coefficient is indistinguishable from 0), an error is raised - If ``secure`` is False, the returned value is the largest + If ``secure`` is ``False``, the returned value is the largest `n` so that the coefficient of `x^n` does not compare equal to `0`. EXAMPLES:: - sage: K = Qp(3,10) - sage: R. = K[] - sage: f = T + 2; f + sage: K = Qp(3, 10) # optional - sage.rings.padics + sage: R. = K[] # optional - sage.rings.padics + sage: f = T + 2; f # optional - sage.rings.padics (1 + O(3^10))*T + 2 + O(3^10) - sage: f.degree() + sage: f.degree() # optional - sage.rings.padics 1 - sage: (f-T).degree() + sage: (f - T).degree() # optional - sage.rings.padics 0 - sage: (f-T).degree(secure=True) + sage: (f - T).degree(secure=True) # optional - sage.rings.padics Traceback (most recent call last): ... PrecisionError: the leading coefficient is indistinguishable from 0 - sage: x = O(3^5) - sage: li = [3^i * x for i in range(0,5)]; li + sage: x = O(3^5) # optional - sage.rings.padics + sage: li = [3^i * x for i in range(0,5)]; li # optional - sage.rings.padics [O(3^5), O(3^6), O(3^7), O(3^8), O(3^9)] - sage: f = R(li); f + sage: f = R(li); f # optional - sage.rings.padics O(3^9)*T^4 + O(3^8)*T^3 + O(3^7)*T^2 + O(3^6)*T + O(3^5) - sage: f.degree() + sage: f.degree() # optional - sage.rings.padics -1 - sage: f.degree(secure=True) + sage: f.degree(secure=True) # optional - sage.rings.padics Traceback (most recent call last): ... PrecisionError: the leading coefficient is indistinguishable from 0 @@ -12098,20 +12165,20 @@ cdef class Polynomial_generic_dense_inexact(Polynomial_generic_dense): EXAMPLES:: - sage: K = Qp(3,10) - sage: R. = K[] - sage: f = T + 2; f + sage: K = Qp(3, 10) # optional - sage.rings.padics + sage: R. = K[] # optional - sage.rings.padics + sage: f = T + 2; f # optional - sage.rings.padics (1 + O(3^10))*T + 2 + O(3^10) - sage: f.degree() + sage: f.degree() # optional - sage.rings.padics 1 - sage: f.prec_degree() + sage: f.prec_degree() # optional - sage.rings.padics 1 - sage: g = f - T; g + sage: g = f - T; g # optional - sage.rings.padics O(3^10)*T + 2 + O(3^10) - sage: g.degree() + sage: g.degree() # optional - sage.rings.padics 0 - sage: g.prec_degree() + sage: g.prec_degree() # optional - sage.rings.padics 1 AUTHOR: @@ -12125,25 +12192,25 @@ cdef class ConstantPolynomialSection(Map): """ This class is used for conversion from a polynomial ring to its base ring. - Since :trac:`9944`, it calls the ``constant_coefficient`` method, + Since :trac:`9944`, it calls the :meth:`constant_coefficient` method, which can be optimized for a particular polynomial type. EXAMPLES:: - sage: P0. = GF(3)[] - sage: P1. = GF(3)[] - sage: P0(-y_1) # indirect doctest + sage: P0. = GF(3)[] # optional - sage.rings.finite_rings + sage: P1. = GF(3)[] # optional - sage.rings.finite_rings + sage: P0(-y_1) # indirect doctest # optional - sage.rings.finite_rings 2*y_1 - sage: phi = GF(3).convert_map_from(P0); phi + sage: phi = GF(3).convert_map_from(P0); phi # optional - sage.rings.finite_rings Generic map: From: Univariate Polynomial Ring in y_1 over Finite Field of size 3 To: Finite Field of size 3 - sage: type(phi) + sage: type(phi) # optional - sage.rings.finite_rings - sage: phi(P0.one()) + sage: phi(P0.one()) # optional - sage.rings.finite_rings 1 - sage: phi(y_1) + sage: phi(y_1) # optional - sage.rings.finite_rings Traceback (most recent call last): ... TypeError: not a constant polynomial @@ -12180,12 +12247,12 @@ cdef class PolynomialBaseringInjection(Morphism): This class is used for conversion from a ring to a polynomial over that ring. - It calls the _new_constant_poly method on the generator, + It calls the :meth:`_new_constant_poly` method on the generator, which should be optimized for a particular polynomial type. Technically, it should be a method of the polynomial ring, but - few polynomial rings are cython classes, and so, as a method - of a cython polynomial class, it is faster. + few polynomial rings are Cython classes, and so, as a method + of a Cython polynomial class, it is faster. EXAMPLES: @@ -12194,16 +12261,18 @@ cdef class PolynomialBaseringInjection(Morphism): supposed to be the fastest maps for that purpose. See :trac:`9944`. :: - sage: R. = Qp(3)[] - sage: R.coerce_map_from(R.base_ring()) + sage: R. = Qp(3)[] # optional - sage.rings.padics + sage: R.coerce_map_from(R.base_ring()) # optional - sage.rings.padics Polynomial base injection morphism: From: 3-adic Field with capped relative precision 20 - To: Univariate Polynomial Ring in x over 3-adic Field with capped relative precision 20 - sage: R. = Qp(3)[] - sage: R.coerce_map_from(R.base_ring()) + To: Univariate Polynomial Ring in x over + 3-adic Field with capped relative precision 20 + sage: R. = Qp(3)[] # optional - sage.rings.padics + sage: R.coerce_map_from(R.base_ring()) # optional - sage.rings.padics Polynomial base injection morphism: From: 3-adic Field with capped relative precision 20 - To: Multivariate Polynomial Ring in x, y over 3-adic Field with capped relative precision 20 + To: Multivariate Polynomial Ring in x, y over + 3-adic Field with capped relative precision 20 sage: R. = QQ[] sage: R.coerce_map_from(R.base_ring()) Polynomial base injection morphism: @@ -12242,11 +12311,11 @@ cdef class PolynomialBaseringInjection(Morphism): :: - sage: R. = Qp(2)[] - sage: f = R.convert_map_from(R.base_ring()) # indirect doctest - sage: f(Qp(2).one()*3) + sage: R. = Qp(2)[] # optional - sage.rings.padics + sage: f = R.convert_map_from(R.base_ring()) # indirect doctest # optional - sage.rings.padics + sage: f(Qp(2).one()*3) # optional - sage.rings.padics 1 + 2 + O(2^20) - sage: (Qp(2).one()*3)*t + sage: (Qp(2).one()*3)*t # optional - sage.rings.padics (1 + 2 + O(2^20))*t """ assert codomain.base_ring() is domain, "domain must be basering" @@ -12310,8 +12379,8 @@ cdef class PolynomialBaseringInjection(Morphism): TESTS:: sage: from sage.rings.polynomial.polynomial_element import PolynomialBaseringInjection - sage: m = PolynomialBaseringInjection(Qp(5), Qp(5)['x']) - sage: m(1 + O(5^11), absprec = 5) # indirect doctest + sage: m = PolynomialBaseringInjection(Qp(5), Qp(5)['x']) # optional - sage.rings.padics + sage: m(1 + O(5^11), absprec=5) # indirect doctest # optional - sage.rings.padics 1 + O(5^11) """ try: diff --git a/src/sage/rings/polynomial/polynomial_element_generic.py b/src/sage/rings/polynomial/polynomial_element_generic.py index 78692bc93d8..2f012daca29 100644 --- a/src/sage/rings/polynomial/polynomial_element_generic.py +++ b/src/sage/rings/polynomial/polynomial_element_generic.py @@ -12,12 +12,12 @@ We test coercion in a particularly complicated situation:: - sage: W.=QQ['w'] - sage: WZ.=W['z'] - sage: m = matrix(WZ,2,2,[1,z,z,z^2]) - sage: a = m.charpoly() - sage: R. = WZ[] - sage: R(a) + sage: W. = QQ['w'] + sage: WZ. = W['z'] + sage: m = matrix(WZ, 2, 2, [1, z, z, z^2]) # optional - sage.modules + sage: a = m.charpoly() # optional - sage.modules + sage: R. = WZ[] # optional - sage.modules + sage: R(a) # optional - sage.modules x^2 + (-z^2 - 1)*x """ @@ -65,13 +65,15 @@ class Polynomial_generic_sparse(Polynomial): A more extensive example:: - sage: A. = PolynomialRing(Integers(5),sparse=True) ; f = T^2+1 ; B = A.quo(f) - sage: C. = PolynomialRing(B) - sage: C - Univariate Polynomial Ring in s over Univariate Quotient Polynomial Ring in Tbar over Ring of integers modulo 5 with modulus T^2 + 1 - sage: s + T + sage: A. = PolynomialRing(Integers(5), sparse=True) # optional - sage.libs.pari + sage: f = T^2 + 1; B = A.quo(f) # optional - sage.libs.pari + sage: C. = PolynomialRing(B) # optional - sage.libs.pari + sage: C # optional - sage.libs.pari + Univariate Polynomial Ring in s over Univariate Quotient Polynomial Ring in Tbar + over Ring of integers modulo 5 with modulus T^2 + 1 + sage: s + T # optional - sage.libs.pari s + Tbar - sage: (s + T)**2 + sage: (s + T)**2 # optional - sage.libs.pari s^2 + 2*Tbar*s + 4 """ @@ -188,13 +190,13 @@ def valuation(self, p=None): EXAMPLES:: - sage: R. = PolynomialRing(GF(9,'a'), sparse=True) - sage: f = w^1997 - w^10000 - sage: f.valuation() + sage: R. = PolynomialRing(GF(9, 'a'), sparse=True) # optional - sage.rings.finite_rings + sage: f = w^1997 - w^10000 # optional - sage.rings.finite_rings + sage: f.valuation() # optional - sage.rings.finite_rings 1997 - sage: R(19).valuation() + sage: R(19).valuation() # optional - sage.rings.finite_rings 0 - sage: R(0).valuation() + sage: R(0).valuation() # optional - sage.rings.finite_rings +Infinity """ if not self.__coeffs: @@ -243,10 +245,10 @@ def _derivative(self, var=None): Check that :trac:`28187` is fixed:: sage: R = PolynomialRing(ZZ, 't', sparse=True) - sage: t, u = var('t, u') - sage: R.gen()._derivative(t) + sage: t, u = var('t, u') # optional - sage.symbolic + sage: R.gen()._derivative(t) # optional - sage.symbolic 1 - sage: R.gen()._derivative(u) + sage: R.gen()._derivative(u) # optional - sage.symbolic Traceback (most recent call last): ... ValueError: cannot differentiate with respect to u @@ -417,14 +419,14 @@ def __getitem__(self, n): EXAMPLES:: sage: R. = PolynomialRing(RDF, sparse=True) - sage: e = RDF(e) - sage: f = sum(e^n*w^n for n in range(4)); f # abs tol 1.1e-14 + sage: e = RDF(e) # optional - sage.symbolic + sage: f = sum(e^n*w^n for n in range(4)); f # abs tol 1.1e-14 # optional - sage.symbolic 20.085536923187664*w^3 + 7.3890560989306495*w^2 + 2.718281828459045*w + 1.0 - sage: f[1] # abs tol 5e-16 + sage: f[1] # abs tol 5e-16 # optional - sage.symbolic 2.718281828459045 - sage: f[5] + sage: f[5] # optional - sage.symbolic 0.0 - sage: f[-1] + sage: f[-1] # optional - sage.symbolic 0.0 sage: R. = PolynomialRing(RealField(19), sparse=True) sage: f = (2-3.5*x)^3; f @@ -547,14 +549,14 @@ def __floordiv__(self, right): EXAMPLES:: - sage: R. = PolynomialRing(QQbar, sparse=True) - sage: f = (1+2*x)^3 + 3*x; f + sage: R. = PolynomialRing(QQbar, sparse=True) # optional - sage.rings.number_field + sage: f = (1+2*x)^3 + 3*x; f # optional - sage.rings.number_field 8*x^3 + 12*x^2 + 9*x + 1 - sage: g = f // (1+2*x); g + sage: g = f // (1+2*x); g # optional - sage.rings.number_field 4*x^2 + 4*x + 5/2 - sage: f - g * (1+2*x) + sage: f - g * (1+2*x) # optional - sage.rings.number_field -3/2 - sage: f.quo_rem(1+2*x) + sage: f.quo_rem(1+2*x) # optional - sage.rings.number_field (4*x^2 + 4*x + 5/2, -3/2) """ @@ -734,7 +736,7 @@ def _richcmp_(self, other, op): def shift(self, n): r""" - Returns this polynomial multiplied by the power `x^n`. + Return this polynomial multiplied by the power `x^n`. If `n` is negative, terms below `x^n` will be discarded. Does not change this polynomial. @@ -785,12 +787,12 @@ def shift(self, n): @coerce_binop def quo_rem(self, other): """ - Returns the quotient and remainder of the Euclidean division of + Return the quotient and remainder of the Euclidean division of ``self`` and ``other``. - Raises ZerodivisionError if ``other`` is zero. + Raises :class:`ZeroDivisionError` if ``other`` is zero. - Raises ArithmeticError if ``other`` has a nonunit leading coefficient + Raises :class:`ArithmeticError` if ``other`` has a nonunit leading coefficient and this causes the Euclidean division to fail. EXAMPLES:: @@ -808,7 +810,8 @@ def quo_rem(self, other): sage: f.quo_rem(g) Traceback (most recent call last): ... - ArithmeticError: Division non exact (consider coercing to polynomials over the fraction field) + ArithmeticError: Division non exact + (consider coercing to polynomials over the fraction field) sage: g = 0 sage: f.quo_rem(g) Traceback (most recent call last): @@ -824,12 +827,12 @@ def quo_rem(self, other): Polynomials over noncommutative rings are also allowed:: - sage: HH = QuaternionAlgebra(QQ, -1, -1) - sage: P. = PolynomialRing(HH, sparse=True) - sage: f = P.random_element(5) - sage: g = P.random_element((0, 5)) - sage: q, r = f.quo_rem(g) - sage: f == q*g + r + sage: HH = QuaternionAlgebra(QQ, -1, -1) # optional - sage.combinat sage.modules + sage: P. = PolynomialRing(HH, sparse=True) # optional - sage.combinat sage.modules + sage: f = P.random_element(5) # optional - sage.combinat sage.modules + sage: g = P.random_element((0, 5)) # optional - sage.combinat sage.modules + sage: q, r = f.quo_rem(g) # optional - sage.combinat sage.modules + sage: f == q*g + r # optional - sage.combinat sage.modules True TESTS:: @@ -892,7 +895,7 @@ def quo_rem(self, other): @coerce_binop def gcd(self,other,algorithm=None): - """ + r""" Return the gcd of this polynomial and ``other`` INPUT: @@ -904,27 +907,27 @@ def gcd(self,other,algorithm=None): Two algorithms are provided: - - ``generic``: Uses the generic implementation, which depends on the + - ``generic`` -- Uses the generic implementation, which depends on the base ring being a UFD or a field. - - ``dense``: The polynomials are converted to the dense representation, + - ``dense`` -- The polynomials are converted to the dense representation, their gcd is computed and is converted back to the sparse representation. - Default is ``dense`` for polynomials over ZZ and ``generic`` in the + Default is ``dense`` for polynomials over `\ZZ` and ``generic`` in the other cases. EXAMPLES:: - sage: R. = PolynomialRing(ZZ,sparse=True) + sage: R. = PolynomialRing(ZZ, sparse=True) sage: p = x^6 + 7*x^5 + 8*x^4 + 6*x^3 + 2*x^2 + x + 2 sage: q = 2*x^4 - x^3 - 2*x^2 - 4*x - 1 - sage: gcd(p,q) + sage: gcd(p, q) x^2 + x + 1 - sage: gcd(p, q, algorithm = "dense") + sage: gcd(p, q, algorithm="dense") x^2 + x + 1 - sage: gcd(p, q, algorithm = "generic") + sage: gcd(p, q, algorithm="generic") x^2 + x + 1 - sage: gcd(p, q, algorithm = "foobar") + sage: gcd(p, q, algorithm="foobar") Traceback (most recent call last): ... ValueError: Unknown algorithm 'foobar' @@ -971,7 +974,7 @@ def reverse(self, degree=None): """ Return this polynomial but with the coefficients reversed. - If an optional degree argument is given the coefficient list will be + If an optional degree argument is given, the coefficient list will be truncated or zero padded as necessary and the reverse polynomial will have the specified degree. @@ -993,7 +996,7 @@ def reverse(self, degree=None): def truncate(self, n): """ - Return the polynomial of degree `< n` equal to `self` modulo `x^n`. + Return the polynomial of degree `< n` equal to ``self`` modulo `x^n`. EXAMPLES:: @@ -1011,7 +1014,7 @@ def number_of_terms(self): EXAMPLES:: - sage: R. = PolynomialRing(ZZ,sparse=True) + sage: R. = PolynomialRing(ZZ, sparse=True) sage: p = x^100 - 3*x^10 + 12 sage: p.number_of_terms() 3 @@ -1058,17 +1061,17 @@ class Polynomial_generic_field(Polynomial_singular_repr, @coerce_binop def quo_rem(self, other): """ - Returns a tuple (quotient, remainder) where - self = quotient * other + remainder. + Return a tuple ``(quotient, remainder)`` where + ``self = quotient * other + remainder``. EXAMPLES:: sage: R. = PolynomialRing(QQ) - sage: K. = NumberField(y^2 - 2) - sage: P. = PolynomialRing(K) - sage: x.quo_rem(K(1)) + sage: K. = NumberField(y^2 - 2) # optional - sage.rings.number_field + sage: P. = PolynomialRing(K) # optional - sage.rings.number_field + sage: x.quo_rem(K(1)) # optional - sage.rings.number_field (x, 0) - sage: x.xgcd(K(1)) + sage: x.xgcd(K(1)) # optional - sage.rings.number_field (1, 0, 1) """ P = self.parent() @@ -1129,7 +1132,7 @@ class Polynomial_generic_cdv(Polynomial_generic_domain): """ def newton_slopes(self, repetition=True): """ - Returns a list of the Newton slopes of this polynomial. + Return a list of the Newton slopes of this polynomial. These are the valuations of the roots of this polynomial. @@ -1139,15 +1142,15 @@ def newton_slopes(self, repetition=True): EXAMPLES:: - sage: K = Qp(5) - sage: R. = K[] - sage: f = 5 + 3*t + t^4 + 25*t^10 - sage: f.newton_polygon() + sage: K = Qp(5) # optional - sage.rings.padics + sage: R. = K[] # optional - sage.rings.padics + sage: f = 5 + 3*t + t^4 + 25*t^10 # optional - sage.rings.padics + sage: f.newton_polygon() # optional - sage.rings.padics Finite Newton polygon with 4 vertices: (0, 1), (1, 0), (4, 0), (10, 2) - sage: f.newton_slopes() + sage: f.newton_slopes() # optional - sage.rings.padics [1, 0, 0, 0, -1/3, -1/3, -1/3, -1/3, -1/3, -1/3] - sage: f.newton_slopes(repetition=False) + sage: f.newton_slopes(repetition=False) # optional - sage.rings.padics [1, 0, -1/3] AUTHOR: @@ -1159,7 +1162,7 @@ def newton_slopes(self, repetition=True): def newton_polygon(self): r""" - Returns a list of vertices of the Newton polygon of this polynomial. + Return a list of vertices of the Newton polygon of this polynomial. .. NOTE:: @@ -1167,15 +1170,15 @@ def newton_polygon(self): EXAMPLES:: - sage: K = Qp(5) - sage: R. = K[] - sage: f = 5 + 3*t + t^4 + 25*t^10 - sage: f.newton_polygon() + sage: K = Qp(5) # optional - sage.rings.padics + sage: R. = K[] # optional - sage.rings.padics + sage: f = 5 + 3*t + t^4 + 25*t^10 # optional - sage.rings.padics + sage: f.newton_polygon() # optional - sage.rings.padics Finite Newton polygon with 4 vertices: (0, 1), (1, 0), (4, 0), (10, 2) - sage: g = f + K(0,0)*t^4; g + sage: g = f + K(0,0)*t^4; g # optional - sage.rings.padics (5^2 + O(5^22))*t^10 + O(5^0)*t^4 + (3 + O(5^20))*t + 5 + O(5^21) - sage: g.newton_polygon() + sage: g.newton_polygon() # optional - sage.rings.padics Traceback (most recent call last): ... PrecisionError: The coefficient of t^4 has not enough precision @@ -1184,10 +1187,10 @@ def newton_polygon(self): Check that :trac:`22936` is fixed:: - sage: S. = PowerSeriesRing(GF(5)) - sage: R. = S[] - sage: p = x^2+y+x*y^2 - sage: p.newton_polygon() + sage: S. = PowerSeriesRing(GF(5)) # optional - sage.rings.finite_rings + sage: R. = S[] # optional - sage.rings.finite_rings + sage: p = x^2 + y + x*y^2 # optional - sage.rings.finite_rings + sage: p.newton_polygon() # optional - sage.rings.finite_rings Finite Newton polygon with 3 vertices: (0, 2), (1, 0), (2, 1) AUTHOR: @@ -1222,16 +1225,16 @@ def hensel_lift(self, a): EXAMPLES:: - sage: K = Qp(5, 10) - sage: P. = PolynomialRing(K) - sage: f = x^2 + 1 - sage: root = f.hensel_lift(2); root + sage: K = Qp(5, 10) # optional - sage.rings.padics + sage: P. = PolynomialRing(K) # optional - sage.rings.padics + sage: f = x^2 + 1 # optional - sage.rings.padics + sage: root = f.hensel_lift(2); root # optional - sage.rings.padics 2 + 5 + 2*5^2 + 5^3 + 3*5^4 + 4*5^5 + 2*5^6 + 3*5^7 + 3*5^9 + O(5^10) - sage: f(root) + sage: f(root) # optional - sage.rings.padics O(5^10) - sage: g = (x^2 + 1)*(x - 7) - sage: g.hensel_lift(2) # here, 2 is a multiple root modulo p + sage: g = (x^2 + 1) * (x - 7) # optional - sage.rings.padics + sage: g.hensel_lift(2) # here, 2 is a multiple root modulo p # optional - sage.rings.padics Traceback (most recent call last): ... ValueError: a is not close enough to a root of this polynomial @@ -1270,27 +1273,27 @@ def _factor_of_degree(self, deg): EXAMPLES:: - sage: K = Qp(5) - sage: R. = K[] - sage: K = Qp(5) - sage: R. = K[] - sage: f = 5 + 3*t + t^4 + 25*t^10 + sage: K = Qp(5) # optional - sage.rings.padics + sage: R. = K[] # optional - sage.rings.padics + sage: K = Qp(5) # optional - sage.rings.padics + sage: R. = K[] # optional - sage.rings.padics + sage: f = 5 + 3*t + t^4 + 25*t^10 # optional - sage.rings.padics - sage: g = f._factor_of_degree(4) - sage: (f % g).is_zero() + sage: g = f._factor_of_degree(4) # optional - sage.rings.padics + sage: (f % g).is_zero() # optional - sage.rings.padics True - sage: g = f._factor_of_degree(3) # not tested + sage: g = f._factor_of_degree(3) # not tested # optional - sage.rings.padics Traceback (most recent call last) ... KeyboardInterrupt: TESTS:: - sage: S. = PowerSeriesRing(GF(5)) - sage: R. = S[] - sage: p = x^2+y+x*y^2 - sage: p._factor_of_degree(1) + sage: S. = PowerSeriesRing(GF(5)) # optional - sage.rings.finite_rings + sage: R. = S[] # optional - sage.rings.finite_rings + sage: p = x^2 + y + x*y^2 # optional - sage.rings.finite_rings + sage: p._factor_of_degree(1) # optional - sage.rings.finite_rings (1 + O(x^20))*y + x^2 + x^5 + 2*x^8 + 4*x^14 + 2*x^17 + 2*x^20 + O(x^22) AUTHOR: @@ -1323,7 +1326,7 @@ def factor_of_slope(self, slope=None): """ INPUT: - - slope -- a rational number (default: the first slope + - ``slope`` -- a rational number (default: the first slope in the Newton polygon of ``self``) OUTPUT: @@ -1334,30 +1337,30 @@ def factor_of_slope(self, slope=None): EXAMPLES:: - sage: K = Qp(5) - sage: R. = K[] - sage: K = Qp(5) - sage: R. = K[] - sage: f = 5 + 3*t + t^4 + 25*t^10 - sage: f.newton_slopes() + sage: K = Qp(5) # optional - sage.rings.padics + sage: R. = K[] # optional - sage.rings.padics + sage: K = Qp(5) # optional - sage.rings.padics + sage: R. = K[] # optional - sage.rings.padics + sage: f = 5 + 3*t + t^4 + 25*t^10 # optional - sage.rings.padics + sage: f.newton_slopes() # optional - sage.rings.padics [1, 0, 0, 0, -1/3, -1/3, -1/3, -1/3, -1/3, -1/3] - sage: g = f.factor_of_slope(0) - sage: g.newton_slopes() + sage: g = f.factor_of_slope(0) # optional - sage.rings.padics + sage: g.newton_slopes() # optional - sage.rings.padics [0, 0, 0] - sage: (f % g).is_zero() + sage: (f % g).is_zero() # optional - sage.rings.padics True - sage: h = f.factor_of_slope() - sage: h.newton_slopes() + sage: h = f.factor_of_slope() # optional - sage.rings.padics + sage: h.newton_slopes() # optional - sage.rings.padics [1] - sage: (f % h).is_zero() + sage: (f % h).is_zero() # optional - sage.rings.padics True If ``slope`` is not a slope of ``self``, the corresponding factor is `1`:: - sage: f.factor_of_slope(-1) + sage: f.factor_of_slope(-1) # optional - sage.rings.padics 1 + O(5^20) AUTHOR: @@ -1403,18 +1406,18 @@ def slope_factorization(self): EXAMPLES:: - sage: K = Qp(5) - sage: R. = K[] - sage: K = Qp(5) - sage: R. = K[] - sage: f = 5 + 3*t + t^4 + 25*t^10 - sage: f.newton_slopes() + sage: K = Qp(5) # optional - sage.rings.padics + sage: R. = K[] # optional - sage.rings.padics + sage: K = Qp(5) # optional - sage.rings.padics + sage: R. = K[] # optional - sage.rings.padics + sage: f = 5 + 3*t + t^4 + 25*t^10 # optional - sage.rings.padics + sage: f.newton_slopes() # optional - sage.rings.padics [1, 0, 0, 0, -1/3, -1/3, -1/3, -1/3, -1/3, -1/3] - sage: F = f.slope_factorization() - sage: F.prod() == f + sage: F = f.slope_factorization() # optional - sage.rings.padics + sage: F.prod() == f # optional - sage.rings.padics True - sage: for (f,_) in F: + sage: for (f,_) in F: # optional - sage.rings.padics ....: print(f.newton_slopes()) [-1/3, -1/3, -1/3, -1/3, -1/3, -1/3] [0, 0, 0] @@ -1422,11 +1425,13 @@ def slope_factorization(self): TESTS:: - sage: S. = PowerSeriesRing(GF(5)) - sage: R. = S[] - sage: p = x^2+y+x*y^2 - sage: p.slope_factorization() - (x) * ((x + O(x^22))*y + 1 + 4*x^3 + 4*x^6 + 3*x^9 + x^15 + 3*x^18 + O(x^21)) * ((x^-1 + O(x^20))*y + x + x^4 + 2*x^7 + 4*x^13 + 2*x^16 + 2*x^19 + O(x^22)) + sage: S. = PowerSeriesRing(GF(5)) # optional - sage.rings.finite_rings + sage: R. = S[] # optional - sage.rings.finite_rings + sage: p = x^2 + y + x*y^2 # optional - sage.rings.finite_rings + sage: p.slope_factorization() # optional - sage.rings.finite_rings + (x) + * ((x + O(x^22))*y + 1 + 4*x^3 + 4*x^6 + 3*x^9 + x^15 + 3*x^18 + O(x^21)) + * ((x^-1 + O(x^20))*y + x + x^4 + 2*x^7 + 4*x^13 + 2*x^16 + 2*x^19 + O(x^22)) AUTHOR: @@ -1478,11 +1483,11 @@ def _roots(self, secure, minval, hint): TESTS:: - sage: R = Zp(2) - sage: S. = R[] - sage: P = (x-1) * (x-2) * (x-4) * (x-8) * (x-16) - sage: Q = P^2 - sage: Q.roots(algorithm="sage") # indirect doctest + sage: R = Zp(2) # optional - sage.rings.padics + sage: S. = R[] # optional - sage.rings.padics + sage: P = (x-1) * (x-2) * (x-4) * (x-8) * (x-16) # optional - sage.rings.padics + sage: Q = P^2 # optional - sage.rings.padics + sage: Q.roots(algorithm="sage") # indirect doctest # optional - sage.rings.padics [(2^4 + O(2^14), 2), (2^3 + O(2^13), 2), (2^2 + O(2^12), 2), diff --git a/src/sage/rings/polynomial/polynomial_gf2x.pyx b/src/sage/rings/polynomial/polynomial_gf2x.pyx index 97b565e9cd0..552e6d72de6 100644 --- a/src/sage/rings/polynomial/polynomial_gf2x.pyx +++ b/src/sage/rings/polynomial/polynomial_gf2x.pyx @@ -34,8 +34,8 @@ from sage.matrix.matrix_mod2_dense cimport Matrix_mod2_dense from sage.misc.cachefunc import cached_method cdef class Polynomial_GF2X(Polynomial_template): - """ - Univariate Polynomials over GF(2) via NTL's GF2X. + r""" + Univariate Polynomials over `\GF{2}` via NTL's GF2X. EXAMPLES:: @@ -44,8 +44,8 @@ cdef class Polynomial_GF2X(Polynomial_template): x^3 + x^2 + 1 """ def __init__(self, parent, x=None, check=True, is_gen=False, construct=False): - """ - Create a new univariate polynomials over GF(2). + r""" + Create a new univariate polynomials over `\GF{2}`. EXAMPLES:: @@ -117,7 +117,7 @@ cdef class Polynomial_GF2X(Polynomial_template): - ``g`` -- a polynomial - ``h`` -- a polynomial - - ``algorithm`` -- either 'native' or 'ntl' (default: 'native') + - ``algorithm`` -- either ``'native'`` or ``'ntl'`` (default: ``'native'``) EXAMPLES:: @@ -132,7 +132,7 @@ cdef class Polynomial_GF2X(Polynomial_template): sage: f = x^29 + x^24 + x^22 + x^21 + x^20 + x^16 + x^15 + x^14 + x^10 + x^9 + x^8 + x^7 + x^6 + x^5 + x^2 sage: g = x^31 + x^30 + x^28 + x^26 + x^24 + x^21 + x^19 + x^18 + x^11 + x^10 + x^9 + x^8 + x^5 + x^2 + 1 sage: h = x^30 + x^28 + x^26 + x^25 + x^24 + x^22 + x^21 + x^18 + x^17 + x^15 + x^13 + x^12 + x^11 + x^10 + x^9 + x^4 - sage: f.modular_composition(g,h) == f(g) % h + sage: f.modular_composition(g, h) == f(g) % h True AUTHORS: @@ -259,7 +259,7 @@ cdef class Polynomial_GF2X(Polynomial_template): @cached_method def is_irreducible(self): r""" - Return whether this polynomial is irreducible over `\GF{2}`.` + Return whether this polynomial is irreducible over `\GF{2}`. EXAMPLES:: diff --git a/src/sage/rings/polynomial/polynomial_integer_dense_flint.pyx b/src/sage/rings/polynomial/polynomial_integer_dense_flint.pyx index 55cb653f6dc..af32b6c624b 100644 --- a/src/sage/rings/polynomial/polynomial_integer_dense_flint.pyx +++ b/src/sage/rings/polynomial/polynomial_integer_dense_flint.pyx @@ -637,7 +637,7 @@ cdef class Polynomial_integer_dense_flint(Polynomial): cpdef _add_(self, right): r""" - Returns self plus right. + Return ``self`` plus ``right``. EXAMPLES:: @@ -657,7 +657,7 @@ cdef class Polynomial_integer_dense_flint(Polynomial): cpdef _sub_(self, right): r""" - Return self minus right. + Return ``self`` minus ``right``. EXAMPLES:: @@ -677,7 +677,7 @@ cdef class Polynomial_integer_dense_flint(Polynomial): cpdef _neg_(self): r""" - Returns negative of self. + Return negative of ``self``. EXAMPLES:: @@ -695,7 +695,7 @@ cdef class Polynomial_integer_dense_flint(Polynomial): @coerce_binop def quo_rem(self, Polynomial_integer_dense_flint right): r""" - Attempts to divide self by right, and return a quotient and remainder. + Attempts to divide ``self`` by ``right``, and return a quotient and remainder. EXAMPLES:: @@ -764,7 +764,7 @@ cdef class Polynomial_integer_dense_flint(Polynomial): cpdef bint is_zero(self) except -1: """ - Returns True if self is equal to zero. + Return ``True`` if ``self`` is equal to zero. EXAMPLES:: @@ -780,7 +780,7 @@ cdef class Polynomial_integer_dense_flint(Polynomial): cpdef bint is_one(self) except -1: """ - Returns True if self is equal to one. + Return ``True`` if ``self`` is equal to one. EXAMPLES:: @@ -796,7 +796,7 @@ cdef class Polynomial_integer_dense_flint(Polynomial): def __bool__(self): """ - Check if self is not zero. + Check if ``self`` is not zero. EXAMPLES:: @@ -813,14 +813,14 @@ cdef class Polynomial_integer_dense_flint(Polynomial): @coerce_binop def gcd(self, right): r""" - Return the GCD of self and right. The leading + Return the GCD of ``self`` and ``right``. The leading coefficient need not be 1. EXAMPLES:: sage: R. = PolynomialRing(ZZ) - sage: f = (6*x + 47)*(7*x^2 - 2*x + 38) - sage: g = (6*x + 47)*(3*x^3 + 2*x + 1) + sage: f = (6*x + 47) * (7*x^2 - 2*x + 38) + sage: g = (6*x + 47) * (3*x^3 + 2*x + 1) sage: f.gcd(g) 6*x + 47 """ @@ -840,16 +840,16 @@ cdef class Polynomial_integer_dense_flint(Polynomial): @coerce_binop def lcm(self, right): """ - Return the LCM of self and right. + Return the LCM of ``self`` and ``right``. EXAMPLES:: sage: R. = PolynomialRing(ZZ) - sage: f = (6*x + 47)*(7*x^2 - 2*x + 38) - sage: g = (6*x + 47)*(3*x^3 + 2*x + 1) + sage: f = (6*x + 47) * (7*x^2 - 2*x + 38) + sage: g = (6*x + 47) * (3*x^3 + 2*x + 1) sage: h = f.lcm(g); h 126*x^6 + 951*x^5 + 486*x^4 + 6034*x^3 + 585*x^2 + 3706*x + 1786 - sage: h == (6*x + 47)*(7*x^2 - 2*x + 38)*(3*x^3 + 2*x + 1) + sage: h == (6*x + 47) * (7*x^2 - 2*x + 38) * (3*x^3 + 2*x + 1) True TESTS: @@ -868,9 +868,9 @@ cdef class Polynomial_integer_dense_flint(Polynomial): @coerce_binop def xgcd(self, right): - """ - Return a triple ``(g,s,t)`` such that `g = s*self + t*right` and such - that `g` is the `gcd` of ``self`` and ``right`` up to a divisor of the + r""" + Return a triple `(g,s,t)` such that `g = s\cdot{}` ``self`` + `t\cdot{}` ``right`` and such + that `g` is the gcd of ``self`` and ``right`` up to a divisor of the resultant of ``self`` and ``other``. As integer polynomials do not form a principal ideal domain, it is not @@ -886,14 +886,14 @@ cdef class Polynomial_integer_dense_flint(Polynomial): sage: P. = PolynomialRing(ZZ) - sage: (x+2).xgcd(x+4) + sage: (x + 2).xgcd(x + 4) (2, -1, 1) - sage: (x+2).resultant(x+4) + sage: (x + 2).resultant(x + 4) 2 - sage: (x+2).gcd(x+4) + sage: (x + 2).gcd(x + 4) 1 - sage: F = (x^2 + 2)*x^3; G = (x^2+2)*(x-3) + sage: F = (x^2 + 2)*x^3; G = (x^2 + 2) * (x - 3) sage: g, u, v = F.xgcd(G) sage: g, u, v (27*x^2 + 54, 1, -x^2 - 3*x - 9) @@ -906,7 +906,7 @@ cdef class Polynomial_integer_dense_flint(Polynomial): sage: zero.xgcd(x) (x, 0, 1) - sage: F = (x-3)^3; G = (x-15)^2 + sage: F = (x - 3)^3; G = (x - 15)^2 sage: g, u, v = F.xgcd(G) sage: g, u, v (2985984, -432*x + 8208, 432*x^2 + 864*x + 14256) @@ -960,7 +960,7 @@ cdef class Polynomial_integer_dense_flint(Polynomial): cpdef _mul_(self, right): r""" - Returns self multiplied by right. + Return ``self`` multiplied by ``right``. EXAMPLES:: @@ -1008,7 +1008,7 @@ cdef class Polynomial_integer_dense_flint(Polynomial): cpdef _lmul_(self, Element right): r""" - Returns self multiplied by right, where right is a scalar (integer). + Return ``self`` multiplied by ``right``, where ``right`` is a scalar (integer). EXAMPLES:: @@ -1026,7 +1026,7 @@ cdef class Polynomial_integer_dense_flint(Polynomial): cpdef _rmul_(self, Element right): r""" - Returns self multiplied by right, where right is a scalar (integer). + Return ``self`` multiplied by ``right``, where right is a scalar (integer). EXAMPLES:: @@ -1260,7 +1260,7 @@ cdef class Polynomial_integer_dense_flint(Polynomial): EXAMPLES:: sage: x = polygen(ZZ) - sage: p = 1+x+2*x^2 + sage: p = 1 + x + 2*x^2 sage: q5 = p.inverse_series_trunc(5) sage: q5 -x^4 + 3*x^3 - x^2 - x + 1 @@ -1345,7 +1345,7 @@ cdef class Polynomial_integer_dense_flint(Polynomial): def real_root_intervals(self): """ - Returns isolating intervals for the real roots of this + Return isolating intervals for the real roots of this polynomial. EXAMPLES: @@ -1372,7 +1372,7 @@ cdef class Polynomial_integer_dense_flint(Polynomial): """ Return the degree of this polynomial. - The zero polynomial has degree -1. + The zero polynomial has degree `-1`. EXAMPLES:: @@ -1431,7 +1431,7 @@ cdef class Polynomial_integer_dense_flint(Polynomial): def discriminant(self, proof=True): r""" - Return the discriminant of self, which is by definition + Return the discriminant of ``self``, which is by definition .. MATH:: @@ -1490,11 +1490,11 @@ cdef class Polynomial_integer_dense_flint(Polynomial): def squarefree_decomposition(Polynomial_integer_dense_flint self): """ - Return the square-free decomposition of self. This is - a partial factorization of self into square-free, relatively + Return the square-free decomposition of ``self``. This is + a partial factorization of ``self`` into square-free, relatively prime polynomials. - This is a wrapper for the NTL function SquareFreeDecomp. + This is a wrapper for the NTL function ``SquareFreeDecomp``. EXAMPLES:: @@ -1616,7 +1616,7 @@ cdef class Polynomial_integer_dense_flint(Polynomial): def factor(self): """ This function overrides the generic polynomial factorization to - make a somewhat intelligent decision to use Pari or NTL based on + make a somewhat intelligent decision to use PARI or NTL based on some benchmarking. Note: This function factors the content of the polynomial, @@ -1626,11 +1626,11 @@ cdef class Polynomial_integer_dense_flint(Polynomial): EXAMPLES:: - sage: R.=ZZ[] - sage: f=x^4-1 + sage: R. = ZZ[] + sage: f = x^4 - 1 sage: f.factor() (x - 1) * (x + 1) * (x^2 + 1) - sage: f=1-x + sage: f = 1 - x sage: f.factor() (-1) * (x - 1) sage: f.factor().unit() @@ -1651,15 +1651,13 @@ cdef class Polynomial_integer_dense_flint(Polynomial): def factor_mod(self, p): """ - Return the factorization of self modulo the prime `p`. + Return the factorization of ``self`` modulo the prime `p`. INPUT: - ``p`` -- prime - OUTPUT: - - factorization of self reduced modulo p. + OUTPUT: factorization of ``self`` reduced modulo `p`. EXAMPLES:: @@ -1667,13 +1665,13 @@ cdef class Polynomial_integer_dense_flint(Polynomial): sage: f = -3*x*(x-2)*(x-9) + x sage: f.factor_mod(3) x - sage: f = -3*x*(x-2)*(x-9) + sage: f = -3 * x * (x - 2) * (x - 9) sage: f.factor_mod(3) Traceback (most recent call last): ... ArithmeticError: factorization of 0 is not defined - sage: f = 2*x*(x-2)*(x-9) + sage: f = 2 * x * (x - 2) * (x - 9) sage: f.factor_mod(7) (2) * x * (x + 5)^2 """ @@ -1691,7 +1689,7 @@ cdef class Polynomial_integer_dense_flint(Polynomial): def factor_padic(self, p, prec=10): """ - Return `p`-adic factorization of self to given precision. + Return `p`-adic factorization of ``self`` to given precision. INPUT: @@ -1699,22 +1697,22 @@ cdef class Polynomial_integer_dense_flint(Polynomial): - ``prec`` -- integer; the precision - OUTPUT: - - - factorization of ``self`` over the completion at `p`. + OUTPUT: factorization of ``self`` over the completion at `p`. EXAMPLES:: sage: R. = PolynomialRing(ZZ) sage: f = x^2 + 1 sage: f.factor_padic(5, 4) - ((1 + O(5^4))*x + 2 + 5 + 2*5^2 + 5^3 + O(5^4)) * ((1 + O(5^4))*x + 3 + 3*5 + 2*5^2 + 3*5^3 + O(5^4)) + ((1 + O(5^4))*x + 2 + 5 + 2*5^2 + 5^3 + O(5^4)) + * ((1 + O(5^4))*x + 3 + 3*5 + 2*5^2 + 3*5^3 + O(5^4)) A more difficult example:: sage: f = 100 * (5*x + 1)^2 * (x + 5)^2 sage: f.factor_padic(5, 10) - (4 + O(5^10)) * (5 + O(5^11))^2 * ((1 + O(5^10))*x + 5 + O(5^10))^2 * ((5 + O(5^10))*x + 1 + O(5^10))^2 + (4 + O(5^10)) * (5 + O(5^11))^2 * ((1 + O(5^10))*x + 5 + O(5^10))^2 + * ((5 + O(5^10))*x + 1 + O(5^10))^2 """ from sage.rings.padics.factory import Zp @@ -1753,20 +1751,18 @@ cdef class Polynomial_integer_dense_flint(Polynomial): @coerce_binop def resultant(self, other, proof=True): """ - Returns the resultant of self and other, which must lie in the same + Return the resultant of ``self`` and ``other``, which must lie in the same polynomial ring. - If ``proof = False`` (the default is ``proof=True``), then this function may + If ``proof=False`` (the default is ``proof=True``), then this function may use a randomized strategy that errors with probability no more than `2^{-80}`. INPUT: - - other -- a polynomial - - OUTPUT: + - ``other`` -- a polynomial - an element of the base ring of the polynomial ring + OUTPUT: an element of the base ring of the polynomial ring EXAMPLES:: @@ -1842,7 +1838,7 @@ cdef class Polynomial_integer_dense_flint(Polynomial): def revert_series(self, n): r""" - Return a polynomial `f` such that `f(self(x)) = self(f(x)) = x mod x^n`. + Return a polynomial `f` such that `f(` ``self`` `(x)) =` ``self`` `(f(x)) = x` (mod `x^n`). EXAMPLES:: diff --git a/src/sage/rings/polynomial/polynomial_integer_dense_ntl.pyx b/src/sage/rings/polynomial/polynomial_integer_dense_ntl.pyx index 38e2470f1f1..0d9da73602e 100644 --- a/src/sage/rings/polynomial/polynomial_integer_dense_ntl.pyx +++ b/src/sage/rings/polynomial/polynomial_integer_dense_ntl.pyx @@ -469,7 +469,7 @@ cdef class Polynomial_integer_dense_ntl(Polynomial): cpdef _neg_(self): r""" - Returns negative of self. + Returns negative of ``self``. EXAMPLES:: @@ -486,13 +486,13 @@ cdef class Polynomial_integer_dense_ntl(Polynomial): @coerce_binop def quo_rem(self, right): r""" - Attempts to divide self by right, and return a quotient and remainder. + Attempt to divide ``self`` by ``right``, and return a quotient and remainder. - If right is monic, then it returns ``(q, r)`` where `self = q * right + r` - and `deg(r) < deg(right)`. + If right is monic, then it returns ``(q, r)`` where ``self = q * right + r`` + and ``deg(r) < deg(right)``. - If right is not monic, then it returns `(q, 0)` where q = self/right if - right exactly divides self, otherwise it raises an exception. + If right is not monic, then it returns `(q, 0)` where ``q = self/right`` if + ``right`` exactly divides ``self``, otherwise it raises an exception. EXAMPLES:: @@ -574,14 +574,14 @@ cdef class Polynomial_integer_dense_ntl(Polynomial): @coerce_binop def gcd(self, right): r""" - Return the GCD of self and right. The leading + Return the GCD of ``self`` and ``right``. The leading coefficient need not be 1. EXAMPLES:: sage: R. = PolynomialRing(ZZ, implementation='NTL') - sage: f = (6*x + 47)*(7*x^2 - 2*x + 38) - sage: g = (6*x + 47)*(3*x^3 + 2*x + 1) + sage: f = (6*x + 47) * (7*x^2 - 2*x + 38) + sage: g = (6*x + 47) * (3*x^3 + 2*x + 1) sage: f.gcd(g) 6*x + 47 """ @@ -596,16 +596,16 @@ cdef class Polynomial_integer_dense_ntl(Polynomial): @coerce_binop def lcm(self, right): """ - Return the LCM of self and right. + Return the LCM of ``self`` and ``right``. EXAMPLES:: sage: R. = PolynomialRing(ZZ, implementation='NTL') - sage: f = (6*x + 47)*(7*x^2 - 2*x + 38) - sage: g = (6*x + 47)*(3*x^3 + 2*x + 1) + sage: f = (6*x + 47) * (7*x^2 - 2*x + 38) + sage: g = (6*x + 47) * (3*x^3 + 2*x + 1) sage: h = f.lcm(g); h 126*x^6 + 951*x^5 + 486*x^4 + 6034*x^3 + 585*x^2 + 3706*x + 1786 - sage: h == (6*x + 47)*(7*x^2 - 2*x + 38)*(3*x^3 + 2*x + 1) + sage: h == (6*x + 47) * (7*x^2 - 2*x + 38) * (3*x^3 + 2*x + 1) True TESTS: @@ -625,7 +625,7 @@ cdef class Polynomial_integer_dense_ntl(Polynomial): @coerce_binop def xgcd(self, right): """ - This function can't in general return ``(g,s,t)`` as above, + This function can't in general return `(g,s,t)` as above, since they need not exist. Instead, over the integers, we first multiply `g` by a divisor of the resultant of `a/g` and `b/g`, up to sign, and return ``g, u, v`` such that @@ -634,7 +634,7 @@ cdef class Polynomial_integer_dense_ntl(Polynomial): If ``self`` and ``right`` are coprime as polynomials over the rationals, then ``g`` is guaranteed to be the resultant of - self and right, as a constant polynomial. + ``self`` and ``right``, as a constant polynomial. EXAMPLES:: @@ -815,7 +815,7 @@ cdef class Polynomial_integer_dense_ntl(Polynomial): def degree(self, gen=None): """ Return the degree of this polynomial. The zero polynomial has - degree -1. + degree `-1`. EXAMPLES:: @@ -833,11 +833,11 @@ cdef class Polynomial_integer_dense_ntl(Polynomial): def discriminant(self, proof=True): r""" - Return the discriminant of self, which is by definition + Return the discriminant of ``self``, which is by definition .. MATH:: - (-1)^{m(m-1)/2} {\mbox{\tt resultant}}(a, a')/lc(a), + (-1)^{m(m-1)/2} \text{resultant}(a, a')/lc(a), where `m = deg(a)`, and `lc(a)` is the leading coefficient of a. If ``proof`` is False (the default is True), then this function @@ -863,7 +863,7 @@ cdef class Polynomial_integer_dense_ntl(Polynomial): """ EXAMPLES:: - sage: t = PolynomialRing(ZZ,"t",implementation='NTL').gen() + sage: t = PolynomialRing(ZZ, "t", implementation='NTL').gen() sage: f = t^3 + 3*t - 17 sage: pari(f) t^3 + 3*t - 17 @@ -875,11 +875,11 @@ cdef class Polynomial_integer_dense_ntl(Polynomial): def squarefree_decomposition(self): """ - Return the square-free decomposition of self. This is - a partial factorization of self into square-free, relatively + Return the square-free decomposition of ``self``. This is + a partial factorization of ``self`` into square-free, relatively prime polynomials. - This is a wrapper for the NTL function SquareFreeDecomp. + This is a wrapper for the NTL function ``SquareFreeDecomp``. EXAMPLES:: @@ -893,7 +893,7 @@ cdef class Polynomial_integer_dense_ntl(Polynomial): Verify that :trac:`13053` has been resolved:: sage: R. = PolynomialRing(ZZ, implementation='NTL') - sage: f=-x^2 + sage: f = -x^2 sage: f.squarefree_decomposition() (-1) * x^2 @@ -977,7 +977,7 @@ cdef class Polynomial_integer_dense_ntl(Polynomial): def factor(self): """ This function overrides the generic polynomial factorization to - make a somewhat intelligent decision to use Pari or NTL based on + make a somewhat intelligent decision to use PARI or NTL based on some benchmarking. Note: This function factors the content of the polynomial, @@ -987,11 +987,11 @@ cdef class Polynomial_integer_dense_ntl(Polynomial): EXAMPLES:: - sage: R.=ZZ[] - sage: f=x^4-1 + sage: R. = ZZ[] + sage: f = x^4 - 1 sage: f.factor() (x - 1) * (x + 1) * (x^2 + 1) - sage: f=1-x + sage: f = 1 - x sage: f.factor() (-1) * (x - 1) sage: f.factor().unit() @@ -1011,13 +1011,13 @@ cdef class Polynomial_integer_dense_ntl(Polynomial): def factor_mod(self, p): """ - Return the factorization of self modulo the prime p. + Return the factorization of ``self`` modulo the prime `p`. INPUT: - ``p`` -- prime - OUTPUT: factorization of self reduced modulo p. + OUTPUT: factorization of ``self`` reduced modulo `p`. EXAMPLES:: @@ -1049,7 +1049,7 @@ cdef class Polynomial_integer_dense_ntl(Polynomial): def factor_padic(self, p, prec=10): """ - Return `p`-adic factorization of self to given precision. + Return `p`-adic factorization of ``self`` to given precision. INPUT: @@ -1066,13 +1066,15 @@ cdef class Polynomial_integer_dense_ntl(Polynomial): sage: R. = PolynomialRing(ZZ, implementation='NTL') sage: f = x^2 + 1 sage: f.factor_padic(5, 4) - ((1 + O(5^4))*x + 2 + 5 + 2*5^2 + 5^3 + O(5^4)) * ((1 + O(5^4))*x + 3 + 3*5 + 2*5^2 + 3*5^3 + O(5^4)) + ((1 + O(5^4))*x + 2 + 5 + 2*5^2 + 5^3 + O(5^4)) + * ((1 + O(5^4))*x + 3 + 3*5 + 2*5^2 + 3*5^3 + O(5^4)) A more difficult example:: sage: f = 100 * (5*x + 1)^2 * (x + 5)^2 sage: f.factor_padic(5, 10) - (4 + O(5^10)) * (5 + O(5^11))^2 * ((1 + O(5^10))*x + 5 + O(5^10))^2 * ((5 + O(5^10))*x + 1 + O(5^10))^2 + (4 + O(5^10)) * (5 + O(5^11))^2 * ((1 + O(5^10))*x + 5 + O(5^10))^2 + * ((5 + O(5^10))*x + 1 + O(5^10))^2 """ from sage.rings.padics.factory import Zp @@ -1097,11 +1099,11 @@ cdef class Polynomial_integer_dense_ntl(Polynomial): EXAMPLES:: - sage: x = PolynomialRing(ZZ,'x',implementation='NTL').0 + sage: x = PolynomialRing(ZZ, 'x', implementation='NTL').0 sage: f = x^3 + 3*x - 17 sage: f.list() [-17, 3, 0, 1] - sage: f = PolynomialRing(ZZ,'x',implementation='NTL')(0) + sage: f = PolynomialRing(ZZ, 'x', implementation='NTL')(0) sage: f.list() [] """ @@ -1111,23 +1113,21 @@ cdef class Polynomial_integer_dense_ntl(Polynomial): @coerce_binop def resultant(self, other, proof=True): """ - Returns the resultant of self and other, which must lie in the same + Returns the resultant of ``self`` and ``other``, which must lie in the same polynomial ring. - If proof = False (the default is proof=True), then this function may use a + If ``proof=False`` (the default is ``proof=True``), then this function may use a randomized strategy that errors with probability no more than `2^{-80}`. INPUT: - - other -- a polynomial + - ``other`` -- a polynomial - OUTPUT: - - an element of the base ring of the polynomial ring + OUTPUT: an element of the base ring of the polynomial ring EXAMPLES:: - sage: x = PolynomialRing(ZZ,'x',implementation='NTL').0 + sage: x = PolynomialRing(ZZ, 'x', implementation='NTL').0 sage: f = x^3 + x + 1; g = x^3 - x - 1 sage: r = f.resultant(g); r -8 diff --git a/src/sage/rings/polynomial/polynomial_modn_dense_ntl.pyx b/src/sage/rings/polynomial/polynomial_modn_dense_ntl.pyx index e0621f2c4a4..6021e96d3bc 100644 --- a/src/sage/rings/polynomial/polynomial_modn_dense_ntl.pyx +++ b/src/sage/rings/polynomial/polynomial_modn_dense_ntl.pyx @@ -85,7 +85,7 @@ cdef class Polynomial_dense_mod_n(Polynomial): sage: R. = PolynomialRing(Integers(100), implementation='NTL') sage: p = 3*x sage: q = 7*x - sage: p+q + sage: p + q 10*x sage: R. = PolynomialRing(Integers(8), implementation='NTL') sage: parent(p) @@ -172,7 +172,7 @@ cdef class Polynomial_dense_mod_n(Polynomial): """ EXAMPLES:: - sage: t = PolynomialRing(IntegerModRing(17),"t", implementation='NTL').gen() + sage: t = PolynomialRing(IntegerModRing(17), "t", implementation='NTL').gen() sage: f = t^3 + 3*t - 17 sage: pari(f) Mod(1, 17)*t^3 + Mod(3, 17)*t @@ -202,7 +202,7 @@ cdef class Polynomial_dense_mod_n(Polynomial): sage: R. = PolynomialRing(Integers(100), implementation='NTL') sage: from sage.rings.polynomial.polynomial_modn_dense_ntl import Polynomial_dense_mod_n - sage: f = Polynomial_dense_mod_n(R,[5,10,13,1,4]); f + sage: f = Polynomial_dense_mod_n(R, [5,10,13,1,4]); f 4*x^4 + x^3 + 13*x^2 + 10*x + 5 sage: f[2] 13 @@ -248,8 +248,8 @@ cdef class Polynomial_dense_mod_n(Polynomial): @coerce_binop def quo_rem(self, right): """ - Returns a tuple (quotient, remainder) where self = quotient*other + - remainder. + Return a tuple ``(quotient, remainder)`` where ``self = quotient*other + + remainder``. """ v = self.__poly.quo_rem((right).__poly) P = self.parent() @@ -257,7 +257,7 @@ cdef class Polynomial_dense_mod_n(Polynomial): def shift(self, n): r""" - Returns this polynomial multiplied by the power `x^n`. If `n` is negative, + Return this polynomial multiplied by the power `x^n`. If `n` is negative, terms below `x^n` will be discarded. Does not change this polynomial. EXAMPLES:: @@ -475,7 +475,7 @@ def small_roots(self, X=None, beta=1.0, epsilon=None, **kwds): To compute its roots we need to factor the modulus `N` and use the Chinese remainder theorem:: - sage: p,q = N.prime_divisors() + sage: p, q = N.prime_divisors() sage: f.change_ring(GF(p)).roots() [(4, 1)] sage: f.change_ring(GF(q)).roots() @@ -510,7 +510,7 @@ def small_roots(self, X=None, beta=1.0, epsilon=None, **kwds): sage: K = ZZ.random_element(0, 2^Kbits) - and pad it with 512-56=456 1s:: + and pad it with `512-56=456` 1s:: sage: Kdigits = K.digits(2) sage: M = [0]*Kbits + [1]*(Nbits-Kbits) @@ -688,7 +688,7 @@ cdef class Polynomial_dense_modn_ntl_zz(Polynomial_dense_mod_n): def int_list(self): """ - Returns the coefficients of self as efficiently as possible as a + Return the coefficients of ``self`` as efficiently as possible as a list of python ints. EXAMPLES:: @@ -731,7 +731,7 @@ cdef class Polynomial_dense_modn_ntl_zz(Polynomial_dense_mod_n): TESTS:: sage: R. = PolynomialRing(Integers(100), implementation='NTL') - sage: (x+5) + (x^2 - 6) + sage: (x + 5) + (x^2 - 6) x^2 + x + 99 """ cdef Polynomial_dense_modn_ntl_zz right = _right @@ -748,7 +748,7 @@ cdef class Polynomial_dense_modn_ntl_zz(Polynomial_dense_mod_n): TESTS:: sage: R. = PolynomialRing(Integers(100), implementation='NTL') - sage: (x+5) - (x^2 - 6) + sage: (x + 5) - (x^2 - 6) 99*x^2 + x + 11 """ cdef Polynomial_dense_modn_ntl_zz right = _right @@ -765,7 +765,7 @@ cdef class Polynomial_dense_modn_ntl_zz(Polynomial_dense_mod_n): TESTS:: sage: R. = PolynomialRing(Integers(100), implementation='NTL') - sage: (x+5) * (x^2 - 1) + sage: (x + 5) * (x^2 - 1) x^3 + 5*x^2 + 99*x + 95 """ cdef Polynomial_dense_modn_ntl_zz right = _right @@ -919,9 +919,9 @@ cdef class Polynomial_dense_modn_ntl_zz(Polynomial_dense_mod_n): @coerce_binop def quo_rem(self, right): - """ - Returns `q` and `r`, with the degree of `r` less than the degree of `right`, - such that `q * right + r = self`. + r""" + Return `q` and `r`, with the degree of `r` less than the degree of ``right``, + such that `q \cdot` ``right`` `{}+ r =` ``self``. EXAMPLES:: @@ -946,7 +946,7 @@ cdef class Polynomial_dense_modn_ntl_zz(Polynomial_dense_mod_n): cpdef _floordiv_(self, right): """ - Returns the whole part of self/right, without remainder. + Return the whole part of ``self``/``right``, without remainder. For q = n // d, we have deg(n - q*d) < deg(d) @@ -1043,7 +1043,7 @@ cdef class Polynomial_dense_modn_ntl_zz(Polynomial_dense_mod_n): def _derivative(self, var=None): r""" - Return the formal derivative of self with respect to ``var``. + Return the formal derivative of ``self`` with respect to ``var``. ``var`` must be either the generator of the polynomial ring to which this polynomial belongs, or ``None`` (either way the behaviour is the @@ -1140,8 +1140,8 @@ cdef class Polynomial_dense_modn_ntl_zz(Polynomial_dense_mod_n): def valuation(self): """ - Returns the valuation of self, that is, the power of the - lowest non-zero monomial of self. + Return the valuation of ``self``, that is, the power of the + lowest non-zero monomial of ``self``. EXAMPLES:: @@ -1177,7 +1177,7 @@ cdef class Polynomial_dense_modn_ntl_zz(Polynomial_dense_mod_n): cpdef Polynomial truncate(self, long n): """ - Returns this polynomial mod `x^n`. + Return this polynomial mod `x^n`. EXAMPLES:: @@ -1193,14 +1193,14 @@ cdef class Polynomial_dense_modn_ntl_zz(Polynomial_dense_mod_n): def __call__(self, *args, **kwds): """ - Evaluate self at x. If x is a single argument coercible into - the base ring of self, this is done directly in NTL, otherwise + Evaluate self at ``x``. If ``x`` is a single argument coercible into + the base ring of ``self``, this is done directly in NTL, otherwise the generic Polynomial call code is used. EXAMPLES:: sage: R. = PolynomialRing(Integers(100), implementation='NTL') - sage: f = x^3+7 + sage: f = x^3 + 7 sage: f(5) 32 sage: f(5r) @@ -1303,7 +1303,7 @@ cdef class Polynomial_dense_modn_ntl_ZZ(Polynomial_dense_mod_n): TESTS:: sage: R. = PolynomialRing(Integers(10^30), implementation='NTL') - sage: (x+5) + (x^2 - 6) + sage: (x + 5) + (x^2 - 6) x^2 + x + 999999999999999999999999999999 """ cdef Polynomial_dense_modn_ntl_ZZ right = _right @@ -1320,7 +1320,7 @@ cdef class Polynomial_dense_modn_ntl_ZZ(Polynomial_dense_mod_n): TESTS:: sage: R. = PolynomialRing(Integers(10^30), implementation='NTL') - sage: (x+5) - (x^2 - 6) + sage: (x + 5) - (x^2 - 6) 999999999999999999999999999999*x^2 + x + 11 """ cdef Polynomial_dense_modn_ntl_ZZ right = _right @@ -1476,9 +1476,9 @@ cdef class Polynomial_dense_modn_ntl_ZZ(Polynomial_dense_mod_n): @coerce_binop def quo_rem(self, right): - """ - Returns `q` and `r`, with the degree of `r` less than the degree of `right`, - such that `q * right + r = self`. + r""" + Return `q` and `r`, with the degree of `r` less than the degree of ``right``, + such that `q \cdot` ``right`` `+ r =` ``self``. EXAMPLES:: @@ -1503,7 +1503,7 @@ cdef class Polynomial_dense_modn_ntl_ZZ(Polynomial_dense_mod_n): cpdef _floordiv_(self, right): """ - Returns the whole part of self/right, without remainder. + Return the whole part of ``self`` / ``right``, without remainder. For q = n // d, we have deg(n - q*d) < deg(d) @@ -1601,7 +1601,7 @@ cdef class Polynomial_dense_modn_ntl_ZZ(Polynomial_dense_mod_n): def _derivative(self, var=None): r""" - Return the formal derivative of self with respect to ``var``. + Return the formal derivative of ``self`` with respect to ``var``. ``var`` must be either the generator of the polynomial ring to which this polynomial belongs, or None (either way the behaviour is the @@ -1686,19 +1686,19 @@ cdef class Polynomial_dense_modn_ntl_ZZ(Polynomial_dense_mod_n): def valuation(self): """ - Returns the valuation of self, that is, the power of the - lowest non-zero monomial of self. + Return the valuation of ``self``, that is, the power of the + lowest non-zero monomial of ``self``. EXAMPLES:: sage: R. = PolynomialRing(Integers(10^50), implementation='NTL') sage: x.valuation() 1 - sage: f = x-3; f.valuation() + sage: f = x - 3; f.valuation() 0 sage: f = x^99; f.valuation() 99 - sage: f = x-x; f.valuation() + sage: f = x - x; f.valuation() +Infinity """ cdef long n @@ -1738,7 +1738,7 @@ cdef class Polynomial_dense_modn_ntl_ZZ(Polynomial_dense_mod_n): cpdef Polynomial truncate(self, long n): """ - Returns this polynomial mod `x^n`. + Return this polynomial mod `x^n`. EXAMPLES:: @@ -1754,14 +1754,14 @@ cdef class Polynomial_dense_modn_ntl_ZZ(Polynomial_dense_mod_n): def __call__(self, *args, **kwds): """ - Evaluate self at x. If x is a single argument coercible into - the base ring of self, this is done directly in NTL, otherwise + Evaluate ``self`` at ``x``. If ``x`` is a single argument coercible into + the base ring of ``self``, this is done directly in NTL, otherwise the generic Polynomial call code is used. EXAMPLES:: sage: R. = PolynomialRing(Integers(10^30), implementation='NTL') - sage: f = x^3+7 + sage: f = x^3 + 7 sage: f(5) 132 sage: f(5r) @@ -1796,7 +1796,7 @@ cdef class Polynomial_dense_modn_ntl_ZZ(Polynomial_dense_mod_n): cdef class Polynomial_dense_mod_p(Polynomial_dense_mod_n): """ - A dense polynomial over the integers modulo p, where p is prime. + A dense polynomial over the integers modulo `p`, where `p` is prime. """ @coerce_binop @@ -1811,8 +1811,8 @@ cdef class Polynomial_dense_mod_p(Polynomial_dense_mod_n): EXAMPLES:: - sage: R. = PolynomialRing(GF(3),implementation="NTL") - sage: f,g = x + 2, x^2 - 1 + sage: R. = PolynomialRing(GF(3), implementation="NTL") + sage: f, g = x + 2, x^2 - 1 sage: f.gcd(g) x + 2 @@ -1836,7 +1836,7 @@ cdef class Polynomial_dense_mod_p(Polynomial_dense_mod_n): EXAMPLES:: - sage: R. = PolynomialRing(GF(3),implementation='NTL') + sage: R. = PolynomialRing(GF(3), implementation='NTL') sage: x.xgcd(x) (x, 0, 1) sage: (x^2 - 1).xgcd(x - 1) @@ -1855,7 +1855,7 @@ cdef class Polynomial_dense_mod_p(Polynomial_dense_mod_n): @coerce_binop def resultant(self, other): """ - Returns the resultant of self and other, which must lie in the same + Return the resultant of ``self`` and ``other``, which must lie in the same polynomial ring. INPUT: @@ -1866,7 +1866,7 @@ cdef class Polynomial_dense_mod_p(Polynomial_dense_mod_n): EXAMPLES:: - sage: R. = PolynomialRing(GF(19),implementation='NTL') + sage: R. = PolynomialRing(GF(19), implementation='NTL') sage: f = x^3 + x + 1; g = x^3 - x - 1 sage: r = f.resultant(g); r 11 @@ -1880,7 +1880,7 @@ cdef class Polynomial_dense_mod_p(Polynomial_dense_mod_n): """ EXAMPLES:: - sage: _. = PolynomialRing(GF(19),implementation='NTL') + sage: _. = PolynomialRing(GF(19), implementation='NTL') sage: f = x^3 + 3*x - 17 sage: f.discriminant() 12 diff --git a/src/sage/rings/polynomial/polynomial_number_field.pyx b/src/sage/rings/polynomial/polynomial_number_field.pyx index 82c3d467bea..05bb580bbed 100644 --- a/src/sage/rings/polynomial/polynomial_number_field.pyx +++ b/src/sage/rings/polynomial/polynomial_number_field.pyx @@ -1,5 +1,5 @@ r""" -Univariate polynomials over number fields. +Univariate polynomials over number fields AUTHOR: @@ -10,11 +10,11 @@ EXAMPLES: Define a polynomial over an absolute number field and perform basic operations with them:: - sage: N. = NumberField(x^2-2) + sage: N. = NumberField(x^2 - 2) sage: K. = N[] sage: f = x - a sage: g = x^3 - 2*a + 1 - sage: f*(x + a) + sage: f * (x + a) x^2 - 2 sage: f + g x^3 + x - 3*a + 1 @@ -29,34 +29,34 @@ operations with them:: Polynomials are aware of embeddings of the underlying field:: - sage: x = var('x') - sage: Q7 = Qp(7) - sage: r1 = Q7(3 + 7 + 2*7^2 + 6*7^3 + 7^4 + 2*7^5 + 7^6 + 2*7^7 + 4*7^8 +\ - 6*7^9 + 6*7^10 + 2*7^11 + 7^12 + 7^13 + 2*7^15 + 7^16 + 7^17 +\ - 4*7^18 + 6*7^19) - sage: N. = NumberField(x^2-2, embedding = r1) - sage: K. = N[] - sage: f = t^3-2*t+1 - sage: f(r1) + sage: x = polygen(ZZ, 'x') + sage: Q7 = Qp(7) # optional - sage.rings.padics + sage: r1 = Q7(3 + 7 + 2*7^2 + 6*7^3 + 7^4 + 2*7^5 + 7^6 + 2*7^7 + 4*7^8 # optional - sage.rings.padics + ....: + 6*7^9 + 6*7^10 + 2*7^11 + 7^12 + 7^13 + 2*7^15 + 7^16 + 7^17 + ....: + 4*7^18 + 6*7^19) + sage: N. = NumberField(x^2 - 2, embedding=r1) # optional - sage.rings.padics + sage: K. = N[] # optional - sage.rings.padics + sage: f = t^3 - 2*t + 1 # optional - sage.rings.padics + sage: f(r1) # optional - sage.rings.padics 1 + O(7^20) We can also construct polynomials over relative number fields:: - sage: N. = QQ[I, sqrt(2)] - sage: K. = N[] - sage: f = x - s2 - sage: g = x^3 - 2*i*x^2 + s2*x - sage: f*(x + s2) + sage: N. = QQ[I, sqrt(2)] # optional - sage.symbolic + sage: K. = N[] # optional - sage.symbolic + sage: f = x - s2 # optional - sage.symbolic + sage: g = x^3 - 2*i*x^2 + s2*x # optional - sage.symbolic + sage: f * (x + s2) # optional - sage.symbolic x^2 - 2 - sage: f + g + sage: f + g # optional - sage.symbolic x^3 - 2*I*x^2 + (sqrt2 + 1)*x - sqrt2 - sage: g // f + sage: g // f # optional - sage.symbolic x^2 + (-2*I + sqrt2)*x - 2*sqrt2*I + sqrt2 + 2 - sage: g % f + sage: g % f # optional - sage.symbolic -4*I + 2*sqrt2 + 2 - sage: factor(i*x^4 - 2*i*x^2 + 9*i) + sage: factor(i*x^4 - 2*i*x^2 + 9*i) # optional - sage.symbolic (I) * (x - I + sqrt2) * (x + I - sqrt2) * (x - I - sqrt2) * (x + I + sqrt2) - sage: gcd(f, x-i) + sage: gcd(f, x - i) # optional - sage.symbolic 1 """ @@ -122,13 +122,11 @@ class Polynomial_absolute_number_field_dense(Polynomial_generic_dense_field): - ``other`` -- a polynomial with the same parent as ``self``. - OUTPUT: - - - The monic gcd of ``self`` and ``other``. + OUTPUT: The monic gcd of ``self`` and ``other``. EXAMPLES:: - sage: N. = NumberField(x^3-1/2, 'a') + sage: N. = NumberField(x^3 - 1/2, 'a') sage: R. = N['r'] sage: f = (5/4*a^2 - 2*a + 4)*r^2 + (5*a^2 - 81/5*a - 17/2)*r + 4/5*a^2 + 24*a + 6 sage: g = (5/4*a^2 - 2*a + 4)*r^2 + (-11*a^2 + 79/5*a - 7/2)*r - 4/5*a^2 - 24*a - 6 @@ -138,8 +136,8 @@ class Polynomial_absolute_number_field_dense(Polynomial_generic_dense_field): sage: f = R.random_element(2) sage: g = f + 1 sage: h = R.random_element(2).monic() - sage: f *=h - sage: g *=h + sage: f *= h + sage: g *= h sage: gcd(f, g) - h 0 sage: f.gcd(g) - h @@ -149,8 +147,8 @@ class Polynomial_absolute_number_field_dense(Polynomial_generic_dense_field): Test for degree one extensions:: - sage: x = var('x') - sage: N = NumberField(x-3, 'a') + sage: x = polygen(ZZ, 'x') + sage: N = NumberField(x - 3, 'a') sage: a = N.gen() sage: R = N['x'] sage: f = R._random_nonzero_element() @@ -167,7 +165,7 @@ class Polynomial_absolute_number_field_dense(Polynomial_generic_dense_field): Test for coercion with other rings and force weird variables to test PARI behavior:: - sage: r = var('r') + sage: r = polygen(ZZ, 'r') sage: N = NumberField(r^2 - 2, 'r') sage: a = N.gen() sage: R = N['r'] @@ -180,8 +178,9 @@ class Polynomial_absolute_number_field_dense(Polynomial_generic_dense_field): sage: h = f.gcd(g); h 1 sage: h.parent() - Univariate Polynomial Ring in r over Number Field in r with defining polynomial r^2 - 2 - sage: gcd([a*r+2, r^2-2]) + Univariate Polynomial Ring in r over + Number Field in r with defining polynomial r^2 - 2 + sage: gcd([a*r + 2, r^2 - 2]) r + r """ if self.is_zero(): @@ -236,7 +235,7 @@ class Polynomial_relative_number_field_dense(Polynomial_generic_dense_field): EXAMPLES:: - sage: f = NumberField([x^2-2, x^2-3], 'a')['x'].random_element() + sage: f = NumberField([x^2 - 2, x^2 - 3], 'a')['x'].random_element() sage: from sage.rings.polynomial.polynomial_number_field import Polynomial_relative_number_field_dense sage: isinstance(f, Polynomial_relative_number_field_dense) True @@ -268,7 +267,7 @@ class Polynomial_relative_number_field_dense(Polynomial_generic_dense_field): sage: N = QQ[sqrt(2), sqrt(3)] sage: s2, s3 = N.gens() sage: x = polygen(N) - sage: f = x^4 - 5*x^2 +6 + sage: f = x^4 - 5*x^2 + 6 sage: g = x^3 + (-2*s2 + s3)*x^2 + (-2*s3*s2 + 2)*x + 2*s3 sage: gcd(f, g) x^2 + (-sqrt2 + sqrt3)*x - sqrt3*sqrt2 @@ -277,11 +276,11 @@ class Polynomial_relative_number_field_dense(Polynomial_generic_dense_field): TESTS:: - sage: x = var('x') - sage: R = NumberField([x^2-2, x^2-3], 'a')['x'] + sage: x = polygen(ZZ, 'x') + sage: R = NumberField([x^2 - 2, x^2 - 3], 'a')['x'] sage: f = R._random_nonzero_element() sage: g1 = R.random_element() - sage: g2 = R.random_element()*g1+1 + sage: g2 = R.random_element()*g1 + 1 sage: g1 *= f sage: g2 *= f sage: f.monic() - g1.gcd(g2) @@ -289,10 +288,10 @@ class Polynomial_relative_number_field_dense(Polynomial_generic_dense_field): Test for degree one extensions:: - sage: R = NumberField([x-2,x+1,x-3],'a')['x'] + sage: R = NumberField([x - 2, x + 1, x - 3], 'a')['x'] sage: f = R.random_element(2) sage: g1 = R.random_element(2) - sage: g2 = R.random_element(2)*g1+1 + sage: g2 = R.random_element(2)*g1 + 1 sage: g1 *= f sage: g2 *= f sage: d = gcd(g1, g2) diff --git a/src/sage/rings/polynomial/polynomial_quotient_ring.py b/src/sage/rings/polynomial/polynomial_quotient_ring.py index 0c9be09df64..057aecded7c 100644 --- a/src/sage/rings/polynomial/polynomial_quotient_ring.py +++ b/src/sage/rings/polynomial/polynomial_quotient_ring.py @@ -5,14 +5,14 @@ EXAMPLES:: sage: R. = QQ[] - sage: S = R.quotient(x**3-3*x+1, 'alpha') - sage: S.gen()**2 in S + sage: S = R.quotient(x**3 - 3*x + 1, 'alpha') # optional - sage.libs.pari + sage: S.gen()**2 in S # optional - sage.libs.pari True - sage: x in S + sage: x in S # optional - sage.libs.pari True - sage: S.gen() in R + sage: S.gen() in R # optional - sage.libs.pari False - sage: 1 in S + sage: 1 in S # optional - sage.libs.pari True TESTS:: @@ -80,25 +80,26 @@ class PolynomialQuotientRingFactory(UniqueFactory): demonstrate many basic functions with it:: sage: Z = IntegerRing() - sage: R = PolynomialRing(Z,'x'); x = R.gen() - sage: S = R.quotient(x^3 + 7, 'a'); a = S.gen() - sage: S - Univariate Quotient Polynomial Ring in a over Integer Ring with modulus x^3 + 7 - sage: a^3 + sage: R = PolynomialRing(Z, 'x'); x = R.gen() + sage: S = R.quotient(x^3 + 7, 'a'); a = S.gen() # optional - sage.libs.pari + sage: S # optional - sage.libs.pari + Univariate Quotient Polynomial Ring in a + over Integer Ring with modulus x^3 + 7 + sage: a^3 # optional - sage.libs.pari -7 - sage: S.is_field() + sage: S.is_field() # optional - sage.libs.pari False - sage: a in S + sage: a in S # optional - sage.libs.pari True - sage: x in S + sage: x in S # optional - sage.libs.pari True - sage: a in R + sage: a in R # optional - sage.libs.pari False - sage: S.polynomial_ring() + sage: S.polynomial_ring() # optional - sage.libs.pari Univariate Polynomial Ring in x over Integer Ring - sage: S.modulus() + sage: S.modulus() # optional - sage.libs.pari x^3 + 7 - sage: S.degree() + sage: S.degree() # optional - sage.libs.pari 3 We create the "iterated" polynomial ring quotient @@ -109,35 +110,43 @@ class PolynomialQuotientRingFactory(UniqueFactory): :: - sage: A. = PolynomialRing(GF(2)); A + sage: A. = PolynomialRing(GF(2)); A # optional - sage.rings.finite_rings Univariate Polynomial Ring in y over Finite Field of size 2 (using GF2X) - sage: B = A.quotient(y^2 + y + 1, 'y2'); B - Univariate Quotient Polynomial Ring in y2 over Finite Field of size 2 with modulus y^2 + y + 1 - sage: C = PolynomialRing(B, 'x'); x=C.gen(); C - Univariate Polynomial Ring in x over Univariate Quotient Polynomial Ring in y2 over Finite Field of size 2 with modulus y^2 + y + 1 - sage: R = C.quotient(x^3 - 5); R - Univariate Quotient Polynomial Ring in xbar over Univariate Quotient Polynomial Ring in y2 over Finite Field of size 2 with modulus y^2 + y + 1 with modulus x^3 + 1 + sage: B = A.quotient(y^2 + y + 1, 'y2'); B # optional - sage.rings.finite_rings + Univariate Quotient Polynomial Ring in y2 over Finite Field of size 2 + with modulus y^2 + y + 1 + sage: C = PolynomialRing(B, 'x'); x = C.gen(); C # optional - sage.rings.finite_rings + Univariate Polynomial Ring in x + over Univariate Quotient Polynomial Ring in y2 + over Finite Field of size 2 with modulus y^2 + y + 1 + sage: R = C.quotient(x^3 - 5); R # optional - sage.rings.finite_rings + Univariate Quotient Polynomial Ring in xbar + over Univariate Quotient Polynomial Ring in y2 + over Finite Field of size 2 with modulus y^2 + y + 1 + with modulus x^3 + 1 Next we create a number field, but viewed as a quotient of a polynomial ring over `\QQ`:: sage: R = PolynomialRing(RationalField(), 'x'); x = R.gen() - sage: S = R.quotient(x^3 + 2*x - 5, 'a') - sage: S - Univariate Quotient Polynomial Ring in a over Rational Field with modulus x^3 + 2*x - 5 - sage: S.is_field() + sage: S = R.quotient(x^3 + 2*x - 5, 'a') # optional - sage.libs.pari + sage: S # optional - sage.libs.pari + Univariate Quotient Polynomial Ring in a over Rational Field + with modulus x^3 + 2*x - 5 + sage: S.is_field() # optional - sage.libs.pari True - sage: S.degree() + sage: S.degree() # optional - sage.libs.pari 3 There are conversion functions for easily going back and forth between quotients of polynomial rings over `\QQ` and number fields:: - sage: K = S.number_field(); K + sage: K = S.number_field(); K # optional - sage.libs.pari sage.rings.number_field Number Field in a with defining polynomial x^3 + 2*x - 5 - sage: K.polynomial_quotient_ring() - Univariate Quotient Polynomial Ring in a over Rational Field with modulus x^3 + 2*x - 5 + sage: K.polynomial_quotient_ring() # optional - sage.libs.pari sage.rings.number_field + Univariate Quotient Polynomial Ring in a + over Rational Field with modulus x^3 + 2*x - 5 The leading coefficient must be a unit (but need not be 1). @@ -154,14 +163,14 @@ class PolynomialQuotientRingFactory(UniqueFactory): sage: R. = PolynomialRing(IntegerRing()) sage: f = x^2 + 1 - sage: R.quotient(f) + sage: R.quotient(f) # optional - sage.libs.pari Univariate Quotient Polynomial Ring in xbar over Integer Ring with modulus x^2 + 1 This shows that the issue at :trac:`5482` is solved:: sage: R. = PolynomialRing(QQ) - sage: f = x^2-1 - sage: R.quotient_by_principal_ideal(f) + sage: f = x^2 - 1 + sage: R.quotient_by_principal_ideal(f) # optional - sage.libs.pari Univariate Quotient Polynomial Ring in xbar over Rational Field with modulus x^2 - 1 """ @@ -186,19 +195,19 @@ def create_key(self, ring, polynomial, names=None): Consequently, you get two distinct objects:: - sage: S = PolynomialQuotientRing(R, x + 1); S + sage: S = PolynomialQuotientRing(R, x + 1); S # optional - sage.libs.pari Univariate Quotient Polynomial Ring in xbar over Rational Field with modulus x + 1 - sage: T = PolynomialQuotientRing(R, 2*x + 2); T + sage: T = PolynomialQuotientRing(R, 2*x + 2); T # optional - sage.libs.pari Univariate Quotient Polynomial Ring in xbar over Rational Field with modulus 2*x + 2 - sage: S is T + sage: S is T # optional - sage.libs.pari False - sage: S == T + sage: S == T # optional - sage.libs.pari False In most applications this will not be a concern since the calling code takes care of normalizing the generators:: - sage: R.quo(x + 1) is R.quo(2*x + 2) + sage: R.quo(x + 1) is R.quo(2*x + 2) # optional - sage.libs.pari True """ @@ -227,7 +236,8 @@ def create_object(self, version, key): EXAMPLES:: sage: R. = QQ[] - sage: PolynomialQuotientRing.create_object((8, 0, 0), (R, x^2 - 1, ('xbar'))) + sage: PolynomialQuotientRing.create_object((8, 0, 0), # optional - sage.libs.pari + ....: (R, x^2 - 1, ('xbar'))) Univariate Quotient Polynomial Ring in xbar over Rational Field with modulus x^2 - 1 """ @@ -265,7 +275,8 @@ class PolynomialQuotientRing_generic(QuotientRing_generic): sage: R. = PolynomialRing(Integers(8)); R Univariate Polynomial Ring in x over Ring of integers modulo 8 sage: S. = R.quotient(x^2 + 1); S - Univariate Quotient Polynomial Ring in xbar over Ring of integers modulo 8 with modulus x^2 + 1 + Univariate Quotient Polynomial Ring in xbar over Ring of integers modulo 8 + with modulus x^2 + 1 We demonstrate object persistence. @@ -281,18 +292,19 @@ class PolynomialQuotientRing_generic(QuotientRing_generic): :: sage: R. = PolynomialRing(ZZ) - sage: S = R.quo(x^2-4) - sage: f = S.hom([2]) - sage: f + sage: S = R.quo(x^2 - 4) # optional - sage.libs.pari + sage: f = S.hom([2]) # optional - sage.libs.pari + sage: f # optional - sage.libs.pari Ring morphism: - From: Univariate Quotient Polynomial Ring in xbar over Integer Ring with modulus x^2 - 4 + From: Univariate Quotient Polynomial Ring in xbar over Integer Ring + with modulus x^2 - 4 To: Integer Ring Defn: xbar |--> 2 - sage: f(x) + sage: f(x) # optional - sage.libs.pari 2 - sage: f(x^2 - 4) + sage: f(x^2 - 4) # optional - sage.libs.pari 0 - sage: f(x^2) + sage: f(x^2) # optional - sage.libs.pari 4 TESTS: @@ -308,8 +320,8 @@ class of the quotient ring and its newly created elements. Thus, in order to document that this works fine, we go into some detail:: sage: P. = QQ[] - sage: Q = P.quotient(x^2+2) - sage: Q.category() + sage: Q = P.quotient(x^2 + 2) # optional - sage.libs.pari + sage: Q.category() # optional - sage.libs.pari Category of commutative no zero divisors quotients of algebras over (number fields and quotient fields and metric spaces) @@ -318,23 +330,24 @@ class of the quotient ring and its newly created elements. class of the category, and store the current class of the quotient ring:: - sage: isinstance(Q.an_element(),Q.element_class) + sage: isinstance(Q.an_element(), Q.element_class) # optional - sage.libs.pari True - sage: [s for s in dir(Q.category().element_class) if not s.startswith('_')] - ['cartesian_product', 'inverse', 'inverse_of_unit', 'is_idempotent', 'is_one', 'is_unit', 'lift', 'powers'] - sage: first_class = Q.__class__ + sage: [s for s in dir(Q.category().element_class) if not s.startswith('_')] # optional - sage.libs.pari + ['cartesian_product', 'inverse', 'inverse_of_unit', 'is_idempotent', + 'is_one', 'is_unit', 'lift', 'powers'] + sage: first_class = Q.__class__ # optional - sage.libs.pari We try to find out whether `Q` is a field. Indeed it is, and thus its category, including its class and element class, is changed accordingly:: - sage: Q in Fields() + sage: Q in Fields() # optional - sage.libs.pari True - sage: Q.category() + sage: Q.category() # optional - sage.libs.pari Category of commutative division no zero divisors quotients of algebras over (number fields and quotient fields and metric spaces) - sage: first_class == Q.__class__ + sage: first_class == Q.__class__ # optional - sage.libs.pari False - sage: [s for s in dir(Q.category().element_class) if not s.startswith('_')] + sage: [s for s in dir(Q.category().element_class) if not s.startswith('_')] # optional - sage.libs.pari ['cartesian_product', 'euclidean_degree', 'factor', @@ -358,22 +371,22 @@ class of the category, and store the current class of the quotient new methods from the category of fields, thanks to :meth:`Element.__getattr__`:: - sage: e = Q.an_element() - sage: isinstance(e, Q.element_class) + sage: e = Q.an_element() # optional - sage.libs.pari + sage: isinstance(e, Q.element_class) # optional - sage.libs.pari False - sage: e.gcd(e+1) + sage: e.gcd(e + 1) # optional - sage.libs.pari 1 The test suite passes. However, we have to skip the test for its elements, since `an_element` has been cached in the call above and its class does not match the new category's element class anymore:: - sage: TestSuite(Q).run(skip=['_test_elements']) + sage: TestSuite(Q).run(skip=['_test_elements']) # optional - sage.libs.pari Newly created elements are fine, though, and their test suite passes:: - sage: TestSuite(Q(x)).run() - sage: isinstance(Q(x), Q.element_class) + sage: TestSuite(Q(x)).run() # optional - sage.libs.pari + sage: isinstance(Q(x), Q.element_class) # optional - sage.libs.pari True """ Element = PolynomialQuotientRingElement @@ -383,18 +396,18 @@ def __init__(self, ring, polynomial, name=None, category=None): TESTS:: sage: R. = PolynomialRing(ZZ) - sage: S = R.quo(x^2-4) + sage: S = R.quo(x^2 - 4) # optional - sage.libs.pari sage: from sage.rings.polynomial.polynomial_quotient_ring import PolynomialQuotientRing_generic - sage: S == PolynomialQuotientRing_generic(R,x^2-4,'xbar') + sage: S == PolynomialQuotientRing_generic(R, x^2 - 4, 'xbar') # optional - sage.libs.pari True Check that :trac:`26161` has been resolved:: - sage: R. = GF(2)[] - sage: S = R.quo(x) - sage: S in FiniteFields() + sage: R. = GF(2)[] # optional - sage.rings.finite_rings + sage: S = R.quo(x) # optional - sage.rings.finite_rings + sage: S in FiniteFields() # optional - sage.rings.finite_rings True - sage: type(S).mro() + sage: type(S).mro() # optional - sage.rings.finite_rings [, ... , @@ -440,18 +453,18 @@ def _element_constructor_(self, x): EXAMPLES:: sage: R. = PolynomialRing(QQ) - sage: S. = R.quotient(x^3-3*x+1) - sage: S(x) + sage: S. = R.quotient(x^3 - 3*x + 1) # optional - sage.libs.pari + sage: S(x) # optional - sage.libs.pari alpha - sage: S(x^3) + sage: S(x^3) # optional - sage.libs.pari 3*alpha - 1 - sage: S([1,2]) + sage: S([1,2]) # optional - sage.libs.pari 2*alpha + 1 - sage: S([1,2,3,4,5]) + sage: S([1,2,3,4,5]) # optional - sage.libs.pari 18*alpha^2 + 9*alpha - 3 - sage: S(S.gen()+1) + sage: S(S.gen()+1) # optional - sage.libs.pari alpha + 1 - sage: S(S.gen()^10+1) + sage: S(S.gen()^10+1) # optional - sage.libs.pari 90*alpha^2 - 109*alpha + 28 TESTS: @@ -460,53 +473,54 @@ def _element_constructor_(self, x): This was fixed in :trac:`8800`:: sage: P. = QQ[] - sage: Q1 = P.quo([(x^2+1)^2*(x^2-3)]) - sage: Q = P.quo([(x^2+1)^2]) - sage: Q1.has_coerce_map_from(Q) + sage: Q1 = P.quo([(x^2+1)^2*(x^2-3)]) # optional - sage.libs.pari + sage: Q = P.quo([(x^2+1)^2]) # optional - sage.libs.pari + sage: Q1.has_coerce_map_from(Q) # optional - sage.libs.pari False - sage: Q1(Q.gen()) + sage: Q1(Q.gen()) # optional - sage.libs.pari xbar Here we test against several issues discussed in :trac:`8992`:: sage: P. = QQ[] - sage: Q1 = P.quo([(x^2+1)^2*(x^2-3)]) - sage: Q2 = P.quo([(x^2+1)^2*(x^5+3)]) - sage: p = Q1.gen() + Q2.gen() - sage: p + sage: Q1 = P.quo([(x^2+1)^2*(x^2-3)]) # optional - sage.libs.pari + sage: Q2 = P.quo([(x^2+1)^2*(x^5+3)]) # optional - sage.libs.pari + sage: p = Q1.gen() + Q2.gen() # optional - sage.libs.pari + sage: p # optional - sage.libs.pari 2*xbar - sage: p.parent() - Univariate Quotient Polynomial Ring in xbar over Rational Field with modulus x^4 + 2*x^2 + 1 - sage: p.parent()('xbar') + sage: p.parent() # optional - sage.libs.pari + Univariate Quotient Polynomial Ring in xbar over Rational Field + with modulus x^4 + 2*x^2 + 1 + sage: p.parent()('xbar') # optional - sage.libs.pari xbar Note that the result of string conversion has the correct parent, even when the given string suggests an element of the cover ring or the base ring:: - sage: a = Q1('x'); a + sage: a = Q1('x'); a # optional - sage.libs.pari xbar - sage: a.parent() is Q1 + sage: a.parent() is Q1 # optional - sage.libs.pari True - sage: b = Q1('1'); b + sage: b = Q1('1'); b # optional - sage.libs.pari 1 - sage: b.parent() is Q1 + sage: b.parent() is Q1 # optional - sage.libs.pari True Conversion may lift an element of one quotient ring to the base ring of another quotient ring:: - sage: R. = P[] - sage: Q3 = R.quo([(y^2+1)]) - sage: Q3(Q1.gen()) + sage: R. = P[] # optional - sage.libs.pari + sage: Q3 = R.quo([(y^2+1)]) # optional - sage.libs.pari + sage: Q3(Q1.gen()) # optional - sage.libs.pari x - sage: Q3.has_coerce_map_from(Q1) + sage: Q3.has_coerce_map_from(Q1) # optional - sage.libs.pari False String conversion takes into account both the generators of the quotient ring and its base ring:: - sage: Q3('x*ybar^2') + sage: Q3('x*ybar^2') # optional - sage.libs.pari -x """ @@ -548,25 +562,25 @@ def _coerce_map_from_(self, R): TESTS:: - sage: P5. = GF(5)[] - sage: Q = P5.quo([(x^2+1)^2]) + sage: P5. = GF(5)[] # optional - sage.rings.finite_rings + sage: Q = P5.quo([(x^2+1)^2]) # optional - sage.rings.finite_rings sage: P. = ZZ[] - sage: Q1 = P.quo([(x^2+1)^2*(x^2-3)]) - sage: Q2 = P.quo([(x^2+1)^2*(x^5+3)]) - sage: Q.has_coerce_map_from(Q1) #indirect doctest + sage: Q1 = P.quo([(x^2+1)^2*(x^2-3)]) # optional - sage.libs.pari + sage: Q2 = P.quo([(x^2+1)^2*(x^5+3)]) # optional - sage.libs.pari + sage: Q.has_coerce_map_from(Q1) #indirect doctest # optional - sage.libs.pari sage.rings.finite_rings True - sage: Q1.has_coerce_map_from(Q) + sage: Q1.has_coerce_map_from(Q) # optional - sage.libs.pari sage.rings.finite_rings False - sage: Q1.has_coerce_map_from(Q2) + sage: Q1.has_coerce_map_from(Q2) # optional - sage.libs.pari sage.rings.finite_rings False The following tests against a bug fixed in :trac:`8992`:: sage: P. = QQ[] - sage: Q1 = P.quo([(x^2+1)^2*(x^2-3)]) + sage: Q1 = P.quo([(x^2+1)^2*(x^2-3)]) # optional - sage.libs.pari sage: R. = P[] - sage: Q2 = R.quo([(y^2+1)]) - sage: Q2.has_coerce_map_from(Q1) + sage: Q2 = R.quo([(y^2 + 1)]) # optional - sage.libs.pari + sage: Q2.has_coerce_map_from(Q1) # optional - sage.libs.pari False """ @@ -587,15 +601,15 @@ def _is_valid_homomorphism_(self, codomain, im_gens, base_map=None): EXAMPLES:: sage: T. = ZZ[] - sage: K. = NumberField(t^2 + 1) - sage: R. = K[] - sage: S. = R.quotient(x^2 - i) - sage: Q8. = CyclotomicField(8) - sage: S._is_valid_homomorphism_(Q8, [z]) # no coercion from K to Q8 + sage: K. = NumberField(t^2 + 1) # optional - sage.rings.number_field + sage: R. = K[] # optional - sage.rings.number_field + sage: S. = R.quotient(x^2 - i) # optional - sage.rings.number_field + sage: Q8. = CyclotomicField(8) # optional - sage.rings.number_field + sage: S._is_valid_homomorphism_(Q8, [z]) # no coercion from K to Q8 # optional - sage.rings.number_field False - sage: S._is_valid_homomorphism_(Q8, [z], K.hom([z^2])) + sage: S._is_valid_homomorphism_(Q8, [z], K.hom([z^2])) # optional - sage.rings.number_field True - sage: S._is_valid_homomorphism_(Q8, [1/z], K.hom([z^-2])) + sage: S._is_valid_homomorphism_(Q8, [1/z], K.hom([z^-2])) # optional - sage.rings.number_field True """ if base_map is None and not codomain.has_coerce_map_from(self.base_ring()): @@ -645,12 +659,12 @@ def lift(self, x): EXAMPLES:: sage: P. = QQ[] - sage: Q = P.quotient(x^2+2) - sage: Q.lift(Q.0^3) + sage: Q = P.quotient(x^2 + 2) # optional - sage.libs.pari + sage: Q.lift(Q.0^3) # optional - sage.libs.pari -2*x - sage: Q(-2*x) + sage: Q(-2*x) # optional - sage.libs.pari -2*xbar - sage: Q.0^3 + sage: Q.0^3 # optional - sage.libs.pari -2*xbar """ @@ -666,14 +680,14 @@ def __eq__(self, other): sage: Ry. = PolynomialRing(QQ) sage: Rx == Ry False - sage: Qx = Rx.quotient(x^2+1) - sage: Qy = Ry.quotient(y^2+1) - sage: Qx == Qy + sage: Qx = Rx.quotient(x^2 + 1) # optional - sage.libs.pari + sage: Qy = Ry.quotient(y^2 + 1) # optional - sage.libs.pari + sage: Qx == Qy # optional - sage.libs.pari False - sage: Qx == Qx + sage: Qx == Qx # optional - sage.libs.pari True - sage: Qz = Rx.quotient(x^2+1) - sage: Qz == Qx + sage: Qz = Rx.quotient(x^2 + 1) # optional - sage.libs.pari + sage: Qz == Qx # optional - sage.libs.pari True """ if not isinstance(other, PolynomialQuotientRing_generic): @@ -691,14 +705,14 @@ def __ne__(self, other): sage: Ry. = PolynomialRing(QQ) sage: Rx != Ry True - sage: Qx = Rx.quotient(x^2+1) - sage: Qy = Ry.quotient(y^2+1) - sage: Qx != Qy + sage: Qx = Rx.quotient(x^2 + 1) # optional - sage.libs.pari + sage: Qy = Ry.quotient(y^2 + 1) # optional - sage.libs.pari + sage: Qx != Qy # optional - sage.libs.pari True - sage: Qx != Qx + sage: Qx != Qx # optional - sage.libs.pari False - sage: Qz = Rx.quotient(x^2+1) - sage: Qz != Qx + sage: Qz = Rx.quotient(x^2 + 1) # optional - sage.libs.pari + sage: Qz != Qx # optional - sage.libs.pari False """ return not (self == other) @@ -713,14 +727,14 @@ def __hash__(self): sage: Ry. = PolynomialRing(QQ) sage: hash(Rx) == hash(Ry) False - sage: Qx = Rx.quotient(x^2+1) - sage: Qy = Ry.quotient(y^2+1) - sage: hash(Qx) == hash(Qy) + sage: Qx = Rx.quotient(x^2 + 1) # optional - sage.libs.pari + sage: Qy = Ry.quotient(y^2 + 1) # optional - sage.libs.pari + sage: hash(Qx) == hash(Qy) # optional - sage.libs.pari False - sage: hash(Qx) == hash(Qx) + sage: hash(Qx) == hash(Qx) # optional - sage.libs.pari True - sage: Qz = Rx.quotient(x^2+1) - sage: hash(Qz) == hash(Qx) + sage: Qz = Rx.quotient(x^2 + 1) # optional - sage.libs.pari + sage: hash(Qz) == hash(Qx) # optional - sage.libs.pari True """ return hash((self.polynomial_ring(), self.modulus())) @@ -732,8 +746,8 @@ def _singular_init_(self, S=None): TESTS:: sage: P. = QQ[] - sage: Q = P.quo([(x^2+1)]) - sage: singular(Q) # indirect doctest + sage: Q = P.quo([(x^2 + 1)]) # optional - sage.libs.pari + sage: singular(Q) # indirect doctest # optional - sage.libs.pari polynomial ring, over a field, global ordering // coefficients: QQ // number of vars : 1 @@ -742,7 +756,7 @@ def _singular_init_(self, S=None): // block 2 : ordering C // quotient ring from ideal _[1]=xbar^2+1 - sage: singular(Q.gen()) + sage: singular(Q.gen()) # optional - sage.libs.pari xbar """ @@ -766,15 +780,15 @@ def construction(self): EXAMPLES:: - sage: P.=ZZ[] - sage: Q = P.quo(5+t^2) - sage: F, R = Q.construction() - sage: F(R) == Q + sage: P. = ZZ[] + sage: Q = P.quo(5 + t^2) # optional - sage.libs.pari + sage: F, R = Q.construction() # optional - sage.libs.pari + sage: F(R) == Q # optional - sage.libs.pari True - sage: P. = GF(3)[] - sage: Q = P.quo([2+t^2]) - sage: F, R = Q.construction() - sage: F(R) == Q + sage: P. = GF(3)[] # optional - sage.rings.finite_rings + sage: Q = P.quo([2 + t^2]) # optional - sage.rings.finite_rings + sage: F, R = Q.construction() # optional - sage.rings.finite_rings + sage: F(R) == Q # optional - sage.rings.finite_rings True AUTHOR: @@ -803,8 +817,8 @@ def base_ring(self): :: sage: R. = PolynomialRing(ZZ) - sage: S. = R.quo(z^3 + z^2 + z + 1) - sage: S.base_ring() + sage: S. = R.quo(z^3 + z^2 + z + 1) # optional - sage.libs.pari + sage: S.base_ring() # optional - sage.libs.pari Integer Ring Next we make a polynomial quotient ring over `S` and ask @@ -812,10 +826,11 @@ def base_ring(self): :: - sage: T. = PolynomialRing(S) - sage: W = T.quotient(t^99 + 99) - sage: W.base_ring() - Univariate Quotient Polynomial Ring in beta over Integer Ring with modulus z^3 + z^2 + z + 1 + sage: T. = PolynomialRing(S) # optional - sage.libs.pari + sage: W = T.quotient(t^99 + 99) # optional - sage.libs.pari + sage: W.base_ring() # optional - sage.libs.pari + Univariate Quotient Polynomial Ring in beta + over Integer Ring with modulus z^3 + z^2 + z + 1 """ return self.__ring.base_ring() @@ -830,22 +845,22 @@ def cardinality(self): sage: R. = ZZ[] sage: R.quo(1).cardinality() 1 - sage: R.quo(x^3-2).cardinality() + sage: R.quo(x^3 - 2).cardinality() # optional - sage.libs.pari +Infinity sage: R.quo(1).order() 1 - sage: R.quo(x^3-2).order() + sage: R.quo(x^3 - 2).order() # optional - sage.libs.pari +Infinity :: - sage: R. = GF(9,'a')[] - sage: R.quo(2*x^3+x+1).cardinality() + sage: R. = GF(9, 'a')[] # optional - sage.rings.finite_rings + sage: R.quo(2*x^3 + x + 1).cardinality() # optional - sage.rings.finite_rings 729 - sage: GF(9,'a').extension(2*x^3+x+1).cardinality() + sage: GF(9, 'a').extension(2*x^3 + x + 1).cardinality() # optional - sage.rings.finite_rings 729 - sage: R.quo(2).cardinality() + sage: R.quo(2).cardinality() # optional - sage.rings.finite_rings 1 TESTS:: @@ -879,21 +894,21 @@ def is_finite(self): sage: R. = ZZ[] sage: R.quo(1).is_finite() True - sage: R.quo(x^3-2).is_finite() + sage: R.quo(x^3 - 2).is_finite() # optional - sage.libs.pari False :: - sage: R. = GF(9,'a')[] - sage: R.quo(2*x^3+x+1).is_finite() + sage: R. = GF(9, 'a')[] # optional - sage.rings.finite_rings + sage: R.quo(2*x^3 + x + 1).is_finite() # optional - sage.rings.finite_rings True - sage: R.quo(2).is_finite() + sage: R.quo(2).is_finite() # optional - sage.rings.finite_rings True :: - sage: P. = GF(2)[] - sage: P.quotient(v^2-v).is_finite() + sage: P. = GF(2)[] # optional - sage.rings.finite_rings + sage: P.quotient(v^2 - v).is_finite() # optional - sage.rings.finite_rings True """ f = self.modulus() @@ -909,9 +924,9 @@ def __iter__(self): r""" EXAMPLES:: - sage: R. = GF(3)[] - sage: Q = R.quo(x^3 - x^2 - x - 1) - sage: list(Q) + sage: R. = GF(3)[] # optional - sage.rings.finite_rings + sage: Q = R.quo(x^3 - x^2 - x - 1) # optional - sage.rings.finite_rings + sage: list(Q) # optional - sage.rings.finite_rings [0, 1, 2, @@ -922,7 +937,7 @@ def __iter__(self): ... 2*xbar^2 + 2*xbar + 1, 2*xbar^2 + 2*xbar + 2] - sage: len(_) == Q.cardinality() == 27 + sage: len(_) == Q.cardinality() == 27 # optional - sage.rings.finite_rings True """ if not self.is_finite(): @@ -943,12 +958,12 @@ def characteristic(self): EXAMPLES:: sage: R. = PolynomialRing(ZZ) - sage: S. = R.quo(z - 19) - sage: S.characteristic() + sage: S. = R.quo(z - 19) # optional - sage.libs.pari + sage: S.characteristic() # optional - sage.libs.pari 0 - sage: R. = PolynomialRing(GF(9,'a')) - sage: S = R.quotient(x^3 + 1) - sage: S.characteristic() + sage: R. = PolynomialRing(GF(9, 'a')) # optional - sage.rings.finite_rings + sage: S = R.quotient(x^3 + 1) # optional - sage.rings.finite_rings + sage: S.characteristic() # optional - sage.rings.finite_rings 3 """ return self.base_ring().characteristic() @@ -960,9 +975,9 @@ def degree(self): EXAMPLES:: - sage: R. = PolynomialRing(GF(3)) - sage: S = R.quotient(x^2005 + 1) - sage: S.degree() + sage: R. = PolynomialRing(GF(3)) # optional - sage.rings.finite_rings + sage: S = R.quotient(x^2005 + 1) # optional - sage.rings.finite_rings + sage: S.degree() # optional - sage.rings.finite_rings 2005 """ return self.modulus().degree() @@ -976,11 +991,11 @@ def discriminant(self, v=None): EXAMPLES:: sage: R. = PolynomialRing(QQ) - sage: S = R.quotient(x^3 + x^2 + x + 1) - sage: S.discriminant() + sage: S = R.quotient(x^3 + x^2 + x + 1) # optional - sage.libs.pari + sage: S.discriminant() # optional - sage.libs.pari -16 - sage: S = R.quotient((x + 1) * (x + 1)) - sage: S.discriminant() + sage: S = R.quotient((x + 1) * (x + 1)) # optional - sage.libs.pari + sage: S.discriminant() # optional - sage.libs.pari 0 The discriminant of the quotient polynomial ring need not equal the @@ -988,10 +1003,10 @@ def discriminant(self, v=None): discriminant of a number field is by definition the discriminant of the ring of integers of the number field:: - sage: S = R.quotient(x^2 - 8) - sage: S.number_field().discriminant() + sage: S = R.quotient(x^2 - 8) # optional - sage.libs.pari + sage: S.number_field().discriminant() # optional - sage.libs.pari 8 - sage: S.discriminant() + sage: S.discriminant() # optional - sage.libs.pari 32 """ return self.modulus().discriminant() @@ -1004,8 +1019,8 @@ class of the image of the generator of the polynomial ring. EXAMPLES:: sage: R. = PolynomialRing(QQ) - sage: S = R.quotient(x^2 - 8, 'gamma') - sage: S.gen() + sage: S = R.quotient(x^2 - 8, 'gamma') # optional - sage.libs.pari + sage: S.gen() # optional - sage.libs.pari gamma """ if n != 0: @@ -1023,26 +1038,28 @@ def is_field(self, proof = True): EXAMPLES:: sage: R. = PolynomialRing(ZZ) - sage: S = R.quo(z^2-2) - sage: S.is_field() + sage: S = R.quo(z^2 - 2) # optional - sage.libs.pari + sage: S.is_field() # optional - sage.libs.pari False sage: R. = PolynomialRing(QQ) - sage: S = R.quotient(x^2 - 2) - sage: S.is_field() + sage: S = R.quotient(x^2 - 2) # optional - sage.libs.pari + sage: S.is_field() # optional - sage.libs.pari True If proof is ``True``, requires the ``is_irreducible`` method of the modulus to be implemented:: - sage: R1. = Qp(2)[] - sage: F1 = R1.quotient_ring(x^2+x+1) - sage: R2. = F1[] - sage: F2 = R2.quotient_ring(x^2+x+1) - sage: F2.is_field() + sage: R1. = Qp(2)[] # optional - sage.rings.padics + sage: F1 = R1.quotient_ring(x^2 + x + 1) # optional - sage.rings.padics + sage: R2. = F1[] # optional - sage.rings.padics + sage: F2 = R2.quotient_ring(x^2 + x + 1) # optional - sage.rings.padics + sage: F2.is_field() # optional - sage.rings.padics Traceback (most recent call last): ... - NotImplementedError: cannot rewrite Univariate Quotient Polynomial Ring in xbar over 2-adic Field with capped relative precision 20 with modulus (1 + O(2^20))*x^2 + (1 + O(2^20))*x + 1 + O(2^20) as an isomorphic ring - sage: F2.is_field(proof = False) + NotImplementedError: cannot rewrite Univariate Quotient Polynomial Ring in + xbar over 2-adic Field with capped relative precision 20 with modulus + (1 + O(2^20))*x^2 + (1 + O(2^20))*x + 1 + O(2^20) as an isomorphic ring + sage: F2.is_field(proof = False) # optional - sage.rings.padics False """ @@ -1067,25 +1084,25 @@ def is_integral_domain(self, proof = True): EXAMPLES:: sage: R. = PolynomialRing(ZZ) - sage: S = R.quotient(z^2 - z) - sage: S.is_integral_domain() + sage: S = R.quotient(z^2 - z) # optional - sage.libs.pari + sage: S.is_integral_domain() # optional - sage.libs.pari False - sage: T = R.quotient(z^2 + 1) - sage: T.is_integral_domain() + sage: T = R.quotient(z^2 + 1) # optional - sage.libs.pari + sage: T.is_integral_domain() # optional - sage.libs.pari True sage: U = R.quotient(-1) sage: U.is_integral_domain() False sage: R2. = PolynomialRing(R) - sage: S2 = R2.quotient(z^2 - y^3) - sage: S2.is_integral_domain() + sage: S2 = R2.quotient(z^2 - y^3) # optional - sage.libs.pari + sage: S2.is_integral_domain() # optional - sage.libs.pari True - sage: S3 = R2.quotient(z^2 - 2*y*z + y^2) - sage: S3.is_integral_domain() + sage: S3 = R2.quotient(z^2 - 2*y*z + y^2) # optional - sage.libs.pari + sage: S3.is_integral_domain() # optional - sage.libs.pari False sage: R. = PolynomialRing(ZZ.quotient(4)) - sage: S = R.quotient(z-1) + sage: S = R.quotient(z - 1) sage: S.is_integral_domain() False @@ -1095,17 +1112,18 @@ def is_integral_domain(self, proof = True): domain, even though the base ring is integral and the modulus is irreducible:: - sage: B = ZZ.extension(x^2 - 5, 'a') - sage: R. = PolynomialRing(B) - sage: S = R.quotient(y^2 - y - 1) - sage: S.is_integral_domain() + sage: x = polygen(ZZ, 'x') + sage: B = ZZ.extension(x^2 - 5, 'a') # optional - sage.rings.number_field + sage: R. = PolynomialRing(B) # optional - sage.rings.number_field + sage: S = R.quotient(y^2 - y - 1) # optional - sage.libs.pari sage.rings.number_field + sage: S.is_integral_domain() # optional - sage.libs.pari sage.rings.number_field Traceback (most recent call last): ... NotImplementedError - sage: S.is_integral_domain(proof = False) + sage: S.is_integral_domain(proof=False) # optional - sage.libs.pari sage.rings.number_field False - The reason that the modulus y^2 - y -1 is not prime is that it + The reason that the modulus y^2 - y - 1 is not prime is that it divides the product (2*y-(1+a))*(2*y-(1-a)) = 4*y^2 - 4*y - 4. @@ -1150,11 +1168,12 @@ def krull_dimension(self): EXAMPLES:: - sage: R = PolynomialRing(ZZ,'x').quotient(x**6-1) - sage: R.krull_dimension() + sage: x = polygen(ZZ, 'x') + sage: R = PolynomialRing(ZZ, 'x').quotient(x**6 - 1) # optional - sage.libs.pari + sage: R.krull_dimension() # optional - sage.libs.pari 1 - sage: R = PolynomialRing(ZZ,'x').quotient(1) - sage: R.krull_dimension() + sage: R = PolynomialRing(ZZ, 'x').quotient(1) # optional - sage.libs.pari + sage: R.krull_dimension() # optional - sage.libs.pari -1 """ if self.is_zero(): @@ -1167,9 +1186,9 @@ def modulus(self): EXAMPLES:: - sage: R. = PolynomialRing(GF(3)) - sage: S = R.quotient(x^2 - 2) - sage: S.modulus() + sage: R. = PolynomialRing(GF(3)) # optional - sage.rings.finite_rings + sage: S = R.quotient(x^2 - 2) # optional - sage.rings.finite_rings + sage: S.modulus() # optional - sage.rings.finite_rings x^2 + 1 """ return self.__polynomial @@ -1199,12 +1218,11 @@ def number_field(self): EXAMPLES:: sage: R. = PolynomialRing(QQ) - sage: S. = R.quotient(x^29 - 17*x - 1) - sage: K = S.number_field() - sage: K + sage: S. = R.quotient(x^29 - 17*x - 1) # optional - sage.libs.pari + sage: K = S.number_field(); K # optional - sage.libs.pari sage.rings.number_field Number Field in alpha with defining polynomial x^29 - 17*x - 1 - sage: alpha = K.gen() - sage: alpha^29 + sage: alpha = K.gen() # optional - sage.libs.pari sage.rings.number_field + sage: alpha^29 # optional - sage.libs.pari sage.rings.number_field 17*alpha + 1 """ if self.characteristic() != 0: @@ -1222,8 +1240,8 @@ def polynomial_ring(self): EXAMPLES:: sage: R. = PolynomialRing(QQ) - sage: S = R.quotient(x^2-2) - sage: S.polynomial_ring() + sage: S = R.quotient(x^2 - 2) # optional - sage.libs.pari + sage: S.polynomial_ring() # optional - sage.libs.pari Univariate Polynomial Ring in x over Rational Field """ return self.__ring @@ -1246,10 +1264,10 @@ def random_element(self, *args, **kwds): EXAMPLES:: - sage: F1. = GF(2^7) - sage: P1. = F1[] - sage: F2 = F1.extension(x^2+x+1, 'u') - sage: F2.random_element().parent() is F2 + sage: F1. = GF(2^7) # optional - sage.rings.finite_rings + sage: P1. = F1[] # optional - sage.rings.finite_rings + sage: F2 = F1.extension(x^2 + x + 1, 'u') # optional - sage.rings.finite_rings + sage: F2.random_element().parent() is F2 # optional - sage.rings.finite_rings True """ return self(self.polynomial_ring().random_element( @@ -1265,22 +1283,22 @@ def _S_decomposition(self, S): EXAMPLES:: - sage: K. = QuadraticField(-5) - sage: R. = K[] - sage: S. = R.quotient((x^2 + 23)*(x^2 + 31)) - sage: fields, isos, iso_classes = S._S_decomposition(tuple(K.primes_above(3))) + sage: K. = QuadraticField(-5) # optional - sage.rings.number_field + sage: R. = K[] # optional - sage.rings.number_field + sage: S. = R.quotient((x^2 + 23) * (x^2 + 31)) # optional - sage.rings.number_field + sage: fields, isos, iso_classes = S._S_decomposition(tuple(K.primes_above(3))) # optional - sage.rings.number_field Representatives of the number fields up to isomorphism that occur in the decomposition:: - sage: fields + sage: fields # optional - sage.rings.number_field [Number Field in x0 with defining polynomial x^2 + 23 over its base field, Number Field in x1 with defining polynomial x^2 + 31 over its base field] In this case, the isomorphisms of these representatives to the components are the identity maps:: - sage: isos + sage: isos # optional - sage.rings.number_field [(Ring endomorphism of Number Field in y0 with defining polynomial x^4 + 56*x^2 + 324 Defn: y0 |--> y0, 0), @@ -1291,9 +1309,9 @@ def _S_decomposition(self, S): There are four primes above 3 in the first component and two in the second component:: - sage: len(iso_classes[0][1]) + sage: len(iso_classes[0][1]) # optional - sage.rings.number_field 4 - sage: len(iso_classes[1][1]) + sage: len(iso_classes[1][1]) # optional - sage.rings.number_field 2 """ from sage.rings.number_field.number_field_base import NumberField @@ -1340,7 +1358,7 @@ def _S_decomposition(self, S): def S_class_group(self, S, proof=True): r""" - If self is an étale algebra `D` over a number field `K` (i.e. + If ``self`` is an étale algebra `D` over a number field `K` (i.e. a quotient of `K[x]` by a squarefree polynomial) and `S` is a finite set of places of `K`, return a list of generators of the `S`-class group of `D`. @@ -1372,42 +1390,43 @@ def S_class_group(self, S, proof=True): A trivial algebra over `\QQ(\sqrt{-5})` has the same class group as its base:: - sage: K. = QuadraticField(-5) - sage: R. = K[] - sage: S. = R.quotient(x) - sage: S.S_class_group([]) + sage: K. = QuadraticField(-5) # optional - sage.rings.number_field + sage: R. = K[] # optional - sage.rings.number_field + sage: S. = R.quotient(x) # optional - sage.rings.number_field + sage: S.S_class_group([]) # optional - sage.rings.number_field [((2, -a + 1), 2)] When we include the prime `(2, -a+1)`, the `S`-class group becomes trivial:: - sage: S.S_class_group([K.ideal(2, -a+1)]) + sage: S.S_class_group([K.ideal(2, -a+1)]) # optional - sage.rings.number_field [] Here is an example where the base and the extension both contribute to the class group:: - sage: K. = QuadraticField(-5) - sage: K.class_group() - Class group of order 2 with structure C2 of Number Field in a with defining polynomial x^2 + 5 with a = 2.236067977499790?*I - sage: R. = K[] - sage: S. = R.quotient(x^2 + 23) - sage: S.S_class_group([]) + sage: K. = QuadraticField(-5) # optional - sage.rings.number_field + sage: K.class_group() # optional - sage.rings.number_field + Class group of order 2 with structure C2 of Number Field in a + with defining polynomial x^2 + 5 with a = 2.236067977499790?*I + sage: R. = K[] # optional - sage.rings.number_field + sage: S. = R.quotient(x^2 + 23) # optional - sage.rings.number_field + sage: S.S_class_group([]) # optional - sage.rings.number_field [((2, -a + 1, 1/2*xbar + 1/2, -1/2*a*xbar + 1/2*a + 1), 6)] - sage: S.S_class_group([K.ideal(3, a-1)]) + sage: S.S_class_group([K.ideal(3, a-1)]) # optional - sage.rings.number_field [] - sage: S.S_class_group([K.ideal(2, a+1)]) + sage: S.S_class_group([K.ideal(2, a+1)]) # optional - sage.rings.number_field [] - sage: S.S_class_group([K.ideal(a)]) + sage: S.S_class_group([K.ideal(a)]) # optional - sage.rings.number_field [((2, -a + 1, 1/2*xbar + 1/2, -1/2*a*xbar + 1/2*a + 1), 6)] Now we take an example over a nontrivial base with two factors, each contributing to the class group:: - sage: K. = QuadraticField(-5) - sage: R. = K[] - sage: S. = R.quotient((x^2 + 23)*(x^2 + 31)) - sage: S.S_class_group([]) # representation varies, not tested + sage: K. = QuadraticField(-5) # optional - sage.rings.number_field + sage: R. = K[] # optional - sage.rings.number_field + sage: S. = R.quotient((x^2 + 23) * (x^2 + 31)) # optional - sage.rings.number_field + sage: S.S_class_group([]) # representation varies, not tested # optional - sage.rings.number_field [((1/4*xbar^2 + 31/4, (-1/8*a + 1/8)*xbar^2 - 31/8*a + 31/8, 1/16*xbar^3 + 1/16*xbar^2 + 31/16*xbar + 31/16, @@ -1428,26 +1447,33 @@ def S_class_group(self, S, proof=True): `x^2 + 31` from 12 to 2, i.e. we lose a generator of order 6 (this was fixed in :trac:`14489`):: - sage: S.S_class_group([K.ideal(a)]) # representation varies, not tested - [((1/4*xbar^2 + 31/4, (-1/8*a + 1/8)*xbar^2 - 31/8*a + 31/8, 1/16*xbar^3 + 1/16*xbar^2 + 31/16*xbar + 31/16, -1/16*a*xbar^3 + (1/16*a + 1/8)*xbar^2 - 31/16*a*xbar + 31/16*a + 31/8), 6), ((-1/4*xbar^2 - 23/4, (1/8*a - 1/8)*xbar^2 + 23/8*a - 23/8, -1/16*xbar^3 - 1/16*xbar^2 - 23/16*xbar - 23/16, 1/16*a*xbar^3 + (-1/16*a - 1/8)*xbar^2 + 23/16*a*xbar - 23/16*a - 23/8), 2)] + sage: S.S_class_group([K.ideal(a)]) # representation varies, not tested # optional - sage.rings.number_field + [((1/4*xbar^2 + 31/4, (-1/8*a + 1/8)*xbar^2 - 31/8*a + 31/8, + 1/16*xbar^3 + 1/16*xbar^2 + 31/16*xbar + 31/16, + -1/16*a*xbar^3 + (1/16*a + 1/8)*xbar^2 - 31/16*a*xbar + 31/16*a + 31/8), + 6), + ((-1/4*xbar^2 - 23/4, (1/8*a - 1/8)*xbar^2 + 23/8*a - 23/8, + -1/16*xbar^3 - 1/16*xbar^2 - 23/16*xbar - 23/16, + 1/16*a*xbar^3 + (-1/16*a - 1/8)*xbar^2 + 23/16*a*xbar - 23/16*a - 23/8), + 2)] Note that all the returned values live where we expect them to:: - sage: CG = S.S_class_group([]) - sage: type(CG[0][0][1]) + sage: CG = S.S_class_group([]) # optional - sage.rings.number_field + sage: type(CG[0][0][1]) # optional - sage.rings.number_field - sage: type(CG[0][1]) + sage: type(CG[0][1]) # optional - sage.rings.number_field TESTS: We verify the above test, where the representation depends on the PARI version:: - sage: K. = QuadraticField(-5) - sage: R. = K[] - sage: S. = R.quotient((x^2 + 23)*(x^2 + 31)) - sage: C = S.S_class_group([]) - sage: C[:2] + sage: K. = QuadraticField(-5) # optional - sage.rings.number_field + sage: R. = K[] # optional - sage.rings.number_field + sage: S. = R.quotient((x^2 + 23) * (x^2 + 31)) # optional - sage.rings.number_field + sage: C = S.S_class_group([]) # optional - sage.rings.number_field + sage: C[:2] # optional - sage.rings.number_field [((1/4*xbar^2 + 31/4, (-1/8*a + 1/8)*xbar^2 - 31/8*a + 31/8, 1/16*xbar^3 + 1/16*xbar^2 + 31/16*xbar + 31/16, @@ -1458,21 +1484,21 @@ def S_class_group(self, S, proof=True): -1/16*xbar^3 - 1/16*xbar^2 - 23/16*xbar - 23/16, 1/16*a*xbar^3 + (-1/16*a - 1/8)*xbar^2 + 23/16*a*xbar - 23/16*a - 23/8), 6)] - sage: C[2][1] + sage: C[2][1] # optional - sage.rings.number_field 2 - sage: gens = C[2][0] - sage: expected_gens = ( + sage: gens = C[2][0] # optional - sage.rings.number_field + sage: expected_gens = ( # optional - sage.rings.number_field ....: -5/4*xbar^2 - 115/4, ....: 1/4*a*xbar^2 + 23/4*a, ....: -1/16*xbar^3 - 7/16*xbar^2 - 23/16*xbar - 161/16, ....: 1/16*a*xbar^3 - 1/16*a*xbar^2 + 23/16*a*xbar - 23/16*a) - sage: gens[0] == expected_gens[0] + sage: gens[0] == expected_gens[0] # optional - sage.rings.number_field True - sage: gens[1] in (expected_gens[1], expected_gens[1]/2 + expected_gens[0]/2) + sage: gens[1] in (expected_gens[1], expected_gens[1]/2 + expected_gens[0]/2) # optional - sage.rings.number_field True - sage: gens[2] in (expected_gens[2], expected_gens[2] + expected_gens[0]/2) + sage: gens[2] in (expected_gens[2], expected_gens[2] + expected_gens[0]/2) # optional - sage.rings.number_field True - sage: gens[3] in (expected_gens[3], expected_gens[3] + expected_gens[0]/2) + sage: gens[3] in (expected_gens[3], expected_gens[3] + expected_gens[0]/2) # optional - sage.rings.number_field True """ fields, isos, iso_classes = self._S_decomposition(tuple(S)) @@ -1503,7 +1529,7 @@ def S_class_group(self, S, proof=True): def class_group(self, proof=True): r""" - If self is a quotient ring of a polynomial ring over a number + If ``self`` is a quotient ring of a polynomial ring over a number field `K`, by a polynomial of nonzero discriminant, return a list of generators of the class group. @@ -1527,54 +1553,62 @@ def class_group(self, proof=True): EXAMPLES:: - sage: K. = QuadraticField(-3) - sage: K.class_group() - Class group of order 1 of Number Field in a with defining polynomial x^2 + 3 with a = 1.732050807568878?*I - sage: K. = QQ['x'].quotient(x^2 + 3) - sage: K.class_group() + sage: K. = QuadraticField(-3) # optional - sage.rings.number_field + sage: K.class_group() # optional - sage.rings.number_field + Class group of order 1 of Number Field in a + with defining polynomial x^2 + 3 with a = 1.732050807568878?*I + sage: K. = QQ['x'].quotient(x^2 + 3) # optional - sage.libs.pari sage.rings.number_field + sage: K.class_group() # optional - sage.libs.pari sage.rings.number_field [] A trivial algebra over `\QQ(\sqrt{-5})` has the same class group as its base:: - sage: K. = QuadraticField(-5) - sage: R. = K[] - sage: S. = R.quotient(x) - sage: S.class_group() + sage: K. = QuadraticField(-5) # optional - sage.rings.number_field + sage: R. = K[] # optional - sage.rings.number_field + sage: S. = R.quotient(x) # optional - sage.rings.number_field + sage: S.class_group() # optional - sage.rings.number_field [((2, -a + 1), 2)] The same algebra constructed in a different way:: - sage: K. = QQ['x'].quotient(x^2 + 5) - sage: K.class_group(()) + sage: x = polygen(ZZ, 'x') + sage: K. = QQ['x'].quotient(x^2 + 5) # optional - sage.libs.pari + sage: K.class_group(()) # optional - sage.libs.pari [((2, a + 1), 2)] Here is an example where the base and the extension both contribute to the class group:: - sage: K. = QuadraticField(-5) - sage: K.class_group() - Class group of order 2 with structure C2 of Number Field in a with defining polynomial x^2 + 5 with a = 2.236067977499790?*I - sage: R. = K[] - sage: S. = R.quotient(x^2 + 23) - sage: S.class_group() + sage: K. = QuadraticField(-5) # optional - sage.rings.number_field + sage: K.class_group() # optional - sage.rings.number_field + Class group of order 2 with structure C2 of Number Field in a + with defining polynomial x^2 + 5 with a = 2.236067977499790?*I + sage: R. = K[] # optional - sage.rings.number_field + sage: S. = R.quotient(x^2 + 23) # optional - sage.rings.number_field + sage: S.class_group() # optional - sage.rings.number_field [((2, -a + 1, 1/2*xbar + 1/2, -1/2*a*xbar + 1/2*a + 1), 6)] Here is an example of a product of number fields, both of which contribute to the class group:: - sage: R. = QQ[] - sage: S. = R.quotient((x^2 + 23)*(x^2 + 47)) - sage: S.class_group() - [((1/12*xbar^2 + 47/12, 1/48*xbar^3 - 1/48*xbar^2 + 47/48*xbar - 47/48), 3), ((-1/12*xbar^2 - 23/12, -1/48*xbar^3 - 1/48*xbar^2 - 23/48*xbar - 23/48), 5)] + sage: R. = QQ[] # optional - sage.rings.number_field + sage: S. = R.quotient((x^2 + 23) * (x^2 + 47)) # optional - sage.rings.number_field + sage: S.class_group() # optional - sage.rings.number_field + [((1/12*xbar^2 + 47/12, + 1/48*xbar^3 - 1/48*xbar^2 + 47/48*xbar - 47/48), + 3), + ((-1/12*xbar^2 - 23/12, + -1/48*xbar^3 - 1/48*xbar^2 - 23/48*xbar - 23/48), + 5)] Now we take an example over a nontrivial base with two factors, each contributing to the class group:: - sage: K. = QuadraticField(-5) - sage: R. = K[] - sage: S. = R.quotient((x^2 + 23)*(x^2 + 31)) - sage: S.class_group() # representation varies, not tested + sage: K. = QuadraticField(-5) # optional - sage.rings.number_field + sage: R. = K[] # optional - sage.rings.number_field + sage: S. = R.quotient((x^2 + 23) * (x^2 + 31)) # optional - sage.rings.number_field + sage: S.class_group() # representation varies, not tested # optional - sage.rings.number_field [((1/4*xbar^2 + 31/4, (-1/8*a + 1/8)*xbar^2 - 31/8*a + 31/8, 1/16*xbar^3 + 1/16*xbar^2 + 31/16*xbar + 31/16, @@ -1593,10 +1627,10 @@ def class_group(self, proof=True): Note that all the returned values live where we expect them to:: - sage: CG = S.class_group() - sage: type(CG[0][0][1]) + sage: CG = S.class_group() # optional - sage.rings.number_field + sage: type(CG[0][0][1]) # optional - sage.rings.number_field - sage: type(CG[0][1]) + sage: type(CG[0][1]) # optional - sage.rings.number_field """ @@ -1622,35 +1656,40 @@ def S_units(self, S, proof=True): EXAMPLES:: - sage: K. = QuadraticField(-3) - sage: K.unit_group() - Unit group with structure C6 of Number Field in a with defining polynomial x^2 + 3 with a = 1.732050807568878?*I - sage: K. = QQ['x'].quotient(x^2 + 3) - sage: u,o = K.S_units([])[0]; o + sage: K. = QuadraticField(-3) # optional - sage.rings.number_field + sage: K.unit_group() # optional - sage.rings.number_field + Unit group with structure C6 of Number Field in a + with defining polynomial x^2 + 3 with a = 1.732050807568878?*I + sage: x = polygen(ZZ, 'x') + sage: K. = QQ['x'].quotient(x^2 + 3) # optional - sage.libs.pari + sage: u, o = K.S_units([])[0]; o # optional - sage.libs.pari 6 - sage: 2*u - 1 in {a, -a} + sage: 2*u - 1 in {a, -a} # optional - sage.libs.pari True - sage: u^6 + sage: u^6 # optional - sage.libs.pari 1 - sage: u^3 + sage: u^3 # optional - sage.libs.pari -1 - sage: 2*u^2 + 1 in {a, -a} + sage: 2*u^2 + 1 in {a, -a} # optional - sage.libs.pari True :: - sage: K. = QuadraticField(-3) - sage: y = polygen(K) - sage: L. = K['y'].quotient(y^3 + 5); L - Univariate Quotient Polynomial Ring in b over Number Field in a with defining polynomial x^2 + 3 with a = 1.732050807568878?*I with modulus y^3 + 5 - sage: [u for u, o in L.S_units([]) if o is Infinity] + sage: K. = QuadraticField(-3) # optional - sage.rings.number_field + sage: y = polygen(K) # optional - sage.rings.number_field + sage: L. = K['y'].quotient(y^3 + 5); L # optional - sage.rings.number_field + Univariate Quotient Polynomial Ring in b over Number Field in a + with defining polynomial x^2 + 3 with a = 1.732050807568878?*I + with modulus y^3 + 5 + sage: [u for u, o in L.S_units([]) if o is Infinity] # optional - sage.rings.number_field [(-1/3*a - 1)*b^2 - 4/3*a*b - 5/6*a + 7/2, 2/3*a*b^2 + (2/3*a - 2)*b - 5/6*a - 7/2] - sage: [u for u, o in L.S_units([K.ideal(1/2*a - 3/2)]) if o is Infinity] + sage: [u for u, o in L.S_units([K.ideal(1/2*a - 3/2)]) # optional - sage.rings.number_field + ....: if o is Infinity] [(-1/6*a - 1/2)*b^2 + (1/3*a - 1)*b + 4/3*a, (-1/3*a - 1)*b^2 - 4/3*a*b - 5/6*a + 7/2, 2/3*a*b^2 + (2/3*a - 2)*b - 5/6*a - 7/2] - sage: [u for u, o in L.S_units([K.ideal(2)]) if o is Infinity] + sage: [u for u, o in L.S_units([K.ideal(2)]) if o is Infinity] # optional - sage.rings.number_field [(1/2*a - 1/2)*b^2 + (a + 1)*b + 3, (1/6*a + 1/2)*b^2 + (-1/3*a + 1)*b - 5/6*a + 1/2, (1/6*a + 1/2)*b^2 + (-1/3*a + 1)*b - 5/6*a - 1/2, @@ -1659,12 +1698,12 @@ def S_units(self, S, proof=True): Note that all the returned values live where we expect them to:: - sage: U = L.S_units([]) - sage: type(U[0][0]) + sage: U = L.S_units([]) # optional - sage.rings.number_field + sage: type(U[0][0]) # optional - sage.rings.number_field - sage: type(U[0][1]) + sage: type(U[0][1]) # optional - sage.rings.number_field - sage: type(U[1][1]) + sage: type(U[1][1]) # optional - sage.rings.number_field """ @@ -1708,49 +1747,56 @@ def units(self, proof=True): EXAMPLES:: - sage: K. = QuadraticField(-3) - sage: K.unit_group() - Unit group with structure C6 of Number Field in a with defining polynomial x^2 + 3 with a = 1.732050807568878?*I - sage: K. = QQ['x'].quotient(x^2 + 3) - sage: u = K.units()[0][0] - sage: 2*u - 1 in {a, -a} + sage: K. = QuadraticField(-3) # optional - sage.rings.number_field + sage: K.unit_group() # optional - sage.rings.number_field + Unit group with structure C6 of + Number Field in a with defining polynomial x^2 + 3 with a = 1.732050807568878?*I + sage: x = polygen(ZZ, 'x') + sage: K. = QQ['x'].quotient(x^2 + 3) # optional - sage.libs.pari + sage: u = K.units()[0][0] # optional - sage.libs.pari + sage: 2*u - 1 in {a, -a} # optional - sage.libs.pari True - sage: u^6 + sage: u^6 # optional - sage.libs.pari 1 - sage: u^3 + sage: u^3 # optional - sage.libs.pari -1 - sage: 2*u^2 + 1 in {a, -a} + sage: 2*u^2 + 1 in {a, -a} # optional - sage.libs.pari True - sage: K. = QQ['x'].quotient(x^2 + 5) - sage: K.units(()) + sage: x = polygen(ZZ, 'x') + sage: K. = QQ['x'].quotient(x^2 + 5) # optional - sage.libs.pari + sage: K.units(()) # optional - sage.libs.pari [(-1, 2)] :: - sage: K. = QuadraticField(-3) - sage: y = polygen(K) - sage: L. = K['y'].quotient(y^3 + 5); L - Univariate Quotient Polynomial Ring in b over Number Field in a with defining polynomial x^2 + 3 with a = 1.732050807568878?*I with modulus y^3 + 5 - sage: [u for u, o in L.units() if o is Infinity] + sage: K. = QuadraticField(-3) # optional - sage.rings.number_field + sage: y = polygen(K) # optional - sage.rings.number_field + sage: L. = K['y'].quotient(y^3 + 5); L # optional - sage.rings.number_field + Univariate Quotient Polynomial Ring in b over Number Field in a + with defining polynomial x^2 + 3 with a = 1.732050807568878?*I + with modulus y^3 + 5 + sage: [u for u, o in L.units() if o is Infinity] # optional - sage.rings.number_field [(-1/3*a - 1)*b^2 - 4/3*a*b - 5/6*a + 7/2, 2/3*a*b^2 + (2/3*a - 2)*b - 5/6*a - 7/2] - sage: L. = K.extension(y^3 + 5) - sage: L.unit_group() - Unit group with structure C6 x Z x Z of Number Field in b with defining polynomial x^3 + 5 over its base field - sage: L.unit_group().gens() # abstract generators + sage: L. = K.extension(y^3 + 5) # optional - sage.rings.number_field + sage: L.unit_group() # optional - sage.rings.number_field + Unit group with structure C6 x Z x Z of + Number Field in b with defining polynomial x^3 + 5 over its base field + sage: L.unit_group().gens() # abstract generators # optional - sage.rings.number_field (u0, u1, u2) - sage: L.unit_group().gens_values()[1:] - [(-1/3*a - 1)*b^2 - 4/3*a*b - 5/6*a + 7/2, 2/3*a*b^2 + (2/3*a - 2)*b - 5/6*a - 7/2] + sage: L.unit_group().gens_values()[1:] # optional - sage.rings.number_field + [(-1/3*a - 1)*b^2 - 4/3*a*b - 5/6*a + 7/2, + 2/3*a*b^2 + (2/3*a - 2)*b - 5/6*a - 7/2] Note that all the returned values live where we expect them to:: - sage: L. = K['y'].quotient(y^3 + 5) - sage: U = L.units() - sage: type(U[0][0]) + sage: L. = K['y'].quotient(y^3 + 5) # optional - sage.libs.pari + sage: U = L.units() # optional - sage.libs.pari + sage: type(U[0][0]) # optional - sage.libs.pari - sage: type(U[0][1]) + sage: type(U[0][1]) # optional - sage.libs.pari - sage: type(U[1][1]) + sage: type(U[1][1]) # optional - sage.libs.pari """ @@ -1779,22 +1825,24 @@ def selmer_generators(self, S, m, proof=True): EXAMPLES:: - sage: K. = QuadraticField(-5) - sage: R. = K[] - sage: D. = R.quotient(x) - sage: D.selmer_generators((), 2) + sage: K. = QuadraticField(-5) # optional - sage.rings.number_field + sage: R. = K[] # optional - sage.rings.number_field + sage: D. = R.quotient(x) # optional - sage.rings.number_field + sage: D.selmer_generators((), 2) # optional - sage.rings.number_field [-1, 2] - sage: D.selmer_generators([K.ideal(2, -a+1)], 2) + sage: D.selmer_generators([K.ideal(2, -a + 1)], 2) # optional - sage.rings.number_field [2, -1] - sage: D.selmer_generators([K.ideal(2, -a+1), K.ideal(3, a+1)], 2) + sage: D.selmer_generators([K.ideal(2, -a + 1), K.ideal(3, a + 1)], 2) # optional - sage.rings.number_field [2, a + 1, -1] - sage: D.selmer_generators((K.ideal(2, -a+1),K.ideal(3, a+1)), 4) + sage: D.selmer_generators((K.ideal(2, -a + 1), K.ideal(3, a + 1)), 4) # optional - sage.rings.number_field [2, a + 1, -1] - sage: D.selmer_generators([K.ideal(2, -a+1)], 3) + sage: D.selmer_generators([K.ideal(2, -a + 1)], 3) # optional - sage.rings.number_field [2] - sage: D.selmer_generators([K.ideal(2, -a+1), K.ideal(3, a+1)], 3) + sage: D.selmer_generators([K.ideal(2, -a + 1), K.ideal(3, a + 1)], 3) # optional - sage.rings.number_field [2, a + 1] - sage: D.selmer_generators([K.ideal(2, -a+1), K.ideal(3, a+1), K.ideal(a)], 3) + sage: D.selmer_generators([K.ideal(2, -a + 1), # optional - sage.rings.number_field + ....: K.ideal(3, a + 1), + ....: K.ideal(a)], 3) [2, a + 1, -a] """ @@ -1829,13 +1877,13 @@ def _factor_multivariate_polynomial(self, f, proof=True): TESTS:: - sage: k. = GF(4) - sage: R. = k[] - sage: l. = k.extension(b^2 + b + a) - sage: K. = FunctionField(l) - sage: R. = K[] - sage: F = t*x - sage: F.factor(proof=False) + sage: k. = GF(4) # optional - sage.rings.finite_rings + sage: R. = k[] # optional - sage.rings.finite_rings + sage: l. = k.extension(b^2 + b + a) # optional - sage.rings.finite_rings + sage: K. = FunctionField(l) # optional - sage.rings.finite_rings + sage: R. = K[] # optional - sage.rings.finite_rings + sage: F = t * x # optional - sage.rings.finite_rings + sage: F.factor(proof=False) # optional - sage.rings.finite_rings (x) * t """ @@ -1856,17 +1904,17 @@ def _factor_univariate_polynomial(self, f): TESTS:: - sage: K = GF(2) - sage: R. = K[] - sage: L. = K.extension(x^2 + x + 1) - sage: R. = L[] - sage: M. = L.extension(y^2 + y + x) - sage: R. = M[] - sage: R(y).factor() # indirect doctest + sage: K = GF(2) # optional - sage.rings.finite_rings + sage: R. = K[] # optional - sage.rings.finite_rings + sage: L. = K.extension(x^2 + x + 1) # optional - sage.rings.finite_rings + sage: R. = L[] # optional - sage.rings.finite_rings + sage: M. = L.extension(y^2 + y + x) # optional - sage.rings.finite_rings + sage: R. = M[] # optional - sage.rings.finite_rings + sage: R(y).factor() # indirect doctest # optional - sage.rings.finite_rings y - sage: (T^2 + T + x).factor() # indirect doctest + sage: (T^2 + T + x).factor() # indirect doctest # optional - sage.rings.finite_rings (T + y) * (T + y + 1) - sage: (y*T^2 + y*T + y*x).factor() # indirect doctest + sage: (y*T^2 + y*T + y*x).factor() # indirect doctest # optional - sage.rings.finite_rings (y) * (T + y) * (T + y + 1) """ @@ -1907,32 +1955,36 @@ def _isomorphic_ring(self): EXAMPLES:: - sage: K. = GF(4) - sage: R. = K[] - sage: L. = K.extension(b^2+b+a); L - Univariate Quotient Polynomial Ring in b over Finite Field in a of size 2^2 with modulus b^2 + b + a - sage: from_M, to_M, M = L._isomorphic_ring(); M + sage: K. = GF(4) # optional - sage.rings.finite_rings + sage: R. = K[] # optional - sage.rings.finite_rings + sage: L. = K.extension(b^2 + b + a); L # optional - sage.rings.finite_rings + Univariate Quotient Polynomial Ring in b + over Finite Field in a of size 2^2 with modulus b^2 + b + a + sage: from_M, to_M, M = L._isomorphic_ring(); M # optional - sage.rings.finite_rings Finite Field in z4 of size 2^4 - sage: R. = L[] - sage: M. = L.extension(c^2+b*c+b); M - Univariate Quotient Polynomial Ring in c over Univariate Quotient Polynomial Ring in b over Finite Field in a of size 2^2 with modulus b^2 + b + a with modulus c^2 + b*c + b - sage: from_N, to_N, N = M._isomorphic_ring(); N + sage: R. = L[] # optional - sage.rings.finite_rings + sage: M. = L.extension(c^2 + b*c + b); M # optional - sage.rings.finite_rings + Univariate Quotient Polynomial Ring in c + over Univariate Quotient Polynomial Ring in b + over Finite Field in a of size 2^2 with modulus b^2 + b + a + with modulus c^2 + b*c + b + sage: from_N, to_N, N = M._isomorphic_ring(); N # optional - sage.rings.finite_rings Finite Field in z8 of size 2^8 sage: R. = QQ[] - sage: K = R.quo(x^2 + 1) - sage: from_L, to_L, L = K._isomorphic_ring() - sage: L + sage: K = R.quo(x^2 + 1) # optional - sage.libs.pari + sage: from_L, to_L, L = K._isomorphic_ring() # optional - sage.libs.pari sage.rings.number_field + sage: L # optional - sage.libs.pari sage.rings.number_field Number Field in xbar with defining polynomial x^2 + 1 TESTS: Verify that this works for trivial extensions:: - sage: K. = GF(4) - sage: R. = K[] - sage: from_L, to_L, L = R.quo(b)._isomorphic_ring(); L + sage: K. = GF(4) # optional - sage.rings.finite_rings + sage: R. = K[] # optional - sage.rings.finite_rings + sage: from_L, to_L, L = R.quo(b)._isomorphic_ring(); L # optional - sage.rings.finite_rings Finite Field in a of size 2^2 """ @@ -2049,13 +2101,13 @@ def _test_isomorphic_ring(self, **options): TESTS:: - sage: K. = GF(4) - sage: R. = K[] - sage: L. = K.extension(b^2+b+a) - sage: L._test_isomorphic_ring() - sage: R. = L[] - sage: M. = L.extension(c^2+b*c+b) - sage: M._test_isomorphic_ring() + sage: K. = GF(4) # optional - sage.rings.finite_rings + sage: R. = K[] # optional - sage.rings.finite_rings + sage: L. = K.extension(b^2 + b + a) # optional - sage.rings.finite_rings + sage: L._test_isomorphic_ring() # optional - sage.rings.finite_rings + sage: R. = L[] # optional - sage.rings.finite_rings + sage: M. = L.extension(c^2 + b*c + b) # optional - sage.rings.finite_rings + sage: M._test_isomorphic_ring() # optional - sage.rings.finite_rings """ tester = self._tester(**options) @@ -2093,25 +2145,27 @@ class PolynomialQuotientRing_coercion(DefaultConvertMap_unique): sage: R. = ZZ[] sage: S. = QQ[] - sage: f = S.quo(x^2 + 1).coerce_map_from(R.quo(x^2 + 1)); f + sage: f = S.quo(x^2 + 1).coerce_map_from(R.quo(x^2 + 1)); f # optional - sage.libs.pari Coercion map: - From: Univariate Quotient Polynomial Ring in xbar over Integer Ring with modulus x^2 + 1 - To: Univariate Quotient Polynomial Ring in xbar over Rational Field with modulus x^2 + 1 + From: Univariate Quotient Polynomial Ring in xbar over Integer Ring + with modulus x^2 + 1 + To: Univariate Quotient Polynomial Ring in xbar over Rational Field + with modulus x^2 + 1 TESTS:: sage: from sage.rings.polynomial.polynomial_quotient_ring import PolynomialQuotientRing_coercion - sage: isinstance(f, PolynomialQuotientRing_coercion) + sage: isinstance(f, PolynomialQuotientRing_coercion) # optional - sage.libs.pari True - sage: TestSuite(f).run(skip=['_test_pickling']) + sage: TestSuite(f).run(skip=['_test_pickling']) # optional - sage.libs.pari Pickling works:: - sage: g = loads(dumps(f)); g + sage: g = loads(dumps(f)); g # optional - sage.libs.pari Coercion map: From: Univariate Quotient Polynomial Ring in xbar over Integer Ring with modulus x^2 + 1 To: Univariate Quotient Polynomial Ring in xbar over Rational Field with modulus x^2 + 1 - sage: f == g + sage: f == g # optional - sage.libs.pari True """ @@ -2127,8 +2181,8 @@ def is_injective(self): sage: R. = ZZ[] sage: S. = QQ[] - sage: f = S.quo(x^2 + 1).coerce_map_from(R.quo(x^2 + 1)) - sage: f.is_injective() + sage: f = S.quo(x^2 + 1).coerce_map_from(R.quo(x^2 + 1)) # optional - sage.libs.pari + sage: f.is_injective() # optional - sage.libs.pari True """ @@ -2151,18 +2205,18 @@ def is_surjective(self): domain:: sage: R. = ZZ[] - sage: f = R.quo(x).coerce_map_from(R.quo(x^2)) - sage: f.is_surjective() + sage: f = R.quo(x).coerce_map_from(R.quo(x^2)) # optional - sage.libs.pari + sage: f.is_surjective() # optional - sage.libs.pari True If the modulus of the domain and the codomain is the same, then the map is surjective iff the underlying map on the constants is:: - sage: A. = ZqCA(9) - sage: R. = A[] - sage: S. = A.fraction_field()[] - sage: f = S.quo(x^2 + 2).coerce_map_from(R.quo(x^2 + 2)) - sage: f.is_surjective() + sage: A. = ZqCA(9) # optional - sage.rings.padics + sage: R. = A[] # optional - sage.rings.padics + sage: S. = A.fraction_field()[] # optional - sage.rings.padics + sage: f = S.quo(x^2 + 2).coerce_map_from(R.quo(x^2 + 2)) # optional - sage.rings.padics + sage: f.is_surjective() # optional - sage.rings.padics False """ @@ -2181,11 +2235,11 @@ def _richcmp_(self, other, op): sage: R. = ZZ[] sage: S. = ZZ[] - sage: f = S.quo(x).coerce_map_from(R.quo(x^2)) - sage: g = S.quo(x).coerce_map_from(R.quo(x^3)) - sage: f == g + sage: f = S.quo(x).coerce_map_from(R.quo(x^2)) # optional - sage.libs.pari + sage: g = S.quo(x).coerce_map_from(R.quo(x^3)) # optional - sage.libs.pari + sage: f == g # optional - sage.libs.pari False - sage: f == f + sage: f == f # optional - sage.libs.pari True """ @@ -2193,17 +2247,19 @@ def _richcmp_(self, other, op): return NotImplemented return richcmp(self.parent(), other.parent(), op) + class PolynomialQuotientRing_domain(PolynomialQuotientRing_generic, IntegralDomain): """ EXAMPLES:: sage: R. = PolynomialRing(ZZ) - sage: S. = R.quotient(x^2 + 1) - sage: S - Univariate Quotient Polynomial Ring in xbar over Integer Ring with modulus x^2 + 1 - sage: loads(S.dumps()) == S + sage: S. = R.quotient(x^2 + 1) # optional - sage.libs.pari + sage: S # optional - sage.libs.pari + Univariate Quotient Polynomial Ring in xbar + over Integer Ring with modulus x^2 + 1 + sage: loads(S.dumps()) == S # optional - sage.libs.pari True - sage: loads(xbar.dumps()) == xbar + sage: loads(xbar.dumps()) == xbar # optional - sage.libs.pari True """ def __init__(self, ring, polynomial, name=None, category=None): @@ -2213,21 +2269,21 @@ def __init__(self, ring, polynomial, name=None, category=None): TESTS:: sage: R. = PolynomialRing(ZZ) - sage: S. = R.quotient(x^2 + 1) - sage: TestSuite(S).run() + sage: S. = R.quotient(x^2 + 1) # optional - sage.libs.pari + sage: TestSuite(S).run() # optional - sage.libs.pari Check that :trac:`17450` is fixed:: - sage: S in IntegralDomains() + sage: S in IntegralDomains() # optional - sage.libs.pari True Check that :trac:`29017` is fixed:: sage: R. = ZZ[] - sage: Q = R.quo(x-1) - sage: H = R.Hom(Q) - sage: h = R.hom(Q) - sage: h.parent() is H + sage: Q = R.quo(x - 1) # optional - sage.libs.pari + sage: H = R.Hom(Q) # optional - sage.libs.pari + sage: h = R.hom(Q) # optional - sage.libs.pari + sage: h.parent() is H # optional - sage.libs.pari True """ category = CommutativeAlgebras(ring.base_ring().category()).Quotients().NoZeroDivisors().or_subcategory(category) @@ -2235,38 +2291,38 @@ def __init__(self, ring, polynomial, name=None, category=None): def field_extension(self, names): r""" - Takes a polynomial quotient ring, and returns a tuple with three - elements: the NumberField defined by the same polynomial quotient - ring, a homomorphism from its parent to the NumberField sending the + Take a polynomial quotient ring, and return a tuple with three + elements: the :class:`NumberField` defined by the same polynomial quotient + ring, a homomorphism from its parent to the :class:`NumberField` sending the generators to one another, and the inverse isomorphism. OUTPUT: - field - - homomorphism from self to field + - homomorphism from ``self`` to field - - homomorphism from field to self + - homomorphism from field to ``self`` EXAMPLES:: sage: R. = PolynomialRing(Rationals()) - sage: S. = R.quotient(x^3-2) - sage: F., f, g = S.field_extension() - sage: F + sage: S. = R.quotient(x^3 - 2) # optional - sage.libs.pari + sage: F., f, g = S.field_extension() # optional - sage.libs.pari sage.rings.number_field + sage: F # optional - sage.libs.pari sage.rings.number_field Number Field in b with defining polynomial x^3 - 2 - sage: a = F.gen() - sage: f(alpha) + sage: a = F.gen() # optional - sage.libs.pari sage.rings.number_field + sage: f(alpha) # optional - sage.libs.pari sage.rings.number_field b - sage: g(a) + sage: g(a) # optional - sage.libs.pari sage.rings.number_field alpha Note that the parent ring must be an integral domain:: - sage: R. = GF(25,'f25')['x'] - sage: S. = R.quo(x^3 - 2) - sage: F, g, h = S.field_extension('b') + sage: R. = GF(25, 'f25')['x'] # optional - sage.rings.finite_rings + sage: S. = R.quo(x^3 - 2) # optional - sage.rings.finite_rings + sage: F, g, h = S.field_extension('b') # optional - sage.rings.finite_rings Traceback (most recent call last): ... AttributeError: 'PolynomialQuotientRing_generic_with_category' object has no attribute 'field_extension' @@ -2274,21 +2330,21 @@ def field_extension(self, names): Over a finite field, the corresponding field extension is not a number field:: - sage: R. = GF(25, 'a')['x'] - sage: S. = R.quo(x^3 + 2*x + 1) - sage: F, g, h = S.field_extension('b') - sage: h(F.0^2 + 3) + sage: R. = GF(25, 'a')['x'] # optional - sage.rings.finite_rings + sage: S. = R.quo(x^3 + 2*x + 1) # optional - sage.rings.finite_rings + sage: F, g, h = S.field_extension('b') # optional - sage.rings.finite_rings + sage: h(F.0^2 + 3) # optional - sage.rings.finite_rings a^2 + 3 - sage: g(x^2 + 2) + sage: g(x^2 + 2) # optional - sage.rings.finite_rings b^2 + 2 We do an example involving a relative number field:: sage: R. = QQ['x'] - sage: K. = NumberField(x^3 - 2) - sage: S. = K['X'] - sage: Q. = S.quo(X^3 + 2*X + 1) - sage: Q.field_extension('b') + sage: K. = NumberField(x^3 - 2) # optional - sage.rings.number_field + sage: S. = K['X'] # optional - sage.rings.number_field + sage: Q. = S.quo(X^3 + 2*X + 1) # optional - sage.rings.number_field + sage: Q.field_extension('b') # optional - sage.rings.number_field (Number Field in b with defining polynomial X^3 + 2*X + 1 over its base field, ... Defn: b |--> b, Relative number field morphism: From: Number Field in b with defining polynomial X^3 + 2*X + 1 over its base field @@ -2301,19 +2357,19 @@ def field_extension(self, names): :: sage: R. = QQ['x'] - sage: K. = NumberField(x^3 - 2) - sage: S. = K['X'] - sage: f = (X+a)^3 + 2*(X+a) + 1 - sage: f + sage: K. = NumberField(x^3 - 2) # optional - sage.rings.number_field + sage: S. = K['X'] # optional - sage.rings.number_field + sage: f = (X+a)^3 + 2*(X+a) + 1 # optional - sage.rings.number_field + sage: f # optional - sage.rings.number_field X^3 + 3*a*X^2 + (3*a^2 + 2)*X + 2*a + 3 - sage: Q. = S.quo(f) - sage: F., g, h = Q.field_extension() - sage: c = g(z) - sage: f(c) + sage: Q. = S.quo(f) # optional - sage.rings.number_field + sage: F., g, h = Q.field_extension() # optional - sage.rings.number_field + sage: c = g(z) # optional - sage.rings.number_field + sage: f(c) # optional - sage.rings.number_field 0 - sage: h(g(z)) + sage: h(g(z)) # optional - sage.rings.number_field z - sage: g(h(w)) + sage: g(h(w)) # optional - sage.rings.number_field w AUTHORS: @@ -2331,12 +2387,13 @@ class PolynomialQuotientRing_field(PolynomialQuotientRing_domain, Field): EXAMPLES:: sage: R. = PolynomialRing(QQ) - sage: S. = R.quotient(x^2 + 1) - sage: S - Univariate Quotient Polynomial Ring in xbar over Rational Field with modulus x^2 + 1 - sage: loads(S.dumps()) == S + sage: S. = R.quotient(x^2 + 1) # optional - sage.rings.number_field + sage: S # optional - sage.rings.number_field + Univariate Quotient Polynomial Ring in xbar over Rational Field + with modulus x^2 + 1 + sage: loads(S.dumps()) == S # optional - sage.rings.number_field True - sage: loads(xbar.dumps()) == xbar + sage: loads(xbar.dumps()) == xbar # optional - sage.rings.number_field True """ def __init__(self, ring, polynomial, name=None, category=None): @@ -2344,23 +2401,27 @@ def __init__(self, ring, polynomial, name=None, category=None): def base_field(self): r""" - Alias for base_ring, when we're defined over a field. + Alias for :meth:`base_ring`, when we're defined over a field. """ return self.base_ring() def complex_embeddings(self, prec=53): r""" Return all homomorphisms of this ring into the approximate complex - field with precision prec. + field with precision ``prec``. EXAMPLES:: sage: R. = QQ[] sage: f = x^5 + x + 17 - sage: k = R.quotient(f) - sage: v = k.complex_embeddings(100) - sage: [phi(k.0^2) for phi in v] - [2.9757207403766761469671194565, -2.4088994371613850098316292196 + 1.9025410530350528612407363802*I, -2.4088994371613850098316292196 - 1.9025410530350528612407363802*I, 0.92103906697304693634806949137 - 3.0755331188457794473265418086*I, 0.92103906697304693634806949137 + 3.0755331188457794473265418086*I] + sage: k = R.quotient(f) # optional - sage.rings.number_field + sage: v = k.complex_embeddings(100) # optional - sage.rings.number_field + sage: [phi(k.0^2) for phi in v] # optional - sage.rings.number_field + [2.9757207403766761469671194565, + -2.4088994371613850098316292196 + 1.9025410530350528612407363802*I, + -2.4088994371613850098316292196 - 1.9025410530350528612407363802*I, + 0.92103906697304693634806949137 - 3.0755331188457794473265418086*I, + 0.92103906697304693634806949137 + 3.0755331188457794473265418086*I] """ CC = sage.rings.complex_mpfr.ComplexField(prec) v = self.modulus().roots(multiplicities=False, ring=CC) diff --git a/src/sage/rings/polynomial/polynomial_quotient_ring_element.py b/src/sage/rings/polynomial/polynomial_quotient_ring_element.py index be05a312725..7dd4e836be1 100644 --- a/src/sage/rings/polynomial/polynomial_quotient_ring_element.py +++ b/src/sage/rings/polynomial/polynomial_quotient_ring_element.py @@ -1,3 +1,4 @@ +# sage.doctest: optional - sage.libs.pari r""" Elements of Quotients of Univariate Polynomial Rings @@ -7,8 +8,8 @@ :: sage: R. = ZZ[] - sage: S. = R.quotient(x^3 + 3*x -1) - sage: 2 * a^3 + sage: S. = R.quotient(x^3 + 3*x - 1) # optional - sage.libs.pari + sage: 2 * a^3 # optional - sage.libs.pari -6*a + 2 Next we make a univariate polynomial ring over @@ -16,24 +17,24 @@ :: - sage: S1. = S[] + sage: S1. = S[] # optional - sage.libs.pari And, we quotient out that by `y^2 + a`. :: - sage: T. = S1.quotient(y^2+a) + sage: T. = S1.quotient(y^2 + a) # optional - sage.libs.pari In the quotient `z^2` is `-a`. :: - sage: z^2 + sage: z^2 # optional - sage.libs.pari -a And since `a^3 = -3x + 1`, we have:: - sage: z^6 + sage: z^6 # optional - sage.libs.pari 3*a - 1 :: @@ -46,7 +47,7 @@ :: sage: R. = PolynomialRing(QQ) - sage: S. = R.quotient(x^3-2) + sage: S. = R.quotient(x^3 - 2) sage: a a sage: a^3 @@ -96,7 +97,7 @@ class PolynomialQuotientRingElement(polynomial_singular_interface.Polynomial_sin EXAMPLES:: sage: P. = QQ[] - sage: Q. = P.quo([(x^2+1)]) + sage: Q. = P.quo([(x^2 + 1)]) sage: xi^2 -1 sage: singular(xi) @@ -161,15 +162,15 @@ def _im_gens_(self, codomain, im_gens, base_map=None): EXAMPLES:: sage: Zx. = ZZ[] - sage: K. = NumberField(x^2 + 1) - sage: cc = K.hom([-i]) - sage: S. = K[] - sage: Q. = S.quotient(y^2*(y-1)*(y-i)) - sage: T. = S.quotient(y*(y+1)) - sage: phi = Q.hom([t+1], base_map=cc) - sage: phi(q) + sage: K. = NumberField(x^2 + 1) # optional - sage.rings.number_field + sage: cc = K.hom([-i]) # optional - sage.rings.number_field + sage: S. = K[] # optional - sage.rings.number_field + sage: Q. = S.quotient(y^2*(y-1)*(y-i)) # optional - sage.rings.number_field + sage: T. = S.quotient(y*(y+1)) # optional - sage.rings.number_field + sage: phi = Q.hom([t+1], base_map=cc) # optional - sage.rings.number_field + sage: phi(q) # optional - sage.rings.number_field t + 1 - sage: phi(i*q) + sage: phi(i*q) # optional - sage.rings.number_field -i*t - i """ return self._polynomial._im_gens_(codomain, im_gens, base_map=base_map) @@ -270,7 +271,7 @@ def _add_(self, right): EXAMPLES:: sage: R. = PolynomialRing(QQ) - sage: S. = R.quotient(x^3-2) + sage: S. = R.quotient(x^3 - 2) sage: (a^2 - 4) + (a+2) a^2 + a - 2 sage: int(1) + a @@ -286,7 +287,7 @@ def _div_(self, right): EXAMPLES:: sage: R. = PolynomialRing(QQ) - sage: S. = R.quotient(x^3-2) + sage: S. = R.quotient(x^3 - 2) sage: (a^2 - 4) / (a+2) a - 2 """ @@ -303,7 +304,7 @@ def _richcmp_(self, other, op): EXAMPLES:: sage: R. = PolynomialRing(QQ) - sage: S. = R.quotient(x^3-2) + sage: S. = R.quotient(x^3 - 2) sage: (a^2 - 4) / (a+2) == a - 2 True sage: a^2 - 4 == a @@ -321,7 +322,7 @@ def __int__(self): EXAMPLES:: sage: R. = PolynomialRing(QQ) - sage: S. = R.quotient(x^3-2) + sage: S. = R.quotient(x^3 - 2) sage: int(S(10)) 10 sage: int(a) @@ -345,7 +346,7 @@ def is_unit(self): sage: S. = R.quotient(x^2 + 2*x + 1) sage: (2*y).is_unit() True - sage: (y+1).is_unit() + sage: (y + 1).is_unit() False TESTS: @@ -460,59 +461,59 @@ def field_extension(self, names): - field - - homomorphism from self to field + - homomorphism from ``self`` to field - - homomorphism from field to self + - homomorphism from field to ``self`` EXAMPLES:: sage: R. = PolynomialRing(QQ) - sage: S. = R.quotient(x^3-2) - sage: F., f, g = alpha.field_extension() - sage: F + sage: S. = R.quotient(x^3 - 2) + sage: F., f, g = alpha.field_extension() # optional - sage.rings.number_field + sage: F # optional - sage.rings.number_field Number Field in a with defining polynomial x^3 - 2 - sage: a = F.gen() - sage: f(alpha) + sage: a = F.gen() # optional - sage.rings.number_field + sage: f(alpha) # optional - sage.rings.number_field a - sage: g(a) + sage: g(a) # optional - sage.rings.number_field alpha Over a finite field, the corresponding field extension is not a number field:: - sage: R. = GF(25,'b')['x'] - sage: S. = R.quo(x^3 + 2*x + 1) - sage: F., g, h = a.field_extension() - sage: h(b^2 + 3) + sage: R. = GF(25,'b')['x'] # optional - sage.rings.finite_rings + sage: S. = R.quo(x^3 + 2*x + 1) # optional - sage.rings.finite_rings + sage: F., g, h = a.field_extension() # optional - sage.rings.finite_rings + sage: h(b^2 + 3) # optional - sage.rings.finite_rings a^2 + 3 - sage: g(x^2 + 2) + sage: g(x^2 + 2) # optional - sage.rings.finite_rings b^2 + 2 We do an example involving a relative number field:: sage: R. = QQ['x'] - sage: K. = NumberField(x^3-2) - sage: S. = K['X'] - sage: Q. = S.quo(X^3 + 2*X + 1) - sage: F, g, h = b.field_extension('c') + sage: K. = NumberField(x^3 - 2) # optional - sage.rings.number_field + sage: S. = K['X'] # optional - sage.rings.number_field + sage: Q. = S.quo(X^3 + 2*X + 1) # optional - sage.rings.number_field + sage: F, g, h = b.field_extension('c') # optional - sage.rings.number_field Another more awkward example:: sage: R. = QQ['x'] - sage: K. = NumberField(x^3-2) - sage: S. = K['X'] - sage: f = (X+a)^3 + 2*(X+a) + 1 - sage: f + sage: K. = NumberField(x^3 - 2) # optional - sage.rings.number_field + sage: S. = K['X'] # optional - sage.rings.number_field + sage: f = (X+a)^3 + 2*(X+a) + 1 # optional - sage.rings.number_field + sage: f # optional - sage.rings.number_field X^3 + 3*a*X^2 + (3*a^2 + 2)*X + 2*a + 3 - sage: Q. = S.quo(f) - sage: F., g, h = z.field_extension() - sage: c = g(z) - sage: f(c) + sage: Q. = S.quo(f) # optional - sage.rings.number_field + sage: F., g, h = z.field_extension() # optional - sage.rings.number_field + sage: c = g(z) # optional - sage.rings.number_field + sage: f(c) # optional - sage.rings.number_field 0 - sage: h(g(z)) + sage: h(g(z)) # optional - sage.rings.number_field z - sage: g(h(w)) + sage: g(h(w)) # optional - sage.rings.number_field w AUTHORS: @@ -693,21 +694,21 @@ def minpoly(self): sage: R. = PolynomialRing(QQ) sage: S. = R.quotient(x^3 + 2*x - 5) - sage: (a+123).minpoly() + sage: (a + 123).minpoly() x^3 - 369*x^2 + 45389*x - 1861118 - sage: (a+123).matrix().minpoly() + sage: (a + 123).matrix().minpoly() x^3 - 369*x^2 + 45389*x - 1861118 One useful application of this function is to compute a minimal polynomial of a finite-field element over an intermediate extension, rather than the absolute minimal polynomial over the prime field:: - sage: F2. = GF((431,2), modulus=[1,0,1]) - sage: F6. = F2.extension(3) - sage: (u+1).minpoly() + sage: F2. = GF((431,2), modulus=[1,0,1]) # optional - sage.rings.finite_rings + sage: F6. = F2.extension(3) # optional - sage.rings.finite_rings + sage: (u + 1).minpoly() # optional - sage.rings.finite_rings x^6 + 425*x^5 + 19*x^4 + 125*x^3 + 189*x^2 + 239*x + 302 - sage: ext = F6.over(F2) - sage: ext(u+1).minpoly() # indirect doctest + sage: ext = F6.over(F2) # optional - sage.rings.finite_rings + sage: ext(u + 1).minpoly() # indirect doctest # optional - sage.rings.finite_rings x^3 + (396*i + 428)*x^2 + (80*i + 39)*x + 9*i + 178 TESTS: @@ -715,15 +716,15 @@ def minpoly(self): We make sure that the previous example works on random examples:: sage: p = random_prime(50) - sage: K. = GF((p, randrange(1,20))) - sage: L. = K.extension(randrange(2,20)) - sage: LK = L.over(K) - sage: a = L.random_element() - sage: poly = LK(a).minpoly() # indirect doctest - sage: poly(a) + sage: K. = GF((p, randrange(1,20))) # optional - sage.rings.finite_rings + sage: L. = K.extension(randrange(2,20)) # optional - sage.rings.finite_rings + sage: LK = L.over(K) # optional - sage.rings.finite_rings + sage: a = L.random_element() # optional - sage.rings.finite_rings + sage: poly = LK(a).minpoly() # indirect doctest # optional - sage.rings.finite_rings + sage: poly(a) # optional - sage.rings.finite_rings 0 - sage: abs_deg = a.minpoly().degree() - sage: poly.degree() == abs_deg // gcd(abs_deg, K.degree()) + sage: abs_deg = a.minpoly().degree() # optional - sage.rings.finite_rings + sage: poly.degree() == abs_deg // gcd(abs_deg, K.degree()) # optional - sage.rings.finite_rings True """ poly = self.lift() @@ -741,7 +742,7 @@ def norm(self): EXAMPLES:: sage: R. = PolynomialRing(QQ) - sage: S. = R.quotient(x^3 -389*x^2 + 2*x - 5) + sage: S. = R.quotient(x^3 - 389*x^2 + 2*x - 5) sage: a.norm() 5 """ @@ -771,11 +772,14 @@ def rational_reconstruction(self, *args, **kwargs): EXAMPLES:: - sage: R. = GF(65537)[] - sage: m = x^11 + 25345*x^10 + 10956*x^9 + 13873*x^8 + 23962*x^7 + 17496*x^6 + 30348*x^5 + 7440*x^4 + 65438*x^3 + 7676*x^2 + 54266*x + 47805 - sage: f = 20437*x^10 + 62630*x^9 + 63241*x^8 + 12820*x^7 + 42171*x^6 + 63091*x^5 + 15288*x^4 + 32516*x^3 + 2181*x^2 + 45236*x + 2447 - sage: f_mod_m = R.quotient(m)(f) - sage: f_mod_m.rational_reconstruction() + sage: R. = GF(65537)[] # optional - sage.rings.finite_rings + sage: m = (x^11 + 25345*x^10 + 10956*x^9 + 13873*x^8 + 23962*x^7 # optional - sage.rings.finite_rings + ....: + 17496*x^6 + 30348*x^5 + 7440*x^4 + 65438*x^3 + 7676*x^2 + ....: + 54266*x + 47805) + sage: f = (20437*x^10 + 62630*x^9 + 63241*x^8 + 12820*x^7 + 42171*x^6 # optional - sage.rings.finite_rings + ....: + 63091*x^5 + 15288*x^4 + 32516*x^3 + 2181*x^2 + 45236*x + 2447) + sage: f_mod_m = R.quotient(m)(f) # optional - sage.rings.finite_rings + sage: f_mod_m.rational_reconstruction() # optional - sage.rings.finite_rings (51388*x^5 + 29141*x^4 + 59341*x^3 + 7034*x^2 + 14152*x + 23746, x^5 + 15208*x^4 + 19504*x^3 + 20457*x^2 + 11180*x + 28352) """ diff --git a/src/sage/rings/polynomial/polynomial_rational_flint.pyx b/src/sage/rings/polynomial/polynomial_rational_flint.pyx index d85ad4af690..50837b850d0 100644 --- a/src/sage/rings/polynomial/polynomial_rational_flint.pyx +++ b/src/sage/rings/polynomial/polynomial_rational_flint.pyx @@ -193,11 +193,11 @@ cdef class Polynomial_rational_flint(Polynomial): def __init__(self, parent, x=None, check=True, is_gen=False, construct=False): """ - Initialises the associated data for the polynomial self. + Initialises the associated data for the polynomial ``self``. INPUT: - - ``parent`` - Polynomial ring, the parent of self + - ``parent`` - Polynomial ring, the parent of ``self`` - ``x`` - Data for the new polynomial self, e.g. a polynomial, an integer, a rational, a list of rationals, a dictionary with keys the degrees and the rational coefficients, etc (default: ``None``) @@ -319,7 +319,7 @@ cdef class Polynomial_rational_flint(Polynomial): def __copy__(self): """ - Return a copy of self. + Return a copy of ``self``. TESTS:: @@ -334,7 +334,7 @@ cdef class Polynomial_rational_flint(Polynomial): def _singular_(self, singular=singular_default): """ - Return a Singular representation of self. + Return a Singular representation of ``self``. INPUT: @@ -375,7 +375,7 @@ cdef class Polynomial_rational_flint(Polynomial): """ Return the degree of ``self``. - By convention, the degree of the zero polynomial is -1. + By convention, the degree of the zero polynomial is `-1`. EXAMPLES:: @@ -418,7 +418,7 @@ cdef class Polynomial_rational_flint(Polynomial): cpdef _unsafe_mutate(self, unsigned long n, value): """ - Sets the `n`-th coefficient of self to value. + Sets the `n`-th coefficient of ``self`` to value. TESTS:: @@ -557,7 +557,7 @@ cdef class Polynomial_rational_flint(Polynomial): INPUT: - - ``n`` - The power of `t` modulo which self is truncated + - ``n`` - The power of `t` modulo which ``self`` is truncated EXAMPLES:: @@ -603,7 +603,7 @@ cdef class Polynomial_rational_flint(Polynomial): sage: f.reverse() t^4 + t^3 + 1/2*t^2 + 1/3*t + 1/4 - Next, an example we the returned polynomial has lower degree because + Next, an example where the returned polynomial has lower degree because the original polynomial has low coefficients equal to zero:: sage: R. = QQ[] @@ -612,7 +612,7 @@ cdef class Polynomial_rational_flint(Polynomial): 3/4*t^5 + 6 The next example illustrates the passing of a value for ``degree`` less - than the length of self, notationally resulting in truncation prior to + than the length of ``self``, notationally resulting in truncation prior to reversing:: sage: R. = QQ[] @@ -621,7 +621,7 @@ cdef class Polynomial_rational_flint(Polynomial): t^2 + t + 1/2 Now we illustrate the passing of a value for ``degree`` greater than - the length of self, notationally resulting in zero padding at the top + the length of ``self``, notationally resulting in zero padding at the top end prior to reversing:: sage: R. = QQ[] @@ -681,7 +681,7 @@ cdef class Polynomial_rational_flint(Polynomial): def revert_series(self, n): r""" - Return a polynomial `f` such that `f(self(x)) = self(f(x)) = x mod x^n`. + Return a polynomial `f` such that ``f(self(x)) = self(f(x)) = x mod x^n``. EXAMPLES:: @@ -721,7 +721,7 @@ cdef class Polynomial_rational_flint(Polynomial): cpdef bint is_zero(self) except -1: """ - Return whether or not self is the zero polynomial. + Return whether or not ``self`` is the zero polynomial. EXAMPLES:: @@ -756,7 +756,7 @@ cdef class Polynomial_rational_flint(Polynomial): def __bool__(self): """ - Return whether or not self is non-zero. + Return whether or not ``self`` is non-zero. EXAMPLES:: @@ -808,7 +808,7 @@ cdef class Polynomial_rational_flint(Polynomial): def __rshift__(self, n): """ - Notationally returns the quotient of Euclidean division of self + Notationally returns the quotient of Euclidean division of ``self`` by `t^n`. EXAMPLES:: @@ -922,11 +922,11 @@ cdef class Polynomial_rational_flint(Polynomial): @coerce_binop def quo_rem(self, right): - """ + r""" Return the quotient and remainder of the Euclidean division of - self and right. + ``self`` and ``right``. - Raises a ZerodivisionError if right is zero. + Raises a :class:`ZeroDivisionError` if ``right`` is zero. EXAMPLES:: @@ -953,10 +953,10 @@ cdef class Polynomial_rational_flint(Polynomial): @coerce_binop def gcd(self, right): - """ - Return the (monic) greatest common divisor of self and right. + r""" + Return the (monic) greatest common divisor of ``self`` and ``right``. - Corner cases: if self and right are both zero, returns zero. If + Corner cases: if ``self`` and ``right`` are both zero, returns zero. If only one of them is zero, returns the other polynomial, up to normalisation. @@ -982,11 +982,11 @@ cdef class Polynomial_rational_flint(Polynomial): @coerce_binop def lcm(self, right): - """ - Return the monic (or zero) least common multiple of self and right. + r""" + Return the monic (or zero) least common multiple of ``self`` and ``right``. - Corner cases: if either of self and right are zero, returns zero. - This behaviour is ensures that the relation lcm(a,b) gcd(a,b) == a b + Corner cases: if either of ``self`` and ``right`` are zero, returns zero. + This behaviour is ensures that the relation `\lcm(a,b)\cdot \gcd(a,b) = a\cdot b` holds up to multiplication by rationals. EXAMPLES:: @@ -1009,14 +1009,14 @@ cdef class Polynomial_rational_flint(Polynomial): @coerce_binop def xgcd(self, right): - """ - Return polynomials d, s, and t such that d == s * self + t * right, - where d is the (monic) greatest common divisor of self and right. - The choice of s and t is not specified any further. + r""" + Return polynomials `d`, `s`, and `t` such that ``d == s * self + t * right``, + where `d` is the (monic) greatest common divisor of ``self`` and ``right``. + The choice of `s` and `t` is not specified any further. - Corner cases: if self and right are zero, returns zero polynomials. - Otherwise, if only self is zero, returns (d, s, t) = (right, 0, 1) up - to normalisation, and similarly if only right is zero. + Corner cases: if ``self`` and ``right`` are zero, returns zero polynomials. + Otherwise, if only ``self`` is zero, returns ``(d, s, t) = (right, 0, 1)`` up + to normalisation, and similarly if only ``right`` is zero. EXAMPLES:: @@ -1050,7 +1050,7 @@ cdef class Polynomial_rational_flint(Polynomial): cpdef _mul_(self, right): """ - Return the product of self and right. + Return the product of ``self`` and ``right``. EXAMPLES:: @@ -1116,7 +1116,7 @@ cdef class Polynomial_rational_flint(Polynomial): cpdef _rmul_(self, Element left): r""" - Return left * self, where left is a rational number. + Return ``left * self``, where ``left`` is a rational number. EXAMPLES:: @@ -1136,7 +1136,7 @@ cdef class Polynomial_rational_flint(Polynomial): cpdef _lmul_(self, Element right): r""" - Return self * right, where right is a rational number. + Return ``self * right``, where ``right`` is a rational number. EXAMPLES:: @@ -1299,7 +1299,7 @@ cdef class Polynomial_rational_flint(Polynomial): def __floordiv__(Polynomial_rational_flint self, right): """ - Return the quotient of self and right obtain by Euclidean division. + Return the quotient of ``self`` and ``right`` obtained by Euclidean division. EXAMPLES:: @@ -1396,7 +1396,7 @@ cdef class Polynomial_rational_flint(Polynomial): cpdef _mod_(self, right): """ - Return the remainder of self and right obtain by Euclidean division. + Return the remainder of ``self`` and ``right`` obtain by Euclidean division. EXAMPLES:: @@ -1435,7 +1435,7 @@ cdef class Polynomial_rational_flint(Polynomial): def numerator(self): """ - Return the numerator of self. + Return the numerator of ``self``. Representing self as the quotient of an integer polynomial and a positive integer denominator (coprime to the content of the @@ -1460,7 +1460,7 @@ cdef class Polynomial_rational_flint(Polynomial): def denominator(self): """ - Return the denominator of self. + Return the denominator of ``self``. EXAMPLES:: @@ -1527,7 +1527,7 @@ cdef class Polynomial_rational_flint(Polynomial): def real_root_intervals(self): """ - Return isolating intervals for the real roots of self. + Return isolating intervals for the real roots of ``self``. EXAMPLES: @@ -1545,10 +1545,10 @@ cdef class Polynomial_rational_flint(Polynomial): @coerce_binop def resultant(Polynomial_rational_flint self, right): r""" - Return the resultant of self and right. + Return the resultant of ``self`` and ``right``. - Enumerating the roots over `\QQ` as `r_1, \cdots, r_m` and - `s_1, \cdots, s_n` and letting `x` and `y` denote the leading + Enumerating the roots over `\QQ` as `r_1, \dots, r_m` and + `s_1, \dots, s_n` and letting `x` and `y` denote the leading coefficients of `f` and `g`, the resultant of the two polynomials is defined by @@ -1610,7 +1610,7 @@ cdef class Polynomial_rational_flint(Polynomial): False sage: R(-1/2).is_irreducible() False - sage: (t+1).is_irreducible() + sage: (t + 1).is_irreducible() True Test that caching works:: @@ -2067,7 +2067,7 @@ cdef class Polynomial_rational_flint(Polynomial): - ``pari_group`` - bool (default: ``False``); if ``True`` instead return the Galois group as a PARI group. This has a useful label in it, and may be slightly faster since it doesn't require looking - up a group in Gap. To get a permutation group from a PARI + up a group in GAP. To get a permutation group from a PARI group ``P``, type ``PermutationGroup(P)``. - ``algorithm`` - ``'pari'``, ``'gap'``, ``'kash'``, ``'magma'`` (default: @@ -2075,9 +2075,7 @@ cdef class Polynomial_rational_flint(Polynomial): ``'gap'``, for degrees from 12 to 15; ``'kash'``, for degrees from 16 or more). - OUTPUT: - - - Galois group + OUTPUT: Galois group ALGORITHM: @@ -2234,23 +2232,21 @@ cdef class Polynomial_rational_flint(Polynomial): def factor_mod(self, p): """ - Return the factorization of self modulo the prime ``p``. + Return the factorization of ``self`` modulo the prime `p`. Assumes that the degree of this polynomial is at least one, and raises - a ``ValueError`` otherwise. + a :class:`ValueError` otherwise. INPUT: - ``p`` - Prime number - OUTPUT: - - - Factorization of this polynomial modulo ``p`` + OUTPUT: Factorization of this polynomial modulo `p` EXAMPLES:: sage: R. = QQ[] - sage: (x^5 + 17*x^3 + x+ 3).factor_mod(3) + sage: (x^5 + 17*x^3 + x + 3).factor_mod(3) x * (x^2 + 1)^2 sage: (x^5 + 2).factor_mod(5) (x + 2)^5 @@ -2278,7 +2274,7 @@ cdef class Polynomial_rational_flint(Polynomial): return R(1)._factor_pari_helper(G, unit=R(self).leading_coefficient()) def factor_padic(self, p, prec=10): - """ + r""" Return the `p`-adic factorization of this polynomial to the given precision. @@ -2288,47 +2284,53 @@ cdef class Polynomial_rational_flint(Polynomial): - ``prec`` - Integer; the precision - OUTPUT: - - - factorization of ``self`` viewed as a `p`-adic polynomial + OUTPUT: factorization of ``self`` viewed as a `p`-adic polynomial EXAMPLES:: sage: R. = QQ[] sage: f = x^3 - 2 sage: f.factor_padic(2) - (1 + O(2^10))*x^3 + O(2^10)*x^2 + O(2^10)*x + 2 + 2^2 + 2^3 + 2^4 + 2^5 + 2^6 + 2^7 + 2^8 + 2^9 + O(2^10) + (1 + O(2^10))*x^3 + O(2^10)*x^2 + O(2^10)*x + + 2 + 2^2 + 2^3 + 2^4 + 2^5 + 2^6 + 2^7 + 2^8 + 2^9 + O(2^10) sage: f.factor_padic(3) - (1 + O(3^10))*x^3 + O(3^10)*x^2 + O(3^10)*x + 1 + 2*3 + 2*3^2 + 2*3^3 + 2*3^4 + 2*3^5 + 2*3^6 + 2*3^7 + 2*3^8 + 2*3^9 + O(3^10) + (1 + O(3^10))*x^3 + O(3^10)*x^2 + O(3^10)*x + + 1 + 2*3 + 2*3^2 + 2*3^3 + 2*3^4 + 2*3^5 + 2*3^6 + 2*3^7 + 2*3^8 + 2*3^9 + O(3^10) sage: f.factor_padic(5) - ((1 + O(5^10))*x + 2 + 4*5 + 2*5^2 + 2*5^3 + 5^4 + 3*5^5 + 4*5^7 + 2*5^8 + 5^9 + O(5^10)) * ((1 + O(5^10))*x^2 + (3 + 2*5^2 + 2*5^3 + 3*5^4 + 5^5 + 4*5^6 + 2*5^8 + 3*5^9 + O(5^10))*x + 4 + 5 + 2*5^2 + 4*5^3 + 4*5^4 + 3*5^5 + 3*5^6 + 4*5^7 + 4*5^9 + O(5^10)) + ((1 + O(5^10))*x + + 2 + 4*5 + 2*5^2 + 2*5^3 + 5^4 + 3*5^5 + 4*5^7 + 2*5^8 + 5^9 + O(5^10)) + * ((1 + O(5^10))*x^2 + + (3 + 2*5^2 + 2*5^3 + 3*5^4 + 5^5 + 4*5^6 + 2*5^8 + 3*5^9 + O(5^10))*x + + 4 + 5 + 2*5^2 + 4*5^3 + 4*5^4 + 3*5^5 + 3*5^6 + 4*5^7 + 4*5^9 + O(5^10)) The input polynomial is considered to have "infinite" precision, therefore the `p`-adic factorization of the polynomial is not - the same as first coercing to `Q_p` and then factoring + the same as first coercing to `\QQ_p` and then factoring (see also :trac:`15422`):: sage: f = x^2 - 3^6 - sage: f.factor_padic(3,5) + sage: f.factor_padic(3, 5) ((1 + O(3^5))*x + 3^3 + O(3^5)) * ((1 + O(3^5))*x + 2*3^3 + 2*3^4 + O(3^5)) sage: f.change_ring(Qp(3,5)).factor() Traceback (most recent call last): ... - PrecisionError: p-adic factorization not well-defined since the discriminant is zero up to the requestion p-adic precision + PrecisionError: p-adic factorization not well-defined since + the discriminant is zero up to the requestion p-adic precision A more difficult example:: sage: f = 100 * (5*x + 1)^2 * (x + 5)^2 sage: f.factor_padic(5, 10) - (4*5^4 + O(5^14)) * ((1 + O(5^9))*x + 5^-1 + O(5^9))^2 * ((1 + O(5^10))*x + 5 + O(5^10))^2 + (4*5^4 + O(5^14)) * ((1 + O(5^9))*x + 5^-1 + O(5^9))^2 + * ((1 + O(5^10))*x + 5 + O(5^10))^2 Try some bogus inputs:: - sage: f.factor_padic(3,-1) + sage: f.factor_padic(3, -1) Traceback (most recent call last): ... ValueError: prec_cap must be non-negative - sage: f.factor_padic(6,10) + sage: f.factor_padic(6, 10) Traceback (most recent call last): ... ValueError: p must be prime @@ -2362,12 +2364,10 @@ cdef class Polynomial_rational_flint(Polynomial): INPUT: - - ``p`` - Prime number; coerceable to ``Integer`` - - ``e`` - Exponent; coerceable to ``Integer`` - - OUTPUT: + - ``p`` - Prime number; coerceable to :class:`Integer` + - ``e`` - Exponent; coerceable to :class:`Integer` - - Hensel lifts; list of polynomials over `\ZZ / p^e \ZZ` + OUTPUT: Hensel lifts; list of polynomials over `\ZZ / p^e \ZZ` EXAMPLES:: @@ -2388,7 +2388,7 @@ cdef class Polynomial_rational_flint(Polynomial): [] sage: R(x).hensel_lift(7, 2) [x] - sage: R(x-1).hensel_lift(7, 2) + sage: R(x - 1).hensel_lift(7, 2) [x + 48] Variable names that are reserved in PARI, such as ``I``, are @@ -2446,16 +2446,14 @@ cdef class Polynomial_rational_flint(Polynomial): The discriminant of constant polynomials is defined to be 0. - OUTPUT: - - - Discriminant, an element of the base ring of the polynomial ring + OUTPUT: Discriminant, an element of the base ring of the polynomial ring .. NOTE:: - Note the identity `R_n(f) := (-1)^(n (n-1)/2) R(f,f') a_n^(n-k-2)`, + Note the identity `R_n(f) := (-1)^{(n (n-1)/2)} R(f,f') a_n^{(n-k-2)}`, where `n` is the degree of this polynomial, `a_n` is the leading coefficient, `f'` is the derivative of `f`, and `k` is the degree - of `f'`. Calls :meth:`.resultant`. + of `f'`. Calls :meth:`resultant`. ALGORITHM: @@ -2514,14 +2512,14 @@ cdef class Polynomial_rational_flint(Polynomial): def galois_group_davenport_smith_test(self, num_trials=50, assume_irreducible=False): """ - Use the Davenport-Smith test to attempt to certify that `f` has Galois group A_n or S_n. + Use the Davenport-Smith test to attempt to certify that `f` has Galois group `A_n` or `S_n`. - Return 1 if the Galois group is certified as S_n, 2 if A_n, or 0 if no conclusion is reached. + Return 1 if the Galois group is certified as `S_n`, 2 if `A_n`, or 0 if no conclusion is reached. By default, we first check that `f` is irreducible. For extra efficiency, one can override this - by specifying `assume_irreducible=True`; this yields undefined results if `f` is not irreducible. + by specifying ``assume_irreducible=True``; this yields undefined results if `f` is not irreducible. - A corresponding function in Magma is `IsEasySnAn`. + A corresponding function in Magma is ``IsEasySnAn``. EXAMPLES:: diff --git a/src/sage/rings/polynomial/polynomial_real_mpfr_dense.pyx b/src/sage/rings/polynomial/polynomial_real_mpfr_dense.pyx index c13372dcd25..4b61c4aa89d 100644 --- a/src/sage/rings/polynomial/polynomial_real_mpfr_dense.pyx +++ b/src/sage/rings/polynomial/polynomial_real_mpfr_dense.pyx @@ -6,19 +6,19 @@ TESTS: Check that operations with numpy elements work well (see :trac:`18076` and :trac:`8426`):: - sage: import numpy + sage: import numpy # optional - numpy sage: x = polygen(RR) - sage: x * numpy.int32('1') + sage: x * numpy.int32('1') # optional - numpy x - sage: numpy.int32('1') * x + sage: numpy.int32('1') * x # optional - numpy x - sage: x * numpy.int64('1') + sage: x * numpy.int64('1') # optional - numpy x - sage: numpy.int64('1') * x + sage: numpy.int64('1') * x # optional - numpy x - sage: x * numpy.float32('1.5') + sage: x * numpy.float32('1.5') # optional - numpy 1.50000000000000*x - sage: numpy.float32('1.5') * x + sage: numpy.float32('1.5') * x # optional - numpy 1.50000000000000*x """ @@ -72,7 +72,7 @@ cdef class PolynomialRealDense(Polynomial): EXAMPLES:: sage: from sage.rings.polynomial.polynomial_real_mpfr_dense import PolynomialRealDense - sage: PolynomialRealDense(RR['x'], [1, int(2), RR(3), 4/1, pi]) + sage: PolynomialRealDense(RR['x'], [1, int(2), RR(3), 4/1, pi]) # optional - sage.symbolic 3.14159265358979*x^4 + 4.00000000000000*x^3 + 3.00000000000000*x^2 + 2.00000000000000*x + 1.00000000000000 sage: PolynomialRealDense(RR['x'], None) 0 @@ -81,13 +81,13 @@ cdef class PolynomialRealDense(Polynomial): Check that errors and interrupts are handled properly (see :trac:`10100`):: - sage: a = var('a') - sage: PolynomialRealDense(RR['x'], [1,a]) + sage: a = var('a') # optional - sage.symbolic + sage: PolynomialRealDense(RR['x'], [1,a]) # optional - sage.symbolic Traceback (most recent call last): ... TypeError: cannot evaluate symbolic expression to a numeric value - sage: R. = SR[] - sage: (x-a).change_ring(RR) + sage: R. = SR[] # optional - sage.symbolic + sage: (x-a).change_ring(RR) # optional - sage.symbolic Traceback (most recent call last): ... TypeError: cannot evaluate symbolic expression to a numeric value @@ -96,9 +96,9 @@ cdef class PolynomialRealDense(Polynomial): Test that we don't clean up uninitialized coefficients (:trac:`9826`):: - sage: k. = GF(7^3) - sage: P. = PolynomialRing(k) - sage: (a*x).complex_roots() + sage: k. = GF(7^3) # optional - sage.rings.finite_rings + sage: P. = PolynomialRing(k) # optional - sage.rings.finite_rings + sage: (a*x).complex_roots() # optional - sage.rings.finite_rings Traceback (most recent call last): ... TypeError: unable to convert 'a' to a real number @@ -283,14 +283,15 @@ cdef class PolynomialRealDense(Polynomial): def truncate_abs(self, RealNumber bound): """ - Truncate all high order coefficients below bound. + Truncate all high order coefficients below ``bound``. EXAMPLES:: sage: from sage.rings.polynomial.polynomial_real_mpfr_dense import PolynomialRealDense sage: f = PolynomialRealDense(RealField(10)['x'], [10^-k for k in range(10)]) sage: f - 1.0e-9*x^9 + 1.0e-8*x^8 + 1.0e-7*x^7 + 1.0e-6*x^6 + 0.000010*x^5 + 0.00010*x^4 + 0.0010*x^3 + 0.010*x^2 + 0.10*x + 1.0 + 1.0e-9*x^9 + 1.0e-8*x^8 + 1.0e-7*x^7 + 1.0e-6*x^6 + 0.000010*x^5 + + 0.00010*x^4 + 0.0010*x^3 + 0.010*x^2 + 0.10*x + 1.0 sage: f.truncate_abs(0.5e-6) 1.0e-6*x^6 + 0.000010*x^5 + 0.00010*x^4 + 0.0010*x^3 + 0.010*x^2 + 0.10*x + 1.0 sage: f.truncate_abs(10.0) @@ -513,16 +514,16 @@ cdef class PolynomialRealDense(Polynomial): EXAMPLES:: sage: from sage.rings.polynomial.polynomial_real_mpfr_dense import PolynomialRealDense - sage: f = PolynomialRealDense(RR['x'], [pi, 0, 2, 1]) - sage: f.derivative() + sage: f = PolynomialRealDense(RR['x'], [pi, 0, 2, 1]) # optional - sage.symbolic + sage: f.derivative() # optional - sage.symbolic 3.00000000000000*x^2 + 4.00000000000000*x TESTS:: - sage: x, y = var('x,y') - sage: f.derivative(x) + sage: x, y = var('x,y') # optional - sage.symbolic + sage: f.derivative(x) # optional - sage.symbolic 3.00000000000000*x^2 + 4.00000000000000*x - sage: f.derivative(y) + sage: f.derivative(y) # optional - sage.symbolic Traceback (most recent call last): ... ValueError: cannot differentiate with respect to y @@ -541,8 +542,8 @@ cdef class PolynomialRealDense(Polynomial): EXAMPLES:: sage: from sage.rings.polynomial.polynomial_real_mpfr_dense import PolynomialRealDense - sage: f = PolynomialRealDense(RR['x'], [3, pi, 1]) - sage: f.integral() + sage: f = PolynomialRealDense(RR['x'], [3, pi, 1]) # optional - sage.symbolic + sage: f.integral() # optional - sage.symbolic 0.333333333333333*x^3 + 1.57079632679490*x^2 + 3.00000000000000*x """ cdef mpfr_rnd_t rnd = self._base_ring.rnd @@ -566,19 +567,19 @@ cdef class PolynomialRealDense(Polynomial): EXAMPLES:: - sage: f = RR['x']([-3, pi, 0, 1]) - sage: f.reverse() + sage: f = RR['x']([-3, pi, 0, 1]) # optional - sage.symbolic + sage: f.reverse() # optional - sage.symbolic -3.00000000000000*x^3 + 3.14159265358979*x^2 + 1.00000000000000 - sage: f.reverse(2) + sage: f.reverse(2) # optional - sage.symbolic -3.00000000000000*x^2 + 3.14159265358979*x - sage: f.reverse(5) + sage: f.reverse(5) # optional - sage.symbolic -3.00000000000000*x^5 + 3.14159265358979*x^4 + x^2 TESTS: We check that this implementation is compatible with the generic one:: - sage: all(f.reverse(d) == Polynomial.reverse(f, d) + sage: all(f.reverse(d) == Polynomial.reverse(f, d) # optional - sage.symbolic ....: for d in [None, 0, 1, 2, 3, 4, 5]) True """ @@ -619,9 +620,9 @@ cdef class PolynomialRealDense(Polynomial): (x^2 - 2.00000000000000, 0) sage: f = PolynomialRealDense(RR['x'], range(5)) - sage: g = PolynomialRealDense(RR['x'], [pi,3000,4]) - sage: q, r = f.quo_rem(g) - sage: g*q + r == f + sage: g = PolynomialRealDense(RR['x'], [pi,3000,4]) # optional - sage.symbolic + sage: q, r = f.quo_rem(g) # optional - sage.symbolic + sage: g*q + r == f # optional - sage.symbolic True TESTS: @@ -680,7 +681,7 @@ cdef class PolynomialRealDense(Polynomial): 2.00000000000000 sage: f(RealField(10)(2)) 2.0 - sage: f(pi) + sage: f(pi) # optional - sage.symbolic 1.00000000000000*pi^2 - 2.00000000000000 diff --git a/src/sage/rings/polynomial/polynomial_ring.py b/src/sage/rings/polynomial/polynomial_ring.py index ea07c8f5437..ff1d3532124 100644 --- a/src/sage/rings/polynomial/polynomial_ring.py +++ b/src/sage/rings/polynomial/polynomial_ring.py @@ -47,23 +47,23 @@ We create a polynomial ring over a quaternion algebra:: - sage: A. = QuaternionAlgebra(QQ, -1,-1) - sage: R. = PolynomialRing(A,sparse=True) - sage: f = w^3 + (i+j)*w + 1 - sage: f + sage: A. = QuaternionAlgebra(QQ, -1,-1) # optional - sage.combinat sage.modules + sage: R. = PolynomialRing(A, sparse=True) # optional - sage.combinat sage.modules + sage: f = w^3 + (i+j)*w + 1 # optional - sage.combinat sage.modules + sage: f # optional - sage.combinat sage.modules w^3 + (i + j)*w + 1 - sage: f^2 + sage: f^2 # optional - sage.combinat sage.modules w^6 + (2*i + 2*j)*w^4 + 2*w^3 - 2*w^2 + (2*i + 2*j)*w + 1 - sage: f = w + i ; g = w + j - sage: f * g + sage: f = w + i ; g = w + j # optional - sage.combinat sage.modules + sage: f * g # optional - sage.combinat sage.modules w^2 + (i + j)*w + k - sage: g * f + sage: g * f # optional - sage.combinat sage.modules w^2 + (i + j)*w - k :trac:`9944` introduced some changes related with coercion. Previously, a dense and a sparse polynomial ring with the same variable name over the same base ring evaluated equal, but of -course they were not identical.Coercion maps are cached - but if a +course they were not identical. Coercion maps are cached - but if a coercion to a dense ring is requested and a coercion to a sparse ring is returned instead (since the cache keys are equal!), all hell breaks loose. @@ -79,42 +79,42 @@ True sage: R.has_coerce_map_from(S) False - sage: (R.0+S.0).parent() + sage: (R.0 + S.0).parent() Univariate Polynomial Ring in x over Rational Field - sage: (S.0+R.0).parent() + sage: (S.0 + R.0).parent() Univariate Polynomial Ring in x over Rational Field It may be that one has rings of dense or sparse polynomials over different base rings. In that situation, coercion works by means of the :func:`~sage.categories.pushout.pushout` formalism:: - sage: R. = PolynomialRing(GF(5), sparse=True) + sage: R. = PolynomialRing(GF(5), sparse=True) # optional - sage.rings.finite_rings sage: S. = PolynomialRing(ZZ) - sage: R.has_coerce_map_from(S) + sage: R.has_coerce_map_from(S) # optional - sage.rings.finite_rings False - sage: S.has_coerce_map_from(R) + sage: S.has_coerce_map_from(R) # optional - sage.rings.finite_rings False - sage: S.0 + R.0 + sage: S.0 + R.0 # optional - sage.rings.finite_rings 2*x - sage: (S.0 + R.0).parent() + sage: (S.0 + R.0).parent() # optional - sage.rings.finite_rings Univariate Polynomial Ring in x over Finite Field of size 5 - sage: (S.0 + R.0).parent().is_sparse() + sage: (S.0 + R.0).parent().is_sparse() # optional - sage.rings.finite_rings False Similarly, there is a coercion from the (non-default) NTL implementation for univariate polynomials over the integers to the default FLINT implementation, but not vice versa:: - sage: R. = PolynomialRing(ZZ, implementation = 'NTL') - sage: S. = PolynomialRing(ZZ, implementation = 'FLINT') - sage: (S.0+R.0).parent() is S + sage: R. = PolynomialRing(ZZ, implementation='NTL') # optional - sage.libs.ntl + sage: S. = PolynomialRing(ZZ, implementation='FLINT') # optional - sage.libs.flint + sage: (S.0 + R.0).parent() is S # optional - sage.libs.flint sage.libs.ntl True - sage: (R.0+S.0).parent() is S + sage: (R.0 + S.0).parent() is S # optional - sage.libs.flint sage.libs.ntl True TESTS:: - sage: K.=FractionField(QQ['x']) + sage: K. = FractionField(QQ['x']) sage: V. = K[] sage: x+z z + x @@ -122,9 +122,9 @@ Check that :trac:`5562` has been fixed:: sage: R. = PolynomialRing(RDF, 1) - sage: v1 = vector([u]) - sage: v2 = vector([CDF(2)]) - sage: v1 * v2 + sage: v1 = vector([u]) # optional - sage.modules + sage: v2 = vector([CDF(2)]) # optional - sage.modules + sage: v1 * v2 # optional - sage.modules 2.0*u """ @@ -180,7 +180,7 @@ def is_PolynomialRing(x): """ - Return True if x is a *univariate* polynomial ring (and not a + Return ``True`` if ``x`` is a *univariate* polynomial ring (and not a sparse multivariate polynomial ring in one variable). EXAMPLES:: @@ -210,11 +210,11 @@ def is_PolynomialRing(x): :: - sage: R. = PolynomialRing(ZZ, implementation="singular"); R + sage: R. = PolynomialRing(ZZ, implementation="singular"); R # optional - sage.libs.singular Multivariate Polynomial Ring in w over Integer Ring - sage: is_PolynomialRing(R) + sage: is_PolynomialRing(R) # optional - sage.libs.singular False - sage: type(R) + sage: type(R) # optional - sage.libs.singular """ return isinstance(x, PolynomialRing_general) @@ -243,7 +243,7 @@ def __init__(self, base_ring, name=None, sparse=False, implementation=None, and Category of commutative algebras over (euclidean domains and infinite enumerated sets and metric spaces) and Category of infinite sets - sage: category(GF(7)['x']) + sage: category(GF(7)['x']) # optional - sage.rings.finite_rings Join of Category of euclidean domains and Category of commutative algebras over (finite enumerated fields and subquotients of monoids and quotients of semigroups) and Category of infinite sets @@ -268,13 +268,13 @@ def __init__(self, base_ring, name=None, sparse=False, implementation=None, sage: Zmod(1)['x'].is_finite() True - sage: GF(7)['x'].is_finite() + sage: GF(7)['x'].is_finite() # optional - sage.rings.finite_rings False sage: Zmod(1)['x']['y'].is_finite() True - sage: GF(7)['x']['y'].is_finite() + sage: GF(7)['x']['y'].is_finite() # optional - sage.rings.finite_rings False """ @@ -357,9 +357,9 @@ def _element_constructor_(self, x=None, check=True, is_gen=False, Coercing in pari elements:: - sage: QQ['x'](pari('[1,2,3/5]')) + sage: QQ['x'](pari('[1,2,3/5]')) # optional - sage.libs.pari 3/5*x^2 + 2*x + 1 - sage: QQ['x'](pari('(-1/3)*x^10 + (2/3)*x - 1/5')) + sage: QQ['x'](pari('(-1/3)*x^10 + (2/3)*x - 1/5')) # optional - sage.libs.pari -1/3*x^10 + 2/3*x - 1/5 Coercing strings:: @@ -377,10 +377,10 @@ def _element_constructor_(self, x=None, check=True, is_gen=False, This shows that the issue at :trac:`4106` is fixed:: - sage: x = var('x') + sage: x = var('x') # optional - sage.symbolic sage: R = IntegerModRing(4) - sage: S = R['x'] - sage: S(x) + sage: S = R['x'] # optional - sage.symbolic + sage: S(x) # optional - sage.symbolic x Throw a TypeError if any of the coefficients cannot be coerced @@ -393,16 +393,16 @@ def _element_constructor_(self, x=None, check=True, is_gen=False, Check that the bug in :trac:`11239` is fixed:: - sage: K. = GF(5^2, prefix='z') - sage: L. = GF(5^4, prefix='z') - sage: f = K['x'].gen() + a - sage: L['x'](f) + sage: K. = GF(5^2, prefix='z') # optional - sage.rings.finite_rings + sage: L. = GF(5^4, prefix='z') # optional - sage.rings.finite_rings + sage: f = K['x'].gen() + a # optional - sage.rings.finite_rings + sage: L['x'](f) # optional - sage.rings.finite_rings x + b^3 + b^2 + b + 3 A test from :trac:`14485` :: - sage: x = SR.var('x') - sage: QQbar[x](x^6+x^5+x^4-x^3+x^2-x+2/5) + sage: x = SR.var('x') # optional - sage.symbolic + sage: QQbar[x](x^6 + x^5 + x^4 - x^3 + x^2 - x + 2/5) # optional - sage.rings.number_field sage.symbolic x^6 + x^5 + x^4 - x^3 + x^2 - x + 2/5 Check support for unicode characters (:trac:`29280`):: @@ -603,7 +603,8 @@ def flattening_morphism(self): sage: QQ['a','b']['x'].flattening_morphism() Flattening morphism: - From: Univariate Polynomial Ring in x over Multivariate Polynomial Ring in a, b over Rational Field + From: Univariate Polynomial Ring in x over + Multivariate Polynomial Ring in a, b over Rational Field To: Multivariate Polynomial Ring in a, b, x over Rational Field sage: QQ['x'].flattening_morphism() @@ -693,7 +694,7 @@ def _coerce_map_from_base_ring(self): Polynomial base injection morphism: From: Rational Field To: Univariate Polynomial Ring in x over Rational Field - sage: R.coerce_map_from(GF(7)) + sage: R.coerce_map_from(GF(7)) # optional - sage.rings.finite_rings """ from .polynomial_element import PolynomialBaseringInjection @@ -732,9 +733,9 @@ def _coerce_map_from_(self, P): sage: R. = PolynomialRing(QQ, sparse=True) sage: S. = QQ[] - sage: (R.0+S.0).parent() + sage: (R.0 + S.0).parent() Univariate Polynomial Ring in x over Rational Field - sage: (S.0+R.0).parent() + sage: (S.0 + R.0).parent() Univariate Polynomial Ring in x over Rational Field Here we test a feature that was implemented in :trac:`813`:: @@ -743,7 +744,7 @@ def _coerce_map_from_(self, P): sage: Q = Frac(QQ['x'])['y'] sage: Q.has_coerce_map_from(P) True - sage: P.0+Q.0 + sage: P.0 + Q.0 y + x In order to avoid bidirectional coercions (which are generally @@ -761,20 +762,20 @@ def _coerce_map_from_(self, P): Over the integers, there is a coercion from the NTL and generic implementation to the default FLINT implementation:: - sage: R = PolynomialRing(ZZ, 't', implementation="NTL") - sage: S = PolynomialRing(ZZ, 't', implementation="FLINT") + sage: R = PolynomialRing(ZZ, 't', implementation="NTL") # optional - sage.libs.ntl + sage: S = PolynomialRing(ZZ, 't', implementation="FLINT") # optional - sage.libs.flint sage: T = PolynomialRing(ZZ, 't', implementation="generic") - sage: R.has_coerce_map_from(S) + sage: R.has_coerce_map_from(S) # optional - sage.libs.flint sage.libs.ntl False - sage: R.has_coerce_map_from(T) + sage: R.has_coerce_map_from(T) # optional - sage.libs.ntl False - sage: S.has_coerce_map_from(T) + sage: S.has_coerce_map_from(T) # optional - sage.libs.flint True - sage: S.has_coerce_map_from(R) + sage: S.has_coerce_map_from(R) # optional - sage.libs.flint sage.libs.ntl True - sage: T.has_coerce_map_from(R) + sage: T.has_coerce_map_from(R) # optional - sage.libs.ntl False - sage: T.has_coerce_map_from(S) + sage: T.has_coerce_map_from(S) # optional - sage.libs.flint False """ base_ring = self.base_ring() @@ -843,11 +844,11 @@ def _magma_init_(self, magma): Univariate Polynomial Ring in y over Rational Field sage: S.1 # optional - magma y - sage: magma(PolynomialRing(GF(7), 'x')) # optional - magma + sage: magma(PolynomialRing(GF(7), 'x')) # optional - magma # optional - sage.rings.finite_rings Univariate Polynomial Ring in x over GF(7) - sage: magma(PolynomialRing(GF(49,'a'), 'x')) # optional - magma + sage: magma(PolynomialRing(GF(49,'a'), 'x')) # optional - magma # optional - sage.rings.finite_rings Univariate Polynomial Ring in x over GF(7^2) - sage: magma(PolynomialRing(PolynomialRing(ZZ,'w'), 'x')) # optional - magma + sage: magma(PolynomialRing(PolynomialRing(ZZ,'w'), 'x')) # optional - magma Univariate Polynomial Ring in x over Univariate Polynomial Ring in w over Integer Ring Watch out, Magma has different semantics from Sage, i.e., in Magma @@ -867,9 +868,9 @@ def _magma_init_(self, magma): A nested example over a Givaro finite field:: - sage: k. = GF(9) - sage: R. = k[] - sage: magma(a^2*x^3 + (a+1)*x + a) # optional - magma + sage: k. = GF(9) # optional - sage.rings.finite_rings + sage: R. = k[] # optional - sage.rings.finite_rings + sage: magma(a^2*x^3 + (a+1)*x + a) # optional - magma # optional - sage.rings.finite_rings a^2*x^3 + a^2*x + a """ B = magma(self.base_ring()) @@ -888,23 +889,23 @@ def _gap_init_(self, gap=None): EXAMPLES:: sage: R. = ZZ[] - sage: gap(R) + sage: gap(R) # optional - sage.libs.gap PolynomialRing( Integers, ["z"] ) - sage: gap(R) is gap(R) + sage: gap(R) is gap(R) # optional - sage.libs.gap True - sage: gap(z^2 + z) + sage: gap(z^2 + z) # optional - sage.libs.gap z^2+z A univariate polynomial ring over a multivariate polynomial ring over a number field:: sage: Q. = QQ[] - sage: K. = NumberField(t^2+t+1) - sage: P. = K[] - sage: S. = P[] - sage: gap(S) + sage: K. = NumberField(t^2 + t + 1) # optional - sage.rings.number_field + sage: P. = K[] # optional - sage.rings.number_field + sage: S. = P[] # optional - sage.rings.number_field + sage: gap(S) # optional - sage.libs.gap sage.rings.number_field PolynomialRing( PolynomialRing( , ["x", "y"] ), ["z"] ) - sage: gap(S) is gap(S) + sage: gap(S) is gap(S) # optional - sage.libs.gap sage.rings.number_field True """ if gap is not None: @@ -920,11 +921,11 @@ def _sage_input_(self, sib, coerced): EXAMPLES:: - sage: sage_input(GF(5)['x']['y'], verify=True) + sage: sage_input(GF(5)['x']['y'], verify=True) # optional - sage.rings.finite_rings # Verified GF(5)['x']['y'] - sage: from sage.misc.sage_input import SageInputBuilder - sage: ZZ['z']._sage_input_(SageInputBuilder(), False) + sage: from sage.misc.sage_input import SageInputBuilder # optional - sage.rings.finite_rings + sage: ZZ['z']._sage_input_(SageInputBuilder(), False) # optional - sage.rings.finite_rings {constr_parent: {subscr: {atomic:ZZ}[{atomic:'z'}]} with gens: ('z',)} """ base = sib(self.base_ring()) @@ -963,9 +964,9 @@ def _is_valid_homomorphism_(self, codomain, im_gens, base_map=None): EXAMPLES:: sage: R. = QQ[] - sage: R._is_valid_homomorphism_(GF(7), [5]) + sage: R._is_valid_homomorphism_(GF(7), [5]) # optional - sage.rings.finite_rings False - sage: R._is_valid_homomorphism_(Qp(7), [5]) + sage: R._is_valid_homomorphism_(Qp(7), [5]) # optional - sage.rings.padics True """ # Since poly rings are free, any image of the gen @@ -1004,7 +1005,7 @@ def _latex_(self): r""" EXAMPLES:: - sage: S.=ZZ[] + sage: S. = ZZ[] sage: latex(S) \Bold{Z}[\alpha_{12}] """ @@ -1012,7 +1013,7 @@ def _latex_(self): def base_extend(self, R): """ - Return the base extension of this polynomial ring to R. + Return the base extension of this polynomial ring to `R`. EXAMPLES:: @@ -1036,13 +1037,14 @@ def base_extend(self, R): def change_ring(self, R): """ - Return the polynomial ring in the same variable as self over R. + Return the polynomial ring in the same variable as ``self`` over `R`. EXAMPLES:: - sage: R. = RealIntervalField() []; R - Univariate Polynomial Ring in ZZZ over Real Interval Field with 53 bits of precision - sage: R.change_ring(GF(19^2,'b')) + sage: R. = RealIntervalField()[]; R + Univariate Polynomial Ring in ZZZ over + Real Interval Field with 53 bits of precision + sage: R.change_ring(GF(19^2, 'b')) # optional - sage.rings.finite_rings Univariate Polynomial Ring in ZZZ over Finite Field in b of size 19^2 """ from sage.rings.polynomial.polynomial_ring_constructor import PolynomialRing @@ -1051,7 +1053,7 @@ def change_ring(self, R): def change_var(self, var): r""" - Return the polynomial ring in variable var over the same base + Return the polynomial ring in variable ``var`` over the same base ring. EXAMPLES:: @@ -1067,8 +1069,8 @@ def change_var(self, var): def extend_variables(self, added_names, order = 'degrevlex'): r""" - Returns a multivariate polynomial ring with the same base ring but - with added_names as additional variables. + Return a multivariate polynomial ring with the same base ring but + with ``added_names`` as additional variables. EXAMPLES:: @@ -1142,11 +1144,11 @@ def characteristic(self): EXAMPLES:: - sage: R. = RealIntervalField() []; R + sage: R. = RealIntervalField()[]; R Univariate Polynomial Ring in ZZZ over Real Interval Field with 53 bits of precision sage: R.characteristic() 0 - sage: S = R.change_ring(GF(19^2,'b')); S + sage: S = R.change_ring(GF(19^2, 'b')); S # optional - sage.rings.finite_rings Univariate Polynomial Ring in ZZZ over Finite Field in b of size 19^2 sage: S.characteristic() 19 @@ -1163,23 +1165,23 @@ def cyclotomic_polynomial(self, n): EXAMPLES:: sage: R = ZZ['x'] - sage: R.cyclotomic_polynomial(8) + sage: R.cyclotomic_polynomial(8) # optional - sage.libs.pari x^4 + 1 - sage: R.cyclotomic_polynomial(12) + sage: R.cyclotomic_polynomial(12) # optional - sage.libs.pari x^4 - x^2 + 1 - sage: S = PolynomialRing(FiniteField(7), 'x') - sage: S.cyclotomic_polynomial(12) + sage: S = PolynomialRing(FiniteField(7), 'x') # optional - sage.rings.finite_rings + sage: S.cyclotomic_polynomial(12) # optional - sage.rings.finite_rings x^4 + 6*x^2 + 1 - sage: S.cyclotomic_polynomial(1) + sage: S.cyclotomic_polynomial(1) # optional - sage.rings.finite_rings x + 6 TESTS: Make sure it agrees with other systems for the trivial case:: - sage: ZZ['x'].cyclotomic_polynomial(1) + sage: ZZ['x'].cyclotomic_polynomial(1) # optional - sage.libs.pari x - 1 - sage: gp('polcyclo(1)') + sage: gp('polcyclo(1)') # optional - sage.libs.pari x - 1 """ if n <= 0: @@ -1259,7 +1261,7 @@ def is_field(self, proof = True): def is_sparse(self): """ - Return true if elements of this polynomial ring have a sparse + Return ``True`` if elements of this polynomial ring have a sparse representation. EXAMPLES:: @@ -1307,16 +1309,16 @@ def krull_dimension(self): sage: R. = QQ[] sage: R.krull_dimension() 1 - sage: R. = GF(9,'a')[]; R + sage: R. = GF(9, 'a')[]; R # optional - sage.rings.finite_rings Univariate Polynomial Ring in z over Finite Field in a of size 3^2 - sage: R.krull_dimension() + sage: R.krull_dimension() # optional - sage.rings.finite_rings 1 - sage: S. = R[] - sage: S.krull_dimension() + sage: S. = R[] # optional - sage.rings.finite_rings + sage: S.krull_dimension() # optional - sage.rings.finite_rings 2 - sage: for n in range(10): - ....: S = PolynomialRing(S,'w') - sage: S.krull_dimension() + sage: for n in range(10): # optional - sage.rings.finite_rings + ....: S = PolynomialRing(S, 'w') + sage: S.krull_dimension() # optional - sage.rings.finite_rings 12 """ return self.base_ring().krull_dimension() + 1 @@ -1361,7 +1363,7 @@ def random_element(self, degree=(-1,2), *args, **kwds): sage: R.random_element(6).degree() 6 - If a tuple of two integers is given for the degree argument, a degree + If a tuple of two integers is given for the ``degree`` argument, a degree is first uniformly chosen, then a polynomial of that degree is given:: sage: R.random_element(degree=(0, 8)).degree() in range(0, 9) @@ -1370,10 +1372,10 @@ def random_element(self, degree=(-1,2), *args, **kwds): sage: while not all(found): ....: found[R.random_element(degree=(0, 8)).degree()] = True - Note that the zero polynomial has degree ``-1``, so if you want to - consider it set the minimum degree to ``-1``:: + Note that the zero polynomial has degree `-1`, so if you want to + consider it set the minimum degree to `-1`:: - sage: while R.random_element(degree=(-1,2),x=-1,y=1) != R.zero(): + sage: while R.random_element(degree=(-1,2), x=-1, y=1) != R.zero(): ....: pass TESTS:: @@ -1390,13 +1392,13 @@ def random_element(self, degree=(-1,2), *args, **kwds): Check that :trac:`16682` is fixed:: - sage: R = PolynomialRing(GF(2), 'z') - sage: for _ in range(100): + sage: R = PolynomialRing(GF(2), 'z') # optional - sage.rings.finite_rings + sage: for _ in range(100): # optional - sage.rings.finite_rings ....: d = randint(-1,20) ....: P = R.random_element(degree=d) ....: assert P.degree() == d, "problem with {} which has not degree {}".format(P,d) - sage: R.random_element(degree=-2) + sage: R.random_element(degree=-2) # optional - sage.rings.finite_rings Traceback (most recent call last): ... ValueError: degree should be an integer greater or equal than -1 @@ -1494,12 +1496,12 @@ def _Karatsuba_threshold(self): EXAMPLES:: - sage: R. = QQbar[] - sage: R._Karatsuba_threshold + sage: R. = QQbar[] # optional - sage.rings.number_field + sage: R._Karatsuba_threshold # optional - sage.rings.number_field 8 - sage: MS = MatrixSpace(ZZ, 2, 2) - sage: R. = MS[] - sage: R._Karatsuba_threshold + sage: MS = MatrixSpace(ZZ, 2, 2) # optional - sage.modules + sage: R. = MS[] # optional - sage.modules + sage: R._Karatsuba_threshold # optional - sage.modules 0 """ base_ring = self.base_ring() @@ -1517,7 +1519,7 @@ def _Karatsuba_threshold(self): def karatsuba_threshold(self): """ Return the Karatsuba threshold used for this ring by the method - _mul_karatsuba to fall back to the schoolbook algorithm. + :meth:`_mul_karatsuba` to fall back to the schoolbook algorithm. EXAMPLES:: @@ -1532,7 +1534,7 @@ def karatsuba_threshold(self): def set_karatsuba_threshold(self, Karatsuba_threshold): """ - Changes the default threshold for this ring in the method _mul_karatsuba + Changes the default threshold for this ring in the method :meth:`_mul_karatsuba` to fall back to the schoolbook algorithm. .. warning:: @@ -1557,21 +1559,19 @@ def polynomials( self, of_degree = None, max_degree = None ): INPUT: Pass exactly one of: - - ``max_degree`` - an int; the iterator will generate all polynomials which have degree less than or equal to - max_degree + ``max_degree`` - ``of_degree`` - an int; the iterator will generate - all polynomials which have degree of_degree - + all polynomials which have degree ``of_degree`` OUTPUT: an iterator EXAMPLES:: - sage: P = PolynomialRing(GF(3),'y') - sage: for p in P.polynomials( of_degree = 2 ): print(p) + sage: P = PolynomialRing(GF(3), 'y') # optional - sage.rings.finite_rings + sage: for p in P.polynomials(of_degree=2): print(p) # optional - sage.rings.finite_rings y^2 y^2 + 1 y^2 + 2 @@ -1590,7 +1590,7 @@ def polynomials( self, of_degree = None, max_degree = None ): 2*y^2 + 2*y 2*y^2 + 2*y + 1 2*y^2 + 2*y + 2 - sage: for p in P.polynomials( max_degree = 1 ): print(p) + sage: for p in P.polynomials(max_degree=1): print(p) # optional - sage.rings.finite_rings 0 1 2 @@ -1600,7 +1600,7 @@ def polynomials( self, of_degree = None, max_degree = None ): 2*y 2*y + 1 2*y + 2 - sage: for p in P.polynomials( max_degree = 1, of_degree = 3 ): print(p) + sage: for p in P.polynomials(max_degree=1, of_degree=3): print(p) # optional - sage.rings.finite_rings Traceback (most recent call last): ... ValueError: you should pass exactly one of of_degree and max_degree @@ -1627,18 +1627,18 @@ def monics( self, of_degree = None, max_degree = None ): - ``max_degree`` - an int; the iterator will generate all monic polynomials which have degree less than or equal to - max_degree + ``max_degree`` - ``of_degree`` - an int; the iterator will generate - all monic polynomials which have degree of_degree + all monic polynomials which have degree ``of_degree`` OUTPUT: an iterator EXAMPLES:: - sage: P = PolynomialRing(GF(4,'a'),'y') - sage: for p in P.monics( of_degree = 2 ): print(p) + sage: P = PolynomialRing(GF(4, 'a'), 'y') # optional - sage.rings.finite_rings + sage: for p in P.monics(of_degree=2): print(p) # optional - sage.rings.finite_rings y^2 y^2 + a y^2 + a + 1 @@ -1655,13 +1655,13 @@ def monics( self, of_degree = None, max_degree = None ): y^2 + y + a y^2 + y + a + 1 y^2 + y + 1 - sage: for p in P.monics( max_degree = 1 ): print(p) + sage: for p in P.monics(max_degree=1): print(p) # optional - sage.rings.finite_rings 1 y y + a y + a + 1 y + 1 - sage: for p in P.monics( max_degree = 1, of_degree = 3 ): print(p) + sage: for p in P.monics(max_degree=1, of_degree=3): print(p) # optional - sage.rings.finite_rings Traceback (most recent call last): ... ValueError: you should pass exactly one of of_degree and max_degree @@ -1712,25 +1712,27 @@ def quotient_by_principal_ideal(self, f, names=None, **kwds): EXAMPLES:: sage: R. = QQ[] - sage: I = (x^2-1)*R - sage: R.quotient_by_principal_ideal(I) - Univariate Quotient Polynomial Ring in xbar over Rational Field with modulus x^2 - 1 + sage: I = (x^2 - 1) * R + sage: R.quotient_by_principal_ideal(I) # optional - sage.libs.pari + Univariate Quotient Polynomial Ring in xbar + over Rational Field with modulus x^2 - 1 The same example, using the polynomial instead of the ideal, and customizing the variable name:: sage: R. = QQ[] - sage: R.quotient_by_principal_ideal(x^2-1, names=('foo',)) - Univariate Quotient Polynomial Ring in foo over Rational Field with modulus x^2 - 1 + sage: R.quotient_by_principal_ideal(x^2 - 1, names=('foo',)) # optional - sage.libs.pari + Univariate Quotient Polynomial Ring in foo + over Rational Field with modulus x^2 - 1 TESTS: Quotienting by the zero ideal returns ``self`` (:trac:`5978`):: sage: R = QQ['x'] - sage: R.quotient_by_principal_ideal(R.zero_ideal()) is R + sage: R.quotient_by_principal_ideal(R.zero_ideal()) is R # optional - sage.libs.pari True - sage: R.quotient_by_principal_ideal(0) is R + sage: R.quotient_by_principal_ideal(0) is R # optional - sage.libs.pari True """ from sage.rings.ideal import Ideal @@ -1748,9 +1750,9 @@ def weyl_algebra(self): EXAMPLES:: sage: R = QQ['x'] - sage: W = R.weyl_algebra(); W + sage: W = R.weyl_algebra(); W # optional - sage.combinat sage.modules Differential Weyl algebra of polynomials in x over Rational Field - sage: W.polynomial_ring() == R + sage: W.polynomial_ring() == R # optional - sage.combinat sage.modules True """ from sage.algebras.weyl_algebra import DifferentialWeylAlgebra @@ -1813,12 +1815,12 @@ def __init__(self, base_ring, name="x", sparse=False, implementation=None, sage: from sage.rings.polynomial.polynomial_ring import PolynomialRing_integral_domain as PRing sage: R = PRing(ZZ, 'x'); R Univariate Polynomial Ring in x over Integer Ring - sage: type(R.gen()) + sage: type(R.gen()) # optional - sage.libs.flint - sage: R = PRing(ZZ, 'x', implementation='NTL'); R + sage: R = PRing(ZZ, 'x', implementation='NTL'); R # optional - sage.libs.ntl Univariate Polynomial Ring in x over Integer Ring (using NTL) - sage: type(R.gen()) + sage: type(R.gen()) # optional - sage.libs.ntl """ self._implementation_repr = '' @@ -1872,77 +1874,80 @@ def weil_polynomials(self, d, q, sign=1, lead=1): - ``sign`` -- integer (default `1`), the sign `s` of the functional equation - ``lead`` -- integer, list of integers or list of pairs of integers (default `1`), - constraints on the leading few coefficients of the generated polynomials. - If pairs `(a, b)` of integers are given, they are treated as a constraint - of the form `\equiv a \pmod{b}`; the moduli must be in decreasing order by - divisibility, and the modulus of the leading coefficient must be 0. + constraints on the leading few coefficients of the generated polynomials. + If pairs `(a, b)` of integers are given, they are treated as a constraint + of the form `\equiv a \pmod{b}`; the moduli must be in decreasing order by + divisibility, and the modulus of the leading coefficient must be 0. .. SEEALSO:: More documentation and additional options are available using the iterator :class:`sage.rings.polynomial.weil.weil_polynomials.WeilPolynomials` - directly. In addition, polynomials have a method `is_weil_polynomial` to + directly. In addition, polynomials have a method :meth:`is_weil_polynomial` to test whether or not the given polynomial is a Weil polynomial. EXAMPLES:: sage: R. = ZZ[] - sage: L = R.weil_polynomials(4, 2) - sage: len(L) + sage: L = R.weil_polynomials(4, 2) # optional - sage.libs.flint + sage: len(L) # optional - sage.libs.flint 35 - sage: L[9] + sage: L[9] # optional - sage.libs.flint T^4 + T^3 + 2*T^2 + 2*T + 4 - sage: all(p.is_weil_polynomial() for p in L) + sage: all(p.is_weil_polynomial() for p in L) # optional - sage.libs.flint True Setting multiple leading coefficients:: sage: R. = QQ[] - sage: l = R.weil_polynomials(4,2,lead=((1,0),(2,4),(1,2))) - sage: l + sage: l = R.weil_polynomials(4, 2, lead=((1,0), (2,4), (1,2))) # optional - sage.libs.flint + sage: l # optional - sage.libs.flint [T^4 + 2*T^3 + 5*T^2 + 4*T + 4, - T^4 + 2*T^3 + 3*T^2 + 4*T + 4, - T^4 - 2*T^3 + 5*T^2 - 4*T + 4, - T^4 - 2*T^3 + 3*T^2 - 4*T + 4] + T^4 + 2*T^3 + 3*T^2 + 4*T + 4, + T^4 - 2*T^3 + 5*T^2 - 4*T + 4, + T^4 - 2*T^3 + 3*T^2 - 4*T + 4] We do not require Weil polynomials to be monic. This example generates Weil - polynomials associated to K3 surfaces over `GF(2)` of Picard number at least 12:: + polynomials associated to K3 surfaces over `\GF{2}` of Picard number at least 12:: sage: R. = QQ[] - sage: l = R.weil_polynomials(10,1,lead=2) - sage: len(l) + sage: l = R.weil_polynomials(10, 1, lead=2) # optional - sage.libs.flint + sage: len(l) # optional - sage.libs.flint 4865 - sage: l[len(l)//2] + sage: l[len(l)//2] # optional - sage.libs.flint 2*T^10 + T^8 + T^6 + T^4 + T^2 + 2 TESTS: We check that products of Weil polynomials are also listed as Weil polynomials:: - sage: all((f * g) in R.weil_polynomials(6, q) for q in [3,4] for f in R.weil_polynomials(2, q) for g in R.weil_polynomials(4, q)) + sage: all((f * g) in R.weil_polynomials(6, q) for q in [3, 4] # optional - sage.libs.flint + ....: for f in R.weil_polynomials(2, q) for g in R.weil_polynomials(4, q)) True We check that irreducible Weil polynomials of degree 6 are CM:: - sage: simples = [f for f in R.weil_polynomials(6, 3) if f.is_irreducible()] - sage: len(simples) + sage: simples = [f for f in R.weil_polynomials(6, 3) if f.is_irreducible()] # optional - sage.libs.flint + sage: len(simples) # optional - sage.libs.flint 348 - sage: reals = [R([f[3+i] + sum((-3)^j * (i+2*j)/(i+j) * binomial(i+j,j) * f[3+i+2*j] for j in range(1,(3+i)//2+1)) for i in range(4)]) for f in simples] + sage: reals = [R([f[3+i] + sum((-3)^j * (i+2*j)/(i+j) * binomial(i+j,j) * f[3+i+2*j] # optional - sage.libs.flint + ....: for j in range(1, (3+i)//2 + 1)) + ....: for i in range(4)]) for f in simples] Check that every polynomial in this list has 3 real roots between `-2 \sqrt{3}` and `2 \sqrt{3}`:: - sage: roots = [f.roots(RR, multiplicities=False) for f in reals] - sage: all(len(L) == 3 and all(x^2 <= 12 for x in L) for L in roots) + sage: roots = [f.roots(RR, multiplicities=False) for f in reals] # optional - sage.libs.flint + sage: all(len(L) == 3 and all(x^2 <= 12 for x in L) for L in roots) # optional - sage.libs.flint True Finally, check that the original polynomials are reconstructed as CM polynomials:: - sage: all(f == T^3*r(T + 3/T) for (f, r) in zip(simples, reals)) + sage: all(f == T^3*r(T + 3/T) for (f, r) in zip(simples, reals)) # optional - sage.libs.flint True A simple check (not sufficient):: - sage: all(f.number_of_real_roots() == 0 for f in simples) + sage: all(f.number_of_real_roots() == 0 for f in simples) # optional - sage.libs.flint True """ R = self.base_ring() @@ -1981,7 +1986,7 @@ def _repr_(self): TESTS:: sage: from sage.rings.polynomial.polynomial_ring import PolynomialRing_integral_domain as PRing - sage: R = PRing(ZZ, 'x', implementation='NTL'); R + sage: R = PRing(ZZ, 'x', implementation='NTL'); R # optional - sage.libs.ntl Univariate Polynomial Ring in x over Integer Ring (using NTL) """ s = PolynomialRing_commutative._repr_(self) @@ -2001,11 +2006,11 @@ def construction(self): sage: functor.implementation is None True - sage: R = PRing(ZZ, 'x', implementation='NTL'); R + sage: R = PRing(ZZ, 'x', implementation='NTL'); R # optional - sage.libs.ntl Univariate Polynomial Ring in x over Integer Ring (using NTL) - sage: functor, arg = R.construction(); functor, arg + sage: functor, arg = R.construction(); functor, arg # optional - sage.libs.ntl (Poly[x], Integer Ring) - sage: functor.implementation + sage: functor.implementation # optional - sage.libs.ntl 'NTL' """ implementation = None @@ -2030,7 +2035,7 @@ def __init__(self, base_ring, name="x", sparse=False, implementation=None, sage: from sage.rings.polynomial.polynomial_ring import PolynomialRing_field as PRing sage: R = PRing(QQ, 'x'); R Univariate Polynomial Ring in x over Rational Field - sage: type(R.gen()) + sage: type(R.gen()) # optional - sage.libs.flint sage: R = PRing(QQ, 'x', sparse=True); R Sparse Univariate Polynomial Ring in x over Rational Field @@ -2043,7 +2048,7 @@ def __init__(self, base_ring, name="x", sparse=False, implementation=None, Demonstrate that :trac:`8762` is fixed:: - sage: R. = PolynomialRing(GF(next_prime(10^20)), sparse=True) + sage: R. = PolynomialRing(GF(next_prime(10^20)), sparse=True) # optional - sage.rings.finite_rings sage: x^(10^20) # this should be fast x^100000000000000000000 """ @@ -2090,8 +2095,8 @@ def _ideal_class_(self, n=0): EXAMPLES:: - sage: R. = GF(5)[] - sage: R._ideal_class_() + sage: R. = GF(5)[] # optional - sage.rings.finite_rings + sage: R._ideal_class_() # optional - sage.rings.finite_rings """ from sage.rings.polynomial.ideal import Ideal_1poly_field @@ -2107,7 +2112,7 @@ def divided_difference(self, points, full_table=False): - ``points`` -- a list of pairs `(x_0, y_0), (x_1, y_1), \dots, (x_n, y_n)` of elements of the base ring of ``self``, where `x_i - x_j` is invertible for `i \neq j`. This method - converts the `x_i` and `y_i` into the base ring of `self`. + converts the `x_i` and `y_i` into the base ring of ``self``. - ``full_table`` -- boolean (default: ``False``): If ``True``, return the full divided-difference table. If ``False``, @@ -2119,7 +2124,7 @@ def divided_difference(self, points, full_table=False): The Newton divided-difference coefficients of the `n`-th Lagrange interpolation polynomial `P_n(x)` that passes through the points in ``points`` (see :meth:`lagrange_polynomial`). - These are the coefficients `F_{0,0}, F_{1,1}, \dots, `F_{n,n}` + These are the coefficients `F_{0,0}, F_{1,1}, \dots, F_{n,n}` in the base ring of ``self`` such that .. MATH:: @@ -2131,32 +2136,29 @@ def divided_difference(self, points, full_table=False): Only return the divided-difference coefficients `F_{i,i}`. This example is taken from Example 1, page 121 of [BF2005]_:: - sage: points = [(1.0, 0.7651977), (1.3, 0.6200860), (1.6, 0.4554022), (1.9, 0.2818186), (2.2, 0.1103623)] + sage: points = [(1.0, 0.7651977), (1.3, 0.6200860), (1.6, 0.4554022), + ....: (1.9, 0.2818186), (2.2, 0.1103623)] sage: R = PolynomialRing(RR, "x") sage: R.divided_difference(points) [0.765197700000000, - -0.483705666666666, - -0.108733888888889, - 0.0658783950617283, - 0.00182510288066044] + -0.483705666666666, + -0.108733888888889, + 0.0658783950617283, + 0.00182510288066044] Now return the full divided-difference table:: - sage: points = [(1.0, 0.7651977), (1.3, 0.6200860), (1.6, 0.4554022), (1.9, 0.2818186), (2.2, 0.1103623)] + sage: points = [(1.0, 0.7651977), (1.3, 0.6200860), (1.6, 0.4554022), + ....: (1.9, 0.2818186), (2.2, 0.1103623)] sage: R = PolynomialRing(RR, "x") sage: R.divided_difference(points, full_table=True) [[0.765197700000000], - [0.620086000000000, -0.483705666666666], - [0.455402200000000, -0.548946000000000, -0.108733888888889], - [0.281818600000000, - -0.578612000000000, - -0.0494433333333339, - 0.0658783950617283], - [0.110362300000000, - -0.571520999999999, - 0.0118183333333349, - 0.0680685185185209, - 0.00182510288066044]] + [0.620086000000000, -0.483705666666666], + [0.455402200000000, -0.548946000000000, -0.108733888888889], + [0.281818600000000, -0.578612000000000, + -0.0494433333333339, 0.0658783950617283], + [0.110362300000000, -0.571520999999999, 0.0118183333333349, + 0.0680685185185209, 0.00182510288066044]] The following example is taken from Example 4.12, page 225 of [MF1999]_:: @@ -2167,11 +2169,11 @@ def divided_difference(self, points, full_table=False): [-3, 3, 6, 1, 0, 0] sage: R.divided_difference(points, full_table=True) [[-3], - [0, 3], - [15, 15, 6], - [48, 33, 9, 1], - [105, 57, 12, 1, 0], - [192, 87, 15, 1, 0, 0]] + [0, 3], + [15, 15, 6], + [48, 33, 9, 1], + [105, 57, 12, 1, 0], + [192, 87, 15, 1, 0, 0]] """ to_base_ring = self.base_ring() points = [tuple(to_base_ring(c) for c in p) for p in points] @@ -2197,7 +2199,7 @@ def lagrange_polynomial(self, points, algorithm="divided_difference", previous_r - ``points`` -- a list of pairs `(x_0, y_0), (x_1, y_1), \dots, (x_n, y_n)` of elements of the base ring of ``self``, where `x_i - x_j` is invertible for `i \neq j`. This method - converts the `x_i` and `y_i` into the base ring of `self`. + converts the `x_i` and `y_i` into the base ring of ``self``. - ``algorithm`` -- (default: ``'divided_difference'``): one of the following: @@ -2205,7 +2207,7 @@ def lagrange_polynomial(self, points, algorithm="divided_difference", previous_r - ``'divided_difference'``: use the method of divided differences. - - ``algorithm='neville'``: adapt Neville's method as + - ``'neville'``: adapt Neville's method as described on page 144 of [BF2005]_ to recursively generate the Lagrange interpolation polynomial. Neville's method generates a table of approximating polynomials, where the @@ -2236,7 +2238,7 @@ def lagrange_polynomial(self, points, algorithm="divided_difference", previous_r By default, we use the method of divided differences:: sage: R = PolynomialRing(QQ, 'x') - sage: f = R.lagrange_polynomial([(0,1),(2,2),(3,-2),(-4,9)]); f + sage: f = R.lagrange_polynomial([(0,1), (2,2), (3,-2), (-4,9)]); f -23/84*x^3 - 11/84*x^2 + 13/7*x + 1 sage: f(0) 1 @@ -2246,41 +2248,45 @@ def lagrange_polynomial(self, points, algorithm="divided_difference", previous_r -2 sage: f(-4) 9 - sage: R = PolynomialRing(GF(2**3,'a'), 'x') - sage: a = R.base_ring().gen() - sage: f = R.lagrange_polynomial([(a^2+a,a),(a,1),(a^2,a^2+a+1)]); f + sage: R = PolynomialRing(GF(2**3, 'a'), 'x') # optional - sage.rings.finite_rings + sage: a = R.base_ring().gen() # optional - sage.rings.finite_rings + sage: f = R.lagrange_polynomial([(a^2+a, a), (a, 1), (a^2, a^2+a+1)]); f # optional - sage.rings.finite_rings a^2*x^2 + a^2*x + a^2 - sage: f(a^2+a) + sage: f(a^2 + a) # optional - sage.rings.finite_rings a - sage: f(a) + sage: f(a) # optional - sage.rings.finite_rings 1 - sage: f(a^2) + sage: f(a^2) # optional - sage.rings.finite_rings a^2 + a + 1 Now use a memory efficient version of Neville's method:: sage: R = PolynomialRing(QQ, 'x') - sage: R.lagrange_polynomial([(0,1),(2,2),(3,-2),(-4,9)], algorithm="neville") + sage: R.lagrange_polynomial([(0,1), (2,2), (3,-2), (-4,9)], + ....: algorithm="neville") [9, -11/7*x + 19/7, -17/42*x^2 - 83/42*x + 53/7, -23/84*x^3 - 11/84*x^2 + 13/7*x + 1] - sage: R = PolynomialRing(GF(2**3,'a'), 'x') - sage: a = R.base_ring().gen() - sage: R.lagrange_polynomial([(a^2+a,a),(a,1),(a^2,a^2+a+1)], algorithm="neville") + sage: R = PolynomialRing(GF(2**3, 'a'), 'x') # optional - sage.rings.finite_rings + sage: a = R.base_ring().gen() # optional - sage.rings.finite_rings + sage: R.lagrange_polynomial([(a^2+a, a), (a, 1), (a^2, a^2+a+1)], # optional - sage.rings.finite_rings + ....: algorithm="neville") [a^2 + a + 1, x + a + 1, a^2*x^2 + a^2*x + a^2] Repeated use of Neville's method to get better Lagrange interpolation polynomials:: sage: R = PolynomialRing(QQ, 'x') - sage: p = R.lagrange_polynomial([(0,1),(2,2)], algorithm="neville") - sage: R.lagrange_polynomial([(0,1),(2,2),(3,-2),(-4,9)], algorithm="neville", previous_row=p)[-1] + sage: p = R.lagrange_polynomial([(0,1), (2,2)], algorithm="neville") + sage: R.lagrange_polynomial([(0,1), (2,2), (3,-2), (-4,9)], + ....: algorithm="neville", previous_row=p)[-1] -23/84*x^3 - 11/84*x^2 + 13/7*x + 1 - sage: R = PolynomialRing(GF(2**3,'a'), 'x') - sage: a = R.base_ring().gen() - sage: p = R.lagrange_polynomial([(a^2+a,a),(a,1)], algorithm="neville") - sage: R.lagrange_polynomial([(a^2+a,a),(a,1),(a^2,a^2+a+1)], algorithm="neville", previous_row=p)[-1] + sage: R = PolynomialRing(GF(2**3, 'a'), 'x') # optional - sage.rings.finite_rings + sage: a = R.base_ring().gen() # optional - sage.rings.finite_rings + sage: p = R.lagrange_polynomial([(a^2+a, a), (a, 1)], algorithm="neville") # optional - sage.rings.finite_rings + sage: R.lagrange_polynomial([(a^2+a, a), (a, 1), (a^2, a^2+a+1)], # optional - sage.rings.finite_rings + ....: algorithm="neville", previous_row=p)[-1] a^2*x^2 + a^2*x + a^2 TESTS: @@ -2322,10 +2328,10 @@ def lagrange_polynomial(self, points, algorithm="divided_difference", previous_r Check that base fields of positive characteristic are treated correctly (see :trac:`9787`):: - sage: R. = GF(101)[] - sage: R.lagrange_polynomial([[1, 0], [2, 0]]) + sage: R. = GF(101)[] # optional - sage.rings.finite_rings + sage: R.lagrange_polynomial([[1, 0], [2, 0]]) # optional - sage.rings.finite_rings 0 - sage: R.lagrange_polynomial([[1, 0], [2, 0], [3, 0]]) + sage: R.lagrange_polynomial([[1, 0], [2, 0], [3, 0]]) # optional - sage.rings.finite_rings 0 """ # Perhaps we should be slightly stricter on the input and use @@ -2411,24 +2417,25 @@ def fraction_field(self): EXAMPLES:: - sage: R. = GF(5)[] - sage: R.fraction_field() - Fraction Field of Univariate Polynomial Ring in t over Finite Field of size 5 + sage: R. = GF(5)[] # optional - sage.rings.finite_rings + sage: R.fraction_field() # optional - sage.rings.finite_rings + Fraction Field of Univariate Polynomial Ring in t + over Finite Field of size 5 TESTS: Check that :trac:`25449` has been resolved:: - sage: k = GF(25453) - sage: F. = FunctionField(k) - sage: R. = k[] - sage: t(x) + sage: k = GF(25453) # optional - sage.rings.finite_rings + sage: F. = FunctionField(k) # optional - sage.rings.finite_rings + sage: R. = k[] # optional - sage.rings.finite_rings + sage: t(x) # optional - sage.rings.finite_rings x - sage: k = GF(55667) - sage: F. = FunctionField(k) - sage: R. = k[] - sage: t(x) + sage: k = GF(55667) # optional - sage.rings.finite_rings + sage: F. = FunctionField(k) # optional - sage.rings.finite_rings + sage: R. = k[] # optional - sage.rings.finite_rings + sage: t(x) # optional - sage.rings.finite_rings x """ @@ -2448,24 +2455,24 @@ class PolynomialRing_dense_finite_field(PolynomialRing_field): EXAMPLES:: - sage: R = PolynomialRing(GF(27, 'a'), 'x') - sage: type(R) + sage: R = PolynomialRing(GF(27, 'a'), 'x') # optional - sage.rings.finite_rings + sage: type(R) # optional - sage.rings.finite_rings """ def __init__(self, base_ring, name="x", element_class=None, implementation=None): """ TESTS:: - sage: from sage.rings.polynomial.polynomial_ring import PolynomialRing_dense_finite_field - sage: R = PolynomialRing_dense_finite_field(GF(5), implementation='generic') - sage: type(R(0)) + sage: from sage.rings.polynomial.polynomial_ring import PolynomialRing_dense_finite_field # optional - sage.rings.finite_rings + sage: R = PolynomialRing_dense_finite_field(GF(5), implementation='generic') # optional - sage.rings.finite_rings + sage: type(R(0)) # optional - sage.rings.finite_rings - sage: S = PolynomialRing_dense_finite_field(GF(25, 'a'), implementation='NTL') - sage: type(S(0)) + sage: S = PolynomialRing_dense_finite_field(GF(25, 'a'), implementation='NTL') # optional - sage.rings.finite_rings + sage: type(S(0)) # optional - sage.rings.finite_rings - sage: S = PolynomialRing_dense_finite_field(GF(64), implementation='superfast') + sage: S = PolynomialRing_dense_finite_field(GF(64), implementation='superfast') # optional - sage.rings.finite_rings Traceback (most recent call last): ... ValueError: unknown implementation 'superfast' for dense polynomial rings over Finite Field in z6 of size 2^6 @@ -2494,16 +2501,16 @@ def _implementation_names_impl(implementation, base_ring, sparse): """ TESTS:: - sage: from sage.rings.polynomial.polynomial_ring import PolynomialRing_dense_finite_field - sage: PolynomialRing_dense_finite_field._implementation_names_impl("NTL", GF(4), False) + sage: from sage.rings.polynomial.polynomial_ring import PolynomialRing_dense_finite_field # optional - sage.rings.finite_rings + sage: PolynomialRing_dense_finite_field._implementation_names_impl("NTL", GF(4), False) # optional - sage.rings.finite_rings ['NTL', None] - sage: PolynomialRing_dense_finite_field._implementation_names_impl(None, GF(4), False) + sage: PolynomialRing_dense_finite_field._implementation_names_impl(None, GF(4), False) # optional - sage.rings.finite_rings ['NTL', None] - sage: PolynomialRing_dense_finite_field._implementation_names_impl("generic", GF(4), False) + sage: PolynomialRing_dense_finite_field._implementation_names_impl("generic", GF(4), False) # optional - sage.rings.finite_rings ['generic'] - sage: PolynomialRing_dense_finite_field._implementation_names_impl("FLINT", GF(4), False) + sage: PolynomialRing_dense_finite_field._implementation_names_impl("FLINT", GF(4), False) # optional - sage.rings.finite_rings NotImplemented - sage: PolynomialRing_dense_finite_field._implementation_names_impl(None, GF(4), True) + sage: PolynomialRing_dense_finite_field._implementation_names_impl(None, GF(4), True) # optional - sage.rings.finite_rings NotImplemented """ if sparse: @@ -2538,14 +2545,16 @@ def irreducible_element(self, n, algorithm=None): EXAMPLES:: - sage: f = GF(5^3, 'a')['x'].irreducible_element(2) - sage: f.degree() + sage: f = GF(5^3, 'a')['x'].irreducible_element(2) # optional - sage.rings.finite_rings + sage: f.degree() # optional - sage.rings.finite_rings 2 - sage: f.is_irreducible() + sage: f.is_irreducible() # optional - sage.rings.finite_rings True - sage: GF(19)['x'].irreducible_element(21, algorithm="first_lexicographic") + sage: R = GF(19)['x'] # optional - sage.rings.finite_rings + sage: R.irreducible_element(21, algorithm="first_lexicographic") # optional - sage.rings.finite_rings x^21 + x + 5 - sage: GF(5**2, 'a')['x'].irreducible_element(17, algorithm="first_lexicographic") + sage: R = GF(5**2, 'a')['x'] # optional - sage.rings.finite_rings + sage: R.irreducible_element(17, algorithm="first_lexicographic") # optional - sage.rings.finite_rings x^17 + a*x + 4*a + 3 AUTHORS: @@ -2606,15 +2615,15 @@ def _roth_ruckenstein(self, p, degree_bound, precision): EXAMPLES:: - sage: F = GF(17) - sage: Px. = F[] - sage: Pxy. = Px[] - sage: p = (y - (x**2 + x + 1)) * (y**2 - x + 1) * (y - (x**3 + 4*x + 16)) - sage: Px._roth_ruckenstein(p, 3, None) + sage: F = GF(17) # optional - sage.rings.finite_rings + sage: Px. = F[] # optional - sage.rings.finite_rings + sage: Pxy. = Px[] # optional - sage.rings.finite_rings + sage: p = (y - (x**2 + x + 1)) * (y**2 - x + 1) * (y - (x**3 + 4*x + 16)) # optional - sage.rings.finite_rings + sage: Px._roth_ruckenstein(p, 3, None) # optional - sage.rings.finite_rings [x^3 + 4*x + 16, x^2 + x + 1] - sage: Px._roth_ruckenstein(p, 2, None) + sage: Px._roth_ruckenstein(p, 2, None) # optional - sage.rings.finite_rings [x^2 + x + 1] - sage: Px._roth_ruckenstein(p, 1, 2) + sage: Px._roth_ruckenstein(p, 1, 2) # optional - sage.rings.finite_rings [(4*x + 16, 2), (2*x + 13, 2), (15*x + 4, 2), (x + 1, 2)] """ def roth_rec(p, lam, k, g): @@ -2705,28 +2714,29 @@ def _alekhnovich(self, p, degree_bound, precision=None, dc_threshold=None): EXAMPLES:: - sage: R. = GF(17)[] - sage: S. = R[] - sage: p = (y - 2*x^2 - 3*x - 14) * (y - 3*x + 2) * (y - 1) - sage: R._alekhnovich(p, 2) + sage: R. = GF(17)[] # optional - sage.rings.finite_rings + sage: S. = R[] # optional - sage.rings.finite_rings + sage: p = (y - 2*x^2 - 3*x - 14) * (y - 3*x + 2) * (y - 1) # optional - sage.rings.finite_rings + sage: R._alekhnovich(p, 2) # optional - sage.rings.finite_rings [3*x + 15, 2*x^2 + 3*x + 14, 1] - sage: R._alekhnovich(p, 1) + sage: R._alekhnovich(p, 1) # optional - sage.rings.finite_rings [3*x + 15, 1] - sage: R._alekhnovich(p, 1, precision = 2) + sage: R._alekhnovich(p, 1, precision=2) # optional - sage.rings.finite_rings [(3*x + 15, 2), (3*x + 14, 2), (1, 2)] Example of benchmark to check that `dc_threshold = None` is better:: - sage: p = prod(y - R.random_element(20) for _ in range(10)) * S.random_element(10,10) # not tested - sage: %timeit _alekhnovich(R, p, 20, dc_threshold = None) # not tested + sage: p = prod(y - R.random_element(20) # not tested # optional - sage.rings.finite_rings + ....: for _ in range(10)) * S.random_element(10,10) + sage: %timeit _alekhnovich(R, p, 20, dc_threshold = None) # not tested # optional - sage.rings.finite_rings 1 loop, best of 3: 418 ms per loop - sage: %timeit _alekhnovich(R, p, 20, dc_threshold = 1) # not tested + sage: %timeit _alekhnovich(R, p, 20, dc_threshold = 1) # not tested # optional - sage.rings.finite_rings 1 loop, best of 3: 416 ms per loop - sage: %timeit _alekhnovich(R, p, 20, dc_threshold = 2) # not tested + sage: %timeit _alekhnovich(R, p, 20, dc_threshold = 2) # not tested # optional - sage.rings.finite_rings 1 loop, best of 3: 418 ms per loop - sage: %timeit _alekhnovich(R, p, 20, dc_threshold = 3) # not tested + sage: %timeit _alekhnovich(R, p, 20, dc_threshold = 3) # not tested # optional - sage.rings.finite_rings 1 loop, best of 3: 454 ms per loop - sage: %timeit _alekhnovich(R, p, 20, dc_threshold = 4) # not tested + sage: %timeit _alekhnovich(R, p, 20, dc_threshold = 4) # not tested # optional - sage.rings.finite_rings 1 loop, best of 3: 519 ms per loop AUTHORS: @@ -2816,24 +2826,24 @@ def _roots_univariate_polynomial(self, p, ring=None, multiplicities=False, algor EXAMPLES:: - sage: R. = GF(13)[] - sage: S. = R[] - sage: p = y^2 + (12*x^2 + x + 11)*y + x^3 + 12*x^2 + 12*x + 1 - sage: p.roots(multiplicities=False) + sage: R. = GF(13)[] # optional - sage.rings.finite_rings + sage: S. = R[] # optional - sage.rings.finite_rings + sage: p = y^2 + (12*x^2 + x + 11)*y + x^3 + 12*x^2 + 12*x + 1 # optional - sage.rings.finite_rings + sage: p.roots(multiplicities=False) # optional - sage.rings.finite_rings [x^2 + 11*x + 1, x + 1] - sage: p.roots(multiplicities=False, degree_bound=1) + sage: p.roots(multiplicities=False, degree_bound=1) # optional - sage.rings.finite_rings [x + 1] - sage: p.roots(multiplicities=False, algorithm="Roth-Ruckenstein") + sage: p.roots(multiplicities=False, algorithm="Roth-Ruckenstein") # optional - sage.rings.finite_rings [x^2 + 11*x + 1, x + 1] TESTS: Check that :trac:`23639` is fixed:: - sage: R = GF(3)['x']['y'] - sage: R.one().roots(multiplicities=False) + sage: R = GF(3)['x']['y'] # optional - sage.rings.finite_rings + sage: R.one().roots(multiplicities=False) # optional - sage.rings.finite_rings [] - sage: R.zero().roots(multiplicities=False) + sage: R.zero().roots(multiplicities=False) # optional - sage.rings.finite_rings Traceback (most recent call last): ... ArithmeticError: roots of 0 are not defined @@ -2878,7 +2888,7 @@ def __init__(self, base_ring, name=None, sparse=False, implementation=None, sage: isinstance(S, PolynomialRing_cdvr) False - sage: S. = Zp(5)[] + sage: S. = Zp(5)[] # optional - sage.rings.padics sage: isinstance(S, PolynomialRing_cdvr) True """ @@ -2909,8 +2919,8 @@ def __init__(self, base_ring, name=None, sparse=False, implementation=None, sage: isinstance(S, PolynomialRing_cdvf) False - sage: S. = Qp(5)[] - sage: isinstance(S, PolynomialRing_cdvf) + sage: S. = Qp(5)[] # optional - sage.rings.padics + sage: isinstance(S, PolynomialRing_cdvf) # optional - sage.rings.padics True """ if element_class is None: @@ -2927,7 +2937,7 @@ def __init__(self, base_ring, name=None, sparse=False, implementation=None, class PolynomialRing_dense_padic_ring_generic(PolynomialRing_cdvr): r""" - A class for dense polynomial ring over padic rings + A class for dense polynomial ring over p-adic rings """ def __init__(self, base_ring, name=None, implementation=None, element_class=None, category=None): PolynomialRing_cdvr.__init__(self, base_ring, sparse=False, name=name, @@ -2942,11 +2952,11 @@ def _implementation_names_impl(implementation, base_ring, sparse): TESTS:: sage: from sage.rings.polynomial.polynomial_ring import PolynomialRing_dense_padic_ring_generic - sage: PolynomialRing_dense_padic_ring_generic._implementation_names_impl(None, Zp(2), False) + sage: PolynomialRing_dense_padic_ring_generic._implementation_names_impl(None, Zp(2), False) # optional - sage.rings.padics [None] - sage: PolynomialRing_dense_padic_ring_generic._implementation_names_impl(None, Zp(2), True) + sage: PolynomialRing_dense_padic_ring_generic._implementation_names_impl(None, Zp(2), True) # optional - sage.rings.padics NotImplemented - sage: PolynomialRing_dense_padic_ring_generic._implementation_names_impl("generic", Zp(2), False) + sage: PolynomialRing_dense_padic_ring_generic._implementation_names_impl("generic", Zp(2), False) # optional - sage.rings.padics NotImplemented """ if implementation is None and not sparse: @@ -2956,7 +2966,7 @@ def _implementation_names_impl(implementation, base_ring, sparse): class PolynomialRing_dense_padic_field_generic(PolynomialRing_cdvf): r""" - A class for dense polynomial ring over padic fields + A class for dense polynomial ring over p-adic fields """ def __init__(self, base_ring, name=None, implementation=None, element_class=None, category=None): PolynomialRing_cdvf.__init__(self, base_ring, sparse=False, name=name, @@ -2971,11 +2981,11 @@ def _implementation_names_impl(implementation, base_ring, sparse): TESTS:: sage: from sage.rings.polynomial.polynomial_ring import PolynomialRing_dense_padic_field_generic - sage: PolynomialRing_dense_padic_field_generic._implementation_names_impl(None, Qp(2), False) + sage: PolynomialRing_dense_padic_field_generic._implementation_names_impl(None, Qp(2), False) # optional - sage.rings.padics [None] - sage: PolynomialRing_dense_padic_field_generic._implementation_names_impl(None, Qp(2), True) + sage: PolynomialRing_dense_padic_field_generic._implementation_names_impl(None, Qp(2), True) # optional - sage.rings.padics NotImplemented - sage: PolynomialRing_dense_padic_field_generic._implementation_names_impl("generic", Qp(2), False) + sage: PolynomialRing_dense_padic_field_generic._implementation_names_impl("generic", Qp(2), False) # optional - sage.rings.padics NotImplemented """ if implementation is None and not sparse: @@ -2989,9 +2999,9 @@ def __init__(self, base_ring, name=None, implementation=None, element_class=None TESTS:: sage: from sage.rings.polynomial.polynomial_ring import PolynomialRing_dense_padic_ring_capped_relative as PRing - sage: R = PRing(Zp(13), name='t'); R + sage: R = PRing(Zp(13), name='t'); R # optional - sage.rings.padics Univariate Polynomial Ring in t over 13-adic Ring with capped relative precision 20 - sage: type(R.gen()) + sage: type(R.gen()) # optional - sage.rings.padics """ if element_class is None: @@ -3010,9 +3020,9 @@ def __init__(self, base_ring, name=None, implementation=None, element_class=None TESTS:: sage: from sage.rings.polynomial.polynomial_ring import PolynomialRing_dense_padic_ring_capped_absolute as PRing - sage: R = PRing(Zp(13, type='capped-abs'), name='t'); R + sage: R = PRing(Zp(13, type='capped-abs'), name='t'); R # optional - sage.rings.padics Univariate Polynomial Ring in t over 13-adic Ring with capped absolute precision 20 - sage: type(R.gen()) + sage: type(R.gen()) # optional - sage.rings.padics """ if element_class is None: @@ -3030,10 +3040,10 @@ def __init__(self, base_ring, name=None, implementation=None, element_class=None TESTS:: sage: from sage.rings.polynomial.polynomial_ring import PolynomialRing_dense_padic_ring_fixed_mod as PRing - sage: R = PRing(Zp(13, type='fixed-mod'), name='t'); R + sage: R = PRing(Zp(13, type='fixed-mod'), name='t'); R # optional - sage.rings.padics Univariate Polynomial Ring in t over 13-adic Ring of fixed modulus 13^20 - sage: type(R.gen()) + sage: type(R.gen()) # optional - sage.rings.padics """ if element_class is None: @@ -3051,9 +3061,9 @@ def __init__(self, base_ring, name=None, implementation=None, element_class=None TESTS:: sage: from sage.rings.polynomial.polynomial_ring import PolynomialRing_dense_padic_field_capped_relative as PRing - sage: R = PRing(Qp(13), name='t'); R + sage: R = PRing(Qp(13), name='t'); R # optional - sage.rings.padics Univariate Polynomial Ring in t over 13-adic Field with capped relative precision 20 - sage: type(R.gen()) + sage: type(R.gen()) # optional - sage.rings.padics """ if element_class is None: @@ -3075,27 +3085,27 @@ def __init__(self, base_ring, name=None, element_class=None, sage: from sage.rings.polynomial.polynomial_ring import PolynomialRing_dense_mod_n as PRing sage: R = PRing(Zmod(15), 'x'); R Univariate Polynomial Ring in x over Ring of integers modulo 15 - sage: type(R.gen()) + sage: type(R.gen()) # optional - sage.libs.flint - sage: R = PRing(Zmod(15), 'x', implementation='NTL'); R + sage: R = PRing(Zmod(15), 'x', implementation='NTL'); R # optional - sage.libs.ntl Univariate Polynomial Ring in x over Ring of integers modulo 15 (using NTL) - sage: type(R.gen()) + sage: type(R.gen()) # optional - sage.libs.ntl - sage: R = PRing(Zmod(2**63*3), 'x', implementation='NTL'); R + sage: R = PRing(Zmod(2**63*3), 'x', implementation='NTL'); R # optional - sage.libs.ntl Univariate Polynomial Ring in x over Ring of integers modulo 27670116110564327424 (using NTL) - sage: type(R.gen()) + sage: type(R.gen()) # optional - sage.libs.ntl - sage: R = PRing(Zmod(2**63*3), 'x', implementation='FLINT') + sage: R = PRing(Zmod(2**63*3), 'x', implementation='FLINT') # optional - sage.libs.flint Traceback (most recent call last): ... ValueError: FLINT does not support modulus 27670116110564327424 - sage: R = PRing(Zmod(2**63*3), 'x'); R + sage: R = PRing(Zmod(2**63*3), 'x'); R # optional - sage.libs.ntl Univariate Polynomial Ring in x over Ring of integers modulo 27670116110564327424 (using NTL) - sage: type(R.gen()) + sage: type(R.gen()) # optional - sage.libs.ntl """ if element_class is None: @@ -3186,7 +3196,7 @@ def _repr_(self): TESTS:: sage: from sage.rings.polynomial.polynomial_ring import PolynomialRing_integral_domain as PRing - sage: R = PRing(ZZ, 'x', implementation='NTL'); R + sage: R = PRing(ZZ, 'x', implementation='NTL'); R # optional - sage.libs.ntl Univariate Polynomial Ring in x over Integer Ring (using NTL) """ s = PolynomialRing_commutative._repr_(self) @@ -3198,32 +3208,38 @@ def residue_field(self, ideal, names=None): EXAMPLES:: - sage: R. = GF(2)[] - sage: k. = R.residue_field(t^3+t+1); k - Residue field in a of Principal ideal (t^3 + t + 1) of Univariate Polynomial Ring in t over Finite Field of size 2 (using GF2X) - sage: k.list() + sage: R. = GF(2)[] # optional - sage.rings.finite_rings + sage: k. = R.residue_field(t^3 + t + 1); k # optional - sage.rings.finite_rings + Residue field in a + of Principal ideal (t^3 + t + 1) of Univariate Polynomial Ring in t + over Finite Field of size 2 (using GF2X) + sage: k.list() # optional - sage.rings.finite_rings [0, a, a^2, a + 1, a^2 + a, a^2 + a + 1, a^2 + 1, 1] - sage: R.residue_field(t) - Residue field of Principal ideal (t) of Univariate Polynomial Ring in t over Finite Field of size 2 (using GF2X) - sage: P = R.irreducible_element(8) * R - sage: P - Principal ideal (t^8 + t^4 + t^3 + t^2 + 1) of Univariate Polynomial Ring in t over Finite Field of size 2 (using GF2X) - sage: k. = R.residue_field(P); k - Residue field in a of Principal ideal (t^8 + t^4 + t^3 + t^2 + 1) of Univariate Polynomial Ring in t over Finite Field of size 2 (using GF2X) - sage: k.cardinality() + sage: R.residue_field(t) # optional - sage.rings.finite_rings + Residue field of Principal ideal (t) of Univariate Polynomial Ring in t + over Finite Field of size 2 (using GF2X) + sage: P = R.irreducible_element(8) * R # optional - sage.rings.finite_rings + sage: P # optional - sage.rings.finite_rings + Principal ideal (t^8 + t^4 + t^3 + t^2 + 1) of Univariate Polynomial Ring in t + over Finite Field of size 2 (using GF2X) + sage: k. = R.residue_field(P); k # optional - sage.rings.finite_rings + Residue field in a + of Principal ideal (t^8 + t^4 + t^3 + t^2 + 1) of Univariate Polynomial Ring in t + over Finite Field of size 2 (using GF2X) + sage: k.cardinality() # optional - sage.rings.finite_rings 256 Non-maximal ideals are not accepted:: - sage: R.residue_field(t^2 + 1) + sage: R.residue_field(t^2 + 1) # optional - sage.rings.finite_rings Traceback (most recent call last): ... ArithmeticError: ideal is not maximal - sage: R.residue_field(0) + sage: R.residue_field(0) # optional - sage.rings.finite_rings Traceback (most recent call last): ... ArithmeticError: ideal is not maximal - sage: R.residue_field(1) + sage: R.residue_field(1) # optional - sage.rings.finite_rings Traceback (most recent call last): ... ArithmeticError: ideal is not maximal @@ -3241,36 +3257,36 @@ def __init__(self, base_ring, name="x", implementation=None, element_class=None, """ TESTS:: - sage: P = GF(2)['x']; P + sage: P = GF(2)['x']; P # optional - sage.rings.finite_rings Univariate Polynomial Ring in x over Finite Field of size 2 (using GF2X) - sage: type(P.gen()) + sage: type(P.gen()) # optional - sage.rings.finite_rings - sage: from sage.rings.polynomial.polynomial_ring import PolynomialRing_dense_mod_p - sage: P = PolynomialRing_dense_mod_p(GF(5), 'x'); P + sage: from sage.rings.polynomial.polynomial_ring import PolynomialRing_dense_mod_p # optional - sage.rings.finite_rings + sage: P = PolynomialRing_dense_mod_p(GF(5), 'x'); P # optional - sage.rings.finite_rings Univariate Polynomial Ring in x over Finite Field of size 5 - sage: type(P.gen()) + sage: type(P.gen()) # optional - sage.rings.finite_rings - sage: P = PolynomialRing_dense_mod_p(GF(5), 'x', implementation='NTL'); P + sage: P = PolynomialRing_dense_mod_p(GF(5), 'x', implementation='NTL'); P # optional - sage.rings.finite_rings Univariate Polynomial Ring in x over Finite Field of size 5 (using NTL) - sage: type(P.gen()) + sage: type(P.gen()) # optional - sage.rings.finite_rings - sage: P = PolynomialRing_dense_mod_p(GF(9223372036854775837), 'x') - sage: P + sage: P = PolynomialRing_dense_mod_p(GF(9223372036854775837), 'x') # optional - sage.rings.finite_rings + sage: P # optional - sage.rings.finite_rings Univariate Polynomial Ring in x over Finite Field of size 9223372036854775837 (using NTL) - sage: type(P.gen()) + sage: type(P.gen()) # optional - sage.rings.finite_rings This caching bug was fixed in :trac:`24264`:: sage: p = 2^64 + 13 - sage: A = GF(p^2) - sage: B = GF(p^3) - sage: R = A.modulus().parent() - sage: S = B.modulus().parent() - sage: R is S + sage: A = GF(p^2) # optional - sage.rings.finite_rings + sage: B = GF(p^3) # optional - sage.rings.finite_rings + sage: R = A.modulus().parent() # optional - sage.rings.finite_rings + sage: S = B.modulus().parent() # optional - sage.rings.finite_rings + sage: R is S # optional - sage.rings.finite_rings True """ if element_class is None: @@ -3312,15 +3328,15 @@ def _implementation_names_impl(implementation, base_ring, sparse): """ TESTS:: - sage: PolynomialRing(GF(2), 'x', implementation="GF2X") + sage: PolynomialRing(GF(2), 'x', implementation="GF2X") # optional - sage.rings.finite_rings Univariate Polynomial Ring in x over Finite Field of size 2 (using GF2X) - sage: PolynomialRing(GF(2), 'x', implementation="NTL") + sage: PolynomialRing(GF(2), 'x', implementation="NTL") # optional - sage.rings.finite_rings Univariate Polynomial Ring in x over Finite Field of size 2 (using GF2X) - sage: PolynomialRing(GF(2), 'x', implementation=None) + sage: PolynomialRing(GF(2), 'x', implementation=None) # optional - sage.rings.finite_rings Univariate Polynomial Ring in x over Finite Field of size 2 (using GF2X) - sage: PolynomialRing(GF(2), 'x', implementation="FLINT") + sage: PolynomialRing(GF(2), 'x', implementation="FLINT") # optional - sage.rings.finite_rings Univariate Polynomial Ring in x over Finite Field of size 2 - sage: PolynomialRing(GF(3), 'x', implementation="GF2X") + sage: PolynomialRing(GF(3), 'x', implementation="GF2X") # optional - sage.rings.finite_rings Traceback (most recent call last): ... ValueError: GF2X only supports modulus 2 @@ -3356,13 +3372,13 @@ def irreducible_element(self, n, algorithm=None): Currently available options are: - ``'adleman-lenstra'``: a variant of the Adleman--Lenstra - algorithm as implemented in PARI. + algorithm as implemented in PARI. - ``'conway'``: look up the Conway polynomial of degree `n` over the field of `p` elements in the database; raise a ``RuntimeError`` if it is not found. - - ``'ffprimroot'``: use the ``ffprimroot()`` function from + - ``'ffprimroot'``: use the :pari:`ffprimroot` function from PARI. - ``'first_lexicographic'``: return the lexicographically @@ -3375,7 +3391,7 @@ def irreducible_element(self, n, algorithm=None): - ``'primitive'``: return a polynomial `f` such that a root of `f` generates the multiplicative group of the finite field extension defined by `f`. This uses the Conway polynomial if - possible, otherwise it uses ``ffprimroot``. + possible, otherwise it uses ``'ffprimroot'``. - ``'random'``: try random polynomials until an irreducible one is found. @@ -3383,7 +3399,7 @@ def irreducible_element(self, n, algorithm=None): If ``algorithm`` is ``None``, use `x - 1` in degree 1. In degree > 1, the Conway polynomial is used if it is found in the database. Otherwise, the algorithm ``minimal_weight`` - is used if `p = 2`, and the algorithm ``adleman-lenstra`` if + is used if `p = 2`, and the algorithm ``'adleman-lenstra'`` if `p > 2`. OUTPUT: @@ -3392,35 +3408,35 @@ def irreducible_element(self, n, algorithm=None): EXAMPLES:: - sage: GF(5)['x'].irreducible_element(2) + sage: GF(5)['x'].irreducible_element(2) # optional - sage.rings.finite_rings x^2 + 4*x + 2 - sage: GF(5)['x'].irreducible_element(2, algorithm="adleman-lenstra") + sage: GF(5)['x'].irreducible_element(2, algorithm="adleman-lenstra") # optional - sage.rings.finite_rings x^2 + x + 1 - sage: GF(5)['x'].irreducible_element(2, algorithm="primitive") + sage: GF(5)['x'].irreducible_element(2, algorithm="primitive") # optional - sage.rings.finite_rings x^2 + 4*x + 2 - sage: GF(5)['x'].irreducible_element(32, algorithm="first_lexicographic") + sage: GF(5)['x'].irreducible_element(32, algorithm="first_lexicographic") # optional - sage.rings.finite_rings x^32 + 2 - sage: GF(5)['x'].irreducible_element(32, algorithm="conway") + sage: GF(5)['x'].irreducible_element(32, algorithm="conway") # optional - sage.rings.finite_rings Traceback (most recent call last): ... RuntimeError: requested Conway polynomial not in database. - sage: GF(5)['x'].irreducible_element(32, algorithm="primitive") + sage: GF(5)['x'].irreducible_element(32, algorithm="primitive") # optional - sage.rings.finite_rings x^32 + ... In characteristic 2:: - sage: GF(2)['x'].irreducible_element(33) + sage: GF(2)['x'].irreducible_element(33) # optional - sage.rings.finite_rings x^33 + x^13 + x^12 + x^11 + x^10 + x^8 + x^6 + x^3 + 1 - sage: GF(2)['x'].irreducible_element(33, algorithm="minimal_weight") + sage: GF(2)['x'].irreducible_element(33, algorithm="minimal_weight") # optional - sage.rings.finite_rings x^33 + x^10 + 1 In degree 1:: - sage: GF(97)['x'].irreducible_element(1) + sage: GF(97)['x'].irreducible_element(1) # optional - sage.rings.finite_rings x + 96 - sage: GF(97)['x'].irreducible_element(1, algorithm="conway") + sage: GF(97)['x'].irreducible_element(1, algorithm="conway") # optional - sage.rings.finite_rings x + 92 - sage: GF(97)['x'].irreducible_element(1, algorithm="adleman-lenstra") + sage: GF(97)['x'].irreducible_element(1, algorithm="adleman-lenstra") # optional - sage.rings.finite_rings x AUTHORS: @@ -3489,9 +3505,9 @@ def polygen(ring_or_element, name="x"): INPUT: - - polygen(base_ring, name="x") + - ``polygen(base_ring, name="x")`` - - polygen(ring_element, name="x") + - ``polygen(ring_element, name="x")`` If the first input is a ring, return a polynomial generator over that ring. If it is a ring element, return a polynomial generator @@ -3499,7 +3515,7 @@ def polygen(ring_or_element, name="x"): EXAMPLES:: - sage: z = polygen(QQ,'z') + sage: z = polygen(QQ, 'z') sage: z^3 + z +1 z^3 + z + 1 sage: parent(z) @@ -3507,9 +3523,9 @@ def polygen(ring_or_element, name="x"): .. note:: - If you give a list or comma separated string to polygen, you'll + If you give a list or comma-separated string to :func:`polygen`, you'll get a tuple of indeterminates, exactly as if you called - polygens. + :func:`polygens`. """ if is_RingElement(ring_or_element): base_ring = ring_or_element.parent() @@ -3536,7 +3552,7 @@ def polygens(base_ring, names="x", *args): x^2 + 2*x*y + y^2 + 2*x*z + 2*y*z + z^2 sage: parent(x) Multivariate Polynomial Ring in x, y, z over Rational Field - sage: t = polygens(QQ,['x','yz','abc']) + sage: t = polygens(QQ, ['x','yz','abc']) sage: t (x, yz, abc) diff --git a/src/sage/rings/polynomial/polynomial_ring_constructor.py b/src/sage/rings/polynomial/polynomial_ring_constructor.py index 5f823ec7205..08968a5795b 100644 --- a/src/sage/rings/polynomial/polynomial_ring_constructor.py +++ b/src/sage/rings/polynomial/polynomial_ring_constructor.py @@ -114,7 +114,7 @@ def PolynomialRing(base_ring, *args, **kwds): one multivariate polynomial ring over each base ring for each choice of names of variables and term order. The names of the generators can only be temporarily changed after the ring has been - created. Do this using the localvars context: + created. Do this using the :func:`localvars` context. EXAMPLES: @@ -144,8 +144,9 @@ def PolynomialRing(base_ring, *args, **kwds): sage: R. = PolynomialRing(QQ, sparse=True); R Sparse Univariate Polynomial Ring in abc over Rational Field - sage: R. = PolynomialRing(PolynomialRing(GF(7),'k')); R - Univariate Polynomial Ring in w over Univariate Polynomial Ring in k over Finite Field of size 7 + sage: R. = PolynomialRing(PolynomialRing(GF(7),'k')); R # optional - sage.rings.finite_rings + Univariate Polynomial Ring in w over + Univariate Polynomial Ring in k over Finite Field of size 7 The square bracket notation:: @@ -164,7 +165,7 @@ def PolynomialRing(base_ring, *args, **kwds): This is exactly the same ring as what PolynomialRing returns:: - sage: R is PolynomialRing(QQ,'zz') + sage: R is PolynomialRing(QQ, 'zz') True However, rings with different variables are different:: @@ -179,32 +180,32 @@ def PolynomialRing(base_ring, *args, **kwds): like 2^1000000 * x^1000000 in FLINT may be unwise. :: - sage: ZxNTL = PolynomialRing(ZZ, 'x', implementation='NTL'); ZxNTL + sage: ZxNTL = PolynomialRing(ZZ, 'x', implementation='NTL'); ZxNTL # optional - sage.libs.ntl Univariate Polynomial Ring in x over Integer Ring (using NTL) - sage: ZxFLINT = PolynomialRing(ZZ, 'x', implementation='FLINT'); ZxFLINT + sage: ZxFLINT = PolynomialRing(ZZ, 'x', implementation='FLINT'); ZxFLINT # optional - sage.libs.flint Univariate Polynomial Ring in x over Integer Ring - sage: ZxFLINT is ZZ['x'] + sage: ZxFLINT is ZZ['x'] # optional - sage.libs.flint True - sage: ZxFLINT is PolynomialRing(ZZ, 'x') + sage: ZxFLINT is PolynomialRing(ZZ, 'x') # optional - sage.libs.flint True - sage: xNTL = ZxNTL.gen() - sage: xFLINT = ZxFLINT.gen() - sage: xNTL.parent() + sage: xNTL = ZxNTL.gen() # optional - sage.libs.ntl + sage: xFLINT = ZxFLINT.gen() # optional - sage.libs.flint + sage: xNTL.parent() # optional - sage.libs.ntl Univariate Polynomial Ring in x over Integer Ring (using NTL) - sage: xFLINT.parent() + sage: xFLINT.parent() # optional - sage.libs.flint Univariate Polynomial Ring in x over Integer Ring There is a coercion from the non-default to the default implementation, so the values can be mixed in a single expression:: - sage: (xNTL + xFLINT^2) + sage: (xNTL + xFLINT^2) # optional - sage.libs.flint sage.libs.ntl x^2 + x The result of such an expression will use the default, i.e., the FLINT implementation:: - sage: (xNTL + xFLINT^2).parent() + sage: (xNTL + xFLINT^2).parent() # optional - sage.libs.flint sage.libs.ntl Univariate Polynomial Ring in x over Integer Ring The generic implementation uses neither NTL nor FLINT:: @@ -259,9 +260,9 @@ def PolynomialRing(base_ring, *args, **kwds): The Singular implementation always returns a multivariate ring, even for 1 variable:: - sage: PolynomialRing(QQ, "x", implementation="singular") + sage: PolynomialRing(QQ, "x", implementation="singular") # optional - sage.libs.singular Multivariate Polynomial Ring in x over Rational Field - sage: P. = PolynomialRing(QQ, implementation="singular"); P + sage: P. = PolynomialRing(QQ, implementation="singular"); P # optional - sage.libs.singular Multivariate Polynomial Ring in x over Rational Field **3. PolynomialRing(base_ring, n, names, ...)** (where the arguments @@ -278,7 +279,7 @@ def PolynomialRing(base_ring, *args, **kwds): sage: PolynomialRing(QQ, 2, 'alpha0') Multivariate Polynomial Ring in alpha00, alpha01 over Rational Field - sage: PolynomialRing(GF(7), 'y', 5) + sage: PolynomialRing(GF(7), 'y', 5) # optional - sage.rings.finite_rings Multivariate Polynomial Ring in y0, y1, y2, y3, y4 over Finite Field of size 7 sage: PolynomialRing(QQ, 'y', 3, sparse=True) @@ -298,16 +299,19 @@ def PolynomialRing(base_ring, *args, **kwds): example, here is a ring with generators labeled by the primes less than 100:: - sage: R = PolynomialRing(ZZ, ['x%s'%p for p in primes(100)]); R - Multivariate Polynomial Ring in x2, x3, x5, x7, x11, x13, x17, x19, x23, x29, x31, x37, x41, x43, x47, x53, x59, x61, x67, x71, x73, x79, x83, x89, x97 over Integer Ring + sage: R = PolynomialRing(ZZ, ['x%s'%p for p in primes(100)]); R # optional - sage.libs.pari + Multivariate Polynomial Ring in x2, x3, x5, x7, x11, x13, x17, x19, x23, x29, + x31, x37, x41, x43, x47, x53, x59, x61, x67, x71, x73, x79, x83, x89, x97 + over Integer Ring By calling the :meth:`~sage.structure.category_object.CategoryObject.inject_variables` method, all those variable names are available for interactive use:: - sage: R.inject_variables() - Defining x2, x3, x5, x7, x11, x13, x17, x19, x23, x29, x31, x37, x41, x43, x47, x53, x59, x61, x67, x71, x73, x79, x83, x89, x97 - sage: (x2 + x41 + x71)^2 + sage: R.inject_variables() # optional - sage.libs.pari + Defining x2, x3, x5, x7, x11, x13, x17, x19, x23, x29, x31, x37, x41, x43, + x47, x53, x59, x61, x67, x71, x73, x79, x83, x89, x97 + sage: (x2 + x41 + x71)^2 # optional - sage.libs.pari x2^2 + 2*x2*x41 + x41^2 + 2*x2*x71 + 2*x41*x71 + x71^2 **4. PolynomialRing(base_ring, n, ..., var_array=var_array, ...)** @@ -323,9 +327,13 @@ def PolynomialRing(base_ring, *args, **kwds): It is possible to create higher-dimensional arrays:: sage: PolynomialRing(ZZ, 2, 3, var_array=('p', 'q')) - Multivariate Polynomial Ring in p00, q00, p01, q01, p02, q02, p10, q10, p11, q11, p12, q12 over Integer Ring + Multivariate Polynomial Ring + in p00, q00, p01, q01, p02, q02, p10, q10, p11, q11, p12, q12 + over Integer Ring sage: PolynomialRing(ZZ, 2, 3, 4, var_array='m') - Multivariate Polynomial Ring in m000, m001, m002, m003, m010, m011, m012, m013, m020, m021, m022, m023, m100, m101, m102, m103, m110, m111, m112, m113, m120, m121, m122, m123 over Integer Ring + Multivariate Polynomial Ring in m000, m001, m002, m003, m010, m011, + m012, m013, m020, m021, m022, m023, m100, m101, m102, m103, m110, + m111, m112, m113, m120, m121, m122, m123 over Integer Ring The array is always at least 2-dimensional. So, if ``var_array`` is a single string and only a single number `n` @@ -352,7 +360,7 @@ def PolynomialRing(base_ring, *args, **kwds): Consider :: - sage: R. = PolynomialRing(QQ,2); R + sage: R. = PolynomialRing(QQ, 2); R Multivariate Polynomial Ring in x, y over Rational Field sage: f = x^2 - 2*y^2 @@ -418,9 +426,9 @@ def PolynomialRing(base_ring, *args, **kwds): The generic implementation is different in some cases:: - sage: R = PolynomialRing(GF(2), 'j', implementation="generic"); TestSuite(R).run(skip=['_test_construction', '_test_pickling']); type(R) + sage: R = PolynomialRing(GF(2), 'j', implementation="generic"); TestSuite(R).run(skip=['_test_construction', '_test_pickling']); type(R) # optional - sage.rings.finite_rings - sage: S = PolynomialRing(GF(2), 'j'); TestSuite(S).run(); type(S) + sage: S = PolynomialRing(GF(2), 'j'); TestSuite(S).run(); type(S) # optional - sage.rings.finite_rings sage: R = PolynomialRing(ZZ, 'x,y', implementation="generic"); TestSuite(R).run(skip=['_test_elements', '_test_elements_eq_transitive']); type(R) @@ -433,7 +441,7 @@ def PolynomialRing(base_ring, *args, **kwds): sage: R = PolynomialRing(ZZ, 'j', sparse=True); TestSuite(R).run(); type(R) - sage: R = PolynomialRing(GF(49), 'j', sparse=True); TestSuite(R).run(); type(R) + sage: R = PolynomialRing(GF(49), 'j', sparse=True); TestSuite(R).run(); type(R) # optional - sage.rings.finite_rings If the requested implementation is not known or not supported for @@ -443,7 +451,7 @@ def PolynomialRing(base_ring, *args, **kwds): Traceback (most recent call last): ... ValueError: unknown implementation 'Foo' for dense polynomial rings over Integer Ring - sage: R. = PolynomialRing(GF(2), implementation='GF2X', sparse=True) + sage: R. = PolynomialRing(GF(2), implementation='GF2X', sparse=True) # optional - sage.rings.finite_rings Traceback (most recent call last): ... ValueError: unknown implementation 'GF2X' for sparse polynomial rings over Finite Field of size 2 @@ -555,7 +563,7 @@ def PolynomialRing(base_ring, *args, **kwds): We run the testsuite for various polynomial rings, skipping tests that currently fail:: - sage: R. = PolynomialRing(PolynomialRing(GF(7),'k')); TestSuite(R).run(); R + sage: R. = PolynomialRing(PolynomialRing(GF(7),'k')); TestSuite(R).run(); R # optional - sage.rings.finite_rings Univariate Polynomial Ring in w over Univariate Polynomial Ring in k over Finite Field of size 7 sage: ZxNTL = PolynomialRing(ZZ, 'x', implementation='NTL'); TestSuite(ZxNTL).run(skip='_test_pickling'); ZxNTL Univariate Polynomial Ring in x over Integer Ring (using NTL) @@ -577,9 +585,9 @@ def PolynomialRing(base_ring, *args, **kwds): Multivariate Polynomial Ring in x over Rational Field sage: Q0 = PolynomialRing(QQ,"x",0); TestSuite(Q0).run(skip=['_test_elements', '_test_elements_eq_transitive', '_test_gcd_vs_xgcd', '_test_quo_rem']); Q0 Multivariate Polynomial Ring in no variables over Rational Field - sage: R = PolynomialRing(GF(2), 'j', implementation="generic"); TestSuite(R).run(skip=['_test_construction', '_test_pickling']); type(R) + sage: R = PolynomialRing(GF(2), 'j', implementation="generic"); TestSuite(R).run(skip=['_test_construction', '_test_pickling']); type(R) # optional - sage.rings.finite_rings - sage: S = PolynomialRing(GF(2), 'j'); TestSuite(S).run(); type(S) + sage: S = PolynomialRing(GF(2), 'j'); TestSuite(S).run(); type(S) # optional - sage.rings.finite_rings sage: R = PolynomialRing(ZZ, 'x,y', implementation="generic"); TestSuite(R).run(skip=['_test_elements', '_test_elements_eq_transitive']); type(R) @@ -587,7 +595,7 @@ def PolynomialRing(base_ring, *args, **kwds): sage: R = PolynomialRing(ZZ, 'j', sparse=True); TestSuite(R).run(); type(R) - sage: R = PolynomialRing(GF(49), 'j', sparse=True); TestSuite(R).run(); type(R) + sage: R = PolynomialRing(GF(49), 'j', sparse=True); TestSuite(R).run(); type(R) # optional - sage.rings.finite_rings sage: P. = PolynomialRing(RealIntervalField(2)) sage: TestSuite(P).run(skip=['_test_elements', '_test_elements_eq_transitive']) @@ -930,47 +938,46 @@ def BooleanPolynomialRing_constructor(n=None, names=None, order="lex"): - ``n`` -- number of variables (an integer > 1) - ``names`` -- names of ring variables, may be a string or list/tuple of strings - - ``order`` -- term order (default: lex) + - ``order`` -- term order (default: ``'lex'``) EXAMPLES:: - sage: R. = BooleanPolynomialRing() # indirect doctest - sage: R + sage: R. = BooleanPolynomialRing(); R # indirect doctest # optional - sage.rings.polynomial.pbori Boolean PolynomialRing in x, y, z - sage: p = x*y + x*z + y*z - sage: x*p + sage: p = x*y + x*z + y*z # optional - sage.rings.polynomial.pbori + sage: x*p # optional - sage.rings.polynomial.pbori x*y*z + x*y + x*z - sage: R.term_order() + sage: R.term_order() # optional - sage.rings.polynomial.pbori Lexicographic term order - sage: R = BooleanPolynomialRing(5,'x',order='deglex(3),deglex(2)') - sage: R.term_order() + sage: R = BooleanPolynomialRing(5, 'x', order='deglex(3),deglex(2)') # optional - sage.rings.polynomial.pbori + sage: R.term_order() # optional - sage.rings.polynomial.pbori Block term order with blocks: (Degree lexicographic term order of length 3, Degree lexicographic term order of length 2) - sage: R = BooleanPolynomialRing(3,'x',order='degneglex') - sage: R.term_order() + sage: R = BooleanPolynomialRing(3, 'x', order='degneglex') # optional - sage.rings.polynomial.pbori + sage: R.term_order() # optional - sage.rings.polynomial.pbori Degree negative lexicographic term order - sage: BooleanPolynomialRing(names=('x','y')) + sage: BooleanPolynomialRing(names=('x','y')) # optional - sage.rings.polynomial.pbori Boolean PolynomialRing in x, y - sage: BooleanPolynomialRing(names='x,y') + sage: BooleanPolynomialRing(names='x,y') # optional - sage.rings.polynomial.pbori Boolean PolynomialRing in x, y TESTS:: - sage: P. = BooleanPolynomialRing(2,order='deglex') - sage: x > y + sage: P. = BooleanPolynomialRing(2, order='deglex') # optional - sage.rings.polynomial.pbori + sage: x > y # optional - sage.rings.polynomial.pbori True - sage: P. = BooleanPolynomialRing(4,order='deglex(2),deglex(2)') - sage: x0 > x1 + sage: P. = BooleanPolynomialRing(4, order='deglex(2),deglex(2)') # optional - sage.rings.polynomial.pbori + sage: x0 > x1 # optional - sage.rings.polynomial.pbori True - sage: x2 > x3 + sage: x2 > x3 # optional - sage.rings.polynomial.pbori True """ if isinstance(n, str): diff --git a/src/sage/rings/polynomial/polynomial_ring_homomorphism.pyx b/src/sage/rings/polynomial/polynomial_ring_homomorphism.pyx index 18140a24981..4b55fa8c778 100644 --- a/src/sage/rings/polynomial/polynomial_ring_homomorphism.pyx +++ b/src/sage/rings/polynomial/polynomial_ring_homomorphism.pyx @@ -73,18 +73,18 @@ cdef class PolynomialRingHomomorphism_from_base(RingHomomorphism_from_base): sage: from sage.rings.polynomial.polynomial_ring_homomorphism import PolynomialRingHomomorphism_from_base sage: R. = ZZ[] - sage: S = GF(5)['x'] - sage: f = ZZ.hom(GF(5)) - sage: F = PolynomialRingHomomorphism_from_base(R.Hom(S), f) - sage: F(2*x, check=True) + sage: S = GF(5)['x'] # optional - sage.rings.finite_rings + sage: f = ZZ.hom(GF(5)) # optional - sage.rings.finite_rings + sage: F = PolynomialRingHomomorphism_from_base(R.Hom(S), f) # optional - sage.rings.finite_rings + sage: F(2 * x, check=True) # optional - sage.rings.finite_rings 2*x - sage: k = GF(49, 'z') - sage: A = PolynomialRing(GF(7), 'x', sparse=True) - sage: B = PolynomialRing(k, 'x', sparse=True) - sage: g = GF(7).hom(k) - sage: G = PolynomialRingHomomorphism_from_base(A.Hom(B), g) - sage: G(A.gen()^1000000, True, construct=False) + sage: k = GF(49, 'z') # optional - sage.rings.finite_rings + sage: A = PolynomialRing(GF(7), 'x', sparse=True) # optional - sage.rings.finite_rings + sage: B = PolynomialRing(k, 'x', sparse=True) # optional - sage.rings.finite_rings + sage: g = GF(7).hom(k) # optional - sage.rings.finite_rings + sage: G = PolynomialRingHomomorphism_from_base(A.Hom(B), g) # optional - sage.rings.finite_rings + sage: G(A.gen()^1000000, True, construct=False) # optional - sage.rings.finite_rings x^1000000 """ diff --git a/src/sage/rings/polynomial/polynomial_singular_interface.py b/src/sage/rings/polynomial/polynomial_singular_interface.py index 254d908a592..e00cb4ca63b 100644 --- a/src/sage/rings/polynomial/polynomial_singular_interface.py +++ b/src/sage/rings/polynomial/polynomial_singular_interface.py @@ -5,16 +5,16 @@ - Martin Albrecht (2006-04-21) - Robert Bradshaw: Re-factor to avoid multiple inheritance vs. Cython (2007-09) -- Syed Ahmad Lavasani: Added function field to _singular_init_ (2011-12-16) - Added non-prime finite fields to _singular_init_ (2012-1-22) +- Syed Ahmad Lavasani: Added function field to _singular_init_ (2011-12-16); + Added non-prime finite fields to _singular_init_ (2012-1-22) TESTS:: - sage: R = PolynomialRing(GF(2**8,'a'),10,'x', order='invlex') - sage: R == loads(dumps(R)) + sage: R = PolynomialRing(GF(2**8,'a'), 10, 'x', order='invlex') # optional - sage.rings.finite_rings + sage: R == loads(dumps(R)) # optional - sage.rings.finite_rings True - sage: P. = PolynomialRing(GF(7), 2) - sage: f = (a^3 + 2*b^2*a)^7; f + sage: P. = PolynomialRing(GF(7), 2) # optional - sage.rings.finite_rings + sage: f = (a^3 + 2*b^2*a)^7; f # optional - sage.rings.finite_rings a^21 + 2*a^7*b^14 """ @@ -61,7 +61,7 @@ def _do_singular_init_(singular, base_ring, char, _vars, order): TESTS:: sage: from sage.rings.polynomial.polynomial_singular_interface import _do_singular_init_ - sage: _do_singular_init_(singular, ZZ, 0, 'X', 'dp') + sage: _do_singular_init_(singular, ZZ, 0, 'X', 'dp') # optional - sage.libs.singular (polynomial ring, over a domain, global ordering // coefficients: ZZ // number of vars : 1 @@ -214,8 +214,8 @@ def _singular_(self, singular=singular): sage: w = var('w') - sage: R. = PolynomialRing(NumberField(w^2+1,'s')) - sage: singular(R) + sage: R. = PolynomialRing(NumberField(w^2 + 1, 's')) # optional - sage.rings.number_field + sage: singular(R) # optional - sage.rings.number_field polynomial ring, over a field, global ordering // coefficients: QQ[s]/(s^2+1) // number of vars : 1 @@ -223,8 +223,8 @@ def _singular_(self, singular=singular): // : names x // block 2 : ordering C - sage: R = PolynomialRing(GF(127), 'x', implementation="singular") - sage: singular(R) + sage: R = PolynomialRing(GF(127), 'x', implementation="singular") # optional - sage.rings.finite_rings + sage: singular(R) # optional - sage.rings.finite_rings polynomial ring, over a field, global ordering // coefficients: ZZ/127 // number of vars : 1 @@ -250,8 +250,8 @@ def _singular_(self, singular=singular): // : names x // block 2 : ordering C - sage: R = PolynomialRing(GF(127),'x') - sage: singular(R) + sage: R = PolynomialRing(GF(127), 'x') # optional - sage.rings.finite_rings + sage: singular(R) # optional - sage.rings.finite_rings polynomial ring, over a field, global ordering // coefficients: ZZ/127 // number of vars : 1 @@ -305,11 +305,11 @@ def _singular_(self, singular=singular): // : names x // block 2 : ordering C - sage: k. = FiniteField(25) - sage: R = k['x'] - sage: K = R.fraction_field() - sage: S = K['y'] - sage: singular(S) + sage: k. = FiniteField(25) # optional - sage.rings.finite_rings + sage: R = k['x'] # optional - sage.rings.finite_rings + sage: K = R.fraction_field() # optional - sage.rings.finite_rings + sage: S = K['y'] # optional - sage.rings.finite_rings + sage: singular(S) # optional - sage.rings.finite_rings polynomial ring, over a field, global ordering // coefficients: ZZ/5(x) // number of vars : 2 @@ -350,7 +350,7 @@ def _singular_init_(self, singular=singular): EXAMPLES:: - sage: PolynomialRing(QQ,'u_ba')._singular_init_() + sage: PolynomialRing(QQ,'u_ba')._singular_init_() # optional - sage.libs.singular polynomial ring, over a field, global ordering // coefficients: QQ // number of vars : 1 @@ -399,23 +399,23 @@ def can_convert_to_singular(R): Avoid non absolute number fields (see :trac:`23535`):: - sage: K. = NumberField([x^2-2,x^2-5]) - sage: can_convert_to_singular(K['s,t']) + sage: K. = NumberField([x^2 - 2, x^2 - 5]) # optional - sage.rings.number_field + sage: can_convert_to_singular(K['s,t']) # optional - sage.rings.number_field False Check for :trac:`33319`:: - sage: R. = GF((2^31-1)^3)[] - sage: R._has_singular + sage: R. = GF((2^31-1)^3)[] # optional - sage.rings.finite_rings + sage: R._has_singular # optional - sage.rings.finite_rings True - sage: R. = GF((2^31+11)^2)[] - sage: R._has_singular + sage: R. = GF((2^31+11)^2)[] # optional - sage.rings.finite_rings + sage: R._has_singular # optional - sage.rings.finite_rings False - sage: R. = GF(10^20-11)[] - sage: R._has_singular + sage: R. = GF(10^20 - 11)[] # optional - sage.rings.finite_rings + sage: R._has_singular # optional - sage.rings.finite_rings True - sage: R. = Zmod(10^20+1)[] - sage: R._has_singular + sage: R. = Zmod(10^20 + 1)[] # optional - sage.libs.pari + sage: R._has_singular # optional - sage.libs.pari True """ if R.ngens() == 0: @@ -470,25 +470,25 @@ def _singular_func(self, singular=singular): EXAMPLES:: - sage: P. = PolynomialRing(GF(7), 2) - sage: f = (a^3 + 2*b^2*a)^7; f + sage: P. = PolynomialRing(GF(7), 2) # optional - sage.rings.finite_rings + sage: f = (a^3 + 2*b^2*a)^7; f # optional - sage.rings.finite_rings a^21 + 2*a^7*b^14 - sage: h = f._singular_(); h + sage: h = f._singular_(); h # optional - sage.rings.finite_rings a^21+2*a^7*b^14 - sage: P(h) + sage: P(h) # optional - sage.rings.finite_rings a^21 + 2*a^7*b^14 - sage: P(h^20) == f^20 + sage: P(h^20) == f^20 # optional - sage.rings.finite_rings True - sage: R. = PolynomialRing(GF(7)) - sage: f = (x^3 + 2*x^2*x)^7 - sage: f + sage: R. = PolynomialRing(GF(7)) # optional - sage.rings.finite_rings + sage: f = (x^3 + 2*x^2*x)^7 # optional - sage.rings.finite_rings + sage: f # optional - sage.rings.finite_rings 3*x^21 - sage: h = f._singular_(); h + sage: h = f._singular_(); h # optional - sage.rings.finite_rings 3*x^21 - sage: R(h) + sage: R(h) # optional - sage.rings.finite_rings 3*x^21 - sage: R(h^20) == f^20 + sage: R(h^20) == f^20 # optional - sage.rings.finite_rings True """ self.parent()._singular_(singular).set_ring() # this is expensive diff --git a/src/sage/rings/polynomial/polynomial_zmod_flint.pyx b/src/sage/rings/polynomial/polynomial_zmod_flint.pyx index 2c7e23be960..6f30bf046d5 100644 --- a/src/sage/rings/polynomial/polynomial_zmod_flint.pyx +++ b/src/sage/rings/polynomial/polynomial_zmod_flint.pyx @@ -182,7 +182,7 @@ cdef class Polynomial_zmod_flint(Polynomial_template): EXAMPLES:: - sage: P.=GF(7)[] + sage: P. = GF(7)[] sage: P([2^60,0,1]) a^2 + 1 sage: P([]) @@ -329,12 +329,12 @@ cdef class Polynomial_zmod_flint(Polynomial_template): @coerce_binop def resultant(self, Polynomial_zmod_flint other): """ - Returns the resultant of self and other, which must lie in the same + Return the resultant of ``self`` and ``other``, which must lie in the same polynomial ring. INPUT: - - other -- a polynomial + - ``other`` -- a polynomial OUTPUT: an element of the base ring of the polynomial ring @@ -388,8 +388,8 @@ cdef class Polynomial_zmod_flint(Polynomial_template): INPUT: - - n -- degree - - value -- coefficient + - ``n`` -- degree + - ``value`` -- coefficient .. warning:: @@ -425,7 +425,7 @@ cdef class Polynomial_zmod_flint(Polynomial_template): EXAMPLES:: - sage: P.=GF(7)[] + sage: P. = GF(7)[] sage: a = P(range(10)); b = P(range(5, 15)) sage: a._mul_trunc_(b, 5) 4*a^4 + 6*a^3 + 2*a^2 + 5*a @@ -457,7 +457,7 @@ cdef class Polynomial_zmod_flint(Polynomial_template): EXAMPLES:: - sage: P.=GF(7)[] + sage: P. = GF(7)[] sage: b = P(range(10)); c = P(range(5, 15)) sage: b._mul_trunc_opposite(c, 10) 5*a^17 + 2*a^16 + 6*a^15 + 4*a^14 + 4*a^13 + 5*a^10 + 2*a^9 + 5*a^8 + 4*a^5 + 4*a^4 + 6*a^3 + 2*a^2 + 5*a @@ -522,7 +522,7 @@ cdef class Polynomial_zmod_flint(Polynomial_template): cpdef rational_reconstruction(self, m, n_deg=0, d_deg=0): """ - Construct a rational function n/d such that `p*d` is equivalent to `n` + Construct a rational function `n/d` such that `p*d` is equivalent to `n` modulo `m` where `p` is this polynomial. EXAMPLES:: @@ -594,7 +594,8 @@ cdef class Polynomial_zmod_flint(Polynomial_template): sage: (s^2).is_irreducible() Traceback (most recent call last): ... - NotImplementedError: checking irreducibility of polynomials over rings with composite characteristic is not implemented + NotImplementedError: checking irreducibility of polynomials + over rings with composite characteristic is not implemented TESTS:: @@ -610,7 +611,8 @@ cdef class Polynomial_zmod_flint(Polynomial_template): sage: S(2).is_irreducible() Traceback (most recent call last): ... - NotImplementedError: checking irreducibility of polynomials over rings with composite characteristic is not implemented + NotImplementedError: checking irreducibility of polynomials + over rings with composite characteristic is not implemented Test that caching works:: @@ -639,7 +641,7 @@ cdef class Polynomial_zmod_flint(Polynomial_template): def squarefree_decomposition(self): """ - Returns the squarefree decomposition of this polynomial. + Return the squarefree decomposition of this polynomial. EXAMPLES:: @@ -665,7 +667,7 @@ cdef class Polynomial_zmod_flint(Polynomial_template): def factor(self): """ - Returns the factorization of the polynomial. + Return the factorization of the polynomial. EXAMPLES:: @@ -720,13 +722,13 @@ cdef class Polynomial_zmod_flint(Polynomial_template): """ Return this polynomial divided by its leading coefficient. - Raises ValueError if the leading coefficient is not invertible in the + Raises :class:`ValueError` if the leading coefficient is not invertible in the base ring. EXAMPLES:: sage: R. = GF(5)[] - sage: (2*x^2+1).monic() + sage: (2*x^2 + 1).monic() x^2 + 3 TESTS:: @@ -748,7 +750,7 @@ cdef class Polynomial_zmod_flint(Polynomial_template): """ Return a polynomial with the coefficients of this polynomial reversed. - If an optional degree argument is given the coefficient list will be + If the optional argument ``degree`` is given, the coefficient list will be truncated or zero padded as necessary before computing the reverse. EXAMPLES:: @@ -819,7 +821,7 @@ cdef class Polynomial_zmod_flint(Polynomial_template): def revert_series(self, n): r""" - Return a polynomial `f` such that `f(self(x)) = self(f(x)) = x mod x^n`. + Return a polynomial `f` such that ``f(self(x)) = self(f(x)) = x`` (mod `x^n`). EXAMPLES:: @@ -872,7 +874,7 @@ cdef class Polynomial_zmod_flint(Polynomial_template): sage: R. = GF(127)[] sage: type(x) - sage: (x^5-3).minpoly_mod(x^3+5*x-1) + sage: (x^5 - 3).minpoly_mod(x^3 + 5*x - 1) x^3 + 34*x^2 + 125*x + 95 """ parent = self.parent() diff --git a/src/sage/rings/polynomial/polynomial_zz_pex.pyx b/src/sage/rings/polynomial/polynomial_zz_pex.pyx index 0d885e522ef..6d981a245f3 100644 --- a/src/sage/rings/polynomial/polynomial_zz_pex.pyx +++ b/src/sage/rings/polynomial/polynomial_zz_pex.pyx @@ -1,3 +1,4 @@ +# sage.doctest: optional - sage.libs.ntl sage.rings.finite_rings # distutils: libraries = NTL_LIBRARIES gmp # distutils: extra_compile_args = NTL_CFLAGS # distutils: include_dirs = NTL_INCDIR @@ -67,24 +68,24 @@ cdef inline ZZ_pE_c_to_list(ZZ_pE_c x): cdef class Polynomial_ZZ_pEX(Polynomial_template): - """ - Univariate Polynomials over GF(p^n) via NTL's ZZ_pEX. + r""" + Univariate Polynomials over `\GF{p^n}` via NTL's ``ZZ_pEX``. EXAMPLES:: - sage: K.=GF(next_prime(2**60)**3) - sage: R. = PolynomialRing(K,implementation='NTL') + sage: K. = GF(next_prime(2**60)**3) + sage: R. = PolynomialRing(K, implementation='NTL') sage: (x^3 + a*x^2 + 1) * (x + a) x^4 + 2*a*x^3 + a^2*x^2 + x + a """ def __init__(self, parent, x=None, check=True, is_gen=False, construct=False): - """ - Create a new univariate polynomials over GF(p^n). + r""" + Create a new univariate polynomials over `\GF{p^n}`. EXAMPLES:: - sage: K.=GF(next_prime(2**60)**3) - sage: R. = PolynomialRing(K,implementation='NTL') + sage: K. = GF(next_prime(2**60)**3) + sage: R. = PolynomialRing(K, implementation='NTL') sage: x^2+a x^2 + a @@ -156,14 +157,14 @@ cdef class Polynomial_ZZ_pEX(Polynomial_template): Polynomial_template.__init__(self, parent, x, check, is_gen, construct) cdef get_unsafe(self, Py_ssize_t i): - """ + r""" Return the `i`-th coefficient of ``self``. EXAMPLES:: - sage: K.=GF(next_prime(2**60)**3) - sage: R. = PolynomialRing(K,implementation='NTL') - sage: f = x^3+(2*a+1)*x+a + sage: K. = GF(next_prime(2**60)**3) + sage: R. = PolynomialRing(K, implementation='NTL') + sage: f = x^3 + (2*a+1)*x + a sage: f[0] a sage: f[1] @@ -180,7 +181,7 @@ cdef class Polynomial_ZZ_pEX(Polynomial_template): return self._parent._base(ZZ_pE_c_to_list(c_pE)) cpdef list list(self, bint copy=True): - """ + r""" Return the list of coefficients. EXAMPLES:: @@ -188,7 +189,7 @@ cdef class Polynomial_ZZ_pEX(Polynomial_template): sage: K. = GF(5^3) sage: P = PolynomialRing(K, 'x') sage: f = P.random_element(100) - sage: f.list() == [f[i] for i in range(f.degree()+1)] + sage: f.list() == [f[i] for i in range(f.degree()+1)] True sage: P.0.list() [0, 1] @@ -202,11 +203,11 @@ cdef class Polynomial_ZZ_pEX(Polynomial_template): for i in range(celement_len(&self.x, (self)._cparent))] cpdef _lmul_(self, Element left): - """ + r""" EXAMPLES:: - sage: K.=GF(next_prime(2**60)**3) - sage: R. = PolynomialRing(K,implementation='NTL') + sage: K. = GF(next_prime(2**60)**3) + sage: R. = PolynomialRing(K, implementation='NTL') sage: (2*a+1)*x # indirect doctest (2*a + 1)*x sage: x*(2*a+1) # indirect doctest @@ -223,13 +224,13 @@ cdef class Polynomial_ZZ_pEX(Polynomial_template): return r def __call__(self, *x, **kwds): - """ + r""" Evaluate polynomial at `a`. EXAMPLES:: - sage: K.=GF(next_prime(2**60)**3) - sage: R. = PolynomialRing(K,implementation='NTL') + sage: K. = GF(next_prime(2**60)**3) + sage: R. = PolynomialRing(K, implementation='NTL') sage: P = (x-u)*(x+u+1) sage: P(u) 0 @@ -243,7 +244,7 @@ cdef class Polynomial_ZZ_pEX(Polynomial_template): sage: F. = GF(4) sage: P. = F[] sage: p = y^4 + x*y^3 + y^2 + (x + 1)*y + x + 1 - sage: SR(p) + sage: SR(p) # optional - sage.symbolic Traceback (most recent call last): ... TypeError: positive characteristic not allowed in symbolic computations @@ -288,24 +289,24 @@ cdef class Polynomial_ZZ_pEX(Polynomial_template): return K(ZZ_pE_c_to_list(c_b)) def resultant(self, other): - """ - Returns the resultant of self and other, which must lie in the same + r""" + Return the resultant of ``self`` and ``other``, which must lie in the same polynomial ring. INPUT: - :argument other: a polynomial + - ``other`` -- a polynomial OUTPUT: an element of the base ring of the polynomial ring EXAMPLES:: - sage: K.=GF(next_prime(2**60)**3) - sage: R. = PolynomialRing(K,implementation='NTL') - sage: f=(x-a)*(x-a**2)*(x+1) - sage: g=(x-a**3)*(x-a**4)*(x+a) + sage: K. = GF(next_prime(2**60)**3) + sage: R. = PolynomialRing(K, implementation='NTL') + sage: f = (x-a)*(x-a**2)*(x+1) + sage: g = (x-a**3)*(x-a**4)*(x+a) sage: r = f.resultant(g) - sage: r == prod(u-v for (u,eu) in f.roots() for (v,ev) in g.roots()) + sage: r == prod(u - v for (u,eu) in f.roots() for (v,ev) in g.roots()) True """ cdef ZZ_pE_c r @@ -320,23 +321,24 @@ cdef class Polynomial_ZZ_pEX(Polynomial_template): return K(K.polynomial_ring()(ZZ_pE_c_to_list(r))) def is_irreducible(self, algorithm="fast_when_false", iter=1): - """ - Returns `True` precisely when self is irreducible over its base ring. + r""" + Return ``True`` precisely when ``self`` is irreducible over its base ring. INPUT: - :argument algorithm: a string (default "fast_when_false"), - there are 3 available algorithms: - "fast_when_true", "fast_when_false" and "probabilistic". - :argument iter: (default: 1) if the algorithm is "probabilistic" - defines the number of iterations. The error probability is bounded - by `q**-iter` for polynomials in `GF(q)[x]`. + - ``algorithm`` -- a string (default ``"fast_when_false"``), + there are 3 available algorithms: + ``"fast_when_true"``, ``"fast_when_false"``, and ``"probabilistic".`` + + - ``iter`` -- (default: 1) if the algorithm is ``"probabilistic"``, + defines the number of iterations. The error probability is bounded + by `q^{\text{-iter}}` for polynomials in `\GF{q}[x]`. EXAMPLES:: - sage: K.=GF(next_prime(2**60)**3) - sage: R. = PolynomialRing(K,implementation='NTL') - sage: P = x^3+(2-a)*x+1 + sage: K. = GF(next_prime(2**60)**3) + sage: R. = PolynomialRing(K, implementation='NTL') + sage: P = x^3 + (2-a)*x + 1 sage: P.is_irreducible(algorithm="fast_when_false") True sage: P.is_irreducible(algorithm="fast_when_true") @@ -350,7 +352,7 @@ cdef class Polynomial_ZZ_pEX(Polynomial_template): False sage: Q.is_irreducible(algorithm="probabilistic") False - """ + """ self._parent._modulus.restore() if algorithm=="fast_when_false": sig_on() @@ -413,20 +415,20 @@ cdef class Polynomial_ZZ_pEX(Polynomial_template): return r cpdef _richcmp_(self, other, int op): - """ + r""" EXAMPLES:: - sage: K.=GF(next_prime(2**60)**3) - sage: R. = PolynomialRing(K,implementation='NTL') - sage: P1 = (a**2+a+1)*x^2+a*x+1 - sage: P2 = ( a+1)*x^2+a*x+1 + sage: K. = GF(next_prime(2**60)**3) + sage: R. = PolynomialRing(K, implementation='NTL') + sage: P1 = (a**2+a+1)*x^2 + a*x + 1 + sage: P2 = ( a+1)*x^2 + a*x + 1 sage: P1 < P2 # indirect doctests False TESTS:: - sage: P3 = (a**2+a+1)*x^2+ x+1 - sage: P4 = x+1 + sage: P3 = (a**2+a+1)*x^2 + x + 1 + sage: P4 = x + 1 sage: P1 < P3 False sage: P1 < P4 @@ -441,11 +443,11 @@ cdef class Polynomial_ZZ_pEX(Polynomial_template): return Polynomial._richcmp_(self, other, op) def shift(self, int n): - """ + r""" EXAMPLES:: - sage: K.=GF(next_prime(2**60)**3) - sage: R. = PolynomialRing(K,implementation='NTL') + sage: K. = GF(next_prime(2**60)**3) + sage: R. = PolynomialRing(K, implementation='NTL') sage: f = x^3 + x^2 + 1 sage: f.shift(1) x^4 + x^3 + x @@ -462,11 +464,11 @@ cdef class Polynomial_ZZ_pEX(Polynomial_template): return r def __lshift__(self, int n): - """ + r""" EXAMPLES:: - sage: K.=GF(next_prime(2**60)**3) - sage: R. = PolynomialRing(K,implementation='NTL') + sage: K. = GF(next_prime(2**60)**3) + sage: R. = PolynomialRing(K, implementation='NTL') sage: f = x^3 + x^2 + 1 sage: f << 1 x^4 + x^3 + x @@ -476,11 +478,11 @@ cdef class Polynomial_ZZ_pEX(Polynomial_template): return self.shift(n) def __rshift__(self, int n): - """ + r""" EXAMPLES:: - sage: K.=GF(next_prime(2**60)**3) - sage: R. = PolynomialRing(K,implementation='NTL') + sage: K. = GF(next_prime(2**60)**3) + sage: R. = PolynomialRing(K, implementation='NTL') sage: f = x^3 + x^2 + 1 sage: f >> 1 x^2 + x diff --git a/src/sage/rings/polynomial/real_roots.pyx b/src/sage/rings/polynomial/real_roots.pyx index 94fa0b84d40..3422efb7c6f 100644 --- a/src/sage/rings/polynomial/real_roots.pyx +++ b/src/sage/rings/polynomial/real_roots.pyx @@ -3129,7 +3129,7 @@ cdef class ocean: def all_done(self): """ - Returns true iff all islands are known to contain exactly one root. + Return ``True`` iff all islands are known to contain exactly one root. EXAMPLES:: diff --git a/src/sage/rings/polynomial/skew_polynomial_finite_order.pyx b/src/sage/rings/polynomial/skew_polynomial_finite_order.pyx index f3ff0617484..7acfec8c97f 100644 --- a/src/sage/rings/polynomial/skew_polynomial_finite_order.pyx +++ b/src/sage/rings/polynomial/skew_polynomial_finite_order.pyx @@ -1,3 +1,4 @@ +# sage.doctest: optional - sage.rings.finite_rings r""" Univariate dense skew polynomials over a field with a finite order automorphism diff --git a/src/sage/rings/polynomial/skew_polynomial_ring.py b/src/sage/rings/polynomial/skew_polynomial_ring.py index a71a217719b..9f499430d59 100644 --- a/src/sage/rings/polynomial/skew_polynomial_ring.py +++ b/src/sage/rings/polynomial/skew_polynomial_ring.py @@ -78,7 +78,7 @@ def _base_ring_to_fraction_field(S): sage: from sage.rings.polynomial.skew_polynomial_ring import _base_ring_to_fraction_field sage: R. = ZZ[] - sage: sigma = R.hom([t+1]) + sage: sigma = R.hom([t + 1]) sage: S. = R['x', sigma] sage: _base_ring_to_fraction_field(S) Ore Polynomial Ring in x over Fraction Field of Univariate Polynomial Ring in t over Integer Ring twisted by t |--> t + 1 @@ -117,11 +117,11 @@ def _minimal_vanishing_polynomial(R, eval_pts): EXAMPLES:: sage: from sage.rings.polynomial.skew_polynomial_ring import _minimal_vanishing_polynomial - sage: k. = GF(5^3) - sage: Frob = k.frobenius_endomorphism() - sage: S. = k['x',Frob] - sage: eval_pts = [1, t, t^2] - sage: b = _minimal_vanishing_polynomial(S, eval_pts); b + sage: k. = GF(5^3) # optional - sage.rings.finite_rings + sage: Frob = k.frobenius_endomorphism() # optional - sage.rings.finite_rings + sage: S. = k['x',Frob] # optional - sage.rings.finite_rings + sage: eval_pts = [1, t, t^2] # optional - sage.rings.finite_rings + sage: b = _minimal_vanishing_polynomial(S, eval_pts); b # optional - sage.rings.finite_rings doctest:...: FutureWarning: This class/method/function is marked as experimental. It, its functionality or its interface might change without a formal deprecation. See https://github.com/sagemath/sage/issues/13215 for details. @@ -172,23 +172,23 @@ def _lagrange_polynomial(R, eval_pts, values): EXAMPLES:: sage: from sage.rings.polynomial.skew_polynomial_ring import _lagrange_polynomial - sage: k. = GF(5^3) - sage: Frob = k.frobenius_endomorphism() - sage: S. = k['x',Frob] - sage: eval_pts = [ t , t^2 ] - sage: values = [ 3*t^2 + 4*t + 4 , 4*t ] - sage: d = _lagrange_polynomial(S, eval_pts, values); d + sage: k. = GF(5^3) # optional - sage.rings.finite_rings + sage: Frob = k.frobenius_endomorphism() # optional - sage.rings.finite_rings + sage: S. = k['x', Frob] # optional - sage.rings.finite_rings + sage: eval_pts = [t , t^2] # optional - sage.rings.finite_rings + sage: values = [3*t^2 + 4*t + 4, 4*t] # optional - sage.rings.finite_rings + sage: d = _lagrange_polynomial(S, eval_pts, values); d # optional - sage.rings.finite_rings x + t - sage: d.multi_point_evaluation(eval_pts) == values + sage: d.multi_point_evaluation(eval_pts) == values # optional - sage.rings.finite_rings True The following restrictions are impossible to satisfy because the evaluation points are linearly dependent over the fixed field of the twisting morphism, and the corresponding values do not match:: - sage: eval_pts = [ t, 2*t ] - sage: values = [ 1, 3 ] - sage: _lagrange_polynomial(S, eval_pts, values) + sage: eval_pts = [t, 2*t] # optional - sage.rings.finite_rings + sage: values = [1, 3] # optional - sage.rings.finite_rings + sage: _lagrange_polynomial(S, eval_pts, values) # optional - sage.rings.finite_rings Traceback (most recent call last): ... ValueError: the given evaluation points are linearly dependent over the fixed field of the twisting morphism, @@ -240,7 +240,7 @@ def __init__(self, base_ring, morphism, derivation, name, sparse, category=None) EXAMPLES:: sage: R. = ZZ[] - sage: sigma = R.hom([t+1]) + sage: sigma = R.hom([t + 1]) sage: S. = SkewPolynomialRing(R,sigma) sage: S.category() Category of algebras over Univariate Polynomial Ring in t over Integer Ring @@ -275,26 +275,26 @@ def minimal_vanishing_polynomial(self, eval_pts): EXAMPLES:: - sage: k. = GF(5^3) - sage: Frob = k.frobenius_endomorphism() - sage: S. = k['x',Frob] - sage: eval_pts = [1, t, t^2] - sage: b = S.minimal_vanishing_polynomial(eval_pts); b + sage: k. = GF(5^3) # optional - sage.rings.finite_rings + sage: Frob = k.frobenius_endomorphism() # optional - sage.rings.finite_rings + sage: S. = k['x', Frob] # optional - sage.rings.finite_rings + sage: eval_pts = [1, t, t^2] # optional - sage.rings.finite_rings + sage: b = S.minimal_vanishing_polynomial(eval_pts); b # optional - sage.rings.finite_rings x^3 + 4 The minimal vanishing polynomial evaluates to 0 at each of the evaluation points:: - sage: eval = b.multi_point_evaluation(eval_pts); eval + sage: eval = b.multi_point_evaluation(eval_pts); eval # optional - sage.rings.finite_rings [0, 0, 0] If the evaluation points are linearly dependent over the fixed field of the twisting morphism, then the returned polynomial has lower degree than the number of evaluation points:: - sage: S.minimal_vanishing_polynomial([t]) + sage: S.minimal_vanishing_polynomial([t]) # optional - sage.rings.finite_rings x + 3*t^2 + 3*t - sage: S.minimal_vanishing_polynomial([t, 3*t]) + sage: S.minimal_vanishing_polynomial([t, 3*t]) # optional - sage.rings.finite_rings x + 3*t^2 + 3*t """ return _minimal_vanishing_polynomial(_base_ring_to_fraction_field(self), eval_pts) @@ -328,26 +328,27 @@ def lagrange_polynomial(self, points): EXAMPLES:: - sage: k. = GF(5^3) - sage: Frob = k.frobenius_endomorphism() - sage: S. = k['x',Frob] - sage: points = [(t, 3*t^2 + 4*t + 4), (t^2, 4*t)] - sage: d = S.lagrange_polynomial(points); d + sage: k. = GF(5^3) # optional - sage.rings.finite_rings + sage: Frob = k.frobenius_endomorphism() # optional - sage.rings.finite_rings + sage: S. = k['x', Frob] # optional - sage.rings.finite_rings + sage: points = [(t, 3*t^2 + 4*t + 4), (t^2, 4*t)] # optional - sage.rings.finite_rings + sage: d = S.lagrange_polynomial(points); d # optional - sage.rings.finite_rings x + t sage: R. = ZZ[] - sage: sigma = R.hom([t+1]) + sage: sigma = R.hom([t + 1]) sage: T. = R['x', sigma] - sage: points = [ (1, t^2 + 3*t + 4), (t, 2*t^2 + 3*t + 1), (t^2, t^2 + 3*t + 4) ] + sage: points = [(1, t^2 + 3*t + 4), (t, 2*t^2 + 3*t + 1), (t^2, t^2 + 3*t + 4)] sage: p = T.lagrange_polynomial(points); p - ((-t^4 - 2*t - 3)/-2)*x^2 + (-t^4 - t^3 - t^2 - 3*t - 2)*x + (-t^4 - 2*t^3 - 4*t^2 - 10*t - 9)/-2 - sage: p.multi_point_evaluation([1, t, t^2]) == [ t^2 + 3*t + 4, 2*t^2 + 3*t + 1, t^2 + 3*t + 4 ] + ((-t^4 - 2*t - 3)/-2)*x^2 + (-t^4 - t^3 - t^2 - 3*t - 2)*x + + (-t^4 - 2*t^3 - 4*t^2 - 10*t - 9)/-2 + sage: p.multi_point_evaluation([1, t, t^2]) == [t^2 + 3*t + 4, 2*t^2 + 3*t + 1, t^2 + 3*t + 4] True If the `x_i` are linearly dependent over the fixed field of ``self.twisting_morphism()``, then an error is raised:: - sage: T.lagrange_polynomial([ (t, 1), (2*t, 3) ]) + sage: T.lagrange_polynomial([(t, 1), (2*t, 3)]) Traceback (most recent call last): ... ValueError: the given evaluation points are linearly dependent over the fixed field of the twisting morphism, @@ -378,12 +379,12 @@ class SectionSkewPolynomialCenterInjection(Section): TESTS:: - sage: k. = GF(5^3) - sage: S. = SkewPolynomialRing(k, k.frobenius_endomorphism()) - sage: Z = S.center() - sage: iota = S.convert_map_from(Z) - sage: sigma = iota.section() - sage: TestSuite(sigma).run(skip=['_test_category']) + sage: k. = GF(5^3) # optional - sage.rings.finite_rings + sage: S. = SkewPolynomialRing(k, k.frobenius_endomorphism()) # optional - sage.rings.finite_rings + sage: Z = S.center() # optional - sage.rings.finite_rings + sage: iota = S.convert_map_from(Z) # optional - sage.rings.finite_rings + sage: sigma = iota.section() # optional - sage.rings.finite_rings + sage: TestSuite(sigma).run(skip=['_test_category']) # optional - sage.rings.finite_rings """ def _call_(self, x): r""" @@ -391,14 +392,14 @@ def _call_(self, x): EXAMPLES:: - sage: k. = GF(5^3) - sage: S. = SkewPolynomialRing(k, k.frobenius_endomorphism()) - sage: Z = S.center() - sage: iota = S.convert_map_from(Z) - sage: sigma = iota.section() - sage: sigma(x^3) + sage: k. = GF(5^3) # optional - sage.rings.finite_rings + sage: S. = SkewPolynomialRing(k, k.frobenius_endomorphism()) # optional - sage.rings.finite_rings + sage: Z = S.center() # optional - sage.rings.finite_rings + sage: iota = S.convert_map_from(Z) # optional - sage.rings.finite_rings + sage: sigma = iota.section() # optional - sage.rings.finite_rings + sage: sigma(x^3) # optional - sage.rings.finite_rings z - sage: sigma(x^2) + sage: sigma(x^2) # optional - sage.rings.finite_rings Traceback (most recent call last): ... ValueError: x^2 is not in the center @@ -425,18 +426,18 @@ def _richcmp_(self, right, op): TESTS:: - sage: k. = GF(5^3) - sage: S. = SkewPolynomialRing(k, k.frobenius_endomorphism()) - sage: Z = S.center() - sage: iota = S.convert_map_from(Z) - sage: sigma = iota.section() + sage: k. = GF(5^3) # optional - sage.rings.finite_rings + sage: S. = SkewPolynomialRing(k, k.frobenius_endomorphism()) # optional - sage.rings.finite_rings + sage: Z = S.center() # optional - sage.rings.finite_rings + sage: iota = S.convert_map_from(Z) # optional - sage.rings.finite_rings + sage: sigma = iota.section() # optional - sage.rings.finite_rings - sage: s = loads(dumps(sigma)) - sage: s == sigma + sage: s = loads(dumps(sigma)) # optional - sage.rings.finite_rings + sage: s == sigma # optional - sage.rings.finite_rings True - sage: s != sigma + sage: s != sigma # optional - sage.rings.finite_rings False - sage: s is sigma + sage: s is sigma # optional - sage.rings.finite_rings False """ if op == op_EQ: @@ -453,11 +454,11 @@ class SkewPolynomialCenterInjection(RingHomomorphism): TESTS:: - sage: k. = GF(5^3) - sage: S. = SkewPolynomialRing(k, k.frobenius_endomorphism()) - sage: Z = S.center() - sage: iota = S.convert_map_from(Z) - sage: TestSuite(iota).run(skip=['_test_category']) + sage: k. = GF(5^3) # optional - sage.rings.finite_rings + sage: S. = SkewPolynomialRing(k, k.frobenius_endomorphism()) # optional - sage.rings.finite_rings + sage: Z = S.center() # optional - sage.rings.finite_rings + sage: iota = S.convert_map_from(Z) # optional - sage.rings.finite_rings + sage: TestSuite(iota).run(skip=['_test_category']) # optional - sage.rings.finite_rings """ def __init__(self, domain, codomain, embed, order): r""" @@ -465,10 +466,10 @@ def __init__(self, domain, codomain, embed, order): EXAMPLES:: - sage: k. = GF(5^3) - sage: S. = SkewPolynomialRing(k, k.frobenius_endomorphism()) - sage: Z = S.center() - sage: S.convert_map_from(Z) # indirect doctest + sage: k. = GF(5^3) # optional - sage.rings.finite_rings + sage: S. = SkewPolynomialRing(k, k.frobenius_endomorphism()) # optional - sage.rings.finite_rings + sage: Z = S.center() # optional - sage.rings.finite_rings + sage: S.convert_map_from(Z) # indirect doctest # optional - sage.rings.finite_rings Embedding of the center of Ore Polynomial Ring in x over Finite Field in a of size 5^3 twisted by a |--> a^5 into this ring """ RingHomomorphism.__init__(self, Hom(domain, codomain)) @@ -483,13 +484,13 @@ def _repr_(self): EXAMPLES:: - sage: k. = GF(5^3) - sage: S. = SkewPolynomialRing(k, k.frobenius_endomorphism()) - sage: Z = S.center() - sage: iota = S.convert_map_from(Z) - sage: iota + sage: k. = GF(5^3) # optional - sage.rings.finite_rings + sage: S. = SkewPolynomialRing(k, k.frobenius_endomorphism()) # optional - sage.rings.finite_rings + sage: Z = S.center() # optional - sage.rings.finite_rings + sage: iota = S.convert_map_from(Z) # optional - sage.rings.finite_rings + sage: iota # optional - sage.rings.finite_rings Embedding of the center of Ore Polynomial Ring in x over Finite Field in a of size 5^3 twisted by a |--> a^5 into this ring - sage: iota._repr_() + sage: iota._repr_() # optional - sage.rings.finite_rings 'Embedding of the center of Ore Polynomial Ring in x over Finite Field in a of size 5^3 twisted by a |--> a^5 into this ring' """ return "Embedding of the center of %s into this ring" % self._codomain @@ -500,12 +501,12 @@ def _call_(self, x): TESTS:: - sage: k. = GF(5^3) - sage: S. = SkewPolynomialRing(k, k.frobenius_endomorphism()) - sage: Z. = S.center() - sage: iota = S.convert_map_from(Z) + sage: k. = GF(5^3) # optional - sage.rings.finite_rings + sage: S. = SkewPolynomialRing(k, k.frobenius_endomorphism()) # optional - sage.rings.finite_rings + sage: Z. = S.center() # optional - sage.rings.finite_rings + sage: iota = S.convert_map_from(Z) # optional - sage.rings.finite_rings - sage: iota(z) + sage: iota(z) # optional - sage.rings.finite_rings x^3 """ k = self._codomain.base_ring() @@ -521,17 +522,17 @@ def _richcmp_(self, right, op): TESTS:: - sage: k. = GF(5^3) - sage: S. = SkewPolynomialRing(k, k.frobenius_endomorphism()) - sage: Z = S.center() - sage: iota = S.convert_map_from(Z) + sage: k. = GF(5^3) # optional - sage.rings.finite_rings + sage: S. = SkewPolynomialRing(k, k.frobenius_endomorphism()) # optional - sage.rings.finite_rings + sage: Z = S.center() # optional - sage.rings.finite_rings + sage: iota = S.convert_map_from(Z) # optional - sage.rings.finite_rings - sage: i = loads(dumps(iota)) - sage: i == iota + sage: i = loads(dumps(iota)) # optional - sage.rings.finite_rings + sage: i == iota # optional - sage.rings.finite_rings True - sage: i != iota + sage: i != iota # optional - sage.rings.finite_rings False - sage: i is iota + sage: i is iota # optional - sage.rings.finite_rings False """ if op == op_EQ: @@ -546,12 +547,12 @@ def section(self): EXAMPLES:: - sage: k. = GF(5^3) - sage: S. = SkewPolynomialRing(k, k.frobenius_endomorphism()) - sage: Z = S.center() - sage: iota = S.convert_map_from(Z) - sage: sigma = iota.section() - sage: sigma(x^3) + sage: k. = GF(5^3) # optional - sage.rings.finite_rings + sage: S. = SkewPolynomialRing(k, k.frobenius_endomorphism()) # optional - sage.rings.finite_rings + sage: Z = S.center() # optional - sage.rings.finite_rings + sage: iota = S.convert_map_from(Z) # optional - sage.rings.finite_rings + sage: sigma = iota.section() # optional - sage.rings.finite_rings + sage: sigma(x^3) # optional - sage.rings.finite_rings z """ return self._section @@ -573,26 +574,26 @@ def __init__(self, base_ring, morphism, derivation, name, sparse, category=None) TESTS:: - sage: k. = GF(5^3) - sage: Frob = k.frobenius_endomorphism() - sage: S. = k['x', Frob]; S + sage: k. = GF(5^3) # optional - sage.rings.finite_rings + sage: Frob = k.frobenius_endomorphism() # optional - sage.rings.finite_rings + sage: S. = k['x', Frob]; S # optional - sage.rings.finite_rings Ore Polynomial Ring in x over Finite Field in t of size 5^3 twisted by t |--> t^5 - sage: S.category() + sage: S.category() # optional - sage.rings.finite_rings Category of algebras over Finite Field in t of size 5^3 - sage: TestSuite(S).run() + sage: TestSuite(S).run() # optional - sage.rings.finite_rings We check that a call to the method :meth:`sage.rings.polynomial.skew_polynomial_finite_order.SkewPolynomial_finite_order.is_central` does not affect the behaviour of default central variable names:: - sage: k. = GF(7^4) - sage: phi = k.frobenius_endomorphism() - sage: S. = k['x', phi] - sage: (x^4).is_central() + sage: k. = GF(7^4) # optional - sage.rings.finite_rings + sage: phi = k.frobenius_endomorphism() # optional - sage.rings.finite_rings + sage: S. = k['x', phi] # optional - sage.rings.finite_rings + sage: (x^4).is_central() # optional - sage.rings.finite_rings True - sage: Z. = S.center() - sage: S.center() is Z + sage: Z. = S.center() # optional - sage.rings.finite_rings + sage: S.center() is Z # optional - sage.rings.finite_rings True """ if self.Element is None: @@ -638,55 +639,57 @@ def center(self, name=None, names=None, default=False): EXAMPLES:: - sage: k. = GF(5^3) - sage: Frob = k.frobenius_endomorphism() - sage: S. = k['x',Frob]; S - Ore Polynomial Ring in x over Finite Field in t of size 5^3 twisted by t |--> t^5 + sage: k. = GF(5^3) # optional - sage.rings.finite_rings + sage: Frob = k.frobenius_endomorphism() # optional - sage.rings.finite_rings + sage: S. = k['x',Frob]; S # optional - sage.rings.finite_rings + Ore Polynomial Ring in x over Finite Field in t of size 5^3 + twisted by t |--> t^5 - sage: Z = S.center(); Z + sage: Z = S.center(); Z # optional - sage.rings.finite_rings Univariate Polynomial Ring in z over Finite Field of size 5 - sage: Z.gen() + sage: Z.gen() # optional - sage.rings.finite_rings z We can pass in another variable name:: - sage: S.center(name='y') + sage: S.center(name='y') # optional - sage.rings.finite_rings Univariate Polynomial Ring in y over Finite Field of size 5 or use the bracket notation:: - sage: Zy. = S.center(); Zy + sage: Zy. = S.center(); Zy # optional - sage.rings.finite_rings Univariate Polynomial Ring in y over Finite Field of size 5 - sage: y.parent() is Zy + sage: y.parent() is Zy # optional - sage.rings.finite_rings True A coercion map from the center to the skew polynomial ring is set:: - sage: S.has_coerce_map_from(Zy) + sage: S.has_coerce_map_from(Zy) # optional - sage.rings.finite_rings True - sage: P = y + x; P + sage: P = y + x; P # optional - sage.rings.finite_rings x^3 + x - sage: P.parent() - Ore Polynomial Ring in x over Finite Field in t of size 5^3 twisted by t |--> t^5 - sage: P.parent() is S + sage: P.parent() # optional - sage.rings.finite_rings + Ore Polynomial Ring in x over Finite Field in t of size 5^3 + twisted by t |--> t^5 + sage: P.parent() is S # optional - sage.rings.finite_rings True together with a conversion map in the reverse direction:: - sage: Zy(x^6 + 2*x^3 + 3) + sage: Zy(x^6 + 2*x^3 + 3) # optional - sage.rings.finite_rings y^2 + 2*y + 3 - sage: Zy(x^2) + sage: Zy(x^2) # optional - sage.rings.finite_rings Traceback (most recent call last): ... ValueError: x^2 is not in the center Two different skew polynomial rings can share the same center:: - sage: S1. = k['x1', Frob] - sage: S2. = k['x2', Frob] - sage: S1.center() is S2.center() + sage: S1. = k['x1', Frob] # optional - sage.rings.finite_rings + sage: S2. = k['x2', Frob] # optional - sage.rings.finite_rings + sage: S1.center() is S2.center() # optional - sage.rings.finite_rings True .. RUBRIC:: About the default name of the central variable @@ -696,32 +699,32 @@ def center(self, name=None, names=None, default=False): However, a variable name is given the first time this method is called, the given name become the default for the next calls:: - sage: K. = GF(11^3) - sage: phi = K.frobenius_endomorphism() - sage: A. = K['X', phi] + sage: K. = GF(11^3) # optional - sage.rings.finite_rings + sage: phi = K.frobenius_endomorphism() # optional - sage.rings.finite_rings + sage: A. = K['X', phi] # optional - sage.rings.finite_rings - sage: C. = A.center() # first call - sage: C + sage: C. = A.center() # first call # optional - sage.rings.finite_rings + sage: C # optional - sage.rings.finite_rings Univariate Polynomial Ring in u over Finite Field of size 11 - sage: A.center() # second call: the variable name is still u + sage: A.center() # second call: the variable name is still u # optional - sage.rings.finite_rings Univariate Polynomial Ring in u over Finite Field of size 11 - sage: A.center() is C + sage: A.center() is C # optional - sage.rings.finite_rings True We can update the default variable name by passing in the argument ``default=True``:: - sage: D. = A.center(default=True) - sage: D + sage: D. = A.center(default=True) # optional - sage.rings.finite_rings + sage: D # optional - sage.rings.finite_rings Univariate Polynomial Ring in v over Finite Field of size 11 - sage: A.center() + sage: A.center() # optional - sage.rings.finite_rings Univariate Polynomial Ring in v over Finite Field of size 11 - sage: A.center() is D + sage: A.center() is D # optional - sage.rings.finite_rings True TESTS:: - sage: C. = S.center() + sage: C. = S.center() # optional - sage.rings.finite_rings Traceback (most recent call last): ... IndexError: the number of names must equal the number of generators @@ -793,9 +796,9 @@ def __init__(self, base_ring, morphism, derivation, names, sparse, category=None EXAMPLES:: - sage: k. = GF(5^3) - sage: Frob = k.frobenius_endomorphism() - sage: T. = k['x', Frob]; T + sage: k. = GF(5^3) # optional - sage.rings.finite_rings + sage: Frob = k.frobenius_endomorphism() # optional - sage.rings.finite_rings + sage: T. = k['x', Frob]; T # optional - sage.rings.finite_rings Ore Polynomial Ring in x over Finite Field in t of size 5^3 twisted by t |--> t^5 """ if self.Element is None: @@ -820,21 +823,21 @@ def _new_retraction_map(self, seed=None): TESTS:: - sage: k. = GF(11^4) - sage: Frob = k.frobenius_endomorphism() - sage: S. = k['x', Frob] + sage: k. = GF(11^4) # optional - sage.rings.finite_rings + sage: Frob = k.frobenius_endomorphism() # optional - sage.rings.finite_rings + sage: S. = k['x', Frob] # optional - sage.rings.finite_rings - sage: S._new_retraction_map() - sage: S._matrix_retraction # random + sage: S._new_retraction_map() # optional - sage.rings.finite_rings + sage: S._matrix_retraction # random # optional - sage.rings.finite_rings [ 9 4 10 4] We can specify a seed:: - sage: S._new_retraction_map(seed=a) - sage: S._matrix_retraction + sage: S._new_retraction_map(seed=a) # optional - sage.rings.finite_rings + sage: S._matrix_retraction # optional - sage.rings.finite_rings [ 0 6 3 10] - sage: S._new_retraction_map(seed=a) - sage: S._matrix_retraction + sage: S._new_retraction_map(seed=a) # optional - sage.rings.finite_rings + sage: S._matrix_retraction # optional - sage.rings.finite_rings [ 0 6 3 10] """ k = self.base_ring() @@ -872,27 +875,27 @@ def _retraction(self, x, newmap=False, seed=None): TESTS:: - sage: k. = GF(11^4) - sage: Frob = k.frobenius_endomorphism() - sage: S. = k['x', Frob] + sage: k. = GF(11^4) # optional - sage.rings.finite_rings + sage: Frob = k.frobenius_endomorphism() # optional - sage.rings.finite_rings + sage: S. = k['x', Frob] # optional - sage.rings.finite_rings - sage: S._retraction(a) # random + sage: S._retraction(a) # random # optional - sage.rings.finite_rings 6 Note that a retraction map has been automatically created:: - sage: S._matrix_retraction # random + sage: S._matrix_retraction # random # optional - sage.rings.finite_rings [ 0 6 3 10] If we call again the method :meth:`_retraction`, the same retraction map is used:: - sage: S._retraction(a) # random + sage: S._retraction(a) # random # optional - sage.rings.finite_rings 6 We can specify a seed:: - sage: S._retraction(a^2, seed=a) # random + sage: S._retraction(a^2, seed=a) # random # optional - sage.rings.finite_rings 10 """ # Better to return the retraction map but more difficult diff --git a/src/sage/rings/polynomial/symmetric_ideal.py b/src/sage/rings/polynomial/symmetric_ideal.py index dfe66e9f2f5..4905e5d87a6 100644 --- a/src/sage/rings/polynomial/symmetric_ideal.py +++ b/src/sage/rings/polynomial/symmetric_ideal.py @@ -23,12 +23,13 @@ Note that ``I`` is not a symmetric Groebner basis:: - sage: G = R*I.groebner_basis() - sage: G - Symmetric Ideal (x_1^2 + x_1, x_2 - x_1) of Infinite polynomial ring in x over Rational Field - sage: Q = R.quotient(G) - sage: p = x[3]*x[1]+x[2]^2+3 - sage: Q(p) + sage: G = R * I.groebner_basis() # optional - sage.combinat + sage: G # optional - sage.combinat + Symmetric Ideal (x_1^2 + x_1, x_2 - x_1) of + Infinite polynomial ring in x over Rational Field + sage: Q = R.quotient(G) # optional - sage.combinat + sage: p = x[3]*x[1] + x[2]^2 + 3 # optional - sage.combinat + sage: Q(p) # optional - sage.combinat -2*x_1 + 3 By the second generator of ``G``, variable `x_n` is equal to `x_1` for @@ -36,7 +37,7 @@ equal to `x_1` in ``Q``. Indeed, we have :: - sage: Q(p)*x[2] == Q(p)*x[1]*x[3]*x[5] + sage: Q(p)*x[2] == Q(p)*x[1]*x[3]*x[5] # optional - sage.combinat True """ @@ -109,7 +110,7 @@ class SymmetricIdeal(Ideal_generic): EXAMPLES:: sage: X. = InfinitePolynomialRing(QQ) - sage: I = [x[1]*y[2]*y[1] + 2*x[1]*y[2]]*X + sage: I = [x[1]*y[2]*y[1] + 2*x[1]*y[2]] * X sage: I == loads(dumps(I)) True sage: latex(I) @@ -117,25 +118,26 @@ class SymmetricIdeal(Ideal_generic): The default ordering is lexicographic. We now compute a Groebner basis:: - sage: J = I.groebner_basis() ; J # about 3 seconds - [x_1*y_2*y_1 + 2*x_1*y_2, x_2*y_2*y_1 + 2*x_2*y_1, x_2*x_1*y_1^2 + 2*x_2*x_1*y_1, x_2*x_1*y_2 - x_2*x_1*y_1] + sage: J = I.groebner_basis(); J # about 3 seconds # optional - sage.combinat + [x_1*y_2*y_1 + 2*x_1*y_2, x_2*y_2*y_1 + 2*x_2*y_1, + x_2*x_1*y_1^2 + 2*x_2*x_1*y_1, x_2*x_1*y_2 - x_2*x_1*y_1] Note that even though the symmetric ideal can be generated by a single polynomial, its reduced symmetric Groebner basis comprises four elements. Ideal membership in ``I`` can now be tested by commuting symmetric reduction modulo ``J``:: - sage: I.reduce(J) + sage: I.reduce(J) # optional - sage.combinat Symmetric Ideal (0) of Infinite polynomial ring in x, y over Rational Field The Groebner basis is not point-wise invariant under permutation:: - sage: P=Permutation([2, 1]) - sage: J[2] + sage: P = Permutation([2, 1]) # optional - sage.combinat + sage: J[2] # optional - sage.combinat x_2*x_1*y_1^2 + 2*x_2*x_1*y_1 - sage: J[2]^P + sage: J[2]^P # optional - sage.combinat x_2*x_1*y_2^2 + 2*x_2*x_1*y_2 - sage: J[2]^P in J + sage: J[2]^P in J # optional - sage.combinat False However, any element of ``J`` has symmetric reduction zero even @@ -143,13 +145,13 @@ class SymmetricIdeal(Ideal_generic): permutations involve higher variable indices than the ones occurring in ``J``:: - sage: [[(p^P).reduce(J) for p in J] for P in Permutations(3)] + sage: [[(p^P).reduce(J) for p in J] for P in Permutations(3)] # optional - sage.combinat [[0, 0, 0, 0], [0, 0, 0, 0], [0, 0, 0, 0], [0, 0, 0, 0], [0, 0, 0, 0], [0, 0, 0, 0]] Since ``I`` is not a Groebner basis, it is no surprise that it cannot detect ideal membership:: - sage: [p.reduce(I) for p in J] + sage: [p.reduce(I) for p in J] # optional - sage.combinat [0, x_2*y_2*y_1 + 2*x_2*y_1, x_2*x_1*y_1^2 + 2*x_2*x_1*y_1, x_2*x_1*y_2 - x_2*x_1*y_1] Note that we give no guarantee that the computation of a symmetric @@ -161,12 +163,14 @@ class SymmetricIdeal(Ideal_generic): product is indeed the product of ideals in the mathematical sense. :: - sage: I=X*(x[1]) - sage: I*I - Symmetric Ideal (x_1^2, x_2*x_1) of Infinite polynomial ring in x, y over Rational Field - sage: I^3 - Symmetric Ideal (x_1^3, x_2*x_1^2, x_2^2*x_1, x_3*x_2*x_1) of Infinite polynomial ring in x, y over Rational Field - sage: I*I == X*(x[1]^2) + sage: I = X * (x[1]) + sage: I * I # optional - sage.combinat + Symmetric Ideal (x_1^2, x_2*x_1) of + Infinite polynomial ring in x, y over Rational Field + sage: I^3 # optional - sage.combinat + Symmetric Ideal (x_1^3, x_2*x_1^2, x_2^2*x_1, x_3*x_2*x_1) of + Infinite polynomial ring in x, y over Rational Field + sage: I * I == X * (x[1]^2) # optional - sage.combinat False """ @@ -182,12 +186,12 @@ def __init__(self, ring, gens, coerce=True): EXAMPLES:: sage: X. = InfinitePolynomialRing(QQ) - sage: I=X*(x[1]^2+y[2]^2,x[1]*x[2]*y[3]+x[1]*y[4]) # indirect doctest + sage: I = X * (x[1]^2 + y[2]^2, x[1]*x[2]*y[3] + x[1]*y[4]) # indirect doctest sage: I Symmetric Ideal (x_1^2 + y_2^2, x_2*x_1*y_3 + x_1*y_4) of Infinite polynomial ring in x, y over Rational Field sage: from sage.rings.polynomial.symmetric_ideal import SymmetricIdeal - sage: J=SymmetricIdeal(X,[x[1]^2+y[2]^2,x[1]*x[2]*y[3]+x[1]*y[4]]) - sage: I==J + sage: J = SymmetricIdeal(X, [x[1]^2 + y[2]^2, x[1]*x[2]*y[3] + x[1]*y[4]]) + sage: I == J True """ @@ -198,7 +202,7 @@ def __repr__(self): EXAMPLES:: sage: X. = InfinitePolynomialRing(QQ) - sage: I=X*(x[1]^2+y[2]^2,x[1]*x[2]*y[3]+x[1]*y[4]) + sage: I = X * (x[1]^2 + y[2]^2, x[1]*x[2]*y[3] + x[1]*y[4]) sage: I # indirect doctest Symmetric Ideal (x_1^2 + y_2^2, x_2*x_1*y_3 + x_1*y_4) of Infinite polynomial ring in x, y over Rational Field @@ -211,7 +215,7 @@ def _latex_(self): sage: from sage.misc.latex import latex sage: X. = InfinitePolynomialRing(QQ) - sage: I=X*(x[1]*y[2]) + sage: I = X * (x[1]*y[2]) sage: latex(I) # indirect doctest \left(x_{1} y_{2}\right)\Bold{Q}[x_{\ast}, y_{\ast}][\mathfrak{S}_{\infty}] @@ -231,10 +235,11 @@ def _contains_(self, p): sage: R. = InfinitePolynomialRing(QQ) sage: I = R.ideal([x[1]*x[2] + x[3]]) - sage: I = R*I.groebner_basis() - sage: I - Symmetric Ideal (x_1^2 + x_1, x_2 - x_1) of Infinite polynomial ring in x over Rational Field - sage: x[2]^2 + x[3] in I # indirect doctest + sage: I = R * I.groebner_basis() # optional - sage.combinat + sage: I # optional - sage.combinat + Symmetric Ideal (x_1^2 + x_1, x_2 - x_1) of + Infinite polynomial ring in x over Rational Field + sage: x[2]^2 + x[3] in I # indirect doctest # optional - sage.combinat True """ try: @@ -254,8 +259,8 @@ def __mul__(self, other): EXAMPLES:: sage: X. = InfinitePolynomialRing(QQ) - sage: I=X*(x[1]) - sage: I*I # indirect doctest + sage: I = X * (x[1]) + sage: I*I # indirect doctest # optional - sage.combinat Symmetric Ideal (x_1^2, x_2*x_1) of Infinite polynomial ring in x over Rational Field """ @@ -283,7 +288,7 @@ def __mul__(self, other): def __pow__(self, n): """ - Raise self to some power. + Raise ``self`` to some power. Since the generators of a symmetric ideal are subject to a permutation action, they in fact stand for a set of @@ -294,8 +299,8 @@ def __pow__(self, n): EXAMPLES:: sage: X. = InfinitePolynomialRing(QQ) - sage: I=X*(x[1]) - sage: I^2 # indirect doctest + sage: I = X * (x[1]) + sage: I^2 # indirect doctest # optional - sage.combinat Symmetric Ideal (x_1^2, x_2*x_1) of Infinite polynomial ring in x over Rational Field """ @@ -306,7 +311,7 @@ def __pow__(self, n): def is_maximal(self): """ - Answers whether self is a maximal ideal. + Answer whether ``self`` is a maximal ideal. ASSUMPTION: @@ -314,30 +319,30 @@ def is_maximal(self): NOTE: - It is not checked whether self is in fact a symmetric Groebner + It is not checked whether ``self`` is in fact a symmetric Groebner basis. A wrong answer can result if this assumption does not - hold. A ``NotImplementedError`` is raised if the base ring is not + hold. A :class:`NotImplementedError` is raised if the base ring is not a field, since symmetric Groebner bases are not implemented in this setting. EXAMPLES:: sage: R. = InfinitePolynomialRing(QQ) - sage: I = R.ideal([x[1]+y[2], x[2]-y[1]]) - sage: I = R*I.groebner_basis() - sage: I - Symmetric Ideal (y_1, x_1) of Infinite polynomial ring in x, y over Rational Field - sage: I = R.ideal([x[1]+y[2], x[2]-y[1]]) - sage: I.is_maximal() + sage: I = R.ideal([x[1] + y[2], x[2] - y[1]]) + sage: I = R * I.groebner_basis(); I # optional - sage.combinat + Symmetric Ideal (y_1, x_1) of + Infinite polynomial ring in x, y over Rational Field + sage: I = R.ideal([x[1] + y[2], x[2] - y[1]]) # optional - sage.combinat + sage: I.is_maximal() # optional - sage.combinat False The preceding answer is wrong, since it is not the case that ``I`` is given by a symmetric Groebner basis:: - sage: I = R*I.groebner_basis() - sage: I - Symmetric Ideal (y_1, x_1) of Infinite polynomial ring in x, y over Rational Field - sage: I.is_maximal() + sage: I = R * I.groebner_basis(); I # optional - sage.combinat + Symmetric Ideal (y_1, x_1) of + Infinite polynomial ring in x, y over Rational Field + sage: I.is_maximal() # optional - sage.combinat True """ @@ -353,8 +358,8 @@ def is_maximal(self): def reduce(self, I, tailreduce=False): r""" - Symmetric reduction of self by another Symmetric Ideal or list of Infinite Polynomials, - or symmetric reduction of a given Infinite Polynomial by self. + Symmetric reduction of ``self`` by another Symmetric Ideal or list of Infinite Polynomials, + or symmetric reduction of a given Infinite Polynomial by ``self``. INPUT: @@ -377,14 +382,15 @@ def reduce(self, I, tailreduce=False): not diminish the variable indices occurring in `N` and preserves their order, so that there is some term `T\in X` with `T N^P = M`. If there is no such permutation, return `p` - 3. Replace `p` by `p-T q^P` and continue with step 1. + 3. Replace `p` by `p - T q^P` and continue with step 1. EXAMPLES:: sage: X. = InfinitePolynomialRing(QQ) - sage: I = X*(y[1]^2*y[3]+y[1]*x[3]^2) + sage: I = X * (y[1]^2*y[3] + y[1]*x[3]^2) sage: I.reduce([x[1]^2*y[2]]) - Symmetric Ideal (x_3^2*y_1 + y_3*y_1^2) of Infinite polynomial ring in x, y over Rational Field + Symmetric Ideal (x_3^2*y_1 + y_3*y_1^2) of + Infinite polynomial ring in x, y over Rational Field The preceding is correct, since any permutation that turns ``x[1]^2*y[2]`` into a factor of ``x[3]^2*y[2]`` interchanges @@ -392,18 +398,21 @@ def reduce(self, I, tailreduce=False): reduction by ``x[2]^2*y[1]`` works, since one can change variable index 1 into 2 and 2 into 3:: - sage: I.reduce([x[2]^2*y[1]]) - Symmetric Ideal (y_3*y_1^2) of Infinite polynomial ring in x, y over Rational Field + sage: I.reduce([x[2]^2*y[1]]) # optional - sage.combinat + Symmetric Ideal (y_3*y_1^2) of + Infinite polynomial ring in x, y over Rational Field The next example shows that tail reduction is not done, unless it is explicitly advised. The input can also be a symmetric ideal:: - sage: J = (y[2])*X + sage: J = (y[2]) * X sage: I.reduce(J) - Symmetric Ideal (x_3^2*y_1 + y_3*y_1^2) of Infinite polynomial ring in x, y over Rational Field - sage: I.reduce(J, tailreduce=True) - Symmetric Ideal (x_3^2*y_1) of Infinite polynomial ring in x, y over Rational Field + Symmetric Ideal (x_3^2*y_1 + y_3*y_1^2) of + Infinite polynomial ring in x, y over Rational Field + sage: I.reduce(J, tailreduce=True) # optional - sage.combinat + Symmetric Ideal (x_3^2*y_1) of + Infinite polynomial ring in x, y over Rational Field """ if I in self.ring(): # we want to reduce a polynomial by self @@ -419,15 +428,15 @@ def reduce(self, I, tailreduce=False): def interreduction(self, tailreduce=True, sorted=False, report=None, RStrat=None): """ - Return symmetrically interreduced form of self + Return symmetrically interreduced form of ``self``. INPUT: - - ``tailreduce`` -- (bool, default ``True``) If True, the + - ``tailreduce`` -- (bool, default ``True``) If ``True``, the interreduction is also performed on the non-leading monomials. - - ``sorted`` -- (bool, default ``False``) If True, it is assumed that the - generators of self are already increasingly sorted. - - ``report`` -- (object, default ``None``) If not None, some information on the + - ``sorted`` -- (bool, default ``False``) If ``True``, it is assumed that the + generators of ``self`` are already increasingly sorted. + - ``report`` -- (object, default ``None``) If not ``None``, some information on the progress of computation is printed - ``RStrat`` -- (:class:`~sage.rings.polynomial.symmetric_reduction.SymmetricReductionStrategy`, default ``None``) A reduction strategy to which the polynomials resulting @@ -437,28 +446,30 @@ def interreduction(self, tailreduce=True, sorted=False, report=None, RStrat=None OUTPUT: - A Symmetric Ideal J (sorted list of generators) coinciding - with self as an ideal, so that any generator is symmetrically + A Symmetric Ideal `J` (sorted list of generators) coinciding + with ``self`` as an ideal, so that any generator is symmetrically reduced w.r.t. the other generators. Note that the leading coefficients of the result are not necessarily 1. EXAMPLES:: sage: X. = InfinitePolynomialRing(QQ) - sage: I=X*(x[1]+x[2],x[1]*x[2]) + sage: I = X * (x[1] + x[2], x[1]*x[2]) sage: I.interreduction() - Symmetric Ideal (-x_1^2, x_2 + x_1) of Infinite polynomial ring in x over Rational Field + Symmetric Ideal (-x_1^2, x_2 + x_1) of + Infinite polynomial ring in x over Rational Field Here, we show the ``report`` option:: - sage: I.interreduction(report=True) + sage: I.interreduction(report=True) # optional - sage.combinat Symmetric interreduction [1/2] > [2/2] :> [1/2] > [2/2] T[1]> > - Symmetric Ideal (-x_1^2, x_2 + x_1) of Infinite polynomial ring in x over Rational Field + Symmetric Ideal (-x_1^2, x_2 + x_1) of + Infinite polynomial ring in x over Rational Field ``[m/n]`` indicates that polynomial number ``m`` is considered and the total number of polynomials under consideration is @@ -472,13 +483,14 @@ def interreduction(self, tailreduce=True, sorted=False, report=None, RStrat=None sage: R = SymmetricReductionStrategy(X) sage: R Symmetric Reduction Strategy in Infinite polynomial ring in x over Rational Field - sage: I.interreduction(RStrat=R) - Symmetric Ideal (-x_1^2, x_2 + x_1) of Infinite polynomial ring in x over Rational Field + sage: I.interreduction(RStrat=R) # optional - sage.combinat + Symmetric Ideal (-x_1^2, x_2 + x_1) of + Infinite polynomial ring in x over Rational Field sage: R Symmetric Reduction Strategy in Infinite polynomial ring in x over Rational Field, modulo x_1^2, x_2 + x_1 - sage: R = SymmetricReductionStrategy(X,[x[1]^2]) + sage: R = SymmetricReductionStrategy(X, [x[1]^2]) sage: I.interreduction(RStrat=R) Symmetric Ideal (x_2 + x_1) of Infinite polynomial ring in x over Rational Field @@ -560,8 +572,8 @@ def interreduced_basis(self): EXAMPLES:: sage: X. = InfinitePolynomialRing(QQ) - sage: I=X*(x[1]+x[2],x[1]*x[2]) - sage: I.interreduced_basis() + sage: I = X * (x[1] + x[2], x[1]*x[2]) + sage: I.interreduced_basis() # optional - sage.combinat [-x_1^2, x_2 + x_1] """ @@ -569,7 +581,7 @@ def interreduced_basis(self): def symmetrisation(self, N=None, tailreduce=False, report=None, use_full_group=False): """ - Apply permutations to the generators of self and interreduce + Apply permutations to the generators of ``self`` and interreduce. INPUT: @@ -581,8 +593,8 @@ def symmetrisation(self, N=None, tailreduce=False, report=None, use_full_group=F tail reductions. - ``report`` -- (object, default ``None``) If not ``None``, report on the progress of computations. - - ``use_full_group`` (optional) -- If True, apply *all* elements of - `Sym(N)` to the generators of self (this is what [AB2008]_ + - ``use_full_group`` (optional) -- If ``True``, apply *all* elements of + `Sym(N)` to the generators of ``self`` (this is what [AB2008]_ originally suggests). The default is to apply all elementary transpositions to the generators of ``self.squeezed()``, interreduce, and repeat until the result stabilises, which is @@ -592,7 +604,7 @@ def symmetrisation(self, N=None, tailreduce=False, report=None, use_full_group=F OUTPUT: A symmetrically interreduced symmetric ideal with respect to - which any `Sym(N)`-translate of a generator of self is + which any `Sym(N)`-translate of a generator of ``self`` is symmetrically reducible, where by default ``N`` is the maximal variable index that occurs in the generators of ``self.interreduction().squeezed()``. @@ -607,12 +619,13 @@ def symmetrisation(self, N=None, tailreduce=False, report=None, use_full_group=F EXAMPLES:: sage: X. = InfinitePolynomialRing(QQ) - sage: I = X*(x[1]+x[2], x[1]*x[2]) - sage: I.symmetrisation() - Symmetric Ideal (-x_1^2, x_2 + x_1) of Infinite polynomial ring in x over Rational Field - sage: I.symmetrisation(N=3) + sage: I = X * (x[1] + x[2], x[1]*x[2]) + sage: I.symmetrisation() # optional - sage.combinat + Symmetric Ideal (-x_1^2, x_2 + x_1) of + Infinite polynomial ring in x over Rational Field + sage: I.symmetrisation(N=3) # optional - sage.combinat Symmetric Ideal (-2*x_1) of Infinite polynomial ring in x over Rational Field - sage: I.symmetrisation(N=3, use_full_group=True) + sage: I.symmetrisation(N=3, use_full_group=True) # optional - sage.combinat Symmetric Ideal (-2*x_1) of Infinite polynomial ring in x over Rational Field """ @@ -656,18 +669,18 @@ def symmetrisation(self, N=None, tailreduce=False, report=None, use_full_group=F def symmetric_basis(self): """ - A symmetrised generating set (type :class:`~sage.structure.sequence.Sequence`) of self. + A symmetrised generating set (type :class:`~sage.structure.sequence.Sequence`) of ``self``. This does essentially the same as :meth:`symmetrisation` with - the option 'tailreduce', and it returns a + the option ``tailreduce``, and it returns a :class:`~sage.structure.sequence.Sequence` rather than a :class:`~sage.rings.polynomial.symmetric_ideal.SymmetricIdeal`. EXAMPLES:: sage: X. = InfinitePolynomialRing(QQ) - sage: I = X*(x[1]+x[2], x[1]*x[2]) - sage: I.symmetric_basis() + sage: I = X * (x[1] + x[2], x[1]*x[2]) + sage: I.symmetric_basis() # optional - sage.combinat [x_1^2, x_2 + x_1] """ @@ -675,16 +688,17 @@ def symmetric_basis(self): def normalisation(self): """ - Return an ideal that coincides with self, so that all generators have leading coefficient 1. + Return an ideal that coincides with ``self``, so that all generators have leading coefficient 1. Possibly occurring zeroes are removed from the generator list. EXAMPLES:: sage: X. = InfinitePolynomialRing(QQ) - sage: I = X*(1/2*x[1]+2/3*x[2], 0, 4/5*x[1]*x[2]) + sage: I = X*(1/2*x[1] + 2/3*x[2], 0, 4/5*x[1]*x[2]) sage: I.normalisation() - Symmetric Ideal (x_2 + 3/4*x_1, x_2*x_1) of Infinite polynomial ring in x over Rational Field + Symmetric Ideal (x_2 + 3/4*x_1, x_2*x_1) of + Infinite polynomial ring in x over Rational Field """ return SymmetricIdeal(self.ring(), [X/X.lc() for X in self.gens() if X._p!=0]) @@ -705,10 +719,11 @@ def squeezed(self): EXAMPLES:: - sage: X. = InfinitePolynomialRing(QQ,implementation='sparse') - sage: I = X*(x[1000]*y[100],x[50]*y[1000]) + sage: X. = InfinitePolynomialRing(QQ, implementation='sparse') + sage: I = X * (x[1000]*y[100], x[50]*y[1000]) sage: I.squeezed() - Symmetric Ideal (x_2*y_1, x_1*y_2) of Infinite polynomial ring in x, y over Rational Field + Symmetric Ideal (x_2*y_1, x_1*y_2) of + Infinite polynomial ring in x, y over Rational Field """ return SymmetricIdeal(self.ring(), [X.squeezed() for X in self.gens()]) @@ -720,7 +735,7 @@ def groebner_basis(self, tailreduce=False, reduced=True, algorithm=None, report= INPUT: - - ``tailreduce`` -- (bool, default ``False``) If True, use tail reduction + - ``tailreduce`` -- (bool, default ``False``) If ``True``, use tail reduction in intermediate computations - ``reduced`` -- (bool, default ``True``) If ``True``, return the reduced normalised symmetric Groebner basis. @@ -730,7 +745,7 @@ def groebner_basis(self, tailreduce=False, reduced=True, algorithm=None, report= progress of computation. - ``use_full_group`` -- (bool, default ``False``) If ``True`` then proceed as originally suggested by [AB2008]_. Our default method should be faster; see - :meth:`.symmetrisation` for more details. + :meth:`symmetrisation` for more details. The computation of symmetric Groebner bases also involves the computation of *classical* Groebner bases, i.e., of Groebner @@ -791,11 +806,11 @@ def groebner_basis(self, tailreduce=False, reduced=True, algorithm=None, report= EXAMPLES:: sage: X. = InfinitePolynomialRing(QQ) - sage: I1 = X*(x[1]+x[2],x[1]*x[2]) - sage: I1.groebner_basis() + sage: I1 = X * (x[1] + x[2], x[1]*x[2]) + sage: I1.groebner_basis() # optional - sage.combinat [x_1] - sage: I2 = X*(y[1]^2*y[3]+y[1]*x[3]) - sage: I2.groebner_basis() + sage: I2 = X * (y[1]^2*y[3] + y[1]*x[3]) + sage: I2.groebner_basis() # optional - sage.combinat [x_1*y_2 + y_2^2*y_1, x_2*y_1 + y_2*y_1^2] Note that a symmetric Groebner basis of a principal ideal is @@ -805,13 +820,13 @@ def groebner_basis(self, tailreduce=False, reduced=True, algorithm=None, report= and Hillar, the result is the same, but the computation takes much longer:: - sage: I2.groebner_basis(use_full_group=True) + sage: I2.groebner_basis(use_full_group=True) # optional - sage.combinat [x_1*y_2 + y_2^2*y_1, x_2*y_1 + y_2*y_1^2] Last, we demonstrate how the report on the progress of computations looks like:: - sage: I1.groebner_basis(report=True, reduced=True) + sage: I1.groebner_basis(report=True, reduced=True) # optional - sage.combinat Symmetric interreduction [1/2] > [2/2] :> @@ -879,12 +894,12 @@ def groebner_basis(self, tailreduce=False, reduced=True, algorithm=None, report= [x_1] The Aschenbrenner-Hillar algorithm is only guaranteed to work - if the base ring is a field. So, we raise a TypeError if this + if the base ring is a field. So, we raise a :class:`TypeError` if this is not the case:: sage: R. = InfinitePolynomialRing(ZZ) - sage: I = R*[x[1]+x[2],y[1]] - sage: I.groebner_basis() + sage: I = R * [x[1] + x[2], y[1]] + sage: I.groebner_basis() # optional - sage.combinat Traceback (most recent call last): ... TypeError: The base ring (= Integer Ring) must be a field @@ -893,14 +908,19 @@ def groebner_basis(self, tailreduce=False, reduced=True, algorithm=None, report= In an earlier version, the following examples failed:: - sage: X. = InfinitePolynomialRing(GF(5),order='degrevlex') - sage: I = ['-2*y_0^2 + 2*z_0^2 + 1', '-y_0^2 + 2*y_0*z_0 - 2*z_0^2 - 2*z_0 - 1', 'y_0*z_0 + 2*z_0^2 - 2*z_0 - 1', 'y_0^2 + 2*y_0*z_0 - 2*z_0^2 + 2*z_0 - 2', '-y_0^2 - 2*y_0*z_0 - z_0^2 + y_0 - 1']*X - sage: I.groebner_basis() + sage: X. = InfinitePolynomialRing(GF(5), order='degrevlex') # optional - sage.rings.finite_rings + sage: I = ['-2*y_0^2 + 2*z_0^2 + 1', + ....: '-y_0^2 + 2*y_0*z_0 - 2*z_0^2 - 2*z_0 - 1', + ....: 'y_0*z_0 + 2*z_0^2 - 2*z_0 - 1', + ....: 'y_0^2 + 2*y_0*z_0 - 2*z_0^2 + 2*z_0 - 2', + ....: '-y_0^2 - 2*y_0*z_0 - z_0^2 + y_0 - 1'] * X + sage: I.groebner_basis() # optional - sage.combinat sage.rings.finite_rings [1] - sage: Y. = InfinitePolynomialRing(GF(3), order='degrevlex', implementation='sparse') - sage: I = ['-y_3']*Y - sage: I.groebner_basis() + sage: Y. = InfinitePolynomialRing(GF(3), order='degrevlex', # optional - sage.rings.finite_rings + ....: implementation='sparse') + sage: I = ['-y_3'] * Y + sage: I.groebner_basis() # optional - sage.combinat sage.rings.finite_rings [y_1] """ diff --git a/src/sage/rings/polynomial/symmetric_reduction.pyx b/src/sage/rings/polynomial/symmetric_reduction.pyx index 25213e1318a..c8384b72977 100644 --- a/src/sage/rings/polynomial/symmetric_reduction.pyx +++ b/src/sage/rings/polynomial/symmetric_reduction.pyx @@ -51,7 +51,7 @@ EXAMPLES: First, we create an infinite polynomial ring and one of its elements:: sage: X. = InfinitePolynomialRing(QQ) - sage: p = y[1]*y[3]+y[1]^2*x[3] + sage: p = y[1]*y[3] + y[1]^2*x[3] We want to symmetrically reduce it by another polynomial. So, we put this other polynomial into a list and create a Symmetric Reduction @@ -60,7 +60,8 @@ Strategy object:: sage: from sage.rings.polynomial.symmetric_reduction import SymmetricReductionStrategy sage: S = SymmetricReductionStrategy(X, [y[2]^2*x[1]]) sage: S - Symmetric Reduction Strategy in Infinite polynomial ring in x, y over Rational Field, modulo + Symmetric Reduction Strategy in + Infinite polynomial ring in x, y over Rational Field, modulo x_1*y_2^2 sage: S.reduce(p) x_3*y_1^2 + y_3*y_1 @@ -74,18 +75,19 @@ change variable index 1 into 2 and 2 into 3. So, we add this to sage: S.add_generator(y[1]^2*x[2]) sage: S - Symmetric Reduction Strategy in Infinite polynomial ring in x, y over Rational Field, modulo + Symmetric Reduction Strategy in + Infinite polynomial ring in x, y over Rational Field, modulo x_2*y_1^2, x_1*y_2^2 - sage: S.reduce(p) + sage: S.reduce(p) # optional - sage.combinat y_3*y_1 The next example shows that tail reduction is not done, unless it is explicitly advised:: - sage: S.reduce(x[3] + 2*x[2]*y[1]^2 + 3*y[2]^2*x[1]) + sage: S.reduce(x[3] + 2*x[2]*y[1]^2 + 3*y[2]^2*x[1]) # optional - sage.combinat x_3 + 2*x_2*y_1^2 + 3*x_1*y_2^2 - sage: S.tailreduce(x[3] + 2*x[2]*y[1]^2 + 3*y[2]^2*x[1]) + sage: S.tailreduce(x[3] + 2*x[2]*y[1]^2 + 3*y[2]^2*x[1]) # optional - sage.combinat x_3 However, it is possible to ask for tailreduction already when the @@ -93,11 +95,12 @@ Symmetric Reduction Strategy is created:: sage: S2 = SymmetricReductionStrategy(X, [y[2]^2*x[1],y[1]^2*x[2]], tailreduce=True) sage: S2 - Symmetric Reduction Strategy in Infinite polynomial ring in x, y over Rational Field, modulo + Symmetric Reduction Strategy in + Infinite polynomial ring in x, y over Rational Field, modulo x_2*y_1^2, x_1*y_2^2 with tailreduction - sage: S2.reduce(x[3] + 2*x[2]*y[1]^2 + 3*y[2]^2*x[1]) + sage: S2.reduce(x[3] + 2*x[2]*y[1]^2 + 3*y[2]^2*x[1]) # optional - sage.combinat x_3 """ @@ -144,7 +147,7 @@ cdef class SymmetricReductionStrategy: sage: S = SymmetricReductionStrategy(X, [y[2]^2*y[1],y[1]^2*y[2]], good_input=True) sage: S.reduce(y[3] + 2*y[2]*y[1]^2 + 3*y[2]^2*y[1]) y_3 + 3*y_2^2*y_1 + 2*y_2*y_1^2 - sage: S.tailreduce(y[3] + 2*y[2]*y[1]^2 + 3*y[2]^2*y[1]) + sage: S.tailreduce(y[3] + 2*y[2]*y[1]^2 + 3*y[2]^2*y[1]) # optional - sage.combinat y_3 """ @@ -265,7 +268,8 @@ cdef class SymmetricReductionStrategy: sage: from sage.rings.polynomial.symmetric_reduction import SymmetricReductionStrategy sage: S = SymmetricReductionStrategy(X, [y[2]^2*y[1],y[1]^2*y[2]]) sage: S - Symmetric Reduction Strategy in Infinite polynomial ring in y over Rational Field, modulo + Symmetric Reduction Strategy in + Infinite polynomial ring in y over Rational Field, modulo y_2*y_1^2, y_2^2*y_1 sage: S.gens() @@ -295,7 +299,8 @@ cdef class SymmetricReductionStrategy: sage: R = SymmetricReductionStrategy(X) sage: R.setgens(S.gens()) sage: R - Symmetric Reduction Strategy in Infinite polynomial ring in y over Rational Field, modulo + Symmetric Reduction Strategy in + Infinite polynomial ring in y over Rational Field, modulo y_2*y_1^2, y_2^2*y_1 sage: R.gens() is S.gens() @@ -316,7 +321,8 @@ cdef class SymmetricReductionStrategy: sage: from sage.rings.polynomial.symmetric_reduction import SymmetricReductionStrategy sage: S = SymmetricReductionStrategy(X, [y[2]^2*y[1],y[1]^2*y[2]]) sage: S - Symmetric Reduction Strategy in Infinite polynomial ring in y over Rational Field, modulo + Symmetric Reduction Strategy in + Infinite polynomial ring in y over Rational Field, modulo y_2*y_1^2, y_2^2*y_1 sage: S.reset() @@ -336,7 +342,7 @@ cdef class SymmetricReductionStrategy: sage: from sage.rings.polynomial.symmetric_reduction import SymmetricReductionStrategy sage: X. = InfinitePolynomialRing(QQ) - sage: S = SymmetricReductionStrategy(X, [y[2]^2*y[1],y[1]^2*y[2]], tailreduce=True) + sage: S = SymmetricReductionStrategy(X, [y[2]^2*y[1], y[1]^2*y[2]], tailreduce=True) sage: S # indirect doctest Symmetric Reduction Strategy in Infinite polynomial ring in x, y over Rational Field, modulo y_2*y_1^2, @@ -424,18 +430,21 @@ cdef class SymmetricReductionStrategy: sage: X. = InfinitePolynomialRing(QQ) sage: S = SymmetricReductionStrategy(X) sage: S - Symmetric Reduction Strategy in Infinite polynomial ring in x, y over Rational Field + Symmetric Reduction Strategy in + Infinite polynomial ring in x, y over Rational Field sage: S.add_generator(y[3] + y[1]*(x[3]+x[1])) sage: S - Symmetric Reduction Strategy in Infinite polynomial ring in x, y over Rational Field, modulo + Symmetric Reduction Strategy in + Infinite polynomial ring in x, y over Rational Field, modulo x_3*y_1 + x_1*y_1 + y_3 Note that the first added polynomial will be simplified when adding a suitable second polynomial:: - sage: S.add_generator(x[2]+x[1]) - sage: S - Symmetric Reduction Strategy in Infinite polynomial ring in x, y over Rational Field, modulo + sage: S.add_generator(x[2] + x[1]) # optional - sage.combinat + sage: S # optional - sage.combinat + Symmetric Reduction Strategy in + Infinite polynomial ring in x, y over Rational Field, modulo y_3, x_2 + x_1 @@ -443,17 +452,19 @@ cdef class SymmetricReductionStrategy: polynomial. This can be avoided by specifying the optional parameter 'good_input':: - sage: S.add_generator(y[2]+y[1]*x[2]) - sage: S - Symmetric Reduction Strategy in Infinite polynomial ring in x, y over Rational Field, modulo + sage: S.add_generator(y[2] + y[1]*x[2]) # optional - sage.combinat + sage: S # optional - sage.combinat + Symmetric Reduction Strategy in + Infinite polynomial ring in x, y over Rational Field, modulo y_3, x_1*y_1 - y_2, x_2 + x_1 - sage: S.reduce(x[3]+x[2]) + sage: S.reduce(x[3] + x[2]) # optional - sage.combinat -2*x_1 - sage: S.add_generator(x[3]+x[2], good_input=True) - sage: S - Symmetric Reduction Strategy in Infinite polynomial ring in x, y over Rational Field, modulo + sage: S.add_generator(x[3] + x[2], good_input=True) # optional - sage.combinat + sage: S # optional - sage.combinat + Symmetric Reduction Strategy in + Infinite polynomial ring in x, y over Rational Field, modulo y_3, x_3 + x_2, x_1*y_1 - y_2, @@ -528,7 +539,7 @@ cdef class SymmetricReductionStrategy: .. NOTE:: - If tail reduction shall be forced, use :meth:`.tailreduce`. + If tail reduction shall be forced, use :meth:`tailreduce`. EXAMPLES:: @@ -540,15 +551,18 @@ cdef class SymmetricReductionStrategy: sage: S.reduce(y[4]*x[1] + y[1]*x[4], notail=True) x_4*y_1 + x_1*y_4 - Last, we demonstrate the 'report' option:: + Last, we demonstrate the ``report`` option:: - sage: S = SymmetricReductionStrategy(X, [x[2]+y[1],x[2]*y[3]+x[1]*y[2]+y[4],y[3]+y[2]]) + sage: S = SymmetricReductionStrategy(X, [x[2] + y[1], + ....: x[2]*y[3] + x[1]*y[2] + y[4], + ....: y[3] + y[2]]) sage: S - Symmetric Reduction Strategy in Infinite polynomial ring in x, y over Rational Field, modulo + Symmetric Reduction Strategy in + Infinite polynomial ring in x, y over Rational Field, modulo y_3 + y_2, x_2 + y_1, x_1*y_2 + y_4 - y_3*y_1 - sage: S.reduce(x[3] + x[1]*y[3] + x[1]*y[1],report=True) + sage: S.reduce(x[3] + x[1]*y[3] + x[1]*y[1], report=True) :::> x_1*y_1 + y_4 - y_3*y_1 - y_1 @@ -625,18 +639,21 @@ cdef class SymmetricReductionStrategy: sage: S = SymmetricReductionStrategy(X, [y[3]]) sage: S.reduce(y[4]*x[1] + y[1]*x[4]) x_4*y_1 + x_1*y_4 - sage: S.tailreduce(y[4]*x[1] + y[1]*x[4]) + sage: S.tailreduce(y[4]*x[1] + y[1]*x[4]) # optional - sage.combinat x_4*y_1 Last, we demonstrate the 'report' option:: - sage: S = SymmetricReductionStrategy(X, [x[2]+y[1],x[2]*x[3]+x[1]*y[2]+y[4],y[3]+y[2]]) + sage: S = SymmetricReductionStrategy(X, [x[2] + y[1], + ....: x[2]*x[3] + x[1]*y[2] + y[4], + ....: y[3] + y[2]]) sage: S - Symmetric Reduction Strategy in Infinite polynomial ring in x, y over Rational Field, modulo + Symmetric Reduction Strategy in + Infinite polynomial ring in x, y over Rational Field, modulo y_3 + y_2, x_2 + y_1, x_1*y_2 + y_4 + y_1^2 - sage: S.tailreduce(x[3] + x[1]*y[3] + x[1]*y[1],report=True) + sage: S.tailreduce(x[3] + x[1]*y[3] + x[1]*y[1], report=True) # optional - sage.combinat T[3]:::> T[3]:> x_1*y_1 - y_2 + y_1^2 - y_1 diff --git a/src/sage/rings/polynomial/term_order.py b/src/sage/rings/polynomial/term_order.py index bda1ec75a10..39c103e215d 100644 --- a/src/sage/rings/polynomial/term_order.py +++ b/src/sage/rings/polynomial/term_order.py @@ -272,22 +272,22 @@ EXAMPLES:: - sage: m = matrix(2,[2,3,0,1]); m + sage: m = matrix(2, [2,3,0,1]); m # optional - sage.modules [2 3] [0 1] - sage: T = TermOrder(m); T + sage: T = TermOrder(m); T # optional - sage.modules Matrix term order with matrix [2 3] [0 1] - sage: P. = PolynomialRing(QQ,2,order=T) - sage: P + sage: P. = PolynomialRing(QQ, 2, order=T) # optional - sage.modules + sage: P # optional - sage.modules Multivariate Polynomial Ring in a, b over Rational Field - sage: a > b + sage: a > b # optional - sage.modules False - sage: a^3 < b^2 + sage: a^3 < b^2 # optional - sage.modules True - sage: S = TermOrder('M(2,3,0,1)') - sage: T == S + sage: S = TermOrder('M(2,3,0,1)') # optional - sage.modules + sage: T == S # optional - sage.modules True Additionally all these monomial orders may be combined to product or block @@ -313,7 +313,7 @@ :: - sage: P. = PolynomialRing(QQ, 6,order='degrevlex(4),neglex(2)') + sage: P. = PolynomialRing(QQ, 6, order='degrevlex(4),neglex(2)') sage: a > c^4 False sage: a > e^4 @@ -341,7 +341,7 @@ Traceback (most recent call last): ... ValueError: unknown term order 'royalorder' - sage: T = TermOrder("royalorder",force=True) + sage: T = TermOrder("royalorder", force=True) sage: T royalorder term order sage: T.singular_str() @@ -647,7 +647,7 @@ def __init__(self, name='lex', n=0, force=False): :trac:`12748`):: sage: T = TermOrder('degrevlex', 6) + TermOrder('degrevlex',10) - sage: R. = PolynomialRing(QQ,order=T) + sage: R. = PolynomialRing(QQ, order=T) Traceback (most recent call last): ... ValueError: the length of the given term order (16) differs from the number of variables (15) @@ -657,7 +657,7 @@ def __init__(self, name='lex', n=0, force=False): sage: T = TermOrder('degrevlex') sage: R. = PolynomialRing(QQ, order=T) - sage: R._singular_() + sage: R._singular_() # optional - sage.libs.singular polynomial ring, over a field, global ordering // coefficients: QQ // number of vars : 3 @@ -673,7 +673,7 @@ def __init__(self, name='lex', n=0, force=False): sage: S = R.change_ring(order=T2) sage: S == T False - sage: S._singular_() + sage: S._singular_() # optional - sage.libs.singular polynomial ring, over a field, global ordering // coefficients: QQ // number of vars : 3 @@ -683,10 +683,11 @@ def __init__(self, name='lex', n=0, force=False): Check that :trac:`29635` is fixed:: - sage: T = PolynomialRing(GF(101^5), 'u,v,w', order=TermOrder('degneglex')).term_order() - sage: T.singular_str() + sage: T = PolynomialRing(GF(101^5), 'u,v,w', # optional - sage.rings.finite_rings + ....: order=TermOrder('degneglex')).term_order() + sage: T.singular_str() # optional - sage.rings.finite_rings '(a(1:3),ls(3))' - sage: (T + T).singular_str() + sage: (T + T).singular_str() # optional - sage.rings.finite_rings '(a(1:3),ls(3),a(1:3),ls(3))' """ if isinstance(name, TermOrder): @@ -929,10 +930,10 @@ def sortkey_matrix(self, f): EXAMPLES:: - sage: P. = PolynomialRing(QQbar, 2, order='m(1,3,1,0)') - sage: y > x^2 # indirect doctest + sage: P. = PolynomialRing(QQbar, 2, order='m(1,3,1,0)') # optional - sage.rings.number_field + sage: y > x^2 # indirect doctest # optional - sage.rings.number_field True - sage: y > x^3 + sage: y > x^3 # optional - sage.rings.number_field False """ return tuple(sum(l * r for l, r in zip(row, f)) @@ -949,10 +950,10 @@ def sortkey_lex(self, f): EXAMPLES:: - sage: P. = PolynomialRing(QQbar, 2, order='lex') - sage: x > y^2 # indirect doctest + sage: P. = PolynomialRing(QQbar, 2, order='lex') # optional - sage.rings.number_field + sage: x > y^2 # indirect doctest # optional - sage.rings.number_field True - sage: x > 1 + sage: x > 1 # optional - sage.rings.number_field True """ return f @@ -968,10 +969,10 @@ def sortkey_invlex(self, f): EXAMPLES:: - sage: P. = PolynomialRing(QQbar, 2, order='invlex') - sage: x > y^2 # indirect doctest + sage: P. = PolynomialRing(QQbar, 2, order='invlex') # optional - sage.rings.number_field + sage: x > y^2 # indirect doctest # optional - sage.rings.number_field False - sage: x > 1 + sage: x > 1 # optional - sage.rings.number_field True """ return f.reversed() @@ -987,10 +988,10 @@ def sortkey_deglex(self, f): EXAMPLES:: - sage: P. = PolynomialRing(QQbar, 2, order='deglex') - sage: x > y^2 # indirect doctest + sage: P. = PolynomialRing(QQbar, 2, order='deglex') # optional - sage.rings.number_field + sage: x > y^2 # indirect doctest # optional - sage.rings.number_field False - sage: x > 1 + sage: x > 1 # optional - sage.rings.number_field True """ @@ -1007,10 +1008,10 @@ def sortkey_degrevlex(self, f): EXAMPLES:: - sage: P. = PolynomialRing(QQbar, 2, order='degrevlex') - sage: x > y^2 # indirect doctest + sage: P. = PolynomialRing(QQbar, 2, order='degrevlex') # optional - sage.rings.number_field + sage: x > y^2 # indirect doctest # optional - sage.rings.number_field False - sage: x > 1 + sage: x > 1 # optional - sage.rings.number_field True """ @@ -1029,10 +1030,10 @@ def sortkey_neglex(self, f): EXAMPLES:: - sage: P. = PolynomialRing(QQbar, 2, order='neglex') - sage: x > y^2 # indirect doctest + sage: P. = PolynomialRing(QQbar, 2, order='neglex') # optional - sage.rings.number_field + sage: x > y^2 # indirect doctest # optional - sage.rings.number_field False - sage: x > 1 + sage: x > 1 # optional - sage.rings.number_field False """ return tuple(-v for v in f) @@ -1048,10 +1049,10 @@ def sortkey_negdegrevlex(self, f): EXAMPLES:: - sage: P. = PolynomialRing(QQbar, 2, order='negdegrevlex') - sage: x > y^2 # indirect doctest + sage: P. = PolynomialRing(QQbar, 2, order='negdegrevlex') # optional - sage.rings.number_field + sage: x > y^2 # indirect doctest # optional - sage.rings.number_field True - sage: x > 1 + sage: x > 1 # optional - sage.rings.number_field False """ return (-sum(f.nonzero_values(sort=False)), @@ -1068,10 +1069,10 @@ def sortkey_negdeglex(self, f): EXAMPLES:: - sage: P. = PolynomialRing(QQbar, 2, order='negdeglex') - sage: x > y^2 # indirect doctest + sage: P. = PolynomialRing(QQbar, 2, order='negdeglex') # optional - sage.rings.number_field + sage: x > y^2 # indirect doctest # optional - sage.rings.number_field True - sage: x > 1 + sage: x > 1 # optional - sage.rings.number_field False """ return (-sum(f.nonzero_values(sort=False)), f) @@ -1087,10 +1088,10 @@ def sortkey_degneglex(self, f): EXAMPLES:: - sage: P. = PolynomialRing(QQbar, 3, order='degneglex') - sage: x*y > y*z # indirect doctest + sage: P. = PolynomialRing(QQbar, 3, order='degneglex') # optional - sage.rings.number_field + sage: x*y > y*z # indirect doctest # optional - sage.rings.number_field False - sage: x*y > x + sage: x*y > x # optional - sage.rings.number_field True """ return (sum(f.nonzero_values(sort=False)), tuple(-v for v in f)) @@ -1107,10 +1108,10 @@ def sortkey_wdegrevlex(self, f): EXAMPLES:: sage: t = TermOrder('wdegrevlex',(3,2)) - sage: P. = PolynomialRing(QQbar, 2, order=t) - sage: x > y^2 # indirect doctest + sage: P. = PolynomialRing(QQbar, 2, order=t) # optional - sage.rings.number_field + sage: x > y^2 # indirect doctest # optional - sage.rings.number_field False - sage: x^2 > y^3 + sage: x^2 > y^3 # optional - sage.rings.number_field True """ return (sum(l * r for (l, r) in zip(f, self._weights)), @@ -1128,10 +1129,10 @@ def sortkey_wdeglex(self, f): EXAMPLES:: sage: t = TermOrder('wdeglex',(3,2)) - sage: P. = PolynomialRing(QQbar, 2, order=t) - sage: x > y^2 # indirect doctest + sage: P. = PolynomialRing(QQbar, 2, order=t) # optional - sage.rings.number_field + sage: x > y^2 # indirect doctest # optional - sage.rings.number_field False - sage: x > y + sage: x > y # optional - sage.rings.number_field True """ return (sum(l * r for (l, r) in zip(f, self._weights)), f) @@ -1148,10 +1149,10 @@ def sortkey_negwdeglex(self, f): EXAMPLES:: sage: t = TermOrder('negwdeglex',(3,2)) - sage: P. = PolynomialRing(QQbar, 2, order=t) - sage: x > y^2 # indirect doctest + sage: P. = PolynomialRing(QQbar, 2, order=t) # optional - sage.rings.number_field + sage: x > y^2 # indirect doctest # optional - sage.rings.number_field True - sage: x^2 > y^3 + sage: x^2 > y^3 # optional - sage.rings.number_field True """ return (-sum(l * r for (l, r) in zip(f, self._weights)), f) @@ -1168,10 +1169,10 @@ def sortkey_negwdegrevlex(self, f): EXAMPLES:: sage: t = TermOrder('negwdegrevlex',(3,2)) - sage: P. = PolynomialRing(QQbar, 2, order=t) - sage: x > y^2 # indirect doctest + sage: P. = PolynomialRing(QQbar, 2, order=t) # optional - sage.rings.number_field + sage: x > y^2 # indirect doctest # optional - sage.rings.number_field True - sage: x^2 > y^3 + sage: x^2 > y^3 # optional - sage.rings.number_field True """ return (-sum(l * r for (l, r) in zip(f, self._weights)), @@ -1188,18 +1189,19 @@ def sortkey_block(self, f): EXAMPLES:: - sage: P.=PolynomialRing(QQbar, 6, order='degrevlex(3),degrevlex(3)') - sage: a > c^4 # indirect doctest + sage: P. = PolynomialRing(QQbar, 6, # optional - sage.rings.number_field + ....: order='degrevlex(3),degrevlex(3)') + sage: a > c^4 # indirect doctest # optional - sage.rings.number_field False - sage: a > e^4 + sage: a > e^4 # optional - sage.rings.number_field True TESTS: Check that the issue in :trac:`27139` is fixed:: - sage: R. = PolynomialRing(AA, order='lex(2),lex(2)') - sage: x > y + sage: R. = PolynomialRing(AA, order='lex(2),lex(2)') # optional - sage.rings.number_field + sage: x > y # optional - sage.rings.number_field True """ key = tuple() @@ -1223,10 +1225,10 @@ def greater_tuple_matrix(self,f,g): EXAMPLES:: - sage: P. = PolynomialRing(QQbar, 2, order='m(1,3,1,0)') - sage: y > x^2 # indirect doctest + sage: P. = PolynomialRing(QQbar, 2, order='m(1,3,1,0)') # optional - sage.rings.number_field + sage: y > x^2 # indirect doctest # optional - sage.rings.number_field True - sage: y > x^3 + sage: y > x^3 # optional - sage.rings.number_field False """ for row in self._matrix: @@ -1252,8 +1254,8 @@ def greater_tuple_lex(self,f,g): EXAMPLES:: - sage: P. = PolynomialRing(QQbar, 3, order='lex') - sage: f = x + y^2; f.lm() # indirect doctest + sage: P. = PolynomialRing(QQbar, 3, order='lex') # optional - sage.rings.number_field + sage: f = x + y^2; f.lm() # indirect doctest # optional - sage.rings.number_field x This method is called by the lm/lc/lt methods of @@ -1274,10 +1276,10 @@ def greater_tuple_invlex(self,f,g): EXAMPLES:: - sage: P. = PolynomialRing(QQbar, 3, order='invlex') - sage: f = x + y; f.lm() # indirect doctest + sage: P. = PolynomialRing(QQbar, 3, order='invlex') # optional - sage.rings.number_field + sage: f = x + y; f.lm() # indirect doctest # optional - sage.rings.number_field y - sage: f = y + x^2; f.lm() + sage: f = y + x^2; f.lm() # optional - sage.rings.number_field y This method is called by the lm/lc/lt methods of @@ -1298,10 +1300,10 @@ def greater_tuple_deglex(self,f,g): EXAMPLES:: - sage: P. = PolynomialRing(QQbar, 3, order='deglex') - sage: f = x + y; f.lm() # indirect doctest + sage: P. = PolynomialRing(QQbar, 3, order='deglex') # optional - sage.rings.number_field + sage: f = x + y; f.lm() # indirect doctest # optional - sage.rings.number_field x - sage: f = x + y^2*z; f.lm() + sage: f = x + y^2*z; f.lm() # optional - sage.rings.number_field y^2*z This method is called by the lm/lc/lt methods of @@ -1324,10 +1326,10 @@ def greater_tuple_degrevlex(self,f,g): EXAMPLES:: - sage: P. = PolynomialRing(QQbar, 3, order='degrevlex') - sage: f = x + y; f.lm() # indirect doctest + sage: P. = PolynomialRing(QQbar, 3, order='degrevlex') # optional - sage.rings.number_field + sage: f = x + y; f.lm() # indirect doctest # optional - sage.rings.number_field x - sage: f = x + y^2*z; f.lm() + sage: f = x + y^2*z; f.lm() # optional - sage.rings.number_field y^2*z This method is called by the lm/lc/lt methods of @@ -1350,12 +1352,12 @@ def greater_tuple_negdegrevlex(self,f,g): EXAMPLES:: - sage: P. = PolynomialRing(QQbar, 3, order='negdegrevlex') - sage: f = x + y; f.lm() # indirect doctest + sage: P. = PolynomialRing(QQbar, 3, order='negdegrevlex') # optional - sage.rings.number_field + sage: f = x + y; f.lm() # indirect doctest # optional - sage.rings.number_field x - sage: f = x + x^2; f.lm() + sage: f = x + x^2; f.lm() # optional - sage.rings.number_field x - sage: f = x^2*y*z^2 + x*y^3*z; f.lm() + sage: f = x^2*y*z^2 + x*y^3*z; f.lm() # optional - sage.rings.number_field x*y^3*z This method is called by the lm/lc/lt methods of @@ -1378,12 +1380,12 @@ def greater_tuple_negdeglex(self,f,g): EXAMPLES:: - sage: P. = PolynomialRing(QQbar, 3, order='negdeglex') - sage: f = x + y; f.lm() # indirect doctest + sage: P. = PolynomialRing(QQbar, 3, order='negdeglex') # optional - sage.rings.number_field + sage: f = x + y; f.lm() # indirect doctest # optional - sage.rings.number_field x - sage: f = x + x^2; f.lm() + sage: f = x + x^2; f.lm() # optional - sage.rings.number_field x - sage: f = x^2*y*z^2 + x*y^3*z; f.lm() + sage: f = x^2*y*z^2 + x*y^3*z; f.lm() # optional - sage.rings.number_field x^2*y*z^2 This method is called by the lm/lc/lt methods of @@ -1406,10 +1408,10 @@ def greater_tuple_degneglex(self,f,g): EXAMPLES:: - sage: P. = PolynomialRing(QQbar, 3, order='degneglex') - sage: f = x + y; f.lm() # indirect doctest + sage: P. = PolynomialRing(QQbar, 3, order='degneglex') # optional - sage.rings.number_field + sage: f = x + y; f.lm() # indirect doctest # optional - sage.rings.number_field y - sage: f = x + y^2*z; f.lm() + sage: f = x + y^2*z; f.lm() # optional - sage.rings.number_field y^2*z This method is called by the lm/lc/lt methods of @@ -1435,10 +1437,11 @@ def greater_tuple_neglex(self,f,g): EXAMPLES:: - sage: P.=PolynomialRing(QQbar, 6, order='degrevlex(3),degrevlex(3)') - sage: f = a + c^4; f.lm() # indirect doctest + sage: P. = PolynomialRing(QQbar, 6, # optional - sage.rings.number_field + ....: order='degrevlex(3),degrevlex(3)') + sage: f = a + c^4; f.lm() # indirect doctest # optional - sage.rings.number_field c^4 - sage: g = a + e^4; g.lm() + sage: g = a + e^4; g.lm() # optional - sage.rings.number_field a """ return (f < g) and f or g @@ -1457,10 +1460,10 @@ def greater_tuple_wdeglex(self,f,g): EXAMPLES:: sage: t = TermOrder('wdeglex',(1,2,3)) - sage: P. = PolynomialRing(QQbar, 3, order=t) - sage: f = x + y; f.lm() # indirect doctest + sage: P. = PolynomialRing(QQbar, 3, order=t) # optional - sage.rings.number_field + sage: f = x + y; f.lm() # indirect doctest # optional - sage.rings.number_field y - sage: f = x*y + z; f.lm() + sage: f = x*y + z; f.lm() # optional - sage.rings.number_field x*y This method is called by the lm/lc/lt methods of @@ -1484,10 +1487,10 @@ def greater_tuple_wdegrevlex(self,f,g): EXAMPLES:: sage: t = TermOrder('wdegrevlex',(1,2,3)) - sage: P. = PolynomialRing(QQbar, 3, order=t) - sage: f = x + y; f.lm() # indirect doctest + sage: P. = PolynomialRing(QQbar, 3, order=t) # optional - sage.rings.number_field + sage: f = x + y; f.lm() # indirect doctest # optional - sage.rings.number_field y - sage: f = x + y^2*z; f.lm() + sage: f = x + y^2*z; f.lm() # optional - sage.rings.number_field y^2*z This method is called by the lm/lc/lt methods of @@ -1511,12 +1514,12 @@ def greater_tuple_negwdeglex(self,f,g): EXAMPLES:: sage: t = TermOrder('negwdeglex',(1,2,3)) - sage: P. = PolynomialRing(QQbar, 3, order=t) - sage: f = x + y; f.lm() # indirect doctest + sage: P. = PolynomialRing(QQbar, 3, order=t) # optional - sage.rings.number_field + sage: f = x + y; f.lm() # indirect doctest # optional - sage.rings.number_field x - sage: f = x + x^2; f.lm() + sage: f = x + x^2; f.lm() # optional - sage.rings.number_field x - sage: f = x^3 + z; f.lm() + sage: f = x^3 + z; f.lm() # optional - sage.rings.number_field x^3 This method is called by the lm/lc/lt methods of @@ -1540,12 +1543,12 @@ def greater_tuple_negwdegrevlex(self,f,g): EXAMPLES:: sage: t = TermOrder('negwdegrevlex',(1,2,3)) - sage: P. = PolynomialRing(QQbar, 3, order=t) - sage: f = x + y; f.lm() # indirect doctest + sage: P. = PolynomialRing(QQbar, 3, order=t) # optional - sage.rings.number_field + sage: f = x + y; f.lm() # indirect doctest # optional - sage.rings.number_field x - sage: f = x + x^2; f.lm() + sage: f = x + x^2; f.lm() # optional - sage.rings.number_field x - sage: f = x^3 + z; f.lm() + sage: f = x^3 + z; f.lm() # optional - sage.rings.number_field x^3 This method is called by the lm/lc/lt methods of @@ -1571,10 +1574,11 @@ def greater_tuple_block(self, f,g): EXAMPLES:: - sage: P.=PolynomialRing(QQbar, 6, order='degrevlex(3),degrevlex(3)') - sage: f = a + c^4; f.lm() # indirect doctest + sage: P. = PolynomialRing(QQbar, 6, # optional - sage.rings.number_field + ....: order='degrevlex(3),degrevlex(3)') + sage: f = a + c^4; f.lm() # indirect doctest # optional - sage.rings.number_field c^4 - sage: g = a + e^4; g.lm() + sage: g = a + e^4; g.lm() # optional - sage.rings.number_field a """ n = 0 @@ -1600,9 +1604,9 @@ def tuple_weight(self, f): EXAMPLES:: - sage: t=TermOrder('wdeglex',(1,2,3)) - sage: P.=PolynomialRing(QQbar, order=t) - sage: P.term_order().tuple_weight([3,2,1]) + sage: t = TermOrder('wdeglex',(1,2,3)) + sage: P. = PolynomialRing(QQbar, order=t) # optional - sage.rings.number_field + sage: P.term_order().tuple_weight([3,2,1]) # optional - sage.rings.number_field 10 """ return sum(l*r for (l,r) in zip(f,self._weights)) @@ -1641,17 +1645,18 @@ def _repr_(self): def singular_str(self): """ - Return a SINGULAR representation of self. + Return a SINGULAR representation of ``self``. Used to convert polynomial rings to their SINGULAR representation. EXAMPLES:: - sage: P = PolynomialRing(GF(127),10,names='x',order='lex(3),deglex(5),lex(2)') - sage: T = P.term_order() - sage: T.singular_str() + sage: P = PolynomialRing(GF(127), 10, names='x', # optional - sage.rings.finite_rings + ....: order='lex(3),deglex(5),lex(2)') + sage: T = P.term_order() # optional - sage.rings.finite_rings + sage: T.singular_str() # optional - sage.rings.finite_rings '(lp(3),Dp(5),lp(2))' - sage: P._singular_() + sage: P._singular_() # optional - sage.rings.finite_rings polynomial ring, over a field, global ordering // coefficients: ZZ/127 // number of vars : 10 @@ -1677,7 +1682,7 @@ def singular_str(self): sage: T = P.term_order() sage: T.singular_str() '(a(1:2),ls(2),a(1:2),ls(2))' - sage: P._singular_() + sage: P._singular_() # optional - sage.libs.singular polynomial ring, over a field, global ordering // coefficients: QQ // number of vars : 4 @@ -1699,7 +1704,7 @@ def singular_str(self): sage: T = TermOrder("degneglex", 2) + TermOrder("degneglex", 2) sage: T._singular_ringorder_column = 0 sage: P = PolynomialRing(QQ, 4, names='x', order=T) - sage: P._singular_() + sage: P._singular_() # optional - sage.libs.singular polynomial ring, over a field, global ordering // coefficients: QQ // number of vars : 4 @@ -1717,7 +1722,7 @@ def singular_str(self): sage: T._singular_ringorder_column = 1 sage: P = PolynomialRing(QQ, 4, names='y', order=T) - sage: P._singular_() + sage: P._singular_() # optional - sage.libs.singular polynomial ring, over a field, global ordering // coefficients: QQ // number of vars : 4 @@ -1735,7 +1740,7 @@ def singular_str(self): sage: T._singular_ringorder_column = 2 sage: P = PolynomialRing(QQ, 4, names='z', order=T) - sage: P._singular_() + sage: P._singular_() # optional - sage.libs.singular polynomial ring, over a field, global ordering // coefficients: QQ // number of vars : 4 @@ -1770,21 +1775,24 @@ def singular_str(self): def singular_moreblocks(self): """ Return a the number of additional blocks SINGULAR needs to allocate - for handling non-native orderings like `degneglex`. + for handling non-native orderings like ``degneglex``. EXAMPLES:: - sage: P = PolynomialRing(GF(127),10,names='x',order='lex(3),deglex(5),lex(2)') - sage: T = P.term_order() - sage: T.singular_moreblocks() + sage: P = PolynomialRing(GF(127), 10, names='x', # optional - sage.rings.finite_rings + ....: order='lex(3),deglex(5),lex(2)') + sage: T = P.term_order() # optional - sage.rings.finite_rings + sage: T.singular_moreblocks() # optional - sage.rings.finite_rings 0 - sage: P = PolynomialRing(GF(127),10,names='x',order='lex(3),degneglex(5),lex(2)') - sage: T = P.term_order() - sage: T.singular_moreblocks() + sage: P = PolynomialRing(GF(127), 10, names='x', # optional - sage.rings.finite_rings + ....: order='lex(3),degneglex(5),lex(2)') + sage: T = P.term_order() # optional - sage.rings.finite_rings + sage: T.singular_moreblocks() # optional - sage.rings.finite_rings 1 - sage: P = PolynomialRing(GF(127),10,names='x',order='degneglex(5),degneglex(5)') - sage: T = P.term_order() - sage: T.singular_moreblocks() + sage: P = PolynomialRing(GF(127), 10, names='x', # optional - sage.rings.finite_rings + ....: order='degneglex(5),degneglex(5)') + sage: T = P.term_order() # optional - sage.rings.finite_rings + sage: T.singular_moreblocks() # optional - sage.rings.finite_rings 2 TESTS: @@ -1807,18 +1815,19 @@ def singular_moreblocks(self): def macaulay2_str(self): """ - Return a Macaulay2 representation of self. + Return a Macaulay2 representation of ``self``. Used to convert polynomial rings to their Macaulay2 representation. EXAMPLES:: - sage: P = PolynomialRing(GF(127), 8,names='x',order='degrevlex(3),lex(5)') - sage: T = P.term_order() - sage: T.macaulay2_str() + sage: P = PolynomialRing(GF(127), 8, names='x', # optional - sage.rings.finite_rings + ....: order='degrevlex(3),lex(5)') + sage: T = P.term_order() # optional - sage.rings.finite_rings + sage: T.macaulay2_str() # optional - sage.rings.finite_rings '{GRevLex => 3,Lex => 5}' - sage: P._macaulay2_().options()['MonomialOrder'] # optional - macaulay2 + sage: P._macaulay2_().options()['MonomialOrder'] # optional - macaulay2 # optional - sage.rings.finite_rings {MonomialSize => 16 } {GRevLex => {1, 1, 1}} {Lex => 5 } @@ -1828,29 +1837,29 @@ def macaulay2_str(self): def magma_str(self): """ - Return a MAGMA representation of self. + Return a MAGMA representation of ``self``. Used to convert polynomial rings to their MAGMA representation. EXAMPLES:: - sage: P = PolynomialRing(GF(127), 10,names='x',order='degrevlex') - sage: magma(P) # optional - magma + sage: P = PolynomialRing(GF(127), 10, names='x', order='degrevlex') # optional - sage.rings.finite_rings + sage: magma(P) # optional - magma # optional - sage.rings.finite_rings Polynomial ring of rank 10 over GF(127) Order: Graded Reverse Lexicographical Variables: x0, x1, x2, x3, x4, x5, x6, x7, x8, x9 :: - sage: T = P.term_order() - sage: T.magma_str() + sage: T = P.term_order() # optional - sage.rings.finite_rings + sage: T.magma_str() # optional - sage.rings.finite_rings '"grevlex"' """ return self._magma_str def blocks(self): """ - Return the term order blocks of self. + Return the term order blocks of ``self``. NOTE: @@ -1860,7 +1869,7 @@ def blocks(self): EXAMPLES:: - sage: t=TermOrder('deglex',2)+TermOrder('lex',2) + sage: t = TermOrder('deglex',2) + TermOrder('lex',2) sage: t.blocks() (Degree lexicographic term order, Lexicographic term order) """ @@ -1875,8 +1884,8 @@ def matrix(self): EXAMPLES:: - sage: t = TermOrder("M(1,2,0,1)") - sage: t.matrix() + sage: t = TermOrder("M(1,2,0,1)") # optional - sage.modules + sage: t.matrix() # optional - sage.modules [1 2] [0 1] @@ -1889,7 +1898,7 @@ def weights(self): EXAMPLES:: - sage: t=TermOrder('wdeglex',(2,3)) + sage: t = TermOrder('wdeglex',(2,3)) sage: t.weights() (2, 3) """ @@ -1897,7 +1906,7 @@ def weights(self): def __eq__(self, other): """ - Return true if self and other are equal. + Return ``True`` if ``self`` and ``other`` are equal. EXAMPLES:: @@ -1911,15 +1920,15 @@ def __eq__(self, other): :: - sage: T1 = TermOrder('lex',2)+TermOrder('lex',3) - sage: T2 = TermOrder('lex',3)+TermOrder('lex',2) + sage: T1 = TermOrder('lex',2) + TermOrder('lex',3) + sage: T2 = TermOrder('lex',3) + TermOrder('lex',2) sage: T1 == T2 False :: - sage: T1 = TermOrder('lex',2)+TermOrder('neglex',3) - sage: T2 = TermOrder('lex',2)+TermOrder('neglex',3) + sage: T1 = TermOrder('lex',2) + TermOrder('neglex',3) + sage: T2 = TermOrder('lex',2) + TermOrder('neglex',3) sage: T1 == T2 True @@ -1953,12 +1962,12 @@ def __eq__(self, other): def __ne__(self, other): """ - Return true if self and other are not equal. + Return ``True`` if ``self`` and ``other`` are not equal. EXAMPLES:: - sage: T1 = TermOrder('lex',2)+TermOrder('lex',3) - sage: T2 = TermOrder('lex',3)+TermOrder('lex',2) + sage: T1 = TermOrder('lex',2) + TermOrder('lex',3) + sage: T2 = TermOrder('lex',3) + TermOrder('lex',2) sage: T1 != T2 True """ @@ -2063,7 +2072,7 @@ def __iter__(self): def is_global(self): r""" - Return true if this term order is definitely + Return ``True`` if this term order is definitely global. Return false otherwise, which includes unknown term orders. @@ -2095,7 +2104,7 @@ def is_global(self): def is_local(self): r""" - Return true if this term order is definitely + Return ``True`` if this term order is definitely local. Return false otherwise, which includes unknown term orders. @@ -2122,11 +2131,11 @@ def is_local(self): def is_block_order(self): """ - Return true if self is a block term order. + Return ``True`` if ``self`` is a block term order. EXAMPLES:: - sage: t=TermOrder('deglex',2)+TermOrder('lex',2) + sage: t = TermOrder('deglex',2) + TermOrder('lex',2) sage: t.is_block_order() True """ @@ -2134,11 +2143,11 @@ def is_block_order(self): def is_weighted_degree_order(self): """ - Return true if self is a weighted degree term order. + Return ``True`` if ``self`` is a weighted degree term order. EXAMPLES:: - sage: t=TermOrder('wdeglex',(2,3)) + sage: t = TermOrder('wdeglex',(2,3)) sage: t.is_weighted_degree_order() True """ @@ -2156,13 +2165,13 @@ def termorder_from_singular(S): EXAMPLES:: sage: from sage.rings.polynomial.term_order import termorder_from_singular - sage: singular.eval('ring r1 = (9,x),(a,b,c,d,e,f),(M((1,2,3,0)),wp(2,3),lp)') + sage: singular.eval('ring r1 = (9,x),(a,b,c,d,e,f),(M((1,2,3,0)),wp(2,3),lp)') # optional - sage.libs.singular '' - sage: termorder_from_singular(singular) + sage: termorder_from_singular(singular) # optional - sage.libs.singular Block term order with blocks: (Matrix term order with matrix - [1 2] - [3 0], + [1 2] + [3 0], Weighted degree reverse lexicographic term order with weights (2, 3), Lexicographic term order of length 2) @@ -2170,7 +2179,7 @@ def termorder_from_singular(S): This information is reflected in ``_singular_ringorder_column`` attribute of the term order. :: - sage: singular.ring(0, '(x,y,z,w)', '(C,dp(2),lp(2))') + sage: singular.ring(0, '(x,y,z,w)', '(C,dp(2),lp(2))') # optional - sage.libs.singular polynomial ring, over a field, global ordering // coefficients: QQ // number of vars : 4 @@ -2179,15 +2188,15 @@ def termorder_from_singular(S): // : names x y // block 3 : ordering lp // : names z w - sage: T = termorder_from_singular(singular) - sage: T + sage: T = termorder_from_singular(singular) # optional - sage.libs.singular + sage: T # optional - sage.libs.singular Block term order with blocks: (Degree reverse lexicographic term order of length 2, Lexicographic term order of length 2) - sage: T._singular_ringorder_column + sage: T._singular_ringorder_column # optional - sage.libs.singular 0 - sage: singular.ring(0, '(x,y,z,w)', '(c,dp(2),lp(2))') + sage: singular.ring(0, '(x,y,z,w)', '(c,dp(2),lp(2))') # optional - sage.libs.singular polynomial ring, over a field, global ordering // coefficients: QQ // number of vars : 4 @@ -2196,12 +2205,12 @@ def termorder_from_singular(S): // : names x y // block 3 : ordering lp // : names z w - sage: T = termorder_from_singular(singular) - sage: T + sage: T = termorder_from_singular(singular) # optional - sage.libs.singular + sage: T # optional - sage.libs.singular Block term order with blocks: (Degree reverse lexicographic term order of length 2, Lexicographic term order of length 2) - sage: T._singular_ringorder_column + sage: T._singular_ringorder_column # optional - sage.libs.singular 1 TESTS: @@ -2209,16 +2218,16 @@ def termorder_from_singular(S): Check that ``degneglex`` term orders are converted correctly (:trac:`29635`):: - sage: _ = singular.ring(0, '(x,y,z,w)', '(a(1:4),ls(4))') - sage: termorder_from_singular(singular).singular_str() + sage: _ = singular.ring(0, '(x,y,z,w)', '(a(1:4),ls(4))') # optional - sage.libs.singular + sage: termorder_from_singular(singular).singular_str() # optional - sage.libs.singular '(a(1:4),ls(4))' - sage: _ = singular.ring(0, '(x,y,z,w)', '(a(1:2),ls(2),a(1:2),ls(2))') - sage: termorder_from_singular(singular).singular_str() + sage: _ = singular.ring(0, '(x,y,z,w)', '(a(1:2),ls(2),a(1:2),ls(2))') # optional - sage.libs.singular + sage: termorder_from_singular(singular).singular_str() # optional - sage.libs.singular '(a(1:2),ls(2),a(1:2),ls(2))' - sage: _ = singular.ring(0, '(x,y,z,w)', '(a(1:2),ls(2),C,a(1:2),ls(2))') - sage: termorder_from_singular(singular).singular_str() + sage: _ = singular.ring(0, '(x,y,z,w)', '(a(1:2),ls(2),C,a(1:2),ls(2))') # optional - sage.libs.singular + sage: termorder_from_singular(singular).singular_str() # optional - sage.libs.singular '(a(1:2),ls(2),C,a(1:2),ls(2))' - sage: PolynomialRing(QQ, 'x,y', order='degneglex')('x^2')._singular_().sage() + sage: PolynomialRing(QQ, 'x,y', order='degneglex')('x^2')._singular_().sage() # optional - sage.libs.singular x^2 """ from sage.rings.integer_ring import ZZ diff --git a/src/sage/rings/polynomial/toy_buchberger.py b/src/sage/rings/polynomial/toy_buchberger.py index 2f02ca65e05..c70cf1f90aa 100644 --- a/src/sage/rings/polynomial/toy_buchberger.py +++ b/src/sage/rings/polynomial/toy_buchberger.py @@ -24,39 +24,40 @@ Consider Katsura-6 with respect to a ``degrevlex`` ordering. :: sage: from sage.rings.polynomial.toy_buchberger import * - sage: P. = PolynomialRing(GF(32003)) - sage: I = sage.rings.ideal.Katsura(P, 6) + sage: P. = PolynomialRing(GF(32003)) # optional - sage.rings.finite_rings + sage: I = sage.rings.ideal.Katsura(P, 6) # optional - sage.rings.finite_rings - sage: g1 = buchberger(I) - sage: g2 = buchberger_improved(I) - sage: g3 = I.groebner_basis() + sage: g1 = buchberger(I) # optional - sage.rings.finite_rings + sage: g2 = buchberger_improved(I) # optional - sage.rings.finite_rings + sage: g3 = I.groebner_basis() # optional - sage.rings.finite_rings All algorithms actually compute a Groebner basis:: - sage: Ideal(g1).basis_is_groebner() + sage: Ideal(g1).basis_is_groebner() # optional - sage.rings.finite_rings True - sage: Ideal(g2).basis_is_groebner() + sage: Ideal(g2).basis_is_groebner() # optional - sage.rings.finite_rings True - sage: Ideal(g3).basis_is_groebner() + sage: Ideal(g3).basis_is_groebner() # optional - sage.rings.finite_rings True The results are correct:: - sage: Ideal(g1) == Ideal(g2) == Ideal(g3) + sage: Ideal(g1) == Ideal(g2) == Ideal(g3) # optional - sage.rings.finite_rings True If ``get_verbose()`` is `\ge 1`, a protocol is provided:: sage: from sage.misc.verbose import set_verbose sage: set_verbose(1) - sage: P. = PolynomialRing(GF(127)) - sage: I = sage.rings.ideal.Katsura(P) + sage: P. = PolynomialRing(GF(127)) # optional - sage.rings.finite_rings + sage: I = sage.rings.ideal.Katsura(P) # optional - sage.rings.finite_rings // sage... ideal - sage: I - Ideal (a + 2*b + 2*c - 1, a^2 + 2*b^2 + 2*c^2 - a, 2*a*b + 2*b*c - b) of Multivariate Polynomial Ring in a, b, c over Finite Field of size 127 + sage: I # optional - sage.rings.finite_rings + Ideal (a + 2*b + 2*c - 1, a^2 + 2*b^2 + 2*c^2 - a, 2*a*b + 2*b*c - b) + of Multivariate Polynomial Ring in a, b, c over Finite Field of size 127 - sage: buchberger(I) # random + sage: buchberger(I) # random # optional - sage.rings.finite_rings (a + 2*b + 2*c - 1, a^2 + 2*b^2 + 2*c^2 - a) => -2*b^2 - 6*b*c - 6*c^2 + b + 2*c G: set([a + 2*b + 2*c - 1, 2*a*b + 2*b*c - b, a^2 + 2*b^2 + 2*c^2 - a, -2*b^2 - 6*b*c - 6*c^2 + b + 2*c]) @@ -117,18 +118,19 @@ The original Buchberger algorithm performs 15 useless reductions to zero for this example:: - sage: gb = buchberger(I) + sage: gb = buchberger(I) # optional - sage.rings.finite_rings ... 15 reductions to zero. The 'improved' Buchberger algorithm in contrast only performs 1 reduction to zero:: - sage: gb = buchberger_improved(I) + sage: gb = buchberger_improved(I) # optional - sage.rings.finite_rings ... 1 reductions to zero. - sage: sorted(gb) - [a + 2*b + 2*c - 1, b*c + 52*c^2 + 38*b + 25*c, b^2 - 26*c^2 - 51*b + 51*c, c^3 + 22*c^2 - 55*b + 49*c] + sage: sorted(gb) # optional - sage.rings.finite_rings + [a + 2*b + 2*c - 1, b*c + 52*c^2 + 38*b + 25*c, + b^2 - 26*c^2 - 51*b + 51*c, c^3 + 22*c^2 - 55*b + 49*c] AUTHORS: @@ -191,10 +193,10 @@ def buchberger(F): sage: R. = PolynomialRing(QQ) sage: I = R.ideal([x^2 - z - 1, z^2 - y - 1, x*y^2 - x - 1]) sage: set_verbose(0) - sage: gb = buchberger(I) - sage: gb.is_groebner() + sage: gb = buchberger(I) # optional - sage.libs.singular + sage: gb.is_groebner() # optional - sage.libs.singular True - sage: gb.ideal() == I + sage: gb.ideal() == I # optional - sage.libs.singular True """ G = set(F.gens()) @@ -249,7 +251,7 @@ def buchberger_improved(F): sage: from sage.rings.polynomial.toy_buchberger import buchberger_improved sage: R. = PolynomialRing(QQ) sage: set_verbose(0) - sage: sorted(buchberger_improved(R.ideal([x^4 - y - z, x*y*z - 1]))) + sage: sorted(buchberger_improved(R.ideal([x^4 - y - z, x*y*z - 1]))) # optional - sage.libs.singular [x*y*z - 1, x^3 - y^2*z - y*z^2, y^3*z^2 + y^2*z^3 - x^2] """ F = inter_reduction(F.gens()) @@ -382,8 +384,8 @@ def select(P): sage: from sage.rings.polynomial.toy_buchberger import select sage: R. = PolynomialRing(QQ, order='lex') - sage: ps = [x^3 - z -1, z^3 - y - 1, x^5 - y - 2] - sage: pairs = [[ps[i], ps[j]] for i in range(3) for j in range(i+1, 3)] + sage: ps = [x^3 - z - 1, z^3 - y - 1, x^5 - y - 2] + sage: pairs = [[ps[i], ps[j]] for i in range(3) for j in range(i + 1, 3)] sage: select(pairs) [x^3 - z - 1, -y + z^3 - 1] """ @@ -401,10 +403,10 @@ def inter_reduction(Q): OUTPUT: - if ``Q`` is the set `(f_1, ..., f_n)`, this method returns `(g_1, - ..., g_s)` such that: + if ``Q`` is the set `f_1, ..., f_n`, this method returns `g_1, + ..., g_s` such that: - - ` = ` + - `(f_1,...,f_n) = (g_1,...,g_s)` - `LM(g_i) \neq LM(g_j)` for all `i \neq j` - `LM(g_i)` does not divide `m` for all monomials `m` of `\{g_1,...,g_{i-1}, g_{i+1},...,g_s\}` @@ -419,10 +421,10 @@ def inter_reduction(Q): :: sage: P. = QQ[] - sage: reduced = inter_reduction(set([x^2 - 5*y^2, x^3])) - sage: reduced == set([x*y^2, x^2-5*y^2]) + sage: reduced = inter_reduction(set([x^2 - 5*y^2, x^3])) # optional - sage.libs.singular + sage: reduced == set([x*y^2, x^2 - 5*y^2]) # optional - sage.libs.singular True - sage: reduced == inter_reduction(set([2*(x^2 - 5*y^2), x^3])) + sage: reduced == inter_reduction(set([2*(x^2 - 5*y^2), x^3])) # optional - sage.libs.singular True """ if not Q: diff --git a/src/sage/rings/polynomial/toy_d_basis.py b/src/sage/rings/polynomial/toy_d_basis.py index 07f83100df7..660922aaf64 100644 --- a/src/sage/rings/polynomial/toy_d_basis.py +++ b/src/sage/rings/polynomial/toy_d_basis.py @@ -20,12 +20,12 @@ First, consider an example from arithmetic geometry:: sage: A. = PolynomialRing(ZZ, 2) - sage: B. = PolynomialRing(Rationals(),2) + sage: B. = PolynomialRing(Rationals(), 2) sage: f = -y^2 - y + x^3 + 7*x + 1 sage: fx = f.derivative(x) sage: fy = f.derivative(y) - sage: I = B.ideal([B(f),B(fx),B(fy)]) - sage: I.groebner_basis() + sage: I = B.ideal([B(f), B(fx), B(fy)]) + sage: I.groebner_basis() # optional - sage.libs.singular [1] Since the output is 1, we know that there are no generic @@ -34,7 +34,7 @@ To look at the singularities of the arithmetic surface, we need to do the corresponding computation over `\ZZ`:: - sage: I = A.ideal([f,fx,fy]) + sage: I = A.ideal([f, fx, fy]) sage: gb = d_basis(I); gb [x - 2020, y - 11313, 22627] @@ -52,7 +52,7 @@ Another example. This one is from the Magma Handbook:: sage: P. = PolynomialRing(IntegerRing(), 3, order='lex') - sage: I = ideal( x^2 - 1, y^2 - 1, 2*x*y - z) + sage: I = ideal(x^2 - 1, y^2 - 1, 2*x*y - z) sage: I = Ideal(d_basis(I)) sage: x.reduce(I) x @@ -61,7 +61,7 @@ To compute modulo 4, we can add the generator 4 to our basis.:: - sage: I = ideal( x^2 - 1, y^2 - 1, 2*x*y - z, 4) + sage: I = ideal(x^2 - 1, y^2 - 1, 2*x*y - z, 4) sage: gb = d_basis(I) sage: R = P.change_ring(IntegerModRing(4)) sage: gb = [R(f) for f in gb if R(f)]; gb @@ -79,7 +79,7 @@ there are 4 equations in 3 unknowns). :: sage: P. = PolynomialRing(IntegerRing(), 3, order='degneglex') - sage: I = ideal( x^2 - 3*y, y^3 - x*y, z^3 - x, x^4 - y*z + 1 ) + sage: I = ideal(x^2 - 3*y, y^3 - x*y, z^3 - x, x^4 - y*z + 1) sage: I.change_ring(P.change_ring(RationalField())).groebner_basis() [1] @@ -96,19 +96,19 @@ sage: factor(282687803443) 101 * 103 * 27173681 - sage: I.change_ring( P.change_ring( GF(101) ) ).groebner_basis() + sage: I.change_ring(P.change_ring(GF(101))).groebner_basis() [z - 33, y + 48, x + 19] - sage: I.change_ring( P.change_ring( GF(103) ) ).groebner_basis() + sage: I.change_ring(P.change_ring(GF(103))).groebner_basis() [z - 18, y + 8, x + 39] - sage: I.change_ring( P.change_ring( GF(27173681) ) ).groebner_basis() + sage: I.change_ring( P.change_ring(GF(27173681))).groebner_basis() [z + 10380032, y + 3186055, x - 536027] Of course, modulo any other prime the Groebner basis is trivial so there are no other solutions. For example:: - sage: I.change_ring( P.change_ring( GF(3) ) ).groebner_basis() + sage: I.change_ring(P.change_ring(GF(3))).groebner_basis() [1] AUTHOR: diff --git a/src/sage/rings/polynomial/toy_variety.py b/src/sage/rings/polynomial/toy_variety.py index 3f2a1705989..16ccfb6cf8c 100644 --- a/src/sage/rings/polynomial/toy_variety.py +++ b/src/sage/rings/polynomial/toy_variety.py @@ -100,7 +100,7 @@ def coefficient_matrix(polys): sage: from sage.rings.polynomial.toy_variety import coefficient_matrix sage: R. = PolynomialRing(QQ) - sage: coefficient_matrix([x^2 + 1, y^2 + 1, x*y + 1]) + sage: coefficient_matrix([x^2 + 1, y^2 + 1, x*y + 1]) # optional - sage.modules [1 0 0 1] [0 0 1 1] [0 1 0 1] @@ -159,12 +159,12 @@ def is_linearly_dependent(polys) -> bool: sage: R. = PolynomialRing(QQ) sage: B = [x^2 + 1, y^2 + 1, x*y + 1] sage: p = 3*B[0] - 2*B[1] + B[2] - sage: is_linearly_dependent(B + [p]) + sage: is_linearly_dependent(B + [p]) # optional - sage.modules True - sage: p = x*B[0] - sage: is_linearly_dependent(B + [p]) + sage: p = x*B[0] # optional - sage.modules + sage: is_linearly_dependent(B + [p]) # optional - sage.modules False - sage: is_linearly_dependent([]) + sage: is_linearly_dependent([]) # optional - sage.modules False """ if not polys: @@ -204,10 +204,10 @@ def linear_representation(p, polys): EXAMPLES:: sage: from sage.rings.polynomial.toy_variety import linear_representation - sage: R. = PolynomialRing(GF(32003)) - sage: B = [x^2 + 1, y^2 + 1, x*y + 1] - sage: p = 3*B[0] - 2*B[1] + B[2] - sage: linear_representation(p, B) + sage: R. = PolynomialRing(GF(32003)) # optional - sage.rings.finite_rings + sage: B = [x^2 + 1, y^2 + 1, x*y + 1] # optional - sage.rings.finite_rings + sage: p = 3*B[0] - 2*B[1] + B[2] # optional - sage.rings.finite_rings + sage: linear_representation(p, B) # optional - sage.rings.finite_rings [3, 32001, 1] """ from sage.matrix.constructor import diagonal_matrix @@ -243,12 +243,12 @@ def triangular_factorization(B, n=-1): sage: from sage.misc.verbose import set_verbose sage: set_verbose(0) sage: from sage.rings.polynomial.toy_variety import triangular_factorization - sage: R. = PolynomialRing(GF(32003)) - sage: p1 = x^2*(x-1)^3*y^2*(z-3)^3 - sage: p2 = z^2 - z - sage: p3 = (x-2)^2*(y-1)^3 - sage: I = R.ideal(p1,p2,p3) - sage: triangular_factorization(I.groebner_basis()) + sage: R. = PolynomialRing(GF(32003)) # optional - sage.rings.finite_rings + sage: p1 = x^2*(x-1)^3*y^2*(z-3)^3 # optional - sage.rings.finite_rings + sage: p2 = z^2 - z # optional - sage.rings.finite_rings + sage: p3 = (x-2)^2*(y-1)^3 # optional - sage.rings.finite_rings + sage: I = R.ideal(p1,p2,p3) # optional - sage.rings.finite_rings + sage: triangular_factorization(I.groebner_basis()) # optional - sage.rings.finite_rings [[x^2 - 4*x + 4, y, z], [x^5 - 3*x^4 + 3*x^3 - x^2, y - 1, z], [x^2 - 4*x + 4, y, z - 1], @@ -317,12 +317,12 @@ def elim_pol(B, n=-1): sage: from sage.misc.verbose import set_verbose sage: set_verbose(0) sage: from sage.rings.polynomial.toy_variety import elim_pol - sage: R. = PolynomialRing(GF(32003)) - sage: p1 = x^2*(x-1)^3*y^2*(z-3)^3 - sage: p2 = z^2 - z - sage: p3 = (x-2)^2*(y-1)^3 - sage: I = R.ideal(p1,p2,p3) - sage: elim_pol(I.groebner_basis()) + sage: R. = PolynomialRing(GF(32003)) # optional - sage.rings.finite_rings + sage: p1 = x^2*(x-1)^3*y^2*(z-3)^3 # optional - sage.rings.finite_rings + sage: p2 = z^2 - z # optional - sage.rings.finite_rings + sage: p3 = (x-2)^2*(y-1)^3 # optional - sage.rings.finite_rings + sage: I = R.ideal(p1,p2,p3) # optional - sage.rings.finite_rings + sage: elim_pol(I.groebner_basis()) # optional - sage.rings.finite_rings z^2 - z """ # type checking in a probably vain attempt to avoid stupid errors diff --git a/src/sage/rings/power_series_poly.pyx b/src/sage/rings/power_series_poly.pyx index d3546fc0c72..6b7dcce74ab 100644 --- a/src/sage/rings/power_series_poly.pyx +++ b/src/sage/rings/power_series_poly.pyx @@ -105,9 +105,9 @@ cdef class PowerSeries_poly(PowerSeries): EXAMPLES:: - sage: R. = GF(7)[[]] - sage: f = 3 - t^3 + O(t^5) - sage: f.polynomial() + sage: R. = GF(7)[[]] # optional - sage.rings.finite_rings + sage: f = 3 - t^3 + O(t^5) # optional - sage.rings.finite_rings + sage: f.polynomial() # optional - sage.rings.finite_rings 6*t^3 + 3 """ return self.__f @@ -159,12 +159,12 @@ cdef class PowerSeries_poly(PowerSeries): EXAMPLES:: - sage: R. = GF(11)[[]] - sage: bool(1 + t + O(t^18)) + sage: R. = GF(11)[[]] # optional - sage.rings.finite_rings + sage: bool(1 + t + O(t^18)) # optional - sage.rings.finite_rings True - sage: bool(R(0)) + sage: bool(R(0)) # optional - sage.rings.finite_rings False - sage: bool(O(t^18)) + sage: bool(O(t^18)) # optional - sage.rings.finite_rings False """ return not not self.__f @@ -225,17 +225,17 @@ cdef class PowerSeries_poly(PowerSeries): A series defined over another ring can be substituted:: - sage: S. = GF(7)[[]] - sage: f(2*u + u^3 + O(u^5)) + sage: S. = GF(7)[[]] # optional - sage.rings.finite_rings + sage: f(2*u + u^3 + O(u^5)) # optional - sage.rings.finite_rings 4*u^2 + u^3 + 4*u^4 + 5*u^5 + O(u^6) As can a p-adic integer as long as the coefficient ring is compatible:: - sage: f(100 + O(5^7)) + sage: f(100 + O(5^7)) # optional - sage.rings.padics 5^4 + 3*5^5 + 4*5^6 + 2*5^7 + 2*5^8 + O(5^9) - sage: f.change_ring(Zp(5))(100 + O(5^7)) + sage: f.change_ring(Zp(5))(100 + O(5^7)) # optional - sage.rings.padics 5^4 + 3*5^5 + 4*5^6 + 2*5^7 + 2*5^8 + O(5^9) - sage: f.change_ring(Zp(5))(100 + O(2^7)) + sage: f.change_ring(Zp(5))(100 + O(2^7)) # optional - sage.rings.padics Traceback (most recent call last): ... ValueError: Cannot substitute this value @@ -248,7 +248,7 @@ cdef class PowerSeries_poly(PowerSeries): Traceback (most recent call last): ... ValueError: Can only substitute elements of positive valuation - sage: f(2 + O(5^3)) + sage: f(2 + O(5^3)) # optional - sage.rings.padics Traceback (most recent call last): ... ValueError: Can only substitute elements of positive valuation @@ -268,18 +268,18 @@ cdef class PowerSeries_poly(PowerSeries): Arguments beyond the first can refer to the base ring:: - sage: P. = GF(5)[] - sage: Q. = P[[]] - sage: h = (1 - x*y)^-1 + O(y^7); h + sage: P. = GF(5)[] # optional - sage.rings.finite_rings + sage: Q. = P[[]] # optional - sage.rings.finite_rings + sage: h = (1 - x*y)^-1 + O(y^7); h # optional - sage.rings.finite_rings 1 + x*y + x^2*y^2 + x^3*y^3 + x^4*y^4 + x^5*y^5 + x^6*y^6 + O(y^7) - sage: h(y^2, 3) + sage: h(y^2, 3) # optional - sage.rings.finite_rings 1 + 3*y^2 + 4*y^4 + 2*y^6 + y^8 + 3*y^10 + 4*y^12 + O(y^14) These secondary values can also be specified using keywords:: - sage: h(y=y^2, x=3) + sage: h(y=y^2, x=3) # optional - sage.rings.finite_rings 1 + 3*y^2 + 4*y^4 + 2*y^6 + y^8 + 3*y^10 + 4*y^12 + O(y^14) - sage: h(y^2, x=3) + sage: h(y^2, x=3) # optional - sage.rings.finite_rings 1 + 3*y^2 + 4*y^4 + 2*y^6 + y^8 + 3*y^10 + 4*y^12 + O(y^14) """ P = self.parent() @@ -375,27 +375,27 @@ cdef class PowerSeries_poly(PowerSeries): EXAMPLES:: - sage: R. = GF(7)[[]] - sage: f = 3 + 6*t^3 + O(t^5) - sage: f._unsafe_mutate(0, 5) - sage: f + sage: R. = GF(7)[[]] # optional - sage.rings.finite_rings + sage: f = 3 + 6*t^3 + O(t^5) # optional - sage.rings.finite_rings + sage: f._unsafe_mutate(0, 5) # optional - sage.rings.finite_rings + sage: f # optional - sage.rings.finite_rings 5 + 6*t^3 + O(t^5) - sage: f._unsafe_mutate(2, 1) ; f + sage: f._unsafe_mutate(2, 1) ; f # optional - sage.rings.finite_rings 5 + t^2 + 6*t^3 + O(t^5) - Mutating can even bump up the precision:: - sage: f._unsafe_mutate(6, 1) ; f + sage: f._unsafe_mutate(6, 1) ; f # optional - sage.rings.finite_rings 5 + t^2 + 6*t^3 + t^6 + O(t^7) - sage: f._unsafe_mutate(0, 0) ; f + sage: f._unsafe_mutate(0, 0) ; f # optional - sage.rings.finite_rings t^2 + 6*t^3 + t^6 + O(t^7) - sage: f._unsafe_mutate(1, 0) ; f + sage: f._unsafe_mutate(1, 0) ; f # optional - sage.rings.finite_rings t^2 + 6*t^3 + t^6 + O(t^7) - sage: f._unsafe_mutate(11,0) ; f + sage: f._unsafe_mutate(11,0) ; f # optional - sage.rings.finite_rings t^2 + 6*t^3 + t^6 + O(t^12) - sage: g = t + O(t^7) - sage: g._unsafe_mutate(1,0) ; g + sage: g = t + O(t^7) # optional - sage.rings.finite_rings + sage: g._unsafe_mutate(1,0) ; g # optional - sage.rings.finite_rings O(t^7) """ self.__f._unsafe_mutate(i, value) @@ -554,9 +554,9 @@ cdef class PowerSeries_poly(PowerSeries): EXAMPLES:: - sage: R. = GF(7)[[]] - sage: f = t + 3*t^4 + O(t^11) - sage: f * GF(7)(3) + sage: R. = GF(7)[[]] # optional - sage.rings.finite_rings + sage: f = t + 3*t^4 + O(t^11) # optional - sage.rings.finite_rings + sage: f * GF(7)(3) # optional - sage.rings.finite_rings 3*t + 2*t^4 + O(t^11) """ return PowerSeries_poly(self._parent, self.__f * c, self._prec, check=False) @@ -567,9 +567,9 @@ cdef class PowerSeries_poly(PowerSeries): EXAMPLES:: - sage: R. = GF(11)[[]] - sage: f = 1 + 3*t^4 + O(t^120) - sage: 2 * f + sage: R. = GF(11)[[]] # optional - sage.rings.finite_rings + sage: f = 1 + 3*t^4 + O(t^120) # optional - sage.rings.finite_rings + sage: 2 * f # optional - sage.rings.finite_rings 2 + 6*t^4 + O(t^120) """ return PowerSeries_poly(self._parent, c * self.__f, self._prec, check=False) @@ -597,11 +597,11 @@ cdef class PowerSeries_poly(PowerSeries): EXAMPLES:: - sage: R. = GF(2)[[]] - sage: f = t + t^4 + O(t^7) - sage: f >> 1 + sage: R. = GF(2)[[]] # optional - sage.rings.finite_rings + sage: f = t + t^4 + O(t^7) # optional - sage.rings.finite_rings + sage: f >> 1 # optional - sage.rings.finite_rings 1 + t^3 + O(t^6) - sage: f >> 10 + sage: f >> 10 # optional - sage.rings.finite_rings O(t^0) """ if n: @@ -733,10 +733,10 @@ cdef class PowerSeries_poly(PowerSeries): EXAMPLES:: - sage: R. = GF(2)[[]] - sage: f = 1/(1+I+O(I^8)); f + sage: R. = GF(2)[[]] # optional - sage.rings.finite_rings + sage: f = 1/(1+I+O(I^8)); f # optional - sage.rings.finite_rings 1 + I + I^2 + I^3 + I^4 + I^5 + I^6 + I^7 + O(I^8) - sage: f.truncate(5) + sage: f.truncate(5) # optional - sage.rings.finite_rings I^4 + I^3 + I^2 + I + 1 """ if prec is infinity: @@ -764,10 +764,10 @@ cdef class PowerSeries_poly(PowerSeries): EXAMPLES:: - sage: R. = GF(2)[[]] - sage: f = 1/(1+I+O(I^8)); f + sage: R. = GF(2)[[]] # optional - sage.rings.finite_rings + sage: f = 1/(1+I+O(I^8)); f # optional - sage.rings.finite_rings 1 + I + I^2 + I^3 + I^4 + I^5 + I^6 + I^7 + O(I^8) - sage: f.truncate_powerseries(5) + sage: f.truncate_powerseries(5) # optional - sage.rings.finite_rings 1 + I + I^2 + I^3 + I^4 + O(I^5) """ return PowerSeries_poly(self._parent, self.__f.truncate(prec), @@ -845,8 +845,8 @@ cdef class PowerSeries_poly(PowerSeries): TESTS:: sage: R. = PowerSeriesRing(QQ, sparse=True) - sage: x = var('x') - sage: t.derivative(x) + sage: x = var('x') # optional - sage.symbolic + sage: t.derivative(x) # optional - sage.symbolic Traceback (most recent call last): ... ValueError: cannot differentiate with respect to x @@ -871,7 +871,7 @@ cdef class PowerSeries_poly(PowerSeries): By default, the integration variable is the variable of the power series. - Otherwise, the integration variable is the optional parameter ``var`` + Otherwise, the integration variable is the optional parameter ``var``. .. NOTE:: @@ -909,15 +909,15 @@ cdef class PowerSeries_poly(PowerSeries): def reverse(self, precision=None): """ - Return the reverse of f, i.e., the series g such that g(f(x)) = x. + Return the reverse of `f`, i.e., the series `g` such that `g(f(x)) = x`. Given an optional argument ``precision``, return the reverse with given precision (note that the reverse can have precision at most - ``f.prec()``). If ``f`` has infinite precision, and the argument + ``f.prec()``). If `f` has infinite precision, and the argument ``precision`` is not given, then the precision of the reverse defaults to the default precision of ``f.parent()``. - Note that this is only possible if the valuation of self is exactly + Note that this is only possible if the valuation of ``self`` is exactly 1. ALGORITHM: @@ -1019,7 +1019,10 @@ cdef class PowerSeries_poly(PowerSeries): sage: R. = PowerSeriesRing(QQ, default_prec=20) sage: (x - x^2).reverse() # get some Catalan numbers - x + x^2 + 2*x^3 + 5*x^4 + 14*x^5 + 42*x^6 + 132*x^7 + 429*x^8 + 1430*x^9 + 4862*x^10 + 16796*x^11 + 58786*x^12 + 208012*x^13 + 742900*x^14 + 2674440*x^15 + 9694845*x^16 + 35357670*x^17 + 129644790*x^18 + 477638700*x^19 + O(x^20) + x + x^2 + 2*x^3 + 5*x^4 + 14*x^5 + 42*x^6 + 132*x^7 + 429*x^8 + 1430*x^9 + + 4862*x^10 + 16796*x^11 + 58786*x^12 + 208012*x^13 + 742900*x^14 + + 2674440*x^15 + 9694845*x^16 + 35357670*x^17 + 129644790*x^18 + + 477638700*x^19 + O(x^20) sage: (x - x^2).reverse(precision=3) x + x^2 + O(x^3) @@ -1032,11 +1035,10 @@ cdef class PowerSeries_poly(PowerSeries): ... ValueError: Series must have valuation one for reversion. - sage: Series = PowerSeriesRing(SR, 'x') - sage: ser = Series([0, pi]) - sage: ser + sage: Series = PowerSeriesRing(SR, 'x') # optional - sage.symbolic + sage: ser = Series([0, pi]); ser # optional - sage.symbolic pi*x - sage: ser.reverse() + sage: ser.reverse() # optional - sage.symbolic 1/pi*x + O(x^20) """ if self.valuation() != 1: @@ -1195,19 +1197,19 @@ cdef class PowerSeries_poly(PowerSeries): EXAMPLES:: sage: R. = PowerSeriesRing(QQ) - sage: s = R([1,2,3,4,5],prec=10); s + sage: s = R([1,2,3,4,5], prec=10); s 1 + 2*x + 3*x^2 + 4*x^3 + 5*x^4 + O(x^10) - sage: SR(s) + sage: SR(s) # optional - sage.symbolic 1 + 2*x + 3*x^2 + 4*x^3 + 5*x^4 + Order(x^10) - sage: SR(s).is_terminating_series() + sage: SR(s).is_terminating_series() # optional - sage.symbolic False - sage: SR(s).variables() + sage: SR(s).variables() # optional - sage.symbolic (x,) sage: s = R([1,2,3,4,5]); s 1 + 2*x + 3*x^2 + 4*x^3 + 5*x^4 - sage: SR(s) + sage: SR(s) # optional - sage.symbolic 1 + 2*x + 3*x^2 + 4*x^3 + 5*x^4 - sage: _.is_terminating_series() + sage: _.is_terminating_series() # optional - sage.symbolic True TESTS: @@ -1215,7 +1217,7 @@ cdef class PowerSeries_poly(PowerSeries): Check that :trac:`18094` is fixed:: sage: R. = PolynomialRing(ZZ) - sage: SR(R(0).add_bigoh(20)) + sage: SR(R(0).add_bigoh(20)) # optional - sage.symbolic Order(x^20) """ from sage.symbolic.ring import SR diff --git a/src/sage/rings/power_series_ring.py b/src/sage/rings/power_series_ring.py index a65af81d061..65ed3311cd8 100644 --- a/src/sage/rings/power_series_ring.py +++ b/src/sage/rings/power_series_ring.py @@ -59,13 +59,13 @@ :: - sage: K. = PowerSeriesRing(SR, default_prec=5) - sage: a, b, c = var('a,b,c') - sage: f = a + b*t + c*t^2 + O(t^3) - sage: f*f + sage: K. = PowerSeriesRing(SR, default_prec=5) # optional - sage.symbolic + sage: a, b, c = var('a,b,c') # optional - sage.symbolic + sage: f = a + b*t + c*t^2 + O(t^3) # optional - sage.symbolic + sage: f*f # optional - sage.symbolic a^2 + 2*a*b*t + (b^2 + 2*a*c)*t^2 + O(t^3) - sage: f = sqrt(2) + sqrt(3)*t + O(t^3) - sage: f^2 + sage: f = sqrt(2) + sqrt(3)*t + O(t^3) # optional - sage.symbolic + sage: f^2 # optional - sage.symbolic 2 + 2*sqrt(3)*sqrt(2)*t + 3*t^2 + O(t^3) Elements are first coerced to constants in ``base_ring``, then coerced @@ -176,21 +176,21 @@ def PowerSeriesRing(base_ring, name=None, arg2=None, names=None, INPUT: - - ``base_ring`` - a commutative ring + - ``base_ring`` -- a commutative ring - - ``name``, ``names`` - name(s) of the indeterminate + - ``name``, ``names`` -- name(s) of the indeterminate - - ``default_prec`` - the default precision used if an exact object must + - ``default_prec`` -- the default precision used if an exact object must be changed to an approximate object in order to do an arithmetic operation. If left as ``None``, it will be set to the global default (20) in the univariate case, and 12 in the multivariate case. - - ``sparse`` - (default: ``False``) whether power series + - ``sparse`` -- (default: ``False``) whether power series are represented as sparse objects. - - ``order`` - (default: ``negdeglex``) term ordering, for multivariate case + - ``order`` -- (default: ``negdeglex``) term ordering, for multivariate case - - ``num_gens`` - number of generators, for multivariate case + - ``num_gens`` -- number of generators, for multivariate case There is a unique power series ring over each base ring with given @@ -216,7 +216,7 @@ def PowerSeriesRing(base_ring, name=None, arg2=None, names=None, :: - sage: S = PowerSeriesRing(QQ, 'x', default_prec = 15); S + sage: S = PowerSeriesRing(QQ, 'x', default_prec=15); S Power Series Ring in x over Rational Field sage: S.default_prec() 15 @@ -252,19 +252,19 @@ def PowerSeriesRing(base_ring, name=None, arg2=None, names=None, Power series ring over polynomial ring:: - sage: H = PowerSeriesRing(PolynomialRing(ZZ,3,'z'),4,'f'); H + sage: H = PowerSeriesRing(PolynomialRing(ZZ,3,'z'), 4, 'f'); H Multivariate Power Series Ring in f0, f1, f2, f3 over Multivariate Polynomial Ring in z0, z1, z2 over Integer Ring Power series ring over finite field:: - sage: S = PowerSeriesRing(GF(65537),'x,y'); S + sage: S = PowerSeriesRing(GF(65537),'x,y'); S # optional - sage.rings.finite_rings Multivariate Power Series Ring in x, y over Finite Field of size 65537 Power series ring with many variables:: - sage: R = PowerSeriesRing(ZZ, ['x%s'%p for p in primes(100)]); R + sage: R = PowerSeriesRing(ZZ, ['x%s'%p for p in primes(100)]); R # optional - sage.libs.pari Multivariate Power Series Ring in x2, x3, x5, x7, x11, x13, x17, x19, x23, x29, x31, x37, x41, x43, x47, x53, x59, x61, x67, x71, x73, x79, x83, x89, x97 over Integer Ring @@ -274,12 +274,12 @@ def PowerSeriesRing(base_ring, name=None, arg2=None, names=None, :: - sage: R.inject_variables() + sage: R.inject_variables() # optional - sage.libs.pari Defining x2, x3, x5, x7, x11, x13, x17, x19, x23, x29, x31, x37, x41, x43, x47, x53, x59, x61, x67, x71, x73, x79, x83, x89, x97 - sage: f = x47 + 3*x11*x29 - x19 + R.O(3) - sage: f in R + sage: f = x47 + 3*x11*x29 - x19 + R.O(3) # optional - sage.libs.pari + sage: f in R # optional - sage.libs.pari True @@ -450,7 +450,7 @@ def _single_variate(): def is_PowerSeriesRing(R): """ - Return True if this is a *univariate* power series ring. This is in + Return ``True`` if this is a *univariate* power series ring. This is in keeping with the behavior of ``is_PolynomialRing`` versus ``is_MPolynomialRing``. @@ -480,13 +480,13 @@ def __init__(self, base_ring, name=None, default_prec=None, sparse=False, INPUT: - - ``base_ring`` - a commutative ring + - ``base_ring`` -- a commutative ring - - ``name`` - name of the indeterminate + - ``name`` -- name of the indeterminate - - ``default_prec`` - the default precision + - ``default_prec`` -- the default precision - - ``sparse`` - whether or not power series are + - ``sparse`` -- whether or not power series are sparse - ``implementation`` -- either ``'poly'``, ``'mpoly'``, or @@ -519,11 +519,11 @@ def __init__(self, base_ring, name=None, default_prec=None, sparse=False, commutative ring, but also a complete discrete valuation ring (CDVR). The appropriate (sub)category is automatically set in this case:: - sage: k = GF(11) - sage: R. = k[[]] - sage: R.category() + sage: k = GF(11) # optional - sage.rings.finite_rings + sage: R. = k[[]] # optional - sage.rings.finite_rings + sage: R.category() # optional - sage.rings.finite_rings Category of complete discrete valuation rings - sage: TestSuite(R).run() + sage: TestSuite(R).run() # optional - sage.rings.finite_rings It is checked that the default precision is non-negative (see :trac:`19409`):: @@ -615,13 +615,13 @@ def _repr_(self): EXAMPLES:: - sage: R = GF(17)[['y']] - sage: R + sage: R = GF(17)[['y']] # optional - sage.rings.finite_rings + sage: R # optional - sage.rings.finite_rings Power Series Ring in y over Finite Field of size 17 - sage: R.__repr__() + sage: R.__repr__() # optional - sage.rings.finite_rings 'Power Series Ring in y over Finite Field of size 17' - sage: R.rename('my power series ring') - sage: R + sage: R.rename('my power series ring') # optional - sage.rings.finite_rings + sage: R # optional - sage.rings.finite_rings my power series ring """ s = "Power Series Ring in %s over %s"%(self.variable_name(), self.base_ring()) @@ -661,11 +661,11 @@ def _latex_(self): EXAMPLES:: - sage: R = GF(17)[['y']] - sage: latex(R) # indirect doctest + sage: R = GF(17)[['y']] # optional - sage.rings.finite_rings + sage: latex(R) # indirect doctest # optional - sage.rings.finite_rings \Bold{F}_{17}[[y]] - sage: R = GF(17)[['y12']] - sage: latex(R) + sage: R = GF(17)[['y12']] # optional - sage.rings.finite_rings + sage: latex(R) # optional - sage.rings.finite_rings \Bold{F}_{17}[[y_{12}]] """ return "%s[[%s]]"%(latex.latex(self.base_ring()), self.latex_variable_names()[0]) @@ -679,14 +679,14 @@ def _coerce_map_from_(self, S): EXAMPLES:: - sage: A = GF(17)[['x']] - sage: A.has_coerce_map_from(ZZ) # indirect doctest + sage: A = GF(17)[['x']] # optional - sage.rings.finite_rings + sage: A.has_coerce_map_from(ZZ) # indirect doctest # optional - sage.rings.finite_rings True - sage: A.has_coerce_map_from(ZZ['x']) + sage: A.has_coerce_map_from(ZZ['x']) # optional - sage.rings.finite_rings True - sage: A.has_coerce_map_from(ZZ['y']) + sage: A.has_coerce_map_from(ZZ['y']) # optional - sage.rings.finite_rings False - sage: A.has_coerce_map_from(ZZ[['x']]) + sage: A.has_coerce_map_from(ZZ[['x']]) # optional - sage.rings.finite_rings True """ @@ -706,12 +706,12 @@ def _element_constructor_(self, f, prec=infinity, check=True): INPUT: - - ``f`` - object, e.g., a power series ring element + - ``f`` -- object, e.g., a power series ring element - - ``prec`` - (default: infinity); truncation precision + - ``prec`` -- (default: infinity); truncation precision for coercion - - ``check`` - bool (default: True), whether to verify + - ``check`` -- bool (default: ``True``), whether to verify that the coefficients, etc., coerce in correctly. @@ -759,15 +759,15 @@ def _element_constructor_(self, f, prec=infinity, check=True): Conversion from symbolic series:: - sage: x,y = var('x,y') - sage: s=(1/(1-x)).series(x,3); s + sage: x,y = var('x,y') # optional - sage.symbolic + sage: s = (1/(1-x)).series(x,3); s # optional - sage.symbolic 1 + 1*x + 1*x^2 + Order(x^3) - sage: R. = PowerSeriesRing(QQ) - sage: R(s) + sage: R. = PowerSeriesRing(QQ) # optional - sage.symbolic + sage: R(s) # optional - sage.symbolic 1 + x + x^2 + O(x^3) - sage: ex=(gamma(1-y)).series(y,3) - sage: R. = PowerSeriesRing(SR) - sage: R(ex) + sage: ex = (gamma(1-y)).series(y,3) # optional - sage.symbolic + sage: R. = PowerSeriesRing(SR) # optional - sage.symbolic + sage: R(ex) # optional - sage.symbolic 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 @@ -823,7 +823,7 @@ def _element_constructor_(self, f, prec=infinity, check=True): def construction(self): """ - Return the functorial construction of self, namely, completion of + Return the functorial construction of ``self``, namely, completion of the univariate polynomial ring with respect to the indeterminate (to a given precision). @@ -891,18 +891,21 @@ def _coerce_impl(self, x): We illustrate canonical coercion between power series rings with compatible base rings:: - sage: R. = PowerSeriesRing(GF(7)['w']) + sage: R. = PowerSeriesRing(GF(7)['w']) # optional - sage.rings.finite_rings sage: S = PowerSeriesRing(ZZ, 't') sage: f = S([1,2,3,4]); f 1 + 2*t + 3*t^2 + 4*t^3 - sage: g = R.coerce(f); g + sage: g = R.coerce(f); g # optional - sage.rings.finite_rings 1 + 2*t + 3*t^2 + 4*t^3 - sage: parent(g) - Power Series Ring in t over Univariate Polynomial Ring in w over Finite Field of size 7 - sage: S.coerce(g) + sage: parent(g) # optional - sage.rings.finite_rings + Power Series Ring in t over + Univariate Polynomial Ring in w over Finite Field of size 7 + sage: S.coerce(g) # optional - sage.rings.finite_rings Traceback (most recent call last): ... - TypeError: no canonical coercion from Power Series Ring in t over Univariate Polynomial Ring in w over Finite Field of size 7 to Power Series Ring in t over Integer Ring + TypeError: no canonical coercion + from Power Series Ring in t over Univariate Polynomial Ring in w over Finite Field of size 7 + to Power Series Ring in t over Integer Ring """ try: P = x.parent() @@ -924,7 +927,7 @@ def _is_valid_homomorphism_(self, codomain, im_gens, base_map=None): EXAMPLES:: - sage: S = RationalField(); R.=PowerSeriesRing(S) + sage: S = RationalField(); R. = PowerSeriesRing(S) sage: f = R.hom([0]) sage: f(3) 3 @@ -972,17 +975,17 @@ def _poly_ring(self): def base_extend(self, R): """ - Return the power series ring over R in the same variable as self, - assuming there is a canonical coerce map from the base ring of self - to R. + Return the power series ring over `R` in the same variable as ``self``, + assuming there is a canonical coerce map from the base ring of ``self`` + to `R`. EXAMPLES:: - sage: R. = GF(7)[[]]; R + sage: R. = GF(7)[[]]; R # optional - sage.rings.finite_rings Power Series Ring in T over Finite Field of size 7 - sage: R.change_ring(ZZ) + sage: R.change_ring(ZZ) # optional - sage.rings.finite_rings Power Series Ring in T over Integer Ring - sage: R.base_extend(ZZ) + sage: R.base_extend(ZZ) # optional - sage.rings.finite_rings Traceback (most recent call last): ... TypeError: no base extension defined @@ -994,20 +997,21 @@ def base_extend(self, R): def change_ring(self, R): """ - Return the power series ring over R in the same variable as self. + Return the power series ring over `R` in the same variable as ``self``. EXAMPLES:: sage: R. = QQ[[]]; R Power Series Ring in T over Rational Field - sage: R.change_ring(GF(7)) + sage: R.change_ring(GF(7)) # optional - sage.rings.finite_rings Power Series Ring in T over Finite Field of size 7 - sage: R.base_extend(GF(7)) + sage: R.base_extend(GF(7)) # optional - sage.rings.finite_rings Traceback (most recent call last): ... TypeError: no base extension defined - sage: R.base_extend(QuadraticField(3,'a')) - Power Series Ring in T over Number Field in a with defining polynomial x^2 - 3 with a = 1.732050807568878? + sage: R.base_extend(QuadraticField(3,'a')) # optional - sage.rings.number_field + Power Series Ring in T over Number Field in a + with defining polynomial x^2 - 3 with a = 1.732050807568878? """ return PowerSeriesRing(R, name = self.variable_name(), default_prec = self.default_prec()) @@ -1026,7 +1030,7 @@ def change_var(self, var): def is_exact(self): """ - Return False since the ring of power series over any ring is not + Return ``False`` since the ring of power series over any ring is not exact. EXAMPLES:: @@ -1096,13 +1100,12 @@ def random_element(self, prec=None, *args, **kwds): r""" Return a random power series. - INPUT: - - ``prec`` - Integer specifying precision of output (default: - default precision of self) + - ``prec`` -- Integer specifying precision of output (default: + default precision of ``self``) - - ``*args, **kwds`` - Passed on to the ``random_element`` method for + - ``*args``, ``**kwds`` -- Passed on to the ``random_element`` method for the base ring OUTPUT: @@ -1111,7 +1114,6 @@ def random_element(self, prec=None, *args, **kwds): random elements from the base ring, randomized subject to the arguments ``*args`` and ``**kwds`` - ALGORITHM: Call the ``random_element`` method on the underlying polynomial @@ -1131,7 +1133,8 @@ def random_element(self, prec=None, *args, **kwds): sage: T.default_prec() 20 sage: T.random_element() # random - 4 + 2*t - t^2 - t^3 + 2*t^4 + t^5 + t^6 - 2*t^7 - t^8 - t^9 + t^11 - 6*t^12 + 2*t^14 + 2*t^16 - t^17 - 3*t^18 + O(t^20) + 4 + 2*t - t^2 - t^3 + 2*t^4 + t^5 + t^6 - 2*t^7 - t^8 - t^9 + t^11 + - 6*t^12 + 2*t^14 + 2*t^16 - t^17 - 3*t^18 + O(t^20) sage: S = PowerSeriesRing(ZZ,'t', default_prec=4) sage: S.random_element() # random 2 - t - 5*t^2 + t^3 + O(t^4) @@ -1144,7 +1147,9 @@ def random_element(self, prec=None, *args, **kwds): sage: SR = PowerSeriesRing(RR,'v') sage: SZ.random_element(x=4, y=6) # random - 4 + 5*v + 5*v^2 + 5*v^3 + 4*v^4 + 5*v^5 + 5*v^6 + 5*v^7 + 4*v^8 + 5*v^9 + 4*v^10 + 4*v^11 + 5*v^12 + 5*v^13 + 5*v^14 + 5*v^15 + 5*v^16 + 5*v^17 + 4*v^18 + 5*v^19 + O(v^20) + 4 + 5*v + 5*v^2 + 5*v^3 + 4*v^4 + 5*v^5 + 5*v^6 + 5*v^7 + 4*v^8 + + 5*v^9 + 4*v^10 + 4*v^11 + 5*v^12 + 5*v^13 + 5*v^14 + 5*v^15 + + 5*v^16 + 5*v^17 + 4*v^18 + 5*v^19 + O(v^20) sage: SZ.random_element(3, x=4, y=6) # random 5 + 4*v + 5*v^2 + O(v^3) sage: SQ.random_element(3, num_bound=3, den_bound=100) # random @@ -1159,7 +1164,7 @@ def random_element(self, prec=None, *args, **kwds): def __contains__(self, x): """ - Return True if x is an element of this power series ring or + Return ``True`` if x is an element of this power series ring or canonically coerces to this ring. EXAMPLES:: @@ -1181,7 +1186,7 @@ def __contains__(self, x): def is_field(self, proof = True): """ - Return False since the ring of power series over any ring is never + Return ``False`` since the ring of power series over any ring is never a field. EXAMPLES:: @@ -1194,7 +1199,7 @@ def is_field(self, proof = True): def is_finite(self): """ - Return False since the ring of power series over any ring is never + Return ``False`` since the ring of power series over any ring is never finite. EXAMPLES:: @@ -1229,11 +1234,11 @@ def residue_field(self): EXAMPLES:: - sage: R. = PowerSeriesRing(GF(17)) - sage: R.residue_field() + sage: R. = PowerSeriesRing(GF(17)) # optional - sage.rings.finite_rings + sage: R.residue_field() # optional - sage.rings.finite_rings Finite Field of size 17 - sage: R. = PowerSeriesRing(Zp(5)) - sage: R.residue_field() + sage: R. = PowerSeriesRing(Zp(5)) # optional - sage.rings.padics + sage: R.residue_field() # optional - sage.rings.padics Finite Field of size 5 """ if self.base_ring().is_field(): @@ -1248,12 +1253,12 @@ def laurent_series_ring(self): EXAMPLES:: - sage: R. = PowerSeriesRing(ZZ,default_prec=5) + sage: R. = PowerSeriesRing(ZZ, default_prec=5) sage: S = R.laurent_series_ring(); S Laurent Series Ring in t over Integer Ring sage: S.default_prec() 5 - sage: f = 1+t; g=1/f; g + sage: f = 1 + t; g = 1/f; g 1 - t + t^2 - t^3 + t^4 + O(t^5) """ try: @@ -1326,10 +1331,10 @@ def fraction_field(self): EXAMPLES:: - sage: R. = PowerSeriesRing(GF(7)) - sage: R.fraction_field() + sage: R. = PowerSeriesRing(GF(7)) # optional - sage.rings.finite_rings + sage: R.fraction_field() # optional - sage.rings.finite_rings Laurent Series Ring in t over Finite Field of size 7 - sage: Frac(R) + sage: Frac(R) # optional - sage.rings.finite_rings Laurent Series Ring in t over Finite Field of size 7 """ return self.laurent_series_ring() @@ -1343,7 +1348,7 @@ def unpickle_power_series_ring_v0(base_ring, name, default_prec, sparse): EXAMPLES:: sage: P. = PowerSeriesRing(QQ) - sage: loads(dumps(P)) == P # indirect doctest + sage: loads(dumps(P)) == P # indirect doctest True """ return PowerSeriesRing(base_ring, name=name, default_prec = default_prec, sparse=sparse) diff --git a/src/sage/rings/power_series_ring_element.pyx b/src/sage/rings/power_series_ring_element.pyx index 2422521fba8..1e166618e9d 100644 --- a/src/sage/rings/power_series_ring_element.pyx +++ b/src/sage/rings/power_series_ring_element.pyx @@ -126,22 +126,22 @@ from sage.structure.richcmp cimport richcmp def is_PowerSeries(x): """ - Return True if ``x`` is an instance of a univariate + Return ``True`` if ``x`` is an instance of a univariate or multivariate power series. EXAMPLES:: sage: R. = PowerSeriesRing(ZZ) sage: from sage.rings.power_series_ring_element import is_PowerSeries - sage: is_PowerSeries(1+x^2) + sage: is_PowerSeries(1 + x^2) True - sage: is_PowerSeries(x-x) + sage: is_PowerSeries(x - x) True sage: is_PowerSeries(0) False - sage: var('x') + sage: var('x') # optional - sage.symbolic x - sage: is_PowerSeries(1+x^2) + sage: is_PowerSeries(1 + x^2) # optional - sage.symbolic False """ return isinstance(x, PowerSeries) @@ -163,9 +163,9 @@ cdef class PowerSeries(AlgebraElement): sage: PowerSeriesRing(CC, 'q') Power Series Ring in q over Complex Field with 53 bits of precision - sage: T = PowerSeriesRing(GF(3),5,'t'); T - Multivariate Power Series Ring in t0, t1, t2, t3, t4 over Finite - Field of size 3 + sage: T = PowerSeriesRing(GF(3), 5, 't'); T # optional - sage.rings.finite_rings + Multivariate Power Series Ring in t0, t1, t2, t3, t4 + over Finite Field of size 3 """ AlgebraElement.__init__(self, parent) self.__is_gen = is_gen @@ -222,7 +222,7 @@ cdef class PowerSeries(AlgebraElement): def is_gen(self): """ - Return True if this is the generator (the variable) of the power + Return ``True`` if this is the generator (the variable) of the power series ring. EXAMPLES:: @@ -285,13 +285,13 @@ cdef class PowerSeries(AlgebraElement): sage: R. = QQ[[]]; R Power Series Ring in T over Rational Field sage: f = 1 - 1/2*T + 1/3*T^2 + O(T^3) - sage: f.base_extend(GF(5)) + sage: f.base_extend(GF(5)) # optional - sage.rings.finite_rings Traceback (most recent call last): ... TypeError: no base extension defined - sage: f.change_ring(GF(5)) + sage: f.change_ring(GF(5)) # optional - sage.rings.finite_rings 1 + 2*T + 2*T^2 + O(T^3) - sage: f.change_ring(GF(3)) + sage: f.change_ring(GF(3)) # optional - sage.rings.finite_rings Traceback (most recent call last): ... ZeroDivisionError: inverse of Mod(0, 3) does not exist @@ -301,18 +301,18 @@ cdef class PowerSeries(AlgebraElement): :: - sage: K. = NumberField(cyclotomic_polynomial(3), 'a') - sage: R. = K[['t']] - sage: (4*t).change_ring(ZZ) + sage: K. = NumberField(cyclotomic_polynomial(3), 'a') # optional - sage.rings.number_field + sage: R. = K[['t']] # optional - sage.rings.number_field + sage: (4*t).change_ring(ZZ) # optional - sage.rings.number_field 4*t This does not succeed because ``ZZ(K(a+1))`` is not defined. :: - sage: K. = NumberField(cyclotomic_polynomial(3), 'a') - sage: R. = K[['t']] - sage: ((a+1)*t).change_ring(ZZ) + sage: K. = NumberField(cyclotomic_polynomial(3), 'a') # optional - sage.rings.number_field + sage: R. = K[['t']] # optional - sage.rings.number_field + sage: ((a+1)*t).change_ring(ZZ) # optional - sage.rings.number_field Traceback (most recent call last): ... TypeError: Unable to coerce a + 1 to an integer @@ -492,11 +492,11 @@ cdef class PowerSeries(AlgebraElement): EXAMPLES:: - sage: A. = PowerSeriesRing(GF(5)) - sage: x = t + t^2 + O(t^5) - sage: x.lift_to_precision(10) + sage: A. = PowerSeriesRing(GF(5)) # optional - sage.rings.finite_rings + sage: x = t + t^2 + O(t^5) # optional - sage.rings.finite_rings + sage: x.lift_to_precision(10) # optional - sage.rings.finite_rings t + t^2 + O(t^10) - sage: x.lift_to_precision() + sage: x.lift_to_precision() # optional - sage.rings.finite_rings t + t^2 """ @@ -530,8 +530,8 @@ cdef class PowerSeries(AlgebraElement): EXAMPLES:: - sage: R. = GF(49,'alpha')[[]] - sage: (t^2 + O(t^3)).base_ring() + sage: R. = GF(49,'alpha')[[]] # optional - sage.rings.finite_rings + sage: (t^2 + O(t^3)).base_ring() # optional - sage.rings.finite_rings Finite Field in alpha of size 7^2 """ return self._parent.base_ring() @@ -808,10 +808,10 @@ cdef class PowerSeries(AlgebraElement): EXAMPLES:: - sage: R. = GF(2)[[]] - sage: f = 1/(1+I+O(I^8)); f + sage: R. = GF(2)[[]] # optional - sage.rings.finite_rings + sage: f = 1/(1+I+O(I^8)); f # optional - sage.rings.finite_rings 1 + I + I^2 + I^3 + I^4 + I^5 + I^6 + I^7 + O(I^8) - sage: f.truncate(5) + sage: f.truncate(5) # optional - sage.rings.finite_rings I^4 + I^3 + I^2 + I + 1 """ if prec is infinity: @@ -952,7 +952,7 @@ cdef class PowerSeries(AlgebraElement): def __bool__(self): """ - Return True if this power series is not equal to 0. + Return ``True`` if this power series is not equal to 0. EXAMPLES:: @@ -972,7 +972,7 @@ cdef class PowerSeries(AlgebraElement): def is_unit(self): """ - Return True if this power series is invertible. + Return ``True`` if this power series is invertible. A power series is invertible precisely when the constant term is invertible. @@ -1113,9 +1113,9 @@ cdef class PowerSeries(AlgebraElement): """ EXAMPLES:: - sage: R. = Qp(7)[[]] - sage: f = (48*67 + 46*67^2)*T + (1 + 42*67 + 5*67^3)*T^2 + O(T^3) - sage: f % 67 + sage: R. = Qp(7)[[]] # optional - sage.rings.padics + sage: f = (48*67 + 46*67^2)*T + (1 + 42*67 + 5*67^3)*T^2 + O(T^3) # optional - sage.rings.padics + sage: f % 67 # optional - sage.rings.padics T^2 + O(T^3) """ from sage.rings.power_series_ring import PowerSeriesRing @@ -1203,12 +1203,12 @@ cdef class PowerSeries(AlgebraElement): EXAMPLES:: - sage: R. = PowerSeriesRing(QQ, implementation='pari') - sage: f = exp(x) + O(x^7); f + sage: R. = PowerSeriesRing(QQ, implementation='pari') # optional - sage.libs.pari + sage: f = exp(x) + O(x^7); f # optional - sage.libs.pari 1 + x + 1/2*x^2 + 1/6*x^3 + 1/24*x^4 + 1/120*x^5 + 1/720*x^6 + O(x^7) - sage: f << 2 + sage: f << 2 # optional - sage.libs.pari x^2 + x^3 + 1/2*x^4 + 1/6*x^5 + 1/24*x^6 + 1/120*x^7 + 1/720*x^8 + O(x^9) - sage: (f << 99) >> 99 + sage: (f << 99) >> 99 # optional - sage.libs.pari 1 + x + 1/2*x^2 + 1/6*x^3 + 1/24*x^4 + 1/120*x^5 + 1/720*x^6 + O(x^7) """ return self.shift(n) @@ -1221,22 +1221,22 @@ cdef class PowerSeries(AlgebraElement): EXAMPLES:: - sage: R. = PowerSeriesRing(QQ, implementation='pari') - sage: f = exp(x) + O(x^7) - sage: f >> 3 + sage: R. = PowerSeriesRing(QQ, implementation='pari') # optional - sage.libs.pari + sage: f = exp(x) + O(x^7) # optional - sage.libs.pari + sage: f >> 3 # optional - sage.libs.pari 1/6 + 1/24*x + 1/120*x^2 + 1/720*x^3 + O(x^4) - sage: f >> 7 + sage: f >> 7 # optional - sage.libs.pari O(x^0) - sage: f >> 99 + sage: f >> 99 # optional - sage.libs.pari O(x^0) - sage: (f >> 99) << 99 + sage: (f >> 99) << 99 # optional - sage.libs.pari O(x^99) """ return self.shift(-n) def is_monomial(self): """ - Return True if this element is a monomial. That is, if self is + Return ``True`` if this element is a monomial. That is, if self is `x^n` for some non-negative integer `n`. EXAMPLES:: @@ -1275,9 +1275,9 @@ cdef class PowerSeries(AlgebraElement): EXAMPLES:: - sage: R. = SR[[]] - sage: f = (1+I)*x^2 + 3*x - I - sage: f.map_coefficients(lambda z: z.conjugate()) + sage: R. = SR[[]] # optional - sage.symbolic + sage: f = (1+I)*x^2 + 3*x - I # optional - sage.symbolic + sage: f.map_coefficients(lambda z: z.conjugate()) # optional - sage.symbolic I + 3*x + (-I + 1)*x^2 sage: R. = ZZ[[]] sage: f = x^2 + 2 @@ -1287,28 +1287,28 @@ cdef class PowerSeries(AlgebraElement): Examples with different base ring:: sage: R. = ZZ[[]] - sage: k = GF(2) - sage: residue = lambda x: k(x) - sage: f = 4*x^2+x+3 - sage: g = f.map_coefficients(residue); g + sage: k = GF(2) # optional - sage.rings.finite_rings + sage: residue = lambda x: k(x) # optional - sage.rings.finite_rings + sage: f = 4*x^2+x+3 # optional - sage.rings.finite_rings + sage: g = f.map_coefficients(residue); g # optional - sage.rings.finite_rings 1 + x - sage: g.parent() + sage: g.parent() # optional - sage.rings.finite_rings Power Series Ring in x over Integer Ring - sage: g = f.map_coefficients(residue, new_base_ring = k); g + sage: g = f.map_coefficients(residue, new_base_ring=k); g # optional - sage.rings.finite_rings 1 + x - sage: g.parent() + sage: g.parent() # optional - sage.rings.finite_rings Power Series Ring in x over Finite Field of size 2 - sage: residue = k.coerce_map_from(ZZ) - sage: g = f.map_coefficients(residue); g + sage: residue = k.coerce_map_from(ZZ) # optional - sage.rings.finite_rings + sage: g = f.map_coefficients(residue); g # optional - sage.rings.finite_rings 1 + x - sage: g.parent() + sage: g.parent() # optional - sage.rings.finite_rings Power Series Ring in x over Finite Field of size 2 Tests other implementations:: - sage: R. = PowerSeriesRing(GF(11), implementation='pari') - sage: f = q - q^3 + O(q^10) - sage: f.map_coefficients(lambda c: c - 2) + sage: R. = PowerSeriesRing(GF(11), implementation='pari') # optional - sage.rings.finite_rings + sage: f = q - q^3 + O(q^10) # optional - sage.rings.finite_rings + sage: f.map_coefficients(lambda c: c - 2) # optional - sage.rings.finite_rings 10*q + 8*q^3 + O(q^10) """ pol = self.polynomial() @@ -1351,7 +1351,7 @@ cdef class PowerSeries(AlgebraElement): Another example:: - sage: (log(1+t)/t).jacobi_continued_fraction() + sage: (log(1+t)/t).jacobi_continued_fraction() # optional - sage.symbolic ((1/2, -1/12), (1/2, -1/15), (1/2, -9/140), @@ -1410,8 +1410,8 @@ cdef class PowerSeries(AlgebraElement): EXAMPLES:: sage: t = PowerSeriesRing(QQ, 't').gen() - sage: s = sum(catalan_number(k) * t**k for k in range(12)).O(12) - sage: s.stieltjes_continued_fraction() + sage: s = sum(catalan_number(k) * t**k for k in range(12)).O(12) # optional - sage.combinat + sage: s.stieltjes_continued_fraction() # optional - sage.combinat (1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1) Another example:: @@ -1464,7 +1464,7 @@ cdef class PowerSeries(AlgebraElement): def is_square(self): """ - Return True if this function has a square root in this ring, e.g., + Return ``True`` if this function has a square root in this ring, e.g., there is an element `y` in ``self.parent()`` such that `y^2` equals ``self``. @@ -1773,11 +1773,11 @@ cdef class PowerSeries(AlgebraElement): Positive characteristic:: - sage: R. = GF(3)[[]] - sage: p = 1 + 2 * u^2 - sage: p.nth_root(4) + sage: R. = GF(3)[[]] # optional - sage.rings.finite_rings + sage: p = 1 + 2 * u^2 # optional - sage.rings.finite_rings + sage: p.nth_root(4) # optional - sage.rings.finite_rings 1 + 2*u^2 + u^6 + 2*u^8 + u^12 + 2*u^14 + O(u^20) - sage: p.nth_root(4)**4 + sage: p.nth_root(4)**4 # optional - sage.rings.finite_rings 1 + 2*u^2 + O(u^20) TESTS: @@ -1848,14 +1848,14 @@ cdef class PowerSeries(AlgebraElement): sage: t = PowerSeriesRing(QQ, 't').gen() sage: f = (t + t**2).O(4) - sage: cos(f) + sage: cos(f) # optional - sage.symbolic 1 - 1/2*t^2 - t^3 + O(t^4) For several variables:: sage: T. = PowerSeriesRing(ZZ,2) sage: f = a + b + a*b + T.O(3) - sage: cos(f) + sage: cos(f) # optional - sage.symbolic 1 - 1/2*a^2 - a*b - 1/2*b^2 + O(a, b)^3 sage: f.cos() 1 - 1/2*a^2 - a*b - 1/2*b^2 + O(a, b)^3 @@ -1875,16 +1875,16 @@ cdef class PowerSeries(AlgebraElement): sage: T.default_prec() 12 - sage: cos(a) + sage: cos(a) # optional - sage.symbolic 1 - 1/2*a^2 + 1/24*a^4 - 1/720*a^6 + 1/40320*a^8 - 1/3628800*a^10 + O(a, b)^12 sage: a.cos(prec=5) 1 - 1/2*a^2 + 1/24*a^4 + O(a, b)^5 - sage: cos(a + T.O(5)) + sage: cos(a + T.O(5)) # optional - sage.symbolic 1 - 1/2*a^2 + 1/24*a^4 + O(a, b)^5 TESTS:: - sage: cos(a^2 + T.O(5)) + sage: cos(a^2 + T.O(5)) # optional - sage.symbolic 1 - 1/2*a^4 + O(a, b)^5 """ R = self.parent() @@ -1933,14 +1933,14 @@ cdef class PowerSeries(AlgebraElement): sage: t = PowerSeriesRing(QQ, 't').gen() sage: f = (t + t**2).O(4) - sage: sin(f) + sage: sin(f) # optional - sage.symbolic t + t^2 - 1/6*t^3 + O(t^4) For several variables:: sage: T. = PowerSeriesRing(ZZ,2) sage: f = a + b + a*b + T.O(3) - sage: sin(f) + sage: sin(f) # optional - sage.symbolic a + b + a*b + O(a, b)^3 sage: f.sin() a + b + a*b + O(a, b)^3 @@ -1960,16 +1960,16 @@ cdef class PowerSeries(AlgebraElement): sage: T.default_prec() 12 - sage: sin(a) + sage: sin(a) # optional - sage.symbolic a - 1/6*a^3 + 1/120*a^5 - 1/5040*a^7 + 1/362880*a^9 - 1/39916800*a^11 + O(a, b)^12 sage: a.sin(prec=5) a - 1/6*a^3 + O(a, b)^5 - sage: sin(a + T.O(5)) + sage: sin(a + T.O(5)) # optional - sage.symbolic a - 1/6*a^3 + O(a, b)^5 TESTS:: - sage: sin(a^2 + T.O(5)) + sage: sin(a^2 + T.O(5)) # optional - sage.symbolic a^2 + O(a, b)^5 """ R = self.parent() @@ -2019,14 +2019,14 @@ cdef class PowerSeries(AlgebraElement): sage: t = PowerSeriesRing(QQ, 't').gen() sage: f = (t + t**2).O(4) - sage: tan(f) + sage: tan(f) # optional - sage.symbolic t + t^2 + 1/3*t^3 + O(t^4) For several variables:: sage: T. = PowerSeriesRing(ZZ,2) sage: f = a + b + a*b + T.O(3) - sage: tan(f) + sage: tan(f) # optional - sage.symbolic a + b + a*b + O(a, b)^3 sage: f.tan() a + b + a*b + O(a, b)^3 @@ -2036,8 +2036,8 @@ cdef class PowerSeries(AlgebraElement): If the power series has a non-zero constant coefficient `c`, one raises an error:: - sage: g = 2+f - sage: tan(g) + sage: g = 2 + f + sage: tan(g) # optional - sage.symbolic Traceback (most recent call last): ... ValueError: can only apply tan to formal power series with zero constant term @@ -2046,16 +2046,16 @@ cdef class PowerSeries(AlgebraElement): sage: T.default_prec() 12 - sage: tan(a) + sage: tan(a) # optional - sage.symbolic a + 1/3*a^3 + 2/15*a^5 + 17/315*a^7 + 62/2835*a^9 + 1382/155925*a^11 + O(a, b)^12 sage: a.tan(prec=5) a + 1/3*a^3 + O(a, b)^5 - sage: tan(a + T.O(5)) + sage: tan(a + T.O(5)) # optional - sage.symbolic a + 1/3*a^3 + O(a, b)^5 TESTS:: - sage: tan(a^2 + T.O(5)) + sage: tan(a^2 + T.O(5)) # optional - sage.symbolic a^2 + O(a, b)^5 """ if not self[0].is_zero(): @@ -2083,14 +2083,14 @@ cdef class PowerSeries(AlgebraElement): sage: t = PowerSeriesRing(QQ, 't').gen() sage: f = (t + t**2).O(4) - sage: sinh(f) + sage: sinh(f) # optional - sage.symbolic t + t^2 + 1/6*t^3 + O(t^4) For several variables:: sage: T. = PowerSeriesRing(ZZ,2) sage: f = a + b + a*b + T.O(3) - sage: sin(f) + sage: sinh(f) # optional - sage.symbolic a + b + a*b + O(a, b)^3 sage: f.sinh() a + b + a*b + O(a, b)^3 @@ -2100,8 +2100,8 @@ cdef class PowerSeries(AlgebraElement): If the power series has a non-zero constant coefficient `c`, one raises an error:: - sage: g = 2+f - sage: sinh(g) + sage: g = 2 + f + sage: sinh(g) # optional - sage.symbolic Traceback (most recent call last): ... ValueError: can only apply sinh to formal power series with zero @@ -2111,17 +2111,17 @@ cdef class PowerSeries(AlgebraElement): sage: T.default_prec() 12 - sage: sinh(a) + sage: sinh(a) # optional - sage.symbolic a + 1/6*a^3 + 1/120*a^5 + 1/5040*a^7 + 1/362880*a^9 + 1/39916800*a^11 + O(a, b)^12 sage: a.sinh(prec=5) a + 1/6*a^3 + O(a, b)^5 - sage: sinh(a + T.O(5)) + sage: sinh(a + T.O(5)) # optional - sage.symbolic a + 1/6*a^3 + O(a, b)^5 TESTS:: - sage: sinh(a^2 + T.O(5)) + sage: sinh(a^2 + T.O(5)) # optional - sage.symbolic a^2 + O(a, b)^5 """ @@ -2172,14 +2172,14 @@ cdef class PowerSeries(AlgebraElement): sage: t = PowerSeriesRing(QQ, 't').gen() sage: f = (t + t**2).O(4) - sage: cosh(f) + sage: cosh(f) # optional - sage.symbolic 1 + 1/2*t^2 + t^3 + O(t^4) For several variables:: sage: T. = PowerSeriesRing(ZZ,2) sage: f = a + b + a*b + T.O(3) - sage: cosh(f) + sage: cosh(f) # optional - sage.symbolic 1 + 1/2*a^2 + a*b + 1/2*b^2 + O(a, b)^3 sage: f.cosh() 1 + 1/2*a^2 + a*b + 1/2*b^2 + O(a, b)^3 @@ -2189,8 +2189,8 @@ cdef class PowerSeries(AlgebraElement): If the power series has a non-zero constant coefficient `c`, one raises an error:: - sage: g = 2+f - sage: cosh(g) + sage: g = 2 + f + sage: cosh(g) # optional - sage.symbolic Traceback (most recent call last): ... ValueError: can only apply cosh to formal power series with zero @@ -2200,17 +2200,17 @@ cdef class PowerSeries(AlgebraElement): sage: T.default_prec() 12 - sage: cosh(a) + sage: cosh(a) # optional - sage.symbolic 1 + 1/2*a^2 + 1/24*a^4 + 1/720*a^6 + 1/40320*a^8 + 1/3628800*a^10 + O(a, b)^12 sage: a.cosh(prec=5) 1 + 1/2*a^2 + 1/24*a^4 + O(a, b)^5 - sage: cosh(a + T.O(5)) + sage: cosh(a + T.O(5)) # optional - sage.symbolic 1 + 1/2*a^2 + 1/24*a^4 + O(a, b)^5 TESTS:: - sage: cosh(a^2 + T.O(5)) + sage: cosh(a^2 + T.O(5)) # optional - sage.symbolic 1 + 1/2*a^4 + O(a, b)^5 """ @@ -2260,14 +2260,14 @@ cdef class PowerSeries(AlgebraElement): sage: t = PowerSeriesRing(QQ, 't').gen() sage: f = (t + t**2).O(4) - sage: tanh(f) + sage: tanh(f) # optional - sage.symbolic t + t^2 - 1/3*t^3 + O(t^4) For several variables:: sage: T. = PowerSeriesRing(ZZ,2) sage: f = a + b + a*b + T.O(3) - sage: tanh(f) + sage: tanh(f) # optional - sage.symbolic a + b + a*b + O(a, b)^3 sage: f.tanh() a + b + a*b + O(a, b)^3 @@ -2277,8 +2277,8 @@ cdef class PowerSeries(AlgebraElement): If the power series has a non-zero constant coefficient `c`, one raises an error:: - sage: g = 2+f - sage: tanh(g) + sage: g = 2 + f + sage: tanh(g) # optional - sage.symbolic Traceback (most recent call last): ... ValueError: can only apply tanh to formal power series with zero @@ -2288,17 +2288,17 @@ cdef class PowerSeries(AlgebraElement): sage: T.default_prec() 12 - sage: tanh(a) + sage: tanh(a) # optional - sage.symbolic a - 1/3*a^3 + 2/15*a^5 - 17/315*a^7 + 62/2835*a^9 - 1382/155925*a^11 + O(a, b)^12 sage: a.tanh(prec=5) a - 1/3*a^3 + O(a, b)^5 - sage: tanh(a + T.O(5)) + sage: tanh(a + T.O(5)) # optional - sage.symbolic a - 1/3*a^3 + O(a, b)^5 TESTS:: - sage: tanh(a^2 + T.O(5)) + sage: tanh(a^2 + T.O(5)) # optional - sage.symbolic a^2 + O(a, b)^5 """ @@ -2527,8 +2527,8 @@ cdef class PowerSeries(AlgebraElement): :: - sage: R. = PowerSeriesRing(GF(5)) - sage: (1 + x + O(x^2)).exp() + sage: R. = PowerSeriesRing(GF(5)) # optional - sage.rings.finite_rings + sage: (1 + x + O(x^2)).exp() # optional - sage.rings.finite_rings Traceback (most recent call last): ... ArithmeticError: constant term of power series does not support exponentiation @@ -2578,7 +2578,7 @@ cdef class PowerSeries(AlgebraElement): sage: t.exp().log() t + O(t^10) - sage: (1+t).log().exp() + sage: (1 + t).log().exp() 1 + t + O(t^10) sage: (-1 + t + O(t^10)).log() @@ -2617,7 +2617,7 @@ cdef class PowerSeries(AlgebraElement): 1 + x^2 + x^10 sage: p.V(3) 1 + x^6 + x^30 - sage: (p+O(x^20)).V(3) + sage: (p + O(x^20)).V(3) 1 + x^6 + x^30 + O(x^60) """ v = self.list() @@ -2652,7 +2652,7 @@ cdef class PowerSeries(AlgebraElement): Dense examples:: sage: R. = PowerSeriesRing(ZZ) - sage: f = 17*t^100 +O(t^110) + sage: f = 17*t^100 + O(t^110) sage: f.valuation() 100 sage: t.valuation() @@ -2744,7 +2744,7 @@ cdef class PowerSeries(AlgebraElement): EXAMPLES:: sage: k. = QQ[[]] - sage: f = 1+17*w+15*w^3+O(w^5) + sage: f = 1 + 17*w + 15*w^3 + O(w^5) sage: parent(f) Power Series Ring in w over Rational Field sage: g = f.laurent_series(); g @@ -2790,27 +2790,27 @@ cdef class PowerSeries(AlgebraElement): There are currently limits to the possible base rings over which this function works. See the documentation for - ``sage.rings.polynomial.polynomial_element.Polynomial.__pari__`` + :meth:`~sage.rings.polynomial.polynomial_element.Polynomial.__pari__` EXAMPLES:: sage: k. = QQ[[]] - sage: f = 1+17*w+15*w^3+O(w^5) - sage: pari(f) # indirect doctest + sage: f = 1 + 17*w + 15*w^3 + O(w^5) + sage: pari(f) # indirect doctest # optional - sage.libs.pari 1 + 17*w + 15*w^3 + O(w^5) - sage: pari(1 - 19*w + w^5) # indirect doctest + sage: pari(1 - 19*w + w^5) # indirect doctest # optional - sage.libs.pari w^5 - 19*w + 1 sage: R. = Zmod(6)[[]] - sage: pari(1 + x + 8*x^3 + O(x^8)) # indirect doctest + sage: pari(1 + x + 8*x^3 + O(x^8)) # indirect doctest # optional - sage.libs.pari Mod(1, 6) + Mod(1, 6)*x + Mod(2, 6)*x^3 + O(x^8) TESTS:: - sage: pari(1 + O(x^1)) + sage: pari(1 + O(x^1)) # optional - sage.libs.pari Mod(1, 6) + O(x) - sage: pari(O(x^1)) + sage: pari(O(x^1)) # optional - sage.libs.pari O(x) - sage: pari(O(x^0)) + sage: pari(O(x^0)) # optional - sage.libs.pari O(x^0) """ n = self.prec() diff --git a/src/sage/rings/qqbar.py b/src/sage/rings/qqbar.py index 8339127693b..fe71e673da3 100644 --- a/src/sage/rings/qqbar.py +++ b/src/sage/rings/qqbar.py @@ -645,12 +645,12 @@ def order(self): def common_polynomial(self, poly): """ - Given a polynomial with algebraic coefficients, returns a + Given a polynomial with algebraic coefficients, return a wrapper that caches high-precision calculations and - factorizations. This wrapper can be passed to ``polynomial_root`` + factorizations. This wrapper can be passed to :meth:`polynomial_root` in place of the polynomial. - Using ``common_polynomial`` makes no semantic difference, but will + Using :meth:`common_polynomial` makes no semantic difference, but will improve efficiency if you are dealing with multiple roots of a single polynomial. @@ -665,13 +665,13 @@ def common_polynomial(self, poly): sage: phi * tau == -1 True - sage: x = polygen(SR) - sage: p = (x - sqrt(-5)) * (x - sqrt(3)); p + sage: x = polygen(SR) # optional - sage.symbolic + sage: p = (x - sqrt(-5)) * (x - sqrt(3)); p # optional - sage.symbolic x^2 + (-sqrt(3) - sqrt(-5))*x + sqrt(3)*sqrt(-5) - sage: p = QQbar.common_polynomial(p) - sage: a = QQbar.polynomial_root(p, CIF(RIF(-0.1, 0.1), RIF(2, 3))); a + 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 0.?e-18 + 2.236067977499790?*I - sage: b = QQbar.polynomial_root(p, RIF(1, 2)); b + sage: b = QQbar.polynomial_root(p, RIF(1, 2)); b # optional - sage.symbolic 1.732050807568878? These "common polynomials" can be shared between real and @@ -1177,7 +1177,7 @@ def _coerce_map_from_(self, from_par): True sage: a + AA(3) 5.645751311064590? - sage: AA.has_coerce_map_from(SR) + sage: AA.has_coerce_map_from(SR) # optional - sage.symbolic False sage: K = NumberField(x^3 - 2, 'a', embedding=2.**(1/3)) @@ -1683,7 +1683,7 @@ def _coerce_map_from_(self, from_par): True sage: QQbar.has_coerce_map_from(CC) False - sage: QQbar.has_coerce_map_from(SR) + sage: QQbar.has_coerce_map_from(SR) # optional - sage.symbolic False sage: i + QQbar(2) @@ -3134,7 +3134,7 @@ def root_as_algebraic(self): def is_trivial(self): """ - Return true iff this is the trivial generator (alpha == 1), which + Return ``True`` iff this is the trivial generator (alpha == 1), which does not actually extend the rationals. EXAMPLES:: @@ -4695,27 +4695,27 @@ def radical_expression(self): EXAMPLES:: - sage: AA(1/sqrt(5)).radical_expression() + sage: AA(1/sqrt(5)).radical_expression() # optional - sage.symbolic sqrt(1/5) - sage: AA(sqrt(5 + sqrt(5))).radical_expression() + sage: AA(sqrt(5 + sqrt(5))).radical_expression() # optional - sage.symbolic sqrt(sqrt(5) + 5) - sage: QQbar.zeta(5).radical_expression() + sage: QQbar.zeta(5).radical_expression() # optional - sage.symbolic 1/4*sqrt(5) + 1/2*sqrt(-1/2*sqrt(5) - 5/2) - 1/4 sage: a = QQ[x](x^7 - x - 1).roots(AA, False)[0] - sage: a.radical_expression() + sage: a.radical_expression() # optional - sage.symbolic 1.112775684278706? - sage: a.radical_expression().parent() == SR + sage: a.radical_expression().parent() == SR # optional - sage.symbolic False sage: a = sorted(QQ[x](x^7-x-1).roots(QQbar, False), key=imag)[0] - sage: a.radical_expression() + sage: a.radical_expression() # optional - sage.symbolic -0.3636235193291805? - 0.9525611952610331?*I - sage: QQbar.zeta(5).imag().radical_expression() + sage: QQbar.zeta(5).imag().radical_expression() # optional - sage.symbolic 1/2*sqrt(1/2*sqrt(5) + 5/2) - sage: AA(5/3).radical_expression() + sage: AA(5/3).radical_expression() # optional - sage.symbolic 5/3 - sage: AA(5/3).radical_expression().parent() == SR + sage: AA(5/3).radical_expression().parent() == SR # optional - sage.symbolic True - sage: QQbar(0).radical_expression() + sage: QQbar(0).radical_expression() # optional - sage.symbolic 0 TESTS: @@ -4732,7 +4732,7 @@ def radical_expression(self): sage: f = ComplexIntervalField(v.prec()) sage: [f(b.rhs()).overlaps(f(v)) for b in SR(p).solve(x)] [True, True] - sage: a.radical_expression() + sage: a.radical_expression() # optional - sage.symbolic sqrt(2) + 10000000000000000000000000 """ from sage.symbolic.ring import SR # Lazy to avoid cyclic dependency @@ -4762,15 +4762,15 @@ def _maxima_init_(self, I=None): sage: maxima(AA(7)) 7 - sage: maxima(QQbar(sqrt(5/2))) + sage: maxima(QQbar(sqrt(5/2))) # optional - sage.symbolic sqrt(10)/2 - sage: maxima(AA(-sqrt(5))) + sage: maxima(AA(-sqrt(5))) # optional - sage.symbolic -sqrt(5) - sage: maxima(QQbar(sqrt(-2))) + sage: maxima(QQbar(sqrt(-2))) # optional - sage.symbolic sqrt(2)*%i - sage: maxima(AA(2+sqrt(5))) + sage: maxima(AA(2+sqrt(5))) # optional - sage.symbolic sqrt(5)+2 - sage: maxima(QQ[x](x^7 - x - 1).roots(AA, False)[0]) + sage: maxima(QQ[x](x^7 - x - 1).roots(AA, False)[0]) # optional - sage.symbolic Traceback (most recent call last): ... NotImplementedError: cannot find radical expression @@ -4789,7 +4789,7 @@ class AlgebraicNumber(AlgebraicNumber_base): r""" The class for algebraic numbers (complex numbers which are the roots of a polynomial with integer coefficients). Much of its functionality - is inherited from ``AlgebraicNumber_base``. + is inherited from :class:`AlgebraicNumber_base`. .. automethod:: _richcmp_ """ @@ -4884,24 +4884,24 @@ def _richcmp_(self, other, op): TESTS:: - sage: QQbar.zeta(6) == QQbar(1/2 + I*sqrt(3)/2) + sage: QQbar.zeta(6) == QQbar(1/2 + I*sqrt(3)/2) # optional - 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) + sage: QQbar(2) == GF(7)(2) # optional - sage.rings.finite_rings False - sage: GF(7)(2) in QQbar + sage: GF(7)(2) in QQbar # optional - sage.rings.finite_rings False - sage: QQbar.zeta(6) != QQbar(1/2 + I*sqrt(3)/2) + sage: QQbar.zeta(6) != QQbar(1/2 + I*sqrt(3)/2) # optional - 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) + sage: QQbar(2) != GF(7)(2) # optional - sage.rings.finite_rings True sage: QQbar.zeta(3).real() == -1/2 @@ -5118,7 +5118,7 @@ def _rational_(self): def real(self): r""" - Return the real part of self. + Return the real part of ``self``. EXAMPLES:: @@ -5129,7 +5129,7 @@ def real(self): def imag(self): r""" - Return the imaginary part of self. + Return the imaginary part of ``self``. EXAMPLES:: @@ -5173,7 +5173,7 @@ def norm(self): def interval_exact(self, field): r""" - Given a ``ComplexIntervalField``, compute the best possible + Given a :class:`ComplexIntervalField`, compute the best possible approximation of this number in that field. Note that if either the real or imaginary parts of this number are sufficiently close to some floating-point number (and, in @@ -5186,10 +5186,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) - sage: (a - b).interval(CIF) + sage: b = QQbar((1+I)*sqrt(2)/2) # optional - sage.symbolic + sage: (a - b).interval(CIF) # optional - sage.symbolic 0.?e-19 + 0.?e-18*I - sage: (a - b).interval_exact(CIF) + sage: (a - b).interval_exact(CIF) # optional - sage.symbolic 0 """ if not isinstance(field, sage.rings.abc.ComplexIntervalField): @@ -5216,12 +5216,12 @@ def _complex_mpfr_field_(self, field): def complex_number(self, field): r""" - Given the complex field ``field`` compute an accurate approximation of + Given the complex field ``field``, compute an accurate approximation of this element in that field. The approximation will be off by at most two ulp's in each component, except for components which are very close to zero, which will have an - absolute error at most `2^{-prec+1}` where `prec` is the precision of + absolute error at most `2^{-prec+1}` where ``prec`` is the precision of the field. EXAMPLES:: @@ -5239,10 +5239,10 @@ def complex_number(self, field): def complex_exact(self, field): r""" - Given a ``ComplexField``, return the best possible approximation of + Given a :class:`ComplexField`, return the best possible approximation of this number in that field. Note that if either component is sufficiently close to the halfway point between two floating-point - numbers in the corresponding ``RealField``, then this will trigger + numbers in the corresponding :class:`RealField`, then this will trigger exact computation, which may be very slow. EXAMPLES:: @@ -5269,7 +5269,7 @@ def multiplicative_order(self): EXAMPLES:: - sage: QQbar(-sqrt(3)/2 - I/2).multiplicative_order() + sage: QQbar(-sqrt(3)/2 - I/2).multiplicative_order() # optional - sage.symbolic 12 sage: QQbar(1).multiplicative_order() 1 @@ -5295,11 +5295,11 @@ def rational_argument(self): EXAMPLES:: - sage: QQbar((1+I)*(sqrt(2)+sqrt(5))).rational_argument() + sage: QQbar((1+I)*(sqrt(2)+sqrt(5))).rational_argument() # optional - sage.symbolic 1/8 - sage: QQbar(-1 + I*sqrt(3)).rational_argument() + sage: QQbar(-1 + I*sqrt(3)).rational_argument() # optional - sage.symbolic 1/3 - sage: QQbar(-1 - I*sqrt(3)).rational_argument() + sage: QQbar(-1 - I*sqrt(3)).rational_argument() # optional - sage.symbolic -1/3 sage: QQbar(3+4*I).rational_argument() is None True @@ -5329,9 +5329,9 @@ def _pow_(self, other): EXAMPLES:: - sage: QQbar(1) ^ QQbar(sqrt(2)) + sage: QQbar(1) ^ QQbar(sqrt(2)) # optional - sage.symbolic 1 - sage: 1 ^ QQbar(sqrt(2)) + sage: 1 ^ QQbar(sqrt(2)) # optional - sage.symbolic 1 sage: QQbar(2) ^ QQbar(2) Traceback (most recent call last): @@ -5401,8 +5401,8 @@ def _more_precision(self): EXAMPLES:: - sage: a = QQbar(sqrt(2)) - sage: a._more_precision() + sage: a = QQbar(sqrt(2)) # optional - sage.symbolic + sage: a._more_precision() # optional - sage.symbolic TESTS: @@ -5426,8 +5426,8 @@ def __reduce__(self): EXAMPLES:: - sage: t = AA(sqrt(2)) - sage: loads(dumps(t)) == t + sage: t = AA(sqrt(2)) # optional - sage.symbolic + sage: loads(dumps(t)) == t # optional - sage.symbolic True """ return (AlgebraicReal, (self._descr, )) @@ -5447,32 +5447,32 @@ def _richcmp_(self, other, op): TESTS:: - sage: AA(golden_ratio) < AA(sqrt(5)) + sage: AA(golden_ratio) < AA(sqrt(5)) # optional - sage.symbolic True - sage: AA(golden_ratio) == AA((sqrt(5)+1)/2) + sage: AA(golden_ratio) == AA((sqrt(5)+1)/2) # optional - sage.symbolic True sage: AA(7) >= AA(50/7) False Check for trivial equality with identical elements:: - sage: x1 = AA(2^(1/50)) - sage: x2 = AA(2^(1/50)) - sage: y = x1 - x2 - sage: y == y + 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 True - sage: y >= y + sage: y >= y # optional - sage.symbolic True - sage: y < y + sage: y < y # optional - sage.symbolic False - sage: z = x1 - x2 - sage: z == 0 + sage: z = x1 - x2 # optional - sage.symbolic + sage: z == 0 # optional - sage.symbolic True - sage: a = x1 - x2 - sage: b = x1 - x2 - sage: a == b + sage: a = x1 - x2 # optional - sage.symbolic + sage: b = x1 - x2 # optional - sage.symbolic + sage: a == b # optional - sage.symbolic True """ if self is other: @@ -5608,9 +5608,9 @@ def floor(self): EXAMPLES:: - sage: AA(sqrt(2)).floor() + sage: AA(sqrt(2)).floor() # optional - sage.symbolic 1 - sage: AA(-sqrt(2)).floor() + sage: AA(-sqrt(2)).floor() # optional - sage.symbolic -2 sage: AA(42).floor() 42 @@ -5619,8 +5619,8 @@ def floor(self): Check that :trac:`15501` is fixed:: - sage: a = QQbar((-1)^(1/4)).real() - sage: (floor(a-a) + a).parent() + sage: a = QQbar((-1)^(1/4)).real() # optional - sage.symbolic + sage: (floor(a-a) + a).parent() # optional - sage.symbolic Algebraic Real Field """ return self._floor_ceil(lambda x: x.floor()) @@ -5631,9 +5631,9 @@ def ceil(self): EXAMPLES:: - sage: AA(sqrt(2)).ceil() + sage: AA(sqrt(2)).ceil() # optional - sage.symbolic 2 - sage: AA(-sqrt(2)).ceil() + sage: AA(-sqrt(2)).ceil() # optional - sage.symbolic -1 sage: AA(42).ceil() 42 @@ -5646,7 +5646,7 @@ def round(self): EXAMPLES:: - sage: AA(sqrt(2)).round() + sage: AA(sqrt(2)).round() # optional - sage.symbolic 1 sage: AA(1/2).round() 1 @@ -5661,9 +5661,9 @@ def trunc(self): EXAMPLES:: - sage: AA(sqrt(2)).trunc() + sage: AA(sqrt(2)).trunc() # optional - sage.symbolic 1 - sage: AA(-sqrt(2)).trunc() + sage: AA(-sqrt(2)).trunc() # optional - sage.symbolic -1 sage: AA(1).trunc() 1 @@ -5682,11 +5682,11 @@ def _rational_(self): Rational Field sage: AA(-22/7)._rational_() -22/7 - sage: AA(sqrt(7))._rational_() + sage: AA(sqrt(7))._rational_() # optional - 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 + sage: v = AA(1/2 + sqrt(2))^3 - AA(11/4*sqrt(2)); v # optional - sage.symbolic 3.125000000000000? sage: v._rational_() 25/8 @@ -5705,10 +5705,10 @@ def real(self): EXAMPLES:: - sage: a = AA(sqrt(2) + sqrt(3)) - sage: a.real() + sage: a = AA(sqrt(2) + sqrt(3)) # optional - sage.symbolic + sage: a.real() # optional - sage.symbolic 3.146264369941973? - sage: a.real() is a + sage: a.real() is a # optional - sage.symbolic True """ return self @@ -5721,10 +5721,10 @@ def imag(self): EXAMPLES:: - sage: a = AA(sqrt(2) + sqrt(3)) - sage: a.imag() + sage: a = AA(sqrt(2) + sqrt(3)) # optional - sage.symbolic + sage: a.imag() # optional - sage.symbolic 0 - sage: parent(a.imag()) + sage: parent(a.imag()) # optional - sage.symbolic Algebraic Real Field """ return AA_0 @@ -5735,10 +5735,10 @@ def conjugate(self): EXAMPLES:: - sage: a = AA(sqrt(2) + sqrt(3)) - sage: a.conjugate() + sage: a = AA(sqrt(2) + sqrt(3)) # optional - sage.symbolic + sage: a.conjugate() # optional - sage.symbolic 3.146264369941973? - sage: a.conjugate() is a + sage: a.conjugate() is a # optional - sage.symbolic True """ return self @@ -5751,7 +5751,7 @@ def multiplicative_order(self): that `x^n = 1`. If there is no such `n`, returns ``+Infinity``. We first check that ``abs(x)`` is very close to 1. If so, we compute - `x` exactly and compare it to 1 and -1. + `x` exactly and compare it to `1` and `-1`. EXAMPLES:: @@ -5773,8 +5773,8 @@ def multiplicative_order(self): def sign(self): """ - Compute the sign of this algebraic number (return -1 if negative, - 0 if zero, or 1 if positive). + Compute the sign of this algebraic number (return `-1` if negative, + `0` if zero, or `1` if positive). This computes an interval enclosing this number using 128-bit interval arithmetic; if this interval includes 0, then fall back to @@ -5811,9 +5811,9 @@ def sign(self): sage: (a*b - b*a).sign() 0 - sage: a = AA(sqrt(1/2)) - sage: b = AA(-sqrt(1/2)) - sage: (a + b).sign() + 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 0 TESTS: @@ -5822,17 +5822,17 @@ def sign(self): following example will take a long time (more than 5 seconds) when calling ``y.exactify()``:: - sage: x1 = AA(2^(1/50)) - sage: x2 = AA(2^(1/50)) - sage: y = x1 - x2 - sage: y.sign() + 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 0 Simplify to rationals for binary operations when computing the sign:: - sage: a = AA(2^(1/60)) - sage: b = a - (a + 1) - sage: (b + 1).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 0 """ if not self._value.contains_zero(): @@ -5928,15 +5928,15 @@ def _interval_fast(self, prec): EXAMPLES:: - sage: t = AA(sqrt(7)) - sage: t._interval_fast(100) + sage: t = AA(sqrt(7)) # optional - sage.symbolic + sage: t._interval_fast(100) # optional - sage.symbolic 2.64575131106459059050161575364? """ return self.interval_fast(RealIntervalField(prec)) def interval_exact(self, field): """ - Given a ``RealIntervalField``, compute the best possible + Given a :class:`RealIntervalField`, compute the best possible approximation of this number in that field. Note that if this number is sufficiently close to some floating-point number (and, in particular, if this number is exactly representable in @@ -6010,7 +6010,7 @@ def interval_exact(self, field): def real_number(self, field): """ - Given a ``RealField``, compute a good approximation to self in + Given a :class:`RealField`, compute a good approximation to ``self`` in that field. The approximation will be off by at most two ulp's, except for numbers which are very close to 0, which will have an absolute error at most @@ -6096,7 +6096,7 @@ def _complex_mpfr_field_(self, field): def real_exact(self, field): r""" - Given a ``RealField``, compute the best possible approximation of + Given a :class:`RealField`, compute the best possible approximation of this number in that field. Note that if this number is sufficiently close to the halfway point between two floating-point numbers in the field (for the default @@ -6413,7 +6413,7 @@ def _repr_name_(self): class ANRational(ANDescr): r""" - The subclass of ``ANDescr`` that represents an arbitrary + The subclass of :class:`ANDescr` that represents an arbitrary rational. This class is private, and should not be used directly. """ @@ -6510,7 +6510,7 @@ def generator(self): def is_complex(self): r""" - Return False, since rational numbers are real + Return ``False``, since rational numbers are real EXAMPLES:: @@ -6521,7 +6521,7 @@ def is_complex(self): def exactify(self): r""" - Calculate self exactly. Since self is a rational number, return self. + Calculate ``self`` exactly. Since ``self`` is a rational number, return ``self``. EXAMPLES:: @@ -6547,7 +6547,7 @@ def is_simple(self): def minpoly(self): r""" - Return the min poly of self over `\QQ`. + Return the min poly of ``self`` over `\QQ`. EXAMPLES:: @@ -6558,7 +6558,7 @@ def minpoly(self): def neg(self, n): r""" - Negation of self. + Negation of ``self``. EXAMPLES:: @@ -6573,7 +6573,7 @@ def neg(self, n): def invert(self, n): r""" - 1/self. + 1/``self``. EXAMPLES:: @@ -6586,7 +6586,7 @@ def invert(self, n): def abs(self, n): r""" - Absolute value of self. + Absolute value of ``self``. EXAMPLES:: @@ -6636,7 +6636,7 @@ def angle(self): def scale(self): r""" Return a rational number `r` such that ``self`` is equal to `r e^{2 \pi - i q}` for some `q \in (-1/2, 1/2]`. In other words, just return self + i q}` for some `q \in (-1/2, 1/2]`. In other words, just return ``self`` as a rational number. EXAMPLES:: @@ -6801,7 +6801,7 @@ def _repr_(self): def poly(self): r""" - Return the underlying polynomial of self. + Return the underlying polynomial of ``self``. EXAMPLES:: @@ -6838,7 +6838,7 @@ def complex_roots(self, prec, multiplicity): sage: cp = AA.common_polynomial(x^4 - 2) Note that the precision is not guaranteed to find the tightest - possible interval since ``complex_roots()`` depends on the + possible interval since :meth:`complex_roots` depends on the underlying BLAS implementation. :: sage: cp.complex_roots(30, 1) @@ -6923,7 +6923,7 @@ def factors(self): def generator(self): r""" Return an :class:`AlgebraicGenerator` for a number field containing all - the coefficients of self. + the coefficients of ``self``. EXAMPLES:: @@ -6931,7 +6931,8 @@ def generator(self): sage: p = sqrt(AA(2)) * x^2 - sqrt(AA(3)) sage: cp = AA.common_polynomial(p) sage: cp.generator() - Number Field in a with defining polynomial y^4 - 4*y^2 + 1 with a in -0.5176380902050415? + Number Field in a with defining polynomial y^4 - 4*y^2 + 1 + with a in -0.5176380902050415? """ self.exactify() return self._gen @@ -6939,7 +6940,7 @@ def generator(self): class ANRoot(ANDescr): """ - The subclass of ``ANDescr`` that represents a particular + The subclass of :class:`ANDescr` that represents a particular root of a polynomial with algebraic coefficients. This class is private, and should not be used directly. """ @@ -6992,8 +6993,8 @@ def _repr_(self): def handle_sage_input(self, sib, coerce, is_qqbar): r""" Produce an expression which will reproduce this value when evaluated, - and an indication of whether this value is worth sharing (always True, - for ``ANRoot``). + and an indication of whether this value is worth sharing (always ``True`` + for :class:`ANRoot`). EXAMPLES:: @@ -7074,7 +7075,7 @@ def is_complex(self): def conjugate(self, n): r""" - Complex conjugate of this ANRoot object. + Complex conjugate of this :class:`ANRoot` object. EXAMPLES:: @@ -7461,8 +7462,8 @@ def _complex_isolate_interval(self, interval, prec): def exactify(self): """ - Return either an ``ANRational`` or an - ``ANExtensionElement`` with the same value as this number. + Return either an :class:`ANRational` or an + :class:`ANExtensionElement` with the same value as this number. EXAMPLES:: @@ -7479,10 +7480,10 @@ def exactify(self): Verify that :trac:`12727` is fixed:: - sage: m = sqrt(sin(pi/5)); a = QQbar(m); b = AA(m) - sage: a.minpoly() + sage: m = sqrt(sin(pi/5)); a = QQbar(m); b = AA(m) # optional - sage.symbolic + sage: a.minpoly() # optional - sage.symbolic x^8 - 5/4*x^4 + 5/16 - sage: b.minpoly() + sage: b.minpoly() # optional - sage.symbolic x^8 - 5/4*x^4 + 5/16 """ gen = self._poly.generator() @@ -7624,10 +7625,10 @@ def _interval_fast(self, prec): class ANExtensionElement(ANDescr): r""" - The subclass of ``ANDescr`` that represents a number field + The subclass of :class:`ANDescr` that represents a number field element in terms of a specific generator. Consists of a polynomial with rational coefficients in terms of the generator, and the - generator itself, an ``AlgebraicGenerator``. + generator itself, an :class:`AlgebraicGenerator`. """ def __new__(self, generator, value): @@ -7668,8 +7669,8 @@ def _repr_(self): def handle_sage_input(self, sib, coerce, is_qqbar): r""" Produce an expression which will reproduce this value when evaluated, - and an indication of whether this value is worth sharing (always True, - for ``ANExtensionElement``). + and an indication of whether this value is worth sharing (always ``True`` + for :class:`ANExtensionElement`). EXAMPLES:: @@ -7737,23 +7738,23 @@ def handle_sage_input(self, sib, coerce, is_qqbar): def is_complex(self): r""" - Return True if the number field that defines this element is not real. + Return ``True`` if the number field that defines this element is not real. This does not imply that the element itself is definitely non-real, as in the example below. EXAMPLES:: - 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: 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: y.is_complex() + sage: y.is_complex() # optional - sage.symbolic True - sage: x.imag() == 0 + sage: x.imag() == 0 # optional - sage.symbolic True """ return not self._exactly_real @@ -7763,25 +7764,25 @@ def is_simple(self): Check whether this descriptor represents a value with the same algebraic degree as the number field associated with the descriptor. - For ``ANExtensionElement`` elements, we check this by + For :class:`ANExtensionElement` elements, we check this by comparing the degree of the minimal polynomial to the degree of the field. EXAMPLES:: - sage: rt2 = AA(sqrt(2)) - sage: rt3 = AA(sqrt(3)) - sage: rt2b = rt3 + rt2 - rt3 - sage: rt2.exactify() - sage: rt2._descr + 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 a where a^2 - 2 = 0 and a in 1.414213562373095? - sage: rt2._descr.is_simple() + sage: rt2._descr.is_simple() # optional - sage.symbolic True - sage: rt2b.exactify() - sage: rt2b._descr + sage: rt2b.exactify() # optional - sage.symbolic + sage: rt2b._descr # optional - sage.symbolic a^3 - 3*a where a^4 - 4*a^2 + 1 = 0 and a in -0.5176380902050415? - sage: rt2b._descr.is_simple() + sage: rt2b._descr.is_simple() # optional - sage.symbolic False """ try: @@ -7792,7 +7793,7 @@ def is_simple(self): def generator(self): r""" - Return the :class:`~AlgebraicGenerator` object corresponding to self. + Return the :class:`~AlgebraicGenerator` object corresponding to ``self``. EXAMPLES:: @@ -7860,13 +7861,13 @@ def simplify(self, n): EXAMPLES:: - sage: rt2 = AA(sqrt(2)) - sage: rt3 = AA(sqrt(3)) - sage: rt2b = rt3 + rt2 - rt3 - sage: rt2b.exactify() - sage: rt2b._descr + 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 a^3 - 3*a where a^4 - 4*a^2 + 1 = 0 and a in -0.5176380902050415? - sage: rt2b._descr.simplify(rt2b) + sage: rt2b._descr.simplify(rt2b) # optional - sage.symbolic a where a^2 - 2 = 0 and a in 1.414213562373095? """ @@ -7894,75 +7895,84 @@ def _interval_fast(self, prec): def neg(self, n): r""" - Negation of self. + Negation of ``self``. EXAMPLES:: - sage: a = QQbar(sqrt(-2)) + QQbar(sqrt(-3)) - sage: a.exactify() - sage: b = a._descr - sage: type(b) + 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: 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() and c.field_element_value() + b.field_element_value() == 0 + sage: c = b.neg(None); c # random (not uniquely represented) # optional - sage.symbolic + -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 + ....: and c.field_element_value() + b.field_element_value() == 0) True The parameter is ignored:: - sage: b.neg("random").generator() == c.generator() and b.neg("random").field_element_value() == c.field_element_value() + sage: (b.neg("random").generator() == c.generator() # optional - sage.symbolic + ....: and b.neg("random").field_element_value() == c.field_element_value()) True """ return ANExtensionElement(self._generator, -self._value) def invert(self, n): r""" - Reciprocal of self. + Reciprocal of ``self``. EXAMPLES:: - sage: a = QQbar(sqrt(-2)) + QQbar(sqrt(-3)) - sage: a.exactify() - sage: b = a._descr - sage: type(b) + 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: 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() and c.field_element_value() * b.field_element_value() == 1 + sage: c = b.invert(None); c # random (not uniquely represented) # optional - sage.symbolic + -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 + ....: and c.field_element_value() * b.field_element_value() == 1) True The parameter is ignored:: - sage: b.invert("random").generator() == c.generator() and b.invert("random").field_element_value() == c.field_element_value() + sage: (b.invert("random").generator() == c.generator() # optional - sage.symbolic + ....: and b.invert("random").field_element_value() == c.field_element_value()) True """ return ANExtensionElement(self._generator, ~self._value) def conjugate(self, n): - r"""Complex conjugate of self. + r""" + Complex conjugate of ``self``. EXAMPLES:: - sage: a = QQbar(sqrt(-2)) + QQbar(sqrt(-3)) - sage: a.exactify() - sage: b = a._descr - sage: type(b) + 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: 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 + sage: c = b.conjugate(None); c # random (not uniquely represented) # optional - sage.symbolic + 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 Internally, complex conjugation is implemented by taking the same abstract field element but conjugating the complex embedding of the field:: - sage: c.generator() == b.generator().conjugate() + sage: c.generator() == b.generator().conjugate() # optional - sage.symbolic True - sage: c.field_element_value() == b.field_element_value() + sage: c.field_element_value() == b.field_element_value() # optional - sage.symbolic True The parameter is ignored:: - sage: b.conjugate("random").generator() == c.generator() and b.conjugate("random").field_element_value() == c.field_element_value() + sage: (b.conjugate("random").generator() == c.generator() # optional - sage.symbolic + ....: and b.conjugate("random").field_element_value() == c.field_element_value()) True """ @@ -7976,16 +7986,16 @@ def conjugate(self, n): def norm(self, n): r""" - Norm of self (square of complex absolute value) + Norm of ``self`` (square of complex absolute value) EXAMPLES:: - sage: a = QQbar(sqrt(-2)) + QQbar(sqrt(-3)) - sage: a.exactify() - sage: b = a._descr - sage: type(b) + 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: b.norm(a) + sage: b.norm(a) # optional - sage.symbolic """ if self._exactly_real: @@ -7997,33 +8007,33 @@ def norm(self, n): def abs(self, n): r""" - Return the absolute value of self (square root of the norm). + Return the absolute value of ``self`` (square root of the norm). EXAMPLES:: - sage: a = QQbar(sqrt(-2)) + QQbar(sqrt(-3)) - sage: a.exactify() - sage: b = a._descr - sage: type(b) + 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: b.abs(a) + sage: b.abs(a) # optional - sage.symbolic Root 3.146264369941972342? of x^2 - 9.89897948556636? """ return AlgebraicReal(self.norm(n)).sqrt()._descr def rational_argument(self, n): r""" - If the argument of self is `2\pi` times some rational number in `[1/2, + If the argument of ``self`` is `2\pi` times some rational number in `[1/2, -1/2)`, return that rational; otherwise, return ``None``. EXAMPLES:: - sage: a = QQbar(sqrt(-2)) + QQbar(sqrt(3)) - sage: a.exactify() - sage: b = a._descr - sage: type(b) + 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: b.rational_argument(a) is None + sage: b.rational_argument(a) is None # optional - sage.symbolic True sage: x = polygen(QQ) sage: a = (x^4 + 1).roots(QQbar, multiplicities=False)[0] @@ -8074,7 +8084,7 @@ def __init__(self, arg, op): EXAMPLES:: - sage: t = ~QQbar(sqrt(2)); type(t._descr) # indirect doctest + sage: t = ~QQbar(sqrt(2)); type(t._descr) # indirect doctest # optional - sage.symbolic """ self._arg = arg @@ -8087,9 +8097,9 @@ def __reduce__(self): EXAMPLES:: - sage: t = ~QQbar(sqrt(2)); type(t._descr) + sage: t = ~QQbar(sqrt(2)); type(t._descr) # optional - sage.symbolic - sage: loads(dumps(t)) == 1/QQbar(sqrt(2)) + sage: loads(dumps(t)) == 1/QQbar(sqrt(2)) # optional - sage.symbolic True """ return (ANUnaryExpr, (self._arg, self._op)) @@ -8098,7 +8108,7 @@ def handle_sage_input(self, sib, coerce, is_qqbar): r""" Produce an expression which will reproduce this value when evaluated, and an indication of whether this value is worth sharing (always - True for ``ANUnaryExpr``). + ``True`` for :class:`ANUnaryExpr`). EXAMPLES:: @@ -8183,18 +8193,18 @@ def handle_sage_input(self, sib, coerce, is_qqbar): def is_complex(self): r""" Return whether or not this element is complex. Note that this is a data - type check, and triggers no computations -- if it returns False, the + type check, and triggers no computations -- if it returns ``False``, the element might still be real, it just doesn't know it yet. EXAMPLES:: - sage: t = AA(sqrt(2)) - sage: s = (-t)._descr - sage: s + sage: t = AA(sqrt(2)) # optional - sage.symbolic + sage: s = (-t)._descr # optional - sage.symbolic + sage: s # optional - sage.symbolic - sage: s.is_complex() + sage: s.is_complex() # optional - sage.symbolic False - sage: QQbar(-sqrt(2))._descr.is_complex() + sage: QQbar(-sqrt(2))._descr.is_complex() # optional - sage.symbolic True """ return self._complex @@ -8205,11 +8215,11 @@ def _interval_fast(self, prec): EXAMPLES:: - sage: t = AA(sqrt(2)) - sage: s = (-t)._descr - sage: s + sage: t = AA(sqrt(2)) # optional - sage.symbolic + sage: s = (-t)._descr # optional - sage.symbolic + sage: s # optional - sage.symbolic - sage: s._interval_fast(150) + sage: s._interval_fast(150) # optional - sage.symbolic -1.414213562373095048801688724209698078569671876? """ op = self._op @@ -8258,14 +8268,14 @@ def _interval_fast(self, prec): def exactify(self): r""" - Trigger exact computation of self. + Trigger exact computation of ``self``. EXAMPLES:: - sage: v = (-QQbar(sqrt(2)))._descr - sage: type(v) + sage: v = (-QQbar(sqrt(2)))._descr # optional - sage.symbolic + sage: type(v) # optional - sage.symbolic - sage: v.exactify() + sage: v.exactify() # optional - sage.symbolic -a where a^2 - 2 = 0 and a in 1.414213562373095? """ op = self._op @@ -8329,7 +8339,7 @@ def __init__(self, left, right, op): EXAMPLES:: - sage: t = QQbar(sqrt(2)) + QQbar(sqrt(3)); type(t._descr) # indirect doctest + sage: t = QQbar(sqrt(2)) + QQbar(sqrt(3)); type(t._descr) # indirect doctest # optional - sage.symbolic """ self._left = left @@ -8343,9 +8353,9 @@ def __reduce__(self): EXAMPLES:: - sage: t = QQbar(sqrt(2)) + QQbar(sqrt(3)); type(t._descr) + sage: t = QQbar(sqrt(2)) + QQbar(sqrt(3)); type(t._descr) # optional - sage.symbolic - sage: loads(dumps(t)) == QQbar(sqrt(2)) + QQbar(sqrt(3)) + sage: loads(dumps(t)) == QQbar(sqrt(2)) + QQbar(sqrt(3)) # optional - sage.symbolic True """ return (ANBinaryExpr, (self._left, self._right, self._op)) @@ -8354,7 +8364,7 @@ def handle_sage_input(self, sib, coerce, is_qqbar): r""" Produce an expression which will reproduce this value when evaluated, and an indication of whether this value is worth sharing (always - True for ``ANBinaryExpr``). + ``True`` for :class:`ANBinaryExpr`). EXAMPLES:: @@ -8393,10 +8403,10 @@ def handle_sage_input(self, sib, coerce, is_qqbar): True sage: sage_input(n) 1 + AA(3) - sage: rt3 = QQbar(sqrt(3)) - sage: one = rt3/rt3 - sage: n = sqrt(AA(2))+one - sage: one == 1 + sage: rt3 = QQbar(sqrt(3)) # optional - sage.symbolic + sage: one = rt3/rt3 # optional - sage.symbolic + sage: n = sqrt(AA(2)) + one + sage: one == 1 # optional - sage.symbolic True sage: sage_input(n) R. = AA[] @@ -8463,12 +8473,12 @@ def handle_sage_input(self, sib, coerce, is_qqbar): def is_complex(self): r""" Whether this element is complex. Does not trigger exact computation, so - may return True even if the element is real. + may return ``True`` even if the element is real. EXAMPLES:: - sage: x = (QQbar(sqrt(-2)) / QQbar(sqrt(-5)))._descr - sage: x.is_complex() + sage: x = (QQbar(sqrt(-2)) / QQbar(sqrt(-5)))._descr # optional - sage.symbolic + sage: x.is_complex() # optional - sage.symbolic True """ return self._complex @@ -8479,10 +8489,10 @@ def _interval_fast(self, prec): EXAMPLES:: - sage: x = (QQbar(sqrt(-2)) / QQbar(sqrt(-5)))._descr - sage: y= x._interval_fast(64); y + sage: x = (QQbar(sqrt(-2)) / QQbar(sqrt(-5)))._descr # optional - sage.symbolic + sage: y= x._interval_fast(64); y # optional - sage.symbolic 0.632455532033675867? - sage: y.parent() + sage: y.parent() # optional - sage.symbolic Complex Interval Field with 64 bits of precision """ op = self._op @@ -8499,8 +8509,8 @@ def exactify(self): """ TESTS:: - sage: rt2c = QQbar.zeta(3) + AA(sqrt(2)) - QQbar.zeta(3) - sage: rt2c.exactify() + sage: rt2c = QQbar.zeta(3) + AA(sqrt(2)) - QQbar.zeta(3) # optional - sage.symbolic + sage: rt2c.exactify() # optional - 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 @@ -8588,25 +8598,27 @@ def an_binop_expr(a, b, op): EXAMPLES:: - sage: a = QQbar(sqrt(2)) + QQbar(sqrt(3)) - sage: b = QQbar(sqrt(3)) + QQbar(sqrt(5)) - sage: type(a._descr); type(b._descr) + 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: from sage.rings.qqbar import an_binop_expr - sage: x = an_binop_expr(a, b, operator.add); x + sage: x = an_binop_expr(a, b, operator.add); x # 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: x.exactify() # optional - sage.symbolic + 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)) - sage: b = QQbar(sqrt(3)) + QQbar(sqrt(5)) - sage: type(a._descr) + 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: x = an_binop_expr(a, b, operator.mul); x + sage: x = an_binop_expr(a, b, operator.mul); x # 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? + sage: x.exactify() # optional - sage.symbolic + 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? """ return ANBinaryExpr(a, b, op) @@ -8738,7 +8750,7 @@ def get_AA_golden_ratio(): EXAMPLES:: - sage: AA(golden_ratio) # indirect doctest + sage: AA(golden_ratio) # indirect doctest # optional - 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 0f7a19bed50..27448c2def6 100644 --- a/src/sage/rings/qqbar_decorators.py +++ b/src/sage/rings/qqbar_decorators.py @@ -1,3 +1,4 @@ +# sage.doctest: optional - sage.rings.number_field """ QQbar decorators diff --git a/src/sage/rings/quotient_ring.py b/src/sage/rings/quotient_ring.py index 33df6cf2e37..b683889b79a 100644 --- a/src/sage/rings/quotient_ring.py +++ b/src/sage/rings/quotient_ring.py @@ -38,8 +38,8 @@ ....: def reduce(self,x): ....: R = self.ring() ....: return add([c*R(m) for m,c in x if len(m) = FreeAlgebra(QQ, 3) - sage: I3 = PowerIdeal(F,3); I3 + sage: F. = FreeAlgebra(QQ, 3) # optional - sage.combinat sage.modules + sage: I3 = PowerIdeal(F,3); I3 # optional - sage.combinat sage.modules Twosided Ideal (x^3, x^2*y, x^2*z, x*y*x, x*y^2, x*y*z, x*z*x, x*z*y, x*z^2, y*x^2, y*x*y, y*x*z, y^2*x, y^3, y^2*z, y*z*x, y*z*y, y*z^2, z*x^2, z*x*y, z*x*z, z*y*x, z*y^2, z*y*z, z^2*x, z^2*y, z^3) of @@ -49,33 +49,33 @@ finite dimensional quotients defined by multiplication matrices. We are bypassing it, so that we obtain the default quotient:: - sage: Q3. = F.quotient(I3) - sage: Q3 + sage: Q3. = F.quotient(I3) # optional - sage.combinat sage.modules + sage: Q3 # optional - sage.combinat sage.modules Quotient of Free Algebra on 3 generators (x, y, z) over Rational Field by the ideal (x^3, x^2*y, x^2*z, x*y*x, x*y^2, x*y*z, x*z*x, x*z*y, x*z^2, y*x^2, y*x*y, y*x*z, y^2*x, y^3, y^2*z, y*z*x, y*z*y, y*z^2, z*x^2, z*x*y, z*x*z, z*y*x, z*y^2, z*y*z, z^2*x, z^2*y, z^3) - sage: (a+b+2)^4 + sage: (a+b+2)^4 # optional - sage.combinat sage.modules 16 + 32*a + 32*b + 24*a^2 + 24*a*b + 24*b*a + 24*b^2 - sage: Q3.is_commutative() + sage: Q3.is_commutative() # optional - sage.combinat sage.modules False Even though `Q_3` is not commutative, there is commutativity for products of degree three:: - sage: a*(b*c)-(b*c)*a==F.zero() + sage: a*(b*c)-(b*c)*a==F.zero() # optional - sage.combinat sage.modules True If we quotient out all terms of degree two then of course the resulting quotient ring is commutative:: - sage: I2 = PowerIdeal(F,2); I2 + sage: I2 = PowerIdeal(F,2); I2 # optional - sage.combinat sage.modules Twosided Ideal (x^2, x*y, x*z, y*x, y^2, y*z, z*x, z*y, z^2) of Free Algebra on 3 generators (x, y, z) over Rational Field - sage: Q2. = F.quotient(I2) - sage: Q2.is_commutative() + sage: Q2. = F.quotient(I2) # optional - sage.combinat sage.modules + sage: Q2.is_commutative() # optional - sage.combinat sage.modules True - sage: (a+b+2)^4 + sage: (a+b+2)^4 # optional - sage.combinat sage.modules 16 + 32*a + 32*b Since :trac:`7797`, there is an implementation of free algebras @@ -84,16 +84,17 @@ easily:: sage: from itertools import product - sage: F. = FreeAlgebra(QQ, implementation='letterplace') - sage: Q3 = F.quo(F*[F.prod(m) for m in product(F.gens(), repeat=3)]*F) - sage: Q3 - Quotient of Free Associative Unital Algebra on 3 generators (x, y, z) over Rational Field by the ideal (x*x*x, x*x*y, x*x*z, x*y*x, x*y*y, x*y*z, x*z*x, x*z*y, x*z*z, y*x*x, y*x*y, y*x*z, y*y*x, y*y*y, y*y*z, y*z*x, y*z*y, y*z*z, z*x*x, z*x*y, z*x*z, z*y*x, z*y*y, z*y*z, z*z*x, z*z*y, z*z*z) - sage: Q3.0*Q3.1-Q3.1*Q3.0 + sage: F. = FreeAlgebra(QQ, implementation='letterplace') # optional - sage.combinat sage.modules + sage: Q3 = F.quo(F*[F.prod(m) for m in product(F.gens(), repeat=3)]*F) # optional - sage.combinat sage.modules + sage: Q3 # optional - sage.combinat sage.modules + Quotient of Free Associative Unital Algebra on 3 generators (x, y, z) + over Rational Field by the ideal (x*x*x, x*x*y, x*x*z, x*y*x, x*y*y, x*y*z, x*z*x, x*z*y, x*z*z, y*x*x, y*x*y, y*x*z, y*y*x, y*y*y, y*y*z, y*z*x, y*z*y, y*z*z, z*x*x, z*x*y, z*x*z, z*y*x, z*y*y, z*y*z, z*z*x, z*z*y, z*z*z) + sage: Q3.0*Q3.1 - Q3.1*Q3.0 # optional - sage.combinat sage.modules xbar*ybar - ybar*xbar - sage: Q3.0*(Q3.1*Q3.2)-(Q3.1*Q3.2)*Q3.0 + sage: Q3.0*(Q3.1*Q3.2) - (Q3.1*Q3.2)*Q3.0 # optional - sage.combinat sage.modules 0 - sage: Q2 = F.quo(F*[F.prod(m) for m in product(F.gens(), repeat=2)]*F) - sage: Q2.is_commutative() + sage: Q2 = F.quo(F*[F.prod(m) for m in product(F.gens(), repeat=2)]*F) # optional - sage.combinat sage.modules + sage: Q2.is_commutative() # optional - sage.combinat sage.modules True """ @@ -157,7 +158,7 @@ def QuotientRing(R, I, names=None, **kwds): Some simple quotient rings with the integers:: - sage: R = QuotientRing(ZZ,7*ZZ); R + sage: R = QuotientRing(ZZ, 7*ZZ); R Quotient of Integer Ring by the ideal (7) sage: R.gens() (1,) @@ -177,13 +178,14 @@ def QuotientRing(R, I, names=None, **kwds): ring can be specified as shown below):: sage: P. = QQ[] - sage: R. = QuotientRing(P, P.ideal(x^2 + 1)) - sage: R - Univariate Quotient Polynomial Ring in xx over Rational Field with modulus x^2 + 1 - sage: R.gens(); R.gen() + sage: R. = QuotientRing(P, P.ideal(x^2 + 1)) # optional - sage.libs.pari + sage: R # optional - sage.libs.pari + Univariate Quotient Polynomial Ring in xx over Rational Field + with modulus x^2 + 1 + sage: R.gens(); R.gen() # optional - sage.libs.pari (xx,) xx - sage: for n in range(4): xx^n + sage: for n in range(4): xx^n # optional - sage.libs.pari 1 xx -1 @@ -192,13 +194,13 @@ def QuotientRing(R, I, names=None, **kwds): :: sage: P. = QQ[] - sage: S = QuotientRing(P, P.ideal(x^2 - 2)) - sage: S - Univariate Quotient Polynomial Ring in xbar over Rational Field with - modulus x^2 - 2 - sage: xbar = S.gen(); S.gen() + sage: S = QuotientRing(P, P.ideal(x^2 - 2)) # optional - sage.libs.pari + sage: S # optional - sage.libs.pari + Univariate Quotient Polynomial Ring in xbar over Rational Field + with modulus x^2 - 2 + sage: xbar = S.gen(); S.gen() # optional - sage.libs.pari xbar - sage: for n in range(3): xbar^n + sage: for n in range(3): xbar^n # optional - sage.libs.pari 1 xbar 2 @@ -206,25 +208,26 @@ def QuotientRing(R, I, names=None, **kwds): Sage coerces objects into ideals when possible:: sage: P. = QQ[] - sage: R = QuotientRing(P, x^2 + 1); R - Univariate Quotient Polynomial Ring in xbar over Rational Field with - modulus x^2 + 1 + sage: R = QuotientRing(P, x^2 + 1); R # optional - sage.libs.pari + Univariate Quotient Polynomial Ring in xbar over Rational Field + with modulus x^2 + 1 By Noether's homomorphism theorems, the quotient of a quotient ring of `R` is just the quotient of `R` by the sum of the ideals. In this example, we end up modding out the ideal `(x)` from the ring `\QQ[x,y]`:: - sage: R. = PolynomialRing(QQ,2) - sage: S. = QuotientRing(R,R.ideal(1 + y^2)) - sage: T. = QuotientRing(S,S.ideal(a)) - sage: T - Quotient of Multivariate Polynomial Ring in x, y over Rational Field by the ideal (x, y^2 + 1) - sage: R.gens(); S.gens(); T.gens() + sage: R. = PolynomialRing(QQ, 2) + sage: S. = QuotientRing(R, R.ideal(1 + y^2)) # optional - sage.libs.pari + sage: T. = QuotientRing(S, S.ideal(a)) # optional - sage.libs.pari + sage: T # optional - sage.libs.pari + Quotient of Multivariate Polynomial Ring in x, y over Rational Field + by the ideal (x, y^2 + 1) + sage: R.gens(); S.gens(); T.gens() # optional - sage.libs.pari (x, y) (a, b) (0, d) - sage: for n in range(4): d^n + sage: for n in range(4): d^n # optional - sage.libs.pari 1 d -1 @@ -243,20 +246,23 @@ def QuotientRing(R, I, names=None, **kwds): Here is an example of the quotient of a free algebra by a twosided homogeneous ideal (see :trac:`7797`):: - sage: F. = FreeAlgebra(QQ, implementation='letterplace') - sage: I = F*[x*y+y*z,x^2+x*y-y*x-y^2]*F - sage: Q. = F.quo(I); Q - Quotient of Free Associative Unital Algebra on 3 generators (x, y, z) over Rational Field by the ideal (x*y + y*z, x*x + x*y - y*x - y*y) - sage: a*b + sage: F. = FreeAlgebra(QQ, implementation='letterplace') # optional - sage.combinat sage.modules + sage: I = F * [x*y + y*z, x^2 + x*y - y*x - y^2] * F # optional - sage.combinat sage.modules + sage: Q. = F.quo(I); Q # optional - sage.combinat sage.modules + Quotient of Free Associative Unital Algebra on 3 generators (x, y, z) + over Rational Field by the ideal (x*y + y*z, x*x + x*y - y*x - y*y) + sage: a*b # optional - sage.combinat sage.modules -b*c - sage: a^3 + sage: a^3 # optional - sage.combinat sage.modules -b*c*a - b*c*b - b*c*c - sage: J = Q*[a^3-b^3]*Q - sage: R. = Q.quo(J); R - Quotient of Free Associative Unital Algebra on 3 generators (x, y, z) over Rational Field by the ideal (-y*y*z - y*z*x - 2*y*z*z, x*y + y*z, x*x + x*y - y*x - y*y) - sage: i^3 + sage: J = Q * [a^3 - b^3] * Q # optional - sage.combinat sage.modules + sage: R. = Q.quo(J); R # optional - sage.combinat sage.modules + Quotient of Free Associative Unital Algebra on 3 generators (x, y, z) + over Rational Field by the ideal + (-y*y*z - y*z*x - 2*y*z*z, x*y + y*z, x*x + x*y - y*x - y*y) + sage: i^3 # optional - sage.combinat sage.modules -j*k*i - j*k*j - j*k*k - sage: j^3 + sage: j^3 # optional - sage.combinat sage.modules -j*k*i - j*k*j - j*k*k Check that :trac:`5978` is fixed by if we quotient by the zero ideal `(0)` @@ -342,12 +348,12 @@ def is_QuotientRing(x): :: - sage: F. = FreeAlgebra(QQ, implementation='letterplace') - sage: I = F*[x*y+y*z,x^2+x*y-y*x-y^2]*F - sage: Q = F.quo(I) - sage: is_QuotientRing(Q) + sage: F. = FreeAlgebra(QQ, implementation='letterplace') # optional - sage.combinat sage.modules + sage: I = F * [x*y + y*z, x^2 + x*y - y*x - y^2] * F # optional - sage.combinat sage.modules + sage: Q = F.quo(I) # optional - sage.combinat sage.modules + sage: is_QuotientRing(Q) # optional - sage.combinat sage.modules True - sage: is_QuotientRing(F) + sage: is_QuotientRing(F) # optional - sage.combinat sage.modules False """ return isinstance(x, QuotientRing_nc) @@ -370,24 +376,26 @@ class QuotientRing_nc(ring.Ring, sage.structure.parent_gens.ParentWithGens): Here is a quotient of a free algebra by a twosided homogeneous ideal:: - sage: F. = FreeAlgebra(QQ, implementation='letterplace') - sage: I = F*[x*y+y*z,x^2+x*y-y*x-y^2]*F - sage: Q. = F.quo(I); Q - Quotient of Free Associative Unital Algebra on 3 generators (x, y, z) over Rational Field by the ideal (x*y + y*z, x*x + x*y - y*x - y*y) - sage: a*b + sage: F. = FreeAlgebra(QQ, implementation='letterplace') # optional - sage.combinat sage.modules + sage: I = F * [x*y + y*z, x^2 + x*y - y*x - y^2]*F # optional - sage.combinat sage.modules + sage: Q. = F.quo(I); Q # optional - sage.combinat sage.modules + Quotient of Free Associative Unital Algebra on 3 generators (x, y, z) over Rational Field + by the ideal (x*y + y*z, x*x + x*y - y*x - y*y) + sage: a*b # optional - sage.combinat sage.modules -b*c - sage: a^3 + sage: a^3 # optional - sage.combinat sage.modules -b*c*a - b*c*b - b*c*c A quotient of a quotient is just the quotient of the original top ring by the sum of two ideals:: - sage: J = Q*[a^3-b^3]*Q - sage: R. = Q.quo(J); R - Quotient of Free Associative Unital Algebra on 3 generators (x, y, z) over Rational Field by the ideal (-y*y*z - y*z*x - 2*y*z*z, x*y + y*z, x*x + x*y - y*x - y*y) - sage: i^3 + sage: J = Q * [a^3 - b^3] * Q # optional - sage.combinat sage.modules + sage: R. = Q.quo(J); R # optional - sage.combinat sage.modules + Quotient of Free Associative Unital Algebra on 3 generators (x, y, z) over Rational Field + by the ideal (-y*y*z - y*z*x - 2*y*z*z, x*y + y*z, x*x + x*y - y*x - y*y) + sage: i^3 # optional - sage.combinat sage.modules -j*k*i - j*k*j - j*k*k - sage: j^3 + sage: j^3 # optional - sage.combinat sage.modules -j*k*i - j*k*j - j*k*k For rings that *do* inherit from :class:`~sage.rings.ring.CommutativeRing`, @@ -399,15 +407,16 @@ class QuotientRing_nc(ring.Ring, sage.structure.parent_gens.ParentWithGens): sage: R. = PolynomialRing(ZZ,'x') sage: I = R.ideal([4 + 3*x + x^2, 1 + x^2]) sage: S = R.quotient_ring(I); S - Quotient of Univariate Polynomial Ring in x over Integer Ring by the ideal (x^2 + 3*x + 4, x^2 + 1) + Quotient of Univariate Polynomial Ring in x over Integer Ring + by the ideal (x^2 + 3*x + 4, x^2 + 1) :: sage: R. = PolynomialRing(QQ) - sage: S. = R.quo(x^2 + y^2) - sage: a^2 + b^2 == 0 + sage: S. = R.quo(x^2 + y^2) # optional - sage.libs.singular + sage: a^2 + b^2 == 0 # optional - sage.libs.singular True - sage: S(0) == a^2 + b^2 + sage: S(0) == a^2 + b^2 # optional - sage.libs.singular True Again, a quotient of a quotient is just the quotient of the original top @@ -415,12 +424,13 @@ class QuotientRing_nc(ring.Ring, sage.structure.parent_gens.ParentWithGens): :: - sage: R. = PolynomialRing(QQ,2) - sage: S. = R.quo(1 + y^2) - sage: T. = S.quo(a) - sage: T - Quotient of Multivariate Polynomial Ring in x, y over Rational Field by the ideal (x, y^2 + 1) - sage: T.gens() + sage: R. = PolynomialRing(QQ, 2) + sage: S. = R.quo(1 + y^2) # optional - sage.libs.singular + sage: T. = S.quo(a) # optional - sage.libs.singular + sage: T # optional - sage.libs.singular + Quotient of Multivariate Polynomial Ring in x, y over Rational Field + by the ideal (x, y^2 + 1) + sage: T.gens() # optional - sage.libs.singular (0, d) """ Element = quotient_ring_element.QuotientRingElement @@ -438,13 +448,15 @@ def __init__(self, R, I, names, category=None): EXAMPLES:: - sage: F. = FreeAlgebra(QQ, implementation='letterplace') - sage: I = F*[x*y+y*z,x^2+x*y-y*x-y^2]*F - sage: Q. = F.quo(I); Q - Quotient of Free Associative Unital Algebra on 3 generators (x, y, z) over Rational Field by the ideal (x*y + y*z, x*x + x*y - y*x - y*y) - sage: a*b + sage: F. = FreeAlgebra(QQ, implementation='letterplace') # optional - sage.combinat sage.modules + sage: I = F * [x*y + y*z, x^2 + x*y - y*x - y^2] * F # optional - sage.combinat sage.modules + sage: Q. = F.quo(I); Q # optional - sage.combinat sage.modules + Quotient of + Free Associative Unital Algebra on 3 generators (x, y, z) over Rational Field + by the ideal (x*y + y*z, x*x + x*y - y*x - y*y) + sage: a*b # optional - sage.combinat sage.modules -b*c - sage: a^3 + sage: a^3 # optional - sage.combinat sage.modules -b*c*a - b*c*b - b*c*c """ @@ -491,19 +503,20 @@ def construction(self): sage: I = R.ideal([4 + 3*x + x^2, 1 + x^2]) sage: R.quotient_ring(I).construction() (QuotientFunctor, Univariate Polynomial Ring in x over Integer Ring) - sage: F. = FreeAlgebra(QQ, implementation='letterplace') - sage: I = F*[x*y+y*z,x^2+x*y-y*x-y^2]*F - sage: Q = F.quo(I) - sage: Q.construction() - (QuotientFunctor, Free Associative Unital Algebra on 3 generators (x, y, z) over Rational Field) + sage: F. = FreeAlgebra(QQ, implementation='letterplace') # optional - sage.combinat sage.modules + sage: I = F * [x*y + y*z, x^2 + x*y - y*x - y^2] * F # optional - sage.combinat sage.modules + sage: Q = F.quo(I) # optional - sage.combinat sage.modules + sage: Q.construction() # optional - sage.combinat sage.modules + (QuotientFunctor, + Free Associative Unital Algebra on 3 generators (x, y, z) over Rational Field) TESTS:: sage: F, R = Integers(5).construction() sage: F(R) Ring of integers modulo 5 - sage: F, R = GF(5).construction() - sage: F(R) + sage: F, R = GF(5).construction() # optional - sage.rings.finite_rings + sage: F(R) # optional - sage.rings.finite_rings Finite Field of size 5 """ from sage.categories.pushout import QuotientFunctor @@ -575,19 +588,19 @@ def is_commutative(self): The non-commutative case is more interesting:: - sage: F. = FreeAlgebra(QQ, implementation='letterplace') - sage: I = F*[x*y+y*z,x^2+x*y-y*x-y^2]*F - sage: Q = F.quo(I) - sage: Q.is_commutative() + sage: F. = FreeAlgebra(QQ, implementation='letterplace') # optional - sage.combinat sage.modules + sage: I = F * [x*y + y*z, x^2 + x*y - y*x - y^2] * F # optional - sage.combinat sage.modules + sage: Q = F.quo(I) # optional - sage.combinat sage.modules + sage: Q.is_commutative() # optional - sage.combinat sage.modules False - sage: Q.1*Q.2==Q.2*Q.1 + sage: Q.1*Q.2 == Q.2*Q.1 # optional - sage.combinat sage.modules False In the next example, the generators apparently commute:: - sage: J = F*[x*y-y*x,x*z-z*x,y*z-z*y,x^3-y^3]*F - sage: R = F.quo(J) - sage: R.is_commutative() + sage: J = F * [x*y - y*x, x*z - z*x, y*z - z*y, x^3 - y^3] * F # optional - sage.combinat sage.modules + sage: R = F.quo(J) # optional - sage.combinat sage.modules + sage: R.is_commutative() # optional - sage.combinat sage.modules True """ @@ -610,12 +623,11 @@ def is_commutative(self): @cached_method def cover(self): r""" - The covering ring homomorphism `R \to R/I`, equipped with a - section. + The covering ring homomorphism `R \to R/I`, equipped with a section. EXAMPLES:: - sage: R = ZZ.quo(3*ZZ) + sage: R = ZZ.quo(3 * ZZ) sage: pi = R.cover() sage: pi Ring morphism: @@ -629,19 +641,20 @@ def cover(self): :: sage: R. = PolynomialRing(QQ) - sage: Q = R.quo( (x^2,y^2) ) - sage: pi = Q.cover() - sage: pi(x^3+y) + sage: Q = R.quo((x^2, y^2)) + sage: pi = Q.cover() # optional - sage.libs.singular + sage: pi(x^3 + y) # optional - sage.libs.singular ybar - sage: l = pi.lift(x+y^3) - sage: l + sage: l = pi.lift(x + y^3) # optional - sage.libs.singular + sage: l # optional - sage.libs.singular x - sage: l = pi.lift(); l + sage: l = pi.lift(); l # optional - sage.libs.singular Set-theoretic ring morphism: - From: Quotient of Multivariate Polynomial Ring in x, y over Rational Field by the ideal (x^2, y^2) + From: Quotient of Multivariate Polynomial Ring in x, y over Rational Field + by the ideal (x^2, y^2) To: Multivariate Polynomial Ring in x, y over Rational Field Defn: Choice of lifting map - sage: l(x+y^3) + sage: l(x + y^3) # optional - sage.libs.singular x """ try: @@ -663,40 +676,43 @@ def lifting_map(self): sage: R. = PolynomialRing(QQ, 2) sage: S = R.quotient(x^2 + y^2) - sage: pi = S.cover(); pi + sage: pi = S.cover(); pi # optional - sage.libs.singular Ring morphism: From: Multivariate Polynomial Ring in x, y over Rational Field - To: Quotient of Multivariate Polynomial Ring in x, y over Rational Field by the ideal (x^2 + y^2) + To: Quotient of Multivariate Polynomial Ring in x, y over Rational Field + by the ideal (x^2 + y^2) Defn: Natural quotient map - sage: L = S.lifting_map(); L + sage: L = S.lifting_map(); L # optional - sage.libs.singular Set-theoretic ring morphism: - From: Quotient of Multivariate Polynomial Ring in x, y over Rational Field by the ideal (x^2 + y^2) + From: Quotient of Multivariate Polynomial Ring in x, y over Rational Field + by the ideal (x^2 + y^2) To: Multivariate Polynomial Ring in x, y over Rational Field Defn: Choice of lifting map - sage: L(S.0) + sage: L(S.0) # optional - sage.libs.singular x - sage: L(S.1) + sage: L(S.1) # optional - sage.libs.singular y Note that some reduction may be applied so that the lift of a reduction need not equal the original element:: - sage: z = pi(x^3 + 2*y^2); z + sage: z = pi(x^3 + 2*y^2); z # optional - sage.libs.singular -xbar*ybar^2 + 2*ybar^2 - sage: L(z) + sage: L(z) # optional - sage.libs.singular -x*y^2 + 2*y^2 - sage: L(z) == x^3 + 2*y^2 + sage: L(z) == x^3 + 2*y^2 # optional - sage.libs.singular False Test that there also is a lift for rings that are no instances of :class:`~sage.rings.ring.Ring` (see :trac:`11068`):: - sage: MS = MatrixSpace(GF(5),2,2) - sage: I = MS*[MS.0*MS.1,MS.2+MS.3]*MS - sage: Q = MS.quo(I) - sage: Q.lift() + sage: MS = MatrixSpace(GF(5), 2, 2) # optional - sage.modules sage.rings.finite_rings + sage: I = MS * [MS.0*MS.1, MS.2 + MS.3] * MS # optional - sage.modules sage.rings.finite_rings + sage: Q = MS.quo(I) # optional - sage.modules sage.rings.finite_rings + sage: Q.lift() # optional - sage.modules sage.rings.finite_rings Set-theoretic ring morphism: - From: Quotient of Full MatrixSpace of 2 by 2 dense matrices over Finite Field of size 5 by the ideal + From: Quotient of Full MatrixSpace of 2 by 2 dense matrices + over Finite Field of size 5 by the ideal ( [0 1] [0 0], @@ -719,7 +735,7 @@ def lifting_map(self): return m # The following is to make the category framework happy. - def lift(self,x=None): + def lift(self, x=None): """ Return the lifting map to the cover, or the image of an element under the lifting map. @@ -735,12 +751,13 @@ def lift(self,x=None): sage: R. = PolynomialRing(QQ, 2) sage: S = R.quotient(x^2 + y^2) - sage: S.lift() + sage: S.lift() # optional - sage.libs.singular Set-theoretic ring morphism: - From: Quotient of Multivariate Polynomial Ring in x, y over Rational Field by the ideal (x^2 + y^2) + From: Quotient of Multivariate Polynomial Ring in x, y over Rational Field + by the ideal (x^2 + y^2) To: Multivariate Polynomial Ring in x, y over Rational Field Defn: Choice of lifting map - sage: S.lift(S.0) == x + sage: S.lift(S.0) == x # optional - sage.libs.singular True """ @@ -764,7 +781,7 @@ def retract(self,x): sage: R. = PolynomialRing(QQ, 2) sage: S = R.quotient(x^2 + y^2) - sage: S.retract((x+y)^2) + sage: S.retract((x+y)^2) # optional - sage.libs.singular 2*xbar*ybar """ @@ -804,12 +821,12 @@ def defining_ideal(self): homomorphism theorems, this is actually a quotient by a sum of two ideals:: - sage: R. = PolynomialRing(QQ,2) - sage: S. = QuotientRing(R,R.ideal(1 + y^2)) - sage: T. = QuotientRing(S,S.ideal(a)) - sage: S.defining_ideal() + sage: R. = PolynomialRing(QQ, 2) + sage: S. = QuotientRing(R, R.ideal(1 + y^2)) # optional - sage.libs.singular + sage: T. = QuotientRing(S, S.ideal(a)) # optional - sage.libs.singular + sage: S.defining_ideal() # optional - sage.libs.singular Ideal (y^2 + 1) of Multivariate Polynomial Ring in x, y over Rational Field - sage: T.defining_ideal() + sage: T.defining_ideal() # optional - sage.libs.singular Ideal (x, y^2 + 1) of Multivariate Polynomial Ring in x, y over Rational Field """ return self.__I @@ -822,15 +839,15 @@ def is_field(self, proof = True): TESTS:: - sage: Q = QuotientRing(ZZ,7*ZZ) - sage: Q.is_field() + sage: Q = QuotientRing(ZZ, 7*ZZ) + sage: Q.is_field() # optional - sage.libs.pari True Requires the ``is_maximal`` method of the defining ideal to be implemented:: sage: R. = ZZ[] - sage: R.quotient_ring(R.ideal([2, 4 +x])).is_field() + sage: R.quotient_ring(R.ideal([2, 4 + x])).is_field() # optional - sage.libs.pari Traceback (most recent call last): ... NotImplementedError @@ -857,19 +874,19 @@ def is_integral_domain(self, proof=True): EXAMPLES:: sage: R. = QQ[] - sage: R.quo(x^2 - y).is_integral_domain() + sage: R.quo(x^2 - y).is_integral_domain() # optional - sage.singular True - sage: R.quo(x^2 - y^2).is_integral_domain() + sage: R.quo(x^2 - y^2).is_integral_domain() # optional - sage.singular False - sage: R.quo(x^2 - y^2).is_integral_domain(proof=False) + sage: R.quo(x^2 - y^2).is_integral_domain(proof=False) # optional - sage.singular False - sage: R. = ZZ[] - sage: Q = R.quotient_ring([a, b]) - sage: Q.is_integral_domain() + sage: R. = ZZ[] # optional - sage.singular + sage: Q = R.quotient_ring([a, b]) # optional - sage.singular + sage: Q.is_integral_domain() # optional - sage.singular Traceback (most recent call last): ... NotImplementedError - sage: Q.is_integral_domain(proof=False) + sage: Q.is_integral_domain(proof=False) # optional - sage.singular False """ if proof: @@ -886,13 +903,13 @@ def is_noetherian(self): EXAMPLES:: - sage: R = QuotientRing(ZZ, 102*ZZ) + sage: R = QuotientRing(ZZ, 102 * ZZ) sage: R.is_noetherian() True sage: P. = QQ[] - sage: R = QuotientRing(P, x^2+1) - sage: R.is_noetherian() + sage: R = QuotientRing(P, x^2 + 1) # optional - sage.libs.pari + sage: R.is_noetherian() # optional - sage.libs.pari True If the cover ring of ``self`` is not Noetherian, we currently @@ -903,8 +920,8 @@ def is_noetherian(self): sage: R.is_noetherian() False sage: I = R.ideal([x[1]^2, x[2]]) - sage: S = R.quotient(I) - sage: S.is_noetherian() + sage: S = R.quotient(I) # optional - sage.libs.pari + sage: S.is_noetherian() # optional - sage.libs.pari Traceback (most recent call last): ... NotImplementedError @@ -923,15 +940,15 @@ def cover_ring(self): EXAMPLES:: - sage: Q = QuotientRing(ZZ,7*ZZ) + sage: Q = QuotientRing(ZZ, 7 * ZZ) sage: Q.cover_ring() Integer Ring :: sage: P. = QQ[] - sage: Q = QuotientRing(P, x^2 + 1) - sage: Q.cover_ring() + sage: Q = QuotientRing(P, x^2 + 1) # optional - sage.libs.pari + sage: Q.cover_ring() # optional - sage.libs.pari Univariate Polynomial Ring in x over Rational Field """ return self.__R @@ -946,11 +963,13 @@ def ideal(self, *gens, **kwds): EXAMPLES:: sage: R. = PolynomialRing(QQ) - sage: S = R.quotient_ring(x^2+y^2) - sage: S.ideal() - Ideal (0) of Quotient of Multivariate Polynomial Ring in x, y over Rational Field by the ideal (x^2 + y^2) - sage: S.ideal(x+y+1) - Ideal (xbar + ybar + 1) of Quotient of Multivariate Polynomial Ring in x, y over Rational Field by the ideal (x^2 + y^2) + sage: S = R.quotient_ring(x^2 + y^2) + sage: S.ideal() # optional - sage.libs.pari + Ideal (0) of Quotient of Multivariate Polynomial Ring in x, y + over Rational Field by the ideal (x^2 + y^2) + sage: S.ideal(x + y + 1) # optional - sage.libs.pari + Ideal (xbar + ybar + 1) of Quotient of Multivariate Polynomial Ring in x, y + over Rational Field by the ideal (x^2 + y^2) TESTS: @@ -986,10 +1005,10 @@ def _element_constructor_(self, x, coerce=True): EXAMPLES:: sage: R. = PolynomialRing(QQ) - sage: S = R.quotient_ring(x^2+y^2) - sage: S(x) # indirect doctest + sage: S = R.quotient_ring(x^2 + y^2) + sage: S(x) # indirect doctest # optional - sage.libs.singular xbar - sage: S(x^2 + y^2) + sage: S(x^2 + y^2) # optional - sage.libs.singular 0 The rings that coerce into the quotient ring canonically, are: @@ -1002,21 +1021,22 @@ def _element_constructor_(self, x, coerce=True): :: sage: R. = PolynomialRing(QQ, 2) - sage: S. = R.quotient(x^2 + y^2) - sage: S.coerce(0) + sage: S. = R.quotient(x^2 + y^2) # optional - sage.libs.singular + sage: S.coerce(0) # optional - sage.libs.singular 0 - sage: S.coerce(2/3) + sage: S.coerce(2/3) # optional - sage.libs.singular 2/3 - sage: S.coerce(a^2 - b) + sage: S.coerce(a^2 - b) # optional - sage.libs.singular -b^2 - b - sage: S.coerce(GF(7)(3)) + sage: S.coerce(GF(7)(3)) # optional - sage.rings.finite_rings sage.libs.singular Traceback (most recent call last): ... - TypeError: no canonical coercion from Finite Field of size 7 to Quotient of Multivariate Polynomial Ring in x, y over Rational Field by the ideal (x^2 + y^2) + TypeError: no canonical coercion from Finite Field of size 7 + to Quotient of Multivariate Polynomial Ring in x, y over Rational Field by the ideal (x^2 + y^2) TESTS:: - sage: S(x, coerce=False) + sage: S(x, coerce=False) # optional - sage.libs.singular a """ if isinstance(x, quotient_ring_element.QuotientRingElement): @@ -1039,15 +1059,15 @@ def _coerce_map_from_(self, R): EXAMPLES:: sage: R. = PolynomialRing(QQ) - sage: S = R.quotient_ring(x^2+y^2) + sage: S = R.quotient_ring(x^2 + y^2) sage: S.has_coerce_map_from(R) # indirect doctest True sage: S.has_coerce_map_from(QQ) True - sage: T = S.quotient_ring(x^3 - y) - sage: S.has_coerce_map_from(T) + sage: T = S.quotient_ring(x^3 - y) # optional - sage.libs.singular + sage: S.has_coerce_map_from(T) # optional - sage.libs.singular False - sage: T.has_coerce_map_from(R) + sage: T.has_coerce_map_from(R) # optional - sage.libs.singular True TESTS: @@ -1055,33 +1075,33 @@ def _coerce_map_from_(self, R): We check that :trac:`13682` is fixed:: sage: R. = PolynomialRing(QQ) - sage: I = R.ideal(x^2+y^2) - sage: J = R.ideal(x^2+y^2, x^3 - y) - sage: I < J + sage: I = R.ideal(x^2 + y^2) + sage: J = R.ideal(x^2 + y^2, x^3 - y) + sage: I < J # optional - sage.libs.singular True - sage: S = R.quotient(I) - sage: T = R.quotient(J) - sage: T.has_coerce_map_from(S) + sage: S = R.quotient(I) # optional - sage.libs.singular + sage: T = R.quotient(J) # optional - sage.libs.singular + sage: T.has_coerce_map_from(S) # optional - sage.libs.singular True - sage: S.quotient_ring(x^4-x*y+1).has_coerce_map_from(S) + sage: S.quotient_ring(x^4 - x*y + 1).has_coerce_map_from(S) # optional - sage.libs.singular True - sage: S.has_coerce_map_from(T) + sage: S.has_coerce_map_from(T) # optional - sage.libs.singular False We also allow coercions with the cover rings:: sage: Rp. = PolynomialRing(ZZ) - sage: Ip = Rp.ideal(x^2+y^2) - sage: Jp = Rp.ideal(x^2+y^2, x^3 - y) - sage: Sp = Rp.quotient(Ip) - sage: Tp = Rp.quotient(Jp) - sage: R.has_coerce_map_from(Rp) + sage: Ip = Rp.ideal(x^2 + y^2) + sage: Jp = Rp.ideal(x^2 + y^2, x^3 - y) + sage: Sp = Rp.quotient(Ip) # optional - sage.libs.singular + sage: Tp = Rp.quotient(Jp) # optional - sage.libs.singular + sage: R.has_coerce_map_from(Rp) # optional - sage.libs.singular True - sage: Sp.has_coerce_map_from(Sp) + sage: Sp.has_coerce_map_from(Sp) # optional - sage.libs.singular True - sage: T.has_coerce_map_from(Sp) + sage: T.has_coerce_map_from(Sp) # optional - sage.libs.singular True - sage: Sp.has_coerce_map_from(T) + sage: Sp.has_coerce_map_from(T) # optional - sage.libs.singular False """ C = self.cover_ring() @@ -1113,9 +1133,9 @@ def __richcmp__(self, other, op): equal, but since the generators are different, the corresponding quotient rings are not equal:: - sage: R.ideal(x^2+y^2) == R.ideal(-x^2 - y^2) + sage: R.ideal(x^2 + y^2) == R.ideal(-x^2 - y^2) # optional - sage.libs.singular True - sage: R.quotient_ring(x^2 + y^2) == R.quotient_ring(-x^2 - y^2) + sage: R.quotient_ring(x^2 + y^2) == R.quotient_ring(-x^2 - y^2) # optional - sage.libs.singular False """ if not isinstance(other, QuotientRing_nc): @@ -1137,7 +1157,7 @@ def ngens(self): EXAMPLES:: - sage: R = QuotientRing(ZZ,7*ZZ) + sage: R = QuotientRing(ZZ, 7*ZZ) sage: R.gens(); R.ngens() (1,) 1 @@ -1145,15 +1165,16 @@ def ngens(self): :: sage: R. = PolynomialRing(QQ,2) - sage: S. = QuotientRing(R,R.ideal(1 + y^2)) - sage: T. = QuotientRing(S,S.ideal(a)) - sage: T - Quotient of Multivariate Polynomial Ring in x, y over Rational Field by the ideal (x, y^2 + 1) - sage: R.gens(); S.gens(); T.gens() + sage: S. = QuotientRing(R, R.ideal(1 + y^2)) # optional - sage.libs.singular + sage: T. = QuotientRing(S, S.ideal(a)) # optional - sage.libs.singular + sage: T # optional - sage.libs.singular + Quotient of Multivariate Polynomial Ring in x, y over Rational Field + by the ideal (x, y^2 + 1) + sage: R.gens(); S.gens(); T.gens() # optional - sage.libs.singular (x, y) (a, b) (0, d) - sage: R.ngens(); S.ngens(); T.ngens() + sage: R.ngens(); S.ngens(); T.ngens() # optional - sage.libs.singular 2 2 2 @@ -1166,24 +1187,25 @@ def gen(self, i=0): EXAMPLES:: - sage: R = QuotientRing(ZZ,7*ZZ) + sage: R = QuotientRing(ZZ, 7*ZZ) sage: R.gen(0) 1 :: sage: R. = PolynomialRing(QQ,2) - sage: S. = QuotientRing(R,R.ideal(1 + y^2)) - sage: T. = QuotientRing(S,S.ideal(a)) - sage: T - Quotient of Multivariate Polynomial Ring in x, y over Rational Field by the ideal (x, y^2 + 1) - sage: R.gen(0); R.gen(1) + sage: S. = QuotientRing(R, R.ideal(1 + y^2)) # optional - sage.libs.singular + sage: T. = QuotientRing(S, S.ideal(a)) # optional - sage.libs.singular + sage: T # optional - sage.libs.singular + Quotient of Multivariate Polynomial Ring in x, y over Rational Field + by the ideal (x, y^2 + 1) + sage: R.gen(0); R.gen(1) # optional - sage.libs.singular x y - sage: S.gen(0); S.gen(1) + sage: S.gen(0); S.gen(1) # optional - sage.libs.singular a b - sage: T.gen(0); T.gen(1) + sage: T.gen(0); T.gen(1) # optional - sage.libs.singular 0 d """ @@ -1209,8 +1231,8 @@ def _singular_(self, singular=None): EXAMPLES:: sage: R. = PolynomialRing(QQ) - sage: S = R.quotient_ring(x^2+y^2) - sage: S._singular_() + sage: S = R.quotient_ring(x^2 + y^2) + sage: S._singular_() # optional - sage.libs.singular polynomial ring, over a field, global ordering // coefficients: QQ // number of vars : 2 @@ -1243,11 +1265,11 @@ def _singular_init_(self, singular=None): EXAMPLES:: sage: R. = PolynomialRing(QQ) - sage: S = R.quotient_ring(x^2+y^2) - sage: T = S._singular_init_() - sage: parent(S) + sage: S = R.quotient_ring(x^2 + y^2) + sage: T = S._singular_init_() # optional - sage.libs.singular + sage: parent(S) # optional - sage.libs.singular - sage: parent(T) + sage: parent(T) # optional - sage.libs.singular Singular """ if singular is None: @@ -1267,9 +1289,9 @@ def _magma_init_(self, magma): EXAMPLES:: - sage: P. = PolynomialRing(GF(2)) - sage: Q = P.quotient(sage.rings.ideal.FieldIdeal(P)) - sage: magma(Q) # optional - magma # indirect doctest + sage: P. = PolynomialRing(GF(2)) # optional - sage.rings.finite_rings + sage: Q = P.quotient(sage.rings.ideal.FieldIdeal(P)) # optional - sage.rings.finite_rings + sage: magma(Q) # optional - magma # indirect doctest # optional - sage.rings.finite_rings Affine Algebra of rank 2 over GF(2) Graded Reverse Lexicographical Order Variables: x, y @@ -1307,7 +1329,8 @@ class QuotientRing_generic(QuotientRing_nc, ring.CommutativeRing): sage: R. = PolynomialRing(ZZ) sage: I = R.ideal([4 + 3*x + x^2, 1 + x^2]) sage: S = R.quotient_ring(I); S - Quotient of Univariate Polynomial Ring in x over Integer Ring by the ideal (x^2 + 3*x + 4, x^2 + 1) + Quotient of Univariate Polynomial Ring in x over Integer Ring + by the ideal (x^2 + 3*x + 4, x^2 + 1) """ def __init__(self, R, I, names, category=None): @@ -1361,11 +1384,12 @@ def _macaulay2_init_(self, macaulay2=None): 2 2 2 (x*y - z , y - w ) - sage: R. = PolynomialRing(GF(101), 2) - sage: I = R.ideal([x^2 + x, y^2 + y]) - sage: Q = R.quotient_ring(I); Q - Quotient of Multivariate Polynomial Ring in x, y over Finite Field of size 101 by the ideal (x^2 + x, y^2 + y) - sage: Q._macaulay2_init_() # optional - macaulay2 + sage: R. = PolynomialRing(GF(101), 2) # optional - sage.rings.finite_rings + sage: I = R.ideal([x^2 + x, y^2 + y]) # optional - sage.rings.finite_rings + sage: Q = R.quotient_ring(I); Q # optional - sage.rings.finite_rings + Quotient of Multivariate Polynomial Ring in x, y over + Finite Field of size 101 by the ideal (x^2 + x, y^2 + y) + sage: Q._macaulay2_init_() # optional - macaulay2 # optional - sage.rings.finite_rings ZZ ---[x...y] 101 @@ -1439,12 +1463,12 @@ def _contains_(self, other): :: sage: R. = QQ[] - sage: S. = R.quotient(T^3-1) - sage: 1 in S.ideal(t^2-1) + sage: S. = R.quotient(T^3 - 1) # optional - sage.libs.pari + sage: 1 in S.ideal(t^2 - 1) # optional - sage.libs.pari False - sage: 7 in S.ideal(t^2+1) + sage: 7 in S.ideal(t^2 + 1) # optional - sage.libs.pari True - sage: 5-5*t in S.ideal(t^2-1) + sage: 5-5*t in S.ideal(t^2 - 1) # optional - sage.libs.pari True """ R = self.ring() diff --git a/src/sage/rings/quotient_ring_element.py b/src/sage/rings/quotient_ring_element.py index 05cc52e7681..27ceb3ceaf9 100644 --- a/src/sage/rings/quotient_ring_element.py +++ b/src/sage/rings/quotient_ring_element.py @@ -45,7 +45,8 @@ class QuotientRingElement(RingElement): sage: R. = PolynomialRing(ZZ) sage: S. = R.quo((4 + 3*x + x^2, 1 + x^2)); S - Quotient of Univariate Polynomial Ring in x over Integer Ring by the ideal (x^2 + 3*x + 4, x^2 + 1) + Quotient of Univariate Polynomial Ring in x over Integer Ring + by the ideal (x^2 + 3*x + 4, x^2 + 1) sage: v = S.gens(); v (xbar,) @@ -58,24 +59,25 @@ class QuotientRingElement(RingElement): sage: R. = PolynomialRing(QQ, 2) sage: S = R.quo(x^2 + y^2); S - Quotient of Multivariate Polynomial Ring in x, y over Rational Field by the ideal (x^2 + y^2) - sage: S.gens() + Quotient of Multivariate Polynomial Ring in x, y over Rational Field + by the ideal (x^2 + y^2) + sage: S.gens() # optional - sage.libs.singular (xbar, ybar) We name each of the generators. :: - sage: S. = R.quotient(x^2 + y^2) - sage: a + sage: S. = R.quotient(x^2 + y^2) # optional - sage.libs.singular + sage: a # optional - sage.libs.singular a - sage: b + sage: b # optional - sage.libs.singular b - sage: a^2 + b^2 == 0 + sage: a^2 + b^2 == 0 # optional - sage.libs.singular True - sage: b.lift() + sage: b.lift() # optional - sage.libs.singular y - sage: (a^3 + b^2).lift() + sage: (a^3 + b^2).lift() # optional - sage.libs.singular -x*y^2 + y^2 """ def __init__(self, parent, rep, reduce=True): @@ -87,7 +89,8 @@ def __init__(self, parent, rep, reduce=True): sage: R. = PolynomialRing(ZZ) sage: S. = R.quo((4 + 3*x + x^2, 1 + x^2)); S - Quotient of Univariate Polynomial Ring in x over Integer Ring by the ideal (x^2 + 3*x + 4, x^2 + 1) + Quotient of Univariate Polynomial Ring in x over Integer Ring + by the ideal (x^2 + 3*x + 4, x^2 + 1) sage: v = S.gens(); v (xbar,) """ @@ -106,10 +109,10 @@ def _reduce_(self): TESTS:: - sage: R. = QQ[]; S. = R.quo(x^2 + y^2); type(a) + sage: R. = QQ[]; S. = R.quo(x^2 + y^2); type(a) # optional - sage.libs.singular - sage: a._reduce_() - sage: a._QuotientRingElement__rep + sage: a._reduce_() # optional - sage.libs.singular + sage: a._QuotientRingElement__rep # optional - sage.libs.singular x """ I = self.parent().defining_ideal() @@ -122,55 +125,55 @@ def lift(self): EXAMPLES:: - sage: R. = QQ[]; S. = R.quo(x^2 + y^2); type(a) + sage: R. = QQ[]; S. = R.quo(x^2 + y^2); type(a) # optional - sage.libs.singular - sage: a.lift() + sage: a.lift() # optional - sage.libs.singular x - sage: (3/5*(a + a^2 + b^2)).lift() + sage: (3/5*(a + a^2 + b^2)).lift() # optional - sage.libs.singular 3/5*x """ return self.__rep def __bool__(self): """ - Return True if quotient ring element is non-zero in the + Return ``True`` if quotient ring element is non-zero in the quotient ring `R/I`, by determining whether the element is in `I`. EXAMPLES:: - sage: R. = QQ[]; S. = R.quo(x^2 + y^2); type(a) + sage: R. = QQ[]; S. = R.quo(x^2 + y^2); type(a) # optional - sage.libs.singular - sage: bool(a) # indirect doctest + sage: bool(a) # indirect doctest # optional - sage.libs.singular True - sage: bool(S(0)) + sage: bool(S(0)) # optional - sage.libs.singular False TESTS:: - sage: bool(a - a) + sage: bool(a - a) # optional - sage.libs.singular False """ return self.__rep not in self.parent().defining_ideal() def is_unit(self): """ - Return True if self is a unit in the quotient ring. + Return ``True`` if self is a unit in the quotient ring. EXAMPLES:: - sage: R. = QQ[]; S. = R.quo(1 - x*y); type(a) + sage: R. = QQ[]; S. = R.quo(1 - x*y); type(a) # optional - sage.libs.singular - sage: a*b + sage: a*b # optional - sage.libs.singular 1 - sage: S(2).is_unit() + sage: S(2).is_unit() # optional - sage.libs.singular True Check that :trac:`29469` is fixed:: - sage: a.is_unit() + sage: a.is_unit() # optional - sage.libs.singular True - sage: (a+b).is_unit() + sage: (a+b).is_unit() # optional - sage.libs.singular False """ if self.__rep.is_unit(): @@ -191,18 +194,18 @@ def _repr_(self): TESTS:: - sage: R. = QQ[]; S. = R.quo(x^2 + y^2); type(a) + sage: R. = QQ[]; S. = R.quo(x^2 + y^2); type(a) # optional - sage.libs.singular - sage: a-2*a*b # indirect doctest + sage: a-2*a*b # indirect doctest # optional - sage.libs.singular -2*a*b + a In :trac:`11068`, the case of quotient rings without assigned names has been covered as well:: - sage: S = SteenrodAlgebra(2) - sage: I = S*[S.0+S.1]*S - sage: Q = S.quo(I) - sage: Q.0 + sage: S = SteenrodAlgebra(2) # optional - sage.libs.singular + sage: I = S * [S.0 + S.1] * S # optional - sage.libs.singular + sage: Q = S.quo(I) # optional - sage.libs.singular + sage: Q.0 # optional - sage.libs.singular Sq(1) """ @@ -232,8 +235,8 @@ def _latex_(self): sage: a = R.gen(0) sage: I = R.ideal(a**2 + a + 1) sage: S = R.quotient(I, names=R.variable_names()) - sage: a = S.gen(0) - sage: latex(a) + sage: a = S.gen(0) # optional - sage.libs.singular + sage: latex(a) # optional - sage.libs.singular a """ from sage.structure.parent_gens import localvars @@ -257,20 +260,20 @@ def __pari__(self): EXAMPLES:: sage: R. = QQ[] - sage: I = R.ideal(x^3,y^3) - sage: S. = R.quo(I) - sage: pari(xb) + sage: I = R.ideal(x^3, y^3) + sage: S. = R.quo(I) # optional - sage.libs.singular + sage: pari(xb) # optional - sage.libs.pari sage.libs.singular Traceback (most recent call last): ... ValueError: Pari does not support quotients by non-principal ideals Note that the quotient does work in the case that the ideal is principal:: - sage: I = R.ideal(x^3+y^3) - sage: S. = R.quo(I) - sage: pari(xb)^4 + sage: I = R.ideal(x^3 + y^3) + sage: S. = R.quo(I) # optional - sage.libs.singular + sage: pari(xb)^4 # optional - sage.libs.pari sage.libs.singular Mod(-y^3*x, x^3 + y^3) - sage: pari(yb)^4 + sage: pari(yb)^4 # optional - sage.libs.pari sage.libs.singular Mod(y^4, x^3 + y^3) """ gens = self.parent().defining_ideal().gens() @@ -286,14 +289,14 @@ def _add_(self, right): EXAMPLES:: - sage: R. = QQ[]; S. = R.quo(x^2 + y^2); type(a) + sage: R. = QQ[]; S. = R.quo(x^2 + y^2); type(a) # optional - sage.libs.singular - sage: a + b + sage: a + b # optional - sage.libs.singular a + b TESTS:: - sage: a._add_(b) + sage: a._add_(b) # optional - sage.libs.singular a + b """ return self.__class__(self.parent(), self.__rep + right.__rep) @@ -306,14 +309,14 @@ def _sub_(self, right): EXAMPLES:: - sage: R. = QQ[]; S. = R.quo(x^2 + y^2); type(a) + sage: R. = QQ[]; S. = R.quo(x^2 + y^2); type(a) # optional - sage.libs.singular - sage: a - b + sage: a - b # optional - sage.libs.singular a - b TESTS:: - sage: a._sub_(b) + sage: a._sub_(b) # optional - sage.libs.singular a - b """ return self.__class__(self.parent(), self.__rep - right.__rep) @@ -326,16 +329,16 @@ def _mul_(self, right): EXAMPLES:: - sage: R. = QQ[]; S. = R.quo(x^2 + y^2); type(a) + sage: R. = QQ[]; S. = R.quo(x^2 + y^2); type(a) # optional - sage.libs.singular - sage: a * b + sage: a * b # optional - sage.libs.singular a*b TESTS:: - sage: a._mul_(b) + sage: a._mul_(b) # optional - sage.libs.singular a*b - sage: a._mul_(a) + sage: a._mul_(a) # optional - sage.libs.singular -b^2 """ return self.__class__(self.parent(), self.__rep * right.__rep) @@ -350,30 +353,30 @@ def _div_(self, right): sage: R. = QQ[] sage: I = R.ideal([x^2 + 1, y^3 - 2]) - sage: S. = R.quotient(I) - sage: 1/(1+i) + sage: S. = R.quotient(I) # optional - sage.libs.singular + sage: 1/(1+i) # optional - sage.libs.singular -1/2*i + 1/2 Confirm via symbolic computation:: - sage: 1/(1+sqrt(-1)) + sage: 1/(1+sqrt(-1)) # optional - sage.symbolic -1/2*I + 1/2 Another more complicated quotient:: - sage: b = 1/(i+cuberoot); b + sage: b = 1/(i+cuberoot); b # optional - sage.libs.singular 1/5*i*cuberoot^2 - 2/5*i*cuberoot + 2/5*cuberoot^2 - 1/5*i + 1/5*cuberoot - 2/5 - sage: b*(i+cuberoot) + sage: b*(i+cuberoot) # optional - sage.libs.singular 1 Another really easy example:: - sage: R. = QQ[]; S. = R.quo(x^2 + y^2); type(a) + sage: R. = QQ[]; S. = R.quo(x^2 + y^2); type(a) # optional - sage.libs.singular - sage: a / S(2) + sage: a / S(2) # optional - sage.libs.singular 1/2*a - sage: (a*b)._div_(b) + sage: (a*b)._div_(b) # optional - sage.libs.singular a An example in which we try to divide in a ring that is not a @@ -381,18 +384,18 @@ def _div_(self, right): sage: R. = QQ[] sage: I = R.ideal([x^2 - 1, y^3 - 2]) - sage: S. = R.quotient(I) - sage: 1/cuberoot + sage: S. = R.quotient(I) # optional - sage.libs.singular + sage: 1/cuberoot # optional - sage.libs.singular 1/2*cuberoot^2 - sage: 1/a + sage: 1/a # optional - sage.libs.singular a Check that :trac:`13670` is fixed (i.e. that the error message actually describes what happens when the result of division is not defined):: sage: R. = QQ[] - sage: S = R.quotient_ring( R.ideal(x2**2 + x1 - 2, x1**2 - 1) ) - sage: 1 / S(x1 + x2) + sage: S = R.quotient_ring( R.ideal(x2**2 + x1 - 2, x1**2 - 1) ) # optional - sage.libs.singular + sage: 1 / S(x1 + x2) # optional - sage.libs.singular Traceback (most recent call last): ... ArithmeticError: Division failed. The numerator is not a multiple of the denominator. @@ -404,7 +407,7 @@ def _div_(self, right): sage: R. = QQ[] sage: S. = R[] - sage: Z. = S.quotient([y^2 - 2, z^2 - 3]) + sage: Z. = S.quotient([y^2 - 2, z^2 - 3]) # optional - sage.libs.singular Traceback (most recent call last): ... TypeError: Can only reduce polynomials over fields. @@ -472,15 +475,15 @@ def _im_gens_(self, codomain, im_gens, base_map=None): quotient ring work correctly (see :trac:`16135`):: sage: R. = QQ[] - sage: K = R.quotient(x^2 - y^3).fraction_field() + sage: K = R.quotient(x^2 - y^3).fraction_field() # optional - sage.libs.singular sage: L. = FunctionField(QQ) - sage: f = K.hom((t^3, t^2)) - sage: list(map(f, K.gens())) + sage: f = K.hom((t^3, t^2)) # optional - sage.libs.singular + sage: list(map(f, K.gens())) # optional - sage.libs.singular [t^3, t^2] - sage: xbar, ybar = K.gens() - sage: f(1/ybar) + sage: xbar, ybar = K.gens() # optional - sage.libs.singular + sage: f(1/ybar) # optional - sage.libs.singular 1/t^2 - sage: f(xbar/ybar) + sage: f(xbar/ybar) # optional - sage.libs.singular t """ return self.lift()._im_gens_(codomain, im_gens, base_map=base_map) @@ -493,13 +496,13 @@ def __int__(self): EXAMPLES:: - sage: R. = QQ[]; S. = R.quo(x^2 + y^2); type(a) + sage: R. = QQ[]; S. = R.quo(x^2 + y^2); type(a) # optional - sage.libs.singular - sage: int(S(-3)) # indirect doctest + sage: int(S(-3)) # indirect doctest # optional - sage.libs.singular -3 - sage: type(int(S(-3))) + sage: type(int(S(-3))) # optional - sage.libs.singular <... 'int'> - sage: int(a) + sage: int(a) # optional - sage.libs.singular Traceback (most recent call last): ... TypeError: unable to convert non-constant polynomial x to @@ -510,14 +513,14 @@ def _integer_(self, Z): """ EXAMPLES:: - sage: R. = QQ[]; S. = R.quo(x^2 + y^2); type(a) + sage: R. = QQ[]; S. = R.quo(x^2 + y^2); type(a) # optional - sage.libs.singular - sage: ZZ(S(-3)) + sage: ZZ(S(-3)) # optional - sage.libs.singular -3 TESTS:: - sage: type(ZZ(S(-3))) + sage: type(ZZ(S(-3))) # optional - sage.libs.singular """ return Z(self.lift()) @@ -526,14 +529,14 @@ def _rational_(self): """ EXAMPLES:: - sage: R. = QQ[]; S. = R.quo(x^2 + y^2); type(a) + sage: R. = QQ[]; S. = R.quo(x^2 + y^2); type(a) # optional - sage.libs.singular - sage: QQ(S(-2/3)) + sage: QQ(S(-2/3)) # optional - sage.libs.singular -2/3 TESTS:: - sage: type(S(-2/3)._rational_()) + sage: type(S(-2/3)._rational_()) # optional - sage.libs.singular """ from sage.rings.rational_field import QQ @@ -543,11 +546,11 @@ def __neg__(self): """ EXAMPLES:: - sage: R. = QQ[]; S. = R.quo(x^2 + y^2); type(a) + sage: R. = QQ[]; S. = R.quo(x^2 + y^2); type(a) # optional - sage.libs.singular - sage: -a # indirect doctest + sage: -a # indirect doctest # optional - sage.libs.singular -a - sage: -(a+b) + sage: -(a+b) # optional - sage.libs.singular -a - b """ return self.__class__(self.parent(), -self.__rep) @@ -556,11 +559,11 @@ def __pos__(self): """ TESTS:: - sage: R. = QQ[]; S. = R.quo(x^2 + y^2); type(a) + sage: R. = QQ[]; S. = R.quo(x^2 + y^2); type(a) # optional - sage.libs.singular - sage: (a+b).__pos__() + sage: (a+b).__pos__() # optional - sage.libs.singular a + b - sage: c = a+b; c.__pos__() is c + sage: c = a+b; c.__pos__() is c # optional - sage.libs.singular True """ return self @@ -569,19 +572,19 @@ def __invert__(self): """ EXAMPLES:: - sage: R. = QQ[]; S. = R.quo(x^2 + y^2); type(a) + sage: R. = QQ[]; S. = R.quo(x^2 + y^2); type(a) # optional - sage.libs.singular - sage: ~S(2/3) + sage: ~S(2/3) # optional - sage.libs.singular 3/2 TESTS:: - sage: S(2/3).__invert__() + sage: S(2/3).__invert__() # optional - sage.libs.singular 3/2 Note that a is not invertible as an element of R:: - sage: a.__invert__() + sage: a.__invert__() # optional - sage.libs.singular Traceback (most recent call last): ... ArithmeticError: element is non-invertible @@ -596,11 +599,11 @@ def __float__(self): """ EXAMPLES:: - sage: R. = QQ[]; S. = R.quo(x^2 + y^2); type(a) + sage: R. = QQ[]; S. = R.quo(x^2 + y^2); type(a) # optional - sage.libs.singular - sage: float(S(2/3)) + sage: float(S(2/3)) # optional - sage.libs.singular 0.6666666666666666 - sage: float(a) + sage: float(a) # optional - sage.libs.singular Traceback (most recent call last): ... TypeError: unable to convert non-constant polynomial x to @@ -611,10 +614,10 @@ def __hash__(self): r""" TESTS:: - sage: R. = QQ[] - sage: S. = R.quo(x^2 + y^2) - sage: c = a*a + b - sage: hash(a) != hash(b) + sage: R. = QQ[] # optional - sage.libs.singular + sage: S. = R.quo(x^2 + y^2) # optional - sage.libs.singular + sage: c = a*a + b # optional - sage.libs.singular + sage: hash(a) != hash(b) # optional - sage.libs.singular True """ return hash(self.__rep) @@ -623,38 +626,38 @@ def _richcmp_(self, other, op): """ EXAMPLES:: - sage: R. = QQ[]; S. = R.quo(x^2 + y^2); type(a) + sage: R. = QQ[]; S. = R.quo(x^2 + y^2); type(a) # optional - sage.libs.singular - sage: a > b # indirect doctest + sage: a > b # indirect doctest # optional - sage.libs.singular True - sage: b > a + sage: b > a # optional - sage.libs.singular False - sage: a == loads(dumps(a)) + sage: a == loads(dumps(a)) # optional - sage.libs.singular True TESTS:: - sage: a == (a+1-1) + sage: a == (a+1-1) # optional - sage.libs.singular True - sage: a > b + sage: a > b # optional - sage.libs.singular True See :trac:`7797`:: - sage: F. = FreeAlgebra(QQ, implementation='letterplace') - sage: I = F*[x*y+y*z,x^2+x*y-y*x-y^2]*F - sage: Q = F.quo(I) - sage: Q.0^4 # indirect doctest + sage: F. = FreeAlgebra(QQ, implementation='letterplace') # optional - sage.combinat + sage: I = F * [x*y + y*z, x^2 + x*y - y*x - y^2] * F # optional - sage.combinat + sage: Q = F.quo(I) # optional - sage.combinat sage.libs.singular + sage: Q.0^4 # indirect doctest # optional - sage.combinat sage.libs.singular ybar*zbar*zbar*xbar + ybar*zbar*zbar*ybar + ybar*zbar*zbar*zbar The issue from :trac:`8005` was most likely fixed as part of :trac:`9138`:: - sage: F = GF(5) - sage: R.=F[] - sage: I=Ideal(R, [x, y]) - sage: S.=QuotientRing(R,I) - sage: x1^4 + sage: F = GF(5) # optional - sage.rings.finite_rings + sage: R. = F[] # optional - sage.rings.finite_rings + sage: I = Ideal(R, [x, y]) # optional - sage.rings.finite_rings + sage: S. = QuotientRing(R, I) # optional - sage.rings.finite_rings + sage: x1^4 # optional - sage.rings.finite_rings 0 """ # A containment test is not implemented for univariate polynomial @@ -677,18 +680,18 @@ def lt(self): EXAMPLES:: - sage: R.=PolynomialRing(GF(7),3,order='lex') - sage: I = sage.rings.ideal.FieldIdeal(R) - sage: Q = R.quo( I ) - sage: f = Q( z*y + 2*x ) - sage: f.lt() + sage: R. = PolynomialRing(GF(7), 3, order='lex') # optional - sage.rings.finite_rings + sage: I = sage.rings.ideal.FieldIdeal(R) # optional - sage.rings.finite_rings + sage: Q = R.quo(I) # optional - sage.rings.finite_rings + sage: f = Q(z*y + 2*x) # optional - sage.rings.finite_rings + sage: f.lt() # optional - sage.rings.finite_rings 2*xbar TESTS:: - sage: R. = QQ[]; S. = R.quo(x^2 + y^2); type(a) + sage: R. = QQ[]; S. = R.quo(x^2 + y^2); type(a) # optional - sage.libs.singular - sage: (a+3*a*b+b).lt() + sage: (a + 3*a*b + b).lt() # optional - sage.libs.singular 3*a*b """ return self.__class__(self.parent(), self.__rep.lt()) @@ -699,18 +702,18 @@ def lm(self): EXAMPLES:: - sage: R.=PolynomialRing(GF(7),3,order='lex') - sage: I = sage.rings.ideal.FieldIdeal(R) - sage: Q = R.quo( I ) - sage: f = Q( z*y + 2*x ) - sage: f.lm() + sage: R. = PolynomialRing(GF(7), 3, order='lex') # optional - sage.rings.finite_rings + sage: I = sage.rings.ideal.FieldIdeal(R) # optional - sage.rings.finite_rings + sage: Q = R.quo(I) # optional - sage.rings.finite_rings + sage: f = Q(z*y + 2*x) # optional - sage.rings.finite_rings + sage: f.lm() # optional - sage.rings.finite_rings xbar TESTS:: - sage: R. = QQ[]; S. = R.quo(x^2 + y^2); type(a) + sage: R. = QQ[]; S. = R.quo(x^2 + y^2); type(a) # optional - sage.libs.singular - sage: (a+3*a*b+b).lm() + sage: (a+3*a*b+b).lm() # optional - sage.libs.singular a*b """ @@ -722,18 +725,18 @@ def lc(self): EXAMPLES:: - sage: R.=PolynomialRing(GF(7),3,order='lex') - sage: I = sage.rings.ideal.FieldIdeal(R) - sage: Q = R.quo( I ) - sage: f = Q( z*y + 2*x ) - sage: f.lc() + sage: R. = PolynomialRing(GF(7), 3, order='lex') # optional - sage.rings.finite_rings + sage: I = sage.rings.ideal.FieldIdeal(R) # optional - sage.rings.finite_rings + sage: Q = R.quo(I) # optional - sage.rings.finite_rings + sage: f = Q(z*y + 2*x) # optional - sage.rings.finite_rings + sage: f.lc() # optional - sage.rings.finite_rings 2 TESTS:: - sage: R. = QQ[]; S. = R.quo(x^2 + y^2); type(a) + sage: R. = QQ[]; S. = R.quo(x^2 + y^2); type(a) # optional - sage.libs.singular - sage: (a+3*a*b+b).lc() + sage: (a + 3*a*b + b).lc() # optional - sage.libs.singular 3 """ return self.__rep.lc() @@ -749,17 +752,17 @@ def variables(self): EXAMPLES:: - sage: R. = QQ[]; S. = R.quo(x^2 + y^2); type(a) + sage: R. = QQ[]; S. = R.quo(x^2 + y^2); type(a) # optional - sage.libs.singular - sage: a.variables() + sage: a.variables() # optional - sage.libs.singular (a,) - sage: b.variables() + sage: b.variables() # optional - sage.libs.singular (b,) - sage: s = a^2 + b^2 + 1; s + sage: s = a^2 + b^2 + 1; s # optional - sage.libs.singular 1 - sage: s.variables() + sage: s.variables() # optional - sage.libs.singular () - sage: (a+b).variables() + sage: (a + b).variables() # optional - sage.libs.singular (a, b) """ return tuple(self.__class__(self.parent(), v) for v in self.__rep.variables()) @@ -774,13 +777,13 @@ def monomials(self): EXAMPLES:: - sage: R. = QQ[]; S. = R.quo(x^2 + y^2); type(a) + sage: R. = QQ[]; S. = R.quo(x^2 + y^2); type(a) # optional - sage.libs.singular - sage: a.monomials() + sage: a.monomials() # optional - sage.libs.singular [a] - sage: (a+a*b).monomials() + sage: (a + a*b).monomials() # optional - sage.libs.singular [a*b, a] - sage: R.zero().monomials() + sage: R.zero().monomials() # optional - sage.libs.singular [] """ return [self.__class__(self.parent(), m) for m in self.__rep.monomials()] @@ -796,10 +799,10 @@ def _singular_(self, singular=singular_default): EXAMPLES:: - sage: P. = PolynomialRing(GF(2),2) - sage: I = sage.rings.ideal.FieldIdeal(P) - sage: Q = P.quo(I) - sage: Q._singular_() + sage: P. = PolynomialRing(GF(2), 2) # optional - sage.rings.finite_rings + sage: I = sage.rings.ideal.FieldIdeal(P) # optional - sage.rings.finite_rings + sage: Q = P.quo(I) # optional - sage.rings.finite_rings + sage: Q._singular_() # optional - sage.rings.finite_rings polynomial ring, over a field, global ordering // coefficients: ZZ/2 // number of vars : 2 @@ -809,20 +812,20 @@ def _singular_(self, singular=singular_default): // quotient ring from ideal _[1]=x2+x _[2]=y2+y - sage: xbar = Q(x); xbar + sage: xbar = Q(x); xbar # optional - sage.rings.finite_rings xbar - sage: xbar._singular_() + sage: xbar._singular_() # optional - sage.rings.finite_rings x - sage: Q(xbar._singular_()) # a round-trip + sage: Q(xbar._singular_()) # a round-trip # optional - sage.rings.finite_rings xbar TESTS:: - sage: R. = QQ[]; S. = R.quo(x^2 + y^2); type(a) + sage: R. = QQ[]; S. = R.quo(x^2 + y^2); type(a) # optional - sage.libs.singular - sage: (a-2/3*b)._singular_() + sage: (a - 2/3*b)._singular_() # optional - sage.libs.singular x-2/3*y - sage: S((a-2/3*b)._singular_()) + sage: S((a - 2/3*b)._singular_()) # optional - sage.libs.singular a - 2/3*b """ if singular is None: @@ -835,12 +838,12 @@ def _magma_init_(self, magma): EXAMPLES:: - sage: P. = PolynomialRing(GF(2)) - sage: Q = P.quotient(sage.rings.ideal.FieldIdeal(P)) - sage: xbar, ybar = Q.gens() - sage: magma(xbar) # optional -- magma + sage: P. = PolynomialRing(GF(2)) # optional - sage.rings.finite_rings + sage: Q = P.quotient(sage.rings.ideal.FieldIdeal(P)) # optional - sage.rings.finite_rings + sage: xbar, ybar = Q.gens() # optional - sage.rings.finite_rings + sage: magma(xbar) # optional - magma # optional - sage.rings.finite_rings x - sage: xbar._magma_init_(magma) # optional -- magma + sage: xbar._magma_init_(magma) # optional - magma # optional - sage.rings.finite_rings '_sage_[...]!_sage_ref...' """ g = magma(self.__rep) @@ -853,19 +856,19 @@ def _macaulay2_(self, macaulay2=None): EXAMPLES:: - sage: R. = PolynomialRing(GF(7), 2) - sage: Q = R.quotient([x^2 - y]) - sage: x, y = Q.gens() - sage: f = (x^3 + 2*y^2*x)^7; f + sage: R. = PolynomialRing(GF(7), 2) # optional - sage.rings.finite_rings + sage: Q = R.quotient([x^2 - y]) # optional - sage.rings.finite_rings + sage: x, y = Q.gens() # optional - sage.rings.finite_rings + sage: f = (x^3 + 2*y^2*x)^7; f # optional - sage.rings.finite_rings 2*xbar*ybar^17 + xbar*ybar^10 - sage: mf = macaulay2(f); mf # optional - macaulay2 + sage: mf = macaulay2(f); mf # optional - macaulay2 # optional - sage.rings.finite_rings 17 10 2x*y + x*y - sage: mf.sage() # optional - macaulay2 + sage: mf.sage() # optional - macaulay2 # optional - sage.rings.finite_rings 2*x*y^17 + x*y^10 - sage: mf.sage() == f # optional - macaulay2 + sage: mf.sage() == f # optional - macaulay2 # optional - sage.rings.finite_rings True - sage: Q(mf) # optional - macaulay2 + sage: Q(mf) # optional - macaulay2 # optional - sage.rings.finite_rings 2*xbar*ybar^17 + xbar*ybar^10 In Macaulay2, the variable names for a quotient ring are inherited from @@ -877,15 +880,15 @@ def _macaulay2_(self, macaulay2=None): :: - sage: R. = PolynomialRing(GF(7), 2) - sage: Q = R.quotient([x^2 - y], names=R.gens()) - sage: x, y = Q.gens() - sage: f = (x^3 + 2*y^2*x)^7; f + sage: R. = PolynomialRing(GF(7), 2) # optional - sage.rings.finite_rings + sage: Q = R.quotient([x^2 - y], names=R.gens()) # optional - sage.rings.finite_rings + sage: x, y = Q.gens() # optional - sage.rings.finite_rings + sage: f = (x^3 + 2*y^2*x)^7; f # optional - sage.rings.finite_rings 2*x*y^17 + x*y^10 - sage: macaulay2(f) # optional - macaulay2 + sage: macaulay2(f) # optional - macaulay2 # optional - sage.rings.finite_rings 17 10 2x*y + x*y - sage: _.sage() # optional - macaulay2 + sage: _.sage() # optional - macaulay2 # optional - sage.rings.finite_rings 2*x*y^17 + x*y^10 TESTS: @@ -893,15 +896,15 @@ def _macaulay2_(self, macaulay2=None): Check that changing the currently defined global variables (`x`, `y`, ...) in Macaulay2 does not affect the result of this conversion:: - sage: R. = PolynomialRing(GF(7), 2) - sage: Q = R.quotient([x^2 - y], names=R.gens()) - sage: x, y = Q.gens() - sage: f = (x^3 + 2*y^2*x)^7 - sage: macaulay2(f) # optional - macaulay2 + sage: R. = PolynomialRing(GF(7), 2) # optional - sage.rings.finite_rings + sage: Q = R.quotient([x^2 - y], names=R.gens()) # optional - sage.rings.finite_rings + sage: x, y = Q.gens() # optional - sage.rings.finite_rings + sage: f = (x^3 + 2*y^2*x)^7 # optional - sage.rings.finite_rings + sage: macaulay2(f) # optional - macaulay2 # optional - sage.rings.finite_rings 17 10 2x*y + x*y - sage: macaulay2.use(R.quotient([x, y])) # optional - macaulay2 - sage: macaulay2(f) # optional - macaulay2 + sage: macaulay2.use(R.quotient([x, y])) # optional - macaulay2 # optional - sage.rings.finite_rings + sage: macaulay2(f) # optional - macaulay2 # optional - sage.rings.finite_rings 17 10 2x*y + x*y """ @@ -930,17 +933,18 @@ def reduce(self, G): EXAMPLES:: - sage: P. = PolynomialRing(GF(2), 5, order='lex') - sage: I1 = ideal([a*b + c*d + 1, a*c*e + d*e, a*b*e + c*e, b*c + c*d*e + 1]) - sage: Q = P.quotient( sage.rings.ideal.FieldIdeal(P) ) - sage: I2 = ideal([Q(f) for f in I1.gens()]) - sage: f = Q((a*b + c*d + 1)^2 + e) - sage: f.reduce(I2.gens()) + sage: P. = PolynomialRing(GF(2), 5, order='lex') # optional - sage.rings.finite_rings + sage: I1 = ideal([a*b + c*d + 1, a*c*e + d*e, # optional - sage.rings.finite_rings + ....: a*b*e + c*e, b*c + c*d*e + 1]) + sage: Q = P.quotient(sage.rings.ideal.FieldIdeal(P)) # optional - sage.rings.finite_rings + sage: I2 = ideal([Q(f) for f in I1.gens()]) # optional - sage.rings.finite_rings + sage: f = Q((a*b + c*d + 1)^2 + e) # optional - sage.rings.finite_rings + sage: f.reduce(I2.gens()) # optional - sage.rings.finite_rings ebar Notice that the result above is not minimal:: - sage: I2.reduce(f) + sage: I2.reduce(f) # optional - sage.rings.finite_rings 0 """ try: diff --git a/src/sage/rings/rational.pyx b/src/sage/rings/rational.pyx index 0e9d1f35f47..8f5c9df7593 100644 --- a/src/sage/rings/rational.pyx +++ b/src/sage/rings/rational.pyx @@ -300,30 +300,31 @@ cpdef rational_power_parts(a, Rational b, factor_limit=10**5): sage: rational_power_parts(3/4, -1/2) (2, 3) - sage: t = (3/4)^(-1/2); t + sage: t = (3/4)^(-1/2); t # optional - sage.symbolic 2/3*sqrt(3) - sage: t^2 + sage: t^2 # optional - sage.symbolic 4/3 Check if :trac:`15605` is fixed:: sage: rational_power_parts(-1, -1/3) (1, -1) - sage: (-1)^(-1/3) + sage: (-1)^(-1/3) # optional - sage.symbolic -(-1)^(2/3) - sage: 1 / ((-1)^(1/3)) + sage: 1 / ((-1)^(1/3)) # optional - sage.symbolic -(-1)^(2/3) sage: rational_power_parts(-1, 2/3) (1, -1) - sage: (-1)^(2/3) + sage: (-1)^(2/3) # optional - sage.symbolic (-1)^(2/3) sage: all(rational_power_parts(-1, i/77) == (1,-1) for i in range(1,9)) True - sage: (-1)^(1/3)*(-1)^(1/5) + sage: (-1)^(1/3)*(-1)^(1/5) # optional - sage.symbolic (-1)^(8/15) - sage: bool((-1)^(2/3) == -1/2 + sqrt(3)/2*I) + sage: bool((-1)^(2/3) == -1/2 + sqrt(3)/2*I) # optional - sage.symbolic True - sage: all((-1)^(p/q) == cos(p*pi/q) + I * sin(p*pi/q) for p in srange(1,6) for q in srange(1,6)) + sage: all((-1)^(p/q) == cos(p*pi/q) + I * sin(p*pi/q) # optional - sage.symbolic + ....: for p in srange(1, 6) for q in srange(1, 6)) True A few more tests added in :trac:`26414`:: @@ -380,7 +381,7 @@ cpdef rational_power_parts(a, Rational b, factor_limit=10**5): def is_Rational(x): """ - Return true if x is of the Sage rational number type. + Return ``True`` if ``x`` is of the Sage :class:`Rational` type. EXAMPLES:: @@ -422,9 +423,10 @@ cdef class Rational(sage.structure.element.FieldElement): 1/2 sage: Rational(("2", "10"), 16) 1/8 - sage: Rational(QQbar(125/8).nth_root(3)) + sage: Rational(QQbar(125/8).nth_root(3)) # optional - sage.rings.number_field 5/2 - sage: Rational(AA(209735/343 - 17910/49*golden_ratio).nth_root(3) + 3*AA(golden_ratio)) + sage: Rational(AA(209735/343 - 17910/49*golden_ratio).nth_root(3) # optional - sage.rings.number_field + ....: + 3*AA(golden_ratio)) 53/7 sage: QQ(float(1.5)) 3/2 @@ -440,24 +442,24 @@ cdef class Rational(sage.structure.element.FieldElement): Conversion from PARI:: - sage: Rational(pari('-939082/3992923')) + sage: Rational(pari('-939082/3992923')) # optional - sage.libs.pari -939082/3992923 - sage: Rational(pari('Pol([-1/2])')) #9595 + sage: Rational(pari('Pol([-1/2])')) #9595 # optional - sage.libs.pari -1/2 Conversions from numpy:: - sage: import numpy as np - sage: QQ(np.int8('-15')) + sage: import numpy as np # optional - numpy + sage: QQ(np.int8('-15')) # optional - numpy -15 - sage: QQ(np.int16('-32')) + sage: QQ(np.int16('-32')) # optional - numpy -32 - sage: QQ(np.int32('-19')) + sage: QQ(np.int32('-19')) # optional - numpy -19 - sage: QQ(np.uint32('1412')) + sage: QQ(np.uint32('1412')) # optional - numpy 1412 - sage: QQ(np.float16('12')) + sage: QQ(np.float16('12')) # optional - numpy 12 Conversions from gmpy2:: @@ -512,7 +514,7 @@ cdef class Rational(sage.structure.element.FieldElement): 7 sage: a.__init__('70', base=8); a 56 - sage: a.__init__(pari('2/3')); a + sage: a.__init__(pari('2/3')); a # optional - sage.libs.pari 2/3 sage: a.__init__('-h/3ki', 32); a -17/3730 @@ -963,9 +965,9 @@ cdef class Rational(sage.structure.element.FieldElement): EXAMPLES:: - sage: ex = SR(QQ(7)/3); ex + sage: ex = SR(QQ(7)/3); ex # optional - sage.symbolic 7/3 - sage: parent(ex) + sage: parent(ex) # optional - sage.symbolic Symbolic Ring """ return sring._force_pyobject(self, force=True) @@ -976,12 +978,12 @@ cdef class Rational(sage.structure.element.FieldElement): EXAMPLES:: - sage: n = 1/2; n._sympy_() + sage: n = 1/2; n._sympy_() # optional - sympy 1/2 - sage: n = -1/5; n._sympy_() + sage: n = -1/5; n._sympy_() # optional - sympy -1/5 - sage: from sympy import Symbol - sage: QQ(1)+Symbol('x')*QQ(2) + sage: from sympy import Symbol # optional - sympy + sage: QQ(1) + Symbol('x')*QQ(2) # optional - sympy 2*x + 1 """ import sympy @@ -1035,7 +1037,7 @@ cdef class Rational(sage.structure.element.FieldElement): EXAMPLES:: sage: n = -485/82847 - sage: n._magma_init_(magma) # optional - magma + sage: n._magma_init_(magma) # optional - magma '-485/82847' """ return self.numerator()._magma_init_(magma) + '/' + self.denominator()._magma_init_(magma) @@ -1049,16 +1051,16 @@ cdef class Rational(sage.structure.element.FieldElement): EXAMPLES:: - sage: import numpy - sage: numpy.array([1, 2, 3/1]) + sage: import numpy # optional - numpy + sage: numpy.array([1, 2, 3/1]) # optional - numpy array([1, 2, 3]) - sage: numpy.array(QQ(2**40)).dtype + sage: numpy.array(QQ(2**40)).dtype # optional - numpy dtype('int64') - sage: numpy.array(QQ(2**400)).dtype + sage: numpy.array(QQ(2**400)).dtype # optional - numpy dtype('O') - sage: numpy.array([1, 1/2, 3/4]) + sage: numpy.array([1, 1/2, 3/4]) # optional - numpy array([1. , 0.5 , 0.75]) """ if mpz_cmp_ui(mpq_denref(self.value), 1) == 0: @@ -1114,7 +1116,7 @@ cdef class Rational(sage.structure.element.FieldElement): def content(self, other): """ - Return the content of ``self`` and ``other``, i.e. the unique positive + Return the content of ``self`` and ``other``, i.e., the unique positive rational number `c` such that ``self/c`` and ``other/c`` are coprime integers. @@ -1191,7 +1193,7 @@ cdef class Rational(sage.structure.element.FieldElement): - ``p`` -- a prime number - ``prec`` (int) -- desired floating point precision (default: - default RealField precision). + default :class:`RealField` precision). OUTPUT: @@ -1228,7 +1230,7 @@ cdef class Rational(sage.structure.element.FieldElement): INPUT: - ``prec`` (int) -- desired floating point precision (default: - default RealField precision). + default :class:`RealField` precision). OUTPUT: @@ -1264,7 +1266,7 @@ cdef class Rational(sage.structure.element.FieldElement): INPUT: - ``prec`` (int) -- desired floating point precision (default: - default RealField precision). + default :class:`RealField` precision). OUTPUT: @@ -1307,7 +1309,7 @@ cdef class Rational(sage.structure.element.FieldElement): INPUT: - ``prec`` (int) -- desired floating point precision (default: - default RealField precision). + default :class:`RealField` precision). OUTPUT: @@ -1339,7 +1341,7 @@ cdef class Rational(sage.structure.element.FieldElement): INPUT: - ``prec`` (int) -- desired floating point precision (default: - default RealField precision). + default :class:`RealField` precision). OUTPUT: @@ -1402,11 +1404,11 @@ cdef class Rational(sage.structure.element.FieldElement): INPUT: - - ``L`` -- a number field - - ``element`` -- (default: ``False``) boolean whether to also output - an element of which ``self`` is a norm - - proof -- If ``True``, then the output is correct unconditionally. - If ``False``, then the output assumes GRH. + - ``L`` -- a number field + - ``element`` -- (default: ``False``) boolean whether to also output + an element of which ``self`` is a norm + - ``proof`` -- If ``True``, then the output is correct unconditionally. + If ``False``, then the output assumes GRH. OUTPUT: @@ -1418,46 +1420,47 @@ cdef class Rational(sage.structure.element.FieldElement): ALGORITHM: - Uses PARI's bnfisnorm. See ``_bnfisnorm()``. + Uses the PARI function :pari:`bnfisnorm`. See :meth:`_bnfisnorm()`. EXAMPLES:: - sage: K = NumberField(x^2 - 2, 'beta') - sage: (1/7).is_norm(K) + sage: K = NumberField(x^2 - 2, 'beta') # optional - sage.rings.number_field + sage: (1/7).is_norm(K) # optional - sage.rings.number_field True - sage: (1/10).is_norm(K) + sage: (1/10).is_norm(K) # optional - sage.rings.number_field False - sage: 0.is_norm(K) + sage: 0.is_norm(K) # optional - sage.rings.number_field True - sage: (1/7).is_norm(K, element=True) + sage: (1/7).is_norm(K, element=True) # optional - sage.rings.number_field (True, 1/7*beta + 3/7) - sage: (1/10).is_norm(K, element=True) + sage: (1/10).is_norm(K, element=True) # optional - sage.rings.number_field (False, None) - sage: (1/691).is_norm(QQ, element=True) + sage: (1/691).is_norm(QQ, element=True) # optional - sage.rings.number_field (True, 1/691) The number field doesn't have to be defined by an integral polynomial:: - sage: B, e = (1/5).is_norm(QuadraticField(5/4, 'a'), element=True) - sage: B + sage: B, e = (1/5).is_norm(QuadraticField(5/4, 'a'), element=True) # optional - sage.rings.number_field + sage: B # optional - sage.rings.number_field True - sage: e.norm() + sage: e.norm() # optional - sage.rings.number_field 1/5 A non-Galois number field:: - sage: K. = NumberField(x^3-2) - sage: B, e = (3/5).is_norm(K, element=True); B + sage: K. = NumberField(x^3 - 2) # optional - sage.rings.number_field + sage: B, e = (3/5).is_norm(K, element=True); B # optional - sage.rings.number_field True - sage: e.norm() + sage: e.norm() # optional - sage.rings.number_field 3/5 - sage: 7.is_norm(K) + sage: 7.is_norm(K) # optional - sage.rings.number_field Traceback (most recent call last): ... - NotImplementedError: is_norm is not implemented unconditionally for norms from non-Galois number fields - sage: 7.is_norm(K, proof=False) + NotImplementedError: is_norm is not implemented unconditionally + for norms from non-Galois number fields + sage: 7.is_norm(K, proof=False) # optional - sage.rings.number_field False AUTHORS: @@ -1540,9 +1543,9 @@ cdef class Rational(sage.structure.element.FieldElement): EXAMPLES:: - sage: QQ(2)._bnfisnorm(QuadraticField(-1, 'i')) + sage: QQ(2)._bnfisnorm(QuadraticField(-1, 'i')) # optional - sage.rings.number_field (i + 1, 1) - sage: 7._bnfisnorm(NumberField(x^3-2, 'b')) + sage: 7._bnfisnorm(NumberField(x^3 - 2, 'b')) # optional - sage.rings.number_field (1, 7) AUTHORS: @@ -1609,9 +1612,9 @@ cdef class Rational(sage.structure.element.FieldElement): This test makes sure we workaround a bug in GMP (see :trac:`4612`):: - sage: [ -a for a in srange(100) if not QQ(-a^3).is_perfect_power() ] + sage: [-a for a in srange(100) if not QQ(-a^3).is_perfect_power()] [] - sage: [ -a for a in srange(100) if not QQ(-a^3).is_perfect_power(True) ] + sage: [-a for a in srange(100) if not QQ(-a^3).is_perfect_power(True)] [] """ cdef int s @@ -1694,7 +1697,7 @@ cdef class Rational(sage.structure.element.FieldElement): def squarefree_part(self): """ - Return the square free part of `x`, i.e., an integer z such + Return the square free part of `x`, i.e., an integer `z` such that `x = z y^2`, for a perfect square `y^2`. EXAMPLES:: @@ -1901,16 +1904,16 @@ cdef class Rational(sage.structure.element.FieldElement): sage: x.sqrt(all=True) [10, -10] sage: x = 81/5 - sage: x.sqrt() + sage: x.sqrt() # optional - sage.symbolic 9*sqrt(1/5) sage: x = -81/3 - sage: x.sqrt() + sage: x.sqrt() # optional - sage.symbolic 3*sqrt(-3) :: sage: n = 2/3 - sage: n.sqrt() + sage: n.sqrt() # optional - sage.symbolic sqrt(2/3) sage: n.sqrt(prec=10) 0.82 @@ -1924,7 +1927,7 @@ cdef class Rational(sage.structure.element.FieldElement): Traceback (most recent call last): ... ValueError: square root of 2/3 not a rational number - sage: sqrt(-2/3, all=True) + sage: sqrt(-2/3, all=True) # optional - sage.symbolic [sqrt(-2/3), -sqrt(-2/3)] sage: sqrt(-2/3, prec=53) 0.816496580927726*I @@ -1990,20 +1993,20 @@ cdef class Rational(sage.structure.element.FieldElement): EXAMPLES:: - sage: (1/7).period() + sage: (1/7).period() # optional - sage.libs.pari 6 sage: RR(1/7) 0.142857142857143 - sage: (1/8).period() + sage: (1/8).period() # optional - sage.libs.pari 1 sage: RR(1/8) 0.125000000000000 sage: RR(1/6) 0.166666666666667 - sage: (1/6).period() + sage: (1/6).period() # optional - sage.libs.pari 1 sage: x = 333/106 - sage: x.period() + sage: x.period() # optional - sage.libs.pari 13 sage: RealField(200)(x) 3.1415094339622641509433962264150943396226415094339622641509 @@ -2022,7 +2025,7 @@ cdef class Rational(sage.structure.element.FieldElement): INPUT: - - ``n`` - integer (must fit in C int type) + - ``n`` - integer (must fit in C ``int`` type) AUTHORS: @@ -2085,7 +2088,7 @@ cdef class Rational(sage.structure.element.FieldElement): INPUT: - - ``n`` - integer (must fit in C int type) + - ``n`` - integer (must fit in C ``int`` type) .. NOTE:: @@ -2515,9 +2518,9 @@ cdef class Rational(sage.structure.element.FieldElement): sage: (2/3)^5 32/243 - sage: (-1/1)^(1/3) + sage: (-1/1)^(1/3) # optional - sage.symbolic (-1)^(1/3) - sage: (2/3)^(3/4) + sage: (2/3)^(3/4) # optional - sage.symbolic (2/3)^(3/4) sage: (-1/3)^0 1 @@ -2532,18 +2535,18 @@ cdef class Rational(sage.structure.element.FieldElement): 2/3 sage: parent(a) Rational Field - sage: (-27/125)^(1/3) + sage: (-27/125)^(1/3) # optional - sage.symbolic 3/5*(-1)^(1/3) - sage: (-27/125)^(1/2) + sage: (-27/125)^(1/2) # optional - sage.symbolic 3/5*sqrt(-3/5) The result is normalized to have the rational power in the numerator:: - sage: 2^(-1/2) + sage: 2^(-1/2) # optional - sage.symbolic 1/2*sqrt(2) - sage: 8^(-1/5) + sage: 8^(-1/5) # optional - sage.symbolic 1/8*8^(4/5) - sage: 3^(-3/2) + sage: 3^(-3/2) # optional - sage.symbolic 1/9*sqrt(3) TESTS:: @@ -2555,14 +2558,14 @@ cdef class Rational(sage.structure.element.FieldElement): This works even if the base is a Python integer:: - sage: int(2)^(1/2) + sage: int(2)^(1/2) # optional - sage.symbolic sqrt(2) sage: a = int(2)^(3/1); a 8 sage: type(a) - The exponent must fit in a long unless the base is -1, 0, or 1:: + The exponent must fit in a ``long`` unless the base is -1, 0, or 1:: sage: (1/2)^(2^100) Traceback (most recent call last): @@ -2574,7 +2577,7 @@ cdef class Rational(sage.structure.element.FieldElement): ... OverflowError: exponent must be at most 2147483647 # 32-bit OverflowError: exponent must be at most 9223372036854775807 # 64-bit - sage: QQ(-1)^(2^100) + sage: QQ(-1)^(2^100) # optional - sage.symbolic 1 """ n = other @@ -2821,7 +2824,7 @@ cdef class Rational(sage.structure.element.FieldElement): def norm(self): r""" Return the norm from `\QQ` to `\QQ` of `x` (which is just `x`). This - was added for compatibility with :class:`NumberFields`. + was added for compatibility with :class:`NumberField`. OUTPUT: @@ -2904,7 +2907,7 @@ cdef class Rational(sage.structure.element.FieldElement): sage: (1/3).charpoly('x') x - 1/3 - The default is var='x'. (:trac:`20967`):: + The default is ``var='x'``. (:trac:`20967`):: sage: a = QQ(2); a.charpoly('x') x - 2 @@ -2968,7 +2971,7 @@ cdef class Rational(sage.structure.element.FieldElement): def numerator(self): """ Return the numerator of this rational number. - numer is an alias of numerator. + :meth:`numer` is an alias of :meth:`numerator`. EXAMPLES:: @@ -3018,7 +3021,7 @@ cdef class Rational(sage.structure.element.FieldElement): def denominator(self): """ Return the denominator of this rational number. - denom is an alias of denominator. + :meth:`denom` is an alias of :meth:`denominator`. EXAMPLES:: @@ -3121,15 +3124,15 @@ cdef class Rational(sage.structure.element.FieldElement): EXAMPLES:: - sage: (124/345).log(5) + sage: (124/345).log(5) # optional - sage.symbolic log(124/345)/log(5) - sage: (124/345).log(5,100) + sage: (124/345).log(5, 100) -0.63578895682825611710391773754 - sage: log(QQ(125)) + sage: log(QQ(125)) # optional - sage.symbolic 3*log(5) sage: log(QQ(125), 5) 3 - sage: log(QQ(125), 3) + sage: log(QQ(125), 3) # optional - sage.symbolic 3*log(5)/log(3) sage: QQ(8).log(1/2) -3 @@ -3149,14 +3152,14 @@ cdef class Rational(sage.structure.element.FieldElement): -4/3 sage: (125/8).log(5/2) 3 - sage: (125/8).log(5/2,prec=53) + sage: (125/8).log(5/2, prec=53) 3.00000000000000 TESTS:: - sage: (25/2).log(5/2) + sage: (25/2).log(5/2) # optional - sage.symbolic log(25/2)/log(5/2) - sage: (-1/2).log(3) + sage: (-1/2).log(3) # optional - sage.symbolic (I*pi + log(1/2))/log(3) """ cdef int self_sgn @@ -3225,15 +3228,15 @@ cdef class Rational(sage.structure.element.FieldElement): EXAMPLES:: - sage: gamma(1/2) + sage: gamma(1/2) # optional - sage.symbolic sqrt(pi) - sage: gamma(7/2) + sage: gamma(7/2) # optional - sage.symbolic 15/8*sqrt(pi) - sage: gamma(-3/2) + sage: gamma(-3/2) # optional - sage.symbolic 4/3*sqrt(pi) - sage: gamma(6/1) + sage: gamma(6/1) # optional - sage.symbolic 120 - sage: gamma(1/3) + sage: gamma(1/3) # optional - sage.symbolic gamma(1/3) This function accepts an optional precision argument:: @@ -3341,7 +3344,7 @@ cdef class Rational(sage.structure.element.FieldElement): def round(Rational self, mode="away"): """ Return the nearest integer to ``self``, rounding away from 0 by - default, for consistency with the builtin Python round. + default, for consistency with the builtin Python :func:`round`. INPUT: @@ -3554,7 +3557,7 @@ cdef class Rational(sage.structure.element.FieldElement): def is_integral(self): r""" - Determine if a rational number is integral (i.e is in + Determine if a rational number is integral (i.e., is in `\ZZ`). OUTPUT: bool @@ -3768,11 +3771,11 @@ cdef class Rational(sage.structure.element.FieldElement): EXAMPLES:: sage: n = 9390823/17 - sage: m = n.__pari__(); m + sage: m = n.__pari__(); m # optional - sage.libs.pari 9390823/17 - sage: type(m) + sage: type(m) # optional - sage.libs.pari - sage: m.type() + sage: m.type() # optional - sage.libs.pari 't_FRAC' """ global new_gen_from_rational @@ -4124,7 +4127,8 @@ cdef class Z_to_Q(Morphism): maps (see :trac:`15618`):: sage: f.parent() - Set of Morphisms from Rational Field to Integer Ring in Category of sets with partial maps + Set of Morphisms from Rational Field to Integer Ring + in Category of sets with partial maps """ from sage.categories.sets_with_partial_maps import SetsWithPartialMaps return Q_to_Z(self._codomain.Hom(self.domain(), category=SetsWithPartialMaps())) diff --git a/src/sage/rings/rational_field.py b/src/sage/rings/rational_field.py index ca704238181..a5755f56206 100644 --- a/src/sage/rings/rational_field.py +++ b/src/sage/rings/rational_field.py @@ -11,7 +11,7 @@ Rational Field Values of various types can be converted to rational numbers by using the -``__call__`` method of ``RationalField`` (that is, by treating ``QQ`` as a +:meth:`__call__` method of :class:`RationalField` (that is, by treating ``QQ`` as a function). :: @@ -86,7 +86,7 @@ class RationalField(Singleton, number_field_base.NumberField): -930482/9320842317 sage: QQ([9320842317]) 9320842317 - sage: QQ(pari(39029384023840928309482842098430284398243982394)) + sage: QQ(pari(39029384023840928309482842098430284398243982394)) # optional - sage.libs.pari 39029384023840928309482842098430284398243982394 sage: QQ('sage') Traceback (most recent call last): @@ -105,7 +105,7 @@ class RationalField(Singleton, number_field_base.NumberField): sage: QQ(RR(1/7)) - 1/7 0 - If you specify an optional second base argument, then the string + If you specify the optional second argument ``base``, then the string representation of the float is used. :: @@ -304,7 +304,7 @@ def __len__(self): def construction(self): r""" - Returns a pair ``(functor, parent)`` such that ``functor(parent)`` + Return a pair ``(functor, parent)`` such that ``functor(parent)`` returns ``self``. This is the construction of `\QQ` as the fraction field of `\ZZ`. @@ -441,7 +441,7 @@ def __truediv__(self, I): EXAMPLES:: - sage: QQ / ZZ + sage: QQ / ZZ # optional - sage.groups Q/Z """ from sage.rings.ideal import Ideal_generic @@ -459,9 +459,9 @@ def range_by_height(self, start, end=None): Returns a Python generator for the list of rational numbers with heights in ``range(start, end)``. Follows the same - convention as Python range, see ``range?`` for details. + convention as Python :func:`range`, type ``range?`` for details. - See also ``__iter__()``. + See also :meth:`__iter__`. EXAMPLES: @@ -526,9 +526,9 @@ def primes_of_bounded_norm_iter(self, B): EXAMPLES:: sage: it = QQ.primes_of_bounded_norm_iter(10) - sage: list(it) + sage: list(it) # optional - sage.libs.pari [2, 3, 5, 7] - sage: list(QQ.primes_of_bounded_norm_iter(1)) + sage: list(QQ.primes_of_bounded_norm_iter(1)) # optional - sage.libs.pari [] """ try: @@ -607,14 +607,14 @@ def embeddings(self, K): sage: QQ.embeddings(QQ) [Identity endomorphism of Rational Field] - sage: QQ.embeddings(CyclotomicField(5)) + sage: QQ.embeddings(CyclotomicField(5)) # optional - sage.rings.number_field [Coercion map: From: Rational Field To: Cyclotomic Field of order 5 and degree 4] `K` must have characteristic 0:: - sage: QQ.embeddings(GF(3)) + sage: QQ.embeddings(GF(3)) # optional - sage.rings.finite_rings Traceback (most recent call last): ... ValueError: no embeddings of the rational field into K. @@ -627,9 +627,7 @@ def automorphisms(self): r""" Return all Galois automorphisms of ``self``. - OUTPUT: - - - a sequence containing just the identity morphism + OUTPUT: a sequence containing just the identity morphism EXAMPLES:: @@ -644,15 +642,15 @@ def automorphisms(self): def places(self, all_complex=False, prec=None): r""" - Return the collection of all infinite places of self, which - in this case is just the embedding of self into `\RR`. + Return the collection of all infinite places of ``self``, which + in this case is just the embedding of ``self`` into `\RR`. By default, this returns homomorphisms into ``RR``. If ``prec`` is not None, we simply return homomorphisms into ``RealField(prec)`` (or ``RDF`` if ``prec=53``). There is an optional flag ``all_complex``, which defaults to - False. If ``all_complex`` is True, then the real embeddings + ``False``. If ``all_complex`` is ``True``, then the real embeddings are returned as embeddings into the corresponding complex field. @@ -723,7 +721,7 @@ def residue_field(self, p, check=True): - ``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. @@ -740,7 +738,7 @@ def residue_field(self, p, check=True): def hilbert_symbol_negative_at_S(self, S, b, check=True): r""" - Returns an integer that has a negative Hilbert symbol with respect + Return an integer that has a negative Hilbert symbol with respect to a given rational number and a given set of primes (or places). The function is algorithm 3.4.1 in [Kir2016]_. It finds an integer `a` @@ -750,10 +748,10 @@ def hilbert_symbol_negative_at_S(self, S, b, check=True): INPUT: - ``S`` -- a list of rational primes, the infinite place as real - embedding of `\QQ` or as -1 + embedding of `\QQ` or as `-1` - ``b`` -- a non-zero rational number which is a non-square locally at every prime in ``S``. - - ``check`` -- ``bool`` (default:``True``) perform additional checks on + - ``check`` -- ``bool`` (default: ``True``) perform additional checks on input and confirm the output. OUTPUT: @@ -763,37 +761,37 @@ def hilbert_symbol_negative_at_S(self, S, b, check=True): EXAMPLES:: - sage: QQ.hilbert_symbol_negative_at_S([-1,5,3,2,7,11,13,23], -10/7) + sage: QQ.hilbert_symbol_negative_at_S([-1,5,3,2,7,11,13,23], -10/7) # optional - sage.rings.padics -9867 - sage: QQ.hilbert_symbol_negative_at_S([3, 5, QQ.places()[0], 11], -15) + sage: QQ.hilbert_symbol_negative_at_S([3, 5, QQ.places()[0], 11], -15) # optional - sage.rings.padics -33 - sage: QQ.hilbert_symbol_negative_at_S([3, 5], 2) + sage: QQ.hilbert_symbol_negative_at_S([3, 5], 2) # optional - sage.rings.padics 15 TESTS:: - sage: QQ.hilbert_symbol_negative_at_S(5/2, -2) + sage: QQ.hilbert_symbol_negative_at_S(5/2, -2) # optional - sage.libs.pari sage.modules Traceback (most recent call last): ... TypeError: first argument must be a list or integer :: - sage: QQ.hilbert_symbol_negative_at_S([1, 3], 0) + sage: QQ.hilbert_symbol_negative_at_S([1, 3], 0) # optional - sage.libs.pari sage.modules Traceback (most recent call last): ... ValueError: second argument must be nonzero :: - sage: QQ.hilbert_symbol_negative_at_S([-1, 3, 5], 2) + sage: QQ.hilbert_symbol_negative_at_S([-1, 3, 5], 2) # optional - sage.libs.pari sage.modules Traceback (most recent call last): ... ValueError: list should be of even cardinality :: - sage: QQ.hilbert_symbol_negative_at_S([1, 3], 2) + sage: QQ.hilbert_symbol_negative_at_S([1, 3], 2) # optional - sage.libs.pari sage.modules Traceback (most recent call last): ... ValueError: all entries in list must be prime or -1 for @@ -801,7 +799,7 @@ def hilbert_symbol_negative_at_S(self, S, b, check=True): :: - sage: QQ.hilbert_symbol_negative_at_S([5, 7], 2) + sage: QQ.hilbert_symbol_negative_at_S([5, 7], 2) # optional - sage.libs.pari sage.modules Traceback (most recent call last): ... ValueError: second argument must be a nonsquare with @@ -809,14 +807,14 @@ def hilbert_symbol_negative_at_S(self, S, b, check=True): :: - sage: QQ.hilbert_symbol_negative_at_S([1, 3], sqrt(2)) + sage: QQ.hilbert_symbol_negative_at_S([1, 3], sqrt(2)) # optional - sage.libs.pari sage.modules Traceback (most recent call last): ... TypeError: second argument must be a rational number :: - sage: QQ.hilbert_symbol_negative_at_S([-1, 3], 2) + sage: QQ.hilbert_symbol_negative_at_S([-1, 3], 2) # optional - sage.libs.pari sage.modules Traceback (most recent call last): ... ValueError: if the infinite place is in the list, the second @@ -913,7 +911,7 @@ def phi(x): def gens(self): r""" - Return a tuple of generators of `\QQ` which is only ``(1,)``. + Return a tuple of generators of `\QQ`, which is only ``(1,)``. EXAMPLES:: @@ -926,7 +924,7 @@ def gen(self, n=0): r""" Return the ``n``-th generator of `\QQ`. - There is only the 0-th generator which is 1. + There is only the 0-th generator, which is 1. EXAMPLES:: @@ -940,7 +938,7 @@ def gen(self, n=0): def degree(self): r""" - Return the degree of `\QQ` which is 1. + Return the degree of `\QQ`, which is 1. EXAMPLES:: @@ -951,7 +949,7 @@ def degree(self): def absolute_degree(self): r""" - Return the absolute degree of `\QQ` which is 1. + Return the absolute degree of `\QQ`, which is 1. EXAMPLES:: @@ -962,7 +960,7 @@ def absolute_degree(self): def ngens(self): r""" - Return the number of generators of `\QQ` which is 1. + Return the number of generators of `\QQ`, which is 1. EXAMPLES:: @@ -1056,16 +1054,16 @@ def extension(self, poly, names, **kwds): We make a single absolute extension:: - sage: K. = QQ.extension(x^3 + 5); K + sage: K. = QQ.extension(x^3 + 5); K # optional - sage.rings.number_field Number Field in a with defining polynomial x^3 + 5 We make an extension generated by roots of two polynomials:: - sage: K. = QQ.extension([x^3 + 5, x^2 + 3]); K + sage: K. = QQ.extension([x^3 + 5, x^2 + 3]); K # optional - sage.rings.number_field Number Field in a with defining polynomial x^3 + 5 over its base field - sage: b^2 + sage: b^2 # optional - sage.rings.number_field -3 - sage: a^3 + sage: a^3 # optional - sage.rings.number_field -5 """ from sage.rings.number_field.number_field import NumberField @@ -1073,11 +1071,11 @@ def extension(self, poly, names, **kwds): def algebraic_closure(self): r""" - Return the algebraic closure of self (which is `\QQbar`). + Return the algebraic closure of ``self`` (which is `\QQbar`). EXAMPLES:: - sage: QQ.algebraic_closure() + sage: QQ.algebraic_closure() # optional - sage.rings.number_field Algebraic Field """ from sage.rings.qqbar import QQbar @@ -1085,7 +1083,7 @@ def algebraic_closure(self): def order(self): r""" - Return the order of `\QQ` which is `\infty`. + Return the order of `\QQ`, which is `\infty`. EXAMPLES:: @@ -1099,8 +1097,8 @@ def polynomial(self): r""" Return a defining polynomial of `\QQ`, as for other number fields. - This is also aliased to :meth:`self.defining_polynomial()` - and :meth:`self.absolute_polynomial()`. + This is also aliased to :meth:`defining_polynomial` + and :meth:`absolute_polynomial`. EXAMPLES:: @@ -1131,9 +1129,7 @@ def some_elements(self): See :func:`TestSuite` for a typical use case. - OUTPUT: - - An iterator over 100 elements of `\QQ`. + OUTPUT: An iterator over 100 elements of `\QQ`. EXAMPLES:: @@ -1172,7 +1168,7 @@ def some_elements(self): def random_element(self, num_bound=None, den_bound=None, *args, **kwds): r""" - Return an random element of `\QQ`. + Return a random element of `\QQ`. Elements are constructed by randomly choosing integers for the numerator and denominator, not necessarily coprime. @@ -1282,7 +1278,7 @@ def selmer_generators(self, S, m, proof=True, orders=False): - ``proof`` -- ignored - - ``orders`` (default False) -- if True, output two lists, the + - ``orders`` (default ``False``) -- if ``True``, output two lists, the generators and their orders OUTPUT: @@ -1301,7 +1297,7 @@ def selmer_generators(self, S, m, proof=True, orders=False): :meth:`RationalField.selmer_space`, which gives additional output when `m=p` is prime: as well as generators, it gives an - abstract vector space over `GF(p)` isomorphic to `\QQ(S,p)` + abstract vector space over `\GF{p}` isomorphic to `\QQ(S,p)` and maps implementing the isomorphism between this space and `\QQ(S,p)` as a subgroup of `\QQ^*/(\QQ^*)^p`. @@ -1388,7 +1384,7 @@ def selmer_space(self, S, p, proof=None): (tuple) ``QSp``, ``QSp_gens``, ``from_QSp``, ``to_QSp`` where - - ``QSp`` is an abstract vector space over `GF(p)` isomorphic to `\QQ(S,p)`; + - ``QSp`` is an abstract vector space over `\GF{p}` isomorphic to `\QQ(S,p)`; - ``QSp_gens`` is a list of elements of `\QQ^*` generating `\QQ(S,p)`; @@ -1412,45 +1408,47 @@ def selmer_space(self, S, p, proof=None): When `S` is empty, `\QQ(S,p)` is only nontrivial for `p=2`:: - sage: QS2, QS2gens, fromQS2, toQS2 = QQ.selmer_space([], 2) - sage: QS2 + sage: QS2, QS2gens, fromQS2, toQS2 = QQ.selmer_space([], 2) # optional - sage.rings.number_field + sage: QS2 # optional - sage.rings.number_field Vector space of dimension 1 over Finite Field of size 2 - sage: QS2gens + sage: QS2gens # optional - sage.rings.number_field [-1] - sage: all(QQ.selmer_space([], p)[0].dimension() == 0 for p in primes(3,10)) + sage: all(QQ.selmer_space([], p)[0].dimension() == 0 # optional - sage.libs.pari + ....: for p in primes(3, 10)) True In general there is one generator for each `p\in S`, and an additional generator of `-1` when `p=2`:: - sage: QS2, QS2gens, fromQS2, toQS2 = QQ.selmer_space([5,7], 2) - sage: QS2 + sage: QS2, QS2gens, fromQS2, toQS2 = QQ.selmer_space([5,7], 2) # optional - sage.modules + sage: QS2 # optional - sage.modules Vector space of dimension 3 over Finite Field of size 2 - sage: QS2gens + sage: QS2gens # optional - sage.modules [5, 7, -1] - sage: toQS2(-7) + sage: toQS2(-7) # optional - sage.modules (0, 1, 1) - sage: fromQS2((0,1,1)) + sage: fromQS2((0,1,1)) # optional - sage.modules -7 The map ``fromQS2`` is only well-defined modulo `p`'th powers (in this case, modulo squares):: - sage: toQS2(-5/7) + sage: toQS2(-5/7) # optional - sage.modules (1, 1, 1) - sage: fromQS2((1,1,1)) + sage: fromQS2((1,1,1)) # optional - sage.modules -35 - sage: ((-5/7)/(-35)).is_square() + sage: ((-5/7)/(-35)).is_square() # optional - sage.modules True The map ``toQS2`` is not defined on all of `\QQ^*`, only on those numbers which are squares away from `5` and `7`:: - sage: toQS2(210) + sage: toQS2(210) # optional - sage.modules Traceback (most recent call last): ... - ValueError: argument 210 should have valuations divisible by 2 at all primes in [5, 7] + ValueError: argument 210 should have valuations divisible by 2 + at all primes in [5, 7] """ from sage.rings.number_field.selmer_group import pSelmerGroup @@ -1516,7 +1514,7 @@ def _gap_init_(self): EXAMPLES:: - sage: gap(QQ) # indirect doctest + sage: gap(QQ) # indirect doctest # optional - sage.libs.gap Rationals """ return 'Rationals' @@ -1584,7 +1582,7 @@ def _sympy_(self): EXAMPLES:: - sage: QQ._sympy_() + sage: QQ._sympy_() # optional - sympy Rationals """ from sympy import Rationals @@ -1630,20 +1628,20 @@ def _factor_univariate_polynomial(self, f): TESTS:: sage: R. = QQ[] - sage: QQ._factor_univariate_polynomial( x ) + sage: QQ._factor_univariate_polynomial(x) # optional - sage.libs.pari x - sage: QQ._factor_univariate_polynomial( 2*x ) + sage: QQ._factor_univariate_polynomial(2*x) # optional - sage.libs.pari (2) * x - sage: QQ._factor_univariate_polynomial( (x^2 - 1/4)^4 ) + sage: QQ._factor_univariate_polynomial((x^2 - 1/4)^4) # optional - sage.libs.pari (x - 1/2)^4 * (x + 1/2)^4 - sage: QQ._factor_univariate_polynomial( (2*x + 1) * (3*x^2 - 5)^2 ) + sage: QQ._factor_univariate_polynomial((2*x + 1) * (3*x^2 - 5)^2) # optional - sage.libs.pari (18) * (x + 1/2) * (x^2 - 5/3)^2 - sage: f = prod((k^2*x^k + k)^(k-1) for k in primes(10)) - sage: QQ._factor_univariate_polynomial(f) + sage: f = prod((k^2*x^k + k)^(k-1) for k in primes(10)) # optional - sage.libs.pari + sage: QQ._factor_univariate_polynomial(f) # optional - sage.libs.pari (1751787911376562500) * (x^2 + 1/2) * (x^3 + 1/3)^2 * (x^5 + 1/5)^4 * (x^7 + 1/7)^6 - sage: QQ._factor_univariate_polynomial( 10*x^5 - 1 ) + sage: QQ._factor_univariate_polynomial(10*x^5 - 1) # optional - sage.libs.pari (10) * (x^5 - 1/10) - sage: QQ._factor_univariate_polynomial( 10*x^5 - 10 ) + sage: QQ._factor_univariate_polynomial(10*x^5 - 10) # optional - sage.libs.pari (10) * (x - 1) * (x^4 + x^3 + x^2 + x + 1) """ @@ -1661,9 +1659,9 @@ def valuation(self, p): EXAMPLES:: - sage: v = QQ.valuation(3); v + sage: v = QQ.valuation(3); v # optional - sage.rings.padics 3-adic valuation - sage: v(1/3) + sage: v(1/3) # optional - sage.rings.padics -1 .. SEEALSO:: diff --git a/src/sage/rings/real_arb.pyx b/src/sage/rings/real_arb.pyx index b969c762e84..383376cd1ff 100644 --- a/src/sage/rings/real_arb.pyx +++ b/src/sage/rings/real_arb.pyx @@ -175,11 +175,11 @@ TESTS:: :: - sage: SR.coerce(RBF(0.42)) + sage: SR.coerce(RBF(0.42)) # optional - sage.symbolic [0.4200000000000000 +/- ...e-17] - sage: RBF(0.42) + SR(1) + sage: RBF(0.42) + SR(1) # optional - sage.symbolic [1.420000000000000 +/- ...e-16] - sage: _.parent() + sage: _.parent() # optional - sage.symbolic Symbolic Ring Classes and Methods @@ -457,7 +457,7 @@ class RealBallField(UniqueRepresentation, sage.rings.abc.RealBallField): False sage: RealBallField().has_coerce_map_from(RIF) False - sage: RealBallField().has_coerce_map_from(SR) + sage: RealBallField().has_coerce_map_from(SR) # optional - sage.symbolic False sage: RealBallField().has_coerce_map_from(RR) False @@ -2521,7 +2521,7 @@ cdef class RealBall(RingElement): def is_finite(self): """ - Return True iff the midpoint and radius of this ball are both + Return ``True`` iff the midpoint and radius of this ball are both finite floating-point numbers, i.e. not infinities or NaN. EXAMPLES:: @@ -2535,7 +2535,7 @@ cdef class RealBall(RingElement): def identical(self, RealBall other): """ - Return True iff ``self`` and ``other`` are equal as balls, i.e. + Return ``True`` iff ``self`` and ``other`` are equal as balls, i.e. have both the same midpoint and radius. Note that this is not the same thing as testing whether both ``self`` @@ -2558,7 +2558,7 @@ cdef class RealBall(RingElement): def overlaps(self, RealBall other): """ - Return True iff ``self`` and ``other`` have some point in common. + Return ``True`` iff ``self`` and ``other`` have some point in common. If either ``self`` or ``other`` contains NaN, this method always returns nonzero (as a NaN could be anything, it could in particular @@ -2641,7 +2641,7 @@ cdef class RealBall(RingElement): def __contains__(self, other): """ - Return True if ``other`` can be verified to be contained in ``self``. + Return ``True`` if ``other`` can be verified to be contained in ``self``. The test is done using interval arithmetic with a precision determined by the parent of ``self`` and may return false negatives. diff --git a/src/sage/rings/real_double.pyx b/src/sage/rings/real_double.pyx index 21a2f293ee9..dcaf1108e8c 100644 --- a/src/sage/rings/real_double.pyx +++ b/src/sage/rings/real_double.pyx @@ -5,21 +5,21 @@ EXAMPLES: We create the real double vector space of dimension `3`:: - sage: V = RDF^3; V + sage: V = RDF^3; V # optional - sage.modules Vector space of dimension 3 over Real Double Field Notice that this space is unique:: - sage: V is RDF^3 + sage: V is RDF^3 # optional - sage.modules True - sage: V is FreeModule(RDF, 3) + sage: V is FreeModule(RDF, 3) # optional - sage.modules True - sage: V is VectorSpace(RDF, 3) + sage: V is VectorSpace(RDF, 3) # optional - sage.modules True Also, you can instantly create a space of large dimension:: - sage: V = RDF^10000 + sage: V = RDF^10000 # optional - sage.modules TESTS: @@ -27,8 +27,8 @@ Test NumPy conversions:: sage: RDF(1).__array_interface__ {'typestr': '=f8'} - sage: import numpy - sage: numpy.array([RDF.pi()]).dtype + sage: import numpy # optional - numpy + sage: numpy.array([RDF.pi()]).dtype # optional - numpy dtype('float64') """ @@ -332,10 +332,10 @@ cdef class RealDoubleField_class(sage.rings.abc.RealDoubleField): sage: RLF(2/3) + RDF(1) 1.6666666666666665 - sage: import numpy - sage: RDF.coerce(numpy.int8('1')) + sage: import numpy # optional - numpy + sage: RDF.coerce(numpy.int8('1')) # optional - numpy 1.0 - sage: RDF.coerce(numpy.float64('1')) + sage: RDF.coerce(numpy.float64('1')) # optional - numpy 1.0 sage: RDF.coerce(pi) @@ -793,20 +793,20 @@ cdef class RealDoubleElement(FieldElement): EXAMPLES:: - sage: a = RDF(pi) - sage: a.ulp() + sage: a = RDF(pi) # optional - sage.symbolic + sage: a.ulp() # optional - sage.symbolic 4.440892098500626e-16 - sage: b = a + a.ulp() + sage: b = a + a.ulp() # optional - sage.symbolic Adding or subtracting an ulp always gives a different number:: - sage: a + a.ulp() == a + sage: a + a.ulp() == a # optional - sage.symbolic False - sage: a - a.ulp() == a + sage: a - a.ulp() == a # optional - sage.symbolic False - sage: b + b.ulp() == b + sage: b + b.ulp() == b # optional - sage.symbolic False - sage: b - b.ulp() == b + sage: b - b.ulp() == b # optional - sage.symbolic False Since the default rounding mode is round-to-nearest, adding or @@ -815,13 +815,13 @@ cdef class RealDoubleElement(FieldElement): can only happen if the input number is (up to sign) exactly a power of 2:: - sage: a - a.ulp()/3 == a + sage: a - a.ulp()/3 == a # optional - sage.symbolic True - sage: a + a.ulp()/3 == a + sage: a + a.ulp()/3 == a # optional - sage.symbolic True - sage: b - b.ulp()/3 == b + sage: b - b.ulp()/3 == b # optional - sage.symbolic True - sage: b + b.ulp()/3 == b + sage: b + b.ulp()/3 == b # optional - sage.symbolic True sage: c = RDF(1) sage: c - c.ulp()/3 == c @@ -980,11 +980,11 @@ cdef class RealDoubleElement(FieldElement): EXAMPLES:: - sage: s1 = RDF(sin(1)); s1 + sage: s1 = RDF(sin(1)); s1 # optional - sage.symbolic 0.8414709848078965 - sage: s1._interface_init_() + sage: s1._interface_init_() # optional - sage.symbolic '0.8414709848078965' - sage: s1 == RDF(gp(s1)) + sage: s1 == RDF(gp(s1)) # optional - sage.libs.pari sage.symbolic True """ return repr(self._value) @@ -1009,7 +1009,7 @@ cdef class RealDoubleElement(FieldElement): EXAMPLES:: - sage: sage_input(RDF(NaN)) + sage: sage_input(RDF(NaN)) # optional - sage.symbolic RDF(NaN) sage: sage_input(RDF(-infinity), verify=True) # Verified @@ -1268,12 +1268,12 @@ cdef class RealDoubleElement(FieldElement): EXAMPLES:: - sage: a = RDF(exp(1.0)); a + sage: a = RDF(exp(1.0)); a # optional - sage.symbolic 2.718281828459045 - sage: sign,mantissa,exponent = RDF(exp(1.0)).sign_mantissa_exponent() - sage: sign,mantissa,exponent + sage: sign,mantissa,exponent = RDF(exp(1.0)).sign_mantissa_exponent() # optional - sage.symbolic + sage: sign,mantissa,exponent # optional - sage.symbolic (1, 6121026514868073, -51) - sage: sign*mantissa*(2**exponent) == a + sage: sign*mantissa*(2**exponent) == a # optional - sage.symbolic True The mantissa is always a nonnegative number:: @@ -1687,7 +1687,7 @@ cdef class RealDoubleElement(FieldElement): EXAMPLES:: - sage: RDF(1.5).__pari__() + sage: RDF(1.5).__pari__() # optional - sage.libs.pari 1.50000000000000 """ global new_gen_from_real_double_element @@ -1897,7 +1897,7 @@ cdef class RealDoubleElement(FieldElement): def is_integer(self): """ - Return True if this number is a integer + Return ``True`` if this number is a integer EXAMPLES:: @@ -1975,7 +1975,7 @@ cdef class RealDoubleElement(FieldElement): sage: r = sqrt(RDF(2)); r 1.4142135623730951 - sage: r.algebraic_dependency(5) + sage: r.algebraic_dependency(5) # optional - sage.libs.pari x^2 - 2 """ return sage.arith.all.algdep(self,n) diff --git a/src/sage/rings/real_mpfi.pyx b/src/sage/rings/real_mpfi.pyx index 33e94b93094..1904bbff3e7 100644 --- a/src/sage/rings/real_mpfi.pyx +++ b/src/sage/rings/real_mpfi.pyx @@ -230,10 +230,10 @@ specified if given a non-interval and an interval:: TESTS:: - sage: import numpy - sage: RIF(2) == numpy.int8('2') + sage: import numpy # optional - numpy + sage: RIF(2) == numpy.int8('2') # optional - numpy True - sage: numpy.int8('2') == RIF(2) + sage: numpy.int8('2') == RIF(2) # optional - numpy True sage: RIF(0,1) < float('2') Traceback (most recent call last): diff --git a/src/sage/rings/real_mpfr.pyx b/src/sage/rings/real_mpfr.pyx index 18d1345ec81..61569a41ff2 100644 --- a/src/sage/rings/real_mpfr.pyx +++ b/src/sage/rings/real_mpfr.pyx @@ -1438,12 +1438,12 @@ cdef class RealNumber(sage.structure.element.RingElement): EXAMPLES:: - sage: import numpy - sage: numpy.arange(10.0) + sage: import numpy # optional - numpy + sage: numpy.arange(10.0) # optional - numpy array([0., 1., 2., 3., 4., 5., 6., 7., 8., 9.]) - sage: numpy.array([1.0, 1.1, 1.2]).dtype + sage: numpy.array([1.0, 1.1, 1.2]).dtype # optional - numpy dtype('float64') - sage: numpy.array([1.000000000000000000000000000000000000]).dtype + sage: numpy.array([1.000000000000000000000000000000000000]).dtype # optional - numpy dtype('O') """ if (self._parent).__prec <= 53: diff --git a/src/sage/rings/ring.pyx b/src/sage/rings/ring.pyx index e806637c38a..9b3504aa4e0 100644 --- a/src/sage/rings/ring.pyx +++ b/src/sage/rings/ring.pyx @@ -165,13 +165,13 @@ cdef class Ring(ParentWithGens): sage: QQ.is_finite() False - sage: GF(2^10,'a').is_finite() + sage: GF(2^10, 'a').is_finite() # optional - sage.rings.finite_rings True - sage: R. = GF(7)[] - sage: R.is_finite() + sage: R. = GF(7)[] # optional - sage.rings.finite_rings + sage: R.is_finite() # optional - sage.rings.finite_rings False - sage: S. = R.quo(x^2+1) - sage: S.is_finite() + sage: S. = R.quo(x^2 + 1) # optional - sage.rings.finite_rings + sage: S.is_finite() # optional - sage.rings.finite_rings True sage: Integers(7).cardinality() @@ -255,11 +255,11 @@ cdef class Ring(ParentWithGens): """ EXAMPLES:: - sage: QQ.base_extend(GF(7)) + sage: QQ.base_extend(GF(7)) # optional - sage.rings.finite_rings Traceback (most recent call last): ... TypeError: no base extension defined - sage: ZZ.base_extend(GF(7)) + sage: ZZ.base_extend(GF(7)) # optional - sage.rings.finite_rings Finite Field of size 7 """ if R.has_coerce_map_from(self): @@ -280,7 +280,7 @@ cdef class Ring(ParentWithGens): EXAMPLES:: - sage: FreeAlgebra(QQ, 3, 'x').category() # todo: use a ring which is not an algebra! + sage: FreeAlgebra(QQ, 3, 'x').category() # todo: use a ring which is not an algebra! # optional - sage.combinat sage.modules Category of algebras with basis over Rational Field Since a quotient of the integers is its own base ring, and during @@ -310,16 +310,19 @@ cdef class Ring(ParentWithGens): EXAMPLES:: - sage: F. = FreeAlgebra(ZZ, 3) - sage: I = F*[x*y+y*z,x^2+x*y-y*x-y^2]*F - sage: Q = F.quotient(I) - sage: Q.ideal_monoid() - Monoid of ideals of Quotient of Free Algebra on 3 generators (x, y, z) over Integer Ring by the ideal (x*y + y*z, x^2 + x*y - y*x - y^2) - sage: F. = FreeAlgebra(ZZ, implementation='letterplace') - sage: I = F*[x*y+y*z,x^2+x*y-y*x-y^2]*F - sage: Q = F.quo(I) - sage: Q.ideal_monoid() - Monoid of ideals of Quotient of Free Associative Unital Algebra on 3 generators (x, y, z) over Integer Ring by the ideal (x*y + y*z, x*x + x*y - y*x - y*y) + sage: F. = FreeAlgebra(ZZ, 3) # optional - sage.combinat sage.modules + sage: I = F * [x*y + y*z, x^2 + x*y - y*x - y^2] * F # optional - sage.combinat sage.modules + sage: Q = F.quotient(I) # optional - sage.combinat sage.modules + sage: Q.ideal_monoid() # optional - sage.combinat sage.modules + Monoid of ideals of Quotient of Free Algebra on 3 generators (x, y, z) + over Integer Ring by the ideal (x*y + y*z, x^2 + x*y - y*x - y^2) + sage: F. = FreeAlgebra(ZZ, implementation='letterplace') # optional - sage.combinat sage.modules + sage: I = F * [x*y + y*z, x^2 + x*y - y*x - y^2] * F # optional - sage.combinat sage.modules + sage: Q = F.quo(I) # optional - sage.combinat sage.modules + sage: Q.ideal_monoid() # optional - sage.combinat sage.modules + Monoid of ideals of Quotient of Free Associative Unital Algebra + on 3 generators (x, y, z) over Integer Ring + by the ideal (x*y + y*z, x*x + x*y - y*x - y*y) """ if self.__ideal_monoid is not None: @@ -363,10 +366,10 @@ cdef class Ring(ParentWithGens): Here is an example over a non-commutative ring:: - sage: A = SteenrodAlgebra(2) - sage: A.ideal(A.1,A.2^2) + sage: A = SteenrodAlgebra(2) # optional - sage.combinat sage.modules + sage: A.ideal(A.1, A.2^2) # optional - sage.combinat sage.modules Twosided Ideal (Sq(2), Sq(2,2)) of mod 2 Steenrod algebra, milnor basis - sage: A.ideal(A.1,A.2^2,side='left') + sage: A.ideal(A.1, A.2^2, side='left') # optional - sage.combinat sage.modules Left Ideal (Sq(2), Sq(2,2)) of mod 2 Steenrod algebra, milnor basis TESTS: @@ -445,20 +448,22 @@ cdef class Ring(ParentWithGens): EXAMPLES:: - sage: R. = GF(7)[] - sage: (x+y)*R - Ideal (x + y) of Multivariate Polynomial Ring in x, y, z over Finite Field of size 7 - sage: (x+y,z+y^3)*R - Ideal (x + y, y^3 + z) of Multivariate Polynomial Ring in x, y, z over Finite Field of size 7 + sage: R. = GF(7)[] # optional - sage.rings.finite_rings + sage: (x + y) * R # optional - sage.rings.finite_rings + Ideal (x + y) of Multivariate Polynomial Ring in x, y, z + over Finite Field of size 7 + sage: (x + y, z + y^3) * R # optional - sage.rings.finite_rings + Ideal (x + y, y^3 + z) of Multivariate Polynomial Ring in x, y, z + over Finite Field of size 7 The following was implemented in :trac:`7797`:: - sage: A = SteenrodAlgebra(2) - sage: A*[A.1+A.2,A.1^2] + sage: A = SteenrodAlgebra(2) # optional - sage.combinat sage.modules + sage: A * [A.1 + A.2, A.1^2] # optional - sage.combinat sage.modules Left Ideal (Sq(2) + Sq(4), Sq(1,1)) of mod 2 Steenrod algebra, milnor basis - sage: [A.1+A.2,A.1^2]*A + sage: [A.1 + A.2, A.1^2] * A # optional - sage.combinat sage.modules Right Ideal (Sq(2) + Sq(4), Sq(1,1)) of mod 2 Steenrod algebra, milnor basis - sage: A*[A.1+A.2,A.1^2]*A + sage: A * [A.1 + A.2, A.1^2] * A # optional - sage.combinat sage.modules Twosided Ideal (Sq(2) + Sq(4), Sq(1,1)) of mod 2 Steenrod algebra, milnor basis """ @@ -516,18 +521,18 @@ cdef class Ring(ParentWithGens): sage: RR._ideal_class_() - sage: R. = GF(5)[] - sage: R._ideal_class_(1) + sage: R. = GF(5)[] # optional - sage.rings.finite_rings + sage: R._ideal_class_(1) # optional - sage.rings.finite_rings - sage: S = R.quo(x^3-y^2) - sage: S._ideal_class_(1) + sage: S = R.quo(x^3 - y^2) # optional - sage.rings.finite_rings + sage: S._ideal_class_(1) # optional - sage.rings.finite_rings - sage: S._ideal_class_(2) + sage: S._ideal_class_(2) # optional - sage.rings.finite_rings - sage: T. = S[] - sage: T._ideal_class_(5) + sage: T. = S[] # optional - sage.rings.finite_rings + sage: T._ideal_class_(5) # optional - sage.rings.finite_rings - sage: T._ideal_class_(1) + sage: T._ideal_class_(1) # optional - sage.rings.finite_rings Since :trac:`7797`, non-commutative rings have ideals as well:: @@ -571,7 +576,7 @@ cdef class Ring(ParentWithGens): EXAMPLES:: - sage: Zp(7).unit_ideal() + sage: Zp(7).unit_ideal() # optional - sage.rings.padics Principal ideal (1 + O(7^20)) of 7-adic Ring with capped relative precision 20 """ if self._unit_ideal is None: @@ -602,10 +607,10 @@ cdef class Ring(ParentWithGens): Make sure that :trac:`13644` is fixed:: - sage: K = Qp(3) - sage: R. = K[] - sage: L. = K.extension(a^2-3) - sage: L.ideal(a) + sage: K = Qp(3) # optional - sage.rings.padics + sage: R. = K[] # optional - sage.rings.padics + sage: L. = K.extension(a^2-3) # optional - sage.rings.padics + sage: L.ideal(a) # optional - sage.rings.padics Principal ideal (1 + O(a^40)) of 3-adic Eisenstein Extension Field in a defined by a^2 - 3 """ @@ -673,8 +678,8 @@ cdef class Ring(ParentWithGens): True sage: QQ['x,y,z'].is_commutative() True - sage: Q. = QuaternionAlgebra(QQ, -1,-1) - sage: Q.is_commutative() + sage: Q. = QuaternionAlgebra(QQ, -1, -1) # optional - sage.combinat sage.modules + sage: Q.is_commutative() # optional - sage.combinat sage.modules False """ if self.is_zero(): @@ -701,7 +706,7 @@ cdef class Ring(ParentWithGens): sage: QQ.is_field() True - sage: GF(9,'a').is_field() + sage: GF(9, 'a').is_field() # optional - sage.rings.finite_rings True sage: ZZ.is_field() False @@ -713,12 +718,12 @@ cdef class Ring(ParentWithGens): This illustrates the use of the ``proof`` parameter:: sage: R. = QQ[] - sage: S. = R.quo((b^3)) - sage: S.is_field(proof = True) + sage: S. = R.quo((b^3)) # optional - sage.libs.singular + sage: S.is_field(proof=True) # optional - sage.libs.singular Traceback (most recent call last): ... NotImplementedError - sage: S.is_field(proof = False) + sage: S.is_field(proof=False) # optional - sage.libs.singular False """ if self.is_zero(): @@ -745,9 +750,9 @@ cdef class Ring(ParentWithGens): True sage: ZZ.is_exact() True - sage: Qp(7).is_exact() + sage: Qp(7).is_exact() # optional - sage.rings.padics False - sage: Zp(7, type='capped-abs').is_exact() + sage: Zp(7, type='capped-abs').is_exact() # optional - sage.rings.padics False """ return True @@ -763,30 +768,30 @@ cdef class Ring(ParentWithGens): sage: ZZ.is_subring(QQ) True - sage: ZZ.is_subring(GF(19)) + sage: ZZ.is_subring(GF(19)) # optional - sage.rings.finite_rings False TESTS:: sage: QQ.is_subring(QQ['x']) True - sage: QQ.is_subring(GF(7)) + sage: QQ.is_subring(GF(7)) # optional - sage.rings.finite_rings False - sage: QQ.is_subring(CyclotomicField(7)) + sage: QQ.is_subring(CyclotomicField(7)) # optional - sage.rings.number_field True sage: QQ.is_subring(ZZ) False Every ring is a subring of itself, :trac:`17287`:: - sage: QQbar.is_subring(QQbar) + sage: QQbar.is_subring(QQbar) # optional - sage.rings.number_field True sage: RR.is_subring(RR) True sage: CC.is_subring(CC) True - sage: K. = NumberField(x^3-x+1/10) - sage: K.is_subring(K) + sage: K. = NumberField(x^3 - x + 1/10) # optional - sage.rings.number_field + sage: K.is_subring(K) # optional - sage.rings.number_field True sage: R. = RR[] sage: R.is_subring(R) @@ -808,15 +813,15 @@ cdef class Ring(ParentWithGens): sage: QQ.is_prime_field() True - sage: GF(3).is_prime_field() + sage: GF(3).is_prime_field() # optional - sage.rings.finite_rings True - sage: GF(9,'a').is_prime_field() + sage: GF(9, 'a').is_prime_field() # optional - sage.rings.finite_rings False sage: ZZ.is_prime_field() False sage: QQ['x'].is_prime_field() False - sage: Qp(19).is_prime_field() + sage: Qp(19).is_prime_field() # optional - sage.rings.padics False """ return False @@ -847,33 +852,32 @@ cdef class Ring(ParentWithGens): True sage: Integers(8).is_integral_domain() False - sage: Zp(7).is_integral_domain() + sage: Zp(7).is_integral_domain() # optional - sage.rings.padics True - sage: Qp(7).is_integral_domain() + sage: Qp(7).is_integral_domain() # optional - sage.rings.padics True sage: R. = QQ[] - sage: S. = R.quo((b^3)) - sage: S.is_integral_domain() + sage: S. = R.quo((b^3)) # optional - sage.libs.singular + sage: S.is_integral_domain() # optional - sage.libs.singular False This illustrates the use of the ``proof`` parameter:: sage: R. = ZZ[] - sage: S. = R.quo((b^3)) - sage: S.is_integral_domain(proof = True) + sage: S. = R.quo((b^3)) # optional - sage.libs.singular + sage: S.is_integral_domain(proof=True) # optional - sage.libs.singular Traceback (most recent call last): ... NotImplementedError - sage: S.is_integral_domain(proof = False) + sage: S.is_integral_domain(proof=False) # optional - sage.libs.singular False TESTS: Make sure :trac:`10481` is fixed:: - sage: var('x') - x - sage: R. = ZZ['x'].quo(x^2) + sage: x = polygen(ZZ, 'x') + sage: R. = ZZ['x'].quo(x^2) # optional - sage.libs.pari sage: R.fraction_field() Traceback (most recent call last): ... @@ -883,11 +887,11 @@ cdef class Ring(ParentWithGens): Forward the proof flag to ``is_field``, see :trac:`22910`:: - sage: R1. = GF(5)[] - sage: F1 = R1.quotient_ring(x^2+x+1) - sage: R2. = F1[] - sage: F2 = R2.quotient_ring(x^2+x+1) - sage: F2.is_integral_domain(False) + sage: R1. = GF(5)[] # optional - sage.rings.finite_rings + sage: F1 = R1.quotient_ring(x^2 + x + 1) # optional - sage.rings.finite_rings + sage: R2. = F1[] # optional - sage.rings.finite_rings + sage: F2 = R2.quotient_ring(x^2 + x + 1) # optional - sage.rings.finite_rings + sage: F2.is_integral_domain(False) # optional - sage.rings.finite_rings False """ if self.is_field(proof): @@ -920,7 +924,7 @@ cdef class Ring(ParentWithGens): EXAMPLES:: - sage: GF(19).order() + sage: GF(19).order() # optional - sage.rings.finite_rings 19 sage: QQ.order() +Infinity @@ -952,29 +956,29 @@ cdef class Ring(ParentWithGens): -1 sage: QQ.zeta(1) 1 - sage: CyclotomicField(6).zeta(6) + sage: CyclotomicField(6).zeta(6) # optional - sage.rings.number_field zeta6 - sage: CyclotomicField(3).zeta(3) + sage: CyclotomicField(3).zeta(3) # optional - sage.rings.number_field zeta3 - sage: CyclotomicField(3).zeta(3).multiplicative_order() + sage: CyclotomicField(3).zeta(3).multiplicative_order() # optional - sage.rings.number_field 3 - sage: a = GF(7).zeta(); a + sage: a = GF(7).zeta(); a # optional - sage.rings.finite_rings 3 - sage: a.multiplicative_order() + sage: a.multiplicative_order() # optional - sage.rings.finite_rings 6 - sage: a = GF(49,'z').zeta(); a + sage: a = GF(49,'z').zeta(); a # optional - sage.rings.finite_rings z - sage: a.multiplicative_order() + sage: a.multiplicative_order() # optional - sage.rings.finite_rings 48 - sage: a = GF(49,'z').zeta(2); a + sage: a = GF(49,'z').zeta(2); a # optional - sage.rings.finite_rings 6 - sage: a.multiplicative_order() + sage: a.multiplicative_order() # optional - sage.rings.finite_rings 2 sage: QQ.zeta(3) Traceback (most recent call last): ... ValueError: no n-th root of unity in rational field - sage: Zp(7, prec=8).zeta() + sage: Zp(7, prec=8).zeta() # optional - sage.rings.padics 3 + 4*7 + 6*7^2 + 3*7^3 + 2*7^5 + 6*7^6 + 2*7^7 + O(7^8) TESTS:: @@ -984,7 +988,7 @@ cdef class Ring(ParentWithGens): 1 sage: Ring.zeta(QQ, 2) -1 - sage: Ring.zeta(QQ, 3) + sage: Ring.zeta(QQ, 3) # optional - sage.libs.pari Traceback (most recent call last): ... ValueError: no 3rd root of unity in Rational Field @@ -1021,13 +1025,13 @@ cdef class Ring(ParentWithGens): EXAMPLES:: - sage: CyclotomicField(19).zeta_order() + sage: CyclotomicField(19).zeta_order() # optional - sage.rings.number_field 38 - sage: GF(19).zeta_order() + sage: GF(19).zeta_order() # optional - sage.rings.finite_rings 18 - sage: GF(5^3,'a').zeta_order() + sage: GF(5^3,'a').zeta_order() # optional - sage.rings.finite_rings 124 - sage: Zp(7, prec=8).zeta_order() + sage: Zp(7, prec=8).zeta_order() # optional - sage.rings.padics 6 """ return self.zeta().multiplicative_order() @@ -1137,7 +1141,7 @@ cdef class Ring(ParentWithGens): For the symbolic ring, there is no reasonable answer:: - sage: SR.epsilon() + sage: SR.epsilon() # optional - sage.symbolics Traceback (most recent call last): ... NotImplementedError @@ -1195,10 +1199,11 @@ cdef class CommutativeRing(Ring): EXAMPLES:: - sage: R. = GF(3)[] - sage: R.localization((x*y, x**2+y**2)) - Multivariate Polynomial Ring in x, y over Finite Field of size 3 localized at (y, x, x^2 + y^2) - sage: ~y in _ + sage: R. = GF(3)[] # optional - sage.rings.finite_rings + sage: R.localization((x*y, x**2 + y**2)) # optional - sage.rings.finite_rings + Multivariate Polynomial Ring in x, y over Finite Field of size 3 + localized at (y, x, x^2 + y^2) + sage: ~y in _ # optional - sage.rings.finite_rings True """ if not self.is_integral_domain(): @@ -1272,11 +1277,11 @@ cdef class CommutativeRing(Ring): sage: QQ.is_commutative() True - sage: ZpCA(7).is_commutative() + sage: ZpCA(7).is_commutative() # optional - sage.rings.padics True - sage: A = QuaternionAlgebra(QQ, -1, -3, names=('i','j','k')); A + sage: A = QuaternionAlgebra(QQ, -1, -3, names=('i','j','k')); A # optional - sage.combinat sage.modules Quaternion Algebra (-1, -3) with base ring Rational Field - sage: A.is_commutative() + sage: A.is_commutative() # optional - sage.combinat sage.modules False """ return True @@ -1312,16 +1317,18 @@ cdef class CommutativeRing(Ring): All orders in number fields have Krull dimension 1, including non-maximal orders:: - sage: K. = QuadraticField(-1) - sage: R = K.maximal_order(); R - Gaussian Integers in Number Field in i with defining polynomial x^2 + 1 with i = 1*I - sage: R.krull_dimension() + sage: K. = QuadraticField(-1) # optional - sage.rings.number_field + sage: R = K.maximal_order(); R # optional - sage.rings.number_field + Gaussian Integers in Number Field in i + with defining polynomial x^2 + 1 with i = 1*I + sage: R.krull_dimension() # optional - sage.rings.number_field 1 - sage: R = K.order(2*i); R - Order in Number Field in i with defining polynomial x^2 + 1 with i = 1*I - sage: R.is_maximal() + sage: R = K.order(2*i); R # optional - sage.rings.number_field + Order in Number Field in i + with defining polynomial x^2 + 1 with i = 1*I + sage: R.is_maximal() # optional - sage.rings.number_field False - sage: R.krull_dimension() + sage: R.krull_dimension() # optional - sage.rings.number_field 1 """ raise NotImplementedError @@ -1366,16 +1373,18 @@ cdef class CommutativeRing(Ring): sage: R = QQ['x'] sage: y = polygen(R) - sage: R.extension(y^2 - 5, 'a') - Univariate Quotient Polynomial Ring in a over Univariate Polynomial Ring in x over Rational Field with modulus a^2 - 5 + sage: R.extension(y^2 - 5, 'a') # optional - sage.libs.pari + Univariate Quotient Polynomial Ring in a over + Univariate Polynomial Ring in x over Rational Field with modulus a^2 - 5 :: - sage: P. = PolynomialRing(GF(5)) - sage: F. = GF(5).extension(x^2 - 2) - sage: P. = F[] - sage: R. = F.extension(t^2 - a); R - Univariate Quotient Polynomial Ring in b over Finite Field in a of size 5^2 with modulus b^2 + 4*a + sage: P. = PolynomialRing(GF(5)) # optional - sage.rings.finite_rings + sage: F. = GF(5).extension(x^2 - 2) # optional - sage.rings.finite_rings + sage: P. = F[] # optional - sage.rings.finite_rings + sage: R. = F.extension(t^2 - a); R # optional - sage.rings.finite_rings + Univariate Quotient Polynomial Ring in b over + Finite Field in a of size 5^2 with modulus b^2 + 4*a """ from sage.rings.polynomial.polynomial_element import Polynomial if not isinstance(poly, Polynomial): @@ -1411,17 +1420,19 @@ cdef class CommutativeRing(Ring): EXAMPLES:: - sage: K. = PowerSeriesRing(GF(5)) - sage: Frob = K.frobenius_endomorphism(); Frob - Frobenius endomorphism x |--> x^5 of Power Series Ring in u over Finite Field of size 5 - sage: Frob(u) + sage: K. = PowerSeriesRing(GF(5)) # optional - sage.rings.finite_rings + sage: Frob = K.frobenius_endomorphism(); Frob # optional - sage.rings.finite_rings + Frobenius endomorphism x |--> x^5 of Power Series Ring in u + over Finite Field of size 5 + sage: Frob(u) # optional - sage.rings.finite_rings u^5 We can specify a power:: - sage: f = K.frobenius_endomorphism(2); f - Frobenius endomorphism x |--> x^(5^2) of Power Series Ring in u over Finite Field of size 5 - sage: f(1+u) + sage: f = K.frobenius_endomorphism(2); f # optional - sage.rings.finite_rings + Frobenius endomorphism x |--> x^(5^2) of Power Series Ring in u + over Finite Field of size 5 + sage: f(1+u) # optional - sage.rings.finite_rings 1 + u^25 """ from .morphism import FrobeniusEndomorphism_generic @@ -1456,18 +1467,21 @@ cdef class CommutativeRing(Ring): EXAMPLES:: sage: R. = QQ[] - sage: M = R.derivation_module(); M - Module of derivations over Multivariate Polynomial Ring in x, y, z over Rational Field - sage: M.gens() + sage: M = R.derivation_module(); M # optional - sage.modules + Module of derivations over + Multivariate Polynomial Ring in x, y, z over Rational Field + sage: M.gens() # optional - sage.modules (d/dx, d/dy, d/dz) We can specify a different codomain:: sage: K = R.fraction_field() - sage: M = R.derivation_module(K); M - Module of derivations from Multivariate Polynomial Ring in x, y, z over - Rational Field to Fraction Field of Multivariate Polynomial Ring in x, y, z over Rational Field - sage: M.gen() / x + sage: M = R.derivation_module(K); M # optional - sage.modules + Module of derivations + from Multivariate Polynomial Ring in x, y, z over Rational Field + to Fraction Field of + Multivariate Polynomial Ring in x, y, z over Rational Field + sage: M.gen() / x # optional - sage.modules 1/x*d/dx Here is an example with a non-canonical defining morphism:: @@ -1480,30 +1494,32 @@ cdef class CommutativeRing(Ring): Defn: x |--> 0 y |--> 1 z |--> 2 - sage: M = R.derivation_module(ev) - sage: M - Module of derivations from Multivariate Polynomial Ring in x, y, z over Rational Field to Rational Field + sage: M = R.derivation_module(ev) # optional - sage.modules + sage: M # optional - sage.modules + Module of derivations + from Multivariate Polynomial Ring in x, y, z over Rational Field + to Rational Field Elements in `M` acts as derivations at `(0,1,2)`:: - sage: Dx = M.gen(0); Dx + sage: Dx = M.gen(0); Dx # optional - sage.modules d/dx - sage: Dy = M.gen(1); Dy + sage: Dy = M.gen(1); Dy # optional - sage.modules d/dy - sage: Dz = M.gen(2); Dz + sage: Dz = M.gen(2); Dz # optional - sage.modules d/dz sage: f = x^2 + y^2 + z^2 - sage: Dx(f) # = 2*x evaluated at (0,1,2) + sage: Dx(f) # = 2*x evaluated at (0,1,2) # optional - sage.modules 0 - sage: Dy(f) # = 2*y evaluated at (0,1,2) + sage: Dy(f) # = 2*y evaluated at (0,1,2) # optional - sage.modules 2 - sage: Dz(f) # = 2*z evaluated at (0,1,2) + sage: Dz(f) # = 2*z evaluated at (0,1,2) # optional - sage.modules 4 An example with a twisting homomorphism:: sage: theta = R.hom([x^2, y^2, z^2]) - sage: M = R.derivation_module(twist=theta); M + sage: M = R.derivation_module(twist=theta); M # optional - sage.modules Module of twisted derivations over Multivariate Polynomial Ring in x, y, z over Rational Field (twisting morphism: x |--> x^2, y |--> y^2, z |--> z^2) @@ -1542,23 +1558,23 @@ cdef class CommutativeRing(Ring): EXAMPLES:: sage: R. = QQ[] - sage: R.derivation() + sage: R.derivation() # optional - sage.modules d/dx In that case, ``arg`` could be a generator:: - sage: R.derivation(y) + sage: R.derivation(y) # optional - sage.modules d/dy or a list of coefficients:: - sage: R.derivation([1,2,3]) + sage: R.derivation([1,2,3]) # optional - sage.modules d/dx + 2*d/dy + 3*d/dz It is not possible to define derivations with respect to a polynomial which is not a variable:: - sage: R.derivation(x^2) + sage: R.derivation(x^2) # optional - sage.modules Traceback (most recent call last): ... ValueError: unable to create the derivation @@ -1567,18 +1583,18 @@ cdef class CommutativeRing(Ring): sage: R. = QQ[] sage: theta = R.hom([x^2, y^2, z^2]) - sage: f = R.derivation(twist=theta); f + sage: f = R.derivation(twist=theta); f # optional - sage.modules 0 - sage: f.parent() + sage: f.parent() # optional - sage.modules Module of twisted derivations over Multivariate Polynomial Ring in x, y, z over Rational Field (twisting morphism: x |--> x^2, y |--> y^2, z |--> z^2) Specifying a scalar, the returned twisted derivation is the corresponding multiple of `\theta - id`:: - sage: R.derivation(1, twist=theta) + sage: R.derivation(1, twist=theta) # optional - sage.modules [x |--> x^2, y |--> y^2, z |--> z^2] - id - sage: R.derivation(x, twist=theta) + sage: R.derivation(x, twist=theta) # optional - sage.modules x*([x |--> x^2, y |--> y^2, z |--> z^2] - id) """ @@ -1696,9 +1712,9 @@ cdef class IntegralDomain(CommutativeRing): True sage: QQ.is_integrally_closed() True - sage: QQbar.is_integrally_closed() + sage: QQbar.is_integrally_closed() # optional - sage.rings.number_field True - sage: GF(5).is_integrally_closed() + sage: GF(5).is_integrally_closed() # optional - sage.rings.finite_rings True sage: Z5 = Integers(5); Z5 Ring of integers modulo 5 @@ -1715,7 +1731,7 @@ cdef class IntegralDomain(CommutativeRing): EXAMPLES:: - sage: GF(7).is_field() + sage: GF(7).is_field() # optional - sage.rings.finite_rings True The following examples have their own ``is_field`` implementations:: @@ -1785,9 +1801,9 @@ cdef class DedekindDomain(IntegralDomain): sage: ZZ.krull_dimension() 1 - sage: K = NumberField(x^2 + 1, 's') - sage: OK = K.ring_of_integers() - sage: OK.krull_dimension() + sage: K = NumberField(x^2 + 1, 's') # optional - sage.rings.number_field + sage: OK = K.ring_of_integers() # optional - sage.rings.number_field + sage: OK.krull_dimension() # optional - sage.rings.number_field 1 The following are not Dedekind domains but have @@ -1804,12 +1820,13 @@ cdef class DedekindDomain(IntegralDomain): sage: U.krull_dimension() 4 - sage: K. = QuadraticField(-1) - sage: R = K.order(2*i); R - Order in Number Field in i with defining polynomial x^2 + 1 with i = 1*I - sage: R.is_maximal() + sage: K. = QuadraticField(-1) # optional - sage.rings.number_field + sage: R = K.order(2*i); R # optional - sage.rings.number_field + Order in Number Field in i + with defining polynomial x^2 + 1 with i = 1*I + sage: R.is_maximal() # optional - sage.rings.number_field False - sage: R.krull_dimension() + sage: R.krull_dimension() # optional - sage.rings.number_field 1 """ return 1 @@ -1828,18 +1845,18 @@ cdef class DedekindDomain(IntegralDomain): sage: ZZ.is_integrally_closed() True - sage: K = NumberField(x^2 + 1, 's') - sage: OK = K.ring_of_integers() - sage: OK.is_integrally_closed() + sage: K = NumberField(x^2 + 1, 's') # optional - sage.rings.number_field + sage: OK = K.ring_of_integers() # optional - sage.rings.number_field + sage: OK.is_integrally_closed() # optional - sage.rings.number_field True These, however, are not Dedekind domains:: sage: QQ.is_integrally_closed() True - sage: S = ZZ[sqrt(5)]; S.is_integrally_closed() + sage: S = ZZ[sqrt(5)]; S.is_integrally_closed() # optional - sage.rings.number_field sage.symbolic False - sage: T. = PolynomialRing(QQ,2); T + sage: T. = PolynomialRing(QQ, 2); T Multivariate Polynomial Ring in x, y over Rational Field sage: T.is_integral_domain() True @@ -1852,11 +1869,12 @@ cdef class DedekindDomain(IntegralDomain): EXAMPLES:: - sage: K = NumberField(x^2 + 1, 's') - sage: OK = K.ring_of_integers() - sage: OK.integral_closure() - Gaussian Integers in Number Field in s with defining polynomial x^2 + 1 - sage: OK.integral_closure() == OK + sage: K = NumberField(x^2 + 1, 's') # optional - sage.rings.number_field + sage: OK = K.ring_of_integers() # optional - sage.rings.number_field + sage: OK.integral_closure() # optional - sage.rings.number_field + Gaussian Integers in Number Field in s + with defining polynomial x^2 + 1 + sage: OK.integral_closure() == OK # optional - sage.rings.number_field True sage: QQ.integral_closure() == QQ @@ -1875,9 +1893,9 @@ cdef class DedekindDomain(IntegralDomain): sage: ZZ.is_noetherian() True - sage: K = NumberField(x^2 + 1, 's') - sage: OK = K.ring_of_integers() - sage: OK.is_noetherian() + sage: K = NumberField(x^2 + 1, 's') # optional - sage.rings.number_field + sage: OK = K.ring_of_integers() # optional - sage.rings.number_field + sage: OK.is_noetherian() # optional - sage.rings.number_field True sage: QQ.is_noetherian() True @@ -1901,7 +1919,7 @@ cdef class PrincipalIdealDomain(IntegralDomain): EXAMPLES:: - sage: Zp(5).is_noetherian() + sage: Zp(5).is_noetherian() # optional - sage.rings.padics True """ return True @@ -1912,7 +1930,7 @@ cdef class PrincipalIdealDomain(IntegralDomain): EXAMPLES:: - sage: QQ.class_group() + sage: QQ.class_group() # optional - sage.groups Trivial Abelian group """ from sage.groups.abelian_gps.abelian_group import AbelianGroup @@ -1958,22 +1976,22 @@ cdef class PrincipalIdealDomain(IntegralDomain): coercible:: sage: R. = PolynomialRing(QQ) - sage: S. = NumberField(x^2 - 2, 'a') - sage: f = (x - a)*(x + a); g = (x - a)*(x^2 - 2) - sage: print(f); print(g) + sage: S. = NumberField(x^2 - 2, 'a') # optional - sage.rings.number_field + sage: f = (x - a)*(x + a); g = (x - a)*(x^2 - 2) # optional - sage.rings.number_field + sage: print(f); print(g) # optional - sage.rings.number_field x^2 - 2 x^3 - a*x^2 - 2*x + 2*a - sage: f in R + sage: f in R # optional - sage.rings.number_field True - sage: g in R + sage: g in R # optional - sage.rings.number_field False - sage: R.gcd(f,g) + sage: R.gcd(f, g) # optional - sage.rings.number_field Traceback (most recent call last): ... TypeError: Unable to coerce 2*a to a rational - sage: R.base_extend(S).gcd(f,g) + sage: R.base_extend(S).gcd(f,g) # optional - sage.rings.number_field x^2 - 2 - sage: R.base_extend(S).gcd(f, (x - a)*(x^2 - 3)) + sage: R.base_extend(S).gcd(f, (x - a)*(x^2 - 3)) # optional - sage.rings.number_field x - a """ if coerce: @@ -2066,7 +2084,7 @@ cpdef bint _is_Field(x) except -2: True sage: _is_Field(ZZ) False - sage: _is_Field(pAdicField(2)) + sage: _is_Field(pAdicField(2)) # optional - sage.rings.padics True sage: _is_Field(5) False @@ -2113,8 +2131,8 @@ cdef class Field(PrincipalIdealDomain): sage: CC.fraction_field() Complex Field with 53 bits of precision - sage: F = NumberField(x^2 + 1, 'i') - sage: F.fraction_field() + sage: F = NumberField(x^2 + 1, 'i') # optional - sage.rings.number_field + sage: F.fraction_field() # optional - sage.rings.number_field Number Field in i with defining polynomial x^2 + 1 """ return self @@ -2127,10 +2145,10 @@ cdef class Field(PrincipalIdealDomain): sage: QQ._pseudo_fraction_field() Rational Field - sage: K = GF(5) - sage: K._pseudo_fraction_field() + sage: K = GF(5) # optional - sage.rings.finite_rings + sage: K._pseudo_fraction_field() # optional - sage.rings.finite_rings Finite Field of size 5 - sage: K._pseudo_fraction_field() is K + sage: K._pseudo_fraction_field() is K # optional - sage.rings.finite_rings True """ return self @@ -2242,8 +2260,8 @@ cdef class Field(PrincipalIdealDomain): EXAMPLES:: - sage: k = GF(9, 'a') - sage: k.prime_subfield() + sage: k = GF(9, 'a') # optional - sage.rings.finite_rings + sage: k.prime_subfield() # optional - sage.rings.finite_rings Finite Field of size 3 """ if self.characteristic() == 0: @@ -2283,7 +2301,7 @@ cdef class Algebra(Ring): EXAMPLES:: - sage: A = Algebra(ZZ); A + sage: A = Algebra(ZZ); A # optional - sage.modules """ # This is a low-level class. For performance, we trust that the category @@ -2303,12 +2321,12 @@ cdef class Algebra(Ring): EXAMPLES:: - sage: A = Algebra(ZZ); A + sage: A = Algebra(ZZ); A # optional - sage.modules - sage: A.characteristic() + sage: A.characteristic() # optional - sage.modules 0 - sage: A = Algebra(GF(7^3, 'a')) - sage: A.characteristic() + sage: A = Algebra(GF(7^3, 'a')) # optional - sage.rings.finite_rings sage.modules + sage: A.characteristic() # optional - sage.rings.finite_rings sage.modules 7 """ return self.base_ring().characteristic() @@ -2323,16 +2341,16 @@ cdef class Algebra(Ring): EXAMPLES:: - sage: B = QuaternionAlgebra(2) - sage: B.has_standard_involution() + sage: B = QuaternionAlgebra(2) # optional - sage.combinat sage.modules + sage: B.has_standard_involution() # optional - sage.combinat sage.modules True sage: R. = PolynomialRing(QQ) - sage: K. = NumberField(x**2 - 2) - sage: A = QuaternionAlgebra(K,-2,5) - sage: A.has_standard_involution() + sage: K. = NumberField(x**2 - 2) # optional - sage.rings.number_field + sage: A = QuaternionAlgebra(K, -2, 5) # optional - sage.rings.number_field sage.combinat sage.modules + sage: A.has_standard_involution() # optional - sage.rings.number_field sage.combinat sage.modules True - sage: L. = FreeAlgebra(QQ,2) - sage: L.has_standard_involution() + sage: L. = FreeAlgebra(QQ, 2) # optional - sage.combinat sage.modules + sage: L.has_standard_involution() # optional - sage.combinat sage.modules Traceback (most recent call last): ... NotImplementedError: has_standard_involution is not implemented for this algebra @@ -2386,7 +2404,7 @@ cdef class CommutativeAlgebra(CommutativeRing): sage: sage.rings.ring.CommutativeAlgebra(QQ) - sage: sage.rings.ring.CommutativeAlgebra(QuaternionAlgebra(QQ,-1,-1)) + sage: sage.rings.ring.CommutativeAlgebra(QuaternionAlgebra(QQ, -1, -1)) # optional - sage.combinat sage.modules Traceback (most recent call last): ... TypeError: base ring must be a commutative ring @@ -2433,8 +2451,8 @@ def is_Ring(x): sage: from sage.rings.ring import is_Ring sage: is_Ring(ZZ) True - sage: MS = MatrixSpace(QQ,2) - sage: is_Ring(MS) + sage: MS = MatrixSpace(QQ, 2) # optional - sage.modules + sage: is_Ring(MS) # optional - sage.modules True """ return x in _Rings diff --git a/src/sage/rings/semirings/non_negative_integer_semiring.py b/src/sage/rings/semirings/non_negative_integer_semiring.py index ea3bce495d9..c041f18f99f 100644 --- a/src/sage/rings/semirings/non_negative_integer_semiring.py +++ b/src/sage/rings/semirings/non_negative_integer_semiring.py @@ -37,15 +37,15 @@ class NonNegativeIntegerSemiring(NonNegativeIntegers): Here is a piece of the Cayley graph for the multiplicative structure:: - sage: G = NN.cayley_graph(elements=range(9), generators=[0,1,2,3,5,7]) - sage: G + sage: G = NN.cayley_graph(elements=range(9), generators=[0,1,2,3,5,7]) # optional - sage.graphs + sage: G # optional - sage.graphs Looped multi-digraph on 9 vertices - sage: G.plot() + sage: G.plot() # optional - sage.graphs Graphics object consisting of 48 graphics primitives This is the Hasse diagram of the divisibility order on ``NN``. - sage: Poset(NN.cayley_graph(elements=[1..12], generators=[2,3,5,7,11])).show() + sage: Poset(NN.cayley_graph(elements=[1..12], generators=[2,3,5,7,11])).show() # optional - sage.combinat sage.graphs Note: as for :class:`NonNegativeIntegers `, ``NN`` is diff --git a/src/sage/rings/sum_of_squares.pyx b/src/sage/rings/sum_of_squares.pyx index a1d3edcedef..7e19380441e 100644 --- a/src/sage/rings/sum_of_squares.pyx +++ b/src/sage/rings/sum_of_squares.pyx @@ -140,7 +140,7 @@ def two_squares_pyx(uint32_t n): .. SEEALSO:: - :func:`~sage.arith.all.two_squares` is much more suited for large inputs + :func:`~sage.arith.misc.two_squares` is much more suited for large inputs EXAMPLES:: @@ -166,7 +166,7 @@ def two_squares_pyx(uint32_t n): TESTS:: sage: s = lambda t: sum(i^2 for i in t) - sage: for ij in Subsets(Subsets(45000,15).random_element(),2): + sage: for ij in Subsets(Subsets(45000, 15).random_element(), 2): # optional - sage.combinat ....: if s(two_squares_pyx(s(ij))) != s(ij): ....: print("hey") @@ -254,7 +254,7 @@ def three_squares_pyx(uint32_t n): TESTS:: sage: s = lambda t: sum(i^2 for i in t) - sage: for ijk in Subsets(Subsets(35000,15).random_element(),3): + sage: for ijk in Subsets(Subsets(35000,15).random_element(),3): # optional - sage.combinat ....: if s(three_squares_pyx(s(ijk))) != s(ijk): ....: print("hey") """ @@ -278,7 +278,7 @@ def four_squares_pyx(uint32_t n): .. SEEALSO:: - :func:`~sage.arith.all.four_squares` is much more suited for large input + :func:`~sage.arith.misc.four_squares` is much more suited for large input EXAMPLES:: diff --git a/src/sage/rings/tests.py b/src/sage/rings/tests.py index 2c4ab8ec988..d7d14aa4e0a 100644 --- a/src/sage/rings/tests.py +++ b/src/sage/rings/tests.py @@ -23,9 +23,9 @@ def prime_finite_field(): EXAMPLES:: sage: import sage.rings.tests - sage: K = sage.rings.tests.prime_finite_field(); K + sage: K = sage.rings.tests.prime_finite_field(); K # optional - sage.rings.finite_rings Finite Field of size ... - sage: K.cardinality().is_prime() + sage: K.cardinality().is_prime() # optional - sage.rings.finite_rings True """ from sage.rings.integer_ring import ZZ @@ -42,11 +42,11 @@ def finite_field(): EXAMPLES:: sage: import sage.rings.tests - sage: K = sage.rings.tests.finite_field(); K + sage: K = sage.rings.tests.finite_field(); K # optional - sage.rings.finite_rings Finite Field...of size ... - sage: K.cardinality().is_prime_power() + sage: K.cardinality().is_prime_power() # optional - sage.rings.finite_rings True - sage: while K.cardinality().is_prime(): + sage: while K.cardinality().is_prime(): # optional - sage.rings.finite_rings ....: K = sage.rings.tests.finite_field() """ from sage.rings.integer_ring import ZZ @@ -65,12 +65,12 @@ def small_finite_field(): EXAMPLES:: sage: import sage.rings.tests - sage: K = sage.rings.tests.small_finite_field(); K + sage: K = sage.rings.tests.small_finite_field(); K # optional - sage.rings.finite_rings Finite Field...of size ... - sage: q = K.cardinality() - sage: q.is_prime_power() + sage: q = K.cardinality() # optional - sage.rings.finite_rings + sage: q.is_prime_power() # optional - sage.rings.finite_rings True - sage: q <= 2^16 + sage: q <= 2^16 # optional - sage.rings.finite_rings True """ from sage.rings.integer_ring import ZZ @@ -107,7 +107,7 @@ def padic_field(): EXAMPLES:: sage: import sage.rings.tests - sage: sage.rings.tests.padic_field() + sage: sage.rings.tests.padic_field() # optional - sage.rings.padics ...-adic Field with capped relative precision ... """ from sage.rings.integer_ring import ZZ @@ -124,7 +124,7 @@ def quadratic_number_field(): EXAMPLES:: sage: import sage.rings.tests - sage: K = sage.rings.tests.quadratic_number_field(); K + sage: K = sage.rings.tests.quadratic_number_field(); K # optional - sage.rings.number_field Number Field in a with defining polynomial x^2 ... with a = ... """ from sage.rings.integer_ring import ZZ @@ -142,9 +142,9 @@ def absolute_number_field(maxdeg=10): EXAMPLES:: sage: import sage.rings.tests - sage: K = sage.rings.tests.absolute_number_field(); K + sage: K = sage.rings.tests.absolute_number_field(); K # optional - sage.rings.number_field Number Field in a with defining polynomial ... - sage: K.degree() <= 10 + sage: K.degree() <= 10 # optional - sage.rings.number_field True """ from sage.rings.integer_ring import ZZ @@ -167,26 +167,26 @@ def relative_number_field(n=2, maxdeg=2): EXAMPLES:: sage: import sage.rings.tests - sage: K = sage.rings.tests.relative_number_field(3); K + sage: K = sage.rings.tests.relative_number_field(3); K # optional - sage.rings.number_field Number Field in aaa with defining polynomial x^2 ... over its base field - sage: K.relative_degree() + sage: K.relative_degree() # optional - sage.rings.number_field 2 - sage: L = K.base_ring() - sage: L.relative_degree() + sage: L = K.base_ring() # optional - sage.rings.number_field + sage: L.relative_degree() # optional - sage.rings.number_field 2 - sage: M = L.base_ring() - sage: M.relative_degree() + sage: M = L.base_ring() # optional - sage.rings.number_field + sage: M.relative_degree() # optional - sage.rings.number_field 2 - sage: M.base_ring() is QQ + sage: M.base_ring() is QQ # optional - sage.rings.number_field True TESTS: Check that :trac:`32117` is fixed:: - sage: set_random_seed(3030) - sage: from sage.rings.tests import relative_number_field - sage: _ = relative_number_field(3) + sage: set_random_seed(3030) # optional - sage.rings.number_field + sage: from sage.rings.tests import relative_number_field # optional - sage.rings.number_field + sage: _ = relative_number_field(3) # optional - sage.rings.number_field """ from sage.rings.integer_ring import ZZ K = absolute_number_field(maxdeg) @@ -333,7 +333,7 @@ def test_random_elements(level=MAX_LEVEL, trials=1): EXAMPLES:: sage: import sage.rings.tests - sage: sage.rings.tests.test_random_elements(trials=2, seed=0) + sage: sage.rings.tests.test_random_elements(trials=2, seed=0) # optional - sage.rings.number_field survived 0 tests Rational Field -1/2 @@ -382,7 +382,7 @@ def test_random_arith(level=MAX_LEVEL, trials=1): EXAMPLES:: sage: import sage.rings.tests - sage: sage.rings.tests.test_random_arith(trials=2, seed=0) + sage: sage.rings.tests.test_random_arith(trials=2, seed=0) # optional - sage.rings.number_field survived 0 tests Rational Field -1/2 -1/95 @@ -437,12 +437,16 @@ def test_karatsuba_multiplication(base_ring, maxdeg1, maxdeg2, Test Karatsuba multiplication of polynomials of small degree over some common rings:: - sage: for C in [QQ, ZZ[I], GF(49, 'a'), MatrixSpace(GF(17), 3)]: + sage: rings = [QQ] + sage: rings += [ZZ[I], ZZ[I, sqrt(2)]] # optional - sage.rings.number_field + sage: rings += [GF(49, 'a')] # optional - sage.rings.finite_rings + sage: rings += [MatrixSpace(GF(17), 3)] # optional - sage.rings.finite_rings 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 + sage: test_karatsuba_multiplication(QQbar, 3, 3, numtests=2) # long time # optional - sage.rings.number_field Larger degrees (over ``ZZ``, using FLINT):: @@ -452,10 +456,10 @@ def test_karatsuba_multiplication(base_ring, maxdeg1, maxdeg2, Some more aggressive tests:: - sage: testrings = [ZZ[I, sqrt(2)], ZZ[I, sqrt(2), sqrt(3)]] # long time - sage: for C in testrings: # long time + sage: testrings = [ZZ[I, sqrt(2)], ZZ[I, sqrt(2), sqrt(3)]] # long time + sage: for C in testrings: # long time ....: test_karatsuba_multiplication(C, 100, 100) - sage: test_karatsuba_multiplication(ZZ, 10000, 10000, # long time + sage: test_karatsuba_multiplication(ZZ, 10000, 10000, # long time ....: ref_mul=lambda f,g: f*g, ....: base_ring_random_elt_args=[100000]) diff --git a/src/sage/rings/universal_cyclotomic_field.py b/src/sage/rings/universal_cyclotomic_field.py index f5d2bc5b1d9..2c6097e74e8 100644 --- a/src/sage/rings/universal_cyclotomic_field.py +++ b/src/sage/rings/universal_cyclotomic_field.py @@ -521,14 +521,14 @@ def _symbolic_(self, R): r""" TESTS:: - sage: SR(E(7)) + sage: SR(E(7)) # optional - sage.symbolic e^(2/7*I*pi) - sage: SR(E(5) + 2*E(5,2) + 3*E(5,3)) + sage: SR(E(5) + 2*E(5,2) + 3*E(5,3)) # optional - 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)) + sage: SR(1+E(4)) # optional - sage.symbolic I + 1 """ from sage.symbolic.constants import pi, I diff --git a/src/sage/schemes/product_projective/morphism.py b/src/sage/schemes/product_projective/morphism.py index 853ffdaf435..f28aa84e7ba 100644 --- a/src/sage/schemes/product_projective/morphism.py +++ b/src/sage/schemes/product_projective/morphism.py @@ -54,7 +54,7 @@ def __init__(self, parent, polys, check=True): - ``polys`` -- anything that defines a point in the class. - ``check`` -- Boolean. Whether or not to perform input checks. - (Default:`` True``) + (Default: ``True``) EXAMPLES:: diff --git a/src/sage/sets/set_from_iterator.py b/src/sage/sets/set_from_iterator.py index a99a559b691..fbbbbe4c9a0 100644 --- a/src/sage/sets/set_from_iterator.py +++ b/src/sage/sets/set_from_iterator.py @@ -460,7 +460,7 @@ def _instancedoc_(self): sage: print(sage_getdoc(d)) # indirect doctest Test whether "self" is prime. ... - Calls the PARI "isprime" function. + Calls the PARI ...isprime... """ # Duplicates sage.misc.cachefunc.CachedFunction._instancedoc_ from sage.misc.sageinspect import sage_getsourcelines, sage_getfile_relative, _extract_embedded_position