doc-next-gen

Mathlib.Order.WellFoundedSet

Module docstring

{"# Well-founded sets

This file introduces versions of WellFounded and WellQuasiOrdered for sets.

Main Definitions

  • Set.WellFoundedOn s r indicates that the relation r is well-founded when restricted to the set s.
  • Set.IsWF s indicates that < is well-founded when restricted to s.
  • Set.PartiallyWellOrderedOn s r indicates that the relation r is partially well-ordered (also known as well quasi-ordered) when restricted to the set s.
  • Set.IsPWO s indicates that any infinite sequence of elements in s contains an infinite monotone subsequence. Note that this is equivalent to containing only two comparable elements.

Main Results

  • Higman's Lemma, Set.PartiallyWellOrderedOn.partiallyWellOrderedOn_sublistForall₂, shows that if r is partially well-ordered on s, then List.SublistForall₂ is partially well-ordered on the set of lists of elements of s. The result was originally published by Higman, but this proof more closely follows Nash-Williams.
  • Set.wellFoundedOn_iff relates well_founded_on to the well-foundedness of a relation on the original type, to avoid dealing with subtypes.
  • Set.IsWF.mono shows that a subset of a well-founded subset is well-founded.
  • Set.IsWF.union shows that the union of two well-founded subsets is well-founded.
  • Finset.isWF shows that all Finsets are well-founded.

TODO

  • Prove that s is partial well ordered iff it has no infinite descending chain or antichain.
  • Rename Set.PartiallyWellOrderedOn to Set.WellQuasiOrderedOn and Set.IsPWO to Set.IsWQO.

References

  • [Higman, Ordering by Divisibility in Abstract Algebras][Higman52]
  • [Nash-Williams, On Well-Quasi-Ordering Finite Trees][Nash-Williams63] ","### Relations well-founded on sets ","### Sets well-founded w.r.t. the strict inequality ","### Partially well-ordered sets "}
Set.WellFoundedOn definition
(s : Set α) (r : α → α → Prop) : Prop
Full source
/-- `s.WellFoundedOn r` indicates that the relation `r` is `WellFounded` when restricted to `s`. -/
def WellFoundedOn (s : Set α) (r : α → α → Prop) : Prop :=
  WellFounded (Subrel r (· ∈ s))
Well-founded relation on a set
Informal description
Given a set $s$ in a type $\alpha$ and a binary relation $r$ on $\alpha$, the relation $r$ is said to be *well-founded on $s$* if the restriction of $r$ to elements of $s$ is well-founded. That is, there are no infinite descending chains $a_1 \succ_r a_2 \succ_r \cdots$ with all $a_i \in s$.
Set.wellFoundedOn_empty theorem
(r : α → α → Prop) : WellFoundedOn ∅ r
Full source
@[simp]
theorem wellFoundedOn_empty (r : α → α → Prop) : WellFoundedOn  r :=
  wellFounded_of_isEmpty _
Well-foundedness on the Empty Set
Informal description
For any binary relation $r$ on a type $\alpha$, the relation $r$ is well-founded on the empty set $\emptyset \subseteq \alpha$.
Set.wellFoundedOn_iff theorem
: s.WellFoundedOn r ↔ WellFounded fun a b : α => r a b ∧ a ∈ s ∧ b ∈ s
Full source
theorem wellFoundedOn_iff :
    s.WellFoundedOn r ↔ WellFounded fun a b : α => r a b ∧ a ∈ s ∧ b ∈ s := by
  have f : RelEmbedding (Subrel r (· ∈ s)) fun a b : α => r a b ∧ a ∈ s ∧ b ∈ s :=
    ⟨⟨(↑), Subtype.coe_injective⟩, by simp⟩
  refine ⟨fun h => ?_, f.wellFounded⟩
  rw [WellFounded.wellFounded_iff_has_min]
  intro t ht
  by_cases hst : (s ∩ t).Nonempty
  · rw [← Subtype.preimage_coe_nonempty] at hst
    rcases h.has_min (Subtype.valSubtype.val ⁻¹' t) hst with ⟨⟨m, ms⟩, mt, hm⟩
    exact ⟨m, mt, fun x xt ⟨xm, xs, _⟩ => hm ⟨x, xs⟩ xt xm⟩
  · rcases ht with ⟨m, mt⟩
    exact ⟨m, mt, fun x _ ⟨_, _, ms⟩ => hst ⟨m, ⟨ms, mt⟩⟩⟩
Characterization of Well-Foundedness on a Set via Restricted Relation
Informal description
A relation $r$ is well-founded on a set $s \subseteq \alpha$ if and only if the relation $\{(a, b) \in \alpha \times \alpha \mid r(a, b) \text{ and } a, b \in s\}$ is well-founded on $\alpha$.
Set.wellFoundedOn_univ theorem
: (univ : Set α).WellFoundedOn r ↔ WellFounded r
Full source
@[simp]
theorem wellFoundedOn_univ : (univ : Set α).WellFoundedOn r ↔ WellFounded r := by
  simp [wellFoundedOn_iff]
Well-foundedness on Universal Set Equivalence
Informal description
A relation $r$ on a type $\alpha$ is well-founded on the universal set $\mathrm{univ} \subseteq \alpha$ if and only if $r$ is well-founded on the entire type $\alpha$.
WellFounded.wellFoundedOn theorem
: WellFounded r → s.WellFoundedOn r
Full source
theorem _root_.WellFounded.wellFoundedOn : WellFounded r → s.WellFoundedOn r :=
  InvImage.wf _
Well-foundedness is preserved under restriction to subsets
Informal description
If a binary relation $r$ on a type $\alpha$ is well-founded, then its restriction to any subset $s \subseteq \alpha$ is also well-founded.
Set.wellFoundedOn_range theorem
: (range f).WellFoundedOn r ↔ WellFounded (r on f)
Full source
@[simp]
theorem wellFoundedOn_range : (range f).WellFoundedOn r ↔ WellFounded (r on f) := by
  let f' : β → range f := fun c => ⟨f c, c, rfl⟩
  refine ⟨fun h => (InvImage.wf f' h).mono fun c c' => id, fun h => ⟨?_⟩⟩
  rintro ⟨_, c, rfl⟩
  refine Acc.of_downward_closed f' ?_ _ ?_
  · rintro _ ⟨_, c', rfl⟩ -
    exact ⟨c', rfl⟩
  · exact h.apply _
Well-foundedness of Relation on Range vs. Composed Relation
Informal description
For any function $f \colon \beta \to \alpha$ and relation $r$ on $\alpha$, the relation $r$ is well-founded on the range of $f$ if and only if the relation $r$ composed with $f$ (i.e., the relation defined by $(r \text{ on } f)(x, y) = r(f(x), f(y))$) is well-founded on $\beta$.
Set.wellFoundedOn_image theorem
{s : Set β} : (f '' s).WellFoundedOn r ↔ s.WellFoundedOn (r on f)
Full source
@[simp]
theorem wellFoundedOn_image {s : Set β} : (f '' s).WellFoundedOn r ↔ s.WellFoundedOn (r on f) := by
  rw [image_eq_range]; exact wellFoundedOn_range
Well-foundedness of Relation on Image vs. Composed Relation on Preimage
Informal description
For any set $s \subseteq \beta$ and function $f \colon \beta \to \alpha$, the relation $r$ is well-founded on the image $f(s)$ if and only if the relation $r$ composed with $f$ (i.e., $(r \text{ on } f)(x, y) = r(f(x), f(y))$) is well-founded on $s$.
Set.WellFoundedOn.induction theorem
(hs : s.WellFoundedOn r) (hx : x ∈ s) {P : α → Prop} (hP : ∀ y ∈ s, (∀ z ∈ s, r z y → P z) → P y) : P x
Full source
protected theorem induction (hs : s.WellFoundedOn r) (hx : x ∈ s) {P : α → Prop}
    (hP : ∀ y ∈ s, (∀ z ∈ s, r z y → P z) → P y) : P x := by
  let Q : s → Prop := fun y => P y
  change Q ⟨x, hx⟩
  refine WellFounded.induction hs ⟨x, hx⟩ ?_
  simpa only [Subtype.forall]
Induction Principle for Well-Founded Relations on Sets
Informal description
Let $s$ be a subset of a type $\alpha$ and $r$ a binary relation on $\alpha$. If $r$ is well-founded on $s$ and $x \in s$, then for any predicate $P$ on $\alpha$, if for every $y \in s$ the implication $(\forall z \in s, r(z,y) \to P(z)) \to P(y)$ holds, then $P(x)$ holds.
Set.WellFoundedOn.mono theorem
(h : t.WellFoundedOn r') (hle : r ≤ r') (hst : s ⊆ t) : s.WellFoundedOn r
Full source
protected theorem mono (h : t.WellFoundedOn r') (hle : r ≤ r') (hst : s ⊆ t) :
    s.WellFoundedOn r := by
  rw [wellFoundedOn_iff] at *
  exact Subrelation.wf (fun xy => ⟨hle _ _ xy.1, hst xy.2.1, hst xy.2.2⟩) h
Monotonicity of Well-Foundedness under Weaker Relations and Subsets
Informal description
Let $s$ and $t$ be sets in a type $\alpha$, and let $r$ and $r'$ be binary relations on $\alpha$. If $r'$ is well-founded on $t$, $r$ is pointwise weaker than $r'$ (i.e., $r \leq r'$), and $s$ is a subset of $t$, then $r$ is well-founded on $s$.
Set.WellFoundedOn.mono' theorem
(h : ∀ (a) (_ : a ∈ s) (b) (_ : b ∈ s), r' a b → r a b) : s.WellFoundedOn r → s.WellFoundedOn r'
Full source
theorem mono' (h : ∀ (a) (_ : a ∈ s) (b) (_ : b ∈ s), r' a b → r a b) :
    s.WellFoundedOn r → s.WellFoundedOn r' :=
  Subrelation.wf @fun a b => h _ a.2 _ b.2
Monotonicity of Well-Foundedness under Relation Strengthening
Informal description
Let $s$ be a set in a type $\alpha$, and let $r$ and $r'$ be binary relations on $\alpha$. If for all $a, b \in s$, $r' a b$ implies $r a b$, and $r$ is well-founded on $s$, then $r'$ is also well-founded on $s$.
Set.WellFoundedOn.subset theorem
(h : t.WellFoundedOn r) (hst : s ⊆ t) : s.WellFoundedOn r
Full source
theorem subset (h : t.WellFoundedOn r) (hst : s ⊆ t) : s.WellFoundedOn r :=
  h.mono le_rfl hst
Well-foundedness is preserved under subset inclusion
Informal description
Let $s$ and $t$ be sets in a type $\alpha$, and let $r$ be a binary relation on $\alpha$. If $r$ is well-founded on $t$ and $s$ is a subset of $t$, then $r$ is well-founded on $s$.
Set.WellFoundedOn.acc_iff_wellFoundedOn theorem
{α} {r : α → α → Prop} {a : α} : TFAE [Acc r a, WellFoundedOn {b | ReflTransGen r b a} r, WellFoundedOn {b | TransGen r b a} r]
Full source
/-- `a` is accessible under the relation `r` iff `r` is well-founded on the downward transitive
closure of `a` under `r` (including `a` or not). -/
theorem acc_iff_wellFoundedOn {α} {r : α → α → Prop} {a : α} :
    TFAE [Acc r a,
      WellFoundedOn { b | ReflTransGen r b a } r,
      WellFoundedOn { b | TransGen r b a } r] := by
  tfae_have 1 → 2 := by
    refine fun h => ⟨fun b => InvImage.accessible Subtype.val ?_⟩
    rw [← acc_transGen_iff] at h ⊢
    obtain h' | h' := reflTransGen_iff_eq_or_transGen.1 b.2
    · rwa [h'] at h
    · exact h.inv h'
  tfae_have 2 → 3 := fun h => h.subset fun _ => TransGen.to_reflTransGen
  tfae_have 3 → 1 := by
    refine fun h => Acc.intro _ (fun b hb => (h.apply ⟨b, .single hb⟩).of_fibration Subtype.val ?_)
    exact fun ⟨c, hc⟩ d h => ⟨⟨d, .head h hc⟩, h, rfl⟩
  tfae_finish
Equivalence of Accessibility and Well-Foundedness on Reachable Sets
Informal description
For any relation $r$ on a type $\alpha$ and any element $a \in \alpha$, the following statements are equivalent: 1. The element $a$ is accessible under the relation $r$. 2. The relation $r$ is well-founded on the set $\{b \mid \text{ReflTransGen}\, r\, b\, a\}$ of elements that can reach $a$ via the reflexive transitive closure of $r$. 3. The relation $r$ is well-founded on the set $\{b \mid \text{TransGen}\, r\, b\, a\}$ of elements that can reach $a$ via the transitive closure of $r$.
Set.IsStrictOrder.subset instance
: IsStrictOrder α fun a b : α => r a b ∧ a ∈ s ∧ b ∈ s
Full source
instance IsStrictOrder.subset : IsStrictOrder α fun a b : α => r a b ∧ a ∈ s ∧ b ∈ s where
  toIsIrrefl := ⟨fun a con => irrefl_of r a con.1⟩
  toIsTrans := ⟨fun _ _ _ ab bc => ⟨trans_of r ab.1 bc.1, ab.2.1, bc.2.2⟩⟩
Strict Order Restriction to Subsets
Informal description
For any relation $r$ on a type $\alpha$ and any subset $s \subseteq \alpha$, the restriction of $r$ to $s$ (defined by $r(a, b) \land a \in s \land b \in s$) is a strict order if $r$ is a strict order on $\alpha$.
Set.wellFoundedOn_iff_no_descending_seq theorem
: s.WellFoundedOn r ↔ ∀ f : ((· > ·) : ℕ → ℕ → Prop) ↪r r, ¬∀ n, f n ∈ s
Full source
theorem wellFoundedOn_iff_no_descending_seq :
    s.WellFoundedOn r ↔ ∀ f : ((· > ·) : ℕ → ℕ → Prop) ↪r r, ¬∀ n, f n ∈ s := by
  simp only [wellFoundedOn_iff, RelEmbedding.wellFounded_iff_no_descending_seq, ← not_exists, ←
    not_nonempty_iff, not_iff_not]
  constructor
  · rintro ⟨⟨f, hf⟩⟩
    have H : ∀ n, f n ∈ s := fun n => (hf.2 n.lt_succ_self).2.2
    refine ⟨⟨f, ?_⟩, H⟩
    simpa only [H, and_true] using @hf
  · rintro ⟨⟨f, hf⟩, hfs : ∀ n, f n ∈ s⟩
    refine ⟨⟨f, ?_⟩⟩
    simpa only [hfs, and_true] using @hf
Characterization of Well-Founded Relations on Sets via Descending Sequences
Informal description
A relation $r$ is well-founded on a set $s$ if and only if there does not exist a function $f : \mathbb{N} \to \alpha$ that is a relation embedding from the strict greater-than relation on $\mathbb{N}$ to $r$ (i.e., $f$ preserves the order relations) and satisfies $f(n) \in s$ for all $n \in \mathbb{N}$. In other words, there are no infinite descending sequences in $s$ with respect to $r$.
Set.WellFoundedOn.union theorem
(hs : s.WellFoundedOn r) (ht : t.WellFoundedOn r) : (s ∪ t).WellFoundedOn r
Full source
theorem WellFoundedOn.union (hs : s.WellFoundedOn r) (ht : t.WellFoundedOn r) :
    (s ∪ t).WellFoundedOn r := by
  rw [wellFoundedOn_iff_no_descending_seq] at *
  rintro f hf
  rcases Nat.exists_subseq_of_forall_mem_union f hf with ⟨g, hg | hg⟩
  exacts [hs (g.dual.ltEmbedding.trans f) hg, ht (g.dual.ltEmbedding.trans f) hg]
Union of Well-Founded Sets is Well-Founded
Informal description
Let $r$ be a binary relation on a type $\alpha$. If $r$ is well-founded on sets $s$ and $t$ (i.e., there are no infinite descending chains in $s$ or $t$ with respect to $r$), then $r$ is also well-founded on their union $s \cup t$.
Set.wellFoundedOn_union theorem
: (s ∪ t).WellFoundedOn r ↔ s.WellFoundedOn r ∧ t.WellFoundedOn r
Full source
@[simp]
theorem wellFoundedOn_union : (s ∪ t).WellFoundedOn r ↔ s.WellFoundedOn r ∧ t.WellFoundedOn r :=
  ⟨fun h => ⟨h.subset subset_union_left, h.subset subset_union_right⟩, fun h =>
    h.1.union h.2⟩
Well-foundedness of Union Set Equivalence: $(s \cup t).\text{WellFoundedOn}\ r \leftrightarrow s.\text{WellFoundedOn}\ r \land t.\text{WellFoundedOn}\ r$
Informal description
For any sets $s$ and $t$ in a type $\alpha$ and any binary relation $r$ on $\alpha$, the relation $r$ is well-founded on the union $s \cup t$ if and only if $r$ is well-founded on both $s$ and $t$ individually.
Set.IsWF definition
(s : Set α) : Prop
Full source
/-- `s.IsWF` indicates that `<` is well-founded when restricted to `s`. -/
def IsWF (s : Set α) : Prop :=
  WellFoundedOn s (· < ·)
Well-founded set with respect to strict inequality
Informal description
A set $s$ in a type $\alpha$ is called *well-founded* if the strict inequality relation $<$ is well-founded when restricted to $s$. That is, there are no infinite descending chains $a_1 > a_2 > \cdots$ with all $a_i \in s$.
Set.isWF_empty theorem
: IsWF (∅ : Set α)
Full source
@[simp]
theorem isWF_empty : IsWF ( : Set α) :=
  wellFounded_of_isEmpty _
Well-foundedness of the Empty Set
Informal description
The empty set $\emptyset$ in a type $\alpha$ is well-founded with respect to the strict inequality relation $<$.
Set.IsWF.mono theorem
(h : IsWF t) (st : s ⊆ t) : IsWF s
Full source
theorem IsWF.mono (h : IsWF t) (st : s ⊆ t) : IsWF s := h.subset st
Subset of Well-Founded Set is Well-Founded
Informal description
Let $s$ and $t$ be sets in a type $\alpha$. If $t$ is well-founded with respect to the strict inequality relation $<$ and $s$ is a subset of $t$, then $s$ is also well-founded with respect to $<$.
Set.isWF_univ_iff theorem
: IsWF (univ : Set α) ↔ WellFoundedLT α
Full source
theorem isWF_univ_iff : IsWFIsWF (univ : Set α) ↔ WellFoundedLT α := by
  simp [IsWF, wellFoundedOn_iff, isWellFounded_iff]
Universal Set Well-Foundedness Equivalence: $\text{IsWF}(\text{univ}) \leftrightarrow \text{WellFoundedLT}(\alpha)$
Informal description
The universal set $\text{univ}$ in a type $\alpha$ is well-founded with respect to the strict inequality relation $<$ if and only if the relation $<$ is well-founded on the entire type $\alpha$.
Set.IsWF.of_wellFoundedLT theorem
[h : WellFoundedLT α] (s : Set α) : s.IsWF
Full source
theorem IsWF.of_wellFoundedLT [h : WellFoundedLT α] (s : Set α) : s.IsWF :=
  (Set.isWF_univ_iff.2 h).mono s.subset_univ
Well-foundedness of Subsets under Well-founded Strict Order
Informal description
Let $\alpha$ be a type with a well-founded strict less-than relation $<$. Then any subset $s$ of $\alpha$ is well-founded with respect to $<$.
WellFounded.isWF theorem
(h : WellFounded ((· < ·) : α → α → Prop)) (s : Set α) : s.IsWF
Full source
@[deprecated IsWF.of_wellFoundedLT (since := "2025-01-16")]
theorem _root_.WellFounded.isWF (h : WellFounded ((· < ·) : α → α → Prop)) (s : Set α) : s.IsWF :=
  have : WellFoundedLT α := ⟨h⟩
  .of_wellFoundedLT s
Well-foundedness of Subsets under Well-founded Strict Order
Informal description
Let $\alpha$ be a type with a strict order $<$. If the relation $<$ is well-founded on $\alpha$, then for any subset $s \subseteq \alpha$, the restriction of $<$ to $s$ is also well-founded.
Set.IsWF.union theorem
(hs : IsWF s) (ht : IsWF t) : IsWF (s ∪ t)
Full source
protected nonrec theorem IsWF.union (hs : IsWF s) (ht : IsWF t) : IsWF (s ∪ t) := hs.union ht
Union of Well-Founded Sets is Well-Founded with Respect to Strict Inequality
Informal description
If $s$ and $t$ are well-founded subsets of a type $\alpha$ with respect to the strict inequality relation $<$, then their union $s \cup t$ is also well-founded.
Set.isWF_union theorem
: IsWF (s ∪ t) ↔ IsWF s ∧ IsWF t
Full source
@[simp] theorem isWF_union : IsWFIsWF (s ∪ t) ↔ IsWF s ∧ IsWF t := wellFoundedOn_union
Union of Well-Founded Sets is Well-Founded if and only if Each Set is Well-Founded
Informal description
For any sets $s$ and $t$ in a type $\alpha$ with a strict order $<$, the union $s \cup t$ is well-founded with respect to $<$ if and only if both $s$ and $t$ are individually well-founded with respect to $<$.
Set.isWF_iff_no_descending_seq theorem
: IsWF s ↔ ∀ f : ℕ → α, StrictAnti f → ¬∀ n, f (OrderDual.toDual n) ∈ s
Full source
theorem isWF_iff_no_descending_seq :
    IsWFIsWF s ↔ ∀ f : ℕ → α, StrictAnti f → ¬∀ n, f (OrderDual.toDual n) ∈ s :=
  wellFoundedOn_iff_no_descending_seq.trans
    ⟨fun H f hf => H ⟨⟨f, hf.injective⟩, hf.lt_iff_lt⟩, fun H f => H f fun _ _ => f.map_rel_iff.2⟩
Characterization of Well-Founded Sets via Absence of Infinite Descending Sequences
Informal description
A set $s$ in a type $\alpha$ is well-founded with respect to the strict inequality relation $<$ if and only if there does not exist any strictly decreasing sequence $f : \mathbb{N} \to \alpha$ (i.e., $f(n+1) < f(n)$ for all $n$) such that $f(n) \in s$ for all $n \in \mathbb{N}$.
Set.PartiallyWellOrderedOn definition
(s : Set α) (r : α → α → Prop) : Prop
Full source
/-- `s.PartiallyWellOrderedOn r` indicates that the relation `r` is `WellQuasiOrdered` when
restricted to `s`.

A set is partially well-ordered by a relation `r` when any infinite sequence contains two elements
where the first is related to the second by `r`. Equivalently, any antichain (see `IsAntichain`) is
finite, see `Set.partiallyWellOrderedOn_iff_finite_antichains`.

TODO: rename this to `WellQuasiOrderedOn` to match `WellQuasiOrdered`. -/
def PartiallyWellOrderedOn (s : Set α) (r : α → α → Prop) : Prop :=
  WellQuasiOrdered (Subrel r (· ∈ s))
Partial well-ordering of a set with respect to a relation
Informal description
A set $s$ in a type $\alpha$ is said to be *partially well-ordered* with respect to a relation $r$ if the restriction of $r$ to $s$ is a well quasi-order. This means that for any infinite sequence of elements in $s$, there exist two indices $m < n$ such that $r(f_m, f_n)$ holds. Equivalently, any antichain in $s$ with respect to $r$ is finite.
Set.PartiallyWellOrderedOn.exists_lt theorem
(hs : s.PartiallyWellOrderedOn r) {f : ℕ → α} (hf : ∀ n, f n ∈ s) : ∃ m n, m < n ∧ r (f m) (f n)
Full source
theorem PartiallyWellOrderedOn.exists_lt (hs : s.PartiallyWellOrderedOn r) {f :  → α}
    (hf : ∀ n, f n ∈ s) : ∃ m n, m < n ∧ r (f m) (f n) :=
  hs fun n ↦ ⟨_, hf n⟩
Existence of Comparable Elements in Infinite Sequences of Partially Well-Ordered Sets
Informal description
For any set $s$ in a type $\alpha$ that is partially well-ordered with respect to a relation $r$, and for any sequence $f : \mathbb{N} \to \alpha$ such that $f(n) \in s$ for all $n \in \mathbb{N}$, there exist indices $m, n \in \mathbb{N}$ with $m < n$ such that $r(f(m), f(n))$ holds.
Set.partiallyWellOrderedOn_iff_exists_lt theorem
: s.PartiallyWellOrderedOn r ↔ ∀ f : ℕ → α, (∀ n, f n ∈ s) → ∃ m n, m < n ∧ r (f m) (f n)
Full source
theorem partiallyWellOrderedOn_iff_exists_lt : s.PartiallyWellOrderedOn r ↔
    ∀ f : ℕ → α, (∀ n, f n ∈ s) → ∃ m n, m < n ∧ r (f m) (f n) :=
  ⟨PartiallyWellOrderedOn.exists_lt, fun hf f ↦ hf _ fun n ↦ (f n).2⟩
Characterization of Partial Well-Ordering via Comparable Elements in Sequences
Informal description
A set $s$ in a type $\alpha$ is partially well-ordered with respect to a relation $r$ if and only if for every sequence $f \colon \mathbb{N} \to \alpha$ such that $f(n) \in s$ for all $n \in \mathbb{N}$, there exist indices $m, n \in \mathbb{N}$ with $m < n$ such that $r(f(m), f(n))$ holds.
Set.PartiallyWellOrderedOn.mono theorem
(ht : t.PartiallyWellOrderedOn r) (h : s ⊆ t) : s.PartiallyWellOrderedOn r
Full source
theorem PartiallyWellOrderedOn.mono (ht : t.PartiallyWellOrderedOn r) (h : s ⊆ t) :
    s.PartiallyWellOrderedOn r :=
  fun f ↦ ht (Set.inclusionSet.inclusion h ∘ f)
Subset of a Partially Well-Ordered Set is Partially Well-Ordered
Informal description
If a set $t$ is partially well-ordered with respect to a relation $r$, then any subset $s \subseteq t$ is also partially well-ordered with respect to $r$.
Set.partiallyWellOrderedOn_empty theorem
(r : α → α → Prop) : PartiallyWellOrderedOn ∅ r
Full source
@[simp]
theorem partiallyWellOrderedOn_empty (r : α → α → Prop) : PartiallyWellOrderedOn  r :=
  wellQuasiOrdered_of_isEmpty _
Empty Set is Partially Well-Ordered Under Any Relation
Informal description
The empty set $\emptyset$ is partially well-ordered with respect to any relation $r$ on a type $\alpha$.
Set.PartiallyWellOrderedOn.union theorem
(hs : s.PartiallyWellOrderedOn r) (ht : t.PartiallyWellOrderedOn r) : (s ∪ t).PartiallyWellOrderedOn r
Full source
theorem PartiallyWellOrderedOn.union (hs : s.PartiallyWellOrderedOn r)
    (ht : t.PartiallyWellOrderedOn r) : (s ∪ t).PartiallyWellOrderedOn r := by
  intro f
  obtain ⟨g, hgs | hgt⟩ := Nat.exists_subseq_of_forall_mem_union _ fun x ↦ (f x).2
  · rcases hs.exists_lt hgs with ⟨m, n, hlt, hr⟩
    exact ⟨g m, g n, g.strictMono hlt, hr⟩
  · rcases ht.exists_lt hgt with ⟨m, n, hlt, hr⟩
    exact ⟨g m, g n, g.strictMono hlt, hr⟩
Union of Partially Well-Ordered Sets is Partially Well-Ordered
Informal description
Let $s$ and $t$ be subsets of a type $\alpha$ that are partially well-ordered with respect to a relation $r$. Then their union $s \cup t$ is also partially well-ordered with respect to $r$.
Set.partiallyWellOrderedOn_union theorem
: (s ∪ t).PartiallyWellOrderedOn r ↔ s.PartiallyWellOrderedOn r ∧ t.PartiallyWellOrderedOn r
Full source
@[simp]
theorem partiallyWellOrderedOn_union :
    (s ∪ t).PartiallyWellOrderedOn r ↔ s.PartiallyWellOrderedOn r ∧ t.PartiallyWellOrderedOn r :=
  ⟨fun h ↦ ⟨h.mono subset_union_left, h.mono subset_union_right⟩, fun h ↦ h.1.union h.2⟩
Union of Sets is Partially Well-Ordered if and only if Both Sets Are Partially Well-Ordered
Informal description
For any sets $s$ and $t$ in a type $\alpha$ and any relation $r$ on $\alpha$, the union $s \cup t$ is partially well-ordered with respect to $r$ if and only if both $s$ and $t$ are partially well-ordered with respect to $r$.
Set.PartiallyWellOrderedOn.image_of_monotone_on theorem
(hs : s.PartiallyWellOrderedOn r) (hf : ∀ a₁ ∈ s, ∀ a₂ ∈ s, r a₁ a₂ → r' (f a₁) (f a₂)) : (f '' s).PartiallyWellOrderedOn r'
Full source
theorem PartiallyWellOrderedOn.image_of_monotone_on (hs : s.PartiallyWellOrderedOn r)
    (hf : ∀ a₁ ∈ s, ∀ a₂ ∈ s, r a₁ a₂ → r' (f a₁) (f a₂)) : (f '' s).PartiallyWellOrderedOn r' := by
  rw [partiallyWellOrderedOn_iff_exists_lt] at *
  intro g' hg'
  choose g hgs heq using hg'
  obtain rfl : f ∘ g = g' := funext heq
  obtain ⟨m, n, hlt, hmn⟩ := hs g hgs
  exact ⟨m, n, hlt, hf _ (hgs m) _ (hgs n) hmn⟩
Image of a Partially Well-Ordered Set under a Monotone Function is Partially Well-Ordered
Informal description
Let $s$ be a subset of a type $\alpha$ that is partially well-ordered with respect to a relation $r$, and let $f : \alpha \to \beta$ be a function. If $f$ is monotone on $s$ with respect to $r$ and $r'$ (i.e., for any $a_1, a_2 \in s$, $r(a_1, a_2)$ implies $r'(f(a_1), f(a_2))$), then the image $f(s)$ is partially well-ordered with respect to $r'$.
IsAntichain.finite_of_partiallyWellOrderedOn theorem
(ha : IsAntichain r s) (hp : s.PartiallyWellOrderedOn r) : s.Finite
Full source
theorem _root_.IsAntichain.finite_of_partiallyWellOrderedOn (ha : IsAntichain r s)
    (hp : s.PartiallyWellOrderedOn r) : s.Finite := by
  refine not_infinite.1 fun hi => ?_
  obtain ⟨m, n, hmn, h⟩ := hp (hi.natEmbedding _)
  exact hmn.ne ((hi.natEmbedding _).injective <| Subtype.val_injective <|
    ha.eq (hi.natEmbedding _ m).2 (hi.natEmbedding _ n).2 h)
Finite Antichain in Partially Well-Ordered Set
Informal description
Let $s$ be a set in a type $\alpha$ and $r$ a relation on $\alpha$. If $s$ is an antichain with respect to $r$ (i.e., no two distinct elements in $s$ are related by $r$) and $s$ is partially well-ordered with respect to $r$, then $s$ is finite.
Set.Finite.partiallyWellOrderedOn theorem
(hs : s.Finite) : s.PartiallyWellOrderedOn r
Full source
protected theorem Finite.partiallyWellOrderedOn (hs : s.Finite) : s.PartiallyWellOrderedOn r :=
  hs.to_subtype.wellQuasiOrdered _
Finite Sets are Partially Well-Ordered
Informal description
For any finite set $s$ in a type $\alpha$ and any relation $r$ on $\alpha$, the set $s$ is partially well-ordered with respect to $r$.
IsAntichain.partiallyWellOrderedOn_iff theorem
(hs : IsAntichain r s) : s.PartiallyWellOrderedOn r ↔ s.Finite
Full source
theorem _root_.IsAntichain.partiallyWellOrderedOn_iff (hs : IsAntichain r s) :
    s.PartiallyWellOrderedOn r ↔ s.Finite :=
  ⟨hs.finite_of_partiallyWellOrderedOn, Finite.partiallyWellOrderedOn⟩
Finite Antichain Characterization for Partial Well-Ordering
Informal description
For a set $s$ in a type $\alpha$ that forms an antichain with respect to a relation $r$ (i.e., no two distinct elements in $s$ are related by $r$), the set $s$ is partially well-ordered with respect to $r$ if and only if $s$ is finite.
Set.Subsingleton.partiallyWellOrderedOn theorem
(hs : s.Subsingleton) : PartiallyWellOrderedOn s r
Full source
@[nontriviality]
theorem Subsingleton.partiallyWellOrderedOn (hs : s.Subsingleton) : PartiallyWellOrderedOn s r :=
  hs.finite.partiallyWellOrderedOn
Subsingleton Sets are Partially Well-Ordered
Informal description
For any set $s$ in a type $\alpha$, if $s$ is a subsingleton (i.e., contains at most one element), then $s$ is partially well-ordered with respect to any relation $r$ on $\alpha$.
Set.partiallyWellOrderedOn_insert theorem
: PartiallyWellOrderedOn (insert a s) r ↔ PartiallyWellOrderedOn s r
Full source
@[simp]
theorem partiallyWellOrderedOn_insert :
    PartiallyWellOrderedOnPartiallyWellOrderedOn (insert a s) r ↔ PartiallyWellOrderedOn s r := by
  simp only [← singleton_union, partiallyWellOrderedOn_union,
    partiallyWellOrderedOn_singleton, true_and]
Partial Well-Ordering of Set Insertion: $s \cup \{a\}$ is partially well-ordered iff $s$ is partially well-ordered.
Informal description
For any set $s$ in a type $\alpha$ and any element $a \in \alpha$, the set $s \cup \{a\}$ is partially well-ordered with respect to a relation $r$ if and only if $s$ itself is partially well-ordered with respect to $r$.
Set.PartiallyWellOrderedOn.insert theorem
(h : PartiallyWellOrderedOn s r) (a : α) : PartiallyWellOrderedOn (insert a s) r
Full source
protected theorem PartiallyWellOrderedOn.insert (h : PartiallyWellOrderedOn s r) (a : α) :
    PartiallyWellOrderedOn (insert a s) r :=
  partiallyWellOrderedOn_insert.2 h
Partial Well-Ordering is Preserved by Insertion
Informal description
If a set $s$ in a type $\alpha$ is partially well-ordered with respect to a relation $r$, then for any element $a \in \alpha$, the set $s \cup \{a\}$ is also partially well-ordered with respect to $r$.
Set.partiallyWellOrderedOn_iff_finite_antichains theorem
[IsSymm α r] : s.PartiallyWellOrderedOn r ↔ ∀ t, t ⊆ s → IsAntichain r t → t.Finite
Full source
theorem partiallyWellOrderedOn_iff_finite_antichains [IsSymm α r] :
    s.PartiallyWellOrderedOn r ↔ ∀ t, t ⊆ s → IsAntichain r t → t.Finite := by
  refine ⟨fun h t ht hrt => hrt.finite_of_partiallyWellOrderedOn (h.mono ht), ?_⟩
  rw [partiallyWellOrderedOn_iff_exists_lt]
  intro hs f hf
  by_contra! H
  refine infinite_range_of_injective (fun m n hmn => ?_) (hs _ (range_subset_iff.2 hf) ?_)
  · obtain h | h | h := lt_trichotomy m n
    · refine (H _ _ h ?_).elim
      rw [hmn]
      exact refl _
    · exact h
    · refine (H _ _ h ?_).elim
      rw [hmn]
      exact refl _
  rintro _ ⟨m, hm, rfl⟩ _ ⟨n, hn, rfl⟩ hmn
  obtain h | h := (ne_of_apply_ne _ hmn).lt_or_lt
  · exact H _ _ h
  · exact mt symm (H _ _ h)
Characterization of Partial Well-Ordering via Finite Antichains
Informal description
For any symmetric relation $r$ on a type $\alpha$, a set $s \subseteq \alpha$ is partially well-ordered with respect to $r$ if and only if every antichain $t \subseteq s$ (with respect to $r$) is finite.
Set.PartiallyWellOrderedOn.exists_monotone_subseq theorem
(h : s.PartiallyWellOrderedOn r) {f : ℕ → α} (hf : ∀ n, f n ∈ s) : ∃ g : ℕ ↪o ℕ, ∀ m n : ℕ, m ≤ n → r (f (g m)) (f (g n))
Full source
theorem PartiallyWellOrderedOn.exists_monotone_subseq (h : s.PartiallyWellOrderedOn r) {f :  → α}
    (hf : ∀ n, f n ∈ s) : ∃ g : ℕ ↪o ℕ, ∀ m n : ℕ, m ≤ n → r (f (g m)) (f (g n)) :=
  WellQuasiOrdered.exists_monotone_subseq h fun n ↦ ⟨_, hf n⟩
Existence of Monotone Subsequence in Partially Well-Ordered Sets
Informal description
For any set $s$ in a type $\alpha$ that is partially well-ordered with respect to a relation $r$, and any sequence $f \colon \mathbb{N} \to \alpha$ such that $f(n) \in s$ for all $n \in \mathbb{N}$, there exists an order embedding $g \colon \mathbb{N} \hookrightarrow \mathbb{N}$ such that the subsequence $(f \circ g)$ is monotone with respect to $r$, i.e., for all $m \leq n$ in $\mathbb{N}$, we have $r(f(g(m)), f(g(n)))$.
Set.partiallyWellOrderedOn_iff_exists_monotone_subseq theorem
: s.PartiallyWellOrderedOn r ↔ ∀ f : ℕ → α, (∀ n, f n ∈ s) → ∃ g : ℕ ↪o ℕ, ∀ m n : ℕ, m ≤ n → r (f (g m)) (f (g n))
Full source
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
  use PartiallyWellOrderedOn.exists_monotone_subseq
  rw [PartiallyWellOrderedOn, wellQuasiOrdered_iff_exists_monotone_subseq]
  exact fun H f ↦ H _ fun n ↦ (f n).2
Characterization of Partial Well-Ordering via Monotone Subsequences
Informal description
A set $s$ in a type $\alpha$ is partially well-ordered with respect to a relation $r$ if and only if for every sequence $f \colon \mathbb{N} \to \alpha$ such that $f(n) \in s$ for all $n \in \mathbb{N}$, there exists an order embedding $g \colon \mathbb{N} \hookrightarrow \mathbb{N}$ such that the subsequence $(f \circ g)$ is monotone with respect to $r$, i.e., $r(f(g(m)), f(g(n)))$ holds for all $m \leq n$ in $\mathbb{N}$.
Set.PartiallyWellOrderedOn.prod theorem
{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
Full source
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
  rw [partiallyWellOrderedOn_iff_exists_lt]
  intro f hf
  obtain ⟨g₁, h₁⟩ := hs.exists_monotone_subseq fun n => (hf n).1
  obtain ⟨m, n, hlt, hle⟩ := ht.exists_lt fun n => (hf _).2
  exact ⟨g₁ m, g₁ n, g₁.strictMono hlt, h₁ _ _ hlt.le, hle⟩
Product of Partially Well-Ordered Sets is Partially Well-Ordered
Informal description
Let $s$ be a set in a type $\alpha$ and $t$ a set in a type $\beta$. If $s$ is partially well-ordered with respect to a relation $r$ on $\alpha$ and $t$ is partially well-ordered with respect to a relation $r'$ on $\beta$, then the Cartesian product $s \times t$ is partially well-ordered with respect to the relation $(x_1, y_1) \leq (x_2, y_2) \iff r(x_1, x_2) \land r'(y_1, y_2)$.
Set.PartiallyWellOrderedOn.wellFoundedOn theorem
(h : s.PartiallyWellOrderedOn r) : s.WellFoundedOn fun a b => r a b ∧ ¬r b a
Full source
theorem PartiallyWellOrderedOn.wellFoundedOn (h : s.PartiallyWellOrderedOn r) :
    s.WellFoundedOn fun a b => r a b ∧ ¬ r b a :=
  h.wellFounded
Well-foundedness of the Strict Order Induced by a Partial Well-Ordering
Informal description
Let $s$ be a set in a type $\alpha$ and $r$ a binary relation on $\alpha$. If $s$ is partially well-ordered with respect to $r$, then the relation $\lambda a b, r(a, b) \land \neg r(b, a)$ is well-founded on $s$.
Set.IsPWO definition
(s : Set α) : Prop
Full source
/-- A subset of a preorder is partially well-ordered when any infinite sequence contains
  a monotone subsequence of length 2 (or equivalently, an infinite monotone subsequence). -/
def IsPWO (s : Set α) : Prop :=
  PartiallyWellOrderedOn s (· ≤ ·)
Partially well-ordered set
Informal description
A set $s$ in a type $\alpha$ with a preorder is called *partially well-ordered* if every infinite sequence of elements in $s$ contains a monotone subsequence of length 2 (or equivalently, an infinite monotone subsequence). This is equivalent to the condition that the set has no infinite antichains with respect to the preorder.
Set.IsPWO.mono theorem
(ht : t.IsPWO) : s ⊆ t → s.IsPWO
Full source
nonrec theorem IsPWO.mono (ht : t.IsPWO) : s ⊆ t → s.IsPWO := ht.mono
Subset of a Partially Well-Ordered Set is Partially Well-Ordered
Informal description
If a set $t$ is partially well-ordered, then any subset $s \subseteq t$ is also partially well-ordered.
Set.IsPWO.exists_monotone_subseq theorem
(h : s.IsPWO) {f : ℕ → α} (hf : ∀ n, f n ∈ s) : ∃ g : ℕ ↪o ℕ, Monotone (f ∘ g)
Full source
nonrec theorem IsPWO.exists_monotone_subseq (h : s.IsPWO) {f :  → α} (hf : ∀ n, f n ∈ s) :
    ∃ g : ℕ ↪o ℕ, Monotone (f ∘ g) :=
  h.exists_monotone_subseq hf
Existence of Monotone Subsequence in Partially Well-Ordered Sets
Informal description
For any partially well-ordered set $s$ in a type $\alpha$ with a preorder, and any sequence $f \colon \mathbb{N} \to \alpha$ such that $f(n) \in s$ for all $n \in \mathbb{N}$, there exists an order embedding $g \colon \mathbb{N} \hookrightarrow \mathbb{N}$ such that the composition $f \circ g$ is monotone.
Set.isPWO_iff_exists_monotone_subseq theorem
: s.IsPWO ↔ ∀ f : ℕ → α, (∀ n, f n ∈ s) → ∃ g : ℕ ↪o ℕ, Monotone (f ∘ g)
Full source
theorem isPWO_iff_exists_monotone_subseq :
    s.IsPWO ↔ ∀ f : ℕ → α, (∀ n, f n ∈ s) → ∃ g : ℕ ↪o ℕ, Monotone (f ∘ g) :=
  partiallyWellOrderedOn_iff_exists_monotone_subseq
Characterization of Partially Well-Ordered Sets via Monotone Subsequences
Informal description
A set $s$ in a type $\alpha$ with a preorder is partially well-ordered if and only if for every sequence $(f_n)_{n \in \mathbb{N}}$ of elements in $s$, there exists an order embedding $g \colon \mathbb{N} \hookrightarrow \mathbb{N}$ such that the subsequence $(f_{g(n)})_{n \in \mathbb{N}}$ is monotone.
Set.IsPWO.isWF theorem
(h : s.IsPWO) : s.IsWF
Full source
protected theorem IsPWO.isWF (h : s.IsPWO) : s.IsWF := by
  simpa only [← lt_iff_le_not_le] using h.wellFoundedOn
Partial Well-Ordering Implies Well-Foundedness
Informal description
If a set $s$ in a type $\alpha$ with a preorder is partially well-ordered, then it is well-founded with respect to the strict order relation $<$. That is, there are no infinite descending chains in $s$ with respect to $<$.
Set.IsPWO.prod theorem
{t : Set β} (hs : s.IsPWO) (ht : t.IsPWO) : IsPWO (s ×ˢ t)
Full source
nonrec theorem IsPWO.prod {t : Set β} (hs : s.IsPWO) (ht : t.IsPWO) : IsPWO (s ×ˢ t) :=
  hs.prod ht
Product of Partially Well-Ordered Sets is Partially Well-Ordered
Informal description
Let $s$ be a subset of a type $\alpha$ and $t$ a subset of a type $\beta$, both equipped with preorders. If $s$ is partially well-ordered and $t$ is partially well-ordered, then their Cartesian product $s \times t$ is also partially well-ordered with respect to the product preorder.
Set.IsPWO.image_of_monotoneOn theorem
(hs : s.IsPWO) {f : α → β} (hf : MonotoneOn f s) : IsPWO (f '' s)
Full source
theorem IsPWO.image_of_monotoneOn (hs : s.IsPWO) {f : α → β} (hf : MonotoneOn f s) :
    IsPWO (f '' s) :=
  hs.image_of_monotone_on hf
Image of a Partially Well-Ordered Set under a Monotone Function is Partially Well-Ordered
Informal description
Let $s$ be a subset of a type $\alpha$ that is partially well-ordered. If $f : \alpha \to \beta$ is a monotone function on $s$, then the image $f(s)$ is also partially well-ordered.
Set.IsPWO.image_of_monotone theorem
(hs : s.IsPWO) {f : α → β} (hf : Monotone f) : IsPWO (f '' s)
Full source
theorem IsPWO.image_of_monotone (hs : s.IsPWO) {f : α → β} (hf : Monotone f) : IsPWO (f '' s) :=
  hs.image_of_monotone_on (hf.monotoneOn _)
Image of a Partially Well-Ordered Set under a Monotone Function is Partially Well-Ordered
Informal description
Let $s$ be a partially well-ordered subset of a type $\alpha$, and let $f : \alpha \to \beta$ be a monotone function. Then the image $f(s)$ is partially well-ordered in $\beta$.
Set.IsPWO.union theorem
(hs : IsPWO s) (ht : IsPWO t) : IsPWO (s ∪ t)
Full source
protected nonrec theorem IsPWO.union (hs : IsPWO s) (ht : IsPWO t) : IsPWO (s ∪ t) :=
  hs.union ht
Union of Partially Well-Ordered Sets is Partially Well-Ordered
Informal description
If $s$ and $t$ are partially well-ordered subsets of a type $\alpha$, then their union $s \cup t$ is also partially well-ordered.
Set.isPWO_union theorem
: IsPWO (s ∪ t) ↔ IsPWO s ∧ IsPWO t
Full source
@[simp]
theorem isPWO_union : IsPWOIsPWO (s ∪ t) ↔ IsPWO s ∧ IsPWO t :=
  partiallyWellOrderedOn_union
Union of Sets is Partially Well-Ordered if and only if Both Sets Are Partially Well-Ordered
Informal description
For any sets $s$ and $t$ in a type $\alpha$, the union $s \cup t$ is partially well-ordered if and only if both $s$ and $t$ are partially well-ordered.
Set.Finite.isPWO theorem
(hs : s.Finite) : IsPWO s
Full source
protected theorem Finite.isPWO (hs : s.Finite) : IsPWO s := hs.partiallyWellOrderedOn
Finite Sets are Partially Well-Ordered
Informal description
For any finite set $s$ in a type $\alpha$ with a preorder, $s$ is partially well-ordered. That is, every infinite sequence of elements in $s$ contains a monotone subsequence of length 2 (or equivalently, an infinite monotone subsequence).
Set.isPWO_of_finite theorem
[Finite α] : s.IsPWO
Full source
@[simp] theorem isPWO_of_finite [Finite α] : s.IsPWO := s.toFinite.isPWO
Finite Types Have Partially Well-Ordered Sets
Informal description
For any set $s$ in a finite type $\alpha$ with a preorder, $s$ is partially well-ordered. That is, every infinite sequence of elements in $s$ contains a monotone subsequence of length 2 (or equivalently, an infinite monotone subsequence).
Set.isPWO_singleton theorem
(a : α) : IsPWO ({ a } : Set α)
Full source
@[simp] theorem isPWO_singleton (a : α) : IsPWO ({a} : Set α) := (finite_singleton a).isPWO
Singleton Sets are Partially Well-Ordered
Informal description
For any element $a$ of a type $\alpha$ with a preorder, the singleton set $\{a\}$ is partially well-ordered. That is, every infinite sequence of elements in $\{a\}$ contains a monotone subsequence of length 2 (or equivalently, an infinite monotone subsequence).
Set.isPWO_empty theorem
: IsPWO (∅ : Set α)
Full source
@[simp] theorem isPWO_empty : IsPWO ( : Set α) := finite_empty.isPWO
Empty Set is Partially Well-Ordered
Informal description
The empty set $\emptyset$ in any type $\alpha$ with a preorder is partially well-ordered.
Set.Subsingleton.isPWO theorem
(hs : s.Subsingleton) : IsPWO s
Full source
protected theorem Subsingleton.isPWO (hs : s.Subsingleton) : IsPWO s := hs.finite.isPWO
Subsingleton Sets are Partially Well-Ordered
Informal description
For any set $s$ in a type $\alpha$ with a preorder, if $s$ is a subsingleton (i.e., contains at most one element), then $s$ is partially well-ordered.
Set.isPWO_insert theorem
{a} : IsPWO (insert a s) ↔ IsPWO s
Full source
@[simp]
theorem isPWO_insert {a} : IsPWOIsPWO (insert a s) ↔ IsPWO s := by
  simp only [← singleton_union, isPWO_union, isPWO_singleton, true_and]
Partial Well-Ordering of Inserted Set $\{a\} \cup s$ iff $s$ is Partially Well-Ordered
Informal description
For any element $a$ and set $s$ in a type $\alpha$ with a preorder, the set $\{a\} \cup s$ is partially well-ordered if and only if $s$ is partially well-ordered.
Set.IsPWO.insert theorem
(h : IsPWO s) (a : α) : IsPWO (insert a s)
Full source
protected theorem IsPWO.insert (h : IsPWO s) (a : α) : IsPWO (insert a s) :=
  isPWO_insert.2 h
Insertion Preserves Partial Well-Ordering
Informal description
If a set $s$ in a type $\alpha$ with a preorder is partially well-ordered, then for any element $a \in \alpha$, the set $\{a\} \cup s$ is also partially well-ordered.
Set.Finite.isWF theorem
(hs : s.Finite) : IsWF s
Full source
protected theorem Finite.isWF (hs : s.Finite) : IsWF s := hs.isPWO.isWF
Finite Sets are Well-Founded with Respect to Strict Order
Informal description
For any finite set $s$ in a type $\alpha$ with a strict order relation $<$, the set $s$ is well-founded with respect to $<$. That is, there are no infinite descending chains in $s$ with respect to $<$.
Set.isWF_singleton theorem
{a : α} : IsWF ({ a } : Set α)
Full source
@[simp] theorem isWF_singleton {a : α} : IsWF ({a} : Set α) := (finite_singleton a).isWF
Well-foundedness of Singleton Sets
Informal description
For any element $a$ of a type $\alpha$, the singleton set $\{a\}$ is well-founded with respect to the strict order relation $<$.
Set.Subsingleton.isWF theorem
(hs : s.Subsingleton) : IsWF s
Full source
protected theorem Subsingleton.isWF (hs : s.Subsingleton) : IsWF s := hs.isPWO.isWF
Subsingleton Sets are Well-Founded
Informal description
For any set $s$ in a type $\alpha$ with a strict order, if $s$ is a subsingleton (i.e., contains at most one element), then $s$ is well-founded with respect to the strict order relation $<$.
Set.isWF_insert theorem
{a} : IsWF (insert a s) ↔ IsWF s
Full source
@[simp]
theorem isWF_insert {a} : IsWFIsWF (insert a s) ↔ IsWF s := by
  simp only [← singleton_union, isWF_union, isWF_singleton, true_and]
Well-foundedness of Inserted Set $\{a\} \cup s$ iff $s$ is Well-founded
Informal description
For any element $a$ and set $s$ in a type $\alpha$, the set $\{a\} \cup s$ is well-founded with respect to the strict inequality relation if and only if $s$ is well-founded.
Set.IsWF.insert theorem
(h : IsWF s) (a : α) : IsWF (insert a s)
Full source
protected theorem IsWF.insert (h : IsWF s) (a : α) : IsWF (insert a s) :=
  isWF_insert.2 h
Well-foundedness is preserved by inserting an element into a well-founded set
Informal description
Given a well-founded set $s$ with respect to the strict inequality relation $<$ on a type $\alpha$, and an element $a \in \alpha$, the set $\{a\} \cup s$ is also well-founded.
Set.Finite.wellFoundedOn theorem
(hs : s.Finite) : s.WellFoundedOn r
Full source
protected theorem Finite.wellFoundedOn (hs : s.Finite) : s.WellFoundedOn r :=
  letI := partialOrderOfSO r
  hs.isWF
Well-foundedness of relations on finite sets
Informal description
For any finite set $s$ in a type $\alpha$ and any binary relation $r$ on $\alpha$, the relation $r$ is well-founded when restricted to $s$.
Set.wellFoundedOn_singleton theorem
: WellFoundedOn ({ a } : Set α) r
Full source
@[simp]
theorem wellFoundedOn_singleton : WellFoundedOn ({a} : Set α) r :=
  (finite_singleton a).wellFoundedOn
Well-foundedness of Relation on Singleton Set
Informal description
For any element $a$ of a type $\alpha$ and any binary relation $r$ on $\alpha$, the relation $r$ is well-founded on the singleton set $\{a\}$.
Set.Subsingleton.wellFoundedOn theorem
(hs : s.Subsingleton) : s.WellFoundedOn r
Full source
protected theorem Subsingleton.wellFoundedOn (hs : s.Subsingleton) : s.WellFoundedOn r :=
  hs.finite.wellFoundedOn
Well-foundedness of Relations on Subsingleton Sets
Informal description
For any set $s$ in a type $\alpha$, if $s$ is a subsingleton (i.e., contains at most one element), then any binary relation $r$ on $\alpha$ is well-founded when restricted to $s$.
Set.wellFoundedOn_insert theorem
: WellFoundedOn (insert a s) r ↔ WellFoundedOn s r
Full source
@[simp]
theorem wellFoundedOn_insert : WellFoundedOnWellFoundedOn (insert a s) r ↔ WellFoundedOn s r := by
  simp only [← singleton_union, wellFoundedOn_union, wellFoundedOn_singleton, true_and]
Well-foundedness of Relation on Set Union with Singleton
Informal description
For any set $s$ in a type $\alpha$, any element $a \in \alpha$, and any binary relation $r$ on $\alpha$, the relation $r$ is well-founded on the set $s \cup \{a\}$ if and only if $r$ is well-founded on $s$.
Set.wellFoundedOn_sdiff_singleton theorem
: WellFoundedOn (s \ { a }) r ↔ WellFoundedOn s r
Full source
@[simp]
theorem wellFoundedOn_sdiff_singleton : WellFoundedOnWellFoundedOn (s \ {a}) r ↔ WellFoundedOn s r := by
  simp only [← wellFoundedOn_insert (a := a), insert_diff_singleton, mem_insert_iff, true_or,
    insert_eq_of_mem]
Well-foundedness of Relation on Set Minus Singleton is Equivalent to Well-foundedness on Original Set
Informal description
For any set $s$ in a type $\alpha$, any element $a \in \alpha$, and any binary relation $r$ on $\alpha$, the relation $r$ is well-founded on the set difference $s \setminus \{a\}$ if and only if $r$ is well-founded on $s$.
Set.WellFoundedOn.insert theorem
(h : WellFoundedOn s r) (a : α) : WellFoundedOn (insert a s) r
Full source
protected theorem WellFoundedOn.insert (h : WellFoundedOn s r) (a : α) :
    WellFoundedOn (insert a s) r :=
  wellFoundedOn_insert.2 h
Well-foundedness Preserved by Insertion of an Element
Informal description
Let $s$ be a set in a type $\alpha$ and $r$ a binary relation on $\alpha$. If $r$ is well-founded on $s$, then for any element $a \in \alpha$, the relation $r$ is also well-founded on the set $s \cup \{a\}$.
Set.WellFoundedOn.sdiff_singleton theorem
(h : WellFoundedOn s r) (a : α) : WellFoundedOn (s \ { a }) r
Full source
protected theorem WellFoundedOn.sdiff_singleton (h : WellFoundedOn s r) (a : α) :
    WellFoundedOn (s \ {a}) r :=
  wellFoundedOn_sdiff_singleton.2 h
Well-foundedness Preserved by Set Difference with Singleton
Informal description
Let $s$ be a set in a type $\alpha$ and $r$ a binary relation on $\alpha$. If $r$ is well-founded on $s$, then for any element $a \in \alpha$, the relation $r$ is also well-founded on the set difference $s \setminus \{a\}$.
Set.WellFoundedOn.mapsTo theorem
{α β : Type*} {r : α → α → Prop} (f : β → α) {s : Set α} {t : Set β} (h : MapsTo f t s) (hw : s.WellFoundedOn r) : t.WellFoundedOn (r on f)
Full source
lemma WellFoundedOn.mapsTo {α β : Type*} {r : α → α → Prop} (f : β → α)
    {s : Set α} {t : Set β} (h : MapsTo f t s) (hw : s.WellFoundedOn r) :
    t.WellFoundedOn (r on f) := by
  exact InvImage.wf (fun x : t ↦ ⟨f x, h x.prop⟩) hw
Well-foundedness Preservation under Function Mapping
Informal description
Let $r$ be a binary relation on a type $\alpha$, and let $s \subseteq \alpha$ be a set on which $r$ is well-founded. Given a function $f : \beta \to \alpha$ and a set $t \subseteq \beta$ such that $f$ maps $t$ into $s$, then the relation $r$ composed with $f$ (i.e., the relation defined by $x \ (r \circ f) \ y \leftrightarrow r \ (f(x)) \ (f(y))$) is well-founded on $t$.
Set.isPWO_iff_isWF theorem
: s.IsPWO ↔ s.IsWF
Full source
/-- In a linear order, the predicates `Set.IsPWO` and `Set.IsWF` are equivalent. -/
theorem isPWO_iff_isWF : s.IsPWO ↔ s.IsWF := by
  change WellQuasiOrderedWellQuasiOrdered (· ≤ ·) ↔ WellFounded (· < ·)
  rw [← wellQuasiOrderedLE_def, ← isWellFounded_iff, wellQuasiOrderedLE_iff_wellFoundedLT]
Equivalence of Partial Well-Ordering and Well-Foundedness in Linear Orders
Informal description
For any set $s$ in a linearly ordered type $\alpha$, the following are equivalent: 1. $s$ is partially well-ordered (every infinite sequence in $s$ contains a monotone subsequence) 2. $s$ is well-founded with respect to the strict order relation (contains no infinite descending chains)
Set.isWF_iff_isPWO theorem
: s.IsWF ↔ s.IsPWO
Full source
@[deprecated isPWO_iff_isWF (since := "2025-01-21")]
theorem isWF_iff_isPWO : s.IsWF ↔ s.IsPWO :=
  isPWO_iff_isWF.symm
Equivalence of Well-Foundedness and Partial Well-Ordering in Linear Orders
Informal description
For any set $s$ in a linearly ordered type $\alpha$, the following are equivalent: 1. $s$ is well-founded with respect to the strict order relation (contains no infinite descending chains) 2. $s$ is partially well-ordered (every infinite sequence in $s$ contains a monotone subsequence)
Set.IsPWO.of_linearOrder theorem
[WellFoundedLT α] (s : Set α) : s.IsPWO
Full source
/--
If `α` is a linear order with well-founded `<`, then any set in it is a partially well-ordered set.
Note this does not hold without the linearity assumption.
-/
lemma IsPWO.of_linearOrder [WellFoundedLT α] (s : Set α) : s.IsPWO :=
  (IsWF.of_wellFoundedLT s).isPWO
Partial Well-Ordering of Subsets in Well-Founded Linear Orders
Informal description
Let $\alpha$ be a linearly ordered type with a well-founded strict less-than relation $<$. Then any subset $s$ of $\alpha$ is partially well-ordered (i.e., every infinite sequence in $s$ contains a monotone subsequence).
Finset.partiallyWellOrderedOn theorem
[IsRefl α r] (s : Finset α) : (s : Set α).PartiallyWellOrderedOn r
Full source
@[simp]
protected theorem partiallyWellOrderedOn [IsRefl α r] (s : Finset α) :
    (s : Set α).PartiallyWellOrderedOn r :=
  s.finite_toSet.partiallyWellOrderedOn
Finsets are Partially Well-Ordered under Reflexive Relations
Informal description
For any reflexive relation $r$ on a type $\alpha$ and any finset $s$ of $\alpha$, the underlying set of $s$ is partially well-ordered with respect to $r$.
Finset.isPWO theorem
[Preorder α] (s : Finset α) : Set.IsPWO (↑s : Set α)
Full source
@[simp]
protected theorem isPWO [Preorder α] (s : Finset α) : Set.IsPWO (↑s : Set α) :=
  s.partiallyWellOrderedOn
Finite Sets are Partially Well-Ordered
Informal description
For any preorder $\alpha$ and any finite subset $s$ of $\alpha$, the set $s$ is partially well-ordered (i.e., every infinite sequence in $s$ contains a monotone subsequence of length 2).
Finset.isWF theorem
[Preorder α] (s : Finset α) : Set.IsWF (↑s : Set α)
Full source
@[simp]
protected theorem isWF [Preorder α] (s : Finset α) : Set.IsWF (↑s : Set α) :=
  s.finite_toSet.isWF
Finite Sets are Well-Founded with Respect to Strict Order
Informal description
For any preorder $\alpha$ and any finite subset $s$ of $\alpha$, the set $s$ is well-founded with respect to the strict order relation $<$. That is, there are no infinite descending chains in $s$ with respect to $<$.
Finset.wellFoundedOn theorem
[IsStrictOrder α r] (s : Finset α) : Set.WellFoundedOn (↑s : Set α) r
Full source
@[simp]
protected theorem wellFoundedOn [IsStrictOrder α r] (s : Finset α) :
    Set.WellFoundedOn (↑s : Set α) r :=
  letI := partialOrderOfSO r
  s.isWF
Well-foundedness of Finite Sets under Strict Order
Informal description
For any type $\alpha$ with a strict order relation $r$ and any finite subset $s$ of $\alpha$, the relation $r$ is well-founded on $s$. That is, there are no infinite descending chains $a_1 \succ_r a_2 \succ_r \cdots$ with all $a_i \in s$.
Finset.wellFoundedOn_sup theorem
[IsStrictOrder α r] (s : Finset ι) {f : ι → Set α} : (s.sup f).WellFoundedOn r ↔ ∀ i ∈ s, (f i).WellFoundedOn r
Full source
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 simp [-sup_set_eq_biUnion, hs]
Well-foundedness of Finite Union of Sets with Respect to a Strict Order
Informal description
Let $\alpha$ be a type with a strict order relation $r$, and let $s$ be a finite set of indices. For a family of sets $\{f_i\}_{i \in s}$ in $\alpha$, the union $\bigcup_{i \in s} f_i$ is well-founded with respect to $r$ if and only if each individual set $f_i$ is well-founded with respect to $r$ for every $i \in s$.
Finset.partiallyWellOrderedOn_sup theorem
(s : Finset ι) {f : ι → Set α} : (s.sup f).PartiallyWellOrderedOn r ↔ ∀ i ∈ s, (f i).PartiallyWellOrderedOn r
Full source
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 simp [-sup_set_eq_biUnion, hs]
Partial Well-Ordering of Finite Union of Sets
Informal description
For any finite set $s$ of indices and a family of sets $\{f_i\}_{i \in s}$ in a type $\alpha$, the union $\bigcup_{i \in s} f_i$ is partially well-ordered with respect to a relation $r$ if and only if each individual set $f_i$ is partially well-ordered with respect to $r$ for every $i \in s$.
Finset.isWF_sup theorem
[Preorder α] (s : Finset ι) {f : ι → Set α} : (s.sup f).IsWF ↔ ∀ i ∈ s, (f i).IsWF
Full source
theorem isWF_sup [Preorder α] (s : Finset ι) {f : ι → Set α} :
    (s.sup f).IsWF ↔ ∀ i ∈ s, (f i).IsWF :=
  s.wellFoundedOn_sup
Well-foundedness of finite union of sets with respect to strict order
Informal description
Let $\alpha$ be a preorder and $s$ be a finite set of indices. For a family of sets $\{f_i\}_{i \in s}$ in $\alpha$, the union $\bigcup_{i \in s} f_i$ is well-founded with respect to the strict order $<$ if and only if each individual set $f_i$ is well-founded with respect to $<$ for every $i \in s$.
Finset.isPWO_sup theorem
[Preorder α] (s : Finset ι) {f : ι → Set α} : (s.sup f).IsPWO ↔ ∀ i ∈ s, (f i).IsPWO
Full source
theorem isPWO_sup [Preorder α] (s : Finset ι) {f : ι → Set α} :
    (s.sup f).IsPWO ↔ ∀ i ∈ s, (f i).IsPWO :=
  s.partiallyWellOrderedOn_sup
Partial Well-Ordering of Finite Union of Sets
Informal description
For a preorder $\alpha$, a finite set $s$ of indices, and a family of sets $\{f_i\}_{i \in s}$ in $\alpha$, the union $\bigcup_{i \in s} f_i$ is partially well-ordered if and only if each $f_i$ is partially well-ordered for every $i \in s$.
Finset.wellFoundedOn_bUnion theorem
[IsStrictOrder α r] (s : Finset ι) {f : ι → Set α} : (⋃ i ∈ s, f i).WellFoundedOn r ↔ ∀ i ∈ s, (f i).WellFoundedOn r
Full source
@[simp]
theorem wellFoundedOn_bUnion [IsStrictOrder α r] (s : Finset ι) {f : ι → Set α} :
    (⋃ i ∈ s, f i).WellFoundedOn r ↔ ∀ i ∈ s, (f i).WellFoundedOn r := by
  simpa only [Finset.sup_eq_iSup] using s.wellFoundedOn_sup
Well-foundedness of Finite Union with Respect to a Strict Order
Informal description
Let $\alpha$ be a type equipped with a strict order relation $r$, and let $s$ be a finite set of indices. For a family of sets $\{f_i\}_{i \in s}$ in $\alpha$, the union $\bigcup_{i \in s} f_i$ is well-founded with respect to $r$ if and only if each individual set $f_i$ is well-founded with respect to $r$ for every $i \in s$.
Finset.partiallyWellOrderedOn_bUnion theorem
(s : Finset ι) {f : ι → Set α} : (⋃ i ∈ s, f i).PartiallyWellOrderedOn r ↔ ∀ i ∈ s, (f i).PartiallyWellOrderedOn r
Full source
@[simp]
theorem partiallyWellOrderedOn_bUnion (s : Finset ι) {f : ι → Set α} :
    (⋃ i ∈ s, f i).PartiallyWellOrderedOn r ↔ ∀ i ∈ s, (f i).PartiallyWellOrderedOn r := by
  simpa only [Finset.sup_eq_iSup] using s.partiallyWellOrderedOn_sup
Partial Well-Ordering of Finite Union of Sets: $\bigcup_{i \in s} f_i$ is partially well-ordered w.r.t. $r$ iff each $f_i$ is partially well-ordered w.r.t. $r$ for $i \in s$
Informal description
For any finite set $s$ of indices and a family of sets $\{f_i\}_{i \in s}$ in a type $\alpha$, the union $\bigcup_{i \in s} f_i$ is partially well-ordered with respect to a relation $r$ if and only if each individual set $f_i$ is partially well-ordered with respect to $r$ for every $i \in s$.
Finset.isWF_bUnion theorem
[Preorder α] (s : Finset ι) {f : ι → Set α} : (⋃ i ∈ s, f i).IsWF ↔ ∀ i ∈ s, (f i).IsWF
Full source
@[simp]
theorem isWF_bUnion [Preorder α] (s : Finset ι) {f : ι → Set α} :
    (⋃ i ∈ s, f i).IsWF ↔ ∀ i ∈ s, (f i).IsWF :=
  s.wellFoundedOn_bUnion
Well-foundedness of finite union of sets: $\bigcup_{i \in s} f_i$ is well-founded w.r.t. $<$ iff each $f_i$ is well-founded w.r.t. $<$ for all $i \in s$
Informal description
Let $\alpha$ be a preorder and $s$ be a finite set of indices. For a family of sets $\{f_i\}_{i \in s}$ in $\alpha$, the union $\bigcup_{i \in s} f_i$ is well-founded with respect to the strict order $<$ if and only if each individual set $f_i$ is well-founded with respect to $<$ for every $i \in s$.
Finset.isPWO_bUnion theorem
[Preorder α] (s : Finset ι) {f : ι → Set α} : (⋃ i ∈ s, f i).IsPWO ↔ ∀ i ∈ s, (f i).IsPWO
Full source
@[simp]
theorem isPWO_bUnion [Preorder α] (s : Finset ι) {f : ι → Set α} :
    (⋃ i ∈ s, f i).IsPWO ↔ ∀ i ∈ s, (f i).IsPWO :=
  s.partiallyWellOrderedOn_bUnion
Partial Well-Ordering of Finite Union: $\bigcup_{i \in s} f_i$ is PWO iff each $f_i$ is PWO for $i \in s$
Informal description
For a finite set $s$ of indices and a family of sets $\{f_i\}_{i \in s}$ in a preorder $\alpha$, the union $\bigcup_{i \in s} f_i$ is partially well-ordered if and only if each $f_i$ is partially well-ordered for every $i \in s$.
Set.IsWF.min definition
(hs : IsWF s) (hn : s.Nonempty) : α
Full source
/-- `Set.IsWF.min` returns a minimal element of a nonempty well-founded set. -/
noncomputable nonrec def IsWF.min (hs : IsWF s) (hn : s.Nonempty) : α :=
  hs.min univ (nonempty_iff_univ_nonempty.1 hn.to_subtype)
Minimal element of a nonempty well-founded set
Informal description
Given a well-founded set $s$ in a type $\alpha$ and a proof that $s$ is nonempty, the function returns a minimal element of $s$ with respect to the strict inequality relation $<$. Specifically, if $s$ is well-founded and nonempty, then $\text{min}\ s$ is an element of $s$ such that no other element in $s$ is strictly less than it.
Set.IsWF.min_mem theorem
(hs : IsWF s) (hn : s.Nonempty) : hs.min hn ∈ s
Full source
theorem IsWF.min_mem (hs : IsWF s) (hn : s.Nonempty) : hs.min hn ∈ s :=
  (WellFounded.min hs univ (nonempty_iff_univ_nonempty.1 hn.to_subtype)).2
Minimal Element Belongs to Well-Founded Set
Informal description
For any well-founded set $s$ in a type $\alpha$ with respect to the strict inequality relation $<$, if $s$ is nonempty, then the minimal element $\mathrm{min}(s)$ (with respect to $<$) belongs to $s$.
Set.IsWF.not_lt_min theorem
(hs : IsWF s) (hn : s.Nonempty) (ha : a ∈ s) : ¬a < hs.min hn
Full source
nonrec theorem IsWF.not_lt_min (hs : IsWF s) (hn : s.Nonempty) (ha : a ∈ s) : ¬a < hs.min hn :=
  hs.not_lt_min univ (nonempty_iff_univ_nonempty.1 hn.to_subtype) (mem_univ (⟨a, ha⟩ : s))
Minimal Element Property in Well-Founded Sets: $\neg (a < \text{min}(s))$ for $a \in s$
Informal description
For any well-founded set $s$ in a type $\alpha$ with respect to the strict inequality relation $<$, if $s$ is nonempty and $a$ is an element of $s$, then $a$ is not strictly less than the minimal element of $s$ (with respect to $<$).
Set.IsWF.min_of_subset_not_lt_min theorem
{hs : s.IsWF} {hsn : s.Nonempty} {ht : t.IsWF} {htn : t.Nonempty} (hst : s ⊆ t) : ¬hs.min hsn < ht.min htn
Full source
theorem IsWF.min_of_subset_not_lt_min {hs : s.IsWF} {hsn : s.Nonempty} {ht : t.IsWF}
    {htn : t.Nonempty} (hst : s ⊆ t) : ¬hs.min hsn < ht.min htn :=
  ht.not_lt_min htn (hst (min_mem hs hsn))
Minimal Elements of Nested Well-Founded Sets: $\neg(\text{min}(s) < \text{min}(t))$ for $s \subseteq t$
Informal description
Let $s$ and $t$ be nonempty well-founded sets with respect to the strict inequality relation $<$ in a type $\alpha$, such that $s \subseteq t$. Then the minimal element of $s$ is not strictly less than the minimal element of $t$.
Set.isWF_min_singleton theorem
(a) {hs : IsWF ({ a } : Set α)} {hn : ({ a } : Set α).Nonempty} : hs.min hn = a
Full source
@[simp]
theorem isWF_min_singleton (a) {hs : IsWF ({a} : Set α)} {hn : ({a} : Set α).Nonempty} :
    hs.min hn = a :=
  eq_of_mem_singleton (IsWF.min_mem hs hn)
Minimal Element of Singleton Well-Founded Set is Itself
Informal description
For any element $a$ of a type $\alpha$, if the singleton set $\{a\}$ is well-founded with respect to the strict inequality relation $<$ and is nonempty, then the minimal element of $\{a\}$ is $a$ itself.
Set.IsWF.min_eq_of_lt theorem
(hs : s.IsWF) (ha : a ∈ s) (hlt : ∀ b ∈ s, b ≠ a → a < b) : hs.min (nonempty_of_mem ha) = a
Full source
theorem IsWF.min_eq_of_lt (hs : s.IsWF) (ha : a ∈ s) (hlt : ∀ b ∈ s, b ≠ a → a < b) :
    hs.min (nonempty_of_mem ha) = a := by
  by_contra h
  exact (hs.not_lt_min (nonempty_of_mem ha) ha) (hlt (hs.min (nonempty_of_mem ha))
    (hs.min_mem (nonempty_of_mem ha)) h)
Minimal Element Characterization in Well-Founded Sets: $a$ is Minimal if it is Strictly Less Than All Other Elements
Informal description
Let $s$ be a well-founded set in a type $\alpha$ with respect to the strict inequality relation $<$. If $a \in s$ satisfies the condition that for all $b \in s$ with $b \neq a$, we have $a < b$, then the minimal element of $s$ (with respect to $<$) is equal to $a$.
Set.IsWF.min_eq_of_le theorem
(hs : s.IsWF) (ha : a ∈ s) (hle : ∀ b ∈ s, a ≤ b) : hs.min (nonempty_of_mem ha) = a
Full source
theorem IsWF.min_eq_of_le (hs : s.IsWF) (ha : a ∈ s) (hle : ∀ b ∈ s, a ≤ b) :
    hs.min (nonempty_of_mem ha) = a :=
  (eq_of_le_of_not_lt (hle (hs.min (nonempty_of_mem ha))
    (hs.min_mem (nonempty_of_mem ha))) (hs.not_lt_min (nonempty_of_mem ha) ha)).symm
Minimal Element Characterization in Well-Founded Sets: $\text{min}(s) = a$ when $a$ is a lower bound for $s$
Informal description
Let $s$ be a well-founded set in a type $\alpha$ with respect to the strict inequality relation $<$, and let $a$ be an element of $s$. If for every element $b \in s$ we have $a \leq b$, then the minimal element of $s$ (with respect to $<$) is equal to $a$.
Set.IsWF.min_le theorem
(hs : s.IsWF) (hn : s.Nonempty) (ha : a ∈ s) : hs.min hn ≤ a
Full source
theorem IsWF.min_le (hs : s.IsWF) (hn : s.Nonempty) (ha : a ∈ s) : hs.min hn ≤ a :=
  le_of_not_lt (hs.not_lt_min hn ha)
Minimal Element Property in Well-Founded Sets: $\text{min}(s) \leq a$ for all $a \in s$
Informal description
For any nonempty well-founded set $s$ with respect to the strict inequality relation $<$ and any element $a \in s$, the minimal element of $s$ (denoted $\text{min}(s)$) satisfies $\text{min}(s) \leq a$.
Set.IsWF.le_min_iff theorem
(hs : s.IsWF) (hn : s.Nonempty) : a ≤ hs.min hn ↔ ∀ b, b ∈ s → a ≤ b
Full source
theorem IsWF.le_min_iff (hs : s.IsWF) (hn : s.Nonempty) : a ≤ hs.min hn ↔ ∀ b, b ∈ s → a ≤ b :=
  ⟨fun ha _b hb => le_trans ha (hs.min_le hn hb), fun h => h _ (hs.min_mem _)⟩
Characterization of Minimal Element in Well-Founded Sets: $a \leq \text{min}(s) \leftrightarrow \forall b \in s, a \leq b$
Informal description
Let $s$ be a nonempty well-founded set with respect to the strict inequality relation $<$ in a type $\alpha$. For any element $a \in \alpha$, we have $a \leq \text{min}(s)$ if and only if $a \leq b$ for all $b \in s$, where $\text{min}(s)$ denotes the minimal element of $s$ with respect to $<$.
Set.IsWF.min_le_min_of_subset theorem
{hs : s.IsWF} {hsn : s.Nonempty} {ht : t.IsWF} {htn : t.Nonempty} (hst : s ⊆ t) : ht.min htn ≤ hs.min hsn
Full source
theorem IsWF.min_le_min_of_subset {hs : s.IsWF} {hsn : s.Nonempty} {ht : t.IsWF} {htn : t.Nonempty}
    (hst : s ⊆ t) : ht.min htn ≤ hs.min hsn :=
  (IsWF.le_min_iff _ _).2 fun _b hb => ht.min_le htn (hst hb)
Minimal Element Comparison for Subsets of Well-Founded Sets: $\text{min}(t) \leq \text{min}(s)$ when $s \subseteq t$
Informal description
Let $s$ and $t$ be nonempty well-founded sets with respect to the strict inequality relation $<$ in a type $\alpha$, and suppose $s \subseteq t$. Then the minimal element of $t$ is less than or equal to the minimal element of $s$, i.e., $\text{min}(t) \leq \text{min}(s)$.
Set.IsWF.min_union theorem
(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)
Full source
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]
  exact ((mem_union _ _ _).1 ((hs.union ht).min_mem (union_nonempty.2 (.inl hsn)))).imp
    (hs.min_le _) (ht.min_le _)
Minimal Element of Union of Well-Founded Sets: $\text{min}(s \cup t) = \min(\text{min}(s), \text{min}(t))$
Informal description
Let $s$ and $t$ be nonempty well-founded subsets of a type $\alpha$ with respect to the strict inequality relation $<$. Then the minimal element of their union $s \cup t$ is equal to the minimum of the minimal elements of $s$ and $t$, i.e., \[ \text{min}(s \cup t) = \min(\text{min}(s), \text{min}(t)). \]
BddBelow.wellFoundedOn_lt theorem
: BddBelow s → s.WellFoundedOn (· < ·)
Full source
theorem BddBelow.wellFoundedOn_lt : BddBelow s → s.WellFoundedOn (· < ·) := by
  rw [wellFoundedOn_iff_no_descending_seq]
  rintro ⟨a, ha⟩ f hf
  refine infinite_range_of_injective f.injective ?_
  exact (finite_Icc a <| f 0).subset <| range_subset_iff.2 <| fun n =>
    ⟨ha <| hf _,
      antitone_iff_forall_lt.2 (fun a b hab => (f.map_rel_iff.2 hab).le) <| Nat.zero_le _⟩
Well-foundedness of $<$ on bounded below sets
Informal description
For any set $s$ in a partially ordered type $\alpha$, if $s$ is bounded below, then the strict less-than relation $<$ is well-founded on $s$.
BddAbove.wellFoundedOn_gt theorem
: BddAbove s → s.WellFoundedOn (· > ·)
Full source
theorem BddAbove.wellFoundedOn_gt : BddAbove s → s.WellFoundedOn (· > ·) :=
  fun h => h.dual.wellFoundedOn_lt
Well-foundedness of $>$ on bounded above sets
Informal description
For any set $s$ in a partially ordered type $\alpha$, if $s$ is bounded above, then the strict greater-than relation $>$ is well-founded on $s$.
BddBelow.isWF theorem
: BddBelow s → IsWF s
Full source
theorem BddBelow.isWF : BddBelow s → IsWF s :=
  BddBelow.wellFoundedOn_lt
Bounded below sets are well-founded with respect to $<$
Informal description
For any set $s$ in a partially ordered type $\alpha$, if $s$ is bounded below, then $s$ is well-founded with respect to the strict inequality relation $<$. That is, there are no infinite descending chains $a_1 > a_2 > \cdots$ with all $a_i \in s$.
Set.PartiallyWellOrderedOn.IsBadSeq definition
(r : α → α → Prop) (s : Set α) (f : ℕ → α) : Prop
Full source
/-- In the context of partial well-orderings, a bad sequence is a nonincreasing sequence
  whose range is contained in a particular set `s`. One exists if and only if `s` is not
  partially well-ordered. -/
def IsBadSeq (r : α → α → Prop) (s : Set α) (f :  → α) : Prop :=
  (∀ n, f n ∈ s) ∧ ∀ m n : ℕ, m < n → ¬r (f m) (f n)
Bad sequence with respect to a relation on a set
Informal description
A sequence \( f : \mathbb{N} \to \alpha \) is called a *bad sequence* with respect to a relation \( r \) on a set \( s \) if every term \( f(n) \) belongs to \( s \) and for any two natural numbers \( m < n \), the relation \( r(f(m), f(n)) \) does not hold. In other words, the sequence is non-increasing with respect to \( r \) and entirely contained in \( s \).
Set.PartiallyWellOrderedOn.iff_forall_not_isBadSeq theorem
(r : α → α → Prop) (s : Set α) : s.PartiallyWellOrderedOn r ↔ ∀ f, ¬IsBadSeq r s f
Full source
theorem iff_forall_not_isBadSeq (r : α → α → Prop) (s : Set α) :
    s.PartiallyWellOrderedOn r ↔ ∀ f, ¬IsBadSeq r s f := by
  rw [partiallyWellOrderedOn_iff_exists_lt]
  exact forall_congr' fun f => by simp [IsBadSeq]
Characterization of Partial Well-Ordering via Nonexistence of Bad Sequences
Informal description
A set $s$ in a type $\alpha$ is partially well-ordered with respect to a relation $r$ if and only if there does not exist any infinite sequence $f \colon \mathbb{N} \to \alpha$ such that: 1. $f(n) \in s$ for all $n \in \mathbb{N}$, 2. For all $m < n$, the relation $r(f(m), f(n))$ does not hold. In other words, $s$ is partially well-ordered by $r$ precisely when no "bad sequence" (a sequence in $s$ with no $r$-related pair of elements) exists.
Set.PartiallyWellOrderedOn.IsMinBadSeq definition
(r : α → α → Prop) (rk : α → ℕ) (s : Set α) (n : ℕ) (f : ℕ → α) : Prop
Full source
/-- This indicates that every bad sequence `g` that agrees with `f` on the first `n`
  terms has `rk (f n) ≤ rk (g n)`. -/
def IsMinBadSeq (r : α → α → Prop) (rk : α → ) (s : Set α) (n : ) (f :  → α) : Prop :=
  ∀ g :  → α, (∀ m : , m < n → f m = g m) → rk (g n) < rk (f n) → ¬IsBadSeq r s g
Minimal bad sequence with respect to a relation and rank function
Informal description
A sequence \( f : \mathbb{N} \to \alpha \) is called a *minimal bad sequence* with respect to a relation \( r \) on a set \( s \) and a rank function \( \text{rk} : \alpha \to \mathbb{N} \) at position \( n \) if for any other sequence \( g \) that agrees with \( f \) on the first \( n \) terms, if \( \text{rk}(g(n)) < \text{rk}(f(n)) \), then \( g \) is not a bad sequence with respect to \( r \) on \( s \). In other words, \( f \) minimizes the rank at position \( n \) among all sequences that agree with \( f \) on the first \( n \) terms and are bad sequences with respect to \( r \) on \( s \).
Set.PartiallyWellOrderedOn.minBadSeqOfBadSeq definition
(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 }
Full source
/-- 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 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]
Construction of a minimal bad sequence from a given bad sequence
Informal description
Given a relation \( r \) on a set \( s \subseteq \alpha \), a rank function \( \text{rk} : \alpha \to \mathbb{N} \), a natural number \( n \), and a bad sequence \( f : \mathbb{N} \to \alpha \) with respect to \( r \) on \( s \), there exists a sequence \( g : \mathbb{N} \to \alpha \) such that: 1. \( g \) agrees with \( f \) on the first \( n \) terms, 2. \( g \) is a bad sequence with respect to \( r \) on \( s \), 3. \( g \) is minimal at position \( n \) with respect to the rank function \( \text{rk} \).
Set.PartiallyWellOrderedOn.exists_min_bad_of_exists_bad theorem
(r : α → α → Prop) (rk : α → ℕ) (s : Set α) : (∃ f, IsBadSeq r s f) → ∃ f, IsBadSeq r s f ∧ ∀ n, IsMinBadSeq r rk s n f
Full source
theorem exists_min_bad_of_exists_bad (r : α → α → Prop) (rk : α → ) (s : Set α) :
    (∃ f, IsBadSeq r s f) → ∃ f, IsBadSeq r s f ∧ ∀ n, IsMinBadSeq r rk s n f := by
  rintro ⟨f0, hf0 : IsBadSeq r s f0⟩
  let fs : ∀ n : , { f : ℕ → α // IsBadSeq r s f ∧ IsMinBadSeq r rk s n f } := by
    refine Nat.rec ?_ fun n fn => ?_
    · exact ⟨(minBadSeqOfBadSeq r rk s 0 f0 hf0).1, (minBadSeqOfBadSeq r rk s 0 f0 hf0).2.2⟩
    · exact ⟨(minBadSeqOfBadSeq r rk s (n + 1) fn.1 fn.2.1).1,
        (minBadSeqOfBadSeq r rk s (n + 1) fn.1 fn.2.1).2.2⟩
  have h : ∀ m n, m ≤ n → (fs m).1 m = (fs n).1 m := fun m n mn => by
    obtain ⟨k, rfl⟩ := Nat.exists_eq_add_of_le mn; clear mn
    induction' k with k ih
    · rfl
    · rw [ih, (minBadSeqOfBadSeq r rk s (m + k + 1) (fs (m + k)).1 (fs (m + k)).2.1).2.1 m
        (Nat.lt_succ_iff.2 (Nat.add_le_add_left k.zero_le m))]
      rfl
  refine ⟨fun n => (fs n).1 n, ⟨fun n => (fs n).2.1.1 n, fun m n mn => ?_⟩, fun n g hg1 hg2 => ?_⟩
  · dsimp
    rw [h m n mn.le]
    exact (fs n).2.1.2 m n mn
  · refine (fs n).2.2 g (fun m mn => ?_) hg2
    rw [← h m n mn.le, ← hg1 m mn]
Existence of Minimal Bad Sequences for Partially Well-Ordered Sets
Informal description
For any relation $r$ on a set $s \subseteq \alpha$ and any rank function $\text{rk} : \alpha \to \mathbb{N}$, if there exists a bad sequence $f : \mathbb{N} \to \alpha$ with respect to $r$ on $s$, then there exists a bad sequence $g : \mathbb{N} \to \alpha$ that is minimal with respect to $\text{rk}$ at every position $n \in \mathbb{N}$.
Set.PartiallyWellOrderedOn.iff_not_exists_isMinBadSeq theorem
(rk : α → ℕ) {s : Set α} : s.PartiallyWellOrderedOn r ↔ ¬∃ f, IsBadSeq r s f ∧ ∀ n, IsMinBadSeq r rk s n f
Full source
theorem iff_not_exists_isMinBadSeq (rk : α → ) {s : Set α} :
    s.PartiallyWellOrderedOn r ↔ ¬∃ f, IsBadSeq r s f ∧ ∀ n, IsMinBadSeq r rk s n f := by
  rw [iff_forall_not_isBadSeq, ← not_exists, not_congr]
  constructor
  · apply exists_min_bad_of_exists_bad
  · rintro ⟨f, hf1, -⟩
    exact ⟨f, hf1⟩
Characterization of Partial Well-Ordering via Nonexistence of Minimal Bad Sequences
Informal description
A set $s$ in a type $\alpha$ is partially well-ordered with respect to a relation $r$ if and only if there does not exist any infinite sequence $f \colon \mathbb{N} \to \alpha$ such that: 1. $f(n) \in s$ for all $n \in \mathbb{N}$, 2. $f$ is a bad sequence with respect to $r$ on $s$ (i.e., for all $m < n$, $r(f(m), f(n))$ does not hold), 3. For every $n \in \mathbb{N}$, the sequence $f$ is minimal with respect to a given rank function $\text{rk} \colon \alpha \to \mathbb{N}$ at position $n$. In other words, partial well-ordering is equivalent to the nonexistence of minimal bad sequences with respect to any rank function.
Set.PartiallyWellOrderedOn.partiallyWellOrderedOn_sublistForall₂ theorem
(r : α → α → Prop) [IsPreorder α r] {s : Set α} (h : s.PartiallyWellOrderedOn r) : {l : List α | ∀ x, x ∈ l → x ∈ s}.PartiallyWellOrderedOn (List.SublistForall₂ r)
Full source
/-- 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) [IsPreorder α 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.symmList.SublistForall₂.nil)
  obtain ⟨g, hg⟩ := h.exists_monotone_subseq fun n => hf1.1 n _ (List.head!_mem_self (hnil n))
  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)), Nat.sub_self]
    rw [List.length_tail, ← Nat.pred_eq_sub_one]
    exact Nat.pred_lt fun con => hnil _ (List.length_eq_zero_iff.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⟩ := Nat.exists_eq_add_of_le (not_lt.1 hn)
    rw [if_neg hn, add_comm (g 0) n', Nat.add_sub_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 [← Nat.sub_lt_iff_lt_add' (le_of_not_lt hm)] at mn
      apply hf1.2 _ _ (g.lt_iff_lt.2 mn)
      rw [← List.cons_head!_tail (hnil (g (m - g 0))), ← List.cons_head!_tail (hnil (g n'))]
      exact List.SublistForall₂.cons (hg _ _ (le_of_lt mn)) hmn
Higman's Lemma: Partial Well-Ordering of Lists under SublistForall₂ Relation
Informal description
Let $\alpha$ be a type with a preorder relation $r$, and let $s$ be a subset of $\alpha$ that is partially well-ordered with respect to $r$. Then the set of all lists of elements from $s$ is partially well-ordered with respect to the relation $\text{SublistForall₂}\ r$, where $\text{SublistForall₂}\ r\ l_1\ l_2$ holds if there exists a sublist of $l_2$ that is pointwise related to $l_1$ via $r$.
Set.PartiallyWellOrderedOn.subsetProdLex theorem
[PartialOrder α] [Preorder β] {s : Set (α ×ₗ β)} (hα : ((fun (x : α ×ₗ β) => (ofLex x).1) '' s).IsPWO) (hβ : ∀ a, {y | toLex (a, y) ∈ s}.IsPWO) : s.IsPWO
Full source
theorem subsetProdLex [PartialOrder α] [Preorder β] {s : Set (α ×ₗ β)}
    (hα : ((fun (x : α ×ₗ β) => (ofLex x).1) '' s).IsPWO)
    (hβ : ∀ a, {y | toLex (a, y) ∈ s}.IsPWO) : s.IsPWO := by
  rw [IsPWO, partiallyWellOrderedOn_iff_exists_lt]
  intro f hf
  rw [isPWO_iff_exists_monotone_subseq] at hα
  obtain ⟨g, hg⟩ : ∃ (g : (ℕ ↪o ℕ)), Monotone fun n => (ofLex f (g n)).1 :=
    hα (fun n => (ofLex f n).1) (fun k => mem_image_of_mem (fun x => (ofLex x).1) (hf k))
  have hhg : ∀ n, (ofLex f (g 0)).1 ≤ (ofLex f (g n)).1 := fun n => hg n.zero_le
  by_cases hc : ∃ n, (ofLex f (g 0)).1 < (ofLex f (g n)).1
  · obtain ⟨n, hn⟩ := hc
    use (g 0), (g n)
    constructor
    · by_contra hx
      simp_all
    · exact Prod.Lex.toLex_le_toLex.mpr <| .inl hn
  · have hhc : ∀ n, (ofLex f (g 0)).1 = (ofLex f (g n)).1 := by
      intro n
      rw [not_exists] at hc
      exact (hhg n).eq_of_not_lt (hc n)
    obtain ⟨g', hg'⟩ : ∃ g' : ℕ ↪o ℕ, Monotone ((fun n ↦ (ofLex f (g (g' n))).2)) := by
      simp_rw [isPWO_iff_exists_monotone_subseq] at hβ
      apply hβ (ofLex f (g 0)).1 fun n ↦ (ofLex f (g n)).2
      intro n
      rw [hhc n]
      simpa using hf _
    use (g (g' 0)), (g (g' 1))
    suffices (f (g (g' 0))) ≤ (f (g (g' 1))) by simpa
    · refine Prod.Lex.toLex_le_toLex.mpr <| .inr ⟨?_, ?_⟩
      · exact (hhc (g' 0)).symm.trans (hhc (g' 1))
      · exact hg' (Nat.zero_le 1)
