l3lab/ntp-mathlib huggingface dataset:
theorem exists_chain_of_le_chainHeight {n : ℕ} (hn : ↑n ≤ s.chainHeight) :
    ∃ l ∈ s.subchain, length l = n := by
  rcases (le_top : s.chainHeight ≤ ⊤).eq_or_lt with ha | ha <;>
    rw [chainHeight_eq_iSup_subtype] at ha
  · obtain ⟨_, ⟨⟨l, h₁, h₂⟩, rfl⟩, h₃⟩ :=
      not_bddAbove_iff'.mp (WithTop.iSup_coe_eq_top.1 ha) n
    exact ⟨l.take n, ⟨h₁.take _, fun x h ↦ h₂ _ <| take_subset _ _ h⟩,
      (l.length_take n).trans <| min_eq_left <| le_of_not_ge h₃⟩
  · rw [ENat.iSup_coe_lt_top] at ha
    obtain ⟨⟨l, h₁, h₂⟩, e : l.length = _⟩ := Nat.sSup_mem (Set.range_nonempty _) ha
    

Proof state:
case inr.intro.mk.intro
α : Type u_1
β : Type u_2
inst✝¹ : LT α
inst✝ : LT β
s t : Set α
l✝ : List α
a : α
n : ℕ
hn : ↑n ≤ chainHeight s
ha : BddAbove (range fun l => length ↑l)
l : List α
h₁ : Chain' (fun x x_1 => x < x_1) l
h₂ : ∀ i ∈ l, i ∈ s
e : length l = sSup (range fun l => length ↑l)
⊢ ∃ l ∈ subchain s, length l = n

Next tactic:
refine'
      ⟨l.take n, ⟨h₁.take _, fun x h ↦ h₂ _ <| take_subset _ _ h⟩,
        (l.length_take n).trans <| min_eq_left <| _⟩
theorem exists_chain_of_le_chainHeight {n : ℕ} (hn : ↑n ≤ s.chainHeight) :
    ∃ l ∈ s.subchain, length l = n := by
  rcases (le_top : s.chainHeight ≤ ⊤).eq_or_lt with ha | ha <;>
    rw [chainHeight_eq_iSup_subtype] at ha
  · obtain ⟨_, ⟨⟨l, h₁, h₂⟩, rfl⟩, h₃⟩ :=
      not_bddAbove_iff'.mp (WithTop.iSup_coe_eq_top.1 ha) n
    exact ⟨l.take n, ⟨h₁.take _, fun x h ↦ h₂ _ <| take_subset _ _ h⟩,
      (l.length_take n).trans <| min_eq_left <| le_of_not_ge h₃⟩
  · rw [ENat.iSup_coe_lt_top] at ha
    obtain ⟨⟨l, h₁, h₂⟩, e : l.length = _⟩ := Nat.sSup_mem (Set.range_nonempty _) ha
    refine'
      ⟨l.take n, ⟨h₁.take _, fun x h ↦ h₂ _ <| take_subset _ _ h⟩,
        (l.length_take n).trans <| min_eq_left <| _⟩
    

Proof state:
case inr.intro.mk.intro
α : Type u_1
β : Type u_2
inst✝¹ : LT α
inst✝ : LT β
s t : Set α
l✝ : List α
a : α
n : ℕ
hn : ↑n ≤ chainHeight s
ha : BddAbove (range fun l => length ↑l)
l : List α
h₁ : Chain' (fun x x_1 => x < x_1) l
h₂ : ∀ i ∈ l, i ∈ s
e : length l = sSup (range fun l => length ↑l)
⊢ n ≤ length l

Next tactic:
rwa [e, ← Nat.cast_le (α := ℕ∞), sSup_range, ENat.coe_iSup ha, ← chainHeight_eq_iSup_subtype]
theorem le_chainHeight_TFAE (n : ℕ) :
    TFAE [↑n ≤ s.chainHeight, ∃ l ∈ s.subchain, length l = n, ∃ l ∈ s.subchain, n ≤ length l] := by
  

Proof state:
α : Type u_1
β : Type u_2
inst✝¹ : LT α
inst✝ : LT β
s t : Set α
l : List α
a : α
n : ℕ
⊢ TFAE [↑n ≤ chainHeight s, ∃ l ∈ subchain s, length l = n, ∃ l ∈ subchain s, n ≤ length l]

Next tactic:
tfae_have 1 → 2
theorem le_chainHeight_TFAE (n : ℕ) :
    TFAE [↑n ≤ s.chainHeight, ∃ l ∈ s.subchain, length l = n, ∃ l ∈ s.subchain, n ≤ length l] := by
  tfae_have 1 → 2; · 

Proof state:
case tfae_1_to_2
α : Type u_1
β : Type u_2
inst✝¹ : LT α
inst✝ : LT β
s t : Set α
l : List α
a : α
n : ℕ
⊢ ↑n ≤ chainHeight s → ∃ l ∈ subchain s, length l = n

