ASKSAGE: Sage Q&A Forum - RSS feedhttps://ask.sagemath.org/questions/Q&A Forum for SageenCopyright Sage, 2010. Some rights reserved under creative commons license.Mon, 25 Oct 2021 07:22:56 +0200Checking if expressions are equivalent, using certain equationshttps://ask.sagemath.org/question/59460/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 processSun, 24 Oct 2021 02:33:02 +0200https://ask.sagemath.org/question/59460/checking-if-expressions-are-equivalent-using-certain-equations/Comment by rburing for <p>Let's say I have a bunch of formulas, and want to check if 2 expressions are the same, using those formulas:</p>
<p>Example:</p>
<pre><code>F=m*a
W=F*s
m=rho*V
</code></pre>
<p>Now I would want to use something like full_simplify() on an expression like <code>W-rho*V*a*s</code>, to check that <code>W</code> and <code>rho*V*a*s</code> are indeed equivalent.
I would like to be able to tell Sage which equations are allowed to be used for this simplification process</p>
https://ask.sagemath.org/question/59460/checking-if-expressions-are-equivalent-using-certain-equations/?comment=59463#post-id-59463So polynomial equations/formulas?Sun, 24 Oct 2021 18:43:32 +0200https://ask.sagemath.org/question/59460/checking-if-expressions-are-equivalent-using-certain-equations/?comment=59463#post-id-59463Answer by cav_rt for <p>Let's say I have a bunch of formulas, and want to check if 2 expressions are the same, using those formulas:</p>
<p>Example:</p>
<pre><code>F=m*a
W=F*s
m=rho*V
</code></pre>
<p>Now I would want to use something like full_simplify() on an expression like <code>W-rho*V*a*s</code>, to check that <code>W</code> and <code>rho*V*a*s</code> are indeed equivalent.
I would like to be able to tell Sage which equations are allowed to be used for this simplification process</p>
https://ask.sagemath.org/question/59460/checking-if-expressions-are-equivalent-using-certain-equations/?answer=59464#post-id-59464You 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`.Sun, 24 Oct 2021 19:11:20 +0200https://ask.sagemath.org/question/59460/checking-if-expressions-are-equivalent-using-certain-equations/?answer=59464#post-id-59464Comment by cav_rt for <p>You can define your expressions as proper equations and use <code>.subs()</code></p>
<pre><code>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
</code></pre>
<p>Thus</p>
<pre><code>eq.subs(eq_W).subs(eq_F).subs(eq_m)
</code></pre>
<p>returns <code>0</code>.</p>
https://ask.sagemath.org/question/59460/checking-if-expressions-are-equivalent-using-certain-equations/?comment=59472#post-id-59472I 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[0]).subs(k[1]).subs(k[2]).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`.Mon, 25 Oct 2021 07:22:56 +0200https://ask.sagemath.org/question/59460/checking-if-expressions-are-equivalent-using-certain-equations/?comment=59472#post-id-59472Comment by fT3g0 for <p>You can define your expressions as proper equations and use <code>.subs()</code></p>
<pre><code>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
</code></pre>
<p>Thus</p>
<pre><code>eq.subs(eq_W).subs(eq_F).subs(eq_m)
</code></pre>
<p>returns <code>0</code>.</p>
https://ask.sagemath.org/question/59460/checking-if-expressions-are-equivalent-using-certain-equations/?comment=59467#post-id-59467Thank 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.Sun, 24 Oct 2021 21:20:51 +0200https://ask.sagemath.org/question/59460/checking-if-expressions-are-equivalent-using-certain-equations/?comment=59467#post-id-59467