# An idea to use algebra in to variable definition

**URL:** https://discourse.julialang.org/t/an-idea-to-use-algebra-in-to-variable-definition/121616
**Category:** General Usage
**Created:** [October 22, 2024, 10:21pm UTC](https://discourse.julialang.org/t/an-idea-to-use-algebra-in-to-variable-definition/121616 "2024-10-22T22:21:12Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![xiaodai](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/xiaodai/32/15937_2.png) [@xiaodai](https://discourse.julialang.org/u/xiaodai)
#### Post date: [October 22, 2024, 10:21pm UTC](https://discourse.julialang.org/t/an-idea-to-use-algebra-in-to-variable-definition/121616/1 "2024-10-22T22:21:13Z")

</div>

If I know that `c^2=a^2+b^2` and I know the values of `a` and `c` but want to find `b` then I have to manually rearrange the equation and do

`b = sqrt(c^2 - a^2)`

For complicated cases, it may be hard to decipher what was the intent.

With the current packages available in Julia, is it possible to do something like this

`@define b: c^2 = a^2 + b^2`

and have the macro do the algebra for me?

---

<div class="post-metadata">

### Author: ![heliosdrm](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/heliosdrm/32/3851_2.png) [@heliosdrm](https://discourse.julialang.org/u/heliosdrm)
#### Post date: [October 22, 2024, 10:40pm UTC](https://discourse.julialang.org/t/an-idea-to-use-algebra-in-to-variable-definition/121616/2 "2024-10-22T22:40:43Z")

</div>

Symbolics.jl may not be exactly what you ask for, but it is related and perhaps useful for the problem that you want to address. Specially the symbolic solver:

> **[Solver · Symbolics.jl](https://docs.sciml.ai/Symbolics/stable/manual/solver/#Symbolics.symbolic_solve)**
>
> Documentation for Symbolics.jl.

---

<div class="post-metadata">

### Author: ![xiaodai](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/xiaodai/32/15937_2.png) [@xiaodai](https://discourse.julialang.org/u/xiaodai)
#### Post date: [October 22, 2024, 11:33pm UTC](https://discourse.julialang.org/t/an-idea-to-use-algebra-in-to-variable-definition/121616/3 "2024-10-22T23:33:25Z")

</div>

Cool. I don’t want it solve it at run time but want it to have done it algebraically at compile time. But I suspect we may be able to wrangle it and put that in a macro

---

<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: [October 22, 2024, 11:38pm UTC](https://discourse.julialang.org/t/an-idea-to-use-algebra-in-to-variable-definition/121616/4 "2024-10-22T23:38:47Z")

</div>

> [@xiaodai](#):
>
> If I know that `c^2=a^2+b^2` and I know the values of `a` and `c` but want to find `b` then I have to manually rearrange the equation and do
> 
> `b = sqrt(c^2 - a^2)`

The second equation doesn’t follow from the first on its own, though, it’s not known whether b is positive or negative. So it’s not enough to work with a single equation, rather I guess the implementation of the feature you desire would need to solve systems of polynomial inequalities. Which is very demanding.

---

<div class="post-metadata">

### Author: ![xiaodai](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/xiaodai/32/15937_2.png) [@xiaodai](https://discourse.julialang.org/u/xiaodai)
#### Post date: [October 23, 2024, 12:55am UTC](https://discourse.julialang.org/t/an-idea-to-use-algebra-in-to-variable-definition/121616/5 "2024-10-23T00:55:34Z")

</div>

> [@nsajko](#):
>
> The second equation doesn’t follow from the first on its own

Hmmm…… ok…..