Next tactic:
exact s.exists_chain_of_le_chainHeight
theorem le_chainHeight_TFAE (n : ℕ) :
    TFAE [↑n ≤ s.chainHeight, ∃ l ∈ s.subchain, length l = n, ∃ l ∈ s.subchain, n ≤ length l] := by
  tfae_have 1 → 2; · exact s.exists_chain_of_le_chainHeight
  

Proof state:
α : Type u_1
β : Type u_2
inst✝¹ : LT α
inst✝ : LT β
s t : Set α
l : List α
a : α
n : ℕ
tfae_1_to_2 : ↑n ≤ chainHeight s → ∃ l ∈ subchain s, length l = n
⊢ TFAE [↑n ≤ chainHeight s, ∃ l ∈ subchain s, length l = n, ∃ l ∈ subchain s, n ≤ length l]

Next tactic:
tfae_have 2 → 3
theorem le_chainHeight_TFAE (n : ℕ) :
    TFAE [↑n ≤ s.chainHeight, ∃ l ∈ s.subchain, length l = n, ∃ l ∈ s.subchain, n ≤ length l] := by
  tfae_have 1 → 2; · exact s.exists_chain_of_le_chainHeight
  tfae_have 2 → 3; · 

Proof state:
case tfae_2_to_3
α : Type u_1
β : Type u_2
inst✝¹ : LT α
inst✝ : LT β
s t : Set α
l : List α
a : α
n : ℕ
tfae_1_to_2 : ↑n ≤ chainHeight s → ∃ l ∈ subchain s, length l = n
⊢ (∃ l ∈ subchain s, length l = n) → ∃ l ∈ subchain s, n ≤ length l

Next tactic:
rintro ⟨l, hls, he⟩
theorem le_chainHeight_TFAE (n : ℕ) :
    TFAE [↑n ≤ s.chainHeight, ∃ l ∈ s.subchain, length l = n, ∃ l ∈ s.subchain, n ≤ length l] := by
  tfae_have 1 → 2; · exact s.exists_chain_of_le_chainHeight
  tfae_have 2 → 3; · rintro ⟨l, hls, he⟩; 

Proof state:
case tfae_2_to_3.intro.intro
α : Type u_1
β : Type u_2
inst✝¹ : LT α
inst✝ : LT β
s t : Set α
l✝ : List α
a : α
n : ℕ
tfae_1_to_2 : ↑n ≤ chainHeight s → ∃ l ∈ subchain s, length l = n
l : List α
hls : l ∈ subchain s
he : length l = n
⊢ ∃ l ∈ subchain s, n ≤ length l

Next tactic:
exact ⟨l, hls, he.ge⟩
theorem le_chainHeight_TFAE (n : ℕ) :
    TFAE [↑n ≤ s.chainHeight, ∃ l ∈ s.subchain, length l = n, ∃ l ∈ s.subchain, n ≤ length l] := by
  tfae_have 1 → 2; · exact s.exists_chain_of_le_chainHeight
  tfae_have 2 → 3; · rintro ⟨l, hls, he⟩; exact ⟨l, hls, he.ge⟩
  

Proof state:
α : Type u_1
β : Type u_2
inst✝¹ : LT α
inst✝ : LT β
s t : Set α
l : List α
a : α
n : ℕ
tfae_1_to_2 : ↑n ≤ chainHeight s → ∃ l ∈ subchain s, length l = n
tfae_2_to_3 : (∃ l ∈ subchain s, length l = n) → ∃ l ∈ subchain s, n ≤ length l
⊢ TFAE [↑n ≤ chainHeight s, ∃ l ∈ subchain s, length l = n, ∃ l ∈ subchain s, n ≤ length l]

Next tactic:
tfae_have 3 → 1
theorem le_chainHeight_TFAE (n : ℕ) :
    TFAE [↑n ≤ s.chainHeight, ∃ l ∈ s.subchain, length l = n, ∃ l ∈ s.subchain, n ≤ length l] := by
  tfae_have 1 → 2; · exact s.exists_chain_of_le_chainHeight
  tfae_have 2 → 3; · rintro ⟨l, hls, he⟩; exact ⟨l, hls, he.ge⟩
  tfae_have 3 → 1; · 

Proof state:
case tfae_3_to_1
α : Type u_1
β : Type u_2
inst✝¹ : LT α
inst✝ : LT β
s t : Set α
l : List α
a : α
n : ℕ
tfae_1_to_2 : ↑n ≤ chainHeight s → ∃ l ∈ subchain s, length l = n
tfae_2_to_3 : (∃ l ∈ subchain s, length l = n) → ∃ l ∈ subchain s, n ≤ length l
⊢ (∃ l ∈ subchain s, n ≤ length l) → ↑n ≤ chainHeight s

