Pi Digits

Author

Eric W. Weisstein
February 2, 2022

This notebook downloaded from http://mathworld.wolfram.com/notebooks/Constants/PiDigits.nb.

For more information, see Eric's MathWorld entry http://mathworld.wolfram.com/PiDigits.html.

©2022 Wolfram Research, Inc. except for portions noted otherwise

Compute

Terms

(10^6)

{$MachineName,$TopDirectory,$Version,DateString[]}

pi=N[Pi,1*^6];//Timing

{Precision[pi],{ByteCount[pi],MaxMemoryUsed[]}/10^6.MB}

DumpSave["/Developer/eww/Constants/Pi_10_6.mx",pi];

(10^7)

{$MachineName,$TopDirectory,$Version,DateString[]}

Precision[pi=N[Pi,1*^7]]//Timing

{Precision[pi],{ByteCount[pi],MaxMemoryUsed[]}/10^6.MB}

DumpSave["/Developer/eww/Constants/Pi_10_7.mx",pi];

(10^8)

{$MachineName,$TopDirectory,$Version,DateString[]}

Precision[pi=N[Pi,1*^8]]//Timing

{ByteCount[pi],MaxMemoryUsed[]}/10^6.MB

DumpSave["/Developer/eww/Constants/Pi_10_8.mx",pi];

(10^9)

{$MachineName,$TopDirectory,$Version,DateString[]}

Precision[pi=N[Pi,1*^9]]//Timing

{ByteCount[pi],MaxMemoryUsed[]}/10^9.GB

DumpSave["/Developer/eww/Constants/Pi_10_9.mx",pi];

(10^10)

{$MachineName,$TopDirectory,$Version,DateString[]}

Precision[pi=N[Pi,1*^10]]//Timing

{ByteCount[pi],MaxMemoryUsed[]}/10^9.GB

DumpSave["/Developer/eww/Constants/Pi_10_10.mx",pi];

1.1×(10^10)

{$MachineName,$TopDirectory,$Version,DateString[]}

cons=N[Pi,11*^9];//Timing

{Precision[cons],{ByteCount[cons],MaxMemoryUsed[]}/10^9. GB}

DumpSave["/Developer/eww/Constants/Pi_11_10_9.mx",cons];

StringLength[string=StringTake[ToString[cons],{3,-1}]]//Timing

StringTake[string,10]

{ByteCount[string],MaxMemoryUsed[]}/10^9. GB

DumpSave["/Developer/eww/DigitStrings/Pi_1.1_10_10.mx",string];

2×(10^10)

{$MachineName,$TopDirectory,$Version,DateString[]}//Column

cons=N[Pi,2*^10+10];//Timing

{Precision[cons],{ByteCount[cons],MaxMemoryUsed[]}/10^9. GB}

DumpSave["/Developer/eww/Constants/Pi_2_10_10.mx",cons];

StringLength[string=StringTake[ToString[cons],{3,-3}]]//Timing

StringTake[string,10]

{ByteCount[string],MaxMemoryUsed[]}/10^9. GB

DumpSave["/Developer/eww/DigitStrings/Pi_2_10_10.mx",string];

8×(10^10)

{$MachineName,$TopDirectory,$Version,DateString[]}//Column

cons=N[Pi,8*^10+10];//Timing

{Precision[cons],{ByteCount[cons],MaxMemoryUsed[]}/10^9. GB}

DumpSave["/Developer/eww/Constants/Pi_8_10_10.mx",cons];

StringLength[string=StringTake[ToString[cons],{3,-3}]]//Timing

StringTake[string,10]

{ByteCount[string],MaxMemoryUsed[]}/10^9. GB

DumpSave["/Developer/eww/DigitStrings/Pi_8_10_10.mx",string];

Read from file

Get["/Developer/eww/Constants/Pi_2.0_10_10.mx"];//Timing//AbsoluteTiming

{Precision[cons],ByteCount[cons]/10^9. GB,MaxMemoryUsed[]/10^9.GB}

Compute RealDigits

Length[realdigits=RealDigits[cons,10][[1]]]//Timing

{ByteCount[realdigits],MemoryInUse[],MaxMemoryUsed[]}/10^9.GB

DumpSave["/Developer/eww/RealDigits/Pi_2.0_10_10.mx",realdigits];

Read RealDigits

Plots

Binary Plot

<<Utilities`Plot`

binary represenation of the digits of π

Show[PixelPerfect[BasePlot[RealDigits[Pi,10,255][[1]]],
BlockSize->2]]

decimal digits of π

