2
$\begingroup$

I am doing symbolic manipulations to get some equations. After generating the equations I want to put them into a more readable form. I am doing this by hand; moving terms from one side of an equals to the other (with the appropriate change in sign). Now doing things by hand can result in slips so I like to check that I have not slipped up by getting Simplify to compare my original equation with the one I have tided up by hand. It does not give back True. What have I done wrong? Below the original equation is eqnsb. I have changed this to eqnsc by moving the second term in the second equation from the left hand side to the right hand side.

enter image description here

Here is the code

eqnsb = {g + (\[Omega]0^2 + \[Alpha] \[Omega]1^2) y[
       t] + \[Alpha] \[Omega]1^2 y1[t] + 
     2 \[Zeta] \[Omega]0 (-Derivative[1][x][t] + 
        Derivative[1][y][t]) + (y^\[Prime]\[Prime])[t] == 
    L \[Omega]0^2 + (2 L + L1) \[Alpha] \[Omega]1^2 + (\[Omega]0^2 + 
        2 \[Alpha] \[Omega]1^2) x[t], 
   g \[Alpha] + 
     2 \[Zeta] \[Omega]0 Derivative[1][x][
       t] + \[Alpha] (\[Omega]1^2 (y[t] + y1[t]) + (
         y1^\[Prime]\[Prime])[t]) == \[Alpha] \[Omega]1^2 (2 L + L1 + 
        2 x[t]) + 2 \[Zeta] \[Omega]0 Derivative[1][y][t]};




eqnsc = {g + (\[Omega]0^2 + \[Alpha] \[Omega]1^2) y[
       t] + \[Alpha] \[Omega]1^2 y1[t] + 
     2 \[Zeta] \[Omega]0 (-Derivative[1][x][t] + 
        Derivative[1][y][t]) + (y^\[Prime]\[Prime])[t] == 
    L \[Omega]0^2 + (2 L + L1) \[Alpha] \[Omega]1^2 + (\[Omega]0^2 + 
        2 \[Alpha] \[Omega]1^2) x[t], 
   g \[Alpha] + \[Alpha] (\[Omega]1^2 (y[t] + y1[t]) + (
         y1^\[Prime]\[Prime])[t]) == \[Alpha] \[Omega]1^2 (2 L + L1 + 
        2 x[t]) + 2 \[Zeta] \[Omega]0 Derivative[1][y][t] - 
     2 \[Zeta] \[Omega]0 Derivative[1][x][t]};
Simplify[eqnsc == eqnsb]

I have checked that when copying back the mess above into my notebook it still does not say True. Hopefully the picture is also helpful.

Version 13.0 for Windows Thanks

$\endgroup$

3 Answers 3

1
$\begingroup$

You better compare expressions, not equations. This can be done by subtracting the left side from the right side of the equations. Toward this aim you index the list of equations. As you want to compare all equations, the first index is "All". Then to get the right side of an equation, the index is "1". And to get the right side, the index is "2". Therefore:

eqnsc[[All, 1]] - eqnsc[[All, 2]] == eqnsb[[All, 1]] - eqnsb[[All, 2]]

True
$\endgroup$
4
  • 1
    $\begingroup$ Sometimes it's helpful to change equations to expressions with equation /.Equal->Subtract $\endgroup$ Feb 23, 2023 at 11:57
  • $\begingroup$ What about SubtractSides[eqn]? $\endgroup$
    – rhermans
    Feb 23, 2023 at 12:34
  • $\begingroup$ I think this is an excellent suggestion and the one I will use first. Out of interest do you know why Simplify fails to work. $\endgroup$
    – Hugh
    Feb 24, 2023 at 14:39
  • $\begingroup$ I can not say with certainty, but I think Simplify is geared towards simplifying expressions not determining the truth of a equation. $\endgroup$ Feb 24, 2023 at 15:53
5
$\begingroup$

SubtractSides with a single argument

I would use SubtractSides with a single argument as a shorter, easier to understand and equally effective alternative.

SubtractSides[eqnsc] == SubtractSides[eqnsb]
(* True *)

or equivalently

Equal @@ SubtractSides/@{eqnsc,eqnsb}
(* True *)

or

Equal @@ SubtractSides@{eqnsc,eqnsb}
(* True *)

Issues

Sometimes you may need to wrap that inside Assuming and FullSimplify, or just Simplify

Equal@@  SubtractSides@{2 a == 4, 1 == a-1}
(* (-4+2 a == 0) == (2-a == 0) *)

but

Simplify [
     Equal@@  SubtractSides@{2 a == 4, 1 == a-1}
]
(* True *)

Documentation

From the documentation for SubtractSides

enter image description here

SubtractSides[rel] subtracts the right-hand side of rel from each side, producing a zero right-hand side.

$\endgroup$
5
  • $\begingroup$ A very good suggestion. I will use this. Out of interest do you know why Simplify does not work? $\endgroup$
    – Hugh
    Feb 24, 2023 at 14:41
  • $\begingroup$ @Hugh What do you mean exactly when you say it doesn't work? $\endgroup$
    – rhermans
    Feb 24, 2023 at 14:42
  • $\begingroup$ I mean Simplify does not come back with True or False. Instead it generates an equation. However, since the original equation has an== It should come back with True or False and does so with less complicated examples. $\endgroup$
    – Hugh
    Feb 24, 2023 at 14:47
  • $\begingroup$ @Hugh, Consider this equations: {2 a == 4,1 == a-1}. Do you say (2 a == 4)==(1 == a-1) is True? $\endgroup$
    – rhermans
    Feb 24, 2023 at 14:49
  • $\begingroup$ You have a point there. I have used the Simplify construction often in the past for moving terms around and it has worked for me. Your example is clearly going further and you are correct; I would not expect that to work. I guess there must be a threshold whereby simply moving terms around cannot be checked without solving. Thanks. $\endgroup$
    – Hugh
    Feb 24, 2023 at 15:01
