Although the new nonlinear rewrite that is in progress, https://github.com/jump-dev/JuMP.jl/pull/3106, will automatically detect linear and quadratic expressions and simplify them.

Thanks for the answer. Will the rewrite able to simplify linear/quadratic expressions which are parts of a larger nonlinear expression? For example, x + exp(x + x + x*y) + x to 2*x + exp(2*x + x*y).

Will the rewrite able to simplify linear/quadratic expressions which are parts of a larger nonlinear expression?

Mostly. But there are a few cases where we wonâ€™t:

julia> using JuMP
julia> model = Model();
julia> @variable(model, x);
julia> @variable(model, y);
julia> @expression(model, x + exp(x + x + x*y) + x)
+(x, exp(x*y + 2 x), x)
julia> @expression(model, x + x + exp(x + x + x*y))
+(2 x, exp(x*y + 2 x))

Because we build expressions from left to right, the first @expression doesnâ€™t go back and realize that it could add the first and third terms together.

It might be worth giving MTK a try Modeling Optimization Problems Â· ModelingToolkit.jl if you have such expressions in constraints, then you can call structural_simplify on the OptimizationSystem though it doesnâ€™t do it for the objective right now

Thanks for the suggestion. But I do not have such expressions in constraints or the objective function. They are some expressions that I would like to calculate their values at the optimal conditions.