[{"data":1,"prerenderedAt":-1},["ShallowReactive",2],{"doc-detail-85633-en":3,"doc-seo-85633-105":30,"detail-sidebar-cat-0-en-105":91},{"code":4,"msg":5,"data":6},0,"success",{"doc_id":7,"user_id":8,"nickname":9,"user_avatar":10,"doc_module":4,"category_id":11,"category_name":12,"doc_title":13,"doc_description":14,"doc_content":15,"file_id":16,"file_url":17,"file_type":18,"file_size":19,"view_count":20,"is_deleted":4,"is_public":21,"is_downloadable":21,"audit_status":21,"page_count":22,"language":23,"language_code":24,"site_id":25,"html_lang":24,"table_of_contents":26,"faqs":27,"seo_title":13,"seo_description":14,"update_tm":28,"read_time":29},85633,4810365810221,"Aurora","https://ap-avatar.wpscdn.com/davatar_155a257f0dc6eb9ab79c44ca47cae57d",8,"Research & Report","Prismriver Formalization of Music Theory and Algorithmic Composition in Lean 4","Prismriver is a Lean 4 formalization library that encodes music theory using proof-assistant precision, turning musical symmetries and rules into verifiable statements. It generalizes prior approaches that rely on equal temperament tuning and extends support toward xenharmonic tuning systems and non-octave fundamental intervals. The work enables provable algorithmic composition and counterpoint modeling, offering monadic composition primitives and a LilyPond-like DSL integrated with MusicXML export for interoperability.","Prismriver: Formalization of Music Theory and Algorithmic Composition in Lean 4  \narXiv :2606 . 19936v2 [ cs .LO] 12 Jul 2026  \nLeni Aniva  \nStanford University  \nComputer Science Department  \nStanford, USA  \n[aniva@stanford.edu](aniva@stanford.edu)  \nAbstract  \nMusic theory obeys a rich set of mathematical rules and symmetries. These symmetries follow mathematical structures which can be verified and expressed in the precise language of a proof assistant. In this paper, we present Prismriver, a formalization library of music theory in Lean 4. We use Prismriver to generalize beyond existing work that assumes equal temperament tuning. We also discuss modelling counterpoint music theory with Prismriver. By formalizing music theory in Lean 4, we open the door to verifiable algorithmic composition and accompaniment generation. Prismriver also has a custom DSL integrated with MusicXML exports to interoperate with other music software. Prismriver can be used to compose music with Lean, using monadic composition primitives.  \nCCS Concepts: • Theory of computation → Automated reasoning; • Applied computing → Sound and music computing.  \nKeywords: Music Theory, Music, Lean 4, Algorithmic Composition  \nACM Reference Format:  \nLeni Aniva and Claire Wang. 2026. Prismriver: Formalization of Music Theory and Algorithmic Composition in Lean 4 . In Proceedings of the 14th ACM SIGPLAN International Workshop on Functional Art, Music, Modelling, and Design (FARM’26), August 24–29, 2026, Indianapolis, IN, USA. ACM, New York, NY, USA, 12 pages.  \n[https://doi.org/10.1145/3830435.3830954](https://doi.org/10.1145/3830435.3830954)  \n1 Introduction  \nMusic theory studies the structures underlying composition, which can have mathematical parallels [33] . For example, when representing pitch classes as integers in ℤ/12ℤ, transposing the C major chord {0, 4, 7} up by five semitones yields the F major chord {5, 9, 0} = {0 + 5, 4 + 5, 7 + 5} mod 12,  \nThis work is licensed under a Creative Commons Attribution 4 .0 International License.  \nFARM’26, Indianapolis, IN, USA  \n© 2026 Copyright held by the owner/author(s) .  \nACM ISBN 979-8-4007-2867-9/2026/08  \n[https://doi.org/10.1145/3830435.3830954](https://doi.org/10.1145/3830435.3830954)  \nClaire Wang  \nUniversity of Pennsylvania  \nPhiladelphia, USA [cdwang@seas.upenn.edu](cdwang@seas.upenn.edu)  \nshowing how musical transposition corresponds to translation [33] . The rules and symmetries in music theory can be stated precisely and proven as opposed to only described informally. Mathematical music theory already consists of proving theorems on music theory structures [19] though such proofs are written in natural language, which can only be checked by hand and peer review. Checking handwritten proofs can lead to missed errors and lack of mechanical reuse of results. Interactive theorem provers are software systems for writing proofs that can be verified by a computer, eliminating the inefficiencies of handwritten proofs [24]. The Lean [20] theorem prover is a functional language and theorem prover accompanied by Mathlib [9], a Lean library containing the largest collection of math proofs. The Lean language is highly expressive for defining custom domain specific languages given its support for rich custom abstractions, extensible syntax, and metaprogramming. When formalizing music theory, users may benefit from using existing musical primitives and the ability to use Mathlib with their proofs.  \nWe present Prismriver, a Lean 4 library for the representation, analysis, and algorithmic composition of music.1 Lean is both a proof assistant and a general-purpose programming language, which enables us to build a versatile library that both proves theorems about musical structure and performs I/O to compose music. Lean can also prove properties about composition algorithms such as that of first species counterpoint.  \nOur contributions with Prismriver are the following:  \n1. Formalization of music theory includin","cbCaingnEu4H9dM5","https://ap.wps.com/l/cbCaingnEu4H9dM5","pdf",231902,3,1,12,"English","en",105,"# Introduction\n# Contributions\n# Related Work","[{\"question\":\"What is Prismriver and what problem does it address?\",\"answer\":\"Prismriver is a Lean 4 library that formalizes music theory so its rules and symmetries can be expressed and verified by a proof assistant. It reduces reliance on informal, human-checked proofs.\"},{\"question\":\"How does Prismriver go beyond equal temperament assumptions?\",\"answer\":\"Prismriver is designed to be compatible with xenharmonic scales, including quartertones and non-equally tempered tuning systems. It also supports tuning systems whose fundamental interval is not the octave.\"},{\"question\":\"How are music compositions produced and shared with other tools?\",\"answer\":\"Prismriver uses monadic composition primitives and a LilyPond-like DSL for input. Compositions are exported to MusicXML so they can interoperate with other music software and be played back via tools that support MusicXML.\"}]",1784205136,30,{"code":4,"msg":31,"data":32},"ok",{"site_id":25,"language":24,"slug":33,"title":13,"keywords":34,"description":14,"schema_data":35,"social_meta":86,"head_meta":88,"extra_data":90,"updated_unix":28},"prismriver-formalization-of-music-theory-and-algorithmic-composition-in-lean-4","",{"@graph":36,"@context":85},[37,53,68],{"@type":38,"itemListElement":39},"BreadcrumbList",[40,44,48,50],{"item":41,"name":42,"@type":43,"position":21},"https://docshare.wps.com","Home","ListItem",{"item":45,"name":46,"@type":43,"position":47},"https://docshare.wps.com/document/","Document",2,{"item":49,"name":12,"@type":43,"position":20},"https://docshare.wps.com/document/research-report/",{"item":51,"name":13,"@type":43,"position":52},"https://docshare.wps.com/document/prismriver-formalization-of-music-theory-and-algorithmic-composition-in-lean-4/85633/",4,{"url":51,"name":13,"@type":54,"author":55,"headline":13,"publisher":57,"fileFormat":60,"inLanguage":24,"description":14,"dateModified":61,"datePublished":62,"encodingFormat":60,"isAccessibleForFree":63,"interactionStatistic":64},"DigitalDocument",{"name":9,"@type":56},"Person",{"url":41,"name":58,"@type":59},"DocShare","Organization","application/pdf","2026-07-24","2026-07-16",true,{"@type":65,"interactionType":66,"userInteractionCount":20},"InteractionCounter",{"@type":67},"ViewAction",{"@type":69,"mainEntity":70},"FAQPage",[71,77,81],{"name":72,"@type":73,"acceptedAnswer":74},"What is Prismriver and what problem does it address?","Question",{"text":75,"@type":76},"Prismriver is a Lean 4 library that formalizes music theory so its rules and symmetries can be expressed and verified by a proof assistant. It reduces reliance on informal, human-checked proofs.","Answer",{"name":78,"@type":73,"acceptedAnswer":79},"How does Prismriver go beyond equal temperament assumptions?",{"text":80,"@type":76},"Prismriver is designed to be compatible with xenharmonic scales, including quartertones and non-equally tempered tuning systems. It also supports tuning systems whose fundamental interval is not the octave.",{"name":82,"@type":73,"acceptedAnswer":83},"How are music compositions produced and shared with other tools?",{"text":84,"@type":76},"Prismriver uses monadic composition primitives and a LilyPond-like DSL for input. Compositions are exported to MusicXML so they can interoperate with other music software and be played back via tools that support MusicXML.","https://schema.org",{"og:url":51,"og:type":87,"og:title":13,"og:site_name":58,"og:description":14},"article",{"robots":89,"canonical":51},"index,follow",{"doc_id":7,"site_id":25},{"code":4,"msg":5,"data":92},[93,97,101,105,110,115,120,122,127,130,134],{"id":21,"doc_module":4,"doc_module_name":46,"category_name":94,"show_sort_weight":95,"slug":96},"Story & Novel",90,"story-novel",{"id":47,"doc_module":4,"doc_module_name":46,"category_name":98,"show_sort_weight":99,"slug":100},"Literature",80,"literature",{"id":52,"doc_module":4,"doc_module_name":46,"category_name":102,"show_sort_weight":103,"slug":104},"Exam",70,"exam",{"id":106,"doc_module":4,"doc_module_name":46,"category_name":107,"show_sort_weight":108,"slug":109},5,"Comic",60,"comic",{"id":111,"doc_module":4,"doc_module_name":46,"category_name":112,"show_sort_weight":113,"slug":114},6,"Technology",50,"technology",{"id":116,"doc_module":4,"doc_module_name":46,"category_name":117,"show_sort_weight":118,"slug":119},7,"Healthcare",40,"healthcare",{"id":11,"doc_module":4,"doc_module_name":46,"category_name":12,"show_sort_weight":29,"slug":121},"research-report",{"id":123,"doc_module":4,"doc_module_name":46,"category_name":124,"show_sort_weight":125,"slug":126},9,"Religion & Spirituality",20,"religion-spirituality",{"id":125,"doc_module":4,"doc_module_name":46,"category_name":128,"show_sort_weight":125,"slug":129},"World Cup","world-cup",{"id":131,"doc_module":4,"doc_module_name":46,"category_name":132,"show_sort_weight":131,"slug":133},10,"Lifestyle","lifestyle",{"id":135,"doc_module":4,"doc_module_name":46,"category_name":136,"show_sort_weight":106,"slug":137},19,"General","general"]