-- import Batteries.Tactic.Rcases
-- import Mathlib.Tactic.Cases
-- import Mathlib.Tactic.Use
import Mathlib.Logic.Basic
import Mathlib.Tactic.Cases
import Mathlib.Tactic.Use
-- https://leanprover.zulipchat.com/#narrow/stream/113489-new-members/topic/rcases.20vs.20cases
-- ## Understanding `rintro` for 1 pattern
-- using `rintro`
example (p: Nat → Prop ) : (∃ a, p a) → (∃ b, p b) → (∃ c, p c) := by
rintro ⟨ a , ha ⟩ ⟨ p : ℕ → Prop
(∃ b, p b) → (∃ b, p b) → ∃ c, p c
b Warning: unused variable `b `
note: this linter can be disabled with `set_option linter.unusedVariables false` p : ℕ → Prop
(∃ b, p b) → (∃ b, p b) → ∃ c, p c
, p : ℕ → Prop
(∃ b, p b) → (∃ b, p b) → ∃ c, p c
hb Warning: unused variable `hb `
note: this linter can be disabled with `set_option linter.unusedVariables false` p : ℕ → Prop
(∃ b, p b) → (∃ b, p b) → ∃ c, p c
⟩ p : ℕ → Prop a : ℕ ha : p a b : ℕ hb : p b
intro.intro ∃ c, p c
use a
-- break `rintro` into `intro`s and `obtain`s
example (p: Nat → Prop ) : (∃ a, p a) → (∃ b, p b) → (∃ c, p c) := by
intro h1 p : ℕ → Prop h1 : ∃ a, p a
(∃ b, p b) → ∃ c, p c
intro h2 p : ℕ → Prop h1, h2 : ∃ b, p b
∃ c, p c
obtain ⟨ a , ha ⟩ := h1 p : ℕ → Prop h2 : ∃ b, p ba : ℕ ha : p a
intro ∃ c, p c
obtain ⟨ p : ℕ → Prop h2 : ∃ b, p ba : ℕ ha : p a
intro ∃ c, p c
b Warning: unused variable `b `
note: this linter can be disabled with `set_option linter.unusedVariables false` p : ℕ → Prop h2 : ∃ b, p ba : ℕ ha : p a
intro ∃ c, p c
, p : ℕ → Prop h2 : ∃ b, p ba : ℕ ha : p a
intro ∃ c, p c
hb Warning: unused variable `hb `
note: this linter can be disabled with `set_option linter.unusedVariables false` p : ℕ → Prop h2 : ∃ b, p ba : ℕ ha : p a
intro ∃ c, p c
⟩ := h2 p : ℕ → Prop a : ℕ ha : p a b : ℕ hb : p b
intro.intro ∃ c, p c
use a
-- rewrite `obtain` to `cases'`
example (p: Nat → Prop ) : (∃ a, p a) → (∃ b, p b) → (∃ c, p c) := by
intro h1 p : ℕ → Prop h1 : ∃ a, p a
(∃ b, p b) → ∃ c, p c
intro h2 p : ℕ → Prop h1, h2 : ∃ b, p b
∃ c, p c
cases' h1 with a ha p : ℕ → Prop h2 : ∃ b, p ba : ℕ ha : p a
intro ∃ c, p c
cases' h2 with a ha p : ℕ → Prop a✝ : ℕ ha✝ : p a✝ a : ℕ ha : p a
intro.intro ∃ c, p c
use a
-- ## Understanding `rintro` for 1+ patterns
-- using `rintro`
example (p: Nat → Nat → Prop ) : (∃ a, (∃ b, p a b)) → (∃ c, (∃ d, p c d)) := by
rintro ⟨a, ⟨b, hb⟩⟩ : ∃ a b, p a b
⟨a ⟨a, ⟨b, hb⟩⟩ : ∃ a b, p a b
, ⟨ b , hb ⟩ ⟨a, ⟨b, hb⟩⟩ : ∃ a b, p a b
⟩p : ℕ → ℕ → Prop a, b : ℕ hb : p a b
intro.intro ∃ c d, p c d
use a p : ℕ → ℕ → Prop a, b : ℕ hb : p a b
h ∃ d, p a d
use b
-- break `rintro` into `intro`s and `cases'`s
example (p: Nat → Nat → Prop ) : (∃ a, (∃ b, p a b)) → (∃ c, (∃ d, p c d)) := by
intro h p : ℕ → ℕ → Prop h : ∃ a b, p a b
∃ c d, p c d
cases' h with a ha p : ℕ → ℕ → Prop a : ℕ ha : ∃ b, p a b
intro ∃ c d, p c d
cases' ha with b hb p : ℕ → ℕ → Prop a, b : ℕ hb : p a b
intro.intro ∃ c d, p c d
use a p : ℕ → ℕ → Prop a, b : ℕ hb : p a b
h ∃ d, p a d
use b
-- collapse `cases'`s into a single `rcases`
example (p: Nat → Nat → Prop ) : (∃ a, (∃ b, p a b)) → (∃ c, (∃ d, p c d)) := by
intro h p : ℕ → ℕ → Prop h : ∃ a b, p a b
∃ c d, p c d
rcases h with ⟨a, ⟨b, hb⟩⟩ : ∃ a b, p a b
⟨a ⟨a, ⟨b, hb⟩⟩ : ∃ a b, p a b
, ⟨ b , hb ⟩ ⟨a, ⟨b, hb⟩⟩ : ∃ a b, p a b
⟩p : ℕ → ℕ → Prop a, b : ℕ hb : p a b
intro.intro ∃ c d, p c d
use a p : ℕ → ℕ → Prop a, b : ℕ hb : p a b
h ∃ d, p a d
use b
-- rewrite `rcases` to `obtain` then look at `rintro` above again
example (p: Nat → Nat → Prop ) : (∃ a, (∃ b, p a b)) → (∃ c, (∃ d, p c d)) := by
intro h p : ℕ → ℕ → Prop h : ∃ a b, p a b
∃ c d, p c d
obtain ⟨a, ⟨b, hb⟩⟩ : ∃ a b, p a b
⟨a ⟨a, ⟨b, hb⟩⟩ : ∃ a b, p a b
, ⟨ b , hb ⟩ ⟨a, ⟨b, hb⟩⟩ : ∃ a b, p a b
⟩ := h p : ℕ → ℕ → Prop a, b : ℕ hb : p a b
intro.intro ∃ c d, p c d
use a p : ℕ → ℕ → Prop a, b : ℕ hb : p a b
h ∃ d, p a d
use b
namespace Foo
#check eq_or_ne. {u_1} {α : Sort u_1} (x y : α) : x = y ∨ x ≠ y eq_or_ne : ∀ {α : Sort u_1} (x y : α), x = y ∨ x ≠ y
eq_or_ne
variable ( p q r : Prop )
example : ∀ (p q : Prop), p ∨ q → q ∨ p
example ( h : p ∨ q ) : q ∨ p := by
obtain ( hp | hq ) := h p, q, r : Prop hp : p
inl q ∨ p
. p, q, r : Prop hp : p
inl q ∨ p
exact Or.inr : ∀ {a b : Prop}, b → a ∨ b
Or.inr hp
. p, q, r : Prop hq : q
inr q ∨ p
exact Or.inl : ∀ {a b : Prop}, a → a ∨ b
Or.inl hq
example : ∀ (p q : Prop), p ∧ q → q ∧ p
example ( h : p ∧ q ) : q ∧ p := by
obtain ⟨ hp , hq ⟩ := h p, q, r : Prop hp : p hq : q
intro q ∧ p
exact ⟨ hq , hp ⟩
example : ∀ (p q r : Prop), (p ∨ q) ∧ r → r ∧ (q ∨ p)
example ( h : ( p ∨ q ) ∧ r ) : r ∧ ( q ∨ p ) := by
obtain ⟨hp | hq, hr⟩ : (p ∨ q) ∧ r
⟨hp | hq ⟨hp | hq, hr⟩ : (p ∨ q) ∧ r
, hr ⟨hp | hq, hr⟩ : (p ∨ q) ∧ r
⟩ := h p, q, r : Prop hr : r hp : p
intro.inl r ∧ (q ∨ p)
. p, q, r : Prop hr : r hp : p
intro.inl r ∧ (q ∨ p)
exact ⟨ hr , Or.inr : ∀ {a b : Prop}, b → a ∨ b
Or.inr hp ⟩
. p, q, r : Prop hr : r hq : q
intro.inr r ∧ (q ∨ p)
exact ⟨ hr , Or.inl : ∀ {a b : Prop}, a → a ∨ b
Or.inl hq ⟩
example : ∀ (p q : Prop), p ∨ q → q ∨ p
example ( h : p ∨ q ) : q ∨ p := by
cases h with p, q, r : Prop h : p ∨ q
q ∨ p
| inl : ∀ {a b : Prop}, a → a ∨ b
inl h => p, q, r : Prop h : p
inl q ∨ p
exact Or.inr : ∀ {a b : Prop}, b → a ∨ b
Or.inr h
| inr : ∀ {a b : Prop}, b → a ∨ b
inr h => p, q, r : Prop h : q
inr q ∨ p
exact Or.inl : ∀ {a b : Prop}, a → a ∨ b
Or.inl h