So, now I've got my "schoolboy approach" working, care to point me at the methods clever people would use?
I was too lazy to look before, but now that I have, I was a bit off. On the other hand, I snuck in something similar in step 5 anyway. Here's what I remembered when I said that:
In QOTW #2 MJD considers the n_choose_k function that computes:
sub n_choose_k {
my ($n, $k) = @_;
# f($n) = $n!
return f($n)/f($k)/f($n-$k);
}
He notes that the intermediate values are very large, even though the final result is not. He submits this replacement:
sub n_choose_k {
my ($n, $k) = @_;
my $t = 1;
for my $i (1 .. $k) {
$t *= $n - $k + $i;
$t /= $i;
}
return $t;
}
and he notes:
$t here is always an integer, and never gets bigger than necessary.
For your formula, this only applies to a small portion of the terms. You may be better off just ignoring MJD's improvement and proceeding as I outlined before.
-QM
--
Quantum Mechanics: The dreams stuff is made of
-
Are you posting in the right place? Check out Where do I post X? to know for sure.
-
Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
<code> <a> <b> <big>
<blockquote> <br /> <dd>
<dl> <dt> <em> <font>
<h1> <h2> <h3> <h4>
<h5> <h6> <hr /> <i>
<li> <nbsp> <ol> <p>
<small> <strike> <strong>
<sub> <sup> <table>
<td> <th> <tr> <tt>
<u> <ul>
-
Snippets of code should be wrapped in
<code> tags not
<pre> tags. In fact, <pre>
tags should generally be avoided. If they must
be used, extreme care should be
taken to ensure that their contents do not
have long lines (<70 chars), in order to prevent
horizontal scrolling (and possible janitor
intervention).
-
Want more info? How to link
or How to display code and escape characters
are good places to start.
|