Skip to content

Commit 0906bba

Browse files
committed
feat: remove @[simp] from Option.pmap/pbind and add simp lemmas
1 parent 1b09952 commit 0906bba

File tree

2 files changed

+20
-3
lines changed

2 files changed

+20
-3
lines changed

src/Init/Data/Option/Instances.lean

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ partial function defined on `a : α` giving an `Option β`, where `some a = x`,
5555
then `pbind x f h` is essentially the same as `bind x f`
5656
but is defined only when all `x = some a`, using the proof to apply `f`.
5757
-/
58-
@[simp, inline]
58+
@[inline]
5959
def pbind : ∀ x : Option α, (∀ a : α, a ∈ x → Option β) → Option β
6060
| none, _ => none
6161
| some a, f => f a rfl
@@ -65,7 +65,7 @@ Partial map. If `f : Π a, p a → β` is a partial function defined on `a : α`
6565
then `pmap f x h` is essentially the same as `map f x` but is defined only when all members of `x`
6666
satisfy `p`, using the proof to apply `f`.
6767
-/
68-
@[simp, inline] def pmap {p : α → Prop} (f : ∀ a : α, p a → β) :
68+
@[inline] def pmap {p : α → Prop} (f : ∀ a : α, p a → β) :
6969
∀ x : Option α, (∀ a, a ∈ x → p a) → Option β
7070
| none, _ => none
7171
| some a, H => f a (H a rfl)

src/Init/Data/Option/Lemmas.lean

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,11 @@ import Init.Ext
1111

1212
namespace Option
1313

14-
theorem mem_iff {a : α} {b : Option α} : a ∈ b ↔ b = a := .rfl
14+
theorem mem_iff {a : α} {b : Option α} : a ∈ b ↔ b = some a := .rfl
15+
16+
@[simp] theorem mem_some {a b : α} : a ∈ some b ↔ a = b := by simp [mem_iff, eq_comm]
17+
18+
theorem mem_some_self (a : α) : a ∈ some a := mem_some.2 rfl
1519

1620
theorem some_ne_none (x : α) : some x ≠ none := nofun
1721

@@ -395,4 +399,17 @@ section ite
395399

396400
end ite
397401

402+
/-! ### pbind -/
403+
404+
@[simp] theorem pbind_none : pbind none f = none := rfl
405+
@[simp] theorem pbind_some : pbind (some a) f = f a (mem_some_self a) := rfl
406+
407+
/-! ### pmap -/
408+
409+
@[simp] theorem pmap_none {p : α → Prop} {f : ∀ (a : α), p a → β} {h} :
410+
pmap f none h = none := rfl
411+
412+
@[simp] theorem pmap_some {p : α → Prop} {f : ∀ (a : α), p a → β} {h}:
413+
pmap f (some a) h = f a (h a (mem_some_self a)) := rfl
414+
398415
end Option

0 commit comments

Comments
 (0)