Skip to content

Commit 227989a

Browse files
authored
Fix deflection of monomial (#174)
1 parent 7ccc7b8 commit 227989a

File tree

2 files changed

+12
-3
lines changed

2 files changed

+12
-3
lines changed

src/gcd.jl

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -164,11 +164,15 @@ function deflation(p::AbstractPolynomialLike)
164164
return s, d
165165
end
166166

167+
function _zero_to_one_exp(defl::AbstractMonomial)
168+
# TODO Make it faster by calling something like `mapexponents`.
169+
return prod(variables(defl).^map(d -> iszero(d) ? one(d) : d, exponents(defl)))
170+
end
167171
function deflate(p::AbstractPolynomialLike, shift, defl)
168172
if isconstant(shift) && all(d -> isone(d) || iszero(d), exponents(defl))
169173
return p
170174
end
171-
q = MA.operate(deflate, p, shift, defl)
175+
q = MA.operate(deflate, p, shift, _zero_to_one_exp(defl))
172176
return q
173177
end
174178
function inflate(α, shift, defl)
@@ -178,7 +182,7 @@ function inflate(p::AbstractPolynomialLike, shift, defl)
178182
if isconstant(shift) && all(d -> isone(d) || iszero(d), exponents(defl))
179183
return p
180184
end
181-
q = MA.operate(inflate, p, shift, defl)
185+
q = MA.operate(inflate, p, shift, _zero_to_one_exp(defl))
182186
return q
183187
end
184188

@@ -193,7 +197,6 @@ end
193197

194198
# Inspired from to `AbstractAlgebra.deflate`
195199
function MA.operate(op::Union{typeof(deflate), typeof(inflate)}, p::AbstractPolynomialLike, shift, defl)
196-
defl = prod(variables(defl).^map(d -> iszero(d) ? one(d) : d, exponents(defl)))
197200
return polynomial(map(terms(p)) do t
198201
return term(coefficient(t), MA.operate(op, monomial(t), shift, defl))
199202
end)

test/division.jl

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,12 @@ function multivariate_gcd_test(::Type{T}, algo=GeneralizedEuclideanAlgorithm())
143143
sym_test(f3, f1, x, algo)
144144
triple_test(f1, f2, f3, algo)
145145

146+
@testset "Issue #173" begin
147+
p1 = o*x*y + x
148+
p2 = x^2
149+
sym_test(p1, p2, x, algo)
150+
end
151+
146152
p1 = o*z - z
147153
p2 = z
148154
@test gcd(p1, p2, algo) == z

0 commit comments

Comments
 (0)