Cantor String Generator
Generate Cantor set ternary strings and visualize fractal iterations. Build strings of length 3^n by recursive middle-third removal.
About
The Cantor set is constructed by iteratively deleting the open middle third of every remaining line segment, starting from the unit interval [0, 1]. After n iterations the set's indicator string has length 3n, where 1 marks retained segments and 0 marks removed gaps. The resulting object is a nowhere-dense, uncountable set of Lebesgue measure zero. Miscounting iterations or misunderstanding the recursion leads to incorrect fractal dimension estimates; the Hausdorff dimension is exactly log 2log 3 ≈ 0.6309. This tool generates the precise binary indicator string and renders each stage so you can inspect the fractal structure directly.
The generator caps at n = 10 iterations (59,049 characters). This limit is practical, not theoretical. The substitution rule is exact: every 1 ā 101, every 0 ā 000. No approximation is involved.
Formulas
The Cantor string is built by a substitution system applied to an initial axiom. The axiom is the single character 1. At each iteration, two production rules fire simultaneously across the entire string:
After n iterations the string length is 3n and the count of 1s is 2n. The remaining measure (fraction of 1s) at iteration n is:
As n ā ā, M ā 0. The Hausdorff dimension of the limiting Cantor set is:
Where dH is the Hausdorff dimension, 2 is the number of self-similar pieces per iteration, and 3 is the scaling factor (each piece is 13 the size of its parent).
Reference Data
| Iteration n | String Length 3n | Filled Segments (2n) | Removed Gaps | Measure Remaining | String Preview |
|---|---|---|---|---|---|
| 0 | 1 | 1 | 0 | 1 | 1 |
| 1 | 3 | 2 | 1 | 23 | 101 |
| 2 | 9 | 4 | 5 | 49 | 101000101 |
| 3 | 27 | 8 | 19 | 827 | 101000101000000000101000101 |
| 4 | 81 | 16 | 65 | 1681 | (81 chars) |
| 5 | 243 | 32 | 211 | 32243 | (243 chars) |
| 6 | 729 | 64 | 665 | 64729 | (729 chars) |
| 7 | 2,187 | 128 | 2,059 | 1282187 | (2,187 chars) |
| 8 | 6,561 | 256 | 6,305 | 2566561 | (6,561 chars) |
| 9 | 19,683 | 512 | 19,171 | 51219683 | (19,683 chars) |
| 10 | 59,049 | 1,024 | 58,025 | 102459049 | (59,049 chars) |