# listplot very large numbers

Suppose we have the following function:

NN = 150;
W[n1_] := NN!/(n1 ! (NN - n1!)) (1/2)^n1 (1/2)^(NN - n1)


Then we can Plot or Listplot it:

ListPlot[Table[{n1, W[n1]}, {n1, 1, 10, 0.1}], Joined -> True,
Frame -> True, Axes -> None, BaseStyle -> {FontSize -> 16},
PlotMarkers -> {"\[Bullet]", 10}, PlotStyle -> Red]


If we change NN to 200 or more, then we get the following error:

ListPlot::prng: Value of option PlotRange -> {{0,10.},{-1.341145999799935*10^312,2.466246209857526*10^312}} is not All, Full, Automatic, a positive machine number, or an appropriate list of range specifications. >>

How can we deal with these large numbers in plot?

-
Divide the function by some large exponent, e.g. 10^200, then generate your own tick labels that reverse the scaling. –  ciao Feb 11 '14 at 9:05
The workaround to use is what rasher said. One more thing to mention is that while in general Mathematica can handle arbitrary precision numbers, Plot (and Graphics) will only work with machine precision numbers, i.e. numbers smaller than $MaxMachineNumber. – Szabolcs Feb 11 '14 at 14:39 rasher and Szabolcs, thanks a lot for your answers. – Soodeh Z. Feb 11 '14 at 19:42 I just met the same problem. Shouldn't this be considered a bug? Because the error message that mma gives is completely irrelevant. – Yi Wang Mar 5 '14 at 10:06 This problem has annoyed me for several years -I use the scaling solution but it is a nuisance. Maybe it is worth writing to Wolfram to develop a specialized function for this purpose that does this scaling automatically so the front end plot functions can be used seamlessly. – user20060 Sep 27 '14 at 3:10 ## 2 Answers Plot and more generally Graphics can only handle coordinates that are machine numbers, i.e. in the range $MinMachineNumber to $MaxMachineNumber. On my machine these are of the order$10^{308}\$.

This limitation is probably present because graphics are rendered by the front end (not the kernel which supports arbitrary precision arithmetic).

The simplest solution would be to linearly rescale everything, i.e. divide the numbers by a large value, before plotting. Then you can manually set the Ticks to reflect the unscaled values.

-
I think Plot uses Compile to plot faster, so it uses only machine number.. ? –  DaoTRINH Feb 12 '14 at 16:32
@DaoTRINH Good point. I don't know if it auto-compiles or not. But it also has the WorkingPrecision option, so it can work with arbitrary precision arithmetic, even if it doesn't by default ... This comes useful as a simple brute force solution when there's some cancellation in the formula that eats up precision. –  Szabolcs Feb 12 '14 at 18:01

This is a limitation of Graphics itself. If the PlotRange problem is bypassed we still get an error:

NN = 200;
W[n1_] := NN!/(n1! (NN - n1!)) (1/2)^n1 (1/2)^(NN - n1)
dat = Table[{n1, W[n1]}, {n1, 1, 10, 0.1}];

Graphics[Point @ dat]


This at least indicates that the problem is with the coordinates, but again the error message is less than accurate such obviously that is "a pair of numbers."

Briefly searching I could not find it directly stated in the documentation that Graphics only works with machine size floats. I wonder if such an omission (if true) is sufficient to consider this at least a "documentation bug."

-