Skip to main content
In the previous tutorial, we marked the values that belong to the Cantor Set using a phase change. This time, let’s do something similar with Fibonacci numbers. Instead of building a pattern, we will start with all the values and mark the ones that are Fibonacci numbers. We will use the same idea as before: a phase change.

Finding the Fibonacci values

Let’s first think about the Fibonacci sequence. Each number is made by adding the two previous numbers. Here, we start with 2 and 3:
So we need a small function that can answer one question: Is this value a Fibonacci number? We can write this function as:
Let’s see what happens inside it. We start with:
We compare a with x. If they are equal, we have found the Fibonacci number we are looking for, so we return True. Otherwise, this line moves us to the next pair of Fibonacci numbers:
So we move through the sequence:
Each new number comes from adding the previous two. We keep going until a is equal to x or becomes larger than it. If it becomes larger without finding x, we return False. For example:
Now we have a simple way to recognize the Fibonacci values.

Marking the Fibonacci values

Next, we need to decide which phase each value should receive. We can write another small Python function for it:
This gives us a very simple rule:
Why use π? Because a phase change of π reverses the direction of an amplitude. So just like in the Cantor Set example, we can think of it as putting a small minus sign on the values we want to mark. We are not removing the other values. We are simply giving the Fibonacci values a different phase.

Starting with the values

Now let’s create our values. We use:
A quint with size=4 gives us:
All the values in u have equal amplitudes, as shown in the debugger:
Debugger showing the values before applying the phase change
So our Fibonacci values in this range are:
Now we have all the values we need. We just need to mark the Fibonacci ones.

Applying the phase

Let’s apply the phase to the Fibonacci values by giving our mark_fib() function to add_phase():
This tells Rhyme to use mark_fib() as the phase function. For each value, the function checks whether it is a Fibonacci number. If it is a Fibonacci number, the value gets phase π. Otherwise, it gets phase 0. So the idea is:
For our quint with size=4, the result is shown in the debugger:
Debugger showing the values after applying the phase change
The Fibonacci values are now marked by phase.

What changed?

We started with all the values:
Then is_fib() told us which ones are Fibonacci numbers. mark_fib() turned that answer into a phase:
Finally, add_phase() applied that rule. We did not build the Fibonacci sequence inside the quint. Instead, we used the sequence to recognize and mark particular values. And just like with the Cantor Set, the important part is the phase change. That’s Fibonacci marking with phase in Rhyme!