From aed9edf97041eb9e81a13d8da7ba4ecac3021a30 Mon Sep 17 00:00:00 2001 From: Max Horn Date: Wed, 10 Dec 2025 23:26:49 +0100 Subject: [PATCH] Fix is_power for e.g. ZZPolyRing Without this, we get in Nemo: julia> ZZx, x = ZZ[:x]; is_power(2^2 * x^2, 2) (true, 4*x) With it, the correct result is produced: julia> ZZx, x = ZZ[:x]; is_power(2^2 * x^2, 2) (true, 2*x) --- src/generic/Misc/Poly.jl | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/generic/Misc/Poly.jl b/src/generic/Misc/Poly.jl index 5d6ae4f203..a8c4806045 100644 --- a/src/generic/Misc/Poly.jl +++ b/src/generic/Misc/Poly.jl @@ -9,10 +9,10 @@ function is_power(a::PolyRingElem, n::Int) # probably a equal-degree-factorisation would be good + some more gcd's # implement some Newton-type algo? degree(a) % n == 0 || return false, a - fl, x = is_power(leading_coefficient(a), n) - fl || return false, a f = factor(a) all(i % n == 0 for (_, i) in f) || return false, a + fl, x = is_power(constant_coefficient(f.unit), n) + fl || return false, a return true, x*prod(p^div(k, n) for (p, k) = f) end