Papers
Topics
Authors
Recent
Search
2000 character limit reached

Prismriver in Lean 4: Formal Music Theory & Composition

Updated 4 July 2026
  • Prismriver is a domain-specific library in Lean 4 that formalizes music theory concepts using dependently typed structures.
  • It enables verifiable algorithmic composition and counterpoint generation by embedding musical rules as machine-checked proofs.
  • The framework models classical notions such as dihedral group actions and torsors, ensuring rigor in computational music analysis and composition.

Searching arXiv for the specified paper to ground the article in the source metadata. Prismriver is a domain-specific library and embedded language in Lean 4 for music theory, analysis, and algorithmic composition. It formalizes pitches, intervals, scales, chords, transposition, counterpoint, part assignments, and durations in a dependently typed setting, with the stated goals of capturing the mathematical essence of music theory and leveraging that formalization for verifiable, extensible algorithmic composition and accompaniment generation. The system is presented as a framework in which classical theorems of music theory can be verified and composition algorithms can be made correct-by-construction, while interoperating with MIDI, MusicXML, and Alda for playback and export (Aniva et al., 18 Jun 2026).

1. Definition, scope, and stated objectives

Prismriver’s primary goal is explicitly two-fold. First, it formalizes notes, accidentals, intervals, scales, chords, part assignments, and durations in Lean 4. Second, it uses that formalization as a basis for verifiable and extensible algorithmic composition, including accompaniment, counterpoint, and monadic score generators, with interoperability for MIDI, MusicXML, and Alda (Aniva et al., 18 Jun 2026).

The project is motivated by the claim that nearly every core notion in music carries algebraic structure, specifically including torsors, abelian groups, and dihedral-group actions. In Prismriver, these structures are not treated as informal analogies but as objects of formal proof. This design links music-theoretic reasoning to interactive theorem proving: one can represent a score, express compositional rules as propositions, and discharge proof obligations within Lean.

The abstract also states that Prismriver opens the door to verifiable algorithmic composition and accompaniment generation and enables the analysis of monadic analysis of structures in music (Aniva et al., 18 Jun 2026). A plausible implication is that the project is intended not merely as a notation library, but as a formal substrate for both compositional construction and proof-oriented analytical work.

2. Algebraic representation of pitch, interval, and scale

The foundational abstraction is the Lean type class class PseudoScale (P : Type), where the elements of P represent pitches in an arbitrary tuning system (Aniva et al., 18 Jun 2026). A true Scale extends this idea by equipping a PseudoScale P with an index type I of intervals satisfying two requirements: I is an additive abelian group, and there is a group action * : I → P → P making P into an I-torsor. In the paper’s presentation, this supports the notation p+ip + i for transposition of a pitch pp by an interval ii, while pitch subtraction yields intervals.

The familiar 12-tone equal-temperament system is recovered concretely by taking

Peq=ZP_{\mathrm{eq}} = \mathbb{Z}

for MIDI-style pitch numbers,

Ieq=Z/12ZI_{\mathrm{eq}} = \mathbb{Z}/12\mathbb{Z}

for semitone intervals modulo 12, and fundamental interval 1eq=121_{\mathrm{eq}} = 12 (Aniva et al., 18 Jun 2026). Enharmonic equivalence, such as C\mathrm{C}\sharp versus D\mathrm{D}\flat, is described as emerging as the orbit under IeqI_{\mathrm{eq}}.

For Western classical music with explicit note names and accidentals, Prismriver instantiates the following structures: ii9 In this representation, an interval stores both its diatonic name-distance nn and its semitone-count pp0 (Aniva et al., 18 Jun 2026). The stated significance of this separation is that it permits modeling non-equal-temperaments and xenharmonic systems, including Bohlen–Pierce and quarter-tones, by choosing a different group pp1 or base pp2. This directly counters a common misconception that a formal music-theory library in Lean would necessarily be confined to 12-tone equal temperament.

3. Symmetry, transposition, and generalized dihedral actions

Prismriver’s formal machinery is organized around two algebraic pillars. The first is the Scale class, which axiomatizes that pp3 is an AddCommGroup with zero pp4, together with scalar multiplication by integers, negation, subtraction, and a list of natural pitches in one fundamental interval, such as those for C major (Aniva et al., 18 Jun 2026). The second is a generalized treatment of transposition and inversion through dihedral-type actions.

Any transposition or inversion of pitches is encoded by the inductive type Peq=ZP_{\mathrm{eq}} = \mathbb{Z}0 Prismriver then proves in Lean that the four possible compositions satisfy the following relations: pp5

pp6

pp7

pp8

where pp9 denotes pitch subtraction yielding an interval, and ii0 uses the group structure on ii1 (Aniva et al., 18 Jun 2026).

A centerpiece theorem relates this abstract TransposeAction on Pitch and Interval to the classical action of the dihedral group ii2 on 12-tone pitch classes ii3. Lean code defines a lift Peq=ZP_{\mathrm{eq}} = \mathbb{Z}1 and proves that for every ii4 and every pitch-class triad ii5 with major/minor parity,

