l3lab/ntp-mathlib huggingface dataset:
theorem partiallyWellOrderedOn_iff_exists_monotone_subseq :
    s.PartiallyWellOrderedOn r ↔
      ∀ f : ℕ → α, (∀ n, f n ∈ s) → ∃ g : ℕ ↪o ℕ, ∀ m n : ℕ, m ≤ n → r (f (g m)) (f (g n)) := by
  constructor <;> intro h f hf
  · exact h.exists_monotone_subseq f hf
  · obtain ⟨g, gmon⟩ := h f hf
    

Proof state:
case mpr.intro
ι : Type u_1
α : Type u_2
β : Type u_3
γ : Type u_4
π : ι → Type u_5
r : α → α → Prop
r' : β → β → Prop
f✝ : α → β
s t : Set α
a : α
inst✝¹ : IsRefl α r
inst✝ : IsTrans α r
h : ∀ (f : ℕ → α), (∀ (n : ℕ), f n ∈ s) → ∃ g, ∀ (m n : ℕ), m ≤ n → r (f (g m)) (f (g n))
f : ℕ → α
hf : ∀ (n : ℕ), f n ∈ s
g : ℕ ↪o ℕ
gmon : ∀ (m n : ℕ), m ≤ n → r (f (g m)) (f (g n))
⊢ ∃ m n, m < n ∧ r (f m) (f n)

