# Symbolics.jl \`simplify\` behaves in a strange random fashion

**URL:** <https://discourse.julialang.org/t/symbolics-jl-simplify-behaves-in-a-strange-random-fashion/119141>\
**Category:** General Usage\
**Created:** [September 6, 2024, 7:13pm UTC](https://discourse.julialang.org/t/symbolics-jl-simplify-behaves-in-a-strange-random-fashion/119141 "2024-09-06T19:13:30Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![AronT](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/aront/32/24890_2.png) [@AronT](https://discourse.julialang.org/u/AronT)\
**Post date:** [September 6, 2024, 7:13pm UTC](https://discourse.julialang.org/t/symbolics-jl-simplify-behaves-in-a-strange-random-fashion/119141/1 "2024-09-06T19:13:30Z")

</div>

So I was trying to simplify some expression and it didn’t work for me and I couldn’t understand why. Boiling it down to its simplest form, if I use different letters of the alphabet sometimes it works and sometimes it doesn’t;. I give 5 examples to show it’s not even the order of the alphabet. I also go in an out of the Julia REPL each time to be sure previous attempts don’t influence the next. What am I doing wrong here?

```julia
% julia
…
using Symbolics
julia> @variables a x y x̄ ȳ
5-element Vector{Num}:
 a
 x
 y
 x̄
 ȳ
 
 julia> simplify(a*y + a*ȳ)
a*(y + ȳ)

% julia
…
julia> using Symbolics

julia> @variables b x y x̄ ȳ
5-element Vector{Num}:
 b
 x
y
 x̄
 ȳ

julia> simplify(b*y + b*ȳ)
b*y + b*ȳ
 
% julia
…
julia> using Symbolics

julia> @variables c x y x̄ ȳ
5-element Vector{Num}:
 c
 x
 y
 x̄
 ȳ

julia> simplify(c*y + c*ȳ)
c*(y + ȳ)

% julia                                                          
…  
julia> using Symbolics

julia> @variables d x y x̄ ȳ
5-element Vector{Num}:
 d
 x
 y
 x̄
 ȳ

julia> simplify(d*y + d*ȳ)
d*y + d*ȳ

% julia
…
julia> using Symbolics

julia> @variables e x y x̄ ȳ
5-element Vector{Num}:
 e
 x
 y
 x̄
 ȳ

julia> simplify(e*y + e*ȳ)
e*y + e*ȳ

```

---

<div class="post-metadata">

**Author:** ![mike.ingold](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mike.ingold/32/203749_2.png) [@mike.ingold](https://discourse.julialang.org/u/mike.ingold)\
**Post date:** [September 6, 2024, 7:31pm UTC](https://discourse.julialang.org/t/symbolics-jl-simplify-behaves-in-a-strange-random-fashion/119141/2 "2024-09-06T19:31:04Z")

</div>

Are you using a fresh session of Julia for each of these example sections? (I’m wondering if there’s some weirdness going on around re-definition of a `@variable`.)

---

<div class="post-metadata">

**Author:** ![Benny](https://avatars.discourse-cdn.com/v4/letter/b/49beb7/32.png) [@Benny](https://discourse.julialang.org/u/Benny)\
**Post date:** [September 6, 2024, 7:50pm UTC](https://discourse.julialang.org/t/symbolics-jl-simplify-behaves-in-a-strange-random-fashion/119141/3 "2024-09-06T19:50:51Z")

</div>

I can kinda\* replicate this in the same session, even if I omit the redefinitions of y and ȳ. How are you not running into `ay not defined` etc. errors though? \*I have to reasonably use `a*y`.

---

<div class="post-metadata">

**Author:** ![AronT](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/aront/32/24890_2.png) [@AronT](https://discourse.julialang.org/u/AronT)\
**Post date:** [September 6, 2024, 7:51pm UTC](https://discourse.julialang.org/t/symbolics-jl-simplify-behaves-in-a-strange-random-fashion/119141/4 "2024-09-06T19:51:10Z")

</div>

Yes as you can see in the log I go in and out of Julia each time. I had same thought as you which is why I did it this way.

---

<div class="post-metadata">

**Author:** ![AronT](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/aront/32/24890_2.png) [@AronT](https://discourse.julialang.org/u/AronT)\
**Post date:** [September 6, 2024, 7:52pm UTC](https://discourse.julialang.org/t/symbolics-jl-simplify-behaves-in-a-strange-random-fashion/119141/5 "2024-09-06T19:52:55Z")

</div>

That’s just the formatting of the quote. I actually used `*`

---

<div class="post-metadata">

**Author:** ![Benny](https://avatars.discourse-cdn.com/v4/letter/b/49beb7/32.png) [@Benny](https://discourse.julialang.org/u/Benny)\
**Post date:** [September 6, 2024, 7:54pm UTC](https://discourse.julialang.org/t/symbolics-jl-simplify-behaves-in-a-strange-random-fashion/119141/6 "2024-09-06T19:54:23Z")

</div>

Oh I see that leading stripe now. Maybe use ``` quote blocks for code formatting?

---

<div class="post-metadata">

**Author:** ![AronT](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/aront/32/24890_2.png) [@AronT](https://discourse.julialang.org/u/AronT)\
**Post date:** [September 6, 2024, 7:57pm UTC](https://discourse.julialang.org/t/symbolics-jl-simplify-behaves-in-a-strange-random-fashion/119141/7 "2024-09-06T19:57:40Z")

</div>

Yes I fixed it! Apologies for the confusion

---

<div class="post-metadata">

**Author:** ![ufechner7](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ufechner7/32/51363_2.png) [@ufechner7](https://discourse.julialang.org/u/ufechner7)\
**Post date:** [September 6, 2024, 11:34pm UTC](https://discourse.julialang.org/t/symbolics-jl-simplify-behaves-in-a-strange-random-fashion/119141/8 "2024-09-06T23:34:45Z")

</div>

> [@AronT](#):
>
> `simplify(b*y + b*ȳ)`

I can replicate the issue. Please, create a bug report!
