doc-next-gen

Mathlib.Order.WellQuasiOrder

Module docstring

{"# Well quasi-orders

A well quasi-order (WQO) is a relation such that any infinite sequence contains an infinite subsequence of related elements. For a preorder, this is equivalent to having a well-founded order with no infinite antichains.

Main definitions

  • WellQuasiOrdered: a predicate for WQO unbundled relations
  • WellQuasiOrderedLE: a typeclass for a bundled WQO relation

Tags

wqo, pwo, well quasi-order, partial well order, dickson order "}

WellQuasiOrdered definition
(r : α → α → Prop) : Prop
Full source
/-- A well quasi-order or WQO is a relation such that any infinite sequence contains an infinite
monotonic subsequence, or equivalently, two elements `f m` and `f n` with `m < n` and
`r (f m) (f n)`.

For a preorder, this is equivalent to having a well-founded order with no infinite antichains.

Despite the nomenclature, we don't require the relation to be preordered. Moreover, a well
quasi-order will not in general be a well-order. -/
def WellQuasiOrdered (r : α → α → Prop) : Prop :=
  ∀ f :  → α, ∃ m n : ℕ, m < n ∧ r (f m) (f n)
Well quasi-order (WQO)
Informal description
A relation $r$ on a type $\alpha$ is called a *well quasi-order* if for every infinite sequence $(f_n)_{n \in \mathbb{N}}$ in $\alpha$, there exist indices $m < n$ such that $r(f_m, f_n)$ holds. Equivalently, this means that any infinite sequence contains an infinite monotonic subsequence with respect to $r$. Note that $r$ is not required to be a preorder, and a well quasi-order is not necessarily a well-order.
wellQuasiOrdered_of_isEmpty theorem
[IsEmpty α] (r : α → α → Prop) : WellQuasiOrdered r
Full source
theorem wellQuasiOrdered_of_isEmpty [IsEmpty α] (r : α → α → Prop) : WellQuasiOrdered r :=
  fun f ↦ isEmptyElim (f 0)
Empty Type Implies Well Quasi-Order for Any Relation
Informal description
For any empty type $\alpha$ and any relation $r$ on $\alpha$, the relation $r$ is a well quasi-order.
IsAntichain.finite_of_wellQuasiOrdered theorem
{s : Set α} (hs : IsAntichain r s) (hr : WellQuasiOrdered r) : s.Finite
Full source
theorem IsAntichain.finite_of_wellQuasiOrdered {s : Set α} (hs : IsAntichain r s)
    (hr : WellQuasiOrdered r) : s.Finite := by
  refine Set.not_infinite.1 fun hi => ?_
  obtain ⟨m, n, hmn, h⟩ := hr fun n => hi.natEmbedding _ n
  exact hmn.ne ((hi.natEmbedding _).injective <| Subtype.val_injective <|
    hs.eq (hi.natEmbedding _ m).2 (hi.natEmbedding _ n).2 h)
Finite Antichain Property of Well Quasi-Orders
Informal description
For any set $s$ in a type $\alpha$, if $s$ is an antichain with respect to a relation $r$ (i.e., no two distinct elements in $s$ are related by $r$) and $r$ is a well quasi-order, then $s$ must be finite.
Finite.wellQuasiOrdered theorem
(r : α → α → Prop) [Finite α] [IsRefl α r] : WellQuasiOrdered r
Full source
theorem Finite.wellQuasiOrdered (r : α → α → Prop) [Finite α] [IsRefl α r] :
    WellQuasiOrdered r := by
  intro f
  obtain ⟨m, n, h, hf⟩ := Set.finite_univ.exists_lt_map_eq_of_forall_mem (f := f)
    fun _ ↦ Set.mem_univ _
  exact ⟨m, n, h, hf ▸ refl _⟩
Finite Types with Reflexive Relations are Well Quasi-Orders
Informal description
For any finite type $\alpha$ and any reflexive relation $r$ on $\alpha$, the relation $r$ is a well quasi-order. That is, every infinite sequence in $\alpha$ contains an infinite subsequence where all elements are related under $r$.
WellQuasiOrdered.exists_monotone_subseq theorem
[IsPreorder α r] (h : WellQuasiOrdered r) (f : ℕ → α) : ∃ g : ℕ ↪o ℕ, ∀ m n, m ≤ n → r (f (g m)) (f (g n))
Full source
theorem WellQuasiOrdered.exists_monotone_subseq [IsPreorder α r] (h : WellQuasiOrdered r)
    (f :  → α) : ∃ g : ℕ ↪o ℕ, ∀ m n, m ≤ n → r (f (g m)) (f (g n)) := by
  obtain ⟨g, h1 | h2⟩ := exists_increasing_or_nonincreasing_subseq r f
  · refine ⟨g, fun m n hle => ?_⟩
    obtain hlt | rfl := hle.lt_or_eq
    exacts [h1 m n hlt, refl_of r _]
  · obtain ⟨m, n, hlt, hle⟩ := h (f ∘ g)
    cases h2 m n hlt hle
Existence of Monotone Subsequence in Well Quasi-Orders
Informal description
For any preorder relation $r$ on a type $\alpha$ that is a well quasi-order, and any sequence $f \colon \mathbb{N} \to \alpha$, 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)))$.
wellQuasiOrdered_iff_exists_monotone_subseq theorem
[IsPreorder α r] : WellQuasiOrdered r ↔ ∀ f : ℕ → α, ∃ g : ℕ ↪o ℕ, ∀ m n : ℕ, m ≤ n → r (f (g m)) (f (g n))
Full source
theorem wellQuasiOrdered_iff_exists_monotone_subseq [IsPreorder α r] :
    WellQuasiOrderedWellQuasiOrdered r ↔ ∀ f : ℕ → α, ∃ g : ℕ ↪o ℕ, ∀ m n : ℕ, m ≤ n → r (f (g m)) (f (g n)) := by
  constructor <;> intro h f
  · exact h.exists_monotone_subseq f
  · obtain ⟨g, gmon⟩ := h f
    exact ⟨_, _, g.strictMono Nat.zero_lt_one, gmon _ _ (Nat.zero_le 1)⟩
