Skip to content

Commit

Permalink
Add is_prime(char) check to GF(char, k) (#1598)
Browse files Browse the repository at this point in the history
  • Loading branch information
lgoettgens authored Dec 18, 2023
1 parent 209d6b4 commit 7761cc1
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 3 deletions.
12 changes: 9 additions & 3 deletions src/flint/FlintTypes.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2237,7 +2237,9 @@ See [`FqPolyRepField`](@ref) for $p$ being a [`ZZRingElem`](@ref). See [`fqPolyR
overfields :: Dict{Int, Vector{FinFieldMorphism}}
subfields :: Dict{Int, Vector{FinFieldMorphism}}

function fqPolyRepField(c::ZZRingElem, deg::Int, s::Symbol, cached::Bool = true)
function fqPolyRepField(c::ZZRingElem, deg::Int, s::Symbol, cached::Bool = true; check::Bool = true)
check && !is_prime(c) &&
throw(DomainError(c, "the characteristic must be a prime"))
return get_cached!(FqNmodFiniteFieldID, (c, deg, s), cached) do
d = new()
ccall((:fq_nmod_ctx_init, libflint), Nothing,
Expand Down Expand Up @@ -2646,7 +2648,9 @@ if NEW_FLINT
overfields :: Dict{Int, Vector{FinFieldMorphism}}
subfields :: Dict{Int, Vector{FinFieldMorphism}}

function FqPolyRepField(char::ZZRingElem, deg::Int, s::Symbol, cached::Bool = true)
function FqPolyRepField(char::ZZRingElem, deg::Int, s::Symbol, cached::Bool = true; check::Bool = true)
check && !is_probable_prime(char) &&
throw(DomainError(char, "the characteristic must be a prime"))
return get_cached!(FqFiniteFieldID, (char, deg, s), cached) do
d = new()
finalizer(_FqFiniteField_clear_fn, d)
Expand Down Expand Up @@ -2717,7 +2721,9 @@ else
overfields :: Dict{Int, Vector{FinFieldMorphism}}
subfields :: Dict{Int, Vector{FinFieldMorphism}}

function FqPolyRepField(char::ZZRingElem, deg::Int, s::Symbol, cached::Bool = true)
function FqPolyRepField(char::ZZRingElem, deg::Int, s::Symbol, cached::Bool = true; check::Bool = true)
check && !is_probable_prime(char) &&
throw(DomainError(char, "the characteristic must be a prime"))
return get_cached!(FqFiniteFieldID, (char, deg, s), cached) do
d = new()
finalizer(_FqFiniteField_clear_fn, d)
Expand Down
5 changes: 5 additions & 0 deletions test/flint/fq-test.jl
Original file line number Diff line number Diff line change
Expand Up @@ -258,3 +258,8 @@ end
R, x = finite_field(ZZ(19), 3, "x")
@test R([1, 0, 1]) == x^2 + 1
end

@testset "Nemo.jl#1493" begin
@test_throws DomainError GF(ZZ(4), 2)
@test_throws DomainError finite_field(ZZ(6), 2, "x")
end
5 changes: 5 additions & 0 deletions test/flint/fq_nmod-test.jl
Original file line number Diff line number Diff line change
Expand Up @@ -270,3 +270,8 @@ end
R, x = finite_field(19, 3, "x")
@test R([1, 0, 1]) == x^2 + 1
end

@testset "Nemo.jl#1493" begin
@test_throws DomainError GF(4, 2)
@test_throws DomainError finite_field(6, 2, "x")
end

0 comments on commit 7761cc1

Please sign in to comment.