Skip to content

src/sage/rings/lazy_series_ring.py: test failure for LazyPowerSeriesRing over Zmod(6) #38684

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

Closed
orlitzky opened this issue Sep 20, 2024 · 12 comments

Comments

@orlitzky
Copy link
Contributor

I'm not sure why the CI isn't catching this, I can reproduce it at https://sagecell.sagemath.org/

sage: L = LazyPowerSeriesRing(Zmod(6), 's, t')
sage: TestSuite(L).run(skip=['_test_revert'])
Failure in _test_additive_associativity:
Traceback (most recent call last):
  File "/home/sc_serv/sage/src/sage/misc/sage_unittest.py", line 297, in run
    test_method(tester=tester)
  File "/home/sc_serv/sage/src/sage/categories/additive_semigroups.py", line 86, in _test_additive_associativity
    tester.assertEqual((x + y) + z, x + (y + z))
  File "/usr/lib/python3.10/unittest/case.py", line 845, in assertEqual
    assertion_func(first, second, msg=msg)
  File "/usr/lib/python3.10/unittest/case.py", line 838, in _baseAssertEqual
    raise self.failureException(msg)
AssertionError: 3 + s + 4*s^2 + 5*s^3 + 5*s^4 + 2*s^5 + 5*s^6 + O(s,t)^7 != 3 + s + 4*s^2 + 5*s^3 + 5*s^4 + 2*s^5 + 5*s^6 + O(s,t)^7
------------------------------------------------------------
Failure in _test_associativity:
Traceback (most recent call last):
  File "/home/sc_serv/sage/src/sage/misc/sage_unittest.py", line 297, in run
    test_method(tester=tester)
  File "/home/sc_serv/sage/src/sage/categories/semigroups.py", line 121, in _test_associativity
    tester.assertEqual((x * y) * z, x * (y * z))
  File "/usr/lib/python3.10/unittest/case.py", line 845, in assertEqual
    assertion_func(first, second, msg=msg)
  File "/usr/lib/python3.10/unittest/case.py", line 838, in _baseAssertEqual
    raise self.failureException(msg)
AssertionError: s^2 + s^3 + 4*s^4 + 5*s^5 + 5*s^6 + 2*s^7 + 5*s^8 + O(s,t)^9 != s^2 + s^3 + 4*s^4 + 5*s^5 + 5*s^6 + 2*s^7 + 5*s^8 + O(s,t)^9
------------------------------------------------------------
Failure in _test_distributivity:
Traceback (most recent call last):
  File "/home/sc_serv/sage/src/sage/misc/sage_unittest.py", line 297, in run
    test_method(tester=tester)
  File "/home/sc_serv/sage/src/sage/categories/distributive_magmas_and_additive_magmas.py", line 82, in _test_distributivity
    tester.assertEqual((x + y) * z, (x * z) + (y * z))
  File "/usr/lib/python3.10/unittest/case.py", line 845, in assertEqual
    assertion_func(first, second, msg=msg)
  File "/usr/lib/python3.10/unittest/case.py", line 838, in _baseAssertEqual
    raise self.failureException(msg)
AssertionError: 2 + 2*s + 2*s^2 + 4*s^3 + 4*s^4 + 4*s^5 + 4*s^6 + O(s,t)^7 != 2 + 2*s + 2*s^2 + 4*s^3 + 4*s^4 + 4*s^5 + 4*s^6 + O(s,t)^7
------------------------------------------------------------
Failure in _test_div:
Traceback (most recent call last):
  File "/home/sc_serv/sage/src/sage/misc/sage_unittest.py", line 297, in run
    test_method(tester=tester)
  File "/home/sc_serv/sage/src/sage/rings/lazy_series_ring.py", line 1173, in _test_div
    tester.assertEqual(xx, x, "the element (%s) should be the quotient times the divisor (%s)" % (x, y))
  File "/usr/lib/python3.10/unittest/case.py", line 845, in assertEqual
    assertion_func(first, second, msg=msg)
  File "/usr/lib/python3.10/unittest/case.py", line 838, in _baseAssertEqual
    raise self.failureException(msg)
AssertionError: the element (1) should be the quotient times the divisor (1 + s + 4*s^2 + 5*s^3 + 5*s^4 + 2*s^5 + 5*s^6 + O(s,t)^7)
------------------------------------------------------------
The following tests failed: _test_additive_associativity, _test_associativity, _test_distributivity, _test_div
@mantepse
Copy link
Contributor

