Theorem: Nat.Subtype.ofNat_surjective_aux
File: Mathlib/Logic/Denumerable.lean

Proof steps:
state_before: α : Type u_1
β : Type u_2
s : Set ℕ
inst✝¹ : Infinite ↑s
inst✝ : DecidablePred fun x => x ∈ s
x✝ : ℕ
x : ℕ := x✝
hx : x✝ ∈ s
⊢ ∃ n, ofNat s n = ⟨x✝, hx⟩
state_after: α : Type u_1
β : Type u_2
s : Set ℕ
inst✝¹ : Infinite ↑s
inst✝ : DecidablePred fun x => x ∈ s
x✝ : ℕ
x : ℕ := x✝
hx : x✝ ∈ s
t : List ↑s := List.pmap (fun y hy => ⟨y, hy⟩) (List.filter (fun y => decide (y ∈ s)) (List.range x)) ⋯
ht : t = List.pmap (fun y hy => ⟨y, hy⟩) (List.filter (fun y => decide (y ∈ s)) (List.range x)) ⋯
⊢ ∃ n, ofNat s n = ⟨x✝, hx⟩
tactic: set t : List s :=
      ((List.range x).filter fun y => y ∈ s).pmap
        (fun (y : ℕ) (hy : y ∈ s) => ⟨y, hy⟩)
        (by intros a ha; simpa using (List.mem_filter.mp ha).2) with ht
state_before: α : Type u_1
β : Type u_2
s : Set ℕ
inst✝¹ : Infinite ↑s
inst✝ : DecidablePred fun x => x ∈ s
x✝ : ℕ
x : ℕ := x✝
hx : x✝ ∈ s
t : List ↑s := List.pmap (fun y hy => ⟨y, hy⟩) (List.filter (fun y => decide (y ∈ s)) (List.range x)) ⋯
ht : t = List.pmap (fun y hy => ⟨y, hy⟩) (List.filter (fun y => decide (y ∈ s)) (List.range x)) ⋯
⊢ ∃ n, ofNat s n = ⟨x✝, hx⟩
state_after: α : Type u_1
β : Type u_2
s : Set ℕ
inst✝¹ : Infinite ↑s
inst✝ : DecidablePred fun x => x ∈ s
x✝ : ℕ
x : ℕ := x✝
hx : x✝ ∈ s
t : List ↑s := List.pmap (fun y hy => ⟨y, hy⟩) (List.filter (fun y => decide (y ∈ s)) (List.range x)) ⋯
ht : t = List.pmap (fun y hy => ⟨y, hy⟩) (List.filter (fun y => decide (y ∈ s)) (List.range x)) ⋯
hmt : ∀ {y : ↑s}, y ∈ t ↔ y < ⟨x, hx⟩
⊢ ∃ n, ofNat s n = ⟨x✝, hx⟩
tactic: have hmt : ∀ {y : s}, y ∈ t ↔ y < ⟨x, hx⟩ := by
      simp [List.mem_filter, Subtype.ext_iff_val, ht]
state_before: α : Type u_1
β : Type u_2
s : Set ℕ
inst✝¹ : Infinite ↑s
inst✝ : DecidablePred fun x => x ∈ s
x✝ : ℕ
x : ℕ := x✝
hx : x✝ ∈ s
t : List ↑s := List.pmap (fun y hy => ⟨y, hy⟩) (List.filter (fun y => decide (y ∈ s)) (List.range x)) ⋯
ht : t = List.pmap (fun y hy => ⟨y, hy⟩) (List.filter (fun y => decide (y ∈ s)) (List.range x)) ⋯
hmt : ∀ {y : ↑s}, y ∈ t ↔ y < ⟨x, hx⟩
⊢ ∃ n, ofNat s n = ⟨x✝, hx⟩
state_after: α : Type u_1
β : Type u_2
s : Set ℕ
inst✝¹ : Infinite ↑s
inst✝ : DecidablePred fun x => x ∈ s
x✝ : ℕ
x : ℕ := x✝
hx : x✝ ∈ s
t : List ↑s := List.pmap (fun y hy => ⟨y, hy⟩) (List.filter (fun y => decide (y ∈ s)) (List.range x)) ⋯
ht : t = List.pmap (fun y hy => ⟨y, hy⟩) (List.filter (fun y => decide (y ∈ s)) (List.range x)) ⋯
hmt : ∀ {y : ↑s}, y ∈ t ↔ y < ⟨x, hx⟩
wf : ∀ (m : ↑s), t.maximum = ↑m → ↑m < x
⊢ ∃ n, ofNat s n = ⟨x✝, hx⟩
tactic: have wf : ∀ m : s, List.maximum t = m → ↑m < x := fun m hmax => by
      simpa using hmt.mp (List.maximum_mem hmax)
