JuliaAlgebra / DynamicPolynomials.jl

Multivariate polynomials implementation of commutative and non-commutative variables
Other
60 stars 21 forks source link

incorrect gcd #107

Closed sumiya11 closed 2 years ago

sumiya11 commented 2 years ago

Hi, the following seems to be incorrect

using DynamicPolynomials
@polyvar x

f = (7x - 1)*(4x + 3)^2*(x^2 + 5x + 13)^5
g = (4x + 3)*(x^3 - x - 1)^3*(x - 2)^2

gcd(f, g)
1
blegat commented 2 years ago

It seems the Int has overflowed. Closing as a duplicate of https://github.com/JuliaAlgebra/DynamicPolynomials.jl/issues/110

julia> f = (big(7)*x - 1)*(4x + 3)^2*(x^2 + 5x + 13)^5
112x¹³ + 2952x¹² + 39119x¹¹ + 334446x¹⁰ + 2030940x⁹ + 9139695x⁸ + 31019925x⁷ + 79293780x⁶ + 149850240x⁵ + 200266105x⁴ + 173228211x³ + 78055016x² + 8054202x - 3341637

julia> g = (big(4)*x + 3)*(x^3 - x - 1)^3*(x - 2)^2
4x¹² - 13x¹¹ - 8x¹⁰ + 39x⁹ + 39x⁸ - 63x⁷ - 94x⁶ + 22x⁵ + 107x⁴ + 47x³ - 35x² - 40x - 12

julia> gcd(f, g)
4x + 3