This PR adds `CongrInfo` analysis for function applications in the symbolic simulator framework. `CongrInfo` determines how to build congruence proofs for rewriting subterms efficiently, categorizing functions into: - `none`: no arguments can be rewritten (e.g., proofs) - `fixedPrefix`: common case where implicit/instance arguments form a fixed prefix and explicit arguments can be rewritten (e.g., `HAdd.hAdd`, `Eq`) - `interlaced`: rewritable and non-rewritable arguments alternate (e.g., `HEq`) - `congrTheorem`: uses auto-generated congruence theorems for functions with dependent proof arguments (e.g., `Array.eraseIdx`)
40 lines
983 B
Text
40 lines
983 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]
|