2
$\begingroup$

How can I automatically identify the type of term in an equation and shift it to the left of the equal sign in this equation? The quadratic terms containing x and y should remain on the left side of the equation. How to automatically identify terms (a^2 λ^2)/(-1 + λ^2)^2 that do not contain x and y in the equation and move them to the right side of the equation?

y^2 - (a^2 λ^2)/(-1 + λ^2)^2 + (x - (a λ^2)/(-1 + λ^2))^2 == 0

The equation obtained according to the above rules is:

y^2 + (x - (a λ^2)/(-1 + λ^2))^2 == (a^2 λ^2)/(-1 + λ^2)^2

I tried to write it myself (code below), but is there a better way?

ClearAll["`*"]

eq = y^2 - (a^2 λ^2)/(-1 + λ^2)^2 + (x - (a λ^2)/(-1 + λ^2))^2 == 0

pl = Apply[Subtract, eq]
term = First@CoefficientList[pl, y][[1]]
SubtractSides[eq, term]

(* y^2 + (x - (a λ^2)/(-1 + λ^2))^2 == (a^2 λ^2)/(-1 + λ^2)^2 *)
$\endgroup$
5
  • $\begingroup$ Did you try CoefficientList? This gives you desired terms (free of X and Y) as coefficients of the zero power of X and Y. $\endgroup$
    – Rom38
    Apr 19, 2023 at 9:10
  • $\begingroup$ ClearAll["`*"] eq = y^2 - (a^2 \[Lambda]^2)/(-1 + \[Lambda]^2)^2 + (x - (a \ \[Lambda]^2)/(-1 + \[Lambda]^2))^2 == 0 Apply[Subtract, eq] First@Flatten@CoefficientList[%, {x, y}]how to do it? $\endgroup$
    – csn899
    Apr 19, 2023 at 10:13
  • $\begingroup$ @Rom38 The structure of the equation cannot be destroyed, which means that the complete square term cannot be reopened when extracting coefficients $\endgroup$
    – csn899
    Apr 19, 2023 at 10:22
  • $\begingroup$ ClearAll["`*"] eq = y^2 - (a^2 \[Lambda]^2)/(-1 + \[Lambda]^2)^2 + (x - (a \ \[Lambda]^2)/(-1 + \[Lambda]^2))^2 == 0 pl = Apply[Subtract, eq] List @@ pl Coefficient[List @@ pl, x, 0] Coefficient[List @@ pl, y, 0] SubtractSides[eq, term] $\endgroup$
    – csn899
    Apr 19, 2023 at 10:47
  • $\begingroup$ Replace[eq, x1___ + x2_ + x3___ == 0 /; FreeQ[x2, x | y] :> Plus[x1, x3] == -x2] $\endgroup$ Apr 19, 2023 at 10:59

2 Answers 2

5
$\begingroup$

You can use FreeQ to identify terms without x or y.

Fold[SubtractSides, eq, Select[List @@ First@eq, FreeQ[x | y]]]

(* y^2 + (x - (a λ^2)/(-1 + λ^2))^2 == (a^2 λ^2)/(-1 + λ^2)^2 *)
$\endgroup$
3
$\begingroup$
eq = y^2 - (a^2 λ^2)/(-1 + λ^2)^2 + (x - (a λ^2)/(-1 + λ^2))^2 == 0;
terms = Cases[eq, a_?(FreeQ[x | y]), {2}]
(* {-((a^2 λ^2)/(-1 + λ^2)^2)} *)
SubtractSides[eq, Total@terms]
(* y^2 + (x - (a λ^2)/(-1 + λ^2))^2 == (a^2 λ^2)/(-1 + λ^2)^2 *)

Alternatively, for the last step:

Thread[eq - Total[terms], Equal]
$\endgroup$

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.