# Mathematica is not responding for very large numbers

So, I am having Mathematica 11.3 and trying to evaluate 2^1,000,000,000.

When I am trying to show the output in its full form to manipulate the digits, Mathematica stops responding.

I am having 32GB of memory so this would not be a problem. Also when I am using Intel's extreme utility to monitor, I find it to always employ 1 kernel out of 8, altho I specifically set it to work with all 8 in the settings and never uses more than 6GB of memory.

• The number 2^1,000,000,000 is not from real life: eg Planck constant^(-1) is 6.626070150(81)*10^34. Nov 30, 2018 at 12:11
• @dimachaerus it does not mean you can throw this expansion at any gui and expect it to be responsive.
– Kuba
Nov 30, 2018 at 12:17
• Also 2^(10^9) has around 3e8 digits. Are you sure 32GB is enough to interactively play with them?
– Kuba
Nov 30, 2018 at 12:21
• For 8 bits= 1 byte a digit, yes I am certain. Also if it ran out of memory it'd show up on the monitor. I am telling you this program never goes further than 6GB of memory and 1 kernel. Nov 30, 2018 at 12:27
• What exactly do you mean by "manipulate the digits"? Nov 30, 2018 at 17:28

The Mathematica kernel can handle such numbers. The following returns immediately; note that I suppressed the output with ;.

var = 2^1000000000;


The issue you are perhaps experiencing is that the front-end takes a long time to format and print the number. This is because it is an Integer

Head@var

Integer


and has a large amount of digits

IntegerLength@var

301029996


and Mathematica fully prints all digits of integers so this will take the front-end some time. You can return a portion of the digits with IntegerDigits; first 10 below.

IntegerDigits[var, 10, 10]

{1, 7, 8, 7, 1, 0, 9, 3, 7, 6}


You can get better print performance using reals instead of integers. The follow returns the print immediately.

var2 = 2.^1000000000

4.612976001169*10^301029995


RealDigits can be used to return digits in this case.

RealDigits[var2, 10, 10]

{{4, 6, 1, 2, 9, 7, 6, 0, 0, 1}, 301029996}


Hope this helps.

• It doesn't help but thanks for the answer. I know all these commands. I am not expecting the output to be any larger than 100MB in size. Nov 30, 2018 at 16:02
• The output, printed, is characters. This is true whether the number is stringified or just printed as digits. There are a billion bits, so around 300 million base ten digits. At one byte per ascii character (the minimum) this gives 300MB. That factor of three vs stated expectation might or might not be an issue. Nov 30, 2018 at 18:03
• Wrong! It's not 1 byte per character (digit here), tho I claimed this in a previous comment to make sense for some people who are here for downvoting only. 10^300,000,000=2^1,000,000,000 approx. so it's 1,000,000,000/8 bytes is 125MB approximately, you do the math...but you may be right after all the notebook's size is 300MB after saving it with the full answer. Nov 30, 2018 at 19:03
• Ascii characters, which are what get used in formatting numbers, occupy a whole number of bytes. And I'm perilously close to awarding this one of my quite rare down votes, and voting to close based on the moving target nature of the question. The number itself is 1.25 MB. I'll put the sizes in my actual response, so that the code for computing them is there. Nov 30, 2018 at 19:10
• @dimachaerus any specific reason for this award? :-) p.s. I was not precise, I didn't mean 300MB is more that 32GB but 3e8 digits is quite a long box which undergoes various processes in a FE. Line breaks, syntax highlighting etc etc. Notebook is more than a simple text editor.
– Kuba
Nov 30, 2018 at 21:28

It is probably a formatting speed issue. Also note that obtaining the digits in base 10 also takes time (it's an O(n log n) algorithm for n the bit length of the number). One way to see that is as below. Notice that getting digits in base 2 is much faster (it's O(n)).

Table[{Timing[IntegerString[2^(10^n)];],
Timing[IntegerString[2^(10^n), 2];]}, {n, 5, 8}]

(* Out= {{{0., Null}, {0., Null}}, {{0.028, Null}, {0.,
Null}}, {{0.396, Null}, {0.008, Null}}, {{6.924, Null}, {0.12,
Null}}} *)


I would expect that IntegerString might format faster than printing the digits directly, but I'm too scared to try on my memory-limited machine.

As for sizes: the number will occupy an eight of a gig, since it is exactly a billion bits.

ee = 2^(10^9);
ByteCount[ee]

(* Out= 125000080 *)


In decimal form, at one byte per character, it will be around 300Mb. This is computed more accurately by any of the means below.

Log[10., 2]*10^9

(* Out= 3.01029995664*10^8 *)

Timing[eeString = IntegerString[ee];]
ByteCount[eeString]
StringLength[eeString]

(* Out= {106.264, Null}

Out= 301030064

Out= 301029996 *)

• I can run this for n=9 with 16 GB of RAM. It takes 98 s on a PC similar in speed to Daniel Lichtblau's. Nov 30, 2018 at 16:36
• That's not what I am asking. To find 2^1,000,000,000 my system takes 0.0468595 s exactly but when I ask Mathematica to show the number in full form: "show all", well it does show it, but then if I want to copy-paste or move the cursor in the evaluated cell, Mathematica halts forever. Nov 30, 2018 at 18:13
• What are the platform specifics? Is it possible you have a 32 bit front end? Also have you tried putting the result into InputForm? This might improve the behavior in terms of manuevering inside the cell. Nov 30, 2018 at 19:02
• No.. Win10 Enterprise x64, 8700k processor. I'll check the InputForm now, might be the answer... Nov 30, 2018 at 19:13
• One possible advantage to the InputForm (sort of implicit in a comment by @Kuba) is that it does not have a BoxData wrapper. This might translate to an easier time moving a cursor into and through the cell. Dec 2, 2018 at 13:23