l3lab/ntp-mathlib huggingface dataset:
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
    rw [← hk, ← hl]
    

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
⊢ ↑(length l) + ↑n ≤ chainHeight t + ↑m

Next tactic:
exact le_chainHeight_add_nat_iff.2 (H l hs)
theorem chainHeight_le_chainHeight_TFAE (s : Set α) (t : Set β) :
    TFAE [s.chainHeight ≤ t.chainHeight, ∀ l ∈ s.subchain, ∃ l' ∈ t.subchain, length l = length l',
      ∀ l ∈ s.subchain, ∃ l' ∈ t.subchain, length l ≤ length l'] := by
  

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

Next tactic:
tfae_have 1 ↔ 3
theorem chainHeight_le_chainHeight_TFAE (s : Set α) (t : Set β) :
    TFAE [s.chainHeight ≤ t.chainHeight, ∀ l ∈ s.subchain, ∃ l' ∈ t.subchain, length l = length l',
      ∀ l ∈ s.subchain, ∃ l' ∈ t.subchain, length l ≤ length l'] := by
  tfae_have 1 ↔ 3
  · 

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

Next tactic:
convert ← chainHeight_add_le_chainHeight_add s t 0 0
theorem chainHeight_le_chainHeight_TFAE (s : Set α) (t : Set β) :
    TFAE [s.chainHeight ≤ t.chainHeight, ∀ l ∈ s.subchain, ∃ l' ∈ t.subchain, length l = length l',
      ∀ l ∈ s.subchain, ∃ l' ∈ t.subchain, length l ≤ length l'] := by
  tfae_have 1 ↔ 3
  · convert ← chainHeight_add_le_chainHeight_add s t 0 0 <;> 

Proof state:
case h.e'_1.h.e'_3
α : Type u_1
β : Type u_2
inst✝¹ : LT α
inst✝ : LT β
s✝ t✝ : Set α
l : List α
a : α
s : Set α
t : Set β
⊢ chainHeight s + ↑0 = chainHeight s

Next tactic:
apply add_zero
theorem chainHeight_le_chainHeight_TFAE (s : Set α) (t : Set β) :
    TFAE [s.chainHeight ≤ t.chainHeight, ∀ l ∈ s.subchain, ∃ l' ∈ t.subchain, length l = length l',
      ∀ l ∈ s.subchain, ∃ l' ∈ t.subchain, length l ≤ length l'] := by
  tfae_have 1 ↔ 3
  · convert ← chainHeight_add_le_chainHeight_add s t 0 0 <;> 

Proof state:
case h.e'_1.h.e'_4
α : Type u_1
β : Type u_2
inst✝¹ : LT α
inst✝ : LT β
s✝ t✝ : Set α
l : List α
a : α
s : Set α
t : Set β
⊢ chainHeight t + ↑0 = chainHeight t

Next tactic:
apply add_zero
theorem chainHeight_le_chainHeight_TFAE (s : Set α) (t : Set β) :
    TFAE [s.chainHeight ≤ t.chainHeight, ∀ l ∈ s.subchain, ∃ l' ∈ t.subchain, length l = length l',
      ∀ l ∈ s.subchain, ∃ l' ∈ t.subchain, length l ≤ length l'] := by
  tfae_have 1 ↔ 3
  · convert ← chainHeight_add_le_chainHeight_add s t 0 0 <;> apply add_zero
  

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

Next tactic:
tfae_have 2 ↔ 3
theorem chainHeight_le_chainHeight_TFAE (s : Set α) (t : Set β) :
    TFAE [s.chainHeight ≤ t.chainHeight, ∀ l ∈ s.subchain, ∃ l' ∈ t.subchain, length l = length l',
      ∀ l ∈ s.subchain, ∃ l' ∈ t.subchain, length l ≤ length l'] := by
  tfae_have 1 ↔ 3
  · convert ← chainHeight_add_le_chainHeight_add s t 0 0 <;> apply add_zero
  tfae_have 2 ↔ 3
  · 

Proof state:
case tfae_2_iff_3
α : Type u_1
β : Type u_2
inst✝¹ : LT α
inst✝ : LT β
s✝ t✝ : Set α
l : List α
a : α
s : Set α
t : Set β
tfae_1_iff_3 : chainHeight s ≤ chainHeight t ↔ ∀ l ∈ subchain s, ∃ l' ∈ subchain t, length l ≤ length l'
⊢ (∀ l ∈ subchain s, ∃ l' ∈ subchain t, length l = length l') ↔
    ∀ l ∈ subchain s, ∃ l' ∈ subchain t, length l ≤ length l'

Next tactic:
refine' forall₂_congr fun l hl ↦ _
theorem chainHeight_le_chainHeight_TFAE (s : Set α) (t : Set β) :
    TFAE [s.chainHeight ≤ t.chainHeight, ∀ l ∈ s.subchain, ∃ l' ∈ t.subchain, length l = length l',
      ∀ l ∈ s.subchain, ∃ l' ∈ t.subchain, length l ≤ length l'] := by
  tfae_have 1 ↔ 3
  · convert ← chainHeight_add_le_chainHeight_add s t 0 0 <;> apply add_zero
  tfae_have 2 ↔ 3
  · refine' forall₂_congr fun l hl ↦ _
    

Proof state:
case tfae_2_iff_3
α : Type u_1
β : Type u_2
inst✝¹ : LT α
inst✝ : LT β
s✝ t✝ : Set α
l✝ : List α
a : α
s : Set α
t : Set β
tfae_1_iff_3 : chainHeight s ≤ chainHeight t ↔ ∀ l ∈ subchain s, ∃ l' ∈ subchain t, length l ≤ length l'
l : List α
hl : l ∈ subchain s
⊢ (∃ l' ∈ subchain t, length l = length l') ↔ ∃ l' ∈ subchain t, length l ≤ length l'

Next tactic:
simp_rw [← (le_chainHeight_TFAE t l.length).out 1 2, eq_comm]
theorem chainHeight_le_chainHeight_TFAE (s : Set α) (t : Set β) :
    TFAE [s.chainHeight ≤ t.chainHeight, ∀ l ∈ s.subchain, ∃ l' ∈ t.subchain, length l = length l',
      ∀ l ∈ s.subchain, ∃ l' ∈ t.subchain, length l ≤ length l'] := by
  tfae_have 1 ↔ 3
  · convert ← chainHeight_add_le_chainHeight_add s t 0 0 <;> apply add_zero
  tfae_have 2 ↔ 3
  · refine' forall₂_congr fun l hl ↦ _
    simp_rw [← (le_chainHeight_TFAE t l.length).out 1 2, eq_comm]
  

Proof state:
α : Type u_1
β : Type u_2
inst✝¹ : LT α
inst✝ : LT β
s✝ t✝ : Set α
l : List α
a : α
s : Set α
t : Set β
tfae_1_iff_3 : chainHeight s ≤ chainHeight t ↔ ∀ l ∈ subchain s, ∃ l' ∈ subchain t, length l ≤ length l'
tfae_2_iff_3 :
  (∀ l ∈ subchain s, ∃ l' ∈ subchain t, length l = length l') ↔
    ∀ l ∈ subchain s, ∃ l' ∈ subchain t, length l ≤ length l'
⊢ TFAE
    [chainHeight s ≤ chainHeight t, ∀ l ∈ subchain s, ∃ l' ∈ subchain t, length l = length l',
      ∀ l ∈ subchain s, ∃ l' ∈ subchain t, length l ≤ length l']

Next tactic:
tfae_finish
theorem chainHeight_image (f : α → β) (hf : ∀ {x y}, x < y ↔ f x < f y) (s : Set α) :
    (f '' s).chainHeight = s.chainHeight := by
  

Proof state:
α : 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 α
⊢ chainHeight (f '' s) = chainHeight s

Next tactic:
apply le_antisymm
theorem chainHeight_image (f : α → β) (hf : ∀ {x y}, x < y ↔ f x < f y) (s : Set α) :
    (f '' 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 : α
f : α → β
hf : ∀ {x y : α}, x < y ↔ f x < f y
s : Set α
⊢ chainHeight (f '' s) ≤ chainHeight s

Next tactic:
rw [chainHeight_le_chainHeight_iff]
theorem chainHeight_image (f : α → β) (hf : ∀ {x y}, x < y ↔ f x < f y) (s : Set α) :
    (f '' 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 : α
f : α → β
hf : ∀ {x y : α}, x < y ↔ f x < f y
s : Set α
⊢ chainHeight s ≤ chainHeight (f '' s)

Next tactic:
rw [chainHeight_le_chainHeight_iff]
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]
  · 

Proof state:
case a
α : 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 ∈ subchain (f '' s), ∃ l' ∈ subchain s, length l = length l'

Next tactic:
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 _ _⟩
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
      

Proof state:
α : 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 α
this : ∀ l ∈ subchain (f '' s), ∃ l' ∈ subchain s, map f l' = l
⊢ ∀ l ∈ subchain (f '' s), ∃ l' ∈ subchain s, length l = length l'

Next tactic:
intro l hl
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
      

Proof state:
α : 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 α
this : ∀ l ∈ subchain (f '' s), ∃ l' ∈ subchain s, map f l' = l
l : List β
hl : l ∈ subchain (f '' s)
⊢ ∃ l' ∈ subchain s, length l = length l'

Next tactic:
obtain ⟨l', h₁, rfl⟩ := this l hl
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
      

Proof state:
case 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 α
this : ∀ l ∈ subchain (f '' s), ∃ l' ∈ subchain s, map f l' = l
l' : List α
h₁ : l' ∈ subchain s
hl : map f l' ∈ subchain (f '' s)
⊢ ∃ l'_1 ∈ subchain s, length (map f l') = length l'_1

Next tactic:
exact ⟨l', h₁, length_map _ _⟩
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 _ _⟩
    

Proof state:
case a
α : 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 ∈ subchain (f '' s), ∃ l' ∈ subchain s, map f l' = l

Next tactic:
intro l
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
    

Proof state:
case a
α : 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 β
⊢ l ∈ subchain (f '' s) → ∃ l' ∈ subchain s, map f l' = l

Next tactic:
induction' l with x xs hx
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
    · 

Proof state:
case a.nil
α : 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 α
⊢ [] ∈ subchain (f '' s) → ∃ l' ∈ subchain s, map f l' = []

Next tactic:
exact fun _ ↦ ⟨nil, ⟨trivial, fun x h ↦ (not_mem_nil x h).elim⟩, rfl⟩
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⟩
    · 

Proof state:
case a.cons
α : 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 α
x : β
xs : List β
hx : xs ∈ subchain (f '' s) → ∃ l' ∈ subchain s, map f l' = xs
⊢ x :: xs ∈ subchain (f '' s) → ∃ l' ∈ subchain s, map f l' = x :: xs

Next tactic:
intro h
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
      

Proof state:
case a.cons
α : 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 α
x : β
xs : List β
hx : xs ∈ subchain (f '' s) → ∃ l' ∈ subchain s, map f l' = xs
h : x :: xs ∈ subchain (f '' s)
⊢ ∃ l' ∈ subchain s, map f l' = x :: xs

Next tactic:
rw [cons_mem_subchain_iff] at h
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
      

Proof state:
case a.cons
α : 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 α
x : β
xs : List β
hx : xs ∈ subchain (f '' s) → ∃ l' ∈ subchain s, map f l' = xs
h : x ∈ f '' s ∧ xs ∈ subchain (f '' s) ∧ ∀ b ∈ head? xs, x < b
⊢ ∃ l' ∈ subchain s, map f l' = x :: xs

Next tactic:
obtain ⟨⟨x, hx', rfl⟩, h₁, h₂⟩ := h
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
      

Proof state:
case a.cons.intro.intro.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 α
xs : List β
hx : xs ∈ subchain (f '' s) → ∃ l' ∈ subchain s, map f l' = xs
x : α
hx' : x ∈ s
h₁ : xs ∈ subchain (f '' s)
h₂ : ∀ b ∈ head? xs, f x < b
⊢ ∃ l' ∈ subchain s, map f l' = f x :: xs

Next tactic:
obtain ⟨l', h₃, rfl⟩ := hx h₁
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₁
      

Proof state:
case a.cons.intro.intro.intro.intro.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 α
x : α
hx' : x ∈ s
l' : List α
h₃ : l' ∈ subchain s
hx : map f l' ∈ subchain (f '' s) → ∃ l'_1 ∈ subchain s, map f l'_1 = map f l'
h₁ : map f l' ∈ subchain (f '' s)
h₂ : ∀ b ∈ head? (map f l'), f x < b
⊢ ∃ l'_1 ∈ subchain s, map f l'_1 = f x :: map f l'

Next tactic:
refine' ⟨x::l', Set.cons_mem_subchain_iff.mpr ⟨hx', h₃, _⟩, rfl⟩
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⟩
      

Proof state:
case a.cons.intro.intro.intro.intro.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 α
x : α
hx' : x ∈ s
l' : List α
h₃ : l' ∈ subchain s
hx : map f l' ∈ subchain (f '' s) → ∃ l'_1 ∈ subchain s, map f l'_1 = map f l'
h₁ : map f l' ∈ subchain (f '' s)
h₂ : ∀ b ∈ head? (map f l'), f x < b
⊢ ∀ b ∈ head? l', x < b

Next tactic:
cases l'
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'
      · 

Proof state:
case a.cons.intro.intro.intro.intro.intro.intro.nil
α : 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 α
x : α
hx' : x ∈ s
h₃ : [] ∈ subchain s
hx : map f [] ∈ subchain (f '' s) → ∃ l' ∈ subchain s, map f l' = map f []
h₁ : map f [] ∈ subchain (f '' s)
h₂ : ∀ b ∈ head? (map f []), f x < b
⊢ ∀ b ∈ head? [], x < b

Next tactic:
simp
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
      · 

Proof state:
case a.cons.intro.intro.intro.intro.intro.intro.cons
α : 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 α
x : α
hx' : x ∈ s
head✝ : α
tail✝ : List α
h₃ : head✝ :: tail✝ ∈ subchain s
hx : map f (head✝ :: tail✝) ∈ subchain (f '' s) → ∃ l' ∈ subchain s, map f l' = map f (head✝ :: tail✝)
h₁ : map f (head✝ :: tail✝) ∈ subchain (f '' s)
h₂ : ∀ b ∈ head? (map f (head✝ :: tail✝)), f x < b
⊢ ∀ b ∈ head? (head✝ :: tail✝), x < b

Next tactic:
simpa [← hf] using h₂
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₂
  · 

Proof state:
case a
α : 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 ∈ subchain s, ∃ l' ∈ subchain (f '' s), length l = length l'

Next tactic:
intro l hl
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
    

Proof state:
case a
α : 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
⊢ ∃ l' ∈ subchain (f '' s), length l = length l'

Next tactic:
refine' ⟨l.map f, ⟨_, _⟩, _⟩
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, ⟨_, _⟩, _⟩
    · 

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 x x_1 => x < x_1) (map f l)

Next tactic:
simp_rw [chain'_map, ← hf]