This is not a bug, you need to set LazyPowerSeriesRing.options.halting_precision, otherwise there is no way the LazyPowerSeriesRing could check equality.

            sage: LazyPowerSeriesRing.options.halting_precision(12)
            sage: L = LazyPowerSeriesRing(Zmod(6), 's, t')
            sage: TestSuite(L).run(skip=['_test_revert'])
            sage: LazyPowerSeriesRing.options._reset()  # reset the options

@orlitzky
Copy link
Contributor Author

Ok, thank you, that explains why the CI isn't catching it... but not why make ptestlong triggers it on my machine. I'm getting on a plane soon but I can debug it next week.

@mantepse
Copy link
Contributor

Could it be that ptestlong doesn't execute the doc tests in this docstring in one block?

@orlitzky
Copy link
Contributor Author

Then we're back to why doesn't the CI catch it :)

It's a new machine so possibly some obscure precision issue. I only discounted that explanation at first because I thought I could reproduce it on sagecell.

@orlitzky
Copy link
Contributor Author

orlitzky commented Oct 2, 2024

Ok, I'm back. This works:

sage: LazyPowerSeriesRing.options.halting_precision(4)
sage: TestSuite(L).run(skip=['_test_revert'])

but this does not:

sage: LazyPowerSeriesRing.options.halting_precision(5)
sage: TestSuite(L).run(skip=['_test_revert'])
Failure in _test_associativity:
Traceback (most recent call last):
  File "/home/mjo/src/sage.git/local/var/lib/sage/venv-python3.12/lib/python3.12/site-packages/sage/misc/sage_unittest.py", line 298, in run
    test_method(tester=tester)
  File "/home/mjo/src/sage.git/local/var/lib/sage/venv-python3.12/lib/python3.12/site-packages/sage/categories/semigroups.py", line 121, in _test_associativity
    tester.assertEqual((x * y) * z, x * (y * z))
  File "/usr/lib/python3.12/unittest/case.py", line 885, in assertEqual
    assertion_func(first, second, msg=msg)
  File "/usr/lib/python3.12/unittest/case.py", line 878, in _baseAssertEqual
    raise self.failureException(msg)
AssertionError: s + ([61 chars]^4*t+2*s^2*t^3+5*s*t^4) + (s^7+3*s^5*t^2+2*s^4[27 chars],t)^8 != s + ([61 chars]^4*t+4*s^3*t^2+2*s^2*t^3+5*s*t^4) + (s^7+3*s^5[37 chars],t)^8
------------------------------------------------------------
Failure in _test_distributivity:
Traceback (most recent call last):
  File "/home/mjo/src/sage.git/local/var/lib/sage/venv-python3.12/lib/python3.12/site-packages/sage/misc/sage_unittest.py", line 298, in run
    test_method(tester=tester)
  File "/home/mjo/src/sage.git/local/var/lib/sage/venv-python3.12/lib/python3.12/site-packages/sage/categories/distributive_magmas_and_additive_magmas.py", line 83, in _test_distributivity
    tester.assertEqual((x + y) * z, (x * z) + (y * z))
  File "/usr/lib/python3.12/unittest/case.py", line 885, in assertEqual
    assertion_func(first, second, msg=msg)
  File "/usr/lib/python3.12/unittest/case.py", line 878, in _baseAssertEqual
    raise self.failureException(msg)
AssertionError: 2 + ([60 chars]3) + (s^5+5*s^4*t+4*s^3*t^2+4*s^2*t^3+5*s*t^4+[36 chars],t)^7 != 2 + ([60 chars]3) + 4*s^2*t^2 + (s^5+5*s^4*t+4*s^3*t^2+4*s^2*[48 chars],t)^7
------------------------------------------------------------
The following tests failed: _test_associativity, _test_distributivity

I'd love to know what elements cause this to fail, but the POS test runner is hiding them, so now I have N+1 problems.

@mantepse
Copy link
Contributor

mantepse commented Oct 2, 2024

