JuliaMath / Polynomials.jl

Polynomial manipulations in Julia
http://juliamath.github.io/Polynomials.jl/
Other
300 stars 74 forks source link

Polynomial/Polynomial = Rational or? #557

Closed andreasvarga closed 5 months ago

andreasvarga commented 5 months ago

I expected to be able to compute the ratio of two polynomials and get a rational function. So,

julia> using Polynomials

julia> z = Polynomial([0,1],:z)
Polynomial(z)

julia> z/z
ERROR: MethodError: no method matching /(::Int64, ::Polynomial{Int64, :z})

Closest candidates are:
  /(::Union{Int128, Int16, Int32, Int64, Int8, UInt128, UInt16, UInt32, UInt64, UInt8}, ::Union{Int128, Int16, Int32, Int64, Int8, UInt128, UInt16, UInt32, UInt64, UInt8})
   @ Base int.jl:97
  /(::Union{Integer, Complex{<:Union{Integer, Rational}}}, ::Rational)
   @ Base rational.jl:361
  /(::R, ::S) where {R<:Real, S<:Complex}
   @ Base complex.jl:348
  ...

Stacktrace:
 [1] scalar_div(p::Polynomial{Int64, :z}, c::Polynomial{Int64, :z})
   @ Polynomials C:\Users\Andreas\.julia\packages\Polynomials\5ZhzG\src\common.jl:1035
 [2] /(p::Polynomial{Int64, :z}, c::Polynomial{Int64, :z})
   @ Polynomials C:\Users\Andreas\.julia\packages\Polynomials\5ZhzG\src\common.jl:1111
 [3] top-level scope
   @ REPL[3]:1

Such a function would be, in my opinion, very useful.

For my purposes, I defined

function Base.:/(p::AbstractPolynomial,q::AbstractPolynomial)
    RationalFunction(p,q)
end

but Aqua complains of type piracy. So, it would be preferable to have this function available in Polynomials.

andreasvarga commented 5 months ago

Ignore please my request. I can also manage with z//z, so it's OK.