Next tactic:
rintro ⟨l, hs, hn⟩
theorem le_chainHeight_TFAE (n : ℕ) :
    TFAE [↑n ≤ s.chainHeight, ∃ l ∈ s.subchain, length l = n, ∃ l ∈ s.subchain, n ≤ length l] := by
  tfae_have 1 → 2; · exact s.exists_chain_of_le_chainHeight
  tfae_have 2 → 3; · rintro ⟨l, hls, he⟩; exact ⟨l, hls, he.ge⟩
  tfae_have 3 → 1; · rintro ⟨l, hs, hn⟩; 

Proof state:
case tfae_3_to_1.intro.intro
α : Type u_1
β : Type u_2
inst✝¹ : LT α
inst✝ : LT β
s t : Set α
l✝ : List α
a : α
n : ℕ
tfae_1_to_2 : ↑n ≤ chainHeight s → ∃ l ∈ subchain s, length l = n
tfae_2_to_3 : (∃ l ∈ subchain s, length l = n) → ∃ l ∈ subchain s, n ≤ length l
l : List α
hs : l ∈ subchain s
hn : n ≤ length l
⊢ ↑n ≤ chainHeight s

Next tactic:
exact le_iSup₂_of_le l hs (WithTop.coe_le_coe.2 hn)
theorem le_chainHeight_TFAE (n : ℕ) :
    TFAE [↑n ≤ s.chainHeight, ∃ l ∈ s.subchain, length l = n, ∃ l ∈ s.subchain, n ≤ length l] := by
  tfae_have 1 → 2; · exact s.exists_chain_of_le_chainHeight
  tfae_have 2 → 3; · rintro ⟨l, hls, he⟩; exact ⟨l, hls, he.ge⟩
  tfae_have 3 → 1; · rintro ⟨l, hs, hn⟩; exact le_iSup₂_of_le l hs (WithTop.coe_le_coe.2 hn)
  

Proof state:
α : Type u_1
β : Type u_2
inst✝¹ : LT α
inst✝ : LT β
s t : Set α
l : List α
a : α
n : ℕ
tfae_1_to_2 : ↑n ≤ chainHeight s → ∃ l ∈ subchain s, length l = n
tfae_2_to_3 : (∃ l ∈ subchain s, length l = n) → ∃ l ∈ subchain s, n ≤ length l
tfae_3_to_1 : (∃ l ∈ subchain s, n ≤ length l) → ↑n ≤ chainHeight s
⊢ TFAE [↑n ≤ chainHeight s, ∃ l ∈ subchain s, length l = n, ∃ l ∈ subchain s, n ≤ length l]

Next tactic:
tfae_finish
theorem chainHeight_eq_top_iff : s.chainHeight = ⊤ ↔ ∀ n, ∃ l ∈ s.subchain, length l = n := by
  

Proof state:
α : Type u_1
β : Type u_2
inst✝¹ : LT α
inst✝ : LT β
s t : Set α
l : List α
a : α
⊢ chainHeight s = ⊤ ↔ ∀ (n : ℕ), ∃ l ∈ subchain s, length l = n

Next tactic:
refine' ⟨fun h n ↦ le_chainHeight_iff.1 (le_top.trans_eq h.symm), fun h ↦ _⟩
theorem chainHeight_eq_top_iff : s.chainHeight = ⊤ ↔ ∀ n, ∃ l ∈ s.subchain, length l = n := by
  refine' ⟨fun h n ↦ le_chainHeight_iff.1 (le_top.trans_eq h.symm), fun h ↦ _⟩
  

Proof state:
α : Type u_1
β : Type u_2
inst✝¹ : LT α
inst✝ : LT β
s t : Set α
l : List α
a : α
h : ∀ (n : ℕ), ∃ l ∈ subchain s, length l = n
⊢ chainHeight s = ⊤

Next tactic:
contrapose! h
theorem chainHeight_eq_top_iff : s.chainHeight = ⊤ ↔ ∀ n, ∃ l ∈ s.subchain, length l = n := by
  refine' ⟨fun h n ↦ le_chainHeight_iff.1 (le_top.trans_eq h.symm), fun h ↦ _⟩
  contrapose! h; 

Proof state:
α : Type u_1
β : Type u_2
inst✝¹ : LT α
inst✝ : LT β
s t : Set α
l : List α
a : α
h : chainHeight s ≠ ⊤
⊢ ∃ n, ∀ l ∈ subchain s, length l ≠ n

Next tactic:
obtain ⟨n, hn⟩ := WithTop.ne_top_iff_exists.1 h
theorem chainHeight_eq_top_iff : s.chainHeight = ⊤ ↔ ∀ n, ∃ l ∈ s.subchain, length l = n := by
  refine' ⟨fun h n ↦ le_chainHeight_iff.1 (le_top.trans_eq h.symm), fun h ↦ _⟩
  contrapose! h; obtain ⟨n, hn⟩ := WithTop.ne_top_iff_exists.1 h
  

Proof state:
case intro
α : Type u_1
β : Type u_2
inst✝¹ : LT α
inst✝ : LT β
s t : Set α
l : List α
a : α
h : chainHeight s ≠ ⊤
n : ℕ
hn : ↑n = chainHeight s
⊢ ∃ n, ∀ l ∈ subchain s, length l ≠ n

Next tactic:
exact ⟨n + 1, fun l hs ↦ (Nat.lt_succ_iff.2 <| Nat.cast_le.1 <|
    (length_le_chainHeight_of_mem_subchain hs).trans_eq hn.symm).ne⟩
@[simp]
theorem one_le_chainHeight_iff : 1 ≤ s.chainHeight ↔ s.Nonempty := by
  

Proof state:
α : Type u_1
β : Type u_2
inst✝¹ : LT α
inst✝ : LT β
s t : Set α
l : List α
a : α
⊢ 1 ≤ chainHeight s ↔ Set.Nonempty s

Next tactic:
rw [← Nat.cast_one, Set.le_chainHeight_iff]
@[simp]
theorem one_le_chainHeight_iff : 1 ≤ s.chainHeight ↔ s.Nonempty := by
  rw [← Nat.cast_one, Set.le_chainHeight_iff]
  

Proof state:
α : Type u_1
β : Type u_2
inst✝¹ : LT α
inst✝ : LT β
s t : Set α
l : List α
a : α
⊢ (∃ l ∈ subchain s, length l = 1) ↔ Set.Nonempty s

Next tactic:
simp only [length_eq_one, @and_comm (_ ∈ _), @eq_comm _ _ [_], exists_exists_eq_and,
    singleton_mem_subchain_iff, Set.Nonempty]
@[simp]
theorem chainHeight_eq_zero_iff : s.chainHeight = 0 ↔ s = ∅ := by
  

Proof state:
α : Type u_1
β : Type u_2
inst✝¹ : LT α
inst✝ : LT β
s t : Set α
l : List α
a : α
⊢ chainHeight s = 0 ↔ s = ∅

Next tactic:
rw [← not_iff_not, ← Ne.def, ← ENat.one_le_iff_ne_zero, one_le_chainHeight_iff,
    nonempty_iff_ne_empty]
theorem le_chainHeight_add_nat_iff {n m : ℕ} :
    ↑n ≤ s.chainHeight + m ↔ ∃ l ∈ s.subchain, n ≤ length l + m := by
  

Proof state:
α : Type u_1
β : Type u_2
inst✝¹ : LT α
inst✝ : LT β
s t : Set α
l : List α
a : α
n m : ℕ
⊢ ↑n ≤ chainHeight s + ↑m ↔ ∃ l ∈ subchain s, n ≤ length l + m

Next tactic:
simp_rw [← tsub_le_iff_right, ← ENat.coe_sub, (le_chainHeight_TFAE s (n - m)).out 0 2]
theorem chainHeight_add_le_chainHeight_add (s : Set α) (t : Set β) (n m : ℕ) :
    s.chainHeight + n ≤ t.chainHeight + m ↔
      ∀ l ∈ s.subchain, ∃ l' ∈ t.subchain, length l + n ≤ length l' + m := by
  

Proof state:
α : Type u_1
β : Type u_2
inst✝¹ : LT α
inst✝ : LT β
s✝ t✝ : Set α
l : List α
a : α
s : Set α
t : Set β
n m : ℕ
⊢ chainHeight s + ↑n ≤ chainHeight t + ↑m ↔ ∀ l ∈ subchain s, ∃ l' ∈ subchain t, length l + n ≤ length l' + m

Next tactic:
refine'
    ⟨fun e l h ↦
      le_chainHeight_add_nat_iff.1
        ((add_le_add_right (length_le_chainHeight_of_mem_subchain h) _).trans e),
      fun H ↦ _⟩
theorem chainHeight_add_le_chainHeight_add (s : Set α) (t : Set β) (n m : ℕ) :
    s.chainHeight + n ≤ t.chainHeight + m ↔
      ∀ l ∈ s.subchain, ∃ l' ∈ t.subchain, length l + n ≤ length l' + m := by
  refine'
    ⟨fun e l h ↦
      le_chainHeight_add_nat_iff.1
        ((add_le_add_right (length_le_chainHeight_of_mem_subchain h) _).trans e),
      fun H ↦ _⟩
  

Proof state:
α : Type u_1
β : Type u_2
inst✝¹ : LT α
inst✝ : LT β
s✝ t✝ : Set α
l : List α
a : α
s : Set α
t : Set β
n m : ℕ
H : ∀ l ∈ subchain s, ∃ l' ∈ subchain t, length l + n ≤ length l' + m
⊢ chainHeight s + ↑n ≤ chainHeight t + ↑m

