From d16100a3dafc1fd140bc1ee6a775c826ea1e57a2 Mon Sep 17 00:00:00 2001 From: Aayush Sabharwal Date: Mon, 18 Aug 2025 19:42:24 +0530 Subject: [PATCH 1/2] feat: support GCD for non-concrete polynomial types --- src/gcd.jl | 8 +++----- test/commutative/gcd.jl | 7 +++++++ 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/src/gcd.jl b/src/gcd.jl index 6688059a..06e170f6 100644 --- a/src/gcd.jl +++ b/src/gcd.jl @@ -306,11 +306,9 @@ function MA.operate( defl, ) return polynomial( - map(terms(p)) do t - return term( - coefficient(t), - MA.operate(op, monomial(t), shift, defl), - ) + coefficients(p), + map(monomials(p)) do m + return MA.operate(op, m, shift, defl) end, ) end diff --git a/test/commutative/gcd.jl b/test/commutative/gcd.jl index c6731309..adcb58c9 100644 --- a/test/commutative/gcd.jl +++ b/test/commutative/gcd.jl @@ -291,4 +291,11 @@ end end end end + @testset "Non-concrete polynomial GCD" begin + Mod.@polyvar p q + p1 = MP.polynomial(p^2 + q^2, Number) + p2 = MP.polynomial(p * q, Number) + g = @inferred gcd(p1, p2) + @test isone(g) + end end From 29e2291275aafcb6b0f8cb2a9e3aa6842f278bc0 Mon Sep 17 00:00:00 2001 From: Aayush Sabharwal Date: Tue, 19 Aug 2025 11:32:50 +0530 Subject: [PATCH 2/2] feat: support complex coefficient GCD --- src/gcd.jl | 7 +++++++ test/commutative/gcd.jl | 8 ++++++++ 2 files changed, 15 insertions(+) diff --git a/src/gcd.jl b/src/gcd.jl index 06e170f6..1d615355 100644 --- a/src/gcd.jl +++ b/src/gcd.jl @@ -79,9 +79,16 @@ end _coefficient_gcd(α, β) = gcd(α, β) _coefficient_gcd(α::AbstractFloat, β) = one(Base.promote_typeof(α, β)) _coefficient_gcd(α, β::AbstractFloat) = one(Base.promote_typeof(α, β)) +_coefficient_gcd(α::Complex, β) = one(Base.promote_typeof(α, β)) +_coefficient_gcd(α, β::Complex) = one(Base.promote_typeof(α, β)) +_coefficient_gcd(α::Complex, β::AbstractFloat) = one(Base.promote_typeof(α, β)) +_coefficient_gcd(α::AbstractFloat, β::Complex) = one(Base.promote_typeof(α, β)) function _coefficient_gcd(α::AbstractFloat, β::AbstractFloat) return one(Base.promote_typeof(α, β)) end +function _coefficient_gcd(α::Complex, β::Complex) + return one(Base.promote_typeof(α, β)) +end function Base.lcm( p::_APL, diff --git a/test/commutative/gcd.jl b/test/commutative/gcd.jl index adcb58c9..0b791639 100644 --- a/test/commutative/gcd.jl +++ b/test/commutative/gcd.jl @@ -298,4 +298,12 @@ end g = @inferred gcd(p1, p2) @test isone(g) end + + @testset "Complex coefficient GCD" begin + Mod.@polyvar p q + p1 = MP.polynomial(p^2 + q^2, ComplexF64) + p2 = MP.polynomial(p * q, ComplexF64) + g = @inferred gcd(p1, p2) + @test isone(g) + end end