Canonical way to find the type of a polynomial?
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.
Yes this one does exactly that https://juliaalgebra.github.io/MultivariatePolynomials.jl/stable/types/#MultivariatePolynomials.polynomial_type
I meant also for standard types like Float64 and something accessible in packages not dependent on this…
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.