in reply to Re: probabilistic pi algorithm
in thread probabilistic pi algorithm

hi,

Your ideea is very nice,I thought about it
so if we take $d=2 then the radius which in this case is $d/2=1
so now we can have the formula ($x-1)**2 + ($y-1)**2 <= 1
exactly as you write in your comment.
About the difference between $x*$x and $x**2,what optimisations do you think could be
made ?

Replies are listed 'Best First'.
Re^3: probabilistic pi algorithm
by FunkyMonk (Bishop) on Feb 16, 2008 at 10:07 UTC
    Subroutine calls in Perl are expensive, especially when there's a few million of them, so inline as much as you can.

    Benchmarking 3 variants reveals...

    Rate original multiply powers original 0.405/s -- -72% -76% multiply 1.45/s 257% -- -14% powers 1.69/s 317% 17% --

Re^3: probabilistic pi algorithm
by starbolin (Hermit) on Feb 20, 2008 at 06:35 UTC

    Further optimization is of little value in terms of convergence. The problem is in the random-walk nature of the convergence. While the quotient is guaranteed to eventually converge, over a given interval the quotient can diverge. While convergence is guaranteed the time over which it converges is not guaranteed.


    s//----->\t/;$~="JAPH";s//\r<$~~/;{s|~$~-|-~$~|||s |-$~~|$~~-|||s,<$~~,<~$~,,s,~$~>,$~~>,, $|=1,select$,,$,,$,,1e-1;print;redo}