← All papers
First page of Semantics-Preserving Compilers via Operadic Algebras and Factorization Algebras

Semantics-Preserving Compilers via Operadic Algebras and Factorization Algebras

Yuwen Gu

math.AT Nov 27, 2026 · v1 cs.PL math.LO
Builds a bidirectional C++/Lean compiler and uses Lean to verify a translated Milnor multiplication routine and ML-KEM polynomial multiplication equivalence.
We investigate an operadic approach to semantics-preserving translation from a well-defined subset of C++ to Lean. The proposed development has three components. First, it organizes program constructors and their interpretations using colored operads and their algebras. We give sufficient conditions for a correspondence on fundamental types and basic operations to induce a semantically faithful compiler, and prove that such a compiler extends through finite products and recursion. Second, we use a factorization algebra to describe how the semantics of a program is assembled from its function fragments. The local data include the embedding of each fragment algebra into the program's semantic algebra. We prove that, for a cover by function fragments, the images of these embeddings generate that algebra. Third, we propose a compiler architecture based on the factorization algebra of program fragments and implement it for translation from C++ to Lean. The compiler records each function as a fragment, translates each fragment using the correspondence on types and operations, and assembles the resulting definitions according to their call dependencies. We compile and verify the Milnor multiplication program used by Lin, Wang, and Xu in their computations for the Kervaire invariant one problem in dimension 126. After repairing an uninitialized read, we verify that the translated program computes the product specified by the formalized Milnor coproduct for every ordered basis pair of combined degree at most 180. As another application, we rewrite a Lean-verified algorithm for ML-KEM polynomial multiplication in the Lean fragment accepted by our compiler. We prove in Lean that the two formulations agree on all canonical inputs and compile the rewritten definition to C++. On an Apple M4, the generated C++ code ran 6.1 times as fast as the native Lean version of the same definition.

Mathematical results increasingly rely on C++ software, such as the Lin–Wang–Xu computations for the Kervaire invariant one problem in dimension 126. Such implementations may contain bugs or depart from the intended mathematics. A semantics-preserving translation into Lean is needed to connect the code to formal specifications.

Program constructors and their interpretations are modeled as algebras over colored operads. The paper gives sufficient conditions under which a correspondence on fundamental types and basic operations induces a semantically faithful compiler, and shows that this extends through finite products and recursion. A factorization algebra over function fragments describes how local translations assemble into the whole program. On this basis a bidirectional compiler between a subset of C++20 and Lean is implemented, storing function fragments in SQLite.

After repairing an uninitialized read, the translated Milnor multiplication program is verified in Lean against the formalized Milnor coproduct for all ordered basis pairs of combined degree at most 180. An ML-KEM NTT polynomial multiplication is proved in Lean to agree with a Lean-verified algorithm and is compiled to C++. The generated C++ runs 6.1 times as fast as native Lean on an Apple M4.