-
Notifications
You must be signed in to change notification settings - Fork 27
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
Use exact division for a/b
for fmpz
, fmpz_mat
, and *_poly
#109
Use exact division for a/b
for fmpz
, fmpz_mat
, and *_poly
#109
Conversation
fmpz(4) / fmpz(2) -> fmpz(2) fmpz(5) / fmpz(2) -> DomainError
Previously fmpz_mat / fmpz would give an fmpq_mat. Now fmpz_mat / fmpz succeeds and returns fmpz_mat if the division is exact and raises DomainError otherwise.
Previously an error would be raised instead.
There is a bug in the In [1]: from flint import *
In [2]: F_cmp = fmpz_mod_ctx(10)
...: R_cmp = fmpz_mod_poly_ctx(F_cmp)
...: f_cmp = R_cmp([1,2,3,4,5])
...: f_bad = R_cmp([2,2,2,2,2])
In [3]: f_cmp.exact_division(R_cmp([2]))
Out[3]: 0 The code is here: python-flint/src/flint/types/fmpz_mod_poly.pyx Lines 457 to 489 in ea65d5f
As far as I can tell everything works up to the call to fmpz_mod_poly_divides which returns 1 (meaning divisible) but sets the quotient to zero.
Maybe Maybe just anything related to any kind of division should be disallowed in python-flint for non-prime characteristic. Otherwise it seems like there will always be cases where python-flint calls some function that is not guaranteed to return sensible results or might abort on some inputs. Checking if the modulus is prime can be done when creating the context so it does not need to slow down basic operations. |
I think that non-prime moduli can be dealt with later. There would need to be a context object for nmod so that it can keep track of whether or not the modulus is prime. For now this gets the right behaviour in the well-defined cases so let's get it in. |
Use exact division for fmpz etc e.g.:
Prevously fmpz_mat and fmpz_poly when divided by fmpz would give convert to fmpq but now only exact division is supported:
Also add exact division for
fmpz_poly
,fmpq_poly
,nmod_poly
andfmpz_mod_poly
:This is all working as far as I can tell apart from the case of
nmod_poly
andfmpz_mod_poly
with non-prime moduli e.g.:The same core dump is seen with divmod (an existing problem, not changed in this PR):