# How to formulate the following constraints in JuMP

**URL:** <https://discourse.julialang.org/t/how-to-formulate-the-following-constraints-in-jump/95182>\
**Category:** Optimization (Mathematical)\
**Tags:** question, jump\
**Created:** [February 25, 2023, 12:59pm UTC](https://discourse.julialang.org/t/how-to-formulate-the-following-constraints-in-jump/95182 "2023-02-25T12:59:36Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![kevinqiao](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/kevinqiao/32/44492_2.png) [@kevinqiao](https://discourse.julialang.org/u/kevinqiao)\
**Post date:** [February 25, 2023, 12:59pm UTC](https://discourse.julialang.org/t/how-to-formulate-the-following-constraints-in-jump/95182/1 "2023-02-25T12:59:36Z")

</div>

I have a following constraint

\left\| \begin{array}{c} x\\ y\\ \end{array} \right\| \_2\leqslant z \;\;\;\;\;\;\;\;\;\;\;\;\;\;\;\;\;\;(1)

where x, y, and z are all non-negative variables, it’s said that (1) is a SOC relaxation of the following constraint

x^2 = z^2-y^2 \;\;\;\;\;\;\;\;\;\;\;\;\;\;(2)

and I have two questions that have puzzled me:

1. how to transform (1) into (2), though (1) is relaxed.
2. how to formulate (1) in JuMP?

Thanks in advance.

---

<div class="post-metadata">

**Author:** ![odow](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/odow/32/28685_2.png) [@odow](https://discourse.julialang.org/u/odow)\
**Post date:** [February 25, 2023, 8:04pm UTC](https://discourse.julialang.org/t/how-to-formulate-the-following-constraints-in-jump/95182/2 "2023-02-25T20:04:52Z")

</div>

See

> **[Constraints · JuMP](https://jump.dev/JuMP.jl/stable/manual/constraints/#Second-order-cone-constraints)**
>
> Documentation for JuMP.

> **[Tips and Tricks · JuMP](https://jump.dev/JuMP.jl/stable/tutorials/conic/tips_and_tricks/#Second-Order-Cone)**
>
> Documentation for JuMP.

---

<div class="post-metadata">

**Author:** ![kevinqiao](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/kevinqiao/32/44492_2.png) [@kevinqiao](https://discourse.julialang.org/u/kevinqiao)\
**Post date:** [February 27, 2023, 1:28am UTC](https://discourse.julialang.org/t/how-to-formulate-the-following-constraints-in-jump/95182/3 "2023-02-27T01:28:29Z")

</div>

Thanks for your reply, if constraints (1) and (2) are equivalent, is there a performance difference when modeling (1) and (2), separately?

---

<div class="post-metadata">

**Author:** ![odow](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/odow/32/28685_2.png) [@odow](https://discourse.julialang.org/u/odow)\
**Post date:** [February 27, 2023, 1:45am UTC](https://discourse.julialang.org/t/how-to-formulate-the-following-constraints-in-jump/95182/4 "2023-02-27T01:45:52Z")

</div>

It depends on the solver. In most cases, JuMP will reformulate (1) into (2) or (2) into (1) to best support the solver so it doesn’t matter.

But in general, modeling as a `SecondOrderCone` is better.

One reason is that the quadratic constraint:

```julia
@constraint(model, x^2 + y^2 <= z^2)

```

is actually non-convex, so it depends on JuMP or the solver figuring out that if there is that quadratic constraint, _and_ `z >= 0`, then it is actually convex and equivalent to a `SecondOrderCone`.

(Also note that your equation (2) is not quite right. It needs `<=` instead of `=`.)

---

<div class="post-metadata">

**Author:** ![kevinqiao](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/kevinqiao/32/44492_2.png) [@kevinqiao](https://discourse.julialang.org/u/kevinqiao)\
**Post date:** [February 27, 2023, 2:37am UTC](https://discourse.julialang.org/t/how-to-formulate-the-following-constraints-in-jump/95182/5 "2023-02-27T02:37:05Z")

</div>

Thanks, that really helps me.