Next tactic:
by_cases h : s.chainHeight = ⊤
theorem chainHeight_add_le_chainHeight_add (s : Set α) (t : Set β) (n m : ℕ) :
    s.chainHeight + n ≤ t.chainHeight + m ↔
      ∀ l ∈ s.subchain, ∃ l' ∈ t.subchain, length l + n ≤ length l' + m := by
  refine'
    ⟨fun e l h ↦
      le_chainHeight_add_nat_iff.1
        ((add_le_add_right (length_le_chainHeight_of_mem_subchain h) _).trans e),
      fun H ↦ _⟩
  by_cases h : s.chainHeight = ⊤
  · 

Proof state:
case pos
α : Type u_1
β : Type u_2
inst✝¹ : LT α
inst✝ : LT β
s✝ t✝ : Set α
l : List α
a : α
s : Set α
t : Set β
n m : ℕ
H : ∀ l ∈ subchain s, ∃ l' ∈ subchain t, length l + n ≤ length l' + m
h : chainHeight s = ⊤
⊢ chainHeight s + ↑n ≤ chainHeight t + ↑m

Next tactic:
suffices t.chainHeight = ⊤ by
      rw [this, top_add]
      exact le_top
theorem chainHeight_add_le_chainHeight_add (s : Set α) (t : Set β) (n m : ℕ) :
    s.chainHeight + n ≤ t.chainHeight + m ↔
      ∀ l ∈ s.subchain, ∃ l' ∈ t.subchain, length l + n ≤ length l' + m := by
  refine'
    ⟨fun e l h ↦
      le_chainHeight_add_nat_iff.1
        ((add_le_add_right (length_le_chainHeight_of_mem_subchain h) _).trans e),
      fun H ↦ _⟩
  by_cases h : s.chainHeight = ⊤
  · suffices t.chainHeight = ⊤ by
      

Proof state:
α : Type u_1
β : Type u_2
inst✝¹ : LT α
inst✝ : LT β
s✝ t✝ : Set α
l : List α
a : α
s : Set α
t : Set β
n m : ℕ
H : ∀ l ∈ subchain s, ∃ l' ∈ subchain t, length l + n ≤ length l' + m
h : chainHeight s = ⊤
this : chainHeight t = ⊤
⊢ chainHeight s + ↑n ≤ chainHeight t + ↑m

Next tactic:
rw [this, top_add]
theorem chainHeight_add_le_chainHeight_add (s : Set α) (t : Set β) (n m : ℕ) :
    s.chainHeight + n ≤ t.chainHeight + m ↔
      ∀ l ∈ s.subchain, ∃ l' ∈ t.subchain, length l + n ≤ length l' + m := by
  refine'
    ⟨fun e l h ↦
      le_chainHeight_add_nat_iff.1
        ((add_le_add_right (length_le_chainHeight_of_mem_subchain h) _).trans e),
      fun H ↦ _⟩
  by_cases h : s.chainHeight = ⊤
  · suffices t.chainHeight = ⊤ by
      rw [this, top_add]
      

Proof state:
α : Type u_1
β : Type u_2
inst✝¹ : LT α
inst✝ : LT β
s✝ t✝ : Set α
l : List α
a : α
s : Set α
t : Set β
n m : ℕ
H : ∀ l ∈ subchain s, ∃ l' ∈ subchain t, length l + n ≤ length l' + m
h : chainHeight s = ⊤
this : chainHeight t = ⊤
⊢ chainHeight s + ↑n ≤ ⊤

Next tactic:
exact le_top
theorem chainHeight_add_le_chainHeight_add (s : Set α) (t : Set β) (n m : ℕ) :
    s.chainHeight + n ≤ t.chainHeight + m ↔
      ∀ l ∈ s.subchain, ∃ l' ∈ t.subchain, length l + n ≤ length l' + m := by
  refine'
    ⟨fun e l h ↦
      le_chainHeight_add_nat_iff.1
        ((add_le_add_right (length_le_chainHeight_of_mem_subchain h) _).trans e),
      fun H ↦ _⟩
  by_cases h : s.chainHeight = ⊤
  · suffices t.chainHeight = ⊤ by
      rw [this, top_add]
      exact le_top
    

Proof state:
case pos
α : Type u_1
β : Type u_2
inst✝¹ : LT α
inst✝ : LT β
s✝ t✝ : Set α
l : List α
a : α
s : Set α
t : Set β
n m : ℕ
H : ∀ l ∈ subchain s, ∃ l' ∈ subchain t, length l + n ≤ length l' + m
h : chainHeight s = ⊤
⊢ chainHeight t = ⊤

