# How to Simplify Symbolic Calculations with SymPy (A+B)(A-B) = A^{2} - B^{2}

**URL:** <https://discourse.julialang.org/t/how-to-simplify-symbolic-calculations-with-sympy-a-b-a-b-a-2-b-2/91680>\
**Category:** General Usage\
**Tags:** question\
**Created:** [December 15, 2022, 7:02am UTC](https://discourse.julialang.org/t/how-to-simplify-symbolic-calculations-with-sympy-a-b-a-b-a-2-b-2/91680 "2022-12-15T07:02:14Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Freya\_the\_Goddess](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/freya_the_goddess/32/36835_2.png) [@Freya\_the\_Goddess](https://discourse.julialang.org/u/Freya_the_Goddess)\
**Post date:** [December 15, 2022, 7:02am UTC](https://discourse.julialang.org/t/how-to-simplify-symbolic-calculations-with-sympy-a-b-a-b-a-2-b-2/91680/1 "2022-12-15T07:02:14Z")

</div>

Hi all,

I have this integral with Mean Value Theorem to find value of `c`:

\frac{\int\_{A}^{B} (ax+b) \ dx}{B-A} = f(c)

with  
f(c) = ac+b

then I use this code:

```julia
using SymPy

x, a, b = symbols("x a b")

A, B = symbols("A B")

f = integrate(a*x+b, (x, A, B))

```

The answer is in square terms:

![Capture d’écran_2022-12-15_14-01-12](https://global.discourse-cdn.com/julialang/original/3X/2/5/2537365cc07dbb0aa255ca7b274dc79e742ccfef.png)

The solution manual can be more simplified. Like this:  
 ![Capture d’écran_2022-12-15_13-57-49](https://global.discourse-cdn.com/julialang/original/3X/9/9/999bc722d912590337a0f99e39b940c52baaf32f.png)

Can Julia do this with SymPy so I will get the end result of

c = \frac{A+B}{2}

---

<div class="post-metadata">

**Author:** ![skleinbo](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/skleinbo/32/36080_2.png) [@skleinbo](https://discourse.julialang.org/u/skleinbo)\
**Post date:** [December 15, 2022, 7:07am UTC](https://discourse.julialang.org/t/how-to-simplify-symbolic-calculations-with-sympy-a-b-a-b-a-2-b-2/91680/2 "2022-12-15T07:07:27Z")

</div>

Yes. I will refer you to  
[https://docs.sympy.org/latest/tutorials/intro-tutorial/simplification.html](https://docs.sympy.org/latest/tutorials/intro-tutorial/simplification.html)

---

<div class="post-metadata">

**Author:** ![Freya\_the\_Goddess](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/freya_the_goddess/32/36835_2.png) [@Freya\_the\_Goddess](https://discourse.julialang.org/u/Freya_the_Goddess)\
**Post date:** [December 15, 2022, 7:27am UTC](https://discourse.julialang.org/t/how-to-simplify-symbolic-calculations-with-sympy-a-b-a-b-a-2-b-2/91680/3 "2022-12-15T07:27:45Z")

</div>

It works very beautiful:

```julia
using SymPy

x, a, b = symbols("x a b")

A, B = symbols("A B")

g = integrate(a*x+b, (x, A, B))

d = simplify((g/(B-A) -b)/a)
println("c = ", d)

```