state_before: α : Type u_1
β : Type u_2
s : Set ℕ
inst✝¹ : Infinite ↑s
inst✝ : DecidablePred fun x => x ∈ s
x✝ : ℕ
x : ℕ := x✝
hx : x✝ ∈ s
t : List ↑s := List.pmap (fun y hy => ⟨y, hy⟩) (List.filter (fun y => decide (y ∈ s)) (List.range x)) ⋯
ht : t = List.pmap (fun y hy => ⟨y, hy⟩) (List.filter (fun y => decide (y ∈ s)) (List.range x)) ⋯
hmt : ∀ {y : ↑s}, y ∈ t ↔ y < ⟨x, hx⟩
wf : ∀ (m : ↑s), t.maximum = ↑m → ↑m < x
⊢ ∃ n, ofNat s n = ⟨x✝, hx⟩
state_after: case bot
α : Type u_1
β : Type u_2
s : Set ℕ
inst✝¹ : Infinite ↑s
inst✝ : DecidablePred fun x => x ∈ s
x✝ : ℕ
x : ℕ := x✝
hx : x✝ ∈ s
t : List ↑s := List.pmap (fun y hy => ⟨y, hy⟩) (List.filter (fun y => decide (y ∈ s)) (List.range x)) ⋯
ht : t = List.pmap (fun y hy => ⟨y, hy⟩) (List.filter (fun y => decide (y ∈ s)) (List.range x)) ⋯
hmt : ∀ {y : ↑s}, y ∈ t ↔ y < ⟨x, hx⟩
wf : ∀ (m : ↑s), t.maximum = ↑m → ↑m < x
hmax : t.maximum = ⊥
⊢ ∃ n, ofNat s n = ⟨x✝, hx⟩

case coe
α : Type u_1
β : Type u_2
s : Set ℕ
inst✝¹ : Infinite ↑s
inst✝ : DecidablePred fun x => x ∈ s
x✝ : ℕ
x : ℕ := x✝
hx : x✝ ∈ s
t : List ↑s := List.pmap (fun y hy => ⟨y, hy⟩) (List.filter (fun y => decide (y ∈ s)) (List.range x)) ⋯
ht : t = List.pmap (fun y hy => ⟨y, hy⟩) (List.filter (fun y => decide (y ∈ s)) (List.range x)) ⋯
hmt : ∀ {y : ↑s}, y ∈ t ↔ y < ⟨x, hx⟩
wf : ∀ (m : ↑s), t.maximum = ↑m → ↑m < x
m : ↑s
hmax : t.maximum = ↑m
⊢ ∃ n, ofNat s n = ⟨x✝, hx⟩
tactic: cases' hmax : List.maximum t with m
state_before: case coe
α : Type u_1
β : Type u_2
s : Set ℕ
inst✝¹ : Infinite ↑s
inst✝ : DecidablePred fun x => x ∈ s
x✝ : ℕ
x : ℕ := x✝
hx : x✝ ∈ s
t : List ↑s := List.pmap (fun y hy => ⟨y, hy⟩) (List.filter (fun y => decide (y ∈ s)) (List.range x)) ⋯
ht : t = List.pmap (fun y hy => ⟨y, hy⟩) (List.filter (fun y => decide (y ∈ s)) (List.range x)) ⋯
hmt : ∀ {y : ↑s}, y ∈ t ↔ y < ⟨x, hx⟩
wf : ∀ (m : ↑s), t.maximum = ↑m → ↑m < x
m : ↑s
hmax : t.maximum = ↑m
⊢ ∃ n, ofNat s n = ⟨x✝, hx⟩
state_after: case coe.intro
α : Type u_1
β : Type u_2
s : Set ℕ
inst✝¹ : Infinite ↑s
inst✝ : DecidablePred fun x => x ∈ s
x✝ : ℕ
x : ℕ := x✝
hx : x✝ ∈ s
t : List ↑s := List.pmap (fun y hy => ⟨y, hy⟩) (List.filter (fun y => decide (y ∈ s)) (List.range x)) ⋯
ht : t = List.pmap (fun y hy => ⟨y, hy⟩) (List.filter (fun y => decide (y ∈ s)) (List.range x)) ⋯
hmt : ∀ {y : ↑s}, y ∈ t ↔ y < ⟨x, hx⟩
wf : ∀ (m : ↑s), t.maximum = ↑m → ↑m < x
m : ↑s
hmax : t.maximum = ↑m
a : ℕ
ha : ofNat s a = ⟨↑m, ⋯⟩
⊢ ∃ n, ofNat s n = ⟨x✝, hx⟩
tactic: cases' ofNat_surjective_aux m.2 with a ha
state_before: case coe.intro
α : Type u_1
β : Type u_2
s : Set ℕ
inst✝¹ : Infinite ↑s
inst✝ : DecidablePred fun x => x ∈ s
x✝ : ℕ
x : ℕ := x✝
hx : x✝ ∈ s
t : List ↑s := List.pmap (fun y hy => ⟨y, hy⟩) (List.filter (fun y => decide (y ∈ s)) (List.range x)) ⋯
ht : t = List.pmap (fun y hy => ⟨y, hy⟩) (List.filter (fun y => decide (y ∈ s)) (List.range x)) ⋯
hmt : ∀ {y : ↑s}, y ∈ t ↔ y < ⟨x, hx⟩
wf : ∀ (m : ↑s), t.maximum = ↑m → ↑m < x
m : ↑s
hmax : t.maximum = ↑m
a : ℕ
ha : ofNat s a = ⟨↑m, ⋯⟩
⊢ ∃ n, ofNat s n = ⟨x✝, hx⟩
state_after: case coe.intro.refine_1
α : Type u_1
β : Type u_2
s : Set ℕ
inst✝¹ : Infinite ↑s
inst✝ : DecidablePred fun x => x ∈ s
x✝ : ℕ
x : ℕ := x✝
hx : x✝ ∈ s
t : List ↑s := List.pmap (fun y hy => ⟨y, hy⟩) (List.filter (fun y => decide (y ∈ s)) (List.range x)) ⋯
ht : t = List.pmap (fun y hy => ⟨y, hy⟩) (List.filter (fun y => decide (y ∈ s)) (List.range x)) ⋯
hmt : ∀ {y : ↑s}, y ∈ t ↔ y < ⟨x, hx⟩
wf : ∀ (m : ↑s), t.maximum = ↑m → ↑m < x
m : ↑s
hmax : t.maximum = ↑m
a : ℕ
ha : ofNat s a = ⟨↑m, ⋯⟩
⊢ succ (ofNat s a) ≤ ⟨x✝, hx⟩

