Work at SourceForge, help us to make it a better place! We have an immediate need for a Support Technician in our San Francisco or Denver office.


#2575 Integration error: integrate(sqrt(k-k*cos(2*x)), x)

Albrecht Mueller

The post Integration error by Ajit Kumar reports a wrong integration result. I did some experiments and think there is an error in the integrate function - see attachment. The sign of the result should not change if you change what is essentially a constant factor.

1 Attachments


  • As you can see in the attatchment, the error affects at least two versions of Maxima: 5.19.2 and 5.28.0-2.

  • Aleksas

    Problem. Find the volume of the intersection of the cylinder with x^2+y^2=a*x and the sphere x^2+y^2+z^2<=a^2.

    See: W.Ledermann
    Multiple Integrals - Page 64 - Google Books Result
    Example 14 (Viviani's Problem). Find the part of the sphere x2 + y2 + z2 < a2 which lies inside the vertical (unlimited) cylinder which intersects the (x, v)-plane in ...

    (%i1) assume(a>0,sin(phi)>0,cos(phi)>0);
    (%o1) [a>0,sin(phi)>0,cos(phi)>0]

    (%i2) V=4integrate(integrate(sqrt(a^2-r^2)r,r, 0,acos(phi)),phi,0,%pi/2);
    (%o2) V=(2

    (%i3) V=4'integrate(integrate(sqrt(a^2-r^2)r,r, 0,acos(phi)),phi,0,%pi/2);
    (%o3) V=4
    (%i4) trigsimp(%);
    (%o4) V=(4
    (%i5) ev(%, nouns);
    (%o5) V=(2

    Where is the mistake?


    Aleksas D

  • Robert Dodier
    Robert Dodier

    • labels: --> Lisp Core - Integration
  • Douglas Davis
    Douglas Davis

    I have had similar issues with integrations of trigonometric functions to find the average magnitude. The simplest error I could generate was

    integrate(sqrt(cos(x)+1), x, -%pi, %pi);

    gives 0 which should be 2*sqrt(2);

    I tried various assume statements to no avail.

    • Using your example, I did some experiments, especially considering the equivalence cos(x) + 1 = 2(cos(x/2))^2, thus sqrt(cos(x) + 1) = sqrt(2)*abs(cos(x/2)).

      I tried indefinite integration using the "integrate" and the "risch" function.

      Neither "integrate" nor "risch" were able to integrate sqrt(2)*abs(cos(x/2)).

      risch(sqrt(cos(x) + 1),x) = risch(sqrt(2)*cos(x/2), x) = integrate(sqrt(2)*cos(x/2), x) = 2^(3/2)*sin(x/2).

      The result of risch(sqrt(cos(x) + 1),x) is wrong as it gives the integral of sqrt(2)*cos(x/2) and not of sqrt(2)*abs(cos(x/2)).

      integrate(sqrt(cos(x) + 1),x) gives (2^(3/2)*sin(x))/((cos(x)+1)*sqrt(sin(x)^2/(cos(x)+1)^2+1)) which I cannot reduce to the result of the other integrations.

      integrate(sqrt(2)*cos(x/2), x, -%pi, %pi) gives 2^(5/2). I think this is correct, as cos(x/2) is not negative between -%pi and %pi.

      integrate(sqrt(cos(x) + 1), x, 0, %pi) asks "Is cos(x)-1.0 positive or negative?". I entered both "p" and "n". In both cases the result was 2^(3/2).

      integrate(sqrt(cos(x) + 1), x, -%pi, 0) gave -2^(3/2), however. Due to the symmetry of cos this should be the same result as before.

      Trying to do the definite integration "by hand":
      lambda([x], (2^(3/2)*sin(x))/((cos(x)+1)*sqrt(sin(x)^2/(cos(x)+1)^2+1)))(-%pi);
      This results in:
      Division by 0

      #0: lambda([x],2^(3/2)*sin(x)/((cos(x)+1)*sqrt(sin(x)^2/(cos(x)+1)^2+1)))(x=-%pi)

      -- an error. To debug this try debugmode(true);
      expt: undefined: 0 to a negative exponent.
      #0: lambda([x],2^(3/2)*sin(x)/((cos(x)+1)*sqrt(sin(x)^2/(cos(x)+1)^2+1)))(x=-%pi)
      -- an error. To debug this try: debugmode(true);

      I tried this with:
      Maxima version: 5.19.2
      Maxima build date: 8:55 8/31/2009
      host type: i686-pc-mingw32
      lisp-implementation-type: GNU Common Lisp (GCL)
      lisp-implementation-version: GCL 2.6.8
      and with:

      build_info("5.28.0-2","2012-08-27 23:16:48","i686-pc-mingw32","GNU Common Lisp (GCL)","GCL 2.6.8")

  • This problem came up again, see

    Therefore I did some further analysis.

    Maximas solution of


    is, after some simplification (radcan, trigreduce, factor)

    2 * sin(x) / sqrt(cos(x)+1)

    This solution has singularities at (2n + 1)%pi, where n is an integer. The solution is not continuous:

    limit(2 * sin(x) / sqrt(cos(x)+1), x, %pi, minus);

    evaluates to 2 ^(3/2) while

    limit(2 * sin(x) / sqrt(cos(x)+1), x, %pi, plus);

    evaluates to - 2 ^(3/2)

    I think the correct solution is something like

    2 * sin(x) / sqrt(cos(x) + 1) + 4*sqrt(2)*floor((x+%pi)/(2*%pi))

    or (in order to avoid singularities)

    + 4*sqrt(2)*floor((x+%pi)/(2*%pi))

    Maxima should come up with this sort of solution. When calculating definite integrals, Maxima should check if there are any singularities (denominator is zero, cot(0), etc) in the integration range, and issue a warning, if it detects this kind of problems.

    Last edit: Albrecht Mueller 2013-10-05
    • There is a package to handle piecewise continuous functions: pw.mac by Richard Hennessy which seems to contain code that could be useful to implement a better support of this kind of situations. For more details see thread how to calculate integrate(abs(sin(x)), x, 0, %pi);.