l3lab/ntp-mathlib huggingface dataset:
/-- Higman's Lemma, which states that for any reflexive, transitive relation `r` which is
  partially well-ordered on a set `s`, the relation `List.SublistForall₂ r` is partially
  well-ordered on the set of lists of elements of `s`. That relation is defined so that
  `List.SublistForall₂ r l₁ l₂` whenever `l₁` related pointwise by `r` to a sublist of `l₂`.  -/
theorem partiallyWellOrderedOn_sublistForall₂ (r : α → α → Prop) [IsRefl α r] [IsTrans α r]
    {s : Set α} (h : s.PartiallyWellOrderedOn r) :
    { l : List α | ∀ x, x ∈ l → x ∈ s }.PartiallyWellOrderedOn (List.SublistForall₂ r) := by
  rcases isEmpty_or_nonempty α
  · exact subsingleton_of_subsingleton.partiallyWellOrderedOn
  inhabit α
  rw [iff_not_exists_isMinBadSeq List.length]
  rintro ⟨f, hf1, hf2⟩
  have hnil : ∀ n, f n ≠ List.nil := fun n con =>
    hf1.2 n n.succ n.lt_succ_self (con.symm ▸ List.SublistForall₂.nil)
  have : ∀ n, (f n).headI ∈ s
  · exact fun n => hf1.1 n _ (List.head!_mem_self (hnil n))
  obtain ⟨g, hg⟩ := h.exists_monotone_subseq (fun n => (f n).headI) this
  have hf' :=
    hf2 (g 0) (fun n => if n < g 0 then f n else List.tail (f (g (n - g 0))))
      (fun m hm => (if_pos hm).symm) ?_
  swap;
  · simp only [if_neg (lt_irrefl (g 0)), tsub_self]
    rw [List.length_tail, ← Nat.pred_eq_sub_one]
    exact Nat.pred_lt fun con => hnil _ (List.length_eq_zero.1 con)
  rw [IsBadSeq] at hf'
  push_neg at hf'
  obtain ⟨m, n, mn, hmn⟩ := hf' <| fun n x hx => by
    split_ifs at hx with hn
    exacts [hf1.1 _ _ hx, hf1.1 _ _ (List.tail_subset _ hx)]
  by_cases hn : n < g 0
  · apply hf1.2 m n mn
    rwa [if_pos hn, if_pos (mn.trans hn)] at hmn
  · obtain ⟨n', rfl⟩ := exists_add_of_le (not_lt.1 hn)
    rw [if_neg hn, add_comm (g 0) n', add_tsub_cancel_right] at hmn
    split_ifs at hmn with hm
    · apply hf1.2 m (g n') (lt_of_lt_of_le hm (g.monotone n'.zero_le))
      exact _root_.trans hmn (List.tail_sublistForall₂_self _)
    · rw [← tsub_lt_iff_left (le_of_not_lt hm)] at mn
      apply hf1.2 _ _ (g.lt_iff_lt.2 mn)
      

Proof state:
case neg
ι : Type u_1
α : Type u_2
β : Type u_3
γ : Type u_4
π : ι → Type u_5
r✝ r : α → α → Prop
inst✝¹ : IsRefl α r
inst✝ : IsTrans α r
s : Set α
h : PartiallyWellOrderedOn s r
h✝ : Nonempty α
inhabited_h : Inhabited α
f : ℕ → List α
hf1 : IsBadSeq (List.SublistForall₂ r) {l | ∀ x ∈ l, x ∈ s} f
hf2 : ∀ (n : ℕ), IsMinBadSeq (List.SublistForall₂ r) List.length {l | ∀ x ∈ l, x ∈ s} n f
hnil : ∀ (n : ℕ), f n ≠ []
this : ∀ (n : ℕ), List.headI (f n) ∈ s
g : ℕ ↪o ℕ
hg : ∀ (m n : ℕ), m ≤ n → r (List.headI (f (g m))) (List.headI (f (g n)))
hf' :
  (∀ (n : ℕ), (if n < g 0 then f n else List.tail (f (g (n - g 0)))) ∈ {l | ∀ x ∈ l, x ∈ s}) →
    ∃ m n,
      m < n ∧
        List.SublistForall₂ r (if m < g 0 then f m else List.tail (f (g (m - g 0))))
          (if n < g 0 then f n else List.tail (f (g (n - g 0))))
