6.2 \(\frac {a}{b}\) and \(a b^{-1}\) sometimes differ (26.9.97)

6.2.1 Harold P. Boas

I was intrigued to discover that Maple evaluates

     5/6.0    and    5*6.0^(-1)
 

to floating-point numbers that differ by 2 units in the last decimal place. The on-line help for arithmetic operations states that

a/b is of type ‘*‘ with operands a and b^(-1)

but evidently this does not tell the whole story.

I am guessing that Maple evaluates 5/6.0 by invoking some built-in algorithm for floating-point division, while Maple evaluates 5*6.0^(-1) by first finding a floating-point approximation to 1/6, and then multiplying by 5. Is this a correct conjecture?

An amusing corollary of this phenomenon is that Maple’s floating-point evaluation is "non-commutative": for example, Maple evaluates

5/6.0 and 5.0/6
 

to different results.

What are the precise circumstances under which Maple does treat a/b and a*b^(-1) as equal?

6.2.2 Robert Israel (6.10.97)

Looks right to me. Actually this is happening during the preliminary "simplification" which is performed on all Maple input before any evaluation takes place. Thus if you do this with variables, there is no difference:

a:= 5; b:= 6.0; 
a/b = a*b^(-1); 
 
               .8333333333 = .8333333333
 

In general floating-point computation is non-commutative. The simplest example is that A + B - A returns 0 when A is much larger than B. Mind you, that _won’t_ necessarily be true if the automatic simplifier is allowed to do its magic:

> 1.0e17 + 1 - 1.0e17; 
          0
 

but

 a:= 1.0e17: b:= 1: 
 a + b - a;  # this will be simplified to b before the arithmetic is performed. 
          1