Search code examples
juliapolynomials

@polyvar not defined, when using MultivariatePolynomials


When trying to compile the code below (Which is from here), I am told " @polyvar is not defined". I am using Julia v.0.6

using MultivariatePolynomials
@polyvar(x[1:2])
p = 2x[1] + 3x[1]x[2]^2 + x[2] + 3
differentiate(p, x[1])
p([1,2], x)

Message: UndefVarError: @polyvar not defined.

Please, what would be wrong?


Solution

  • There may have been recent changes in the package, and now it seems @polyvar is defined in TypedPolynomials package, and MultivariatePolynomials defines a common interface for which TypedPolynomials is an implementation. So,

    # install TypedPolynomials
    Pkg.clone("https://github.com/rdeits/TypedPolynomials.jl")
    
    using MultivariatePolynomials
    using TypedPolynomials
    

    should clear the problem:

    julia> @polyvar(x[1:2])
    (x1, x2)
    julia> p = 2x[1] + 3x[1]x[2]^2 + x[2] + 3
    3x1x2^2 + 2x1 + x2 + 3
    

    And you would like to change the last line to:

    julia> p(x=>[1,2])
    19