# Expanding a complex number

How does one get Mma to expand

(1/2 + I/2)/Sqrt[2]


into

1/(2 Sqrt[2]) + I/(2 Sqrt[2])


Even evaluating this second expression results in the first one. For many things the second form is more useful that the first one, but it gets «simplified» out of existence… This is correct, of course, but unsightly. Apart, Expand and its friends, and a few others do nothing to the ugly iterated fraction.

• It looks like Mathematica like to automatically write it in this form (i.e combines real/part of complex number). !Mathematica graphics but the question is: why does it matter to you? If it is just a display thing, then there are many way to make display as you want (but then you can't use that to compute with, as it will have wrapper around it). Can you show a case where the second form is needed to compute something you want and you can't do it on the first form as is? Jun 19, 2023 at 6:51
• I am generating numbers to include in text to be typeset as part of an example in some lecture notes, and it is more or less standard tradition to write numbers in the way I want them :-) I know I can produce strings in the shape I want, format using wrappers and so on, but I find it rather wierd that there is no way afaict to tell Mma to do it. Jun 19, 2023 at 8:25
• If you give a small example of what you want to generate (i.e. small example of input/output) I am sure someone will show you how to do it without having the original expression written as you want it. Jun 19, 2023 at 8:27
• I want exactly what I described! Jun 19, 2023 at 8:48
• Row[{Re[expr], "+", I Im[expr]}] // TraditionalForm where expr = (1/2 + I/2)/Sqrt[2]
– Syed
Jun 19, 2023 at 8:54

One of many ways to do what you seem to want is to define a new output form:

myForm[z_?NumericQ] := With[{x=Re[z], y=Im[z]}, DisplayForm@
If[y==0, x, RowBox[{x, If[y<0, "-", "+"], I*y*Sign[y]}]]];


Use this as follows:

(1/2 - I/2)/Sqrt[2] //myForm
(* 1/(2 Sqrt[2]) - I/(2 Sqrt[2]) *)


This way may or may not be what you wanted.

Possible (not very neat) workarounds?

exp=(1/2 + I/2)/Sqrt[2]

Defer[Plus[#,I#]]&@@ReIm@exp


$$\frac{1}{2 \sqrt{2}}+\frac{i}{2 \sqrt{2}}$$

Or:

HoldForm[Plus[#,I#]]&@@ReIm@exp


$$\frac{1}{2 \sqrt{2}}+\frac{i}{2 \sqrt{2}}$$

Check:

(HoldForm[Plus[#,I#]]&@@ReIm@exp//ReleaseHold)==exp

(* True *)


By FullForm you see, that it contains

  Complex[Rationa[1,2],Rational[1,2]].


All normal commands respect complexes, because it needs 3 terms of studying, before you learn to deal with functions of z and Conjugate[z]. This is not complex calculus, but differential Kähler geometry in $$R^2$$

• This seems more appropriate as a comment than an answer. Jun 19, 2023 at 15:54
• This strange fact, that MMA is handling exact rational complex numbers as atoms is the source of despair and a waist of time for many users; with no hint anywhere, that atoms don't simplify. So, as an answer, its perhaps easier to google. Jun 19, 2023 at 21:59