interfere().
Now let’s use interfere() to build a famous mathematical pattern: the Cantor Set.
(Note: in 1-dimension, this fractal is called the Cantor Set. When we build the same kind of fractal in more dimensions, we call it Cantor Dust. We’re building the 1-dimensional version here, so we’ll call it the Cantor Set from now on.)
What is the Cantor Set?
Let’s start with a line.
0represents the left third.1represents the middle third.2represents the right third.

0 and 2.
For example, at level 2:
0 or 2.
Now let’s see how we can create this pattern in Rhyme.
Building one ternary digit
We start with a single value:nis the total number of ternary digits.iis the position of the digit we are currently processing.- We start counting
ifrom1.
n is 2.
The two digit positions are:
3s place and the second digit represents the 1s place.
For example, if we have three ternary digits, the digit places are 9, 3, and 1.

i-th ternary digit is 1 maps to itself.
We can see this more clearly by looking at the values from 0 to 8.
For the 3s place:
2 * 3 changes the 3s digit from 2 back to 0.
We can implement this using make_digit_pair():
pair() does three things:
x and y differ only in their i-th ternary digit.
For example, when working with the 3s place:
pair(0) returns 6. The 3s digit changes from 0 to 2, while the other digit stays the same.
Similarly:
3s digit changes from 2 back to 0.
If the i-th digit of x is 1, then pair(x) returns x itself, so its amplitude does not change during this step.
We also need to tell interfere() which value comes first in the pair.
lr() tells interfere() that the value with 0 in the current digit position is the left value of the pair.
So for each ternary digit, we have:
0 identified as the left side.
Now we have everything we need.
Building the Cantor Set
Let’s put the pieces together.0. The for loop then processes each ternary digit, starting with i = 1.
For every digit position, we:
- find its ternary place,
- pair
0with2, - identify
0as the left value, - let the paired values interfere.



Looking at the pattern
At level 3, the generated values correspond to these ternary numbers:1.
Every ternary digit is either:
0 and 2 are paired, while a digit 1 does not create a new branch.
There is also a nice pattern in the number of values.
At each new level, every generated value can be extended in two ways:
0s and 2s.
The whole construction
The idea is simple:0 and grow the pattern one ternary digit at a time.
At every position, 0 and 2 form a pair:
1 maps to itself.
Repeating this for every ternary digit generates values whose ternary representation contains only 0s and 2s.
For example, after three levels we get: