Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Inconsistent behavior of Poly with DynamicPolynomials and TypedPolynomials. #255

Open
hurak opened this issue Aug 16, 2022 · 1 comment
Open

Comments

@hurak
Copy link
Contributor

hurak commented Aug 16, 2022

I am trying to reproduce the example on Lyapunov function search from the documentation. The example uses DynamicPolynomials. Since the degree of the polynomials is fixed here, my understanding was that I can freely switch to TypedPolynomials. But then the example fails. Below is the snippet of code relevant to reproduce the failure. First, with DynamicPolynomials:

julia> using DynamicPolynomials

julia> @polyvar x[1:3]
(PolyVar{true}[x₁, x₂, x₃],)

julia> using SumOfSquares

julia> monosX = x.^2
3-element Vector{Monomial{true}}:
 x₁²
 x₂²
 x₃²

julia> Poly(monosX)
Poly{MonomialBasis{Monomial{true}, Vector{Monomial{true}}}}(MonomialBasis{Monomial{true}, Vector{Monomial{true}}}(Monomial{true}[x₁², x₂², x₃²]))

And now (after restarting the REPL) the same code with TypedPolynomials:

julia> using TypedPolynomials

julia> @polyvar y[1:3]
(y₁, y₂, y₃)

julia> using SumOfSquares

julia> monosY = y.^2
(y₁², y₂², y₃²)

julia> Poly(monosY)
ERROR: MethodError: no method matching Poly(::Tuple{Monomial{(y₁,), 1}, Monomial{(y₂,), 1}, Monomial{(y₃,), 1}})
Closest candidates are:
  Poly(::AbstractVector{<:MultivariatePolynomials.AbstractPolynomialLike}) at ~/.julia/packages/PolyJuMP/pghif/src/variable.jl:36
  Poly(::PB) where PB<:AbstractPolynomialBasis at ~/.julia/packages/PolyJuMP/pghif/src/variable.jl:34
Stacktrace:
 [1] top-level scope
   @ REPL[5]:1

Is this a feature or a bug? I confess I still do not get the difference between the two polynomial types perfectly.

@blegat
Copy link
Member

blegat commented Sep 21, 2022

Sorry for the late reply, I missed the notification. You need to give a vector while here you are giving a tuple.

monosY = [v^2 for v in y]

should fix it. Let's leave this issue open, we could add support for tuple input to ensure consistency.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

2 participants