Polynomials.jl icon indicating copy to clipboard operation
Polynomials.jl copied to clipboard

Incorrect dot product fallback

Open juliohm opened this issue 3 years ago • 3 comments

The fallback is producing results that are not mathematically correct:

julia> using Polynomials
julia> using LinearAlgebra
julia> p = Polynomial([0,1])
julia> p ⋅ p
1

juliohm avatar Feb 18 '22 11:02 juliohm

At one time, we had p ⋅ p mean multiplication, now it falls back to LinearAlgebra.dot for arbitrary iterables. It should be that for vector v P(v) ⋅ P(v) == v ⋅ v.

jverzani avatar Feb 18 '22 12:02 jverzani

So you are not implementing the dot product as the integral \int_{-\infty}^{\infty} f(t) * conj(g(t)) dt?

juliohm avatar Feb 18 '22 12:02 juliohm

No, right now we don't have it implemented for the AbstractPolynomial type, so it fallsback to the generic for iterables. In SpecialPolynomials, for orthogonal polynomials, we have something defined like that internally which should be exposed through dot. I'll definitely add that in.

jverzani avatar Feb 18 '22 12:02 jverzani

This should probably get the bug label.

juliohm avatar Apr 02 '24 09:04 juliohm

Is it a bug? Or does it need a special method. Right now the fall back is to the dot method for two iterables which will error for polynomials of different degree. For orthogonal polynomials, we could use the integral over [-1,1], but in general the integral over (-oo, oo) will always yield an infinite answer, so that isn't the best.

So would having

Polynomials.dot(p::AbstractPolynomial, q::AbstractPolynomial) = throw(ArgumentError("..."))

and

SpecialPolynomials.dot(p::AbstractOrthogonalPolynomial, q::AbstractOrthogonalPolynomial) = integrate(p * conj(q), domain(p)...)

suffice?

jverzani avatar Apr 02 '24 15:04 jverzani

The result is incorrect or throws an error. Clearly a bug.

Em ter., 2 de abr. de 2024, 12:27, john verzani @.***> escreveu:

Is it a bug? Or does it need a special method. Right now the fall back is to the dot method for two iterables which will error for polynomials of different degree. For orthogonal polynomials, we could use the integral over [-1,1], but in general the integral over (-oo, oo) will always yield an infinite answer, so that isn't the best.

So would having

Polynomials.dot(p::AbstractPolynomial, q::AbstractPolynomial) = throw(ArgumentError("..."))

and

SpecialPolynomials.dot(p::AbstractOrthogonalPolynomial, q::AbstractOrthogonalPolynomial) = integrate(p * conj(q), domain(p)...)

suffice?

— Reply to this email directly, view it on GitHub https://github.com/JuliaMath/Polynomials.jl/issues/397#issuecomment-2032363796, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAZQW3IBATYDM5KZWWH4QH3Y3LE7PAVCNFSM5OXVHNE2U5DIOJSWCZC7NNSXTN2JONZXKZKDN5WW2ZLOOQ5TEMBTGIZTMMZXHE3A . You are receiving this because you authored the thread.Message ID: @.***>

juliohm avatar Apr 02 '24 15:04 juliohm

closed by #563

jverzani avatar Apr 06 '24 22:04 jverzani