Reference

Contents

Index

ExpressionTreeForge.Complete_expr_treeType
Complete_expr_tree{T} <: AbstractTree

Implementation of an expression tree. Complete_expr_tree is the same than Type_expr_tree with the additions in each node of a Bounds and Convexity_wrapper. A Complete_expr_tree has fields:

  • field::Complete_node{T} representing an operator, a constant or a variable alongide its bounds and its convexity status;
  • children::Vector{Complete_expr_tree{T}} a vector of children, each of them being a Complete_expr_tree{T}.
ExpressionTreeForge.Type_calculus_treeType
Type_calculus_tree

Represent the different types that a expression can be :

  • constant
  • linear
  • quadratic
  • cubic
  • more which means non-linear, non-quadratic and non-cubic.
ExpressionTreeForge.Type_expr_treeType
Type_expr_tree{T} <: AbstractTree

Basic implementation of an expression tree. Every expression tree supported must be able to return Type_expr_tree. A Type_expr_tree has fields:

  • field::Abstract_expr_node representing an operator, a constant or a variable;
  • children::Vector{Type_expr_tree{T}} a vector of children, each of them being a Type_expr_tree{T}.
ExpressionTreeForge.Type_nodeType
Type_node{T} <: AbstractTree

Basic implementation of a tree. A Type_node has fields:

  • field gathering the informations about the current node;
  • children a vector of children, each of them being a Type_node.
ExpressionTreeForge.cast_type_of_constantMethod
cast_type_of_constant(expr_tree, type::DataType)

Cast to type the constants of expr_tree. expr_tree may be an Expr, a Type_expr_tree or a Complete_expr_tree.

ExpressionTreeForge.complete_treeMethod
complete_tree = complete_tree(expression_tree::Type_expr_tree)

Create a complete_tree::Complete_expr_tree from expression_tree.

ExpressionTreeForge.concave_typeMethod
concave = concave_type()

Return the value of concave from the enumerative type M_implementation_convexity_type.Convexity_type.

ExpressionTreeForge.constant_typeMethod
constant = constant_type()

Return the value of constant from the enumerative type M_implementation_convexity_type.Convexity_type.

ExpressionTreeForge.convex_typeMethod
convex = convex_type()

Return the value of convex from the enumerative type M_implementation_convexity_type.Convexity_type.

ExpressionTreeForge.create_convex_treeMethod
convex_tree = create_convex_tree(tree::Type_expr_tree)

Return a similar expression tree to tree, where each node has an undefined convexity status.

ExpressionTreeForge.evaluate_expr_treeMethod
evaluate_expr_tree(expr_tree::Type_expr_tree, x::AbstractVector)
evaluate_expr_tree(expr_tree::Complete_expr_tree, x::AbstractVector)

Evaluate the expr_tree given the vector x.

Example:

julia> evaluate_expr_tree(:(x[1] + x[2]), ones(2))
2.
ExpressionTreeForge.evaluate_expr_tree_multiple_pointsMethod
evaluate_expr_tree_multiple_points(expression_tree::Any, x::AbstractVector{AbstractVector}})
evaluate_expr_tree_multiple_points(expression_tree::Any)

Evaluate the expression_tree with several points, represented as x.

ExpressionTreeForge.extract_element_functionsMethod
separated_terms = extract_element_functions(expr_tree)

Return the element functions of expr_tree as a vector of its subexpression. expr_tree may be an Expr, a Type_expr_tree or a Complete_expr_tree.

Example:

julia> extract_element_functions(:(x[1] + x[2] + x[3]*x[4] ) )
3-element Vector{Expr}:
 :(x[1])
 :(x[2])
 :(x[3] * x[4])
ExpressionTreeForge.get_UiMethod
Ui = get_Ui(indices::Vector{Int}, n::Int)

Create a sparse matrix Ui from indices computed by get_elemental_variables. Every index i (of indices) form a line of Ui corresponding to i-th Euclidian vector.

