Skip to content
This repository has been archived by the owner on Jan 30, 2023. It is now read-only.

Commit

Permalink
add _test_revert and add more rings to test
Browse files Browse the repository at this point in the history
  • Loading branch information
mantepse committed Sep 18, 2022
1 parent cc48d4e commit 54bb1d8
Showing 1 changed file with 84 additions and 12 deletions.
96 changes: 84 additions & 12 deletions src/sage/rings/lazy_series_ring.py
Original file line number Diff line number Diff line change
Expand Up @@ -763,7 +763,10 @@ def _test_invert(self, **options):
EXAMPLES::
sage: Zp(3)._test_invert()
sage: LazyLaurentSeriesRing.options.halting_precision(5)
sage: L = LazyLaurentSeriesRing(QQ, 'z')
sage: L._test_invert()
sage: LazyLaurentSeriesRing.options._reset()
.. SEEALSO::
Expand All @@ -783,6 +786,47 @@ def _test_invert(self, **options):
tester.assertTrue(e.is_one())
tester.assertEqual(y.valuation(), -x.valuation())

def _test_revert(self, **options):
"""
Test compositional inverse of elements of this ring.
INPUT:
- ``options`` -- any keyword arguments accepted by :meth:`_tester`
EXAMPLES::
sage: LazyLaurentSeriesRing.options.halting_precision(5)
sage: L = LazyLaurentSeriesRing(QQ, 'z')
sage: L._test_revert()
sage: LazyLaurentSeriesRing.options._reset()
.. SEEALSO::
:class:`TestSuite`
"""
if not hasattr(self.element_class, "revert") or self._arity != 1:
return
tester = self._tester(**options)

elements = tester.some_elements()
count = 0
for x in elements:
vx = x.valuation()
try:
y = x.revert()
vy = y.valuation()
except ValueError:
tester.assertFalse(vx == 1)
else:
count += 1
e1 = y(x)
e2 = x(y)
tester.assertEqual(e1, e2, "y(x) and x(y) differ for x = %s and y = %s" %(x, y))
# tester.assertEqual(e1, self.gen())
# we want to test at least 2 elements
tester.assertGreater(count, 1, msg="only %s elements in %s.some_elements() have a compositional inverse" % (count, self))

class LazyLaurentSeriesRing(LazySeriesRing):
r"""
The ring of lazy Laurent series.
Expand Down Expand Up @@ -961,6 +1005,15 @@ def __init__(self, base_ring, names, sparse=True, category=None):
(euclidean domains and infinite enumerated sets and metric spaces)
and infinite sets)
sage: L = LazyLaurentSeriesRing(GF(5), 't')
sage: TestSuite(L).run()
sage: L = LazyLaurentSeriesRing(GF(5)['x'], 't')
sage: TestSuite(L).run()
sage: L = LazyLaurentSeriesRing(GF(5)['x, y'], 't')
sage: TestSuite(L).run()
sage: E.<x,y> = ExteriorAlgebra(QQ)
sage: L = LazyLaurentSeriesRing(E, 't') # not tested
Expand Down Expand Up @@ -1090,23 +1143,23 @@ def some_elements(self):
EXAMPLES::
sage: L = LazyLaurentSeriesRing(ZZ, 'z')
sage: L.some_elements()
sage: L.some_elements()[:7]
[0, 1, z,
-3*z^-4 + z^-3 - 12*z^-2 - 2*z^-1 - 10 - 8*z + z^2 + z^3,
z^-2 + 3*z^-1 + 2*z + z^2 + z^3 + z^4 + O(z^5),
-2*z^-3 - 2*z^-2 + 4*z^-1 + 11 - z - 34*z^2 - 31*z^3 + O(z^4),
4*z^-2 + z^-1 + z + 4*z^2 + 9*z^3 + 16*z^4 + O(z^5)]
sage: L = LazyLaurentSeriesRing(GF(2), 'z')
sage: L.some_elements()
sage: L.some_elements()[:7]
[0, 1, z,
z^-4 + z^-3 + z^2 + z^3,
z^-1 + z^2 + z^3 + z^4 + O(z^5),
1 + z + z^3 + z^4 + z^6 + O(z^7),
z^-1 + z + z^3 + O(z^5)]
sage: L = LazyLaurentSeriesRing(GF(3), 'z')
sage: L.some_elements()
sage: L.some_elements()[:7]
[0, 1, z,
z^-3 + z^-1 + 2 + z + z^2 + z^3,
z^2 + z^3 + z^4 + O(z^5),
Expand All @@ -1115,7 +1168,10 @@ def some_elements(self):
"""
z = self.gen()
elts = [self.zero(), self.one(), z, (z-3)*(z**-2+2+z)**2, self.an_element(),
(1 - 2*z**-3)/(1 - z + 3*z**2), self(lambda n: n**2, valuation=-2)]
(1 - 2*z**-3)/(1 - z + 3*z**2),
self(lambda n: n**2, valuation=-2),
self(lambda n: n**2, valuation=1),
self([3, 2, 1], valuation=1, constant=1)]
return elts

