# How can I automatically identify the type of free term in an equation and shift it?

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 *)

• Did you try CoefficientList? This gives you desired terms (free of X and Y) as coefficients of the zero power of X and Y. Apr 19, 2023 at 9:10
• 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? Apr 19, 2023 at 10:13
• @Rom38 The structure of the equation cannot be destroyed, which means that the complete square term cannot be reopened when extracting coefficients Apr 19, 2023 at 10:22
• 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] Apr 19, 2023 at 10:47
• Replace[eq, x1___ + x2_ + x3___ == 0 /; FreeQ[x2, x | y] :> Plus[x1, x3] == -x2] Apr 19, 2023 at 10:59

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 *)

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]
`