Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

more testsuites for lazy series rings #34552

Closed
mantepse opened this issue Sep 18, 2022 · 105 comments
Closed

more testsuites for lazy series rings #34552

mantepse opened this issue Sep 18, 2022 · 105 comments

Comments

@mantepse
Copy link
Contributor

In this ticket we implement systematic tests for operations on lazy series.

Depends on #34470

CC: @tscrim

Component: combinatorics

Keywords: LazyPowerSeries

Author: Martin Rubey

Branch/Commit: 3e84c90

Reviewer: Travis Scrimshaw, Frédéric Chapoton

Issue created by migration from https://trac.sagemath.org/ticket/34552

@mantepse mantepse added this to the sage-9.8 milestone Sep 18, 2022
@mantepse
Copy link
Contributor Author

@mantepse

This comment has been minimized.

@mantepse
Copy link
Contributor Author

Author: Martin Rubey

@mantepse
Copy link
Contributor Author

Last 10 new commits:

e3e331cadd and correct some_elements for all rings, run all tests in the TestSuite (many fail)
00aaca0introduce halting precision
f9dd62efix equality of exact series, do not produce coefficients of polynomials by iterating over them
b9a66beimplement missing required method lift_to_precision
88109ccfix precision also in species directory, do not forget to switch it off after doctest
08baf9afix punctuation in docstrings
5bd0331correct an_element and some_elements, implement is_unit, _test_invert
1722ecafix is_unit
cdf821aimprove equality, raise errors when trying to invert series which are known not to be invertible, be more careful not to compute terms
cc48d4eMerge branch 'u/mantepse/categories_of_lazy_series' of trac.sagemath.org:sage into t/34552/more_testsuites_for_lazy_series_rings

@mantepse
Copy link
Contributor Author

Changed keywords from none to LazyPowerSeries

@mantepse
Copy link
Contributor Author

Dependencies: #34470

@mantepse
Copy link
Contributor Author

Commit: cc48d4e

@sagetrac-git
Copy link
Mannequin

sagetrac-git mannequin commented Sep 18, 2022

Changed commit from cc48d4e to 54bb1d8

@sagetrac-git
Copy link
Mannequin

sagetrac-git mannequin commented Sep 18, 2022

Branch pushed to git repo; I updated commit sha1. New commits:

54bb1d8add _test_revert and add more rings to test

@sagetrac-git
Copy link
Mannequin

sagetrac-git mannequin commented Sep 18, 2022

Branch pushed to git repo; I updated commit sha1. New commits:

60f0664fix more _an_element and some_element with incorrect coefficients

@sagetrac-git
Copy link
Mannequin

sagetrac-git mannequin commented Sep 18, 2022

Changed commit from 54bb1d8 to 60f0664

@mantepse
Copy link
Contributor Author

comment:5

Apparently, reversion of symmetric functions with linear coefficient different from 1 is completely broken:

sage: g = L(2*s[1]+s[2])
sage: g
2*p[1] + (1/2*p[1,1]+1/2*p[2])
sage: g.revert()(g)
p[1] + (-1/4*p[1,1]-1/4*p[2]) + (1/4*p[1,1,1]+1/4*p[2,1]) + (-9/32*p[1,1,1,1]-5/16*p[2,1,1]+3/32*p[2,2]+1/8*p[4]) + (11/32*p[1,1,1,1,1]+7/16*p[2,1,1,1]-1/32*p[2,2,1]-1/8*p[4,1]) + (-57/128*p[1,1,1,1,1,1]-83/128*p[2,1,1,1,1]-7/128*p[2,2,1,1]-13/128*p[2,2,2]+5/32*p[4,1,1]-3/32*p[4,2]) + (77/128*p[1,1,1,1,1,1,1]+127/128*p[2,1,1,1,1,1]+27/128*p[2,2,1,1,1]+9/128*p[2,2,2,1]-7/32*p[4,1,1,1]+1/32*p[4,2,1]) + O^8

@mantepse
Copy link
Contributor Author

comment:6

Obviously, there was a parenthesis missing. I thought I changed that already once.