ExpressionTreeForge.get_boundsMethod
(inf_bound, sup_bound) = get_bounds(bound_tree::Bound_tree)

Retrieve the bounds of the root of bound_tree, the bounds of expression tree.

ExpressionTreeForge.get_convexity_statusMethod
convexity_status = get_convexity_status(convexity_tree::M_convexity_detection.Convexity_tree)
convexity_status = get_convexity_status(complete_tree::Complete_expr_tree)

Return the convexity status of either convexity_tree or complete_tree. The status can be:

  • constant
  • linear
  • convex
  • concave
  • unknown
ExpressionTreeForge.get_elemental_variablesMethod
indices = get_elemental_variables(expr_tree)

Return the indices of the variable appearing in expr_tree. This function is used to find the elemental variables from the expression tree of an element function. expr_tree may be an Expr, a Type_expr_tree or a Complete_expr_tree.

Example:

julia> get_elemental_variables(:(x[1] + x[3]) )
[1, 3]
julia> get_elemental_variables(:(x[1]^2 + x[6] + x[2]) )
[1, 6, 2]
ExpressionTreeForge.get_expression_treeMethod
expr = get_expression_tree(adnlp::MathOptNLPModel)
expr = get_expression_tree(adnlp::ADNLPModel)
expr = get_expression_tree(model::JuMP.Model)

