guile-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[PATCH] Fast R6RS div/mod; improved extensibility of numerics


From: Mark H Weaver
Subject: [PATCH] Fast R6RS div/mod; improved extensibility of numerics
Date: Sun, 30 Jan 2011 11:27:24 -0500
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/23.1 (gnu/linux)

Here are another four patches of numerics improvements.

The second patch adds fast C implementations of the R6RS
number-theoretic division operations: `div-and-mod', `div', `mod',
`div0-and-mod0', `div0' and `mod0'.  Note that these operations will
accept any real numbers (except division by zero), not just integers.

The first three are equivalent to `euclidean/' et al from Taylor
Campbell's proposal, and those are the names I gave them in guile core.
The other three I named `centered/', `centered-quotient', and
`centered-remainder', because the range of their remainder operation is
centered on 0 in a twos-complement sort of way.  They are almost the
same as Taylor's `round/' et al, but in my opinion they have superior
properties, as I explained in a recent commentary on this list.

The last two patches improve the extensibility of numeric operations,
and as a side effect add documentation strings to many of them.

The last patch might be slightly controversial.  Although it does not
make `integer-expt' a generic function, nonetheless it can now
exponentiate _any_ scheme object that can be multiplied using `*'.
raising to a negative exponent, the reciprocal operation must also be
supported.  As a side effect, (expt <obj> 0) will return 1 and
(expt <obj> 1) will return <obj> for any scheme object whatsoever,
without operating on it at all.  Raising to any other power will however
throw an exception if the requisite methods have not been defined.

I've attached a simple demo that I wrote in about 10 minutes, which
defines a bare-bones matrix class and uses `expt' to do fast matrix
exponentiation.  The demo uses this to define a very fast and exact
fibonacci procedure (fib n).

    Best,
     Mark


Attachment: 0001-Add-SCM_LIKELY-and-SCM_UNLIKELY-for-optimization.patch
Description: Add SCM_LIKELY and SCM_UNLIKELY for optimization

Attachment: 0002-Add-two-new-sets-of-fast-quotient-and-remainder-oper.patch
Description: Add two new sets of fast quotient and remainder operators

Attachment: 0003-Improve-extensibility-of-core-numeric-procedures.patch
Description: Improve extensibility of core numeric procedures

Attachment: 0004-Improve-extensibility-of-expt-and-integer-expt.patch
Description: Improve extensibility of `expt' and `integer-expt'

Attachment: guile-matrix.scm
Description: Simple demonstration of `expt' extensibility


reply via email to

[Prev in Thread] Current Thread [Next in Thread]