l3lab/ntp-mathlib huggingface dataset:
theorem ofNat_surjective_aux : ∀ {x : ℕ} (hx : x ∈ s), ∃ n, ofNat s n = ⟨x, hx⟩
  | x => fun hx => by
    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
    have hmt : ∀ {y : s}, y ∈ t ↔ y < ⟨x, hx⟩ := by
      simp [List.mem_filter, Subtype.ext_iff_val, ht]
    have wf : ∀ m : s, List.maximum t = m → ↑m < x := fun m hmax => by
      simpa using hmt.mp (List.maximum_mem hmax)
    cases' hmax : List.maximum t with m
    · refine ⟨0, le_antisymm bot_le (le_of_not_gt fun h => List.not_mem_nil (⊥ : s) ?_)⟩
      rwa [← List.maximum_eq_none.1 hmax, hmt]
    cases' ofNat_surjective_aux m.2 with a ha
    refine ⟨a + 1, le_antisymm ?_ ?_⟩ <;> rw [ofNat]
    · refine succ_le_of_lt ?_
      rw [ha]
      exact wf _ hmax
    · 

Proof state:
case some.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 => { val := y, property := hy }) (List.filter (fun y => decide (y ∈ s)) (List.range x))
    (_ : ∀ a ∈ List.filter (fun y => decide (y ∈ s)) (List.range x), a ∈ s)
ht :
  t =
    List.pmap (fun y hy => { val := y, property := hy }) (List.filter (fun y => decide (y ∈ s)) (List.range x))
      (_ : ∀ a ∈ List.filter (fun y => decide (y ∈ s)) (List.range x), a ∈ s)
hmt : ∀ {y : ↑s}, y ∈ t ↔ y < { val := x, property := hx }
wf : ∀ (m : ↑s), List.maximum t = ↑m → ↑m < x
m : ↑s
hmax : List.maximum t = some m
a : ℕ
ha : ofNat s a = { val := ↑m, property := (_ : ↑m ∈ s) }
⊢ { val := x✝, property := hx } ≤ succ (ofNat s a)

Next tactic:
refine le_succ_of_forall_lt_le fun z hz => ?_
theorem ofNat_surjective_aux : ∀ {x : ℕ} (hx : x ∈ s), ∃ n, ofNat s n = ⟨x, hx⟩
  | x => fun hx => by
    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
    have hmt : ∀ {y : s}, y ∈ t ↔ y < ⟨x, hx⟩ := by
      simp [List.mem_filter, Subtype.ext_iff_val, ht]
    have wf : ∀ m : s, List.maximum t = m → ↑m < x := fun m hmax => by
      simpa using hmt.mp (List.maximum_mem hmax)
    cases' hmax : List.maximum t with m
    · refine ⟨0, le_antisymm bot_le (le_of_not_gt fun h => List.not_mem_nil (⊥ : s) ?_)⟩
      rwa [← List.maximum_eq_none.1 hmax, hmt]
    cases' ofNat_surjective_aux m.2 with a ha
    refine ⟨a + 1, le_antisymm ?_ ?_⟩ <;> rw [ofNat]
    · refine succ_le_of_lt ?_
      rw [ha]
      exact wf _ hmax
    · refine le_succ_of_forall_lt_le fun z hz => ?_
      

Proof state:
case some.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 => { val := y, property := hy }) (List.filter (fun y => decide (y ∈ s)) (List.range x))
    (_ : ∀ a ∈ List.filter (fun y => decide (y ∈ s)) (List.range x), a ∈ s)
ht :
  t =
    List.pmap (fun y hy => { val := y, property := hy }) (List.filter (fun y => decide (y ∈ s)) (List.range x))
      (_ : ∀ a ∈ List.filter (fun y => decide (y ∈ s)) (List.range x), a ∈ s)
hmt : ∀ {y : ↑s}, y ∈ t ↔ y < { val := x, property := hx }
wf : ∀ (m : ↑s), List.maximum t = ↑m → ↑m < x
m : ↑s
hmax : List.maximum t = some m
a : ℕ
ha : ofNat s a = { val := ↑m, property := (_ : ↑m ∈ s) }
z : ↑s
hz : z < { val := x✝, property := hx }
⊢ z ≤ ofNat s a

