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

Canonical way to find the type of a polynomial?

Open dlfivefifty opened this issue 11 months ago • 3 comments

To support DynamicPolynomials.jl in RecurrenceRelationships.jl I had to be careful to use the type of a polynomial (which is different than a variable). A quick-and-dirty fix was this:

https://github.com/JuliaApproximation/RecurrenceRelationships.jl/blob/82125b04d75df222024abaf7a10670fa6a99e9bc/src/RecurrenceRelationships.jl#L5

Though now I'm also support matrices and so this doesn't work.

I'm wondering if there's a canonical function for determining the type of a polynomial given the type of the coefficients and the type of the variable.

dlfivefifty avatar Dec 20 '24 10:12 dlfivefifty

Yes this one does exactly that https://juliaalgebra.github.io/MultivariatePolynomials.jl/stable/types/#MultivariatePolynomials.polynomial_type

blegat avatar Dec 23 '24 08:12 blegat

I meant also for standard types like Float64 and something accessible in packages not dependent on this…

dlfivefifty avatar Dec 29 '24 18:12 dlfivefifty

Good question. I also need to do this frequently, and also for JuMP when you want to obtain the type JuMP.AffExpr from the type JuMP.VariableRef in a generic way, e.g., when preallocating the result of matrix multiplication. This is one of the reason of the creation of MutableArithmetics.promote_operation. You can even directly call MutableArithmetics.promote_sum_mul(V, T) where V is the variable type and T is the number type and you'll get the polynomial type if V is a polynomial variable or you'll get JuMP.AffExpr if V is a JuMP variable.

blegat avatar Dec 30 '24 08:12 blegat