lean4-htt/tests/elab/simpMatchEta.lean
Garmelon 08eb78a5b2
chore: switch to new test/bench suite (#12590)
This PR sets up the new integrated test/bench suite. It then migrates
all benchmarks and some related tests to the new suite. There's also
some documentation and some linting.

For now, a lot of the old tests are left alone so this PR doesn't become
even larger than it already is. Eventually, all tests should be migrated
to the new suite though so there isn't a confusing mix of two systems.
2026-02-25 13:51:53 +00:00

58 lines
1.6 KiB
Text

import Lean
def foo (n : Nat) (f : Fin n) := match f with | ⟨k, _hk⟩ => if k == 0 then true else false
def thm : foo n f = (if f.val == 0 then true else false) := by simp [foo]
-- NB: equational theorem only applies if motive is manifest constructor
/--
info: foo.match_1.eq_1.{u_1} (n : Nat) (motive : Fin n → Sort u_1) (k : Nat) (_hk : k < n)
(h_1 : (k : Nat) → (_hk : k < n) → motive ⟨k, _hk⟩) :
(match ⟨k, _hk⟩ with
| ⟨k, _hk⟩ => h_1 k _hk) =
h_1 k _hk
-/
#guard_msgs in
#check foo.match_1.eq_1
open Lean Meta Elab Term
elab "simpMatch" t:term : command => do
Command.runTermElabM fun _ => do
withDeclName `_simpMatch do
let e ← elabTerm t none
synthesizeSyntheticMVarsNoPostponing (ignoreStuckTC := false)
let e' ← instantiateMVars e
let r ← Split.simpMatch e'
logInfo m!"{indentExpr e}\n==>{indentExpr r.expr}"
-- This should simplify
/--
info:
fun n f =>
match ⟨↑f, ⋯⟩ with
| ⟨k, _hk⟩ => if (k == 0) = true then true else false
==>
fun n f => if (↑f == 0) = true then true else false
-/
#guard_msgs in
simpMatch
fun (n : Nat) (f : Fin n) => (match Fin.mk f.val f.isLt with | ⟨k, _hk⟩ => if k == 0 then true else false)
-- But this should not
/--
info:
fun n f =>
match f with
| ⟨k, _hk⟩ => if (k == 0) = true then true else false
==>
fun n f =>
match f with
| ⟨k, _hk⟩ => if (k == 0) = true then true else false
-/
#guard_msgs in
simpMatch
fun (n : Nat) (f : Fin n) => (match f with | ⟨k, _hk⟩ => if k == 0 then true else false)