guile-devel
[Top][All Lists]
Advanced

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

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


From: Mark H Weaver
Subject: Re: [PATCH] Fast R6RS div/mod; improved extensibility of numerics
Date: Mon, 31 Jan 2011 12:35:49 -0500
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/23.1 (gnu/linux)

Andy Wingo <address@hidden> writes:
>> 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 `*'.
>
> To me this is fine, in principle; but I wonder about causing `(expt #t
> 0)' to produce 1.  It seems that in any case the range of the output
> should be continuous -- i.e. if (expt <my-matrix> 1) produces a matrix,
> and (expt <my-matrix> n) for n > 1 makes a matrix, then (expt
> <my-matrix> 0) should also produce a matrix.  Or no?

When using generic arithmetic operators, there's no way to return
objects of the correct type in all corner cases like this.

Since (expt <obj> N) for exact non-negative integer N may be defined as
(* <obj> <obj> <obj> ...) with N arguments, then what you are proposing
is essentially equivalent to this:

 (* <my-matrix> <my-matrix>) yields a matrix, and
 (* <my-matrix>) yields a matrix, therefore
 (*) should also yield a matrix.

Obviously there's no way to do this with a generic `*' operator.  In
fact, you can't even do it with a special `matrix*' operator, because it
wouldn't know what size the matrix should be.  You'd need a distinct `*'
operator for each size.  With tensors it gets even more hairy.
Similarly for `+' and `-'.

To avoid these complications, it is conventional to allow 1 to stand for
any multiplicative identity and for 0 to stand for any additive
identity.  Furthermore, it is convenient to allow any scalar to be
interpreted as the relevant multiplicative identity times that scalar.

     Best,
      Mark



reply via email to

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