l3lab/ntp-mathlib huggingface dataset:
theorem chainHeight_union_eq (s t : Set α) (H : ∀ a ∈ s, ∀ b ∈ t, a < b) :
    (s ∪ t).chainHeight = s.chainHeight + t.chainHeight := by
  cases h : t.chainHeight
  · rw [WithTop.none_eq_top, add_top, eq_top_iff, ← WithTop.none_eq_top, ← h]
    

Proof state:
case none
α : Type u_1
β : Type u_2
s✝ t✝ : Set α
inst✝ : Preorder α
s t : Set α
H : ∀ a ∈ s, ∀ b ∈ t, a < b
h : chainHeight t = none
⊢ chainHeight t ≤ chainHeight (s ∪ t)

Next tactic:
exact Set.chainHeight_mono (Set.subset_union_right _ _)
theorem chainHeight_union_eq (s t : Set α) (H : ∀ a ∈ s, ∀ b ∈ t, a < b) :
    (s ∪ t).chainHeight = s.chainHeight + t.chainHeight := by
  cases h : t.chainHeight
  · rw [WithTop.none_eq_top, add_top, eq_top_iff, ← WithTop.none_eq_top, ← h]
    exact Set.chainHeight_mono (Set.subset_union_right _ _)
  

Proof state:
case some
α : Type u_1
β : Type u_2
s✝ t✝ : Set α
inst✝ : Preorder α
s t : Set α
H : ∀ a ∈ s, ∀ b ∈ t, a < b
val✝ : ℕ
h : chainHeight t = some val✝
⊢ chainHeight (s ∪ t) = chainHeight s + some val✝

Next tactic:
apply le_antisymm
theorem chainHeight_union_eq (s t : Set α) (H : ∀ a ∈ s, ∀ b ∈ t, a < b) :
    (s ∪ t).chainHeight = s.chainHeight + t.chainHeight := by
  cases h : t.chainHeight
  · rw [WithTop.none_eq_top, add_top, eq_top_iff, ← WithTop.none_eq_top, ← h]
    exact Set.chainHeight_mono (Set.subset_union_right _ _)
  apply le_antisymm
  · 

Proof state:
case some.a
α : Type u_1
β : Type u_2
s✝ t✝ : Set α
inst✝ : Preorder α
s t : Set α
H : ∀ a ∈ s, ∀ b ∈ t, a < b
val✝ : ℕ
h : chainHeight t = some val✝
⊢ chainHeight (s ∪ t) ≤ chainHeight s + some val✝

Next tactic:
rw [← h]
theorem chainHeight_union_eq (s t : Set α) (H : ∀ a ∈ s, ∀ b ∈ t, a < b) :
    (s ∪ t).chainHeight = s.chainHeight + t.chainHeight := by
  cases h : t.chainHeight
  · rw [WithTop.none_eq_top, add_top, eq_top_iff, ← WithTop.none_eq_top, ← h]
    exact Set.chainHeight_mono (Set.subset_union_right _ _)
  apply le_antisymm
  · rw [← h]
    

Proof state:
case some.a
α : Type u_1
β : Type u_2
s✝ t✝ : Set α
inst✝ : Preorder α
s t : Set α
H : ∀ a ∈ s, ∀ b ∈ t, a < b
val✝ : ℕ
h : chainHeight t = some val✝
⊢ chainHeight (s ∪ t) ≤ chainHeight s + chainHeight t

Next tactic:
exact chainHeight_union_le
theorem chainHeight_union_eq (s t : Set α) (H : ∀ a ∈ s, ∀ b ∈ t, a < b) :
    (s ∪ t).chainHeight = s.chainHeight + t.chainHeight := by
  cases h : t.chainHeight
  · rw [WithTop.none_eq_top, add_top, eq_top_iff, ← WithTop.none_eq_top, ← h]
    exact Set.chainHeight_mono (Set.subset_union_right _ _)
  apply le_antisymm
  · rw [← h]
    exact chainHeight_union_le
  

Proof state:
case some.a
α : Type u_1
β : Type u_2
s✝ t✝ : Set α
inst✝ : Preorder α
s t : Set α
H : ∀ a ∈ s, ∀ b ∈ t, a < b
val✝ : ℕ
h : chainHeight t = some val✝
⊢ chainHeight s + some val✝ ≤ chainHeight (s ∪ t)

Next tactic:
rw [WithTop.some_eq_coe, ← add_zero (s ∪ t).chainHeight, ← WithTop.coe_zero,
    ENat.some_eq_coe, chainHeight_add_le_chainHeight_add]
