# Symbolics: simplifying an equation whose RHS is zero

**URL:** <https://discourse.julialang.org/t/symbolics-simplifying-an-equation-whose-rhs-is-zero/102453>\
**Category:** General Usage\
**Tags:** symbolic, symbolics\
**Created:** [August 3, 2023, 4:34pm UTC](https://discourse.julialang.org/t/symbolics-simplifying-an-equation-whose-rhs-is-zero/102453 "2023-08-03T16:34:09Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![nsajko](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/nsajko/32/221187_2.png) [@nsajko](https://discourse.julialang.org/u/nsajko)\
**Post date:** [August 3, 2023, 4:34pm UTC](https://discourse.julialang.org/t/symbolics-simplifying-an-equation-whose-rhs-is-zero/102453/1 "2023-08-03T16:34:09Z")

</div>

I’m using the `Symbolics` package. Suppose I’ve got an expression in several real variables, let’s call it `expr`, and I equate it with zero, e.g. `expr ~ false`. I’d like some simple automatic simplifications of that equation. For example:

1. Eliminate negation: `-subexpr ~ false` → `subexpr ~ false`
2. Eliminate constant coefficients: `2*subexpr ~ false` → `subexpr ~ false`
3. Eliminate constant exponents: `subexpr^2 ~ false` → `subexpr ~ false`

Is there an easy way to achieve this?

What about the following slightly more complex cases?

1. Eliminate common negation: `-x - y ~ false` → `x + y ~ false`
2. Eliminate common constant coefficients: `6*x + 9*y ~ false` → `2*x + 3*y ~ false`
3. Eliminate common constant exponents: `x^6 * y^9 ~ false` → `x^2 * y^3 ~ false`

---

<div class="post-metadata">

**Author:** ![Sevi](https://avatars.discourse-cdn.com/v4/letter/s/c67d28/32.png) [@Sevi](https://discourse.julialang.org/u/Sevi)\
**Post date:** [August 4, 2023, 5:22am UTC](https://discourse.julialang.org/t/symbolics-simplifying-an-equation-whose-rhs-is-zero/102453/2 "2023-08-04T05:22:57Z")

</div>

Why is zero equivalent to `false`? Are you working with Boolean algebra?

There is the `simplify` function that uses some predefined rewriting rules, but I’m not sure it handles Boolean variables (I guess not). If you are just using “standard” algebra, then it might suit your needs.

If not, you might be looking for defining your own term rewriting rules  
[https://symbolicutils.juliasymbolics.org/rewrite/](https://symbolicutils.juliasymbolics.org/rewrite/)

---

<div class="post-metadata">

**Author:** ![nsajko](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/nsajko/32/221187_2.png) [@nsajko](https://discourse.julialang.org/u/nsajko)\
**Post date:** [August 4, 2023, 11:49am UTC](https://discourse.julialang.org/t/symbolics-simplifying-an-equation-whose-rhs-is-zero/102453/3 "2023-08-04T11:49:49Z")

</div>

> [@Sevi](#):
>
> There is the `simplify` function

Already tried that, it doesn’t seem to use the RHS for simplifying the LHS:

```julia-repl
julia> using Symbolics

julia> @variables x
1-element Vector{Num}:
 x

julia> simplify(-x ~ 0)
-x ~ 0

julia> simplify(2x ~ 0)
2x ~ 0

julia> simplify(x^3 ~ 0)
x^3 ~ 0

```

> [@Sevi](#):
>
> Boolean variables

No, my variables are real, `false` is just a constant.

> [@Sevi](#):
>
> term rewriting rules

Thanks, for the link, I’ll have to check it out sometime, although now I’m already done with what I was doing.

---

<div class="post-metadata">

**Author:** ![Sevi](https://avatars.discourse-cdn.com/v4/letter/s/c67d28/32.png) [@Sevi](https://discourse.julialang.org/u/Sevi)\
**Post date:** [August 4, 2023, 5:58pm UTC](https://discourse.julialang.org/t/symbolics-simplifying-an-equation-whose-rhs-is-zero/102453/4 "2023-08-04T17:58:31Z")

</div>

Ah yeah, looks like `simplify` only considers a term, not equations. Would be interesting to know if there is a way to simplify the whole equation though…
