VOL. 01 / SEPTEMBER 2026Open access
FEATURED RESEARCHAUTHOR-PUBLISHED DRAFT · V2

Counting Melodies

Generating Functions, Regular Languages, and the Combinatorics of Pitch, Duration, and Silence

Explore the interactive lab
Download original files

The revised manuscript, with engraved scores, ribbon and Young diagrams, the complete catalogue of 32 rhythms, and an interactive companion.

Draft status and mathematical attributionThe manuscript’s attribution, novelty qualifications, and incomplete Lean formalization remain unchanged. All diagrams and scores below come from the supplied revision 2. The interactive companion is a separate exploration.
Original file checksums
Open PDF ↗
Counting Melodies, original page 1 of 22. Text transcript follows below.

Page 1 of 22 · Original supplied PDF · No editorial changes

Extracted text for this page

Text extraction may omit or reorder mathematical symbols. The page image and original download preserve the visible notation.

Counting Melodies: Generating Functions, Regular Languages,
and the Combinatorics of Pitch, Duration, and Silence
Christopher Yamba
September 2026
Revision 2 — 2026-09-20
Abstract
We study a deliberately small but musically natural enumeration problem: how many
monophonic melodies of fixed total duration can be written when notes carry pitch, rests
carry no pitch, durations are integer multiples of a smallest temporal unit, and adjacent
rests are identified with the single rest obtained by merging them? The model leads
naturally to integer compositions, regular languages, and ordinary generating functions.
For a pitch alphabet of size p and unrestricted positive integral event durations, the
generating function reduces to a rational function
𝑀𝑝(𝑞) = 1 − 𝑞
1 − (𝑝 + 2)𝑞 + 𝑞2 ,
giving the recurrence 𝑎𝑛 = (𝑝 + 2)𝑎𝑛−1 − 𝑎𝑛−2 with 𝑎0 = 1 and 𝑎1 = 𝑝 + 1. A direct combi-
natorial formula is also obtained. For a 4/4 bar quantized into sixteen sixteenth-note units
and two chromatic octaves ( 𝑝 = 24 ), the model gives 41, 006, 928, 746, 285, 492, 812, 225
admissible melodies. We then lift the commutative counting series to a noncommutative
formal series that retains individual melodic identity, illustrate the encoding on the sub-
ject of Bach’s C-minor fugue BWV 847 with engraved scores, ribbon, Young and Ferrers
diagrams, and outline a Lean 4 formalization. The purpose of the note is both enumera-
tive and conceptual: to show how a musical notation problem turns into a compact piece
of combinatorics.
1. The question
A bar of music looks finite. The staff has a fixed width; a time signature fixes a duration; a
chosen smallest note value fixes a temporal grid. Yet even in a monophonic line, the number of
possible bars becomes enormous as soon as rhythm, silence, and pitch are allowed to interact.
The point of this note is not to claim that a melody is exhausted by pitch and duration.
It plainly is not. Articulation, dynamics, phrasing, harmony, timbre, voice leading, meter,
notation, and musical expectation all matter. The point is narrower and, mathematically,
cleaner:
Given a fixed amount of time, how many legal monophonic event se-
quences are possible under a specified set of notation rules?
The problem began from a very concrete representation. Take a 4/4 bar, measure time in
sixteenths, and write the bar initially as sixteen atomic temporal units. Grouping consecutive
units creates event durations. If order matters, these groupings are compositions rather than
partitions. Pitch then colors note events, while rests behave differently: two adjacent rests
are not musically distinct from their merged rest in the duration model used here.
1