Champernowne Constant

Author

Eric W. Weisstein
September 24, 2014

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

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

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

Code

ChampernowneN[b_,n_]:=Module[{d=Flatten[IntegerDigits[#,b]&/@Range[n]]},
SetPrecision[FromDigits[{d,0},b],Length[d]Log[b]/2.]
]

Champernowne2[b_,n_]:=Flatten[IntegerDigits[#,b]&/@Range[n]]
Champernowne[b_,n_:Infinity]:=Sum[Ch[b,k]/b^S[b,k],{k,n}]
Ch[b_,n_]:=Module[{k},Sum[k b^(-n(k-(b^(n-1)-1))),{k,b^(n-1),b^n-1}]]
S[b_,n_]:=Module[{k},Sum[k(b-1)b^(k-1),{k,0,n-1}]]

Built-In

V7

?ChampernowneNumber

ChampernowneNumber[]//N

Value

Base-10

N[ChampernowneNumber[10],1000]

Algorithms

Form the string

1

ChampernowneString1[n_]:=StringJoin@@ToString/@Range[n]

{ByteCount[ChampernowneString1[10^7]],MaxMemoryUsed[]}/10^6. MB//Timing

{ByteCount[ChampernowneString1[10^8]],MaxMemoryUsed[]}/10^9.GB//Timing

Without StringJoin

{ByteCount[ToString/@Range[10^8]],MaxMemoryUsed[]}/10^9.GB//Timing

2

(ToCharacterCode[ToString[#]]&/@Range[20])

FromCharacterCode[{{49,54},{49,55},{49,56}}]

StringJoin@@FromCharacterCode[ToCharacterCode[ToString[#]]&/@Range[20]]

StringJoin@@FromCharacterCode/@(ToCharacterCode[ToString[#]]&/@Range[20])

ChampernowneString2[n_]:=StringJoin@@FromCharacterCode[ToCharacterCode[ToString[#]]&/@Range[n]]

{ByteCount[ChampernowneString2[10^7]],MaxMemoryUsed[]}/10^6. MB//Timing

3

ChampernowneString3[n_]:=StringTake[StringReplace[ToString[Range[n]],", "->""],{2,-2}]

{ByteCount[ChampernowneString3[10^7]],MaxMemoryUsed[]}/10^6. MB//Timing

{ByteCount[ChampernowneString3[10^8]],MaxMemoryUsed[]}/10^9. GB//Timing

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

4

ChampernowneString4[n_]:=Module[{str="",i},
Do[str=StringJoin[str,ToString[i]],{i,n}];
str
]

ChampernowneString4[10]

{ByteCount[ChampernowneString4[10^5]],MaxMemoryUsed[]}/10^6. MB//Timing

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

5

ChampernowneString5[len_,chunksize_:Infinity]:=Module[{ranges,k},
ranges=If[len<chunksize,{{1,len}},Table[{1+(k-1) chunksize,Min[len,k chunksize]},{k,Ceiling[len/chunksize]}]];
StringJoin@@(StringTake[StringReplace[ToString[Range@@#],", "->""],{2,-2}]&/@ranges)
]

ChampernowneString5[20]

{ByteCount[ChampernowneString5[10^7,10^6]],MaxMemoryUsed[]}/10^6. MB//Timing

{ByteCount[ChampernowneString5[10^8,10^7]],MaxMemoryUsed[]}/10^6. MB//Timing

{ByteCount[ChampernowneString5[10^9,10^7]],MaxMemoryUsed[]}/10^6. MB//Timing

Digits

1

ChampernowneDigits1[n_]:=Developer`ToPackedArray[Flatten[IntegerDigits[Range[n]]]]

{ByteCount[dig=ChampernowneDigits1[10^7]],MaxMemoryUsed[]}/10^6. MB//Timing

Integer

1

ChampernowneInteger1[n_]:=FromDigits[ChampernowneString3[n]]

{ByteCount[dig=ChampernowneInteger1[10^7]],MaxMemoryUsed[]}/10^6. MB//Timing

dig//N

2

ChampernowneInteger2[n_]:=FromDigits[Flatten[IntegerDigits[Range[n]]]]

{ByteCount[ChampernowneString2[10^7]],MaxMemoryUsed[]}/10^6. MB//Timing

{ByteCount[ChampernowneString2[10^8]],MaxMemoryUsed[]}/10^9. GB//Timing

Match digit runs

dig=ChampernowneDigits1[10^7];//Timing

Developer`PackedArrayQ[dig]

tally=Developer`ToPackedArray[First[Tally[#]]&/@Split[dig]];//Timing

Partition[{1,2,2,3},2,1]

Take[dig,10]

Position[{1,2,3,4,2,2,34,3},{__,2,2,__},1,1]

StringPosition["hello",{"h","ll"},1]

Analytic Representations

(∑_k^∞)(((∑_(k=(b^(n-1)))^((b^n)-1))k (b^(-n (k-((b^(n-1))-1)))))/(b^((∑_(k=0)^(n-1))(b-1) k (b^(k-1)))))==(∑_(n=1)^∞)(((b^(((b^n) (-b n+n+1)-b)/(b-1))) (b (-(b^(2 n))+(b^n)-1)+((b^(2 n))-(b^n)+b) (b^((b-1) n (b^(n-1))))))/((((b^n)-1))^2))==(ChampernowneNumber[b])

FullSimplify[Ch[b,k],b>0&&k>0&&(b|k)∈Integers]

(b^(S[b,k]))

N[With[{b=2},Sum[((Ch[b,k])/(b^(S[b,k]))),{k,5}]],20]

N[ChampernowneNumber[2],20]

FullSimplify[((Ch[b,n])/(b^(S[b,n]))),b>0&&n>0&&(n|b)∈Integers]

TraditionalForm[%]

TimeConstrained[Sum[(((b^((-b+(b^n) (1+n-b n))/(-1+b))) (b (-1+(b^n)-(b^(2 n)))+(b^((-1+b) (b^(-1+n)) n)) (b-(b^n)+(b^(2 n)))))/(((-1+(b^n)))^2)),{n,∞}],300]//Timing

b==2

N[With[{b=2},Sum[(((b^((-b+(b^n) (1+n-b n))/(-1+b))) (b (-1+(b^n)-(b^(2 n)))+(b^((-1+b) (b^(-1+n)) n)) (b-(b^n)+(b^(2 n)))))/(((-1+(b^n)))^2)),{n,17}]],1000]==ChampernowneNumber[2]

b==10

With[{b=10},Table[(((b^((-b+(b^n) (1+n-b n))/(-1+b))) (b (-1+(b^n)-(b^(2 n)))+(b^((-1+b) (b^(-1+n)) n)) (b-(b^n)+(b^(2 n)))))/(((-1+(b^n)))^2)),{n,2}]]

N[With[{b=10},Sum[(((b^((-b+(b^n) (1+n-b n))/(-1+b))) (b (-1+(b^n)-(b^(2 n)))+(b^((-1+b) (b^(-1+n)) n)) (b-(b^n)+(b^(2 n)))))/(((-1+(b^n)))^2)),{n,5}]],1000]==ChampernowneNumber[]

(∑_(n=1)^∞)(n/(b^(n+(∑_(k=1)^n)(Floor[(Subscript[log, b])(k)]))))==(ChampernowneNumber[b])

n+Sum[Floor[Log[b,k]],{k,n}]

Sum[(n/(b^(n+Sum[Floor[Log[b,k]],{k,n}]))),{n,∞}]//Timing

b==2

With[{b=2},N[Sum[(n/(b^(n+Sum[Floor[Log[b,k]],{k,n}]))),{n,100}],100]]==ChampernowneNumber[2]

b==10

With[{b=10},N[Sum[(n/(b^(n+Sum[Floor[Log[b,k]],{k,n}]))),{n,100}],100]]==ChampernowneNumber[10]