l3lab/ntp-mathlib huggingface dataset:
theorem chainHeight_image (f : α → β) (hf : ∀ {x y}, x < y ↔ f x < f y) (s : Set α) :
    (f '' s).chainHeight = s.chainHeight := by
  apply le_antisymm <;> rw [chainHeight_le_chainHeight_iff]
  · suffices ∀ l ∈ (f '' s).subchain, ∃ l' ∈ s.subchain, map f l' = l by
      intro l hl
      obtain ⟨l', h₁, rfl⟩ := this l hl
      exact ⟨l', h₁, length_map _ _⟩
    intro l
    induction' l with x xs hx
    · exact fun _ ↦ ⟨nil, ⟨trivial, fun x h ↦ (not_mem_nil x h).elim⟩, rfl⟩
    · intro h
      rw [cons_mem_subchain_iff] at h
      obtain ⟨⟨x, hx', rfl⟩, h₁, h₂⟩ := h
      obtain ⟨l', h₃, rfl⟩ := hx h₁
      refine' ⟨x::l', Set.cons_mem_subchain_iff.mpr ⟨hx', h₃, _⟩, rfl⟩
      cases l'
      · simp
      · simpa [← hf] using h₂
  · intro l hl
    refine' ⟨l.map f, ⟨_, _⟩, _⟩
    · simp_rw [chain'_map, ← hf]
      

Proof state:
case a.refine'_1
α : Type u_1
β : Type u_2
inst✝¹ : LT α
inst✝ : LT β
s✝ t : Set α
l✝ : List α
a : α
f : α → β
hf : ∀ {x y : α}, x < y ↔ f x < f y
s : Set α
l : List α
hl : l ∈ subchain s
⊢ Chain' (fun a b => a < b) l

Next tactic:
exact hl.1
theorem chainHeight_image (f : α → β) (hf : ∀ {x y}, x < y ↔ f x < f y) (s : Set α) :
    (f '' s).chainHeight = s.chainHeight := by
  apply le_antisymm <;> rw [chainHeight_le_chainHeight_iff]
  · suffices ∀ l ∈ (f '' s).subchain, ∃ l' ∈ s.subchain, map f l' = l by
      intro l hl
      obtain ⟨l', h₁, rfl⟩ := this l hl
      exact ⟨l', h₁, length_map _ _⟩
    intro l
    induction' l with x xs hx
    · exact fun _ ↦ ⟨nil, ⟨trivial, fun x h ↦ (not_mem_nil x h).elim⟩, rfl⟩
    · intro h
      rw [cons_mem_subchain_iff] at h
      obtain ⟨⟨x, hx', rfl⟩, h₁, h₂⟩ := h
      obtain ⟨l', h₃, rfl⟩ := hx h₁
      refine' ⟨x::l', Set.cons_mem_subchain_iff.mpr ⟨hx', h₃, _⟩, rfl⟩
      cases l'
      · simp
      · simpa [← hf] using h₂
  · intro l hl
    refine' ⟨l.map f, ⟨_, _⟩, _⟩
    · simp_rw [chain'_map, ← hf]
      exact hl.1
    · 

Proof state:
case a.refine'_2
α : Type u_1
β : Type u_2
inst✝¹ : LT α
inst✝ : LT β
s✝ t : Set α
l✝ : List α
a : α
f : α → β
hf : ∀ {x y : α}, x < y ↔ f x < f y
s : Set α
l : List α
hl : l ∈ subchain s
⊢ ∀ i ∈ map f l, i ∈ f '' s

Next tactic:
intro _ e
theorem chainHeight_image (f : α → β) (hf : ∀ {x y}, x < y ↔ f x < f y) (s : Set α) :
    (f '' s).chainHeight = s.chainHeight := by
  apply le_antisymm <;> rw [chainHeight_le_chainHeight_iff]
  · suffices ∀ l ∈ (f '' s).subchain, ∃ l' ∈ s.subchain, map f l' = l by
      intro l hl
      obtain ⟨l', h₁, rfl⟩ := this l hl
      exact ⟨l', h₁, length_map _ _⟩
    intro l
    induction' l with x xs hx
    · exact fun _ ↦ ⟨nil, ⟨trivial, fun x h ↦ (not_mem_nil x h).elim⟩, rfl⟩
    · intro h
      rw [cons_mem_subchain_iff] at h
      obtain ⟨⟨x, hx', rfl⟩, h₁, h₂⟩ := h
      obtain ⟨l', h₃, rfl⟩ := hx h₁
      refine' ⟨x::l', Set.cons_mem_subchain_iff.mpr ⟨hx', h₃, _⟩, rfl⟩
      cases l'
      · simp
      · simpa [← hf] using h₂
  · intro l hl
    refine' ⟨l.map f, ⟨_, _⟩, _⟩
    · simp_rw [chain'_map, ← hf]
      exact hl.1
    · intro _ e
      

Proof state:
case a.refine'_2
α : Type u_1
β : Type u_2
inst✝¹ : LT α
inst✝ : LT β
s✝ t : Set α
l✝ : List α
a : α
f : α → β
hf : ∀ {x y : α}, x < y ↔ f x < f y
s : Set α
l : List α
hl : l ∈ subchain s
i✝ : β
e : i✝ ∈ map f l
⊢ i✝ ∈ f '' s

Next tactic:
obtain ⟨a, ha, rfl⟩ := mem_map.mp e
theorem chainHeight_image (f : α → β) (hf : ∀ {x y}, x < y ↔ f x < f y) (s : Set α) :
    (f '' s).chainHeight = s.chainHeight := by
  apply le_antisymm <;> rw [chainHeight_le_chainHeight_iff]
  · suffices ∀ l ∈ (f '' s).subchain, ∃ l' ∈ s.subchain, map f l' = l by
      intro l hl
      obtain ⟨l', h₁, rfl⟩ := this l hl
      exact ⟨l', h₁, length_map _ _⟩
    intro l
    induction' l with x xs hx
    · exact fun _ ↦ ⟨nil, ⟨trivial, fun x h ↦ (not_mem_nil x h).elim⟩, rfl⟩
    · intro h
      rw [cons_mem_subchain_iff] at h
      obtain ⟨⟨x, hx', rfl⟩, h₁, h₂⟩ := h
      obtain ⟨l', h₃, rfl⟩ := hx h₁
      refine' ⟨x::l', Set.cons_mem_subchain_iff.mpr ⟨hx', h₃, _⟩, rfl⟩
      cases l'
      · simp
      · simpa [← hf] using h₂
  · intro l hl
    refine' ⟨l.map f, ⟨_, _⟩, _⟩
    · simp_rw [chain'_map, ← hf]
      exact hl.1
    · intro _ e
      obtain ⟨a, ha, rfl⟩ := mem_map.mp e
      

Proof state:
case a.refine'_2.intro.intro
α : Type u_1
β : Type u_2
inst✝¹ : LT α
inst✝ : LT β
s✝ t : Set α
l✝ : List α
a✝ : α
f : α → β
hf : ∀ {x y : α}, x < y ↔ f x < f y
s : Set α
l : List α
hl : l ∈ subchain s
a : α
ha : a ∈ l
e : f a ∈ map f l
⊢ f a ∈ f '' s

Next tactic:
exact Set.mem_image_of_mem _ (hl.2 _ ha)
theorem chainHeight_image (f : α → β) (hf : ∀ {x y}, x < y ↔ f x < f y) (s : Set α) :
    (f '' s).chainHeight = s.chainHeight := by
  apply le_antisymm <;> rw [chainHeight_le_chainHeight_iff]
  · suffices ∀ l ∈ (f '' s).subchain, ∃ l' ∈ s.subchain, map f l' = l by
      intro l hl
      obtain ⟨l', h₁, rfl⟩ := this l hl
      exact ⟨l', h₁, length_map _ _⟩
    intro l
    induction' l with x xs hx
    · exact fun _ ↦ ⟨nil, ⟨trivial, fun x h ↦ (not_mem_nil x h).elim⟩, rfl⟩
    · intro h
      rw [cons_mem_subchain_iff] at h
      obtain ⟨⟨x, hx', rfl⟩, h₁, h₂⟩ := h
      obtain ⟨l', h₃, rfl⟩ := hx h₁
      refine' ⟨x::l', Set.cons_mem_subchain_iff.mpr ⟨hx', h₃, _⟩, rfl⟩
      cases l'
      · simp
      · simpa [← hf] using h₂
  · intro l hl
    refine' ⟨l.map f, ⟨_, _⟩, _⟩
    · simp_rw [chain'_map, ← hf]
      exact hl.1
    · intro _ e
      obtain ⟨a, ha, rfl⟩ := mem_map.mp e
      exact Set.mem_image_of_mem _ (hl.2 _ ha)
    · 

Proof state:
case a.refine'_3
α : Type u_1
β : Type u_2
inst✝¹ : LT α
inst✝ : LT β
s✝ t : Set α
l✝ : List α
a : α
f : α → β
hf : ∀ {x y : α}, x < y ↔ f x < f y
s : Set α
l : List α
hl : l ∈ subchain s
⊢ length l = length (map f l)

Next tactic:
rw [length_map]
@[simp]
theorem chainHeight_dual : (ofDual ⁻¹' s).chainHeight = s.chainHeight := by
  

Proof state:
α : Type u_1
β : Type u_2
inst✝¹ : LT α
inst✝ : LT β
s t : Set α
l : List α
a : α
⊢ chainHeight (⇑ofDual ⁻¹' s) = chainHeight s

Next tactic:
apply le_antisymm
@[simp]
theorem chainHeight_dual : (ofDual ⁻¹' s).chainHeight = s.chainHeight := by
  apply le_antisymm <;>
  · 

Proof state:
case a
α : Type u_1
β : Type u_2
inst✝¹ : LT α
inst✝ : LT β
s t : Set α
l : List α
a : α
⊢ chainHeight (⇑ofDual ⁻¹' s) ≤ chainHeight s

Next tactic:
rw [chainHeight_le_chainHeight_iff]
@[simp]
theorem chainHeight_dual : (ofDual ⁻¹' s).chainHeight = s.chainHeight := by
  apply le_antisymm <;>
  · rw [chainHeight_le_chainHeight_iff]
    

Proof state:
case a
α : Type u_1
β : Type u_2
inst✝¹ : LT α
inst✝ : LT β
s t : Set α
l : List α
a : α
⊢ ∀ l ∈ subchain (⇑ofDual ⁻¹' s), ∃ l' ∈ subchain s, length l = length l'

Next tactic:
rintro l ⟨h₁, h₂⟩
@[simp]
theorem chainHeight_dual : (ofDual ⁻¹' s).chainHeight = s.chainHeight := by
  apply le_antisymm <;>
  · rw [chainHeight_le_chainHeight_iff]
    rintro l ⟨h₁, h₂⟩
    

Proof state:
case a.intro
α : Type u_1
β : Type u_2
inst✝¹ : LT α
inst✝ : LT β
s t : Set α
l✝ : List α
a : α
l : List αᵒᵈ
h₁ : Chain' (fun x x_1 => x < x_1) l
h₂ : ∀ i ∈ l, i ∈ ⇑ofDual ⁻¹' s
⊢ ∃ l' ∈ subchain s, length l = length l'

Next tactic:
exact ⟨l.reverse, ⟨chain'_reverse.mpr h₁, fun i h ↦ h₂ i (mem_reverse.mp h)⟩,
      (length_reverse _).symm⟩
@[simp]
theorem chainHeight_dual : (ofDual ⁻¹' s).chainHeight = s.chainHeight := by
  apply le_antisymm <;>
  · 

Proof state:
case a
α : Type u_1
β : Type u_2
inst✝¹ : LT α
inst✝ : LT β
s t : Set α
l : List α
a : α
⊢ chainHeight s ≤ chainHeight (⇑ofDual ⁻¹' s)

Next tactic:
rw [chainHeight_le_chainHeight_iff]
@[simp]
theorem chainHeight_dual : (ofDual ⁻¹' s).chainHeight = s.chainHeight := by
  apply le_antisymm <;>
  · rw [chainHeight_le_chainHeight_iff]
    

Proof state:
case a
α : Type u_1
β : Type u_2
inst✝¹ : LT α
inst✝ : LT β
s t : Set α
l : List α
a : α
⊢ ∀ l ∈ subchain s, ∃ l' ∈ subchain (⇑ofDual ⁻¹' s), length l = length l'

Next tactic:
rintro l ⟨h₁, h₂⟩
@[simp]
theorem chainHeight_dual : (ofDual ⁻¹' s).chainHeight = s.chainHeight := by
  apply le_antisymm <;>
  · rw [chainHeight_le_chainHeight_iff]
    rintro l ⟨h₁, h₂⟩
    

Proof state:
case a.intro
α : Type u_1
β : Type u_2
inst✝¹ : LT α
inst✝ : LT β
s t : Set α
l✝ : List α
a : α
l : List α
h₁ : Chain' (fun x x_1 => x < x_1) l
h₂ : ∀ i ∈ l, i ∈ s
⊢ ∃ l' ∈ subchain (⇑ofDual ⁻¹' s), length l = length l'

Next tactic:
exact ⟨l.reverse, ⟨chain'_reverse.mpr h₁, fun i h ↦ h₂ i (mem_reverse.mp h)⟩,
      (length_reverse _).symm⟩
theorem chainHeight_eq_iSup_Ici : s.chainHeight = ⨆ i ∈ s, (s ∩ Set.Ici i).chainHeight := by
  

Proof state:
α : Type u_1
β : Type u_2
s t : Set α
inst✝ : Preorder α
⊢ chainHeight s = ⨆ i ∈ s, chainHeight (s ∩ Ici i)

Next tactic:
apply le_antisymm
theorem chainHeight_eq_iSup_Ici : s.chainHeight = ⨆ i ∈ s, (s ∩ Set.Ici i).chainHeight := by
  apply le_antisymm
  · 

Proof state:
case a
α : Type u_1
β : Type u_2
s t : Set α
inst✝ : Preorder α
⊢ chainHeight s ≤ ⨆ i ∈ s, chainHeight (s ∩ Ici i)

Next tactic:
refine' iSup₂_le _
theorem chainHeight_eq_iSup_Ici : s.chainHeight = ⨆ i ∈ s, (s ∩ Set.Ici i).chainHeight := by
  apply le_antisymm
  · refine' iSup₂_le _
    

Proof state:
case a
α : Type u_1
β : Type u_2
s t : Set α
inst✝ : Preorder α
⊢ ∀ i ∈ subchain s, ↑(length i) ≤ ⨆ i ∈ s, chainHeight (s ∩ Ici i)

Next tactic:
rintro (_ | ⟨x, xs⟩) h
theorem chainHeight_eq_iSup_Ici : s.chainHeight = ⨆ i ∈ s, (s ∩ Set.Ici i).chainHeight := by
  apply le_antisymm
  · refine' iSup₂_le _
    rintro (_ | ⟨x, xs⟩) h
    · 

Proof state:
case a.nil
α : Type u_1
β : Type u_2
s t : Set α
inst✝ : Preorder α
h : [] ∈ subchain s
⊢ ↑(length []) ≤ ⨆ i ∈ s, chainHeight (s ∩ Ici i)

Next tactic:
exact zero_le _
theorem chainHeight_eq_iSup_Ici : s.chainHeight = ⨆ i ∈ s, (s ∩ Set.Ici i).chainHeight := by
  apply le_antisymm
  · refine' iSup₂_le _
    rintro (_ | ⟨x, xs⟩) h
    · exact zero_le _
    · 

Proof state:
case a.cons
α : Type u_1
β : Type u_2
s t : Set α
inst✝ : Preorder α
x : α
xs : List α
h : x :: xs ∈ subchain s
⊢ ↑(length (x :: xs)) ≤ ⨆ i ∈ s, chainHeight (s ∩ Ici i)

Next tactic:
apply le_trans _ (le_iSup₂ x (cons_mem_subchain_iff.mp h).1)
theorem chainHeight_eq_iSup_Ici : s.chainHeight = ⨆ i ∈ s, (s ∩ Set.Ici i).chainHeight := by
  apply le_antisymm
  · refine' iSup₂_le _
    rintro (_ | ⟨x, xs⟩) h
    · exact zero_le _
    · apply le_trans _ (le_iSup₂ x (cons_mem_subchain_iff.mp h).1)
      

Proof state:
α : Type u_1
β : Type u_2
s t : Set α
inst✝ : Preorder α
x : α
xs : List α
h : x :: xs ∈ subchain s
⊢ ↑(length (x :: xs)) ≤ chainHeight (s ∩ Ici x)

Next tactic:
apply length_le_chainHeight_of_mem_subchain
theorem chainHeight_eq_iSup_Ici : s.chainHeight = ⨆ i ∈ s, (s ∩ Set.Ici i).chainHeight := by
  apply le_antisymm
  · refine' iSup₂_le _
    rintro (_ | ⟨x, xs⟩) h
    · exact zero_le _
    · apply le_trans _ (le_iSup₂ x (cons_mem_subchain_iff.mp h).1)
      apply length_le_chainHeight_of_mem_subchain
      

Proof state:
case hl
α : Type u_1
β : Type u_2
s t : Set α
inst✝ : Preorder α
x : α
xs : List α
h : x :: xs ∈ subchain s
⊢ x :: xs ∈ subchain (s ∩ Ici x)

Next tactic:
refine' ⟨h.1, fun i hi ↦ ⟨h.2 i hi, _⟩⟩
theorem chainHeight_eq_iSup_Ici : s.chainHeight = ⨆ i ∈ s, (s ∩ Set.Ici i).chainHeight := by
  apply le_antisymm
  · refine' iSup₂_le _
    rintro (_ | ⟨x, xs⟩) h
    · exact zero_le _
    · apply le_trans _ (le_iSup₂ x (cons_mem_subchain_iff.mp h).1)
      apply length_le_chainHeight_of_mem_subchain
      refine' ⟨h.1, fun i hi ↦ ⟨h.2 i hi, _⟩⟩
      

Proof state:
case hl
α : Type u_1
β : Type u_2
s t : Set α
inst✝ : Preorder α
x : α
xs : List α
h : x :: xs ∈ subchain s
i : α
hi : i ∈ x :: xs
⊢ i ∈ Ici x

Next tactic:
cases hi
theorem chainHeight_eq_iSup_Ici : s.chainHeight = ⨆ i ∈ s, (s ∩ Set.Ici i).chainHeight := by
  apply le_antisymm
  · refine' iSup₂_le _
    rintro (_ | ⟨x, xs⟩) h
    · exact zero_le _
    · apply le_trans _ (le_iSup₂ x (cons_mem_subchain_iff.mp h).1)
      apply length_le_chainHeight_of_mem_subchain
      refine' ⟨h.1, fun i hi ↦ ⟨h.2 i hi, _⟩⟩
      cases hi
      · 

Proof state:
case hl.head
α : Type u_1
β : Type u_2
s t : Set α
inst✝ : Preorder α
x : α
xs : List α
h : x :: xs ∈ subchain s
⊢ x ∈ Ici x

Next tactic:
exact left_mem_Ici
theorem chainHeight_eq_iSup_Ici : s.chainHeight = ⨆ i ∈ s, (s ∩ Set.Ici i).chainHeight := by
  apply le_antisymm
  · refine' iSup₂_le _
    rintro (_ | ⟨x, xs⟩) h
    · exact zero_le _
    · apply le_trans _ (le_iSup₂ x (cons_mem_subchain_iff.mp h).1)
      apply length_le_chainHeight_of_mem_subchain
      refine' ⟨h.1, fun i hi ↦ ⟨h.2 i hi, _⟩⟩
      cases hi
      · exact left_mem_Ici
      

Proof state:
case hl.tail
α : Type u_1
β : Type u_2
s t : Set α
inst✝ : Preorder α
x : α
xs : List α
h : x :: xs ∈ subchain s
i : α
a✝ : Mem i xs
⊢ i ∈ Ici x

Next tactic:
rename_i hi
theorem chainHeight_eq_iSup_Ici : s.chainHeight = ⨆ i ∈ s, (s ∩ Set.Ici i).chainHeight := by
  apply le_antisymm
  · refine' iSup₂_le _
    rintro (_ | ⟨x, xs⟩) h
    · exact zero_le _
    · apply le_trans _ (le_iSup₂ x (cons_mem_subchain_iff.mp h).1)
      apply length_le_chainHeight_of_mem_subchain
      refine' ⟨h.1, fun i hi ↦ ⟨h.2 i hi, _⟩⟩
      cases hi
      · exact left_mem_Ici
      rename_i hi
      

Proof state:
case hl.tail
α : Type u_1
β : Type u_2
s t : Set α
inst✝ : Preorder α
x : α
xs : List α
h : x :: xs ∈ subchain s
i : α
hi : Mem i xs
⊢ i ∈ Ici x

Next tactic:
cases' chain'_iff_pairwise.mp h.1 with _ _ h'
theorem chainHeight_eq_iSup_Ici : s.chainHeight = ⨆ i ∈ s, (s ∩ Set.Ici i).chainHeight := by
  apply le_antisymm
  · refine' iSup₂_le _
    rintro (_ | ⟨x, xs⟩) h
    · exact zero_le _
    · apply le_trans _ (le_iSup₂ x (cons_mem_subchain_iff.mp h).1)
      apply length_le_chainHeight_of_mem_subchain
      refine' ⟨h.1, fun i hi ↦ ⟨h.2 i hi, _⟩⟩
      cases hi
      · exact left_mem_Ici
      rename_i hi
      cases' chain'_iff_pairwise.mp h.1 with _ _ h'
      

Proof state:
case hl.tail.cons
α : Type u_1
β : Type u_2
s t : Set α
inst✝ : Preorder α
x : α
xs : List α
h : x :: xs ∈ subchain s
i : α
hi : Mem i xs
a✝ : List.Pairwise (fun x x_1 => x < x_1) xs
h' : ∀ a' ∈ xs, x < a'
⊢ i ∈ Ici x

Next tactic:
exact (h' _ hi).le
theorem chainHeight_eq_iSup_Ici : s.chainHeight = ⨆ i ∈ s, (s ∩ Set.Ici i).chainHeight := by
  apply le_antisymm
  · refine' iSup₂_le _
    rintro (_ | ⟨x, xs⟩) h
    · exact zero_le _
    · apply le_trans _ (le_iSup₂ x (cons_mem_subchain_iff.mp h).1)
      apply length_le_chainHeight_of_mem_subchain
      refine' ⟨h.1, fun i hi ↦ ⟨h.2 i hi, _⟩⟩
      cases hi
      · exact left_mem_Ici
      rename_i hi
      cases' chain'_iff_pairwise.mp h.1 with _ _ h'
      exact (h' _ hi).le
  · 

Proof state:
case a
α : Type u_1
β : Type u_2
s t : Set α
inst✝ : Preorder α
⊢ ⨆ i ∈ s, chainHeight (s ∩ Ici i) ≤ chainHeight s

Next tactic:
exact iSup₂_le fun i _ ↦ chainHeight_mono <| Set.inter_subset_left _ _
theorem chainHeight_eq_iSup_Iic : s.chainHeight = ⨆ i ∈ s, (s ∩ Set.Iic i).chainHeight := by
  

Proof state:
α : Type u_1
β : Type u_2
s t : Set α
inst✝ : Preorder α
⊢ chainHeight s = ⨆ i ∈ s, chainHeight (s ∩ Iic i)

Next tactic:
simp_rw [← chainHeight_dual (_ ∩ _)]
theorem chainHeight_eq_iSup_Iic : s.chainHeight = ⨆ i ∈ s, (s ∩ Set.Iic i).chainHeight := by
  simp_rw [← chainHeight_dual (_ ∩ _)]
  

Proof state:
α : Type u_1
β : Type u_2
s t : Set α
inst✝ : Preorder α
⊢ chainHeight s = ⨆ i ∈ s, chainHeight (⇑ofDual ⁻¹' (s ∩ Iic i))

Next tactic:
rw [← chainHeight_dual, chainHeight_eq_iSup_Ici]
theorem chainHeight_eq_iSup_Iic : s.chainHeight = ⨆ i ∈ s, (s ∩ Set.Iic i).chainHeight := by
  simp_rw [← chainHeight_dual (_ ∩ _)]
  rw [← chainHeight_dual, chainHeight_eq_iSup_Ici]
  

Proof state:
α : Type u_1
β : Type u_2
s t : Set α
inst✝ : Preorder α
⊢ ⨆ i ∈ ⇑ofDual ⁻¹' s, chainHeight (⇑ofDual ⁻¹' s ∩ Ici i) = ⨆ i ∈ s, chainHeight (⇑ofDual ⁻¹' (s ∩ Iic i))

Next tactic:
rfl
theorem chainHeight_insert_of_forall_gt (a : α) (hx : ∀ b ∈ s, a < b) :
    (insert a s).chainHeight = s.chainHeight + 1 := by
  

Proof state:
α : Type u_1
β : Type u_2
s t : Set α
inst✝ : Preorder α
a : α
hx : ∀ b ∈ s, a < b
⊢ chainHeight (insert a s) = chainHeight s + 1

Next tactic:
rw [← add_zero (insert a s).chainHeight]
theorem chainHeight_insert_of_forall_gt (a : α) (hx : ∀ b ∈ s, a < b) :
    (insert a s).chainHeight = s.chainHeight + 1 := by
  rw [← add_zero (insert a s).chainHeight]
  

Proof state:
α : Type u_1
β : Type u_2
s t : Set α
inst✝ : Preorder α
a : α
hx : ∀ b ∈ s, a < b
⊢ chainHeight (insert a s) + 0 = chainHeight s + 1

Next tactic:
change (insert a s).chainHeight + (0 : ℕ) = s.chainHeight + (1 : ℕ)
theorem chainHeight_insert_of_forall_gt (a : α) (hx : ∀ b ∈ s, a < b) :
    (insert a s).chainHeight = s.chainHeight + 1 := by
  rw [← add_zero (insert a s).chainHeight]
  change (insert a s).chainHeight + (0 : ℕ) = s.chainHeight + (1 : ℕ)
  

Proof state:
α : Type u_1
β : Type u_2
s t : Set α
inst✝ : Preorder α
a : α
hx : ∀ b ∈ s, a < b
⊢ chainHeight (insert a s) + ↑0 = chainHeight s + ↑1

Next tactic:
apply le_antisymm
theorem chainHeight_insert_of_forall_gt (a : α) (hx : ∀ b ∈ s, a < b) :
    (insert a s).chainHeight = s.chainHeight + 1 := by
  rw [← add_zero (insert a s).chainHeight]
  change (insert a s).chainHeight + (0 : ℕ) = s.chainHeight + (1 : ℕ)
  apply le_antisymm <;> 

Proof state:
case a
α : Type u_1
β : Type u_2
s t : Set α
inst✝ : Preorder α
a : α
hx : ∀ b ∈ s, a < b
⊢ chainHeight (insert a s) + ↑0 ≤ chainHeight s + ↑1

Next tactic:
rw [chainHeight_add_le_chainHeight_add]
theorem chainHeight_insert_of_forall_gt (a : α) (hx : ∀ b ∈ s, a < b) :
    (insert a s).chainHeight = s.chainHeight + 1 := by
  rw [← add_zero (insert a s).chainHeight]
  change (insert a s).chainHeight + (0 : ℕ) = s.chainHeight + (1 : ℕ)
  apply le_antisymm <;> 

Proof state:
case a
α : Type u_1
β : Type u_2
s t : Set α
inst✝ : Preorder α
a : α
hx : ∀ b ∈ s, a < b
⊢ chainHeight s + ↑1 ≤ chainHeight (insert a s) + ↑0

Next tactic:
rw [chainHeight_add_le_chainHeight_add]
theorem chainHeight_insert_of_forall_gt (a : α) (hx : ∀ b ∈ s, a < b) :
    (insert a s).chainHeight = s.chainHeight + 1 := by
  rw [← add_zero (insert a s).chainHeight]
  change (insert a s).chainHeight + (0 : ℕ) = s.chainHeight + (1 : ℕ)
  apply le_antisymm <;> rw [chainHeight_add_le_chainHeight_add]
  · 

Proof state:
case a
α : Type u_1
β : Type u_2
s t : Set α
inst✝ : Preorder α
a : α
hx : ∀ b ∈ s, a < b
⊢ ∀ l ∈ subchain (insert a s), ∃ l' ∈ subchain s, length l + 0 ≤ length l' + 1

Next tactic:
rintro (_ | ⟨y, ys⟩) h
theorem chainHeight_insert_of_forall_gt (a : α) (hx : ∀ b ∈ s, a < b) :
    (insert a s).chainHeight = s.chainHeight + 1 := by
  rw [← add_zero (insert a s).chainHeight]
  change (insert a s).chainHeight + (0 : ℕ) = s.chainHeight + (1 : ℕ)
  apply le_antisymm <;> rw [chainHeight_add_le_chainHeight_add]
  · rintro (_ | ⟨y, ys⟩) h
    · 

Proof state:
case a.nil
α : Type u_1
β : Type u_2
s t : Set α
inst✝ : Preorder α
a : α
hx : ∀ b ∈ s, a < b
h : [] ∈ subchain (insert a s)
⊢ ∃ l' ∈ subchain s, length [] + 0 ≤ length l' + 1

Next tactic:
exact ⟨[], nil_mem_subchain _, zero_le _⟩
theorem chainHeight_insert_of_forall_gt (a : α) (hx : ∀ b ∈ s, a < b) :
    (insert a s).chainHeight = s.chainHeight + 1 := by
  rw [← add_zero (insert a s).chainHeight]
  change (insert a s).chainHeight + (0 : ℕ) = s.chainHeight + (1 : ℕ)
  apply le_antisymm <;> rw [chainHeight_add_le_chainHeight_add]
  · rintro (_ | ⟨y, ys⟩) h
    · exact ⟨[], nil_mem_subchain _, zero_le _⟩
    · 

Proof state:
case a.cons
α : Type u_1
β : Type u_2
s t : Set α
inst✝ : Preorder α
a : α
hx : ∀ b ∈ s, a < b
y : α
ys : List α
h : y :: ys ∈ subchain (insert a s)
⊢ ∃ l' ∈ subchain s, length (y :: ys) + 0 ≤ length l' + 1

Next tactic:
have h' := cons_mem_subchain_iff.mp h
theorem chainHeight_insert_of_forall_gt (a : α) (hx : ∀ b ∈ s, a < b) :
    (insert a s).chainHeight = s.chainHeight + 1 := by
  rw [← add_zero (insert a s).chainHeight]
  change (insert a s).chainHeight + (0 : ℕ) = s.chainHeight + (1 : ℕ)
  apply le_antisymm <;> rw [chainHeight_add_le_chainHeight_add]
  · rintro (_ | ⟨y, ys⟩) h
    · exact ⟨[], nil_mem_subchain _, zero_le _⟩
    · have h' := cons_mem_subchain_iff.mp h
      

Proof state:
case a.cons
α : Type u_1
β : Type u_2
s t : Set α
inst✝ : Preorder α
a : α
hx : ∀ b ∈ s, a < b
y : α
ys : List α
h : y :: ys ∈ subchain (insert a s)
h' : y ∈ insert a s ∧ ys ∈ subchain (insert a s) ∧ ∀ b ∈ head? ys, y < b
⊢ ∃ l' ∈ subchain s, length (y :: ys) + 0 ≤ length l' + 1

Next tactic:
refine' ⟨ys, ⟨h'.2.1.1, fun i hi ↦ _⟩, by simp⟩
theorem chainHeight_insert_of_forall_gt (a : α) (hx : ∀ b ∈ s, a < b) :
    (insert a s).chainHeight = s.chainHeight + 1 := by
  rw [← add_zero (insert a s).chainHeight]
  change (insert a s).chainHeight + (0 : ℕ) = s.chainHeight + (1 : ℕ)
  apply le_antisymm <;> rw [chainHeight_add_le_chainHeight_add]
  · rintro (_ | ⟨y, ys⟩) h
    · exact ⟨[], nil_mem_subchain _, zero_le _⟩
    · have h' := cons_mem_subchain_iff.mp h
      refine' ⟨ys, ⟨h'.2.1.1, fun i hi ↦ _⟩, by 

Proof state:
α : Type u_1
β : Type u_2
s t : Set α
inst✝ : Preorder α
a : α
hx : ∀ b ∈ s, a < b
y : α
ys : List α
h : y :: ys ∈ subchain (insert a s)
h' : y ∈ insert a s ∧ ys ∈ subchain (insert a s) ∧ ∀ b ∈ head? ys, y < b
⊢ length (y :: ys) + 0 ≤ length ys + 1

Next tactic:
simp
theorem chainHeight_insert_of_forall_gt (a : α) (hx : ∀ b ∈ s, a < b) :
    (insert a s).chainHeight = s.chainHeight + 1 := by
  rw [← add_zero (insert a s).chainHeight]
  change (insert a s).chainHeight + (0 : ℕ) = s.chainHeight + (1 : ℕ)
  apply le_antisymm <;> rw [chainHeight_add_le_chainHeight_add]
  · rintro (_ | ⟨y, ys⟩) h
    · exact ⟨[], nil_mem_subchain _, zero_le _⟩
    · have h' := cons_mem_subchain_iff.mp h
      refine' ⟨ys, ⟨h'.2.1.1, fun i hi ↦ _⟩, by simp⟩
      

Proof state:
case a.cons
α : Type u_1
β : Type u_2
s t : Set α
inst✝ : Preorder α
a : α
hx : ∀ b ∈ s, a < b
y : α
ys : List α
h : y :: ys ∈ subchain (insert a s)
h' : y ∈ insert a s ∧ ys ∈ subchain (insert a s) ∧ ∀ b ∈ head? ys, y < b
i : α
hi : i ∈ ys
⊢ i ∈ s

Next tactic:
apply (h'.2.1.2 i hi).resolve_left
theorem chainHeight_insert_of_forall_gt (a : α) (hx : ∀ b ∈ s, a < b) :
    (insert a s).chainHeight = s.chainHeight + 1 := by
  rw [← add_zero (insert a s).chainHeight]
  change (insert a s).chainHeight + (0 : ℕ) = s.chainHeight + (1 : ℕ)
  apply le_antisymm <;> rw [chainHeight_add_le_chainHeight_add]
  · rintro (_ | ⟨y, ys⟩) h
    · exact ⟨[], nil_mem_subchain _, zero_le _⟩
    · have h' := cons_mem_subchain_iff.mp h
      refine' ⟨ys, ⟨h'.2.1.1, fun i hi ↦ _⟩, by simp⟩
      apply (h'.2.1.2 i hi).resolve_left
      

Proof state:
case a.cons
α : Type u_1
β : Type u_2
s t : Set α
inst✝ : Preorder α
a : α
hx : ∀ b ∈ s, a < b
y : α
ys : List α
h : y :: ys ∈ subchain (insert a s)
h' : y ∈ insert a s ∧ ys ∈ subchain (insert a s) ∧ ∀ b ∈ head? ys, y < b
i : α
hi : i ∈ ys
⊢ ¬i = a

Next tactic:
rintro rfl
theorem chainHeight_insert_of_forall_gt (a : α) (hx : ∀ b ∈ s, a < b) :
    (insert a s).chainHeight = s.chainHeight + 1 := by
  rw [← add_zero (insert a s).chainHeight]
  change (insert a s).chainHeight + (0 : ℕ) = s.chainHeight + (1 : ℕ)
  apply le_antisymm <;> rw [chainHeight_add_le_chainHeight_add]
  · rintro (_ | ⟨y, ys⟩) h
    · exact ⟨[], nil_mem_subchain _, zero_le _⟩
    · have h' := cons_mem_subchain_iff.mp h
      refine' ⟨ys, ⟨h'.2.1.1, fun i hi ↦ _⟩, by simp⟩
      apply (h'.2.1.2 i hi).resolve_left
      rintro rfl
      

Proof state:
case a.cons
α : Type u_1
β : Type u_2
s t : Set α
inst✝ : Preorder α
y : α
ys : List α
i : α
hi : i ∈ ys
hx : ∀ b ∈ s, i < b
h : y :: ys ∈ subchain (insert i s)
h' : y ∈ insert i s ∧ ys ∈ subchain (insert i s) ∧ ∀ b ∈ head? ys, y < b
⊢ False

Next tactic:
cases' chain'_iff_pairwise.mp h.1 with _ _ hy