Next tactic:
rw [ha]
theorem ofNat_surjective_aux : ∀ {x : ℕ} (hx : x ∈ s), ∃ n, ofNat s n = ⟨x, hx⟩
  | x => fun hx => by
    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
    have hmt : ∀ {y : s}, y ∈ t ↔ y < ⟨x, hx⟩ := by
      simp [List.mem_filter, Subtype.ext_iff_val, ht]
    have wf : ∀ m : s, List.maximum t = m → ↑m < x := fun m hmax => by
      simpa using hmt.mp (List.maximum_mem hmax)
    cases' hmax : List.maximum t with m
    · refine ⟨0, le_antisymm bot_le (le_of_not_gt fun h => List.not_mem_nil (⊥ : s) ?_)⟩
      rwa [← List.maximum_eq_none.1 hmax, hmt]
    cases' ofNat_surjective_aux m.2 with a ha
    refine ⟨a + 1, le_antisymm ?_ ?_⟩ <;> rw [ofNat]
    · refine succ_le_of_lt ?_
      rw [ha]
      exact wf _ hmax
    · refine le_succ_of_forall_lt_le fun z hz => ?_
      rw [ha]
      

Proof state:
case some.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 => { val := y, property := hy }) (List.filter (fun y => decide (y ∈ s)) (List.range x))
    (_ : ∀ a ∈ List.filter (fun y => decide (y ∈ s)) (List.range x), a ∈ s)
ht :
  t =
    List.pmap (fun y hy => { val := y, property := hy }) (List.filter (fun y => decide (y ∈ s)) (List.range x))
      (_ : ∀ a ∈ List.filter (fun y => decide (y ∈ s)) (List.range x), a ∈ s)
hmt : ∀ {y : ↑s}, y ∈ t ↔ y < { val := x, property := hx }
wf : ∀ (m : ↑s), List.maximum t = ↑m → ↑m < x
m : ↑s
hmax : List.maximum t = some m
a : ℕ
ha : ofNat s a = { val := ↑m, property := (_ : ↑m ∈ s) }
z : ↑s
hz : z < { val := x✝, property := hx }
⊢ z ≤ { val := ↑m, property := (_ : ↑m ∈ s) }

Next tactic:
cases m
theorem ofNat_surjective_aux : ∀ {x : ℕ} (hx : x ∈ s), ∃ n, ofNat s n = ⟨x, hx⟩
  | x => fun hx => by
    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
    have hmt : ∀ {y : s}, y ∈ t ↔ y < ⟨x, hx⟩ := by
      simp [List.mem_filter, Subtype.ext_iff_val, ht]
    have wf : ∀ m : s, List.maximum t = m → ↑m < x := fun m hmax => by
      simpa using hmt.mp (List.maximum_mem hmax)
    cases' hmax : List.maximum t with m
    · refine ⟨0, le_antisymm bot_le (le_of_not_gt fun h => List.not_mem_nil (⊥ : s) ?_)⟩
      rwa [← List.maximum_eq_none.1 hmax, hmt]
    cases' ofNat_surjective_aux m.2 with a ha
    refine ⟨a + 1, le_antisymm ?_ ?_⟩ <;> rw [ofNat]
    · refine succ_le_of_lt ?_
      rw [ha]
      exact wf _ hmax
    · refine le_succ_of_forall_lt_le fun z hz => ?_
      rw [ha]
      cases m
      

Proof state:
case some.intro.refine_2.mk
α : 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 => { val := y, property := hy }) (List.filter (fun y => decide (y ∈ s)) (List.range x))
    (_ : ∀ a ∈ List.filter (fun y => decide (y ∈ s)) (List.range x), a ∈ s)
ht :
  t =
    List.pmap (fun y hy => { val := y, property := hy }) (List.filter (fun y => decide (y ∈ s)) (List.range x))
      (_ : ∀ a ∈ List.filter (fun y => decide (y ∈ s)) (List.range x), a ∈ s)
