Skip to content

Commit

Permalink
fix: make invmod more robust for non-prime moduli
Browse files Browse the repository at this point in the history
(before it was giving silently wrong results)
  • Loading branch information
thofma committed Dec 20, 2024
1 parent 58071cd commit 7a51b60
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/HeckeMoreStuff.jl
Original file line number Diff line number Diff line change
Expand Up @@ -415,7 +415,8 @@ end
function invmod(f::ZZModPolyRingElem, M::ZZModPolyRingElem)
if !is_unit(f)
r = parent(f)()
i = @ccall libflint.fmpz_mod_poly_invmod(r::Ref{ZZModPolyRingElem}, f::Ref{ZZModPolyRingElem}, M::Ref{ZZModPolyRingElem}, f.parent.base_ring.ninv::Ref{fmpz_mod_ctx_struct})::Int
ff = ZZ()
i = @ccall libflint.fmpz_mod_poly_invmod_f(ff::Ref{ZZRingElem}, r::Ref{ZZModPolyRingElem}, f::Ref{ZZModPolyRingElem}, M::Ref{ZZModPolyRingElem}, f.parent.base_ring.ninv::Ref{fmpz_mod_ctx_struct})::Int

Check warning on line 419 in src/HeckeMoreStuff.jl

View check run for this annotation

Codecov / codecov/patch

src/HeckeMoreStuff.jl#L419

Added line #L419 was not covered by tests
if iszero(i)
error("not yet implemented")
else
Expand Down
6 changes: 6 additions & 0 deletions test/flint/fmpz_mod_poly-test.jl
Original file line number Diff line number Diff line change
Expand Up @@ -343,6 +343,12 @@ end
@test powermod(f, -10, g) == 78305338116088931412*x+91239060941924718463

@test powermod(f, -ZZRingElem(10), g) == 78305338116088931412*x+91239060941924718463

R, = residue_ring(ZZ, ZZ(2809))
Rx, x = R[:x]
f = 32*x^9 + 28*x^8 + 2497*x^7 + 2443*x^6 + 708*x^5 + 996*x^4 + 2557*x^3 + 2104*x^2 + 2517*x + 2752
g = x^10 + 2798*x^8 + 2806*x^7 + 37*x^6 + 14*x^5 + 2761*x^4 + 2787*x^3 + 20*x^2 + 12*x + 1
@test_throws ErrorException invmod(f, g)
end

@testset "ZZModPolyRingElem.euclidean_division" begin
Expand Down

0 comments on commit 7a51b60

Please sign in to comment.