The Cantor ternary set is a remarkable subset of the real numbers named after German mathematician Georg Cantor who described the set in 1883. It has the same cardinality as , yet it has zero Lebesgue measure.
The set can be constructed recursively by first considering the unit interval . In the next step, we divide the set into three equal parts and discard the open middle set. This leads to the new set . This procedure is repeated on the two remaining subintervals and , and iteratively on all remaining subsets such that . The Cantor set is defined by the limit as , i.e., .
The recursion can be illustrated in python in the following way
import numpy as np def transform_interval(x, scale=1.0, translation=0.0): return tuple(map(lambda z: z * scale + translation, x)) def Cantor(n): if n==0: return {(0,1)} Cleft = set(map(lambda x: transform_interval(x, scale=1/3), Cantor(n-1))) Cright = set(map(lambda x: transform_interval(x, translation=2/3), Cleft)) return Cleft.union(Cright) ...