What is the maximum number that can be used with the following command in mathematica?
Length[IntegerDigits[x!]]
where 'x' is replaced by some finite integer for which the above command reaches its max number.
Then, what is this number?
What is the maximum number that can be used with the following command in mathematica?
Length[IntegerDigits[x!]]
where 'x' is replaced by some finite integer for which the above command reaches its max number.
Then, what is this number?
Length[IntegerDigits[n!]].This is a game we can poke at empirically and draw lines that should hold up to some systematic breakdown invisible from low memory scales. Best to work from the inside out as long as the memory constraints are dominated by outer layers. This is reasonable as IntegerDigits will dominate n!.
I'll assume linear dependence but will fit with higher polynomial to verify small weights of higher orders.
facPlot = ListPlot[facData = Table[{x, ByteCount[x!]}, {x, 1, 10000}]]
facSol = FindFit[facData, facFunc = a + b x + c x^2, {a, b, c, d, e},
x]
{a -> -227.075, b -> 1.37349, c -> 0.000020072, d -> 0., e -> 0.}
Show[Plot[{0, facFunc /. facSol}, {x, 1, 10000}], facPlot]
From the $b$ parameter let's say 1.5 bytes for every $n$ to store $n!$. So if you have 15GB, can estimate $n_{\rm max}(15GB)\sim 10^{10}$.
OK, what about integer digits.
idPlot = ListPlot[
idData = Table[{x, ByteCount[IntegerDigits[x!]]}, {x, 1, 1000}]]
idSol = FindFit[idData,
idFunc = a + b x + c x^2 + d x^3 + e x^4 + f x^5, {a, b, c, d, e,
f}, x]
{a -> 151.424, b -> 6.97385, c -> 0.0667293, d -> -0.000152748, e -> 1.66995*10^-7, f -> -6.67819*10^-11}
Show[Plot[{0, idFunc /. idSol}, {x, 1, 1000}], idPlot]
So let's say 8 bytes per IntegerDigits[n!], so if you had 16GB, $n_{\rm max}\sim 2\times 10^9$ .
Let's look at Length firmly believing that it offers no resource constraints relative to the other expenses.
lPlot = ListPlot[
lData = Table[{x, ByteCount[Length[IntegerDigits[x!]]]}, {x, 1,
5000}]]
We see this isn't going to be the factor, it'll be the integerdigits that's expensive and the memory bound.
Update: I decided to use some sleepy cycles on a large memory machine to verify / see where this breaks down. So far ByteCount measurements remains the same, but I noticed top was fluctuating a fair bit higher.
Wrapping ByteCount with MaxMemoryUsed seems to be giving a more top-related factor (still more or less linear)
MaxMemoryUsed[ByteCount[n!]] through $n\sim 6\times 10^9$ . Data will be hosted and updated here if you want to play with it. MaxMemoryUsed[ByteCount[IntegerDigits[n!]]]
xgrows larger and larger? When willx!be so large that it fills your RAM? Can you estimate the how many digits it will have without callingIntegerDigits? Would theoreticallyLengthhave any problems giving you the number? These are easy questions you can answer yourself when you think about how a number is represented in memory. – halirutan Aug 18 '17 at 12:34IntegerDigits[x!]should fit into the memory, so $\log_{10}x!$ probably should be less (up to a constant) than amount of memory available to the kernel. – Andrew Aug 18 '17 at 12:48$MaxMachineNumberor$MaxNumber, or the number whose factorial hasDeveloper`$MaxMachineIntegerdigits.. – J. M.'s missing motivation Aug 18 '17 at 15:30