We have the bug report Bug ID: 2852992 - sqrt(-1/x)-%i/sqrt(x) not zero.
I am working on several issues of the power function. This is one of the
problems.
The following code is responsible for the wrong simplification of
expressions like (-1/x)^a:
((and (or (not (numberp (cadr gr))) (equal (cadr gr) -1))
(setq w (member ($num gr) '(1 -1) :test #'equal)))
(setq pot (mult -1 pot) gr (mul2 (car w) ($denom gr)))
(go cont))
That is what the code does:
(%i4) (-1/x)^a;
(%o4) 1/(-x)^a
This is wrong if x is positive:
(%i1) assume(x>0)$
(%i2) (-1/x)^(1/2);
(%o2) -%i/sqrt(x)
The above result has a wrong sign. We can generate a lot of more wrong
results.
In general the simplification (-1/x)^a -> (-1)^a/x^a is correct for any
real x. This is the code to implement this simplification:
((and (or (not (numberp (cadr gr)))
(equal (cadr gr) -1))
;; Simplify only for expressions like (-1/x)^a
(equal -1 ($num gr))
;; x has to be real
(not (member ($csign (setq w ($denom gr)))
'($complex $imaginary))))
(if (eq ($sign w) '$neg)
;; Negative sign for x: -> 1/(-x)^a
;; Limit expect this type of simplification!
(return (power (neg w) (neg pot)))
;; Any other sign for x: -> (-1)^a/x^a
(return (div (power -1 pot) (power w pot)))))
We get the following results:
A real symbol or an real expression with unknown sign simplifies as
(-1/x)^a -> (-1)^a/x^a:
(%i1) (-1/x)^a;
(%o1) (-1)^a/x^a
(%i2) (-1/(x+2*y))^a;
(%o2) (-1)^a/(2*y+x)^a
No simplification for a complex symbol:
(%i3) declare(z,complex)$
(%i4) (-1/z)^a;
(%o4) (-1/z)^a
Results for symbols declared to be positive or negative:
(%i5) assume(x>0,y<0)$
(%i6) (-1/x)^a;
(%o6) (-1)^a/x^a
(%i7) (-1/y)^a;
(%o7) 1/(-y)^a
The sqrt function now simplifies correctly:
(%i8) sqrt(-1/x);
(%o8) %i/sqrt(x)
(%i9) sqrt(-1/y);
(%o9) 1/sqrt(-y)
This is the example of the bug report, which is now correct:
(%i10) sqrt(-1/x)-%i/sqrt(x);
(%o10) 0
The testsuite has no serious problems. There is one integral in
rtestint.mac which now gives a noun form. With the new code we get an
error.
(%i1) integrate(log(1+exp(cos(phi))),phi,0,%pi);
sign: argument cannot be imaginary; found %i
-- an error. To debug this try: debugmode(true);
We get this error because of the simplification of sqrt(-1/x) ->
%i/sqrt(x). The sign function can not handle the correct imaginary
expression.
In rtest_integral.mac 162 integrals simplifies a bit different (better).
One integral in rtest_integrate_special.mac gives a different sign, but
the new sign is correct. This is the only example I have found which has
a wrong result because of the wrong simplification. (I am working on a
test file rtest_power.mac to test the simpexpt more systematically).
(%i24) integrate(expintegral_ei(1/x^2),x);
(%o24) expintegral_ei(1/x^2)*x+%i*gamma_incomplete(-1/2,-1/x^2)
Any comments?
Next I am working again on the problem sqrt(1/x) -> 1/sqrt(x).
Dieter Kaiser