theorem chainHeight_union_eq (s t : Set α) (H : ∀ a ∈ s, ∀ b ∈ t, a < b) :
    (s ∪ t).chainHeight = s.chainHeight + t.chainHeight := by
  cases h : t.chainHeight
  · rw [WithTop.none_eq_top, add_top, eq_top_iff, ← WithTop.none_eq_top, ← h]
    exact Set.chainHeight_mono (Set.subset_union_right _ _)
  apply le_antisymm
  · rw [← h]
    exact chainHeight_union_le
  rw [WithTop.some_eq_coe, ← add_zero (s ∪ t).chainHeight, ← WithTop.coe_zero,
    ENat.some_eq_coe, chainHeight_add_le_chainHeight_add]
  

Proof state:
case some.a
α : Type u_1
β : Type u_2
s✝ t✝ : Set α
inst✝ : Preorder α
s t : Set α
H : ∀ a ∈ s, ∀ b ∈ t, a < b
val✝ : ℕ
h : chainHeight t = some val✝
⊢ ∀ l ∈ subchain s, ∃ l' ∈ subchain (s ∪ t), length l + val✝ ≤ length l' + 0

Next tactic:
intro l hl
theorem chainHeight_union_eq (s t : Set α) (H : ∀ a ∈ s, ∀ b ∈ t, a < b) :
    (s ∪ t).chainHeight = s.chainHeight + t.chainHeight := by
  cases h : t.chainHeight
  · rw [WithTop.none_eq_top, add_top, eq_top_iff, ← WithTop.none_eq_top, ← h]
    exact Set.chainHeight_mono (Set.subset_union_right _ _)
  apply le_antisymm
  · rw [← h]
    exact chainHeight_union_le
  rw [WithTop.some_eq_coe, ← add_zero (s ∪ t).chainHeight, ← WithTop.coe_zero,
    ENat.some_eq_coe, chainHeight_add_le_chainHeight_add]
  intro l hl
  

Proof state:
case some.a
α : Type u_1
β : Type u_2
s✝ t✝ : Set α
inst✝ : Preorder α
s t : Set α
H : ∀ a ∈ s, ∀ b ∈ t, a < b
val✝ : ℕ
h : chainHeight t = some val✝
l : List α
hl : l ∈ subchain s
⊢ ∃ l' ∈ subchain (s ∪ t), length l + val✝ ≤ length l' + 0

Next tactic:
obtain ⟨l', hl', rfl⟩ := exists_chain_of_le_chainHeight t h.symm.le
theorem chainHeight_union_eq (s t : Set α) (H : ∀ a ∈ s, ∀ b ∈ t, a < b) :
    (s ∪ t).chainHeight = s.chainHeight + t.chainHeight := by
  cases h : t.chainHeight
  · rw [WithTop.none_eq_top, add_top, eq_top_iff, ← WithTop.none_eq_top, ← h]
    exact Set.chainHeight_mono (Set.subset_union_right _ _)
  apply le_antisymm
  · rw [← h]
    exact chainHeight_union_le
  rw [WithTop.some_eq_coe, ← add_zero (s ∪ t).chainHeight, ← WithTop.coe_zero,
    ENat.some_eq_coe, chainHeight_add_le_chainHeight_add]
  intro l hl
  obtain ⟨l', hl', rfl⟩ := exists_chain_of_le_chainHeight t h.symm.le
  

