JuliaAlgebra / DynamicPolynomials.jl

Multivariate polynomials implementation of commutative and non-commutative variables
Other
60 stars 20 forks source link

Support VT("name") where VT::Type{<:Variable} #137

Closed timholy closed 1 year ago

timholy commented 1 year ago

Rather than creating a variable with Variable(name, V, M), sometimes it's easier to create one with Variable{V,M}(name). This allows one to create a new variable from an old one with typeof(oldvar)(newname).

timholy commented 1 year ago

I just discovered similar_variable!

Since this is the first thing I thought of, perhaps for generic programming it could be added to TypedPolynomials too? In essence, have that constructor call similar_variable.

blegat commented 1 year ago

For TypedPolynomials, the type depends on the name so it would be weird to have Variable{:x}(Val{:y}) return Variable{:y}:

julia> typeof(x)
Variable{:x}

julia> typeof(similar_variable(x, Val{:y}))
Variable{:y}
timholy commented 1 year ago

Yeah, that would definitely be bad. I hadn't played enough with TypedPolynomials to realize what that would look like.