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

Minor fixes for nmod #78

Merged
merged 1 commit into from
Sep 9, 2023
Merged

Conversation

oscarbenjamin
Copy link
Collaborator

These are minimal fixes needed for SymPy to be able to use nmod.

@@ -178,6 +182,8 @@ cdef class nmod(flint_scalar):
return NotImplemented
if tval == 0:
raise ZeroDivisionError("%s is not invertible mod %s" % (tval, mod.n))
if not s:
return s
# XXX: check invertibility?
x = nmod_div(sval, tval, mod)
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This change makes it so that nmod(0, p) / nmod(a, p) gives nmod(0, p).

About invertibility: in the context of SymPy's use the modulus here will always be prime. Otherwise though if tval and mod are not coprime then this gives a core dump:

In [3]: flint.nmod(1, 6) / flint.nmod(3, 6)
Flint exception (Impossible inverse):
    Cannot invert modulo 3*0
Aborted (core dumped)

That is not very friendly in Python land but I am not sure if adding checks here for is worth it: you would need to compute gcd(tval, mod) and that calculation would always be unnecessary for prime mod. Ideally Flint should provide an efficient function that could return an error code rather than aborting.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is such a function: n_gcdinv.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks. I've added this in #79

@oscarbenjamin oscarbenjamin merged commit 9a86d4e into flintlib:master Sep 9, 2023
16 checks passed
@oscarbenjamin oscarbenjamin deleted the pr_nmod branch September 9, 2023 11:31
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

Successfully merging this pull request may close these issues.

2 participants