@sagetrac-git
Copy link
Mannequin

sagetrac-git mannequin commented Sep 18, 2022

Branch pushed to git repo; I updated commit sha1. New commits:

fbccb39normalize degree in Stream_exact for correct equality
b20eabfMerge branch 'u/mantepse/categories_of_lazy_series' of trac.sagemath.org:sage into t/34552/more_testsuites_for_lazy_series_rings
7cbde49fix reversion of symmetric functions, improve some_elements and tests

@sagetrac-git
Copy link
Mannequin

sagetrac-git mannequin commented Sep 18, 2022

Changed commit from 60f0664 to 7cbde49

@sagetrac-git
Copy link
Mannequin

sagetrac-git mannequin commented Sep 18, 2022

Changed commit from 7cbde49 to 6a46183

@sagetrac-git
Copy link
Mannequin

sagetrac-git mannequin commented Sep 18, 2022

Branch pushed to git repo; I updated commit sha1. New commits:

3d5b8cfLast little things from the patchbot.
aa593b5Merge branch 'u/mantepse/categories_of_lazy_series' of https://github.com/sagemath/sagetrac-mirror into u/tscrim/categories_lazy_series-34470
840539dMore tests, more bugs fixed.
b930f58Merge branch 'u/mantepse/categories_of_lazy_series' of https://github.com/sagemath/sagetrac-mirror into u/tscrim/categories_lazy_series-34470
6a46183Merge branch 'u/tscrim/categories_lazy_series-34470' of trac.sagemath.org:sage into t/34552/more_testsuites_for_lazy_series_rings

@sagetrac-git
Copy link
Mannequin

sagetrac-git mannequin commented Sep 18, 2022

Changed commit from 6a46183 to b15e36d

@sagetrac-git
Copy link
Mannequin

sagetrac-git mannequin commented Sep 18, 2022

Branch pushed to git repo; I updated commit sha1. New commits:

b15e36dskip test_revert when base ring is not a field

@sagetrac-git
Copy link
Mannequin

sagetrac-git mannequin commented Sep 18, 2022

Branch pushed to git repo; I updated commit sha1. New commits:

8e7b76dfix and simplify wrong doctest

@sagetrac-git
Copy link
Mannequin

sagetrac-git mannequin commented Sep 18, 2022

Changed commit from b15e36d to 8e7b76d

@sagetrac-git
Copy link
Mannequin

sagetrac-git mannequin commented Sep 19, 2022

Branch pushed to git repo; I updated commit sha1. New commits:

b47407bImplementing `_floordiv_`, Stream._true_order to boolean, first fraction field, more tests, marking long tests.
e077b66Using dynamic classes for FPS gcd.
f8ea81bMerge branch 'u/tscrim/categories_lazy_series-34470' of trac.sagemath.org:sage into t/34552/more_testsuites_for_lazy_series_rings

@sagetrac-git
Copy link
Mannequin

sagetrac-git mannequin commented Sep 19, 2022

Changed commit from 8e7b76d to f8ea81b

@mantepse
Copy link
Contributor Author

comment:13

The following should work, but doesn't, because reversion is not lazy enough:

sage: L.<t> = LazyPowerSeriesRing(QQ)
sage: f = L.undefined()
sage: f.define(1+(t*f).revert())

In this case, f should have the coefficients of https://oeis.org/A067145.

@tscrim
Copy link
Collaborator

tscrim commented Sep 20, 2022

comment:14

Replying to Martin Rubey:

The following should work, but doesn't, because reversion is not lazy enough:

sage: L.<t> = LazyPowerSeriesRing(QQ)
sage: f = L.undefined()
sage: f.define(1+(t*f).revert())

In this case, f should have the coefficients of https://oeis.org/A067145.

This one is harder because of the nature of the tests being done. Nothing can be promised about the coefficients of the undefined series. It comes down to how much we want to promise that the code will not break on bad input. I am thinking we can change

-        if not coeff_stream[1]:
+        if coeff_stream._approximate_order > 1:
             raise ValueError("compositional inverse does not exist")
-
-        if coeff_stream[0]:
-            raise ValueError("cannot determine whether the compositional inverse exists")

