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

factorisation in nmod_poly does not gracefully handle errors #73

Open
GiacomoPope opened this issue Sep 7, 2023 · 5 comments · May be fixed by #179
Open

factorisation in nmod_poly does not gracefully handle errors #73

GiacomoPope opened this issue Sep 7, 2023 · 5 comments · May be fixed by #179

Comments

@GiacomoPope
Copy link
Contributor

>>> nmod_poly([12, 7, 1], 10)
x^2 + 7*x + 2
>>> nmod_poly([12, 7, 1], 10).factor()
Flint exception (Impossible inverse):
    Cannot invert modulo 2*0
zsh: abort      python3
@oscarbenjamin
Copy link
Collaborator

In general I think that python-flint should avoid segfaults and aborts (except perhaps if it exposes a very low-level API).

There are some cases like this though where it is tricky because how can we know ahead of time that this will operation will or will not succeed?

In [3]: nmod_poly([1, 1], 10).factor()
Out[3]: (1, [(x + 1, 1)])

If the modulus is prime it should always succeed. The Flint docs don't give any clue as to when this is expected to work or under what circumstances it might crash. At least python-flint should warn in its docs whether a particular function might abort because aborts are considered unfriendly in Python-land.

@GiacomoPope GiacomoPope changed the title nmod does not gracefully handle errors factorisation in nmod_poly does not gracefully handle errors Sep 7, 2023
@GiacomoPope
Copy link
Contributor Author

In SageMath a common trick is with the sig_on and sig_off to check for issues, we could do something like that here?

@oscarbenjamin
Copy link
Collaborator

check for issues

What check could be done besides just warning if the modulus is not prime?

@GiacomoPope
Copy link
Contributor Author

GiacomoPope commented Sep 7, 2023

Oh for the sig_on() and sig_off() I think it just prints the error from C without the abort? So you have:

sig_on()
... some dangerous code
sig_off()

If the modulus is prime, then every element is invertible, a softer check is just ensuring that there's no non-trivial gcd before an inversion is called?

However cysignals would become another requirement for python-flint and I don't know if this is wanted?

@oscarbenjamin
Copy link
Collaborator

Perhaps there could be an argument like .factor(check=True) or something.

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

Successfully merging a pull request may close this issue.

2 participants