# Checking if expressions are equivalent, using certain equations

Let's say I have a bunch of formulas, and want to check if 2 expressions are the same, using those formulas:

Example:

F=m*a
W=F*s
m=rho*V


Now I would want to use something like full_simplify() on an expression like W-rho*V*a*s, to check that W and rho*V*a*s are indeed equivalent. I would like to be able to tell Sage which equations are allowed to be used for this simplification process

edit retag close merge delete

1

Sort by » oldest newest most voted

You can define your expressions as proper equations and use .subs()

var('rho V s a F m W')
eq_F = F == m*a
eq_W = W == F*s
eq_m = m == rho*V
eq = W-rho*V*a*s


Thus

eq.subs(eq_W).subs(eq_F).subs(eq_m)


returns 0.

more

Thank you! One more question: I have to do the substitutions manually here. If it gets more complicated, I would like to do something like: apply any of the following equations (so try out different orders,...) and check if it is true.

I don't know if there is something like this implemented in sage, but you can create a list of equations and try every order. The following seems a little odd but it works

equations = [eq_F, eq_W, eq_m]
ordered_equations = Arrangements(equations, len(equations)).list()
expressions = [eq.subs(k).subs(k).subs(k).full_simplify() for k in ordered_equations]


You can check if any of the expressions is equals to zero by

0 in expressions


which in this case returns True.