# [Maxima] Nested sqrt functions

Dieter Kaiser drdieterkaiser at web.de
Sun Aug 30 18:15:20 CDT 2009

```Am Sonntag, den 30.08.2009, 15:33 -0700 schrieb Edwin Woollett:
> On Sun, 30 Aug 2009 Dieter Kaiser wrote:
> .....
>  This might be a problem of the simplifier, which does not handle the sqrt
> function carefully.
> -------------------------
>
> Dieter, I'm sure you are hyperaware of everything below,
>  but some mailing list readers might benefit from knowing that
> the bug report you have referred to
>
>  BUG ID: 1010768 - sqrt(1/z) - 1/sqrt(z) => 0
>
> has a link to the text file:
>
> http://www.math.unm.edu/~wester/demos/ComplexDomain/Macsyma.problems
>
> by Michael Wester of the  Mathematics Department at the University of New
> Mexico,
>   Albuquerque, reviewing the use of Macsyma with complex expressions, and
> this
> review might be useful for some readers.
>
> This file is dated 1999 and uses Macsyma 422.0 for Sparc (Solaris 2.x)
> computers.
>
> Lines 128 - 175 appear to show careful and correct treatment of
>
>      expr : sqrt(1/z) - 1/sqrt(z);
>
> which is not simplified unless various further information about z is
> furnished.  declare (z, complex) does not cause simplification, but
> remove(z, complex)\$ and assume(z > 0)\$  causes
> ratsimp(expr) --> 0.
>
> forget(z > 0)\$ and assume(z < 0)\$ causes sqrt(1/z) + 1/sqrt(z);
> to be automatically simplified to 0.
>
> Using the principal branch definitions for both w1  = (z)^(1/2)
> and w2 = (1/z)^(1/2) ,  sqrt(1/z) = 1 / sqrt(z)  unless
> z is real and negative (theta = pi radians),  in which case
> sqrt(1/z) = - 1 / sqrt(z).
>
> I would welcome an improvement in simplification
> of square roots of complex expressions, avoiding tedious
> hand work.

Hello Ted,

thank you very much for the link.

Unfortunately, the shown behavior of Macsyma 422.0 for Sparc which has
been used in the link is not the present behavior of Maxima. It is
worse.

sqrt(1/z) is always simplified to 1/sqrt(z). We can declare z to be
complex or use a symbol assumed to be real and negative. Even to set
radexpand to false does not help:

(%i2) declare(z,complex)\$
(%i3) assume(y<0)\$
(%i4) sqrt(1/z);
(%o4) 1/sqrt(z)
(%i6) sqrt(1/y);
(%o6) 1/sqrt(y)

(%i8) sqrt(1/z);
(%o8) 1/sqrt(z)
(%i10) sqrt(1/y);
(%o10) 1/sqrt(y)

I have already improved the code to get a correct simplification. The
testsuite and the share_testsuite have no serious problems.

At the moment I am working on a testfile for the sqrt function, to check
the improved code and a lot of other things too. When I have finished
this work I will present the results on the mailing list.

Dieter Kaiser

```