Hm, I cannot reproduce this on my computer :-(

@orlitzky
Copy link
Contributor Author

orlitzky commented Oct 2, 2024

I added print() statements to the test suites to get x,y,z. This is with LazyPowerSeriesRing.options.halting_precision = 5:

x:  s
y:  1 + (s+t) + (s^2+2*s*t+t^2) + (s^3+3*s^2*t+3*s*t^2+t^3) + (s^4+4*s^3*t+4*s*t^3+t^4) + (s^5+5*s^4*t+4*s^3*t^2+4*s^2*t^3+5*s*t^4+t^5) + (s^6+3*s^4*t^2+2*s^3*t^3+3*s^2*t^4+t^6) + O(s,t)^7
z:  1 + (s+t) + (s^2+2*s*t+t^2) + (s^3+3*s^2*t+3*s*t^2+t^3) + (s^4+4*s^3*t+4*s*t^3+t^4) + (s^5+5*s^4*t+4*s^3*t^2+4*s^2*t^3+5*s*t^4+t^5) + (s^6+3*s^4*t^2+2*s^3*t^3+3*s^2*t^4+t^6) + O(s,t)^7
Failure in _test_associativity:
...
------------------------------------------------------------
x:  1
y:  1 + (s+t) + (s^2+2*s*t+t^2) + (s^3+3*s^2*t+3*s*t^2+t^3) + (s^4+4*s^3*t+4*s*t^3+t^4) + (s^5+5*s^4*t+4*s^3*t^2+4*s^2*t^3+5*s*t^4+t^5) + (s^6+3*s^4*t^2+2*s^3*t^3+3*s^2*t^4+t^6) + O(s,t)^7
z:  1 + (s+t) + (s^2+2*s*t+t^2) + (s^3+3*s^2*t+3*s*t^2+t^3) + (s^4+4*s^3*t+4*s*t^3+t^4) + (s^5+5*s^4*t+4*s^3*t^2+4*s^2*t^3+5*s*t^4+t^5) + (s^6+3*s^4*t^2+2*s^3*t^3+3*s^2*t^4+t^6) + O(s,t)^7
Failure in _test_distributivity:
...

@orlitzky
Copy link
Contributor Author

orlitzky commented Oct 2, 2024

This is probably the same issue so I'm just going to focus on the simpler associativity property. I got the left/right computed values too now. With,

x:  s
y:  1 + (s+t) + (s^2+2*s*t+t^2) + (s^3+3*s^2*t+3*s*t^2+t^3) + (s^4+4*s^3*t+4*s*t^3+t^4) + (s^5+5*s^4*t+4*s^3*t^2+4*s^2*t^3+5*s*t^4+t^5) + (s^6+3*s^4*t^2+2*s^3*t^3+3*s^2*t^4+t^6) + O(s,t)^7
z:  1 + (s+t) + (s^2+2*s*t+t^2) + (s^3+3*s^2*t+3*s*t^2+t^3) + (s^4+4*s^3*t+4*s*t^3+t^4) + (s^5+5*s^4*t+4*s^3*t^2+4*s^2*t^3+5*s*t^4+t^5) + (s^6+3*s^4*t^2+2*s^3*t^3+3*s^2*t^4+t^6) + O(s,t)^7

I get:

LHS = s + (2*s^2+2*s*t) + (3*s^3+3*s*t^2) + (4*s^4+4*s*t^3) + (5*s^5+2*s^4*t+2*s^2*t^3+5*s*t^4) + (s^7+3*s^5*t^2+2*s^4*t^3+3*s^3*t^4+s*t^6) + O(s,t)^8
RHS = s + (2*s^2+2*s*t) + (3*s^3+3*s*t^2) + (4*s^4+4*s*t^3) + (5*s^5+2*s^4*t+4*s^3*t^2+2*s^2*t^3+5*s*t^4) + (s^7+3*s^5*t^2+2*s^4*t^3+3*s^3*t^4+s*t^6) + O(s,t)^8

I guess the LHS in this case is (x+y) + z and RHS is x + (y + z)? Or is it testing multiplication?

@mantepse
Copy link
Contributor

mantepse commented Oct 2, 2024

could you give me precise instructions on how to reproduce this? That is: exact branch (develop?) and input in a fresh session, and perhaps also a diff that makes it print the above LHS and RHS.

Thank you so much for investigating!

@orlitzky
Copy link
Contributor Author

orlitzky commented Oct 2, 2024

I wouldn't worry about it too much, you probably won't be able to reproduce it. It's happening on some new RISC-V hardware, and I would bet that I'm the first person to try to run sage (or at least, the sage test suite) on such a machine.

Mostly things are fine, but I've only had the box for about a month, and I'm still sorting out a lot of other minor issues. Until that is done, I'm working on "develop plus a bunch of random PRs needed to get the tests to pass." Eventually develop will work though, and I may even figure out how to type these elements into sage to get something reproducible.

@orlitzky
Copy link
Contributor Author

orlitzky commented Oct 5, 2024

Spoke too soon! I'm testing #38770 on my "normal" amd64 PC at work and I see the same issue.

Unless there are surprise giac conversions in this code, my next guess is that it has something to do with the system packages on Gentoo that are being used right now.

@orlitzky
Copy link
Contributor Author

orlitzky commented Oct 5, 2024

Argh, after all that... it's because singular forgot how to do multiplication: #38158 (comment)

Second prize goes to github for not showing any results when I search for lazy_series_ring in issues / pull requests.

Sorry for wasting your time, but thanks for trying to help.

@orlitzky orlitzky closed this as completed Oct 5, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants