Skip to content

Commit 22999ff

Browse files
author
Release Manager
committed
gh-35554: Laurent polynomial/series modularization fixes <!-- Please provide a concise, informative and self-explanatory title. --> <!-- Don't put issue numbers in the title. Put it in the Description below. --> <!-- For example, instead of "Fixes #12345", use "Add a new method to multiply two integers" --> ### 📚 Description <!-- Describe your changes here in detail. --> We remove several obstacles to modularization: - `sage.data_structures.stream` importing from `sage.combinat.sf` - eager module-level imports in `sage.rings.bigoh`, importing `LaurentSeries`, `PuiseuxSeries`, padics. - `LaurentSeriesRing._element_constructor_` unconditionally importing `sage.libs.pari.all` just for an `isinstance` test - import of `factorial` from `sage.functions` (only the version from `sage.arith` is needed) - multivariate implementation of Laurent polynomials (with compile-time dependency on `sage.matrix`) mixed with the univariate implementation Also adding `# optional` tags for the doctests that depend on `sage.rings.finite_rings`, `sage.symbolic`. <!-- Why is this change required? What problem does it solve? --> Part of: - #29705 <!-- If this PR resolves an open issue, please link to it here. For example "Fixes #12345". --> <!-- If your change requires a documentation PR, please link it appropriately. --> ### 📝 Checklist <!-- Put an `x` in all the boxes that apply. It should be `[x]` not `[x ]`. --> - [x] The title is concise, informative, and self-explanatory. - [ ] The description explains in detail what this PR is about. - [x] I have linked a relevant issue or discussion. - [ ] I have created tests covering the changes. - [ ] I have updated the documentation accordingly. ### ⌛ Dependencies <!-- List all open PRs that this PR logically depends on - #12345: short description why this is a dependency - #34567: ... --> <!-- If you're unsure about any of these, don't hesitate to ask. We're here to help! --> URL: #35554 Reported by: Matthias Köppe Reviewer(s): Kwankyu Lee, Matthias Köppe
2 parents de29e70 + b9bf5bb commit 22999ff

14 files changed

+2356
-2255
lines changed

src/sage/combinat/root_system/root_lattice_realization_algebras.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -1166,13 +1166,13 @@ def expand(self, alphabet):
11661166
TESTS::
11671167
11681168
sage: type(p.expand(F.gens()))
1169-
<class 'sage.rings.polynomial.laurent_polynomial.LaurentPolynomial_mpair'>
1169+
<class 'sage.rings.polynomial.laurent_polynomial_mpair.LaurentPolynomial_mpair'>
11701170
11711171
sage: p = KL.zero()
11721172
sage: p.expand(F.gens())
11731173
0
11741174
sage: type(p.expand(F.gens()))
1175-
<class 'sage.rings.polynomial.laurent_polynomial.LaurentPolynomial_mpair'>
1175+
<class 'sage.rings.polynomial.laurent_polynomial_mpair.LaurentPolynomial_mpair'>
11761176
"""
11771177
codomain = alphabet[0].parent()
11781178
return codomain.sum(c * prod(X**int(n)

src/sage/data_structures/stream.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -99,10 +99,12 @@
9999
from sage.arith.misc import divisors
100100
from sage.misc.misc_c import prod
101101
from sage.misc.lazy_attribute import lazy_attribute
102+
from sage.misc.lazy_import import lazy_import
102103
from sage.combinat.integer_vector_weighted import iterator_fast as wt_int_vec_iter
103-
from sage.combinat.sf.sfa import _variables_recursive, _raise_variables
104104
from sage.categories.hopf_algebras_with_basis import HopfAlgebrasWithBasis
105105

106+
lazy_import('sage.combinat.sf.sfa', ['_variables_recursive', '_raise_variables'])
107+
106108

107109
class Stream():
108110
"""

src/sage/rings/big_oh.py

