Skip to content

Commit

Permalink
add factor for Laurent polynomials (#1149)
Browse files Browse the repository at this point in the history
  • Loading branch information
tthsqe12 authored Apr 22, 2022
1 parent 99daf26 commit 89755d3
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/Generic.jl
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,8 @@ import ..AbstractAlgebra: add!, addeq!, addmul!, base_ring, canonical_unit,
content, data, deflate, deflation, degree, degrees,
degrees_range, denominator, derivative, div,
divexact, divides, divrem, domain, elem_type,
evaluate, exp, exponent_vectors, expressify, factor,
evaluate, exp, exponent_vectors, expressify,
factor, factor_squarefree,
gen, gens, get_field, identity_matrix, inflate,
integral, inv, isconstant, isdomain_type,
isexact_type, isgen, ismonomial, isreduced_form,
Expand Down
22 changes: 22 additions & 0 deletions src/generic/LaurentMPoly.jl
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,28 @@ function divrem(a::LaurentMPolyWrap, b::LaurentMPolyWrap)
error("divrem not implemented for LaurentMPoly")
end

function factor(a::LaurentMPolyWrap)
R = parent(a)
ap, ad = _normalize(a)
f = factor(ap)
d = Dict{typeof(a), Int}()
for (p, e) in f
d[LaurentMPolyWrap(R, p)] = e
end
return Fac(LaurentMPolyWrap(R, unit(f), ad), d)
end

function factor_squarefree(a::LaurentMPolyWrap)
R = parent(a)
ap, ad = _normalize(a)
f = factor_squarefree(ap)
d = Dict{typeof(a), Int}()
for (p, e) in f
d[LaurentMPolyWrap(R, p)] = e
end
return Fac(LaurentMPolyWrap(R, unit(f), ad), d)
end

###############################################################################
#
# Canonicalisation
Expand Down
26 changes: 26 additions & 0 deletions src/generic/LaurentPoly.jl
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,10 @@ function _remove_gen(a::LaurentPolyWrap)
return i, (i == 0 ? a.poly : shift_right(a.poly, i))
end
end
# we need something finite on zero input
if iszero(a.poly)
return (0, a.poly)
end
return remove(a.poly, gen(parent(a.poly)))
end

Expand Down Expand Up @@ -255,6 +259,28 @@ function lcm(p::LaurentPolyWrap{T}, q::LaurentPolyWrap{T}) where T
return LaurentPolyWrap(parent(p), lcm(p.poly, q.poly), 0)
end

function factor(a::LaurentPolyWrap)
R = parent(a)
va, ua = _remove_gen(a)
f = factor(ua)
d = Dict{typeof(a), Int}()
for (p, e) in f
d[LaurentPolyWrap(R, p, 0)] = e
end
return Fac(LaurentPolyWrap(R, unit(f), a.mindeg + va), d)
end

function factor_squarefree(a::LaurentPolyWrap)
R = parent(a)
va, ua = _remove_gen(a)
f = factor_squarefree(ua)
d = Dict{typeof(a), Int}()
for (p, e) in f
d[LaurentPolyWrap(R, p, 0)] = e
end
return Fac(LaurentPolyWrap(R, unit(f), a.mindeg + va), d)
end

###############################################################################
#
# Ad hoc binary operators
Expand Down

0 comments on commit 89755d3

Please sign in to comment.