3
$\begingroup$

I have a bunch of line equations generated by the following code:

Clear[eq, pts]
eq = Simplify[Det[{{x, y}, -Subtract @@ #}] == Det[#]] &;
pts = 
  {{{0, 3}, {4, 0}}, {{-1, -2}, {4, -2}}, {{3, 4}, {3, -2}}, {{1, -2}, {5, 1}}};
eq /@ pts

The outputs are given as follows.

{3 x + 4 y == 12, 2 + y == 0, x == 3, 3 x == 11 + 4 y}

Question

How can I reformat the outputs to be in the form of $a\,x+b\,y+c=0$?

Note that, although the form $a\,x + b\,y + c == 0$ is fine, I would accept the form $a\,x + b\,y + c = 0$.

$\endgroup$
2
  • 1
    $\begingroup$ TeXForm /@ ((eq /@ pts) /. x__ == y__ :> x - y == 0). $\endgroup$ Sep 1 '20 at 7:42
  • $\begingroup$ @Montevideo: Very good! Thank you. Do you want to post it as your answer? Or I delete the question? $\endgroup$ Sep 1 '20 at 7:44
5
$\begingroup$

You can use SubtractSides:

SubtractSides /@ {3 x + 4 y == 12, 2 + y == 0, x == 3, 3 x == 11 + 4 y}
  {-12 + 3 x + 4 y == 0, 2 + y == 0, -3 + x == 0, -11 + 3 x - 4 y == 0}
TraditionalForm /@ %

enter image description here

Alternatively, you can modify eq using a custom ComplexityFunction in Simplify:

Clear[eq2]
cF = LeafCount[#] + 5000 Count[#, HoldPattern@Equal[_, Except[0]], All] &;

eq2 = Simplify[Det[{{x, y}, -Subtract @@ #}] == Det[#], ComplexityFunction -> cF] &;

TraditionalForm /@ eq2 /@ pts

>     {-12 + 3 x + 4 y == 0, 2 + y == 0, -3 + x == 0, -11 + 3 x - 4 y == 0}

$\endgroup$
3
$\begingroup$
Clear[eq, pts]
eq = Defer@*Plus @@ MonomialList[FactorList[Det[{#1 - #2, #2 - {x, y}}]][[2, 1]]] == 0 &;
pts = {{{0, 3}, {4, 0}}, {{-1, -2}, {4, -2}}, {{3, 4}, {3, -2}}, {{1, -2}, {5, 1}}};
eq @@@ pts

enter image description here

$\endgroup$
1
$\begingroup$

You can solve this problem by:

TeXForm /@ ((eq /@ pts) /. x__ == y__ :> x - y == 0)
$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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