Show[PixelPerfect[Transpose[Reverse/@(DigitCount[#,10]&/@RealDigits[Pi,10,511][[1]])],
BlockSize->1]]

Base 10 (mod 2)

ArrayPlot[Partition[Mod[First[RealDigits[Pi,10,1600]],2],40],Mesh->True,PixelConstrained->True,ImageSize->200]

ArrayPlot[Partition[Mod[First[RealDigits[22/7,10,1600]],2],40],Mesh->True,PixelConstrained->True,ImageSize->200]

Base 60

RealDigits[2Pi,60,10]

Digit distribution

Kanada

(table=ToExpression/@({Log[10,ToExpression[StringDrop[First[#],-2]]],Drop[Rest[#],-1]}&/@Rest/@(ReadList[StringToStream[#],Word]&/@Select[ReadList["/Volumes/Data/Math/pi-decimal_current.html",String],StringMatchQ[#," TO * 100*"]&])/.s_String:>StringReplace[s,"|"->""]))//ColumnForm

(chisq={#1,Plus@@((#2-10^(#1-1))^2)/10.^(#1-1)}&@@@table)//ColumnForm

P[chsq_,k_]:=((Gamma[(1/2) (-1+k),(chsq/2)])/(Gamma[(1/2) (-1+k)]))

P[#,10]&/@Last/@chisq

2×(10^10) manually partitioning string

StringLength[string]

StringPartition[s_String,chunksize_]:=Module[{len=StringLength[s],k},If[chunksize>len,{s},StringTake[s,#]&/@Table[{1+(k-1) chunksize,Min[len,k chunksize]},{k,Ceiling[len/chunksize]}]]]

BigStringCount[s_,c_,chunksize_:((2^31)-1)]:=Total[StringCount[#,c]&/@StringPartition[s,chunksize]]

(digits=Table[{n,BigStringCount[StringTake[string,10^n],#]&/@CharacterRange["0","9"]},{n,10}])//Timing

Grid[digits,Dividers->All,Alignment->Left]

A224615 to A224818

MapIndexed[{#2[[1]]-1,#}&,Transpose[digits[[All,2]]]]

Digit runs

k n’s

(10^6)

PiStringSmall=StringTake[string,10^6];//Timing

data=Flatten[Table[{d,n,If[#=={},0,First[#]]&/@StringPosition[PiStringSmall,StringJoin@@Table[ToString[d],{n}],10]},{d,0,9},{n,9}],1];//Timing

Grid[data,Dividers->All,Alignment->Left]

1.1×(10^10)

data=Flatten[Table[{d,n,If[#=={},0,First[#]]&/@StringPosition[string,StringJoin@@Table[ToString[d],{n}],10]},{d,0,9},{n,15}],1];//Timing

Grid[DeleteCases[data,{_,_,{}}],Dividers->All,Alignment->Left]

2×(10^10)

StringLength[string]

data=Flatten[Table[{d,n,If[#=={},0,First[#]]&/@StringPosition[string,StringJoin@@Table[ToString[d],{n}],10]},{d,0,9},{n,15}],1];//Timing

Grid[DeleteCases[data,{_,_,{}}],Dividers->All,Alignment->Left]

n n’s (Earls Sequence)

A061073

1.1×(10^10)

StringLength[string]

Cases[data,{x_,x_,s_}:>s[[1]]]

twodig=Table[StringPosition[string,StringJoin@@Table[ToString[n],{n}],1],{n,10,99}];//Timing

twodig

2×(10^10)

StringLength[string]

earls=Cases[data,{x_,x_,s_}:>{x,s[[1]]}]

earls[[All,1]]

StringPosition[string,StringJoin@@Table["10",{10}],1][[All,1]]//Timing

6 (Beast)

666

A083625

StringPosition[string,"666",100][[All,1]]//Timing

n or more 6s

A050285

StringLength[string]

((sixes=Cases[data,{6,x_,s_}:>s])/.{}->{{}})[[All,1]]

just n 6s

A096760

If[#=={},{},#[[1,1]]]&/@Table[StringPosition[string,RegularExpression["[^6]"<>StringJoin@@Table["6",{n}]<>"[^6]"],1],{n,10}]

StringLength[string]

Length/@sixes

sixes

((#/.{a___,x_,y_,b___}:>{a,b}/;Abs[x-y]==1)&/@DeleteCases[sixes,{}])[[All,1]]

Regexps are not 64-bit compatible

If[#=={},{},#[[1,1]]]&/@Table[StringPosition[string,RegularExpression["[^6]"<>StringJoin@@Table["6",{n}]<>"[^6]"],1],{n,12}]

(just6s=If[#=={},{},#[[1,1]]]&/@Table[StringPosition[string,Except["6"]~~StringJoin@@Table["6",{n}]~~Except["6"],1],{n,12}])//Timing

9 (Feynman Point)

A048940

StringLength[string]

(Cases[data,{9,x_,s_}:>s]/.{}->{{}})[[All,1]]

Scan digit strings

A080597/A032510

realdigits=RealDigits[Pi,10,10^7][[1]];//Timing

Do[Print[{n,ScanDigitStrings[realdigits,n]//Timing}],{n,6}]

string="3"<>StringDrop[ToString[N[Pi,10^5]],2];

StringTake[string,10]

Do[Print[{n,ScanDigitStrings[string,n]//Timing}],{n,4}]

First digit string occurrences

A032445

Length[f=FirstDigitOccurrences[realdigits,5]]//Timing

Take[f,100]

Length[f=FirstDigitOccurrences[realdigits,6]]//Timing

Position[f,0]

Specific digits runs

StringLength[string]

0123456789

A101815

StringPosition[string,"0123456789"][[All,1]]//Timing

9876543210

A101816

StringPosition[string,"9876543210"][[All,1]]//Timing

314159

Not in OEIS

Length[s1=StringPosition[string,"314159"][[All,1]]]//Timing

Take[s1,100]

Plouffe digit extraction

https://arxiv.org/abs/2201.12601

pi[n_]:=(((((2(2n)!(((-1))^(n+1)))/(BernoulliB[2n](2^(2n))(1-(2^(-2n)))(1-(3^(-2n)))(1-(5^(-2n)))(1-(7^(-2n)))))))^(1/(2n)))

pis=Table[pi[n],{n,10}]

N[pis,20]

N[Subtract@@@Partition[pis,2,1],20]//N

Table[Round[(10^n)pi[n]],{n,10}]

Table[IntegerPart[10FractionalPart[(10^(n-1))pi[n-1]]],{n,3,20}]

RealDigits[Pi,10,22][[1]]