+36-26
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,25 @@
99
- `polynomials <../../../polynomial_rings/index.html>`_
1010
"""
1111

12-
import sage.arith.all as arith
13-
from . import laurent_series_ring_element
14-
from sage.rings.puiseux_series_ring_element import PuiseuxSeries
15-
import sage.rings.padics.factory as padics_factory
16-
import sage.rings.padics.padic_generic_element as padic_generic_element
12+
from sage.arith.misc import factor
13+
from sage.misc.lazy_import import lazy_import
14+
lazy_import('sage.rings.padics.factory', ['Qp', 'Zp'])
15+
lazy_import('sage.rings.padics.padic_generic_element', 'pAdicGenericElement')
16+
from sage.rings.polynomial.polynomial_element import Polynomial
17+
18+
try:
19+
from .laurent_series_ring_element import LaurentSeries
20+
except ImportError:
21+
LaurentSeries = ()
22+
23+
try:
24+
from .puiseux_series_ring_element import PuiseuxSeries
25+
except ImportError:
26+
PuiseuxSeries = ()
27+
1728
from . import power_series_ring_element
1829
from . import integer
1930
from . import rational
20-
from sage.rings.polynomial.polynomial_element import Polynomial
2131
from . import multi_power_series_ring_element
2232

2333

@@ -47,41 +57,42 @@ def O(*x, **kwds):
4757
4858
This is also useful to create `p`-adic numbers::
4959
50-
sage: O(7^6)
60+
sage: O(7^6) # optional - sage.rings.padics
5161
O(7^6)
52-
sage: 1/3 + O(7^6)
62+
sage: 1/3 + O(7^6) # optional - sage.rings.padics
5363
5 + 4*7 + 4*7^2 + 4*7^3 + 4*7^4 + 4*7^5 + O(7^6)
5464
5565
It behaves well with respect to adding negative powers of `p`::
5666
57-
sage: a = O(11^-32); a
67+
sage: a = O(11^-32); a # optional - sage.rings.padics
5868
O(11^-32)
59-
sage: a.parent()
69+
sage: a.parent() # optional - sage.rings.padics
6070
11-adic Field with capped relative precision 20
6171
6272
There are problems if you add a rational with very negative
6373
valuation to an `O`-Term::
6474
65-
sage: 11^-12 + O(11^15)
75+
sage: 11^-12 + O(11^15) # optional - sage.rings.padics
6676
11^-12 + O(11^8)
6777
6878
The reason that this fails is that the constructor doesn't know
6979
the right precision cap to use. If you cast explicitly or use
7080
other means of element creation, you can get around this issue::
7181
72-
sage: K = Qp(11, 30)
73-
sage: K(11^-12) + O(11^15)
82+
sage: K = Qp(11, 30) # optional - sage.rings.padics
83+
sage: K(11^-12) + O(11^15) # optional - sage.rings.padics
7484
11^-12 + O(11^15)
75-
sage: 11^-12 + K(O(11^15))
85+
sage: 11^-12 + K(O(11^15)) # optional - sage.rings.padics
7686
11^-12 + O(11^15)
77-
sage: K(11^-12, absprec = 15)
87+
sage: K(11^-12, absprec=15) # optional - sage.rings.padics
7888
11^-12 + O(11^15)
79-
sage: K(11^-12, 15)
89+
sage: K(11^-12, 15) # optional - sage.rings.padics
8090
11^-12 + O(11^15)
8191
8292
We can also work with `asymptotic expansions`_::
8393
84-
sage: A.<n> = AsymptoticRing(growth_group='QQ^n * n^QQ * log(n)^QQ', coefficient_ring=QQ); A
94+
sage: A.<n> = AsymptoticRing(growth_group='QQ^n * n^QQ * log(n)^QQ', # optional - sage.symbolic
95+
....: coefficient_ring=QQ); A
8596
Asymptotic Ring <QQ^n * n^QQ * log(n)^QQ * Signs^n> over Rational Field
8697
sage: O(n)
8798
O(n)
@@ -137,9 +148,8 @@ def O(*x, **kwds):
137148
"for the maximal ideal (x)")
138149
return x.parent().completion(x.parent().gen())(0, x.degree(), **kwds)
139150

140-
elif isinstance(x, laurent_series_ring_element.LaurentSeries):
141-
return laurent_series_ring_element.LaurentSeries(x.parent(), 0).\
142-
add_bigoh(x.valuation(), **kwds)
151+
elif isinstance(x, LaurentSeries):
152+
return LaurentSeries(x.parent(), 0).add_bigoh(x.valuation(), **kwds)
143153

144154
elif isinstance(x, PuiseuxSeries):
145155
return x.add_bigoh(x.valuation(), **kwds)
@@ -148,18 +158,18 @@ def O(*x, **kwds):
148158
# p-adic number
149159
if x <= 0:
150160
raise ArithmeticError("x must be a prime power >= 2")
151-
F = arith.factor(x)
161+
F = factor(x)
152162
if len(F) != 1:
153163
raise ArithmeticError("x must be prime power")
154164
p, r = F[0]
155165
if r >= 0:
156-
return padics_factory.Zp(p, prec=max(r, 20),
157-
type='capped-rel')(0, absprec=r, **kwds)
166+
return Zp(p, prec=max(r, 20),
167+
type='capped-rel')(0, absprec=r, **kwds)
158168
else:
159-
return padics_factory.Qp(p, prec=max(r, 20),
160-
type='capped-rel')(0, absprec=r, **kwds)
169+
return Qp(p, prec=max(r, 20),
170+
type='capped-rel')(0, absprec=r, **kwds)
161171

162-
elif isinstance(x, padic_generic_element.pAdicGenericElement):
172+
elif isinstance(x, pAdicGenericElement):
163173
return x.parent()(0, absprec=x.valuation(), **kwds)
164174
elif hasattr(x, 'O'):
165175
return x.O(**kwds)

src/sage/rings/laurent_series_ring.py

+5-1
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,11 @@
4747

4848
from sage.rings.integer_ring import ZZ
4949

50+
try:
51+
from sage.libs.pari.all import pari_gen
52+
except ImportError:
53+
pari_gen = ()
54+
5055

5156
def is_LaurentSeriesRing(x):
5257
"""
@@ -483,7 +488,6 @@ def _element_constructor_(self, x, n=0, prec=infinity):
483488
from sage.rings.polynomial.polynomial_element import Polynomial
484489
from sage.rings.polynomial.multi_polynomial import MPolynomial
485490
from sage.structure.element import parent
486-
from sage.libs.pari.all import pari_gen
487491

488492
P = parent(x)
489493
if isinstance(x, self.element_class) and n == 0 and P is self:

src/sage/rings/laurent_series_ring_element.pyx

+2-2
Original file line numberDiff line numberDiff line change
@@ -1594,8 +1594,8 @@ cdef class LaurentSeries(AlgebraElement):
15941594
15951595
TESTS::
15961596
1597-
sage: y = var('y')
1598-
sage: f.derivative(y)
1597+
sage: y = var('y') # optional - sage.symbolic
1598+
sage: f.derivative(y) # optional - sage.symbolic
15991599
Traceback (most recent call last):
16001600
...
16011601
ValueError: cannot differentiate with respect to y

0 commit comments

Comments
 (0)