- The paper introduces Prismriver as a Lean 4 framework, formalizing music theory and enabling algorithmic composition with rigorously verified abstractions.
- It employs algebraic methods and group actions to represent pitches, scales, and chord progressions, ensuring formal equivalence with dihedral group theory.
- The framework integrates interactive composition via monadic constructs for temporal modeling and formally validated counterpoint generation.
Overview
Prismriver offers a comprehensive formalization of music theory leveraging the Lean 4 theorem prover. The library abstracts and encodes core musical concepts—pitches, accidentals, scales, chords, durations, and parts—using parametric and algebraic types, enabling rigorously verified representations and algorithmic composition processes. Prismriver's framework is agnostic to tuning systems and supports both Western heptatonic scales and xenharmonic structures (including quarter tones and alternate fundamental intervals), facilitating analytical and generative tasks far beyond traditional equal temperament conventions.
Mathematical and Computational Representation of Music Theory
Prismriver models the domain of pitches, scales, and intervals using group actions and torsors, formalized through Lean's type class system. Scales are encoded as types with fundamental intervals, where the pitch domain and interval domain interact via abelian additive group actions. This abstraction serves to unify the treatment of scales and tuning systems, supporting arbitrary frequency mappings and lifting representations between pseudo-scales.
A clear separation between note names and accidentals supports the construction of complex enharmonic relationships and tuning system-specific distinctions, bypassing limitations inherent to twelve-tone equal temperament. This enables exact handling of microtonal and non-standard pitch configurations, including infinite enharmonic distinctions and specific exotic intervals such as the "wolf interval" in Pythagorean tuning.
Interval arithmetic is constructed as pairs of name and semitone distances, allowing fine-grained differentiation of augmentations and diminutions—critical for musical property proofs, generative operations, and real-time manipulations in composition and analysis.
Group Actions and Chord Progressions
The paper extends dihedral group action modeling for chord progressions, developing a generalized transpose action framework. Chord transpositions and inversions are realized as group actions (rotations and reflections) on pitch classes and triads, formalized in Lean as compositional transformations. The equivalence between Prismriver's transpose actions and traditional dihedral D12 group actions is formally proven, ensuring both theoretical soundness and practical interoperability for music originating from twelve-tone equal temperament and generalizing to arbitrary scales.
Temporal Representation and Note Construction
Time is abstracted as an ordered abelian additive group, with notes constructed as pitch-duration pairs. This approach supports arbitrary temporal resolution, bar shifting, and negative offsets for preprocessing or analysis tasks. Prismriver allows transparent manipulation of musical objects for compositional workflows, analysis, and export operations, with serializable representations compatible with standard music software ecosystems.
Interactive Music Composition and Output
Prismriver integrates interactive music playback and output serialization. Music can be programmatically composed and played within Lean using Alda backends or exported to MusicXML for interoperability with established notation environments. An extensible Lilypond-like internal DSL facilitates efficient score definition, sequence construction, and manipulation.
Monadic Algorithmic Composition
Algorithmic composition within Prismriver leverages a general state monad (CompositionT), tracking temporal state and event annotations. This monadic architecture allows for flexible, compositional construction of music, including accompaniment generation and structural transformations. Score folding (Score.foldlM) enables event-driven analysis and compositional algorithms, supporting functionally composable workflows for accompaniment and harmonization, all within Lean's proof-oriented environment.
Species counterpoint, particularly first species, is encoded as programmatic constraints representing musical rules (e.g., starting and ending on perfect intervals, restricting allowed leaps and interval movements). Each rule is translated into Lean propositions, and composition is performed by applying combinators and propositional assertions. This approach enables provably correct counterpoint generation, with explicit species rulesets tractable to proof checking and extensible to higher species and more complex constraints.
Numerical Results and Claims
Prismriver demonstrates:
- Provable reduction of music properties across arbitrary tuning systems to 12-tone equal temperament.
- Formal equivalence of generalized transpose actions and dihedral group action (D12) in Lean, verified by theorem-proving.
- Extensible abstraction over pitch, interval, and scale types, supporting arbitrary scale definitions including Bohlen-Pierce and quarter-tone systems.
- Algorithmic composition primitives for monadic score construction, harmonic analysis, and first species counterpoint obeying rule predicates.
Practical and Theoretical Implications
Prismriver establishes a proof-assistant-based approach to music theory, facilitating verifiable algorithmic composition, software interoperability, and advanced musicological analysis. Practically, it enables composers and theorists to encode, analyze, and generate music with formal correctness guarantees, supporting new compositional systems and automated music processing. Theoretically, it lays groundwork for cross-disciplinary research at the intersection of formal methods, abstract algebra, and music informatics.
Future directions include generalizing tuning primitives, expanding external library integrations, formalizing more complex counterpoint species, and supporting broader scale and rhythm systems. This approach underpins rigorous automated reasoning and generative musical processes, informing developments in AI-driven music generation, digital musicology, and verification of creative algorithms.
Conclusion
Prismriver constitutes a sophisticated Lean 4 library for music theory formalization and algorithmic composition, offering compositional, analytical, and output tools grounded in verified mathematical structures. Its abstractions generalize existing music theory representations, enabling robust and extensible music computation, and opening avenues for formalized generative music modeling and advanced theoretical investigation (2606.19936).