Re: help with numeric speed optimization



Thanks to all for your replies. It helped win the case: we're
using Lisp for the project! Yeap! BTW: the math guy apologized:
the reason that the initial pi/2 wasn't very accurate (15% off
or so) is that the formula he gave me was for (sqrt pi), not
(/ pi 2) ...

CL-USER 11 > (defun pi/2-opt4 () ;;; formula for (sqrt pi) not for (/ pi 2) !!
(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 (- (realpart (expt x 2.0d0))))))
finally (return (* sum 0.005d0))))

CL-USER 12 > (pi/2-opt4)
1.7724538509055174D0

CL-USER 13 > (sqrt pi)
1.7724538509055159D0

CL-USER 14 > (/ pi 2)
1.5707963267948966D0

Many thanks again.
--
JFB

.



Relevant Pages

  • Re: Re-opening an existing module and changing a method
    ... I'm trying to hack at the math module. ... convert sqrt into an method of the Math module. ... "Module functions are copies of the original, ... NoMethodError: super: no superclass method `sqrt' ...
    (comp.lang.ruby)
  • Re: pythagorean triples exercise
    ... from math import sqrt ... This version assumes that if a*a+b*c is an exact square of an integer, ... the floating point sqrt will be an exact integral value, ... Only a has an upper limit of 200. ...
    (comp.lang.python)
  • Re: pythagorean triples exercise
    ... from math import sqrt ... This version assumes that if a*a+b*c is an exact square of an integer, ... the floating point sqrt will be an exact integral value, ... Only 'a' has an upper limit of 200. ...
    (comp.lang.python)
  • Re: Re-opening an existing module and changing a method
    ... I'm trying to hack at the math module. ... The problem is that mathn is using the module_function method to ... convert sqrt into an method of the Math module. ... NoMethodError: super: no superclass method `sqrt' ...
    (comp.lang.ruby)
  • how to overload sqrt in a module?
    ... I would like to write a module that provides some mathematical functions on top of those defined in math, cmath etc. but I would like to make it work with "any" type that overloads the math functions. ... I understand why sqrt is not in scope, but my question is: what is the best way to do this? ... def g: ... because of the special member __abs__ attached to the type. ...
    (comp.lang.python)