doc-next-gen

Mathlib.Data.Fin.Basic

Module docstring

{"# The finite type with n elements

Fin n is the type whose elements are natural numbers smaller than n. This file expands on the development in the core library.

Main definitions

Induction principles

  • finZeroElim : Elimination principle for the empty set Fin 0, generalizes Fin.elim0. Further definitions and eliminators can be found in Init.Data.Fin.Lemmas

Embeddings and isomorphisms

  • Fin.valEmbedding : coercion to natural numbers as an Embedding;
  • Fin.succEmb : Fin.succ as an Embedding;
  • Fin.castLEEmb h : Fin.castLE as an Embedding, embed Fin n into Fin m, h : n ≤ m;
  • finCongr : Fin.cast as an Equiv, equivalence between Fin n and Fin m when n = m;
  • Fin.castAddEmb m : Fin.castAdd as an Embedding, embed Fin n into Fin (n+m);
  • Fin.castSuccEmb : Fin.castSucc as an Embedding, embed Fin n into Fin (n+1);
  • Fin.addNatEmb m i : Fin.addNat as an Embedding, add m on i on the right, generalizes Fin.succ;
  • Fin.natAddEmb n i : Fin.natAdd as an Embedding, adds n on i on the left;

Other casts

  • Fin.divNat i : divides i : Fin (m * n) by n;
  • Fin.modNat i : takes the mod of i : Fin (m * n) by n;

","### coercions and constructions ","### order ","### Coercions to and the fin_omega tactic. ","### addition, numerals, and coercion from Nat ","### succ and casts into larger Fin types ","### pred ","### recursion and induction principles ","### mul "}

finZeroElim definition
{α : Fin 0 → Sort*} (x : Fin 0) : α x
Full source
/-- Elimination principle for the empty set `Fin 0`, dependent version. -/
def finZeroElim {α : Fin 0 → Sort*} (x : Fin 0) : α x :=
  x.elim0
Dependent Elimination Principle for `Fin 0`
Informal description
The elimination principle for the empty type `Fin 0` states that for any dependent type family `α : Fin 0 → Sort*`, and for any element `x : Fin 0`, we can construct an element of type `α x`. This is a dependent version of the elimination principle, generalizing `Fin.elim0`.
Fin.mk_eq_one theorem
{n a : Nat} {ha : a < n + 2} : (⟨a, ha⟩ : Fin (n + 2)) = 1 ↔ a = 1
Full source
@[simp] theorem mk_eq_one {n a : Nat} {ha : a < n + 2} :
    (⟨a, ha⟩ : Fin (n + 2)) = 1 ↔ a = 1 :=
  mk.inj_iff
Equality to One in Finite Type $\mathrm{Fin}(n+2)$
Informal description
For any natural numbers $n$ and $a$ with $a < n + 2$, the element $\langle a, ha\rangle$ of $\mathrm{Fin}(n+2)$ equals $1$ if and only if $a = 1$.
Fin.one_eq_mk theorem
{n a : Nat} {ha : a < n + 2} : 1 = (⟨a, ha⟩ : Fin (n + 2)) ↔ a = 1
Full source
@[simp] theorem one_eq_mk {n a : Nat} {ha : a < n + 2} :
    1 = (⟨a, ha⟩ : Fin (n + 2)) ↔ a = 1 := by
  simp [eq_comm]
Equality of One with Fin Element Construction
Informal description
For any natural numbers $n$ and $a$ with $a < n + 2$, the element $1$ in $\mathrm{Fin}(n+2)$ is equal to the element $\langle a, ha \rangle$ (where $ha$ is the proof that $a < n+2$) if and only if $a = 1$.
Fin.instCanLiftNatValLt instance
{n : ℕ} : CanLift ℕ (Fin n) Fin.val (· < n)
Full source
instance {n : } : CanLift  (Fin n) Fin.val (· < n) where
  prf k hk := ⟨⟨k, hk⟩, rfl⟩
Lifting Natural Numbers to Finite Types via Coercion
Informal description
For any natural number $n$, there exists a lifting condition from natural numbers to the finite type $\mathrm{Fin}(n)$ via the coercion function $\mathrm{Fin.val}$, where the lifting condition is that the natural number must be less than $n$.
Fin.rec0 definition
{α : Fin 0 → Sort*} (i : Fin 0) : α i
Full source
/-- A dependent variant of `Fin.elim0`. -/
def rec0 {α : Fin 0 → Sort*} (i : Fin 0) : α i := absurd i.2 (Nat.not_lt_zero _)
Dependent elimination principle for Fin 0
Informal description
The function `Fin.rec0` is a dependent elimination principle for the empty finite type `Fin 0`. For any type family `α : Fin 0 → Sort*` and any element `i : Fin 0`, it produces an element of type `α i`. This is possible because `Fin 0` has no elements (as witnessed by the proof that `0 < 0` is false), making this a vacuous definition.
Fin.val_injective theorem
: Function.Injective (@Fin.val n)
Full source
theorem val_injective : Function.Injective (@Fin.val n) :=
  @Fin.eq_of_val_eq n
Injectivity of the Natural Number Coercion from Finite Types
Informal description
The function `Fin.val` that maps an element of `Fin n` (natural numbers less than `n`) to its underlying natural number is injective. That is, for any two elements `i j : Fin n`, if `Fin.val i = Fin.val j`, then `i = j`.
Fin.size_positive theorem
: Fin n → 0 < n
Full source
/-- If you actually have an element of `Fin n`, then the `n` is always positive -/
lemma size_positive : Fin n → 0 < n := Fin.pos
Positivity of Finite Type Size
Informal description
For any element of the finite type `Fin n` (natural numbers less than `n`), the size `n` must be positive, i.e., $0 < n$.
Fin.size_positive' theorem
[Nonempty (Fin n)] : 0 < n
Full source
lemma size_positive' [Nonempty (Fin n)] : 0 < n :=
  ‹Nonempty (Fin n)›.elim Fin.pos
Positivity of Size for Nonempty Finite Types
Informal description
If the finite type `Fin n` is nonempty, then `n` is positive, i.e., $0 < n$.
Fin.prop theorem
(a : Fin n) : a.val < n
Full source
protected theorem prop (a : Fin n) : a.val < n :=
  a.2
Value Bound for Elements of Finite Type $\text{Fin}\,n$
Informal description
For any element $a$ of the finite type $\text{Fin}\,n$, the natural number value associated with $a$ is strictly less than $n$, i.e., $a.\text{val} < n$.
Fin.lt_last_iff_ne_last theorem
{a : Fin (n + 1)} : a < last n ↔ a ≠ last n
Full source
lemma lt_last_iff_ne_last {a : Fin (n + 1)} : a < last n ↔ a ≠ last n := by
  simp [Fin.lt_iff_le_and_ne, le_last]
Characterization of Elements Less Than the Last Element in $\mathrm{Fin}(n+1)$
Informal description
For any element $a$ of the finite type $\mathrm{Fin}(n+1)$, the inequality $a < \mathrm{last}(n)$ holds if and only if $a$ is not equal to $\mathrm{last}(n)$. Here, $\mathrm{last}(n)$ denotes the maximal element of $\mathrm{Fin}(n+1)$.
Fin.ne_zero_of_lt theorem
{a b : Fin (n + 1)} (hab : a < b) : b ≠ 0
Full source
lemma ne_zero_of_lt {a b : Fin (n + 1)} (hab : a < b) : b ≠ 0 :=
  Fin.ne_of_gt <| Fin.lt_of_le_of_lt a.zero_le hab
Nonzero Conclusion from Strict Inequality in $\mathrm{Fin}(n+1)$
Informal description
For any two elements $a$ and $b$ in $\mathrm{Fin}(n+1)$ (the finite type with $n+1$ elements), if $a < b$, then $b$ is not equal to $0$.
Fin.ne_last_of_lt theorem
{a b : Fin (n + 1)} (hab : a < b) : a ≠ last n
Full source
lemma ne_last_of_lt {a b : Fin (n + 1)} (hab : a < b) : a ≠ last n :=
  Fin.ne_of_lt <| Fin.lt_of_lt_of_le hab b.le_last
Strictly Less Elements Are Not Last in $\mathrm{Fin}(n+1)$
Informal description
For any elements $a$ and $b$ of $\mathrm{Fin}(n+1)$, if $a < b$, then $a$ is not equal to the last element of $\mathrm{Fin}(n+1)$.
Fin.equivSubtype definition
: Fin n ≃ { i // i < n }
Full source
/-- Equivalence between `Fin n` and `{ i // i < n }`. -/
@[simps apply symm_apply]
def equivSubtype : FinFin n ≃ { i // i < n } where
  toFun a := ⟨a.1, a.2⟩
  invFun a := ⟨a.1, a.2⟩
  left_inv := fun ⟨_, _⟩ => rfl
  right_inv := fun ⟨_, _⟩ => rfl
Equivalence between `Fin n` and natural numbers less than `n`
Informal description
The equivalence between the type `Fin n` (the canonical type with `n` elements) and the subtype `{i : ℕ // i < n}` (natural numbers less than `n`). The equivalence maps an element `a : Fin n` to the subtype element `⟨a.1, a.2⟩` and vice versa, where `a.1` is the underlying natural number and `a.2` is the proof that `a.1 < n`.
Fin.val_eq_val theorem
(a b : Fin n) : (a : ℕ) = b ↔ a = b
Full source
theorem val_eq_val (a b : Fin n) : (a : ℕ) = b ↔ a = b :=
  Fin.ext_iff.symm
Equality in $\mathrm{Fin}\,n$ via Natural Number Values
Informal description
For any two elements $a$ and $b$ of the finite type $\mathrm{Fin}\,n$, the natural number values of $a$ and $b$ are equal if and only if $a$ and $b$ are equal as elements of $\mathrm{Fin}\,n$.
Fin.ne_iff_vne theorem
(a b : Fin n) : a ≠ b ↔ a.1 ≠ b.1
Full source
theorem ne_iff_vne (a b : Fin n) : a ≠ ba ≠ b ↔ a.1 ≠ b.1 :=
  Fin.ext_iff.not
Inequality in Fin n Corresponds to Inequality of Underlying Natural Numbers
Informal description
For any two elements $a$ and $b$ of $\mathrm{Fin}\,n$ (the finite type with $n$ elements), $a$ is not equal to $b$ if and only if their underlying natural number values (obtained via the canonical coercion) are not equal. In other words: $$a \neq b \leftrightarrow a.1 \neq b.1$$ where $a.1$ and $b.1$ represent the natural number values of $a$ and $b$ respectively.
Fin.mk_eq_mk theorem
{a h a' h'} : @mk n a h = @mk n a' h' ↔ a = a'
Full source
theorem mk_eq_mk {a h a' h'} : @mk n a h = @mk n a' h' ↔ a = a' :=
  Fin.ext_iff
Equality in $\mathrm{Fin}\,n$ via Underlying Natural Numbers
Informal description
For any natural numbers $a, a' < n$ with proofs $h, h'$ respectively, the elements $\langle a, h \rangle$ and $\langle a', h' \rangle$ of $\mathrm{Fin}\,n$ are equal if and only if $a = a'$.
Fin.heq_fun_iff theorem
{α : Sort*} {k l : ℕ} (h : k = l) {f : Fin k → α} {g : Fin l → α} : HEq f g ↔ ∀ i : Fin k, f i = g ⟨(i : ℕ), h ▸ i.2⟩
Full source
/-- Assume `k = l`. If two functions defined on `Fin k` and `Fin l` are equal on each element,
then they coincide (in the heq sense). -/
protected theorem heq_fun_iff {α : Sort*} {k l : } (h : k = l) {f : Fin k → α} {g : Fin l → α} :
    HEqHEq f g ↔ ∀ i : Fin k, f i = g ⟨(i : ℕ), h ▸ i.2⟩ := by
  subst h
  simp [funext_iff]
Heterogeneous Equality of Functions on Finite Types with Equal Cardinality
Informal description
Let $k$ and $l$ be natural numbers with $k = l$, and let $f : \mathrm{Fin}\,k \to \alpha$ and $g : \mathrm{Fin}\,l \to \alpha$ be two functions. Then $f$ and $g$ are heterogeneously equal (denoted $\mathrm{HEq}\,f\,g$) if and only if for every $i \in \mathrm{Fin}\,k$, we have $f(i) = g(\langle i.1, h \cdot i.2 \rangle)$, where $i.1$ is the underlying natural number of $i$ and $i.2$ is the proof that $i.1 < k$.
Fin.heq_fun₂_iff theorem
{α : Sort*} {k l k' l' : ℕ} (h : k = l) (h' : k' = l') {f : Fin k → Fin k' → α} {g : Fin l → Fin l' → α} : HEq f g ↔ ∀ (i : Fin k) (j : Fin k'), f i j = g ⟨(i : ℕ), h ▸ i.2⟩ ⟨(j : ℕ), h' ▸ j.2⟩
Full source
/-- Assume `k = l` and `k' = l'`.
If two functions `Fin k → Fin k' → α` and `Fin l → Fin l' → α` are equal on each pair,
then they coincide (in the heq sense). -/
protected theorem heq_fun₂_iff {α : Sort*} {k l k' l' : } (h : k = l) (h' : k' = l')
    {f : Fin k → Fin k' → α} {g : Fin l → Fin l' → α} :
    HEqHEq f g ↔ ∀ (i : Fin k) (j : Fin k'), f i j = g ⟨(i : ℕ), h ▸ i.2⟩ ⟨(j : ℕ), h' ▸ j.2⟩ := by
  subst h
  subst h'
  simp [funext_iff]
Heterogeneous Equality of Bivariate Functions on Finite Types
Informal description
Let $k, l, k', l'$ be natural numbers with $k = l$ and $k' = l'$. Given two functions $f : \text{Fin } k \to \text{Fin } k' \to \alpha$ and $g : \text{Fin } l \to \text{Fin } l' \to \alpha$, the functions $f$ and $g$ are heterogeneously equal (denoted $\text{HEq } f g$) if and only if for all $i \in \text{Fin } k$ and $j \in \text{Fin } k'$, we have $f(i)(j) = g(\langle i, h \rangle)(\langle j, h' \rangle)$, where $\langle \cdot, \cdot \rangle$ denotes the construction of a $\text{Fin}$ element from a natural number and a proof that it is within bounds.
Fin.heq_ext_iff theorem
{k l : ℕ} (h : k = l) {i : Fin k} {j : Fin l} : HEq i j ↔ (i : ℕ) = (j : ℕ)
Full source
/-- Two elements of `Fin k` and `Fin l` are heq iff their values in `ℕ` coincide. This requires
`k = l`. For the left implication without this assumption, see `val_eq_val_of_heq`. -/
protected theorem heq_ext_iff {k l : } (h : k = l) {i : Fin k} {j : Fin l} :
    HEqHEq i j ↔ (i : ℕ) = (j : ℕ) := by
  subst h
  simp [val_eq_val]
Heterogeneous Equality in Finite Types via Natural Number Values
Informal description
For natural numbers $k$ and $l$ with $k = l$, two elements $i \in \text{Fin}(k)$ and $j \in \text{Fin}(l)$ are heterogeneously equal (denoted as $\text{HEq}$) if and only if their underlying natural number values are equal, i.e., $(i : \mathbb{N}) = (j : \mathbb{N})$.
Fin.le_iff_val_le_val theorem
{a b : Fin n} : a ≤ b ↔ (a : ℕ) ≤ b
Full source
theorem le_iff_val_le_val {a b : Fin n} : a ≤ b ↔ (a : ℕ) ≤ b :=
  Iff.rfl
Order in Fin n Corresponds to Order of Natural Number Values
Informal description
For any two elements $a$ and $b$ of the finite type $\text{Fin}\,n$, the inequality $a \leq b$ holds if and only if their underlying natural number values satisfy $(a : \mathbb{N}) \leq (b : \mathbb{N})$.
Fin.val_fin_lt theorem
{n : ℕ} {a b : Fin n} : (a : ℕ) < (b : ℕ) ↔ a < b
Full source
/-- `a < b` as natural numbers if and only if `a < b` in `Fin n`. -/
@[norm_cast, simp]
theorem val_fin_lt {n : } {a b : Fin n} : (a : ℕ) < (b : ℕ) ↔ a < b :=
  Iff.rfl
Inequality Correspondence Between $\text{Fin}\,n$ and $\mathbb{N}$
Informal description
For any natural number $n$ and elements $a, b$ of the finite type $\text{Fin}\,n$, the inequality $a < b$ holds in $\text{Fin}\,n$ if and only if the corresponding inequality $(a : \mathbb{N}) < (b : \mathbb{N})$ holds in the natural numbers.
Fin.val_fin_le theorem
{n : ℕ} {a b : Fin n} : (a : ℕ) ≤ (b : ℕ) ↔ a ≤ b
Full source
/-- `a ≤ b` as natural numbers if and only if `a ≤ b` in `Fin n`. -/
@[norm_cast, simp]
theorem val_fin_le {n : } {a b : Fin n} : (a : ℕ) ≤ (b : ℕ) ↔ a ≤ b :=
  Iff.rfl
Coercion Preserves Order in Finite Types: $(a : \mathbb{N}) \leq (b : \mathbb{N}) \leftrightarrow a \leq b$ in $\mathrm{Fin}\,n$
Informal description
For any natural number $n$ and elements $a, b$ of the finite type $\mathrm{Fin}\,n$, the inequality $a \leq b$ holds in $\mathrm{Fin}\,n$ if and only if the corresponding inequality $(a : \mathbb{N}) \leq (b : \mathbb{N})$ holds for their coercions to natural numbers.
Fin.min_val theorem
{a : Fin n} : min (a : ℕ) n = a
Full source
theorem min_val {a : Fin n} : min (a : ) n = a := by simp
Minimum of Finite Type Element and its Bound
Informal description
For any element $a$ of the finite type $\mathrm{Fin}\,n$, the minimum of the natural number corresponding to $a$ and $n$ is equal to $a$ itself, i.e., $\min(a, n) = a$.
Fin.max_val theorem
{a : Fin n} : max (a : ℕ) n = n
Full source
theorem max_val {a : Fin n} : max (a : ) n = n := by simp
Maximum of Finite Type Element and its Bound
Informal description
For any element $a$ of the finite type $\text{Fin}\,n$, the maximum of the natural number corresponding to $a$ and $n$ is equal to $n$, i.e., $\max(a, n) = n$.
Fin.valEmbedding definition
: Fin n ↪ ℕ
Full source
/-- The inclusion map `Fin n → ℕ` is an embedding. -/
@[simps -fullyApplied apply]
def valEmbedding : FinFin n ↪ ℕ :=
  ⟨val, val_injective⟩
Natural number embedding of finite types
Informal description
The embedding from the finite type $\mathrm{Fin}\,n$ (natural numbers less than $n$) to the natural numbers $\mathbb{N}$, given by the inclusion map that sends each element to its underlying natural number value.
Fin.equivSubtype_symm_trans_valEmbedding theorem
: equivSubtype.symm.toEmbedding.trans valEmbedding = Embedding.subtype (· < n)
Full source
@[simp]
theorem equivSubtype_symm_trans_valEmbedding :
    equivSubtype.symm.toEmbedding.trans valEmbedding = Embedding.subtype (· < n) :=
  rfl
Equivalence of Embeddings: `Fin n` and Subtype of Natural Numbers Less Than `n`
Informal description
The composition of the inverse of the equivalence between `Fin n` and the subtype `{i // i < n}` with the natural number embedding of `Fin n` is equal to the embedding of the subtype `{i // i < n}` into the natural numbers.
Fin.instWellFoundedRelation_mathlib instance
{n : ℕ} : WellFoundedRelation (Fin n)
Full source
/-- Use the ordering on `Fin n` for checking recursive definitions.

For example, the following definition is not accepted by the termination checker,
unless we declare the `WellFoundedRelation` instance:
```lean
def factorial {n : ℕ} : Fin n → ℕ
  | ⟨0, _⟩ := 1
  | ⟨i + 1, hi⟩ := (i + 1) * factorial ⟨i, i.lt_succ_self.trans hi⟩
```
-/
instance {n : } : WellFoundedRelation (Fin n) :=
  measure (val : Fin n → )
Well-founded Order on Finite Types $\text{Fin}\,n$
Informal description
For any natural number $n$, the type $\text{Fin}\,n$ of natural numbers less than $n$ is equipped with a well-founded relation given by the standard order on natural numbers.
Fin.mk_zero' theorem
(n : ℕ) [NeZero n] : (⟨0, pos_of_neZero n⟩ : Fin n) = 0
Full source
/-- `Fin.mk_zero` in `Lean` only applies in `Fin (n + 1)`.
This one instead uses a `NeZero n` typeclass hypothesis.
-/
@[simp]
theorem mk_zero' (n : ) [NeZero n] : (⟨0, pos_of_neZero n⟩ : Fin n) = 0 := rfl
Zero Element Construction in Nonzero Finite Types
Informal description
For any natural number $n$ with $n \neq 0$, the element $\langle 0, h \rangle$ of $\mathrm{Fin}\,n$ (where $h$ is a proof that $0 < n$) is equal to the zero element of $\mathrm{Fin}\,n$.
Fin.zero_le' theorem
[NeZero n] (a : Fin n) : 0 ≤ a
Full source
/--
The `Fin.zero_le` in `Lean` only applies in `Fin (n+1)`.
This one instead uses a `NeZero n` typeclass hypothesis.
-/
@[simp]
protected theorem zero_le' [NeZero n] (a : Fin n) : 0 ≤ a :=
  Nat.zero_le a.val
Nonzero Fin Zero is Minimal Element
Informal description
For any nonzero natural number $n$ and any element $a$ in the finite type $\mathrm{Fin}\,n$, the zero element is less than or equal to $a$ in the natural order on $\mathrm{Fin}\,n$.
Fin.val_eq_zero_iff theorem
[NeZero n] {a : Fin n} : a.val = 0 ↔ a = 0
Full source
@[simp, norm_cast]
theorem val_eq_zero_iff [NeZero n] {a : Fin n} : a.val = 0 ↔ a = 0 := by
  rw [Fin.ext_iff, val_zero]
Zero Value Characterization in Finite Types
Informal description
For a non-zero natural number $n$ and an element $a$ of the finite type $\mathrm{Fin}\,n$, the underlying natural number value of $a$ is zero if and only if $a$ is equal to the zero element of $\mathrm{Fin}\,n$.
Fin.val_ne_zero_iff theorem
[NeZero n] {a : Fin n} : a.val ≠ 0 ↔ a ≠ 0
Full source
theorem val_ne_zero_iff [NeZero n] {a : Fin n} : a.val ≠ 0a.val ≠ 0 ↔ a ≠ 0 :=
  val_eq_zero_iff.not
Non-zero Value Characterization in Finite Types
Informal description
For a non-zero natural number $n$ and an element $a$ of the finite type $\mathrm{Fin}\,n$, the underlying natural number value of $a$ is non-zero if and only if $a$ is not equal to the zero element of $\mathrm{Fin}\,n$.
Fin.val_pos_iff theorem
[NeZero n] {a : Fin n} : 0 < a.val ↔ 0 < a
Full source
@[simp, norm_cast]
theorem val_pos_iff [NeZero n] {a : Fin n} : 0 < a.val ↔ 0 < a := by
  rw [← val_fin_lt, val_zero]
Positivity Correspondence Between $\mathrm{Fin}\,n$ and $\mathbb{N}$
Informal description
For a non-zero natural number $n$ and an element $a$ of the finite type $\mathrm{Fin}\,n$, the underlying natural number value of $a$ is positive if and only if $a$ is positive in $\mathrm{Fin}\,n$.
Fin.pos_iff_ne_zero' theorem
[NeZero n] (a : Fin n) : 0 < a ↔ a ≠ 0
Full source
/--
The `Fin.pos_iff_ne_zero` in `Lean` only applies in `Fin (n+1)`.
This one instead uses a `NeZero n` typeclass hypothesis.
-/
theorem pos_iff_ne_zero' [NeZero n] (a : Fin n) : 0 < a ↔ a ≠ 0 := by
  rw [← val_pos_iff, Nat.pos_iff_ne_zero, val_ne_zero_iff]
Positivity in $\mathrm{Fin}\,n$ is Equivalent to Non-Zero Condition
Informal description
For a non-zero natural number $n$ and an element $a$ of the finite type $\mathrm{Fin}\,n$, the element $0$ is less than $a$ if and only if $a$ is not equal to $0$.
Fin.cast_eq_self theorem
(a : Fin n) : a.cast rfl = a
Full source
@[simp] lemma cast_eq_self (a : Fin n) : a.cast rfl = a := rfl
Reflexive Cast Identity in Finite Types
Informal description
For any element $a$ in the finite type $\text{Fin}\,n$, the cast of $a$ with respect to the reflexive equality proof $\text{rfl}$ is equal to $a$ itself, i.e., $a.\text{cast}(\text{rfl}) = a$.
Fin.cast_eq_zero theorem
{k l : ℕ} [NeZero k] [NeZero l] (h : k = l) (x : Fin k) : Fin.cast h x = 0 ↔ x = 0
Full source
@[simp] theorem cast_eq_zero {k l : } [NeZero k] [NeZero l]
    (h : k = l) (x : Fin k) : Fin.castFin.cast h x = 0 ↔ x = 0 := by
  simp [← val_eq_zero_iff]
Preservation of Zero under Fin Cast
Informal description
For any positive natural numbers $k$ and $l$ (with `[NeZero k]` and `[NeZero l]`), given an equality $h : k = l$ and an element $x \in \text{Fin }k$, the cast of $x$ under $h$ equals $0$ in $\text{Fin }l$ if and only if $x = 0$ in $\text{Fin }k$. In other words, the cast operation preserves the zero element: $\text{Fin.cast }h\, x = 0 \leftrightarrow x = 0$.
Fin.cast_injective theorem
{k l : ℕ} (h : k = l) : Injective (Fin.cast h)
Full source
lemma cast_injective {k l : } (h : k = l) : Injective (Fin.cast h) :=
  fun a b hab ↦ by simpa [← val_eq_val] using hab
Injectivity of Fin Cast Function
Informal description
For any natural numbers $k$ and $l$ and an equality proof $h : k = l$, the cast function $\operatorname{Fin.cast} h : \operatorname{Fin} k → \operatorname{Fin} l$ is injective.
Fin.last_pos' theorem
[NeZero n] : 0 < last n
Full source
theorem last_pos' [NeZero n] : 0 < last n := n.pos_of_neZero
Positivity of Last Element in Finite Type
Informal description
For any positive natural number $n$ (i.e., when `[NeZero n]` holds), the last element of `Fin n` is greater than 0, i.e., $0 < \text{last}(n)$.
Fin.coe_int_sub_eq_ite theorem
{n : Nat} (u v : Fin n) : ((u - v : Fin n) : Int) = if v ≤ u then (u - v : Int) else (u - v : Int) + n
Full source
theorem coe_int_sub_eq_ite {n : Nat} (u v : Fin n) :
    ((u - v : Fin n) : Int) = if v ≤ u then (u - v : Int) else (u - v : Int) + n := by
  rw [Fin.sub_def]
  split
  · rw [natCast_emod, Int.emod_eq_sub_self_emod, Int.emod_eq_of_lt] <;> omega
  · rw [natCast_emod, Int.emod_eq_of_lt] <;> omega
Integer Representation of Finite Type Subtraction via Conditional Expression
Informal description
For any natural number $n$ and elements $u, v$ in the finite type $\text{Fin}\ n$, the integer value of the difference $u - v$ in $\text{Fin}\ n$ is given by: \[ (u - v : \mathbb{Z}) = \begin{cases} (u - v : \mathbb{Z}) & \text{if } v \leq u, \\ (u - v : \mathbb{Z}) + n & \text{otherwise}. \end{cases} \]
Fin.coe_int_sub_eq_mod theorem
{n : Nat} (u v : Fin n) : ((u - v : Fin n) : Int) = ((u : Int) - (v : Int)) % n
Full source
theorem coe_int_sub_eq_mod {n : Nat} (u v : Fin n) :
    ((u - v : Fin n) : Int) = ((u : Int) - (v : Int)) % n := by
  rw [coe_int_sub_eq_ite]
  split
  · rw [Int.emod_eq_of_lt] <;> omega
  · rw [Int.emod_eq_add_self_emod, Int.emod_eq_of_lt] <;> omega
Integer Subtraction Modulo $n$ in Finite Types
Informal description
For any natural number $n$ and elements $u, v$ in the finite type $\text{Fin}\ n$, the integer value of the difference $u - v$ in $\text{Fin}\ n$ is equal to the modulo $n$ of the integer difference $(u : \mathbb{Z}) - (v : \mathbb{Z})$, i.e., \[ (u - v : \mathbb{Z}) = ((u : \mathbb{Z}) - (v : \mathbb{Z})) \bmod n. \]
Fin.coe_int_add_eq_ite theorem
{n : Nat} (u v : Fin n) : ((u + v : Fin n) : Int) = if (u + v : ℕ) < n then (u + v : Int) else (u + v : Int) - n
Full source
theorem coe_int_add_eq_ite {n : Nat} (u v : Fin n) :
    ((u + v : Fin n) : Int) = if (u + v : ℕ) < n then (u + v : Int) else (u + v : Int) - n := by
  rw [Fin.add_def]
  split
  · rw [natCast_emod, Int.emod_eq_of_lt] <;> omega
  · rw [natCast_emod, Int.emod_eq_sub_self_emod, Int.emod_eq_of_lt] <;> omega
Integer Representation of Finite Type Addition via Conditional Expression
Informal description
For any natural number $n$ and elements $u, v$ in $\text{Fin}\ n$, the integer value of the sum $u + v$ in $\text{Fin}\ n$ is given by: \[ (u + v : \mathbb{Z}) = \begin{cases} (u + v : \mathbb{Z}) & \text{if } u + v < n \text{ as natural numbers}, \\ (u + v : \mathbb{Z}) - n & \text{otherwise}. \end{cases} \]
Fin.coe_int_add_eq_mod theorem
{n : Nat} (u v : Fin n) : ((u + v : Fin n) : Int) = ((u : Int) + (v : Int)) % n
Full source
theorem coe_int_add_eq_mod {n : Nat} (u v : Fin n) :
    ((u + v : Fin n) : Int) = ((u : Int) + (v : Int)) % n := by
  rw [coe_int_add_eq_ite]
  split
  · rw [Int.emod_eq_of_lt] <;> omega
  · rw [Int.emod_eq_sub_self_emod, Int.emod_eq_of_lt] <;> omega
Integer Sum Congruence in Finite Types Modulo $n$
Informal description
For any natural number $n$ and elements $u, v$ in the finite type $\text{Fin}\ n$, the integer value of the sum $u + v$ in $\text{Fin}\ n$ is congruent modulo $n$ to the sum of their integer values, i.e., \[ (u + v : \mathbb{Z}) \equiv (u : \mathbb{Z}) + (v : \mathbb{Z}) \pmod{n}. \]
Fin.tacticFin_omega definition
: Lean.ParserDescr✝
Full source
macromacro "fin_omega" : tactic => `(tactic|
  { try simp only [fin_omega, ← Int.ofNat_lt, ← Int.ofNat_le] at *
    omega })
Fin omega tactic for inequalities in finite types
Informal description
The tactic `fin_omega` is a preprocessor for the `omega` tactic to handle inequalities involving elements of `Fin n`. It simplifies expressions by rewriting with lemmas specific to `Fin` and converting natural number inequalities to integer inequalities before applying the `omega` tactic.
Fin.val_one' theorem
(n : ℕ) [NeZero n] : ((1 : Fin n) : ℕ) = 1 % n
Full source
@[simp]
theorem val_one' (n : ) [NeZero n] : ((1 : Fin n) : ) = 1 % n :=
  rfl
Embedding of One in Finite Type Modulo $n$
Informal description
For any positive natural number $n$ (i.e., $n \neq 0$), the canonical embedding of the element $1$ in the finite type $\mathrm{Fin}\,n$ (natural numbers less than $n$) into $\mathbb{N}$ is equal to $1 \bmod n$.
Fin.val_one'' theorem
{n : ℕ} : ((1 : Fin (n + 1)) : ℕ) = 1 % (n + 1)
Full source
@[deprecated val_one' (since := "2025-03-10")]
theorem val_one'' {n : } : ((1 : Fin (n + 1)) : ) = 1 % (n + 1) :=
  rfl
Embedding of One in $\mathrm{Fin}(n+1)$ Equals One Modulo $n+1$
Informal description
For any natural number $n$, the canonical embedding of the element $1$ in the finite type $\mathrm{Fin}(n+1)$ into the natural numbers is equal to $1$ modulo $n+1$, i.e., $(1 : \mathrm{Fin}(n+1)) = 1 \mod (n+1)$.
Fin.default_eq_zero theorem
(n : ℕ) [NeZero n] : (default : Fin n) = 0
Full source
@[simp]
theorem default_eq_zero (n : ) [NeZero n] : (default : Fin n) = 0 :=
  rfl
Default Element of $\mathrm{Fin}(n)$ is Zero
Informal description
For any natural number $n \neq 0$, the default element of the finite type $\mathrm{Fin}(n)$ (the type of natural numbers less than $n$) is equal to $0$.
Fin.instNatCast instance
[NeZero n] : NatCast (Fin n)
Full source
instance instNatCast [NeZero n] : NatCast (Fin n) where
  natCast i := Fin.ofNat' n i
Natural Number Casting on Finite Types
Informal description
For any positive integer $n$, the finite type $\mathrm{Fin}\,n$ has a canonical structure of natural number casting, where a natural number $a$ is mapped to $\langle a \bmod n, \text{proof}\rangle \in \mathrm{Fin}\,n$.
Fin.natCast_def theorem
[NeZero n] (a : ℕ) : (a : Fin n) = ⟨a % n, mod_lt _ n.pos_of_neZero⟩
Full source
lemma natCast_def [NeZero n] (a : ) : (a : Fin n) = ⟨a % n, mod_lt _ n.pos_of_neZero⟩ := rfl
Definition of Natural Number Casting into Finite Type: $(a : \mathrm{Fin}\,n) = \langle a \bmod n, \text{proof}\rangle$
Informal description
For any positive integer $n$ and natural number $a$, the canonical casting of $a$ into $\mathrm{Fin}\,n$ is equal to the pair $\langle a \bmod n, \text{proof}\rangle$, where the proof ensures that $a \bmod n < n$.
Fin.val_add_eq_ite theorem
{n : ℕ} (a b : Fin n) : (↑(a + b) : ℕ) = if n ≤ a + b then a + b - n else a + b
Full source
theorem val_add_eq_ite {n : } (a b : Fin n) :
    (↑(a + b) : ) = if n ≤ a + b then a + b - n else a + b := by
  rw [Fin.val_add, Nat.add_mod_eq_ite, Nat.mod_eq_of_lt (show ↑a < n from a.2),
    Nat.mod_eq_of_lt (show ↑b < n from b.2)]
Value of Sum in Finite Type with Condition
Informal description
For any natural number $n$ and elements $a, b$ of the finite type $\mathrm{Fin}\,n$, the natural number value of their sum is given by: \[ \text{val}(a + b) = \begin{cases} a + b - n & \text{if } n \leq a + b, \\ a + b & \text{otherwise.} \end{cases} \] Here, $\text{val}(x)$ denotes the underlying natural number value of $x \in \mathrm{Fin}\,n$.
Fin.val_add_eq_of_add_lt theorem
{n : ℕ} {a b : Fin n} (huv : a.val + b.val < n) : (a + b).val = a.val + b.val
Full source
theorem val_add_eq_of_add_lt {n : } {a b : Fin n} (huv : a.val + b.val < n) :
    (a + b).val = a.val + b.val := by
  rw [val_add]
  simp [Nat.mod_eq_of_lt huv]
Value of Finite Addition When Sum is Within Bounds
Informal description
For any natural number $n$ and elements $a, b$ in $\mathrm{Fin}(n)$, if the sum of their underlying natural numbers $a.\mathrm{val} + b.\mathrm{val}$ is less than $n$, then the underlying natural number of their sum $(a + b).\mathrm{val}$ equals $a.\mathrm{val} + b.\mathrm{val}$.
Fin.intCast_val_sub_eq_sub_add_ite theorem
{n : ℕ} (a b : Fin n) : ((a - b).val : ℤ) = a.val - b.val + if b ≤ a then 0 else n
Full source
lemma intCast_val_sub_eq_sub_add_ite {n : } (a b : Fin n) :
    ((a - b).val : ) = a.val - b.val + if b ≤ a then 0 else n := by
  split <;> fin_omega
Integer Representation of Finite Type Subtraction with Conditional Offset
Informal description
For any natural number $n$ and elements $a, b$ in the finite type $\mathrm{Fin}\,n$, the integer value of the difference $(a - b).\mathrm{val}$ is given by: \[ (a - b).\mathrm{val} = a.\mathrm{val} - b.\mathrm{val} + \begin{cases} 0 & \text{if } b \leq a, \\ n & \text{otherwise.} \end{cases} \] where $a.\mathrm{val}$ and $b.\mathrm{val}$ denote the underlying natural number values of $a$ and $b$ respectively.
Fin.one_le_of_ne_zero theorem
{n : ℕ} [NeZero n] {k : Fin n} (hk : k ≠ 0) : 1 ≤ k
Full source
lemma one_le_of_ne_zero {n : } [NeZero n] {k : Fin n} (hk : k ≠ 0) : 1 ≤ k := by
  obtain ⟨n, rfl⟩ := Nat.exists_eq_succ_of_ne_zero (NeZero.ne n)
  cases n with
  | zero => simp only [Nat.reduceAdd, Fin.isValue, Fin.zero_le]
  | succ n => rwa [Fin.le_iff_val_le_val, Fin.val_one, Nat.one_le_iff_ne_zero, val_ne_zero_iff]
Non-zero Elements in Finite Types are At Least One
Informal description
For any positive integer $n$ and any non-zero element $k$ in $\mathrm{Fin}\,n$, we have $1 \leq k$.
Fin.val_sub_one_of_ne_zero theorem
[NeZero n] {i : Fin n} (hi : i ≠ 0) : (i - 1).val = i - 1
Full source
lemma val_sub_one_of_ne_zero [NeZero n] {i : Fin n} (hi : i ≠ 0) : (i - 1).val = i - 1 := by
  obtain ⟨n, rfl⟩ := Nat.exists_eq_succ_of_ne_zero (NeZero.ne n)
  rw [Fin.sub_val_of_le (one_le_of_ne_zero hi), Fin.val_one', Nat.mod_eq_of_lt
    (Nat.succ_le_iff.mpr (nontrivial_iff_two_le.mp <| nontrivial_of_ne i 0 hi))]
Value of Predecessor in Finite Type for Non-Zero Elements
Informal description
For any positive integer $n$ (i.e., $n \neq 0$) and any non-zero element $i$ in $\mathrm{Fin}\,n$, the underlying value of $i - 1$ is equal to $i - 1$ (as natural numbers).
Fin.ofNat'_eq_cast theorem
(n : ℕ) [NeZero n] (a : ℕ) : Fin.ofNat' n a = a
Full source
@[simp]
theorem ofNat'_eq_cast (n : ) [NeZero n] (a : ) : Fin.ofNat' n a = a :=
  rfl
Equality of Finite Type Construction and Natural Number Casting
Informal description
For any positive integer $n$ and any natural number $a$, the construction of a finite type element via `Fin.ofNat' n a` is equal to the canonical casting of $a$ into $\mathrm{Fin}\,n$, i.e., $\mathrm{Fin.ofNat'}\,n\,a = a$.
Fin.val_natCast theorem
(a n : ℕ) [NeZero n] : (a : Fin n).val = a % n
Full source
@[simp] lemma val_natCast (a n : ) [NeZero n] : (a : Fin n).val = a % n := rfl
Value of Natural Number Cast in Finite Type Equals Modulo
Informal description
For any natural numbers $a$ and $n$ with $n \neq 0$, the underlying value of the cast of $a$ into $\mathrm{Fin}\,n$ is equal to $a$ modulo $n$, i.e., $(a : \mathrm{Fin}\,n).\mathrm{val} = a \bmod n$.
Fin.val_cast_of_lt theorem
{n : ℕ} [NeZero n] {a : ℕ} (h : a < n) : (a : Fin n).val = a
Full source
/-- Converting an in-range number to `Fin (n + 1)` produces a result
whose value is the original number. -/
theorem val_cast_of_lt {n : } [NeZero n] {a : } (h : a < n) : (a : Fin n).val = a :=
  Nat.mod_eq_of_lt h
Value of Natural Number Cast in Finite Type When Less Than Modulus
Informal description
For any positive integer $n$ and any natural number $a < n$, the underlying value of the cast $a : \mathrm{Fin}\,n$ is equal to $a$.
Fin.cast_val_eq_self theorem
{n : ℕ} [NeZero n] (a : Fin n) : (a.val : Fin n) = a
Full source
/-- If `n` is non-zero, converting the value of a `Fin n` to `Fin n` results
in the same value. -/
@[simp, norm_cast] theorem cast_val_eq_self {n : } [NeZero n] (a : Fin n) : (a.val : Fin n) = a :=
  Fin.ext <| val_cast_of_lt a.isLt
Self-Casting Property of Finite Type Elements: $(a.\mathrm{val} : \mathrm{Fin}\,n) = a$
Informal description
For any positive integer $n$ and any element $a \in \mathrm{Fin}\,n$, casting the underlying value of $a$ back to $\mathrm{Fin}\,n$ yields $a$ itself, i.e., $(a.\mathrm{val} : \mathrm{Fin}\,n) = a$.
Fin.natCast_self theorem
(n : ℕ) [NeZero n] : (n : Fin n) = 0
Full source
@[simp high] lemma natCast_self (n : ) [NeZero n] : (n : Fin n) = 0 := by ext; simp
Self-Cast to Zero in Finite Types: $(n : \mathrm{Fin}\,n) = 0$
Informal description
For any positive integer $n$, the natural number $n$ cast as an element of $\mathrm{Fin}\,n$ equals $0$, i.e., $(n : \mathrm{Fin}\,n) = 0$.
Fin.natCast_eq_zero theorem
{a n : ℕ} [NeZero n] : (a : Fin n) = 0 ↔ n ∣ a
Full source
@[simp] lemma natCast_eq_zero {a n : } [NeZero n] : (a : Fin n) = 0 ↔ n ∣ a := by
  simp [Fin.ext_iff, Nat.dvd_iff_mod_eq_zero]
Characterization of Zero in Finite Type Casting: $(a : \mathrm{Fin}\,n) = 0 \leftrightarrow n \mid a$
Informal description
For any natural numbers $a$ and $n$ with $n \neq 0$, the cast of $a$ into $\mathrm{Fin}\,n$ equals zero if and only if $n$ divides $a$. In other words, $(a : \mathrm{Fin}\,n) = 0 \leftrightarrow n \mid a$.
Fin.natCast_eq_last theorem
(n) : (n : Fin (n + 1)) = Fin.last n
Full source
@[simp]
theorem natCast_eq_last (n) : (n : Fin (n + 1)) = Fin.last n := by ext; simp
Casting $n$ as the Last Element of $\mathrm{Fin}(n+1)$
Informal description
For any natural number $n$, the canonical casting of $n$ into $\mathrm{Fin}(n+1)$ equals the last element of $\mathrm{Fin}(n+1)$, i.e., $(n : \mathrm{Fin}(n+1)) = \mathrm{last}\,n$.
Fin.le_val_last theorem
(i : Fin (n + 1)) : i ≤ n
Full source
theorem le_val_last (i : Fin (n + 1)) : i ≤ n := by
  rw [Fin.natCast_eq_last]
  exact Fin.le_last i
Natural Number Value Bound in $\mathrm{Fin}(n+1)$
Informal description
For any element $i$ in the finite type $\mathrm{Fin}(n+1)$, the natural number value of $i$ is less than or equal to $n$.
Fin.natCast_le_natCast theorem
(han : a ≤ n) (hbn : b ≤ n) : (a : Fin (n + 1)) ≤ b ↔ a ≤ b
Full source
lemma natCast_le_natCast (han : a ≤ n) (hbn : b ≤ n) : (a : Fin (n + 1)) ≤ b ↔ a ≤ b := by
  rw [← Nat.lt_succ_iff] at han hbn
  simp [le_iff_val_le_val, -val_fin_le, Nat.mod_eq_of_lt, han, hbn]
Comparison of Natural Number Casts in Finite Types: $(a : \mathrm{Fin}(n+1)) \leq b \leftrightarrow a \leq b$
Informal description
For any natural numbers $a$ and $b$ such that $a \leq n$ and $b \leq n$, the cast of $a$ into $\mathrm{Fin}(n+1)$ is less than or equal to the cast of $b$ if and only if $a \leq b$ holds as natural numbers.
Fin.natCast_lt_natCast theorem
(han : a ≤ n) (hbn : b ≤ n) : (a : Fin (n + 1)) < b ↔ a < b
Full source
lemma natCast_lt_natCast (han : a ≤ n) (hbn : b ≤ n) : (a : Fin (n + 1)) < b ↔ a < b := by
  rw [← Nat.lt_succ_iff] at han hbn; simp [lt_iff_val_lt_val, Nat.mod_eq_of_lt, han, hbn]
Comparison of Natural Number Casts in Finite Types: $(a : \mathrm{Fin}(n+1)) < b \leftrightarrow a < b$
Informal description
For any natural numbers $a, b$ and positive integer $n$ such that $a \leq n$ and $b \leq n$, the cast of $a$ in $\mathrm{Fin}(n+1)$ is less than the cast of $b$ if and only if $a < b$ as natural numbers.
Fin.natCast_mono theorem
(hbn : b ≤ n) (hab : a ≤ b) : (a : Fin (n + 1)) ≤ b
Full source
lemma natCast_mono (hbn : b ≤ n) (hab : a ≤ b) : (a : Fin (n + 1)) ≤ b :=
  (natCast_le_natCast (hab.trans hbn) hbn).2 hab
Monotonicity of Natural Number Cast in Finite Types: $(a : \mathrm{Fin}(n+1)) \leq b$ when $a \leq b \leq n$
Informal description
For any natural numbers $a$, $b$, and $n$ such that $b \leq n$ and $a \leq b$, the cast of $a$ into $\mathrm{Fin}(n+1)$ is less than or equal to $b$.
Fin.natCast_strictMono theorem
(hbn : b ≤ n) (hab : a < b) : (a : Fin (n + 1)) < b
Full source
lemma natCast_strictMono (hbn : b ≤ n) (hab : a < b) : (a : Fin (n + 1)) < b :=
  (natCast_lt_natCast (hab.le.trans hbn) hbn).2 hab
Strict Monotonicity of Natural Number Cast in Finite Types: $(a : \mathrm{Fin}(n+1)) < b$ when $a < b \leq n$
Informal description
For any natural numbers $a$, $b$, and $n$ such that $b \leq n$ and $a < b$, the cast of $a$ into $\mathrm{Fin}(n+1)$ is strictly less than $b$.
Fin.succ_injective theorem
(n : ℕ) : Injective (@Fin.succ n)
Full source
lemma succ_injective (n : ) : Injective (@Fin.succ n) := fun a b ↦ by simp [Fin.ext_iff]
Injectivity of the Successor Function on Finite Types
Informal description
For any natural number $n$, the successor function $\operatorname{succ} : \operatorname{Fin} n \to \operatorname{Fin} (n+1)$ is injective. That is, for any $i, j \in \operatorname{Fin} n$, if $\operatorname{succ}(i) = \operatorname{succ}(j)$, then $i = j$.
Fin.succEmb definition
(n : ℕ) : Fin n ↪ Fin (n + 1)
Full source
/-- `Fin.succ` as an `Embedding` -/
def succEmb (n : ) : FinFin n ↪ Fin (n + 1) where
  toFun := succ
  inj' := succ_injective _
Successor embedding for finite types
Informal description
The embedding $\text{Fin.succEmb} : \text{Fin} n \hookrightarrow \text{Fin} (n+1)$ maps each element $i$ of the finite type $\text{Fin} n$ to its successor $\text{succ}(i) = i + 1$ in $\text{Fin} (n+1)$. This embedding is injective, meaning distinct elements in $\text{Fin} n$ have distinct successors in $\text{Fin} (n+1)$.
Fin.coe_succEmb theorem
: ⇑(succEmb n) = Fin.succ
Full source
@[simp]
theorem coe_succEmb : ⇑(succEmb n) = Fin.succ :=
  rfl
Embedding Function of Successor Equals Successor Function on Finite Types
Informal description
The underlying function of the successor embedding $\text{succEmb}$ for finite types $\text{Fin} n$ is equal to the successor function $\text{Fin.succ}$.
Fin.exists_succ_eq theorem
{x : Fin (n + 1)} : (∃ y, Fin.succ y = x) ↔ x ≠ 0
Full source
@[simp]
theorem exists_succ_eq {x : Fin (n + 1)} : (∃ y, Fin.succ y = x) ↔ x ≠ 0 :=
  ⟨fun ⟨_, hy⟩ => hy ▸ succ_ne_zero _, x.cases (fun h => h.irrefl.elim) (fun _ _ => ⟨_, rfl⟩)⟩
Existence of Predecessor in Finite Types: $\exists y, \text{succ}(y) = x \leftrightarrow x \neq 0$
Informal description
For any element $x$ in $\text{Fin}(n+1)$, there exists an element $y$ in $\text{Fin}(n)$ such that $\text{succ}(y) = x$ if and only if $x \neq 0$.
Fin.exists_succ_eq_of_ne_zero theorem
{x : Fin (n + 1)} (h : x ≠ 0) : ∃ y, Fin.succ y = x
Full source
theorem exists_succ_eq_of_ne_zero {x : Fin (n + 1)} (h : x ≠ 0) :
    ∃ y, Fin.succ y = x := exists_succ_eq.mpr h
Existence of Predecessor for Nonzero Elements in Finite Types
Informal description
For any element $x$ in $\text{Fin}(n+1)$ such that $x \neq 0$, there exists an element $y$ in $\text{Fin}(n)$ satisfying $\text{succ}(y) = x$.
Fin.succ_zero_eq_one' theorem
[NeZero n] : Fin.succ (0 : Fin n) = 1
Full source
@[simp]
theorem succ_zero_eq_one' [NeZero n] : Fin.succ (0 : Fin n) = 1 := by
  cases n
  · exact (NeZero.ne 0 rfl).elim
  · rfl
Successor of Zero Equals One in Finite Types
Informal description
For any positive natural number $n$ (i.e., when `[NeZero n]` holds), the successor of zero in `Fin n` equals one, i.e., $\text{succ}(0) = 1$.
Fin.one_pos' theorem
[NeZero n] : (0 : Fin (n + 1)) < 1
Full source
theorem one_pos' [NeZero n] : (0 : Fin (n + 1)) < 1 := succ_zero_eq_one' (n := n) ▸ succ_pos _
Positivity of One in $\mathrm{Fin}(n+1)$ for Non-Zero $n$
Informal description
For any positive natural number $n$ (i.e., when $n \neq 0$), the element $0$ is strictly less than $1$ in the finite type $\mathrm{Fin}(n+1)$.
Fin.zero_ne_one' theorem
[NeZero n] : (0 : Fin (n + 1)) ≠ 1
Full source
theorem zero_ne_one' [NeZero n] : (0 : Fin (n + 1)) ≠ 1 := Fin.ne_of_lt one_pos'
Distinctness of Zero and One in $\mathrm{Fin}(n+1)$ for Non-Zero $n$
Informal description
For any positive natural number $n$ (i.e., when $n \neq 0$), the elements $0$ and $1$ are distinct in the finite type $\mathrm{Fin}(n+1)$, i.e., $0 \neq 1$.
Fin.succ_one_eq_two' theorem
[NeZero n] : Fin.succ (1 : Fin (n + 1)) = 2
Full source
/--
The `Fin.succ_one_eq_two` in `Lean` only applies in `Fin (n+2)`.
This one instead uses a `NeZero n` typeclass hypothesis.
-/
@[simp]
theorem succ_one_eq_two' [NeZero n] : Fin.succ (1 : Fin (n + 1)) = 2 := by
  cases n
  · exact (NeZero.ne 0 rfl).elim
  · rfl
Successor of One Equals Two in $\mathrm{Fin}(n+1)$ for Non-Zero $n$
Informal description
For any non-zero natural number $n$, the successor of the element $1$ in $\mathrm{Fin}(n+1)$ is equal to $2$.
Fin.le_zero_iff' theorem
{n : ℕ} [NeZero n] {k : Fin n} : k ≤ 0 ↔ k = 0
Full source
/--
The `Fin.le_zero_iff` in `Lean` only applies in `Fin (n+1)`.
This one instead uses a `NeZero n` typeclass hypothesis.
-/
@[simp]
theorem le_zero_iff' {n : } [NeZero n] {k : Fin n} : k ≤ 0 ↔ k = 0 :=
  ⟨fun h => Fin.ext <| by rw [Nat.eq_zero_of_le_zero h]; rfl, by rintro rfl; exact Nat.le_refl _⟩
Characterization of Zero in Finite Types: $k \leq 0 \leftrightarrow k = 0$ in $\text{Fin}\,n$
Informal description
For any natural number $n \neq 0$ and any element $k$ of the finite type $\text{Fin}\,n$, the inequality $k \leq 0$ holds if and only if $k = 0$.
Fin.castLE_inj theorem
{hmn : m ≤ n} {a b : Fin m} : castLE hmn a = castLE hmn b ↔ a = b
Full source
@[simp] lemma castLE_inj {hmn : m ≤ n} {a b : Fin m} : castLEcastLE hmn a = castLE hmn b ↔ a = b := by
  simp [Fin.ext_iff]
Injectivity of Finite Type Casting: $\text{castLE}\ hmn\ a = \text{castLE}\ hmn\ b \leftrightarrow a = b$
Informal description
For any natural numbers $m$ and $n$ with $m \leq n$, and for any elements $a, b$ of $\text{Fin}\ m$, the cast $\text{castLE}\ hmn\ a$ equals $\text{castLE}\ hmn\ b$ if and only if $a = b$.
Fin.castAdd_inj theorem
{a b : Fin m} : castAdd n a = castAdd n b ↔ a = b
Full source
@[simp] lemma castAdd_inj {a b : Fin m} : castAddcastAdd n a = castAdd n b ↔ a = b := by simp [Fin.ext_iff]
Injectivity of Cast Addition on Finite Types: $\text{castAdd}\, n\, a = \text{castAdd}\, n\, b \leftrightarrow a = b$
Informal description
For any natural numbers $m$ and $n$, and any elements $a, b$ of $\text{Fin}\, m$, the equality $\text{castAdd}\, n\, a = \text{castAdd}\, n\, b$ holds if and only if $a = b$.
Fin.castLE_injective theorem
(hmn : m ≤ n) : Injective (castLE hmn)
Full source
lemma castLE_injective (hmn : m ≤ n) : Injective (castLE hmn) :=
  fun _ _ hab ↦ Fin.ext (congr_arg val hab :)
Injectivity of the Fin Cast Under Increasing Bounds
Informal description
For any natural numbers $m$ and $n$ with $m \leq n$, the function $\mathrm{castLE}_{hmn} : \mathrm{Fin}\, m \to \mathrm{Fin}\, n$ is injective. That is, for any $a, b \in \mathrm{Fin}\, m$, if $\mathrm{castLE}_{hmn}(a) = \mathrm{castLE}_{hmn}(b)$, then $a = b$.
Fin.castAdd_injective theorem
(m n : ℕ) : Injective (@Fin.castAdd m n)
Full source
lemma castAdd_injective (m n : ) : Injective (@Fin.castAdd m n) := castLE_injective _
Injectivity of Finite Type Cast Addition: $\mathrm{castAdd}_n$ is injective
Informal description
For any natural numbers $m$ and $n$, the function $\mathrm{castAdd}_n : \mathrm{Fin}\, m \to \mathrm{Fin}\, (m + n)$ is injective. That is, for any $a, b \in \mathrm{Fin}\, m$, if $\mathrm{castAdd}_n(a) = \mathrm{castAdd}_n(b)$, then $a = b$.
Fin.castSucc_injective theorem
(n : ℕ) : Injective (@Fin.castSucc n)
Full source
lemma castSucc_injective (n : ) : Injective (@Fin.castSucc n) := castAdd_injective _ _
Injectivity of the Successor Cast for Finite Types
Informal description
For any natural number $n$, the function $\mathrm{castSucc} : \mathrm{Fin}\, n \to \mathrm{Fin}\, (n + 1)$ is injective. That is, for any $a, b \in \mathrm{Fin}\, n$, if $\mathrm{castSucc}(a) = \mathrm{castSucc}(b)$, then $a = b$.
Fin.castLEEmb definition
(h : n ≤ m) : Fin n ↪ Fin m
Full source
/-- `Fin.castLE` as an `Embedding`, `castLEEmb h i` embeds `i` into a larger `Fin` type. -/
@[simps apply]
def castLEEmb (h : n ≤ m) : FinFin n ↪ Fin m where
  toFun := castLE h
  inj' := castLE_injective _
Embedding of \(\mathrm{Fin}\, n\) into \(\mathrm{Fin}\, m\) for \( n \leq m \)
Informal description
For natural numbers \( n \) and \( m \) with \( n \leq m \), the embedding \(\mathrm{castLEEmb}_h : \mathrm{Fin}\, n \hookrightarrow \mathrm{Fin}\, m\) is defined by the function \(\mathrm{castLE}_h\), which maps an element of \(\mathrm{Fin}\, n\) to the corresponding element in \(\mathrm{Fin}\, m\) under the inequality \( n \leq m \). This embedding is injective.
Fin.coe_castLEEmb theorem
{m n} (hmn : m ≤ n) : castLEEmb hmn = castLE hmn
Full source
@[simp, norm_cast] lemma coe_castLEEmb {m n} (hmn : m ≤ n) : castLEEmb hmn = castLE hmn := rfl
Equality of Embedding and Cast Function for $\mathrm{Fin}$ Types under Inequality
Informal description
For natural numbers $m$ and $n$ with $m \leq n$, the embedding $\mathrm{castLEEmb}_{hmn} : \mathrm{Fin}\, m \hookrightarrow \mathrm{Fin}\, n$ is equal to the function $\mathrm{castLE}_{hmn}$ that maps an element of $\mathrm{Fin}\, m$ to the corresponding element in $\mathrm{Fin}\, n$.
Fin.nonempty_embedding_iff theorem
: Nonempty (Fin n ↪ Fin m) ↔ n ≤ m
Full source
lemma nonempty_embedding_iff : NonemptyNonempty (Fin n ↪ Fin m) ↔ n ≤ m := by
  refine ⟨fun h ↦ ?_, fun h ↦ ⟨castLEEmb h⟩⟩
  induction n generalizing m with
  | zero => exact m.zero_le
  | succ n ihn =>
    obtain ⟨e⟩ := h
    rcases exists_eq_succ_of_ne_zero (pos_iff_nonempty.2 (Nonempty.map e inferInstance)).ne'
      with ⟨m, rfl⟩
    refine Nat.succ_le_succ <| ihn ⟨?_⟩
    refine ⟨fun i ↦ (e.setValue 0 0 i.succ).pred (mt e.setValue_eq_iff.1 i.succ_ne_zero),
      fun i j h ↦ ?_⟩
    simpa only [pred_inj, EmbeddingLike.apply_eq_iff_eq, succ_inj] using h
Existence of Embedding Between Finite Types $\mathrm{Fin}\,n \hookrightarrow \mathrm{Fin}\,m$ iff $n \leq m$
Informal description
For natural numbers $n$ and $m$, there exists an embedding from $\mathrm{Fin}\,n$ to $\mathrm{Fin}\,m$ if and only if $n \leq m$.
Fin.equiv_iff_eq theorem
: Nonempty (Fin m ≃ Fin n) ↔ m = n
Full source
lemma equiv_iff_eq : NonemptyNonempty (Fin m ≃ Fin n) ↔ m = n :=
  ⟨fun ⟨e⟩ ↦ le_antisymm (nonempty_embedding_iff.1 ⟨e⟩) (nonempty_embedding_iff.1 ⟨e.symm⟩),
    fun h ↦ h ▸ ⟨.refl _⟩⟩
Equivalence of Finite Types $\mathrm{Fin}\,m \simeq \mathrm{Fin}\,n$ iff $m = n$
Informal description
For natural numbers $m$ and $n$, there exists an equivalence between the finite types $\mathrm{Fin}\,m$ and $\mathrm{Fin}\,n$ if and only if $m = n$.
Fin.castLE_castSucc theorem
{n m} (i : Fin n) (h : n + 1 ≤ m) : i.castSucc.castLE h = i.castLE (Nat.le_of_succ_le h)
Full source
@[simp] lemma castLE_castSucc {n m} (i : Fin n) (h : n + 1 ≤ m) :
    i.castSucc.castLE h = i.castLE (Nat.le_of_succ_le h) :=
  rfl
Commutativity of Successor and Order-Preserving Embeddings for Finite Types
Informal description
For any natural numbers $n$ and $m$, and any element $i \in \text{Fin}\ n$, if $n + 1 \leq m$, then the composition of the embedding $\text{castSucc}$ (which maps $\text{Fin}\ n$ to $\text{Fin}\ (n+1)$) followed by the embedding $\text{castLE}\ h$ (which maps $\text{Fin}\ (n+1)$ to $\text{Fin}\ m$) is equal to the direct embedding $\text{castLE}\ (n \leq m)$ applied to $i$. In other words, the following diagram commutes: $$\text{Fin}\ n \xrightarrow{\text{castSucc}} \text{Fin}\ (n+1) \xrightarrow{\text{castLE}\ h} \text{Fin}\ m$$ is equal to: $$\text{Fin}\ n \xrightarrow{\text{castLE}\ (n \leq m)} \text{Fin}\ m$$
Fin.castLE_comp_castSucc theorem
{n m} (h : n + 1 ≤ m) : Fin.castLE h ∘ Fin.castSucc = Fin.castLE (Nat.le_of_succ_le h)
Full source
@[simp] lemma castLE_comp_castSucc {n m} (h : n + 1 ≤ m) :
    Fin.castLEFin.castLE h ∘ Fin.castSucc = Fin.castLE (Nat.le_of_succ_le h) :=
  rfl
Composition of Fin Embeddings: $\operatorname{castLE} h \circ \operatorname{castSucc} = \operatorname{castLE} (\operatorname{le\_of\_succ\_le} h)$
Informal description
For natural numbers $n$ and $m$ with $n + 1 \leq m$, the composition of the embedding $\operatorname{castLE} h$ (which embeds $\operatorname{Fin} n$ into $\operatorname{Fin} m$) with the successor embedding $\operatorname{castSucc}$ (which embeds $\operatorname{Fin} n$ into $\operatorname{Fin} (n+1)$) is equal to the embedding $\operatorname{castLE} (\operatorname{Nat.le\_of\_succ\_le} h)$ (which embeds $\operatorname{Fin} n$ directly into $\operatorname{Fin} m$ under the weaker assumption $n \leq m$).
Fin.castLE_rfl theorem
(n : ℕ) : Fin.castLE (le_refl n) = id
Full source
@[simp] lemma castLE_rfl (n : ) : Fin.castLE (le_refl n) = id :=
  rfl
Identity Property of `Fin.castLE` for Reflexive Order
Informal description
For any natural number $n$, the cast function `Fin.castLE` applied with the reflexive proof of $n \leq n$ is equal to the identity function on `Fin n`.
Fin.range_castLE theorem
{n k : ℕ} (h : n ≤ k) : Set.range (castLE h) = {i : Fin k | (i : ℕ) < n}
Full source
@[simp]
theorem range_castLE {n k : } (h : n ≤ k) : Set.range (castLE h) = { i : Fin k | (i : ℕ) < n } :=
  Set.ext fun x => ⟨fun ⟨y, hy⟩ => hy ▸ y.2, fun hx => ⟨⟨x, hx⟩, rfl⟩⟩
Range of the Order-Preserving Embedding from $\mathrm{Fin}\, n$ to $\mathrm{Fin}\, k$
Informal description
For natural numbers $n$ and $k$ with $n \leq k$, the range of the embedding $\mathrm{castLE}\, h : \mathrm{Fin}\, n \to \mathrm{Fin}\, k$ is equal to the set of elements $i \in \mathrm{Fin}\, k$ whose underlying natural number value is less than $n$. That is, \[ \mathrm{range}\, (\mathrm{castLE}\, h) = \{i \in \mathrm{Fin}\, k \mid (i : \mathbb{N}) < n\}. \]
Fin.coe_of_injective_castLE_symm theorem
{n k : ℕ} (h : n ≤ k) (i : Fin k) (hi) : ((Equiv.ofInjective _ (castLE_injective h)).symm ⟨i, hi⟩ : ℕ) = i
Full source
@[simp]
theorem coe_of_injective_castLE_symm {n k : } (h : n ≤ k) (i : Fin k) (hi) :
    ((Equiv.ofInjective _ (castLE_injective h)).symm ⟨i, hi⟩ : ) = i := by
  rw [← coe_castLE h]
  exact congr_arg Fin.val (Equiv.apply_ofInjective_symm _ _)
Natural Number Coercion Commutes with Inverse of Order-Preserving Embedding on $\mathrm{Fin}$
Informal description
For natural numbers $n$ and $k$ with $n \leq k$, let $i \in \mathrm{Fin}\, k$ and suppose $i$ satisfies the condition $hi$ (that its underlying natural number value is less than $n$). Then the natural number value of the inverse of the injective embedding $\mathrm{castLE}\, h$ applied to $\langle i, hi \rangle$ is equal to $i$ itself. In other words, the coercion to $\mathbb{N}$ commutes with the inverse of $\mathrm{castLE}\, h$ on valid inputs.
Fin.leftInverse_cast theorem
(eq : n = m) : LeftInverse (Fin.cast eq.symm) (Fin.cast eq)
Full source
theorem leftInverse_cast (eq : n = m) : LeftInverse (Fin.cast eq.symm) (Fin.cast eq) :=
  fun _ => rfl
Left Inverse Property of Fin.cast for Equal Cardinalities
Informal description
For any natural numbers $n$ and $m$ with $n = m$, the function $\mathrm{Fin.cast}(eq)$ from $\mathrm{Fin}(n)$ to $\mathrm{Fin}(m)$ has a left inverse given by $\mathrm{Fin.cast}(eq.symm)$, where $eq.symm$ is the symmetry of the equality $n = m$. That is, for any $i \in \mathrm{Fin}(n)$, we have $\mathrm{Fin.cast}(eq.symm) (\mathrm{Fin.cast}(eq) (i)) = i$.
Fin.rightInverse_cast theorem
(eq : n = m) : RightInverse (Fin.cast eq.symm) (Fin.cast eq)
Full source
theorem rightInverse_cast (eq : n = m) : RightInverse (Fin.cast eq.symm) (Fin.cast eq) :=
  fun _ => rfl
Right Inverse Property of Fin.cast under Equality
Informal description
For any natural numbers $n$ and $m$ such that $n = m$, the function $\text{Fin.cast}(eq)$ from $\text{Fin}(n)$ to $\text{Fin}(m)$ has a right inverse given by $\text{Fin.cast}(eq.symm)$, where $eq.symm$ is the symmetry of the equality $n = m$. In other words, for any $x \in \text{Fin}(m)$, we have $\text{Fin.cast}(eq) (\text{Fin.cast}(eq.symm) x) = x$.
Fin.cast_inj theorem
(eq : n = m) {a b : Fin n} : a.cast eq = b.cast eq ↔ a = b
Full source
@[simp]
theorem cast_inj (eq : n = m) {a b : Fin n} : a.cast eq = b.cast eq ↔ a = b := by
  simp [← val_inj]
Injectivity of Fin Cast Operation
Informal description
For any natural numbers $n$ and $m$ with $n = m$, and for any elements $a, b$ of $\text{Fin } n$, the cast of $a$ equals the cast of $b$ in $\text{Fin } m$ if and only if $a = b$.
Fin.cast_lt_cast theorem
(eq : n = m) {a b : Fin n} : a.cast eq < b.cast eq ↔ a < b
Full source
@[simp]
theorem cast_lt_cast (eq : n = m) {a b : Fin n} : a.cast eq < b.cast eq ↔ a < b :=
  Iff.rfl
Preservation of Strict Order under Cast in Finite Types
Informal description
For any natural numbers $n$ and $m$ with $n = m$, and for any elements $a, b$ of $\text{Fin } n$, the inequality $a.\text{cast } eq < b.\text{cast } eq$ holds if and only if $a < b$ in $\text{Fin } n$.
Fin.cast_le_cast theorem
(eq : n = m) {a b : Fin n} : a.cast eq ≤ b.cast eq ↔ a ≤ b
Full source
@[simp]
theorem cast_le_cast (eq : n = m) {a b : Fin n} : a.cast eq ≤ b.cast eq ↔ a ≤ b :=
  Iff.rfl
Preservation of Order under Cast in Finite Types
Informal description
For any natural numbers $n$ and $m$ with $n = m$, and for any elements $a, b$ of $\text{Fin } n$, the inequality $a.\text{cast}(eq) \leq b.\text{cast}(eq)$ holds if and only if $a \leq b$.
finCongr definition
(eq : n = m) : Fin n ≃ Fin m
Full source
/-- The 'identity' equivalence between `Fin m` and `Fin n` when `m = n`. -/
@[simps]
def _root_.finCongr (eq : n = m) : FinFin n ≃ Fin m where
  toFun := Fin.cast eq
  invFun := Fin.cast eq.symm
  left_inv := leftInverse_cast eq
  right_inv := rightInverse_cast eq
Equivalence between finite types of equal cardinality
Informal description
Given an equality $n = m$ between natural numbers, the function $\mathrm{finCongr}(eq)$ defines an equivalence between the finite types $\mathrm{Fin}(n)$ and $\mathrm{Fin}(m)$. Specifically, it maps an element $i \in \mathrm{Fin}(n)$ to the corresponding element in $\mathrm{Fin}(m)$ via the cast function $\mathrm{Fin.cast}(eq)$, and its inverse is given by $\mathrm{Fin.cast}(eq.symm)$. This equivalence preserves the order and structure of the elements.
finCongr_apply_mk theorem
(h : m = n) (k : ℕ) (hk : k < m) : finCongr h ⟨k, hk⟩ = ⟨k, h ▸ hk⟩
Full source
@[simp] lemma _root_.finCongr_apply_mk (h : m = n) (k : ) (hk : k < m) :
    finCongr h ⟨k, hk⟩ = ⟨k, h ▸ hk⟩ := rfl
Action of `finCongr` on Constructed Elements
Informal description
Given natural numbers $m$ and $n$ with $h : m = n$, a natural number $k$ with $hk : k < m$, the equivalence `finCongr h` maps the element $\langle k, hk \rangle$ of $\mathrm{Fin}(m)$ to $\langle k, h \triangleright hk \rangle$ in $\mathrm{Fin}(n)$, where $h \triangleright hk$ denotes the proof that $k < n$ obtained by rewriting $hk$ using $h$.
finCongr_symm theorem
(h : m = n) : (finCongr h).symm = finCongr h.symm
Full source
@[simp] lemma _root_.finCongr_symm (h : m = n) : (finCongr h).symm = finCongr h.symm := rfl
Inverse of Finite Equivalence via Symmetry
Informal description
For any natural numbers $m$ and $n$ with $h : m = n$, the inverse of the equivalence $\mathrm{finCongr}(h)$ is equal to the equivalence $\mathrm{finCongr}(h^{-1})$, where $h^{-1}$ is the symmetry of $h$.
finCongr_apply_coe theorem
(h : m = n) (k : Fin m) : (finCongr h k : ℕ) = k
Full source
@[simp] lemma _root_.finCongr_apply_coe (h : m = n) (k : Fin m) : (finCongr h k : ) = k := rfl
Natural Number Preservation under Finite Equivalence
Informal description
Given natural numbers $m$ and $n$ with $h : m = n$, and an element $k \in \mathrm{Fin}(m)$, the natural number value of the equivalence $\mathrm{finCongr}(h)$ applied to $k$ is equal to $k$ itself, i.e., $(\mathrm{finCongr}(h)(k) : \mathbb{N}) = k$.
finCongr_symm_apply_coe theorem
(h : m = n) (k : Fin n) : ((finCongr h).symm k : ℕ) = k
Full source
lemma _root_.finCongr_symm_apply_coe (h : m = n) (k : Fin n) : ((finCongr h).symm k : ) = k := rfl
Natural Number Preservation under Inverse Finite Equivalence
Informal description
For any natural numbers $m$ and $n$ with $m = n$, and for any element $k \in \mathrm{Fin}(n)$, the natural number value of the inverse equivalence $\mathrm{finCongr}(h).\mathrm{symm}$ applied to $k$ is equal to $k$ itself, i.e., $(\mathrm{finCongr}(h).\mathrm{symm}(k) : \mathbb{N}) = k$.
finCongr_eq_equivCast theorem
(h : n = m) : finCongr h = .cast (h ▸ rfl)
Full source
/-- While in many cases `finCongr` is better than `Equiv.cast`/`cast`, sometimes we want to apply
a generic theorem about `cast`. -/
lemma _root_.finCongr_eq_equivCast (h : n = m) : finCongr h = .cast (h ▸ rfl) := by subst h; simp
Equality of Finite Equivalence and Generic Cast: $\mathrm{finCongr}(h) = \mathrm{cast}(h \mapsto \mathrm{rfl})$
Informal description
Given natural numbers $n$ and $m$ with $h : n = m$, the equivalence $\mathrm{finCongr}(h)$ between $\mathrm{Fin}(n)$ and $\mathrm{Fin}(m)$ is equal to the generic cast equivalence $\mathrm{cast}$ applied to the proof obtained by substituting $h$ into the reflexive equality.
Fin.cast_eq_cast theorem
(h : n = m) : (Fin.cast h : Fin n → Fin m) = _root_.cast (h ▸ rfl)
Full source
/-- While in many cases `Fin.cast` is better than `Equiv.cast`/`cast`, sometimes we want to apply
a generic theorem about `cast`. -/
theorem cast_eq_cast (h : n = m) : (Fin.cast h : Fin n → Fin m) = _root_.cast (h ▸ rfl) := by
  subst h
  ext
  rfl
Equality of Fin Casting and Generic Casting Functions
Informal description
For any natural numbers $n$ and $m$ with $n = m$, the casting function `Fin.cast h` from $\text{Fin }n$ to $\text{Fin }m$ is equal to the generic cast function applied to the proof that $h$ implies reflexivity.
Fin.castAddEmb definition
(m) : Fin n ↪ Fin (n + m)
Full source
/-- `Fin.castAdd` as an `Embedding`, `castAddEmb m i` embeds `i : Fin n` in `Fin (n+m)`.
See also `Fin.natAddEmb` and `Fin.addNatEmb`. -/
def castAddEmb (m) : FinFin n ↪ Fin (n + m) := castLEEmb (le_add_right n m)
Embedding of \(\mathrm{Fin}\, n\) into \(\mathrm{Fin}\, (n + m)\) via value preservation
Informal description
For any natural number \( m \), the embedding \(\mathrm{castAddEmb}_m : \mathrm{Fin}\, n \hookrightarrow \mathrm{Fin}\, (n + m)\) maps an element of \(\mathrm{Fin}\, n\) to the corresponding element in \(\mathrm{Fin}\, (n + m)\) by preserving its value. This embedding is injective and is defined via the embedding \(\mathrm{castLEEmb}\) applied to the inequality \( n \leq n + m \).
Fin.coe_castAddEmb theorem
(m) : (castAddEmb m : Fin n → Fin (n + m)) = castAdd m
Full source
@[simp]
lemma coe_castAddEmb (m) : (castAddEmb m : Fin n → Fin (n + m)) = castAdd m := rfl
Embedding Equals Cast Function for Finite Types with Added Constant
Informal description
For any natural number $m$, the embedding function $\mathrm{castAddEmb}_m$ from $\mathrm{Fin}\, n$ to $\mathrm{Fin}\, (n + m)$ is equal to the cast function $\mathrm{castAdd}_m$.
Fin.castAddEmb_apply theorem
(m) (i : Fin n) : castAddEmb m i = castAdd m i
Full source
lemma castAddEmb_apply (m) (i : Fin n) : castAddEmb m i = castAdd m i := rfl
Embedding Application Equals Cast Operation in Finite Types
Informal description
For any natural number $m$ and any element $i$ of the finite type $\mathrm{Fin}\, n$, the embedding $\mathrm{castAddEmb}_m$ applied to $i$ equals the cast operation $\mathrm{castAdd}_m$ applied to $i$, i.e., $\mathrm{castAddEmb}_m(i) = \mathrm{castAdd}_m(i)$.
Fin.castSuccEmb definition
: Fin n ↪ Fin (n + 1)
Full source
/-- `Fin.castSucc` as an `Embedding`, `castSuccEmb i` embeds `i : Fin n` in `Fin (n+1)`. -/
def castSuccEmb : FinFin n ↪ Fin (n + 1) := castAddEmb _
Embedding of $\mathrm{Fin}\, n$ into $\mathrm{Fin}\, (n+1)$ via successor casting
Informal description
The embedding $\mathrm{castSuccEmb} : \mathrm{Fin}\, n \hookrightarrow \mathrm{Fin}\, (n+1)$ maps an element of $\mathrm{Fin}\, n$ to the corresponding element in $\mathrm{Fin}\, (n+1)$ by preserving its value. This is equivalent to the cast operation $\mathrm{castSucc}$ and is injective.
Fin.coe_castSuccEmb theorem
: (castSuccEmb : Fin n → Fin (n + 1)) = Fin.castSucc
Full source
@[simp, norm_cast] lemma coe_castSuccEmb : (castSuccEmb : Fin n → Fin (n + 1)) = Fin.castSucc := rfl
Embedding Equality: $\mathrm{castSuccEmb} = \mathrm{Fin.castSucc}$
Informal description
The embedding $\mathrm{castSuccEmb} : \mathrm{Fin}\, n \to \mathrm{Fin}\, (n+1)$ is equal to the cast operation $\mathrm{Fin.castSucc}$.
Fin.castSuccEmb_apply theorem
(i : Fin n) : castSuccEmb i = i.castSucc
Full source
lemma castSuccEmb_apply (i : Fin n) : castSuccEmb i = i.castSucc := rfl
Embedding Application: $\mathrm{castSuccEmb}(i) = i.\mathrm{castSucc}$
Informal description
For any element $i$ of the finite type $\mathrm{Fin}\,n$, the embedding $\mathrm{castSuccEmb}$ applied to $i$ equals the cast successor of $i$, i.e., $\mathrm{castSuccEmb}(i) = i.\mathrm{castSucc}$.
Fin.castSucc_le_succ theorem
{n} (i : Fin n) : i.castSucc ≤ i.succ
Full source
theorem castSucc_le_succ {n} (i : Fin n) : i.castSucc ≤ i.succ := Nat.le_succ i
Inequality between Cast Successor and Successor in Finite Types
Informal description
For any natural number $n$ and any element $i$ of the finite type $\mathrm{Fin}\,n$, the cast successor of $i$ is less than or equal to the successor of $i$, i.e., $i.\mathrm{castSucc} \leq i.\mathrm{succ}$.
Fin.castSucc_le_castSucc_iff theorem
{a b : Fin n} : castSucc a ≤ castSucc b ↔ a ≤ b
Full source
@[simp] theorem castSucc_le_castSucc_iff {a b : Fin n} : castSucccastSucc a ≤ castSucc b ↔ a ≤ b := .rfl
Order Preservation of `castSucc` in Finite Types
Informal description
For any two elements $a$ and $b$ in $\text{Fin}\,n$, the inequality $\text{castSucc}\,a \leq \text{castSucc}\,b$ holds if and only if $a \leq b$.
Fin.succ_le_castSucc_iff theorem
{a b : Fin n} : succ a ≤ castSucc b ↔ a < b
Full source
@[simp] theorem succ_le_castSucc_iff {a b : Fin n} : succsucc a ≤ castSucc b ↔ a < b := by
  rw [le_castSucc_iff, succ_lt_succ_iff]
Successor and Cast Successor Order Relation in Finite Types: $\text{succ}\,a \leq \text{castSucc}\,b \leftrightarrow a < b$
Informal description
For any elements $a, b$ in $\text{Fin}\,n$, the successor of $a$ is less than or equal to the cast successor of $b$ if and only if $a$ is strictly less than $b$.
Fin.castSucc_lt_succ_iff theorem
{a b : Fin n} : castSucc a < succ b ↔ a ≤ b
Full source
@[simp] theorem castSucc_lt_succ_iff {a b : Fin n} : castSucccastSucc a < succ b ↔ a ≤ b := by
  rw [castSucc_lt_iff_succ_le, succ_le_succ_iff]
Order Relation between Cast Successor and Successor in Finite Types: $\text{castSucc}\,a < \text{succ}\,b \leftrightarrow a \leq b$
Informal description
For any elements $a, b$ in $\text{Fin}\,n$, the cast successor of $a$ is strictly less than the successor of $b$ if and only if $a \leq b$.
Fin.le_of_castSucc_lt_of_succ_lt theorem
{a b : Fin (n + 1)} {i : Fin n} (hl : castSucc i < a) (hu : b < succ i) : b < a
Full source
theorem le_of_castSucc_lt_of_succ_lt {a b : Fin (n + 1)} {i : Fin n}
    (hl : castSucc i < a) (hu : b < succ i) : b < a := by
  simp [Fin.lt_def, -val_fin_lt] at *; omega
Order Relation in Finite Types via Cast Successor and Successor: $b < a$ under $(\text{castSucc}\,i < a) \land (b < \text{succ}\,i)$
Informal description
For any elements $a, b$ in $\text{Fin}\,(n+1)$ and any $i \in \text{Fin}\,n$, if the cast successor of $i$ is strictly less than $a$ and $b$ is strictly less than the successor of $i$, then $b$ is strictly less than $a$.
Fin.castSucc_lt_or_lt_succ theorem
(p : Fin (n + 1)) (i : Fin n) : castSucc i < p ∨ p < i.succ
Full source
theorem castSucc_lt_or_lt_succ (p : Fin (n + 1)) (i : Fin n) : castSucccastSucc i < p ∨ p < i.succ := by
  simp [Fin.lt_def, -val_fin_lt]; omega
Disjunction of Order Relations for Cast Successor in Finite Types
Informal description
For any element $p$ in $\mathrm{Fin}(n+1)$ and any element $i$ in $\mathrm{Fin}(n)$, either the cast successor of $i$ is less than $p$, or $p$ is less than the successor of $i$.
Fin.succ_le_or_le_castSucc theorem
(p : Fin (n + 1)) (i : Fin n) : succ i ≤ p ∨ p ≤ i.castSucc
Full source
theorem succ_le_or_le_castSucc (p : Fin (n + 1)) (i : Fin n) : succsucc i ≤ p ∨ p ≤ i.castSucc := by
  rw [le_castSucc_iff, ← castSucc_lt_iff_succ_le]
  exact p.castSucc_lt_or_lt_succ i
Order Dichotomy for Successor and Cast Successor in Finite Types
Informal description
For any element $p$ in $\mathrm{Fin}(n+1)$ and any element $i$ in $\mathrm{Fin}(n)$, either the successor of $i$ is less than or equal to $p$, or $p$ is less than or equal to the cast successor of $i$.
Fin.forall_fin_succ' theorem
{P : Fin (n + 1) → Prop} : (∀ i, P i) ↔ (∀ i : Fin n, P i.castSucc) ∧ P (.last _)
Full source
theorem forall_fin_succ' {P : Fin (n + 1) → Prop} :
    (∀ i, P i) ↔ (∀ i : Fin n, P i.castSucc) ∧ P (.last _) :=
  ⟨fun H => ⟨fun _ => H _, H _⟩, fun ⟨H0, H1⟩ i => Fin.lastCases H1 H0 i⟩
Universal Quantification over $\mathrm{Fin}(n+1)$ via $\mathrm{castSucc}$ and $\mathrm{last}$
Informal description
For any predicate $P$ on $\mathrm{Fin}(n+1)$, the following equivalence holds: \[ (\forall i \in \mathrm{Fin}(n+1),\, P(i)) \leftrightarrow (\forall i \in \mathrm{Fin}(n),\, P(\mathrm{castSucc}(i))) \land P(\mathrm{last}(n)) \] where $\mathrm{castSucc}(i)$ embeds $i \in \mathrm{Fin}(n)$ into $\mathrm{Fin}(n+1)$ by keeping its value unchanged, and $\mathrm{last}(n)$ is the maximal element of $\mathrm{Fin}(n+1)$ (i.e., the element with value $n$).
Fin.castSucc_ne_last theorem
{n : ℕ} (i : Fin n) : i.castSucc ≠ .last n
Full source
@[simp]
theorem castSucc_ne_last {n : } (i : Fin n) : i.castSucc ≠ .last n :=
  Fin.ne_of_lt i.castSucc_lt_last
Cast successor is not last element in $\mathrm{Fin}\,(n+1)$
Informal description
For any natural number $n$ and any element $i$ of the finite type $\mathrm{Fin}\,n$, the cast successor of $i$ (viewed as an element of $\mathrm{Fin}\,(n+1)$) is not equal to the last element of $\mathrm{Fin}\,(n+1)$.
Fin.exists_fin_succ' theorem
{P : Fin (n + 1) → Prop} : (∃ i, P i) ↔ (∃ i : Fin n, P i.castSucc) ∨ P (.last _)
Full source
theorem exists_fin_succ' {P : Fin (n + 1) → Prop} :
    (∃ i, P i) ↔ (∃ i : Fin n, P i.castSucc) ∨ P (.last _) :=
  ⟨fun ⟨i, h⟩ => Fin.lastCases Or.inr (fun i hi => Or.inl ⟨i, hi⟩) i h,
   fun h => h.elim (fun ⟨i, hi⟩ => ⟨i.castSucc, hi⟩) (fun h => ⟨.last _, h⟩)⟩
Existence in $\text{Fin}(n+1)$ via Cast or Last Element
Informal description
For any predicate $P$ on $\text{Fin}(n+1)$ (the finite type with $n+1$ elements), there exists an element $i \in \text{Fin}(n+1)$ satisfying $P(i)$ if and only if either: 1. There exists $i \in \text{Fin}(n)$ such that $P(\text{castSucc}(i))$, where $\text{castSucc}$ is the embedding of $\text{Fin}(n)$ into $\text{Fin}(n+1)$, or 2. $P$ holds for the last element of $\text{Fin}(n+1)$.
Fin.castSucc_zero' theorem
[NeZero n] : castSucc (0 : Fin n) = 0
Full source
/--
The `Fin.castSucc_zero` in `Lean` only applies in `Fin (n+1)`.
This one instead uses a `NeZero n` typeclass hypothesis.
-/
@[simp]
theorem castSucc_zero' [NeZero n] : castSucc (0 : Fin n) = 0 := rfl
Preservation of Zero under `castSucc` in Non-Zero Finite Types
Informal description
For any positive natural number $n$ (i.e., $n \neq 0$), the `castSucc` operation maps the zero element of $\text{Fin }n$ to the zero element of $\text{Fin }(n+1)$. In other words, $\text{castSucc}(0) = 0$ holds in $\text{Fin }(n+1)$ when $n$ is non-zero.
Fin.castSucc_pos_iff theorem
[NeZero n] {i : Fin n} : 0 < castSucc i ↔ 0 < i
Full source
@[simp]
theorem castSucc_pos_iff [NeZero n] {i : Fin n} : 0 < castSucc i ↔ 0 < i := by simp [← val_pos_iff]
Positivity Preservation under Cast Successor in Finite Types
Informal description
For any nonzero natural number `n` and any element `i` of `Fin n`, the cast successor of `i` is positive (i.e., `0 < castSucc i`) if and only if `i` itself is positive (`0 < i`).
Fin.castSucc_eq_zero_iff' theorem
[NeZero n] (a : Fin n) : castSucc a = 0 ↔ a = 0
Full source
/--
The `Fin.castSucc_eq_zero_iff` in `Lean` only applies in `Fin (n+1)`.
This one instead uses a `NeZero n` typeclass hypothesis.
-/
@[simp]
theorem castSucc_eq_zero_iff' [NeZero n] (a : Fin n) : castSucccastSucc a = 0 ↔ a = 0 :=
  Fin.ext_iff.trans <| (Fin.ext_iff.trans <| by simp).symm
Equivalence of Cast Successor and Zero in Finite Types
Informal description
For any nonzero natural number $n$ and any element $a$ of $\text{Fin}\,n$, the cast successor of $a$ equals zero if and only if $a$ itself equals zero. That is, $\text{castSucc}\,a = 0 \leftrightarrow a = 0$.
Fin.castSucc_ne_zero_iff' theorem
[NeZero n] (a : Fin n) : castSucc a ≠ 0 ↔ a ≠ 0
Full source
/--
The `Fin.castSucc_ne_zero_iff` in `Lean` only applies in `Fin (n+1)`.
This one instead uses a `NeZero n` typeclass hypothesis.
-/
theorem castSucc_ne_zero_iff' [NeZero n] (a : Fin n) : castSucccastSucc a ≠ 0castSucc a ≠ 0 ↔ a ≠ 0 :=
  not_iff_not.mpr <| castSucc_eq_zero_iff' a
Nonzero Preservation under Cast Successor in Finite Types
Informal description
For any nonzero natural number $n$ and any element $a$ of the finite type $\text{Fin}\,n$, the cast successor of $a$ is nonzero if and only if $a$ itself is nonzero. That is, $\text{castSucc}\,a \neq 0 \leftrightarrow a \neq 0$.
Fin.castSucc_ne_zero_of_lt theorem
{p i : Fin n} (h : p < i) : castSucc i ≠ 0
Full source
theorem castSucc_ne_zero_of_lt {p i : Fin n} (h : p < i) : castSucccastSucc i ≠ 0 := by
  cases n
  · exact i.elim0
  · rw [castSucc_ne_zero_iff', Ne, Fin.ext_iff]
    exact ((zero_le _).trans_lt h).ne'
Nonzero Cast Successor for Greater Elements in Finite Types
Informal description
For any elements $p$ and $i$ in the finite type $\text{Fin}\,n$, if $p < i$, then the cast successor of $i$ is not equal to zero.
Fin.succ_ne_last_iff theorem
(a : Fin (n + 1)) : succ a ≠ last (n + 1) ↔ a ≠ last n
Full source
theorem succ_ne_last_iff (a : Fin (n + 1)) : succsucc a ≠ last (n + 1)succ a ≠ last (n + 1) ↔ a ≠ last n :=
  not_iff_not.mpr <| succ_eq_last_succ
Successor Not Last Element Iff Not Last Element
Informal description
For any element $a$ in $\text{Fin}(n+1)$, the successor of $a$ is not equal to the last element of $\text{Fin}(n+1)$ if and only if $a$ is not equal to the last element of $\text{Fin}(n)$.
Fin.succ_ne_last_of_lt theorem
{p i : Fin n} (h : i < p) : succ i ≠ last n
Full source
theorem succ_ne_last_of_lt {p i : Fin n} (h : i < p) : succsucc i ≠ last n := by
  cases n
  · exact i.elim0
  · rw [succ_ne_last_iff, Ne, Fin.ext_iff]
    exact ((le_last _).trans_lt' h).ne
Successor of Less-Than Element is Not Last Element
Informal description
For any elements $i$ and $p$ in $\text{Fin}(n)$, if $i < p$, then the successor of $i$ is not equal to the last element of $\text{Fin}(n)$.
Fin.coe_eq_castSucc theorem
{a : Fin n} : (a : Fin (n + 1)) = castSucc a
Full source
@[norm_cast, simp]
theorem coe_eq_castSucc {a : Fin n} : (a : Fin (n + 1)) = castSucc a := by
  ext
  exact val_cast_of_lt (Nat.lt.step a.is_lt)
Coercion to $\mathrm{Fin}\,(n+1)$ equals successor cast
Informal description
For any element $a$ in the finite type $\mathrm{Fin}\,n$, the coercion of $a$ to $\mathrm{Fin}\,(n+1)$ is equal to the successor cast $\mathrm{castSucc}\,a$.
Fin.coe_succ_lt_iff_lt theorem
{n : ℕ} {j k : Fin n} : (j : Fin <| n + 1) < k ↔ j < k
Full source
theorem coe_succ_lt_iff_lt {n : } {j k : Fin n} : (j : Fin <| n + 1) < k ↔ j < k := by
  simp only [coe_eq_castSucc, castSucc_lt_castSucc_iff]
Coercion Preserves Order in Finite Types: $(j : \mathrm{Fin}\,(n+1)) < k \leftrightarrow j < k$
Informal description
For any natural number $n$ and elements $j, k \in \mathrm{Fin}\,n$, the inequality $(j : \mathrm{Fin}\,(n+1)) < k$ holds if and only if $j < k$ in $\mathrm{Fin}\,n$.
Fin.range_castSucc theorem
{n : ℕ} : Set.range (castSucc : Fin n → Fin n.succ) = ({i | (i : ℕ) < n} : Set (Fin n.succ))
Full source
@[simp]
theorem range_castSucc {n : } : Set.range (castSucc : Fin n → Fin n.succ) =
    ({ i | (i : ℕ) < n } : Set (Fin n.succ)) := range_castLE (by omega)
Range of Successor Cast Embedding for Finite Types
Informal description
For any natural number $n$, the range of the embedding $\mathrm{castSucc} : \mathrm{Fin}\, n \to \mathrm{Fin}\, (n+1)$ is equal to the set of elements $i \in \mathrm{Fin}\, (n+1)$ whose underlying natural number value is less than $n$. That is, \[ \mathrm{range}\, (\mathrm{castSucc}) = \{i \in \mathrm{Fin}\, (n+1) \mid (i : \mathbb{N}) < n\}. \]
Fin.coe_of_injective_castSucc_symm theorem
{n : ℕ} (i : Fin n.succ) (hi) : ((Equiv.ofInjective castSucc (castSucc_injective _)).symm ⟨i, hi⟩ : ℕ) = i
Full source
@[simp]
theorem coe_of_injective_castSucc_symm {n : } (i : Fin n.succ) (hi) :
    ((Equiv.ofInjective castSucc (castSucc_injective _)).symm ⟨i, hi⟩ : ) = i := by
  rw [← coe_castSucc]
  exact congr_arg val (Equiv.apply_ofInjective_symm _ _)
Natural Number Value of Preimage under Successor Cast Equivalence
Informal description
For any natural number $n$ and any element $i \in \mathrm{Fin}\,(n+1)$ with a proof $hi$ that $i$ is in the range of the injective successor cast $\mathrm{castSucc} : \mathrm{Fin}\,n \to \mathrm{Fin}\,(n+1)$, the underlying natural number value of the preimage of $i$ under the equivalence $\mathrm{Equiv.ofInjective}\,\mathrm{castSucc}$ is equal to $i$. That is, if $\varphi$ is the inverse of the injective embedding $\mathrm{castSucc}$, then $(\varphi \langle i, hi \rangle : \mathbb{N}) = i$.
Fin.addNatEmb definition
(m) : Fin n ↪ Fin (n + m)
Full source
/-- `Fin.addNat` as an `Embedding`, `addNatEmb m i` adds `m` to `i`, generalizes `Fin.succ`. -/
@[simps! apply]
def addNatEmb (m) : FinFin n ↪ Fin (n + m) where
  toFun := (addNat · m)
  inj' a b := by simp [Fin.ext_iff]
Embedding of $\text{Fin } n$ into $\text{Fin } (n + m)$ by adding $m$
Informal description
The embedding function that maps an element $i$ of the finite type $\text{Fin } n$ to the element $i + m$ in the finite type $\text{Fin } (n + m)$, where addition is performed modulo $n + m$.
Fin.natAddEmb definition
(n) {m} : Fin m ↪ Fin (n + m)
Full source
/-- `Fin.natAdd` as an `Embedding`, `natAddEmb n i` adds `n` to `i` "on the left". -/
@[simps! apply]
def natAddEmb (n) {m} : FinFin m ↪ Fin (n + m) where
  toFun := natAdd n
  inj' a b := by simp [Fin.ext_iff]
Left addition embedding for finite types
Informal description
The embedding `Fin.natAddEmb n` maps an element `i` of the finite type `Fin m` to the element `i` of the finite type `Fin (n + m)` by adding `n` to the left of `i`. This is an injective function.
Fin.castSucc_castAdd theorem
(i : Fin n) : castSucc (castAdd m i) = castAdd (m + 1) i
Full source
theorem castSucc_castAdd (i : Fin n) : castSucc (castAdd m i) = castAdd (m + 1) i := rfl
Commutativity of castSucc and castAdd embeddings on Fin types
Informal description
For any natural numbers $n$ and $m$, and for any element $i$ of $\text{Fin}\,n$, the following equality holds: $$\text{castSucc}(\text{castAdd}\,m\,i) = \text{castAdd}\,(m+1)\,i$$ where: - $\text{Fin}\,n$ is the type of natural numbers less than $n$, - $\text{castAdd}\,m$ is the embedding of $\text{Fin}\,n$ into $\text{Fin}\,(n+m)$, - $\text{castSucc}$ is the embedding of $\text{Fin}\,k$ into $\text{Fin}\,(k+1)$.
Fin.castSucc_natAdd theorem
(i : Fin m) : castSucc (natAdd n i) = natAdd n (castSucc i)
Full source
theorem castSucc_natAdd (i : Fin m) : castSucc (natAdd n i) = natAdd n (castSucc i) := rfl
Commutativity of Successor Casting and Natural Addition in Finite Types
Informal description
For any natural numbers $n$ and $m$, and for any element $i$ of $\text{Fin}\, m$, the operation of casting the successor of the element obtained by adding $n$ to $i$ is equal to adding $n$ to the successor of $i$. In other words, $\text{castSucc}(\text{natAdd}\, n\, i) = \text{natAdd}\, n\, (\text{castSucc}\, i)$.
Fin.succ_castAdd theorem
(i : Fin n) : succ (castAdd m i) = if h : i.succ = last _ then natAdd n (0 : Fin (m + 1)) else castAdd (m + 1) ⟨i.1 + 1, lt_of_le_of_ne i.2 (Fin.val_ne_iff.mpr h)⟩
Full source
theorem succ_castAdd (i : Fin n) : succ (castAdd m i) =
    if h : i.succ = last _ then natAdd n (0 : Fin (m + 1))
      else castAdd (m + 1) ⟨i.1 + 1, lt_of_le_of_ne i.2 (Fin.val_ne_iff.mpr h)⟩ := by
  split_ifs with h
  exacts [Fin.ext (congr_arg Fin.val h :), rfl]
Successor of Cast Addition in Finite Types
Informal description
Let $i$ be an element of $\mathrm{Fin}\ n$ (the finite type with $n$ elements). The successor of the cast addition of $m$ to $i$ (viewed in $\mathrm{Fin}\ (n+m+1)$) is equal to: - The natural addition of $n$ to $0$ (in $\mathrm{Fin}\ (m+1)$) if the successor of $i$ is the last element of $\mathrm{Fin}\ n$ - Otherwise, the cast addition of $m+1$ to the element $\langle i.1 + 1 \rangle$ (where $i.1$ is the underlying natural number of $i$ and we have the proof that $i.1 + 1 < n$) Here, $\mathrm{Fin}\ n$ represents the finite type with $n$ elements (natural numbers less than $n$), $\mathrm{castAdd}\ m$ is the embedding of $\mathrm{Fin}\ n$ into $\mathrm{Fin}\ (n+m)$, and $\mathrm{succ}$ is the successor operation on $\mathrm{Fin}$ types.
Fin.succ_natAdd theorem
(i : Fin m) : succ (natAdd n i) = natAdd n (succ i)
Full source
theorem succ_natAdd (i : Fin m) : succ (natAdd n i) = natAdd n (succ i) := rfl
Successor Commutes with Right Addition in Finite Types
Informal description
For any natural numbers $n$ and $m$, and for any element $i$ of $\text{Fin}\, m$ (the finite type with $m$ elements), the successor of the element obtained by adding $n$ to $i$ (via `natAdd`) is equal to the element obtained by adding $n$ to the successor of $i$. In symbols: $\text{succ}(\text{natAdd}\, n\, i) = \text{natAdd}\, n\, (\text{succ}\, i)$.
Fin.pred_lt_iff theorem
{j : Fin n} {i : Fin (n + 1)} (hi : i ≠ 0) : pred i hi < j ↔ i < succ j
Full source
theorem pred_lt_iff {j : Fin n} {i : Fin (n + 1)} (hi : i ≠ 0) : predpred i hi < j ↔ i < succ j := by
  rw [← succ_lt_succ_iff, succ_pred]
Predecessor Less Than Element iff Element Less Than Successor in Finite Types
Informal description
For any element $j$ in $\text{Fin}\ n$ and any nonzero element $i$ in $\text{Fin}\ (n + 1)$, the predecessor of $i$ is less than $j$ if and only if $i$ is less than the successor of $j$.
Fin.lt_pred_iff theorem
{j : Fin n} {i : Fin (n + 1)} (hi : i ≠ 0) : j < pred i hi ↔ succ j < i
Full source
theorem lt_pred_iff {j : Fin n} {i : Fin (n + 1)} (hi : i ≠ 0) : j < pred i hi ↔ succ j < i := by
  rw [← succ_lt_succ_iff, succ_pred]
Inequality between Predecessor and Successor in Finite Types
Informal description
For any element $j$ in $\text{Fin } n$ and any nonzero element $i$ in $\text{Fin } (n + 1)$, the inequality $j < \text{pred } i$ holds if and only if $\text{succ } j < i$.
Fin.pred_le_iff theorem
{j : Fin n} {i : Fin (n + 1)} (hi : i ≠ 0) : pred i hi ≤ j ↔ i ≤ succ j
Full source
theorem pred_le_iff {j : Fin n} {i : Fin (n + 1)} (hi : i ≠ 0) : predpred i hi ≤ j ↔ i ≤ succ j := by
  rw [← succ_le_succ_iff, succ_pred]
Predecessor-Successor Order Relation in Finite Types
Informal description
For any natural number $n$, let $j$ be an element of $\text{Fin }n$ and $i$ be a nonzero element of $\text{Fin }(n+1)$. Then the predecessor of $i$ is less than or equal to $j$ if and only if $i$ is less than or equal to the successor of $j$. In symbols: \[ \text{pred}(i) \leq j \leftrightarrow i \leq \text{succ}(j) \]
Fin.le_pred_iff theorem
{j : Fin n} {i : Fin (n + 1)} (hi : i ≠ 0) : j ≤ pred i hi ↔ succ j ≤ i
Full source
theorem le_pred_iff {j : Fin n} {i : Fin (n + 1)} (hi : i ≠ 0) : j ≤ pred i hi ↔ succ j ≤ i := by
  rw [← succ_le_succ_iff, succ_pred]
Predecessor and Successor Order Relation in Finite Types
Informal description
For any element $j$ in $\text{Fin}\,n$ and any nonzero element $i$ in $\text{Fin}\,(n+1)$, the inequality $j \leq \text{pred}\,i$ holds if and only if $\text{succ}\,j \leq i$.
Fin.castSucc_pred_add_one_eq theorem
{a : Fin (n + 1)} (ha : a ≠ 0) : (a.pred ha).castSucc + 1 = a
Full source
theorem castSucc_pred_add_one_eq {a : Fin (n + 1)} (ha : a ≠ 0) :
    (a.pred ha).castSucc + 1 = a := by
  cases a using cases
  · exact (ha rfl).elim
  · rw [pred_succ, coeSucc_eq_succ]
Successor-Predecessor Identity in Finite Types: $\text{castSucc}(\text{pred}(a)) + 1 = a$
Informal description
For any nonzero element $a$ in $\text{Fin}(n+1)$, the successor of the predecessor of $a$ (cast to $\text{Fin}(n+1)$) plus one equals $a$. In symbols: \[ \text{castSucc}(\text{pred}(a)) + 1 = a \]
Fin.le_pred_castSucc_iff theorem
{a b : Fin (n + 1)} (ha : castSucc a ≠ 0) : b ≤ (castSucc a).pred ha ↔ b < a
Full source
theorem le_pred_castSucc_iff {a b : Fin (n + 1)} (ha : castSucccastSucc a ≠ 0) :
    b ≤ (castSucc a).pred ha ↔ b < a := by
  rw [le_pred_iff, succ_le_castSucc_iff]
Predecessor of Cast Successor Order Relation: $b \leq \text{pred}(\text{castSucc}(a)) \leftrightarrow b < a$
Informal description
For any elements $a, b$ in $\text{Fin}(n+1)$ such that $\text{castSucc}(a) \neq 0$, the inequality $b \leq \text{pred}(\text{castSucc}(a))$ holds if and only if $b < a$.
Fin.pred_castSucc_lt_iff theorem
{a b : Fin (n + 1)} (ha : castSucc a ≠ 0) : (castSucc a).pred ha < b ↔ a ≤ b
Full source
theorem pred_castSucc_lt_iff {a b : Fin (n + 1)} (ha : castSucccastSucc a ≠ 0) :
    (castSucc a).pred ha < b ↔ a ≤ b := by
  rw [pred_lt_iff, castSucc_lt_succ_iff]
Predecessor of Cast Successor Relation: $\text{pred}(\text{castSucc}\,a) < b \leftrightarrow a \leq b$
Informal description
For any elements $a, b$ in $\text{Fin}(n+1)$ such that $\text{castSucc}\,a \neq 0$, the predecessor of $\text{castSucc}\,a$ is less than $b$ if and only if $a \leq b$.
Fin.pred_castSucc_lt theorem
{a : Fin (n + 1)} (ha : castSucc a ≠ 0) : (castSucc a).pred ha < a
Full source
theorem pred_castSucc_lt {a : Fin (n + 1)} (ha : castSucccastSucc a ≠ 0) :
    (castSucc a).pred ha < a := by rw [pred_castSucc_lt_iff, le_def]
Predecessor of Cast Successor is Less Than Original Element in Finite Types
Informal description
For any element $a$ in $\text{Fin}(n+1)$ such that $\text{castSucc}(a) \neq 0$, the predecessor of $\text{castSucc}(a)$ is strictly less than $a$.
Fin.le_castSucc_pred_iff theorem
{a b : Fin (n + 1)} (ha : a ≠ 0) : b ≤ castSucc (a.pred ha) ↔ b < a
Full source
theorem le_castSucc_pred_iff {a b : Fin (n + 1)} (ha : a ≠ 0) :
    b ≤ castSucc (a.pred ha) ↔ b < a := by
  rw [castSucc_pred_eq_pred_castSucc, le_pred_castSucc_iff]
Order Relation between Element and Predecessor's Cast Successor in Finite Types
Informal description
For any elements $a, b$ in $\text{Fin}(n+1)$ such that $a \neq 0$, the inequality $b \leq \text{castSucc}(\text{pred}(a))$ holds if and only if $b < a$.
Fin.castSucc_pred_lt_iff theorem
{a b : Fin (n + 1)} (ha : a ≠ 0) : castSucc (a.pred ha) < b ↔ a ≤ b
Full source
theorem castSucc_pred_lt_iff {a b : Fin (n + 1)} (ha : a ≠ 0) :
    castSucccastSucc (a.pred ha) < b ↔ a ≤ b := by
  rw [castSucc_pred_eq_pred_castSucc, pred_castSucc_lt_iff]
Order Relation between Predecessor's Cast Successor and Element in Finite Types
Informal description
For any elements $a, b$ in the finite type $\text{Fin}(n+1)$ such that $a \neq 0$, the inequality $\text{castSucc}(\text{pred}(a)) < b$ holds if and only if $a \leq b$.
Fin.castSucc_pred_lt theorem
{a : Fin (n + 1)} (ha : a ≠ 0) : castSucc (a.pred ha) < a
Full source
theorem castSucc_pred_lt {a : Fin (n + 1)} (ha : a ≠ 0) :
    castSucc (a.pred ha) < a := by rw [castSucc_pred_lt_iff, le_def]
Predecessor's Cast Successor is Less Than Original Element in Finite Types
Informal description
For any element $a$ in the finite type $\mathrm{Fin}(n+1)$ such that $a \neq 0$, the cast successor of the predecessor of $a$ is strictly less than $a$, i.e., $\mathrm{castSucc}(\mathrm{pred}(a)) < a$.
Fin.castPred definition
(i : Fin (n + 1)) (h : i ≠ last n) : Fin n
Full source
/-- `castPred i` sends `i : Fin (n + 1)` to `Fin n` as long as i ≠ last n. -/
@[inline] def castPred (i : Fin (n + 1)) (h : i ≠ last n) : Fin n := castLT i (val_lt_last h)
Cast predecessor for finite types
Informal description
For a natural number \( n \), the function `Fin.castPred` takes an element \( i \) of the finite type `Fin (n + 1)` (i.e., a natural number \( i \) with \( 0 \leq i < n + 1 \)) and a proof \( h \) that \( i \) is not the last element of `Fin (n + 1)`, and returns the corresponding element of `Fin n` (i.e., \( i \) as a natural number with \( 0 \leq i < n \)).
Fin.coe_castPred theorem
(i : Fin (n + 1)) (h : i ≠ last _) : (castPred i h : ℕ) = i
Full source
@[simp]
lemma coe_castPred (i : Fin (n + 1)) (h : i ≠ last _) : (castPred i h : ) = i := rfl
Natural Number Coercion of `castPred` Equals Original Value
Informal description
For any natural number $n$, given an element $i$ of the finite type $\mathrm{Fin}(n+1)$ (i.e., $0 \leq i < n+1$) and a proof $h$ that $i$ is not the last element of $\mathrm{Fin}(n+1)$, the natural number value of $\mathrm{castPred}(i, h)$ is equal to $i$. In other words, the coercion to natural numbers commutes with the `castPred` operation: $(\mathrm{castPred}(i, h) : \mathbb{N}) = i$.
Fin.castSucc_castPred theorem
(i : Fin (n + 1)) (h : i ≠ last n) : castSucc (i.castPred h) = i
Full source
@[simp]
theorem castSucc_castPred (i : Fin (n + 1)) (h : i ≠ last n) :
    castSucc (i.castPred h) = i := by
  rcases exists_castSucc_eq.mpr h with ⟨y, rfl⟩
  rw [castPred_castSucc]
$\mathrm{castSucc} \circ \mathrm{castPred} = \mathrm{id}$ for non-last elements of $\mathrm{Fin}(n+1)$
Informal description
For any natural number $n$ and any element $i$ of $\mathrm{Fin}(n+1)$ (i.e., $0 \leq i < n+1$) such that $i \neq \mathrm{last}\,n$, we have $\mathrm{castSucc}(\mathrm{castPred}\,i\,h) = i$. Here: - $\mathrm{Fin}(n)$ denotes the finite type with $n$ elements (natural numbers less than $n$) - $\mathrm{last}\,n$ is the maximal element of $\mathrm{Fin}(n+1)$ (equal to $n$) - $\mathrm{castPred}$ maps $i \in \mathrm{Fin}(n+1)$ to $\mathrm{Fin}(n)$ when $i \neq \mathrm{last}\,n$ - $\mathrm{castSucc}$ is the canonical embedding $\mathrm{Fin}(n) \hookrightarrow \mathrm{Fin}(n+1)$
Fin.castPred_eq_iff_eq_castSucc theorem
(i : Fin (n + 1)) (hi : i ≠ last _) (j : Fin n) : castPred i hi = j ↔ i = castSucc j
Full source
theorem castPred_eq_iff_eq_castSucc (i : Fin (n + 1)) (hi : i ≠ last _) (j : Fin n) :
    castPredcastPred i hi = j ↔ i = castSucc j :=
  ⟨fun h => by rw [← h, castSucc_castPred], fun h => by simp_rw [h, castPred_castSucc]⟩
Characterization of $\mathrm{castPred}$ via $\mathrm{castSucc}$ in Finite Types
Informal description
For any natural number $n$, an element $i$ of $\mathrm{Fin}(n+1)$ (where $i \neq \mathrm{last}\,n$), and an element $j$ of $\mathrm{Fin}(n)$, we have $\mathrm{castPred}\,i\,hi = j$ if and only if $i = \mathrm{castSucc}\,j$. Here: - $\mathrm{Fin}(n)$ denotes the finite type with $n$ elements (natural numbers less than $n$) - $\mathrm{last}\,n$ is the maximal element of $\mathrm{Fin}(n+1)$ (equal to $n$) - $\mathrm{castPred}$ maps $i \in \mathrm{Fin}(n+1)$ to $\mathrm{Fin}(n)$ when $i \neq \mathrm{last}\,n$ - $\mathrm{castSucc}$ is the canonical embedding $\mathrm{Fin}(n) \hookrightarrow \mathrm{Fin}(n+1)$
Fin.castPred_le_castPred_iff theorem
{i j : Fin (n + 1)} {hi : i ≠ last n} {hj : j ≠ last n} : castPred i hi ≤ castPred j hj ↔ i ≤ j
Full source
@[simp]
theorem castPred_le_castPred_iff {i j : Fin (n + 1)} {hi : i ≠ last n} {hj : j ≠ last n} :
    castPredcastPred i hi ≤ castPred j hj ↔ i ≤ j := Iff.rfl
Inequality Preservation under Cast Pred in Finite Types
Informal description
For any elements $i$ and $j$ of the finite type $\text{Fin}(n+1)$ (natural numbers less than $n+1$), where $i \neq \text{last } n$ and $j \neq \text{last } n$, the inequality $\text{castPred } i \leq \text{castPred } j$ holds if and only if $i \leq j$.
Fin.castPred_le_castPred theorem
{i j : Fin (n + 1)} (h : i ≤ j) (hj : j ≠ last n) : castPred i (by rw [← lt_last_iff_ne_last] at hj ⊢; exact Fin.lt_of_le_of_lt h hj) ≤ castPred j hj
Full source
/-- A version of the right-to-left implication of `castPred_le_castPred_iff`
that deduces `i ≠ last n` from `i ≤ j` and `j ≠ last n`. -/
@[gcongr]
theorem castPred_le_castPred {i j : Fin (n + 1)} (h : i ≤ j) (hj : j ≠ last n) :
    castPred i (by rw [← lt_last_iff_ne_last] at hj ⊢; exact Fin.lt_of_le_of_lt h hj) ≤
      castPred j hj :=
  h
Monotonicity of Cast Predecessor under Inequality in Finite Types
Informal description
For any elements $i$ and $j$ of the finite type $\mathrm{Fin}(n+1)$, if $i \leq j$ and $j$ is not the last element of $\mathrm{Fin}(n+1)$, then the cast predecessor of $i$ is less than or equal to the cast predecessor of $j$.
Fin.castPred_lt_castPred_iff theorem
{i j : Fin (n + 1)} {hi : i ≠ last n} {hj : j ≠ last n} : castPred i hi < castPred j hj ↔ i < j
Full source
@[simp]
theorem castPred_lt_castPred_iff {i j : Fin (n + 1)} {hi : i ≠ last n} {hj : j ≠ last n} :
    castPredcastPred i hi < castPred j hj ↔ i < j := Iff.rfl
Inequality Preservation under Cast Predecessor in Finite Types
Informal description
For any elements $i$ and $j$ of the finite type $\text{Fin}(n+1)$ (natural numbers less than $n+1$), with $i \neq \text{last}\,n$ and $j \neq \text{last}\,n$, the cast predecessor $\text{castPred}\,i\,hi$ is less than $\text{castPred}\,j\,hj$ if and only if $i < j$.
Fin.castPred_lt_castPred theorem
{i j : Fin (n + 1)} (h : i < j) (hj : j ≠ last n) : castPred i (ne_last_of_lt h) < castPred j hj
Full source
/-- A version of the right-to-left implication of `castPred_lt_castPred_iff`
that deduces `i ≠ last n` from `i < j`. -/
@[gcongr]
theorem castPred_lt_castPred {i j : Fin (n + 1)} (h : i < j) (hj : j ≠ last n) :
    castPred i (ne_last_of_lt h) < castPred j hj := h
Cast Predecessor Preserves Strict Order in $\mathrm{Fin}(n+1)$
Informal description
For any elements $i$ and $j$ of $\mathrm{Fin}(n+1)$, if $i < j$ and $j$ is not the last element of $\mathrm{Fin}(n+1)$, then the cast predecessor of $i$ is strictly less than the cast predecessor of $j$.
Fin.castPred_lt_iff theorem
{j : Fin n} {i : Fin (n + 1)} (hi : i ≠ last n) : castPred i hi < j ↔ i < castSucc j
Full source
theorem castPred_lt_iff {j : Fin n} {i : Fin (n + 1)} (hi : i ≠ last n) :
    castPredcastPred i hi < j ↔ i < castSucc j := by
  rw [← castSucc_lt_castSucc_iff, castSucc_castPred]
Order equivalence between $\mathrm{castPred}$ and $\mathrm{castSucc}$ for strict less-than in finite types
Informal description
For any natural number $n$, elements $j \in \mathrm{Fin}\,n$ and $i \in \mathrm{Fin}(n+1)$ with $i \neq \mathrm{last}\,n$, the inequality $\mathrm{castPred}\,i\,h_i < j$ holds if and only if $i < \mathrm{castSucc}\,j$. Here: - $\mathrm{Fin}(n)$ denotes the finite type with $n$ elements (natural numbers less than $n$) - $\mathrm{last}\,n$ is the maximal element of $\mathrm{Fin}(n+1)$ (equal to $n$) - $\mathrm{castPred}$ maps $i \in \mathrm{Fin}(n+1)$ to $\mathrm{Fin}(n)$ when $i \neq \mathrm{last}\,n$ - $\mathrm{castSucc}$ is the canonical embedding $\mathrm{Fin}(n) \hookrightarrow \mathrm{Fin}(n+1)$
Fin.lt_castPred_iff theorem
{j : Fin n} {i : Fin (n + 1)} (hi : i ≠ last n) : j < castPred i hi ↔ castSucc j < i
Full source
theorem lt_castPred_iff {j : Fin n} {i : Fin (n + 1)} (hi : i ≠ last n) :
    j < castPred i hi ↔ castSucc j < i := by
  rw [← castSucc_lt_castSucc_iff, castSucc_castPred]
Order equivalence between $\mathrm{castPred}$ and $\mathrm{castSucc}$ for strict less-than in finite types
Informal description
For any natural number $n$, elements $j \in \mathrm{Fin}\,n$ and $i \in \mathrm{Fin}(n+1)$ with $i \neq \mathrm{last}\,n$, the inequality $j < \mathrm{castPred}\,i\,h_i$ holds if and only if $\mathrm{castSucc}\,j < i$. Here: - $\mathrm{Fin}(n)$ denotes the finite type with $n$ elements (natural numbers less than $n$) - $\mathrm{last}\,n$ is the maximal element of $\mathrm{Fin}(n+1)$ (equal to $n$) - $\mathrm{castPred}$ maps $i \in \mathrm{Fin}(n+1)$ to $\mathrm{Fin}(n)$ when $i \neq \mathrm{last}\,n$ - $\mathrm{castSucc}$ is the canonical embedding $\mathrm{Fin}(n) \hookrightarrow \mathrm{Fin}(n+1)$
Fin.castPred_le_iff theorem
{j : Fin n} {i : Fin (n + 1)} (hi : i ≠ last n) : castPred i hi ≤ j ↔ i ≤ castSucc j
Full source
theorem castPred_le_iff {j : Fin n} {i : Fin (n + 1)} (hi : i ≠ last n) :
    castPredcastPred i hi ≤ j ↔ i ≤ castSucc j := by
  rw [← castSucc_le_castSucc_iff, castSucc_castPred]
Order equivalence between $\mathrm{castPred}$ and $\mathrm{castSucc}$ in finite types
Informal description
For any natural number $n$, elements $j \in \mathrm{Fin}\,n$ and $i \in \mathrm{Fin}(n+1)$ with $i \neq \mathrm{last}\,n$, the inequality $\mathrm{castPred}\,i\,h_i \leq j$ holds if and only if $i \leq \mathrm{castSucc}\,j$. Here: - $\mathrm{Fin}(n)$ denotes the finite type with $n$ elements (natural numbers less than $n$) - $\mathrm{last}\,n$ is the maximal element of $\mathrm{Fin}(n+1)$ (equal to $n$) - $\mathrm{castPred}$ maps $i \in \mathrm{Fin}(n+1)$ to $\mathrm{Fin}(n)$ when $i \neq \mathrm{last}\,n$ - $\mathrm{castSucc}$ is the canonical embedding $\mathrm{Fin}(n) \hookrightarrow \mathrm{Fin}(n+1)$
Fin.le_castPred_iff theorem
{j : Fin n} {i : Fin (n + 1)} (hi : i ≠ last n) : j ≤ castPred i hi ↔ castSucc j ≤ i
Full source
theorem le_castPred_iff {j : Fin n} {i : Fin (n + 1)} (hi : i ≠ last n) :
    j ≤ castPred i hi ↔ castSucc j ≤ i := by
  rw [← castSucc_le_castSucc_iff, castSucc_castPred]
Order equivalence between $\mathrm{castPred}$ and $\mathrm{castSucc}$ for non-strict inequalities in finite types
Informal description
For any natural number $n$, elements $j \in \mathrm{Fin}\,n$ and $i \in \mathrm{Fin}(n+1)$ with $i \neq \mathrm{last}\,n$, the inequality $j \leq \mathrm{castPred}\,i\,h_i$ holds if and only if $\mathrm{castSucc}\,j \leq i$. Here: - $\mathrm{Fin}(n)$ denotes the finite type with $n$ elements (natural numbers less than $n$) - $\mathrm{last}\,n$ is the maximal element of $\mathrm{Fin}(n+1)$ (equal to $n$) - $\mathrm{castPred}$ maps $i \in \mathrm{Fin}(n+1)$ to $\mathrm{Fin}(n)$ when $i \neq \mathrm{last}\,n$ - $\mathrm{castSucc}$ is the canonical embedding $\mathrm{Fin}(n) \hookrightarrow \mathrm{Fin}(n+1)$
Fin.castPred_inj theorem
{i j : Fin (n + 1)} {hi : i ≠ last n} {hj : j ≠ last n} : castPred i hi = castPred j hj ↔ i = j
Full source
@[simp]
theorem castPred_inj {i j : Fin (n + 1)} {hi : i ≠ last n} {hj : j ≠ last n} :
    castPredcastPred i hi = castPred j hj ↔ i = j := by
  simp_rw [Fin.ext_iff, le_antisymm_iff, ← le_def, castPred_le_castPred_iff]
Injectivity of Predecessor Cast on Finite Types
Informal description
For any two elements $i$ and $j$ of the finite type $\text{Fin}(n+1)$ (i.e., natural numbers $0 \leq i, j < n+1$) that are not the last element, the equality $\text{castPred}(i, h_i) = \text{castPred}(j, h_j)$ holds if and only if $i = j$. Here, $\text{castPred}(i, h_i)$ denotes the predecessor of $i$ in $\text{Fin}(n)$, provided $i$ is not the last element of $\text{Fin}(n+1)$.
Fin.castPred_eq_zero theorem
[NeZero n] {i : Fin (n + 1)} (h : i ≠ last n) : Fin.castPred i h = 0 ↔ i = 0
Full source
@[simp]
theorem castPred_eq_zero [NeZero n] {i : Fin (n + 1)} (h : i ≠ last n) :
    Fin.castPredFin.castPred i h = 0 ↔ i = 0 := by
  rw [← castPred_zero', castPred_inj]
Predecessor Cast of Non-Last Element Equals Zero if and only if Element is Zero
Informal description
For a positive natural number $n$ (i.e., when `[NeZero n]` holds), and for any element $i$ of the finite type $\text{Fin}(n+1)$ (i.e., $0 \leq i < n+1$) that is not the last element, the predecessor cast of $i$ equals $0$ if and only if $i = 0$. In other words, if $i \neq \text{last } n$, then $\text{castPred}(i, h) = 0 \leftrightarrow i = 0$.
Fin.succ_castPred_eq_add_one theorem
{a : Fin (n + 1)} (ha : a ≠ last n) : (a.castPred ha).succ = a + 1
Full source
theorem succ_castPred_eq_add_one {a : Fin (n + 1)} (ha : a ≠ last n) :
    (a.castPred ha).succ = a + 1 := by
  cases a using lastCases
  · exact (ha rfl).elim
  · rw [castPred_castSucc, coeSucc_eq_succ]
Successor of Predecessor Cast Equals Increment in Finite Types
Informal description
For any element $a$ of the finite type $\text{Fin}(n+1)$ (where $n$ is a natural number) such that $a$ is not the last element, the successor of the predecessor cast of $a$ equals $a + 1$. That is, if $a \neq \text{last } n$, then $\text{succ}(\text{castPred}(a, ha)) = a + 1$.
Fin.castpred_succ_le_iff theorem
{a b : Fin (n + 1)} (ha : succ a ≠ last (n + 1)) : (succ a).castPred ha ≤ b ↔ a < b
Full source
theorem castpred_succ_le_iff {a b : Fin (n + 1)} (ha : succsucc a ≠ last (n + 1)) :
    (succ a).castPred ha ≤ b ↔ a < b := by
  rw [castPred_le_iff, succ_le_castSucc_iff]
Order relation between predecessor cast of successor and strict inequality in finite types: $\mathrm{castPred}(\mathrm{succ}\,a) \leq b \leftrightarrow a < b$
Informal description
For any elements $a, b$ in the finite type $\mathrm{Fin}(n+1)$, if the successor of $a$ is not the last element of $\mathrm{Fin}(n+2)$, then the predecessor cast of $\mathrm{succ}\,a$ is less than or equal to $b$ if and only if $a$ is strictly less than $b$. Here: - $\mathrm{Fin}(n)$ denotes the finite type with $n$ elements (natural numbers less than $n$) - $\mathrm{last}\,n$ is the maximal element of $\mathrm{Fin}(n+1)$ (equal to $n$) - $\mathrm{succ}$ is the successor operation on $\mathrm{Fin}(n)$ - $\mathrm{castPred}$ maps $i \in \mathrm{Fin}(n+1)$ to $\mathrm{Fin}(n)$ when $i \neq \mathrm{last}\,n$
Fin.lt_castPred_succ_iff theorem
{a b : Fin (n + 1)} (ha : succ a ≠ last (n + 1)) : b < (succ a).castPred ha ↔ b ≤ a
Full source
theorem lt_castPred_succ_iff {a b : Fin (n + 1)} (ha : succsucc a ≠ last (n + 1)) :
    b < (succ a).castPred ha ↔ b ≤ a := by
  rw [lt_castPred_iff, castSucc_lt_succ_iff]
Order equivalence between predecessor cast of successor and non-strict inequality in finite types: $b < \mathrm{castPred}(\mathrm{succ}\,a) \leftrightarrow b \leq a$
Informal description
For any elements $a, b$ in the finite type $\mathrm{Fin}(n+1)$, if the successor of $a$ is not the last element of $\mathrm{Fin}(n+2)$, then the inequality $b < \mathrm{castPred}(\mathrm{succ}\,a, h_a)$ holds if and only if $b \leq a$. Here: - $\mathrm{Fin}(n)$ denotes the finite type with $n$ elements (natural numbers less than $n$) - $\mathrm{last}\,n$ is the maximal element of $\mathrm{Fin}(n+1)$ (equal to $n$) - $\mathrm{succ}$ is the successor operation on $\mathrm{Fin}(n)$ - $\mathrm{castPred}$ maps $i \in \mathrm{Fin}(n+1)$ to $\mathrm{Fin}(n)$ when $i \neq \mathrm{last}\,n$
Fin.lt_castPred_succ theorem
{a : Fin (n + 1)} (ha : succ a ≠ last (n + 1)) : a < (succ a).castPred ha
Full source
theorem lt_castPred_succ {a : Fin (n + 1)} (ha : succsucc a ≠ last (n + 1)) :
    a < (succ a).castPred ha := by rw [lt_castPred_succ_iff, le_def]
Strict inequality between element and predecessor cast of its successor in finite types: $a < \mathrm{castPred}(\mathrm{succ}\,a)$
Informal description
For any element $a$ in the finite type $\mathrm{Fin}(n+1)$, if the successor of $a$ is not the last element of $\mathrm{Fin}(n+2)$, then $a$ is strictly less than the predecessor cast of $\mathrm{succ}\,a$. Here: - $\mathrm{Fin}(n)$ denotes the finite type with $n$ elements (natural numbers less than $n$) - $\mathrm{last}\,n$ is the maximal element of $\mathrm{Fin}(n+1)$ (equal to $n$) - $\mathrm{succ}$ is the successor operation on $\mathrm{Fin}(n)$ - $\mathrm{castPred}$ maps $i \in \mathrm{Fin}(n+1)$ to $\mathrm{Fin}(n)$ when $i \neq \mathrm{last}\,n$
Fin.succ_castPred_le_iff theorem
{a b : Fin (n + 1)} (ha : a ≠ last n) : succ (a.castPred ha) ≤ b ↔ a < b
Full source
theorem succ_castPred_le_iff {a b : Fin (n + 1)} (ha : a ≠ last n) :
    succsucc (a.castPred ha) ≤ b ↔ a < b := by
  rw [succ_castPred_eq_castPred_succ ha, castpred_succ_le_iff]
Order equivalence: $\mathrm{succ}(\mathrm{castPred}\,a) \leq b \leftrightarrow a < b$ in finite types
Informal description
For any elements $a, b$ in the finite type $\mathrm{Fin}(n+1)$, if $a$ is not the last element of $\mathrm{Fin}(n+1)$, then the successor of the predecessor cast of $a$ is less than or equal to $b$ if and only if $a$ is strictly less than $b$. Here: - $\mathrm{Fin}(n)$ denotes the finite type with $n$ elements (natural numbers less than $n$) - $\mathrm{last}\,n$ is the maximal element of $\mathrm{Fin}(n+1)$ (equal to $n$) - $\mathrm{succ}$ is the successor operation on $\mathrm{Fin}(n)$ - $\mathrm{castPred}$ maps $i \in \mathrm{Fin}(n+1)$ to $\mathrm{Fin}(n)$ when $i \neq \mathrm{last}\,n$
Fin.lt_succ_castPred_iff theorem
{a b : Fin (n + 1)} (ha : a ≠ last n) : b < succ (a.castPred ha) ↔ b ≤ a
Full source
theorem lt_succ_castPred_iff {a b : Fin (n + 1)} (ha : a ≠ last n) :
    b < succ (a.castPred ha) ↔ b ≤ a := by
  rw [succ_castPred_eq_castPred_succ ha, lt_castPred_succ_iff]
Order equivalence between successor of predecessor cast and non-strict inequality in finite types: $b < \mathrm{succ}(\mathrm{castPred}(a)) \leftrightarrow b \leq a$
Informal description
For any elements $a, b$ in the finite type $\mathrm{Fin}(n+1)$, if $a$ is not the last element of $\mathrm{Fin}(n+1)$, then the inequality $b < \mathrm{succ}(\mathrm{castPred}(a, h_a))$ holds if and only if $b \leq a$. Here: - $\mathrm{Fin}(n)$ denotes the finite type with $n$ elements (natural numbers less than $n$) - $\mathrm{last}\,n$ is the maximal element of $\mathrm{Fin}(n+1)$ (equal to $n$) - $\mathrm{succ}$ is the successor operation on $\mathrm{Fin}(n)$ - $\mathrm{castPred}$ maps $i \in \mathrm{Fin}(n+1)$ to $\mathrm{Fin}(n)$ when $i \neq \mathrm{last}\,n$
Fin.lt_succ_castPred theorem
{a : Fin (n + 1)} (ha : a ≠ last n) : a < succ (a.castPred ha)
Full source
theorem lt_succ_castPred {a : Fin (n + 1)} (ha : a ≠ last n) :
    a < succ (a.castPred ha) := by rw [lt_succ_castPred_iff, le_def]
Strict Inequality Between Element and Successor of Its Predecessor Cast in Finite Types
Informal description
For any element $a$ in the finite type $\mathrm{Fin}(n+1)$ (natural numbers less than $n+1$), if $a$ is not the last element of $\mathrm{Fin}(n+1)$, then $a$ is strictly less than the successor of its predecessor cast in $\mathrm{Fin}(n)$. Here: - $\mathrm{Fin}(n)$ denotes the finite type with $n$ elements (natural numbers less than $n$) - $\mathrm{last}\,n$ is the maximal element of $\mathrm{Fin}(n+1)$ (equal to $n$) - $\mathrm{succ}$ is the successor operation on $\mathrm{Fin}(n)$ - $\mathrm{castPred}$ maps $i \in \mathrm{Fin}(n+1)$ to $\mathrm{Fin}(n)$ when $i \neq \mathrm{last}\,n$
Fin.castPred_le_pred_iff theorem
{a b : Fin (n + 1)} (ha : a ≠ last n) (hb : b ≠ 0) : castPred a ha ≤ pred b hb ↔ a < b
Full source
theorem castPred_le_pred_iff {a b : Fin (n + 1)} (ha : a ≠ last n) (hb : b ≠ 0) :
    castPredcastPred a ha ≤ pred b hb ↔ a < b := by
  rw [le_pred_iff, succ_castPred_le_iff]
Order equivalence: $\mathrm{castPred}(a) \leq \mathrm{pred}(b) \leftrightarrow a < b$ in finite types
Informal description
For any elements $a, b$ in the finite type $\mathrm{Fin}(n+1)$, if $a$ is not the last element and $b$ is not zero, then the inequality $\mathrm{castPred}(a) \leq \mathrm{pred}(b)$ holds if and only if $a < b$. Here: - $\mathrm{Fin}(n)$ denotes the finite type with $n$ elements (natural numbers less than $n$) - $\mathrm{last}\,n$ is the maximal element of $\mathrm{Fin}(n+1)$ (equal to $n$) - $\mathrm{castPred}(a)$ maps $a \in \mathrm{Fin}(n+1)$ to $\mathrm{Fin}(n)$ when $a \neq \mathrm{last}\,n$ - $\mathrm{pred}(b)$ is the predecessor of $b$ in $\mathrm{Fin}(n+1)$ (defined when $b \neq 0$)
Fin.pred_lt_castPred_iff theorem
{a b : Fin (n + 1)} (ha : a ≠ 0) (hb : b ≠ last n) : pred a ha < castPred b hb ↔ a ≤ b
Full source
theorem pred_lt_castPred_iff {a b : Fin (n + 1)} (ha : a ≠ 0) (hb : b ≠ last n) :
    predpred a ha < castPred b hb ↔ a ≤ b := by
  rw [lt_castPred_iff, castSucc_pred_lt_iff ha]
Predecessor and Cast Predicate Order Relation in Finite Types
Informal description
For any elements $a, b$ in the finite type $\mathrm{Fin}(n+1)$ such that $a \neq 0$ and $b \neq \mathrm{last}\,n$, the inequality $\mathrm{pred}(a) < \mathrm{castPred}(b)$ holds if and only if $a \leq b$. Here: - $\mathrm{Fin}(n)$ denotes the finite type with $n$ elements (natural numbers less than $n$) - $\mathrm{last}\,n$ is the maximal element of $\mathrm{Fin}(n+1)$ (equal to $n$) - $\mathrm{pred}(a)$ is the predecessor of $a$ in $\mathrm{Fin}(n+1)$ (defined when $a \neq 0$) - $\mathrm{castPred}(b)$ maps $b \in \mathrm{Fin}(n+1)$ to $\mathrm{Fin}(n)$ when $b \neq \mathrm{last}\,n$
Fin.pred_lt_castPred theorem
{a : Fin (n + 1)} (h₁ : a ≠ 0) (h₂ : a ≠ last n) : pred a h₁ < castPred a h₂
Full source
theorem pred_lt_castPred {a : Fin (n + 1)} (h₁ : a ≠ 0) (h₂ : a ≠ last n) :
    pred a h₁ < castPred a h₂ := by
  rw [pred_lt_castPred_iff, le_def]
Predecessor is Less Than Cast Predecessor in Finite Types
Informal description
For any element $a$ in the finite type $\mathrm{Fin}(n+1)$ such that $a \neq 0$ and $a \neq \mathrm{last}\,n$, the predecessor of $a$ is strictly less than the cast predecessor of $a$. Here: - $\mathrm{Fin}(n)$ denotes the finite type with $n$ elements (natural numbers less than $n$) - $\mathrm{last}\,n$ is the maximal element of $\mathrm{Fin}(n+1)$ (equal to $n$) - $\mathrm{pred}(a)$ is the predecessor of $a$ in $\mathrm{Fin}(n+1)$ (defined when $a \neq 0$) - $\mathrm{castPred}(a)$ maps $a \in \mathrm{Fin}(n+1)$ to $\mathrm{Fin}(n)$ when $a \neq \mathrm{last}\,n$
Fin.succAbove definition
(p : Fin (n + 1)) (i : Fin n) : Fin (n + 1)
Full source
/-- `succAbove p i` embeds `Fin n` into `Fin (n + 1)` with a hole around `p`. -/
def succAbove (p : Fin (n + 1)) (i : Fin n) : Fin (n + 1) :=
  if castSucc i < p then i.castSucc else i.succ
Embedding of `Fin n` into `Fin (n + 1)` with a hole at `p`
Informal description
Given a natural number `n`, the function `succAbove p i` embeds the element `i` of the finite type `Fin n` into `Fin (n + 1)` by inserting a "hole" at position `p`. Specifically, if the cast of `i` to `Fin (n + 1)` is less than `p`, then `i` is embedded as `castSucc i`; otherwise, it is embedded as `succ i`.
Fin.succAbove_of_castSucc_lt theorem
(p : Fin (n + 1)) (i : Fin n) (h : castSucc i < p) : p.succAbove i = castSucc i
Full source
/-- Embedding `i : Fin n` into `Fin (n + 1)` with a hole around `p : Fin (n + 1)`
embeds `i` by `castSucc` when the resulting `i.castSucc < p`. -/
lemma succAbove_of_castSucc_lt (p : Fin (n + 1)) (i : Fin n) (h : castSucc i < p) :
    p.succAbove i = castSucc i := if_pos h
Embedding Condition for $\text{succAbove}$ when $\text{castSucc}\,i < p$
Informal description
For any natural number $n$, given an element $p \in \text{Fin}(n+1)$ and an element $i \in \text{Fin}(n)$, if the cast of $i$ to $\text{Fin}(n+1)$ (denoted as $\text{castSucc}\,i$) is strictly less than $p$, then the embedding $\text{succAbove}\,p\,i$ equals $\text{castSucc}\,i$.
Fin.succAbove_of_succ_le theorem
(p : Fin (n + 1)) (i : Fin n) (h : succ i ≤ p) : p.succAbove i = castSucc i
Full source
lemma succAbove_of_succ_le (p : Fin (n + 1)) (i : Fin n) (h : succ i ≤ p) :
    p.succAbove i = castSucc i :=
  succAbove_of_castSucc_lt _ _ (castSucc_lt_iff_succ_le.mpr h)
Embedding Condition for $\text{succAbove}$ when $\text{succ}(i) \leq p$
Informal description
For any natural number $n$, given an element $p \in \text{Fin}(n+1)$ and an element $i \in \text{Fin}(n)$, if the successor of $i$ is less than or equal to $p$, then the embedding $\text{succAbove}(p, i)$ equals the cast of $i$ to $\text{Fin}(n+1)$, denoted as $\text{castSucc}(i)$.
Fin.succAbove_of_le_castSucc theorem
(p : Fin (n + 1)) (i : Fin n) (h : p ≤ castSucc i) : p.succAbove i = i.succ
Full source
/-- Embedding `i : Fin n` into `Fin (n + 1)` with a hole around `p : Fin (n + 1)`
embeds `i` by `succ` when the resulting `p < i.succ`. -/
lemma succAbove_of_le_castSucc (p : Fin (n + 1)) (i : Fin n) (h : p ≤ castSucc i) :
    p.succAbove i = i.succ := if_neg (Fin.not_lt.2 h)
Embedding via Successor When Above Cast Element
Informal description
For any natural number $n$, given an element $p$ of $\text{Fin}(n+1)$ and an element $i$ of $\text{Fin}(n)$, if $p \leq \text{castSucc}(i)$, then the embedding $\text{succAbove}(p, i)$ equals the successor of $i$, i.e., $\text{succ}(i)$.
Fin.succAbove_of_lt_succ theorem
(p : Fin (n + 1)) (i : Fin n) (h : p < succ i) : p.succAbove i = succ i
Full source
lemma succAbove_of_lt_succ (p : Fin (n + 1)) (i : Fin n) (h : p < succ i) :
    p.succAbove i = succ i := succAbove_of_le_castSucc _ _ (le_castSucc_iff.mpr h)
Embedding via Successor When Below Successor Element
Informal description
For any natural number $n$, given an element $p \in \text{Fin}(n+1)$ and an element $i \in \text{Fin}(n)$, if $p < \text{succ}(i)$, then the embedding $\text{succAbove}(p, i)$ equals the successor of $i$, i.e., $\text{succ}(i)$.
Fin.succAbove_succ_of_lt theorem
(p i : Fin n) (h : p < i) : succAbove p.succ i = i.succ
Full source
lemma succAbove_succ_of_lt (p i : Fin n) (h : p < i) : succAbove p.succ i = i.succ :=
  succAbove_of_lt_succ _ _ (succ_lt_succ_iff.mpr h)
Successor Embedding for Elements Below in Finite Types
Informal description
For any natural number $n$ and elements $p, i \in \text{Fin}(n)$, if $p < i$, then the embedding $\text{succAbove}(p.\text{succ}, i)$ equals the successor of $i$, i.e., $i.\text{succ}$.
Fin.succAbove_succ_of_le theorem
(p i : Fin n) (h : i ≤ p) : succAbove p.succ i = i.castSucc
Full source
lemma succAbove_succ_of_le (p i : Fin n) (h : i ≤ p) : succAbove p.succ i = i.castSucc :=
  succAbove_of_succ_le _ _ (succ_le_succ_iff.mpr h)
Embedding via Cast When Below or Equal in Finite Types
Informal description
For any natural number $n$ and elements $p, i \in \text{Fin}(n)$, if $i \leq p$, then the embedding $\text{succAbove}(p.\text{succ}, i)$ equals the cast of $i$ to $\text{Fin}(n+1)$, denoted as $i.\text{castSucc}$.
Fin.succAbove_succ_self theorem
(j : Fin n) : j.succ.succAbove j = j.castSucc
Full source
@[simp] lemma succAbove_succ_self (j : Fin n) : j.succ.succAbove j = j.castSucc :=
  succAbove_succ_of_le _ _ Fin.le_rfl
Self-Embedding via Successor in Finite Types
Informal description
For any natural number $n$ and element $j \in \text{Fin}(n)$, the embedding $\text{succAbove}(j.\text{succ}, j)$ equals the cast of $j$ to $\text{Fin}(n+1)$, denoted as $j.\text{castSucc}$.
Fin.succAbove_castSucc_of_lt theorem
(p i : Fin n) (h : i < p) : succAbove p.castSucc i = i.castSucc
Full source
lemma succAbove_castSucc_of_lt (p i : Fin n) (h : i < p) : succAbove p.castSucc i = i.castSucc :=
  succAbove_of_castSucc_lt _ _ (castSucc_lt_castSucc_iff.2 h)
Embedding Condition for $\text{succAbove}$ when $i < p$ and $p$ is Cast to $\text{Fin}(n+1)$
Informal description
For any natural number $n$ and elements $p, i \in \text{Fin}(n)$, if $i < p$, then the embedding $\text{succAbove}\,p.\text{castSucc}\,i$ equals $i.\text{castSucc}$.
Fin.succAbove_castSucc_of_le theorem
(p i : Fin n) (h : p ≤ i) : succAbove p.castSucc i = i.succ
Full source
lemma succAbove_castSucc_of_le (p i : Fin n) (h : p ≤ i) : succAbove p.castSucc i = i.succ :=
  succAbove_of_le_castSucc _ _ (castSucc_le_castSucc_iff.2 h)
Embedding via Successor When Below Cast Element in Finite Types
Informal description
For any natural number $n$ and elements $p, i \in \text{Fin}(n)$, if $p \leq i$, then the embedding $\text{succAbove}(\text{castSucc}(p), i) = \text{succ}(i)$.
Fin.succAbove_castSucc_self theorem
(j : Fin n) : succAbove j.castSucc j = j.succ
Full source
@[simp] lemma succAbove_castSucc_self (j : Fin n) : succAbove j.castSucc j = j.succ :=
  succAbove_castSucc_of_le _ _ Fin.le_rfl
Self-embedding property of $\mathrm{succAbove}$ at cast element
Informal description
For any natural number $n$ and element $j \in \mathrm{Fin}(n)$, the embedding $\mathrm{succAbove}(\mathrm{castSucc}(j), j)$ equals the successor of $j$ in $\mathrm{Fin}(n+1)$. Here: - $\mathrm{Fin}(n)$ denotes the finite type with $n$ elements (natural numbers less than $n$) - $\mathrm{castSucc}(j)$ casts $j$ to $\mathrm{Fin}(n+1)$ without changing its value - $\mathrm{succAbove}(p, \cdot)$ embeds $\mathrm{Fin}(n)$ into $\mathrm{Fin}(n+1)$ with a "hole" at position $p$ - $\mathrm{succ}(j)$ is the successor operation in $\mathrm{Fin}(n+1)$
Fin.succAbove_pred_of_le theorem
(p i : Fin (n + 1)) (h : i ≤ p) (hi : i ≠ 0) : succAbove p (i.pred hi) = (i.pred hi).castSucc
Full source
lemma succAbove_pred_of_le (p i : Fin (n + 1)) (h : i ≤ p) (hi : i ≠ 0) :
    succAbove p (i.pred hi) = (i.pred hi).castSucc := succAbove_of_succ_le _ _ (succ_pred _ _ ▸ h)
Embedding of Predecessor Below Given Position in Finite Types
Informal description
For any natural number $n$ and elements $p, i \in \mathrm{Fin}(n+1)$, if $i \leq p$ and $i \neq 0$, then the embedding $\mathrm{succAbove}(p, \mathrm{pred}(i))$ equals the cast of $\mathrm{pred}(i)$ to $\mathrm{Fin}(n+1)$, denoted as $\mathrm{castSucc}(\mathrm{pred}(i))$. Here: - $\mathrm{Fin}(n)$ denotes the finite type with $n$ elements (natural numbers less than $n$) - $\mathrm{pred}(i)$ maps $i \in \mathrm{Fin}(n+1)$ to $\mathrm{Fin}(n)$ when $i \neq 0$ - $\mathrm{succAbove}(p, \cdot)$ embeds $\mathrm{Fin}(n)$ into $\mathrm{Fin}(n+1)$ with a "hole" at position $p$ - $\mathrm{castSucc}$ casts an element of $\mathrm{Fin}(n)$ to $\mathrm{Fin}(n+1)$ without changing its value
Fin.succAbove_pred_self theorem
(p : Fin (n + 1)) (h : p ≠ 0) : succAbove p (p.pred h) = (p.pred h).castSucc
Full source
@[simp] lemma succAbove_pred_self (p : Fin (n + 1)) (h : p ≠ 0) :
    succAbove p (p.pred h) = (p.pred h).castSucc := succAbove_pred_of_le _ _ Fin.le_rfl h
Self-embedding Property of Predecessor in Finite Types
Informal description
For any natural number $n$ and any nonzero element $p \in \mathrm{Fin}(n+1)$, the embedding $\mathrm{succAbove}(p, \mathrm{pred}(p))$ equals the cast of $\mathrm{pred}(p)$ to $\mathrm{Fin}(n+1)$, denoted as $\mathrm{castSucc}(\mathrm{pred}(p))$. Here: - $\mathrm{Fin}(n)$ denotes the finite type with $n$ elements (natural numbers less than $n$) - $\mathrm{pred}(p)$ maps $p \in \mathrm{Fin}(n+1)$ to $\mathrm{Fin}(n)$ when $p \neq 0$ - $\mathrm{succAbove}(p, \cdot)$ embeds $\mathrm{Fin}(n)$ into $\mathrm{Fin}(n+1)$ with a "hole" at position $p$ - $\mathrm{castSucc}$ casts an element of $\mathrm{Fin}(n)$ to $\mathrm{Fin}(n+1)$ without changing its value
Fin.succAbove_castPred_of_le theorem
(p i : Fin (n + 1)) (h : p ≤ i) (hi : i ≠ last n) : succAbove p (i.castPred hi) = (i.castPred hi).succ
Full source
lemma succAbove_castPred_of_le (p i : Fin (n + 1)) (h : p ≤ i) (hi : i ≠ last n) :
    succAbove p (i.castPred hi) = (i.castPred hi).succ :=
  succAbove_of_le_castSucc _ _ (castSucc_castPred _ _ ▸ h)
Embedding via Successor for Non-Last Elements Above a Given Position
Informal description
For any natural number $n$, given elements $p, i \in \mathrm{Fin}(n+1)$ such that $p \leq i$ and $i$ is not the last element of $\mathrm{Fin}(n+1)$, the embedding $\mathrm{succAbove}(p, \mathrm{castPred}(i))$ equals the successor of $\mathrm{castPred}(i)$. Here: - $\mathrm{Fin}(n)$ denotes the finite type with $n$ elements (natural numbers less than $n$) - $\mathrm{castPred}(i)$ maps $i \in \mathrm{Fin}(n+1)$ to $\mathrm{Fin}(n)$ when $i \neq \mathrm{last}\,n$ - $\mathrm{succAbove}(p, \cdot)$ embeds $\mathrm{Fin}(n)$ into $\mathrm{Fin}(n+1)$ with a "hole" at position $p$ - The successor operation $\mathrm{succ}$ increments an element of $\mathrm{Fin}(n)$ to $\mathrm{Fin}(n+1)$
Fin.succAbove_castPred_self theorem
(p : Fin (n + 1)) (h : p ≠ last n) : succAbove p (p.castPred h) = (p.castPred h).succ
Full source
lemma succAbove_castPred_self (p : Fin (n + 1)) (h : p ≠ last n) :
    succAbove p (p.castPred h) = (p.castPred h).succ := succAbove_castPred_of_le _ _ Fin.le_rfl h
Self-embedding via Successor for Non-Last Elements in Finite Types
Informal description
For any natural number $n$ and any element $p \in \mathrm{Fin}(n+1)$ that is not the last element, the embedding $\mathrm{succAbove}(p, \mathrm{castPred}(p))$ equals the successor of $\mathrm{castPred}(p)$. Here: - $\mathrm{Fin}(n)$ denotes the finite type with $n$ elements (natural numbers less than $n$) - $\mathrm{castPred}(p)$ maps $p \in \mathrm{Fin}(n+1)$ to $\mathrm{Fin}(n)$ when $p \neq \mathrm{last}\,n$ - $\mathrm{succAbove}(p, \cdot)$ embeds $\mathrm{Fin}(n)$ into $\mathrm{Fin}(n+1)$ with a "hole" at position $p$ - The successor operation $\mathrm{succ}$ increments an element of $\mathrm{Fin}(n)$ to $\mathrm{Fin}(n+1)$
Fin.succAbove_ne theorem
(p : Fin (n + 1)) (i : Fin n) : p.succAbove i ≠ p
Full source
/-- Embedding `i : Fin n` into `Fin (n + 1)` with a hole around `p : Fin (n + 1)`
never results in `p` itself -/
@[simp]
lemma succAbove_ne (p : Fin (n + 1)) (i : Fin n) : p.succAbove i ≠ p := by
  rcases p.castSucc_lt_or_lt_succ i with (h | h)
  · rw [succAbove_of_castSucc_lt _ _ h]
    exact Fin.ne_of_lt h
  · rw [succAbove_of_lt_succ _ _ h]
    exact Fin.ne_of_gt h
Non-identity of $\mathrm{succAbove}$ embedding in finite types
Informal description
For any natural number $n$, given an element $p \in \mathrm{Fin}(n+1)$ and an element $i \in \mathrm{Fin}(n)$, the embedding $\mathrm{succAbove}(p, i)$ is not equal to $p$.
Fin.ne_succAbove theorem
(p : Fin (n + 1)) (i : Fin n) : p ≠ p.succAbove i
Full source
@[simp]
lemma ne_succAbove (p : Fin (n + 1)) (i : Fin n) : p ≠ p.succAbove i := (succAbove_ne _ _).symm
Non-equality of pivot and $\mathrm{succAbove}$ embedding in finite types
Informal description
For any natural number $n$, given an element $p \in \mathrm{Fin}(n+1)$ and an element $i \in \mathrm{Fin}(n)$, the element $p$ is not equal to the embedding $\mathrm{succAbove}(p, i)$.
Fin.succAbove_right_injective theorem
: Injective p.succAbove
Full source
/-- Given a fixed pivot `p : Fin (n + 1)`, `p.succAbove` is injective. -/
lemma succAbove_right_injective : Injective p.succAbove := by
  rintro i j hij
  unfold succAbove at hij
  split_ifs at hij with hi hj hj
  · exact castSucc_injective _ hij
  · rw [hij] at hi
    cases hj <| Nat.lt_trans j.castSucc_lt_succ hi
  · rw [← hij] at hj
    cases hi <| Nat.lt_trans i.castSucc_lt_succ hj
  · exact succ_injective _ hij
Injectivity of the $\mathrm{succAbove}$ Embedding with Fixed Pivot
Informal description
For any natural number $n$ and any fixed element $p \in \mathrm{Fin}(n+1)$, the function $\mathrm{succAbove}(p, \cdot) : \mathrm{Fin}\,n \to \mathrm{Fin}\,(n+1)$ is injective. That is, for any $i, j \in \mathrm{Fin}\,n$, if $\mathrm{succAbove}(p, i) = \mathrm{succAbove}(p, j)$, then $i = j$.
Fin.succAbove_right_inj theorem
: p.succAbove i = p.succAbove j ↔ i = j
Full source
/-- Given a fixed pivot `p : Fin (n + 1)`, `p.succAbove` is injective. -/
lemma succAbove_right_inj : p.succAbove i = p.succAbove j ↔ i = j :=
  succAbove_right_injective.eq_iff
Injectivity of $\mathrm{succAbove}$ with Fixed Pivot: $\mathrm{succAbove}(p, i) = \mathrm{succAbove}(p, j) \leftrightarrow i = j$
Informal description
For any natural number $n$, fixed element $p \in \mathrm{Fin}(n+1)$, and elements $i, j \in \mathrm{Fin}\,n$, the equality $\mathrm{succAbove}(p, i) = \mathrm{succAbove}(p, j)$ holds if and only if $i = j$.
Fin.succAboveEmb definition
(p : Fin (n + 1)) : Fin n ↪ Fin (n + 1)
Full source
/-- `Fin.succAbove p` as an `Embedding`. -/
@[simps!]
def succAboveEmb (p : Fin (n + 1)) : FinFin n ↪ Fin (n + 1) := ⟨p.succAbove, succAbove_right_injective⟩
Embedding of $\mathrm{Fin}(n)$ into $\mathrm{Fin}(n+1)$ with a hole at $p$
Informal description
For a natural number $n$ and an element $p \in \mathrm{Fin}(n+1)$, the embedding $\mathrm{succAboveEmb}(p)$ injectively maps $\mathrm{Fin}(n)$ into $\mathrm{Fin}(n+1)$ by inserting a "hole" at position $p$. Specifically, for $i \in \mathrm{Fin}(n)$, if $i < p$ (when cast to $\mathrm{Fin}(n+1)$), then $i$ is mapped to $\mathrm{castSucc}(i)$; otherwise, it is mapped to $\mathrm{succ}(i)$.
Fin.coe_succAboveEmb theorem
(p : Fin (n + 1)) : p.succAboveEmb = p.succAbove
Full source
@[simp, norm_cast] lemma coe_succAboveEmb (p : Fin (n + 1)) : p.succAboveEmb = p.succAbove := rfl
Equality of $\mathrm{succAboveEmb}$ and $\mathrm{succAbove}$ as Functions
Informal description
For any natural number $n$ and any element $p \in \mathrm{Fin}(n+1)$, the embedding $\mathrm{succAboveEmb}(p)$ is equal to the function $\mathrm{succAbove}(p)$ when viewed as a function from $\mathrm{Fin}(n)$ to $\mathrm{Fin}(n+1)$.
Fin.succAbove_ne_zero_zero theorem
[NeZero n] {a : Fin (n + 1)} (ha : a ≠ 0) : a.succAbove 0 = 0
Full source
@[simp]
lemma succAbove_ne_zero_zero [NeZero n] {a : Fin (n + 1)} (ha : a ≠ 0) : a.succAbove 0 = 0 := by
  rw [Fin.succAbove_of_castSucc_lt]
  · exact castSucc_zero'
  · exact Fin.pos_iff_ne_zero.2 ha
Preservation of Zero under $\text{succAbove}$ for Non-Zero Elements
Informal description
For any positive natural number $n$ (i.e., $n \neq 0$) and any non-zero element $a \in \text{Fin}(n+1)$, the embedding $\text{succAbove}$ maps the zero element of $\text{Fin}(n)$ to the zero element of $\text{Fin}(n+1)$. In other words, $a.\text{succAbove}(0) = 0$ holds when $a \neq 0$.
Fin.succAbove_eq_zero_iff theorem
[NeZero n] {a : Fin (n + 1)} {b : Fin n} (ha : a ≠ 0) : a.succAbove b = 0 ↔ b = 0
Full source
lemma succAbove_eq_zero_iff [NeZero n] {a : Fin (n + 1)} {b : Fin n} (ha : a ≠ 0) :
    a.succAbove b = 0 ↔ b = 0 := by
  rw [← succAbove_ne_zero_zero ha, succAbove_right_inj]
Characterization of Zero in $\mathrm{succAbove}$ Embedding: $\mathrm{succAbove}(a, b) = 0 \leftrightarrow b = 0$ for $a \neq 0$
Informal description
For any positive natural number $n$ (i.e., $n \neq 0$), non-zero element $a \in \mathrm{Fin}(n+1)$, and element $b \in \mathrm{Fin}(n)$, the embedding $\mathrm{succAbove}(a, b)$ equals $0$ if and only if $b = 0$.
Fin.succAbove_ne_zero theorem
[NeZero n] {a : Fin (n + 1)} {b : Fin n} (ha : a ≠ 0) (hb : b ≠ 0) : a.succAbove b ≠ 0
Full source
lemma succAbove_ne_zero [NeZero n] {a : Fin (n + 1)} {b : Fin n} (ha : a ≠ 0) (hb : b ≠ 0) :
    a.succAbove b ≠ 0 := mt (succAbove_eq_zero_iff ha).mp hb
Non-Zero Preservation under $\mathrm{succAbove}$ Embedding
Informal description
For any positive natural number $n$ (i.e., $n \neq 0$), non-zero element $a \in \mathrm{Fin}(n+1)$, and non-zero element $b \in \mathrm{Fin}(n)$, the embedding $\mathrm{succAbove}(a, b)$ is non-zero. In other words, if $a \neq 0$ and $b \neq 0$, then $a.\mathrm{succAbove}(b) \neq 0$.
Fin.succAbove_zero theorem
: succAbove (0 : Fin (n + 1)) = Fin.succ
Full source
/-- Embedding `Fin n` into `Fin (n + 1)` with a hole around zero embeds by `succ`. -/
@[simp] lemma succAbove_zero : succAbove (0 : Fin (n + 1)) = Fin.succ := rfl
`succAbove` at Zero Equals Successor Function on `Fin n`
Informal description
The embedding `succAbove` with a hole at `0` is equal to the successor function `succ` on `Fin n`, i.e., for any natural number `n`, the function `succAbove (0 : Fin (n + 1))` coincides with `Fin.succ` when applied to any element of `Fin n`.
Fin.succAbove_zero_apply theorem
(i : Fin n) : succAbove 0 i = succ i
Full source
lemma succAbove_zero_apply (i : Fin n) : succAbove 0 i = succ i := by rw [succAbove_zero]
$\text{succAbove}$ at Zero Acts as Successor on $\text{Fin } n$
Informal description
For any natural number $n$ and any element $i$ of the finite type $\text{Fin } n$, the embedding $\text{succAbove}$ with a hole at $0$ satisfies $\text{succAbove } 0\ i = \text{succ } i$.
Fin.succAbove_ne_last_last theorem
{a : Fin (n + 2)} (h : a ≠ last (n + 1)) : a.succAbove (last n) = last (n + 1)
Full source
@[simp] lemma succAbove_ne_last_last {a : Fin (n + 2)} (h : a ≠ last (n + 1)) :
    a.succAbove (last n) = last (n + 1) := by
  rw [succAbove_of_lt_succ _ _ (succ_last _ ▸ lt_last_iff_ne_last.2 h), succ_last]
Embedding of Last Element via $\mathrm{succAbove}$ Yields Last Element When Not at Last Position
Informal description
For any element $a$ of $\mathrm{Fin}(n+2)$ such that $a \neq \mathrm{last}(n+1)$, the embedding $\mathrm{succAbove}(a, \mathrm{last}(n))$ equals $\mathrm{last}(n+1)$.
Fin.succAbove_eq_last_iff theorem
{a : Fin (n + 2)} {b : Fin (n + 1)} (ha : a ≠ last _) : a.succAbove b = last _ ↔ b = last _
Full source
lemma succAbove_eq_last_iff {a : Fin (n + 2)} {b : Fin (n + 1)} (ha : a ≠ last _) :
    a.succAbove b = last _ ↔ b = last _ := by
  rw [← succAbove_ne_last_last ha, succAbove_right_inj]
Characterization of When $\mathrm{succAbove}$ Yields Last Element
Informal description
For any element $a$ of $\mathrm{Fin}(n+2)$ such that $a \neq \mathrm{last}(n+1)$, and any element $b$ of $\mathrm{Fin}(n+1)$, the embedding $\mathrm{succAbove}(a, b)$ equals $\mathrm{last}(n+1)$ if and only if $b$ equals $\mathrm{last}(n)$.
Fin.succAbove_ne_last theorem
{a : Fin (n + 2)} {b : Fin (n + 1)} (ha : a ≠ last _) (hb : b ≠ last _) : a.succAbove b ≠ last _
Full source
lemma succAbove_ne_last {a : Fin (n + 2)} {b : Fin (n + 1)} (ha : a ≠ last _) (hb : b ≠ last _) :
    a.succAbove b ≠ last _ := mt (succAbove_eq_last_iff ha).mp hb
Non-last Elements Preserved Under $\mathrm{succAbove}$ Embedding
Informal description
For any element $a$ of $\mathrm{Fin}(n+2)$ such that $a \neq \mathrm{last}(n+1)$, and any element $b$ of $\mathrm{Fin}(n+1)$ such that $b \neq \mathrm{last}(n)$, the embedding $\mathrm{succAbove}(a, b)$ is not equal to $\mathrm{last}(n+1)$.
Fin.succAbove_last theorem
: succAbove (last n) = castSucc
Full source
/-- Embedding `Fin n` into `Fin (n + 1)` with a hole around `last n` embeds by `castSucc`. -/
@[simp] lemma succAbove_last : succAbove (last n) = castSucc := by
  ext; simp only [succAbove_of_castSucc_lt, castSucc_lt_last]
$\text{succAbove}$ at Last Element Equals $\text{castSucc}$
Informal description
For any natural number $n$, the embedding $\text{succAbove}$ applied to the last element of $\text{Fin}(n+1)$ is equal to the cast embedding $\text{castSucc} : \text{Fin}(n) \to \text{Fin}(n+1)$. In other words, when the "hole" position $p$ is chosen as the last element $\text{last}\,n$, the $\text{succAbove}$ embedding reduces to the standard $\text{castSucc}$ embedding.
Fin.succAbove_last_apply theorem
(i : Fin n) : succAbove (last n) i = castSucc i
Full source
lemma succAbove_last_apply (i : Fin n) : succAbove (last n) i = castSucc i := by rw [succAbove_last]
Embedding at Last Element Equals Cast Successor
Informal description
For any natural number $n$ and any element $i \in \mathrm{Fin}(n)$, the embedding $\mathrm{succAbove}$ applied to the last element of $\mathrm{Fin}(n+1)$ and $i$ equals the cast successor of $i$, i.e., $\mathrm{succAbove}\,(\mathrm{last}\,n)\,i = \mathrm{castSucc}\,i$.
Fin.succAbove_lt_iff_castSucc_lt theorem
(p : Fin (n + 1)) (i : Fin n) : p.succAbove i < p ↔ castSucc i < p
Full source
/-- Embedding `i : Fin n` into `Fin (n + 1)` using a pivot `p` that is greater
results in a value that is less than `p`. -/
lemma succAbove_lt_iff_castSucc_lt (p : Fin (n + 1)) (i : Fin n) :
    p.succAbove i < p ↔ castSucc i < p := by
  rcases castSucc_lt_or_lt_succ p i with H | H
  · rwa [iff_true_right H, succAbove_of_castSucc_lt _ _ H]
  · rw [castSucc_lt_iff_succ_le, iff_false_right (Fin.not_le.2 H), succAbove_of_lt_succ _ _ H]
    exact Fin.not_lt.2 <| Fin.le_of_lt H
Embedding Order Condition: $\mathrm{succAbove}(p, i) < p \leftrightarrow \mathrm{castSucc}\,i < p$
Informal description
For any natural number $n$, given an element $p \in \mathrm{Fin}(n+1)$ and an element $i \in \mathrm{Fin}(n)$, the embedding $\mathrm{succAbove}(p, i)$ is less than $p$ if and only if the cast successor of $i$ is less than $p$. In other words, $p.\mathrm{succAbove}\,i < p \leftrightarrow \mathrm{castSucc}\,i < p$.
Fin.succAbove_lt_iff_succ_le theorem
(p : Fin (n + 1)) (i : Fin n) : p.succAbove i < p ↔ succ i ≤ p
Full source
lemma succAbove_lt_iff_succ_le (p : Fin (n + 1)) (i : Fin n) :
    p.succAbove i < p ↔ succ i ≤ p := by
  rw [succAbove_lt_iff_castSucc_lt, castSucc_lt_iff_succ_le]
Order condition for $\mathrm{succAbove}$ embedding: $\mathrm{succAbove}(p, i) < p \leftrightarrow \mathrm{succ}(i) \leq p$
Informal description
For any natural number $n$, given an element $p \in \mathrm{Fin}(n+1)$ and an element $i \in \mathrm{Fin}(n)$, the embedding $\mathrm{succAbove}(p, i)$ is less than $p$ if and only if the successor of $i$ is less than or equal to $p$. In other words, $\mathrm{succAbove}(p, i) < p \leftrightarrow \mathrm{succ}(i) \leq p$.
Fin.lt_succAbove_iff_le_castSucc theorem
(p : Fin (n + 1)) (i : Fin n) : p < p.succAbove i ↔ p ≤ castSucc i
Full source
/-- Embedding `i : Fin n` into `Fin (n + 1)` using a pivot `p` that is lesser
results in a value that is greater than `p`. -/
lemma lt_succAbove_iff_le_castSucc (p : Fin (n + 1)) (i : Fin n) :
    p < p.succAbove i ↔ p ≤ castSucc i := by
  rcases castSucc_lt_or_lt_succ p i with H | H
  · rw [iff_false_right (Fin.not_le.2 H), succAbove_of_castSucc_lt _ _ H]
    exact Fin.not_lt.2 <| Fin.le_of_lt H
  · rwa [succAbove_of_lt_succ _ _ H, iff_true_left H, le_castSucc_iff]
Order Condition for $\mathrm{succAbove}$ Embedding: $p < \mathrm{succAbove}(p, i) \leftrightarrow p \leq \mathrm{castSucc}\,i$
Informal description
For any natural number $n$, given an element $p \in \mathrm{Fin}(n+1)$ and an element $i \in \mathrm{Fin}(n)$, the embedding $\mathrm{succAbove}(p, i)$ is greater than $p$ if and only if $p$ is less than or equal to the cast successor of $i$. In other words, $p < \mathrm{succAbove}(p, i) \leftrightarrow p \leq \mathrm{castSucc}\,i$.
Fin.lt_succAbove_iff_lt_castSucc theorem
(p : Fin (n + 1)) (i : Fin n) : p < p.succAbove i ↔ p < succ i
Full source
lemma lt_succAbove_iff_lt_castSucc (p : Fin (n + 1)) (i : Fin n) :
    p < p.succAbove i ↔ p < succ i := by rw [lt_succAbove_iff_le_castSucc, le_castSucc_iff]
Order condition for $\mathrm{succAbove}$ embedding: $p < \mathrm{succAbove}(p, i) \leftrightarrow p < \mathrm{succ}\,i$
Informal description
For any natural number $n$, given an element $p \in \mathrm{Fin}(n+1)$ and an element $i \in \mathrm{Fin}(n)$, the embedding $\mathrm{succAbove}(p, i)$ is greater than $p$ if and only if $p$ is less than the successor of $i$. In other words, $p < \mathrm{succAbove}(p, i) \leftrightarrow p < \mathrm{succ}\,i$.
Fin.succAbove_pos theorem
[NeZero n] (p : Fin (n + 1)) (i : Fin n) (h : 0 < i) : 0 < p.succAbove i
Full source
/-- Embedding a positive `Fin n` results in a positive `Fin (n + 1)` -/
lemma succAbove_pos [NeZero n] (p : Fin (n + 1)) (i : Fin n) (h : 0 < i) : 0 < p.succAbove i := by
  by_cases H : castSucc i < p
  · simpa [succAbove_of_castSucc_lt _ _ H] using castSucc_pos' h
  · simp [succAbove_of_le_castSucc _ _ (Fin.not_lt.1 H)]
Positivity Preservation under $\text{succAbove}$ Embedding
Informal description
For any positive natural number $n$, given an element $p \in \text{Fin}(n+1)$ and a positive element $i \in \text{Fin}(n)$ (i.e., $0 < i$), the embedding $\text{succAbove}(p, i)$ is also positive, i.e., $0 < \text{succAbove}(p, i)$.
Fin.exists_succAbove_eq theorem
{x y : Fin (n + 1)} (h : x ≠ y) : ∃ z, y.succAbove z = x
Full source
lemma exists_succAbove_eq {x y : Fin (n + 1)} (h : x ≠ y) : ∃ z, y.succAbove z = x := by
  obtain hxy | hyx := Fin.lt_or_lt_of_ne h
  exacts [⟨_, succAbove_castPred_of_lt _ _ hxy⟩, ⟨_, succAbove_pred_of_lt _ _ hyx⟩]
Existence of Preimage under $\mathrm{succAbove}$ for Distinct Elements
Informal description
For any two distinct elements $x$ and $y$ in $\mathrm{Fin}(n+1)$, there exists an element $z \in \mathrm{Fin}(n)$ such that the embedding $\mathrm{succAbove}(y, z)$ equals $x$. In other words, $y.\mathrm{succAbove}(z) = x$.
Fin.exists_succAbove_eq_iff theorem
{x y : Fin (n + 1)} : (∃ z, x.succAbove z = y) ↔ y ≠ x
Full source
@[simp] lemma exists_succAbove_eq_iff {x y : Fin (n + 1)} : (∃ z, x.succAbove z = y) ↔ y ≠ x :=
  ⟨by rintro ⟨y, rfl⟩; exact succAbove_ne _ _, exists_succAbove_eq⟩
Characterization of Preimage under $\mathrm{succAbove}$ via Inequality
Informal description
For any two elements $x$ and $y$ in $\mathrm{Fin}(n+1)$, there exists an element $z \in \mathrm{Fin}(n)$ such that $x.\mathrm{succAbove}(z) = y$ if and only if $y \neq x$.
Fin.range_succAbove theorem
(p : Fin (n + 1)) : Set.range p.succAbove = { p }ᶜ
Full source
/-- The range of `p.succAbove` is everything except `p`. -/
@[simp] lemma range_succAbove (p : Fin (n + 1)) : Set.range p.succAbove = {p}{p}ᶜ :=
  Set.ext fun _ => exists_succAbove_eq_iff
Range of $\mathrm{succAbove}$ Function is Complement of Singleton
Informal description
For any element $p$ in $\mathrm{Fin}(n+1)$, the range of the function $\mathrm{succAbove}(p, \cdot)$ is the complement of the singleton set $\{p\}$. In other words, the function $\mathrm{succAbove}(p, \cdot)$ maps $\mathrm{Fin}(n)$ bijectively onto $\mathrm{Fin}(n+1) \setminus \{p\}$.
Fin.range_succ theorem
(n : ℕ) : Set.range (Fin.succ : Fin n → Fin (n + 1)) = {0}ᶜ
Full source
@[simp] lemma range_succ (n : ) : Set.range (Fin.succ : Fin n → Fin (n + 1)) = {0}{0}ᶜ := by
  rw [← succAbove_zero]; exact range_succAbove (0 : Fin (n + 1))
Range of Successor Function on $\mathrm{Fin}(n)$ is $\mathrm{Fin}(n+1) \setminus \{0\}$
Informal description
For any natural number $n$, the range of the successor function $\mathrm{succ} : \mathrm{Fin}(n) \to \mathrm{Fin}(n+1)$ is the complement of the singleton set $\{0\}$. In other words, the successor function maps $\mathrm{Fin}(n)$ bijectively onto $\mathrm{Fin}(n+1) \setminus \{0\}$.
Fin.succAbove_left_injective theorem
: Injective (@succAbove n)
Full source
/-- `succAbove` is injective at the pivot -/
lemma succAbove_left_injective : Injective (@succAbove n) := fun _ _ h => by
  simpa [range_succAbove] using congr_arg (fun f : Fin n → Fin (n + 1) => (Set.range f)ᶜ) h
Injectivity of $\mathrm{succAbove}$ in Finite Types
Informal description
For any natural number $n$, the function $\mathrm{succAbove} : \mathrm{Fin}(n+1) \to (\mathrm{Fin} n \to \mathrm{Fin}(n+1))$ is injective. In other words, if $\mathrm{succAbove}(p_1) = \mathrm{succAbove}(p_2)$ for $p_1, p_2 \in \mathrm{Fin}(n+1)$, then $p_1 = p_2$.
Fin.succAbove_left_inj theorem
{x y : Fin (n + 1)} : x.succAbove = y.succAbove ↔ x = y
Full source
/-- `succAbove` is injective at the pivot -/
@[simp] lemma succAbove_left_inj {x y : Fin (n + 1)} : x.succAbove = y.succAbove ↔ x = y :=
  succAbove_left_injective.eq_iff
Injectivity of $\mathrm{succAbove}$ at the pivot: $x.\mathrm{succAbove} = y.\mathrm{succAbove} \leftrightarrow x = y$
Informal description
For any natural number $n$ and any two elements $x, y \in \mathrm{Fin}(n+1)$, the embeddings $\mathrm{succAbove}(x)$ and $\mathrm{succAbove}(y)$ are equal if and only if $x = y$.
Fin.zero_succAbove theorem
{n : ℕ} (i : Fin n) : (0 : Fin (n + 1)).succAbove i = i.succ
Full source
@[simp] lemma zero_succAbove {n : } (i : Fin n) : (0 : Fin (n + 1)).succAbove i = i.succ := rfl
Embedding at Zero Maps to Successor in Finite Types
Informal description
For any natural number $n$ and any element $i$ of the finite type $\text{Fin } n$, the embedding $\text{succAbove}$ at position $0$ in $\text{Fin } (n + 1)$ maps $i$ to the successor of $i$, i.e., $(0 : \text{Fin } (n + 1)).\text{succAbove } i = i.\text{succ}$.
Fin.succ_succAbove_zero theorem
{n : ℕ} [NeZero n] (i : Fin n) : succAbove i.succ 0 = 0
Full source
lemma succ_succAbove_zero {n : } [NeZero n] (i : Fin n) : succAbove i.succ 0 = 0 := by simp
Preservation of Zero under Successor-Embedding in Finite Types
Informal description
For any positive natural number $n$ (i.e., $n \neq 0$) and any element $i \in \text{Fin}(n)$, the embedding $\text{succAbove}$ applied to the successor of $i$ maps the zero element of $\text{Fin}(n)$ to the zero element of $\text{Fin}(n+1)$. That is, $\text{succAbove}(i.\text{succ}, 0) = 0$.
Fin.succ_succAbove_succ theorem
{n : ℕ} (i : Fin (n + 1)) (j : Fin n) : i.succ.succAbove j.succ = (i.succAbove j).succ
Full source
/-- `succ` commutes with `succAbove`. -/
@[simp] lemma succ_succAbove_succ {n : } (i : Fin (n + 1)) (j : Fin n) :
    i.succ.succAbove j.succ = (i.succAbove j).succ := by
  obtain h | h := i.lt_or_le (succ j)
  · rw [succAbove_of_lt_succ _ _ h, succAbove_succ_of_lt _ _ h]
  · rwa [succAbove_of_castSucc_lt _ _ h, succAbove_succ_of_le, succ_castSucc]
Commutation of Successor and $\text{succAbove}$ in Finite Types
Informal description
For any natural number $n$, elements $i \in \text{Fin}(n+1)$, and $j \in \text{Fin}(n)$, the following equality holds: \[ \text{succAbove}(i.\text{succ}, j.\text{succ}) = (\text{succAbove}(i, j)).\text{succ} \] Here, $\text{succAbove}$ is the embedding of $\text{Fin}(n)$ into $\text{Fin}(n+1)$ with a "hole" at the given position, and $\text{succ}$ is the successor operation on finite types.
Fin.castSucc_succAbove_castSucc theorem
{n : ℕ} {i : Fin (n + 1)} {j : Fin n} : i.castSucc.succAbove j.castSucc = (i.succAbove j).castSucc
Full source
/-- `castSucc` commutes with `succAbove`. -/
@[simp]
lemma castSucc_succAbove_castSucc {n : } {i : Fin (n + 1)} {j : Fin n} :
    i.castSucc.succAbove j.castSucc = (i.succAbove j).castSucc := by
  rcases i.le_or_lt (castSucc j) with (h | h)
  · rw [succAbove_of_le_castSucc _ _ h, succAbove_castSucc_of_le _ _ h, succ_castSucc]
  · rw [succAbove_of_castSucc_lt _ _ h, succAbove_castSucc_of_lt _ _ h]
Commutativity of $\text{castSucc}$ and $\text{succAbove}$ in finite types
Informal description
For any natural number $n$, elements $i \in \text{Fin}(n+1)$ and $j \in \text{Fin}(n)$, the following equality holds: \[ \text{succAbove}(\text{castSucc}(i), \text{castSucc}(j)) = \text{castSucc}(\text{succAbove}(i, j)) \] Here, $\text{castSucc}$ embeds an element of $\text{Fin}(k)$ into $\text{Fin}(k+1)$, and $\text{succAbove}(p, i)$ embeds $i \in \text{Fin}(n)$ into $\text{Fin}(n+1)$ with a "hole" at position $p$.
Fin.one_succAbove_zero theorem
{n : ℕ} : (1 : Fin (n + 2)).succAbove 0 = 0
Full source
lemma one_succAbove_zero {n : } : (1 : Fin (n + 2)).succAbove 0 = 0 := by
  rfl
Embedding of Zero via `succAbove` at Position One in Finite Types
Informal description
For any natural number $n$, the embedding of $0 \in \mathrm{Fin}(n+1)$ via $\mathrm{succAbove}$ at position $1 \in \mathrm{Fin}(n+2)$ equals $0 \in \mathrm{Fin}(n+2)$. In other words, $(1 : \mathrm{Fin}(n+2)).\mathrm{succAbove}\ 0 = 0$.
Fin.succ_succAbove_one theorem
{n : ℕ} [NeZero n] (i : Fin (n + 1)) : i.succ.succAbove 1 = (i.succAbove 0).succ
Full source
/-- By moving `succ` to the outside of this expression, we create opportunities for further
simplification using `succAbove_zero` or `succ_succAbove_zero`. -/
@[simp] lemma succ_succAbove_one {n : } [NeZero n] (i : Fin (n + 1)) :
    i.succ.succAbove 1 = (i.succAbove 0).succ := by
  rw [← succ_zero_eq_one']; convert succ_succAbove_succ i 0
Commutation of Successor and $\text{succAbove}$ at One in Finite Types
Informal description
For any positive natural number $n$ (i.e., when `[NeZero n]` holds) and any element $i \in \text{Fin}(n+1)$, the following equality holds: \[ \text{succAbove}(i.\text{succ}, 1) = (\text{succAbove}(i, 0)).\text{succ} \] Here, $\text{succAbove}$ is the embedding of $\text{Fin}(n)$ into $\text{Fin}(n+1)$ with a "hole" at the given position, and $\text{succ}$ is the successor operation on finite types.
Fin.one_succAbove_succ theorem
{n : ℕ} (j : Fin n) : (1 : Fin (n + 2)).succAbove j.succ = j.succ.succ
Full source
@[simp] lemma one_succAbove_succ {n : } (j : Fin n) :
    (1 : Fin (n + 2)).succAbove j.succ = j.succ.succ := by
  have := succ_succAbove_succ 0 j; rwa [succ_zero_eq_one, zero_succAbove] at this
Double Successor via $\text{succAbove}$ at Position One in Finite Types
Informal description
For any natural number $n$ and any element $j \in \text{Fin}(n)$, the embedding $\text{succAbove}$ at position $1$ in $\text{Fin}(n+2)$ maps the successor of $j$ to the double successor of $j$, i.e., \[ (1 : \text{Fin}(n+2)).\text{succAbove}(j.\text{succ}) = j.\text{succ}.\text{succ}. \]
Fin.one_succAbove_one theorem
{n : ℕ} : (1 : Fin (n + 3)).succAbove 1 = 2
Full source
@[simp] lemma one_succAbove_one {n : } : (1 : Fin (n + 3)).succAbove 1 = 2 := by
  simpa only [succ_zero_eq_one, val_zero, zero_succAbove, succ_one_eq_two]
    using succ_succAbove_succ (0 : Fin (n + 2)) (0 : Fin (n + 2))
Embedding of One in $\mathrm{Fin}(n+3)$ via $\mathrm{succAbove}$ at One Yields Two
Informal description
For any natural number $n$, the embedding of the element $1$ in $\mathrm{Fin}(n+3)$ via the $\mathrm{succAbove}$ operation at position $1$ results in the element $2$, i.e., $\mathrm{succAbove}(1, 1) = 2$ in $\mathrm{Fin}(n+3)$.
Fin.predAbove definition
(p : Fin n) (i : Fin (n + 1)) : Fin n
Full source
/-- `predAbove p i` surjects `i : Fin (n+1)` into `Fin n` by subtracting one if `p < i`. -/
def predAbove (p : Fin n) (i : Fin (n + 1)) : Fin n :=
  if h : castSucc p < i
  then pred i (Fin.ne_zero_of_lt h)
  else castPred i (Fin.ne_of_lt <| Fin.lt_of_le_of_lt (Fin.not_lt.1 h) (castSucc_lt_last _))
Predecessor above a given element in finite types
Informal description
The function `predAbove` takes an element `p` of `Fin n` (the type of natural numbers less than `n`) and an element `i` of `Fin (n + 1)`, and returns an element of `Fin n`. If `p` is less than `i` (when both are viewed as natural numbers), then the result is `i - 1` (ensuring the result is still in `Fin n`). Otherwise, the result is `i` itself (cast down to `Fin n`). More precisely, for `p : Fin n` and `i : Fin (n + 1)`: - If `p < i`, then `predAbove p i = i - 1` - Otherwise, `predAbove p i = i` (as an element of `Fin n`)
Fin.predAbove_succ_of_le theorem
(p i : Fin n) (h : p ≤ i) : p.predAbove (succ i) = i
Full source
lemma predAbove_succ_of_le (p i : Fin n) (h : p ≤ i) : p.predAbove (succ i) = i := by
  rw [predAbove_of_succ_le _ _ (succ_le_succ_iff.mpr h), pred_succ]
Predecessor Above Successor for Ordered Elements in Finite Types
Informal description
For any elements $p$ and $i$ in $\text{Fin}\,n$ (the type of natural numbers less than $n$) such that $p \leq i$, the predecessor above $p$ of the successor of $i$ equals $i$, i.e., $\text{predAbove}\,p\,(\text{succ}\,i) = i$.
Fin.predAbove_succ_self theorem
(p : Fin n) : p.predAbove (succ p) = p
Full source
@[simp] lemma predAbove_succ_self (p : Fin n) : p.predAbove (succ p) = p :=
  predAbove_succ_of_le _ _ Fin.le_rfl
Predecessor Above Successor Identity in Finite Types
Informal description
For any element $p$ in $\text{Fin}\,n$ (the type of natural numbers less than $n$), the predecessor above $p$ of the successor of $p$ equals $p$, i.e., $\text{predAbove}\,p\,(\text{succ}\,p) = p$.
Fin.predAbove_castSucc_of_le theorem
(p i : Fin n) (h : i ≤ p) : p.predAbove (castSucc i) = i
Full source
lemma predAbove_castSucc_of_le (p i : Fin n) (h : i ≤ p) : p.predAbove (castSucc i) = i := by
  rw [predAbove_of_le_castSucc _ _ (castSucc_le_castSucc_iff.mpr h), castPred_castSucc]
Predecessor Above Cast Successor for Ordered Elements in Finite Types
Informal description
For any elements $p$ and $i$ in $\text{Fin}\,n$ (the type of natural numbers less than $n$) such that $i \leq p$, the predecessor above $p$ of the cast successor of $i$ equals $i$, i.e., $\text{predAbove}\,p\,(\text{castSucc}\,i) = i$.
Fin.predAbove_castSucc_self theorem
(p : Fin n) : p.predAbove (castSucc p) = p
Full source
@[simp] lemma predAbove_castSucc_self (p : Fin n) : p.predAbove (castSucc p) = p :=
  predAbove_castSucc_of_le _ _ Fin.le_rfl
Predecessor Above Cast Successor Identity in Finite Types
Informal description
For any element $p$ in $\text{Fin}\,n$ (the type of natural numbers less than $n$), the predecessor above $p$ of the cast successor of $p$ equals $p$, i.e., $\text{predAbove}\,p\,(\text{castSucc}\,p) = p$.
Fin.predAbove_pred_self theorem
(p : Fin (n + 1)) (hp : p ≠ 0) : (pred p hp).predAbove p = pred p hp
Full source
lemma predAbove_pred_self (p : Fin (n + 1)) (hp : p ≠ 0) : (pred p hp).predAbove p = pred p hp :=
  predAbove_pred_of_le _ _ Fin.le_rfl hp
Predecessor Above Pred Identity in $\mathrm{Fin}(n+1)$
Informal description
For any element $p$ in $\mathrm{Fin}(n+1)$ (the type of natural numbers less than $n+1$) such that $p \neq 0$, the predecessor above $\mathrm{pred}(p)$ of $p$ equals $\mathrm{pred}(p)$, i.e., $(\mathrm{pred}\,p).\mathrm{predAbove}\,p = \mathrm{pred}\,p$.
Fin.predAbove_castPred_self theorem
(p : Fin (n + 1)) (hp : p ≠ last n) : (castPred p hp).predAbove p = castPred p hp
Full source
lemma predAbove_castPred_self (p : Fin (n + 1)) (hp : p ≠ last n) :
    (castPred p hp).predAbove p = castPred p hp := predAbove_castPred_of_le _ _ Fin.le_rfl hp
Predecessor Above Cast Pred Identity in $\mathrm{Fin}(n+1)$
Informal description
For any element $p$ in $\mathrm{Fin}(n+1)$ (the type of natural numbers less than $n+1$) such that $p \neq \mathrm{last}(n)$, the predecessor above $\mathrm{castPred}(p)$ of $p$ equals $\mathrm{castPred}(p)$, i.e., $(\mathrm{castPred}\,p).\mathrm{predAbove}\,p = \mathrm{castPred}\,p$.
Fin.predAbove_right_zero theorem
[NeZero n] {i : Fin n} : predAbove (i : Fin n) 0 = 0
Full source
@[simp] lemma predAbove_right_zero [NeZero n] {i : Fin n} : predAbove (i : Fin n) 0 = 0 := by
  cases n
  · exact i.elim0
  · rw [predAbove_of_le_castSucc _ _ (zero_le _), castPred_zero]
Predecessor Above Zero is Zero in Finite Types
Informal description
For any non-zero natural number `n` and any element `i` of the finite type `Fin n`, the predecessor above `i` of the zero element in `Fin (n + 1)` is equal to zero in `Fin n`. That is, for `i : Fin n`, we have `predAbove i 0 = 0`.
Fin.predAbove_zero_succ theorem
[NeZero n] {i : Fin n} : predAbove 0 i.succ = i
Full source
lemma predAbove_zero_succ [NeZero n] {i : Fin n} : predAbove 0 i.succ = i := by
  rw [predAbove_succ_of_le _ _ (Fin.zero_le' _)]
Predecessor Above Zero of Successor in Finite Types
Informal description
For any nonzero natural number $n$ and any element $i$ in the finite type $\mathrm{Fin}\,n$ (natural numbers less than $n$), the predecessor above $0$ of the successor of $i$ equals $i$, i.e., $\mathrm{predAbove}\,0\,(\mathrm{succ}\,i) = i$.
Fin.succ_predAbove_zero theorem
[NeZero n] {j : Fin (n + 1)} (h : j ≠ 0) : succ (predAbove 0 j) = j
Full source
@[simp]
lemma succ_predAbove_zero [NeZero n] {j : Fin (n + 1)} (h : j ≠ 0) : succ (predAbove 0 j) = j := by
  rcases exists_succ_eq_of_ne_zero h with ⟨k, rfl⟩
  rw [predAbove_zero_succ]
Successor of Predecessor Above Zero in Finite Types: $\mathrm{succ}(\mathrm{predAbove}\,0\,j) = j$ for $j \neq 0$
Informal description
For any nonzero natural number $n$ and any element $j$ in $\mathrm{Fin}(n+1)$ such that $j \neq 0$, the successor of the predecessor above $0$ of $j$ equals $j$, i.e., $\mathrm{succ}(\mathrm{predAbove}\,0\,j) = j$.
Fin.predAbove_zero_of_ne_zero theorem
[NeZero n] {i : Fin (n + 1)} (hi : i ≠ 0) : predAbove 0 i = i.pred hi
Full source
@[simp] lemma predAbove_zero_of_ne_zero [NeZero n] {i : Fin (n + 1)} (hi : i ≠ 0) :
    predAbove 0 i = i.pred hi := by
  obtain ⟨y, rfl⟩ := exists_succ_eq.2 hi; exact predAbove_zero_succ
Predecessor Above Zero Equals Predecessor for Nonzero Elements in Finite Types
Informal description
For any nonzero natural number $n$ and any element $i$ in $\mathrm{Fin}(n+1)$ such that $i \neq 0$, the predecessor above $0$ of $i$ equals the predecessor of $i$ (with respect to the proof that $i \neq 0$), i.e., $\mathrm{predAbove}\,0\,i = \mathrm{pred}\,i$.
Fin.predAbove_zero theorem
[NeZero n] {i : Fin (n + 1)} : predAbove (0 : Fin n) i = if hi : i = 0 then 0 else i.pred hi
Full source
lemma predAbove_zero [NeZero n] {i : Fin (n + 1)} :
    predAbove (0 : Fin n) i = if hi : i = 0 then 0 else i.pred hi := by
  split_ifs with hi
  · rw [hi, predAbove_right_zero]
  · rw [predAbove_zero_of_ne_zero hi]
Predecessor Above Zero in Finite Types: Case Analysis on Zero
Informal description
For any nonzero natural number $n$ and any element $i$ in $\mathrm{Fin}(n+1)$, the predecessor above $0$ of $i$ equals $0$ if $i = 0$, and equals the predecessor of $i$ otherwise. That is: \[ \mathrm{predAbove}\,0\,i = \begin{cases} 0 & \text{if } i = 0 \\ \mathrm{pred}\,i & \text{otherwise} \end{cases} \]
Fin.predAbove_right_last theorem
{i : Fin (n + 1)} : predAbove i (last (n + 1)) = last n
Full source
@[simp] lemma predAbove_right_last {i : Fin (n + 1)} : predAbove i (last (n + 1)) = last n := by
  rw [predAbove_of_castSucc_lt _ _ (castSucc_lt_last _), pred_last]
Predecessor Above Last Element Yields Last Element in Smaller Finite Type
Informal description
For any element $i$ in the finite type $\mathrm{Fin}(n+1)$, the predecessor above $i$ of the last element in $\mathrm{Fin}(n+2)$ is equal to the last element in $\mathrm{Fin}(n)$. In other words, $\mathrm{predAbove}\, i\, (\mathrm{last}\, (n+1)) = \mathrm{last}\, n$.
Fin.predAbove_last_castSucc theorem
{i : Fin (n + 1)} : predAbove (last n) (i.castSucc) = i
Full source
lemma predAbove_last_castSucc {i : Fin (n + 1)} : predAbove (last n) (i.castSucc) = i := by
  rw [predAbove_of_le_castSucc _ _ (castSucc_le_castSucc_iff.mpr (le_last _)), castPred_castSucc]
Predecessor Above Last Element Preserves Cast Successor in Finite Types
Informal description
For any element $i$ in the finite type $\mathrm{Fin}(n+1)$, the predecessor above the last element of $\mathrm{Fin}(n)$ applied to the cast successor of $i$ is equal to $i$ itself. That is, $\mathrm{predAbove}\, (\mathrm{last}\, n)\, (i.\mathrm{castSucc}) = i$.
Fin.predAbove_last_of_ne_last theorem
{i : Fin (n + 2)} (hi : i ≠ last (n + 1)) : predAbove (last n) i = castPred i hi
Full source
@[simp] lemma predAbove_last_of_ne_last {i : Fin (n + 2)} (hi : i ≠ last (n + 1)) :
    predAbove (last n) i = castPred i hi := by
  rw [← exists_castSucc_eq] at hi
  rcases hi with ⟨y, rfl⟩
  exact predAbove_last_castSucc
Predecessor Above Last Element Equals Cast Predecessor for Non-Last Elements
Informal description
For any element $i$ in the finite type $\mathrm{Fin}(n+2)$ such that $i$ is not the last element, the predecessor above the last element of $\mathrm{Fin}(n)$ applied to $i$ is equal to the cast predecessor of $i$. That is, $\mathrm{predAbove}\, (\mathrm{last}\, n)\, i = \mathrm{castPred}\, i\, \mathrm{hi}$.
Fin.predAbove_last_apply theorem
{i : Fin (n + 2)} : predAbove (last n) i = if hi : i = last _ then last _ else i.castPred hi
Full source
lemma predAbove_last_apply {i : Fin (n + 2)} :
    predAbove (last n) i = if hi : i = last _ then last _ else i.castPred hi := by
  split_ifs with hi
  · rw [hi, predAbove_right_last]
  · rw [predAbove_last_of_ne_last hi]
Predecessor Above Last Element in Finite Types: Case Analysis on Last Element
Informal description
For any element $i$ in the finite type $\mathrm{Fin}(n+2)$, the predecessor above the last element of $\mathrm{Fin}(n)$ applied to $i$ is equal to the last element of $\mathrm{Fin}(n)$ if $i$ is the last element of $\mathrm{Fin}(n+2)$, and otherwise equals the cast predecessor of $i$. That is, $$\mathrm{predAbove}\, (\mathrm{last}\, n)\, i = \begin{cases} \mathrm{last}\, n & \text{if } i = \mathrm{last}\, (n+1) \\ i.\mathrm{castPred}\, \mathrm{hi} & \text{otherwise} \end{cases}$$ where $\mathrm{hi}$ is the proof that $i \neq \mathrm{last}\, (n+1)$.
Fin.succAbove_predAbove theorem
{p : Fin n} {i : Fin (n + 1)} (h : i ≠ castSucc p) : p.castSucc.succAbove (p.predAbove i) = i
Full source
/-- Sending `Fin (n+1)` to `Fin n` by subtracting one from anything above `p`
then back to `Fin (n+1)` with a gap around `p` is the identity away from `p`. -/
@[simp]
lemma succAbove_predAbove {p : Fin n} {i : Fin (n + 1)} (h : i ≠ castSucc p) :
    p.castSucc.succAbove (p.predAbove i) = i := by
  obtain h | h := Fin.lt_or_lt_of_ne h
  · rw [predAbove_of_le_castSucc _ _ (Fin.le_of_lt h), succAbove_castPred_of_lt _ _ h]
  · rw [predAbove_of_castSucc_lt _ _ h, succAbove_pred_of_lt _ _ h]
Inverse Property of $\mathrm{succAbove}$ and $\mathrm{predAbove}$ in Finite Types
Informal description
For any natural number $n$, element $p \in \mathrm{Fin}\,n$, and element $i \in \mathrm{Fin}(n+1)$ such that $i \neq \mathrm{castSucc}\,p$, the composition of the $\mathrm{succAbove}$ and $\mathrm{predAbove}$ operations satisfies: $$(\mathrm{castSucc}\,p).\mathrm{succAbove}(p.\mathrm{predAbove}\,i) = i$$
Fin.succ_succAbove_predAbove theorem
{n : ℕ} {p : Fin n} {i : Fin (n + 1)} (h : i ≠ p.succ) : p.succ.succAbove (p.predAbove i) = i
Full source
/-- Sending `Fin (n+1)` to `Fin n` by subtracting one from anything above `p`
then back to `Fin (n+1)` with a gap around `p.succ` is the identity away from `p.succ`. -/
@[simp]
lemma succ_succAbove_predAbove {n : } {p : Fin n} {i : Fin (n + 1)} (h : i ≠ p.succ) :
    p.succ.succAbove (p.predAbove i) = i := by
  obtain h | h := Fin.lt_or_lt_of_ne h
  · rw [predAbove_of_le_castSucc _ _ (le_castSucc_iff.2 h),
      succAbove_castPred_of_lt _ _ h]
  · rw [predAbove_of_castSucc_lt _ _ (Fin.lt_of_le_of_lt (p.castSucc_le_succ) h),
      succAbove_pred_of_lt _ _ h]
Inverse Property of Successor-Predecessor Operations in Finite Types
Informal description
For any natural number $n$, element $p \in \mathrm{Fin}\,n$, and element $i \in \mathrm{Fin}(n+1)$ such that $i \neq p.\mathrm{succ}$, the composition of $\mathrm{succAbove}$ and $\mathrm{predAbove}$ operations satisfies: $$p.\mathrm{succ}.\mathrm{succAbove}(p.\mathrm{predAbove}(i)) = i$$
Fin.predAbove_succAbove theorem
(p : Fin n) (i : Fin n) : p.predAbove ((castSucc p).succAbove i) = i
Full source
/-- Sending `Fin n` into `Fin (n + 1)` with a gap at `p`
then back to `Fin n` by subtracting one from anything above `p` is the identity. -/
@[simp]
lemma predAbove_succAbove (p : Fin n) (i : Fin n) : p.predAbove ((castSucc p).succAbove i) = i := by
  obtain h | h := p.le_or_lt i
  · rw [succAbove_castSucc_of_le _ _ h, predAbove_succ_of_le _ _ h]
  · rw [succAbove_castSucc_of_lt _ _ h, predAbove_castSucc_of_le _ _ <| Fin.le_of_lt h]
Inverse Property of $\mathrm{predAbove}$ and $\mathrm{succAbove}$ in Finite Types
Informal description
For any natural number $n$ and elements $p, i \in \mathrm{Fin}\,n$ (the type of natural numbers less than $n$), the composition of the operations $\mathrm{predAbove}$ and $\mathrm{succAbove}$ satisfies: $$p.\mathrm{predAbove}((\mathrm{castSucc}\,p).\mathrm{succAbove}\,i) = i$$ where: - $\mathrm{castSucc}$ is the canonical embedding $\mathrm{Fin}(n) \hookrightarrow \mathrm{Fin}(n+1)$ - $\mathrm{succAbove}\,p\,i$ embeds $i$ into $\mathrm{Fin}(n+1)$ with a gap at $p$ - $\mathrm{predAbove}\,p\,i$ maps $i \in \mathrm{Fin}(n+1)$ back to $\mathrm{Fin}(n)$ by subtracting one from elements above $p$
Fin.succ_predAbove_succ theorem
(a : Fin n) (b : Fin (n + 1)) : a.succ.predAbove b.succ = (a.predAbove b).succ
Full source
/-- `succ` commutes with `predAbove`. -/
@[simp] lemma succ_predAbove_succ (a : Fin n) (b : Fin (n + 1)) :
    a.succ.predAbove b.succ = (a.predAbove b).succ := by
  obtain h | h := Fin.le_or_lt (succ a) b
  · rw [predAbove_of_castSucc_lt _ _ h, predAbove_succ_of_le _ _ h, succ_pred]
  · rw [predAbove_of_lt_succ _ _ h, predAbove_succ_of_lt _ _ h, succ_castPred_eq_castPred_succ]
Commutation of successor with predAbove in finite types: $\mathrm{predAbove}(a.\mathrm{succ}, b.\mathrm{succ}) = (\mathrm{predAbove}(a, b)).\mathrm{succ}$
Informal description
For any natural number $n$, elements $a \in \mathrm{Fin}(n)$ and $b \in \mathrm{Fin}(n+1)$, the following equality holds: $$\mathrm{predAbove}(a.\mathrm{succ}, b.\mathrm{succ}) = (\mathrm{predAbove}(a, b)).\mathrm{succ}$$ where: - $\mathrm{Fin}(k)$ denotes the finite type with $k$ elements (natural numbers less than $k$) - $\mathrm{succ}$ is the successor operation on $\mathrm{Fin}(k)$ - $\mathrm{predAbove}(p,i)$ is the predecessor function that returns $i-1$ if $p < i$ (as natural numbers), otherwise returns $i$ (as an element of $\mathrm{Fin}(n)$)
Fin.castSucc_predAbove_castSucc theorem
{n : ℕ} (a : Fin n) (b : Fin (n + 1)) : a.castSucc.predAbove b.castSucc = (a.predAbove b).castSucc
Full source
/-- `castSucc` commutes with `predAbove`. -/
@[simp] lemma castSucc_predAbove_castSucc {n : } (a : Fin n) (b : Fin (n + 1)) :
    a.castSucc.predAbove b.castSucc = (a.predAbove b).castSucc := by
  obtain h | h := a.castSucc.lt_or_le b
  · rw [predAbove_of_castSucc_lt _ _ h, predAbove_castSucc_of_lt _ _ h,
      castSucc_pred_eq_pred_castSucc]
  · rw [predAbove_of_le_castSucc _ _ h, predAbove_castSucc_of_le _ _ h, castSucc_castPred]
Commutation of $\mathrm{castSucc}$ with $\mathrm{predAbove}$ in finite types
Informal description
For any natural number $n$ and elements $a \in \mathrm{Fin}(n)$, $b \in \mathrm{Fin}(n+1)$, the following equality holds: $$\mathrm{predAbove}(\mathrm{castSucc}(a), \mathrm{castSucc}(b)) = \mathrm{castSucc}(\mathrm{predAbove}(a, b))$$ where: - $\mathrm{Fin}(n)$ denotes the finite type with $n$ elements (natural numbers less than $n$) - $\mathrm{castSucc}$ is the canonical embedding $\mathrm{Fin}(k) \hookrightarrow \mathrm{Fin}(k+1)$ - $\mathrm{predAbove}(p,i)$ is the predecessor function that returns $i-1$ if $p < i$ (as natural numbers), otherwise returns $i$ (as an element of $\mathrm{Fin}(n)$)
Fin.divNat definition
(i : Fin (m * n)) : Fin m
Full source
/-- Compute `i / n`, where `n` is a `Nat` and inferred the type of `i`. -/
def divNat (i : Fin (m * n)) : Fin m :=
  ⟨i / n, Nat.div_lt_of_lt_mul <| Nat.mul_comm m n ▸ i.prop⟩
Division in finite types
Informal description
For a natural number `n` and an element `i` of the finite type `Fin (m * n)`, the function `Fin.divNat` computes the quotient of `i` divided by `n`, returning an element of `Fin m`.
Fin.coe_divNat theorem
(i : Fin (m * n)) : (i.divNat : ℕ) = i / n
Full source
@[simp]
theorem coe_divNat (i : Fin (m * n)) : (i.divNat : ) = i / n :=
  rfl
Coercion of Division in Finite Types: $\text{divNat}(i) = \lfloor i / n \rfloor$
Informal description
For any natural numbers $m$ and $n$, and any element $i$ of the finite type $\text{Fin}(m \cdot n)$, the natural number obtained by coercing the result of $\text{divNat}(i)$ equals the integer division of $i$ by $n$, i.e., $\text{divNat}(i) = \lfloor i / n \rfloor$.
Fin.modNat definition
(i : Fin (m * n)) : Fin n
Full source
/-- Compute `i % n`, where `n` is a `Nat` and inferred the type of `i`. -/
def modNat (i : Fin (m * n)) : Fin n := ⟨i % n, Nat.mod_lt _ <| Nat.pos_of_mul_pos_left i.pos⟩
Modulo operation on finite types
Informal description
For a natural number `n` and an element `i` of the finite type `Fin (m * n)`, the function `Fin.modNat` computes the remainder of `i` modulo `n`, returning an element of `Fin n`.
Fin.coe_modNat theorem
(i : Fin (m * n)) : (i.modNat : ℕ) = i % n
Full source
@[simp]
theorem coe_modNat (i : Fin (m * n)) : (i.modNat : ) = i % n :=
  rfl
Modulo Operation Preserved Under Coercion: $\text{modNat}(i) = i \% n$
Informal description
For any natural numbers $m$ and $n$, and any element $i$ of the finite type $\text{Fin}(m \cdot n)$, the natural number obtained by coercing the result of $\text{modNat}(i)$ equals the remainder of $i$ modulo $n$, i.e., $\text{modNat}(i) = i \% n$.
Fin.modNat_rev theorem
(i : Fin (m * n)) : i.rev.modNat = i.modNat.rev
Full source
theorem modNat_rev (i : Fin (m * n)) : i.rev.modNat = i.modNat.rev := by
  ext
  have H₁ : i % n + 1 ≤ n := i.modNat.is_lt
  have H₂ : i / n < m := i.divNat.is_lt
  simp only [coe_modNat, val_rev]
  calc
    (m * n - (i + 1)) % n = (m * n - ((i / n) * n + i % n + 1)) % n := by rw [Nat.div_add_mod']
    _ = ((m - i / n - 1) * n + (n - (i % n + 1))) % n := by
      rw [Nat.mul_sub_right_distrib, Nat.one_mul, Nat.sub_add_sub_cancel _ H₁,
        Nat.mul_sub_right_distrib, Nat.sub_sub, Nat.add_assoc]
      exact Nat.le_mul_of_pos_left _ <| Nat.le_sub_of_add_le' H₂
    _ = n - (i % n + 1) := by
      rw [Nat.mul_comm, Nat.mul_add_mod, Nat.mod_eq_of_lt]; exact i.modNat.rev.is_lt
Order-Reversing Property of Modulo Operation on Finite Types
Informal description
For any natural numbers $m, n$ and any element $i$ of the finite type $\mathrm{Fin}(m \cdot n)$, the modulo operation satisfies $\mathrm{modNat}(i^{\mathrm{rev}}) = (\mathrm{modNat}(i))^{\mathrm{rev}}$, where $(\cdot)^{\mathrm{rev}}$ denotes the order-reversing operation on $\mathrm{Fin}(k)$ for any $k$.
Fin.liftFun_iff_succ theorem
{α : Type*} (r : α → α → Prop) [IsTrans α r] {f : Fin (n + 1) → α} : ((· < ·) ⇒ r) f f ↔ ∀ i : Fin n, r (f (castSucc i)) (f i.succ)
Full source
theorem liftFun_iff_succ {α : Type*} (r : α → α → Prop) [IsTrans α r] {f : Fin (n + 1) → α} :
    ((· < ·) ⇒ r) f f ↔ ∀ i : Fin n, r (f (castSucc i)) (f i.succ) := by
  constructor
  · intro H i
    exact H i.castSucc_lt_succ
  · refine fun H i => Fin.induction (fun h ↦ ?_) ?_
    · simp [le_def] at h
    · intro j ihj hij
      rw [← le_castSucc_iff] at hij
      obtain hij | hij := (le_def.1 hij).eq_or_lt
      · obtain rfl := Fin.ext hij
        exact H _
      · exact _root_.trans (ihj hij) (H j)
Monotonicity Criterion for Functions on $\text{Fin}(n+1)$ via Successor Condition
Informal description
Let $\alpha$ be a type equipped with a transitive relation $r : \alpha \to \alpha \to \text{Prop}$, and let $f : \text{Fin}(n+1) \to \alpha$ be a function. Then the following are equivalent: 1. The function $f$ is monotonic with respect to the strict order $<$ on $\text{Fin}(n+1)$ and the relation $r$ on $\alpha$, i.e., for any $i, j \in \text{Fin}(n+1)$, $i < j$ implies $r(f(i), f(j))$. 2. For every $i \in \text{Fin}(n)$, we have $r(f(\text{castSucc}(i)), f(i.\text{succ}))$, where $\text{castSucc}(i)$ is the embedding of $i$ into $\text{Fin}(n+1)$ and $i.\text{succ}$ is the successor of $i$.
Fin.neg instance
(n : ℕ) : Neg (Fin n)
Full source
/-- Negation on `Fin n` -/
instance neg (n : ) : Neg (Fin n) :=
  ⟨fun a => ⟨(n - a) % n, Nat.mod_lt _ a.pos⟩⟩
Negation on Finite Types $\mathrm{Fin}(n)$
Informal description
For any natural number $n$, the type $\mathrm{Fin}(n)$ of natural numbers less than $n$ has a negation operation defined by $-a = \langle (n - a) \bmod n, \ldots \rangle$.
Fin.neg_def theorem
(a : Fin n) : -a = ⟨(n - a) % n, Nat.mod_lt _ a.pos⟩
Full source
theorem neg_def (a : Fin n) : -a = ⟨(n - a) % n, Nat.mod_lt _ a.pos⟩ := rfl
Definition of Negation in $\mathrm{Fin}(n)$: $-a = \langle (n - a) \bmod n \rangle$
Informal description
For any element $a$ in $\mathrm{Fin}(n)$, the negation $-a$ is defined as the element $\langle (n - a) \bmod n \rangle$, where the proof that $(n - a) \bmod n < n$ follows from the fact that $a$ is positive (i.e., $a \neq 0$).
Fin.coe_neg theorem
(a : Fin n) : ((-a : Fin n) : ℕ) = (n - a) % n
Full source
protected theorem coe_neg (a : Fin n) : ((-a : Fin n) : ) = (n - a) % n :=
  rfl
Coercion of Negation in $\mathrm{Fin}(n)$: $(-a)_{\mathbb{N}} = (n - a) \bmod n$
Informal description
For any element $a$ in the finite type $\mathrm{Fin}(n)$, the natural number obtained by coercing $-a$ to $\mathbb{N}$ equals $(n - a) \bmod n$, i.e., $((-a : \mathrm{Fin}(n)) : \mathbb{N}) = (n - a) \bmod n$.
Fin.coe_neg_one theorem
: ↑(-1 : Fin (n + 1)) = n
Full source
@[simp]
theorem coe_neg_one : ↑(-1 : Fin (n + 1)) = n := by
  cases n
  · simp
  rw [Fin.coe_neg, Fin.val_one, Nat.add_one_sub_one, Nat.mod_eq_of_lt]
  constructor
Coercion of Negative One in $\mathrm{Fin}(n+1)$: $(-1)_\mathbb{N} = n$
Informal description
For any natural number $n$, the coercion of $-1$ in $\mathrm{Fin}(n+1)$ to $\mathbb{N}$ equals $n$, i.e., $(-1 : \mathrm{Fin}(n+1))_\mathbb{N} = n$.
Fin.last_sub theorem
(i : Fin (n + 1)) : last n - i = Fin.rev i
Full source
theorem last_sub (i : Fin (n + 1)) : last n - i = Fin.rev i :=
  Fin.ext <| by rw [coe_sub_iff_le.2 i.le_last, val_last, val_rev, Nat.succ_sub_succ_eq_sub]
Last Element Minus Equals Reverse in $\mathrm{Fin}(n+1)$
Informal description
For any element $i$ of the finite type $\mathrm{Fin}(n+1)$, the subtraction of $i$ from the last element $\mathrm{last}\,n$ equals the reverse of $i$, i.e., $\mathrm{last}\,n - i = \mathrm{rev}\,i$.
Fin.add_one_le_of_lt theorem
{n : ℕ} {a b : Fin (n + 1)} (h : a < b) : a + 1 ≤ b
Full source
theorem add_one_le_of_lt {n : } {a b : Fin (n + 1)} (h : a < b) : a + 1 ≤ b := by
  cases n <;> fin_omega
Successor Inequality in Finite Types: $a < b \Rightarrow a + 1 \leq b$
Informal description
For any natural number $n$ and elements $a, b$ in $\mathrm{Fin}(n+1)$, if $a < b$, then $a + 1 \leq b$.
Fin.exists_eq_add_of_le theorem
{n : ℕ} {a b : Fin n} (h : a ≤ b) : ∃ k ≤ b, b = a + k
Full source
theorem exists_eq_add_of_le {n : } {a b : Fin n} (h : a ≤ b) : ∃ k ≤ b, b = a + k := by
  obtain ⟨k, hk⟩ : ∃ k : ℕ, (b : ℕ) = a + k := Nat.exists_eq_add_of_le h
  have hkb : k ≤ b := by omega
  refine ⟨⟨k, hkb.trans_lt b.is_lt⟩, hkb, ?_⟩
  simp [Fin.ext_iff, Fin.val_add, ← hk, Nat.mod_eq_of_lt b.is_lt]
Decomposition of Order Relation in Finite Types via Addition
Informal description
For any natural number $n$ and any elements $a, b$ in $\text{Fin}\,n$ (the finite type with $n$ elements), if $a \leq b$, then there exists a natural number $k \leq b$ such that $b = a + k$.
Fin.exists_eq_add_of_lt theorem
{n : ℕ} {a b : Fin (n + 1)} (h : a < b) : ∃ k < b, k + 1 ≤ b ∧ b = a + k + 1
Full source
theorem exists_eq_add_of_lt {n : } {a b : Fin (n + 1)} (h : a < b) :
    ∃ k < b, k + 1 ≤ b ∧ b = a + k + 1 := by
  cases n
  · omega
  obtain ⟨k, hk⟩ : ∃ k : ℕ, (b : ℕ) = a + k + 1 := Nat.exists_eq_add_of_lt h
  have hkb : k < b := by omega
  refine ⟨⟨k, hkb.trans b.is_lt⟩, hkb, by fin_omega, ?_⟩
  simp [Fin.ext_iff, Fin.val_add, ← hk, Nat.mod_eq_of_lt b.is_lt]
Decomposition of Strict Order in Finite Types via Successor Addition
Informal description
For any natural number $n$ and elements $a, b$ in $\mathrm{Fin}(n+1)$, if $a < b$, then there exists an element $k < b$ such that $k + 1 \leq b$ and $b = a + k + 1$.
Fin.pos_of_ne_zero theorem
{n : ℕ} {a : Fin (n + 1)} (h : a ≠ 0) : 0 < a
Full source
lemma pos_of_ne_zero {n : } {a : Fin (n + 1)} (h : a ≠ 0) :
    0 < a :=
  Nat.pos_of_ne_zero (val_ne_of_ne h)
Nonzero Elements in $\mathrm{Fin}(n+1)$ are Positive
Informal description
For any natural number $n$ and any element $a$ of $\mathrm{Fin}(n+1)$ (the finite type with $n+1$ elements), if $a$ is not equal to $0$, then $0 < a$.
Fin.sub_succ_le_sub_of_le theorem
{n : ℕ} {u v : Fin (n + 2)} (h : u < v) : v - (u + 1) < v - u
Full source
lemma sub_succ_le_sub_of_le {n : } {u v : Fin (n + 2)} (h : u < v) : v - (u + 1) < v - u := by
  fin_omega
Decreasing Difference in Finite Types: $v - (u + 1) < v - u$ when $u < v$
Informal description
For any natural number $n$ and elements $u, v$ in $\mathrm{Fin}(n+2)$, if $u < v$, then the difference $v - (u + 1)$ is less than the difference $v - u$.
Fin.coe_natCast_eq_mod theorem
(m n : ℕ) [NeZero m] : ((n : Fin m) : ℕ) = n % m
Full source
@[simp]
theorem coe_natCast_eq_mod (m n : ) [NeZero m] :
    ((n : Fin m) : ) = n % m :=
  rfl
Coercion-Modulo Equality for Finite Types: $(n : \mathrm{Fin}\,m)_{\mathbb{N}} = n \bmod m$
Informal description
For any positive natural number $m$ and any natural number $n$, the canonical coercion of $n$ as an element of $\mathrm{Fin}\,m$ back to $\mathbb{N}$ equals $n$ modulo $m$, i.e., $(n : \mathrm{Fin}\,m)_{\mathbb{N}} = n \bmod m$.
Fin.coe_ofNat_eq_mod theorem
(m n : ℕ) [NeZero m] : ((ofNat(n) : Fin m) : ℕ) = ofNat(n) % m
Full source
theorem coe_ofNat_eq_mod (m n : ) [NeZero m] :
    ((ofNat(n) : Fin m) : ) = ofNat(n) % m :=
  rfl
Coercion of Natural Number Literal in Finite Type Equals Modulo Operation
Informal description
For any positive natural number $m$ (with `[NeZero m]`) and any natural number $n$, the canonical coercion of the term `ofNat(n)` (interpreted as an element of `Fin m`) to $\mathbb{N}$ is equal to `ofNat(n)` modulo $m$. In other words, $(\mathtt{ofNat}(n) : \mathtt{Fin}\ m)_{\mathbb{N}} = \mathtt{ofNat}(n) \mod m$.
Fin.mul_one' theorem
[NeZero n] (k : Fin n) : k * 1 = k
Full source
protected theorem mul_one' [NeZero n] (k : Fin n) : k * 1 = k := by
  rcases n with - | n
  · simp [eq_iff_true_of_subsingleton]
  cases n
  · simp [fin_one_eq_zero]
  simp [Fin.ext_iff, mul_def, mod_eq_of_lt (is_lt k)]
Right multiplicative identity in $\text{Fin}\ n$
Informal description
For any non-zero natural number $n$ and any element $k$ in $\text{Fin}\ n$ (the finite type with $n$ elements), the product of $k$ and the multiplicative identity $1$ in $\text{Fin}\ n$ equals $k$, i.e., $k \cdot 1 = k$.
Fin.one_mul' theorem
[NeZero n] (k : Fin n) : (1 : Fin n) * k = k
Full source
protected theorem one_mul' [NeZero n] (k : Fin n) : (1 : Fin n) * k = k := by
  rw [Fin.mul_comm, Fin.mul_one']
Left multiplicative identity in $\mathrm{Fin}\,n$: $1 \cdot k = k$
Informal description
For any non-zero natural number $n$ and any element $k$ in the finite type $\mathrm{Fin}\,n$ (the type of natural numbers less than $n$), the product of the multiplicative identity $1$ and $k$ equals $k$, i.e., $1 \cdot k = k$.
Fin.mul_zero' theorem
[NeZero n] (k : Fin n) : k * 0 = 0
Full source
protected theorem mul_zero' [NeZero n] (k : Fin n) : k * 0 = 0 := by simp [Fin.ext_iff, mul_def]
Right Multiplication by Zero in Finite Types: $k \cdot 0 = 0$
Informal description
For any nonzero natural number $n$ and any element $k$ in the finite type $\mathrm{Fin}\,n$, the product of $k$ and $0$ in $\mathrm{Fin}\,n$ equals $0$, i.e., $k \cdot 0 = 0$.
Fin.zero_mul' theorem
[NeZero n] (k : Fin n) : (0 : Fin n) * k = 0
Full source
protected theorem zero_mul' [NeZero n] (k : Fin n) : (0 : Fin n) * k = 0 := by
  simp [Fin.ext_iff, mul_def]
Zero Multiplication Identity in Finite Types: $0 \cdot k = 0$
Informal description
For any non-zero natural number $n$ and any element $k$ in the finite type $\mathrm{Fin}\,n$, the product of the zero element and $k$ is zero, i.e., $0 \cdot k = 0$.