# Taking the intersection of Semialgebraic Sets for Sum of Squares Optimization

**URL:** https://discourse.julialang.org/t/taking-the-intersection-of-semialgebraic-sets-for-sum-of-squares-optimization/118826
**Category:** Optimization (Mathematical)
**Tags:** question, jump
**Created:** [August 30, 2024, 8:03pm UTC](https://discourse.julialang.org/t/taking-the-intersection-of-semialgebraic-sets-for-sum-of-squares-optimization/118826 "2024-08-30T20:03:10Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![Xifan\_Yu](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/xifan_yu/32/211711_2.png) [@Xifan\_Yu](https://discourse.julialang.org/u/Xifan_Yu)
#### Post date: [August 30, 2024, 8:03pm UTC](https://discourse.julialang.org/t/taking-the-intersection-of-semialgebraic-sets-for-sum-of-squares-optimization/118826/1 "2024-08-30T20:03:10Z")

</div>

Hi,

I am trying to construct a semialgebraic set using package SumOfSquares, which involves a mixture of equality and inequality that would be easier to describe by a for loop. Is there an easy way for me to take the intersection of semialgebraic sets and algebraic sets?

For example, I’d like to achieve the following

```julia
using JuMP
using DynamicPolynomials
using SumOfSquares

@polyvar x y

S1 = @set x^2 - x == 0
S2 = @set x + y <= 1

intersect!(S1, S2)

```

Many 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: [September 2, 2024, 8:04am UTC](https://discourse.julialang.org/t/taking-the-intersection-of-semialgebraic-sets-for-sum-of-squares-optimization/118826/2 "2024-09-02T08:04:01Z")

</div>

Hi @Xifan_Yu welcome to the forum.

This is a question for @blegat

---

<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 2, 2024, 1:32pm UTC](https://discourse.julialang.org/t/taking-the-intersection-of-semialgebraic-sets-for-sum-of-squares-optimization/118826/3 "2024-09-02T13:32:58Z")

</div>

Welcome to the forum. We could implement `intersect!`, PR welcome ! (see [this issue](https://github.com/JuliaAlgebra/SemialgebraicSets.jl/issues/12).  
In the meantime, you can use `algebraic_set` and `basic_semialgebraic_set` functions to create these sets programmatically.  
I just added explanation in the [README](https://github.com/JuliaAlgebra/SemialgebraicSets.jl)

---

<div class="post-metadata">

### Author: ![Xifan\_Yu](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/xifan_yu/32/211711_2.png) [@Xifan\_Yu](https://discourse.julialang.org/u/Xifan_Yu)
#### Post date: [September 3, 2024, 2:00pm UTC](https://discourse.julialang.org/t/taking-the-intersection-of-semialgebraic-sets-for-sum-of-squares-optimization/118826/4 "2024-09-03T14:00:18Z")

</div>

Thank you very much for the help! This is exactly what I need.