m n' : ℕ
mn : m - g 0 < n'
hn : ¬g 0 + n' < g 0
hm : ¬m < g 0
hmn : List.SublistForall₂ r (List.tail (f (g (m - g 0)))) (List.tail (f (g n')))
⊢ List.SublistForall₂ r (f (g (m - g 0))) (f (g n'))

Next tactic:
rw [← List.cons_head!_tail (hnil (g (m - g 0))), ← List.cons_head!_tail (hnil (g n'))]
/-- A version of **Dickson's lemma** any subset of functions `Π s : σ, α s` is partially well
ordered, when `σ` is a `Fintype` and each `α s` is a linear well order.
This includes the classical case of Dickson's lemma that `ℕ ^ n` is a well partial order.
Some generalizations would be possible based on this proof, to include cases where the target is
partially well ordered, and also to consider the case of `Set.PartiallyWellOrderedOn` instead of
`Set.IsPwo`. -/
theorem Pi.isPwo {α : ι → Type*} [∀ i, LinearOrder (α i)] [∀ i, IsWellOrder (α i) (· < ·)]
    [Finite ι] (s : Set (∀ i, α i)) : s.IsPwo := by
  

Proof state:
ι : Type u_1
α✝ : Type u_2
β : Type u_3
γ : Type u_4
π : ι → Type u_5
α : ι → Type u_6
inst✝² : (i : ι) → LinearOrder (α i)
inst✝¹ : ∀ (i : ι), IsWellOrder (α i) fun x x_1 => x < x_1
inst✝ : Finite ι
s : Set ((i : ι) → α i)
⊢ IsPwo s

Next tactic:
cases nonempty_fintype ι
/-- A version of **Dickson's lemma** any subset of functions `Π s : σ, α s` is partially well
ordered, when `σ` is a `Fintype` and each `α s` is a linear well order.
This includes the classical case of Dickson's lemma that `ℕ ^ n` is a well partial order.
Some generalizations would be possible based on this proof, to include cases where the target is
partially well ordered, and also to consider the case of `Set.PartiallyWellOrderedOn` instead of
`Set.IsPwo`. -/
theorem Pi.isPwo {α : ι → Type*} [∀ i, LinearOrder (α i)] [∀ i, IsWellOrder (α i) (· < ·)]
    [Finite ι] (s : Set (∀ i, α i)) : s.IsPwo := by
  cases nonempty_fintype ι
  

Proof state:
case intro
ι : Type u_1
α✝ : Type u_2
β : Type u_3
γ : Type u_4
π : ι → Type u_5
α : ι → Type u_6
inst✝² : (i : ι) → LinearOrder (α i)
inst✝¹ : ∀ (i : ι), IsWellOrder (α i) fun x x_1 => x < x_1
inst✝ : Finite ι
s : Set ((i : ι) → α i)
val✝ : Fintype ι
⊢ IsPwo s

Next tactic:
suffices ∀ (s : Finset ι) (f : ℕ → ∀ s, α s),
    ∃ g : ℕ ↪o ℕ, ∀ ⦃a b : ℕ⦄, a ≤ b → ∀ x, x ∈ s → (f ∘ g) a x ≤ (f ∘ g) b x by
    refine isPwo_iff_exists_monotone_subseq.2 fun f _ => ?_
    simpa only [Finset.mem_univ, true_imp_iff] using this Finset.univ f
/-- A version of **Dickson's lemma** any subset of functions `Π s : σ, α s` is partially well
ordered, when `σ` is a `Fintype` and each `α s` is a linear well order.
This includes the classical case of Dickson's lemma that `ℕ ^ n` is a well partial order.
Some generalizations would be possible based on this proof, to include cases where the target is
partially well ordered, and also to consider the case of `Set.PartiallyWellOrderedOn` instead of
`Set.IsPwo`. -/
theorem Pi.isPwo {α : ι → Type*} [∀ i, LinearOrder (α i)] [∀ i, IsWellOrder (α i) (· < ·)]
    [Finite ι] (s : Set (∀ i, α i)) : s.IsPwo := by
  cases nonempty_fintype ι
  suffices ∀ (s : Finset ι) (f : ℕ → ∀ s, α s),
    ∃ g : ℕ ↪o ℕ, ∀ ⦃a b : ℕ⦄, a ≤ b → ∀ x, x ∈ s → (f ∘ g) a x ≤ (f ∘ g) b x by
    

Proof state:
ι : Type u_1
α✝ : Type u_2
β : Type u_3
γ : Type u_4
π : ι → Type u_5
α : ι → Type u_6
inst✝² : (i : ι) → LinearOrder (α i)
inst✝¹ : ∀ (i : ι), IsWellOrder (α i) fun x x_1 => x < x_1
inst✝ : Finite ι
s : Set ((i : ι) → α i)
val✝ : Fintype ι
this : ∀ (s : Finset ι) (f : ℕ → (s : ι) → α s), ∃ g, ∀ ⦃a b : ℕ⦄, a ≤ b → ∀ x ∈ s, (f ∘ ⇑g) a x ≤ (f ∘ ⇑g) b x
⊢ IsPwo s

Next tactic:
refine isPwo_iff_exists_monotone_subseq.2 fun f _ => ?_
/-- A version of **Dickson's lemma** any subset of functions `Π s : σ, α s` is partially well
ordered, when `σ` is a `Fintype` and each `α s` is a linear well order.
This includes the classical case of Dickson's lemma that `ℕ ^ n` is a well partial order.
Some generalizations would be possible based on this proof, to include cases where the target is
partially well ordered, and also to consider the case of `Set.PartiallyWellOrderedOn` instead of
`Set.IsPwo`. -/
theorem Pi.isPwo {α : ι → Type*} [∀ i, LinearOrder (α i)] [∀ i, IsWellOrder (α i) (· < ·)]
    [Finite ι] (s : Set (∀ i, α i)) : s.IsPwo := by
  cases nonempty_fintype ι
  suffices ∀ (s : Finset ι) (f : ℕ → ∀ s, α s),
    ∃ g : ℕ ↪o ℕ, ∀ ⦃a b : ℕ⦄, a ≤ b → ∀ x, x ∈ s → (f ∘ g) a x ≤ (f ∘ g) b x by
    refine isPwo_iff_exists_monotone_subseq.2 fun f _ => ?_
    

Proof state:
ι : Type u_1
α✝ : Type u_2
β : Type u_3
γ : Type u_4
π : ι → Type u_5
α : ι → Type u_6
inst✝² : (i : ι) → LinearOrder (α i)
inst✝¹ : ∀ (i : ι), IsWellOrder (α i) fun x x_1 => x < x_1
inst✝ : Finite ι
s : Set ((i : ι) → α i)
val✝ : Fintype ι
this : ∀ (s : Finset ι) (f : ℕ → (s : ι) → α s), ∃ g, ∀ ⦃a b : ℕ⦄, a ≤ b → ∀ x ∈ s, (f ∘ ⇑g) a x ≤ (f ∘ ⇑g) b x
f : ℕ → (i : ι) → α i
x✝ : ∀ (n : ℕ), f n ∈ s
⊢ ∃ g, Monotone (f ∘ ⇑g)

Next tactic:
simpa only [Finset.mem_univ, true_imp_iff] using this Finset.univ f
/-- A version of **Dickson's lemma** any subset of functions `Π s : σ, α s` is partially well
ordered, when `σ` is a `Fintype` and each `α s` is a linear well order.
This includes the classical case of Dickson's lemma that `ℕ ^ n` is a well partial order.
Some generalizations would be possible based on this proof, to include cases where the target is
partially well ordered, and also to consider the case of `Set.PartiallyWellOrderedOn` instead of
`Set.IsPwo`. -/
theorem Pi.isPwo {α : ι → Type*} [∀ i, LinearOrder (α i)] [∀ i, IsWellOrder (α i) (· < ·)]
    [Finite ι] (s : Set (∀ i, α i)) : s.IsPwo := by
  cases nonempty_fintype ι
  suffices ∀ (s : Finset ι) (f : ℕ → ∀ s, α s),
    ∃ g : ℕ ↪o ℕ, ∀ ⦃a b : ℕ⦄, a ≤ b → ∀ x, x ∈ s → (f ∘ g) a x ≤ (f ∘ g) b x by
    refine isPwo_iff_exists_monotone_subseq.2 fun f _ => ?_
    simpa only [Finset.mem_univ, true_imp_iff] using this Finset.univ f
  

Proof state:
case intro
ι : Type u_1
α✝ : Type u_2
β : Type u_3
γ : Type u_4
π : ι → Type u_5
α : ι → Type u_6
inst✝² : (i : ι) → LinearOrder (α i)
inst✝¹ : ∀ (i : ι), IsWellOrder (α i) fun x x_1 => x < x_1
inst✝ : Finite ι
s : Set ((i : ι) → α i)
val✝ : Fintype ι
⊢ ∀ (s : Finset ι) (f : ℕ → (s : ι) → α s), ∃ g, ∀ ⦃a b : ℕ⦄, a ≤ b → ∀ x ∈ s, (f ∘ ⇑g) a x ≤ (f ∘ ⇑g) b x

Next tactic:
refine' Finset.cons_induction _ _
/-- A version of **Dickson's lemma** any subset of functions `Π s : σ, α s` is partially well
ordered, when `σ` is a `Fintype` and each `α s` is a linear well order.
This includes the classical case of Dickson's lemma that `ℕ ^ n` is a well partial order.
Some generalizations would be possible based on this proof, to include cases where the target is
partially well ordered, and also to consider the case of `Set.PartiallyWellOrderedOn` instead of
`Set.IsPwo`. -/
theorem Pi.isPwo {α : ι → Type*} [∀ i, LinearOrder (α i)] [∀ i, IsWellOrder (α i) (· < ·)]
    [Finite ι] (s : Set (∀ i, α i)) : s.IsPwo := by
  cases nonempty_fintype ι
  suffices ∀ (s : Finset ι) (f : ℕ → ∀ s, α s),
    ∃ g : ℕ ↪o ℕ, ∀ ⦃a b : ℕ⦄, a ≤ b → ∀ x, x ∈ s → (f ∘ g) a x ≤ (f ∘ g) b x by
    refine isPwo_iff_exists_monotone_subseq.2 fun f _ => ?_
    simpa only [Finset.mem_univ, true_imp_iff] using this Finset.univ f
  refine' Finset.cons_induction _ _
  · 

Proof state:
case intro.refine'_1
ι : Type u_1
α✝ : Type u_2
β : Type u_3
γ : Type u_4
π : ι → Type u_5
α : ι → Type u_6
inst✝² : (i : ι) → LinearOrder (α i)
inst✝¹ : ∀ (i : ι), IsWellOrder (α i) fun x x_1 => x < x_1
inst✝ : Finite ι
s : Set ((i : ι) → α i)
val✝ : Fintype ι
⊢ ∀ (f : ℕ → (s : ι) → α s), ∃ g, ∀ ⦃a b : ℕ⦄, a ≤ b → ∀ x ∈ ∅, (f ∘ ⇑g) a x ≤ (f ∘ ⇑g) b x

Next tactic:
intro f
/-- A version of **Dickson's lemma** any subset of functions `Π s : σ, α s` is partially well
ordered, when `σ` is a `Fintype` and each `α s` is a linear well order.
This includes the classical case of Dickson's lemma that `ℕ ^ n` is a well partial order.
Some generalizations would be possible based on this proof, to include cases where the target is
partially well ordered, and also to consider the case of `Set.PartiallyWellOrderedOn` instead of
`Set.IsPwo`. -/
theorem Pi.isPwo {α : ι → Type*} [∀ i, LinearOrder (α i)] [∀ i, IsWellOrder (α i) (· < ·)]
    [Finite ι] (s : Set (∀ i, α i)) : s.IsPwo := by
  cases nonempty_fintype ι
  suffices ∀ (s : Finset ι) (f : ℕ → ∀ s, α s),
    ∃ g : ℕ ↪o ℕ, ∀ ⦃a b : ℕ⦄, a ≤ b → ∀ x, x ∈ s → (f ∘ g) a x ≤ (f ∘ g) b x by
    refine isPwo_iff_exists_monotone_subseq.2 fun f _ => ?_
    simpa only [Finset.mem_univ, true_imp_iff] using this Finset.univ f
  refine' Finset.cons_induction _ _
  · intro f
    

Proof state:
case intro.refine'_1
ι : Type u_1
α✝ : Type u_2
β : Type u_3
γ : Type u_4
π : ι → Type u_5
α : ι → Type u_6
inst✝² : (i : ι) → LinearOrder (α i)
inst✝¹ : ∀ (i : ι), IsWellOrder (α i) fun x x_1 => x < x_1
inst✝ : Finite ι
s : Set ((i : ι) → α i)
val✝ : Fintype ι
f : ℕ → (s : ι) → α s
⊢ ∃ g, ∀ ⦃a b : ℕ⦄, a ≤ b → ∀ x ∈ ∅, (f ∘ ⇑g) a x ≤ (f ∘ ⇑g) b x

Next tactic:
exists RelEmbedding.refl (· ≤ ·)
/-- A version of **Dickson's lemma** any subset of functions `Π s : σ, α s` is partially well
ordered, when `σ` is a `Fintype` and each `α s` is a linear well order.
This includes the classical case of Dickson's lemma that `ℕ ^ n` is a well partial order.
Some generalizations would be possible based on this proof, to include cases where the target is
partially well ordered, and also to consider the case of `Set.PartiallyWellOrderedOn` instead of
`Set.IsPwo`. -/
theorem Pi.isPwo {α : ι → Type*} [∀ i, LinearOrder (α i)] [∀ i, IsWellOrder (α i) (· < ·)]
    [Finite ι] (s : Set (∀ i, α i)) : s.IsPwo := by
  cases nonempty_fintype ι
  suffices ∀ (s : Finset ι) (f : ℕ → ∀ s, α s),
    ∃ g : ℕ ↪o ℕ, ∀ ⦃a b : ℕ⦄, a ≤ b → ∀ x, x ∈ s → (f ∘ g) a x ≤ (f ∘ g) b x by
    refine isPwo_iff_exists_monotone_subseq.2 fun f _ => ?_
    simpa only [Finset.mem_univ, true_imp_iff] using this Finset.univ f
  refine' Finset.cons_induction _ _
  · intro f
    exists RelEmbedding.refl (· ≤ ·)
    

Proof state:
case intro.refine'_1
ι : Type u_1
α✝ : Type u_2
β : Type u_3
γ : Type u_4
π : ι → Type u_5
α : ι → Type u_6
inst✝² : (i : ι) → LinearOrder (α i)
inst✝¹ : ∀ (i : ι), IsWellOrder (α i) fun x x_1 => x < x_1
inst✝ : Finite ι
s : Set ((i : ι) → α i)
val✝ : Fintype ι
f : ℕ → (s : ι) → α s
⊢ ∀ ⦃a b : ℕ⦄,
    a ≤ b →
      ∀ x ∈ ∅, (f ∘ ⇑(RelEmbedding.refl fun x x_1 => x ≤ x_1)) a x ≤ (f ∘ ⇑(RelEmbedding.refl fun x x_1 => x ≤ x_1)) b x

Next tactic:
simp only [IsEmpty.forall_iff, imp_true_iff, forall_const, Finset.not_mem_empty]
/-- A version of **Dickson's lemma** any subset of functions `Π s : σ, α s` is partially well
ordered, when `σ` is a `Fintype` and each `α s` is a linear well order.
This includes the classical case of Dickson's lemma that `ℕ ^ n` is a well partial order.
Some generalizations would be possible based on this proof, to include cases where the target is
partially well ordered, and also to consider the case of `Set.PartiallyWellOrderedOn` instead of
`Set.IsPwo`. -/
theorem Pi.isPwo {α : ι → Type*} [∀ i, LinearOrder (α i)] [∀ i, IsWellOrder (α i) (· < ·)]
    [Finite ι] (s : Set (∀ i, α i)) : s.IsPwo := by
  cases nonempty_fintype ι
  suffices ∀ (s : Finset ι) (f : ℕ → ∀ s, α s),
    ∃ g : ℕ ↪o ℕ, ∀ ⦃a b : ℕ⦄, a ≤ b → ∀ x, x ∈ s → (f ∘ g) a x ≤ (f ∘ g) b x by
    refine isPwo_iff_exists_monotone_subseq.2 fun f _ => ?_
    simpa only [Finset.mem_univ, true_imp_iff] using this Finset.univ f
  refine' Finset.cons_induction _ _
  · intro f
    exists RelEmbedding.refl (· ≤ ·)
    simp only [IsEmpty.forall_iff, imp_true_iff, forall_const, Finset.not_mem_empty]
  · 

Proof state:
case intro.refine'_2
ι : Type u_1
α✝ : Type u_2
β : Type u_3
γ : Type u_4
π : ι → Type u_5
α : ι → Type u_6
inst✝² : (i : ι) → LinearOrder (α i)
inst✝¹ : ∀ (i : ι), IsWellOrder (α i) fun x x_1 => x < x_1
inst✝ : Finite ι
s : Set ((i : ι) → α i)
val✝ : Fintype ι
⊢ ∀ ⦃a : ι⦄ {s : Finset ι} (h : a ∉ s),
    (∀ (f : ℕ → (s : ι) → α s), ∃ g, ∀ ⦃a b : ℕ⦄, a ≤ b → ∀ x ∈ s, (f ∘ ⇑g) a x ≤ (f ∘ ⇑g) b x) →
      ∀ (f : ℕ → (s : ι) → α s), ∃ g, ∀ ⦃a_2 b : ℕ⦄, a_2 ≤ b → ∀ x ∈ Finset.cons a s h, (f ∘ ⇑g) a_2 x ≤ (f ∘ ⇑g) b x

Next tactic:
intro x s hx ih f
/-- A version of **Dickson's lemma** any subset of functions `Π s : σ, α s` is partially well
ordered, when `σ` is a `Fintype` and each `α s` is a linear well order.
This includes the classical case of Dickson's lemma that `ℕ ^ n` is a well partial order.
Some generalizations would be possible based on this proof, to include cases where the target is
partially well ordered, and also to consider the case of `Set.PartiallyWellOrderedOn` instead of
`Set.IsPwo`. -/
theorem Pi.isPwo {α : ι → Type*} [∀ i, LinearOrder (α i)] [∀ i, IsWellOrder (α i) (· < ·)]
    [Finite ι] (s : Set (∀ i, α i)) : s.IsPwo := by
  cases nonempty_fintype ι
  suffices ∀ (s : Finset ι) (f : ℕ → ∀ s, α s),
    ∃ g : ℕ ↪o ℕ, ∀ ⦃a b : ℕ⦄, a ≤ b → ∀ x, x ∈ s → (f ∘ g) a x ≤ (f ∘ g) b x by
    refine isPwo_iff_exists_monotone_subseq.2 fun f _ => ?_
    simpa only [Finset.mem_univ, true_imp_iff] using this Finset.univ f
  refine' Finset.cons_induction _ _
  · intro f
    exists RelEmbedding.refl (· ≤ ·)
    simp only [IsEmpty.forall_iff, imp_true_iff, forall_const, Finset.not_mem_empty]
  · intro x s hx ih f
    

Proof state:
case intro.refine'_2
ι : Type u_1
α✝ : Type u_2
β : Type u_3
γ : Type u_4
π : ι → Type u_5
α : ι → Type u_6
inst✝² : (i : ι) → LinearOrder (α i)
inst✝¹ : ∀ (i : ι), IsWellOrder (α i) fun x x_1 => x < x_1
inst✝ : Finite ι
s✝ : Set ((i : ι) → α i)
val✝ : Fintype ι
x : ι
s : Finset ι
hx : x ∉ s
ih : ∀ (f : ℕ → (s : ι) → α s), ∃ g, ∀ ⦃a b : ℕ⦄, a ≤ b → ∀ x ∈ s, (f ∘ ⇑g) a x ≤ (f ∘ ⇑g) b x
f : ℕ → (s : ι) → α s
⊢ ∃ g, ∀ ⦃a b : ℕ⦄, a ≤ b → ∀ x_1 ∈ Finset.cons x s hx, (f ∘ ⇑g) a x_1 ≤ (f ∘ ⇑g) b x_1

Next tactic:
obtain ⟨g, hg⟩ :=
      (IsWellFounded.wf.isWf univ).isPwo.exists_monotone_subseq (fun n => f n x) mem_univ
/-- A version of **Dickson's lemma** any subset of functions `Π s : σ, α s` is partially well
ordered, when `σ` is a `Fintype` and each `α s` is a linear well order.
This includes the classical case of Dickson's lemma that `ℕ ^ n` is a well partial order.
Some generalizations would be possible based on this proof, to include cases where the target is
partially well ordered, and also to consider the case of `Set.PartiallyWellOrderedOn` instead of
`Set.IsPwo`. -/
theorem Pi.isPwo {α : ι → Type*} [∀ i, LinearOrder (α i)] [∀ i, IsWellOrder (α i) (· < ·)]
    [Finite ι] (s : Set (∀ i, α i)) : s.IsPwo := by
  cases nonempty_fintype ι
  suffices ∀ (s : Finset ι) (f : ℕ → ∀ s, α s),
    ∃ g : ℕ ↪o ℕ, ∀ ⦃a b : ℕ⦄, a ≤ b → ∀ x, x ∈ s → (f ∘ g) a x ≤ (f ∘ g) b x by
    refine isPwo_iff_exists_monotone_subseq.2 fun f _ => ?_
    simpa only [Finset.mem_univ, true_imp_iff] using this Finset.univ f
  refine' Finset.cons_induction _ _
  · intro f
    exists RelEmbedding.refl (· ≤ ·)
    simp only [IsEmpty.forall_iff, imp_true_iff, forall_const, Finset.not_mem_empty]
  · intro x s hx ih f
    obtain ⟨g, hg⟩ :=
      (IsWellFounded.wf.isWf univ).isPwo.exists_monotone_subseq (fun n => f n x) mem_univ
    

Proof state:
case intro.refine'_2.intro
ι : Type u_1
α✝ : Type u_2
β : Type u_3
γ : Type u_4
π : ι → Type u_5
α : ι → Type u_6
inst✝² : (i : ι) → LinearOrder (α i)
inst✝¹ : ∀ (i : ι), IsWellOrder (α i) fun x x_1 => x < x_1
inst✝ : Finite ι
s✝ : Set ((i : ι) → α i)
val✝ : Fintype ι
x : ι
s : Finset ι
hx : x ∉ s
ih : ∀ (f : ℕ → (s : ι) → α s), ∃ g, ∀ ⦃a b : ℕ⦄, a ≤ b → ∀ x ∈ s, (f ∘ ⇑g) a x ≤ (f ∘ ⇑g) b x
f : ℕ → (s : ι) → α s
g : ℕ ↪o ℕ
hg : Monotone ((fun n => f n x) ∘ ⇑g)
⊢ ∃ g, ∀ ⦃a b : ℕ⦄, a ≤ b → ∀ x_1 ∈ Finset.cons x s hx, (f ∘ ⇑g) a x_1 ≤ (f ∘ ⇑g) b x_1

Next tactic:
obtain ⟨g', hg'⟩ := ih (f ∘ g)
/-- A version of **Dickson's lemma** any subset of functions `Π s : σ, α s` is partially well
ordered, when `σ` is a `Fintype` and each `α s` is a linear well order.
This includes the classical case of Dickson's lemma that `ℕ ^ n` is a well partial order.
Some generalizations would be possible based on this proof, to include cases where the target is
partially well ordered, and also to consider the case of `Set.PartiallyWellOrderedOn` instead of
`Set.IsPwo`. -/
theorem Pi.isPwo {α : ι → Type*} [∀ i, LinearOrder (α i)] [∀ i, IsWellOrder (α i) (· < ·)]
    [Finite ι] (s : Set (∀ i, α i)) : s.IsPwo := by
  cases nonempty_fintype ι
  suffices ∀ (s : Finset ι) (f : ℕ → ∀ s, α s),
    ∃ g : ℕ ↪o ℕ, ∀ ⦃a b : ℕ⦄, a ≤ b → ∀ x, x ∈ s → (f ∘ g) a x ≤ (f ∘ g) b x by
    refine isPwo_iff_exists_monotone_subseq.2 fun f _ => ?_
    simpa only [Finset.mem_univ, true_imp_iff] using this Finset.univ f
  refine' Finset.cons_induction _ _
  · intro f
    exists RelEmbedding.refl (· ≤ ·)
    simp only [IsEmpty.forall_iff, imp_true_iff, forall_const, Finset.not_mem_empty]
  · intro x s hx ih f
    obtain ⟨g, hg⟩ :=
      (IsWellFounded.wf.isWf univ).isPwo.exists_monotone_subseq (fun n => f n x) mem_univ
    obtain ⟨g', hg'⟩ := ih (f ∘ g)
    

Proof state:
case intro.refine'_2.intro.intro
ι : Type u_1
α✝ : Type u_2
β : Type u_3
γ : Type u_4
π : ι → Type u_5
α : ι → Type u_6
inst✝² : (i : ι) → LinearOrder (α i)
inst✝¹ : ∀ (i : ι), IsWellOrder (α i) fun x x_1 => x < x_1
inst✝ : Finite ι
s✝ : Set ((i : ι) → α i)
val✝ : Fintype ι
x : ι
s : Finset ι
hx : x ∉ s
ih : ∀ (f : ℕ → (s : ι) → α s), ∃ g, ∀ ⦃a b : ℕ⦄, a ≤ b → ∀ x ∈ s, (f ∘ ⇑g) a x ≤ (f ∘ ⇑g) b x
f : ℕ → (s : ι) → α s
g : ℕ ↪o ℕ
hg : Monotone ((fun n => f n x) ∘ ⇑g)
g' : ℕ ↪o ℕ
hg' : ∀ ⦃a b : ℕ⦄, a ≤ b → ∀ x ∈ s, ((f ∘ ⇑g) ∘ ⇑g') a x ≤ ((f ∘ ⇑g) ∘ ⇑g') b x
⊢ ∃ g, ∀ ⦃a b : ℕ⦄, a ≤ b → ∀ x_1 ∈ Finset.cons x s hx, (f ∘ ⇑g) a x_1 ≤ (f ∘ ⇑g) b x_1

Next tactic:
refine' ⟨g'.trans g, fun a b hab => (Finset.forall_mem_cons _ _).2 _⟩
/-- A version of **Dickson's lemma** any subset of functions `Π s : σ, α s` is partially well
ordered, when `σ` is a `Fintype` and each `α s` is a linear well order.
This includes the classical case of Dickson's lemma that `ℕ ^ n` is a well partial order.
Some generalizations would be possible based on this proof, to include cases where the target is
partially well ordered, and also to consider the case of `Set.PartiallyWellOrderedOn` instead of
`Set.IsPwo`. -/
theorem Pi.isPwo {α : ι → Type*} [∀ i, LinearOrder (α i)] [∀ i, IsWellOrder (α i) (· < ·)]
    [Finite ι] (s : Set (∀ i, α i)) : s.IsPwo := by
  cases nonempty_fintype ι
  suffices ∀ (s : Finset ι) (f : ℕ → ∀ s, α s),
    ∃ g : ℕ ↪o ℕ, ∀ ⦃a b : ℕ⦄, a ≤ b → ∀ x, x ∈ s → (f ∘ g) a x ≤ (f ∘ g) b x by
    refine isPwo_iff_exists_monotone_subseq.2 fun f _ => ?_
    simpa only [Finset.mem_univ, true_imp_iff] using this Finset.univ f
  refine' Finset.cons_induction _ _
  · intro f
    exists RelEmbedding.refl (· ≤ ·)
    simp only [IsEmpty.forall_iff, imp_true_iff, forall_const, Finset.not_mem_empty]
  · intro x s hx ih f
    obtain ⟨g, hg⟩ :=
      (IsWellFounded.wf.isWf univ).isPwo.exists_monotone_subseq (fun n => f n x) mem_univ
    obtain ⟨g', hg'⟩ := ih (f ∘ g)
    refine' ⟨g'.trans g, fun a b hab => (Finset.forall_mem_cons _ _).2 _⟩
    

Proof state:
case intro.refine'_2.intro.intro
ι : Type u_1
α✝ : Type u_2
β : Type u_3
γ : Type u_4
π : ι → Type u_5
α : ι → Type u_6
inst✝² : (i : ι) → LinearOrder (α i)
inst✝¹ : ∀ (i : ι), IsWellOrder (α i) fun x x_1 => x < x_1
inst✝ : Finite ι
s✝ : Set ((i : ι) → α i)
val✝ : Fintype ι
x : ι
s : Finset ι
hx : x ∉ s
ih : ∀ (f : ℕ → (s : ι) → α s), ∃ g, ∀ ⦃a b : ℕ⦄, a ≤ b → ∀ x ∈ s, (f ∘ ⇑g) a x ≤ (f ∘ ⇑g) b x
f : ℕ → (s : ι) → α s
g : ℕ ↪o ℕ
hg : Monotone ((fun n => f n x) ∘ ⇑g)
g' : ℕ ↪o ℕ
hg' : ∀ ⦃a b : ℕ⦄, a ≤ b → ∀ x ∈ s, ((f ∘ ⇑g) ∘ ⇑g') a x ≤ ((f ∘ ⇑g) ∘ ⇑g') b x
a b : ℕ
hab : a ≤ b
⊢ (f ∘ ⇑(RelEmbedding.trans g' g)) a x ≤ (f ∘ ⇑(RelEmbedding.trans g' g)) b x ∧
    ∀ x ∈ s, (f ∘ ⇑(RelEmbedding.trans g' g)) a x ≤ (f ∘ ⇑(RelEmbedding.trans g' g)) b x

Next tactic:
exact ⟨hg (OrderHomClass.mono g' hab), hg' hab⟩
/-- Stronger version of `WellFounded.prod_lex`. Instead of requiring `rβ on g` to be well-founded,
we only require it to be well-founded on fibers of `f`.-/
theorem WellFounded.prod_lex_of_wellFoundedOn_fiber (hα : WellFounded (rα on f))
    (hβ : ∀ a, (f ⁻¹' {a}).WellFoundedOn (rβ on g)) :
    WellFounded (Prod.Lex rα rβ on fun c => (f c, g c)) := by
  

Proof state:
ι : Type u_1
α : Type u_2
β : Type u_3
γ : Type u_4
π : ι → Type u_5
rα : α → α → Prop
rβ : β → β → Prop
f : γ → α
g : γ → β
s : Set γ
hα : WellFounded (rα on f)
hβ : ∀ (a : α), WellFoundedOn (f ⁻¹' {a}) (rβ on g)
⊢ WellFounded (Prod.Lex rα rβ on fun c => (f c, g c))

Next tactic:
refine' (PSigma.lex_wf (wellFoundedOn_range.2 hα) fun a => hβ a).onFun.mono fun c c' h => _