Julia Sympy Apply To Both Sides Of Equation

Brian_Toomey
Sat, 10 Dec 2022 17:47:52 +0000
General Usage

Julia Sympy is great! Many thanks to the people that worked on it.

I’m wondering about how one might implement a strategy like the one described here so that I could work through calculations myself for problem sets.

Take for example a simple algebra 1 problem:

using SymPy
@vars x
eq = Eq(x^2-4x,2x+16)

Obviously, I could use solveset(eq) but if I wanted to work it through myself it would be cumbersome and something like:

eq = Eq(eq.lhs // 2,
        eq.rhs // 2)
eq = Eq(eq.lhs - 8,
        eq.rhs - 8)
eq = Eq(eq.lhs - x,
        eq.rhs - x)
eq = Eq(factor(eq.lhs)*2,
        eq.rhs)

I’m just starting to learn metaprogramming, but I wonder if there is a relatively simple way to set up a macro (or function?) to take in the equation and the operation you wish to perform and return the result as an equation.

This would be similar to ApplySides in Mathematica.

I’m picturing something like @eqApply sin eq or @eqApply \\2 eq.

Thanks!

11 posts - 3 participants