# How to calculate this complex expression?

I have a complex expression as follows,

exp=(2 + I) E^(-(1076673/8800) - (3078 I)/
55) (-E^(24491/8800 + (1539 I)/110) + E^(
135679/8800 + (13509 I)/1100) + E^(135679/8800 + (17271 I)/1100) -
E^(318763/8800 + (1539 I)/110) - E^(430369/8800 + (1539 I)/110) +
E^(100453/1760 + (1539 I)/110))^2 ((10 - 5 I) E^(
177897/8800 + (1539 I)/55) - (10 - 5 I) E^(
249793/8800 + (1539 I)/55) - (10 - 5 I) E^(
57817/1760 + (28899 I)/1100) - (10 - 5 I) E^(
57817/1760 + (32661 I)/1100) + (10 - 5 I) E^(
360981/8800 + (28899 I)/1100) + (10 - 5 I) E^(
360981/8800 + (32661 I)/1100) + (10 - 5 I) E^(
472169/8800 + (1539 I)/55) - (10 - 5 I) E^(
108813/1760 + (1539 I)/55) + (10 - 5 I) E^(
23351/352 + (1539 I)/55) - (20 - 10 I) E^(
655671/8800 + (1539 I)/55) + (10 - 5 I) E^(
727567/8800 + (1539 I)/55));


Very strange that,

                         exp//N=5.54244*10^33 - 5.76461*10^17I
exp 0.1=5.54244*10^33 + 0.I
exp//Simplify//N=5.54244*10^33 + 5.76461*10^17I
exp//ExpandAll//N=5.54244*10^33 + 7.47371*10^-10 I
exp//ExpToTrig//Simplify//N=0.            + 0.I
exp//ComplexExpand//Simplify//N=5.54244*10^33 + 0.I


So, how to understand these results and what is the result of this exp ?

Ps,

In practical calculations, I need to calculate a very huge complex expression. This exp is just constructed as a simple example.

• Try Simplify[ComplexExpand[exp]] // N. – J. M. will be back soon Jun 9 '16 at 14:51
• Cannot test right now... Does it make a difference if you use Exp[] instead of E^? – Lukas Jun 9 '16 at 15:23
• @Lukas, that won't really do much, since Exp[x] is automagically converted to E^x symbolically. – J. M. will be back soon Jun 9 '16 at 15:35
• @J.M. Right. Forgot about that... Thanks! – Lukas Jun 9 '16 at 15:44
• Block[{\$MaxExtraPrecision = 200}, N[..., {Infinity, 10}] // Chop] returns same result for all the examples, imaginary part 0. This is rounding/cancellation/etc. – ciao Jun 10 '16 at 4:22

I think that the imaginary component is a rounding error. Try

N[exp, 40]


and the imaginary part is returned as zero.

If evaluated to sufficient significant figures, we see that the expressions given above all have an imaginary part indistinguishable from zero.

N[exp // Simplify, 40]
N[exp // ExpandAll, 40]
N[exp // ExpToTrig, 100]
N[exp // ComplexExpand, 40]


When working to machine precision (as I understand) Mathematica does not estimate the accuracy of the results it returns. When working at higher precision levels, it does, allowing us to see when precision is totally lost.

Different forms of the expression obtained by different algebraic manipulations suffer from different rounding errors. In particular, the ExpToTrig transformation significantly increases the rounding errors, requiring a higher level of precision to return a meaningful result.

As an example of a similar effect, consider the following, which clearly should have imaginary part zero, as shown by symbolic simplification

exp2 = Sum[a + R Exp[2 I j Pi /3], {j, 1, 3}]
Simplify[exp2]
Block[{R = 4.*^34 + I 3.*^34, a = 1.*^40}, exp2]