This PR reorganizes the monad hierarchy for symbolic computation in Lean. ## Motivation We want a clean layering where: 1. A foundational monad (`SymM`) provides maximally shared terms and structural/syntactic `isDefEq` 2. `GrindM` builds on this foundation, adding E-graphs, congruence closure, and decision procedures 3. Symbolic execution / VCGen uses `GrindM` directly without introducing a third monad ## Changes The core symbolic computation layer still lives in `Lean.Meta.Sym`. This monad (`SymM`) provides: - Maximally shared terms with pointer-based equality - Structural/syntactic `isDefEq` and matching (no reduction, predictable cost) - Monotonic local contexts (no `revert` or `clear`), enabling O(1) metavariable validation - Efficient `intro`, `apply`, and `simp` implementations The name "Sym" reflects that this is infrastructure for symbolic computation: symbolic simulation, verification condition generation, and decision procedures. ### Updated hierarchy ``` Lean.Meta.Sym -- SymM: shared terms, syntactic isDefEq, intro, apply, simp Lean.Meta.Grind -- GrindM: E-graphs, congruence closure (extends SymM) ``` Symbolic execution is a usage pattern of `GrindM` operating on `Grind.Goal`, not a separate monad. This keeps the API surface minimal: users learn two monads, and VCGen is "how you use `GrindM`" (for users that want to use `grind`) rather than a third abstraction to understand.
40 lines
982 B
Text
40 lines
982 B
Text
import Lean.Meta.Sym
|
|
|
|
open Lean Meta Sym
|
|
|
|
def logCongrInfo (f : Expr) : SymM Unit := do
|
|
logInfo m!"{f} ↦ {← getCongrInfo f}"
|
|
|
|
/--
|
|
info: @HAdd.hAdd ↦ fixedPrefix 4 2
|
|
---
|
|
info: And ↦ fixedPrefix 0 2
|
|
---
|
|
info: @Eq ↦ fixedPrefix 1 2
|
|
---
|
|
info: @HEq ↦ interlaced [false, true, false, true]
|
|
---
|
|
info: @Neg.neg ↦ fixedPrefix 2 1
|
|
---
|
|
info: @Array.eraseIdx ↦ congrTheorem @Array.eraseIdx.congr_simp
|
|
---
|
|
info: @cond ↦ fixedPrefix 1 3
|
|
---
|
|
info: @ite ↦ congrTheorem @ite.congr_simp
|
|
---
|
|
info: @Eq.refl ↦ none
|
|
---
|
|
info: @congrArg ↦ none
|
|
-/
|
|
#guard_msgs in
|
|
run_meta SymM.run do
|
|
logCongrInfo <| mkConst ``HAdd.hAdd [0, 0, 0]
|
|
logCongrInfo <| mkConst ``And
|
|
logCongrInfo <| mkConst ``Eq [1]
|
|
logCongrInfo <| mkConst ``HEq [1]
|
|
logCongrInfo <| mkConst ``Neg.neg [0]
|
|
logCongrInfo <| mkConst ``Array.eraseIdx [0]
|
|
logCongrInfo <| mkConst ``cond [1]
|
|
logCongrInfo <| mkConst ``ite [1]
|
|
logCongrInfo <| mkConst ``Eq.refl [1]
|
|
logCongrInfo <| mkConst ``congrArg [1, 1]
|