Characterization of Well Quasi-Orders via Monotone Subsequences
Informal description
For a preorder relation $r$ on a type $\alpha$, the following are equivalent: 1. $r$ is a well quasi-order (i.e., every infinite sequence in $\alpha$ contains an infinite subsequence where all elements are related under $r$). 2. For every sequence $f \colon \mathbb{N} \to \alpha$, 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$, meaning $r(f(g(m)), f(g(n)))$ holds for all $m \leq n$ in $\mathbb{N}$.
WellQuasiOrdered.prod theorem
[IsPreorder α r] (hr : WellQuasiOrdered r) (hs : WellQuasiOrdered s) : WellQuasiOrdered fun a b : α × β ↦ r a.1 b.1 ∧ s a.2 b.2
Full source
theorem WellQuasiOrdered.prod [IsPreorder α r] (hr : WellQuasiOrdered r) (hs : WellQuasiOrdered s) :
    WellQuasiOrdered fun a b : α × βr a.1 b.1 ∧ s a.2 b.2 := by
  intro f
  obtain ⟨g, h₁⟩ := hr.exists_monotone_subseq (Prod.fstProd.fst ∘ f)
  obtain ⟨m, n, h, hf⟩ := hs (Prod.sndProd.snd ∘ f ∘ g)
  exact ⟨g m, g n, g.strictMono h, h₁ _ _ h.le, hf⟩
Product of Well Quasi-Orders is a Well Quasi-Order
Informal description
Let $\alpha$ and $\beta$ be types with preorder relations $r$ and $s$ respectively. If $r$ and $s$ are well quasi-orders, then the product relation on $\alpha \times \beta$ defined by $(a_1, b_1) \leq (a_2, b_2)$ if and only if $r(a_1, a_2)$ and $s(b_1, b_2)$ is also a well quasi-order.
WellQuasiOrderedLE structure
(α : Type*) [LE α]
Full source
/-- A typeclass for an order with a well quasi-ordered `≤` relation.

Note that this is unlike `WellFoundedLT`, which instead takes a `<` relation. -/
@[mk_iff wellQuasiOrderedLE_def]
class WellQuasiOrderedLE (α : Type*) [LE α] where
  wqo : @WellQuasiOrdered α (· ≤ ·)
