Input

The solve and monodromy_solve functions in HomotopyContinuation.jl accept multiple input formats for polynomial systems. These are

  • Arrays of polynomials following the MultivariatePolynomials interface. We export the @polyvar macro from the DynamicPolynomials package to create polynomials with the DynamicPolynomials implementation.
  • Systems constructed with our own symbolic modeling language as implemented in the ModelKit module. We export the @var macro to create variables in this modeling language.
  • Systems (resp. homotopies) following the AbstractSystem (resp. AbstractHomotopy) interface.

The difference between the MultivariatePolynomials and ModelKit input is best shown on an example. Assume we want to solve the polynomial system

\[F(x,y) = \begin{bmatrix} (2x + 3y + 2)^2 (4x - 2y + 3) \\ (y - 4x - 5)^3 - 3x^2 + y^2 \end{bmatrix} = 0\]

Using the @polyvar macro from DynamicPolynomials we can do

@polyvar x y
F = [
  (2x + 3y + 2)^2 * (4x - 2y + 3),
  (y - 4x - 5)^3 - 3x^2 + y^2
]
2-element Array{Polynomial{true,Int64},1}:
 16x³ + 40x²y + 12xy² - 18y³ + 44x² + 68xy + 3y² + 40x + 28y + 12    
 -64x³ + 48x²y - 12xy² + y³ - 243x² + 120xy - 14y² - 300x + 75y - 125

We see that our expression got automatically expanded into a monomial basis. Sometimes this is very useful, but for the fast evaluation of a polynomial system this is not so useful! Here, ModelKit comes into play.

@var x y
F = [
  (2x + 3y + 2)^2 * (4x - 2y + 3),
  (y - 4x - 5)^3 - 3x^2 + y^2
]
2-element Array{HomotopyContinuation.ModelKit.Operation,1}:
 (2x + 3y + 2) ^ 2 * ((4x - 2y) + 3)     
 (((y - 4x) - 5) ^ 3 - 3 * x ^ 2) + y ^ 2

Compared to the polynomial input we see that it doesn't forget the structure of the input.

For the internal computations both formulations will be converted into efficient straight line programs. However, from the polynomial formulation we will not be able to recover the actual formulation of the problem and therefore the generated straight line program will be less efficient than the one created by ModelKit.

However, there are also cases where the polynomial input is preferable. An example is when you only have an expression of your polynomial system in the monomial basis. In this case the polynomial input will generate more efficient code since it is more optimized for this case.

Besides the different macros to generate variables both packages provide a common set of helpful functions for modeling problems:

  • variables(f, parameters = []) to obtain a list of all variables.
  • nvariables(f, parameters = []) to obtain the number of variables.
  • differentiate(f, vars) to compute the gradient with respect to the given variables
  • subs(f, var => expr) to substitute variables with expressions
  • monomials(vars, d; homogenous = false) create all monomials of degree up to d (resp. exactly degree d if homogenous = true)
Variable ordering

While MultivariatePolynomials orders variables in the order of creation, ModelKit orders them alphabetically. Also in ModelKit two variables with the same name are always identical.

ModelKit

HomotopyContinuation.ModelKit.@varMacro
@var(args...)

Declare variables with the given and automatically create the variable bindings.

Examples

julia> @var a b x[1:2] y[1:2,1:3]
(a, b, Variable[x₁, x₂], Variable[y₁₋₁ y₁₋₂ y₁₋₃; y₂₋₁ y₂₋₂ y₂₋₃])

julia> a
a

julia> b
b

julia> x
2-element Array{Variable,1}:
 x₁
 x₂

julia> y
2×3 Array{Variable,2}:
 y₁₋₁  y₁₋₂  y₁₋₃
 y₂₋₁  y₂₋₂  y₂₋₃
HomotopyContinuation.ModelKit.@unique_varMacro
@unique_var(args...)

Declare variables and automatically create the variable bindings to the given names. This will change the names of the variables to ensure uniqueness.

Examples

julia> @unique_var a b
(##a#591, ##b#592)

julia> a
##a#591

julia> b
##b#592
HomotopyContinuation.ModelKit.SystemType
System(exprs, vars, parameters = Variable[])

Create a system from the given exprs. vars are the given variables and determines the variable ordering.

Example

julia> @var x y;
julia> H = System([x^2, y^2], [y, x]);
julia> H([2, 3], 0)
2-element Array{Int64,1}:
 4
 9

It is also possible to declare additional variables.

julia> @var x y t a b;
julia> H = Homotopy([x^2 + a, y^2 + b^2], [x, y], [a, b]);
julia> H([2, 3], [5, 2])
2-element Array{Int64,1}:
 9
 13
HomotopyContinuation.ModelKit.HomotopyType
Homotopy(exprs, vars, t, parameters = Variable[])

Create a homotopy from the given exprs. vars are the given variables and determines the variable ordering, t is the dedicated variable along which is "homotopied".

Example

julia> @var x y t;
julia> H = Homotopy([x + t, y + 2t], [y, x], t);
julia> H([2, 3], 0)
2-element Array{Int64,1}:
 3
 2


julia> H([2, 3], 1)
2-element Array{Int64,1}:
 4
 4

It is also possible to declare additional variables.

julia> @var x y t a b;
julia> H = Homotopy([x^2 + t*a, y^2 + t*b], [x, y], t, [a, b]);
julia> H([2, 3], 1, [5, 2])
2-element Array{Int64,1}:
 9
 11