Then we run into an issue with computing the exact order in Stream_cauchy_invert. So we are doing too many things not lazily enough. (For the invert, we can make _ainv a @lazy_attribute to fix this easily.)

@mantepse
Copy link
Contributor Author

comment:15

In principle, I think it is more important that define works reliably when the input is valid than having helpful error messages. However, silently wrong output is probably equally bad as failures on good input.

For the issue at hand, I think we can rewrite

-        # TODO: shift instead of (self / z) should be more efficient
-        g.define(z / ((self / z)(g)))
+        # the following is mathematically equivalent to
+        # z / ((self / z)(g))
+        # but more efficient and more lazy
+        g.define((~self.shift(-1)(g)).shift(1))

Here is my thinking:

  • in __invert__, and shift(-1) it is correct to fail on LazyPowerSeries with positive valuation (in contrast to _div_). In particular, f * ~ z is actually bad input for LazyPowerSeries

  • I don't see how we can (without great effor) avoid the order computation in Stream_cauchy_invert.__init__, when we have no upper bound on the valuation of the input, because it's negative is passed to super().__init__. In our Aldor implementation, Ralf and I created a new domain which allowed computation with "unknowns". I am not sure whether we want this.

@sagetrac-git
Copy link
Mannequin

sagetrac-git mannequin commented Sep 26, 2022

Branch pushed to git repo; I updated commit sha1. Last 10 new commits:

1388b8aMerge branch 'u/chapoton/34494' of https://github.com/sagemath/sagetrac-mirror into public/rings/lazy_series_revert-34383
7bfe5f7Merge branch 'public/rings/lazy_series_revert-34383' of https://github.com/sagemath/sagetrac-mirror into public/rings/lazy_series_revert-34383
2039990Updating doctest due to changes from #34494.
cdea820Merge branch 'public/rings/lazy_series_revert-34383' of https://github.com/sagemath/sagetrac-mirror into u/tscrim/derivatives_lazy_series-34413
b7f04edMerge branch 'develop' of trac.sagemath.org:sage into t/34413/derivatives_lazy_series-34413
2325826Merge branch 'u/mantepse/derivatives_lazy_series-34413' of trac.sagemath.org:sage into t/34422/implement_functorial_composition_of_lazy_symmetric_functiosn
ebcf5c3Merge branch 'u/mantepse/implement_functorial_composition_of_lazy_symmetric_functiosn' of trac.sagemath.org:sage into t/34423/implement_arithmetic_product_of_lazy_symmetric_functions
4172688Merge branch 'u/mantepse/implement_arithmetic_product_of_lazy_symmetric_functions' of trac.sagemath.org:sage into t/32367/replace_lazy_power_series-32367
41ca99bMerge branch 'u/mantepse/replace_lazy_power_series-32367' of trac.sagemath.org:sage into t/34470/categories_lazy_series-34470
fb3a5cdMerge branch 'u/mantepse/categories_lazy_series-34470' of trac.sagemath.org:sage into t/34552/lazy_series_test_suite-34552

@sagetrac-git
Copy link
Mannequin

sagetrac-git mannequin commented Sep 26, 2022

Branch pushed to git repo; I updated commit sha1. New commits:

855d2bfremove unused variable

@sagetrac-git
Copy link
Mannequin

sagetrac-git mannequin commented Sep 26, 2022

Changed commit from fb3a5cd to 855d2bf

@sagetrac-git
Copy link
Mannequin

sagetrac-git mannequin commented Sep 26, 2022

Branch pushed to git repo; I updated commit sha1. New commits:

75c275cadd documentation and doctests for _approximate_order

@sagetrac-git
Copy link
Mannequin

sagetrac-git mannequin commented Sep 26, 2022

Changed commit from 855d2bf to 75c275c

@mantepse
Copy link
Contributor Author

comment:58

Essentially green bot.

The pyflakes warnings local variable 'res' is assigned to but never used are from #34345. Should I fix them here or elsewhere?

@mantepse
Copy link
Contributor Author

comment:59

The codestylecheck warnings are as follows:

