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

fix: irreducibility of constant polynomials over finite fields #1988

Merged
merged 1 commit into from
Jan 9, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/flint/fmpz_mod_poly.jl
Original file line number Diff line number Diff line change
Expand Up @@ -645,6 +645,7 @@ end

function is_irreducible(x::ZZModPolyRingElem)
!is_probable_prime(modulus(x)) && error("Modulus not prime in is_irreducible")
is_constant(x) && return false
return Bool(@ccall libflint.fmpz_mod_poly_is_irreducible(x::Ref{ZZModPolyRingElem}, x.parent.base_ring.ninv::Ref{fmpz_mod_ctx_struct})::Cint)
end

Expand Down
1 change: 1 addition & 0 deletions src/flint/fq_default_poly.jl
Original file line number Diff line number Diff line change
Expand Up @@ -513,6 +513,7 @@ end
################################################################################

function is_irreducible(x::FqPolyRingElem)
is_constant(x) && return false
return Bool(@ccall libflint.fq_default_poly_is_irreducible(x::Ref{FqPolyRingElem}, base_ring(parent(x))::Ref{FqField})::Int32)
end

Expand Down
1 change: 1 addition & 0 deletions src/flint/fq_nmod_poly.jl
Original file line number Diff line number Diff line change
Expand Up @@ -519,6 +519,7 @@ end
################################################################################

function is_irreducible(x::fqPolyRepPolyRingElem)
is_constant(x) && return false
return Bool(@ccall libflint.fq_nmod_poly_is_irreducible(x::Ref{fqPolyRepPolyRingElem}, base_ring(parent(x))::Ref{fqPolyRepField})::Int32)
end

Expand Down
1 change: 1 addition & 0 deletions src/flint/fq_poly.jl
Original file line number Diff line number Diff line change
Expand Up @@ -519,6 +519,7 @@ end
################################################################################

function is_irreducible(x::FqPolyRepPolyRingElem)
is_constant(x) && return false
return Bool(@ccall libflint.fq_poly_is_irreducible(x::Ref{FqPolyRepPolyRingElem}, base_ring(parent(x))::Ref{FqPolyRepField})::Int32)
end

Expand Down
1 change: 1 addition & 0 deletions src/flint/gfp_fmpz_poly.jl
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,7 @@ end
################################################################################

function is_irreducible(x::FpPolyRingElem)
is_constant(x) && return false
return Bool(@ccall libflint.fmpz_mod_poly_is_irreducible(x::Ref{FpPolyRingElem}, x.parent.base_ring.ninv::Ref{fmpz_mod_ctx_struct})::Cint)
end

Expand Down
1 change: 1 addition & 0 deletions src/flint/gfp_poly.jl
Original file line number Diff line number Diff line change
Expand Up @@ -302,6 +302,7 @@ end
################################################################################

function is_irreducible(x::fpPolyRingElem)
is_constant(x) && return false
return Bool(@ccall libflint.nmod_poly_is_irreducible(x::Ref{fpPolyRingElem})::Int32)
end

Expand Down
1 change: 1 addition & 0 deletions src/flint/nmod_poly.jl
Original file line number Diff line number Diff line change
Expand Up @@ -641,6 +641,7 @@ end

function is_irreducible(x::zzModPolyRingElem)
!is_prime(modulus(x)) && error("Modulus not prime in is_irreducible")
is_constant(x) && return false
return Bool(@ccall libflint.nmod_poly_is_irreducible(x::Ref{zzModPolyRingElem})::Int32)
end

Expand Down
3 changes: 3 additions & 0 deletions test/flint/fmpz_mod_poly-test.jl
Original file line number Diff line number Diff line change
Expand Up @@ -498,6 +498,9 @@ end
f = x^2 + 2x + 1

@test is_irreducible(f) == false

@test !is_irreducible(x^0)
@test !is_irreducible(0*x^0)
end

