doc-next-gen

Mathlib.Order.RelSeries

Module docstring

{"# Series of a relation

If r is a relation on α then a relation series of length n is a series a_0, a_1, ..., a_n such that r a_i a_{i+1} for all i < n

"}

RelSeries structure
Full source
/--
Let `r` be a relation on `α`, a relation series of `r` of length `n` is a series
`a_0, a_1, ..., a_n` such that `r a_i a_{i+1}` for all `i < n`
-/
structure RelSeries where
  /-- The number of inequalities in the series -/
  length : 
  /-- The underlying function of a relation series -/
  toFun : Fin (length + 1) → α
  /-- Adjacent elements are related -/
  step : ∀ (i : Fin length), r (toFun (Fin.castSucc i)) (toFun i.succ)
Relation Series
Informal description
Given a relation `r` on a type `α`, a relation series of length `n` is a sequence of elements `a₀, a₁, ..., aₙ` in `α` such that for every `i < n`, the relation `r aᵢ a_{i+1}` holds. In other words, each consecutive pair in the sequence is related by `r`.
RelSeries.instCoeFunForallFinHAddNatLengthOfNat instance
: CoeFun (RelSeries r) (fun x ↦ Fin (x.length + 1) → α)
Full source
instance : CoeFun (RelSeries r) (fun x ↦ Fin (x.length + 1) → α) :=
{ coe := RelSeries.toFun }
Relation Series as Functions on Finite Indices
Informal description
For any relation `r` on a type `α`, a relation series can be viewed as a function from `Fin (n + 1)` to `α`, where `n` is the length of the series. This means each relation series of length `n` corresponds to a sequence of `n + 1` elements in `α`.
RelSeries.singleton definition
(a : α) : RelSeries r
Full source
/--
For any type `α`, each term of `α` gives a relation series with the right most index to be 0.
-/
@[simps!] def singleton (a : α) : RelSeries r where
  length := 0
  toFun _ := a
  step := Fin.elim0
Singleton relation series
Informal description
For any element $a$ of type $\alpha$, the function `RelSeries.singleton` constructs a relation series of length $0$ where every term in the series is equal to $a$. Since the length is $0$, there are no steps to verify in the relation.
RelSeries.instIsEmpty instance
[IsEmpty α] : IsEmpty (RelSeries r)
Full source
instance [IsEmpty α] : IsEmpty (RelSeries r) where
  false x := IsEmpty.false (x 0)
Empty Relation Series on Empty Types
Informal description
For any empty type $\alpha$ and relation $r$ on $\alpha$, the type of relation series of $r$ is also empty.
RelSeries.instInhabited instance
[Inhabited α] : Inhabited (RelSeries r)
Full source
instance [Inhabited α] : Inhabited (RelSeries r) where
  default := singleton r default
Inhabited Relation Series on Inhabited Types
Informal description
For any inhabited type $\alpha$ and relation $r$ on $\alpha$, the type of relation series of $r$ is inhabited.
RelSeries.instNonempty instance
[Nonempty α] : Nonempty (RelSeries r)
Full source
instance [Nonempty α] : Nonempty (RelSeries r) :=
  Nonempty.map (singleton r) inferInstance
Nonempty Relation Series on Nonempty Types
Informal description
For any nonempty type $\alpha$ and relation $r$ on $\alpha$, the type of relation series of $r$ is nonempty.
RelSeries.ext theorem
{x y : RelSeries r} (length_eq : x.length = y.length) (toFun_eq : x.toFun = y.toFun ∘ Fin.cast (by rw [length_eq])) : x = y
Full source
@[ext (iff := false)]
lemma ext {x y : RelSeries r} (length_eq : x.length = y.length)
    (toFun_eq : x.toFun = y.toFun ∘ Fin.cast (by rw [length_eq])) : x = y := by
  rcases x with ⟨nx, fx⟩
  dsimp only at length_eq toFun_eq
  subst length_eq toFun_eq
  rfl
Extensionality of Relation Series
Informal description
Let $x$ and $y$ be two relation series of a relation $r$ on a type $\alpha$. If $x$ and $y$ have the same length and their underlying functions satisfy $x_i = y_i$ for all indices $i$ (after appropriately casting the indices to account for the equal lengths), then $x = y$.
RelSeries.rel_of_lt theorem
[IsTrans α r] (x : RelSeries r) {i j : Fin (x.length + 1)} (h : i < j) : r (x i) (x j)
Full source
lemma rel_of_lt [IsTrans α r] (x : RelSeries r) {i j : Fin (x.length + 1)} (h : i < j) :
    r (x i) (x j) :=
  (Fin.liftFun_iff_succ r).mpr x.step h
Transitivity of Relation Series under Strict Order
Informal description
Let $\alpha$ be a type equipped with a transitive relation $r$, and let $x$ be a relation series of length $n$ for $r$. For any indices $i, j$ in $\text{Fin}(n+1)$ such that $i < j$, the relation $r(x_i, x_j)$ holds.
RelSeries.rel_or_eq_of_le theorem
[IsTrans α r] (x : RelSeries r) {i j : Fin (x.length + 1)} (h : i ≤ j) : r (x i) (x j) ∨ x i = x j
Full source
lemma rel_or_eq_of_le [IsTrans α r] (x : RelSeries r) {i j : Fin (x.length + 1)} (h : i ≤ j) :
    r (x i) (x j) ∨ x i = x j :=
  (Fin.lt_or_eq_of_le h).imp (x.rel_of_lt ·) (by rw [·])
Transitivity or Equality in Relation Series for Non-Strict Order
Informal description
Let $\alpha$ be a type equipped with a transitive relation $r$, and let $x$ be a relation series of length $n$ for $r$. For any indices $i, j$ in $\{0, \dots, n\}$ such that $i \leq j$, either $r(x_i, x_j)$ holds or $x_i = x_j$.
RelSeries.ofLE definition
(x : RelSeries r) {s : Rel α α} (h : r ≤ s) : RelSeries s
Full source
/--
Given two relations `r, s` on `α` such that `r ≤ s`, any relation series of `r` induces a relation
series of `s`
-/
@[simps!]
def ofLE (x : RelSeries r) {s : Rel α α} (h : r ≤ s) : RelSeries s where
  length := x.length
  toFun := x
  step _ := h _ _ <| x.step _
Relation series lifting
Informal description
Given a relation series `x` of length `n` for a relation `r` on a type `α`, and another relation `s` on `α` such that `r ≤ s` (i.e., `r a b` implies `s a b` for all `a, b ∈ α`), the function `RelSeries.ofLE` constructs a relation series for `s` with the same length and elements as `x`, where each consecutive pair satisfies `s` since they satisfy `r`.
RelSeries.coe_ofLE theorem
(x : RelSeries r) {s : Rel α α} (h : r ≤ s) : (x.ofLE h : _ → _) = x
Full source
lemma coe_ofLE (x : RelSeries r) {s : Rel α α} (h : r ≤ s) :
    (x.ofLE h : _ → _) = x := rfl
Equality of Underlying Functions in Relation Series Lifting
Informal description
Given a relation series $x$ for a relation $r$ on a type $\alpha$, and another relation $s$ on $\alpha$ such that $r \leq s$ (i.e., $r(a,b)$ implies $s(a,b)$ for all $a, b \in \alpha$), the underlying function of the lifted series $x.\text{ofLE}\ h$ is equal to $x$ itself.
RelSeries.toList definition
(x : RelSeries r) : List α
Full source
/-- Every relation series gives a list -/
def toList (x : RelSeries r) : List α := List.ofFn x
List representation of a relation series
Informal description
Given a relation series `x` for a relation `r` on a type `α`, the function maps `x` to the list `[a₀, a₁, ..., aₙ]` where `a₀, a₁, ..., aₙ` are the elements of the series.
RelSeries.length_toList theorem
(x : RelSeries r) : x.toList.length = x.length + 1
Full source
@[simp]
lemma length_toList (x : RelSeries r) : x.toList.length = x.length + 1 :=
  List.length_ofFn
Length of Relation Series List Representation
Informal description
For any relation series $x$ of a relation $r$ on a type $\alpha$, the length of the list representation of $x$ is equal to the length of the series plus one, i.e., $\text{length}(x.\text{toList}) = x.\text{length} + 1$.
RelSeries.toList_chain' theorem
(x : RelSeries r) : x.toList.Chain' r
Full source
lemma toList_chain' (x : RelSeries r) : x.toList.Chain' r := by
  rw [List.chain'_iff_get]
  intros i h
  convert x.step ⟨i, by simpa [toList] using h⟩ <;> apply List.get_ofFn
Relation Series List Satisfies Chain Condition
Informal description
For any relation series $x$ of a relation $r$ on a type $\alpha$, the list representation of $x$ satisfies the chain condition with respect to $r$, meaning that for every consecutive pair $(a_i, a_{i+1})$ in the list, the relation $r(a_i, a_{i+1})$ holds.
RelSeries.toList_ne_nil theorem
(x : RelSeries r) : x.toList ≠ []
Full source
lemma toList_ne_nil (x : RelSeries r) : x.toList ≠ [] := fun m =>
  List.eq_nil_iff_forall_not_mem.mp m (x 0) <| List.mem_ofFn.mpr ⟨_, rfl⟩
Nonemptiness of Relation Series List Representation
Informal description
For any relation series $x$ of a relation $r$ on a type $\alpha$, the list representation of $x$ is nonempty.
RelSeries.fromListChain' definition
(x : List α) (x_ne_nil : x ≠ []) (hx : x.Chain' r) : RelSeries r
Full source
/-- Every nonempty list satisfying the chain condition gives a relation series -/
@[simps]
def fromListChain' (x : List α) (x_ne_nil : x ≠ []) (hx : x.Chain' r) : RelSeries r where
  length := x.length - 1
  toFun i := x[Fin.cast (Nat.succ_pred_eq_of_pos <| List.length_pos_iff.mpr x_ne_nil) i]
  step i := List.chain'_iff_get.mp hx i i.2
Relation series from a nonempty chain list
Informal description
Given a nonempty list `x` of elements in type `α` and a proof that `x` satisfies the chain condition with respect to relation `r` (i.e., for every consecutive pair `(x_i, x_{i+1})` in the list, `r x_i x_{i+1}` holds), the function constructs a relation series of length `n-1` (where `n` is the length of the list) where each element in the series corresponds to an element in the list, and the relation `r` holds between consecutive elements in the series.
RelSeries.Equiv definition
: RelSeries r ≃ {x : List α | x ≠ [] ∧ x.Chain' r}
Full source
/-- Relation series of `r` and nonempty list of `α` satisfying `r`-chain condition bijectively
corresponds to each other. -/
protected def Equiv : RelSeriesRelSeries r ≃ {x : List α | x ≠ [] ∧ x.Chain' r} where
  toFun x := ⟨_, x.toList_ne_nil, x.toList_chain'⟩
  invFun x := fromListChain' _ x.2.1 x.2.2
  left_inv x := ext (by simp [toList]) <| by ext; dsimp; apply List.get_ofFn
  right_inv x := by
    refine Subtype.ext (List.ext_get ?_ fun n hn1 _ => by dsimp; apply List.get_ofFn)
    have := Nat.succ_pred_eq_of_pos <| List.length_pos_iff.mpr x.2.1
    simp_all [toList]
Equivalence between relation series and nonempty chain lists
Informal description
There is a bijective correspondence between relation series of `r` and nonempty lists of elements in `α` that satisfy the chain condition with respect to `r`. Specifically: 1. For any relation series `x` of `r`, the list `[a₀, a₁, ..., aₙ]` obtained from `x` is nonempty and satisfies `r aᵢ a_{i+1}` for all consecutive pairs. 2. Conversely, any nonempty list `[a₀, a₁, ..., aₙ]` satisfying `r aᵢ a_{i+1}` for all consecutive pairs corresponds to a unique relation series of `r`. This establishes an equivalence between the type `RelSeries r` and the subtype of nonempty chain lists `{x : List α | x ≠ [] ∧ x.Chain' r}`.
RelSeries.toList_injective theorem
: Function.Injective (RelSeries.toList (r := r))
Full source
lemma toList_injective : Function.Injective (RelSeries.toList (r := r)) :=
  fun _ _ h ↦ (RelSeries.Equiv).injective <| Subtype.ext h
Injectivity of Relation Series to List Conversion
Informal description
The function that maps a relation series of `r` to its corresponding list of elements is injective. That is, for any two relation series `x` and `y` of a relation `r` on a type `α`, if their list representations are equal (`RelSeries.toList x = RelSeries.toList y`), then `x = y`.
Rel.FiniteDimensional structure
Full source
/-- A relation `r` is said to be finite dimensional iff there is a relation series of `r` with the
  maximum length. -/
@[mk_iff]
class FiniteDimensional : Prop where
  /-- A relation `r` is said to be finite dimensional iff there is a relation series of `r` with the
    maximum length. -/
  exists_longest_relSeries : ∃ x : RelSeries r, ∀ y : RelSeries r, y.length ≤ x.length
Finite dimensional relation
Informal description
A relation `r` on a type `α` is called finite dimensional if there exists a relation series of `r` with the maximum possible length. A relation series of length `n` is a sequence `a₀, a₁, ..., aₙ` in `α` such that `r aᵢ a_{i+1}` holds for all `i < n`.
Rel.InfiniteDimensional structure
Full source
/-- A relation `r` is said to be infinite dimensional iff there exists relation series of arbitrary
  length. -/
@[mk_iff]
class InfiniteDimensional : Prop where
  /-- A relation `r` is said to be infinite dimensional iff there exists relation series of
    arbitrary length. -/
  exists_relSeries_with_length : ∀ n : , ∃ x : RelSeries r, x.length = n
Infinite dimensional relation
Informal description
A relation `r` on a type `α` is called infinite dimensional if there exists a relation series of arbitrary length for `r`. That is, for every natural number `n`, there exists a sequence `a₀, a₁, ..., aₙ` of elements in `α` such that `r aᵢ a_{i+1}` holds for all `i < n`.
RelSeries.longestOf definition
[r.FiniteDimensional] : RelSeries r
Full source
/-- The longest relational series when a relation is finite dimensional -/
protected noncomputable def longestOf [r.FiniteDimensional] : RelSeries r :=
  Rel.FiniteDimensional.exists_longest_relSeries.choose
Longest relation series of a finite dimensional relation
Informal description
Given a finite dimensional relation `r` on a type `α`, the longest relation series of `r` is a sequence `a₀, a₁, ..., aₙ` in `α` such that `r aᵢ a_{i+1}` holds for all `i < n`, and this series has the maximum possible length among all such series for `r`.
RelSeries.length_le_length_longestOf theorem
[r.FiniteDimensional] (x : RelSeries r) : x.length ≤ (RelSeries.longestOf r).length
Full source
lemma length_le_length_longestOf [r.FiniteDimensional] (x : RelSeries r) :
    x.length ≤ (RelSeries.longestOf r).length :=
  Rel.FiniteDimensional.exists_longest_relSeries.choose_spec _
Length Bound for Relation Series in Finite-Dimensional Relations
Informal description
For any finite-dimensional relation $r$ on a type $\alpha$ and any relation series $x$ of $r$, the length of $x$ is less than or equal to the length of the longest relation series of $r$.
RelSeries.withLength definition
[r.InfiniteDimensional] (n : ℕ) : RelSeries r
Full source
/-- A relation series with length `n` if the relation is infinite dimensional -/
protected noncomputable def withLength [r.InfiniteDimensional] (n : ) : RelSeries r :=
  (Rel.InfiniteDimensional.exists_relSeries_with_length n).choose
Relation series of length $n$ for an infinite dimensional relation
Informal description
Given an infinite dimensional relation $r$ on a type $\alpha$ and a natural number $n$, there exists a relation series $a_0, a_1, \dots, a_n$ of length $n$ such that $r(a_i, a_{i+1})$ holds for all $i < n$.
RelSeries.length_withLength theorem
[r.InfiniteDimensional] (n : ℕ) : (RelSeries.withLength r n).length = n
Full source
@[simp] lemma length_withLength [r.InfiniteDimensional] (n : ) :
    (RelSeries.withLength r n).length = n :=
  (Rel.InfiniteDimensional.exists_relSeries_with_length n).choose_spec
Length of Relation Series Constructed from Infinite Dimensional Relation
Informal description
For any infinite dimensional relation $r$ on a type $\alpha$ and any natural number $n$, the length of the relation series constructed by `RelSeries.withLength r n` is equal to $n$.
RelSeries.nonempty_of_infiniteDimensional theorem
[r.InfiniteDimensional] : Nonempty α
Full source
/-- If a relation on `α` is infinite dimensional, then `α` is nonempty. -/
lemma nonempty_of_infiniteDimensional [r.InfiniteDimensional] : Nonempty α :=
  ⟨RelSeries.withLength r 0 0⟩
Nonemptiness of Type with Infinite Dimensional Relation
Informal description
If a relation $r$ on a type $\alpha$ is infinite dimensional (i.e., there exists a relation series of arbitrary length for $r$), then $\alpha$ is nonempty.
RelSeries.nonempty_of_finiteDimensional theorem
[r.FiniteDimensional] : Nonempty α
Full source
lemma nonempty_of_finiteDimensional [r.FiniteDimensional] : Nonempty α := by
  obtain ⟨p, _⟩ := (Rel.finiteDimensional_iff r).mp ‹_›
  exact ⟨p 0⟩
Nonemptiness of Type with Finite Dimensional Relation
Informal description
If a relation $r$ on a type $\alpha$ is finite dimensional (i.e., there exists a relation series of $r$ with maximum possible length), then $\alpha$ is nonempty.
RelSeries.membership instance
: Membership α (RelSeries r)
Full source
instance membership : Membership α (RelSeries r) :=
  ⟨Function.swap (· ∈ Set.range ·)⟩
Membership in Relation Series
Informal description
For any relation $r$ on a type $\alpha$, the collection of relation series of $r$ has a membership relation where an element $x \in \alpha$ belongs to a relation series $s$ if and only if $x$ appears in the sequence of elements forming $s$.
RelSeries.mem_def theorem
: x ∈ s ↔ x ∈ Set.range s
Full source
theorem mem_def : x ∈ sx ∈ s ↔ x ∈ Set.range s := Iff.rfl
Membership in Relation Series Equals Range Membership
Informal description
An element $x$ belongs to a relation series $s$ if and only if $x$ is in the range of $s$ (i.e., $x$ appears in the sequence of elements forming $s$).
RelSeries.subsingleton_of_length_eq_zero theorem
(hs : s.length = 0) : {x | x ∈ s}.Subsingleton
Full source
theorem subsingleton_of_length_eq_zero (hs : s.length = 0) : {x | x ∈ s}.Subsingleton := by
  rintro - ⟨i, rfl⟩ - ⟨j, rfl⟩
  congr!
  exact finCongr (by rw [hs, zero_add]) |>.injective <| Subsingleton.elim (α := Fin 1) _ _
Relation Series of Length Zero is Subsingleton
Informal description
For a relation series $s$ of length $0$, the set $\{x \mid x \in s\}$ is a subsingleton (i.e., contains at most one element).
RelSeries.length_ne_zero_of_nontrivial theorem
(h : {x | x ∈ s}.Nontrivial) : s.length ≠ 0
Full source
theorem length_ne_zero_of_nontrivial (h : {x | x ∈ s}.Nontrivial) : s.length ≠ 0 :=
  fun hs ↦ h.not_subsingleton <| subsingleton_of_length_eq_zero hs
Nontrivial Relation Series Has Nonzero Length
Informal description
For any relation series $s$ of a relation $r$ on a type $\alpha$, if the set $\{x \mid x \in s\}$ is nontrivial (i.e., contains at least two distinct elements), then the length of $s$ is not zero.
RelSeries.length_pos_of_nontrivial theorem
(h : {x | x ∈ s}.Nontrivial) : 0 < s.length
Full source
theorem length_pos_of_nontrivial (h : {x | x ∈ s}.Nontrivial) : 0 < s.length :=
  Nat.pos_iff_ne_zero.mpr <| length_ne_zero_of_nontrivial h
Nontrivial Relation Series Has Positive Length
Informal description
For any relation series $s$ of a relation $r$ on a type $\alpha$, if the set $\{x \mid x \in s\}$ is nontrivial (i.e., contains at least two distinct elements), then the length of $s$ is strictly positive.
RelSeries.length_ne_zero theorem
(irrefl : Irreflexive r) : s.length ≠ 0 ↔ {x | x ∈ s}.Nontrivial
Full source
theorem length_ne_zero (irrefl : Irreflexive r) : s.length ≠ 0s.length ≠ 0 ↔ {x | x ∈ s}.Nontrivial := by
  refine ⟨fun h ↦ ⟨s 0, by simp [mem_def], s 1, by simp [mem_def], fun rid ↦ irrefl (s 0) ?_⟩,
    length_ne_zero_of_nontrivial⟩
  nth_rw 2 [rid]
  convert s.step ⟨0, by omega⟩
  ext
  simpa [Nat.pos_iff_ne_zero]
Nonzero Length of Relation Series Equivalent to Nontriviality under Irreflexive Relation
Informal description
For a relation $r$ on a type $\alpha$ that is irreflexive (i.e., $\forall x \in \alpha, \neg r x x$), and a relation series $s$ of $r$, the length of $s$ is nonzero if and only if the set $\{x \mid x \in s\}$ is nontrivial (i.e., contains at least two distinct elements).
RelSeries.length_pos theorem
(irrefl : Irreflexive r) : 0 < s.length ↔ {x | x ∈ s}.Nontrivial
Full source
theorem length_pos (irrefl : Irreflexive r) : 0 < s.length ↔ {x | x ∈ s}.Nontrivial :=
  Nat.pos_iff_ne_zero.trans <| length_ne_zero irrefl
Positive Length of Relation Series Equivalent to Nontriviality under Irreflexive Relation
Informal description
For an irreflexive relation $r$ on a type $\alpha$ (i.e., $\forall x \in \alpha, \neg r x x$) and a relation series $s$ of $r$, the length of $s$ is positive if and only if the set $\{x \mid x \in s\}$ is nontrivial (i.e., contains at least two distinct elements).
RelSeries.length_eq_zero theorem
(irrefl : Irreflexive r) : s.length = 0 ↔ {x | x ∈ s}.Subsingleton
Full source
lemma length_eq_zero (irrefl : Irreflexive r) : s.length = 0 ↔ {x | x ∈ s}.Subsingleton := by
  rw [← not_ne_iff, length_ne_zero irrefl, Set.not_nontrivial_iff]
Zero-Length Relation Series Characterized by Subsingleton Membership under Irreflexive Relation
Informal description
For an irreflexive relation $r$ on a type $\alpha$ (i.e., $\forall x \in \alpha, \neg r x x$) and a relation series $s$ of $r$, the length of $s$ is zero if and only if the set $\{x \mid x \in s\}$ is a subsingleton (i.e., contains at most one element).
RelSeries.head definition
(x : RelSeries r) : α
Full source
/-- Start of a series, i.e. for `a₀ -r→ a₁ -r→ ... -r→ aₙ`, its head is `a₀`.

Since a relation series is assumed to be non-empty, this is well defined. -/
def head (x : RelSeries r) : α := x 0
Head of a relation series
Informal description
Given a relation `r` on a type `α` and a relation series `x` of length `n` (i.e., a sequence `a₀ → a₁ → ... → aₙ` where each `aᵢ` is related to `a_{i+1}` by `r`), the head of the series is the first element `a₀` in the sequence.
RelSeries.last definition
(x : RelSeries r) : α
Full source
/-- End of a series, i.e. for `a₀ -r→ a₁ -r→ ... -r→ aₙ`, its last element is `aₙ`.

Since a relation series is assumed to be non-empty, this is well defined. -/
def last (x : RelSeries r) : α := x <| Fin.last _
Last element of a relation series
Informal description
Given a relation `r` on a type `α` and a relation series `x` of length `n` (i.e., a sequence `a₀ → a₁ → ... → aₙ` where each `aᵢ` is related to `a_{i+1}` by `r`), the last element of the series is the final element `aₙ` in the sequence.
RelSeries.apply_last theorem
(x : RelSeries r) : x (Fin.last <| x.length) = x.last
Full source
lemma apply_last (x : RelSeries r) : x (Fin.last <| x.length) = x.last := rfl
Last Element of Relation Series at Final Index
Informal description
For any relation series $x$ of length $n$ with respect to a relation $r$ on a type $\alpha$, the element at the last index of the series (i.e., $x(\text{last}(n))$) is equal to the last element of the series $x.\text{last}$.
RelSeries.head_mem theorem
(x : RelSeries r) : x.head ∈ x
Full source
lemma head_mem (x : RelSeries r) : x.head ∈ x := ⟨_, rfl⟩
Head Element Membership in Relation Series
Informal description
For any relation series $x$ of a relation $r$ on a type $\alpha$, the head element $x_0$ of the series is a member of the sequence $x$.
RelSeries.last_mem theorem
(x : RelSeries r) : x.last ∈ x
Full source
lemma last_mem (x : RelSeries r) : x.last ∈ x := ⟨_, rfl⟩
Last Element Membership in Relation Series
Informal description
For any relation series $x$ of a relation $r$ on a type $\alpha$, the last element of $x$ is a member of $x$.
RelSeries.head_singleton theorem
{r : Rel α α} (x : α) : (singleton r x).head = x
Full source
@[simp]
lemma head_singleton {r : Rel α α} (x : α) : (singleton r x).head = x := by simp [singleton, head]
Head of Singleton Relation Series is the Element Itself
Informal description
For any relation $r$ on a type $\alpha$ and any element $x \in \alpha$, the head of the singleton relation series constructed from $x$ is equal to $x$ itself. That is, if we form a relation series consisting only of $x$, then its first (and only) element is $x$.
RelSeries.last_singleton theorem
{r : Rel α α} (x : α) : (singleton r x).last = x
Full source
@[simp]
lemma last_singleton {r : Rel α α} (x : α) : (singleton r x).last = x := by simp [singleton, last]
Last Element of Singleton Relation Series Equals Its Input
Informal description
For any relation $r$ on a type $\alpha$ and any element $x \in \alpha$, the last element of the singleton relation series (of length 0) constructed from $x$ is equal to $x$ itself. That is, $\text{last}(\text{singleton}(r, x)) = x$.
RelSeries.append definition
(p q : RelSeries r) (connect : r p.last q.head) : RelSeries r
Full source
/--
If `a₀ -r→ a₁ -r→ ... -r→ aₙ` and `b₀ -r→ b₁ -r→ ... -r→ bₘ` are two strict series
such that `r aₙ b₀`, then there is a chain of length `n + m + 1` given by
`a₀ -r→ a₁ -r→ ... -r→ aₙ -r→ b₀ -r→ b₁ -r→ ... -r→ bₘ`.
-/
@[simps length]
def append (p q : RelSeries r) (connect : r p.last q.head) : RelSeries r where
  length := p.length + q.length + 1
  toFun := Fin.appendFin.append p q ∘ Fin.cast (by omega)
  step i := by
    obtain hi | rfl | hi :=
      lt_trichotomy i (Fin.castLE (by omega) (Fin.last _ : Fin (p.length + 1)))
    · convert p.step ⟨i.1, hi⟩ <;> convert Fin.append_left p q _ <;> rfl
    · convert connect
      · convert Fin.append_left p q _
      · convert Fin.append_right p q _; rfl
    · set x := _; set y := _
      change r (Fin.append p q x) (Fin.append p q y)
      have hx : x = Fin.natAdd _ ⟨i - (p.length + 1), Nat.sub_lt_left_of_lt_add hi <|
          i.2.trans <| by omega⟩ := by
        ext; dsimp [x, y]; rw [Nat.add_sub_cancel']; exact hi
      have hy : y = Fin.natAdd _ ⟨i - p.length, Nat.sub_lt_left_of_lt_add (le_of_lt hi)
          (by exact i.2)⟩ := by
        ext
        dsimp
        conv_rhs => rw [Nat.add_comm p.length 1, add_assoc,
          Nat.add_sub_cancel' <| le_of_lt (show p.length < i.1 from hi), add_comm]
        rfl
      rw [hx, Fin.append_right, hy, Fin.append_right]
      convert q.step ⟨i - (p.length + 1), Nat.sub_lt_left_of_lt_add hi <| by omega⟩
      rw [Fin.succ_mk, Nat.sub_eq_iff_eq_add (le_of_lt hi : p.length ≤ i),
        Nat.add_assoc _ 1, add_comm 1, Nat.sub_add_cancel]
      exact hi
Concatenation of relation series with connection
Informal description
Given two relation series `p` and `q` of lengths `m` and `n` respectively, and a connection `connect : r p.last q.head` between the last element of `p` and the first element of `q`, the function `RelSeries.append` constructs a new relation series of length `m + n + 1` by concatenating `p` and `q` with the connection `connect` in between. More precisely, the resulting series is the sequence `p₀ → p₁ → ... → pₘ → q₀ → q₁ → ... → qₙ`, where each consecutive pair is related by `r`.
RelSeries.append_apply_left theorem
(p q : RelSeries r) (connect : r p.last q.head) (i : Fin (p.length + 1)) : p.append q connect ((i.castAdd (q.length + 1)).cast (by dsimp; omega)) = p i
Full source
lemma append_apply_left (p q : RelSeries r) (connect : r p.last q.head)
    (i : Fin (p.length + 1)) :
    p.append q connect ((i.castAdd (q.length + 1)).cast (by dsimp; omega)) = p i := by
  delta append
  simp only [Function.comp_apply]
  convert Fin.append_left _ _ _
Preservation of Left Series Elements in Relation Series Concatenation
Informal description
Let $r$ be a relation on a type $\alpha$, and let $p$ and $q$ be relation series of lengths $m$ and $n$ respectively, such that $r$ connects the last element of $p$ to the first element of $q$. For any index $i$ in the first series $p$ (i.e., $i \in \text{Fin}(m+1)$), the element at position $i$ in the concatenated series $p \cdot q$ (formed by appending $q$ to $p$ with the connection) is equal to the element at position $i$ in $p$. More formally, if $\text{append}(p, q, \text{connect})$ is the concatenated series, then for any $i \in \text{Fin}(m+1)$, we have: \[ \text{append}(p, q, \text{connect})\big(\text{castAdd}_{n+1}(i)\big) = p(i) \] where $\text{castAdd}_{n+1}(i)$ embeds $i$ into $\text{Fin}(m + n + 2)$.
RelSeries.append_apply_right theorem
(p q : RelSeries r) (connect : r p.last q.head) (i : Fin (q.length + 1)) : p.append q connect (i.natAdd p.length + 1) = q i
Full source
lemma append_apply_right (p q : RelSeries r) (connect : r p.last q.head)
    (i : Fin (q.length + 1)) :
    p.append q connect (i.natAdd p.length + 1) = q i := by
  delta append
  simp only [Fin.coe_natAdd, Nat.cast_add, Function.comp_apply]
  convert Fin.append_right _ _ _
  ext
  simp only [Fin.coe_cast, Fin.coe_natAdd]
  conv_rhs => rw [add_assoc, add_comm 1, ← add_assoc]
  change _ % _ = _
  simp only [Nat.add_mod_mod, Nat.mod_add_mod, Nat.one_mod, Nat.mod_succ_eq_iff_lt]
  omega
Right Component Preservation in Relation Series Concatenation
Informal description
Given two relation series `p` and `q` of lengths `m` and `n` respectively, and a connection `connect : r p.last q.head` between the last element of `p` and the first element of `q`, the concatenated series `p.append q connect` satisfies that for any index `i` in the finite set `Fin (q.length + 1)`, the element at position `i.natAdd p.length + 1` in the concatenated series is equal to `q i`.
RelSeries.head_append theorem
(p q : RelSeries r) (connect : r p.last q.head) : (p.append q connect).head = p.head
Full source
@[simp] lemma head_append (p q : RelSeries r) (connect : r p.last q.head) :
    (p.append q connect).head = p.head :=
  append_apply_left p q connect 0
Head Preservation in Relation Series Concatenation
Informal description
Let $r$ be a relation on a type $\alpha$, and let $p$ and $q$ be relation series of lengths $m$ and $n$ respectively, such that $r$ connects the last element of $p$ to the first element of $q$. Then the head of the concatenated series $p \cdot q$ (formed by appending $q$ to $p$ with the connection) is equal to the head of $p$. More formally, if $\text{append}(p, q, \text{connect})$ is the concatenated series, then: \[ \text{head}(\text{append}(p, q, \text{connect})) = \text{head}(p) \]
RelSeries.last_append theorem
(p q : RelSeries r) (connect : r p.last q.head) : (p.append q connect).last = q.last
Full source
@[simp] lemma last_append (p q : RelSeries r) (connect : r p.last q.head) :
    (p.append q connect).last = q.last := by
  delta last
  convert append_apply_right p q connect (Fin.last _)
  ext
  change _ = _ % _
  simp only [append_length, Fin.val_last, Fin.natAdd_last, Nat.one_mod, Nat.mod_add_mod,
    Nat.mod_succ]
Last Element Preservation in Relation Series Concatenation
Informal description
Given two relation series $p$ and $q$ for a relation $r$ on a type $\alpha$, and a connection $r(p_{\text{last}}, q_{\text{head}})$ between the last element of $p$ and the first element of $q$, the last element of the concatenated series $p \cdot q$ is equal to the last element of $q$.
RelSeries.map definition
(p : RelSeries r) (f : r →r s) : RelSeries s
Full source
/--
For two types `α, β` and relation on them `r, s`, if `f : α → β` preserves relation `r`, then an
`r`-series can be pushed out to an `s`-series by
`a₀ -r→ a₁ -r→ ... -r→ aₙ ↦ f a₀ -s→ f a₁ -s→ ... -s→ f aₙ`
-/
@[simps length]
def map (p : RelSeries r) (f : r →r s) : RelSeries s where
  length := p.length
  toFun := f.1.comp p
  step := (f.2 <| p.step ·)
Mapping of relation series under a relation homomorphism
Informal description
Given a relation series `p` of length `n` for a relation `r` on type `α`, and a relation homomorphism `f` from `r` to a relation `s` on type `β`, the mapped series `p.map f` is a relation series of length `n` for `s` where each element `a_i` in the original series is mapped to `f(a_i)` in the new series, preserving the relation steps.
RelSeries.map_apply theorem
(p : RelSeries r) (f : r →r s) (i : Fin (p.length + 1)) : p.map f i = f (p i)
Full source
@[simp] lemma map_apply (p : RelSeries r) (f : r →r s) (i : Fin (p.length + 1)) :
    p.map f i = f (p i) := rfl
Element-wise Application of Relation Homomorphism to Series
Informal description
Let $r$ be a relation on a type $\alpha$ and $s$ be a relation on a type $\beta$. Given a relation series $p$ of length $n$ for $r$ and a relation homomorphism $f : r \to_r s$, for any index $i$ in the finite set $\{0, \ldots, n\}$, the $i$-th element of the mapped series $p.map\ f$ is equal to $f$ applied to the $i$-th element of $p$, i.e., $(p.map\ f)_i = f(p_i)$.
RelSeries.head_map theorem
(p : RelSeries r) (f : r →r s) : (p.map f).head = f p.head
Full source
@[simp] lemma head_map (p : RelSeries r) (f : r →r s) : (p.map f).head = f p.head := rfl
Preservation of Head under Relation Series Mapping
Informal description
Given a relation `r` on a type `α` and a relation series `p` of length `n` for `r`, and a relation homomorphism `f` from `r` to a relation `s` on a type `β`, the head of the mapped series `p.map f` is equal to `f` applied to the head of `p`. That is, $(p.map f).head = f(p.head)$.
RelSeries.last_map theorem
(p : RelSeries r) (f : r →r s) : (p.map f).last = f p.last
Full source
@[simp] lemma last_map (p : RelSeries r) (f : r →r s) : (p.map f).last = f p.last := rfl
Preservation of Last Element under Relation Series Mapping
Informal description
Given a relation `r` on a type `α` and a relation series `p` of length `n` for `r`, and a relation homomorphism `f` from `r` to a relation `s` on a type `β`, the last element of the mapped series `p.map f` is equal to `f` applied to the last element of `p`. In other words, $(p.\text{map} f).\text{last} = f(p.\text{last})$.
RelSeries.insertNth definition
(p : RelSeries r) (i : Fin p.length) (a : α) (prev_connect : r (p (Fin.castSucc i)) a) (connect_next : r a (p i.succ)) : RelSeries r
Full source
/--
If `a₀ -r→ a₁ -r→ ... -r→ aₙ` is an `r`-series and `a` is such that
`aᵢ -r→ a -r→ a_ᵢ₊₁`, then
`a₀ -r→ a₁ -r→ ... -r→ aᵢ -r→ a -r→ aᵢ₊₁ -r→ ... -r→ aₙ`
is another `r`-series
-/
@[simps]
def insertNth (p : RelSeries r) (i : Fin p.length) (a : α)
    (prev_connect : r (p (Fin.castSucc i)) a) (connect_next : r a (p i.succ)) : RelSeries r where
  length := p.length + 1
  toFun := (Fin.castSucc i.succ).insertNth a p
  step m := by
    set x := _; set y := _; change r x y
    obtain hm | hm | hm := lt_trichotomy m.1 i.1
    · convert p.step ⟨m, hm.trans i.2⟩
      · show Fin.insertNth _ _ _ _ = _
        rw [Fin.insertNth_apply_below]
        pick_goal 2
        · exact hm.trans (lt_add_one _)
        simp
      · show Fin.insertNth _ _ _ _ = _
        rw [Fin.insertNth_apply_below]
        pick_goal 2
        · change m.1 + 1 < i.1 + 1; rwa [add_lt_add_iff_right]
        simp; rfl
    · rw [show x = p m from show Fin.insertNth _ _ _ _ = _ by
        rw [Fin.insertNth_apply_below]
        pick_goal 2
        · show m.1 < i.1 + 1; exact hm ▸ lt_add_one _
        simp]
      convert prev_connect
      · ext; exact hm
      · change Fin.insertNth _ _ _ _ = _
        rw [show m.succ = i.succ.castSucc by ext; change _ + 1 = _ + 1; rw [hm],
          Fin.insertNth_apply_same]
    · rw [Nat.lt_iff_add_one_le, le_iff_lt_or_eq] at hm
      obtain hm | hm := hm
      · convert p.step ⟨m.1 - 1, Nat.sub_lt_right_of_lt_add (by omega) m.2⟩
        · change Fin.insertNth _ _ _ _ = _
          rw [Fin.insertNth_apply_above (h := hm)]
          aesop
        · change Fin.insertNth _ _ _ _ = _
          rw [Fin.insertNth_apply_above]
          swap
          · exact hm.trans (lt_add_one _)
          simp only [Fin.val_succ, Fin.pred_succ, eq_rec_constant, Fin.succ_mk]
          congr
          exact Fin.ext <| Eq.symm <| Nat.succ_pred_eq_of_pos (lt_trans (Nat.zero_lt_succ _) hm)
      · convert connect_next
        · change Fin.insertNth _ _ _ _ = _
          rw [show m.castSucc = i.succ.castSucc from Fin.ext hm.symm, Fin.insertNth_apply_same]
        · change Fin.insertNth _ _ _ _ = _
          rw [Fin.insertNth_apply_above]
          swap
          · change i.1 + 1 < m.1 + 1; omega
          simp only [Fin.pred_succ, eq_rec_constant]
          congr; ext; exact hm.symm
Insertion into a relation series
Informal description
Given a relation `r` on a type `α`, a relation series `p` of length `n`, an index `i < n`, and an element `a ∈ α` such that `r (p i) a` and `r a (p (i+1))`, the function `RelSeries.insertNth` constructs a new relation series of length `n+1` by inserting `a` between `p i` and `p (i+1)`. More precisely, the new series is defined as: - For indices `j ≤ i`, it equals `p j`. - At index `i+1`, it equals `a`. - For indices `j > i+1`, it equals `p (j-1)`. The new series maintains the relation property: consecutive elements in the series are related by `r`.
RelSeries.reverse definition
(p : RelSeries r) : RelSeries (fun (a b : α) ↦ r b a)
Full source
/--
A relation series `a₀ -r→ a₁ -r→ ... -r→ aₙ` of `r` gives a relation series of the reverse of `r`
by reversing the series `aₙ ←r- aₙ₋₁ ←r- ... ←r- a₁ ←r- a₀`.
-/
@[simps length]
def reverse (p : RelSeries r) : RelSeries (fun (a b : α) ↦ r b a) where
  length := p.length
  toFun := p ∘ Fin.rev
  step i := by
    rw [Function.comp_apply, Function.comp_apply]
    have hi : i.1 + 1 ≤ p.length := by omega
    convert p.step ⟨p.length - (i.1 + 1), Nat.sub_lt_self (by omega) hi⟩
    · ext; simp
    · ext
      simp only [Fin.val_rev, Fin.coe_castSucc, Fin.val_succ]
      omega
Reversed relation series
Informal description
Given a relation `r` on a type `α` and a relation series `p` of `r`, the reverse of `p` is a relation series of the reverse relation `(fun a b ↦ r b a)`. The reversed series is obtained by reversing the order of elements in the original series, i.e., the `i`-th element of the reversed series is the `(n - i)`-th element of the original series, where `n` is the length of the series.
RelSeries.reverse_apply theorem
(p : RelSeries r) (i : Fin (p.length + 1)) : p.reverse i = p i.rev
Full source
@[simp] lemma reverse_apply (p : RelSeries r) (i : Fin (p.length + 1)) :
    p.reverse i = p i.rev := rfl
Element Correspondence in Reversed Relation Series
Informal description
Given a relation `r` on a type `α`, a relation series `p` of `r`, and an index `i` in the range `[0, p.length]`, the `i`-th element of the reversed series `p.reverse` is equal to the `(p.length - i)`-th element of the original series `p`.
RelSeries.last_reverse theorem
(p : RelSeries r) : p.reverse.last = p.head
Full source
@[simp] lemma last_reverse (p : RelSeries r) : p.reverse.last = p.head := by
  simp [RelSeries.last, RelSeries.head]
Last Element of Reversed Relation Series Equals Head of Original Series
Informal description
For any relation series $p$ of a relation $r$ on a type $\alpha$, the last element of the reversed series $p.\mathrm{reverse}$ is equal to the head of the original series $p$.
RelSeries.head_reverse theorem
(p : RelSeries r) : p.reverse.head = p.last
Full source
@[simp] lemma head_reverse (p : RelSeries r) : p.reverse.head = p.last := by
  simp [RelSeries.last, RelSeries.head]
Head of Reversed Relation Series Equals Last Element
Informal description
For any relation series `p` of a relation `r` on a type `α`, the head of the reversed series `p.reverse` is equal to the last element of the original series `p`.
RelSeries.reverse_reverse theorem
{r : Rel α α} (p : RelSeries r) : p.reverse.reverse = p
Full source
@[simp] lemma reverse_reverse {r : Rel α α} (p : RelSeries r) : p.reverse.reverse = p := by
  ext <;> simp
Double Reversal of Relation Series Yields Original Series
Informal description
For any relation series $p$ of a relation $r$ on a type $\alpha$, reversing the series twice yields the original series, i.e., $(p.\mathrm{reverse}).\mathrm{reverse} = p$.
RelSeries.cons definition
(p : RelSeries r) (newHead : α) (rel : r newHead p.head) : RelSeries r
Full source
/--
Given a series `a₀ -r→ a₁ -r→ ... -r→ aₙ` and an `a` such that `a₀ -r→ a` holds, there is
a series of length `n+1`: `a -r→ a₀ -r→ a₁ -r→ ... -r→ aₙ`.
-/
@[simps! length]
def cons (p : RelSeries r) (newHead : α) (rel : r newHead p.head) : RelSeries r :=
  (singleton r newHead).append p rel
Prepending an element to a relation series
Informal description
Given a relation series `p` of a relation `r` on a type `α`, a new element `newHead` of type `α`, and a proof `rel` that `r newHead p.head` holds (i.e., the new element is related to the head of the series), the function `RelSeries.cons` constructs a new relation series by prepending `newHead` to `p`. More precisely, the resulting series is the sequence `newHead → p₀ → p₁ → ... → pₙ`, where each consecutive pair is related by `r`. This is equivalent to concatenating a singleton series `[newHead]` with `p` using the connection `rel`.
RelSeries.head_cons theorem
(p : RelSeries r) (newHead : α) (rel : r newHead p.head) : (p.cons newHead rel).head = newHead
Full source
@[simp] lemma head_cons (p : RelSeries r) (newHead : α) (rel : r newHead p.head) :
    (p.cons newHead rel).head = newHead := rfl
Head of Prepended Relation Series Equals New Element
Informal description
Given a relation series $p$ of a relation $r$ on a type $\alpha$, a new element $\mathrm{newHead} \in \alpha$, and a proof that $r(\mathrm{newHead}, p.\mathrm{head})$ holds, the head of the new series obtained by prepending $\mathrm{newHead}$ to $p$ is equal to $\mathrm{newHead}$. In other words, $(p.\mathrm{cons}~\mathrm{newHead}~rel).\mathrm{head} = \mathrm{newHead}$.
RelSeries.last_cons theorem
(p : RelSeries r) (newHead : α) (rel : r newHead p.head) : (p.cons newHead rel).last = p.last
Full source
@[simp] lemma last_cons (p : RelSeries r) (newHead : α) (rel : r newHead p.head) :
    (p.cons newHead rel).last = p.last := by
  delta cons
  rw [last_append]
Last Element Preservation in Prepended Relation Series
Informal description
Given a relation series $p$ of a relation $r$ on a type $\alpha$, a new element $a \in \alpha$, and a proof that $r(a, p.\mathrm{head})$ holds, the last element of the new series obtained by prepending $a$ to $p$ is equal to the last element of $p$. In other words, $(p.\mathrm{cons}(a, rel)).\mathrm{last} = p.\mathrm{last}$.
RelSeries.cons_cast_succ theorem
(s : RelSeries r) (a : α) (h : r a s.head) (i : Fin (s.length + 1)) : (s.cons a h) (.cast (by simp) (.succ i)) = s i
Full source
lemma cons_cast_succ (s : RelSeries r) (a : α) (h : r a s.head) (i : Fin (s.length + 1)) :
    (s.cons a h) (.cast (by simp) (.succ i)) = s i := by
  dsimp [cons]
  convert append_apply_right (singleton r a) s h i
  ext
  show i.1 + 1 = _ % _
  simpa using (Nat.mod_eq_of_lt (by simp)).symm
Element Preservation in Prepended Relation Series
Informal description
Let $r$ be a relation on a type $\alpha$, and let $s$ be a relation series of length $n$ (i.e., a sequence $a_0 \to a_1 \to \dots \to a_n$ where $r(a_i, a_{i+1})$ holds for all $i < n$). Given an element $a \in \alpha$ and a proof $h : r(a, s.\mathrm{head})$, the prepended series $s.\mathrm{cons}\,a\,h$ satisfies $(s.\mathrm{cons}\,a\,h)(\mathrm{cast}\,(\mathrm{succ}\,i)) = s(i)$ for any index $i \in \mathrm{Fin}(n+1)$.
RelSeries.snoc definition
(p : RelSeries r) (newLast : α) (rel : r p.last newLast) : RelSeries r
Full source
/--
Given a series `a₀ -r→ a₁ -r→ ... -r→ aₙ` and an `a` such that `aₙ -r→ a` holds, there is
a series of length `n+1`: `a₀ -r→ a₁ -r→ ... -r→ aₙ -r→ a`.
-/
@[simps! length]
def snoc (p : RelSeries r) (newLast : α) (rel : r p.last newLast) : RelSeries r :=
  p.append (singleton r newLast) rel
Appending an element to a relation series
Informal description
Given a relation series `p` of length `n` (i.e., a sequence `a₀ → a₁ → ... → aₙ` where each consecutive pair is related by `r`), an element `newLast` of type `α`, and a proof `rel` that `r aₙ newLast` holds, the function `RelSeries.snoc` constructs a new relation series of length `n+1` by appending `newLast` to the end of `p`. The resulting series is the sequence `a₀ → a₁ → ... → aₙ → newLast`, where each consecutive pair is related by `r`.
RelSeries.head_snoc theorem
(p : RelSeries r) (newLast : α) (rel : r p.last newLast) : (p.snoc newLast rel).head = p.head
Full source
@[simp] lemma head_snoc (p : RelSeries r) (newLast : α) (rel : r p.last newLast) :
    (p.snoc newLast rel).head = p.head := by
  delta snoc; rw [head_append]
Head Preservation in Relation Series Extension
Informal description
Let $r$ be a relation on a type $\alpha$, and let $p$ be a relation series of length $n$ (i.e., a sequence $a_0 \to a_1 \to \dots \to a_n$ where each $a_i$ is related to $a_{i+1}$ by $r$). Given an element $\text{newLast} \in \alpha$ and a proof $\text{rel}$ that $r(a_n, \text{newLast})$ holds, the head of the extended series $p.\text{snoc}(\text{newLast}, \text{rel})$ (formed by appending $\text{newLast}$ to $p$) is equal to the head of the original series $p$. In other words, appending an element to a relation series preserves its head element.
RelSeries.last_snoc theorem
(p : RelSeries r) (newLast : α) (rel : r p.last newLast) : (p.snoc newLast rel).last = newLast
Full source
@[simp] lemma last_snoc (p : RelSeries r) (newLast : α) (rel : r p.last newLast) :
    (p.snoc newLast rel).last = newLast := last_append _ _ _
Last Element of Extended Relation Series Equals Appended Element
Informal description
Given a relation series $p$ for a relation $r$ on a type $\alpha$, an element $\text{newLast} \in \alpha$, and a proof that $r(p_{\text{last}}, \text{newLast})$ holds, the last element of the extended series $p \cdot \text{newLast}$ (formed by appending $\text{newLast}$ to $p$) is equal to $\text{newLast}$.
RelSeries.snoc_cast_castSucc theorem
(s : RelSeries r) (a : α) (h : r s.last a) (i : Fin (s.length + 1)) : (s.snoc a h) (.cast (by simp) (.castSucc i)) = s i
Full source
lemma snoc_cast_castSucc (s : RelSeries r) (a : α) (h : r s.last a) (i : Fin (s.length + 1)) :
    (s.snoc a h) (.cast (by simp) (.castSucc i)) = s i :=
  append_apply_left s (singleton r a) h i
Preservation of Original Elements in Extended Relation Series
Informal description
Let $r$ be a relation on a type $\alpha$, and let $s$ be a relation series of length $n$ (i.e., a sequence $a_0 \to a_1 \to \dots \to a_n$ where each $a_i$ is related to $a_{i+1}$ by $r$). Given an element $a \in \alpha$ and a proof $h$ that $r(s.\text{last}, a)$ holds, then for any index $i \in \text{Fin}(n+1)$, the element at position $\text{castSucc}(i)$ in the extended series $s.\text{snoc}(a, h)$ (formed by appending $a$ to $s$) is equal to the element at position $i$ in the original series $s$. In other words, if we extend the series $s$ by appending $a$ (with the relation $h$), then the elements at the original indices (via $\text{castSucc}$) remain unchanged.
RelSeries.last_snoc' theorem
(p : RelSeries r) (newLast : α) (rel : r p.last newLast) : p.snoc newLast rel (Fin.last (p.length + 1)) = newLast
Full source
@[simp] lemma last_snoc' (p : RelSeries r) (newLast : α) (rel : r p.last newLast) :
    p.snoc newLast rel (Fin.last (p.length + 1)) = newLast := last_append _ _ _
Last Element of Extended Relation Series Equals Appended Element
Informal description
Let $r$ be a relation on a type $\alpha$, and let $p$ be a relation series of length $n$ (i.e., a sequence $a_0 \to a_1 \to \dots \to a_n$ where each $r(a_i, a_{i+1})$ holds for $i < n$). For any element $\text{newLast} \in \alpha$ such that $r(a_n, \text{newLast})$ holds, the last element of the extended series $p.\text{snoc}(\text{newLast}, \text{rel})$ (which has length $n+1$) is equal to $\text{newLast}$.
RelSeries.snoc_castSucc theorem
(s : RelSeries r) (a : α) (connect : r s.last a) (i : Fin (s.length + 1)) : snoc s a connect (Fin.castSucc i) = s i
Full source
@[simp] lemma snoc_castSucc (s : RelSeries r) (a : α) (connect : r s.last a)
    (i : Fin (s.length + 1)) : snoc s a connect (Fin.castSucc i) = s i :=
  Fin.append_left _ _ i
Preservation of Series Elements under Extension via $\text{snoc}$ and $\text{castSucc}$
Informal description
Let $s$ be a relation series of length $n$ for a relation $r$ on a type $\alpha$, let $a \in \alpha$ be an element such that $r(s_{\text{last}}, a)$ holds, and let $i$ be an index in $\text{Fin}\, (n + 1)$. Then the $i$-th element of the extended series $\text{snoc}\, s\, a\, \text{connect}$ (formed by appending $a$ to $s$) is equal to the $i$-th element of the original series $s$ when $i$ is considered as an index in $\text{Fin}\, n$ via the embedding $\text{castSucc}$.
RelSeries.mem_snoc theorem
{p : RelSeries r} {newLast : α} {rel : r p.last newLast} {x : α} : x ∈ p.snoc newLast rel ↔ x ∈ p ∨ x = newLast
Full source
lemma mem_snoc {p : RelSeries r} {newLast : α} {rel : r p.last newLast} {x : α} :
    x ∈ p.snoc newLast relx ∈ p.snoc newLast rel ↔ x ∈ p ∨ x = newLast := by
  simp only [snoc, append, singleton_length, Nat.add_zero, Nat.reduceAdd, Fin.cast_refl,
    Function.comp_id, mem_def, id_eq, Set.mem_range]
  constructor
  · rintro ⟨i, rfl⟩
    exact Fin.lastCases (Or.inr <| Fin.append_right _ _ 0) (fun i => Or.inl ⟨⟨i.1, i.2⟩,
      (Fin.append_left _ _ _).symm⟩) i
  · intro h
    rcases h with (⟨i, rfl⟩ | rfl)
    · exact ⟨i.castSucc, Fin.append_left _ _ _⟩
    · exact ⟨Fin.last _, Fin.append_right _ _ 0⟩
Membership in Relation Series Extension: $x \in p.\mathrm{snoc}(\mathrm{newLast}) \leftrightarrow x \in p \lor x = \mathrm{newLast}$
Informal description
Let $r$ be a relation on a type $\alpha$, and let $p$ be a relation series of $r$ (a sequence $a_0 \to a_1 \to \dots \to a_n$ where $r(a_i, a_{i+1})$ holds for each $i < n$). For any new element $\mathrm{newLast} \in \alpha$ such that $r(a_n, \mathrm{newLast})$ holds, and for any $x \in \alpha$, we have that $x$ belongs to the extended series $p.\mathrm{snoc}(\mathrm{newLast}, \mathrm{rel})$ if and only if $x$ belongs to $p$ or $x = \mathrm{newLast}$.
RelSeries.tail definition
(p : RelSeries r) (len_pos : p.length ≠ 0) : RelSeries r
Full source
/--
If a series `a₀ -r→ a₁ -r→ ...` has positive length, then `a₁ -r→ ...` is another series
-/
@[simps]
def tail (p : RelSeries r) (len_pos : p.length ≠ 0) : RelSeries r where
  length := p.length - 1
  toFun := Fin.tailFin.tail p ∘ (Fin.cast <| Nat.succ_pred_eq_of_pos <| Nat.pos_of_ne_zero len_pos)
  step i := p.step ⟨i.1 + 1, Nat.lt_pred_iff.mp i.2⟩
Tail of a relation series
Informal description
Given a relation series `p` of length `n` (with `n ≠ 0`), the tail of `p` is a new relation series of length `n-1` obtained by removing the first element of `p`. Specifically, for each index `i` in the tail series, the corresponding element is `p (i+1)`, and the relation `r` holds between consecutive elements as in the original series.
RelSeries.head_tail theorem
(p : RelSeries r) (len_pos : p.length ≠ 0) : (p.tail len_pos).head = p 1
Full source
@[simp] lemma head_tail (p : RelSeries r) (len_pos : p.length ≠ 0) :
    (p.tail len_pos).head = p 1 := by
  show p (Fin.succ _) = p 1
  congr
  ext
  show (1 : ) = (1 : ) % _
  rw [Nat.mod_eq_of_lt]
  simpa only [lt_add_iff_pos_left, Nat.pos_iff_ne_zero]
Head of Tail Equals Second Element in Relation Series
Informal description
For any relation series $p$ of length $n \neq 0$ with respect to a relation $r$ on a type $\alpha$, the head of the tail of $p$ is equal to the second element of $p$, i.e., $(\mathrm{tail}\,p).\mathrm{head} = p(1)$.
RelSeries.last_tail theorem
(p : RelSeries r) (len_pos : p.length ≠ 0) : (p.tail len_pos).last = p.last
Full source
@[simp] lemma last_tail (p : RelSeries r) (len_pos : p.length ≠ 0) :
    (p.tail len_pos).last = p.last := by
  show p _ = p _
  congr
  ext
  simp only [tail_length, Fin.val_succ, Fin.coe_cast, Fin.val_last]
  exact Nat.succ_pred_eq_of_pos (by simpa [Nat.pos_iff_ne_zero] using len_pos)
Tail of Relation Series Preserves Last Element
Informal description
For any relation series $p$ of length $n \neq 0$ with respect to a relation $r$ on a type $\alpha$, the last element of the tail of $p$ is equal to the last element of $p$ itself. In other words, if $p$ is a sequence $a_0 \xrightarrow{r} a_1 \xrightarrow{r} \cdots \xrightarrow{r} a_n$, then the tail of $p$ is the sequence $a_1 \xrightarrow{r} \cdots \xrightarrow{r} a_n$, and we have $\text{last}(\text{tail}(p)) = \text{last}(p) = a_n$.
RelSeries.eraseLast definition
(p : RelSeries r) : RelSeries r
Full source
/--
If a series ``a₀ -r→ a₁ -r→ ... -r→ aₙ``, then `a₀ -r→ a₁ -r→ ... -r→ aₙ₋₁` is
another series -/
@[simps]
def eraseLast (p : RelSeries r) : RelSeries r where
  length := p.length - 1
  toFun i := p ⟨i, lt_of_lt_of_le i.2 (Nat.succ_le_succ (Nat.sub_le _ _))⟩
  step i := p.step ⟨i, lt_of_lt_of_le i.2 (Nat.sub_le _ _)⟩
Relation series with last element removed
Informal description
Given a relation series `p` of length `n` for a relation `r` on type `α`, the operation `eraseLast` returns a new relation series of length `n-1` consisting of the first `n-1` elements of `p`, where each consecutive pair still satisfies the relation `r`. Specifically, for each index `i` in the new series, the element is `p i`, and the relation `r (p i) (p (i+1))` holds for all `i < n-1`.
RelSeries.head_eraseLast theorem
(p : RelSeries r) : p.eraseLast.head = p.head
Full source
@[simp] lemma head_eraseLast (p : RelSeries r) : p.eraseLast.head = p.head := rfl
Head Preservation Under Last Element Removal in Relation Series
Informal description
For any relation series $p$ of a relation $r$ on a type $\alpha$, the head of the series obtained by removing the last element of $p$ is equal to the head of the original series $p$. In other words, if $p$ is a sequence $a_0, a_1, \dots, a_n$, then the first element of the sequence $a_0, a_1, \dots, a_{n-1}$ is $a_0$.
RelSeries.last_eraseLast theorem
(p : RelSeries r) : p.eraseLast.last = p ⟨p.length.pred, Nat.lt_succ_iff.2 (Nat.pred_le _)⟩
Full source
@[simp] lemma last_eraseLast (p : RelSeries r) :
    p.eraseLast.last = p ⟨p.length.pred, Nat.lt_succ_iff.2 (Nat.pred_le _)⟩ := rfl
Last Element of Truncated Relation Series Equals Penultimate Element
Informal description
For any relation series $p$ of a relation $r$ on a type $\alpha$, the last element of the series obtained by removing the last element of $p$ (denoted as $p.\text{eraseLast}$) is equal to the element of $p$ at the index $\text{length}(p) - 1$.
RelSeries.eraseLast_last_rel_last theorem
(p : RelSeries r) (h : p.length ≠ 0) : r p.eraseLast.last p.last
Full source
/-- In a non-trivial series `p`, the last element of `p.eraseLast` is related to `p.last` -/
lemma eraseLast_last_rel_last (p : RelSeries r) (h : p.length ≠ 0) :
    r p.eraseLast.last p.last := by
  simp only [last, Fin.last, eraseLast_length, eraseLast_toFun]
  convert p.step ⟨p.length - 1, by omega⟩
  simp only [Nat.succ_eq_add_one, Fin.succ_mk]; omega
Last Element Relation in Non-Empty Series: $r(p_{\text{eraseLast}}.last, p.last)$
Informal description
For any non-empty relation series $p$ of a relation $r$ on a type $\alpha$, the last element of the series obtained by removing the last element of $p$ is related to the last element of $p$ by $r$. In other words, if $p$ has length $n \neq 0$, then $r(p_{\text{eraseLast}}.last, p.last)$ holds.
RelSeries.smash definition
(p q : RelSeries r) (connect : p.last = q.head) : RelSeries r
Full source
/--
Given two series of the form `a₀ -r→ ... -r→ X` and `X -r→ b ---> ...`,
then `a₀ -r→ ... -r→ X -r→ b ...` is another series obtained by combining the given two.
-/
@[simps length]
def smash (p q : RelSeries r) (connect : p.last = q.head) : RelSeries r where
  length := p.length + q.length
  toFun := Fin.addCases (m := p.length) (n := q.length + 1) (p ∘ Fin.castSucc) q
  step := by
    apply Fin.addCases <;> intro i
    · simp_rw [Fin.castSucc_castAdd, Fin.addCases_left, Fin.succ_castAdd]
      convert p.step i
      split_ifs with h
      · rw [Fin.addCases_right, h, ← last, connect, head]
      · apply Fin.addCases_left
    simpa only [Fin.castSucc_natAdd, Fin.succ_natAdd, Fin.addCases_right] using q.step i
Concatenation of relation series
Informal description
Given two relation series `p` and `q` of a relation `r` on a type `α`, and a proof `connect` that the last element of `p` equals the first element of `q`, the operation `smash` combines these two series into a new relation series. The resulting series has length `p.length + q.length` and consists of the sequence from `p` followed by the sequence from `q`, with the connection point given by `connect`.
RelSeries.smash_castLE theorem
{p q : RelSeries r} (h : p.last = q.head) (i : Fin (p.length + 1)) : p.smash q h (i.castLE (by simp)) = p i
Full source
lemma smash_castLE {p q : RelSeries r} (h : p.last = q.head) (i : Fin (p.length + 1)) :
    p.smash q h (i.castLE (by simp)) = p i := by
  refine i.lastCases ?_ fun _ ↦ by dsimp only [smash]; apply Fin.addCases_left
  show p.smash q h (Fin.natAdd p.length (0 : Fin (q.length + 1))) = _
  simpa only [smash, Fin.addCases_right] using h.symm
Preservation of Elements in Concatenated Relation Series
Informal description
Let $r$ be a relation on a type $\alpha$, and let $p$ and $q$ be relation series of $r$ such that the last element of $p$ equals the first element of $q$. For any index $i$ in the extended series $p.\text{smash}\ q\ h$ (where $h$ is the proof of connection), the element at position $i$ in the concatenated series is equal to the element at position $i$ in the original series $p$, provided $i$ is within the bounds of $p$.
RelSeries.smash_castAdd theorem
{p q : RelSeries r} (h : p.last = q.head) (i : Fin p.length) : p.smash q h (i.castAdd q.length).castSucc = p i.castSucc
Full source
lemma smash_castAdd {p q : RelSeries r} (h : p.last = q.head) (i : Fin p.length) :
    p.smash q h (i.castAdd q.length).castSucc = p i.castSucc :=
  smash_castLE h i.castSucc
Preservation of Elements in Concatenated Relation Series under Index Shift
Informal description
Let $r$ be a relation on a type $\alpha$, and let $p$ and $q$ be relation series of $r$ such that the last element of $p$ equals the first element of $q$ (i.e., $p_{\text{last}} = q_{\text{head}}$). For any index $i$ in the finite set $\{0, \dots, p.\text{length} - 1\}$, the element at position $(i + q.\text{length}).\text{castSucc}$ in the concatenated series $p.\text{smash}\ q\ h$ is equal to the element at position $i.\text{castSucc}$ in $p$.
RelSeries.smash_succ_castAdd theorem
{p q : RelSeries r} (h : p.last = q.head) (i : Fin p.length) : p.smash q h (i.castAdd q.length).succ = p i.succ
Full source
lemma smash_succ_castAdd {p q : RelSeries r} (h : p.last = q.head)
    (i : Fin p.length) : p.smash q h (i.castAdd q.length).succ = p i.succ :=
  smash_castLE h i.succ
Successor Index Preservation in Concatenated Relation Series
Informal description
Let $r$ be a relation on a type $\alpha$, and let $p$ and $q$ be relation series of $r$ such that the last element of $p$ equals the first element of $q$. For any index $i$ in $p$ (i.e., $i < p.\text{length}$), the element at position $i + q.\text{length} + 1$ in the concatenated series $p.\text{smash}\ q\ h$ is equal to the element at position $i + 1$ in $p$.
RelSeries.smash_natAdd theorem
{p q : RelSeries r} (h : p.last = q.head) (i : Fin q.length) : smash p q h (i.natAdd p.length).castSucc = q i.castSucc
Full source
lemma smash_natAdd {p q : RelSeries r} (h : p.last = q.head) (i : Fin q.length) :
    smash p q h (i.natAdd p.length).castSucc = q i.castSucc := by
  dsimp only [smash, Fin.castSucc_natAdd]
  apply Fin.addCases_right
Element Preservation in Concatenated Relation Series at Shifted Indices
Informal description
Given two relation series $p$ and $q$ of a relation $r$ on a type $\alpha$, and a proof $h$ that the last element of $p$ equals the first element of $q$, then for any index $i$ in the finite set $\text{Fin}(q.\text{length})$, the element at position $i.\text{natAdd}(p.\text{length}).\text{castSucc}$ in the concatenated series $\text{smash}(p, q, h)$ is equal to the element at position $i.\text{castSucc}$ in $q$.
RelSeries.smash_succ_natAdd theorem
{p q : RelSeries r} (h : p.last = q.head) (i : Fin q.length) : smash p q h (i.natAdd p.length).succ = q i.succ
Full source
lemma smash_succ_natAdd {p q : RelSeries r} (h : p.last = q.head) (i : Fin q.length) :
    smash p q h (i.natAdd p.length).succ = q i.succ := by
  dsimp only [smash, Fin.succ_natAdd]
  apply Fin.addCases_right
Successor Index Property in Concatenated Relation Series
Informal description
Given two relation series $p$ and $q$ of a relation $r$ on a type $\alpha$, and a proof $h$ that the last element of $p$ equals the first element of $q$, then for any index $i$ in the series $q$, the $(i + p.\text{length} + 1)$-th element of the concatenated series $\text{smash}(p, q, h)$ is equal to the $(i + 1)$-th element of $q$.
RelSeries.head_smash theorem
{p q : RelSeries r} (h : p.last = q.head) : (smash p q h).head = p.head
Full source
@[simp] lemma head_smash {p q : RelSeries r} (h : p.last = q.head) :
    (smash p q h).head = p.head := by
  obtain ⟨_ | _, _⟩ := p
  · simpa [Fin.addCases] using h.symm
  dsimp only [smash, head]
  exact Fin.addCases_left 0
Head of concatenated relation series equals head of first series
Informal description
Given two relation series $p$ and $q$ of a relation $r$ on a type $\alpha$, and a proof $h$ that the last element of $p$ equals the first element of $q$, the head of the concatenated series $\mathrm{smash}(p, q, h)$ is equal to the head of $p$.
RelSeries.last_smash theorem
{p q : RelSeries r} (h : p.last = q.head) : (smash p q h).last = q.last
Full source
@[simp] lemma last_smash {p q : RelSeries r} (h : p.last = q.head) :
    (smash p q h).last = q.last := by
  dsimp only [smash, last]
  rw [← Fin.natAdd_last, Fin.addCases_right]
Last Element of Concatenated Relation Series Equals Last Element of Second Series
Informal description
Given two relation series $p$ and $q$ of a relation $r$ on a type $\alpha$, and a proof $h$ that the last element of $p$ equals the first element of $q$, the last element of the concatenated series $\text{smash}(p, q, h)$ is equal to the last element of $q$.
RelSeries.take definition
{r : Rel α α} (p : RelSeries r) (i : Fin (p.length + 1)) : RelSeries r
Full source
/-- Given the series `a₀ -r→ … -r→ aᵢ -r→ … -r→ aₙ`, the series `a₀ -r→ … -r→ aᵢ`. -/
@[simps! length]
def take {r : Rel α α} (p : RelSeries r) (i : Fin (p.length + 1)) : RelSeries r where
  length := i
  toFun := fun ⟨j, h⟩ => p.toFun ⟨j, by omega⟩
  step := fun ⟨j, h⟩ => p.step ⟨j, by omega⟩
Initial segment of a relation series
Informal description
Given a relation `r` on a type `α` and a relation series `p` of length `n`, the function `RelSeries.take` returns the initial segment of the series up to the `i`-th element (where `i` is a natural number less than or equal to `n`). This segment is itself a relation series where each consecutive pair of elements satisfies the relation `r`. More formally, for a relation series `p : RelSeries r` and an index `i : Fin (p.length + 1)`, `p.take i` is the relation series of length `i` consisting of the first `i + 1` elements of `p`, with the same relation `r` holding between consecutive elements.
RelSeries.head_take theorem
(p : RelSeries r) (i : Fin (p.length + 1)) : (p.take i).head = p.head
Full source
@[simp]
lemma head_take (p : RelSeries r) (i : Fin (p.length + 1)) :
    (p.take i).head = p.head := by simp [take, head]
Head of Initial Segment Equals Head of Original Series
Informal description
For any relation series $p$ of a relation $r$ on a type $\alpha$, and for any index $i$ (where $0 \leq i \leq \text{length}(p)$), the head of the initial segment $p.\text{take}(i)$ is equal to the head of $p$.
RelSeries.last_take theorem
(p : RelSeries r) (i : Fin (p.length + 1)) : (p.take i).last = p i
Full source
@[simp]
lemma last_take (p : RelSeries r) (i : Fin (p.length + 1)) :
    (p.take i).last = p i := by simp [take, last, Fin.last]
Last Element of Initial Segment in Relation Series
Informal description
Let $r$ be a relation on a type $\alpha$, and let $p$ be a relation series of length $n$ for $r$. For any index $i$ with $0 \leq i \leq n$, the last element of the initial segment $p.\text{take}(i)$ is equal to the $i$-th element of $p$.
RelSeries.drop definition
(p : RelSeries r) (i : Fin (p.length + 1)) : RelSeries r
Full source
/-- Given the series `a₀ -r→ … -r→ aᵢ -r→ … -r→ aₙ`, the series `aᵢ₊₁ -r→ … -r→ aᵢ`. -/
@[simps! length]
def drop (p : RelSeries r) (i : Fin (p.length + 1)) : RelSeries r where
  length := p.length - i
  toFun := fun ⟨j, h⟩ => p.toFun ⟨j+i, by omega⟩
  step := fun ⟨j, h⟩ => by
    convert p.step ⟨j+i.1, by omega⟩
    simp only [Nat.succ_eq_add_one, Fin.succ_mk]; omega
Truncated relation series from index `i`
Informal description
Given a relation series `p` of length `n` for a relation `r` on type `α`, and an index `i` (where `0 ≤ i ≤ n`), the `drop` operation returns a new relation series starting at the `i`-th element of `p` and continuing to the end. The new series has length `n - i`, and its elements are `a_i, a_{i+1}, ..., a_n` with the same relation `r` holding between consecutive elements.
RelSeries.head_drop theorem
(p : RelSeries r) (i : Fin (p.length + 1)) : (p.drop i).head = p.toFun i
Full source
@[simp]
lemma head_drop (p : RelSeries r) (i : Fin (p.length + 1)) : (p.drop i).head = p.toFun i := by
  simp [drop, head]
Head of Truncated Relation Series Equals $i$-th Element
Informal description
Given a relation series $p$ of length $n$ for a relation $r$ on a type $\alpha$, and an index $i$ (where $0 \leq i \leq n$), the head of the truncated series obtained by dropping the first $i$ elements is equal to the $i$-th element of the original series, i.e., $(\text{drop}(p, i)).\text{head} = p(i)$.
RelSeries.last_drop theorem
(p : RelSeries r) (i : Fin (p.length + 1)) : (p.drop i).last = p.last
Full source
@[simp]
lemma last_drop (p : RelSeries r) (i : Fin (p.length + 1)) : (p.drop i).last = p.last := by
  simp only [last, drop, Fin.last]
  congr
  omega
Last Element Invariance Under Series Truncation
Informal description
For any relation series $p$ of length $n$ for a relation $r$ on a type $\alpha$, and for any index $i$ (where $0 \leq i \leq n$), the last element of the truncated series $p.\mathrm{drop}\,i$ is equal to the last element of the original series $p$.
Rel.not_finiteDimensional_iff theorem
[Nonempty α] : ¬r.FiniteDimensional ↔ r.InfiniteDimensional
Full source
lemma Rel.not_finiteDimensional_iff [Nonempty α] :
    ¬ r.FiniteDimensional¬ r.FiniteDimensional ↔ r.InfiniteDimensional := by
  rw [finiteDimensional_iff, infiniteDimensional_iff]
  push_neg
  constructor
  · intro H n
    induction n with
    | zero => refine ⟨⟨0, ![Nonempty.some ‹_›], by simp⟩, by simp⟩
    | succ n IH =>
      obtain ⟨l, hl⟩ := IH
      obtain ⟨l', hl'⟩ := H l
      exact ⟨l'.take ⟨n + 1, by simpa [hl] using hl'⟩, rfl⟩
  · intro H l
    obtain ⟨l', hl'⟩ := H (l.length + 1)
    exact ⟨l', by simp [hl']⟩
Equivalence of Non-Finite Dimensionality and Infinite Dimensionality for Relations
Informal description
For a nonempty type $\alpha$ and a relation $r$ on $\alpha$, the relation $r$ is not finite dimensional if and only if it is infinite dimensional.
Rel.not_infiniteDimensional_iff theorem
[Nonempty α] : ¬r.InfiniteDimensional ↔ r.FiniteDimensional
Full source
lemma Rel.not_infiniteDimensional_iff [Nonempty α] :
    ¬ r.InfiniteDimensional¬ r.InfiniteDimensional ↔ r.FiniteDimensional := by
  rw [← not_finiteDimensional_iff, not_not]
Equivalence of Non-Infinite Dimensionality and Finite Dimensionality for Relations
Informal description
For a nonempty type $\alpha$ and a relation $r$ on $\alpha$, the relation $r$ is not infinite dimensional if and only if it is finite dimensional.
Rel.finiteDimensional_or_infiniteDimensional theorem
[Nonempty α] : r.FiniteDimensional ∨ r.InfiniteDimensional
Full source
lemma Rel.finiteDimensional_or_infiniteDimensional [Nonempty α] :
    r.FiniteDimensional ∨ r.InfiniteDimensional := by
  rw [← not_finiteDimensional_iff]
  exact em r.FiniteDimensional
Dichotomy for Relation Dimensionality: Finite or Infinite
Informal description
For any nonempty type $\alpha$ and any relation $r$ on $\alpha$, either $r$ is finite-dimensional (i.e., there exists a relation series of $r$ with maximum possible length) or $r$ is infinite-dimensional (i.e., there exist relation series of $r$ of arbitrary length).
Rel.FiniteDimensional.swap instance
[FiniteDimensional r] : FiniteDimensional (Function.swap r)
Full source
instance Rel.FiniteDimensional.swap [FiniteDimensional r] : FiniteDimensional (Function.swap r) :=
  ⟨.reverse (.longestOf r), fun s ↦ s.reverse.length_le_length_longestOf⟩
Finite-Dimensionality of the Swapped Relation
Informal description
For any relation $r$ on a type $\alpha$, if $r$ is finite-dimensional, then the swapped relation $\operatorname{swap} r$ (where $\operatorname{swap} r\, y\, x = r\, x\, y$) is also finite-dimensional.
Rel.finiteDimensional_swap_iff theorem
: FiniteDimensional (Function.swap r) ↔ FiniteDimensional r
Full source
@[simp]
lemma Rel.finiteDimensional_swap_iff :
    FiniteDimensionalFiniteDimensional (Function.swap r) ↔ FiniteDimensional r :=
  ⟨fun _ ↦ .swap _, fun _ ↦ .swap _⟩
Finite-Dimensionality Equivalence under Relation Swapping
Informal description
For any relation $r$ on a type $\alpha$, the swapped relation $\operatorname{swap} r$ (defined by $\operatorname{swap} r\, y\, x = r\, x\, y$) is finite-dimensional if and only if $r$ itself is finite-dimensional.
Rel.InfiniteDimensional.swap instance
[InfiniteDimensional r] : InfiniteDimensional (Function.swap r)
Full source
instance Rel.InfiniteDimensional.swap [InfiniteDimensional r] :
    InfiniteDimensional (Function.swap r) :=
  ⟨fun n ↦ ⟨.reverse (.withLength r n), RelSeries.length_withLength r n⟩⟩
Infinite Dimensionality is Preserved under Relation Swapping
Informal description
For any relation $r$ on a type $\alpha$, if $r$ is infinite dimensional (i.e., there exist relation series of arbitrary length for $r$), then the swapped relation $\operatorname{swap} r$ (defined by $\operatorname{swap} r\, y\, x = r\, x\, y$) is also infinite dimensional.
Rel.infiniteDimensional_swap_iff theorem
: InfiniteDimensional (Function.swap r) ↔ InfiniteDimensional r
Full source
@[simp]
lemma Rel.infiniteDimensional_swap_iff :
    InfiniteDimensionalInfiniteDimensional (Function.swap r) ↔ InfiniteDimensional r :=
  ⟨fun _ ↦ .swap _, fun _ ↦ .swap _⟩
Infinite Dimensionality of Relation is Equivalent to Infinite Dimensionality of its Swap
Informal description
For any relation $r$ on a type $\alpha$, the swapped relation $\operatorname{swap} r$ (defined by $\operatorname{swap} r\, y\, x = r\, x\, y$) is infinite dimensional if and only if $r$ itself is infinite dimensional. Here, a relation being infinite dimensional means that for every natural number $n$, there exists a sequence $a_0, a_1, \dots, a_n$ of elements in $\alpha$ such that $r(a_i, a_{i+1})$ holds for all $i < n$.
Rel.wellFounded_swap_of_finiteDimensional theorem
[Rel.FiniteDimensional r] : WellFounded (Function.swap r)
Full source
lemma Rel.wellFounded_swap_of_finiteDimensional [Rel.FiniteDimensional r] :
    WellFounded (Function.swap r) := by
  rw [WellFounded.wellFounded_iff_no_descending_seq]
  refine ⟨fun ⟨f, hf⟩ ↦ ?_⟩
  let s := RelSeries.mk (r := r) ((RelSeries.longestOf r).length + 1) (f ·) (hf ·)
  exact (RelSeries.longestOf r).length.lt_succ_self.not_le s.length_le_length_longestOf
Well-foundedness of the Swapped Relation in Finite-Dimensional Cases
Informal description
For any finite-dimensional relation $r$ on a type $\alpha$, the swapped relation $\operatorname{swap} r$ (defined by $\operatorname{swap} r\, y\, x = r\, x\, y$) is well-founded.
Rel.wellFounded_of_finiteDimensional theorem
[Rel.FiniteDimensional r] : WellFounded r
Full source
lemma Rel.wellFounded_of_finiteDimensional [Rel.FiniteDimensional r] : WellFounded r :=
  have : (Rel.FiniteDimensional (Function.swap r)) := Rel.finiteDimensional_swap_iff.mp ‹_›
  wellFounded_swap_of_finiteDimensional (Function.swap r)
Well-foundedness of Finite-Dimensional Relations
Informal description
For any finite-dimensional relation $r$ on a type $\alpha$, the relation $r$ is well-founded. Here, a relation being finite-dimensional means there exists a finite upper bound on the lengths of all possible relation series of $r$, where a relation series of length $n$ is a sequence $a_0, a_1, \dots, a_n$ in $\alpha$ such that $r(a_i, a_{i+1})$ holds for all $i < n$.
FiniteDimensionalOrder abbrev
(γ : Type*) [Preorder γ]
Full source
/-- A type is finite dimensional if its `LTSeries` has bounded length. -/
abbrev FiniteDimensionalOrder (γ : Type*) [Preorder γ] :=
  Rel.FiniteDimensional ((· < ·) : γ → γ → Prop)
Finite Dimensional Preorder
Informal description
A preorder $\gamma$ is called *finite dimensional* if there exists a finite upper bound on the lengths of all possible relation series in $\gamma$. Here, a relation series of length $n$ is a sequence $a_0, a_1, \ldots, a_n$ in $\gamma$ such that $a_i \leq a_{i+1}$ for all $i < n$.
FiniteDimensionalOrder.ofUnique instance
(γ : Type*) [Preorder γ] [Unique γ] : FiniteDimensionalOrder γ
Full source
instance FiniteDimensionalOrder.ofUnique (γ : Type*) [Preorder γ] [Unique γ] :
    FiniteDimensionalOrder γ where
  exists_longest_relSeries := ⟨.singleton _ default, fun x ↦ by
    by_contra! r
    exact (x.step ⟨0, by omega⟩).ne <| Subsingleton.elim _ _⟩
Finite Dimensionality of Unique Preorders
Informal description
For any preorder $\gamma$ with a unique element, $\gamma$ is finite dimensional. That is, there exists a finite upper bound on the lengths of all possible relation series in $\gamma$.
InfiniteDimensionalOrder abbrev
(γ : Type*) [Preorder γ]
Full source
/-- A type is infinite dimensional if it has `LTSeries` of at least arbitrary length -/
abbrev InfiniteDimensionalOrder (γ : Type*) [Preorder γ] :=
  Rel.InfiniteDimensional ((· < ·) : γ → γ → Prop)
Infinite Dimensional Preorder
Informal description
A preorder $\gamma$ is called *infinite dimensional* if for every natural number $n$, there exists a sequence $a_0, a_1, \dots, a_n$ in $\gamma$ such that $a_i \leq a_{i+1}$ for all $i < n$.
LTSeries abbrev
Full source
/--
If `α` is a preorder, a LTSeries is a relation series of the less than relation.
-/
abbrev LTSeries := RelSeries ((· < ·) : Rel α α)
Less-Than Series in a Preorder
Informal description
Given a preorder $\alpha$, a less-than series (LTSeries) is a sequence of elements $a_0, a_1, \dots, a_n$ in $\alpha$ such that $a_i < a_{i+1}$ for all $i < n$.
LTSeries.longestOf definition
[FiniteDimensionalOrder α] : LTSeries α
Full source
/-- The longest `<`-series when a type is finite dimensional -/
protected noncomputable def longestOf [FiniteDimensionalOrder α] : LTSeries α :=
  RelSeries.longestOf _
Longest less-than series in a finite dimensional preorder
Informal description
Given a finite dimensional preorder $\alpha$, the longest less-than series in $\alpha$ is a sequence $a_0, a_1, \dots, a_n$ such that $a_i < a_{i+1}$ for all $i < n$, and this series has the maximum possible length among all such series in $\alpha$.
LTSeries.withLength definition
[InfiniteDimensionalOrder α] (n : ℕ) : LTSeries α
Full source
/-- A `<`-series with length `n` if the relation is infinite dimensional -/
protected noncomputable def withLength [InfiniteDimensionalOrder α] (n : ) : LTSeries α :=
  RelSeries.withLength _ n
Less-than series of length $n$ in an infinite dimensional preorder
Informal description
Given an infinite dimensional preorder $\alpha$ and a natural number $n$, there exists a less-than series $a_0, a_1, \dots, a_n$ in $\alpha$ of length $n$ such that $a_i < a_{i+1}$ for all $i < n$.
LTSeries.length_withLength theorem
[InfiniteDimensionalOrder α] (n : ℕ) : (LTSeries.withLength α n).length = n
Full source
@[simp] lemma length_withLength [InfiniteDimensionalOrder α] (n : ) :
    (LTSeries.withLength α n).length = n :=
  RelSeries.length_withLength _ _
Length of Less-Than Series in Infinite Dimensional Preorder
Informal description
For any infinite dimensional preorder $\alpha$ and any natural number $n$, the length of the less-than series constructed by `LTSeries.withLength α n` is equal to $n$.
LTSeries.longestOf_is_longest theorem
[FiniteDimensionalOrder α] (x : LTSeries α) : x.length ≤ (LTSeries.longestOf α).length
Full source
lemma longestOf_is_longest [FiniteDimensionalOrder α] (x : LTSeries α) :
    x.length ≤ (LTSeries.longestOf α).length :=
  RelSeries.length_le_length_longestOf _ _
Maximal Length Property of Less-Than Series in Finite-Dimensional Preorders
Informal description
For any finite-dimensional preorder $\alpha$ and any less-than series $x$ in $\alpha$, the length of $x$ is less than or equal to the length of the longest less-than series in $\alpha$.
LTSeries.longestOf_len_unique theorem
[FiniteDimensionalOrder α] (p : LTSeries α) (is_longest : ∀ (q : LTSeries α), q.length ≤ p.length) : p.length = (LTSeries.longestOf α).length
Full source
lemma longestOf_len_unique [FiniteDimensionalOrder α] (p : LTSeries α)
    (is_longest : ∀ (q : LTSeries α), q.length ≤ p.length) :
    p.length = (LTSeries.longestOf α).length :=
  le_antisymm (longestOf_is_longest _) (is_longest _)
Uniqueness of Longest Less-Than Series Length in Finite-Dimensional Preorders
Informal description
Let $\alpha$ be a finite-dimensional preorder and $p$ be a less-than series in $\alpha$ such that for every less-than series $q$ in $\alpha$, the length of $q$ is at most the length of $p$. Then the length of $p$ is equal to the length of the longest less-than series in $\alpha$.
LTSeries.strictMono theorem
(x : LTSeries α) : StrictMono x
Full source
lemma strictMono (x : LTSeries α) : StrictMono x :=
  fun _ _ h => x.rel_of_lt h
Strict Monotonicity of Less-Than Series
Informal description
For any less-than series $x$ in a preorder $\alpha$, the sequence $x_0, x_1, \dots, x_n$ is strictly increasing, i.e., $x_i < x_{i+1}$ for all $i < n$.
LTSeries.monotone theorem
(x : LTSeries α) : Monotone x
Full source
lemma monotone (x : LTSeries α) : Monotone x :=
  x.strictMono.monotone
Monotonicity of Less-Than Series
Informal description
For any less-than series $x$ in a preorder $\alpha$, the sequence $x_0, x_1, \dots, x_n$ is monotone, i.e., $x_i \leq x_{i+1}$ for all $i < n$.
LTSeries.head_le_last theorem
(x : LTSeries α) : x.head ≤ x.last
Full source
lemma head_le_last (x : LTSeries α) : x.head ≤ x.last :=
  LTSeries.monotone x (Fin.zero_le _)
Head-Last Inequality in Less-Than Series
Informal description
For any less-than series $x$ in a preorder $\alpha$, the head (first element) of the series is less than or equal to the last element, i.e., $x_0 \leq x_n$.
LTSeries.mk definition
(length : ℕ) (toFun : Fin (length + 1) → α) (strictMono : StrictMono toFun) : LTSeries α
Full source
/-- An alternative constructor of `LTSeries` from a strictly monotone function. -/
@[simps]
def mk (length : ) (toFun : Fin (length + 1) → α) (strictMono : StrictMono toFun) :
    LTSeries α where
  length := length
  toFun := toFun
  step i := strictMono <| lt_add_one i.1
Constructor for Less-Than Series from Strictly Monotone Function
Informal description
Given a natural number `length` and a strictly monotone function `toFun` from the finite type `Fin (length + 1)` to a preorder `α`, the constructor `LTSeries.mk` creates a less-than series (LTSeries) in `α` where each element is related by the strict order relation `<` to its successor.
LTSeries.injStrictMono definition
(n : ℕ) : { f : (l : Fin n) × (Fin (l + 1) → α) // StrictMono f.2 } ↪ LTSeries α
Full source
/-- An injection from the type of strictly monotone functions with limited length to `LTSeries`. -/
def injStrictMono (n : ) :
    {f : (l : Fin n) × (Fin (l + 1) → α) // StrictMono f.2}{f : (l : Fin n) × (Fin (l + 1) → α) // StrictMono f.2} ↪ LTSeries α where
  toFun f := mk f.1.1 f.1.2 f.2
  inj' f g e := by
    obtain ⟨⟨lf, f⟩, mf⟩ := f
    obtain ⟨⟨lg, g⟩, mg⟩ := g
    dsimp only at mf mg e
    have leq := congr($(e).length)
    rw [mk_length lf f mf, mk_length lg g mg, Fin.val_eq_val] at leq
    subst leq
    simp_rw [Subtype.mk_eq_mk, Sigma.mk.inj_iff, heq_eq_eq, true_and]
    have feq := fun i ↦ congr($(e).toFun i)
    simp_rw [mk_toFun lf f mf, mk_toFun lf g mg, mk_length lf f mf] at feq
    rwa [funext_iff]
Injection from Strictly Monotone Functions to Less-Than Series
Informal description
For a natural number $n$, the function `LTSeries.injStrictMono` injectively maps from the type of pairs $(l, f)$ where $l$ is a natural number less than $n$ and $f$ is a strictly monotone function from $\text{Fin } (l + 1)$ to a preorder $\alpha$, to the type of less-than series in $\alpha$. Specifically, each such pair $(l, f)$ is mapped to the less-than series constructed from $f$ with length $l$.
LTSeries.map definition
(p : LTSeries α) (f : α → β) (hf : StrictMono f) : LTSeries β
Full source
/--
For two preorders `α, β`, if `f : α → β` is strictly monotonic, then a strict chain of `α`
can be pushed out to a strict chain of `β` by
`a₀ < a₁ < ... < aₙ ↦ f a₀ < f a₁ < ... < f aₙ`
-/
@[simps!]
def map (p : LTSeries α) (f : α → β) (hf : StrictMono f) : LTSeries β :=
  LTSeries.mk p.length (f.comp p) (hf.comp p.strictMono)
Image of a less-than series under a strictly monotone map
Informal description
Given a less-than series $p$ in a preorder $\alpha$ and a strictly monotone function $f : \alpha \to \beta$ to another preorder $\beta$, the function `LTSeries.map` constructs a new less-than series in $\beta$ by applying $f$ to each element of $p$. The resulting series has the same length as $p$ and maintains the strict monotonicity property.
LTSeries.head_map theorem
(p : LTSeries α) (f : α → β) (hf : StrictMono f) : (p.map f hf).head = f p.head
Full source
@[simp] lemma head_map (p : LTSeries α) (f : α → β) (hf : StrictMono f) :
  (p.map f hf).head = f p.head := rfl
Head Preservation under Strictly Monotone Mapping of Less-Than Series
Informal description
Given a less-than series $p$ in a preorder $\alpha$ and a strictly monotone function $f : \alpha \to \beta$, the head of the mapped series $p.map\, f\, hf$ is equal to $f$ applied to the head of $p$, i.e., $(p.map\, f\, hf).head = f(p.head)$.
LTSeries.last_map theorem
(p : LTSeries α) (f : α → β) (hf : StrictMono f) : (p.map f hf).last = f p.last
Full source
@[simp] lemma last_map (p : LTSeries α) (f : α → β) (hf : StrictMono f) :
  (p.map f hf).last = f p.last := rfl
Last Element Preservation under Strictly Monotone Mapping
Informal description
Given a less-than series $p$ in a preorder $\alpha$ and a strictly monotone function $f : \alpha \to \beta$, the last element of the mapped series $p.map\, f\, hf$ is equal to $f$ applied to the last element of $p$, i.e., $(p.map\, f\, hf).last = f(p.last)$.
LTSeries.comap definition
(p : LTSeries β) (f : α → β) (comap : ∀ ⦃x y⦄, f x < f y → x < y) (surjective : Function.Surjective f) : LTSeries α
Full source
/--
For two preorders `α, β`, if `f : α → β` is surjective and strictly comonotonic, then a
strict series of `β` can be pulled back to a strict chain of `α` by
`b₀ < b₁ < ... < bₙ ↦ f⁻¹ b₀ < f⁻¹ b₁ < ... < f⁻¹ bₙ` where `f⁻¹ bᵢ` is an arbitrary element in the
preimage of `f⁻¹ {bᵢ}`.
-/
@[simps!]
noncomputable def comap (p : LTSeries β) (f : α → β)
  (comap : ∀ ⦃x y⦄, f x < f y → x < y)
  (surjective : Function.Surjective f) :
  LTSeries α := mk p.length (fun i ↦ (surjective (p i)).choose)
    (fun i j h ↦ comap (by simpa only [(surjective _).choose_spec] using p.strictMono h))
Pullback of a less-than series through a surjective strictly comonotonic function
Informal description
Given a less-than series $p$ in a preorder $\beta$, a function $f : \alpha \to \beta$ that is surjective and satisfies the condition that $f(x) < f(y)$ implies $x < y$ for all $x, y \in \alpha$, the operation `LTSeries.comap` constructs a less-than series in $\alpha$ by pulling back the series $p$ through $f$. Specifically, for each element $b_i$ in the series $p$, an arbitrary preimage $a_i \in f^{-1}(b_i)$ is chosen, forming a new series $a_0, a_1, \dots, a_n$ in $\alpha$ where $a_i < a_{i+1}$ for all $i < n$.
LTSeries.range definition
(n : ℕ) : LTSeries ℕ
Full source
/-- The strict series `0 < … < n` in `ℕ`. -/
def range (n : ) : LTSeries  where
  length := n
  toFun := fun i => i
  step i := Nat.lt_add_one i
Strictly increasing series of natural numbers from 0 to n
Informal description
For any natural number \( n \), the less-than series `range n` is the sequence \( 0, 1, \dots, n \) in \( \mathbb{N} \), where each element is strictly less than the next. Specifically, the \( i \)-th element of the series is \( i \), and the length of the series is \( n \).
LTSeries.length_range theorem
(n : ℕ) : (range n).length = n
Full source
@[simp] lemma length_range (n : ) : (range n).length = n := rfl
Length of Natural Number Series from 0 to $n$ is $n$
Informal description
For any natural number $n$, the length of the strictly increasing series $0, 1, \dots, n$ is equal to $n$.
LTSeries.range_apply theorem
(n : ℕ) (i : Fin (n + 1)) : (range n) i = i
Full source
@[simp] lemma range_apply (n : ) (i : Fin (n+1)) : (range n) i = i := rfl
Element of Natural Number Series at Index $i$ is $i$
Informal description
For any natural number $n$ and any index $i$ in the finite set $\{0, \dots, n\}$, the $i$-th element of the strictly increasing series $0, 1, \dots, n$ is equal to $i$.
LTSeries.head_range theorem
(n : ℕ) : (range n).head = 0
Full source
@[simp] lemma head_range (n : ) : (range n).head = 0 := rfl
Head of Natural Number Series is Zero
Informal description
For any natural number $n$, the first element of the strictly increasing series $0, 1, \dots, n$ is $0$.
LTSeries.last_range theorem
(n : ℕ) : (range n).last = n
Full source
@[simp] lemma last_range (n : ) : (range n).last = n := rfl
Last Element of Natural Number Series is $n$
Informal description
For any natural number $n$, the last element of the strictly increasing series $0, 1, \dots, n$ is equal to $n$.
LTSeries.exists_relSeries_covBy theorem
{α} [PartialOrder α] [WellFoundedLT α] [WellFoundedGT α] (s : LTSeries α) : ∃ (t : RelSeries (α := α) (· ⋖ ·)) (i : Fin (s.length + 1) ↪ Fin (t.length + 1)), t ∘ i = s ∧ i 0 = 0 ∧ i (.last _) = .last _
Full source
/-- Any `LTSeries` can be refined to a `CovBy`-`RelSeries`
in a bidirectionally well-founded order. -/
theorem exists_relSeries_covBy
    {α} [PartialOrder α] [WellFoundedLT α] [WellFoundedGT α] (s : LTSeries α) :
    ∃ (t : RelSeries (α := α) (· ⋖ ·)) (i : Fin (s.length + 1) ↪ Fin (t.length + 1)),
      t ∘ i = s ∧ i 0 = 0 ∧ i (.last _) = .last _ := by
  obtain ⟨n, s, h⟩ := s
  induction n with
  | zero => exact ⟨⟨0, s, nofun⟩, (Equiv.refl _).toEmbedding, rfl, rfl, rfl⟩
  | succ n IH =>
    obtain ⟨t₁, i, ht, hi₁, hi₂⟩ := IH (s ∘ Fin.castSucc) fun _ ↦ h _
    obtain ⟨t₂, h₁, m, h₂, ht₂⟩ :=
      exists_covBy_seq_of_wellFoundedLT_wellFoundedGT_of_le (h (.last _)).le
    let t₃ : RelSeries (α := α) (· ⋖ ·) := ⟨m, (t₂ ·), fun i ↦ by simpa using ht₂ i⟩
    have H : t₁.last = t₂ 0 := (congr(t₁ $hi₂.symm).trans (congr_fun ht _)).trans h₁.symm
    refine ⟨t₁.smash t₃ H, ⟨Fin.snoc (Fin.castLE (by simp) ∘ i) (.last _), ?_⟩, ?_, ?_, ?_⟩
    · refine Fin.lastCases (Fin.lastCases (fun _ ↦ rfl) fun j eq ↦ ?_) fun j ↦ Fin.lastCases
        (fun eq ↦ ?_) fun k eq ↦ Fin.ext (congr_arg Fin.val (by simpa using eq) :)
      on_goal 2 => rw [eq_comm] at eq
      all_goals
        rw [Fin.snoc_castSucc] at eq
        obtain rfl : m = 0 := by simpa [t₃] using (congr_arg Fin.val eq).trans_lt (i j).2
        cases (h (.last _)).ne' (h₂.symm.trans h₁)
    · refine funext (Fin.lastCases ?_ fun j ↦ ?_)
      · convert h₂; simpa using RelSeries.last_smash ..
      convert congr_fun ht j using 1
      simp [RelSeries.smash_castLE]
    all_goals simp [Fin.snoc, Fin.castPred_zero, hi₁]
Refinement of Less-Than Series to Covering Relation Series in Well-Founded Partial Order
Informal description
Let $\alpha$ be a partially ordered set with well-founded strict less-than and greater-than relations. For any less-than series $s$ in $\alpha$, there exists a relation series $t$ of the covering relation $\lessdot$ and an injective embedding $i$ from the indices of $s$ to the indices of $t$ such that: 1. The composition $t \circ i$ equals $s$, 2. The embedding $i$ maps the first index of $s$ to the first index of $t$, 3. The embedding $i$ maps the last index of $s$ to the last index of $t$.
LTSeries.exists_relSeries_covBy_and_head_eq_bot_and_last_eq_bot theorem
{α} [PartialOrder α] [BoundedOrder α] [WellFoundedLT α] [WellFoundedGT α] (s : LTSeries α) : ∃ (t : RelSeries (α := α) (· ⋖ ·)) (i : Fin (s.length + 1) ↪ Fin (t.length + 1)), t ∘ i = s ∧ t.head = ⊥ ∧ t.last = ⊤
Full source
theorem exists_relSeries_covBy_and_head_eq_bot_and_last_eq_bot
    {α} [PartialOrder α] [BoundedOrder α] [WellFoundedLT α] [WellFoundedGT α] (s : LTSeries α) :
    ∃ (t : RelSeries (α := α) (· ⋖ ·)) (i : Fin (s.length + 1) ↪ Fin (t.length + 1)),
      t ∘ i = s ∧ t.head = ⊥ ∧ t.last = ⊤ := by
  wlog h₁ : s.head = 
  · obtain ⟨t, i, hi, ht⟩ := this (s.cons  (bot_lt_iff_ne_bot.mpr h₁)) rfl
    exact ⟨t, ⟨fun j ↦ i (j.succ.cast (by simp)), fun _ _ ↦ by simp⟩,
      funext fun j ↦ (congr_fun hi _).trans (RelSeries.cons_cast_succ _ _ _ _), ht⟩
  wlog h₂ : s.last = 
  · obtain ⟨t, i, hi, ht⟩ := this (s.snoc  (lt_top_iff_ne_top.mpr h₂)) (by simp [h₁]) (by simp)
    exact ⟨t, ⟨fun j ↦ i (.cast (by simp) j.castSucc), fun _ _ ↦ by simp⟩,
      funext fun j ↦ (congr_fun hi _).trans (RelSeries.snoc_cast_castSucc _ _ _ _), ht⟩
  obtain ⟨t, i, hit, hi₁, hi₂⟩ := s.exists_relSeries_covBy
  refine ⟨t, i, hit, ?_, ?_⟩
  · rw [← h₁, RelSeries.head, RelSeries.head, ← hi₁, ← hit, Function.comp]
  · rw [← h₂, RelSeries.last, RelSeries.last, ← hi₂, ← hit, Function.comp]
Refinement of Less-Than Series to Covering Relation Series with Bottom and Top Elements in Well-Founded Bounded Order
Informal description
Let $\alpha$ be a partially ordered set with a bounded order (having both a least element $\bot$ and a greatest element $\top$) and well-founded strict less-than and greater-than relations. For any less-than series $s$ in $\alpha$, there exists a relation series $t$ of the covering relation $\lessdot$ and an injective embedding $i$ from the indices of $s$ to the indices of $t$ such that: 1. The composition $t \circ i$ equals $s$, 2. The head of $t$ is $\bot$, 3. The last element of $t$ is $\top$.
LTSeries.apply_add_index_le_apply_add_index_nat theorem
(p : LTSeries ℕ) (i j : Fin (p.length + 1)) (hij : i ≤ j) : p i + j ≤ p j + i
Full source
/--
In ℕ, two entries in an `LTSeries` differ by at least the difference of their indices.
(Expressed in a way that avoids subtraction).
-/
lemma apply_add_index_le_apply_add_index_nat (p : LTSeries ) (i j : Fin (p.length + 1))
    (hij : i ≤ j) : p i + j ≤ p j + i := by
  have ⟨i, hi⟩ := i
  have ⟨j, hj⟩ := j
  simp only [Fin.mk_le_mk] at hij
  simp only at *
  induction j, hij using Nat.le_induction with
  | base => simp
  | succ j _hij ih =>
    specialize ih (Nat.lt_of_succ_lt hj)
    have step : p ⟨j, _⟩ < p ⟨j + 1, _⟩ := p.step ⟨j, by omega⟩
    norm_cast at *; omega
Indexed Difference Inequality for Natural Number Series
Informal description
For any less-than series $p$ of natural numbers and any indices $i, j$ in the series with $i \leq j$, we have $p(i) + j \leq p(j) + i$.
LTSeries.apply_add_index_le_apply_add_index_int theorem
(p : LTSeries ℤ) (i j : Fin (p.length + 1)) (hij : i ≤ j) : p i + j ≤ p j + i
Full source
/--
In ℤ, two entries in an `LTSeries` differ by at least the difference of their indices.
(Expressed in a way that avoids subtraction).
-/
lemma apply_add_index_le_apply_add_index_int (p : LTSeries ) (i j : Fin (p.length + 1))
    (hij : i ≤ j) : p i + j ≤ p j + i := by
  -- The proof is identical to `LTSeries.apply_add_index_le_apply_add_index_nat`, but seemed easier
  -- to copy rather than to abstract
  have ⟨i, hi⟩ := i
  have ⟨j, hj⟩ := j
  simp only [Fin.mk_le_mk] at hij
  simp only at *
  induction j, hij using Nat.le_induction with
  | base => simp
  | succ j _hij ih =>
    specialize ih (Nat.lt_of_succ_lt hj)
    have step : p ⟨j, _⟩ < p ⟨j + 1, _⟩:= p.step ⟨j, by omega⟩
    norm_cast at *; omega
Integer Series Index Difference Inequality: $p(i) + j \leq p(j) + i$
Informal description
For any strictly increasing series $p$ of integers and any indices $i, j$ in the series with $i \leq j$, we have $p(i) + j \leq p(j) + i$.
LTSeries.head_add_length_le_nat theorem
(p : LTSeries ℕ) : p.head + p.length ≤ p.last
Full source
/-- In ℕ, the head and tail of an `LTSeries` differ at least by the length of the series -/
lemma head_add_length_le_nat (p : LTSeries ) : p.head + p.length ≤ p.last :=
  LTSeries.apply_add_index_le_apply_add_index_nat _ _ (Fin.last _) (Fin.zero_le _)
Head-Length-Last Inequality for Natural Number Series
Informal description
For any less-than series $p$ of natural numbers, the sum of the first element $p(0)$ and the length of the series is less than or equal to the last element $p(n)$, i.e., $p(0) + n \leq p(n)$.
LTSeries.head_add_length_le_int theorem
(p : LTSeries ℤ) : p.head + p.length ≤ p.last
Full source
/-- In ℤ, the head and tail of an `LTSeries` differ at least by the length of the series -/
lemma head_add_length_le_int (p : LTSeries ) : p.head + p.length ≤ p.last := by
  simpa using LTSeries.apply_add_index_le_apply_add_index_int _ _ (Fin.last _) (Fin.zero_le _)
Head-Length-Last Inequality for Integer Series
Informal description
For any strictly increasing series $p$ of integers, the sum of the first element $p(0)$ and the length of the series is less than or equal to the last element $p(n)$, i.e., $p(0) + n \leq p(n)$.
LTSeries.length_lt_card theorem
(s : LTSeries α) : s.length < Fintype.card α
Full source
lemma length_lt_card (s : LTSeries α) : s.length < Fintype.card α := by
  by_contra! h
  obtain ⟨i, j, hn, he⟩ := Fintype.exists_ne_map_eq_of_card_lt s (by rw [Fintype.card_fin]; omega)
  wlog hl : i < j generalizing i j
  · exact this j i hn.symm he.symm (by omega)
  exact absurd he (s.strictMono hl).ne
Length of Strictly Increasing Series is Less Than Cardinality of Finite Preorder
Informal description
For any less-than series $s$ in a finite preorder $\alpha$, the length of the series is strictly less than the cardinality of $\alpha$, i.e., $n < |\alpha|$ where $n$ is the length of the series.
LTSeries.instFintypeOfDecidableLT instance
[DecidableLT α] : Fintype (LTSeries α)
Full source
instance [DecidableLT α] : Fintype (LTSeries α) where
  elems := Finset.univ.map (injStrictMono (Fintype.card α))
  complete s := by
    have bl := s.length_lt_card
    obtain ⟨l, f, mf⟩ := s
    simp_rw [Finset.mem_map, Finset.mem_univ, true_and, Subtype.exists]
    use ⟨⟨l, bl⟩, f⟩, Fin.strictMono_iff_lt_succ.mpr mf; rfl
Finiteness of Less-Than Series in Decidable Preorders
Informal description
For any preorder $\alpha$ with decidable less-than relation, the type of all less-than series in $\alpha$ is finite.
not_finiteDimensionalOrder_iff theorem
[Preorder α] [Nonempty α] : ¬FiniteDimensionalOrder α ↔ InfiniteDimensionalOrder α
Full source
lemma not_finiteDimensionalOrder_iff [Preorder α] [Nonempty α] :
    ¬ FiniteDimensionalOrder α¬ FiniteDimensionalOrder α ↔ InfiniteDimensionalOrder α :=
  Rel.not_finiteDimensional_iff
Equivalence of Non-Finite Dimensionality and Infinite Dimensionality for Preorders
Informal description
For a nonempty preorder $\alpha$, the following are equivalent: 1. $\alpha$ is not finite dimensional (there is no finite upper bound on the lengths of increasing sequences in $\alpha$) 2. $\alpha$ is infinite dimensional (for every natural number $n$, there exists an increasing sequence in $\alpha$ of length $n$)
not_infiniteDimensionalOrder_iff theorem
[Preorder α] [Nonempty α] : ¬InfiniteDimensionalOrder α ↔ FiniteDimensionalOrder α
Full source
lemma not_infiniteDimensionalOrder_iff [Preorder α] [Nonempty α] :
    ¬ InfiniteDimensionalOrder α¬ InfiniteDimensionalOrder α ↔ FiniteDimensionalOrder α :=
  Rel.not_infiniteDimensional_iff
Equivalence of Non-Infinite Dimensionality and Finite Dimensionality for Preorders
Informal description
For a nonempty preorder $\alpha$, the following are equivalent: 1. $\alpha$ is not infinite dimensional (there does not exist arbitrarily long increasing sequences in $\alpha$) 2. $\alpha$ is finite dimensional (there exists a finite upper bound on the lengths of increasing sequences in $\alpha$)
finiteDimensionalOrder_or_infiniteDimensionalOrder theorem
[Preorder α] [Nonempty α] : FiniteDimensionalOrder α ∨ InfiniteDimensionalOrder α
Full source
lemma finiteDimensionalOrder_or_infiniteDimensionalOrder [Preorder α] [Nonempty α] :
    FiniteDimensionalOrderFiniteDimensionalOrder α ∨ InfiniteDimensionalOrder α :=
  Rel.finiteDimensional_or_infiniteDimensional _
Dichotomy for Preorder Dimensionality: Finite or Infinite
Informal description
For any nonempty preorder $\alpha$, either $\alpha$ is finite dimensional (there exists a finite upper bound on the lengths of all increasing sequences in $\alpha$) or $\alpha$ is infinite dimensional (for every natural number $n$, there exists an increasing sequence in $\alpha$ of length $n$).
infiniteDimensionalOrder_of_strictMono theorem
[Preorder α] [Preorder β] (f : α → β) (hf : StrictMono f) [InfiniteDimensionalOrder α] : InfiniteDimensionalOrder β
Full source
/-- If `f : α → β` is a strictly monotonic function and `α` is an infinite dimensional type then so
  is `β`. -/
lemma infiniteDimensionalOrder_of_strictMono [Preorder α] [Preorder β]
    (f : α → β) (hf : StrictMono f) [InfiniteDimensionalOrder α] :
    InfiniteDimensionalOrder β :=
  ⟨fun n ↦ ⟨(LTSeries.withLength _ n).map f hf, LTSeries.length_withLength α n⟩⟩
Strictly Monotonic Functions Preserve Infinite Dimensionality of Preorders
Informal description
Let $\alpha$ and $\beta$ be preorders. If there exists a strictly monotonic function $f : \alpha \to \beta$ and $\alpha$ is infinite dimensional, then $\beta$ is also infinite dimensional.