Expression vs Constraint

Hi,

I’m new to using JuMP and still trying to figure out some of the quirks of JuMP. This may also arise from my ignorance of the underlying methods used by the solvers. I’m using the Ipopt solver and solving a non-linear optimization problem (so I am using NLobjective, NLconstraint, NLexpression).

What exactly is the difference between an expression and a constraint? In my problem my constraints are only equality constraints and so I figured that there should be no difference between expressions and constraints in my problem. However, depending on whether I define something as a constraint or expression vastly changes the result! Clearly, defining something as a constraint vs an expression makes a difference but I am not sure what. I’m hoping someone could clarify the difference for me.

Thanks so much!

An expression is something you define to use elsewhere and is not used implicitly. A constraint can be an equality of inequality.

# variables x, y, z
@NLexpression(model, V, x * y * z) # V = xyz
@NLconstraint(model, V >= 1) # equivalent to x * y * z >= 1

That makes sense, but why then does defining something as an expression vs a constraint make a difference in terms of the result of the optimization procedure if the constraint you define is in terms of an equality?

The two different ways of defining the constraint should result in the same behavior:

x * y * z  == 1

and

V == x * y * z
V == 1

should result in the same output since they impose the same conditions!

When using an expression, you don’t create a new variable, simply an internal reference to that expression to be used internally. V on the NLexpression is not a variable.
In your second example, if you define V as a variable and use two constraints, you’ll have an additional variable and constraint, and for a nonlinear solver, it may make a difference. If you use a NLexpression it should be the same as your first example.