zeroequiv



Awhile back, Justin Smith asked if Maxima had a function
for testing the equality of expressions by comparing
numerical values at random points.  Richard Fateman told him
that (http://www.math.utexas.edu/pipermail/maxima/2002/002435.html)
there was such a function, but that "he would probably do better
with just ratsimp(expr1-expr2)."  Here's proof:


(C1) zeroequiv(x-abs(x),x);
(D1)                         TRUE

/* Let's see how many "random" points are checked. */
(C2) :lisp(trace random);
Warning: RANDOM is being redefined.
(RANDOM)
(C2) zeroequiv(x-abs(x),x);
  1> (RANDOM 1000)
  <1 (RANDOM 885)
(D2)                         TRUE

/* Yikes!  zeroequiv tests at only one point.  The documentation
warns against using zeroequiv on non-smooth functions.  Let's
try it on a function that has a continuous first derivative on
the reals. */

(C3) zeroequiv(x*abs(x) - x^2,x);
  1> (RANDOM 1000)
  <1 (RANDOM 938)
(D3)                         TRUE


Again, equality is only checked at one point.  Looking at the
source,

(DEFUN ZEROEQUIV2 (V)
       (declare (special var v s))
       (PROG (R R1 R2)
             (declare (special r1 r2))
             (SETQ R (SIN (TIMES 0.001 (RANDOM 1000.))))
...

we see that expression is evaluated at exactly one
point in the interval [0, sin(1)].  (I don't know why the
author used the sine function here.)

The documentation does warn that:

  If the expression contains functions
  which are not solutions to first order differential equations
  (e.g.  Bessel functions) there may be incorrect results.

I can guess what the author meant, but Bessel functions do satisfy
first order differential equations: y' = J_0'.

In short, zeroequiv and its documentation could use some code
Feng-Shui.

Barton