Symbol in type signature?

The Polynomial type from the Polynomials package has a symbol in its type signature that I don’t understand.

julia> typeof(Polynomial([1,2]))
Polynomial{Int64, :x}

julia> typeof(Polynomial([1,2], :s))
Polynomial{Int64, :s}

I am trying to use the Polynomial type inside my composite type, but it seems like I need to define the polynomial symbol ahead of time. Why? I wouldn’t think that changing the polynomial symbol would affect memory allocation for the compiler, so can I get away with leaving it abstract somehow? How and why would you define a type based on symbols instead of concrete types?

These error:

struct MyType
struct MyType{T<:Number}
    polys::Vector{Polynomial{T, Symbol}}

This errors if the symbol changes.

struct MyType{T<:Number}
    polys::Vector{Polynomial{T, :s}}

This works, but I think will be slow since it is an abstract type:

struct MyType
julia> isconcretetype(Vector{Polynomial{Int, :x}})

julia> isconcretetype(Vector{<:Polynomial})
1 Like

The variable name used to be a field of Poly, but it was changed in V2.0.0 by jverzani · Pull Request #310 · JuliaMath/Polynomials.jl · GitHub, which says:

breaking changes, the main one is using the type system to hold the indeterminate rather than use a field to hold the indeterminate. The advantage is this plays better with Julia’s promotion mechanisms so matrices of polynomials requires much less fuss.

The question is, why do you care about the polynomial symbol in your application? Why not just call it x and be done with it? It seems like this mostly matters for multivariate polynomials?


Fair point …
In the function I was going to define next, the independent variable would be called s, but that seemed like a weird thing to hard code into the type container. Probably not worth the trouble though. I’ll just use x.