NeurIPS 2026Coming to NeurIPS?Explore papers, orals & directions

DSLean: A Framework for Type-Correct Interoperability Between Lean 4 and External DSLs

Tate Rowney, Riyaz Ahuja, Jeremy Avigad, Sean WelleckarXiv 2026

TL;DR

DSLean is a new framework that simplifies communication between the Lean 4 proof assistant and external automation tools by enabling easy, bidirectional translation. By defining simple syntax-to-object equivalences, users can build powerful automation tactics—such as interfacing with computer algebra systems or interval arithmetic solvers—without wrestling with complex Lean metaprogramming.

What Problem Does This Paper Address?

Interactive Theorem Provers (ITPs) like Lean 4 are incredibly powerful for verifying mathematics and software correctness, but they often require help from external tools (like SMT solvers, computer algebra systems, or specialized verifiers) to handle heavy computational lifting.

To make these tools talk to each other, developers must translate Lean’s internal expressions into an external tool's Domain-Specific Language (DSL) and vice versa. Currently, writing these translators is a massive engineering headache. It requires authoring bespoke, application-specific metaprogramming code to parse raw strings, elaborate them into abstract syntax trees, and ensure type correctness. Because this process is so tedious and requires deep expertise in Lean's internals, it severely bottlenecks the creation of new proof automation tactics.

Methods

DSLean provides a high-level, declarative framework where users simply specify equivalences between external syntax and Lean objects using a clean <==> delimiter.

  • Lean to External Translation: Instead of relying on Lean's default pretty-printer, DSLean uses Lean’s native definitional equality checker. It matches Lean expressions against user-defined patterns by substituting placeholders with metavariables. This allows DSLean to automatically respect complex typing constraints and polymorphism.
  • External to Lean Translation: External syntax is parsed using Lean’s native Pratt parser. DSLean transforms the user's specification into production rules to build a custom grammar. A specialized elaboration stage then recursively merges these parsed pieces back into type-correct Lean expressions using definitional unification.

Crucially, the framework abstracts away the meta-level implementation details while supporting advanced language features like binders (variable scopes), local declarations, and one-way (non-injective) translations (==>).

Datasets

Not discussed in the paper. As a software framework paper rather than a machine learning paper, DSLean does not utilize training datasets or standard ML benchmarks. Instead, it evaluates performance qualitatively and quantitatively through three newly developed automation tactics.

Key Insights and Ideas

  • Type Systems as Grammar Guards: A key "aha moment" is leveraging Lean’s own type system to enforce structural correctness on the external DSL. External syntax is only validated and translated if its Lean counterpart is type-correct, eliminating the need to write complex, manual grammar constraints.
  • Metaprogramming Abstraction: The paper proves that the messy details of parsing, elaboration, and metavariable unification can be entirely hidden behind a user-facing DSL, making compiler-like translation accessible to non-experts.
  • Code Maintainability: Moving from bespoke, imperative translation scripts to a declarative framework drastically reduces code complexity, making automation tactics highly readable and maintainable.

Key Results

The authors demonstrated DSLean's utility by implementing three brand-new automation tactics for Lean 4, achieving remarkably compact codebases:

  • gappa: Interfaces with the Gappa interval arithmetic solver to prove bounds on real numbers (implemented in just 203 lines of code).
  • desolve: Connects to SageMath to find general solutions for ordinary differential equations (implemented in 95 lines of code).
  • lean_m2: Communicates with Macaulay2 to verify ring ideal membership and Gröbner bases (implemented in 315 lines of code).

In a direct comparison, substituting DSLean into a previously handwritten prototype of the lean_m2 tactic reduced the translation codebase size by a factor of 5.

Limitations and Future Work

  • Grammar Restrictions: DSLean currently cannot handle external languages with context-sensitive syntax (where the meaning of a phrase depends on previous expressions) or indentation-based control flow (like full Python).
  • Verification Gap: Although DSLean uses provably correct definitional equality checks during translation, it still relies on some unverified components (like Lean's native parser). Consequently, "round-trip consistency"—the guarantee that translating an expression out of Lean and back in yields the exact same semantic object—is not yet formally proven.
  • Oracle Reliance: For complex domains like ODEs (desolve), Lean currently lacks foundational math libraries. As a result, the tactic must treat the external tool as an unverified oracle (using an axiom) rather than fully reconstructing the proof steps inside Lean.

Summary updated

BibTeX
@misc{rowney2026dslean,
  author = {Tate Rowney and Riyaz Ahuja and Jeremy Avigad and Sean Welleck},
  title = {{DSLean: A Framework for Type-Correct Interoperability Between Lean 4 and External DSLs}},
  year = {2026},
  eprint = {2602.18657},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2602.18657},
}
Figure