sage/rings/lazy_series.py:843:21: E711 comparison to None should be 'if cond is None:'
sage/rings/lazy_series.py:961:17: E711 comparison to None should be 'if cond is None:'
sage/rings/lazy_series.py:5452:9: E306 expected 1 blank line before a nested definition, found 0

The first two wouldn't work with is, because an option only compares equal to None:

            prec = self.parent().options.halting_precision
            if prec == None:
                raise ValueError("undecidable")

The E306 I disagree with, I am setting the "local" variables for the local function definition. (X is used later, but looks best at this spot)

        la = Partition([1])
        X = R(la)
        def coefficient(n):
            if n:
                return 0
            c = coeff_stream[1][la]
            if c.is_unit():
                return ~c
            raise ValueError("compositional inverse does not exist")

@mantepse
Copy link
Contributor Author

comment:60

It is interesting that the github bots will not detect the unused variables.

@fchapoton
Copy link
Contributor

comment:61

Sorry, but the linter must pass, no choice. Even if E306 is in some sense a matter of taste, it is currently required. Your def without empty line before would be the only one in the whole sage code base.

About the comparison to None, this is very strange. Could you use "if not prec" instead ? or some isinstance ? What is the type of "prec" that is equal but not None ?

@mantepse
Copy link
Contributor Author

comment:62

Hi Frédéric!

Concerning the second question:

sage: L.<z> = LazyLaurentSeriesRing(QQ)
sage: L.options.halting_precision
None
sage: type(L.options.halting_precision)
<class 'sage.structure.global_options.Option'>
sage: L.options.halting_precision == None
True
sage: L.options.halting_precision is None
False

@mantepse
Copy link
Contributor Author

comment:63

I'll add the missing line.

Could you please also respond to comment:58?

(these pyflakes warnings were missed in a completely unrelated ticket)

@fchapoton
Copy link
Contributor

comment:64

the pyflakes warning are not your responsability, but you can fix them if you want

For the comparison to None, maybe this could fixed using the complicated syntax

sage: op = L.options.constant_length
sage: op._options[op._name]
3
sage: type(_)
<class 'int'>

or by adding in general a way to extract the bare value of an option somehow.

@fchapoton
Copy link
Contributor

comment:65

simpler:

sage: Q=L.options
sage: type(Q['constant_length'])
<class 'int'>

@sagetrac-git
Copy link
Mannequin

sagetrac-git mannequin commented Sep 29, 2022

Changed commit from 75c275c to 5393242

@sagetrac-git
Copy link
Mannequin

sagetrac-git mannequin commented Sep 29, 2022

Branch pushed to git repo; I updated commit sha1. New commits:

5393242fixes for pycodestyle and pyflakes

@mantepse
Copy link
Contributor Author

comment:67

Cool, thank you!

@sagetrac-git
Copy link
Mannequin

sagetrac-git mannequin commented Oct 5, 2022

Changed commit from 5393242 to 3e84c90

@sagetrac-git
Copy link
Mannequin

sagetrac-git mannequin commented Oct 5, 2022

Branch pushed to git repo; I updated commit sha1. New commits:

67dff95Merge branch 'develop' of trac.sagemath.org:sage into t/32367/replace_lazy_power_series-32367
4fc981bfix for pyflakes and blocks
56cef07Merge branch 'u/mantepse/replace_lazy_power_series-32367' of trac.sagemath.org:sage into t/34470/categories_lazy_series-34470
3e84c90Merge branch 'u/mantepse/categories_lazy_series-34470' of trac.sagemath.org:sage into t/34552/lazy_series_test_suite-34552

@tscrim
Copy link
Collaborator

tscrim commented Oct 11, 2022

Reviewer: Travis Scrimshaw, Frédéric Chapoton

@tscrim
Copy link
Collaborator

tscrim commented Oct 11, 2022

comment:69

I am assuming Frédéric is now happy. LGTM. We can do more on further tickets.

@vbraun
Copy link
Member

vbraun commented Oct 16, 2022

Changed branch from u/mantepse/lazy_series_test_suite-34552 to 3e84c90

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants