[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re[2]: 1. warnings 2. optimizations
- To: <clisp-list@ma2s2.mathematik.uni-karlsruhe.de>, <clisp-list@ma2s2.mathematik.uni-karlsruhe.de>
- Subject: Re[2]: 1. warnings 2. optimizations
- From: sshteingold@cctrading.com
- Date: Thu, 18 Sep 97 17:25:40 -0500
- Return-receipt-to: <sshteingold@cctrading.com>
A better approach to the treatment of line numbers in CLISP would be
needed for this. But you can customize your ~/.emacs :
Is there a chance that CLISP will learn to treat line numbers in a
more "modern" way? :-)
;; Meta-g :== Meta-x goto-line
(global-set-key "\M-g" 'goto-line)
Errr... M-g is already bound in the standard Emacs. (I use f12 for
goto-line).
> 2. The following 3 functions compute factorial:
> ...
> I would expect more difference between fac0 and (fac1 and fac2) than
> between fac1 and fac2. And I definitely did not expect much difference
> between fac 1 and fac2.
fac0 and fac2 are the same algorithm (they multiply the same numbers in the
same order), just in a different look.
A recent discussion in comp.lang.lisp made me think that a good lisp
compiler should compile tail-recursion to a better code than
iteration. The iterative version of factorial takes one gc more than
the tail-recursive one.
> On a second thought... The reason must be that we get to the bignums
> faster with fac0 and fac2!
You are in the bignums nearly all the time (already after 15 multiplications
out of 10000). That cannot account for a 12% speedup. Think once more.
(Hint: In clisp, the time needed for the multiplication of a fixnum with
a bignum is proportional to the length (in bits) of the bignum and independent
of the smaller factor.)
I see! Interesting.
You might then try these:
(defun fac3 (n)
(labels ((f (a b)
(case (- b a)
(1 b)
(2 (* (- b 1) b))
(3 (* (- b 2) (- b 1) b))
(4 (* (- b 3) (- b 2) (- b 1) b))
(t (let ((m (ash (+ a b) -1))) (* (f a m) (f m b))))
)) )
(if (plusp n) (f 0 n) 1)
) )
I suggest that you submit this to the IOLCC (International Obfuscated
Lisp Code Contest :-)