Eq
¶from symbolic_equation import Eq
from sympy import symbols
x, y = symbols('x y')
eq1 = Eq(2*x - y - 1, tag='I')
eq1
eq2 = Eq(x + y - 5, tag='II')
eq2
eq_y = (
(eq1 - 2 * eq2).tag("I - 2 II")
.transform(lambda eq: eq - 9)
.transform(lambda eq: eq / (-3)).tag('y')
)
eq_y
eq_x = (
eq1.apply_to_lhs('subs', eq_y.as_dict).reset().tag(r'$y$ in I')
.transform(lambda eq: eq / 2)
.transform(lambda eq: eq + 2).tag('x')
)
eq_x
Alternatively, we could let sympy
solve the equation directly:
from sympy import solve
sol = solve((eq1, eq2),(x, y))
sol
{x: 2, y: 3}
from sympy import exp, sin, cos, I
θ = symbols('theta', real=True)
n = 6
eq_euler = (
Eq(exp(I * θ), cos(θ) + I * sin(θ))
.apply('subs', {cos(θ): cos(θ).series(n=n)})
.apply('subs', {sin(θ): sin(θ).series(n=n)})
.apply_to_rhs('expand').amend(previous_lines=2)
.apply_to_lhs('series', n=n)
)
eq_euler
eq_euler.lhs - eq_euler.rhs