# [Maxima] cas complex tests

Dieter Kaiser drdieterkaiser at web.de
Thu Nov 11 14:33:28 CST 2010

```Am Donnerstag, den 11.11.2010, 10:45 -0600 schrieb Barton Willis:
> -----maxima-bounces at math.utexas.edu wrote: -----
>
> >On 11/11/2010 7:33 AM, Barton Willis wrote:
> >> How many users will be satisfied with:
> >>
> >>   (%i1) integrate(sqrt((x^2-2*x+1)/x),x,0,1);
> >>   (%o1) -4/3
> >>
> >>   (%i2) integrate(sqrt(x-2+1/x),x,0,1);
> >>   (%o2) 4/3
> >>
> >> --Barton
> >>
> >I'm not sure that this has to do with integration.
>
> The bug has nothing to do with integration--it's a example of the
> kinds of problems that arise when Maxima is careless about
> simplifications of the power function. I thought it was an example
> that most everybody would agree is a bug. The bogus simplification
> sqrt(x*y) --> sqrt(x) * sqrt(y) is listed in Helmer Aslaksen's paper
> as Test 1 on page 7.
>
> The integration integrate(sqrt(x-2+1/x),x,0,1) is in the testsuite;
> maybe integrate(sqrt((x^2-2*x+1)/x),x,0,1) isn't in the testsuite. If
> I recall, Maxima was patched to fix a bug with
> integrate(sqrt(x-2+1/x),x,0,1); the integrate(sqrt((x^2-2*x+1)/x),x,0,1)
> bug remains.

Some remarks:

1.
The wrong result -4/3 of the first example integrate(sqrt((x^2-2*x
+1)/x),x,0,1) is an old problem. I have recognized the bug since Maxima
5.11 (Maxima 5.9 and Maxima 5.10 gives a noun form for the limit).

2.
With the current Maxima version we get the correct result, if we assume
the variable of integration to be complex:

(%i1) declare(z,complex);
(%o1) done

(%i2) integrate(sqrt((z^2-2*z+1)/z),z,0,1);
(%o2) 4/3

3.
The following simplification is done because the following is determined
to be positive:

(%i4) sign(x^2-2*x+1);
(%o4) pz

(%i5) sqrt((x^2-2*x+1)/x);
(%o5) sqrt(1/x)*sqrt(x^2-2*x+1)

This simplification is not done for z a complex variable (new since
Maxima 5.21):

(%i6) sqrt((z^2-2*z+1)/z);
(%o6) sqrt((z^2-2*z+1)/z)

4.
I think the wrong integral is not a problem of the simplification of the
expression sqrt((x^2-2*x+1)/x) -> sqrt(1/x)*sqrt(x^2-2*x+1), but the
integral is wrong. The following expressions should have the same
definite integral in the interval [0,1]:

sqrt((x^2-2*x+1)/x)
sqrt(1/x)*sqrt(x^2-2*x+1)
sqrt(x^2-2*x+1)/sqrt(x)

I have not analyzed it in very detail. If I trace the integrator the
following wrong integral is used to get the definite integral:

(%i3) integrate(sqrt((x^2-2*x+1)/x),x);
(%o3) (2*x^2-6*x)/(3*sqrt(x))

(%i4) limit(%,x,1);
(%o4) -4/3

It is interesting, that for a complex variable the integrator returns a
more correct integral when called from defint:

(%o9) 2*sqrt(1/z)*z-2*sqrt(1/z)*z^2/3

(%i10) limit(%,z,1);
(%o10) 4/3

But if we do the indefinite integral we again get the more simple and
wrong result:

(%i1) declare(z,complex)\$

(%i2) integrate(sqrt((z^2-2*z+1)/z),z);
(%o2) (2*z^2-6*z)/(3*sqrt(z))

It might be interesting to see why we do get a different integral, if we
call the integrator from defint.

Dieter Kaiser

```