// Calculate probability that the nth digit of a number (with certain // properties, like measurements of physical quantities that range over // several orders of magnitude) is the digit d. // // This is generally known as "Benford's Law". prob[n,d] := { if n == 1 return log[1+1/d] sum = 0 for k = 10^(n-2) to 10^(n-1) - 1 sum = sum + log[1 + 1/(10k + d)] return sum }