Well quasi-ordered `≤` relation
Informal description
A structure representing a typeclass for a well quasi-ordered `≤` relation on a type `α`. A well quasi-order is a relation where any infinite sequence contains an infinite subsequence of related elements. For a preorder, this is equivalent to having a well-founded order with no infinite antichains.
wellQuasiOrdered_le theorem
[LE α] [h : WellQuasiOrderedLE α] : @WellQuasiOrdered α (· ≤ ·)
Full source
theorem wellQuasiOrdered_le [LE α] [h : WellQuasiOrderedLE α] : @WellQuasiOrdered α (· ≤ ·) :=
  h.wqo
Well quasi-ordered $\leq$ relation implies well quasi-order property
Informal description
For any type $\alpha$ equipped with a well quasi-order $\leq$ (i.e., an instance of `WellQuasiOrderedLE α`), the relation $\leq$ is a well quasi-order on $\alpha$. In other words, if $\alpha$ has a well quasi-ordered $\leq$ relation, then every infinite sequence in $\alpha$ contains an infinite subsequence of elements that are pairwise related under $\leq$.
Finite.to_wellQuasiOrderedLE instance
[Finite α] : WellQuasiOrderedLE α
Full source
instance (priority := 100) Finite.to_wellQuasiOrderedLE [Finite α] : WellQuasiOrderedLE α where
  wqo := Finite.wellQuasiOrdered _
Finite Types are Well Quasi-Ordered
Informal description
Every finite type $\alpha$ with a reflexive relation $\leq$ is well quasi-ordered. That is, for any infinite sequence in $\alpha$, there exists an infinite subsequence where all elements are related under $\leq$.
WellQuasiOrderedLE.to_wellFoundedLT instance
[WellQuasiOrderedLE α] : WellFoundedLT α
Full source
instance (priority := 100) WellQuasiOrderedLE.to_wellFoundedLT [WellQuasiOrderedLE α] :
    WellFoundedLT α := by
  rw [WellFoundedLT, isWellFounded_iff, RelEmbedding.wellFounded_iff_no_descending_seq]
  refine ⟨fun f ↦ ?_⟩
  obtain ⟨a, b, h, hf⟩ := wellQuasiOrdered_le f
  exact (f.map_rel_iff.2 h).not_le hf
Well-Foundedness of Strict Order from Well Quasi-Order
Informal description
For any type $\alpha$ equipped with a well quasi-order $\leq$, the strict order $<$ derived from $\leq$ is well-founded. In other words, if $\alpha$ has a well quasi-ordered $\leq$ relation, then there are no infinite strictly decreasing sequences with respect to the strict order $<$ associated with $\leq$.
WellQuasiOrdered.wellFounded theorem
{α : Type*} {r : α → α → Prop} [IsPreorder α r] (h : WellQuasiOrdered r) : WellFounded fun a b ↦ r a b ∧ ¬r b a
Full source
theorem WellQuasiOrdered.wellFounded {α : Type*} {r : α → α → Prop} [IsPreorder α r]
    (h : WellQuasiOrdered r) : WellFounded fun a b ↦ r a b ∧ ¬ r b a := by
  let _ : Preorder α :=
    { le := r
      le_refl := refl_of r
      le_trans := fun _ _ _ => trans_of r }
  have : WellQuasiOrderedLE α := ⟨h⟩
  exact wellFounded_lt
Well-foundedness of the strict order associated to a well quasi-order
Informal description
Let $\alpha$ be a type with a preorder relation $r$. If $r$ is a well quasi-order, then the associated strict order defined by $a < b \Leftrightarrow r(a,b) \land \neg r(b,a)$ is well-founded.
WellQuasiOrderedLE.finite_of_isAntichain theorem
[WellQuasiOrderedLE α] {s : Set α} (h : IsAntichain (· ≤ ·) s) : s.Finite
Full source
theorem WellQuasiOrderedLE.finite_of_isAntichain [WellQuasiOrderedLE α] {s : Set α}
    (h : IsAntichain (· ≤ ·) s) : s.Finite :=
  h.finite_of_wellQuasiOrdered wellQuasiOrdered_le