@testset "ZZModPolyRingElem.is_squarefree" begin
Expand Down
3 changes: 3 additions & 0 deletions test/flint/fq_default_poly-test.jl
Original file line number Diff line number Diff line change
Expand Up @@ -490,6 +490,9 @@ end
@test is_irreducible(x)

@test is_irreducible(x^16+2*x^9+x^8+x^2+x+1)

@test !is_irreducible(x^0)
@test !is_irreducible(0*x^0)
end

@testset "FqPolyRingElem.is_squarefree" begin
Expand Down
3 changes: 3 additions & 0 deletions test/flint/fq_nmod_poly-test.jl
Original file line number Diff line number Diff line change
Expand Up @@ -501,6 +501,9 @@ end
@test is_irreducible(x)

@test is_irreducible(x^16+2*x^9+x^8+x^2+x+1)

@test !is_irreducible(x^0)
@test !is_irreducible(0*x^0)
Copy link
Member

Choose a reason for hiding this comment

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

I think it would be better to add this kind of tests to the conformance test suits for polynomial rings instead. Of course we can also test it here first, no big harm (though I think at some point we should get somebody to go through the Nemo test files and weed out tests that are completely covered by the generic conformance tests)

Copy link
Member Author

Choose a reason for hiding this comment

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

Sure, it can be added it to the conformance tests. But still I have the impression that the conformance tests are nice to have, but they are a bit of a black box and it is not clear to me what they guarantee to test. This here fixes a specific bug of the various Nemo methods, so I don't see why this should not be tested explicitly here.

Copy link
Member

Choose a reason for hiding this comment

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

Yeah, to know what the conformance tests test, you need to look into them. Like so many things in AA/Nemo/Oscar that are unfortunately underdocumented :-(. At least they are relatively small, contained in a single file, and it is easy to look in there and see what is tested.

But I am not opposed to adding the tests here, I just think we should add them to the conformance tests, too. Sadly I forgot to do so when I fixed the bug here for QQMPolyRingElem in December, because then we'd have found & fixed the others fixed here a month earlier :-).

Anyway, I've added such tests now in Nemocas/AbstractAlgebra.jl#1952 (and of course that PR fails for now, until this PR here is merged :-) )

end

@testset "fqPolyRepPolyRingElem.is_squarefree" begin
Expand Down
3 changes: 3 additions & 0 deletions test/flint/fq_poly-test.jl
Original file line number Diff line number Diff line change
Expand Up @@ -502,6 +502,9 @@ end
@test is_irreducible(x)

@test is_irreducible(x^16+2*x^9+x^8+x^2+x+1)

@test !is_irreducible(x^0)
@test !is_irreducible(0*x^0)
end

@testset "FqPolyRepPolyRingElem.is_squarefree" begin
Expand Down
3 changes: 3 additions & 0 deletions test/flint/gfp_fmpz_poly-test.jl
Original file line number Diff line number Diff line change
Expand Up @@ -497,6 +497,9 @@ end
f = x^2 + 2x + 1

@test is_irreducible(f) == false

@test !is_irreducible(x^0)
@test !is_irreducible(0*x^0)
end

@testset "FpPolyRingElem.is_squarefree" begin
Expand Down
3 changes: 3 additions & 0 deletions test/flint/gfp_poly-test.jl
Original file line number Diff line number Diff line change
Expand Up @@ -564,6 +564,9 @@ end
@test is_irreducible(x)

@test is_irreducible(x^16+2*x^9+x^8+x^2+x+1)

@test !is_irreducible(x^0)
@test !is_irreducible(0*x^0)
end

@testset "fpPolyRingElem.is_squarefree" begin
Expand Down
3 changes: 3 additions & 0 deletions test/flint/nmod_poly-test.jl
Original file line number Diff line number Diff line change
Expand Up @@ -587,6 +587,9 @@ end
@test is_irreducible(x)

@test is_irreducible(x^16+2*x^9+x^8+x^2+x+1)

@test !is_irreducible(x^0)
@test !is_irreducible(0*x^0)
end

@testset "zzModPolyRingElem.is_squarefree" begin
Expand Down
Loading