# [Maxima] New testsuite failure in today's CVS

Barton Willis willisb at unk.edu
Tue Mar 4 06:32:37 CST 2008

```-----maxima-bounces at math.utexas.edu wrote: -----

>Yes, I've seen it too. But is it maybe a simplification artifact?

No, I think approx-alike is doing its job.

(%i1) [4*x^2-y^2 = 12,x*y-x = 2];
(%o1) [4*x^2-y^2=12,x*y-x=2]

Here is the solution using 5.14:

(%i2) sol_514 : solve(%,[x,y]);
(%o2)
[[x=2,y=2],[x=0.5202594388652*%i-0.13312403573587,y=0.076783785237878-3.608003221870287
*%i],[x=
-0.5202594388652
*%i-0.13312403573587,y=3.608003221870287*%i+0.076783785237878],[x=-1.733751846381093,y=-

0.15356757100197]]

And a solution from Maxima CVS (sbcl / windows)

(%i3) sol_cvs : [[x = 2, y = 2], [x = .5202594388652008 * %i -
.1331240357358706,
y = .07678378523787788 - 3.608003221870287 * %i],
[x = - .5202594388652008 * %i - .1331240357358706,
y = 3.608003221870287 * %i + .07678378523787788],
[x = - 1.733751846381093, y = - .1535675710019696]]\$

There are some differences in the last few digits; approx-alike detects the
differences:

(%i4) ?approx\-alike(sol_514, sol_cvs);
(%o4) false

Increasing float_approx_equal_tolerance by a factor of 2 allows the test to
pass:

(%i5) float_approx_equal_tolerance : float_approx_equal_tolerance * 8\$
(%i6) ?approx\-alike(sol_514, sol_cvs);
(%o6) true

(%i7) float_approx_equal_tolerance : float_approx_equal_tolerance / 4\$
(%i8) ?approx\-alike(sol_514, sol_cvs);
(%o8) true

(%i9) float_approx_equal_tolerance : float_approx_equal_tolerance / 2\$
(%i10) ?approx\-alike(sol_514, sol_cvs);
(%o10) false

Knuth, Vol. II, section 4.2.2 (page 233) gives suggestions on how to
compare
floats. We test equality using

(defun \$float_approx_equal (a b)
(setq a (if (floatp a) a (\$float a)))
(setq b (if (floatp b) b (\$float b)))
(and
(floatp a)
(floatp b)
(<= (abs (- a b)) (* \$float_approx_equal_tolerance (min (abs a) (abs
b))))))

Where we have min(abs(a), abs(b)), Knuth has min(2^exponent of a,
2^exponent of b).  So I think our test is OK (but I wrote approx-alike
and \$float_approx_equal, so ...) Knuth also gives a weaker form of
approximate equality that replaces min with max.

Barton
```