Partial Well-Ordering of Lexicographic Product via Projection and Fibers
Informal description
Let $\alpha$ be a partially ordered type and $\beta$ a preordered type. For a subset $s$ of the lexicographic product $\alpha \times_\ell \beta$, if: 1. The projection of $s$ onto $\alpha$ (i.e., $\{\pi_1(x) \mid x \in s\}$) is partially well-ordered, and 2. For every $a \in \alpha$, the fiber $\{y \in \beta \mid (a, y) \in s\}$ is partially well-ordered, then $s$ itself is partially well-ordered with respect to the lexicographic order on $\alpha \times_\ell \beta$.
Set.PartiallyWellOrderedOn.imageProdLex theorem
[Preorder α] [Preorder β] {s : Set (α ×ₗ β)} (hαβ : s.IsPWO) : ((fun (x : α ×ₗ β) => (ofLex x).1) '' s).IsPWO
Full source
theorem imageProdLex [Preorder α] [Preorder β] {s : Set (α ×ₗ β)}
    (hαβ : s.IsPWO) : ((fun (x : α ×ₗ β) => (ofLex x).1)'' s).IsPWO :=
  IsPWO.image_of_monotone hαβ Prod.Lex.monotone_fst
First Projection Preserves Partial Well-Ordering in Lexicographic Product
Informal description
Let $\alpha$ and $\beta$ be types equipped with preorders, and let $s$ be a subset of the lexicographic product $\alpha \times_\ell \beta$. If $s$ is partially well-ordered, then the image of $s$ under the first projection $\pi_1 : \alpha \times_\ell \beta \to \alpha$ is also partially well-ordered.
Set.PartiallyWellOrderedOn.fiberProdLex theorem
[Preorder α] [Preorder β] {s : Set (α ×ₗ β)} (hαβ : s.IsPWO) (a : α) : {y | toLex (a, y) ∈ s}.IsPWO
Full source
theorem fiberProdLex [Preorder α] [Preorder β] {s : Set (α ×ₗ β)}
    (hαβ : s.IsPWO) (a : α) : {y | toLex (a, y) ∈ s}.IsPWO := by
  let f : α ×ₗ β → β := fun x => (ofLex x).2
  have h : {y | toLex (a, y) ∈ s} = f '' (s ∩ (fun x ↦ (ofLex x).1) ⁻¹' {a}) := by
    ext x
    simp [f]
  rw [h]
  apply IsPWO.image_of_monotoneOn (hαβ.mono inter_subset_left)
  rintro b ⟨-, hb⟩ c ⟨-, hc⟩ hbc
  simp only [mem_preimage, mem_singleton_iff] at hb hc
  have : (ofLex b).1 < (ofLex c).1 ∨ (ofLex b).1 = (ofLex c).1 ∧ f b ≤ f c :=
    Prod.Lex.toLex_le_toLex.mp hbc
  simp_all only [lt_self_iff_false, true_and, false_or]
Partial Well-Ordering of Fibers in Lexicographic Product
Informal description
Let $\alpha$ and $\beta$ be types equipped with preorders, and let $s$ be a subset of the lexicographic product $\alpha \times_\ell \beta$ that is partially well-ordered. Then for any fixed element $a \in \alpha$, the fiber set $\{y \in \beta \mid (a, y) \in s\}$ is also partially well-ordered.
Set.PartiallyWellOrderedOn.ProdLex_iff theorem
[PartialOrder α] [Preorder β] {s : Set (α ×ₗ β)} : s.IsPWO ↔ ((fun (x : α ×ₗ β) ↦ (ofLex x).1) '' s).IsPWO ∧ ∀ a, {y | toLex (a, y) ∈ s}.IsPWO
Full source
theorem ProdLex_iff [PartialOrder α] [Preorder β] {s : Set (α ×ₗ β)} :
    s.IsPWO ↔
      ((fun (x : α ×ₗ β) ↦ (ofLex x).1) '' s).IsPWO ∧ ∀ a, {y | toLex (a, y) ∈ s}.IsPWO :=
  ⟨fun h ↦ ⟨imageProdLex h, fiberProdLex h⟩, fun h ↦ subsetProdLex h.1 h.2⟩
Characterization of Partial Well-Ordering for Lexicographic Products
Informal description
Let $\alpha$ be a partially ordered type and $\beta$ a preordered type. For a subset $s$ of the lexicographic product $\alpha \times_\ell \beta$, the following are equivalent: 1. $s$ is partially well-ordered (every infinite sequence in $s$ contains a monotone subsequence). 2. Both: - The projection of $s$ onto $\alpha$ (i.e., $\{\pi_1(x) \mid x \in s\}$) is partially well-ordered, and - For every $a \in \alpha$, the fiber $\{y \in \beta \mid (a, y) \in s\}$ is partially well-ordered.
Pi.isPWO theorem
{α : ι → Type*} [∀ i, LinearOrder (α i)] [∀ i, IsWellOrder (α i) (· < ·)] [Finite ι] (s : Set (∀ i, α i)) : s.IsPWO
Full source
/-- 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⟩ := (IsPWO.of_linearOrder univ).exists_monotone_subseq (f := (f · x)) mem_univ
    obtain ⟨g', hg'⟩ := ih (f ∘ g)
    refine ⟨g'.trans g, fun a b hab => (Finset.forall_mem_cons _ _).2 ?_⟩
    exact ⟨hg (OrderHomClass.mono g' hab), hg' hab⟩
Dickson's Lemma for Finite Product Spaces with Well-Ordered Components
Informal description
Let $\iota$ be a finite index set, and for each $i \in \iota$, let $\alpha_i$ be a linearly ordered type that is well-ordered with respect to the strict order $<$. Then any subset $s$ of the product space $\prod_{i \in \iota} \alpha_i$ is partially well-ordered (i.e., every infinite sequence in $s$ contains a monotone subsequence).
WellFounded.prod_lex_of_wellFoundedOn_fiber theorem
(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))
Full source
/-- 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.LexProd.Lex rα rβ on fun c => (f c, g c)) := by
  refine ((psigma_lex (wellFoundedOn_range.2 hα) fun a => hβ a).onFun
    (f := fun c => ⟨⟨_, c, rfl⟩, c, rfl⟩)).mono fun c c' h => ?_
  obtain h' | h' := Prod.lex_iff.1 h
  · exact PSigma.Lex.left _ _ h'
  · dsimp only [InvImage, (· on ·)] at h' ⊢
    convert PSigma.Lex.right (⟨_, c', rfl⟩ : range f) _ using 1; swap
    exacts [⟨c, h'.1⟩, PSigma.subtype_ext (Subtype.ext h'.1) rfl, h'.2]
Well-foundedness of Lexicographic Product under Fiberwise Conditions
Informal description
Let $\alpha$ and $\beta$ be types, and let $r_\alpha$ and $r_\beta$ be binary relations on $\alpha$ and $\beta$ respectively. Given functions $f \colon \gamma \to \alpha$ and $g \colon \gamma \to \beta$, suppose that: 1. The relation $r_\alpha$ composed with $f$ (i.e., $r_\alpha \text{ on } f$) is well-founded on $\gamma$. 2. For every $a \in \alpha$, the relation $r_\beta$ composed with $g$ is well-founded on the fiber $f^{-1}(\{a\})$. Then the lexicographic product relation $\text{Prod.Lex}\ r_\alpha\ r_\beta$ composed with $\lambda c \mapsto (f\ c, g\ c)$ is well-founded on $\gamma$.
Set.WellFoundedOn.prod_lex_of_wellFoundedOn_fiber theorem
(hα : s.WellFoundedOn (rα on f)) (hβ : ∀ a, (s ∩ f ⁻¹' { a }).WellFoundedOn (rβ on g)) : s.WellFoundedOn (Prod.Lex rα rβ on fun c => (f c, g c))
Full source
theorem Set.WellFoundedOn.prod_lex_of_wellFoundedOn_fiber (hα : s.WellFoundedOn (rα on f))
    (hβ : ∀ a, (s ∩ f ⁻¹' {a}).WellFoundedOn (rβ on g)) :
    s.WellFoundedOn (Prod.LexProd.Lex rα rβ on fun c => (f c, g c)) :=
  WellFounded.prod_lex_of_wellFoundedOn_fiber hα
    fun a ↦ ((hβ a).onFun (f := fun x => ⟨x, x.1.2, x.2⟩)).mono (fun _ _ h ↦ ‹_›)
Well-foundedness of Lexicographic Product on a Set under Fiberwise Conditions
Informal description
Let $\alpha$ and $\beta$ be types, $r_\alpha$ and $r_\beta$ be binary relations on $\alpha$ and $\beta$ respectively, $s$ be a subset of a type $\gamma$, and $f \colon \gamma \to \alpha$ and $g \colon \gamma \to \beta$ be functions. Suppose that: 1. The relation $r_\alpha$ composed with $f$ (i.e., $r_\alpha(f(x), f(y))$) is well-founded on $s$. 2. For every $a \in \alpha$, the relation $r_\beta$ composed with $g$ is well-founded on the intersection $s \cap f^{-1}(\{a\})$. Then the lexicographic product relation $\text{Lex}(r_\alpha, r_\beta)$ composed with $\lambda c \mapsto (f(c), g(c))$ is well-founded on $s$.
WellFounded.sigma_lex_of_wellFoundedOn_fiber theorem
(hι : WellFounded (rι on f)) (hπ : ∀ i, (f ⁻¹' { i }).WellFoundedOn (rπ i on g i)) : WellFounded (Sigma.Lex rι rπ on fun c => ⟨f c, g (f c) c⟩)
Full source
/-- Stronger version of `PSigma.lex_wf`. Instead of requiring `rπ on g` to be well-founded, we only
require it to be well-founded on fibers of `f`. -/
theorem WellFounded.sigma_lex_of_wellFoundedOn_fiber (hι : WellFounded (rι on f))
    (hπ : ∀ i, (f ⁻¹' {i}).WellFoundedOn (rπ i on g i)) :
    WellFounded (Sigma.LexSigma.Lex rι rπ on fun c => ⟨f c, g (f c) c⟩) := by
  refine ((psigma_lex (wellFoundedOn_range.2 hι) fun a => hπ a).onFun
    (f := fun c => ⟨⟨_, c, rfl⟩, c, rfl⟩)).mono fun c c' h => ?_
  obtain h' | ⟨h', h''⟩ := Sigma.lex_iff.1 h
  · exact PSigma.Lex.left _ _ h'
  · dsimp only [InvImage, (· on ·)] at h' ⊢
    convert PSigma.Lex.right (⟨_, c', rfl⟩ : range f) _ using 1; swap
    · exact ⟨c, h'⟩
    · exact PSigma.subtype_ext (Subtype.ext h') rfl
    · dsimp only [Subtype.coe_mk, Subrel, Order.Preimage] at *
      revert h'
      generalize f c = d
      rintro rfl h''
      exact h''
Well-foundedness of Lexicographic Order on Fibers with Well-founded Base and Fiber Relations
Informal description
Let $\alpha$ and $\beta$ be types, $f \colon \alpha \to \iota$ be a function, and for each $i \in \iota$, let $g_i \colon \alpha \to \beta_i$ be a function. Suppose that: 1. The relation $r_\iota$ composed with $f$ (i.e., $r_\iota \text{ on } f$) is well-founded on $\alpha$. 2. For each $i \in \iota$, the relation $r_\pi(i)$ composed with $g_i$ (i.e., $r_\pi(i) \text{ on } g_i$) is well-founded on the fiber $f^{-1}(\{i\})$. Then the lexicographical order $\text{Lex}(r_\iota, r_\pi)$ composed with the function $\lambda c \mapsto \langle f(c), g_{f(c)}(c) \rangle$ is well-founded on $\alpha$.
Set.WellFoundedOn.sigma_lex_of_wellFoundedOn_fiber theorem
(hι : s.WellFoundedOn (rι on f)) (hπ : ∀ i, (s ∩ f ⁻¹' { i }).WellFoundedOn (rπ i on g i)) : s.WellFoundedOn (Sigma.Lex rι rπ on fun c => ⟨f c, g (f c) c⟩)
Full source
theorem Set.WellFoundedOn.sigma_lex_of_wellFoundedOn_fiber (hι : s.WellFoundedOn (rι on f))
    (hπ : ∀ i, (s ∩ f ⁻¹' {i}).WellFoundedOn (rπ i on g i)) :
    s.WellFoundedOn (Sigma.LexSigma.Lex rι rπ on fun c => ⟨f c, g (f c) c⟩) := by
  show WellFounded (Sigma.LexSigma.Lex rι rπ on fun c : s => ⟨f c, g (f c) c⟩)
  exact
    @WellFounded.sigma_lex_of_wellFoundedOn_fiber _ s _ _ rπ (fun c => f c) (fun i c => g _ c) hι
      fun i => ((hπ i).onFun (f := fun x => ⟨x, x.1.2, x.2⟩)).mono (fun b c h => ‹_›)
Well-foundedness of Lexicographic Order on Fibers for a Set with Well-founded Base and Fiber Relations
Informal description
Let $s$ be a set in a type $\alpha$, $f \colon \alpha \to \iota$ a function, and for each $i \in \iota$, let $g_i \colon \alpha \to \beta_i$ be a function. Suppose that: 1. The relation $r_\iota$ composed with $f$ (i.e., $r_\iota(f(x), f(y))$) is well-founded on $s$. 2. For each $i \in \iota$, the relation $r_\pi(i)$ composed with $g_i$ (i.e., $r_\pi(i)(g_i(x), g_i(y))$) is well-founded on the intersection $s \cap f^{-1}(\{i\})$. Then the lexicographical order $\mathrm{Lex}(r_\iota, r_\pi)$ composed with the function $\lambda c \mapsto (f(c), g_{f(c)}(c))$ is well-founded on $s$.