# How to add assumptions to the integrated function

**URL:** <https://discourse.julialang.org/t/how-to-add-assumptions-to-the-integrated-function/99912>\
**Category:** Modelling & Simulations\
**Tags:** sympy, integrate\
**Created:** [June 5, 2023, 7:41pm UTC](https://discourse.julialang.org/t/how-to-add-assumptions-to-the-integrated-function/99912 "2023-06-05T19:41:09Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![rocco\_sprmnt21](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/rocco_sprmnt21/32/20127_2.png) [@rocco\_sprmnt21](https://discourse.julialang.org/u/rocco_sprmnt21)\
**Post date:** [June 5, 2023, 7:41pm UTC](https://discourse.julialang.org/t/how-to-add-assumptions-to-the-integrated-function/99912/1 "2023-06-05T19:41:10Z")

</div>

I posted the question here because it seemed to me the least unrelated to the question.

Of the following integral I am interested only in the real part. How can I force to consider a\>x\>0?  
Or, alternatively, how can I select only the second one between the two results?

```julia
julia> using SymPy

julia> @syms x y a b
(x, y, a, b)

julia> integrate(sqrt(a^2-x^2),x)
⎧ 2 ⎛x⎞
⎪ ⅈ⋅a ⋅acosh⎜─⎟ 3 │ 2│
⎪ ⎝a⎠ ⅈ⋅a⋅x ⅈ⋅x │x │
⎪- ───────────── - ───────────────── + ─────────────────── for │──│ > 1
⎪ 2 __________________ │ 2│
⎪ ╱ 2 ╱ 2 │a │
⎪ ╱ x ╱ x
⎪ 2⋅ ╱ -1 + ── 2⋅a⋅ ╱ -1 + ──
⎪ ╱ 2 ╱ 2
⎨ ╲╱ a ╲╱ a
⎪
⎪ ________
⎪ ╱ 2
⎪ ╱ x
⎪ 2 ⎛x⎞ a⋅x⋅ ╱ 1 - ──
⎪ a ⋅asin⎜─⎟ ╱ 2
⎪ ⎝a⎠ ╲╱ a
⎪ ────────── + ────────────────── otherwise
⎩ 2 2

```

---

<div class="post-metadata">

**Author:** ![sijo](https://avatars.discourse-cdn.com/v4/letter/s/da6949/32.png) [@sijo](https://discourse.julialang.org/u/sijo)\
**Post date:** [June 6, 2023, 10:47am UTC](https://discourse.julialang.org/t/how-to-add-assumptions-to-the-integrated-function/99912/2 "2023-06-06T10:47:42Z")

</div>

You can set assumptions when you declare the variables:

```julia
julia> using SymPy

julia> @syms x::positive a::positive;

julia> integrate(sqrt(a^2-x^2), x)
 2 ⎛x⎞ _________
a ⋅asin⎜─⎟ ╱ 2 2 
       ⎝a⎠ x⋅╲╱ a - x  
────────── + ──────────────
    2 2       

```

To extract the second case from the general result, I tried some things with `refine` and `SymPy.Q` but without success.

---

<div class="post-metadata">

**Author:** ![rocco\_sprmnt21](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/rocco_sprmnt21/32/20127_2.png) [@rocco\_sprmnt21](https://discourse.julialang.org/u/rocco_sprmnt21)\
**Post date:** [June 6, 2023, 3:05pm UTC](https://discourse.julialang.org/t/how-to-add-assumptions-to-the-integrated-function/99912/3 "2023-06-06T15:05:40Z")

</div>

the condition that x\<=a or that a\>=1/2 can’t be added easily, can it?

---

<div class="post-metadata">

**Author:** ![sijo](https://avatars.discourse-cdn.com/v4/letter/s/da6949/32.png) [@sijo](https://discourse.julialang.org/u/sijo)\
**Post date:** [June 6, 2023, 4:23pm UTC](https://discourse.julialang.org/t/how-to-add-assumptions-to-the-integrated-function/99912/4 "2023-06-06T16:23:42Z")

</div>

Maybe `SymPy.Q(LessThan(x, a))` can work sometimes? I’m not sure…

---

<div class="post-metadata">

**Author:** ![j\_verzani](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/j_verzani/32/8551_2.png) [@j\_verzani](https://discourse.julialang.org/u/j_verzani)\
**Post date:** [June 6, 2023, 5:43pm UTC](https://discourse.julialang.org/t/how-to-add-assumptions-to-the-integrated-function/99912/5 "2023-06-06T17:43:02Z")

</div>

The list of the available “old” assumptions is here [Assumptions - SymPy 1.12 documentation](https://docs.sympy.org/latest/guides/assumptions.html) . There may be tricks to get `|x/a|>1` assumed, but I’m not aware of them.

To answer how you might pull out values from the `Piecewise` object, say you called it `u`, this pattern can help:

```julia
 [(expr=uᵢ.expr, cond=uᵢ.cond) for uᵢ ∈ u.args]

```
