I'm currently doing a maths course where my aim is to understand the concepts and process rather than crunch through problem sets as fast as possible. When solving equations, I'd like to be able to poke at them myself rather than have them solved for me.
Let's say we have the very simple equation z + 1 = 4
- if I were to solve this myself, I would obviously subtract 1 from both sides, but I can't figure out if sympy
provides a simple way to do this. At the moment the best solution I can come up with is:
from sympy import *
z = symbols('z')
eq1 = Eq(z + 1, 4)
Eq(eq1.lhs - 1, eq1.rhs - 1)
# Output:
# z == 3
Where the more obvious expression eq1 - 1
only subtracts from the left-hand side. How can I use sympy to work through equalities step-by-step like this (i.e. without getting the solve()
method to just given me the answer)? Any pointers to the manipulations that are actually possible with sympy equalities would be appreciated.
There is a "do" method and discussion at https://github.com/sympy/sympy/issues/5031#issuecomment-36996878 that would allow you to "do" operations to both sides of a Equality. It's not been accepted as an addition to SymPy but it is a simple add-on that you can use. It is pasted here for convenience: