Forcing complex output to take the form $a + b,i$

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP











up vote
5
down vote

favorite












Solving the complex equation $z^2=1+2,i$ using



Solve[z^2 == 1 + 2 I]


returns $leftleftzto -sqrt1+2,iright,leftztosqrt1+2,irightright$, but how do I force Mathematica to always output on the form $a+b,i$, $a,binmathbbR$? Or, if there is no output form from Solve to do this, to convert/transform the answer to the $a+b,i$ form?



I tried



z = a + b I;
Solve[z^2 == 1 + 2 I, a, b ∈ Reals, a, b]


which returns



$$leftleftato-sqrtfrac12left(1+sqrt5right),btosqrtfrac12left(1+sqrt5right)-fracleft(1+sqrt5right)^3/22sqrt2right,leftato sqrtfrac12left(1+sqrt5right),btofracleft(1+sqrt5right)^3/22sqrt2-sqrtfrac12left(1+sqrt5right)rightright$$
but don't think it's a very elegant (and short) way to solve the equation.



One solution is, in its best presentation
$$z_1=sqrtfrac1+sqrt52+isqrtfrac21+sqrt5$$
Can this be output from Solve (or transformation of the output from Solve)?










share|improve this question



















  • 2




    Solve[z^2 == 1 + 2 I] // ComplexExpand // FunctionExpand gets you pretty close.
    – Bill Watts
    2 days ago










  • Related link: mathematica.stackexchange.com/questions/173930/…
    – mathe
    2 days ago














up vote
5
down vote

favorite












Solving the complex equation $z^2=1+2,i$ using



Solve[z^2 == 1 + 2 I]


returns $leftleftzto -sqrt1+2,iright,leftztosqrt1+2,irightright$, but how do I force Mathematica to always output on the form $a+b,i$, $a,binmathbbR$? Or, if there is no output form from Solve to do this, to convert/transform the answer to the $a+b,i$ form?



I tried



z = a + b I;
Solve[z^2 == 1 + 2 I, a, b ∈ Reals, a, b]


which returns



$$leftleftato-sqrtfrac12left(1+sqrt5right),btosqrtfrac12left(1+sqrt5right)-fracleft(1+sqrt5right)^3/22sqrt2right,leftato sqrtfrac12left(1+sqrt5right),btofracleft(1+sqrt5right)^3/22sqrt2-sqrtfrac12left(1+sqrt5right)rightright$$
but don't think it's a very elegant (and short) way to solve the equation.



One solution is, in its best presentation
$$z_1=sqrtfrac1+sqrt52+isqrtfrac21+sqrt5$$
Can this be output from Solve (or transformation of the output from Solve)?










share|improve this question



















  • 2




    Solve[z^2 == 1 + 2 I] // ComplexExpand // FunctionExpand gets you pretty close.
    – Bill Watts
    2 days ago










  • Related link: mathematica.stackexchange.com/questions/173930/…
    – mathe
    2 days ago












up vote
5
down vote

favorite









up vote
5
down vote

favorite











Solving the complex equation $z^2=1+2,i$ using



Solve[z^2 == 1 + 2 I]


returns $leftleftzto -sqrt1+2,iright,leftztosqrt1+2,irightright$, but how do I force Mathematica to always output on the form $a+b,i$, $a,binmathbbR$? Or, if there is no output form from Solve to do this, to convert/transform the answer to the $a+b,i$ form?



I tried



z = a + b I;
Solve[z^2 == 1 + 2 I, a, b ∈ Reals, a, b]


which returns



$$leftleftato-sqrtfrac12left(1+sqrt5right),btosqrtfrac12left(1+sqrt5right)-fracleft(1+sqrt5right)^3/22sqrt2right,leftato sqrtfrac12left(1+sqrt5right),btofracleft(1+sqrt5right)^3/22sqrt2-sqrtfrac12left(1+sqrt5right)rightright$$
but don't think it's a very elegant (and short) way to solve the equation.



One solution is, in its best presentation
$$z_1=sqrtfrac1+sqrt52+isqrtfrac21+sqrt5$$
Can this be output from Solve (or transformation of the output from Solve)?










share|improve this question















Solving the complex equation $z^2=1+2,i$ using



Solve[z^2 == 1 + 2 I]


returns $leftleftzto -sqrt1+2,iright,leftztosqrt1+2,irightright$, but how do I force Mathematica to always output on the form $a+b,i$, $a,binmathbbR$? Or, if there is no output form from Solve to do this, to convert/transform the answer to the $a+b,i$ form?



I tried



z = a + b I;
Solve[z^2 == 1 + 2 I, a, b ∈ Reals, a, b]


which returns



$$leftleftato-sqrtfrac12left(1+sqrt5right),btosqrtfrac12left(1+sqrt5right)-fracleft(1+sqrt5right)^3/22sqrt2right,leftato sqrtfrac12left(1+sqrt5right),btofracleft(1+sqrt5right)^3/22sqrt2-sqrtfrac12left(1+sqrt5right)rightright$$
but don't think it's a very elegant (and short) way to solve the equation.



One solution is, in its best presentation
$$z_1=sqrtfrac1+sqrt52+isqrtfrac21+sqrt5$$
Can this be output from Solve (or transformation of the output from Solve)?







equation-solving complex






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited 2 days ago









m_goldberg

81.8k869189




81.8k869189










asked 2 days ago









mf67

463




463







  • 2




    Solve[z^2 == 1 + 2 I] // ComplexExpand // FunctionExpand gets you pretty close.
    – Bill Watts
    2 days ago










  • Related link: mathematica.stackexchange.com/questions/173930/…
    – mathe
    2 days ago












  • 2




    Solve[z^2 == 1 + 2 I] // ComplexExpand // FunctionExpand gets you pretty close.
    – Bill Watts
    2 days ago










  • Related link: mathematica.stackexchange.com/questions/173930/…
    – mathe
    2 days ago







2




2




Solve[z^2 == 1 + 2 I] // ComplexExpand // FunctionExpand gets you pretty close.
– Bill Watts
2 days ago




Solve[z^2 == 1 + 2 I] // ComplexExpand // FunctionExpand gets you pretty close.
– Bill Watts
2 days ago












Related link: mathematica.stackexchange.com/questions/173930/…
– mathe
2 days ago




Related link: mathematica.stackexchange.com/questions/173930/…
– mathe
2 days ago










2 Answers
2






active

oldest

votes

















up vote
5
down vote













Perhaps this?



ComplexExpand[Solve[z^2 == 1 + 2 I], TargetFunctions -> Re, Im]
(*
z -> -5^(1/4) Cos[ArcTan[2]/2] - I 5^(1/4) Sin[ArcTan[2]/2],
z -> 5^(1/4) Cos[ArcTan[2]/2] + I 5^(1/4) Sin[ArcTan[2]/2]
*)


Update:
I saw Bill Watts' comment after I posted my first answer, which suggests FunctionExpand will help with the trig. functions. Simplifying the separate parts as follows gets the result closer to the desired form:



FunctionExpand@ComplexExpand[Solve[z^2 == 1 + 2 I]] /. 
x_?NumericQ :> ToRadicals@FullSimplify[Re[x]] + I ToRadicals@FullSimplify[Im[x]]
(*
z -> -I Sqrt[1/2 (-1 + Sqrt[5])] - Sqrt[1/2 (1 + Sqrt[5])],
z -> I Sqrt[1/2 (-1 + Sqrt[5])] + Sqrt[1/2 (1 + Sqrt[5])]
*)





share|improve this answer






















  • Truly amazing. Will it work on any "simpler" complex equation or is it targeted to a special form of z^2=a+bi equations? How on earth do one learn this syntax?
    – mf67
    2 days ago










  • @mf67 It should be general, although it's hard to say whether what Mathematica considers simplified will coincide with what is desired. Here are some tutorials on transformation rules: reference.wolfram.com/language/tutorial/…
    – Michael E2
    2 days ago

















up vote
1
down vote













Well, you can define your own simplifying/expanding functions. For example, the following does the trick:



simplify[exp_] := FullSimplify[FunctionExpand[exp], ComplexityFunction -> ((LeafCount[#] + 100 Count[#, (_Root | _Sin | _Cos), 0, Infinity]) &)]
rootExpand[exp_] := exp /. Sqrt[Complex[a_, b_]] :> (simplify[(a^2 + b^2)^(1/4) Cos[1/2 Arg[a + I b]]] + I simplify[(a^2 + b^2)^(1/4) Sin[1/2 Arg[a + I b]]])


Use them as follows:



Solve[z^2 == 1 + 2 I]
% // rootExpand

(* z -> -Sqrt[1 + 2 I], z -> Sqrt[1 + 2 I] *)
(* z -> -I Sqrt[1/2 (-1 + Sqrt[5])] - Sqrt[1/2 (1 + Sqrt[5])], z -> I Sqrt[1/2 (-1 + Sqrt[5])] + Sqrt[1/2 (1 + Sqrt[5])] *)

Solve[z^2 == 7 + 4 I]
% // rootExpand

(* z -> -Sqrt[7 + 4 I], z -> Sqrt[7 + 4 I] *)
(* z -> -I Sqrt[1/2 (-7 + Sqrt[65])] - Sqrt[1/2 (7 + Sqrt[65])], z -> I Sqrt[1/2 (-7 + Sqrt[65])] + Sqrt[1/2 (7 + Sqrt[65])] *)



FWIW: I think your solution is nice too (I don't find it inelegant nor unreasonably long). You can use the function simplify I defined above to make your output slightly nicer looking:



Solve[(a + I b)^2 == 1 + 2 I, a, b [Element] Reals, a, b] // simplify
(* a -> -Sqrt[1/2 (1 + Sqrt[5])], b -> -Sqrt[1/2 (-1 + Sqrt[5])], a -> Sqrt[1/2 (1 + Sqrt[5])], b -> Sqrt[1/2 (-1 + Sqrt[5])] *)





share|improve this answer




















    Your Answer




    StackExchange.ifUsing("editor", function ()
    return StackExchange.using("mathjaxEditing", function ()
    StackExchange.MarkdownEditor.creationCallbacks.add(function (editor, postfix)
    StackExchange.mathjaxEditing.prepareWmdForMathJax(editor, postfix, [["$", "$"], ["\\(","\\)"]]);
    );
    );
    , "mathjax-editing");

    StackExchange.ready(function()
    var channelOptions =
    tags: "".split(" "),
    id: "387"
    ;
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function()
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled)
    StackExchange.using("snippets", function()
    createEditor();
    );

    else
    createEditor();

    );

    function createEditor()
    StackExchange.prepareEditor(
    heartbeatType: 'answer',
    convertImagesToLinks: false,
    noModals: false,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: null,
    bindNavPrevention: true,
    postfix: "",
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    );



    );













     

    draft saved


    draft discarded


















    StackExchange.ready(
    function ()
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmathematica.stackexchange.com%2fquestions%2f181573%2fforcing-complex-output-to-take-the-form-a-b-i%23new-answer', 'question_page');

    );

    Post as a guest






























    2 Answers
    2






    active

    oldest

    votes








    2 Answers
    2






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes








    up vote
    5
    down vote













    Perhaps this?



    ComplexExpand[Solve[z^2 == 1 + 2 I], TargetFunctions -> Re, Im]
    (*
    z -> -5^(1/4) Cos[ArcTan[2]/2] - I 5^(1/4) Sin[ArcTan[2]/2],
    z -> 5^(1/4) Cos[ArcTan[2]/2] + I 5^(1/4) Sin[ArcTan[2]/2]
    *)


    Update:
    I saw Bill Watts' comment after I posted my first answer, which suggests FunctionExpand will help with the trig. functions. Simplifying the separate parts as follows gets the result closer to the desired form:



    FunctionExpand@ComplexExpand[Solve[z^2 == 1 + 2 I]] /. 
    x_?NumericQ :> ToRadicals@FullSimplify[Re[x]] + I ToRadicals@FullSimplify[Im[x]]
    (*
    z -> -I Sqrt[1/2 (-1 + Sqrt[5])] - Sqrt[1/2 (1 + Sqrt[5])],
    z -> I Sqrt[1/2 (-1 + Sqrt[5])] + Sqrt[1/2 (1 + Sqrt[5])]
    *)





    share|improve this answer






















    • Truly amazing. Will it work on any "simpler" complex equation or is it targeted to a special form of z^2=a+bi equations? How on earth do one learn this syntax?
      – mf67
      2 days ago










    • @mf67 It should be general, although it's hard to say whether what Mathematica considers simplified will coincide with what is desired. Here are some tutorials on transformation rules: reference.wolfram.com/language/tutorial/…
      – Michael E2
      2 days ago














    up vote
    5
    down vote













    Perhaps this?



    ComplexExpand[Solve[z^2 == 1 + 2 I], TargetFunctions -> Re, Im]
    (*
    z -> -5^(1/4) Cos[ArcTan[2]/2] - I 5^(1/4) Sin[ArcTan[2]/2],
    z -> 5^(1/4) Cos[ArcTan[2]/2] + I 5^(1/4) Sin[ArcTan[2]/2]
    *)


    Update:
    I saw Bill Watts' comment after I posted my first answer, which suggests FunctionExpand will help with the trig. functions. Simplifying the separate parts as follows gets the result closer to the desired form:



    FunctionExpand@ComplexExpand[Solve[z^2 == 1 + 2 I]] /. 
    x_?NumericQ :> ToRadicals@FullSimplify[Re[x]] + I ToRadicals@FullSimplify[Im[x]]
    (*
    z -> -I Sqrt[1/2 (-1 + Sqrt[5])] - Sqrt[1/2 (1 + Sqrt[5])],
    z -> I Sqrt[1/2 (-1 + Sqrt[5])] + Sqrt[1/2 (1 + Sqrt[5])]
    *)





    share|improve this answer






















    • Truly amazing. Will it work on any "simpler" complex equation or is it targeted to a special form of z^2=a+bi equations? How on earth do one learn this syntax?
      – mf67
      2 days ago










    • @mf67 It should be general, although it's hard to say whether what Mathematica considers simplified will coincide with what is desired. Here are some tutorials on transformation rules: reference.wolfram.com/language/tutorial/…
      – Michael E2
      2 days ago












    up vote
    5
    down vote










    up vote
    5
    down vote









    Perhaps this?



    ComplexExpand[Solve[z^2 == 1 + 2 I], TargetFunctions -> Re, Im]
    (*
    z -> -5^(1/4) Cos[ArcTan[2]/2] - I 5^(1/4) Sin[ArcTan[2]/2],
    z -> 5^(1/4) Cos[ArcTan[2]/2] + I 5^(1/4) Sin[ArcTan[2]/2]
    *)


    Update:
    I saw Bill Watts' comment after I posted my first answer, which suggests FunctionExpand will help with the trig. functions. Simplifying the separate parts as follows gets the result closer to the desired form:



    FunctionExpand@ComplexExpand[Solve[z^2 == 1 + 2 I]] /. 
    x_?NumericQ :> ToRadicals@FullSimplify[Re[x]] + I ToRadicals@FullSimplify[Im[x]]
    (*
    z -> -I Sqrt[1/2 (-1 + Sqrt[5])] - Sqrt[1/2 (1 + Sqrt[5])],
    z -> I Sqrt[1/2 (-1 + Sqrt[5])] + Sqrt[1/2 (1 + Sqrt[5])]
    *)





    share|improve this answer














    Perhaps this?



    ComplexExpand[Solve[z^2 == 1 + 2 I], TargetFunctions -> Re, Im]
    (*
    z -> -5^(1/4) Cos[ArcTan[2]/2] - I 5^(1/4) Sin[ArcTan[2]/2],
    z -> 5^(1/4) Cos[ArcTan[2]/2] + I 5^(1/4) Sin[ArcTan[2]/2]
    *)


    Update:
    I saw Bill Watts' comment after I posted my first answer, which suggests FunctionExpand will help with the trig. functions. Simplifying the separate parts as follows gets the result closer to the desired form:



    FunctionExpand@ComplexExpand[Solve[z^2 == 1 + 2 I]] /. 
    x_?NumericQ :> ToRadicals@FullSimplify[Re[x]] + I ToRadicals@FullSimplify[Im[x]]
    (*
    z -> -I Sqrt[1/2 (-1 + Sqrt[5])] - Sqrt[1/2 (1 + Sqrt[5])],
    z -> I Sqrt[1/2 (-1 + Sqrt[5])] + Sqrt[1/2 (1 + Sqrt[5])]
    *)






    share|improve this answer














    share|improve this answer



    share|improve this answer








    edited 2 days ago

























    answered 2 days ago









    Michael E2

    140k11191457




    140k11191457











    • Truly amazing. Will it work on any "simpler" complex equation or is it targeted to a special form of z^2=a+bi equations? How on earth do one learn this syntax?
      – mf67
      2 days ago










    • @mf67 It should be general, although it's hard to say whether what Mathematica considers simplified will coincide with what is desired. Here are some tutorials on transformation rules: reference.wolfram.com/language/tutorial/…
      – Michael E2
      2 days ago
















    • Truly amazing. Will it work on any "simpler" complex equation or is it targeted to a special form of z^2=a+bi equations? How on earth do one learn this syntax?
      – mf67
      2 days ago










    • @mf67 It should be general, although it's hard to say whether what Mathematica considers simplified will coincide with what is desired. Here are some tutorials on transformation rules: reference.wolfram.com/language/tutorial/…
      – Michael E2
      2 days ago















    Truly amazing. Will it work on any "simpler" complex equation or is it targeted to a special form of z^2=a+bi equations? How on earth do one learn this syntax?
    – mf67
    2 days ago




    Truly amazing. Will it work on any "simpler" complex equation or is it targeted to a special form of z^2=a+bi equations? How on earth do one learn this syntax?
    – mf67
    2 days ago












    @mf67 It should be general, although it's hard to say whether what Mathematica considers simplified will coincide with what is desired. Here are some tutorials on transformation rules: reference.wolfram.com/language/tutorial/…
    – Michael E2
    2 days ago




    @mf67 It should be general, although it's hard to say whether what Mathematica considers simplified will coincide with what is desired. Here are some tutorials on transformation rules: reference.wolfram.com/language/tutorial/…
    – Michael E2
    2 days ago










    up vote
    1
    down vote













    Well, you can define your own simplifying/expanding functions. For example, the following does the trick:



    simplify[exp_] := FullSimplify[FunctionExpand[exp], ComplexityFunction -> ((LeafCount[#] + 100 Count[#, (_Root | _Sin | _Cos), 0, Infinity]) &)]
    rootExpand[exp_] := exp /. Sqrt[Complex[a_, b_]] :> (simplify[(a^2 + b^2)^(1/4) Cos[1/2 Arg[a + I b]]] + I simplify[(a^2 + b^2)^(1/4) Sin[1/2 Arg[a + I b]]])


    Use them as follows:



    Solve[z^2 == 1 + 2 I]
    % // rootExpand

    (* z -> -Sqrt[1 + 2 I], z -> Sqrt[1 + 2 I] *)
    (* z -> -I Sqrt[1/2 (-1 + Sqrt[5])] - Sqrt[1/2 (1 + Sqrt[5])], z -> I Sqrt[1/2 (-1 + Sqrt[5])] + Sqrt[1/2 (1 + Sqrt[5])] *)

    Solve[z^2 == 7 + 4 I]
    % // rootExpand

    (* z -> -Sqrt[7 + 4 I], z -> Sqrt[7 + 4 I] *)
    (* z -> -I Sqrt[1/2 (-7 + Sqrt[65])] - Sqrt[1/2 (7 + Sqrt[65])], z -> I Sqrt[1/2 (-7 + Sqrt[65])] + Sqrt[1/2 (7 + Sqrt[65])] *)



    FWIW: I think your solution is nice too (I don't find it inelegant nor unreasonably long). You can use the function simplify I defined above to make your output slightly nicer looking:



    Solve[(a + I b)^2 == 1 + 2 I, a, b [Element] Reals, a, b] // simplify
    (* a -> -Sqrt[1/2 (1 + Sqrt[5])], b -> -Sqrt[1/2 (-1 + Sqrt[5])], a -> Sqrt[1/2 (1 + Sqrt[5])], b -> Sqrt[1/2 (-1 + Sqrt[5])] *)





    share|improve this answer
























      up vote
      1
      down vote













      Well, you can define your own simplifying/expanding functions. For example, the following does the trick:



      simplify[exp_] := FullSimplify[FunctionExpand[exp], ComplexityFunction -> ((LeafCount[#] + 100 Count[#, (_Root | _Sin | _Cos), 0, Infinity]) &)]
      rootExpand[exp_] := exp /. Sqrt[Complex[a_, b_]] :> (simplify[(a^2 + b^2)^(1/4) Cos[1/2 Arg[a + I b]]] + I simplify[(a^2 + b^2)^(1/4) Sin[1/2 Arg[a + I b]]])


      Use them as follows:



      Solve[z^2 == 1 + 2 I]
      % // rootExpand

      (* z -> -Sqrt[1 + 2 I], z -> Sqrt[1 + 2 I] *)
      (* z -> -I Sqrt[1/2 (-1 + Sqrt[5])] - Sqrt[1/2 (1 + Sqrt[5])], z -> I Sqrt[1/2 (-1 + Sqrt[5])] + Sqrt[1/2 (1 + Sqrt[5])] *)

      Solve[z^2 == 7 + 4 I]
      % // rootExpand

      (* z -> -Sqrt[7 + 4 I], z -> Sqrt[7 + 4 I] *)
      (* z -> -I Sqrt[1/2 (-7 + Sqrt[65])] - Sqrt[1/2 (7 + Sqrt[65])], z -> I Sqrt[1/2 (-7 + Sqrt[65])] + Sqrt[1/2 (7 + Sqrt[65])] *)



      FWIW: I think your solution is nice too (I don't find it inelegant nor unreasonably long). You can use the function simplify I defined above to make your output slightly nicer looking:



      Solve[(a + I b)^2 == 1 + 2 I, a, b [Element] Reals, a, b] // simplify
      (* a -> -Sqrt[1/2 (1 + Sqrt[5])], b -> -Sqrt[1/2 (-1 + Sqrt[5])], a -> Sqrt[1/2 (1 + Sqrt[5])], b -> Sqrt[1/2 (-1 + Sqrt[5])] *)





      share|improve this answer






















        up vote
        1
        down vote










        up vote
        1
        down vote









        Well, you can define your own simplifying/expanding functions. For example, the following does the trick:



        simplify[exp_] := FullSimplify[FunctionExpand[exp], ComplexityFunction -> ((LeafCount[#] + 100 Count[#, (_Root | _Sin | _Cos), 0, Infinity]) &)]
        rootExpand[exp_] := exp /. Sqrt[Complex[a_, b_]] :> (simplify[(a^2 + b^2)^(1/4) Cos[1/2 Arg[a + I b]]] + I simplify[(a^2 + b^2)^(1/4) Sin[1/2 Arg[a + I b]]])


        Use them as follows:



        Solve[z^2 == 1 + 2 I]
        % // rootExpand

        (* z -> -Sqrt[1 + 2 I], z -> Sqrt[1 + 2 I] *)
        (* z -> -I Sqrt[1/2 (-1 + Sqrt[5])] - Sqrt[1/2 (1 + Sqrt[5])], z -> I Sqrt[1/2 (-1 + Sqrt[5])] + Sqrt[1/2 (1 + Sqrt[5])] *)

        Solve[z^2 == 7 + 4 I]
        % // rootExpand

        (* z -> -Sqrt[7 + 4 I], z -> Sqrt[7 + 4 I] *)
        (* z -> -I Sqrt[1/2 (-7 + Sqrt[65])] - Sqrt[1/2 (7 + Sqrt[65])], z -> I Sqrt[1/2 (-7 + Sqrt[65])] + Sqrt[1/2 (7 + Sqrt[65])] *)



        FWIW: I think your solution is nice too (I don't find it inelegant nor unreasonably long). You can use the function simplify I defined above to make your output slightly nicer looking:



        Solve[(a + I b)^2 == 1 + 2 I, a, b [Element] Reals, a, b] // simplify
        (* a -> -Sqrt[1/2 (1 + Sqrt[5])], b -> -Sqrt[1/2 (-1 + Sqrt[5])], a -> Sqrt[1/2 (1 + Sqrt[5])], b -> Sqrt[1/2 (-1 + Sqrt[5])] *)





        share|improve this answer












        Well, you can define your own simplifying/expanding functions. For example, the following does the trick:



        simplify[exp_] := FullSimplify[FunctionExpand[exp], ComplexityFunction -> ((LeafCount[#] + 100 Count[#, (_Root | _Sin | _Cos), 0, Infinity]) &)]
        rootExpand[exp_] := exp /. Sqrt[Complex[a_, b_]] :> (simplify[(a^2 + b^2)^(1/4) Cos[1/2 Arg[a + I b]]] + I simplify[(a^2 + b^2)^(1/4) Sin[1/2 Arg[a + I b]]])


        Use them as follows:



        Solve[z^2 == 1 + 2 I]
        % // rootExpand

        (* z -> -Sqrt[1 + 2 I], z -> Sqrt[1 + 2 I] *)
        (* z -> -I Sqrt[1/2 (-1 + Sqrt[5])] - Sqrt[1/2 (1 + Sqrt[5])], z -> I Sqrt[1/2 (-1 + Sqrt[5])] + Sqrt[1/2 (1 + Sqrt[5])] *)

        Solve[z^2 == 7 + 4 I]
        % // rootExpand

        (* z -> -Sqrt[7 + 4 I], z -> Sqrt[7 + 4 I] *)
        (* z -> -I Sqrt[1/2 (-7 + Sqrt[65])] - Sqrt[1/2 (7 + Sqrt[65])], z -> I Sqrt[1/2 (-7 + Sqrt[65])] + Sqrt[1/2 (7 + Sqrt[65])] *)



        FWIW: I think your solution is nice too (I don't find it inelegant nor unreasonably long). You can use the function simplify I defined above to make your output slightly nicer looking:



        Solve[(a + I b)^2 == 1 + 2 I, a, b [Element] Reals, a, b] // simplify
        (* a -> -Sqrt[1/2 (1 + Sqrt[5])], b -> -Sqrt[1/2 (-1 + Sqrt[5])], a -> Sqrt[1/2 (1 + Sqrt[5])], b -> Sqrt[1/2 (-1 + Sqrt[5])] *)






        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered 2 days ago









        AccidentalFourierTransform

        4,398838




        4,398838



























             

            draft saved


            draft discarded















































             


            draft saved


            draft discarded














            StackExchange.ready(
            function ()
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmathematica.stackexchange.com%2fquestions%2f181573%2fforcing-complex-output-to-take-the-form-a-b-i%23new-answer', 'question_page');

            );

            Post as a guest













































































            Comments

            Popular posts from this blog

            What does second last employer means? [closed]

            List of Gilmore Girls characters

            One-line joke