JuliaAlgebra / DynamicPolynomials.jl

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

gcd of polynomials with Complex coefficient (should it fail?) #91

Open shashi opened 3 years ago

shashi commented 3 years ago
julia> using DynamicPolynomials

julia> @polyvar a b
(a, b)

julia> julia> gcd(im*a, a)
ERROR: MethodError: no method matching gcd(::Complex{Bool}, ::Complex{Bool})
Closest candidates are:
  gcd(::AbstractPolynomialLike, ::Any) at /home/shashi/.julia/dev/MultivariatePolynomials/src/gcd.jl:50
  gcd(::AbstractPolynomialLike, ::Any, ::MultivariatePolynomials.AbstractUnivariateGCDAlgorithm) at /home/shashi/.julia/dev/MultivariatePolynomials/src/gcd.jl:50
  gcd(::Any, ::AbstractPolynomialLike) at /home/shashi/.julia/dev/MultivariatePolynomials/src/gcd.jl:49
  ...
Stacktrace:
  [1] promote_operation_fallback(op::typeof(gcd), #unused#::Type{Complex{Bool}}, #unused#::Type{Complex{Bool}})
    @ MutableArithmetics ~/.julia/packages/MutableArithmetics/8xkW3/src/interface.jl:20
  [2] promote_operation(::Function, ::Type, ::Type)
    @ MutableArithmetics ~/.julia/packages/MutableArithmetics/8xkW3/src/interface.jl:58

It would make generic downstream code so much easier to write even if this returned 1...

shashi commented 3 years ago

In general, what is a good way to call GCD between two Polynomials only when it's going to work?