Proof state:
case some.a.intro.intro
α : Type u_1
β : Type u_2
s✝ t✝ : Set α
inst✝ : Preorder α
s t : Set α
H : ∀ a ∈ s, ∀ b ∈ t, a < b
l : List α
hl : l ∈ subchain s
l' : List α
hl' : l' ∈ subchain t
h : chainHeight t = some (length l')
⊢ ∃ l'_1 ∈ subchain (s ∪ t), length l + length l' ≤ length l'_1 + 0

Next tactic:
refine' ⟨l ++ l', ⟨Chain'.append hl.1 hl'.1 fun x hx y hy ↦ _, fun i hi ↦ _⟩, by simp⟩
theorem chainHeight_union_eq (s t : Set α) (H : ∀ a ∈ s, ∀ b ∈ t, a < b) :
    (s ∪ t).chainHeight = s.chainHeight + t.chainHeight := by
  cases h : t.chainHeight
  · rw [WithTop.none_eq_top, add_top, eq_top_iff, ← WithTop.none_eq_top, ← h]
    exact Set.chainHeight_mono (Set.subset_union_right _ _)
  apply le_antisymm
  · rw [← h]
    exact chainHeight_union_le
  rw [WithTop.some_eq_coe, ← add_zero (s ∪ t).chainHeight, ← WithTop.coe_zero,
    ENat.some_eq_coe, chainHeight_add_le_chainHeight_add]
  intro l hl
  obtain ⟨l', hl', rfl⟩ := exists_chain_of_le_chainHeight t h.symm.le
  refine' ⟨l ++ l', ⟨Chain'.append hl.1 hl'.1 fun x hx y hy ↦ _, fun i hi ↦ _⟩, by 

Proof state:
α : Type u_1
β : Type u_2
s✝ t✝ : Set α
inst✝ : Preorder α
s t : Set α
H : ∀ a ∈ s, ∀ b ∈ t, a < b
l : List α
hl : l ∈ subchain s
l' : List α
hl' : l' ∈ subchain t
h : chainHeight t = some (length l')
⊢ length l + length l' ≤ length (l ++ l') + 0

Next tactic:
simp
theorem chainHeight_union_eq (s t : Set α) (H : ∀ a ∈ s, ∀ b ∈ t, a < b) :
    (s ∪ t).chainHeight = s.chainHeight + t.chainHeight := by
  cases h : t.chainHeight
  · rw [WithTop.none_eq_top, add_top, eq_top_iff, ← WithTop.none_eq_top, ← h]
    exact Set.chainHeight_mono (Set.subset_union_right _ _)
  apply le_antisymm
  · rw [← h]
    exact chainHeight_union_le
  rw [WithTop.some_eq_coe, ← add_zero (s ∪ t).chainHeight, ← WithTop.coe_zero,
    ENat.some_eq_coe, chainHeight_add_le_chainHeight_add]
  intro l hl
  obtain ⟨l', hl', rfl⟩ := exists_chain_of_le_chainHeight t h.symm.le
  refine' ⟨l ++ l', ⟨Chain'.append hl.1 hl'.1 fun x hx y hy ↦ _, fun i hi ↦ _⟩, by simp⟩
  · 

Proof state:
case some.a.intro.intro.refine'_1
α : Type u_1
β : Type u_2
s✝ t✝ : Set α
inst✝ : Preorder α
s t : Set α
H : ∀ a ∈ s, ∀ b ∈ t, a < b
l : List α
hl : l ∈ subchain s
l' : List α
hl' : l' ∈ subchain t
h : chainHeight t = some (length l')
x : α
hx : x ∈ getLast? l
y : α
hy : y ∈ head? l'
⊢ x < y

Next tactic:
exact H x (hl.2 _ <| mem_of_mem_getLast? hx) y (hl'.2 _ <| mem_of_mem_head? hy)
theorem chainHeight_union_eq (s t : Set α) (H : ∀ a ∈ s, ∀ b ∈ t, a < b) :
    (s ∪ t).chainHeight = s.chainHeight + t.chainHeight := by
  cases h : t.chainHeight
  · rw [WithTop.none_eq_top, add_top, eq_top_iff, ← WithTop.none_eq_top, ← h]
    exact Set.chainHeight_mono (Set.subset_union_right _ _)
  apply le_antisymm
  · rw [← h]
    exact chainHeight_union_le
  rw [WithTop.some_eq_coe, ← add_zero (s ∪ t).chainHeight, ← WithTop.coe_zero,
    ENat.some_eq_coe, chainHeight_add_le_chainHeight_add]
  intro l hl
  obtain ⟨l', hl', rfl⟩ := exists_chain_of_le_chainHeight t h.symm.le
  refine' ⟨l ++ l', ⟨Chain'.append hl.1 hl'.1 fun x hx y hy ↦ _, fun i hi ↦ _⟩, by simp⟩
  · exact H x (hl.2 _ <| mem_of_mem_getLast? hx) y (hl'.2 _ <| mem_of_mem_head? hy)
  · 

Proof state:
case some.a.intro.intro.refine'_2
α : Type u_1
β : Type u_2
s✝ t✝ : Set α
inst✝ : Preorder α
s t : Set α
H : ∀ a ∈ s, ∀ b ∈ t, a < b
l : List α
hl : l ∈ subchain s
l' : List α
hl' : l' ∈ subchain t
h : chainHeight t = some (length l')
i : α
hi : i ∈ l ++ l'
⊢ i ∈ s ∪ t

Next tactic:
rw [mem_append] at hi
theorem chainHeight_union_eq (s t : Set α) (H : ∀ a ∈ s, ∀ b ∈ t, a < b) :
    (s ∪ t).chainHeight = s.chainHeight + t.chainHeight := by
  cases h : t.chainHeight
  · rw [WithTop.none_eq_top, add_top, eq_top_iff, ← WithTop.none_eq_top, ← h]
    exact Set.chainHeight_mono (Set.subset_union_right _ _)
  apply le_antisymm
  · rw [← h]
    exact chainHeight_union_le
  rw [WithTop.some_eq_coe, ← add_zero (s ∪ t).chainHeight, ← WithTop.coe_zero,
    ENat.some_eq_coe, chainHeight_add_le_chainHeight_add]
  intro l hl
  obtain ⟨l', hl', rfl⟩ := exists_chain_of_le_chainHeight t h.symm.le
  refine' ⟨l ++ l', ⟨Chain'.append hl.1 hl'.1 fun x hx y hy ↦ _, fun i hi ↦ _⟩, by simp⟩
  · exact H x (hl.2 _ <| mem_of_mem_getLast? hx) y (hl'.2 _ <| mem_of_mem_head? hy)
  · rw [mem_append] at hi
    

Proof state:
case some.a.intro.intro.refine'_2
α : Type u_1
β : Type u_2
s✝ t✝ : Set α
inst✝ : Preorder α
s t : Set α
H : ∀ a ∈ s, ∀ b ∈ t, a < b
l : List α
hl : l ∈ subchain s
l' : List α
hl' : l' ∈ subchain t
h : chainHeight t = some (length l')
i : α
hi : i ∈ l ∨ i ∈ l'
⊢ i ∈ s ∪ t

Next tactic:
cases' hi with hi hi
theorem chainHeight_union_eq (s t : Set α) (H : ∀ a ∈ s, ∀ b ∈ t, a < b) :
    (s ∪ t).chainHeight = s.chainHeight + t.chainHeight := by
  cases h : t.chainHeight
  · rw [WithTop.none_eq_top, add_top, eq_top_iff, ← WithTop.none_eq_top, ← h]
    exact Set.chainHeight_mono (Set.subset_union_right _ _)
  apply le_antisymm
  · rw [← h]
    exact chainHeight_union_le
  rw [WithTop.some_eq_coe, ← add_zero (s ∪ t).chainHeight, ← WithTop.coe_zero,
    ENat.some_eq_coe, chainHeight_add_le_chainHeight_add]
  intro l hl
  obtain ⟨l', hl', rfl⟩ := exists_chain_of_le_chainHeight t h.symm.le
  refine' ⟨l ++ l', ⟨Chain'.append hl.1 hl'.1 fun x hx y hy ↦ _, fun i hi ↦ _⟩, by simp⟩
  · exact H x (hl.2 _ <| mem_of_mem_getLast? hx) y (hl'.2 _ <| mem_of_mem_head? hy)
  · rw [mem_append] at hi
    cases' hi with hi hi
    

Proof state:
case some.a.intro.intro.refine'_2.inl
α : Type u_1
β : Type u_2
s✝ t✝ : Set α
inst✝ : Preorder α
s t : Set α
H : ∀ a ∈ s, ∀ b ∈ t, a < b
l : List α
hl : l ∈ subchain s
l' : List α
hl' : l' ∈ subchain t
h : chainHeight t = some (length l')
i : α
hi : i ∈ l
⊢ i ∈ s ∪ t
case some.a.intro.intro.refine'_2.inr
α : Type u_1
β : Type u_2
s✝ t✝ : Set α
inst✝ : Preorder α
s t : Set α
H : ∀ a ∈ s, ∀ b ∈ t, a < b
l : List α
hl : l ∈ subchain s
l' : List α
hl' : l' ∈ subchain t
h : chainHeight t = some (length l')
i : α
hi : i ∈ l'
⊢ i ∈ s ∪ t

Next tactic:
exacts [Or.inl (hl.2 _ hi), Or.inr (hl'.2 _ hi)]
theorem wellFoundedGT_of_chainHeight_ne_top (s : Set α) (hs : s.chainHeight ≠ ⊤) :
    WellFoundedGT s := by
  -- Porting note: added
  

Proof state:
α : Type u_1
β : Type u_2
s✝ t : Set α
inst✝ : Preorder α
s : Set α
hs : chainHeight s ≠ ⊤
⊢ WellFoundedGT ↑s

Next tactic:
haveI : IsTrans { x // x ∈ s } (↑· < ↑·) := inferInstance
theorem wellFoundedGT_of_chainHeight_ne_top (s : Set α) (hs : s.chainHeight ≠ ⊤) :
    WellFoundedGT s := by
  -- Porting note: added
  haveI : IsTrans { x // x ∈ s } (↑· < ↑·) := inferInstance

  

Proof state:
α : Type u_1
β : Type u_2
s✝ t : Set α
inst✝ : Preorder α
s : Set α
hs : chainHeight s ≠ ⊤
this : IsTrans { x // x ∈ s } fun x x_1 => x < x_1
⊢ WellFoundedGT ↑s

Next tactic:
obtain ⟨n, hn⟩ := WithTop.ne_top_iff_exists.1 hs
theorem wellFoundedGT_of_chainHeight_ne_top (s : Set α) (hs : s.chainHeight ≠ ⊤) :
    WellFoundedGT s := by
  -- Porting note: added
  haveI : IsTrans { x // x ∈ s } (↑· < ↑·) := inferInstance

  obtain ⟨n, hn⟩ := WithTop.ne_top_iff_exists.1 hs
  

Proof state:
case intro
α : Type u_1
β : Type u_2
s✝ t : Set α
inst✝ : Preorder α
s : Set α
hs : chainHeight s ≠ ⊤
this : IsTrans { x // x ∈ s } fun x x_1 => x < x_1
n : ℕ
hn : ↑n = chainHeight s
⊢ WellFoundedGT ↑s

Next tactic:
refine' ⟨RelEmbedding.wellFounded_iff_no_descending_seq.2 ⟨fun f ↦ _⟩⟩
theorem wellFoundedGT_of_chainHeight_ne_top (s : Set α) (hs : s.chainHeight ≠ ⊤) :
    WellFoundedGT s := by
  -- Porting note: added
  haveI : IsTrans { x // x ∈ s } (↑· < ↑·) := inferInstance

  obtain ⟨n, hn⟩ := WithTop.ne_top_iff_exists.1 hs
  refine' ⟨RelEmbedding.wellFounded_iff_no_descending_seq.2 ⟨fun f ↦ _⟩⟩
  

Proof state:
case intro
α : Type u_1
β : Type u_2
s✝ t : Set α
inst✝ : Preorder α
s : Set α
hs : chainHeight s ≠ ⊤
this : IsTrans { x // x ∈ s } fun x x_1 => x < x_1
n : ℕ
hn : ↑n = chainHeight s
f : (fun x x_1 => x > x_1) ↪r fun x x_1 => x > x_1
⊢ False

Next tactic:
refine' n.lt_succ_self.not_le (WithTop.coe_le_coe.1 <| hn.symm ▸ _)
theorem wellFoundedGT_of_chainHeight_ne_top (s : Set α) (hs : s.chainHeight ≠ ⊤) :
    WellFoundedGT s := by
  -- Porting note: added
  haveI : IsTrans { x // x ∈ s } (↑· < ↑·) := inferInstance

  obtain ⟨n, hn⟩ := WithTop.ne_top_iff_exists.1 hs
  refine' ⟨RelEmbedding.wellFounded_iff_no_descending_seq.2 ⟨fun f ↦ _⟩⟩
  refine' n.lt_succ_self.not_le (WithTop.coe_le_coe.1 <| hn.symm ▸ _)
  

Proof state:
case intro
α : Type u_1
β : Type u_2
s✝ t : Set α
inst✝ : Preorder α
s : Set α
hs : chainHeight s ≠ ⊤
this : IsTrans { x // x ∈ s } fun x x_1 => x < x_1
n : ℕ
hn : ↑n = chainHeight s
f : (fun x x_1 => x > x_1) ↪r fun x x_1 => x > x_1
⊢ ↑(Nat.succ n) ≤ chainHeight s

Next tactic:
refine'
    le_iSup₂_of_le _
      ⟨chain'_map_of_chain' ((↑) : {x // x ∈ s} → α) (fun _ _ ↦ id)
          (chain'_iff_pairwise.2 <| pairwise_ofFn.2 fun i j ↦ f.map_rel_iff.2),
        fun i h ↦ _⟩
      _
theorem wellFoundedGT_of_chainHeight_ne_top (s : Set α) (hs : s.chainHeight ≠ ⊤) :
    WellFoundedGT s := by
  -- Porting note: added
  haveI : IsTrans { x // x ∈ s } (↑· < ↑·) := inferInstance

  obtain ⟨n, hn⟩ := WithTop.ne_top_iff_exists.1 hs
  refine' ⟨RelEmbedding.wellFounded_iff_no_descending_seq.2 ⟨fun f ↦ _⟩⟩
  refine' n.lt_succ_self.not_le (WithTop.coe_le_coe.1 <| hn.symm ▸ _)
  refine'
    le_iSup₂_of_le _
      ⟨chain'_map_of_chain' ((↑) : {x // x ∈ s} → α) (fun _ _ ↦ id)
          (chain'_iff_pairwise.2 <| pairwise_ofFn.2 fun i j ↦ f.map_rel_iff.2),
        fun i h ↦ _⟩
      _
  · 

Proof state:
case intro.refine'_1
α : Type u_1
β : Type u_2
s✝ t : Set α
inst✝ : Preorder α
s : Set α
hs : chainHeight s ≠ ⊤
this : IsTrans { x // x ∈ s } fun x x_1 => x < x_1
n : ℕ
hn : ↑n = chainHeight s
f : (fun x x_1 => x > x_1) ↪r fun x x_1 => x > x_1
⊢ ℕ

Next tactic:
exact n.succ
theorem wellFoundedGT_of_chainHeight_ne_top (s : Set α) (hs : s.chainHeight ≠ ⊤) :
    WellFoundedGT s := by
  -- Porting note: added
  haveI : IsTrans { x // x ∈ s } (↑· < ↑·) := inferInstance

  obtain ⟨n, hn⟩ := WithTop.ne_top_iff_exists.1 hs
  refine' ⟨RelEmbedding.wellFounded_iff_no_descending_seq.2 ⟨fun f ↦ _⟩⟩
  refine' n.lt_succ_self.not_le (WithTop.coe_le_coe.1 <| hn.symm ▸ _)
  refine'
    le_iSup₂_of_le _
      ⟨chain'_map_of_chain' ((↑) : {x // x ∈ s} → α) (fun _ _ ↦ id)
          (chain'_iff_pairwise.2 <| pairwise_ofFn.2 fun i j ↦ f.map_rel_iff.2),
        fun i h ↦ _⟩
      _
  · exact n.succ
  · 

Proof state:
case intro.refine'_2
α : Type u_1
β : Type u_2
s✝ t : Set α
inst✝ : Preorder α
s : Set α
hs : chainHeight s ≠ ⊤
this : IsTrans { x // x ∈ s } fun x x_1 => x < x_1
n : ℕ
hn : ↑n = chainHeight s
f : (fun x x_1 => x > x_1) ↪r fun x x_1 => x > x_1
i : α
h : i ∈ map Subtype.val (ofFn fun i => f ↑i)
⊢ i ∈ s

Next tactic:
obtain ⟨a, -, rfl⟩ := mem_map.1 h
theorem wellFoundedGT_of_chainHeight_ne_top (s : Set α) (hs : s.chainHeight ≠ ⊤) :
    WellFoundedGT s := by
  -- Porting note: added
  haveI : IsTrans { x // x ∈ s } (↑· < ↑·) := inferInstance

  obtain ⟨n, hn⟩ := WithTop.ne_top_iff_exists.1 hs
  refine' ⟨RelEmbedding.wellFounded_iff_no_descending_seq.2 ⟨fun f ↦ _⟩⟩
  refine' n.lt_succ_self.not_le (WithTop.coe_le_coe.1 <| hn.symm ▸ _)
  refine'
    le_iSup₂_of_le _
      ⟨chain'_map_of_chain' ((↑) : {x // x ∈ s} → α) (fun _ _ ↦ id)
          (chain'_iff_pairwise.2 <| pairwise_ofFn.2 fun i j ↦ f.map_rel_iff.2),
        fun i h ↦ _⟩
      _
  · exact n.succ
  · obtain ⟨a, -, rfl⟩ := mem_map.1 h
    

Proof state:
case intro.refine'_2.intro.intro
α : Type u_1
β : Type u_2
s✝ t : Set α
inst✝ : Preorder α
s : Set α
hs : chainHeight s ≠ ⊤
this : IsTrans { x // x ∈ s } fun x x_1 => x < x_1
n : ℕ
hn : ↑n = chainHeight s
f : (fun x x_1 => x > x_1) ↪r fun x x_1 => x > x_1
a : { x // x ∈ s }
h : ↑a ∈ map Subtype.val (ofFn fun i => f ↑i)
⊢ ↑a ∈ s

Next tactic:
exact a.prop
theorem wellFoundedGT_of_chainHeight_ne_top (s : Set α) (hs : s.chainHeight ≠ ⊤) :
    WellFoundedGT s := by
  -- Porting note: added
  haveI : IsTrans { x // x ∈ s } (↑· < ↑·) := inferInstance

  obtain ⟨n, hn⟩ := WithTop.ne_top_iff_exists.1 hs
  refine' ⟨RelEmbedding.wellFounded_iff_no_descending_seq.2 ⟨fun f ↦ _⟩⟩
  refine' n.lt_succ_self.not_le (WithTop.coe_le_coe.1 <| hn.symm ▸ _)
  refine'
    le_iSup₂_of_le _
      ⟨chain'_map_of_chain' ((↑) : {x // x ∈ s} → α) (fun _ _ ↦ id)
          (chain'_iff_pairwise.2 <| pairwise_ofFn.2 fun i j ↦ f.map_rel_iff.2),
        fun i h ↦ _⟩
      _
  · exact n.succ
  · obtain ⟨a, -, rfl⟩ := mem_map.1 h
    exact a.prop
  · 

Proof state:
case intro.refine'_3
α : Type u_1
β : Type u_2
s✝ t : Set α
inst✝ : Preorder α
s : Set α
hs : chainHeight s ≠ ⊤
this : IsTrans { x // x ∈ s } fun x x_1 => x < x_1
n : ℕ
hn : ↑n = chainHeight s
f : (fun x x_1 => x > x_1) ↪r fun x x_1 => x > x_1
⊢ ↑(Nat.succ n) ≤ ↑(length (map Subtype.val (ofFn fun i => f ↑i)))

Next tactic:
rw [length_map, length_ofFn]
theorem wellFoundedGT_of_chainHeight_ne_top (s : Set α) (hs : s.chainHeight ≠ ⊤) :
    WellFoundedGT s := by
  -- Porting note: added
  haveI : IsTrans { x // x ∈ s } (↑· < ↑·) := inferInstance

  obtain ⟨n, hn⟩ := WithTop.ne_top_iff_exists.1 hs
  refine' ⟨RelEmbedding.wellFounded_iff_no_descending_seq.2 ⟨fun f ↦ _⟩⟩
  refine' n.lt_succ_self.not_le (WithTop.coe_le_coe.1 <| hn.symm ▸ _)
  refine'
    le_iSup₂_of_le _
      ⟨chain'_map_of_chain' ((↑) : {x // x ∈ s} → α) (fun _ _ ↦ id)
          (chain'_iff_pairwise.2 <| pairwise_ofFn.2 fun i j ↦ f.map_rel_iff.2),
        fun i h ↦ _⟩
      _
  · exact n.succ
  · obtain ⟨a, -, rfl⟩ := mem_map.1 h
    exact a.prop
  · rw [length_map, length_ofFn]
    

Proof state:
case intro.refine'_3
α : Type u_1
β : Type u_2
s✝ t : Set α
inst✝ : Preorder α
s : Set α
hs : chainHeight s ≠ ⊤
this : IsTrans { x // x ∈ s } fun x x_1 => x < x_1
n : ℕ
hn : ↑n = chainHeight s
f : (fun x x_1 => x > x_1) ↪r fun x x_1 => x > x_1
⊢ ↑(Nat.succ n) ≤ ↑(Nat.succ n)

Next tactic:
exact le_rfl
theorem wellFoundedLT_of_chainHeight_ne_top (s : Set α) (hs : s.chainHeight ≠ ⊤) :
    WellFoundedLT s :=
  wellFoundedGT_of_chainHeight_ne_top (ofDual ⁻¹' s) <| by 

Proof state:
α : Type u_1
β : Type u_2
s✝ t : Set α
inst✝ : Preorder α
s : Set α
hs : chainHeight s ≠ ⊤
⊢ chainHeight (⇑ofDual ⁻¹' s) ≠ ⊤

Next tactic:
rwa [chainHeight_dual]
/-- Let `n : ℤ` and `s` a subset of a commutative group `G` that is invariant under preimage for
the map `x ↦ x^n`. Then `s` is invariant under the pointwise action of the subgroup of elements
`g : G` such that `g^(n^j) = 1` for some `j : ℕ`. (This subgroup is called the Prüfer subgroup when
 `G` is the `Circle` and `n` is prime.) -/
@[to_additive
      "Let `n : ℤ` and `s` a subset of an additive commutative group `G` that is invariant
      under preimage for the map `x ↦ n • x`. Then `s` is invariant under the pointwise action of
      the additive subgroup of elements `g : G` such that `(n^j) • g = 0` for some `j : ℕ`.
      (This additive subgroup is called the Prüfer subgroup when `G` is the `AddCircle` and `n` is
      prime.)"]
theorem smul_eq_self_of_preimage_zpow_eq_self {G : Type*} [CommGroup G] {n : ℤ} {s : Set G}
    (hs : (fun x => x ^ n) ⁻¹' s = s) {g : G} {j : ℕ} (hg : g ^ n ^ j = 1) : g • s = s := by
  

Proof state:
G : Type u_1
inst✝ : CommGroup G
n : ℤ
s : Set G
hs : (fun x => x ^ n) ⁻¹' s = s
g : G
j : ℕ
hg : g ^ n ^ j = 1
⊢ g • s = s

Next tactic:
suffices ∀ {g' : G} (_ : g' ^ n ^ j = 1), g' • s ⊆ s by
    refine' le_antisymm (this hg) _
    conv_lhs => rw [← smul_inv_smul g s]
    replace hg : g⁻¹ ^ n ^ j = 1
    · rw [inv_zpow, hg, inv_one]
    simpa only [le_eq_subset, set_smul_subset_set_smul_iff] using this hg
/-- Let `n : ℤ` and `s` a subset of a commutative group `G` that is invariant under preimage for
the map `x ↦ x^n`. Then `s` is invariant under the pointwise action of the subgroup of elements
`g : G` such that `g^(n^j) = 1` for some `j : ℕ`. (This subgroup is called the Prüfer subgroup when
 `G` is the `Circle` and `n` is prime.) -/
@[to_additive
      "Let `n : ℤ` and `s` a subset of an additive commutative group `G` that is invariant
      under preimage for the map `x ↦ n • x`. Then `s` is invariant under the pointwise action of
      the additive subgroup of elements `g : G` such that `(n^j) • g = 0` for some `j : ℕ`.
      (This additive subgroup is called the Prüfer subgroup when `G` is the `AddCircle` and `n` is
      prime.)"]
theorem smul_eq_self_of_preimage_zpow_eq_self {G : Type*} [CommGroup G] {n : ℤ} {s : Set G}
    (hs : (fun x => x ^ n) ⁻¹' s = s) {g : G} {j : ℕ} (hg : g ^ n ^ j = 1) : g • s = s := by
  suffices ∀ {g' : G} (_ : g' ^ n ^ j = 1), g' • s ⊆ s by
    

Proof state:
G : Type u_1
inst✝ : CommGroup G
n : ℤ
s : Set G
hs : (fun x => x ^ n) ⁻¹' s = s
g : G
j : ℕ
hg : g ^ n ^ j = 1
this : ∀ {g' : G}, g' ^ n ^ j = 1 → g' • s ⊆ s
⊢ g • s = s

Next tactic:
refine' le_antisymm (this hg) _
/-- Let `n : ℤ` and `s` a subset of a commutative group `G` that is invariant under preimage for
the map `x ↦ x^n`. Then `s` is invariant under the pointwise action of the subgroup of elements
`g : G` such that `g^(n^j) = 1` for some `j : ℕ`. (This subgroup is called the Prüfer subgroup when
 `G` is the `Circle` and `n` is prime.) -/
@[to_additive
      "Let `n : ℤ` and `s` a subset of an additive commutative group `G` that is invariant
      under preimage for the map `x ↦ n • x`. Then `s` is invariant under the pointwise action of
      the additive subgroup of elements `g : G` such that `(n^j) • g = 0` for some `j : ℕ`.
      (This additive subgroup is called the Prüfer subgroup when `G` is the `AddCircle` and `n` is
      prime.)"]
theorem smul_eq_self_of_preimage_zpow_eq_self {G : Type*} [CommGroup G] {n : ℤ} {s : Set G}
    (hs : (fun x => x ^ n) ⁻¹' s = s) {g : G} {j : ℕ} (hg : g ^ n ^ j = 1) : g • s = s := by
  suffices ∀ {g' : G} (_ : g' ^ n ^ j = 1), g' • s ⊆ s by
    refine' le_antisymm (this hg) _
    

Proof state:
G : Type u_1
inst✝ : CommGroup G
n : ℤ
s : Set G
hs : (fun x => x ^ n) ⁻¹' s = s
g : G
j : ℕ
hg : g ^ n ^ j = 1
this : ∀ {g' : G}, g' ^ n ^ j = 1 → g' • s ⊆ s
⊢ s ≤ g • s

Next tactic:
conv_lhs => rw [← smul_inv_smul g s]