ii6

where ii7 flips parity precisely for inversions (Aniva et al., 18 Jun 2026). The paper describes this theorem as machine-checked and presents it as establishing the duality between abstract scale theory and the classical neo-Riemannian/ii8 viewpoint associated with Crans–Fiore–Satyendra.

4. Verifiable algorithmic composition and counterpoint

On top of the representation library, Prismriver provides a CompositionT monad, described as a free monad over time-cursor movements, note addition, and event addition (Aniva et al., 18 Jun 2026). This permits composition routines to be written in Lean do-notation while simultaneously supporting proofs of invariants about the resulting musical objects. The paper gives the following example: Peq=ZP_{\mathrm{eq}} = \mathbb{Z}2 This code can be executed via Lean’s #play directive, targeting Alda for real-time playback, or compiled to MusicXML or MIDI for use by external tools (Aniva et al., 18 Jun 2026).

Prismriver also includes a counterpoint-composition framework. First-species rules are encoded as Prop-valued predicates on pairs of voice lists. The rules listed in the paper are: start and end on octave or unison, only consonant vertical intervals, allowed leaps, contrary motion into the finale, no repeated notes, and no hidden fifths or tritones (Aniva et al., 18 Jun 2026). A proof that generated counterpoint satisfies isFirstSpecies is described as a routine Lean proof obtained by unfolding definitions.

This arrangement places compositional correctness inside the proof assistant rather than outside it. In practical terms, a score generator is not merely a producer of candidate outputs; it can be coupled to machine-checked guarantees about contrapuntal admissibility or intervallic properties. This suggests an overview of algorithmic composition and formal verification in which rule systems are executable and provable in the same environment.

5. Library organization and workflow

Prismriver is organized into representation, theory, composition, and examples components (Aniva et al., 18 Jun 2026).

Module path Contents
Prismriver.Repr Scale.lean, Classical.lean, Dihedral.lean
Prismriver.Theory Dihedral.lean, transposition theorems
Prismriver.Composition CompositionT, score analysis, Counterpoint.lean
examples/ Necrofantasia.lean, CounterpointExample.lean

The paper also gives a typical workflow. One imports Prismriver, opens Prismriver.Repr.Classical, defines pitches or scores either as Lean expressions or with a Lilypad-style syntax, proves theorems about the composition, and exports to MusicXML. The specific sequence presented is:

  1. import Prismriver
  2. open Prismriver.Repr.Classical
  3. define pitches or score via Lean expressions or the Lilypad-style syntax: Peq=ZP_{\mathrm{eq}} = \mathbb{Z}3
  4. prove theorems about the composition: Peq=ZP_{\mathrm{eq}} = \mathbb{Z}4
  5. export to MusicXML via runCmd (exportMusicXML “my_score.xml”) (Aniva et al., 18 Jun 2026)

The coexistence of an internal proof workflow and external output targets is central to the library’s architecture. Prismriver is not presented solely as a formal semantics for music-theoretic objects, nor solely as a score-generation tool; rather, it combines theorem-proving infrastructure with practical interchange formats.

6. Significance, extensibility, and proposed directions

The paper identifies four principal benefits of embedding music theory within a proof assistant. The first is formal guarantees: a proposition such as “every interval in this chord progression is consonant” can be proved in Lean. The second is extensibility: quarter-tone accidentals, Pythagorean tuning, and entirely new scales such as Bohlen–Pierce can be introduced by supplying new instances of the Scale and Interval classes. The third is a reusable library in a Mathlib-style repository, allowing proof patterns about dihedral compositions, counterpoint rules, and part-writing invariants to accumulate for future music-theoretic research. The fourth is pedagogical tooling, because students can hear generated output through #play while inspecting proof obligations corresponding to classical compositional rules (Aniva et al., 18 Jun 2026).

Potential extensions listed in the paper include integrating stochastic processes through Markov-chain-based composition, richer species-counterpoint monads, automated search using SMT or tactics for chord progressions satisfying specified criteria, and formalization of twentieth-century techniques such as set theory and serialism (Aniva et al., 18 Jun 2026). These proposals are future directions rather than implemented features.

Prismriver therefore occupies a technically specific position at the intersection of formal methods, computational music theory, and algorithmic composition. Its contribution is not only to encode musical objects, but to express their transformations, constraints, and compositional procedures in a framework where proofs and generated musical artifacts coexist. The paper’s concluding claim is that classical music theory and modern formal methods can illuminate one another, yielding verifiably correct musical artifacts and a platform for future work in computer-aided composition (Aniva et al., 18 Jun 2026).

Definition Search Book Streamline Icon: https://streamlinehq.com
References (1)

Topic to Video (Beta)

No one has generated a video about this topic yet.

Whiteboard

No one has generated a whiteboard explanation for this topic yet.

Follow Topic

Get notified by email when new papers are published related to Prismriver.