## The Cantor Function (a.k.a., "the Devil's Staircase")

The Cantor Set

Consider the closed interval [0,1]. The first stage of the construction is to subdivide [0,1] into thirds and remove the interior of the middle third; that is, remove the open interval (1/3,2/3). Each successive step of the construction is then essentially the same. Thus, at the second stage, we subdivide each of the remaining two intervals [0,1/3] and [2/3,1] into thirds and remove their interiors (1/9,2/9) and (7/9,8/9), of their middle thirds. We continue the construction for each of the remaining intervals. The general recursion which describes the construction can be summarized as: Cn=Cn-1/3∪(2/3+Cn-1/3).

The subset of [0,1] which remains after infinitely many such operations is called the Cantor set C: thus, if Ck denotes the union of the intervals left at the k-th stage, then C=∩k->∞ Ck.

Since each Ck is closed, it follows that C is closed. Note that Ck consists of 2k closed intervals, each of length 3-k, and that C contains the endpoints of all these intervals. Any point of C belongs to an interval in Ck for all k and is therefore a limit point of the endpoints of the intervals. Thus C is perfect. Finally, since C is covered by the intervals in any Ck, we have |C|e<=2k3-k for each k. =>|C|e=0.

The Cantor Function

If Dk=[0,1]-Ck, then Dk consists of the 2k-1 intervals Ijk (ordered from left to right) removed in the k stages of construction of the Cantor set. Let fk be the continuous function on [0,1] which satisfies:

1. fk(0)=0.
2. fk(1)=1.
3. fk(x)=j*2-k on Ijk, j=1,...,2k-1.
4. is linear on each interval of Ck.

By construction, each fk is monotone increasing, fk+1=fk on Ijk, j=1,2,...2k-1, and |fk-fk+1|<2-k. Hence, ∑(fk-fk+1) converges uniformly on [0,1] and therefore, {fk} converges uniformly on [0,1]. Let f=limk->∞fk. Then f is monotone increasing and continuous on [0,1] and f(0)=0 and f(1)=1. Furthermore, f is constant on every interval removed in constructing C. This f is called the Cantor-Lebesgue function.

Here are graphs of the Cantor Function, produced with the following Maple code:

> CF:=proc(a,b,c,d,n,x)
> option remember;
> if n=0 then
> solve((d-c)/(b-a)=(y-c)/(x-a),y);
> else #n>0
> piecewise(a<=x and x<=a+1/3*abs(a-b),CF(a,a+1/3*abs(a-b),c,c+1/2*abs(c-d),n-1,x),
b-1/3*abs(a-b)<=x and x<=b, CF(b-1/3*abs(a-b),b,d-1/2*abs(c-d),d,n-1,x),
c+1/2*abs(c-d));
> fi;
> end:
> for n from 0 to 5 do
> plot(CF(0,1,0,1,n,x),x=0..1,numpoints=300);
> od; n=0 n=1 n=2 n=3 n=4 n=5

One can now construct some code to test whether values x in the interval [0,1] belong to the Cantor Set. For example, consider this modified Maple code, based on proc CF, above:

> CS:=proc(a,b,n,x)
> option remember;
> if n=0 then
> 1;
> else
> piecewise(a<=x and x<=a+1/3*abs(a-b),CS(a,a+1/3*abs(a-b),n-1,x),
b-1/3*abs(a-b)<=x and x<=b,CS(b-1/3*abs(a-b),b,n-1,x),
0);
> fi;
> end:

CS is the characteristic function of the Cantor Set, hence CS(0,1,n,x)=1 iff x belongs to the set, and 0 iff x does not belong. Let us test some values:

> CS(0,1,10,1/3);
1

Now let us make the investigation a bit more interesting. We know that the Cantor Set contains only ternary decimals consisting entirely of 0's and 2's. Let us check it directly with the Cantor Set characteristic function:

> b3tob10:=proc(L)
> local s;
> s:=sum(L[nops(L)-i+1]*3^(-i),i=1..nops(L));
> end:

> x:=b3tob10([2,0,0,2,0,2,0,0,0,0,0]); # this is 0.000002020023
> CS(0,1,10,x);
1 #bingo! In Cantor Set

> x:=b3tob10([2,2,2,2,2]); # this is 0.222223
> CS(0,1,10,x);
1 #bingo again!

Check a ternary with at least one 1 in its expansion:
> x:=b3tob10([2,2,2,1,2,0,0]); # this is 0.00212223
> CS(0,1,10,x);
0 # not in Cantor Set

Problems

1. Construct a Maple graph of the Cantor Set based on the code for CS, above.
2. If f(x) denotes the Cantor function on [0,1], show that ∫01f(x)dx=1/2. Hints: First way: Use the Cantor function identity: f(x)=1-f(1-x), which you should first prove. Second way: stare at the graphs! "Dr.Liebermann, head of the mathematics department, orders the installation of new staircases everywhere in the department", Athens, 2009, pen on paper.

Notes

1. From Cartoons.
{"ft_lang_label":"__label__en","ft_lang_prob":0.83854586,"math_prob":0.9955506,"size":3520,"snap":"2021-43-2021-49","text_gpt3_token_len":1222,"char_repetition_ratio":0.13566554,"word_repetition_ratio":0.014732965,"special_character_ratio":0.3536932,"punctuation_ratio":0.19958203,"nsfw_num_words":0,"has_unicode_error":false,"math_prob_llama3":0.9981828,"pos_list":[0,1,2,3,4,5,6,7,8,9,10,11,12,13,14],"im_url_duplicate_count":[null,3,null,3,null,3,null,3,null,3,null,3,null,3,null],"WARC_HEADER":"{\"WARC-Type\":\"response\",\"WARC-Date\":\"2021-10-16T18:44:59Z\",\"WARC-Record-ID\":\"<urn:uuid:f74d28ac-d7e9-4708-bd7b-b0299f73208b>\",\"Content-Length\":\"9635\",\"Content-Type\":\"application/http; msgtype=response\",\"WARC-Warcinfo-ID\":\"<urn:uuid:9fc3ccf9-dbe8-4d03-8fc7-65b732895abd>\",\"WARC-Concurrent-To\":\"<urn:uuid:2edd3afd-e503-42c5-bd20-659ae356ad0c>\",\"WARC-IP-Address\":\"195.170.8.37\",\"WARC-Target-URI\":\"https://ingalidakis.com/math/cantor.html\",\"WARC-Payload-Digest\":\"sha1:X7GGED7Y7RL46UDK2WNJ4NKD66MMWKQC\",\"WARC-Block-Digest\":\"sha1:WMON2L557WE3EEVM55N7J4O6HSJC36ST\",\"WARC-Identified-Payload-Type\":\"text/html\",\"warc_filename\":\"/cc_download/warc_2021/CC-MAIN-2021-43/CC-MAIN-2021-43_segments_1634323584913.24_warc_CC-MAIN-20211016170013-20211016200013-00379.warc.gz\"}"}