Can I avoid the overflow which I get with the digits of $f_3(3)$?

185 Views Asked by At

I would like to ananlyze the digits of the number $$f_3(3)$$ which is defined as follows :

Start with $\ n=3\ $ and apply the opration $\ n\cdot 2^n\ $ three times. The first iteration gives $\ 24\ $, the second $\ 2^{27}\cdot 3\ $ and the third $$2^{402653211}\cdot 3$$

This number has $$121\ 210\ 695$$ digits.

Now, the problem arises. If I try to calculate the digit-vector of this number with pari/gp with "$v=digits(n)$", the stack overflows even if I choose my personal maximum stack size (which is $4$ Gigabytes) .

Is there a possibility to access the digits avoiding this overflow-issue ?

1

There are 1 best solutions below

0
On BEST ANSWER

Since you seem to insist on PARI/GP, then just process the digits in chunks. Of course it means that you need to update your algorithm (whatever it will be doing) to be able to work in a sort of streaming fashion - process available chunk of digits (e.g. update statistics), move on to the next chunk, etc... Using following approach, I was able to read the digits with using at about 300MB at the peak:

default(parisize, 600000000) // setting approx 572.205 Mbytes, can be probably lowered
x = 3 * (1 << 402653211);
W = 10000000000;

t = x % W; // store least significant 10 digits to a temporary variable
x = truncate(x/W); // move on to next 10 digits

// now process 10 digits however you want stored in t (at this point t=7722374144)
v = digits(t);

t = x % W; // store least significant 10 digits to a temporary variable
x = truncate(x/W); // move on to next 10 digits

// process further digits (at this point t=2384492819)

...

All these commands were done pretty much instantly, so if you put it into the loop it should be still reasonably fast. Now you can experiment with required memory size and used window size.

Also, I would compare the performance of this approach with just reading digit by digit (basically window size of $10$), it is possible it will be fast enough by itself.