Have-Telescope Simplification for Sym.simp #
This module implements efficient simplification of have-telescopes (sequences of
non-dependent let bindings) in the symbolic simplifier. The key insight is to
transform telescopes into a "parallel" beta-application form, simplify the arguments
independently, and then convert back to have form.
The Problem #
Consider a have-telescope:
have x₁ := v₁
have x₂ := v₂[x₁]
...
have xₙ := vₙ[x₁, ..., xₙ₋₁]
b[x₁, ..., xₙ]
Naively generating proofs using have_congr leads to quadratic kernel type-checking time.
The issue is that when the kernel type-checks congruence proofs, it creates fresh free
variables for each binder, destroying sharing and generating O(n²) terms.
The Solution: Virtual Parallelization #
We transform the sequential have telescope into a parallel beta-application:
(fun x₁ x₂' ... xₙ' => b[x₁, x₂' x₁, ..., xₙ' (xₙ₋₁' ...)]) v₁ (fun x₁ => v₂[x₁]) ... (fun ... xₙ₋₁ => vₙ[..., xₙ₋₁])
Each xᵢ' is now a function that takes its dependencies as arguments. This form:
- Is definitionally equal to the original (so conversion is free)
- Enables independent simplification of each argument
- Produces proofs that type-check in linear time using the existing efficient simplification procedure for lambdas.
Algorithm Overview #
toBetaApp: Transformhave-telescope → parallel beta-application- Track dependency graph: which
havedepends on which previoushaves - Convert each value
vᵢ[x₁, ..., xₖ]to(fun y₁ ... yₖ => vᵢ[y₁, ..., yₖ]) - Build the body with appropriate applications
- Track dependency graph: which
simpBetaApp: Simplify the beta-application using congruence lemmastoHave: Convert simplified beta-application →have-telescope- Reconstruct the
havebindings from the lambda structure - Apply each argument to recover original variable references
- Reconstruct the
Simplify a have-telescope.
This is the main entry point for have-telescope simplification in Sym.simp.
See module documentation for the algorithm overview.
Equations
- Lean.Meta.Sym.Simp.simpHave e = do let __do_lift ← Lean.Meta.Sym.Simp.simpHaveCore✝ e pure (Lean.Meta.Sym.Simp.SimpHaveResult.result✝ __do_lift)
Instances For
Simplify a have-telescope and eliminate unused bindings.
This combines simplification with dead variable elimination in a single pass, avoiding quadratic behavior from multiple passes.
Equations
- One or more equations did not get rendered due to their size.