Copeland-Erdős Constant Digits

Author

Eric W. Weisstein
September 14, 2013

This notebook downloaded from http://mathworld.wolfram.com/notebooks/Constants/Copeland-ErdosConstantDigits.nb.

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

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

Code

CopelandErdos[p_]:=Module[{len=0,ar="",k=1,tmp=1},While[len≤p+IntegerLength[tmp],len+=IntegerLength[tmp=Prime[k++]];ar=StringJoin[ar,IntegerString[tmp]];];
SetPrecision[ToExpression["0."<>ar],p]]

CopelandErdosTermsBrutallySlow[n_]:=Module[{d=Flatten[IntegerDigits/@Prime[Range[n]]]},
SetPrecision[FromDigits[d](10^(-Length[d])),Length[d]]
]

CopelandErdosTerms[n_]:=ToExpression["0."<>StringJoin@@ToString/@Prime[Range[n]]]

Digit Computation

CopelandErdos[20]

CopelandErdosTerms[10]

Development

Total[IntegerLength[Prime[Range[1.6 10^5]]]]//Timing

c1=SetPrecision[CopelandErdosTermsBrutallySlow[1030484],10^6];//Timing

c2=SetPrecision[CopelandErdosTerms[1030484],10^6];//Timing

c3=CopelandErdos[10^6];//Timing

c1==c2==c3

Compute

(10^6)

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

cons=CopelandErdos[10^6+10];//Timing

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

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

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

StringTake[string,10]

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

(10^8)

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

cons=CopelandErdos[10^8+10];//Timing

Total[IntegerLength[Prime[Range[2*^7]]]]//Timing

Total[IntegerLength[Prime[Range[1.2*^7]]]]//Timing

Precision[cons=CopelandErdosTerms[1.2*^7]]//Timing

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

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

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

StringTake[string,10]

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

(10^9)

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

Total[IntegerLength[Prime[Range[1.1*^8]]]]//Timing

Precision[cons=CopelandErdosTerms[1.1*^8]]//Timing

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

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

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

StringTake[string,10]

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

Read from file

Get["/Developer/eww/Constants/E_10_9.mx"];//Timing//AbsoluteTiming

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

Read String from file

Get["/Developer/eww/DigitStrings/E_10_9.mx"];//Timing//AbsoluteTiming

Digit Distribution

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]]

(10^8)

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

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

A224615 to A224818

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

(10^9)

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

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

A224615 to A224818

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

Digit Runs

k n’s

StringLength[string]

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

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

n n’s (Earls Sequence)

A224897

StringLength[string]

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

earls[[All,2]]

Length[earls]

Scan until all n-digits strings have been found

?ScanDigitStrings

A000000

A000000

Length[realdigits=RealDigits[CopelandErdosTerms[10^7],10][[1]]]//Timing

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

First digit string occurrences

A229190

Length[realdigits=RealDigits[CopelandErdosTerms[10^6],10][[1]]]//Timing

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

Take[f,100]

Take[Position[f,0],All]//Flatten

BFile["~/b229190.txt",Take[f,1000],0]

Specific Digits Runs

StringLength[string]

0123456789

StringPosition[string,"0123456789"]//Timing

9876543210

StringPosition[string,"9876543210"]//Timing