Khinchin's Constant Digits

Author

Eric W. Weisstein
September 14, 2013

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

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

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

Initialization

Decimal Digits

N[Khinchin,20]

Timings

Timings for small digits

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

ClearSystemCache[]

Monitor[(timings=Table[Timing[N[Khinchin,n]][[1]],{n,1,1000}]),n];//Timing

timings

g1=ListPlot[timings]

Quadratic

fit=b x^2/.FindFit[timings,b x^2,{a,b},x,Method->"LevenbergMarquardt"]

Show[{Plot[fit,{x,1,1000},PlotStyle->Green],g1}]

Quadratic + Linear

fit={a,b}.{x,x^2}/.FindFit[timings,a x+b x^2,{a,b},x,Method->"LevenbergMarquardt"]

Show[{Plot[fit,{x,1,1000},PlotStyle->Green],g1}]

{#,fit/.x->#}&/@{5000,10000}

Timings for large digits

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

timings={{5000,103.329},{10000,937.7884},{20000,9233.96022},{50000,309248.904}};

logtimings={#[[1]],Log10[#[[2]]]}&/@timings;

g1=ListPlot[logtimings,Joined->True]

Computation

1000

V10

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

Precision[cons=N[Khinchin,1*^3]];//Timing

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

5000

V5.2

n = 1;
While[Timing[TimeConstrained[N[Khinchin, n], 1]][[1, 1]] < .5, n++];
Print[n]

...hangs for 5596 and above...

V6

k=N[Khinchin,5000];//Timing

V9

N[Khinchin,5000];//Timing

V10

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

Precision[cons=N[Khinchin,5*^3]];//Timing

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

10,000

V6

k=N[Khinchin,(10^4)];//Timing

V9

{ByteCount[N[Khinchin,1*^4]]/10^6. MB//Timing,MaxMemoryUsed[]/10^6.MB,$Version,DateString[]}//Column

V10

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

Precision[cons=N[Khinchin,10^4+10]];//Timing

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

20,000

V9

{ByteCount[N[Khinchin,2*^4]]/10^6. MB//Timing,MaxMemoryUsed[]/10^6.MB,$Version,DateString[]}//Column

V10

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

Precision[cons=N[Khinchin,2*^4+10]];//Timing

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

30,000

V9

{ByteCount[N[Khinchin,3*^4]]/10^6. MB//Timing,MaxMemoryUsed[]/10^6.MB,$Version,DateString[]}//Column

40,000

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

Precision[cons=N[Khinchin,5*^4+10]];//Timing

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

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

100,000

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

(cons=N[Khinchin,100000]);//Timing

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

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

150,000

{$Version,$TopDirectory}

(cons=N[Khinchin,150000]);//Timing

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

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

Read from File (110,000 digits)

(* khinchin=Import["http://pi.lacim.uqam.ca/piDATA/khintchine.txt"]; *)

Precision[cons=MathConstant["Khinchin"]]

V5.2 is wrong at digit ~3957

N[N[Khinchin,5000]-khinchin,10]

dig=First/@RealDigits/@{N[Khinchin,5000],khinchin};

Position[Transpose[Take[#,5000]&/@dig],_?(Unequal@@#&),1,1]

Take[#,{3950,3960}]&/@dig

Read Constant

FileNames["/Developer/eww/Constants/Khinchin*"]

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

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

Convert to String

(10^4)

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

StringTake[string,10]

N[Khinchin,10]

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

(10^5)

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

StringTake[string,10]

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

Get String from file

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

Digit Distribution

(10^4)

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

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

A224615 to A224818

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

(10^5)

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

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

A224615 to A224818

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

Digit Runs

k n’s

(10^4)

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

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

(10^5)

StringLength[string]

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

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

n n’s (Earls Sequence)

A224819

(10^4)

StringLength[string]

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

earl[[All,2]]

(10^5)

StringLength[string]

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

earl[[All,2]]

Scan until all n-digits strings have been found

?ScanDigitStrings

A000000/A000000

Length[realdigits=RealDigits[MathConstant["Khinchin"],10][[1]]]//Timing

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

First digit string occurrences

A000000

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

Take[f,100]

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

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

Specific Digits Runs

0123456789

StringLength[string]

StringPosition[string,"0123456789"]//Timing

9876543210

StringLength[string]

StringPosition[string,"9876543210"]//Timing