# When are two expressions equal?

**URL:** <https://discourse.julialang.org/t/when-are-two-expressions-equal/87045>\
**Category:** Modelling & Simulations\
**Tags:** symbolics\
**Created:** [September 10, 2022, 5:19pm UTC](https://discourse.julialang.org/t/when-are-two-expressions-equal/87045 "2022-09-10T17:19:42Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![qwerty](https://avatars.discourse-cdn.com/v4/letter/q/4491bb/32.png) [@qwerty](https://discourse.julialang.org/u/qwerty)\
**Post date:** [September 10, 2022, 5:19pm UTC](https://discourse.julialang.org/t/when-are-two-expressions-equal/87045/1 "2022-09-10T17:19:42Z")

</div>

We know that an expression can be written in various forms. For example: `(x - 2)^2` and `4 + x^2 - 4x` are the same function.  
Given a set of substitution rules (such as the default ones in SymbolicUtils.jl), what is the best way to know if two expressions are equal?

---

<div class="post-metadata">

**Author:** ![lferrant](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/lferrant/32/22751_2.png) [@lferrant](https://discourse.julialang.org/u/lferrant)\
**Post date:** [September 10, 2022, 6:31pm UTC](https://discourse.julialang.org/t/when-are-two-expressions-equal/87045/2 "2022-09-10T18:31:37Z")

</div>

In general, equality of real numbers is not decidable, which means given two expressions you cannot always determine whether they are equal or not. This is [Richardson’s theorem](https://en.wikipedia.org/wiki/Richardson%27s_theorem).

For some special cases, e.g. when your expressions are polynomials with rational coefficients, the equality is decidable.In that case, you can use e.g. [Knuth-Bendix algorithm](https://en.wikipedia.org/wiki/Knuth%E2%80%93Bendix_completion_algorithm), which tells you what rewriting rules you need to reduce the expressions to a “normal form” and hence check if they are equal
