# RotatedSecondOrderCone() usage

**URL:** <https://discourse.julialang.org/t/rotatedsecondordercone-usage/46019>\
**Category:** Optimization (Mathematical)\
**Tags:** jump\
**Created:** [September 3, 2020, 5:33pm UTC](https://discourse.julialang.org/t/rotatedsecondordercone-usage/46019 "2020-09-03T17:33:03Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![asavasci](https://avatars.discourse-cdn.com/v4/letter/a/eb8c5e/32.png) [@asavasci](https://discourse.julialang.org/u/asavasci)\
**Post date:** [September 3, 2020, 5:33pm UTC](https://discourse.julialang.org/t/rotatedsecondordercone-usage/46019/1 "2020-09-03T17:33:03Z")

</div>

Hi, how should I use RotatedSecondOrderCone() object when converting soc constraint `x^2 + y^2 <= wz where w>=0, z>= 0` ?

I tried to resemble the constraint to given syntax in the [manual](https://jump.dev/JuMP.jl/dev/constraints/#JuMP.RotatedSecondOrderCone) . However, I am not sure if I am doing correctly in JuMP syntax as follows

`2x^2 + 2y^2 <= 2wz where w>=0, z>= 0`

` @constraint(model, [w, z, 2x, 2y] in RotatedSecondOrderCone())`

---

<div class="post-metadata">

**Author:** ![blegat](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/blegat/32/217090_2.png) [@blegat](https://discourse.julialang.org/u/blegat)\
**Post date:** [September 3, 2020, 6:53pm UTC](https://discourse.julialang.org/t/rotatedsecondordercone-usage/46019/2 "2020-09-03T18:53:23Z")

</div>

Almost, but using `2x`, you will rather have `(2x)^2` hence `4x^2` so you should rather use `sqrt(2) * x`. Another option is to use `w/2` or `z/2`.

---

<div class="post-metadata">

**Author:** ![asavasci](https://avatars.discourse-cdn.com/v4/letter/a/eb8c5e/32.png) [@asavasci](https://discourse.julialang.org/u/asavasci)\
**Post date:** [September 5, 2020, 4:21pm UTC](https://discourse.julialang.org/t/rotatedsecondordercone-usage/46019/4 "2020-09-05T16:21:52Z")

</div>

Just to confirming how RotatedSecondOrderCone() object transforms `x^2 + y^2 <= wz` as particular JuMP syntax

1. `@constraint(model, [w, z, sqrt(2)x, sqrt(2)y] in RotatedSecondOrderCone())`  
OR
2. `@constraint(model, [w/2, z/2, x, y] in RotatedSecondOrderCone())`

However, I am still confused with (1) and (2) when `x^2 + y^2 <= wz` is written as below  
`x^2 + y^2 + [(w-z) / 2]^2 <= [(w+z) / 2]^2`  
`4x^2 + 4y^2 + (w-z)^2 <= (w+z)^2`  
`norm( [2x, 2y, (w-z)] ) <= (w+z)`  
which is also representing the same rotated SOCP cone in R^4.

How RotatedSecondOrderCone() takes norm operation for `x^2 + y^2 <= wz` expression is still unclear to me.

---

<div class="post-metadata">

**Author:** ![mtanneau](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mtanneau/32/17787_2.png) [@mtanneau](https://discourse.julialang.org/u/mtanneau)\
**Post date:** [September 5, 2020, 4:40pm UTC](https://discourse.julialang.org/t/rotatedsecondordercone-usage/46019/5 "2020-09-05T16:40:14Z")

</div>

Formulation 1. is correct but 2. is not.

The RSOC constraint (t, u, v) \in RSOC translates to

t, u \geq 0, 2 \times t \times u \geq x\_{1}^{2} + ... + x\_{n}^{2}

Thus, to have w \times z \geq x^{2} + y^{2}, you can write:

- `[w, z, x*sqrt(2), y*sqrt(2)] in RSOC()`
- `[w/2, z, x, y] in RSOC()`
- `[w, z/2, x, y] in RSOC()`
- `[w/sqrt(2), z/sqrt(2), x, y] in RSOC()`

All these formulations are equivalent, i.e., they represent the same set.

To answer the second part your last post: this relation comes from the fact that a Rotated Second-Order Cone can be obtained… by rotating a second-order cone 🙂 (see the [Mosek modeling cookbook](https://docs.mosek.com/modeling-cookbook/cqo.html#rotated-quadratic-cones)).  
Specifically, the rotation matrix is

\begin{bmatrix} \frac{1}{\sqrt{2}} & \frac{1}{\sqrt{2}} \\ \frac{1}{\sqrt{2}} & -\frac{1}{\sqrt{2}} \\ && 1\\ &&& \ddots\\ &&&& 1 \end{bmatrix}

Apply this change of coordinate to the SOC constraint \| 2x, 2y, w-z\| \leq (w+z)^{2} and you’ll recover the original RSOC constraint.

---

<div class="post-metadata">

**Author:** ![asavasci](https://avatars.discourse-cdn.com/v4/letter/a/eb8c5e/32.png) [@asavasci](https://discourse.julialang.org/u/asavasci)\
**Post date:** [September 5, 2020, 7:42pm UTC](https://discourse.julialang.org/t/rotatedsecondordercone-usage/46019/6 "2020-09-05T19:42:03Z")

</div>

When I apply the norm operator to representations given in bullet-(1,3), it yields 2 \times w z \geq x^2 + y^2 and bullet-(2,4) yield (1/2)\*w z \geq x^2 + y^2.

Why wouldn’t it be written `[w,z,x,y] in RSOC` ?

---

<div class="post-metadata">

**Author:** ![mtanneau](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mtanneau/32/17787_2.png) [@mtanneau](https://discourse.julialang.org/u/mtanneau)\
**Post date:** [September 5, 2020, 7:50pm UTC](https://discourse.julialang.org/t/rotatedsecondordercone-usage/46019/7 "2020-09-05T19:50:59Z")

</div>

What are “bullet-(1,3)” and “bullet-(2,4)” here?

---

<div class="post-metadata">

**Author:** ![asavasci](https://avatars.discourse-cdn.com/v4/letter/a/eb8c5e/32.png) [@asavasci](https://discourse.julialang.org/u/asavasci)\
**Post date:** [September 5, 2020, 7:57pm UTC](https://discourse.julialang.org/t/rotatedsecondordercone-usage/46019/8 "2020-09-05T19:57:58Z")

</div>

Bullets

> [@mtanneau](#):
>
> - `[w, z, x/sqrt(2), y/sqrt(2)] in RSOC()`
> - `[w/2, z, x, y] in RSOC()`
> - `[w, z/2, x, y] in RSOC()`
> - `[w/sqrt(2), z/sqrt(2), x, y] in RSOC()`

---

<div class="post-metadata">

**Author:** ![mtanneau](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mtanneau/32/17787_2.png) [@mtanneau](https://discourse.julialang.org/u/mtanneau)\
**Post date:** [September 5, 2020, 8:09pm UTC](https://discourse.julialang.org/t/rotatedsecondordercone-usage/46019/9 "2020-09-05T20:09:18Z")

</div>

Woops, the first one should have been `[w, z, x*sqrt(2), y*sqrt(2)] in RSOC()`. I just corrected that. 😅

All (corrected) formulations are equivalent and express the constraint you initially stated, i.e., wz \geq x^{2} + y^{2}, w\geq 0, z \geq 0.  
Recall the definition of rotated second-order cones as per my previous post and the [MOI documentation](https://jump.dev/MathOptInterface.jl/stable/apireference/#MathOptInterface.RotatedSecondOrderCone). Don’t forget the 2 factor!

---

<div class="post-metadata">

**Author:** ![asavasci](https://avatars.discourse-cdn.com/v4/letter/a/eb8c5e/32.png) [@asavasci](https://discourse.julialang.org/u/asavasci)\
**Post date:** [September 5, 2020, 8:23pm UTC](https://discourse.julialang.org/t/rotatedsecondordercone-usage/46019/10 "2020-09-05T20:23:45Z")

</div>

Noted. Thanks for all the clarifications
