Theorem: Fin.isSome_find_iff
File: Mathlib/Data/Fin/Tuple/Basic.lean

tactic: rw [Option.isSome_iff_exists] at h
state_before: m n✝ n : ℕ
p : Fin (n + 1) → Prop
x✝ : DecidablePred p
h : (find p).isSome = true
⊢ ∃ i, p i
state_after: m n✝ n : ℕ
p : Fin (n + 1) → Prop
x✝ : DecidablePred p
h : ∃ a, find p = some a
⊢ ∃ i, p i

tactic: cases' h with i hi
state_before: m n✝ n : ℕ
p : Fin (n + 1) → Prop
x✝ : DecidablePred p
h : ∃ a, find p = some a
⊢ ∃ i, p i
state_after: case intro
m n✝ n : ℕ
p : Fin (n + 1) → Prop
x✝ : DecidablePred p
i : Fin (n + 1)
hi : find p = some i
⊢ ∃ i, p i

tactic: exact ⟨i, find_spec _ hi⟩
state_before: case intro
m n✝ n : ℕ
p : Fin (n + 1) → Prop
x✝ : DecidablePred p
i : Fin (n + 1)
hi : find p = some i
⊢ ∃ i, p i
state_after: no goals

tactic: dsimp [find]
state_before: m n✝ n : ℕ
p : Fin (n + 1) → Prop
x✝¹ : DecidablePred p
x✝ : ∃ i, p i
i : ℕ
hin : i < n + 1
hi : p ⟨i, hin⟩
⊢ (find p).isSome = true
state_after: m n✝ n : ℕ
p : Fin (n + 1) → Prop
x✝¹ : DecidablePred p
x✝ : ∃ i, p i
i : ℕ
hin : i < n + 1
hi : p ⟨i, hin⟩
⊢ (Option.rec (if p (last n) then some (last n) else none) (fun val => some (val.castLT ⋯))
        (find fun i => p (i.castLT ⋯))).isSome =
    true

tactic: cases' h : find fun i : Fin n ↦ p (i.castLT (Nat.lt_succ_of_lt i.2)) with j
state_before: m n✝ n : ℕ
p : Fin (n + 1) → Prop
x✝¹ : DecidablePred p
x✝ : ∃ i, p i
i : ℕ
hin : i < n + 1
hi : p ⟨i, hin⟩
⊢ (Option.rec (if p (last n) then some (last n) else none) (fun val => some (val.castLT ⋯))
        (find fun i => p (i.castLT ⋯))).isSome =
    true
state_after: case none
m n✝ n : ℕ
p : Fin (n + 1) → Prop
x✝¹ : DecidablePred p
x✝ : ∃ i, p i
i : ℕ
hin : i < n + 1
hi : p ⟨i, hin⟩
h : (find fun i => p (i.castLT ⋯)) = none
⊢ (Option.rec (if p (last n) then some (last n) else none) (fun val => some (val.castLT ⋯)) none).isSome = true

case some
m n✝ n : ℕ
p : Fin (n + 1) → Prop
x✝¹ : DecidablePred p
x✝ : ∃ i, p i
i : ℕ
hin : i < n + 1
hi : p ⟨i, hin⟩
j : Fin n
h : (find fun i => p (i.castLT ⋯)) = some j
⊢ (Option.rec (if p (last n) then some (last n) else none) (fun val => some (val.castLT ⋯)) (some j)).isSome = true

tactic: split_ifs with hl
state_before: case none
m n✝ n : ℕ
p : Fin (n + 1) → Prop
x✝¹ : DecidablePred p
x✝ : ∃ i, p i
i : ℕ
hin : i < n + 1
hi : p ⟨i, hin⟩
h : (find fun i => p (i.castLT ⋯)) = none
⊢ (Option.rec (if p (last n) then some (last n) else none) (fun val => some (val.castLT ⋯)) none).isSome = true
state_after: case pos
m n✝ n : ℕ
p : Fin (n + 1) → Prop
x✝¹ : DecidablePred p
x✝ : ∃ i, p i
i : ℕ
hin : i < n + 1
hi : p ⟨i, hin⟩
h : (find fun i => p (i.castLT ⋯)) = none
hl : p (last n)
⊢ (Option.rec (some (last n)) (fun val => some (val.castLT ⋯)) none).isSome = true

case neg
m n✝ n : ℕ
p : Fin (n + 1) → Prop
x✝¹ : DecidablePred p
x✝ : ∃ i, p i
i : ℕ
hin : i < n + 1
hi : p ⟨i, hin⟩
h : (find fun i => p (i.castLT ⋯)) = none
hl : ¬p (last n)
⊢ (Option.rec none (fun val => some (val.castLT ⋯)) none).isSome = true