Next tactic:
rw [chainHeight_eq_top_iff] at h ⊢
theorem chainHeight_add_le_chainHeight_add (s : Set α) (t : Set β) (n m : ℕ) :
    s.chainHeight + n ≤ t.chainHeight + m ↔
      ∀ l ∈ s.subchain, ∃ l' ∈ t.subchain, length l + n ≤ length l' + m := by
  refine'
    ⟨fun e l h ↦
      le_chainHeight_add_nat_iff.1
        ((add_le_add_right (length_le_chainHeight_of_mem_subchain h) _).trans e),
      fun H ↦ _⟩
  by_cases h : s.chainHeight = ⊤
  · suffices t.chainHeight = ⊤ by
      rw [this, top_add]
      exact le_top
    rw [chainHeight_eq_top_iff] at h ⊢
    

Proof state:
case pos
α : Type u_1
β : Type u_2
inst✝¹ : LT α
inst✝ : LT β
s✝ t✝ : Set α
l : List α
a : α
s : Set α
t : Set β
n m : ℕ
H : ∀ l ∈ subchain s, ∃ l' ∈ subchain t, length l + n ≤ length l' + m
h : ∀ (n : ℕ), ∃ l ∈ subchain s, length l = n
⊢ ∀ (n : ℕ), ∃ l ∈ subchain t, length l = n

Next tactic:
intro k
theorem chainHeight_add_le_chainHeight_add (s : Set α) (t : Set β) (n m : ℕ) :
    s.chainHeight + n ≤ t.chainHeight + m ↔
      ∀ l ∈ s.subchain, ∃ l' ∈ t.subchain, length l + n ≤ length l' + m := by
  refine'
    ⟨fun e l h ↦
      le_chainHeight_add_nat_iff.1
        ((add_le_add_right (length_le_chainHeight_of_mem_subchain h) _).trans e),
      fun H ↦ _⟩
  by_cases h : s.chainHeight = ⊤
  · suffices t.chainHeight = ⊤ by
      rw [this, top_add]
      exact le_top
    rw [chainHeight_eq_top_iff] at h ⊢
    intro k
    

Proof state:
case pos
α : Type u_1
β : Type u_2
inst✝¹ : LT α
inst✝ : LT β
s✝ t✝ : Set α
l : List α
a : α
s : Set α
t : Set β
n m : ℕ
H : ∀ l ∈ subchain s, ∃ l' ∈ subchain t, length l + n ≤ length l' + m
h : ∀ (n : ℕ), ∃ l ∈ subchain s, length l = n
k : ℕ
⊢ ∃ l ∈ subchain t, length l = k

Next tactic:
have := (le_chainHeight_TFAE t k).out 1 2
theorem chainHeight_add_le_chainHeight_add (s : Set α) (t : Set β) (n m : ℕ) :
    s.chainHeight + n ≤ t.chainHeight + m ↔
      ∀ l ∈ s.subchain, ∃ l' ∈ t.subchain, length l + n ≤ length l' + m := by
  refine'
    ⟨fun e l h ↦
      le_chainHeight_add_nat_iff.1
        ((add_le_add_right (length_le_chainHeight_of_mem_subchain h) _).trans e),
      fun H ↦ _⟩
  by_cases h : s.chainHeight = ⊤
  · suffices t.chainHeight = ⊤ by
      rw [this, top_add]
      exact le_top
    rw [chainHeight_eq_top_iff] at h ⊢
    intro k
    have := (le_chainHeight_TFAE t k).out 1 2
    

Proof state:
case pos
α : Type u_1
β : Type u_2
inst✝¹ : LT α
inst✝ : LT β
s✝ t✝ : Set α
l : List α
a : α
s : Set α
t : Set β
n m : ℕ
H : ∀ l ∈ subchain s, ∃ l' ∈ subchain t, length l + n ≤ length l' + m
h : ∀ (n : ℕ), ∃ l ∈ subchain s, length l = n
k : ℕ
this : (∃ l ∈ subchain t, length l = k) ↔ ∃ l ∈ subchain t, k ≤ length l
⊢ ∃ l ∈ subchain t, length l = k

Next tactic:
rw [this]
theorem chainHeight_add_le_chainHeight_add (s : Set α) (t : Set β) (n m : ℕ) :
    s.chainHeight + n ≤ t.chainHeight + m ↔
      ∀ l ∈ s.subchain, ∃ l' ∈ t.subchain, length l + n ≤ length l' + m := by
  refine'
    ⟨fun e l h ↦
      le_chainHeight_add_nat_iff.1
        ((add_le_add_right (length_le_chainHeight_of_mem_subchain h) _).trans e),
      fun H ↦ _⟩
  by_cases h : s.chainHeight = ⊤
  · suffices t.chainHeight = ⊤ by
      rw [this, top_add]
      exact le_top
    rw [chainHeight_eq_top_iff] at h ⊢
    intro k
    have := (le_chainHeight_TFAE t k).out 1 2
    rw [this]
    