def series(self, coefficient, valuation, degree=None, constant=None):
Expand Down Expand Up @@ -1292,6 +1348,12 @@ def __init__(self, base_ring, names, sparse=True, category=None):
sage: L = LazyPowerSeriesRing(QQ, 's, t')
sage: TestSuite(L).run()
sage: L = LazyPowerSeriesRing(GF(5), 't')
sage: TestSuite(L).run()
sage: L = LazyPowerSeriesRing(GF(5), 's, t')
sage: TestSuite(L).run()
Options are remembered across doctests::
sage: LazyLaurentSeriesRing.options.halting_precision(None)
Expand Down Expand Up @@ -1711,21 +1773,21 @@ def some_elements(self):
EXAMPLES::
sage: L = LazyPowerSeriesRing(ZZ, 'z')
sage: L.some_elements()
sage: L.some_elements()[:6]
[0, 1, z,
-12 - 8*z + z^2 + z^3,
1 + z - 2*z^2 - 7*z^3 - z^4 + 20*z^5 + 23*z^6 + O(z^7),
z + 4*z^2 + 9*z^3 + 16*z^4 + 25*z^5 + 36*z^6 + O(z^7)]
sage: L = LazyPowerSeriesRing(GF(3)["q"], 'z')
sage: L.some_elements()
sage: L.some_elements()[:6]
[0, 1, z,
z + z^2 + z^3,
1 + z + z^2 + 2*z^3 + 2*z^4 + 2*z^5 + O(z^6),
z + z^2 + z^4 + z^5 + O(z^7)]
sage: L = LazyPowerSeriesRing(GF(3), 'q, t')
sage: L.some_elements()
sage: L.some_elements()[:6]
[0, 1, q,
q + q^2 + q^3,
1 + q + q^2 + (-q^3) + (-q^4) + (-q^5) + (-q^6) + O(q,t)^7,
Expand Down Expand Up @@ -1805,6 +1867,14 @@ def __init__(self, basis, sparse=True, category=None):
sage: L = LazySymmetricFunctions(s)
sage: TestSuite(L).run()
sage: s = SymmetricFunctions(QQ["q"]).s()
sage: L = LazySymmetricFunctions(s)
sage: TestSuite(L).run()
sage: s = SymmetricFunctions(GF(5)).s()
sage: L = LazySymmetricFunctions(s)
sage: TestSuite(L).run()
Options are remembered across doctests::
sage: LazySymmetricFunctions.options.halting_precision(None)
Expand Down Expand Up @@ -2104,7 +2174,7 @@ def some_elements(self):
sage: m = SymmetricFunctions(GF(5)).m()
sage: L = LazySymmetricFunctions(m)
sage: L.some_elements()
[0, m[], 2*m[] + 2*m[1] + 3*m[2],
[0, m[], 2*m[] + 2*m[1] + 3*m[2], 2*m[1] + 3*m[2],
3*m[] + 2*m[1] + (m[1,1]+m[2])
+ (2*m[1,1,1]+m[3])
+ (2*m[1,1,1,1]+4*m[2,1,1]+2*m[2,2])
Expand All @@ -2116,16 +2186,17 @@ def some_elements(self):
sage: S = NCSF.Complete()
sage: L = S.formal_series_ring()
sage: L.some_elements()
[0, S[], 2*S[] + 2*S[1] + (3*S[1,1])]
[0, S[], 2*S[] + 2*S[1] + (3*S[1,1]), 2*S[1] + (3*S[1,1])]
"""
elt = self.an_element()
elts = [self.zero(), self.one(), elt]
elts.append(elt - elt[0])
try:
if elt.is_unit():
elts.append(~elt)
else:
elts.append(~(1-elt[0]+elt))
elts.append(~(1 - elt[0] + elt))
except NotImplementedError:
pass
return elts
Expand Down Expand Up @@ -2175,7 +2246,7 @@ class LazyDirichletSeriesRing(LazySeriesRing):
Element = LazyDirichletSeries

def __init__(self, base_ring, names, sparse=True, category=None):
"""
r"""
Initialize the ring.
TESTS::
Expand Down Expand Up @@ -2206,6 +2277,7 @@ def __init__(self, base_ring, names, sparse=True, category=None):
https://mathoverflow.net/questions/5522/dirichlet-series-with-integer-coefficients-as-a-ufd,
the ring of formal Dirichlet series is actually a
UniqueFactorizationDomain.
"""
if base_ring.characteristic() > 0:
raise ValueError("positive characteristic not allowed for Dirichlet series")
Expand Down

0 comments on commit 54bb1d8

Please sign in to comment.