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
69 lines
1.6 KiB
Text
69 lines
1.6 KiB
Text
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
|