Re: Better use of random number generator bits?



James Waldby wrote:
DAC wrote:
"James Waldby" ... wrote ...
Ben Rudiak-Gould wrote:
DAC wrote:
[in "Better use of random number genator bits?" thread]
....
Although for half a minute I thought about writing a program,
I ended up spending about 15 minutes on trial and error with
the bc calculator program to get the above.

Also the 10 9 8 7 6 5 4 3 2 1 multiple isn't very good (only
85% success rate), I have gone for 15bit 10 9 8 7 6 and
7bit 5 4 3 2 1, on average this uses just 232 bits! Very nice.
I am sure there must be some mathetmatical
way to calculate the best distribution of the multiples!

Since this resembles a bin-packing problem (ie, fitting
sums of logs into integer-size bins) I think it would be
difficult to find a conclusive method that performs much
better than exhaustive enumeration. However, dynamic
programming probably can solve it fairly quickly.
....
I meant to say that the dynamic programming approach I was
thinking of doesn't solve the general problem, but instead
just the limited case of grouping adjacent numbers together.

The dynamic programming equation for the minimum cost of
covering numbers from L to R is: cost(L,R) = min (cost(p),
min{j}(cost(L,L+j)+cost(L+j+1,R))), where p is the product
of numbers L, L+1, ... R, and j ranges from 0 to R-L-1, and
obvious boundary conditions. The solution value is cost(1,52).

For example, if your computer does arithmetic with 221-bit
words or larger, the optimal grouping of adjacent numbers
is 1 with 2; 3 by itself; 4 by itself; and 5-52 grouped
together. The expected number of bits used is 227.274,
vs. log_2(52!) ~ 225.581. See http://pat7.com/jp/adj-opti.c
for a program that computes the optimal solutions for word
sizes from 6 bits up to 256 bits, in 0.7 seconds on a 900
MHz machine. For 32-bit words, it shows 243.216 bits
expected, of course not as good as the 232-expected-bits
method mentioned above (where adjacency is not considered).

-jiw
.



Relevant Pages

  • Re: Prediction of local code modifications
    ... cost functions) from the slow main memory to a small but fast memory ... If I understand your question right, the answer is 'dynamic programming'. ... Dynamic programming, which is neither dynamic nor programming, allows ...
    (comp.compilers)
  • Re: Using Excel for statistical analysis - a question for problem-solvers
    ... Well if Var1,Var2,Var3, and Var4 never change then this brute force ... Dynamic programming is not to be confused with computer programming. ... This enumeration is the classic beginners introduction to dynamic ...
    (microsoft.public.excel.programming)
  • Re: Great SWT Program
    ... to the computer variety. ... "Dynamic programming" is a technical term in algorithm ...
    (comp.lang.java.programmer)
  • Re: Recursion Usage and Concepts - Newbie Question
    ... I did all kinds of dynamic programming back in the days of Fortran ... you could handle tracking the history with recursion. ... private Mapsubresults ... ...
    (comp.lang.java.programmer)