hmt : ∀ {y : ↑s}, y ∈ t ↔ y < { val := x, property := hx }
wf : ∀ (m : ↑s), List.maximum t = ↑m → ↑m < x
a : ℕ
z : ↑s
hz : z < { val := x✝, property := hx }
val✝ : ℕ
property✝ : val✝ ∈ s
hmax : List.maximum t = some { val := val✝, property := property✝ }
ha :
  ofNat s a =
    { val := ↑{ val := val✝, property := property✝ }, property := (_ : ↑{ val := val✝, property := property✝ } ∈ s) }
⊢ z ≤ { val := ↑{ val := val✝, property := property✝ }, property := (_ : ↑{ val := val✝, property := property✝ } ∈ s) }

Next tactic:
exact List.le_maximum_of_mem (hmt.2 hz) hmax
theorem ofNat_surjective_aux : ∀ {x : ℕ} (hx : x ∈ s), ∃ n, ofNat s n = ⟨x, hx⟩
  | x => fun hx => by
    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
    have hmt : ∀ {y : s}, y ∈ t ↔ y < ⟨x, hx⟩ := by
      simp [List.mem_filter, Subtype.ext_iff_val, ht]
    have wf : ∀ m : s, List.maximum t = m → ↑m < x := fun m hmax => by
      simpa using hmt.mp (List.maximum_mem hmax)
    cases' hmax : List.maximum t with m
    · refine ⟨0, le_antisymm bot_le (le_of_not_gt fun h => List.not_mem_nil (⊥ : s) ?_)⟩
      rwa [← List.maximum_eq_none.1 hmax, hmt]
    cases' ofNat_surjective_aux m.2 with a ha
    refine ⟨a + 1, le_antisymm ?_ ?_⟩ <;> rw [ofNat]
    · refine succ_le_of_lt ?_
      rw [ha]
      exact wf _ hmax
    · refine le_succ_of_forall_lt_le fun z hz => ?_
      rw [ha]
      cases m
      exact List.le_maximum_of_mem (hmt.2 hz) hmax
decreasing_by
  

Proof state:
s : Set ℕ
inst✝¹ : Infinite ↑s
inst✝ : DecidablePred fun x => x ∈ s
x✝ : ℕ
a✝ :
  ∀ (y : ℕ),
    (invImage (fun a => sizeOf a) instWellFoundedRelation).1 y x✝ →
      ∀ (hx : y ∈ s), ∃ n, ofNat s n = { val := y, property := hx }
x : ℕ := x✝
hx : x✝ ∈ s
t : List ↑s :=
  List.pmap (fun y hy => { val := y, property := hy }) (List.filter (fun y => decide (y ∈ s)) (List.range x))
    (_ : ∀ a ∈ List.filter (fun y => decide (y ∈ s)) (List.range x), a ∈ s)
ht :
  t =
    List.pmap (fun y hy => { val := y, property := hy }) (List.filter (fun y => decide (y ∈ s)) (List.range x))
      (_ : ∀ a ∈ List.filter (fun y => decide (y ∈ s)) (List.range x), a ∈ s)
hmt : ∀ {y : ↑s}, y ∈ t ↔ y < { val := x, property := hx }
wf : ∀ (m : ↑s), List.maximum t = ↑m → ↑m < x
m : ↑s
h✝ hmax : List.maximum t = some m
t✝ : ∃ n, ofNat s n = { val := ↑m, property := (_ : ↑m ∈ s) }
⊢ (invImage (fun a => sizeOf a) instWellFoundedRelation).1 (↑m) x✝