Finite Antichain Property for Well Quasi-Orders
Informal description
Let $\alpha$ be a type equipped with a well quasi-order $\leq$ (i.e., an instance of `WellQuasiOrderedLE α`). For any subset $s \subseteq \alpha$ that forms an antichain with respect to $\leq$ (i.e., no two distinct elements in $s$ are comparable under $\leq$), the set $s$ must be finite.
wellQuasiOrderedLE_iff theorem
: WellQuasiOrderedLE α ↔ WellFoundedLT α ∧ ∀ s : Set α, IsAntichain (· ≤ ·) s → s.Finite
Full source
/-- A preorder is well quasi-ordered iff it's well-founded and has no infinite antichains. -/
theorem wellQuasiOrderedLE_iff :
    WellQuasiOrderedLEWellQuasiOrderedLE α ↔ WellFoundedLT α ∧ ∀ s : Set α, IsAntichain (· ≤ ·) s → s.Finite := by
  refine ⟨fun h ↦ ⟨h.to_wellFoundedLT, fun s ↦ h.finite_of_isAntichain⟩,
    fun ⟨hwf, hc⟩ ↦ ⟨fun f ↦ ?_⟩⟩
  obtain ⟨g, h1 | h2⟩ := exists_increasing_or_nonincreasing_subseq (· > ·) f
  · exfalso
    apply RelEmbedding.not_wellFounded_of_decreasing_seq _ hwf.wf
    exact (RelEmbedding.ofMonotone _ h1).swap
  · contrapose! hc
    refine ⟨Set.range (f ∘ g), ?_, ?_⟩
    · rintro _ ⟨m, rfl⟩ _ ⟨n, rfl⟩ _ hf
      obtain h | rfl | h := lt_trichotomy m n
      · exact hc _ _ (g.strictMono h) hf
      · contradiction
      · exact h2 _ _ h (lt_of_le_not_le hf (hc _ _ (g.strictMono h)))
    · refine Set.infinite_range_of_injective fun m n (hf : f (g m) = f (g n)) ↦ ?_
      obtain h | rfl | h := lt_trichotomy m n <;>
        (first | rfl | cases (hf ▸ hc _ _ (g.strictMono h)) le_rfl)
Characterization of Well Quasi-Orders: Well-Foundedness and Finite Antichains
Informal description
A preorder $\leq$ on a type $\alpha$ is a well quasi-order if and only if the associated strict order $<$ is well-founded and every antichain in $\alpha$ (i.e., every subset where no two distinct elements are comparable under $\leq$) is finite.
instWellQuasiOrderedLEProd instance
[WellQuasiOrderedLE α] [Preorder β] [WellQuasiOrderedLE β] : WellQuasiOrderedLE (α × β)
Full source
instance [WellQuasiOrderedLE α] [Preorder β] [WellQuasiOrderedLE β] : WellQuasiOrderedLE (α × β) :=
  ⟨wellQuasiOrdered_le.prod wellQuasiOrdered_le⟩
Product of Well Quasi-Ordered Sets is Well Quasi-Ordered
Informal description
For any types $\alpha$ and $\beta$ equipped with well quasi-orders $\leq_\alpha$ and $\leq_\beta$ respectively, the product type $\alpha \times \beta$ is also a well quasi-ordered set under the componentwise order relation $(a_1, b_1) \leq (a_2, b_2)$ if and only if $a_1 \leq_\alpha a_2$ and $b_1 \leq_\beta b_2$.
wellQuasiOrderedLE_iff_wellFoundedLT theorem
: WellQuasiOrderedLE α ↔ WellFoundedLT α
Full source
/-- A linear WQO is the same thing as a well-order. -/
theorem wellQuasiOrderedLE_iff_wellFoundedLT : WellQuasiOrderedLEWellQuasiOrderedLE α ↔ WellFoundedLT α := by
  rw [wellQuasiOrderedLE_iff, and_iff_left_iff_imp]
  exact fun _ s hs ↦ hs.subsingleton.finite
Well quasi-order equivalence to well-founded strict order
Informal description
A preorder $\leq$ on a type $\alpha$ is a well quasi-order if and only if the associated strict order $<$ is well-founded.