Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number
 
PerlMonks  

Re: Algorithm for cancelling common factors between two lists of multiplicands

by tlm (Prior)
on Aug 09, 2005 at 01:17 UTC ( #482085=note: print w/ replies, xml ) Need Help??


in reply to Algorithm for cancelling common factors between two lists of multiplicands

Memoize the logs of the factorials.

BTW, I posted some FET code earlier that does just that; if there's something wrong with it, please let me know.

the lowliest monk


Comment on Re: Algorithm for cancelling common factors between two lists of multiplicands
Re^2: Algorithm for cancelling common factors between two lists of multiplicands
by BrowserUk (Pope) on Aug 09, 2005 at 01:25 UTC

    Try it. You'll find that doing combinatorial math with logs of factorials rapidly introduces large errors. For an example see Re^4: Fastest way to calculate hypergeometric distribution probabilities (i.e. BIG factorials)?. That's just one. Once you start adding them together the inaccuracies multiply.


    Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
    Lingua non convalesco, consenesco et abolesco. -- Rule 1 has a caveat! -- Who broke the cabal?
    "Science is about questioning the status quo. Questioning authority".
    The "good enough" maybe good enough for the now, and perfection maybe unobtainable, but that should not preclude us from striving for perfection, when time, circumstance or desire allow.
Re^2: Algorithm for cancelling common factors between two lists of multiplicands
by BrowserUk (Pope) on Aug 10, 2005 at 00:41 UTC
    BTW, I posted some FET code earlier that does just that; if there's something wrong with it, please let me know.

    Trying your code with these inputs

    print Fishers_Exact::fishers_exact( 989, 9400, 43300, 2400 );

    I get these results:

    P:\test>FET-tlm.pl 0.99999999999999999999999999999999999999999999999[... 950 9s truncated +] 9999999999999999999999999999999999999999999999999[... 950 9s truncated +] 9999999999999999999999999999999999999999999999999[... 950 9s truncated +] 9999999999999999999999999999999999999999999999999[... 950 9s truncated +] 9999999999999999999999999999999999999999999999999[... 950 9s truncated +] 9999999999999999999999999999999999999999999999999[... 950 9s truncated +] 9999999999999999999999999999999999999999999999999[... 950 9s truncated +] 99999999999999999999999999999999952665545273822897512768877675 1 trial of _default ( 1.385s total), 1.385s/trial

    Now, given that your code needs Math::Pari, and the "simple" solution using that module produced the correct answer in 26ms, I can't help wonder what all that messing around with Stirling and Gosper approximations bought you?

    I also think that if you are going to require exporter, you might as well let it do it's job and skip all that autoload stuff. And I personally find that littering your code with a dozen BEGIN{} blocks makes it very hard to follow.


    Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
    Lingua non convalesco, consenesco et abolesco. -- Rule 1 has a caveat! -- Who broke the cabal?
    "Science is about questioning the status quo. Questioning authority".
    The "good enough" maybe good enough for the now, and perfection maybe unobtainable, but that should not preclude us from striving for perfection, when time, circumstance or desire allow.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://482085]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others studying the Monastery: (14)
As of 2014-10-24 16:31 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    For retirement, I am banking on:










    Results (133 votes), past polls