Next tactic:
tauto
theorem ofNat_surjective_aux : ∀ {x : ℕ} (hx : x ∈ s), ∃ n, ofNat s n = ⟨x, hx⟩
  | x => fun hx => by
    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
    have hmt : ∀ {y : s}, y ∈ t ↔ y < ⟨x, hx⟩ := by
      simp [List.mem_filter, Subtype.ext_iff_val, ht]
    have wf : ∀ m : s, List.maximum t = m → ↑m < x := fun m hmax => by
      simpa using hmt.mp (List.maximum_mem hmax)
    cases' hmax : List.maximum t with m
    · refine ⟨0, le_antisymm bot_le (le_of_not_gt fun h => List.not_mem_nil (⊥ : s) ?_)⟩
      rwa [← List.maximum_eq_none.1 hmax, hmt]
    cases' ofNat_surjective_aux m.2 with a ha
    refine ⟨a + 1, le_antisymm ?_ ?_⟩ <;> rw [ofNat]
    · refine succ_le_of_lt ?_
      rw [ha]
      exact wf _ hmax
    · refine le_succ_of_forall_lt_le fun z hz => ?_
      rw [ha]
      cases m
      exact List.le_maximum_of_mem (hmt.2 hz) hmax
decreasing_by
  

Proof state:
s : Set ℕ
inst✝¹ : Infinite ↑s
inst✝ : DecidablePred fun x => x ∈ s
x✝ : ℕ
a✝ :
  ∀ (y : ℕ),
    (invImage (fun a => sizeOf a) instWellFoundedRelation).1 y x✝ →
      ∀ (hx : y ∈ s), ∃ n, ofNat s n = { val := y, property := hx }
x : ℕ := x✝
hx : x✝ ∈ s
t : List ↑s :=
  List.pmap (fun y hy => { val := y, property := hy }) (List.filter (fun y => decide (y ∈ s)) (List.range x))
    (_ : ∀ a ∈ List.filter (fun y => decide (y ∈ s)) (List.range x), a ∈ s)
ht :
  t =
    List.pmap (fun y hy => { val := y, property := hy }) (List.filter (fun y => decide (y ∈ s)) (List.range x))
      (_ : ∀ a ∈ List.filter (fun y => decide (y ∈ s)) (List.range x), a ∈ s)
hmt : ∀ {y : ↑s}, y ∈ t ↔ y < { val := x, property := hx }
wf : ∀ (m : ↑s), List.maximum t = ↑m → ↑m < x
m : ↑s
h✝ hmax : List.maximum t = some m
⊢ (invImage (fun a => sizeOf a) instWellFoundedRelation).1 (↑m) x✝

Next tactic:
tauto
theorem ofNat_surjective_aux : ∀ {x : ℕ} (hx : x ∈ s), ∃ n, ofNat s n = ⟨x, hx⟩
  | x => fun hx => by
    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
    have hmt : ∀ {y : s}, y ∈ t ↔ y < ⟨x, hx⟩ := by
      simp [List.mem_filter, Subtype.ext_iff_val, ht]
    have wf : ∀ m : s, List.maximum t = m → ↑m < x := fun m hmax => by
      simpa using hmt.mp (List.maximum_mem hmax)
    cases' hmax : List.maximum t with m
    · refine ⟨0, le_antisymm bot_le (le_of_not_gt fun h => List.not_mem_nil (⊥ : s) ?_)⟩
      rwa [← List.maximum_eq_none.1 hmax, hmt]
    cases' ofNat_surjective_aux m.2 with a ha
    refine ⟨a + 1, le_antisymm ?_ ?_⟩ <;> rw [ofNat]
    · refine succ_le_of_lt ?_
      rw [ha]
      exact wf _ hmax
    · refine le_succ_of_forall_lt_le fun z hz => ?_
      rw [ha]
      cases m
      exact List.le_maximum_of_mem (hmt.2 hz) hmax
decreasing_by
  

Proof state:
s : Set ℕ
inst✝¹ : Infinite ↑s
inst✝ : DecidablePred fun x => x ∈ s
x✝ : ℕ
a✝ :
  ∀ (y : ℕ),
    (invImage (fun a => sizeOf a) instWellFoundedRelation).1 y x✝ →
      ∀ (hx : y ∈ s), ∃ n, ofNat s n = { val := y, property := hx }
x : ℕ := x✝
hx : x✝ ∈ s
t : List ↑s :=
  List.pmap (fun y hy => { val := y, property := hy }) (List.filter (fun y => decide (y ∈ s)) (List.range x))
    (_ : ∀ a ∈ List.filter (fun y => decide (y ∈ s)) (List.range x), a ∈ s)
ht :
  t =
    List.pmap (fun y hy => { val := y, property := hy }) (List.filter (fun y => decide (y ∈ s)) (List.range x))
      (_ : ∀ a ∈ List.filter (fun y => decide (y ∈ s)) (List.range x), a ∈ s)
hmt : ∀ {y : ↑s}, y ∈ t ↔ y < { val := x, property := hx }
wf : ∀ (m : ↑s), List.maximum t = ↑m → ↑m < x
m : ↑s
h✝ hmax : List.maximum t = some m
a : ℕ
ha : ofNat s a = { val := ↑m, property := (_ : ↑m ∈ s) }
⊢ (invImage (fun a => sizeOf a) instWellFoundedRelation).1 (↑m) x✝

Next tactic:
tauto
@[simp]
theorem coe_comp_ofNat_range : Set.range ((↑) ∘ ofNat s : ℕ → ℕ) = s := by
  

Proof state:
α : Type u_1
β : Type u_2
s : Set ℕ
inst✝¹ : Infinite ↑s
inst✝ : DecidablePred fun x => x ∈ s
⊢ Set.range (Subtype.val ∘ ofNat s) = s

Next tactic:
rw [Set.range_comp Subtype.val, ofNat_range, Set.image_univ, Subtype.range_coe]
private theorem toFunAux_eq (x : s) : toFunAux x = ((Finset.range x).filter (· ∈ s)).card := by
  

Proof state:
α : Type u_1
β : Type u_2
s : Set ℕ
inst✝¹ : Infinite ↑s
inst✝ : DecidablePred fun x => x ∈ s
x : ↑s
⊢ Nat.Subtype.toFunAux x = Finset.card (Finset.filter (fun x => x ∈ s) (Finset.range ↑x))

Next tactic:
rw [toFunAux, List.countP_eq_length_filter]
private theorem toFunAux_eq (x : s) : toFunAux x = ((Finset.range x).filter (· ∈ s)).card := by
  rw [toFunAux, List.countP_eq_length_filter]
  

Proof state:
α : Type u_1
β : Type u_2
s : Set ℕ
inst✝¹ : Infinite ↑s
inst✝ : DecidablePred fun x => x ∈ s
x : ↑s
⊢ List.length (List.filter (fun x => decide (x ∈ s)) (List.range ↑x)) =
    Finset.card (Finset.filter (fun x => x ∈ s) (Finset.range ↑x))

Next tactic:
rfl
private theorem right_inverse_aux : ∀ n, toFunAux (ofNat s n) = n
  | 0 => by
    

Proof state:
α : Type u_1
β : Type u_2
s : Set ℕ
inst✝¹ : Infinite ↑s
inst✝ : DecidablePred fun x => x ∈ s
⊢ Nat.Subtype.toFunAux (ofNat s 0) = 0

Next tactic:
rw [toFunAux_eq, card_eq_zero, eq_empty_iff_forall_not_mem]
private theorem right_inverse_aux : ∀ n, toFunAux (ofNat s n) = n
  | 0 => by
    rw [toFunAux_eq, card_eq_zero, eq_empty_iff_forall_not_mem]
    

Proof state:
α : Type u_1
β : Type u_2
s : Set ℕ
inst✝¹ : Infinite ↑s
inst✝ : DecidablePred fun x => x ∈ s
⊢ ∀ (x : ℕ), x ∉ filter (fun x => x ∈ s) (range ↑(ofNat s 0))

Next tactic:
rintro n hn
private theorem right_inverse_aux : ∀ n, toFunAux (ofNat s n) = n
  | 0 => by
    rw [toFunAux_eq, card_eq_zero, eq_empty_iff_forall_not_mem]
    rintro n hn
    

Proof state:
α : Type u_1
β : Type u_2
s : Set ℕ
inst✝¹ : Infinite ↑s
inst✝ : DecidablePred fun x => x ∈ s
n : ℕ
hn : n ∈ filter (fun x => x ∈ s) (range ↑(ofNat s 0))
⊢ False

Next tactic:
rw [mem_filter, ofNat, mem_range] at hn
private theorem right_inverse_aux : ∀ n, toFunAux (ofNat s n) = n
  | 0 => by
    rw [toFunAux_eq, card_eq_zero, eq_empty_iff_forall_not_mem]
    rintro n hn
    rw [mem_filter, ofNat, mem_range] at hn
    

Proof state:
α : Type u_1
β : Type u_2
s : Set ℕ
inst✝¹ : Infinite ↑s
inst✝ : DecidablePred fun x => x ∈ s
n : ℕ
hn : n < ↑⊥ ∧ n ∈ s
⊢ False

Next tactic:
exact bot_le.not_lt (show (⟨n, hn.2⟩ : s) < ⊥ from hn.1)
private theorem right_inverse_aux : ∀ n, toFunAux (ofNat s n) = n
  | 0 => by
    rw [toFunAux_eq, card_eq_zero, eq_empty_iff_forall_not_mem]
    rintro n hn
    rw [mem_filter, ofNat, mem_range] at hn
    exact bot_le.not_lt (show (⟨n, hn.2⟩ : s) < ⊥ from hn.1)
  | n + 1 => by
    

Proof state:
α : Type u_1
β : Type u_2
s : Set ℕ
inst✝¹ : Infinite ↑s
inst✝ : DecidablePred fun x => x ∈ s
n : ℕ
⊢ Nat.Subtype.toFunAux (ofNat s (n + 1)) = n + 1

Next tactic:
have ih : toFunAux (ofNat s n) = n := right_inverse_aux n
private theorem right_inverse_aux : ∀ n, toFunAux (ofNat s n) = n
  | 0 => by
    rw [toFunAux_eq, card_eq_zero, eq_empty_iff_forall_not_mem]
    rintro n hn
    rw [mem_filter, ofNat, mem_range] at hn
    exact bot_le.not_lt (show (⟨n, hn.2⟩ : s) < ⊥ from hn.1)
  | n + 1 => by
    have ih : toFunAux (ofNat s n) = n := right_inverse_aux n
    

Proof state:
α : Type u_1
β : Type u_2
s : Set ℕ
inst✝¹ : Infinite ↑s
inst✝ : DecidablePred fun x => x ∈ s
n : ℕ
ih : Nat.Subtype.toFunAux (ofNat s n) = n
⊢ Nat.Subtype.toFunAux (ofNat s (n + 1)) = n + 1

Next tactic:
have h₁ : (ofNat s n : ℕ) ∉ (range (ofNat s n)).filter (· ∈ s) := by simp
private theorem right_inverse_aux : ∀ n, toFunAux (ofNat s n) = n
  | 0 => by
    rw [toFunAux_eq, card_eq_zero, eq_empty_iff_forall_not_mem]
    rintro n hn
    rw [mem_filter, ofNat, mem_range] at hn
    exact bot_le.not_lt (show (⟨n, hn.2⟩ : s) < ⊥ from hn.1)
  | n + 1 => by
    have ih : toFunAux (ofNat s n) = n := right_inverse_aux n
    have h₁ : (ofNat s n : ℕ) ∉ (range (ofNat s n)).filter (· ∈ s) := by 

Proof state:
α : Type u_1
β : Type u_2
s : Set ℕ
inst✝¹ : Infinite ↑s
inst✝ : DecidablePred fun x => x ∈ s
n : ℕ
ih : Nat.Subtype.toFunAux (ofNat s n) = n
⊢ ↑(ofNat s n) ∉ filter (fun x => x ∈ s) (range ↑(ofNat s n))

Next tactic:
simp
private theorem right_inverse_aux : ∀ n, toFunAux (ofNat s n) = n
  | 0 => by
    rw [toFunAux_eq, card_eq_zero, eq_empty_iff_forall_not_mem]
    rintro n hn
    rw [mem_filter, ofNat, mem_range] at hn
    exact bot_le.not_lt (show (⟨n, hn.2⟩ : s) < ⊥ from hn.1)
  | n + 1 => by
    have ih : toFunAux (ofNat s n) = n := right_inverse_aux n
    have h₁ : (ofNat s n : ℕ) ∉ (range (ofNat s n)).filter (· ∈ s) := by simp
    

Proof state:
α : Type u_1
β : Type u_2
s : Set ℕ
inst✝¹ : Infinite ↑s
inst✝ : DecidablePred fun x => x ∈ s
n : ℕ
ih : Nat.Subtype.toFunAux (ofNat s n) = n
h₁ : ↑(ofNat s n) ∉ filter (fun x => x ∈ s) (range ↑(ofNat s n))
⊢ Nat.Subtype.toFunAux (ofNat s (n + 1)) = n + 1

Next tactic:
have h₂ : (range (succ (ofNat s n))).filter (· ∈ s) =
        insert ↑(ofNat s n) ((range (ofNat s n)).filter (· ∈ s)) := by
      simp only [Finset.ext_iff, mem_insert, mem_range, mem_filter]
      exact fun m =>
        ⟨fun h => by
          simp only [h.2, and_true_iff]
          exact Or.symm (lt_or_eq_of_le ((@lt_succ_iff_le _ _ _ ⟨m, h.2⟩ _).1 h.1)),
         fun h =>
          h.elim (fun h => h.symm ▸ ⟨lt_succ_self _, (ofNat s n).prop⟩) fun h =>
            ⟨h.1.trans (lt_succ_self _), h.2⟩⟩
private theorem right_inverse_aux : ∀ n, toFunAux (ofNat s n) = n
  | 0 => by
    rw [toFunAux_eq, card_eq_zero, eq_empty_iff_forall_not_mem]
    rintro n hn
    rw [mem_filter, ofNat, mem_range] at hn
    exact bot_le.not_lt (show (⟨n, hn.2⟩ : s) < ⊥ from hn.1)
  | n + 1 => by
    have ih : toFunAux (ofNat s n) = n := right_inverse_aux n
    have h₁ : (ofNat s n : ℕ) ∉ (range (ofNat s n)).filter (· ∈ s) := by simp
    have h₂ : (range (succ (ofNat s n))).filter (· ∈ s) =
        insert ↑(ofNat s n) ((range (ofNat s n)).filter (· ∈ s)) := by
      

Proof state:
α : Type u_1
β : Type u_2
s : Set ℕ
inst✝¹ : Infinite ↑s
inst✝ : DecidablePred fun x => x ∈ s
n : ℕ
ih : Nat.Subtype.toFunAux (ofNat s n) = n
h₁ : ↑(ofNat s n) ∉ filter (fun x => x ∈ s) (range ↑(ofNat s n))
⊢ filter (fun x => x ∈ s) (range ↑(succ (ofNat s n))) =
    insert (↑(ofNat s n)) (filter (fun x => x ∈ s) (range ↑(ofNat s n)))

Next tactic:
simp only [Finset.ext_iff, mem_insert, mem_range, mem_filter]
private theorem right_inverse_aux : ∀ n, toFunAux (ofNat s n) = n
  | 0 => by
    rw [toFunAux_eq, card_eq_zero, eq_empty_iff_forall_not_mem]
    rintro n hn
    rw [mem_filter, ofNat, mem_range] at hn
    exact bot_le.not_lt (show (⟨n, hn.2⟩ : s) < ⊥ from hn.1)
  | n + 1 => by
    have ih : toFunAux (ofNat s n) = n := right_inverse_aux n
    have h₁ : (ofNat s n : ℕ) ∉ (range (ofNat s n)).filter (· ∈ s) := by simp
    have h₂ : (range (succ (ofNat s n))).filter (· ∈ s) =
        insert ↑(ofNat s n) ((range (ofNat s n)).filter (· ∈ s)) := by
      simp only [Finset.ext_iff, mem_insert, mem_range, mem_filter]
      

Proof state:
α : Type u_1
β : Type u_2
s : Set ℕ
inst✝¹ : Infinite ↑s
inst✝ : DecidablePred fun x => x ∈ s
n : ℕ
ih : Nat.Subtype.toFunAux (ofNat s n) = n
h₁ : ↑(ofNat s n) ∉ filter (fun x => x ∈ s) (range ↑(ofNat s n))
⊢ ∀ (a : ℕ), a < ↑(succ (ofNat s n)) ∧ a ∈ s ↔ a = ↑(ofNat s n) ∨ a < ↑(ofNat s n) ∧ a ∈ s

Next tactic:
exact fun m =>
        ⟨fun h => by
          simp only [h.2, and_true_iff]
          exact Or.symm (lt_or_eq_of_le ((@lt_succ_iff_le _ _ _ ⟨m, h.2⟩ _).1 h.1)),
         fun h =>
          h.elim (fun h => h.symm ▸ ⟨lt_succ_self _, (ofNat s n).prop⟩) fun h =>
            ⟨h.1.trans (lt_succ_self _), h.2⟩⟩
private theorem right_inverse_aux : ∀ n, toFunAux (ofNat s n) = n
  | 0 => by
    rw [toFunAux_eq, card_eq_zero, eq_empty_iff_forall_not_mem]
    rintro n hn
    rw [mem_filter, ofNat, mem_range] at hn
    exact bot_le.not_lt (show (⟨n, hn.2⟩ : s) < ⊥ from hn.1)
  | n + 1 => by
    have ih : toFunAux (ofNat s n) = n := right_inverse_aux n
    have h₁ : (ofNat s n : ℕ) ∉ (range (ofNat s n)).filter (· ∈ s) := by simp
    have h₂ : (range (succ (ofNat s n))).filter (· ∈ s) =
        insert ↑(ofNat s n) ((range (ofNat s n)).filter (· ∈ s)) := by
      simp only [Finset.ext_iff, mem_insert, mem_range, mem_filter]
      exact fun m =>
        ⟨fun h => by
          

Proof state:
α : Type u_1
β : Type u_2
s : Set ℕ
inst✝¹ : Infinite ↑s
inst✝ : DecidablePred fun x => x ∈ s
n : ℕ
ih : Nat.Subtype.toFunAux (ofNat s n) = n
h₁ : ↑(ofNat s n) ∉ filter (fun x => x ∈ s) (range ↑(ofNat s n))
m : ℕ
h : m < ↑(succ (ofNat s n)) ∧ m ∈ s
⊢ m = ↑(ofNat s n) ∨ m < ↑(ofNat s n) ∧ m ∈ s

Next tactic:
simp only [h.2, and_true_iff]
private theorem right_inverse_aux : ∀ n, toFunAux (ofNat s n) = n
  | 0 => by
    rw [toFunAux_eq, card_eq_zero, eq_empty_iff_forall_not_mem]
    rintro n hn
    rw [mem_filter, ofNat, mem_range] at hn
    exact bot_le.not_lt (show (⟨n, hn.2⟩ : s) < ⊥ from hn.1)
  | n + 1 => by
    have ih : toFunAux (ofNat s n) = n := right_inverse_aux n
    have h₁ : (ofNat s n : ℕ) ∉ (range (ofNat s n)).filter (· ∈ s) := by simp
    have h₂ : (range (succ (ofNat s n))).filter (· ∈ s) =
        insert ↑(ofNat s n) ((range (ofNat s n)).filter (· ∈ s)) := by
      simp only [Finset.ext_iff, mem_insert, mem_range, mem_filter]
      exact fun m =>
        ⟨fun h => by
          simp only [h.2, and_true_iff]
          

Proof state:
α : Type u_1
β : Type u_2
s : Set ℕ
inst✝¹ : Infinite ↑s
inst✝ : DecidablePred fun x => x ∈ s
n : ℕ
ih : Nat.Subtype.toFunAux (ofNat s n) = n
h₁ : ↑(ofNat s n) ∉ filter (fun x => x ∈ s) (range ↑(ofNat s n))
m : ℕ
h : m < ↑(succ (ofNat s n)) ∧ m ∈ s
⊢ m = ↑(ofNat s n) ∨ m < ↑(ofNat s n)

Next tactic:
exact Or.symm (lt_or_eq_of_le ((@lt_succ_iff_le _ _ _ ⟨m, h.2⟩ _).1 h.1))