镜像站点 · 本页由第三方 GitHub 只读镜像提供,非 GitHub 官方站点,不接受任何登录或凭据输入。前往 github.com
Skip to content

factorisation in nmod_poly does not gracefully handle errors #73

Open

Description

@GiacomoPope
>>> 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

Activity

  1. oscarbenjamin commented on Sep 7, 2023

    @oscarbenjamin
    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.

  2. changed the title [-]nmod does not gracefully handle errors[/-] [+]factorisation in nmod_poly does not gracefully handle errors[/+] on Sep 7, 2023
  3. GiacomoPope commented on Sep 7, 2023

    @GiacomoPope
    ContributorAuthor

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

  4. oscarbenjamin commented on Sep 7, 2023

    @oscarbenjamin
    Collaborator

    check for issues

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

  5. GiacomoPope commented on Sep 7, 2023

    @GiacomoPope
    ContributorAuthor

    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?

  6. oscarbenjamin commented on Sep 7, 2023

    @oscarbenjamin
    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

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions