# Wrong answer for complex integral with maxima

I was trying to do the contour integral $\int_C |z-1|^2 dz$ along the upper unit semicircle, and tried

t = var('t')
integrate(abs(exp(i*t)-1)^2*i*exp(i*t), (t,0,pi))


The answer returned was $-\frac{8}{3}$, which is wrong. The correct answer is $-4-i\pi$, which is given by the giac and sympy solvers.

It seems that maybe it is ignoring the absolute value, as we do have $\int_C (z-1)^2 dz = -\frac{8}{3}$.

Is this a bug in Maxima and/or Sage, or am I doing something silly?

edit retag close merge delete

Sort by » oldest newest most voted

Yes, the absolute value is omitted, as seen from integrating without limits, then differentiating the result:

sage: assume(t, 'real')
sage: integrate(abs( (exp(i*t) - 1)^2 ) * i * exp(i*t), t).diff().factor()
I*(e^(I*t) - 1)^2*e^(I*t)


The problem is that the machine was not really educated to take the absolute value correctly, here it must isolate the real and imaginary parts, compute the absolute value, then integrate this value. In giac we have the right answer:

sage: integrate(abs(exp(i*t) - 1)^2 * i * exp(i*t), (t, 0, pi), algorithm='giac')
-I*pi - 4


The expectation that the computer does and must do always the right thing is not really realistic. If it is a must, then the implementers must be written on a black list and punished. However, the implementers are on my list at the top, they did the best, and combined with human common sense and checks the work is almost always done.

In our case, let us explicitly help the integrator:

sage: integrate( (real(exp(i*t) - 1)^2 + imag(exp(i*t) - 1)^2) * i * exp(i*t), t, 0, pi)
-I*pi - 4

sage: integrate(abs((cos(t) + i*sin(t) - 1)^2) * i * exp(i*t), (t, 0, pi))
-I*pi - 4

more

FWIW :

sage: var("t")
t
sage: integrate(abs(exp(i*t).demoivre()-1)^2*i*exp(i*t), (t,0,pi))
-I*pi - 4


HTH,

more