Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 24 additions & 1 deletion src/elimination.jl
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ function simplify_matrix(M::MatElem{P}) where {P <: MPolyRingElem}
function _simplify_range(coords::Array{Tuple{Int, Int}, 1})
gcd_temp = M[coords[1]...]
for c in coords[2:end]
gcd_temp = gcd(gcd_temp, M[c...])
gcd_temp = elimination_gcd(gcd_temp, M[c...])
end
if gcd_temp != 1
for c in coords
Expand Down Expand Up @@ -166,6 +166,29 @@ function simplify_matrix(M::MatElem{P}) where {P <: MPolyRingElem}
return M, extra_factors
end

elimination_gcd(a, b) = gcd(a, b)

@static if Sys.WORD_SIZE == 32
function elimination_gcd(a::QQMPolyRingElem, b::QQMPolyRingElem)
# FLINT can miss nonmonomial factors in multivariate GCDs on 32-bit builds.
if length(a) > length(b)
a, b = b, a
end
length(a) <= 1 && return gcd(a, b)

common = one(parent(a))
for (factor, multiplicity) in Nemo.factor(a)
for _ in 1:multiplicity
exact, quotient = divides(b, factor)
exact || break
b = quotient
common *= factor
end
end
return divexact(common, leading_coefficient(common))
end
end

# ------------------------------------------------------------------------------

# Definition: for an irreducible polynomial P in n variables, we will call
Expand Down
4 changes: 2 additions & 2 deletions src/util.jl
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ function uncertain_factorization(f::MPolyRingElem{QQFieldElem})
mainvar_coeffs = [coeff(f, [main_var], [i]) for i in 0:d]
gcd_coef = mainvar_coeffs[end]
for i in d:-1:1
gcd_coef = gcd(gcd_coef, mainvar_coeffs[i])
gcd_coef = elimination_gcd(gcd_coef, mainvar_coeffs[i])
end
f = divexact(f, gcd_coef)

Expand All @@ -136,7 +136,7 @@ function uncertain_factorization(f::MPolyRingElem{QQFieldElem})
uni_ring, T = Nemo.polynomial_ring(base_ring(f), "T")
f_uni = sum([evaluate(mainvar_coeffs[i + 1], plugin) * T^i for i in 0:d])
if !isone(gcd(f_uni, derivative(f_uni)))
factor_out = gcd(f, derivative(f, main_var))
factor_out = elimination_gcd(f, derivative(f, main_var))
if degree(factor_out, main_var) != degree(gcd(f_uni, derivative(f_uni)))
continue
end
Expand Down
16 changes: 16 additions & 0 deletions test/bodies/det_minor_expansion.jl
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,20 @@ if GROUP == "All" || GROUP == "Core"
end
end
end

@testset "Common polynomial factor in a determinant row" begin
R, vars = Nemo.polynomial_ring(Nemo.QQ, ["x$i" for i in 1:8])
x, y, z = vars[1:3]
shared = x^2 * y^2 * (x + y)^3
a, b = 6 * y^3, x^3 * (2 * x + 3 * y)
entries = Nemo.matrix(R, [a * shared b * shared])

_, factors = StructuralIdentifiability.simplify_matrix(entries)
@test first(factors) == shared

primitive = a * z + b
monic(p) = divexact(p, leading_coefficient(p))
@test Set(monic.(StructuralIdentifiability.fast_factor(shared * primitive))) ==
Set(monic.([x, y, x + y, primitive]))
end
end
Loading