case coe.intro.refine_2
α : Type u_1
β : Type u_2
s : Set ℕ
inst✝¹ : Infinite ↑s
inst✝ : DecidablePred fun x => x ∈ s
x✝ : ℕ
x : ℕ := x✝
hx : x✝ ∈ s
t : List ↑s := List.pmap (fun y hy => ⟨y, hy⟩) (List.filter (fun y => decide (y ∈ s)) (List.range x)) ⋯
ht : t = List.pmap (fun y hy => ⟨y, hy⟩) (List.filter (fun y => decide (y ∈ s)) (List.range x)) ⋯
hmt : ∀ {y : ↑s}, y ∈ t ↔ y < ⟨x, hx⟩
wf : ∀ (m : ↑s), t.maximum = ↑m → ↑m < x
m : ↑s
hmax : t.maximum = ↑m
a : ℕ
ha : ofNat s a = ⟨↑m, ⋯⟩
⊢ ⟨x✝, hx⟩ ≤ succ (ofNat s a)
tactic: refine ⟨a + 1, le_antisymm ?_ ?_⟩ <;> rw [ofNat]
state_before: s : Set ℕ
inst✝¹ : Infinite ↑s
inst✝ : DecidablePred fun x => x ∈ s
x✝ : ℕ
a✝ :
  ∀ (y : ℕ), (invImage (fun x => x) instWellFoundedRelationOfSizeOf).1 y x✝ → ∀ (hx : y ∈ s), ∃ n, ofNat s n = ⟨y, hx⟩
x : ℕ := x✝
hx : x✝ ∈ s
t : List ↑s := List.pmap (fun y hy => ⟨y, hy⟩) (List.filter (fun y => decide (y ∈ s)) (List.range x)) ⋯
ht : t = List.pmap (fun y hy => ⟨y, hy⟩) (List.filter (fun y => decide (y ∈ s)) (List.range x)) ⋯
hmt : ∀ {y : ↑s}, y ∈ t ↔ y < ⟨x, hx⟩
wf : ∀ (m : ↑s), t.maximum = ↑m → ↑m < x
m : ↑s
h✝ hmax : t.maximum = ↑m
⊢ (invImage (fun x => x) instWellFoundedRelationOfSizeOf).1 (↑m) x✝
state_after: no goals
tactic: tauto