{
  "schemaVersion": 1,
  "id": "counting-melodies",
  "slug": "counting-melodies",
  "title": "Counting Melodies: Generating Functions, Regular Languages, and the Combinatorics of Pitch, Duration, and Silence",
  "author": "Christopher Yamba",
  "date": "September 2026",
  "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\n$$M_p(q)=\\frac{1-q}{1-(p+2)q+q^2},$$\ngiving the recurrence $a_n=(p+2)a_{n-1}-a_{n-2}$ with $a_0=1$ and $a_1=p+1$. A direct combinatorial formula is also obtained. For a 4/4 bar quantized into sixteen sixteenth-note units and two chromatic octaves ($p=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 subject of Bach's C-minor fugue BWV 847, and outline a Lean 4 formalization. The purpose of the note is both enumerative and conceptual: to show how a musical notation problem turns into a compact piece of combinatorics.\n",
  "version": "v1",
  "status": "author-published-draft",
  "formalization": "incomplete-blueprint",
  "copyright": "© 2026 Christopher Yamba. All rights reserved. Publicly readable; no additional reuse license granted.",
  "files": [
    {
      "name": "counting_melodies.md",
      "sha256": "2a06cdfa58bbd582bcbcaa77b7b5636490366f38d7285e02bd2074de288e1cf5",
      "bytes": 31077
    },
    {
      "name": "counting_melodies.tex",
      "sha256": "7be2b7233073fff933236c00ae56dffa02fb4576dcc810a76763e1d48bae9db0",
      "bytes": 40086
    },
    {
      "name": "counting_melodies.pdf",
      "sha256": "41b5a34e72714c86cd69cadffbf87724c70617eb8b7b2c214b3ac5335a4544e6",
      "bytes": 191989
    },
    {
      "name": "counting_melodies.html",
      "sha256": "568b8d673f4095f510225f963b278c18ae4a7489756bbf5a71f9f25aca7e3db6",
      "bytes": 231948
    },
    {
      "name": "MelodyCounting.lean",
      "sha256": "4265bcc39a0165ee8a02b15817ff3e0eb763a631eb8724e2ce1809887feaace1",
      "bytes": 3377
    },
    {
      "name": "toy_melody_clean.png",
      "sha256": "d36f697272bdd682cde30623d94ec5d8ac9a71fb225991f98aa22a489bf52c7e",
      "bytes": 31150
    },
    {
      "name": "bach_bwv847_subject_clean.png",
      "sha256": "6e3721472409ba8c613e031550754d0d909b892652928f752348e5d907d883d0",
      "bytes": 67179
    },
    {
      "name": "style.css",
      "sha256": "d93f481c923709afc89e13b1258ec75dadae8af004038f130f3585e34e5740a0",
      "bytes": 1717
    },
    {
      "name": "README.md",
      "sha256": "deb87b64601bec999025911cd01df4adeb65f512c81700a98a8b6d19cbae88fc",
      "bytes": 908
    }
  ]
}
