From: verec on
On 2006-08-12 22:28:15 +0100, Wade Humeniuk
<whumeniu+anti+spam(a)telus.net> said:

> This version is better than the last
>
> (defun pi/2-opt ()
> (declare (optimize (speed 3) (safety 0) (debug 0) (float 0)))
> (loop with sum of-type double-float = #.(realpart (+ (exp (- (expt
> -10.0d0 2.0d0)))
> (exp (- (expt
> 10.0d0 2.0d0)))))
> for x of-type double-float from -9.99d0 below 10.0d0 by 0.01d0
> do (incf sum (* 2d0 (exp (- (* x x)))))
> finally (return (* sum 0.005d0))))
>
> CL-USER 1 > (time (dotimes (i 10000) (pi/2-opt)))
> Timing the evaluation of (DOTIMES (I 10000) (PI/2-OPT))
> ; Loading fasl file C:\Program
> Files\Xanalys\LispWorks\lib\4-3-0-0\modules\util\callcoun.fsl
>
> user time = 1.231
> system time = 0.000
> Elapsed time = 0:00:01
> Allocation = 164304 bytes standard / 113113 bytes conses
> 0 Page faults
> Calls to %EVAL 10035

CL-USER 1 > (pi/2-WH)
1.7724538509055174D0

CL-USER 2 > (time (dotimes (i 10000) (pi/2-WH)))
Timing the evaluation of (DOTIMES (I 10000) (PI/2-WH))

....
Elapsed time = 0:00:12
....
CL-USER 4 > (pi/2-WH2)
1.7724538509055174D0

CL-USER 5 > (time (dotimes (i 10000) (pi/2-WH2)))
Timing the evaluation of (DOTIMES (I 10000) (PI/2-WH2))

....
Elapsed time = 0:00:12
....

Thanks Wade!

At 12s for the Lisp version (still with the same LW 4.4,6 PE compiler)
I have no doubt that I now can successfully make my case!

(Though, out of curiosity I'm going to try with SBCL and OpenMCL)

Many thanks
--
JFB

From: Raffael Cavallaro on
On 2006-08-12 15:18:47 -0400, verec <verec(a)mac.com> said:

> Are type-casts supposed to be implementation dependent?
>
> I thought (erroneously?) that (the float XYZ) would
> just drop the imaginary part, precisely because that's
> the purpose of a cast?

Just to be clear, "the" is *not* a type cast - it is a special form
that acts as a type declaration.

(the float (foo ...)) is a special form telling the
compiler/interpreter that you, the programmer, are certain that the
expression beginning (foo ...) will definitely return a float so the
compiler can treat the return of (foo ...) as a float. If you use this
declaration with an expression that returns something other than a
float you are in undefined territory:

"The consequences are undefined if the values yielded by the form are
not of the type specified by value-type."
(from <http://www.lisp.org/HyperSpec/Body/speope_the.html#the>)


The function cl:float takes a real number and an optional prototype for
float format (e.g., 1.0d0) and returns a float of the same format as
the prototype or a single float if no prototype is supplied:

(float 1.0s0 1.0d0)
=> 1.0d0

(float 33/3 1.0d0)
=> 11.0d0

(float 2)
=> 2.0s0

If you want only the real part of a complex number use the function
cl:realpart:

(realpart #C(1.7724538 -7.747651E-8))

=> 1.7724538


From: verec on
On 2006-08-12 23:07:13 +0100, Raffael Cavallaro
<raffaelcavallaro(a)pas-d'espam-s'il-vous-plait-mac.com> said:

> "The consequences are undefined if the values yielded by the form are
> not of the type specified by value-type."
> (from <http://www.lisp.org/HyperSpec/Body/speope_the.html#the>)
>

[...]

> If you want only the real part of a complex number use the function
> cl:realpart:
>
> (realpart #C(1.7724538 -7.747651E-8))
>
> => 1.7724538

Point taken. Many thanks.
--
JFB

From: verec on
On 2006-08-12 22:54:06 +0100, Barry Margolin <barmar(a)alum.mit.edu> said:

> In article <44de2997$0$639$5a6aecb4(a)news.aaisp.net.uk>,
> verec <verec(a)mac.com> wrote:
>
>> I thought (erroneously?) that (the float XYZ) would
>> just drop the imaginary part, precisely because that's
>> the purpose of a cast? Or should I use (coerce ... in
>> addition?
>
> THE is not a type-cast, it is a declaration that the value of the
> expression is known a priori to be of the specified type. It allows
> the compiler to perform type dispatching at compile time rather than at
> run time, but it doesn't perform any conversion to ensure that the
> object is of that type.
>
> So you should write (the float (realpart xyz)).

I knew that when with a hint of a doubt, I should head straight to the CLHS :-)

Many Thanks
--
JFB

From: Glenn.Ehrlich on
Here are some good links on improving numerical computation speed in
Common Lisp:

"On using Common Lisp in scientific computing", by Nicolas Neuss. This
has a pretty good tuturial-level introduction to how to do numerical
optimization in Common Lisp.
http://www.iwr.uni-heidelberg.de/organization/sfb359/PP/Preprint2002-40.ps.gz

"Fast Floating-Point Processing in Common Lisp", by Richard Fateman.
This is a more in-depth treatment.
http://www.cs.berkeley.edu/~fateman/papers/lispfloat.ps

Ken Anderson's Common Lisp Performance page:
http://openmap.bbn.com/~kanderso/performance/

Additionally, here's a listing of math oriented libraries available for
Common Lisp:
http://www.cliki.net/mathematics

Glenn

First  |  Prev  |  Next  |  Last
Pages: 1 2 3 4 5 6 7 8
Prev: static typing
Next: Java is going to have closures.