why 'lambda' and 'reduce'?

Steven Taschuk staschuk at telusplanet.net
Fri Jun 13 21:35:11 EDT 2003


Quoth Manuel Garcia:
  [...]
> The code contains absolutely no 'obfuscation', except the use of '+'
> for string concatenation.  [...]

I think the expression
    (S((x*y)//F))**2
is a bit obfuscated.  Modulo rounding error, it's equivalent to
x*y, nyet?

  [...]
> calculations by 10**5010 (I needed 10 extra decimal places to
> guarantee the accuracy of the 5000 digits, because I haven't
> eliminated rounding errors, but I only need 10 (maybe less, I didn't
> really try) because the iteration is pretty numerically stable)

This is the point which still puzzles me -- I see no obvious
reason for the rounding error not to propagate.  My experiments
with the code haven't turned up a case with more than about five
wrong digits, but I'd expect a proof of stability to be quite
involved.

> What looked like 'geometrical mean' was actually my having to
> implement a square root function with Newton's method, [...]

Geometric mean is a specific case of square root -- the gm of two
numbers is the square root of their product.  Note, incidentally,
that this is the multiplicative equivalent of the arithmetic mean:

    average(a,b) - a = b - average(a,b)
         gm(a,b) / a = b / gm(a,b)

or, in other words,

    gm(a,b) = sqrt(ab) = exp( (log a + log b)/2 )

(The function in question computes the geometric mean of its
argument n and the up-scope scaling factor F.)

-- 
Steven Taschuk                                                 o- @
staschuk at telusplanet.net                                      7O   )
                                                               "  (





More information about the Python-list mailing list