An idea to use algebra in to variable definition

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?

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:

1 Like

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

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.

Hmmm…… ok……