Binary Structures and Algorithms in Music
Image Generated by ChatGPT- Homage to M.C. Escher

Binary Structures and Algorithms in Music

I recently found myself going down a lovely rabbit hole in the course of reading Marcus Aurelius’ Meditations, and came across this quote:

If all things performed the same role, it would be like an orchestra where every instrument played the same note continuously—there would be no movement, no creation. When different instruments play separate but harmonious parts, the result is a symphony.

Now, we could spend plenty of time unpacking the substance of what Aurelius was saying here, and I probably will in a journaling session. But when I saw the word symphony in an ancient text that predates anything we think of as a symphony by more than a thousand years, I began researching just what that word would have meant to people of Aurelius’ time and region. I found this:

The ancients emphasized:

  • Monophony or heterophony — not modern harmony, but melody with embellishment or drones.
  • Pythagorean tuning — harmony based on natural ratios (e.g., octave, fifth, fourth).

This re-triggered my pursuit of connections between math/engineering and music. I remember the Pythagorean Theorem from my high school Geometry classes (a fond memory as it was actually pretty easy to grasp). And here his name comes up again in a very useful context!

What Are Pythagorean Ratios?

The Pythagoreans discovered that musical intervals could be expressed as simple whole-number ratios between frequencies. When two tones are played together and their frequencies are in a simple ratio, the result is perceived as consonant (pleasing to the ear).

Article content

These relationships are still foundational in music theory, acoustics, and tuning systems.


Musical Significance

1. Tuning Systems

  • Pythagorean tuning builds scales by stacking perfect fifths (3:2), then reducing them to fit within an octave (modulo 2:1).
  • You can generate a scale by repeatedly multiplying by 3/2 and adjusting back into the 2:1 octave space:

Article content

2. Dissonance vs. Consonance

  • The simpler the ratio, the more consonant the interval: 2:1 (octave), 3:2 (fifth), 5:4 (major third) are harmonious. More complex ratios like 45:32 sound dissonant.
  • This principle ties directly into Fourier analysis and modern signal processing: simple ratios → overlapping harmonics → consonance.


Mathematical Connections

A. Number Theory

  • Ratios like 3:2 and 4:3 are examples of rational numbers.
  • Pythagorean tuning uses the multiplicative group of rational numbers modulo 2 (to stay within octaves).

B. Modular Arithmetic

  • Fitting intervals into a scale (like adjusting every new tone down into the same octave) is mod arithmetic: fmod  2f \mod 2fmod2 (doubling/halving to return to octave space).

C. Logarithms

  • Musical intervals are additive in logarithmic space: An octave is +1 (log₂(2)), a fifth is ~+0.58496 (log₂(3/2)). Equal temperament divides the octave into 12 equal log₂ steps (≈0.08333 per semitone).

D. Group Theory

  • The set of musical intervals forms a cyclic group under modulo-octave addition.
  • Interval transformations (inversion, transposition) mirror group operations in abstract algebra.


Cognitive & Aesthetic Insights

  • Pythagorean tuning reflects how simplicity in math maps to aesthetic pleasure.
  • It lays the groundwork for understanding why music affects us emotionally: overlapping harmonic series reinforces tones and creates perceived stability.

As a guitarist, it makes sense to me, as we find octave harmonics at the halfway point of a string, and more complex harmonics as we divide the string further.

Halving String Lengths = Harmonics = Log₂(n) Structure

When you divide a vibrating string in half, you get an octave above the fundamental:

  • Half length → 2× frequency (1st harmonic = octave)
  • Third → 3× frequency (perfect fifth)
  • Quarter → 4× frequency (2nd octave)

This mirrors how binary search works:

  • Each step in binary search divides the search space in half
  • The number of steps to find an item is log₂(n) — just like the number of harmonics you'd hit moving up the string by halves

Computer Science Concepts That Parallel Harmonics

1. Binary Search and Octave Halving

  • Binary search: Starts with midpoint of a sorted array → cut search space in half each step Time complexity: O(log₂ n)
  • Harmonics on a string: Octaves at ½, ¼, ⅛ length, etc. Frequencies double each time: exponential growth
  • Connection: Each decision (or node in the tree) reduces the “space” by half—whether that’s data or string length.

2. Binary Trees and Harmonic Overtones

  • Each harmonic can be visualized as a node in a binary tree: Root: fundamental (full string) Left child: divide by 2 → octave Right child: divide by 3 → perfect fifth Further branches add complexity
  • Traversal mimics how harmonics stack—structurally and recursively.

3. Fourier Transforms and Frequency Domain Decomposition

  • A waveform can be decomposed into sine wave components (harmonics).
  • This is like recursively decomposing a problem in CS (e.g., merge sort).
  • Fast Fourier Transform (FFT) uses divide and conquer, again yielding O(n log n) performance.

4. Logarithmic Encoding and MIDI

  • MIDI pitch numbers correspond to logarithmic scaling: Each semitone is a multiplication by the 12th root of 2 → reflects log-based scaling
  • Just as data is compressed/stored efficiently using logs (e.g., entropy encoding), music encodes pitch perception logarithmically.

Let’s continue this thought process in my next article, which will demonstrate this important connection see how the binary search algorithm is actually musical in nature, and how we apply that algorithm subconsciously when we listen to music!

Dude - you've reached "Plaid' speed here! LOL Loving your big brain 🤘🏻

To view or add a comment, sign in

More articles by John Fontana

Others also viewed

Explore content categories