Return the objective function as a Type_expr_tree for a: MathOptNLPModel, ADNLPModelJuMP.Model`.

ExpressionTreeForge.get_function_of_evaluationMethod
eval_expression_tree = get_function_of_evaluation(expression_tree::Type_expr_tree)

Return and evaluation function of expression_tree with better performance than the actual evaluate_expr_tree.

ExpressionTreeForge.get_type_treeMethod
type = get_type_tree(expr_tree)

Return the type of expr_tree. It can either be: constant, linear, quadratic, cubic or more. expr_tree may be an Expr, a Type_expr_tree or a Complete_expr_tree.

Example:

julia> get_type_tree(:(5+4)) == constant
true
julia> get_type_tree(:(x[1])) == linear
true
julia> get_type_tree(:(x[1]* x[2])) == quadratic
true
ExpressionTreeForge.gradient_forwardMethod
gradient = gradient_forward(expr_tree, x)

Evaluate the gradient of expr_tree at the point x with a forward automatic differentiation method.

Example:

julia> gradient_forward(:(x[1] + x[2]), rand(2))
[1.0 1.0]
ExpressionTreeForge.gradient_reverseMethod
gradient = gradient_reverse(expr_tree, x)

Evaluate the gradient of expr_tree at the point x with a reverse automatic differentiation method.

Example:

julia> gradient_reverse(:(x[1] + x[2]), rand(2))
[1.0 1.0]
ExpressionTreeForge.hessianMethod
hess = hessian(expr_tree, x)

Evaluate the Hessian of expr_tree at the point x with forward automatic differentiation.

Example:

julia> hessian(:(x[1]^2 + x[2]), rand(2))
[2.0 0.0; 0.0 0.0]
ExpressionTreeForge.is_concaveMethod
bool = is_concave(status::Convexity_type)
bool = is_concave(convexity::Convexity_wrapper)

Check if convexity_status is concave.

ExpressionTreeForge.is_constantMethod
bool = is_constant(status::Convexity_type)
bool = is_constant(convexity::Convexity_wrapper)

Check if convexity_status is constant.

ExpressionTreeForge.is_constantMethod
bool = is_constant(type::Type_calculus_tree)

Check if type have the value constant from the enumerative type Type_calculus_tree.

ExpressionTreeForge.is_convexMethod
bool = is_convex(status::Convexity_type)
bool = is_convex(convexity::Convexity_wrapper)

Check if convexity_status is convex.

ExpressionTreeForge.is_cubicMethod
bool = is_cubic(type::Type_calculus_tree)

Check if type have the value cubic from the enumerative type Type_calculus_tree.

ExpressionTreeForge.is_linearMethod
bool = is_linear(status::Convexity_type)
bool = is_linear(convexity::Convexity_wrapper)

Check if convexity_status is linear.

ExpressionTreeForge.is_linearMethod
bool = is_linear(type::Type_calculus_tree)

Check if type have the value linear from the enumerative type Type_calculus_tree.

ExpressionTreeForge.is_moreMethod
bool = is_more(type::Type_calculus_tree)

Check if type have the value more from the enumerative type Type_calculus_tree.

ExpressionTreeForge.is_not_treatedMethod
bool = is_not_treated(status::Convexity_type)
bool = is_not_treated(convexity::Convexity_wrapper)

Check if convexity_status is not_treated.

ExpressionTreeForge.is_quadraticMethod
bool = is_quadratic(type::Type_calculus_tree)

Check if type have the value quadratic from the enumerative type Type_calculus_tree.

ExpressionTreeForge.is_treatedMethod
bool = is_treated(status::Convexity_type)
bool = is_treated(convexity::Convexity_wrapper)

Check if convexity_status is different of not_treated.

ExpressionTreeForge.is_unknownMethod
bool = is_unknown(status::Convexity_type)
bool = is_unknown(convexity::Convexity_wrapper)

Check if convexity_status is unknown.

ExpressionTreeForge.linear_typeMethod
linear = linear_type()

Return the value of linear from the enumerative type M_implementation_convexity_type.Convexity_type.

ExpressionTreeForge.non_linear_JuMP_model_evaluatorMethod
evaluator = non_linear_JuMP_model_evaluator(expr_tree; variables::Vector{Int})

Return a MathOptInterface.Nonlinear.Model and its initialized evaluator for any expr_tree supported. variables informs the indices of the variables appearing in expr_tree. If variables is not provided, it is determined automatically through sort!(get_elemental_variables(expr_tree)). Warning: variables must be sorted! Example:

expr_tree = :(x[1]^2 + x[3]^3)
variables = [1,3]
evaluator = non_linear_JuMP_model_evaluator(expr_tree; variables)

Afterward, you may evaluate the function and the gradient from expr_tree with:

x = rand(2)
MOI.eval_objective(evaluator, x)
grad = similar(x)
MOI.eval_objective_gradient(evaluator, grad, x)

Warning: The size of x depends on the number of variables of expr_tree and not from the highest variable's index.

ExpressionTreeForge.normalize_indices!Method
normalize_indices!(expr_tree, vector_indices::Vector{Int})

Change the indices of the variables of expr_tree given the order given by vector_indices. It it paired with get_elemental_variables to define the elemental element functions expression tree. expr_tree may be an Expr, a Type_expr_tree or a Complete_expr_tree.

Example:

julia> normalize_indices!(:(x[4] + x[5]), [4,5])
:(x[1] + x[2])
ExpressionTreeForge.set_bounds!Method
set_bounds!(tree::Type_expr_tree, bound_tree::Bound_tree)
set_bounds!(complete_tree::Complete_expr_tree)

Set the bounds of bound_tree by walking tree and propagate the computation from the leaves to the root. A Complete_expr_tree contains a precompiled bound_tree, and then can be use alone.

ExpressionTreeForge.set_convexity!Method
set_convexity!(tree::Type_expr_tree, convexity_tree::Convexity_tree, bound_tree::Bound_tree)
set_convexity!(complete_tree::Complete_expr_tree)

Deduce from elementary rules the convexity status of tree nodes or complete_tree nodes. complete_tree integrate a bounds tree and can run alone the convexity detection whereas tree require the bound_tree (see create_bounds_tree) and convexity_tree (see create_convex_tree).

ExpressionTreeForge.sparse_jacobian_JuMP_modelMethod
evaluator = sparse_jacobian_JuMP_model(expr_trees)

Return the evaluator of a MathOptInterface.Nonlinear.Model defined by expr_tree, as long as it is supported. The evaluator considers the objective function as the sum of expr_trees and a constraint for each expr_tree contained in expr_trees. If the expression trees in expr_trees depend on a subset of variables, the constraint Jacobian will be sparse.

ExpressionTreeForge.transform_to_ExprMethod
expr = transform_to_Expr(expr_tree)

Transform expr_tree into an Expr. expr_tree may be a Type_expr_tree or a Complete_expr_tree. Warning: This function return an Expr with variables as MathOptInterface.VariableIndex. In order to get an standard Expr use transform_to_Expr_julia.

ExpressionTreeForge.unknown_typeMethod
unknown = unknown_type()

Return the value of unknown from the enumerative type M_implementation_convexity_type.Convexity_type.

ExpressionTreeForge.M_abstract_expr_tree.create_ExprMethod
expr = create_expr_tree(tree)

Create an Expr from tree. Several types of tree are supported. For now, it supports Expr and ModelingToolkit.Operation, as well as the internal expression trees defined. The variables of the Expr use MathOptInterface variables.

ExpressionTreeForge.M_abstract_expr_tree.create_Expr2Method
expr = create_expr_tree(tree)

Create a julia Expr from tree. Several types of tree are supported. For now, it supports Expr and ModelingToolkit.Operation, as well as the internal expression trees defined.

ExpressionTreeForge.M_abstract_expr_tree.create_Expr_JuMPMethod
expr = create_expr_tree(tree)

Create an Expr from tree. Several types of tree are supported. For now, it supports Expr and ModelingToolkit.Operation, as well as the internal expression trees defined. The variables of the Expr use MathOptInterface.VariableIndex(i).

ExpressionTreeForge.M_implementation_expr_tree.Type_expr_treeType
Type_expr_tree{T} <: AbstractTree

Basic implementation of an expression tree.Every expression tree supported must be able to returnTypeexprtree. ATypeexprtree` has fields:

  • field::Abstract_expr_node representing an operator, a constant or a variable;
  • children::Vector{Type_expr_tree{T}} a vector of children, each of them being a Type_expr_tree{T}.
ExpressionTreeForge.M_implementation_complete_expr_tree.Complete_expr_treeType
Complete_expr_tree{T} <: AbstractTree

Implementation of an expression tree. Complete_expr_tree is the same than Type_expr_tree with the additions in each node of a Bounds and Convexity_wrapper. A Complete_expr_tree has fields:

  • field::Complete_node{T} representing an operator, a constant or a variable alongide its bounds and its convexity status;
  • children::Vector{Complete_expr_tree{T}} a vector of children, each of them being a Complete_expr_tree{T}.
ExpressionTreeForge.M_implementation_complete_expr_tree.Complete_nodeType
Complete_node{T <: Number}

Gather in a single structure:

  • op::M_abstract_expr_node.Abstract_expr_node an arithmetic operator;
  • bounds::M_abstract_expr_tree.Bounds{T} the bounds of this operator depending its children;
  • convexity_status::M_implementation_convexity_type.Convexity_wrapper the convexity status of this operator depending its children.
ExpressionTreeForge.M_bound_propagations.set_bounds!Method
set_bounds!(tree, bound_tree::Bound_tree)
set_bounds!(complete_tree::Complete_expr_tree)

Set the bounds of bound_tree by walking tree and by propagating the computations from the leaves to the root. A Complete_expr_tree contains a precompiled bound_tree, and then can be use alone.

ExpressionTreeForge.M_convexity_detection.get_convexity_statusMethod

convexitystatus = getconvexitystatus(convexitytree::Mconvexitydetection.Convexitytree) convexitystatus = getconvexitystatus(completetree::Mimplementationcompleteexprtree.Completeexpr_tree)

Return the convexity status of either convexity_tree or complete_tree. The status can be:

  • constant
  • linear
  • strictly convex
  • strictly concave
  • unknown
ExpressionTreeForge.M_convexity_detection.set_convexity!Method
set_convexity!(tree, convexity_tree, bound_tree)
set_convexity!(complete_tree)

Deduce from elementary rules the convexity status of tree nodes or complete_tree nodes. complete_tree integrate a bounds tree and can run alone the convexity detection whereas tree require the bound_tree (see create_bounds_tree) and convexity_tree (see create_convex_tree).

ExpressionTreeForge.M_algo_expr_tree.N_to_NiMethod
dic = N_to_Ni(elemental_var::Vector{Int}; initial_index=0)

Return a dictionnary informing the index changes of an element expression tree. If element_var = [4,5] then dic == Dict([4=>initial_index+1, 5=>initial_index+2]).

ExpressionTreeForge.M_algo_expr_tree.extract_element_functionsMethod
separated_terms = extract_element_functions(expr_tree)

Divide the expression tree as a terms of a sum if possible. It returns a vector where each component is a subexpression tree of expr_tree.

Example:

julia> extract_element_functions(:(x[1] + x[2] + x[3]*x[4] ) )
3-element Vector{Expr}:
 :(x[1])
 :(x[2])
 :(x[3] * x[4])
ExpressionTreeForge.M_algo_expr_tree.get_UiMethod
Ui = get_Ui(indices::Vector{Int}, n::Int)

Create a sparse matrix Ui from indices computed by get_elemental_variables. Every index i (of indices) form a line of Ui corresponding to i-th Euclidian vector.

ExpressionTreeForge.M_algo_expr_tree.get_elemental_variablesMethod
indices = get_elemental_variables(expr_tree)

Return the indices of the variable appearing in expr_tree. This function find the elemental variables from the expression tree of an element function.

Example:

julia> get_elemental_variables(:(x[1] + x[3]) )
[1, 3]
julia> get_elemental_variables(:(x[1]^2 + x[6] + x[2]) )
[1, 6, 2]
ExpressionTreeForge.M_algo_expr_tree.get_type_treeMethod
type = get_type_tree(expr_tree)

Return the type of expr_tree. It can either be: constant, linear, quadratic, cubic or more.

Example:

julia> get_type_tree(:(5+4)) == constant
true
julia> get_type_tree(:(x[1])) == linear
true
julia> get_type_tree(:(x[1]* x[2])) == quadratic
true
ExpressionTreeForge.M_algo_expr_tree.non_linear_JuMP_model_evaluatorMethod
evaluator = non_linear_JuMP_model_evaluator(expr_tree; variables::Vector{Int})

Return the evaluator of a MOI.Nonlinear.Model defined by expr_tree, as long as it is supported. variables informs the indices of the variables appearing in expr_tree. If variables is not provided, it is determined automatically through sort!(get_elemental_variables(expr_tree)). Warning: variables must be sorted! Example:

expr_tree = :(x[1]^2 + x[3]^3)
variables = [1,3]
evaluator = non_linear_JuMP_model_evaluator(expr_tree; variables)

Afterward, you may evaluate the function and the gradient from expr_tree with:

x = rand(2)
MOI.eval_objective(evaluator, x)
grad = similar(x)
MOI.eval_objective_gradient(evaluator, grad, x)

Warning: The size of x depends on the number of variables of expr_tree and not from the highest variable's index.

ExpressionTreeForge.M_algo_expr_tree.normalize_indices!Method
normalize_indices!(expr_tree, vector_indices; initial_index=0)

Change the indices of the variables of expr_tree given the order given by vector_indices. It it paired with get_elemental_variables to define the elemental element functions expression tree.

Example:

julia> normalize_indices!(:(x[4] + x[5]), [4,5]; initial_index::Int)
:(x[1+initial_index] + x[2+initial_index])
ExpressionTreeForge.M_algo_expr_tree.sparse_jacobian_JuMP_modelMethod
evaluator = sparse_jacobian_JuMP_model(expr_trees)

Return the evaluator of a MOI.Nonlinear.Model defined by expr_tree, as long as it is supported. The evaluator considers the objective function as the sum of expr_trees and a constraint for each expr_tree contained in expr_trees. If the expression trees in expr_trees depend on a subset of variables, the constraint Jacobian will be sparse.

