Evaluate a nonlinear expression at a point

I have a model with many nonlinear expressions and I would like to evaluate these to test my model.

For example I have something like this

using JuMP
m = Model()

@variable(m,x)

@NLexpression(m,T,x^2)

#What is T(x=2)?

I’m writing an MCP model using the Complementarity package and a really useful model debugging technique is to evaluate the equations (NLexpressions in this case) at a solution point.

Any advice would be greatly appreciated.

Continue with:

value(v -> Dict(x => 2.0)[v], T)

The first argument takes a JuMP variable name, and returns a value. So essentially the Dict can contain several variables and other ways are legit, as long as they return a value.

I had the arguments in the value backwards.

Thank you so much.

Actually, you are right, they are flipped. Had to jump to source to figure this out.

We try to follow the Julia style guide: Style Guide · The Julia Language

It suggests that functions should always come as the first argument. The main reason is to allow the do syntax like:

value(T) do v
    return v == x ? 2.0 : 0.0
end