Next tactic:
exact ⟨g 0, g 1, g.lt_iff_lt.2 zero_lt_one, gmon _ _ zero_le_one⟩
protected theorem PartiallyWellOrderedOn.prod {t : Set β} (hs : PartiallyWellOrderedOn s r)
    (ht : PartiallyWellOrderedOn t r') :
    PartiallyWellOrderedOn (s ×ˢ t) fun x y : α × β => r x.1 y.1 ∧ r' x.2 y.2 := by
  

Proof state:
ι : Type u_1
α : Type u_2
β : Type u_3
γ : Type u_4
π : ι → Type u_5
r : α → α → Prop
r' : β → β → Prop
f : α → β
s t✝ : Set α
a : α
inst✝¹ : IsRefl α r
inst✝ : IsTrans α r
t : Set β
hs : PartiallyWellOrderedOn s r
ht : PartiallyWellOrderedOn t r'
⊢ PartiallyWellOrderedOn (s ×ˢ t) fun x y => r x.1 y.1 ∧ r' x.2 y.2

Next tactic:
intro f hf
protected theorem PartiallyWellOrderedOn.prod {t : Set β} (hs : PartiallyWellOrderedOn s r)
    (ht : PartiallyWellOrderedOn t r') :
    PartiallyWellOrderedOn (s ×ˢ t) fun x y : α × β => r x.1 y.1 ∧ r' x.2 y.2 := by
  intro f hf
  

Proof state:
ι : Type u_1
α : Type u_2
β : Type u_3
γ : Type u_4
π : ι → Type u_5
r : α → α → Prop
r' : β → β → Prop
f✝ : α → β
s t✝ : Set α
a : α
inst✝¹ : IsRefl α r
inst✝ : IsTrans α r
t : Set β
hs : PartiallyWellOrderedOn s r
ht : PartiallyWellOrderedOn t r'
f : ℕ → α × β
hf : ∀ (n : ℕ), f n ∈ s ×ˢ t
⊢ ∃ m n, m < n ∧ (fun x y => r x.1 y.1 ∧ r' x.2 y.2) (f m) (f n)

Next tactic:
obtain ⟨g₁, h₁⟩ := hs.exists_monotone_subseq (Prod.fst ∘ f) fun n => (hf n).1
protected theorem PartiallyWellOrderedOn.prod {t : Set β} (hs : PartiallyWellOrderedOn s r)
    (ht : PartiallyWellOrderedOn t r') :
    PartiallyWellOrderedOn (s ×ˢ t) fun x y : α × β => r x.1 y.1 ∧ r' x.2 y.2 := by
  intro f hf
  obtain ⟨g₁, h₁⟩ := hs.exists_monotone_subseq (Prod.fst ∘ f) fun n => (hf n).1
  

Proof state:
case intro
ι : Type u_1
α : Type u_2
β : Type u_3
γ : Type u_4
π : ι → Type u_5
r : α → α → Prop
r' : β → β → Prop
f✝ : α → β
s t✝ : Set α
a : α
inst✝¹ : IsRefl α r
inst✝ : IsTrans α r
t : Set β
hs : PartiallyWellOrderedOn s r
ht : PartiallyWellOrderedOn t r'
f : ℕ → α × β
hf : ∀ (n : ℕ), f n ∈ s ×ˢ t
g₁ : ℕ ↪o ℕ
h₁ : ∀ (m n : ℕ), m ≤ n → r ((Prod.fst ∘ f) (g₁ m)) ((Prod.fst ∘ f) (g₁ n))
⊢ ∃ m n, m < n ∧ (fun x y => r x.1 y.1 ∧ r' x.2 y.2) (f m) (f n)

Next tactic:
obtain ⟨m, n, hlt, hle⟩ := ht (Prod.snd ∘ f ∘ g₁) fun n => (hf _).2
protected theorem PartiallyWellOrderedOn.prod {t : Set β} (hs : PartiallyWellOrderedOn s r)
    (ht : PartiallyWellOrderedOn t r') :
    PartiallyWellOrderedOn (s ×ˢ t) fun x y : α × β => r x.1 y.1 ∧ r' x.2 y.2 := by
  intro f hf
  obtain ⟨g₁, h₁⟩ := hs.exists_monotone_subseq (Prod.fst ∘ f) fun n => (hf n).1
  obtain ⟨m, n, hlt, hle⟩ := ht (Prod.snd ∘ f ∘ g₁) fun n => (hf _).2
  

Proof state:
case intro.intro.intro.intro
ι : Type u_1
α : Type u_2
β : Type u_3
γ : Type u_4
π : ι → Type u_5
r : α → α → Prop
r' : β → β → Prop
f✝ : α → β
s t✝ : Set α
a : α
inst✝¹ : IsRefl α r
inst✝ : IsTrans α r
t : Set β
hs : PartiallyWellOrderedOn s r
ht : PartiallyWellOrderedOn t r'
f : ℕ → α × β
hf : ∀ (n : ℕ), f n ∈ s ×ˢ t
g₁ : ℕ ↪o ℕ
h₁ : ∀ (m n : ℕ), m ≤ n → r ((Prod.fst ∘ f) (g₁ m)) ((Prod.fst ∘ f) (g₁ n))
m n : ℕ
hlt : m < n
hle : r' ((Prod.snd ∘ f ∘ ⇑g₁) m) ((Prod.snd ∘ f ∘ ⇑g₁) n)
⊢ ∃ m n, m < n ∧ (fun x y => r x.1 y.1 ∧ r' x.2 y.2) (f m) (f n)

Next tactic:
exact ⟨g₁ m, g₁ n, g₁.strictMono hlt, h₁ _ _ hlt.le, hle⟩
theorem PartiallyWellOrderedOn.wellFoundedOn [IsPreorder α r] (h : s.PartiallyWellOrderedOn r) :
    s.WellFoundedOn fun a b => r a b ∧ ¬r b a := by
  

Proof state:
ι : Type u_1
α : Type u_2
β : Type u_3
γ : Type u_4
π : ι → Type u_5
r : α → α → Prop
r' : β → β → Prop
f : α → β
s t : Set α
a : α
inst✝ : IsPreorder α r
h : PartiallyWellOrderedOn s r
⊢ WellFoundedOn s fun a b => r a b ∧ ¬r b a

Next tactic:
letI : Preorder α :=
    { le := r
      le_refl := refl_of r
      le_trans := fun _ _ _ => trans_of r }
theorem PartiallyWellOrderedOn.wellFoundedOn [IsPreorder α r] (h : s.PartiallyWellOrderedOn r) :
    s.WellFoundedOn fun a b => r a b ∧ ¬r b a := by
  letI : Preorder α :=
    { le := r
      le_refl := refl_of r
      le_trans := fun _ _ _ => trans_of r }
  

Proof state:
ι : Type u_1
α : Type u_2
β : Type u_3
γ : Type u_4
π : ι → Type u_5
r : α → α → Prop
r' : β → β → Prop
f : α → β
s t : Set α
a : α
inst✝ : IsPreorder α r
h : PartiallyWellOrderedOn s r
this : Preorder α := Preorder.mk (_ : ∀ (a : α), r a a) (_ : ∀ (x x_1 x_2 : α), r x x_1 → r x_1 x_2 → r x x_2)
⊢ WellFoundedOn s fun a b => r a b ∧ ¬r b a

Next tactic:
change s.WellFoundedOn (· < ·)
theorem PartiallyWellOrderedOn.wellFoundedOn [IsPreorder α r] (h : s.PartiallyWellOrderedOn r) :
    s.WellFoundedOn fun a b => r a b ∧ ¬r b a := by
  letI : Preorder α :=
    { le := r
      le_refl := refl_of r
      le_trans := fun _ _ _ => trans_of r }
  change s.WellFoundedOn (· < ·)
  

Proof state:
ι : Type u_1
α : Type u_2
β : Type u_3
γ : Type u_4
π : ι → Type u_5
r : α → α → Prop
r' : β → β → Prop
f : α → β
s t : Set α
a : α
inst✝ : IsPreorder α r
h : PartiallyWellOrderedOn s r
this : Preorder α := Preorder.mk (_ : ∀ (a : α), r a a) (_ : ∀ (x x_1 x_2 : α), r x x_1 → r x_1 x_2 → r x x_2)
⊢ WellFoundedOn s fun x x_1 => x < x_1

Next tactic:
replace h : s.PartiallyWellOrderedOn (· ≤ ·) := h
theorem PartiallyWellOrderedOn.wellFoundedOn [IsPreorder α r] (h : s.PartiallyWellOrderedOn r) :
    s.WellFoundedOn fun a b => r a b ∧ ¬r b a := by
  letI : Preorder α :=
    { le := r
      le_refl := refl_of r
      le_trans := fun _ _ _ => trans_of r }
  change s.WellFoundedOn (· < ·)
  replace h : s.PartiallyWellOrderedOn (· ≤ ·) := h -- porting note: was `change _ at h`
  

Proof state:
ι : Type u_1
α : Type u_2
β : Type u_3
γ : Type u_4
π : ι → Type u_5
r : α → α → Prop
r' : β → β → Prop
f : α → β
s t : Set α
a : α
inst✝ : IsPreorder α r
this : Preorder α := Preorder.mk (_ : ∀ (a : α), r a a) (_ : ∀ (x x_1 x_2 : α), r x x_1 → r x_1 x_2 → r x x_2)
h : PartiallyWellOrderedOn s fun x x_1 => x ≤ x_1
⊢ WellFoundedOn s fun x x_1 => x < x_1

Next tactic:
rw [wellFoundedOn_iff_no_descending_seq]
theorem PartiallyWellOrderedOn.wellFoundedOn [IsPreorder α r] (h : s.PartiallyWellOrderedOn r) :
    s.WellFoundedOn fun a b => r a b ∧ ¬r b a := by
  letI : Preorder α :=
    { le := r
      le_refl := refl_of r
      le_trans := fun _ _ _ => trans_of r }
  change s.WellFoundedOn (· < ·)
  replace h : s.PartiallyWellOrderedOn (· ≤ ·) := h -- porting note: was `change _ at h`
  rw [wellFoundedOn_iff_no_descending_seq]
  

Proof state:
ι : Type u_1
α : Type u_2
β : Type u_3
γ : Type u_4
π : ι → Type u_5
r : α → α → Prop
r' : β → β → Prop
f : α → β
s t : Set α
a : α
inst✝ : IsPreorder α r
this : Preorder α := Preorder.mk (_ : ∀ (a : α), r a a) (_ : ∀ (x x_1 x_2 : α), r x x_1 → r x_1 x_2 → r x x_2)
h : PartiallyWellOrderedOn s fun x x_1 => x ≤ x_1
⊢ ∀ (f : (fun x x_1 => x > x_1) ↪r fun x x_1 => x < x_1), ¬∀ (n : ℕ), f n ∈ s

Next tactic:
intro f hf
theorem PartiallyWellOrderedOn.wellFoundedOn [IsPreorder α r] (h : s.PartiallyWellOrderedOn r) :
    s.WellFoundedOn fun a b => r a b ∧ ¬r b a := by
  letI : Preorder α :=
    { le := r
      le_refl := refl_of r
      le_trans := fun _ _ _ => trans_of r }
  change s.WellFoundedOn (· < ·)
  replace h : s.PartiallyWellOrderedOn (· ≤ ·) := h -- porting note: was `change _ at h`
  rw [wellFoundedOn_iff_no_descending_seq]
  intro f hf
  

Proof state:
ι : Type u_1
α : Type u_2
β : Type u_3
γ : Type u_4
π : ι → Type u_5
r : α → α → Prop
r' : β → β → Prop
f✝ : α → β
s t : Set α
a : α
inst✝ : IsPreorder α r
this : Preorder α := Preorder.mk (_ : ∀ (a : α), r a a) (_ : ∀ (x x_1 x_2 : α), r x x_1 → r x_1 x_2 → r x x_2)
h : PartiallyWellOrderedOn s fun x x_1 => x ≤ x_1
f : (fun x x_1 => x > x_1) ↪r fun x x_1 => x < x_1
hf : ∀ (n : ℕ), f n ∈ s
⊢ False

Next tactic:
obtain ⟨m, n, hlt, hle⟩ := h f hf
theorem PartiallyWellOrderedOn.wellFoundedOn [IsPreorder α r] (h : s.PartiallyWellOrderedOn r) :
    s.WellFoundedOn fun a b => r a b ∧ ¬r b a := by
  letI : Preorder α :=
    { le := r
      le_refl := refl_of r
      le_trans := fun _ _ _ => trans_of r }
  change s.WellFoundedOn (· < ·)
  replace h : s.PartiallyWellOrderedOn (· ≤ ·) := h -- porting note: was `change _ at h`
  rw [wellFoundedOn_iff_no_descending_seq]
  intro f hf
  obtain ⟨m, n, hlt, hle⟩ := h f hf
  

Proof state:
case intro.intro.intro
ι : Type u_1
α : Type u_2
β : Type u_3
γ : Type u_4
π : ι → Type u_5
r : α → α → Prop
r' : β → β → Prop
f✝ : α → β
s t : Set α
a : α
inst✝ : IsPreorder α r
this : Preorder α := Preorder.mk (_ : ∀ (a : α), r a a) (_ : ∀ (x x_1 x_2 : α), r x x_1 → r x_1 x_2 → r x x_2)
h : PartiallyWellOrderedOn s fun x x_1 => x ≤ x_1
f : (fun x x_1 => x > x_1) ↪r fun x x_1 => x < x_1
hf : ∀ (n : ℕ), f n ∈ s
m n : ℕ
hlt : m < n
hle : f m ≤ f n
⊢ False

Next tactic:
exact (f.map_rel_iff.2 hlt).not_le hle
protected theorem IsPwo.isWf (h : s.IsPwo) : s.IsWf := by
  

Proof state:
ι : Type u_1
α : Type u_2
β : Type u_3
γ : Type u_4
π : ι → Type u_5
inst✝¹ : Preorder α
inst✝ : Preorder β
s t : Set α
h : IsPwo s
⊢ IsWf s

Next tactic:
simpa only [← lt_iff_le_not_le] using h.wellFoundedOn
@[simp]
theorem isPwo_insert {a} : IsPwo (insert a s) ↔ IsPwo s := by
  

Proof state:
ι : Type u_1
α : Type u_2
β : Type u_3
γ : Type u_4
π : ι → Type u_5
inst✝¹ : Preorder α
inst✝ : Preorder β
s t : Set α
a : α
⊢ IsPwo (insert a s) ↔ IsPwo s

Next tactic:
simp only [← singleton_union, isPwo_union, isPwo_singleton, true_and_iff]
@[simp]
theorem isWf_insert {a} : IsWf (insert a s) ↔ IsWf s := by
  

Proof state:
ι : Type u_1
α : Type u_2
β : Type u_3
γ : Type u_4
π : ι → Type u_5
inst✝¹ : Preorder α
inst✝ : Preorder β
s t : Set α
a : α
⊢ IsWf (insert a s) ↔ IsWf s

Next tactic:
simp only [← singleton_union, isWf_union, isWf_singleton, true_and_iff]
@[simp]
theorem wellFoundedOn_insert : WellFoundedOn (insert a s) r ↔ WellFoundedOn s r := by
  

Proof state:
ι : Type u_1
α : Type u_2
β : Type u_3
γ : Type u_4
π : ι → Type u_5
r : α → α → Prop
inst✝ : IsStrictOrder α r
s : Set α
a : α
⊢ WellFoundedOn (insert a s) r ↔ WellFoundedOn s r

Next tactic:
simp only [← singleton_union, wellFoundedOn_union, wellFoundedOn_singleton, true_and_iff]
protected theorem IsWf.isPwo (hs : s.IsWf) : s.IsPwo := by
  

Proof state:
ι : Type u_1
α : Type u_2
β : Type u_3
γ : Type u_4
π : ι → Type u_5
inst✝ : LinearOrder α
s : Set α
hs : IsWf s
⊢ IsPwo s

Next tactic:
intro f hf
protected theorem IsWf.isPwo (hs : s.IsWf) : s.IsPwo := by
  intro f hf
  

Proof state:
ι : Type u_1
α : Type u_2
β : Type u_3
γ : Type u_4
π : ι → Type u_5
inst✝ : LinearOrder α
s : Set α
hs : IsWf s
f : ℕ → α
hf : ∀ (n : ℕ), f n ∈ s
⊢ ∃ m n, m < n ∧ (fun x x_1 => x ≤ x_1) (f m) (f n)

Next tactic:
lift f to ℕ → s using hf
protected theorem IsWf.isPwo (hs : s.IsWf) : s.IsPwo := by
  intro f hf
  lift f to ℕ → s using hf
  

Proof state:
case intro
ι : Type u_1
α : Type u_2
β : Type u_3
γ : Type u_4
π : ι → Type u_5
inst✝ : LinearOrder α
s : Set α
hs : IsWf s
f : ℕ → ↑s
⊢ ∃ m n, m < n ∧ (fun x x_1 => x ≤ x_1) ((fun i => ↑(f i)) m) ((fun i => ↑(f i)) n)

Next tactic:
rcases hs.has_min (range f) (range_nonempty _) with ⟨_, ⟨m, rfl⟩, hm⟩
protected theorem IsWf.isPwo (hs : s.IsWf) : s.IsPwo := by
  intro f hf
  lift f to ℕ → s using hf
  rcases hs.has_min (range f) (range_nonempty _) with ⟨_, ⟨m, rfl⟩, hm⟩
  

Proof state:
case intro.intro.intro.intro
ι : Type u_1
α : Type u_2
β : Type u_3
γ : Type u_4
π : ι → Type u_5
inst✝ : LinearOrder α
s : Set α
hs : IsWf s
f : ℕ → ↑s
m : ℕ
hm : ∀ x ∈ range f, ¬(fun x x_1 => x < x_1) ↑x ↑(f m)
⊢ ∃ m n, m < n ∧ (fun x x_1 => x ≤ x_1) ((fun i => ↑(f i)) m) ((fun i => ↑(f i)) n)

Next tactic:
simp only [forall_range_iff, not_lt] at hm
protected theorem IsWf.isPwo (hs : s.IsWf) : s.IsPwo := by
  intro f hf
  lift f to ℕ → s using hf
  rcases hs.has_min (range f) (range_nonempty _) with ⟨_, ⟨m, rfl⟩, hm⟩
  simp only [forall_range_iff, not_lt] at hm
  

Proof state:
case intro.intro.intro.intro
ι : Type u_1
α : Type u_2
β : Type u_3
γ : Type u_4
π : ι → Type u_5
inst✝ : LinearOrder α
s : Set α
hs : IsWf s
f : ℕ → ↑s
m : ℕ
hm : ∀ (i : ℕ), ↑(f m) ≤ ↑(f i)
⊢ ∃ m n, m < n ∧ (fun x x_1 => x ≤ x_1) ((fun i => ↑(f i)) m) ((fun i => ↑(f i)) n)

Next tactic:
exact ⟨m, m + 1, lt_add_one m, hm _⟩
theorem wellFoundedOn_sup [IsStrictOrder α r] (s : Finset ι) {f : ι → Set α} :
    (s.sup f).WellFoundedOn r ↔ ∀ i ∈ s, (f i).WellFoundedOn r :=
  Finset.cons_induction_on s (by 

Proof state:
ι : Type u_1
α : Type u_2
β : Type u_3
γ : Type u_4
π : ι → Type u_5
r : α → α → Prop
inst✝ : IsStrictOrder α r
s : Finset ι
f : ι → Set α
⊢ Set.WellFoundedOn (sup ∅ f) r ↔ ∀ i ∈ ∅, Set.WellFoundedOn (f i) r

Next tactic:
simp
theorem wellFoundedOn_sup [IsStrictOrder α r] (s : Finset ι) {f : ι → Set α} :
    (s.sup f).WellFoundedOn r ↔ ∀ i ∈ s, (f i).WellFoundedOn r :=
  Finset.cons_induction_on s (by simp) fun a s ha hs => by 

Proof state:
ι : Type u_1
α : Type u_2
β : Type u_3
γ : Type u_4
π : ι → Type u_5
r : α → α → Prop
inst✝ : IsStrictOrder α r
s✝ : Finset ι
f : ι → Set α
a : ι
s : Finset ι
ha : a ∉ s
hs : Set.WellFoundedOn (sup s f) r ↔ ∀ i ∈ s, Set.WellFoundedOn (f i) r
⊢ Set.WellFoundedOn (sup (cons a s ha) f) r ↔ ∀ i ∈ cons a s ha, Set.WellFoundedOn (f i) r

Next tactic:
simp [-sup_set_eq_biUnion, hs]
theorem partiallyWellOrderedOn_sup (s : Finset ι) {f : ι → Set α} :
    (s.sup f).PartiallyWellOrderedOn r ↔ ∀ i ∈ s, (f i).PartiallyWellOrderedOn r :=
  Finset.cons_induction_on s (by 

Proof state:
ι : Type u_1
α : Type u_2
β : Type u_3
γ : Type u_4
π : ι → Type u_5
r : α → α → Prop
s : Finset ι
f : ι → Set α
⊢ Set.PartiallyWellOrderedOn (sup ∅ f) r ↔ ∀ i ∈ ∅, Set.PartiallyWellOrderedOn (f i) r

Next tactic:
simp
theorem partiallyWellOrderedOn_sup (s : Finset ι) {f : ι → Set α} :
    (s.sup f).PartiallyWellOrderedOn r ↔ ∀ i ∈ s, (f i).PartiallyWellOrderedOn r :=
  Finset.cons_induction_on s (by simp) fun a s ha hs => by 

Proof state:
ι : Type u_1
α : Type u_2
β : Type u_3
γ : Type u_4
π : ι → Type u_5
r : α → α → Prop
s✝ : Finset ι
f : ι → Set α
a : ι
s : Finset ι
ha : a ∉ s
hs : Set.PartiallyWellOrderedOn (sup s f) r ↔ ∀ i ∈ s, Set.PartiallyWellOrderedOn (f i) r
⊢ Set.PartiallyWellOrderedOn (sup (cons a s ha) f) r ↔ ∀ i ∈ cons a s ha, Set.PartiallyWellOrderedOn (f i) r

Next tactic:
simp [-sup_set_eq_biUnion, hs]
@[simp]
theorem wellFoundedOn_bUnion [IsStrictOrder α r] (s : Finset ι) {f : ι → Set α} :
    (⋃ i ∈ s, f i).WellFoundedOn r ↔ ∀ i ∈ s, (f i).WellFoundedOn r := by
  

Proof state:
ι : Type u_1
α : Type u_2
β : Type u_3
γ : Type u_4
π : ι → Type u_5
r : α → α → Prop
inst✝ : IsStrictOrder α r
s : Finset ι
f : ι → Set α
⊢ Set.WellFoundedOn (⋃ i ∈ s, f i) r ↔ ∀ i ∈ s, Set.WellFoundedOn (f i) r

Next tactic:
simpa only [Finset.sup_eq_iSup] using s.wellFoundedOn_sup
@[simp]
theorem partiallyWellOrderedOn_bUnion (s : Finset ι) {f : ι → Set α} :
    (⋃ i ∈ s, f i).PartiallyWellOrderedOn r ↔ ∀ i ∈ s, (f i).PartiallyWellOrderedOn r := by
  

Proof state:
ι : Type u_1
α : Type u_2
β : Type u_3
γ : Type u_4
π : ι → Type u_5
r : α → α → Prop
s : Finset ι
f : ι → Set α
⊢ Set.PartiallyWellOrderedOn (⋃ i ∈ s, f i) r ↔ ∀ i ∈ s, Set.PartiallyWellOrderedOn (f i) r

Next tactic:
simpa only [Finset.sup_eq_iSup] using s.partiallyWellOrderedOn_sup
theorem IsWf.min_union (hs : s.IsWf) (hsn : s.Nonempty) (ht : t.IsWf) (htn : t.Nonempty) :
    (hs.union ht).min (union_nonempty.2 (Or.intro_left _ hsn)) =
      Min.min (hs.min hsn) (ht.min htn) := by
  

Proof state:
ι : Type u_1
α : Type u_2
β : Type u_3
γ : Type u_4
π : ι → Type u_5
inst✝ : LinearOrder α
s t : Set α
a : α
hs : IsWf s
hsn : Set.Nonempty s
ht : IsWf t
htn : Set.Nonempty t
⊢ min (_ : IsWf (s ∪ t)) (_ : Set.Nonempty (s ∪ t)) = Min.min (min hs hsn) (min ht htn)

Next tactic:
refine' le_antisymm (le_min (IsWf.min_le_min_of_subset (subset_union_left _ _))
    (IsWf.min_le_min_of_subset (subset_union_right _ _))) _
theorem IsWf.min_union (hs : s.IsWf) (hsn : s.Nonempty) (ht : t.IsWf) (htn : t.Nonempty) :
    (hs.union ht).min (union_nonempty.2 (Or.intro_left _ hsn)) =
      Min.min (hs.min hsn) (ht.min htn) := by
  refine' le_antisymm (le_min (IsWf.min_le_min_of_subset (subset_union_left _ _))
    (IsWf.min_le_min_of_subset (subset_union_right _ _))) _
  

Proof state:
ι : Type u_1
α : Type u_2
β : Type u_3
γ : Type u_4
π : ι → Type u_5
inst✝ : LinearOrder α
s t : Set α
a : α
hs : IsWf s
hsn : Set.Nonempty s
ht : IsWf t
htn : Set.Nonempty t
⊢ Min.min (min hs hsn) (min ht htn) ≤ min (_ : IsWf (s ∪ t)) (_ : Set.Nonempty (s ∪ t))

Next tactic:
rw [min_le_iff]
theorem IsWf.min_union (hs : s.IsWf) (hsn : s.Nonempty) (ht : t.IsWf) (htn : t.Nonempty) :
    (hs.union ht).min (union_nonempty.2 (Or.intro_left _ hsn)) =
      Min.min (hs.min hsn) (ht.min htn) := by
  refine' le_antisymm (le_min (IsWf.min_le_min_of_subset (subset_union_left _ _))
    (IsWf.min_le_min_of_subset (subset_union_right _ _))) _
  rw [min_le_iff]
  

Proof state:
ι : Type u_1
α : Type u_2
β : Type u_3
γ : Type u_4
π : ι → Type u_5
inst✝ : LinearOrder α
s t : Set α
a : α
hs : IsWf s
hsn : Set.Nonempty s
ht : IsWf t
htn : Set.Nonempty t
⊢ min hs hsn ≤ min (_ : IsWf (s ∪ t)) (_ : Set.Nonempty (s ∪ t)) ∨
    min ht htn ≤ min (_ : IsWf (s ∪ t)) (_ : Set.Nonempty (s ∪ t))

Next tactic:
exact ((mem_union _ _ _).1 ((hs.union ht).min_mem (union_nonempty.2 (.inl hsn)))).imp
    (hs.min_le _) (ht.min_le _)
theorem iff_forall_not_isBadSeq (r : α → α → Prop) (s : Set α) :
    s.PartiallyWellOrderedOn r ↔ ∀ f, ¬IsBadSeq r s f :=
  forall_congr' fun f => by 

Proof state:
ι : Type u_1
α : Type u_2
β : Type u_3
γ : Type u_4
π : ι → Type u_5
r✝ r : α → α → Prop
s : Set α
f : ℕ → α
⊢ ((∀ (n : ℕ), f n ∈ s) → ∃ m n, m < n ∧ r (f m) (f n)) ↔ ¬IsBadSeq r s f

Next tactic:
simp [IsBadSeq]
/-- Given a bad sequence `f`, this constructs a bad sequence that agrees with `f` on the first `n`
  terms and is minimal at `n`.
-/
noncomputable def minBadSeqOfBadSeq (r : α → α → Prop) (rk : α → ℕ) (s : Set α) (n : ℕ) (f : ℕ → α)
    (hf : IsBadSeq r s f) :
    { g : ℕ → α // (∀ m : ℕ, m < n → f m = g m) ∧ IsBadSeq r s g ∧ IsMinBadSeq r rk s n g } := by
  

Proof state:
ι : Type u_1
α : Type u_2
β : Type u_3
γ : Type u_4
π : ι → Type u_5
r✝ r : α → α → Prop
rk : α → ℕ
s : Set α
n : ℕ
f : ℕ → α
hf : IsBadSeq r s f
⊢ { g // (∀ m < n, f m = g m) ∧ IsBadSeq r s g ∧ IsMinBadSeq r rk s n g }

Next tactic:
classical
    have h : ∃ (k : ℕ) (g : ℕ → α), (∀ m, m < n → f m = g m) ∧ IsBadSeq r s g ∧ rk (g n) = k :=
      ⟨_, f, fun _ _ => rfl, hf, rfl⟩
    obtain ⟨h1, h2, h3⟩ := Classical.choose_spec (Nat.find_spec h)
    refine' ⟨Classical.choose (Nat.find_spec h), h1, by convert h2, fun g hg1 hg2 con => _⟩
    refine' Nat.find_min h _ ⟨g, fun m mn => (h1 m mn).trans (hg1 m mn), con, rfl⟩
    rwa [← h3]
/-- Given a bad sequence `f`, this constructs a bad sequence that agrees with `f` on the first `n`
  terms and is minimal at `n`.
-/
noncomputable def minBadSeqOfBadSeq (r : α → α → Prop) (rk : α → ℕ) (s : Set α) (n : ℕ) (f : ℕ → α)
    (hf : IsBadSeq r s f) :
    { g : ℕ → α // (∀ m : ℕ, m < n → f m = g m) ∧ IsBadSeq r s g ∧ IsMinBadSeq r rk s n g } := by
  classical
    

Proof state:
ι : Type u_1
α : Type u_2
β : Type u_3
γ : Type u_4
π : ι → Type u_5
r✝ r : α → α → Prop
rk : α → ℕ
s : Set α
n : ℕ
f : ℕ → α
hf : IsBadSeq r s f
⊢ { g // (∀ m < n, f m = g m) ∧ IsBadSeq r s g ∧ IsMinBadSeq r rk s n g }

Next tactic:
have h : ∃ (k : ℕ) (g : ℕ → α), (∀ m, m < n → f m = g m) ∧ IsBadSeq r s g ∧ rk (g n) = k :=
      ⟨_, f, fun _ _ => rfl, hf, rfl⟩
/-- Given a bad sequence `f`, this constructs a bad sequence that agrees with `f` on the first `n`
  terms and is minimal at `n`.
-/
noncomputable def minBadSeqOfBadSeq (r : α → α → Prop) (rk : α → ℕ) (s : Set α) (n : ℕ) (f : ℕ → α)
    (hf : IsBadSeq r s f) :
    { g : ℕ → α // (∀ m : ℕ, m < n → f m = g m) ∧ IsBadSeq r s g ∧ IsMinBadSeq r rk s n g } := by
  classical
    have h : ∃ (k : ℕ) (g : ℕ → α), (∀ m, m < n → f m = g m) ∧ IsBadSeq r s g ∧ rk (g n) = k :=
      ⟨_, f, fun _ _ => rfl, hf, rfl⟩
    

Proof state:
ι : Type u_1
α : Type u_2
β : Type u_3
γ : Type u_4
π : ι → Type u_5
r✝ r : α → α → Prop
rk : α → ℕ
s : Set α
n : ℕ
f : ℕ → α
hf : IsBadSeq r s f
h : ∃ k g, (∀ m < n, f m = g m) ∧ IsBadSeq r s g ∧ rk (g n) = k
⊢ { g // (∀ m < n, f m = g m) ∧ IsBadSeq r s g ∧ IsMinBadSeq r rk s n g }

Next tactic:
obtain ⟨h1, h2, h3⟩ := Classical.choose_spec (Nat.find_spec h)
/-- Given a bad sequence `f`, this constructs a bad sequence that agrees with `f` on the first `n`
  terms and is minimal at `n`.
-/
noncomputable def minBadSeqOfBadSeq (r : α → α → Prop) (rk : α → ℕ) (s : Set α) (n : ℕ) (f : ℕ → α)
    (hf : IsBadSeq r s f) :
    { g : ℕ → α // (∀ m : ℕ, m < n → f m = g m) ∧ IsBadSeq r s g ∧ IsMinBadSeq r rk s n g } := by
  classical
    have h : ∃ (k : ℕ) (g : ℕ → α), (∀ m, m < n → f m = g m) ∧ IsBadSeq r s g ∧ rk (g n) = k :=
      ⟨_, f, fun _ _ => rfl, hf, rfl⟩
    obtain ⟨h1, h2, h3⟩ := Classical.choose_spec (Nat.find_spec h)
    

Proof state:
case intro.intro
ι : Type u_1
α : Type u_2
β : Type u_3
γ : Type u_4
π : ι → Type u_5
r✝ r : α → α → Prop
rk : α → ℕ
s : Set α
n : ℕ
f : ℕ → α
hf : IsBadSeq r s f
h : ∃ k g, (∀ m < n, f m = g m) ∧ IsBadSeq r s g ∧ rk (g n) = k
h1 : ∀ m < n, f m = Classical.choose (_ : ∃ g, (∀ m < n, f m = g m) ∧ IsBadSeq r s g ∧ rk (g n) = Nat.find h) m
h2 : IsBadSeq r s (Classical.choose (_ : ∃ g, (∀ m < n, f m = g m) ∧ IsBadSeq r s g ∧ rk (g n) = Nat.find h))
h3 : rk (Classical.choose (_ : ∃ g, (∀ m < n, f m = g m) ∧ IsBadSeq r s g ∧ rk (g n) = Nat.find h) n) = Nat.find h
⊢ { g // (∀ m < n, f m = g m) ∧ IsBadSeq r s g ∧ IsMinBadSeq r rk s n g }

Next tactic:
refine' ⟨Classical.choose (Nat.find_spec h), h1, by convert h2, fun g hg1 hg2 con => _⟩
/-- Given a bad sequence `f`, this constructs a bad sequence that agrees with `f` on the first `n`
  terms and is minimal at `n`.
-/
noncomputable def minBadSeqOfBadSeq (r : α → α → Prop) (rk : α → ℕ) (s : Set α) (n : ℕ) (f : ℕ → α)
    (hf : IsBadSeq r s f) :
    { g : ℕ → α // (∀ m : ℕ, m < n → f m = g m) ∧ IsBadSeq r s g ∧ IsMinBadSeq r rk s n g } := by
  classical
    have h : ∃ (k : ℕ) (g : ℕ → α), (∀ m, m < n → f m = g m) ∧ IsBadSeq r s g ∧ rk (g n) = k :=
      ⟨_, f, fun _ _ => rfl, hf, rfl⟩
    obtain ⟨h1, h2, h3⟩ := Classical.choose_spec (Nat.find_spec h)
    refine' ⟨Classical.choose (Nat.find_spec h), h1, by 

Proof state:
ι : Type u_1
α : Type u_2
β : Type u_3
γ : Type u_4
π : ι → Type u_5
r✝ r : α → α → Prop
rk : α → ℕ
s : Set α
n : ℕ
f : ℕ → α
hf : IsBadSeq r s f
h : ∃ k g, (∀ m < n, f m = g m) ∧ IsBadSeq r s g ∧ rk (g n) = k
h1 : ∀ m < n, f m = Classical.choose (_ : ∃ g, (∀ m < n, f m = g m) ∧ IsBadSeq r s g ∧ rk (g n) = Nat.find h) m
h2 : IsBadSeq r s (Classical.choose (_ : ∃ g, (∀ m < n, f m = g m) ∧ IsBadSeq r s g ∧ rk (g n) = Nat.find h))
h3 : rk (Classical.choose (_ : ∃ g, (∀ m < n, f m = g m) ∧ IsBadSeq r s g ∧ rk (g n) = Nat.find h) n) = Nat.find h
⊢ IsBadSeq r s (Classical.choose (_ : ∃ g, (∀ m < n, f m = g m) ∧ IsBadSeq r s g ∧ rk (g n) = Nat.find h))

Next tactic:
convert h2