Here's how I think it works
Code:
eq1 = eq.replace("=","-(") + ")"
Ok, that's easy. If you have x-2 = 2*x this line returns x-2 -(2*x).
If you would do the calculation by hand, you would end up with something like a*x + b, where the x is the solution. Well, this line
Code:
c = eval(eq1,{var:1j})
does something similar. It sets x to 1j and evaluates the expression:
Code:
x - 2 - 2*x # now set x to 1j
1j - 2 - 2*1j # gives
2 - 1j
Now, 2 - 1j is not really a complex number, where j would be sqrt(-1), but j here is our x, the solution. All we have to do now is to calculate j.
Code:
a + bj
bj = -a
j = (-a)/b