Skip to content

control-C can make equal polynomials give different cyclotomic parts #26788

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

Open
dsm054 opened this issue Nov 29, 2018 · 1 comment
Open

control-C can make equal polynomials give different cyclotomic parts #26788

dsm054 opened this issue Nov 29, 2018 · 1 comment

Comments

@dsm054
Copy link
Contributor

dsm054 commented Nov 29, 2018

In Sage 8.4 on ubuntu, in some cases, two equal polynomials -- one returned by a cached function and the one returned by a direct call -- give different results when you call .cyclotomic_part() on them. Unfortunately it's nondeterministic, and so it could have nothing to do with the function itself. I think it happens after an ill-fated interrupt.

Starting from

c = cached_function(lambda p,q: cyclotomic_polynomial(p).subs(cyclotomic_polynomial(q)))

I eventually got into a state where

sage: broken = cc(3, 935)
sage: assert broken is cc.cache[((3, 935), ())]
sage: working = cyclotomic_polynomial(3).subs(cyclotomic_polynomial(935))
sage: type(broken), type(working)
(<type 'sage.rings.polynomial.polynomial_integer_dense_flint.Polynomial_integer_dense_flint'>,
 <type 'sage.rings.polynomial.polynomial_integer_dense_flint.Polynomial_integer_dense_flint'>)
sage: broken == working, broken - working, broken / working, broken % working
(True, 0, 1, 0)
sage: broken.has_cyclotomic_factor()
True
sage: broken.cyclotomic_part()
1
sage: working.has_cyclotomic_factor()
True
sage: working.cyclotomic_part()
x^16 + x^8 + 1

I've seen this happen several times now-- earlier, in a different session, it happened at (3, 1103). If I use dumps to save the objects and then load them into a separate session, the problem doesn't carry over.

So since it's clearly stateful in some way, I wondered if it has to do with what happens if you use control-C to interrupt a process at an inopportune moment, and indeed, if I run


cc = cached_function(lambda p,q: cyclotomic_polynomial(p).subs(cyclotomic_polynomial(q)))

to create a new function, and then run the following repeatedly, hitting control-C each time:


for i in range(1, 2000):
    print(i)
    assert cc(3, i).has_cyclotomic_factor() == (cc(3, i).cyclotomic_part() != 1)

I eventually see something like

87
88
89
---------------------------------------------------------------------------
AssertionError                            Traceback (most recent call last)
<ipython-input-5-40435234e9d7> in <module>()
      1 for i in range(Integer(1), Integer(2000)):
      2     print(i)
----> 3     assert cc(Integer(3), i).has_cyclotomic_factor() == (cc(Integer(3), i).cyclotomic_part() != Integer(1))
      4 

AssertionError: 
sage: i
89
sage: cc(3, i) == cyclotomic_polynomial(3).subs(cyclotomic_polynomial(i))
True
sage: cc(3, i).cyclotomic_part()
1
sage: cyclotomic_polynomial(3).subs(cyclotomic_polynomial(i)).cyclotomic_part()
x^2 - x + 1

This is suboptimal. :-)

(I wasn't sure what component to use: please edit to whatever makes sense.)

Component: misc

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

@dsm054 dsm054 added this to the sage-8.5 milestone Nov 29, 2018
@dsm054
Copy link
Contributor Author

dsm054 commented Nov 29, 2018

comment:1

There are several possibly related tickets involving alarms, e.g. #24986, which aren't encouraging.

Unfortunately when I was trying to automate the tests I hit

sage: alarm(3)
sage:                                                                                                          

AlarmInterrupt escaped interact()

sage: 
sage:                                                                                                          
^[[26;1R
**********************************************************************

Oops, Sage crashed. We do our best to make it stable, but...

@mkoeppe mkoeppe removed this from the sage-8.5 milestone Dec 29, 2022
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

2 participants