Skip to content

Commit

Permalink
Fix is_squarefree for non-fields (#1511)
Browse files Browse the repository at this point in the history
  • Loading branch information
thofma authored Jul 21, 2023
1 parent 45d8783 commit 011e590
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 16 deletions.
37 changes: 21 additions & 16 deletions src/HeckeMiscPoly.jl
Original file line number Diff line number Diff line change
Expand Up @@ -515,23 +515,28 @@ end
#
################################################################################

function is_squarefree(f::PolyElem)
R = coefficient_ring(f)
function is_squarefree(f::PolyElem{<:FieldElement})
R = coefficient_ring(f)

if iszero(f) || degree(f) == 0
return true
end
if iszero(f) || degree(f) == 0
return true
end

if !is_monic(f)
g = divexact(f, leading_coefficient(f))
else
g = f
end
if !is_monic(f)
g = divexact(f, leading_coefficient(f))
else
g = f
end

if characteristic(R) == 0 || R isa FinField
return is_constant(gcd(g, derivative(g)))
else
fac = factor_squarefree(g)
return all(e <= 1 for (_, e) in fac)
end
if characteristic(R) == 0 || R isa FinField
return is_constant(gcd(g, derivative(g)))
else
fac = factor_squarefree(g)
return all(e <= 1 for (_, e) in fac)
end
end

function is_squarefree(f::PolyElem{<:RingElement})
fac = factor_squarefree(f)
return all(e <= 1 for (_, e) in fac)
end
5 changes: 5 additions & 0 deletions test/flint/fmpz_poly-test.jl
Original file line number Diff line number Diff line change
Expand Up @@ -416,6 +416,11 @@ end
g = x^30 + 73*x^28 + 2504*x^27 - 1359*x^26 - 4680*x^25 - 148311*x^24 - 159120*x^23 - 2615547*x^22 - 9732528*x^21 - 2087859*x^20 - 28418280*x^19 - 19101979*x^18 - 80724312*x^17 - 252445155*x^16 - 549998688*x^15 - 1003657917*x^14 - 2740409376*x^13 - 3199593893*x^12 - 2678402184*x^11 - 5168185293*x^10 - 2855108728*x^9 - 984488613*x^8 - 364079376*x^7 + 2870497527*x^6 + 5561735376*x^5 + 6329635407*x^4 + 3459410600*x^3 + 601207031*x^2 + 822759704*x + 294114975
@test length(factor(g)) == 6
@test length(factor(4 * g)) == 7

@test is_squarefree(7*x^2 + 2)
@test is_squarefree(2*x)
@test !is_squarefree(4*x)
@test !is_squarefree(2*x^2)
end

@testset "ZZPolyRingElem.square_root" begin
Expand Down

0 comments on commit 011e590

Please sign in to comment.