Your skill will accomplishwhat the force of many cannot PerlMonks

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

by BrowserUk (Pope)
 on Aug 08, 2005 at 20:45 UTC ( #482026=note: print w/replies, xml ) Need Help??

Because getting accurate answers to this equation takes a very long time unless you use arithmetic methods to reduce the problem.

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.
• Comment on Re^2: Algorithm for cancelling common factors between two lists of multiplicands

Replies are listed 'Best First'.
Re^3: Algorithm for cancelling common factors between two lists of multiplicands
by tmoertel (Chaplain) on Aug 08, 2005 at 22:24 UTC
Can you provide a sample data set (i.e., matrix) that you consider to be "large"? Also, could you give me an idea of how long it takes to compute Pcutoff without using arithmetic optimizations? (I would like to try out a quick Haskell-based implementation I whipped up on a real data set.)

Sure. For the following 2x2:  X Y A 989 9,400 10,389 B 43,300 2.400 45,700 44,289 11,800 56,089

The formula comes out to

```(44,289! 11,800!) (10,389! 45,700!)
-----------------------------------
56,089! 989! 9,400! 43,300! 11,800! 2,400!

Which infinite precision will calculate, but it will be quite slow. And remember, in order to determine if the result is significant, there are 11,000 more of these calculations to perform and these numbers are still relatively small. And, theoretically at least, the FET can be applied to more than a 2x2 matrix.

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.
For this matrix, I can compute the exact Pcutoff in about 1 second (on a 1.6-GHz Celeron laptop). How long does the brute-force approach take?
```[thor@arinmir fishers-exact-test]\$ cat ex1.dat
989 9400
43300 2400

[thor@arinmir fishers-exact-test]\$ time ./fet < ex1.dat > /dev/null
real    0m1.007s
user    0m0.991s
sys     0m0.012s

Quick question: If the sample size is so large, is there a reason you aren't using the Chi-square test? My understanding is Fisher's Exact Test may be preferred when the sample size isn't large enough to reasonably support the large-sample approximation for the Chi-square test. Since you have a large sample, why not take the easy road?
BrowserUk,
Once you have a division math problem of factorials that has been reduced by some factoring method (GCD or prime), it can be reduced even further by substraction.
```47! * 1091!
-----------
55! * 1001!

(1002 .. 1091)
--------------
(48   .. 55)
This is only a savings when the factorial is being calculated by multiplying all the terms and not by some other approximation method.

Cheers - L~R

I am not sure whether approximations are OK for your case. But if it is, have you thought about Stirling's approx and Gosper's approx for factorials?

-SK

Re^3: Algorithm for cancelling common factors between two lists of multiplicands
by jimX11 (Friar) on Aug 09, 2005 at 01:07 UTC

The original problem, framed in terms of arrays, is to reduce a fraction.

The equation above is less general.

The less general problem can be restated as reduce a fraction where the numerator and denominator are both the product of factorials.

An example of the original problem is to reduce
(9 * 8 * 8 * 8 * 6 * 4 )/(5 * 3 * 2)

An example of the factorial problem is to reduce
(9! * 8! * 8! * 8! * 6! * 4! )/(5! * 3! * 2!)

Do I understand correctly, are you are interested in the factorial type of problem?

Re-frame the factorial problem thus:

```( 9 * 8 * 7 * 6 * 5 * 4 * 3 * 2
* 8 * 7 * 6 * 5 * 4 * 3 * 2
* 8 * 7 * 6 * 5 * 4 * 3 * 2
* 8 * 7 * 6 * 5 * 4 * 3 * 2
* 6 * 5 * 4 * 3 * 2
* 4 * 3 * 2 )
/
( 5 * 4 * 3 * 2
* 3 * 2
* 2)

And it reduces to

```( 3 * 4 * 7 * 6 * 5 * 4 * 3 * 2
* 4 * 7 * 6 * 5 * 4 * 3 * 2
* 4 * 7 * 6 * 5 * 4 * 3 * 2
* 2 * 7 * 6 * 5 * 4 * 3 * 2
* 3 * 4 * 3 * 2
* 4 * 3 * 2 )
/
( 1 )

Which eliminates factorials completely (and, in this case the need for division). More importantly and relevantly, it reduces the magnitude of the intermediate terms. In the FET, the scale of this reduction should be considerably more significant than in this example.

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.

Create A New User
Node Status?
node history
Node Type: note [id://482026]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others surveying the Monastery: (5)
As of 2019-10-24 00:19 GMT
Sections?
Information?
Find Nodes?
Leftovers?
Voting Booth?
In 2019 the site I miss most is:

Results (58 votes). Check out past polls.

Notices?