Proof state:
case pos
α : Type u_1
β : Type u_2
inst✝¹ : LT α
inst✝ : LT β
s✝ t✝ : Set α
l : List α
a : α
s : Set α
t : Set β
n m : ℕ
H : ∀ l ∈ subchain s, ∃ l' ∈ subchain t, length l + n ≤ length l' + m
h : ∀ (n : ℕ), ∃ l ∈ subchain s, length l = n
k : ℕ
this : (∃ l ∈ subchain t, length l = k) ↔ ∃ l ∈ subchain t, k ≤ length l
⊢ ∃ l ∈ subchain t, k ≤ length l

Next tactic:
obtain ⟨l, hs, hl⟩ := h (k + m)
theorem chainHeight_add_le_chainHeight_add (s : Set α) (t : Set β) (n m : ℕ) :
    s.chainHeight + n ≤ t.chainHeight + m ↔
      ∀ l ∈ s.subchain, ∃ l' ∈ t.subchain, length l + n ≤ length l' + m := by
  refine'
    ⟨fun e l h ↦
      le_chainHeight_add_nat_iff.1
        ((add_le_add_right (length_le_chainHeight_of_mem_subchain h) _).trans e),
      fun H ↦ _⟩
  by_cases h : s.chainHeight = ⊤
  · suffices t.chainHeight = ⊤ by
      rw [this, top_add]
      exact le_top
    rw [chainHeight_eq_top_iff] at h ⊢
    intro k
    have := (le_chainHeight_TFAE t k).out 1 2
    rw [this]
    obtain ⟨l, hs, hl⟩ := h (k + m)
    

Proof state:
case pos.intro.intro
α : Type u_1
β : Type u_2
inst✝¹ : LT α
inst✝ : LT β
s✝ t✝ : Set α
l✝ : List α
a : α
s : Set α
t : Set β
n m : ℕ
H : ∀ l ∈ subchain s, ∃ l' ∈ subchain t, length l + n ≤ length l' + m
h : ∀ (n : ℕ), ∃ l ∈ subchain s, length l = n
k : ℕ
this : (∃ l ∈ subchain t, length l = k) ↔ ∃ l ∈ subchain t, k ≤ length l
l : List α
hs : l ∈ subchain s
hl : length l = k + m
⊢ ∃ l ∈ subchain t, k ≤ length l

Next tactic:
obtain ⟨l', ht, hl'⟩ := H l hs
theorem chainHeight_add_le_chainHeight_add (s : Set α) (t : Set β) (n m : ℕ) :
    s.chainHeight + n ≤ t.chainHeight + m ↔
      ∀ l ∈ s.subchain, ∃ l' ∈ t.subchain, length l + n ≤ length l' + m := by
  refine'
    ⟨fun e l h ↦
      le_chainHeight_add_nat_iff.1
        ((add_le_add_right (length_le_chainHeight_of_mem_subchain h) _).trans e),
      fun H ↦ _⟩
  by_cases h : s.chainHeight = ⊤
  · suffices t.chainHeight = ⊤ by
      rw [this, top_add]
      exact le_top
    rw [chainHeight_eq_top_iff] at h ⊢
    intro k
    have := (le_chainHeight_TFAE t k).out 1 2
    rw [this]
    obtain ⟨l, hs, hl⟩ := h (k + m)
    obtain ⟨l', ht, hl'⟩ := H l hs
    

Proof state:
case pos.intro.intro.intro.intro
α : Type u_1
β : Type u_2
inst✝¹ : LT α
inst✝ : LT β
s✝ t✝ : Set α
l✝ : List α
a : α
s : Set α
t : Set β
n m : ℕ
H : ∀ l ∈ subchain s, ∃ l' ∈ subchain t, length l + n ≤ length l' + m
h : ∀ (n : ℕ), ∃ l ∈ subchain s, length l = n
k : ℕ
this : (∃ l ∈ subchain t, length l = k) ↔ ∃ l ∈ subchain t, k ≤ length l
l : List α
hs : l ∈ subchain s
hl : length l = k + m
l' : List β
ht : l' ∈ subchain t
hl' : length l + n ≤ length l' + m
⊢ ∃ l ∈ subchain t, k ≤ length l

Next tactic:
exact ⟨l', ht, (add_le_add_iff_right m).1 <| _root_.trans (hl.symm.trans_le le_self_add) hl'⟩
theorem chainHeight_add_le_chainHeight_add (s : Set α) (t : Set β) (n m : ℕ) :
    s.chainHeight + n ≤ t.chainHeight + m ↔
      ∀ l ∈ s.subchain, ∃ l' ∈ t.subchain, length l + n ≤ length l' + m := by
  refine'
    ⟨fun e l h ↦
      le_chainHeight_add_nat_iff.1
        ((add_le_add_right (length_le_chainHeight_of_mem_subchain h) _).trans e),
      fun H ↦ _⟩
  by_cases h : s.chainHeight = ⊤
  · suffices t.chainHeight = ⊤ by
      rw [this, top_add]
      exact le_top
    rw [chainHeight_eq_top_iff] at h ⊢
    intro k
    have := (le_chainHeight_TFAE t k).out 1 2
    rw [this]
    obtain ⟨l, hs, hl⟩ := h (k + m)
    obtain ⟨l', ht, hl'⟩ := H l hs
    exact ⟨l', ht, (add_le_add_iff_right m).1 <| _root_.trans (hl.symm.trans_le le_self_add) hl'⟩
  · 

