Am Dienstag, den 18.08.2009, 19:22 +0200 schrieb Stefano Ferri:
> I'm trying to do a definite integral, but defint tells me that one
> limit of integration is not real.
> This is an example:
>
> (%i2) assume(a>0,b>0,c>0);
> (%o2) [a > 0,b > 0,c > 0]
> (%i3) l1 : sqrt(a^2+b^2);
> (%o3) sqrt(b^2+a^2)
> (%i4) l2 : sqrt(b^2+(c-b)^2);
> (%o4) sqrt((c-b)^2+b^2)
> (%i5) defint(x,x,0,l1);
> (%o5) (b^2+a^2)/2
> (%i6) defint(x,x,0,l2);
> defint: upper limit of integration must be real; found sqrt((c-b)^2+b^2)
> -- an error. To debug this try debugmode(true);
>
> but:
>
> (%i7) realpart(l2);
> (%o7) sqrt((c-b)^2+b^2)
> (%i8) is((c-b)^2+b^2>0);
> (%o8) true
>
>
> a, b and c are all assumed > 0, and Maxima correctly evaluates
> sqrt(a^2+b^2) to be real, and also (c-b)^2+b^2 is >0, and its square
> root has to be real, But defint thinks about it in a different way...
>
> I suspect defint does this: instead to evaluate (c-b)^2+b^2 as the sum
> of the square of two terms > 0, wich would lead to a result > 0, it
> does the expansion to c^2 + 2*b^2 - 2*c*b calling ratsimp, that is
> equivalent to (c-b)^2+b^2, but doing so some information are lost: in
> fact, Maxima cannot determine if c^2 + 2*b^2 is greater than 2*c*b,
> thereforecannot determine if sqrt((c-b)^2+b^2) is real, as required by
> defint.
>
> I don't know lisp, but looking at Maxima's source code (version
> 5.19.0) I've found that in /src/defint.lisp there is the following
> code (lines 207-210):
>
>
> (cond ((not (equal (sratsimp ($imagpart ll)) 0))
> (merror (intl:gettext "defint: lower limit of integration must
> be real; found ~M") ll))
> ((not (equal (sratsimp ($imagpart ul)) 0))
> (merror (intl:gettext "defint: upper limit of integration must
> be real; found ~M") ul)))
>
>
> so the problem seems to be the call to ratsimp. In fact, while before we had:
>
> (%i4) l2 : sqrt(b^2+(c-b)^2);
> (%o4) sqrt((c-b)^2+b^2)
> (%i38) realpart(l2);
> (%o38) sqrt((c-b)^2+b^2)
>
> now, after ratsimp is called we have:
>
> (%i39) ratsimp(l2);
> (%o39) sqrt(c^2-2*b*c+2*b^2)
> (%i40) realpart(%o39);
> (%o40) cos(atan2(0,c^2-2*b*c+2*b^2)/2)*sqrt(abs(c^2-2*b*c+2*b^2))
> (%i41) imagpart(%o39);
> (%o41) sin(atan2(0,c^2-2*b*c+2*b^2)/2)*sqrt(abs(c^2-2*b*c+2*b^2))
>
> That's not so good. Now defint sees an imaginary part. In this way,
> informations about the sign of the original expression are lost.
>
> I hope I'm not telling stupid things... I'm not a matematician and I
> don't know wich is the right way to do a definite integral, but l2 is
> obviously real and ratsimp does some transformations that leave me
> with some doubts.
> Could be better to do the simplification in another way instead to call ratsimp?
>
> Thanks for any help.
Yes, I think it is a bug. But the reason is a bit different.
(%i60) assume(b>0,c>0)$
(%i61) l2 : sqrt(b^2+(c-b)^2)$
The problem is that the function SIGN does not get the right answer when
the global variable LIMITP has the value TRUE.
This gives the correct positive sign:
(%i62) block ([?limitp : false], sign (l2));
(%o62) pos
When limitp is set to TRUE we no longer get the expected sign:
(%i63) block ([?limitp : true], sign (l2));
(%o63) pnz
We have changed the implementation of RISPLIT to ask no longer
questions. In RISPLIT the function $SIGN is called. But when we are in
$defint the global variable LIMITP is set to TRUE. Therefore we get a
general form for the imagpart, because the sign of l2 is no longer known
to Maxima:
(%i64) block ([?limitp : true], imagpart (l2));
(%o64) sin(atan2(0,c^2-2*b*c+2*b^2)/2)*sqrt(abs(c^2-2*b*c+2*b^2))
Earlier implementations of Maxima have the same problem, but Maxima asks
the question is c^2-2*b*c+2*b^2 pos, neg, or zero?
I will have a further look at the problem.
Dieter Kaiser