4
$\begingroup$

How can I make mathematica "merge" solutions of a polynomial by using $\pm$ instead of listing the two solutions fully with only one sign difference?

In particular, I am looking to "compactify" the result of the following computation:

Solve[v1^2 + v2^2 + (t1^2 + t2^2)/\[Lambda]^2 + (
     2 t1 v1 + 2 t2 v2)/\[Lambda] + 2 t1 Conjugate[t1] + 
     2 t2 Conjugate[
       t2] + \[Lambda] (2 v1 Conjugate[t1] + 
        2 v2 Conjugate[t2]) + \[Lambda]^2 (Conjugate[t1]^2 + 
        Conjugate[t2]^2) == 
    ET^2, \[Lambda]] /. {(v1 Conjugate[t1] + v2 Conjugate[t2]) -> 
    vDts} /. {(t1 v1 + t2 v2) -> vDt} /. {(v1^2 + v2^2) -> 
  vDv} /. {(2 t1 Conjugate[t1] + 2 t2 Conjugate[t2]) -> 
 2 tDts} /. {(Conjugate[t1]^2 + Conjugate[t2]^2) -> 
tsDts} /. {(t1^2 + t2^2) -> tDt}
$\endgroup$
5
$\begingroup$

Something like

roots = λ /. Solve[v1^2 + v2^2 + (t1^2 + t2^2)/λ^2 + (
     2 t1 v1 + 2 t2 v2)/λ + 2 t1 Conjugate[t1] + 
     2 t2 Conjugate[
       t2] + λ (2 v1 Conjugate[t1] + 
        2 v2 Conjugate[t2]) + λ^2 (Conjugate[t1]^2 + 
        Conjugate[t2]^2) == 
    ET^2, λ] /. {(v1 Conjugate[t1] + v2 Conjugate[t2]) -> 
    vDts} /. {(t1 v1 + t2 v2) -> vDt} /. {(v1^2 + v2^2) -> 
  vDv} /. {(2 t1 Conjugate[t1] + 2 t2 Conjugate[t2]) -> 
 2 tDts} /. {(Conjugate[t1]^2 + Conjugate[t2]^2) -> 
tsDts} /. {(t1^2 + t2^2) -> tDt};

compact = roots //. {a___, b_ + c_, d___, b_ + e_, f___} /; c + e == 0 :> 
  {a, b \[PlusMinus] If[Internal`SyntacticNegativeQ[e], c, e], d, f};

{Length[roots], Length[compact]}
{4, 2}
| improve this answer | |
$\endgroup$
  • $\begingroup$ Hi, thanks for your help. I am not sure how to apply your recipe to what I have. I was guessing I would write something like roots = Solve[...] with my above equation, and then apply the code you provided. However, the result was simply {4, 4} which doesn't make sense to me.. $\endgroup$ – PPR Jan 9 '15 at 16:46
  • 1
    $\begingroup$ @PPR See my edit. $\endgroup$ – Chip Hurst Jan 9 '15 at 16:50

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.