ExpressionTreeForge.M_trait_expr_node.get_type_nodeMethod
type = get_type_node(node::Abstract_expr_node, children_types::AbstractVector{Type_expr_basic})

Return the type of node given the type of its children children_types. The types avaible areconstant, linear, quadratic, cubic or more.

ExpressionTreeForge.M_trait_expr_node.node_convexityMethod
bool = _node_is_operator(node::Abstract_expr_node, children_convex_status::AbstractVector{M_implementation_convexity_type.Convexity_type})

Return the convexity status of node given the children_convex_status.

ExpressionTreeForge.M_trait_expr_node.node_to_ExprMethod
bool = node_to_Expr(node::Abstract_expr_node)

Return the information required to build later on a julia Expr. An operator return the operator symbol (ex: + -> :+). A variable return a variable as a MathOptInterface variable. A constant return its value.

ExpressionTreeForge.M_trait_expr_node.node_to_Expr2Method
bool = node_to_Expr2(node::Abstract_expr_node)

Return the information required to build later on a julia Expr. An operator return the operator symbol (ex: + -> :+). A variable return a variable. A constant return its value.

ExpressionTreeForge.M_trait_expr_node.node_to_Expr_JuMPMethod
bool = _node_to_Expr_JuMP(node::Abstract_expr_node)

Return the information required to build later on a julia Expr. An operator return the operator symbol (ex: + -> :+). A variable parametrized with the index i returns a variable as a MathOptInterface.Variable(i). A constant return its value.

ExpressionTreeForge.M_interface_expr_node._get_type_nodeMethod
type = _get_type_node(node::Abstract_expr_node, children_types::AbstractVector{Type_expr_basic})

Return the type of node given the type of its children children_types. The types available are constant, linear, quadratic, cubic or more.

ExpressionTreeForge.M_interface_expr_node._node_to_ExprMethod
[symbols] = _node_to_Expr(node::Abstract_expr_node)

Return the information required to build later on a julia Expr. An operator return the operator symbol (ex: + -> :+). A variable return a variable as a MathOptInterface variable. A constant return its value.

ExpressionTreeForge.M_interface_expr_node._node_to_Expr2Method
[symbols] = _node_to_Expr2(node::Abstract_expr_node)

Return the information required to build later on a julia Expr. An operator return the operator symbol (ex: + -> :+). A variable return a variable. A constant return its value.

ExpressionTreeForge.M_interface_expr_node._node_to_Expr_JuMPMethod
[symbols] = _node_to_Expr2(node::Abstract_expr_node)

Return the information required to build later on a julia Expr. An operator return the operator symbol (ex: + -> :+). A variable return a MathOptInterface.VariableIndex(). A constant return its value.

ExpressionTreeForge.M_trait_tree.is_type_trait_treeMethod
Type_trait_tree = is_type_trait_tree(a::AbstractTree)
Type_trait_tree = is_type_trait_tree(a::Expr)
Type_trait_tree = is_type_trait_tree(a::Number)
Type_not_trait_tree = is_type_trait_tree(a::Any)

Return a Type_trait_tree only for AbstractTree, Expr or Number (a leaf of a tree). In the other cases it returns Type_not_trait_tree.

Base.showMethod
show(tree::AbstractTree; deepth)
show(io::IO, tree::AbstractTree; deepth)

Print tree in the julia console with a suitable form.

ExpressionTreeForge.M_implementation_tree.Type_nodeType
Type_node{T} <: AbstractTree

Basic implementation of a tree. A Type_node has fields:

  • field gathering the informations about the current node;
  • children a vector of children, each of them being a Type_node.
ExpressionTreeForge.M_abstract_tree.create_treeMethod
tree = create_tree(field::T, children::Vector{Type_node{T}}) where {T}
tree = create_tree(field::T, children::Array{Any, 1}) where {T}
tree = create_tree(ex::Expr)

Create a tree of type Type_node from a field for the current node and its children or from an Expr.