tactic: exact Option.isSome_some
state_before: case pos
m n✝ n : ℕ
p : Fin (n + 1) → Prop
x✝¹ : DecidablePred p
x✝ : ∃ i, p i
i : ℕ
hin : i < n + 1
hi : p ⟨i, hin⟩
h : (find fun i => p (i.castLT ⋯)) = none
hl : p (last n)
⊢ (Option.rec (some (last n)) (fun val => some (val.castLT ⋯)) none).isSome = true
state_after: no goals

tactic: have := (@isSome_find_iff n (fun x ↦ p (x.castLT (Nat.lt_succ_of_lt x.2))) _).2
    ⟨⟨i, lt_of_le_of_ne (Nat.le_of_lt_succ hin) fun h ↦ by cases h; exact hl hi⟩, hi⟩
state_before: case neg
m n✝ n : ℕ
p : Fin (n + 1) → Prop
x✝¹ : DecidablePred p
x✝ : ∃ i, p i
i : ℕ
hin : i < n + 1
hi : p ⟨i, hin⟩
h : (find fun i => p (i.castLT ⋯)) = none
hl : ¬p (last n)
⊢ (Option.rec none (fun val => some (val.castLT ⋯)) none).isSome = true
state_after: case neg
m n✝ n : ℕ
p : Fin (n + 1) → Prop
x✝¹ : DecidablePred p
x✝ : ∃ i, p i
i : ℕ
hin : i < n + 1
hi : p ⟨i, hin⟩
h : (find fun i => p (i.castLT ⋯)) = none
hl : ¬p (last n)
this : (find fun x => p (x.castLT ⋯)).isSome = true
⊢ (Option.rec none (fun val => some (val.castLT ⋯)) none).isSome = true

tactic: rw [h] at this
state_before: case neg
m n✝ n : ℕ
p : Fin (n + 1) → Prop
x✝¹ : DecidablePred p
x✝ : ∃ i, p i
i : ℕ
hin : i < n + 1
hi : p ⟨i, hin⟩
h : (find fun i => p (i.castLT ⋯)) = none
hl : ¬p (last n)
this : (find fun x => p (x.castLT ⋯)).isSome = true
⊢ (Option.rec none (fun val => some (val.castLT ⋯)) none).isSome = true
state_after: case neg
m n✝ n : ℕ
p : Fin (n + 1) → Prop
x✝¹ : DecidablePred p
x✝ : ∃ i, p i
i : ℕ
hin : i < n + 1
hi : p ⟨i, hin⟩
h : (find fun i => p (i.castLT ⋯)) = none
hl : ¬p (last n)
this : none.isSome = true
⊢ (Option.rec none (fun val => some (val.castLT ⋯)) none).isSome = true

tactic: exact this
state_before: case neg
m n✝ n : ℕ
p : Fin (n + 1) → Prop
x✝¹ : DecidablePred p
x✝ : ∃ i, p i
i : ℕ
hin : i < n + 1
hi : p ⟨i, hin⟩
h : (find fun i => p (i.castLT ⋯)) = none
hl : ¬p (last n)
this : none.isSome = true
⊢ (Option.rec none (fun val => some (val.castLT ⋯)) none).isSome = true
state_after: no goals

tactic: cases h
state_before: m n✝ n : ℕ
p : Fin (n + 1) → Prop
x✝¹ : DecidablePred p
x✝ : ∃ i, p i
i : ℕ
hin : i < n + 1
hi : p ⟨i, hin⟩
h✝ : (find fun i => p (i.castLT ⋯)) = none
hl : ¬p (last n)
h : i = n
⊢ False
state_after: case refl
m n✝ n : ℕ
p : Fin (n + 1) → Prop
x✝¹ : DecidablePred p
x✝ : ∃ i, p i
h : (find fun i => p (i.castLT ⋯)) = none
hl : ¬p (last n)
hin : n < n + 1
hi : p ⟨n, hin⟩
⊢ False

tactic: exact hl hi
state_before: case refl
m n✝ n : ℕ
p : Fin (n + 1) → Prop
x✝¹ : DecidablePred p
x✝ : ∃ i, p i
h : (find fun i => p (i.castLT ⋯)) = none
hl : ¬p (last n)
hin : n < n + 1
hi : p ⟨n, hin⟩
⊢ False
state_after: no goals

tactic: simp
state_before: case some
m n✝ n : ℕ
p : Fin (n + 1) → Prop
x✝¹ : DecidablePred p
x✝ : ∃ i, p i
i : ℕ
hin : i < n + 1
hi : p ⟨i, hin⟩
j : Fin n
h : (find fun i => p (i.castLT ⋯)) = some j
⊢ (Option.rec (if p (last n) then some (last n) else none) (fun val => some (val.castLT ⋯)) (some j)).isSome = true
state_after: no goals