4
$\begingroup$

(Edited to emphasize the point about assumptions).

Consider a simple integral:

Integrate[Exp[I x/2], {x, 0, 2 Pi}]

Mathematica produces the following answer: 4 I.

Consider now a different form of this integral:

Integrate[Sqrt[Exp[I x]], {x, 0, 2 Pi}]

This changes the answer to 4. This is presumably consistent with Mathematica's definition of the square root.

However, providing an assumption,

Integrate[Exp[I x/2], {x, 0, 2 Pi}, Assumptions -> x > 0]
Integrate[Sqrt[Exp[I x]], {x, 0, 2 Pi}, Assumptions -> x > 0]

makes both integrals produce the same answer, 4 I.

How come?

This was tested in Mathematica 13, Mathematica 14.2, and Mathematica 14.3.


This behavior was reported to Wolfram Support and confirmed to be a bug by them.

$\endgroup$
6
  • $\begingroup$ Try NIntegrate[Sqrt[Exp[I x]], {x, 0, 2 Pi}] - it confirms it is 4. But we have branch cut at Pi so if you treat this branch cut differently than default behavior of Mathematica then you may come to a different result. $\endgroup$ Commented Aug 21 at 15:48
  • $\begingroup$ So I think it is Integrate[Sqrt[Exp[I x]], {x, 0, 2 Pi}, Assumptions -> x > 0] that gives wrong result. $\endgroup$ Commented Aug 21 at 15:49
  • $\begingroup$ Indeed, in the problem where I stumbled upon this behavior I had a differently chosen branch cut for the square root. But the part about the assumption still remains a mystery. I updated my post to emphasize this point. $\endgroup$ Commented Aug 21 at 16:21
  • $\begingroup$ It is not a mystery it is a bug. But not in Integrate[Sqrt[Exp[I x]], {x, 0, 2 Pi}] as you thought but in Integrate[Sqrt[Exp[I x]], {x, 0, 2 Pi}, Assumptions -> x > 0]. $\endgroup$ Commented Aug 21 at 16:36
  • 1
    $\begingroup$ Yes, the Sqrt+Assumptions case is befouled. $\endgroup$ Commented Aug 21 at 17:50

2 Answers 2

3
$\begingroup$
expr1 = Exp[I x/2];
expr2 = Sqrt[Exp[I x]];

ReImPlot[expr1, {x, 0, 2 Pi}]
ReImPlot[expr2, {x, 0, 2 Pi}]

NIntegrate[expr1, {x, 0, 2 Pi}]
NIntegrate[expr2, {x, 0, 2 Pi}]

enter image description here

So my conclusion is that this is correct:

Integrate[expr2, {x, 0, 2 Pi}]

4

and this is wrong (a bug):

Integrate[expr2, {x, 0, 2 Pi}, Assumptions -> x > 0]

4 I

And the reason of the bug is probably this another bug:

FunctionDiscontinuities[Sqrt[Exp[I x]], x, Reals]

True

But there is discontinuity at x==Pi.

$\endgroup$
2
$\begingroup$

This is a problem of multivalued functions. Square root is 2 valued. Sqrt uses the so called principal value defined as having -Pi/2 < arg <= Pi/2, where arg=argument(z)= angle between real axis and line origin to z. Whereas Exp[I x/2] x in (0,2Pi) has an argument of: 0< arg <= Pi.You can see this by plotting the arguments of the integrands:

Plot[Arg[Exp[I x/2]], {x, 0, 2 Pi}]

enter image description here

Plot[Arg@Sqrt[Exp[I x]], {x, 0, 2 Pi}]

enter image description here

As the absolute value of both integrands are the same you are actually integrating in the first case:

ParametricPlot[ReIm[Exp[I x/2]], {x, 0, 2 Pi}]

enter image description here

and in the second case:

ParametricPlot[ReIm[Sqrt[Exp[I x]]], {x, 0, 2 Pi}]

enter image description here

Therefore, in the first case, the real parts cancel, whereas in the second case the imaginary parts cancel.

$\endgroup$
1
  • $\begingroup$ Very confusing answer. $\endgroup$ Commented Aug 21 at 19:13

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.