MultivariatePolynomials.jl
MultivariatePolynomials.jl copied to clipboard
TypedP/DynamicP issue: confused by @polyvar behavior
with DP I get:
julia> @polyvar a b
b
with TP I get:
julia> @polyvar a b
(a, b)
is there a reason why one returns a tuple and one returns the last polyvar created?
it might be helpful for @polyvar to always return a tuple of the ordered polyvars maybe. my understanding is that DP orders by creation order, but TP orders by name. note that with TP I get:
julia> @polyvar d c
(d, c)
i.e. creation order, despite TP actually using name ordering i.e. (c, d):
julia> typeof(d + c)
TypedPolynomials.Polynomial{Int64,TypedPolynomials.Term{Int64,TypedPolynomials.Monomial{(c, d),2}},Array{TypedPolynomials.Term{Int64,TypedPolynomials.Monomial{(c, d),2}},1}}
so it just gets a bit confusing for new users.
this came up just now when I was trying to solve a simple system using SemialgebraicSets. the ordering of the solutions I get back is non-obvious:
julia> using TypedPolynomials
julia> using SemialgebraicSets
julia> @polyvar x t
(x, t)
julia> V = @set x^2 == 1 && x == t^2
Algebraic Set defined by 2 equalities
x^2 - 1.0 == 0
-t^2 + x == 0
julia> for v in V
@show v
end
v = [1.0, 1.0]
v = [-1.0, 1.0]
versus
julia> using DynamicPolynomials
julia> using SemialgebraicSets
julia> @polyvar x t
t
julia> V = @set x^2 == 1 && x == t^2
Algebraic Set defined by 2 equalities
x^2 - 1.0 == 0
-t^2 + x == 0
julia> for v in V
@show v
end
v = [1.0, 1.0]
v = [1.0, -1.0]
i.e. x and t are quietly swapped and nothing along the way in the REPL informed me of what ordering to expect in the V solutions.
maybe it would be helpful if for example the ordering of the polyvars is automatically printed following creation. like how SemialgebraicSets automatically prints relevant information after @set (see above)
of course, we are supposed to read the documentation and just know this and remember it. but because of the parallel naming of these packages and the shared naming of functions like @polyvar and the functions in MP, it feels to a newbie as if you can expect to see similar behavior when you swap in TP for DP and vice versa and that the only thing that should really change is numerical performance and speed etc. of course that's not the case.
it's unfortunate that the names TP, DP, MP, SP etc all end in "Polynomials", because it gives the impression to newbies that they are alternatives. it is kind of like if MathProgBase and JuMP and Gurobi.jl were named "xModels" and "yModels" and "zModels". though I'm very glad this extensive toolkit under JuliaAlgebra is here, as an unsophisticated user, I have struggled to understand the design and purpose of these different packages, and that has hindered my ability to use and to contribute. (polynomial substitution in particular has caused headaches due to unexpected silent failures and what seem to be float overflows, and the point about this at the end of the DP readme didn't fully clarify the situation for me).
We should probably return [x=>1.0, y=>-1.0] instead of just [1.0, -1.0]