lean4-htt/tests/lean/run/unfoldLemma.lean
Joachim Breitner a993934839
feat: generate f.eq_unfold lemmas (#5141)
With this, lean produces the following zoo of rewrite rules:
```
Option.map.eq_1      : Option.map f none = none
Option.map.eq_2      : Option.map f (some x) = some (f x)
Option.map.eq_def    : Option.map f p = match o with | none => none | (some x) => some (f x)
Option.map.eq_unfold : Option.map = fun f p => match o with | none => none | (some x) => some (f x)
```

The `f.eq_unfold` variant is especially useful to rewrite with `rw`
under
binders.

This implements and fixes #5110
2024-08-29 16:47:40 +00:00

69 lines
1.6 KiB
Text
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

def Option_map (f : α → β) : Option α → Option β
| none => none
| some x => some (f x)
/--
info: equations:
theorem Option_map.eq_1.{u_1, u_2} : ∀ {α : Type u_1} {β : Type u_2} (f : α → β), Option_map f none = none
theorem Option_map.eq_2.{u_1, u_2} : ∀ {α : Type u_1} {β : Type u_2} (f : α → β) (x_1 : α),
Option_map f (some x_1) = some (f x_1)
-/
#guard_msgs in
#print equations Option_map
/--
info: Option_map.eq_def.{u_1, u_2} {α : Type u_1} {β : Type u_2} (f : α → β) :
∀ (x : Option α),
Option_map f x =
match x with
| none => none
| some x => some (f x)
-/
#guard_msgs in
#check Option_map.eq_def
/--
info: Option_map.eq_unfold.{u_1, u_2} :
@Option_map = fun {α} {β} f x =>
match x with
| none => none
| some x => some (f x)
-/
#guard_msgs in
#check Option_map.eq_unfold
def answer := 42
/-- info: answer.eq_unfold : answer = 42 -/
#guard_msgs in
#check answer.eq_unfold
-- structural recursion
def List_map (f : α → β) : List α → List β
| [] => []
| x::xs => f x :: List_map f xs
/--
info: List_map.eq_unfold.{u_1, u_2} :
@List_map = fun {α} {β} f x =>
match x with
| [] => []
| x :: xs => f x :: List_map f xs
-/
#guard_msgs in
#check List_map.eq_unfold
-- wf recursion
def List_map2 (f : α → β) : List α → List β
| [] => []
| x::xs => f x :: List_map2 f xs
termination_by l => l
/--
info: List_map2.eq_unfold.{u_1, u_2} :
@List_map2 = fun {α} {β} f x =>
match x with
| [] => []
| x :: xs => f x :: List_map2 f xs
-/
#guard_msgs in
#check List_map2.eq_unfold