The formal definition of the algorithm is as follows for two positive integers x and y:
(2) if z = 0 return y
(3) if z ≠ 0 set x = y and set y = z then repeat from step 1
You may wonder what this has to do with music and Cuban salsa specifically. The answer lies in a discovery that Godfried Toussaint made in 2014 which he called Euclidean Rhythms. To illustrate this beautiful example of how maths relates to music let us consider an example of where we are trying to find the GCD of 8 and 5 which can be done using Euclid’s algorithm as per the following steps:
(1) x = 8, y = 5
(2) z = 8 mod 5 = 3
(3) z ≠ 0 ∴ x = 5, y = 3
(4) z = 5 mod 3 = 2
(5) z ≠ 0 ∴ x = 3, y = 2
(6) z = 3 mod 2 = 1
(7) z ≠ 0 ∴ x = 2, y = 1
(8) z = 2 mod 1 = 0
(9) z = 0 ∴ GCD = 1
This algorithm shows that the GCD between 8 and 5 is 1 which is a rather simple example of the algorithm in practice and not very interesting mathematically. However, when we consider each step the algorithm takes (numbered 1 to 9 in the example above) we can see some surprising similarities to the problem of trying to distribute 3 onsets as evenly as possible across an 8 pulse structure. More on this to follow in the next post of the Tresillo blog series.