Proof state:
case neg
α : Type u_1
β : Type u_2
inst✝¹ : LT α
inst✝ : LT β
s✝ t✝ : Set α
l : List α
a : α
s : Set α
t : Set β
n m : ℕ
H : ∀ l ∈ subchain s, ∃ l' ∈ subchain t, length l + n ≤ length l' + m
h : ¬chainHeight s = ⊤
⊢ chainHeight s + ↑n ≤ chainHeight t + ↑m

Next tactic:
obtain ⟨k, hk⟩ := WithTop.ne_top_iff_exists.1 h
theorem chainHeight_add_le_chainHeight_add (s : Set α) (t : Set β) (n m : ℕ) :
    s.chainHeight + n ≤ t.chainHeight + m ↔
      ∀ l ∈ s.subchain, ∃ l' ∈ t.subchain, length l + n ≤ length l' + m := by
  refine'
    ⟨fun e l h ↦
      le_chainHeight_add_nat_iff.1
        ((add_le_add_right (length_le_chainHeight_of_mem_subchain h) _).trans e),
      fun H ↦ _⟩
  by_cases h : s.chainHeight = ⊤
  · suffices t.chainHeight = ⊤ by
      rw [this, top_add]
      exact le_top
    rw [chainHeight_eq_top_iff] at h ⊢
    intro k
    have := (le_chainHeight_TFAE t k).out 1 2
    rw [this]
    obtain ⟨l, hs, hl⟩ := h (k + m)
    obtain ⟨l', ht, hl'⟩ := H l hs
    exact ⟨l', ht, (add_le_add_iff_right m).1 <| _root_.trans (hl.symm.trans_le le_self_add) hl'⟩
  · obtain ⟨k, hk⟩ := WithTop.ne_top_iff_exists.1 h
    

Proof state:
case neg.intro
α : Type u_1
β : Type u_2
inst✝¹ : LT α
inst✝ : LT β
s✝ t✝ : Set α
l : List α
a : α
s : Set α
t : Set β
n m : ℕ
H : ∀ l ∈ subchain s, ∃ l' ∈ subchain t, length l + n ≤ length l' + m
h : ¬chainHeight s = ⊤
k : ℕ
hk : ↑k = chainHeight s
⊢ chainHeight s + ↑n ≤ chainHeight t + ↑m

Next tactic:
obtain ⟨l, hs, hl⟩ := le_chainHeight_iff.1 hk.le
theorem chainHeight_add_le_chainHeight_add (s : Set α) (t : Set β) (n m : ℕ) :
    s.chainHeight + n ≤ t.chainHeight + m ↔
      ∀ l ∈ s.subchain, ∃ l' ∈ t.subchain, length l + n ≤ length l' + m := by
  refine'
    ⟨fun e l h ↦
      le_chainHeight_add_nat_iff.1
        ((add_le_add_right (length_le_chainHeight_of_mem_subchain h) _).trans e),
      fun H ↦ _⟩
  by_cases h : s.chainHeight = ⊤
  · suffices t.chainHeight = ⊤ by
      rw [this, top_add]
      exact le_top
    rw [chainHeight_eq_top_iff] at h ⊢
    intro k
    have := (le_chainHeight_TFAE t k).out 1 2
    rw [this]
    obtain ⟨l, hs, hl⟩ := h (k + m)
    obtain ⟨l', ht, hl'⟩ := H l hs
    exact ⟨l', ht, (add_le_add_iff_right m).1 <| _root_.trans (hl.symm.trans_le le_self_add) hl'⟩
  · obtain ⟨k, hk⟩ := WithTop.ne_top_iff_exists.1 h
    obtain ⟨l, hs, hl⟩ := le_chainHeight_iff.1 hk.le
    

Proof state:
case neg.intro.intro.intro
α : Type u_1
β : Type u_2
inst✝¹ : LT α
inst✝ : LT β
s✝ t✝ : Set α
l✝ : List α
a : α
s : Set α
t : Set β
n m : ℕ
H : ∀ l ∈ subchain s, ∃ l' ∈ subchain t, length l + n ≤ length l' + m
h : ¬chainHeight s = ⊤
k : ℕ
hk : ↑k = chainHeight s
l : List α
hs : l ∈ subchain s
hl : length l = k
⊢ chainHeight s + ↑n ≤ chainHeight t + ↑m

Next tactic:
rw [← hk, ← hl]