A Transfer Tactic for Lean
Zhaoxi Chen, Daniel Raggi
cs.LO
Sep 26, 2026 · v1
TL;DR
Implements a transfer tactic family for Lean 4 over a tagged rule database, benchmarked against Mathlib's gcongr and grw test suites.
Abstract
Rewriting in proof assistants spans a strict hierarchy. Equational rewriting substitutes based on extensional equality; subequational rewriting substitutes based on homogeneous relations such as $\leq$ or $\subseteq$, justified by monotonicity lemmas; and generalized rewriting relates different operations across different types, justified by transfer rules. All three are specializations of one schema, the function relator $(R \Rightarrow S)\,f\,g$. Lean 4's rw and Mathlib's grw/gcongr implement the first two levels, but the third has had no Lean implementation. We present one: a transfer tactic family over a tagged rule database, benchmarked using Mathlib's own test suites, of which 112 of 178 ported tests close through the transfer engine. An evaluation of the design's three motivating hypotheses returns a mixed result: generality holds, authoring effort wins in its amortized form (averaged per use), but on dependency footprint, transfer only ties a mature library and loses on coercions. This shows that transfer's value is concentrated on transferring into domains where few theorems exist.
Problem
Rewriting in proof assistants spans equational, subequational, and generalized levels, all specializations of the function relator schema. Lean 4's rw and Mathlib's grw/gcongr implement the first two levels, but the generalized level (relating different operations across different types via transfer rules) had no Lean implementation.
Approach
A transfer tactic family is implemented over a tagged rule database, using attributes such as transfer_rule, transfer_back_rule, transfer_respects, and btransfer_rule, built on Mathlib's Relator.LiftFun. Rules carry numerical priorities and cluster into ground facts, structural rules, uniqueness/totality facts, and one-way equality lemmas. The engine consumes Mathlib's @[gcongr] database directly and reuses grw's occurrence abstraction. The design is inspired by Isabelle's Transfer package.
Results
112 of 178 ported Mathlib gcongr/grw tests close through the transfer engine. Generality holds, authoring effort wins in amortized form, but dependency footprint only ties a mature library and loses on bi-unique coercions where norm_cast is already complete.
| File | Tests | Via transfer | Def. (UX) | Def. (partial) | Fail |
|---|
| GCongrInequalities | 74 | 42 | 20 | 12 | 0 |
| GRewrite | 53 | 42 | 11 | 0 | 0 |
| Total | 178 | 112 | 54 | 12 | 0 |
Parity suite results ported from Mathlib gcongr/grw tests