Skip to content

Commit

Permalink
Fix some more issue reported by JET (#1762)
Browse files Browse the repository at this point in the history
  • Loading branch information
lgoettgens authored May 29, 2024
1 parent b04719f commit d319b55
Show file tree
Hide file tree
Showing 11 changed files with 46 additions and 33 deletions.
2 changes: 1 addition & 1 deletion benchmarks/det_field.jl
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
function benchmark_nf_det()
print("benchmark_nf_det ... ")
QQx, x = polynomial_ring(QQ, "x")
K, a = AbsSimpleNumField(x^3 + 3*x + 1, "a")
K, a = number_field(x^3 + 3*x + 1, "a")
M = matrix_space(K, 80, 80)()

for i in 1:80
Expand Down
4 changes: 2 additions & 2 deletions src/HeckeMiscPoly.jl
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@ function roots(K::FqPolyRepField, f::FpPolyRingElem)
return roots(ff)
end

function is_power(a::Union{fpField, FpFieldElem, fqPolyRepFieldElem,FqPolyRepFieldElem,FqFieldElem}, m::Int)
function is_power(a::Union{fpFieldElem, FpFieldElem, fqPolyRepFieldElem, FqPolyRepFieldElem, FqFieldElem}, m::Int)
if iszero(a)
return true, a
end
Expand All @@ -240,7 +240,7 @@ function is_power(a::Union{fpField, FpFieldElem, fqPolyRepFieldElem,FqPolyRepFie
end
end

function roots(f::T) where {T<:Union{fqPolyRepPolyRingElem,FqPolyRepPolyRingElem}} # should be in Nemo and
function roots(f::Union{fqPolyRepPolyRingElem,FqPolyRepPolyRingElem}) # should be in Nemo and
# made available for all finite fields I guess.
q = size(base_ring(f))
x = gen(parent(f))
Expand Down
4 changes: 2 additions & 2 deletions src/HeckeMoreStuff.jl
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ end


function norm(v::ArbMatrix)
return sqrt(sum([a^2 for a in v]))
return sqrt(sum(a^2 for a in v; init=zero(base_ring(v))))
end

function real(tau::AcbMatrix)
Expand Down Expand Up @@ -105,7 +105,7 @@ end
Return the minimum valuation of the entries of `G`.
"""
function valuation(G::QQMatrix, p)
return minimum([x == 0 ? inf : valuation(x, p) for x in G])
return minimum(x == 0 ? inf : valuation(x, p) for x in G)
end

function roots(f::ZZModPolyRingElem, p::ZZRingElem, e::Int)
Expand Down
4 changes: 2 additions & 2 deletions src/antic/nf_elem.jl
Original file line number Diff line number Diff line change
Expand Up @@ -836,14 +836,14 @@ sub!(c::AbsSimpleNumFieldElem, a::AbsSimpleNumFieldElem, b::Integer) = sub!(c, a
function sub!(c::AbsSimpleNumFieldElem, a::QQFieldElem, b::AbsSimpleNumFieldElem)
ccall((:nf_elem_fmpq_sub, libflint), Nothing,
(Ref{AbsSimpleNumFieldElem}, Ref{QQFieldElem}, Ref{AbsSimpleNumFieldElem}, Ref{AbsSimpleNumField}),
c, a, b, a.parent)
c, a, b, parent(b))
return c
end

function sub!(c::AbsSimpleNumFieldElem, a::ZZRingElem, b::AbsSimpleNumFieldElem)
ccall((:nf_elem_fmpz_sub, libflint), Nothing,
(Ref{AbsSimpleNumFieldElem}, Ref{ZZRingElem}, Ref{AbsSimpleNumFieldElem}, Ref{AbsSimpleNumField}),
c, a, b, a.parent)
c, a, b, parent(b))
return c
end

Expand Down
2 changes: 1 addition & 1 deletion src/calcium/qqbar.jl
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ function native_string(x::QQBarFieldElem)
number = unsafe_string(cstr)
ccall((:flint_free, libflint), Nothing, (Ptr{UInt8},), cstr)

number = number[1:first(findfirst(" (", number))-1]
number = number[1:first(findfirst(" (", number)::UnitRange)-1]
number = replace(number, "I" => "im")

R, Rx = polynomial_ring(ZZ, "x")
Expand Down
2 changes: 1 addition & 1 deletion src/flint/fmpz_laurent_series.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1149,7 +1149,7 @@ function add!(c::ZZLaurentSeriesRingElem, a::ZZLaurentSeriesRingElem, b::ZZLaure
j += 1
pa += sa
elseif pi == pb && pi < minb
setcoeff(c, i, polcoeff(b, k))
setcoeff!(c, i, polcoeff(b, k))
k += 1
pb += sb
else
Expand Down
2 changes: 1 addition & 1 deletion src/flint/fmpz_mod_poly.jl
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,7 @@ end

+(x::ZZModPolyRingElem, y::Integer) = x + ZZRingElem(y)

+(x::Integer, y::ZZModPolyRingElem) = ZZRingElem(y) + x
+(x::Integer, y::ZZModPolyRingElem) = ZZRingElem(x) + y

function +(x::ZZModPolyRingElem, y::ZZModRingElem)
(base_ring(x) != parent(y)) && error("Elements must have same parent")
Expand Down
2 changes: 1 addition & 1 deletion src/flint/fq.jl
Original file line number Diff line number Diff line change
Expand Up @@ -634,7 +634,7 @@ function minpoly(Rx::FpPolyRing, a::FqPolyRepFieldElem)
fa = frobenius(fa)
end
St = polynomial_ring(parent(a), cached=false)[1]
f = prod([gen(St) - x for x = c])
f = prod(gen(St) - x for x = c; init=one(St))
g = Rx()
for i = 0:degree(f)
setcoeff!(g, i, coeff(coeff(f, i), 0))
Expand Down
2 changes: 1 addition & 1 deletion src/flint/fq_nmod_mat.jl
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

dense_matrix_type(::Type{fqPolyRepFieldElem}) = fqPolyRepMatrix

function check_parent(x::fqPolyRepMatrix, y::fqPolyRepMatrix)
function check_parent(x::fqPolyRepMatrix, y::fqPolyRepMatrix, throw::Bool = true)
fl = base_ring(x) != base_ring(y)
fl && throw && error("Residue rings must be equal")
fl && return false
Expand Down
19 changes: 19 additions & 0 deletions test/antic/nf_elem-test.jl
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,25 @@ end
end
end

@testset "AbsSimpleNumFieldElem.mutable_adhoc_binary" begin
R, x = polynomial_ring(QQ, "x")
K, a = number_field(x^3 + 3x + 1, "a")

d = 3a^2 - a + 1
cache1 = zero(K)
cache2 = zero(K)

@test add!(cache1, d, 3) == add!(cache2, 3, d)
@test add!(cache1, d, ZZRingElem(3)) == add!(cache2, ZZRingElem(3), d)
@test add!(cache1, d, QQFieldElem(2, 3)) == add!(cache2, QQFieldElem(2, 3), d)
@test sub!(cache1, d, 3) == -sub!(cache2, 3, d)
@test sub!(cache1, d, ZZRingElem(3)) == -sub!(cache2, ZZRingElem(3), d)
@test sub!(cache1, d, QQFieldElem(2, 3)) == -sub!(cache2, QQFieldElem(2, 3), d)
@test mul!(cache1, d, 3) == mul!(cache2, 3, d)
@test mul!(cache1, d, ZZRingElem(3)) == mul!(cache2, ZZRingElem(3), d)
@test mul!(cache1, d, QQFieldElem(2, 3)) == mul!(cache2, QQFieldElem(2, 3), d)
end

@testset "AbsSimpleNumFieldElem.powering" begin
R, x = polynomial_ring(QQ, "x")
K, a = number_field(x^3 + 3x + 1, "a")
Expand Down
36 changes: 15 additions & 21 deletions test/flint/fmpz_mod_poly-test.jl
Original file line number Diff line number Diff line change
Expand Up @@ -179,41 +179,35 @@ end
f = x^2 + 2x + 1
g = x^3 + 3x + 2

@test f*12 == 12*x^2+24*x+12
@test f * 12 == 12*x^2+24*x+12
@test f * Int32(12) == 12*x^2+24*x+12
@test f * ZZRingElem(12) == 12*x^2+24*x+12
@test f * R(12) == 12*x^2+24*x+12

@test 7*g == 7*x^3+21*x+14

@test ZZRingElem(3)*g == 3*x^3+9*x+6

@test f*ZZRingElem(2) == 2*x^2+4*x+2
@test 7 * g == 7*x^3+21*x+14
@test Int32(7) * g == 7*x^3+21*x+14
@test ZZRingElem(7) * g == 7*x^3+21*x+14
@test R(7) * g == 7*x^3+21*x+14

@test f + 12 == x^2+2*x+13

@test f + Int32(12) == x^2+2*x+13
@test f + ZZRingElem(12) == x^2+2*x+13
@test f + R(12) == x^2+2*x+13

@test f - 12 == x^2+2*x+123456789012345678938

@test f - Int32(12) == x^2+2*x+123456789012345678938
@test f - ZZRingElem(12) == x^2+2*x+123456789012345678938
@test f - R(12) == x^2+2*x+123456789012345678938

@test 12 + g == x^3+3*x+14

@test Int32(12) + g == x^3+3*x+14
@test ZZRingElem(12) + g == x^3+3*x+14
@test R(12) + g == x^3+3*x+14

@test 12 - g == 123456789012345678948*x^3+123456789012345678946*x+10

@test Int32(12) - g == 123456789012345678948*x^3+123456789012345678946*x+10
@test ZZRingElem(12) - g == 123456789012345678948*x^3+123456789012345678946*x+10

@test f + R(12) == x^2+2*x+13

@test R(12) + g == x^3+3*x+14

@test f - R(12) == x^2+2*x+123456789012345678938

@test R(12) - g == 123456789012345678948*x^3+123456789012345678946*x+10

@test R(7)*g == 7*x^3+21*x+14

@test f*R(12) == 12*x^2+24*x+12
end

@testset "ZZModPolyRingElem.comparison" begin
Expand Down

0 comments on commit d319b55

Please sign in to comment.