Skip to content

Commit

Permalink
Fix is_squarefree for non-fields
Browse files Browse the repository at this point in the history
  • Loading branch information
thofma committed Jul 21, 2023
1 parent 45d8783 commit e74c88d
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)

Check warning on line 519 in src/HeckeMiscPoly.jl

View check run for this annotation

Codecov / codecov/patch

src/HeckeMiscPoly.jl#L518-L519

Added lines #L518 - L519 were not covered by tests

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

Check warning on line 522 in src/HeckeMiscPoly.jl

View check run for this annotation

Codecov / codecov/patch

src/HeckeMiscPoly.jl#L521-L522

Added lines #L521 - L522 were not covered by tests
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))

Check warning on line 526 in src/HeckeMiscPoly.jl

View check run for this annotation

Codecov / codecov/patch

src/HeckeMiscPoly.jl#L525-L526

Added lines #L525 - L526 were not covered by tests
else
g = f

Check warning on line 528 in src/HeckeMiscPoly.jl

View check run for this annotation

Codecov / codecov/patch

src/HeckeMiscPoly.jl#L528

Added line #L528 was not covered by tests
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)))

Check warning on line 532 in src/HeckeMiscPoly.jl

View check run for this annotation

Codecov / codecov/patch

src/HeckeMiscPoly.jl#L531-L532

Added lines #L531 - L532 were not covered by tests
else
fac = factor_squarefree(g)
return all(e <= 1 for (_, e) in fac)

Check warning on line 535 in src/HeckeMiscPoly.jl

View check run for this annotation

Codecov / codecov/patch

src/HeckeMiscPoly.jl#L534-L535

Added lines #L534 - L535 were not covered by tests
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 e74c88d

Please sign in to comment.