3
$\begingroup$

First, a small note: I guess that this: (y1^\[Prime]\[Prime])[t] stays in your expression for the second derivative. If you mentioned that, it is incorrect. Use please y1''[t]. If, in contrast, you intended to introduce a new variable, y1 with two primes, it will be misleading since it looks like a second derivative, but it is not. For this reason, in two places, I corrected (y1^\[Prime]\[Prime])[t] for y1''[t].

eqnsb = {g + (\[Omega]0^2 + \[Alpha] \[Omega]1^2) y[
      t] + \[Alpha] \[Omega]1^2 y1[t] + 
    2 \[Zeta] \[Omega]0 (-Derivative[1][x][t] + Derivative[1][y][t]) +
     y''[t] == 
   L \[Omega]0^2 + (2 L + L1) \[Alpha] \[Omega]1^2 + (\[Omega]0^2 + 
       2 \[Alpha] \[Omega]1^2) x[t], 
  g \[Alpha] + 
    2 \[Zeta] \[Omega]0 Derivative[1][x][
      t] + \[Alpha] (\[Omega]1^2 (y[t] + y1[t]) + 
       y1''[t]) == \[Alpha] \[Omega]1^2 (2 L + L1 + 2 x[t]) + 
    2 \[Zeta] \[Omega]0 Derivative[1][y][t]}


eqnsc = {g + (\[Omega]0^2 + \[Alpha] \[Omega]1^2) y[
       t] + \[Alpha] \[Omega]1^2 y1[t] + 
     2 \[Zeta] \[Omega]0 (-Derivative[1][x][t] + 
        Derivative[1][y][t]) + y''[t] == 
    L \[Omega]0^2 + (2 L + L1) \[Alpha] \[Omega]1^2 + (\[Omega]0^2 + 
        2 \[Alpha] \[Omega]1^2) x[t], 
   g \[Alpha] + \[Alpha] (\[Omega]1^2 (y[t] + y1[t]) + 
        y1''[t]) == \[Alpha] \[Omega]1^2 (2 L + L1 + 2 x[t]) + 
     2 \[Zeta] \[Omega]0 Derivative[1][y][t] - 
     2 \[Zeta] \[Omega]0 Derivative[1][x][t]};

Second, it is better not to move terms "by hand." You may comfortably use the commands AddSides and SubtractSides. For example, the operation that you described in your question one makes using the following expression:

SubtractSides[eqnsb[[2]], eqnsb[[2, 1, 2]]]

(* g \[Alpha] + \[Alpha] (\[Omega]1^2 (t^2 + y[t]) + (
      y1^\[Prime]\[Prime])[t]) == \[Alpha] \[Omega]1^2 (2 L + L1 + 
     2 x[t]) - 2 \[Zeta] \[Omega]0 Derivative[1][x][t] + 
  2 \[Zeta] \[Omega]0 Derivative[1][y][t]   *)

Finally, my version of the answer to your main question is

Equal @@ 
 MapThread[
  Subtract, {List @@ eqnsb[[2]], 
   List @@ SubtractSides[eqnsb[[2]], eqnsb[[2, 1, 2]]]}]

(*  True  *)

It is not as good as the one of @Daniel Huber, though.

Have fun!

$\endgroup$
5
  • $\begingroup$ Thanks Alexei. In my code I do use forms like y''[t] and y1''[t]. However, when I post it gets messed up into the form you see above. Is there a way to prevent this happening? Thanks for your suggestions on the main problem. Useful ideas. $\endgroup$
    – Hugh
    Feb 24, 2023 at 14:36
  • $\begingroup$ @Hugh It is probably related to some peculiarity of the system you use. If at your computer it is Ok, let it be. To publish at StackExchange you might use Derivative[2][y][t] instead. $\endgroup$ Feb 24, 2023 at 16:02
  • $\begingroup$ Thanks. I was hoping that it returned to y''[t] when people pasted it into their notebooks. Does this happen to you? I use an ordinary Windows system. If it does not return to y''[t] then this may be a matter for Stackexchange or Mathematica. $\endgroup$
    – Hugh
    Feb 24, 2023 at 16:12
  • $\begingroup$ @Hugh I have Win10, Mma13.2. Indeed, after I copy-pasted it into my notebook, it looked like y''[t]. However, I tried, if this is really derivative. To do this, I first defined y[t_]:=t^2, then copy-pasted your expression looking as y''[t] and evaluated it. It did not return any result. In contrast, it returned y''[t], as if this is an expression unknown to Mma. It is for this reason that I have written in my answer, that the use of such an expression is misleading. $\endgroup$ Feb 24, 2023 at 19:03
  • $\begingroup$ Interesting. So am I correct in thinking that either, Mathematica or stackexchange is making a poor translation? $\endgroup$
    – Hugh
    Feb 24, 2023 at 20:58

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.