Skip to content

Commit

Permalink
feat(data/option): add option.forall and option.exists (#6419)
Browse files Browse the repository at this point in the history
  • Loading branch information
urkud committed Feb 27, 2021
1 parent 4b02853 commit a19af60
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 4 deletions.
7 changes: 7 additions & 0 deletions src/data/option/basic.lean
Expand Up @@ -12,6 +12,13 @@ lemma coe_def : (coe : α → option α) = some := rfl

lemma some_ne_none (x : α) : some x ≠ none := λ h, option.no_confusion h

protected lemma «forall» {p : option α → Prop} : (∀ x, p x) ↔ p none ∧ ∀ x, p (some x) :=
⟨λ h, ⟨h _, λ x, h _⟩, λ h x, option.cases_on x h.1 h.2

protected lemma «exists» {p : option α → Prop} : (∃ x, p x) ↔ p none ∨ ∃ x, p (some x) :=
⟨λ ⟨x, hx⟩, (option.cases_on x or.inl $ λ x hx, or.inr ⟨x, hx⟩) hx,
λ h, h.elim (λ h, ⟨_, h⟩) (λ ⟨x, hx⟩, ⟨_, hx⟩)⟩

@[simp] theorem get_mem : ∀ {o : option α} (h : is_some o), option.get h ∈ o
| (some a) _ := rfl

Expand Down
8 changes: 4 additions & 4 deletions src/data/seq/wseq.lean
Expand Up @@ -1157,7 +1157,7 @@ begin
let ⟨o, m, k, rs1, rs2, en⟩ := of_results_bind ra,
⟨p, mT, rop⟩ := computation.exists_of_lift_rel_left (lift_rel_destruct ST) rs1.mem in
by exact match o, p, rop, rs1, rs2, mT with
| none, none, _, rs1, rs2, mT := by simp [destruct_join]; exact
| none, none, _, rs1, rs2, mT := by simp only [destruct_join]; exact
⟨none, mem_bind mT (ret_mem _), by rw eq_of_ret_mem rs2.mem; trivial⟩
| some (s, S'), some (t, T'), ⟨st, ST'⟩, rs1, rs2, mT :=
by simp [destruct_append] at rs2; exact
Expand Down Expand Up @@ -1238,9 +1238,9 @@ begin
{ exact λ c1 c2 h, match c1, c2, h with
| ._, ._, ⟨s, rfl, rfl⟩ := begin
clear h _match,
apply s.cases_on _ (λ a s, _) (λ s, _); simp [ret],
{ refine ⟨_, ret_mem _, _⟩, simp },
{ exact ⟨s, rfl, rfl⟩ }
have : ∀ s, ∃ s' : wseq α, (map ret s).join.destruct = (map ret s').join.destruct ∧
destruct s = s'.destruct, from λ s, ⟨s, rfl, rfl⟩,
apply s.cases_on _ (λ a s, _) (λ s, _); simp [ret, ret_mem, this, option.exists]
end end },
{ exact ⟨s, rfl, rfl⟩ }
end
Expand Down

0 comments on commit a19af60

Please sign in to comment.