Nonlinear constraints and squaring

Skip to first unread message


Nov 24, 2023, 11:15:08 AM11/24/23
to Artelys Knitro forum
Hi there

I want to inquire about the bounds on nonlinear constraints.

Let's say I have the following (two-sided) nonlinear constraint:
glb <= g(x) <= gub ....... (1)
Assume my bounds are symmetric in the sense that
gb := -glb = gub.
In that case, I can also write the (one-sided) nonlinear constraint:
[g(x)]^2 <= gb^2 ....... (2)

Would there be any implications to using (2) instead of (1)? As a rule of thumb, what would Knitro prefer? I once heard a saying that "if you don't need to square, don't do it".

Also, on the same topic, when I have two-sided constraints,
glb <= g(x) <= gub,
instead of two one-sided constraints
g(x) <= gub
-g(x) <= -glb,
does Knitro do something different internally?

Thank you!


Richard Waltz

Nov 24, 2023, 11:17:50 AM11/24/23

You definitely should NOT square the constraint.  This formulation will generally be more difficult.

You should formulate it as either a two-sided constraint:
glb <= g(x) <= gub,
or two one-sided constraints:
g(x) <= gub
-g(x) <= -glb.

It shouldn't really matter which of the above you choose - they should be handled the same internally.

-Richard Waltz

From: <> on behalf of TD <>
Sent: Thursday, November 23, 2023 2:43 PM
To: Artelys Knitro forum <>
Subject: [Knitro] Nonlinear constraints and squaring
You received this message because you are subscribed to the Artelys "Knitro Nonlinear Optimization Solver" google group.
To post to this group, send email to
To unsubscribe from this group, send email to
For more options, visit this group at
Thank You,
You received this message because you are subscribed to the Google Groups "Artelys Knitro forum" group.
To unsubscribe from this group and stop receiving emails from it, send an email to
To view this discussion on the web visit


Nov 24, 2023, 1:04:31 PM11/24/23
to Artelys Knitro forum
Thanks for the answer! Noted.

Then I have a question on what do with the following. 

I have the following 2-norm of a two-dimensional vector function:
g(x) = sqrt([a(x)]^2 + [b(x)]^2).
Since the norm is by definition positive, I only need an upper bound.
g(x) <= gub.

However, I assume the sqrt() comes with its own difficulties? In this case, would it be beter to use
[g(x)]^2 = [a(x)]^2 + [b(x)]^2  <= gub^2?

I know it's difficult to give general advice that applies anywhere, but it is good to know what is (usually) bad formulations.

Kind regards

Richard Waltz

Nov 24, 2023, 1:07:28 PM11/24/23
Generally, squaring the constraint so that it has the form:

  [g(x)]^2 = [a(x)]^2 + [b(x)]^2  <= gub^2

would be best, since it makes it smooth.  It might be worth trying both forms, however.


Sent: Friday, November 24, 2023 9:41 AM

To: Artelys Knitro forum <>
Subject: Re: [Knitro] Nonlinear constraints and squaring
Reply all
Reply to author
0 new messages