Search All of the Math Forum:
Views expressed in these public forums are not endorsed by
NCTM or The Math Forum.



Re: Precision question
Posted:
Oct 21, 2011 3:45 PM


"mailcwc@gmail.com" <mailcwc@gmail.com> wrote in message <899366060159413480f04248e2cba78b@u13g2000prm.googlegroups.com>... > I have three algorithms to calculate the inner product of vector > A(i,j) and vector V for M x N times. > With the line A = round(A), B1 = B2 = B3. > Without the line A = round(A);, B1 != B2, B2 = B3. > Is this a precision error? > Which one is correct? > ........          When you take the sum of terms (as in an inner product,) if the quantities involved have onebits in their binary representations occurring at or near their least significant bit positions, the results will generally be subject to round off errors. In this case the order in which the additions are performed may affect the result, though of course only in these least bits.
In other words, with such quantities, the associative law of addition is not strictly adhered to, so that (a+b)+c does not always give exactly the same result as a+(b+c). Try this on your computer:
a = 3/14; b = 3/14; c = 15/14; (a+b)+c == a+(b+c)
This would presumably account for your results when the 'rand' function is used without doing a 'round' on A. The matrix multiply operation in algorithm 1 apparently performs its additions in a different order than is used in the elementbyelement multiplication followed by the 'sum' function of algorithms 2 and 3.
The same comment applies to a series of successive multiplications. The associative law of multiplication does not always hold so that the ordering of multiplications would affect the result.
You must always be prepared for differing results in the least few bits of an answer when different, though supposedly mathematically equivalent, series of arithmetic operations are performed, due to differences in rounding errors.
Roger Stafford



