doc-next-gen

Init.Data.Fin.Lemmas

Module docstring

{"### coercions and constructions ","### order ","### last ","### addition, numerals, and coercion from Nat ","### succ and casts into larger Fin types ","### pred ","### Recursion and induction principles ","### add ","### sub ","### mul "}

Fin.ofNat'_zero theorem
(n : Nat) [NeZero n] : Fin.ofNat' n 0 = 0
Full source
@[simp] theorem ofNat'_zero (n : Nat) [NeZero n] : Fin.ofNat' n 0 = 0 := rfl
Zero Mapping in Finite Type Construction
Informal description
For any natural number $n$ with $n \neq 0$, the function `Fin.ofNat'` maps the natural number $0$ to the zero element of `Fin n`, i.e., $\text{Fin.ofNat'}\ n\ 0 = 0$.
Fin.size_pos theorem
(i : Fin n) : 0 < n
Full source
@[deprecated Fin.pos (since := "2024-11-11")]
theorem size_pos (i : Fin n) : 0 < n := i.pos
Positivity of Finite Type Size
Informal description
For any element $i$ of the finite type $\text{Fin}\,n$, the size $n$ is strictly positive, i.e., $0 < n$.
Fin.mod_def theorem
(a m : Fin n) : a % m = Fin.mk (a % m) (Nat.lt_of_le_of_lt (Nat.mod_le _ _) a.2)
Full source
theorem mod_def (a m : Fin n) : a % m = Fin.mk (a % m) (Nat.lt_of_le_of_lt (Nat.mod_le _ _) a.2) :=
  rfl
Definition of Modulo Operation in Finite Types
Informal description
For any elements $a$ and $m$ in the finite type $\text{Fin}\,n$ (natural numbers less than $n$), the modulo operation $a \bmod m$ is defined as the element $\text{Fin.mk}\,(a \bmod m)$, where the modulo operation is performed on the underlying natural numbers, and the result is shown to be less than $n$ using the properties of the natural number modulo operation.
Fin.mul_def theorem
(a b : Fin n) : a * b = Fin.mk ((a * b) % n) (Nat.mod_lt _ a.pos)
Full source
theorem mul_def (a b : Fin n) : a * b = Fin.mk ((a * b) % n) (Nat.mod_lt _ a.pos) := rfl
Definition of Multiplication in Finite Types
Informal description
For any two elements $a$ and $b$ in the finite type $\text{Fin}\,n$ (natural numbers less than $n$), the product $a * b$ is equal to the element $\text{Fin.mk}\,((a * b) \mod n)$, where the modulo operation ensures the result remains within the bounds of $\text{Fin}\,n$.
Fin.sub_def theorem
(a b : Fin n) : a - b = Fin.mk (((n - b) + a) % n) (Nat.mod_lt _ a.pos)
Full source
theorem sub_def (a b : Fin n) : a - b = Fin.mk (((n - b) + a) % n) (Nat.mod_lt _ a.pos) := rfl
Definition of Subtraction in Finite Types
Informal description
For any two elements $a$ and $b$ in the finite type $\text{Fin }n$ (natural numbers less than $n$), the subtraction $a - b$ is defined as the element $\text{Fin.mk }(((n - b) + a) \mod n)$, where the modulo operation ensures the result remains within the bounds of $\text{Fin }n$.
Fin.pos' theorem
: ∀ [Nonempty (Fin n)], 0 < n
Full source
theorem pos' : ∀ [Nonempty (Fin n)], 0 < n | ⟨i⟩ => i.pos
Nonempty Finite Type Implies Positive Bound
Informal description
For any natural number $n$, if the type `Fin n` (of natural numbers less than $n$) is nonempty, then $0 < n$.
Fin.size_pos' abbrev
Full source
@[deprecated pos' (since := "2024-11-11")] abbrev size_pos' := @pos'
Nonempty Finite Type Implies Positive Bound
Informal description
For any natural number $n$, if the type `Fin n` (of natural numbers less than $n$) is nonempty, then $0 < n$.
Fin.is_lt theorem
(a : Fin n) : (a : Nat) < n
Full source
@[simp] theorem is_lt (a : Fin n) : (a : Nat) < n := a.2
Finite Type Elements are Bounded by n
Informal description
For any element $a$ of the finite type `Fin n`, the natural number corresponding to $a$ is strictly less than $n$.
Fin.pos_iff_nonempty theorem
{n : Nat} : 0 < n ↔ Nonempty (Fin n)
Full source
theorem pos_iff_nonempty {n : Nat} : 0 < n ↔ Nonempty (Fin n) :=
  ⟨fun h => ⟨⟨0, h⟩⟩, fun ⟨i⟩ => i.pos⟩
Positivity of $n$ is Equivalent to Nonemptiness of $\mathrm{Fin}\,n$
Informal description
For any natural number $n$, the following are equivalent: 1. $0 < n$ (i.e., $n$ is positive) 2. The type $\mathrm{Fin}\,n$ is nonempty (i.e., there exists at least one element in $\mathrm{Fin}\,n$)
Fin.eta theorem
(a : Fin n) (h : a < n) : (⟨a, h⟩ : Fin n) = a
Full source
@[simp] protected theorem eta (a : Fin n) (h : a < n) : (⟨a, h⟩ : Fin n) = a := rfl
Eta Reduction for Finite Types
Informal description
For any element $a$ of the finite type $\mathrm{Fin}\,n$ and any proof $h$ that $a < n$, the element $\langle a, h \rangle$ (constructed from $a$ and $h$) is equal to $a$ in $\mathrm{Fin}\,n$.
Fin.ext theorem
{a b : Fin n} (h : (a : Nat) = b) : a = b
Full source
@[ext] protected theorem ext {a b : Fin n} (h : (a : Nat) = b) : a = b := eq_of_val_eq h
Equality in Fin n via Natural Number Coercion
Informal description
For any two elements $a$ and $b$ of the finite type $\mathrm{Fin}\,n$, if their underlying natural number values are equal (i.e., $a = b$ as natural numbers), then $a$ and $b$ are equal as elements of $\mathrm{Fin}\,n$.
Fin.val_ne_iff theorem
{a b : Fin n} : a.1 ≠ b.1 ↔ a ≠ b
Full source
theorem val_ne_iff {a b : Fin n} : a.1 ≠ b.1a.1 ≠ b.1 ↔ a ≠ b := not_congr val_inj
Inequality in $\mathrm{Fin}\,n$ via Underlying Natural Numbers
Informal description
For any two elements $a$ and $b$ of the finite type $\mathrm{Fin}\,n$, the inequality of their underlying natural number values ($a.1 \neq b.1$) is equivalent to the inequality of the elements themselves ($a \neq b$).
Fin.forall_iff theorem
{p : Fin n → Prop} : (∀ i, p i) ↔ ∀ i h, p ⟨i, h⟩
Full source
theorem forall_iff {p : Fin n → Prop} : (∀ i, p i) ↔ ∀ i h, p ⟨i, h⟩ :=
  ⟨fun h i hi => h ⟨i, hi⟩, fun h ⟨i, hi⟩ => h i hi⟩
Universal Quantification over Finite Types via Natural Numbers
Informal description
For any predicate $p$ on the finite type $\mathrm{Fin}\,n$, the universal quantification over all elements $i \in \mathrm{Fin}\,n$ is equivalent to the universal quantification over all natural numbers $i$ and proofs $h$ that $i < n$, applied to the element $\langle i, h \rangle \in \mathrm{Fin}\,n$. In other words, $(\forall i \in \mathrm{Fin}\,n, p(i)) \leftrightarrow (\forall i \in \mathbb{N}, \forall h : i < n, p(\langle i, h \rangle))$.
Fin.mk.inj_iff theorem
{n a b : Nat} {ha : a < n} {hb : b < n} : (⟨a, ha⟩ : Fin n) = ⟨b, hb⟩ ↔ a = b
Full source
/-- Restatement of `Fin.mk.injEq` as an `iff`. -/
protected theorem mk.inj_iff {n a b : Nat} {ha : a < n} {hb : b < n} :
    (⟨a, ha⟩ : Fin n) = ⟨b, hb⟩ ↔ a = b := Fin.ext_iff
Equality in $\mathrm{Fin}\,n$ via Underlying Natural Numbers
Informal description
For any natural numbers $a, b < n$, the equality $\langle a, ha \rangle = \langle b, hb \rangle$ in $\mathrm{Fin}\,n$ holds if and only if $a = b$.
Fin.val_mk theorem
{m n : Nat} (h : m < n) : (⟨m, h⟩ : Fin n).val = m
Full source
theorem val_mk {m n : Nat} (h : m < n) : (⟨m, h⟩ : Fin n).val = m := rfl
Underlying Value of Finite Type Element Equals Its Natural Number Component
Informal description
For any natural numbers $m$ and $n$ such that $m < n$, the underlying natural number value of the finite type element $\langle m, h \rangle : \text{Fin } n$ (where $h$ is a proof that $m < n$) is equal to $m$.
Fin.mk_val theorem
(i : Fin n) : (⟨i, i.isLt⟩ : Fin n) = i
Full source
theorem mk_val (i : Fin n) : (⟨i, i.isLt⟩ : Fin n) = i := Fin.eta ..
Constructor Identity for Finite Type Elements: $\langle i, \text{isLt}\,i \rangle = i$
Informal description
For any element $i$ of the finite type $\mathrm{Fin}\,n$, the element constructed from $i$ and its proof of being less than $n$ is equal to $i$ itself, i.e., $\langle i, \text{isLt}\,i \rangle = i$.
Fin.mk_eq_zero theorem
{n a : Nat} {ha : a < n} [NeZero n] : (⟨a, ha⟩ : Fin n) = 0 ↔ a = 0
Full source
@[simp] theorem mk_eq_zero {n a : Nat} {ha : a < n} [NeZero n] :
    (⟨a, ha⟩ : Fin n) = 0 ↔ a = 0 :=
  mk.inj_iff
Zero Equivalence in Finite Type: $\langle a, ha \rangle = 0 \leftrightarrow a = 0$
Informal description
For any natural numbers $n$ and $a$ with $a < n$ and $n \neq 0$, the element $\langle a, ha \rangle$ of $\mathrm{Fin}\,n$ is equal to $0$ if and only if $a = 0$.
Fin.zero_eq_mk theorem
{n a : Nat} {ha : a < n} [NeZero n] : 0 = (⟨a, ha⟩ : Fin n) ↔ a = 0
Full source
@[simp] theorem zero_eq_mk {n a : Nat} {ha : a < n} [NeZero n] :
    0 = (⟨a, ha⟩ : Fin n) ↔ a = 0 := by
  simp [eq_comm]
Zero Equivalence in Finite Type Construction: $0 = \langle a, ha \rangle \leftrightarrow a = 0$
Informal description
For any natural numbers $n$ and $a$ with $a < n$ and $n \neq 0$, the zero element of $\mathrm{Fin}\,n$ is equal to the element $\langle a, ha \rangle$ if and only if $a = 0$.
Fin.val_ofNat' theorem
(n : Nat) [NeZero n] (a : Nat) : (Fin.ofNat' n a).val = a % n
Full source
@[simp] theorem val_ofNat' (n : Nat) [NeZero n] (a : Nat) :
  (Fin.ofNat' n a).val = a % n := rfl
Value of Finite Type Construction via Natural Numbers Equals Modulo
Informal description
For any natural number $n$ (with $n \neq 0$) and any natural number $a$, the underlying value of the finite type element $\mathrm{Fin.ofNat'}\,n\,a$ is equal to $a \bmod n$.
Fin.ofNat'_self theorem
{n : Nat} [NeZero n] : Fin.ofNat' n n = 0
Full source
@[simp] theorem ofNat'_self {n : Nat} [NeZero n] : Fin.ofNat' n n = 0 := by
  ext
  simp
  congr
Finite Type Construction of $n$ Yields Zero: $\mathrm{Fin.ofNat'}\,n\,n = 0$
Informal description
For any natural number $n$ with $n \neq 0$, the construction of a finite type element via `Fin.ofNat'` applied to $n$ itself yields the zero element of $\mathrm{Fin}\,n$, i.e., $\mathrm{Fin.ofNat'}\,n\,n = 0$.
Fin.ofNat'_val_eq_self theorem
[NeZero n] (x : Fin n) : (Fin.ofNat' n x) = x
Full source
@[simp] theorem ofNat'_val_eq_self [NeZero n] (x : Fin n) : (Fin.ofNat' n x) = x := by
  ext
  rw [val_ofNat', Nat.mod_eq_of_lt]
  exact x.2
Finite Type Construction from Natural Number Preserves Identity
Informal description
For any non-zero natural number $n$ and any element $x$ of the finite type $\mathrm{Fin}\,n$, the construction $\mathrm{Fin.ofNat'}\,n\,x$ equals $x$ itself.
Fin.mod_val theorem
(a b : Fin n) : (a % b).val = a.val % b.val
Full source
@[simp] theorem mod_val (a b : Fin n) : (a % b).val = a.val % b.val :=
  rfl
Modulo in $\mathrm{Fin}\,n$ preserves underlying natural number modulo
Informal description
For any two elements $a$ and $b$ in the finite type $\mathrm{Fin}\,n$, the underlying natural number value of their modulo operation $a \% b$ is equal to the modulo operation of their underlying natural number values $a.\mathrm{val} \% b.\mathrm{val}$.
Fin.div_val theorem
(a b : Fin n) : (a / b).val = a.val / b.val
Full source
@[simp] theorem div_val (a b : Fin n) : (a / b).val = a.val / b.val :=
  rfl
Division in $\mathrm{Fin}\,n$ preserves underlying natural number division
Informal description
For any two elements $a$ and $b$ in the finite type $\mathrm{Fin}\,n$, the underlying natural number value of their division $a / b$ is equal to the division of their underlying natural number values $a.\mathrm{val} / b.\mathrm{val}$.
Fin.modn_val theorem
(a : Fin n) (b : Nat) : (a.modn b).val = a.val % b
Full source
@[simp] theorem modn_val (a : Fin n) (b : Nat) : (a.modn b).val = a.val % b :=
  rfl
Modulus Operation Preserves Underlying Value in Finite Types
Informal description
For any element $a$ in the finite type $\mathrm{Fin}\,n$ and any natural number $b$, the underlying natural number value of $a \mod b$ is equal to the modulus of $a$'s underlying value by $b$, i.e., $(a \mod b).\mathrm{val} = a.\mathrm{val} \mod b$.
Fin.val_eq_zero theorem
(a : Fin 1) : a.val = 0
Full source
@[simp] theorem val_eq_zero (a : Fin 1) : a.val = 0 :=
  Nat.eq_zero_of_le_zero <| Nat.le_of_lt_succ a.isLt
All elements of $\mathrm{Fin}\,1$ have value 0
Informal description
For any element $a$ in the finite type $\mathrm{Fin}\,1$ (natural numbers less than 1), the underlying natural number value of $a$ is equal to 0.
Fin.ite_val theorem
{n : Nat} {c : Prop} [Decidable c] {x : c → Fin n} (y : ¬c → Fin n) : (if h : c then x h else y h).val = if h : c then (x h).val else (y h).val
Full source
theorem ite_val {n : Nat} {c : Prop} [Decidable c] {x : c → Fin n} (y : ¬cFin n) :
    (if h : c then x h else y h).val = if h : c then (x h).val else (y h).val := by
  by_cases c <;> simp [*]
Underlying Value of Dependent If-Then-Else in Finite Types: $(\text{if } h : c \text{ then } x\,h \text{ else } y\,h).\mathrm{val} = \text{if } h : c \text{ then } (x\,h).\mathrm{val} \text{ else } (y\,h).\mathrm{val}$
Informal description
For any natural number $n$, decidable proposition $c$, and functions $x : c \to \mathrm{Fin}\,n$ and $y : \neg c \to \mathrm{Fin}\,n$, the underlying natural number value of the dependent if-then-else expression $\mathrm{if}\,h : c\,\mathrm{then}\,x\,h\,\mathrm{else}\,y\,h$ is equal to the dependent if-then-else expression $\mathrm{if}\,h : c\,\mathrm{then}\,(x\,h).\mathrm{val}\,\mathrm{else}\,(y\,h).\mathrm{val}$.
Fin.dite_val theorem
{n : Nat} {c : Prop} [Decidable c] {x y : Fin n} : (if c then x else y).val = if c then x.val else y.val
Full source
theorem dite_val {n : Nat} {c : Prop} [Decidable c] {x y : Fin n} :
    (if c then x else y).val = if c then x.val else y.val := by
  by_cases c <;> simp [*]
Conditional Value Preservation in Finite Numbers: $(\text{if } c \text{ then } x \text{ else } y).\text{val} = \text{if } c \text{ then } x.\text{val} \text{ else } y.\text{val}$
Informal description
For any natural number $n$, any decidable proposition $c$, and any elements $x, y \in \mathrm{Fin}\,n$, the underlying natural number value of the conditional expression $\text{if } c \text{ then } x \text{ else } y$ is equal to the conditional expression $\text{if } c \text{ then } x.\text{val} \text{ else } y.\text{val}$.
Fin.le_def theorem
{a b : Fin n} : a ≤ b ↔ a.1 ≤ b.1
Full source
theorem le_def {a b : Fin n} : a ≤ b ↔ a.1 ≤ b.1 := .rfl
Order Relation on Finite Numbers via Underlying Values
Informal description
For any two elements $a$ and $b$ in $\mathrm{Fin}\,n$ (the type of natural numbers less than $n$), the inequality $a \leq b$ holds if and only if the underlying natural number value of $a$ is less than or equal to the underlying natural number value of $b$.
Fin.lt_def theorem
{a b : Fin n} : a < b ↔ a.1 < b.1
Full source
theorem lt_def {a b : Fin n} : a < b ↔ a.1 < b.1 := .rfl
Strict Order on Finite Numbers via Underlying Values
Informal description
For any two elements $a$ and $b$ of $\mathrm{Fin}\,n$ (the type of natural numbers less than $n$), the strict inequality $a < b$ holds if and only if the underlying natural number value of $a$ is strictly less than the underlying natural number value of $b$.
Fin.lt_iff_val_lt_val theorem
{a b : Fin n} : a < b ↔ a.val < b.val
Full source
theorem lt_iff_val_lt_val {a b : Fin n} : a < b ↔ a.val < b.val := Iff.rfl
Strict Order on Finite Numbers via Underlying Values: $a < b \leftrightarrow a.\mathrm{val} < b.\mathrm{val}$
Informal description
For any two elements $a$ and $b$ of $\mathrm{Fin}\,n$ (the type of natural numbers less than $n$), the strict inequality $a < b$ holds if and only if the underlying natural number values satisfy $a.\mathrm{val} < b.\mathrm{val}$.
Fin.not_le theorem
{a b : Fin n} : ¬a ≤ b ↔ b < a
Full source
@[simp] protected theorem not_le {a b : Fin n} : ¬ a ≤ b¬ a ≤ b ↔ b < a := Nat.not_le
Negation of Order Relation in Finite Types: $\neg(a \leq b) \leftrightarrow b < a$
Informal description
For any two elements $a$ and $b$ of $\mathrm{Fin}\,n$ (the type of natural numbers less than $n$), the negation of $a \leq b$ is equivalent to $b < a$.
Fin.not_lt theorem
{a b : Fin n} : ¬a < b ↔ b ≤ a
Full source
@[simp] protected theorem not_lt {a b : Fin n} : ¬ a < b¬ a < b ↔ b ≤ a := Nat.not_lt
Negation of Strict Order Implies Non-strict Order in Finite Types
Informal description
For any two elements $a, b$ in $\mathrm{Fin}\,n$ (the type of natural numbers less than $n$), the statement $\neg(a < b)$ is equivalent to $b \leq a$.
Fin.le_refl theorem
(a : Fin n) : a ≤ a
Full source
@[simp] protected theorem le_refl (a : Fin n) : a ≤ a := by simp [le_def]
Reflexivity of the Order Relation on Finite Natural Numbers
Informal description
For any element $a$ of the finite type $\mathrm{Fin}\,n$ (natural numbers less than $n$), the reflexive property holds: $a \leq a$.
Fin.lt_irrefl theorem
(a : Fin n) : ¬a < a
Full source
@[simp] protected theorem lt_irrefl (a : Fin n) : ¬ a < a := by simp
Irreflexivity of Strict Order on Finite Natural Numbers
Informal description
For any element $a$ in the finite type $\mathrm{Fin}\,n$ (natural numbers less than $n$), the strict inequality $a < a$ does not hold.
Fin.le_trans theorem
{a b c : Fin n} : a ≤ b → b ≤ c → a ≤ c
Full source
protected theorem le_trans {a b c : Fin n} : a ≤ b → b ≤ c → a ≤ c := Nat.le_trans
Transitivity of Order in Finite Natural Numbers
Informal description
For any elements $a$, $b$, and $c$ in $\mathrm{Fin}\,n$ (the type of natural numbers less than $n$), if $a \leq b$ and $b \leq c$, then $a \leq c$.
Fin.lt_trans theorem
{a b c : Fin n} : a < b → b < c → a < c
Full source
protected theorem lt_trans {a b c : Fin n} : a < b → b < c → a < c := Nat.lt_trans
Transitivity of Strict Order in Finite Natural Numbers
Informal description
For any elements $a$, $b$, and $c$ in $\mathrm{Fin}\,n$ (the type of natural numbers less than $n$), if $a < b$ and $b < c$, then $a < c$.
Fin.le_total theorem
(a b : Fin n) : a ≤ b ∨ b ≤ a
Full source
protected theorem le_total (a b : Fin n) : a ≤ b ∨ b ≤ a := Nat.le_total a b
Total Order Property of $\mathrm{Fin}\,n$
Informal description
For any two elements $a$ and $b$ in $\mathrm{Fin}\,n$, either $a \leq b$ or $b \leq a$ holds.
Fin.lt_asymm theorem
{a b : Fin n} (h : a < b) : ¬b < a
Full source
protected theorem lt_asymm {a b : Fin n} (h : a < b) : ¬ b < a := Nat.lt_asymm h
Asymmetry of Strict Order on Finite Natural Numbers
Informal description
For any two elements $a$ and $b$ in $\mathrm{Fin}\,n$, if $a < b$, then it is not the case that $b < a$.
Fin.ne_of_lt theorem
{a b : Fin n} (h : a < b) : a ≠ b
Full source
protected theorem ne_of_lt {a b : Fin n} (h : a < b) : a ≠ b := Fin.ne_of_val_ne (Nat.ne_of_lt h)
Inequality from Strict Order in Finite Types
Informal description
For any two elements $a$ and $b$ in $\mathrm{Fin}\,n$, if $a < b$ then $a \neq b$.
Fin.ne_of_gt theorem
{a b : Fin n} (h : a < b) : b ≠ a
Full source
protected theorem ne_of_gt {a b : Fin n} (h : a < b) : b ≠ a := Fin.ne_of_val_ne (Nat.ne_of_gt h)
Inequality from Greater-Than Relation in Finite Types
Informal description
For any two elements $a$ and $b$ of $\mathrm{Fin}\,n$ (the type of natural numbers less than $n$), if $a < b$ then $b \neq a$.
Fin.le_of_lt theorem
{a b : Fin n} (h : a < b) : a ≤ b
Full source
protected theorem le_of_lt {a b : Fin n} (h : a < b) : a ≤ b := Nat.le_of_lt h
Weak Ordering from Strict Ordering in Finite Natural Numbers
Informal description
For any two elements $a$ and $b$ of $\mathrm{Fin}\,n$ (the type of natural numbers less than $n$), if $a < b$, then $a \leq b$.
Fin.lt_of_le_of_lt theorem
{a b c : Fin n} : a ≤ b → b < c → a < c
Full source
protected theorem lt_of_le_of_lt {a b c : Fin n} : a ≤ b → b < c → a < c := Nat.lt_of_le_of_lt
Transitivity of $\leq$ and $<$ in Finite Types
Informal description
For any elements $a, b, c$ in $\mathrm{Fin}\,n$ (the type of natural numbers less than $n$), if $a \leq b$ and $b < c$, then $a < c$.
Fin.lt_of_lt_of_le theorem
{a b c : Fin n} : a < b → b ≤ c → a < c
Full source
protected theorem lt_of_lt_of_le {a b c : Fin n} : a < b → b ≤ c → a < c := Nat.lt_of_lt_of_le
Transitivity of Strict and Non-Strict Order in Finite Types
Informal description
For any elements $a, b, c$ in $\mathrm{Fin}\,n$, if $a < b$ and $b \leq c$, then $a < c$.
Fin.le_rfl theorem
{a : Fin n} : a ≤ a
Full source
protected theorem le_rfl {a : Fin n} : a ≤ a := Nat.le_refl _
Reflexivity of the Order on Finite Natural Numbers
Informal description
For any element $a$ of the finite type $\mathrm{Fin}\,n$, the relation $a \leq a$ holds.
Fin.lt_iff_le_and_ne theorem
{a b : Fin n} : a < b ↔ a ≤ b ∧ a ≠ b
Full source
protected theorem lt_iff_le_and_ne {a b : Fin n} : a < b ↔ a ≤ b ∧ a ≠ b := by
  rw [← val_ne_iff]; exact Nat.lt_iff_le_and_ne
Strict Inequality in $\mathrm{Fin}\,n$ via Non-Strict Inequality and Distinctness
Informal description
For any two elements $a$ and $b$ of the finite type $\mathrm{Fin}\,n$, the strict inequality $a < b$ holds if and only if $a \leq b$ and $a \neq b$.
Fin.lt_or_lt_of_ne theorem
{a b : Fin n} (h : a ≠ b) : a < b ∨ b < a
Full source
protected theorem lt_or_lt_of_ne {a b : Fin n} (h : a ≠ b) : a < b ∨ b < a :=
  Nat.lt_or_lt_of_ne <| val_ne_iff.2 h
Trichotomy for Finite Natural Numbers: $a \neq b \Rightarrow a < b \lor b < a$
Informal description
For any two distinct elements $a$ and $b$ in $\mathrm{Fin}\,n$, either $a$ is less than $b$ or $b$ is less than $a$.
Fin.lt_or_le theorem
(a b : Fin n) : a < b ∨ b ≤ a
Full source
protected theorem lt_or_le (a b : Fin n) : a < b ∨ b ≤ a := Nat.lt_or_ge _ _
Trichotomy for Finite Natural Numbers: $a < b$ or $b \leq a$
Informal description
For any two elements $a$ and $b$ in $\mathrm{Fin}\,n$ (the type of natural numbers less than $n$), either $a$ is strictly less than $b$ or $b$ is less than or equal to $a$.
Fin.le_or_lt theorem
(a b : Fin n) : a ≤ b ∨ b < a
Full source
protected theorem le_or_lt (a b : Fin n) : a ≤ b ∨ b < a := (b.lt_or_le a).symm
Trichotomy for Finite Natural Numbers: $a \leq b$ or $b < a$
Informal description
For any two elements $a$ and $b$ in $\mathrm{Fin}\,n$ (the type of natural numbers less than $n$), either $a$ is less than or equal to $b$, or $b$ is strictly less than $a$.
Fin.le_of_eq theorem
{a b : Fin n} (hab : a = b) : a ≤ b
Full source
protected theorem le_of_eq {a b : Fin n} (hab : a = b) : a ≤ b :=
  Nat.le_of_eq <| congrArg val hab
Equality Implies Inequality in Finite Natural Numbers
Informal description
For any two elements $a$ and $b$ in $\mathrm{Fin}\,n$ (the type of natural numbers less than $n$), if $a = b$, then $a \leq b$.
Fin.ge_of_eq theorem
{a b : Fin n} (hab : a = b) : b ≤ a
Full source
protected theorem ge_of_eq {a b : Fin n} (hab : a = b) : b ≤ a := Fin.le_of_eq hab.symm
Equality Implies Reverse Inequality in Finite Natural Numbers
Informal description
For any two elements $a$ and $b$ in $\mathrm{Fin}\,n$ (the type of natural numbers less than $n$), if $a = b$, then $b \leq a$.
Fin.lt_or_eq_of_le theorem
{a b : Fin n} : a ≤ b → a < b ∨ a = b
Full source
protected theorem lt_or_eq_of_le {a b : Fin n} : a ≤ b → a < b ∨ a = b := by
  rw [Fin.ext_iff]; exact Nat.lt_or_eq_of_le
Total Order Property for Finite Natural Numbers: $a \leq b \Rightarrow a < b \lor a = b$
Informal description
For any two elements $a$ and $b$ in $\mathrm{Fin}\,n$ (the type of natural numbers less than $n$), if $a \leq b$, then either $a < b$ or $a = b$.
Fin.is_le theorem
(i : Fin (n + 1)) : i ≤ n
Full source
theorem is_le (i : Fin (n + 1)) : i ≤ n := Nat.le_of_lt_succ i.is_lt
Finite Type Elements are Bounded by n: $i \leq n$ in $\mathrm{Fin}\,(n + 1)$
Informal description
For any element $i$ in the finite type $\mathrm{Fin}\,(n + 1)$ (natural numbers less than $n + 1$), the inequality $i \leq n$ holds.
Fin.is_le' theorem
{a : Fin n} : a ≤ n
Full source
@[simp] theorem is_le' {a : Fin n} : a ≤ n := Nat.le_of_lt a.is_lt
Finite Type Elements are Bounded by n: $a \leq n$
Informal description
For any element $a$ in the finite type $\mathrm{Fin}\,n$ (natural numbers less than $n$), the inequality $a \leq n$ holds.
Fin.mk_lt_of_lt_val theorem
{b : Fin n} {a : Nat} (h : a < b) : (⟨a, Nat.lt_trans h b.is_lt⟩ : Fin n) < b
Full source
theorem mk_lt_of_lt_val {b : Fin n} {a : Nat} (h : a < b) :
    (⟨a, Nat.lt_trans h b.is_lt⟩ : Fin n) < b := h
Strict Order Preservation in $\mathrm{Fin}\,n$ via Natural Number Comparison
Informal description
For any natural number $n$, let $b$ be an element of $\mathrm{Fin}\,n$ (i.e., a natural number less than $n$). Given a natural number $a$ such that $a < b$ (as natural numbers), the element $\langle a, h \rangle$ of $\mathrm{Fin}\,n$ (where $h$ is the proof that $a < n$ obtained via transitivity from $a < b$ and $b < n$) satisfies $\langle a, h \rangle < b$ in $\mathrm{Fin}\,n$.
Fin.mk_le_of_le_val theorem
{b : Fin n} {a : Nat} (h : a ≤ b) : (⟨a, Nat.lt_of_le_of_lt h b.is_lt⟩ : Fin n) ≤ b
Full source
theorem mk_le_of_le_val {b : Fin n} {a : Nat} (h : a ≤ b) :
    (⟨a, Nat.lt_of_le_of_lt h b.is_lt⟩ : Fin n) ≤ b := h
Order Preservation in $\mathrm{Fin}\,n$ via Natural Number Comparison
Informal description
For any natural number $n$, let $b$ be an element of $\mathrm{Fin}\,n$ (i.e., a natural number less than $n$). Given a natural number $a$ such that $a \leq b$ (as natural numbers), the element $\langle a, h \rangle$ of $\mathrm{Fin}\,n$ (where $h$ is the proof that $a < n$ obtained via transitivity from $a \leq b$ and $b < n$) satisfies $\langle a, h \rangle \leq b$ in $\mathrm{Fin}\,n$.
Fin.mk_le_mk theorem
{x y : Nat} {hx hy} : (⟨x, hx⟩ : Fin n) ≤ ⟨y, hy⟩ ↔ x ≤ y
Full source
@[simp] theorem mk_le_mk {x y : Nat} {hx hy} : (⟨x, hx⟩ : Fin n) ≤ ⟨y, hy⟩ ↔ x ≤ y := .rfl
Order Comparison in $\mathrm{Fin}\,n$ via Natural Numbers
Informal description
For any natural numbers $x$ and $y$ with proofs $hx : x < n$ and $hy : y < n$, the inequality $\langle x, hx \rangle \leq \langle y, hy \rangle$ holds in $\mathrm{Fin}\,n$ if and only if $x \leq y$ holds in $\mathbb{N}$.
Fin.mk_lt_mk theorem
{x y : Nat} {hx hy} : (⟨x, hx⟩ : Fin n) < ⟨y, hy⟩ ↔ x < y
Full source
@[simp] theorem mk_lt_mk {x y : Nat} {hx hy} : (⟨x, hx⟩ : Fin n) < ⟨y, hy⟩ ↔ x < y := .rfl
Strict Order in $\mathrm{Fin}\,n$ Reflects Natural Number Order
Informal description
For any natural numbers $x$ and $y$ with proofs $hx : x < n$ and $hy : y < n$, the element $\langle x, hx \rangle$ of $\mathrm{Fin}\,n$ is strictly less than $\langle y, hy \rangle$ if and only if $x < y$ as natural numbers.
Fin.val_zero theorem
(n : Nat) [NeZero n] : ((0 : Fin n) : Nat) = 0
Full source
@[simp] theorem val_zero (n : Nat) [NeZero n] : ((0 : Fin n) : Nat) = 0 := rfl
Natural Number Value of Zero in $\mathrm{Fin}\,n$ is Zero
Informal description
For any positive natural number $n$ (i.e., $n \neq 0$), the natural number value of the zero element in $\mathrm{Fin}\,n$ is equal to $0$.
Fin.mk_zero theorem
: (⟨0, Nat.succ_pos n⟩ : Fin (n + 1)) = 0
Full source
@[simp] theorem mk_zero : (⟨0, Nat.succ_pos n⟩ : Fin (n + 1)) = 0 := rfl
Zero Construction in $\mathrm{Fin}(n+1)$ Equals Zero
Informal description
For any natural number $n$, the element $\langle 0, h \rangle$ of $\mathrm{Fin}(n+1)$ (where $h$ is a proof that $0 < n+1$) is equal to the zero element of $\mathrm{Fin}(n+1)$.
Fin.zero_le theorem
(a : Fin (n + 1)) : 0 ≤ a
Full source
@[simp] theorem zero_le (a : Fin (n + 1)) : 0 ≤ a := Nat.zero_le a.val
Nonnegativity in Finite Types: $0 \leq a$ for all $a \in \mathrm{Fin}\,(n+1)$
Informal description
For any natural number $n$ and any element $a$ in $\mathrm{Fin}\,(n+1)$, the zero element is less than or equal to $a$.
Fin.zero_lt_one theorem
: (0 : Fin (n + 2)) < 1
Full source
theorem zero_lt_one : (0 : Fin (n + 2)) < 1 := Nat.zero_lt_one
Strict Inequality in Finite Types: $0 < 1$ in $\mathrm{Fin}(n+2)$
Informal description
For any natural number $n$, the element $0$ in $\mathrm{Fin}(n+2)$ is strictly less than $1$.
Fin.not_lt_zero theorem
(a : Fin (n + 1)) : ¬a < 0
Full source
@[simp] theorem not_lt_zero (a : Fin (n + 1)) : ¬a < 0 := nofun
No Element is Less Than Zero in $\mathrm{Fin}(n+1)$
Informal description
For any natural number $n$ and any element $a$ in the finite type $\mathrm{Fin}(n+1)$, the statement $a < 0$ is false.
Fin.pos_iff_ne_zero theorem
{a : Fin (n + 1)} : 0 < a ↔ a ≠ 0
Full source
theorem pos_iff_ne_zero {a : Fin (n + 1)} : 0 < a ↔ a ≠ 0 := by
  rw [lt_def, val_zero, Nat.pos_iff_ne_zero, ← val_ne_iff]; rfl
Positivity in $\mathrm{Fin}(n+1)$ is Equivalent to Non-Zero
Informal description
For any element $a$ of the finite type $\mathrm{Fin}(n+1)$ (natural numbers less than $n+1$), the strict inequality $0 < a$ holds if and only if $a$ is not equal to $0$.
Fin.le_antisymm_iff theorem
{x y : Fin n} : x = y ↔ x ≤ y ∧ y ≤ x
Full source
protected theorem le_antisymm_iff {x y : Fin n} : x = y ↔ x ≤ y ∧ y ≤ x :=
  Fin.ext_iff.trans Nat.le_antisymm_iff
Antisymmetry of Order in Finite Types: $x = y \leftrightarrow x \leq y \land y \leq x$
Informal description
For any two elements $x$ and $y$ in the finite type $\mathrm{Fin}\,n$, the equality $x = y$ holds if and only if both $x \leq y$ and $y \leq x$ are satisfied.
Fin.le_antisymm theorem
{x y : Fin n} (h1 : x ≤ y) (h2 : y ≤ x) : x = y
Full source
protected theorem le_antisymm {x y : Fin n} (h1 : x ≤ y) (h2 : y ≤ x) : x = y :=
  Fin.le_antisymm_iff.2 ⟨h1, h2⟩
Antisymmetry of Order in Finite Types: $x \leq y \land y \leq x \to x = y$
Informal description
For any two elements $x$ and $y$ in the finite type $\mathrm{Fin}\,n$, if $x \leq y$ and $y \leq x$, then $x = y$.
Fin.val_rev theorem
(i : Fin n) : rev i = n - (i + 1)
Full source
@[simp] theorem val_rev (i : Fin n) : rev i = n - (i + 1) := rfl
Value of Reversed Element in Finite Type: $\mathrm{rev}\,i = n - (i + 1)$
Informal description
For any element $i$ in the finite type $\mathrm{Fin}\,n$, the value of the reversed element $\mathrm{rev}\,i$ is equal to $n - (i + 1)$, where $i$ is treated as a natural number less than $n$.
Fin.rev_rev theorem
(i : Fin n) : rev (rev i) = i
Full source
@[simp] theorem rev_rev (i : Fin n) : rev (rev i) = i := Fin.ext <| by
  rw [val_rev, val_rev, ← Nat.sub_sub, Nat.sub_sub_self (by exact i.2), Nat.add_sub_cancel]
Double Reversal Identity in Finite Types: $\mathrm{rev}(\mathrm{rev}\,i) = i$
Informal description
For any element $i$ in the finite type $\mathrm{Fin}\,n$, applying the reversal operation twice returns the original element, i.e., $\mathrm{rev}(\mathrm{rev}\,i) = i$.
Fin.rev_le_rev theorem
{i j : Fin n} : rev i ≤ rev j ↔ j ≤ i
Full source
@[simp] theorem rev_le_rev {i j : Fin n} : revrev i ≤ rev j ↔ j ≤ i := by
  simp only [le_def, val_rev, Nat.sub_le_sub_iff_left (Nat.succ_le.2 j.is_lt)]
  exact Nat.succ_le_succ_iff
Inequality Reversal under Fin Element Reversal: $\mathrm{rev}\,i \leq \mathrm{rev}\,j \leftrightarrow j \leq i$
Informal description
For any two elements $i$ and $j$ of the finite type $\mathrm{Fin}\,n$, the reverse of $i$ is less than or equal to the reverse of $j$ if and only if $j$ is less than or equal to $i$.
Fin.rev_inj theorem
{i j : Fin n} : rev i = rev j ↔ i = j
Full source
@[simp] theorem rev_inj {i j : Fin n} : revrev i = rev j ↔ i = j :=
  ⟨fun h => by simpa using congrArg rev h, congrArg _⟩
Reversal is Injective on Finite Types: $\mathrm{rev}\,i = \mathrm{rev}\,j \leftrightarrow i = j$
Informal description
For any two elements $i$ and $j$ in the finite type $\mathrm{Fin}\,n$, the reversal of $i$ equals the reversal of $j$ if and only if $i$ equals $j$.
Fin.rev_eq theorem
{n a : Nat} (i : Fin (n + 1)) (h : n = a + i) : rev i = ⟨a, Nat.lt_succ_of_le (h ▸ Nat.le_add_right ..)⟩
Full source
theorem rev_eq {n a : Nat} (i : Fin (n + 1)) (h : n = a + i) :
    rev i = ⟨a, Nat.lt_succ_of_le (h ▸ Nat.le_add_right ..)⟩ := by
  ext; dsimp
  conv => lhs; congr; rw [h]
  rw [Nat.add_assoc, Nat.add_sub_cancel]
Reverse of Fin Element under Additive Decomposition
Informal description
For any natural numbers $n$ and $a$, and any element $i$ of the finite type $\mathrm{Fin}(n + 1)$, if $n = a + i$ (where $i$ is interpreted as a natural number via the canonical coercion), then the reverse of $i$ in $\mathrm{Fin}(n + 1)$ is equal to the element $\langle a, h \rangle$, where $h$ is a proof that $a < n + 1$ derived from the equation $n = a + i$.
Fin.rev_lt_rev theorem
{i j : Fin n} : rev i < rev j ↔ j < i
Full source
@[simp] theorem rev_lt_rev {i j : Fin n} : revrev i < rev j ↔ j < i := by
  rw [← Fin.not_le, ← Fin.not_le, rev_le_rev]
Order Reversal under Fin Element Reversal: $\mathrm{rev}\,i < \mathrm{rev}\,j \leftrightarrow j < i$
Informal description
For any two elements $i$ and $j$ of the finite type $\mathrm{Fin}\,n$, the reverse of $i$ is strictly less than the reverse of $j$ if and only if $j$ is strictly less than $i$.
Fin.val_last theorem
(n : Nat) : last n = n
Full source
@[simp] theorem val_last (n : Nat) : last n = n := rfl
Value of Last Element in Finite Type $\text{Fin}(n+1)$ is $n$
Informal description
For any natural number $n$, the value of the last element in the finite type $\text{Fin}(n+1)$ is equal to $n$, i.e., $\text{last}(n) = n$.
Fin.last_zero theorem
: (Fin.last 0 : Fin 1) = 0
Full source
@[simp] theorem last_zero : (Fin.last 0 : Fin 1) = 0 := by
  ext
  simp
Last Element of $\mathrm{Fin}\,1$ is Zero
Informal description
The last element of the finite type $\mathrm{Fin}\,1$ is equal to the zero element, i.e., $\mathrm{last}(0) = 0$.
Fin.zero_eq_last_iff theorem
{n : Nat} : (0 : Fin (n + 1)) = last n ↔ n = 0
Full source
@[simp] theorem zero_eq_last_iff {n : Nat} : (0 : Fin (n + 1)) = last n ↔ n = 0 := by
  constructor
  · intro h
    simp_all [Fin.ext_iff]
  · rintro rfl
    simp
Zero Equals Last Element in Finite Type if and only if Index is Zero
Informal description
For any natural number $n$, the zero element in the finite type $\mathrm{Fin}(n+1)$ is equal to the last element if and only if $n = 0$.
Fin.last_eq_zero_iff theorem
{n : Nat} : Fin.last n = 0 ↔ n = 0
Full source
@[simp] theorem last_eq_zero_iff {n : Nat} : Fin.lastFin.last n = 0 ↔ n = 0 := by
  simp [eq_comm (a := Fin.last n)]
Last Element Equals Zero in Finite Type if and only if Index is Zero
Informal description
For any natural number $n$, the last element of the finite type $\text{Fin}(n+1)$ (i.e., the element with value $n$) is equal to the zero element if and only if $n = 0$.
Fin.le_last theorem
(i : Fin (n + 1)) : i ≤ last n
Full source
theorem le_last (i : Fin (n + 1)) : i ≤ last n := Nat.le_of_lt_succ i.is_lt
Every Element in $\mathrm{Fin}(n+1)$ is Bounded by the Last Element
Informal description
For any natural number $n$ and any element $i$ of the finite type $\mathrm{Fin}(n+1)$, the element $i$ is less than or equal to the last element of $\mathrm{Fin}(n+1)$ (which has value $n$).
Fin.last_pos theorem
: (0 : Fin (n + 2)) < last (n + 1)
Full source
theorem last_pos : (0 : Fin (n + 2)) < last (n + 1) := Nat.succ_pos _
Positivity of Last Element in Finite Type: $0 < \mathrm{last}(n+1)$
Informal description
For any natural number $n$, the zero element of the finite type $\mathrm{Fin}(n+2)$ is strictly less than the last element of $\mathrm{Fin}(n+1)$, i.e., $0 < n+1$ in $\mathrm{Fin}(n+2)$.
Fin.val_lt_last theorem
{i : Fin (n + 1)} : i ≠ last n → (i : Nat) < n
Full source
theorem val_lt_last {i : Fin (n + 1)} : i ≠ last n → (i : Nat) < n :=
  Decidable.not_imp_comm.1 eq_last_of_not_lt
Natural Number Value of Non-Last Finite Element is Less Than $n$
Informal description
For any element $i$ of the finite type $\mathrm{Fin}(n+1)$, if $i$ is not equal to the last element $\mathrm{last}\,n$, then the natural number corresponding to $i$ is strictly less than $n$, i.e., $i < n$.
Fin.rev_last theorem
(n : Nat) : rev (last n) = 0
Full source
@[simp] theorem rev_last (n : Nat) : rev (last n) = 0 := Fin.ext <| by simp
Reversal of Last Element in Finite Type Equals Zero
Informal description
For any natural number $n$, the reversal of the last element in $\mathrm{Fin}(n+1)$ (i.e., the element corresponding to $n$) is equal to $0$ in $\mathrm{Fin}(n+1)$.
Fin.rev_zero theorem
(n : Nat) : rev 0 = last n
Full source
@[simp] theorem rev_zero (n : Nat) : rev 0 = last n := by
  rw [← rev_rev (last _), rev_last]
Reversal of Zero Equals Last Element in Finite Types: $\mathrm{rev}(0) = \mathrm{last}\,n$
Informal description
For any natural number $n$, the reversal of the zero element in the finite type $\mathrm{Fin}(n+1)$ is equal to the last element of $\mathrm{Fin}(n+1)$, i.e., $\mathrm{rev}(0) = \mathrm{last}\,n$.
Fin.val_one theorem
(n : Nat) : (1 : Fin (n + 2)).val = 1
Full source
@[simp] theorem val_one (n : Nat) : (1 : Fin (n + 2)).val = 1 := rfl
Value of One in Finite Type $\text{Fin}(n+2)$
Informal description
For any natural number $n$, the underlying value of the element $1$ in the finite type $\text{Fin}(n+2)$ is equal to $1$.
Fin.mk_one theorem
: (⟨1, Nat.succ_lt_succ (Nat.succ_pos n)⟩ : Fin (n + 2)) = (1 : Fin _)
Full source
@[simp] theorem mk_one : (⟨1, Nat.succ_lt_succ (Nat.succ_pos n)⟩ : Fin (n + 2)) = (1 : Fin _) := rfl
Construction of One in Finite Type $\text{Fin}(n+2)$
Informal description
For any natural number $n$, the element $\langle 1, \text{Nat.succ\_lt\_succ} (\text{Nat.succ\_pos}\,n) \rangle$ in the finite type $\text{Fin}(n+2)$ is equal to the element $1$ in $\text{Fin}(n+2)$.
Fin.subsingleton_iff_le_one theorem
: Subsingleton (Fin n) ↔ n ≤ 1
Full source
theorem subsingleton_iff_le_one : SubsingletonSubsingleton (Fin n) ↔ n ≤ 1 := by
  (match n with | 0 | 1 | n+2 => ?_) <;> try simp
  · exact ⟨nofun⟩
  · exact ⟨fun ⟨0, _⟩ ⟨0, _⟩ => rfl⟩
  · exact iff_of_false (fun h => Fin.ne_of_lt zero_lt_one (h.elim ..)) (of_decide_eq_false rfl)
Subsingleton Condition for Finite Types: $\mathrm{Fin}\,n$ is a subsingleton $\leftrightarrow n \leq 1$
Informal description
The finite type $\mathrm{Fin}\,n$ is a subsingleton (has at most one element) if and only if $n \leq 1$.
Fin.subsingleton_zero instance
: Subsingleton (Fin 0)
Full source
instance subsingleton_zero : Subsingleton (Fin 0) := subsingleton_iff_le_one.2 (by decide)
$\mathrm{Fin}\,0$ is a Subsingleton
Informal description
The finite type $\mathrm{Fin}\,0$ is a subsingleton (has at most one element).
Fin.subsingleton_one instance
: Subsingleton (Fin 1)
Full source
instance subsingleton_one : Subsingleton (Fin 1) := subsingleton_iff_le_one.2 (by decide)
Subsingleton Property of $\mathrm{Fin}\,1$
Informal description
The finite type $\mathrm{Fin}\,1$ is a subsingleton, meaning it has at most one element.
Fin.fin_one_eq_zero theorem
(a : Fin 1) : a = 0
Full source
theorem fin_one_eq_zero (a : Fin 1) : a = 0 := Subsingleton.elim a 0
All Elements of $\mathrm{Fin}\,1$ Equal Zero
Informal description
For any element $a$ in the finite type $\mathrm{Fin}\,1$, we have $a = 0$.
Fin.zero_eq_one_iff theorem
{n : Nat} [NeZero n] : (0 : Fin n) = 1 ↔ n = 1
Full source
@[simp] theorem zero_eq_one_iff {n : Nat} [NeZero n] : (0 : Fin n) = 1 ↔ n = 1 := by
  constructor
  · intro h
    simp [Fin.ext_iff] at h
    change 0 % n = 1 % n at h
    rw [eq_comm] at h
    simpa using h
  · rintro rfl
    simp
Equality of Zero and One in Finite Types: $(0 : \text{Fin } n) = 1 \leftrightarrow n = 1$
Informal description
For any natural number $n$ with $n \neq 0$, the equality $(0 : \text{Fin } n) = 1$ holds if and only if $n = 1$.
Fin.one_eq_zero_iff theorem
{n : Nat} [NeZero n] : (1 : Fin n) = 0 ↔ n = 1
Full source
@[simp] theorem one_eq_zero_iff {n : Nat} [NeZero n] : (1 : Fin n) = 0 ↔ n = 1 := by
  rw [eq_comm]
  simp
Equivalence of One and Zero in Finite Types: $(1 : \text{Fin } n) = 0 \leftrightarrow n = 1$
Informal description
For any natural number $n$ with $n \neq 0$, the equality $(1 : \text{Fin } n) = 0$ holds if and only if $n = 1$.
Fin.add_def theorem
(a b : Fin n) : a + b = Fin.mk ((a + b) % n) (Nat.mod_lt _ a.pos)
Full source
theorem add_def (a b : Fin n) : a + b = Fin.mk ((a + b) % n) (Nat.mod_lt _ a.pos) := rfl
Definition of Addition in Finite Types: $a + b = \text{mk}((a + b) \mod n)$
Informal description
For any two elements $a, b$ in $\text{Fin } n$, their sum $a + b$ is equal to the element of $\text{Fin } n$ constructed from $(a + b) \mod n$, with the proof that $(a + b) \mod n < n$ following from the fact that $a$ is a valid element of $\text{Fin } n$ (i.e., $a < n$).
Fin.val_add theorem
(a b : Fin n) : (a + b).val = (a.val + b.val) % n
Full source
theorem val_add (a b : Fin n) : (a + b).val = (a.val + b.val) % n := rfl
Value of Addition in Finite Types: $(a + b).\text{val} = (a.\text{val} + b.\text{val}) \mod n$
Informal description
For any two elements $a$ and $b$ of the finite type $\text{Fin } n$, the underlying natural number value of their sum $a + b$ is equal to the sum of their underlying values modulo $n$, i.e., $(a + b).\text{val} = (a.\text{val} + b.\text{val}) \mod n$.
Fin.zero_add theorem
[NeZero n] (k : Fin n) : (0 : Fin n) + k = k
Full source
@[simp] protected theorem zero_add [NeZero n] (k : Fin n) : (0 : Fin n) + k = k := by
  ext
  simp [Fin.add_def, Nat.mod_eq_of_lt k.2]
Left Additive Identity in Finite Types: $0 + k = k$
Informal description
For any non-zero natural number $n$ and any element $k$ of the finite type $\mathrm{Fin}\,n$, the sum of the zero element and $k$ in $\mathrm{Fin}\,n$ is equal to $k$, i.e., $0 + k = k$.
Fin.add_zero theorem
[NeZero n] (k : Fin n) : k + 0 = k
Full source
@[simp] protected theorem add_zero [NeZero n] (k : Fin n) : k + 0 = k := by
  ext
  simp [add_def, Nat.mod_eq_of_lt k.2]
Right Additive Identity in Finite Types: $k + 0 = k$
Informal description
For any non-zero natural number $n$ and any element $k$ in the finite type $\mathrm{Fin}\,n$, the addition of $k$ with the zero element of $\mathrm{Fin}\,n$ yields $k$, i.e., $k + 0 = k$.
Fin.val_add_one_of_lt theorem
{n : Nat} {i : Fin n.succ} (h : i < last _) : (i + 1).1 = i + 1
Full source
theorem val_add_one_of_lt {n : Nat} {i : Fin n.succ} (h : i < last _) : (i + 1).1 = i + 1 := by
  match n with
  | 0 => cases h
  | n+1 => rw [val_add, val_one, Nat.mod_eq_of_lt (by exact Nat.succ_lt_succ h)]
Value of Successor in Finite Type for Non-Last Elements: $(i + 1).\text{val} = i + 1$ when $i < \text{last}$
Informal description
For any natural number $n$ and any element $i$ of the finite type $\mathrm{Fin}\,(n+1)$, if $i$ is less than the last element of $\mathrm{Fin}\,(n+1)$, then the underlying natural number value of $i + 1$ is equal to $i + 1$.
Fin.last_add_one theorem
: ∀ n, last n + 1 = 0
Full source
@[simp] theorem last_add_one : ∀ n, last n + 1 = 0
  | 0 => rfl
  | n + 1 => by ext; rw [val_add, val_zero, val_last, val_one, Nat.mod_self]
Cyclic Property of Finite Types: $\mathrm{last}(n) + 1 = 0$
Informal description
For any natural number $n$, the sum of the last element of the finite type $\mathrm{Fin}(n+1)$ and $1$ equals the zero element, i.e., $\mathrm{last}(n) + 1 = 0$.
Fin.val_add_one theorem
{n : Nat} (i : Fin (n + 1)) : ((i + 1 : Fin (n + 1)) : Nat) = if i = last _ then (0 : Nat) else i + 1
Full source
theorem val_add_one {n : Nat} (i : Fin (n + 1)) :
    ((i + 1 : Fin (n + 1)) : Nat) = if i = last _ then (0 : Nat) else i + 1 := by
  match Nat.eq_or_lt_of_le (le_last i) with
  | .inl h => cases Fin.eq_of_val_eq h; simp
  | .inr h => simpa [Fin.ne_of_lt h] using val_add_one_of_lt h
Value of Successor in Finite Type: $(i + 1).\text{val} = \text{if } i = \text{last}(n) \text{ then } 0 \text{ else } i + 1$
Informal description
For any natural number $n$ and any element $i$ of the finite type $\mathrm{Fin}(n+1)$, the underlying natural number value of $i + 1$ is equal to $0$ if $i$ is the last element of $\mathrm{Fin}(n+1)$, and $i + 1$ otherwise. That is, $$(i + 1).\text{val} = \begin{cases} 0 & \text{if } i = \text{last}(n), \\ i + 1 & \text{otherwise.} \end{cases}$$
Fin.val_two theorem
{n : Nat} : (2 : Fin (n + 3)).val = 2
Full source
@[simp] theorem val_two {n : Nat} : (2 : Fin (n + 3)).val = 2 := rfl
Value of Two in Finite Type $\text{Fin}(n+3)$
Informal description
For any natural number $n$, the underlying natural number value of the element $2$ in the finite type $\text{Fin}(n+3)$ is equal to $2$.
Fin.add_one_pos theorem
(i : Fin (n + 1)) (h : i < Fin.last n) : (0 : Fin (n + 1)) < i + 1
Full source
theorem add_one_pos (i : Fin (n + 1)) (h : i < Fin.last n) : (0 : Fin (n + 1)) < i + 1 := by
  match n with
  | 0 => cases h
  | n+1 =>
    rw [Fin.lt_def, val_last, ← Nat.add_lt_add_iff_right] at h
    rw [Fin.lt_def, val_add, val_zero, val_one, Nat.mod_eq_of_lt h]
    exact Nat.zero_lt_succ _
Positivity of Successor in Finite Types: $0 < i + 1$ when $i < \mathrm{last}\,n$
Informal description
For any element $i$ of the finite type $\mathrm{Fin}(n+1)$ (natural numbers less than $n+1$) such that $i$ is less than the last element $\mathrm{last}\,n$, the element $0$ is strictly less than $i + 1$ in $\mathrm{Fin}(n+1)$.
Fin.one_pos theorem
: (0 : Fin (n + 2)) < 1
Full source
theorem one_pos : (0 : Fin (n + 2)) < 1 := Nat.succ_pos 0
Positivity of One in $\mathrm{Fin}(n+2)$: $0 < 1$
Informal description
For any natural number $n$, the element $0$ is strictly less than $1$ in the finite type $\mathrm{Fin}(n+2)$.
Fin.zero_ne_one theorem
: (0 : Fin (n + 2)) ≠ 1
Full source
theorem zero_ne_one : (0 : Fin (n + 2)) ≠ 1 := Fin.ne_of_lt one_pos
Non-Equality of Zero and One in $\mathrm{Fin}(n+2)$
Informal description
For any natural number $n$, the elements $0$ and $1$ in the finite type $\mathrm{Fin}(n+2)$ are distinct, i.e., $0 \neq 1$.
Fin.val_succ theorem
(j : Fin n) : (j.succ : Nat) = j + 1
Full source
@[simp] theorem val_succ (j : Fin n) : (j.succ : Nat) = j + 1 := rfl
Successor in $\text{Fin}\,n$ corresponds to addition by one in $\mathbb{N}$
Informal description
For any element $j$ of the finite type $\text{Fin}\,n$, the natural number corresponding to its successor $j.\text{succ}$ is equal to $j + 1$.
Fin.succ_pos theorem
(a : Fin n) : (0 : Fin (n + 1)) < a.succ
Full source
@[simp] theorem succ_pos (a : Fin n) : (0 : Fin (n + 1)) < a.succ := by
  simp [Fin.lt_def, Nat.succ_pos]
Successor in $\mathrm{Fin}\,n$ is strictly positive
Informal description
For any element $a$ of the finite type $\mathrm{Fin}\,n$, the successor of $a$ in $\mathrm{Fin}\,(n + 1)$ is strictly greater than zero, i.e., $0 < a.\mathrm{succ}$.
Fin.succ_le_succ_iff theorem
{a b : Fin n} : a.succ ≤ b.succ ↔ a ≤ b
Full source
@[simp] theorem succ_le_succ_iff {a b : Fin n} : a.succ ≤ b.succ ↔ a ≤ b := Nat.succ_le_succ_iff
Order Preservation of Successor in Finite Types: $a.\mathrm{succ} \leq b.\mathrm{succ} \leftrightarrow a \leq b$
Informal description
For any two elements $a, b$ in $\mathrm{Fin}\,n$, the successor of $a$ is less than or equal to the successor of $b$ if and only if $a$ is less than or equal to $b$.
Fin.succ_lt_succ_iff theorem
{a b : Fin n} : a.succ < b.succ ↔ a < b
Full source
@[simp] theorem succ_lt_succ_iff {a b : Fin n} : a.succ < b.succ ↔ a < b := Nat.succ_lt_succ_iff
Successor Preserves Strict Order in Finite Types
Informal description
For any two elements $a, b$ in $\mathrm{Fin}\,n$, the successor of $a$ is less than the successor of $b$ if and only if $a$ is less than $b$.
Fin.succ_inj theorem
{a b : Fin n} : a.succ = b.succ ↔ a = b
Full source
@[simp] theorem succ_inj {a b : Fin n} : a.succ = b.succ ↔ a = b := by
  refine ⟨fun h => Fin.ext ?_, congrArg _⟩
  apply Nat.le_antisymm <;> exact succ_le_succ_iff.1 (h ▸ Nat.le_refl _)
Injectivity of Successor in Finite Types: $a.\mathrm{succ} = b.\mathrm{succ} \leftrightarrow a = b$
Informal description
For any two elements $a, b$ in $\mathrm{Fin}\,n$, the successor of $a$ equals the successor of $b$ if and only if $a = b$.
Fin.succ_ne_zero theorem
{n} : ∀ k : Fin n, Fin.succ k ≠ 0
Full source
theorem succ_ne_zero {n} : ∀ k : Fin n, Fin.succFin.succ k ≠ 0
  | ⟨k, _⟩, heq => Nat.succ_ne_zero k <| congrArg Fin.val heq
Successor of Finite Number is Nonzero
Informal description
For any natural number $n$ and any element $k$ in $\mathrm{Fin}\,n$, the successor of $k$ is not equal to zero.
Fin.succ_zero_eq_one theorem
: Fin.succ (0 : Fin (n + 1)) = 1
Full source
@[simp] theorem succ_zero_eq_one : Fin.succ (0 : Fin (n + 1)) = 1 := rfl
Successor of Zero in Finite Type Equals One
Informal description
For any natural number $n$, the successor of $0$ in $\mathrm{Fin}(n+1)$ is equal to $1$.
Fin.succ_one_eq_two theorem
: Fin.succ (1 : Fin (n + 2)) = 2
Full source
/-- Version of `succ_one_eq_two` to be used by `dsimp` -/
@[simp] theorem succ_one_eq_two : Fin.succ (1 : Fin (n + 2)) = 2 := rfl
Successor of One in Fin(n+2) is Two
Informal description
For any natural number $n$, the successor of the element $1$ in the finite type $\mathrm{Fin}(n+2)$ is equal to $2$.
Fin.succ_mk theorem
(n i : Nat) (h : i < n) : Fin.succ ⟨i, h⟩ = ⟨i + 1, Nat.succ_lt_succ h⟩
Full source
@[simp] theorem succ_mk (n i : Nat) (h : i < n) :
    Fin.succ ⟨i, h⟩ = ⟨i + 1, Nat.succ_lt_succ h⟩ := rfl
Successor of Fin Element Preserves Order
Informal description
For any natural numbers $n$ and $i$ with $i < n$, the successor of the element $\langle i, h \rangle$ in $\mathrm{Fin}\,n$ is equal to $\langle i+1, h' \rangle$, where $h'$ is the proof that $i+1 < n$ derived from $h$ via the natural number successor operation.
Fin.mk_succ_pos theorem
(i : Nat) (h : i < n) : (0 : Fin (n + 1)) < ⟨i.succ, Nat.add_lt_add_right h 1⟩
Full source
theorem mk_succ_pos (i : Nat) (h : i < n) :
    (0 : Fin (n + 1)) < ⟨i.succ, Nat.add_lt_add_right h 1⟩ := by
  rw [lt_def, val_zero]; exact Nat.succ_pos i
Positivity of Successor in Finite Types: $0 < i+1$ in $\mathrm{Fin}(n+1)$
Informal description
For any natural numbers $i$ and $n$ with $i < n$, the zero element in $\mathrm{Fin}(n+1)$ is strictly less than the element $\langle i+1, h' \rangle$, where $h'$ is the proof that $i+1 < n+1$ obtained by adding 1 to both sides of the inequality $h : i < n$.
Fin.one_lt_succ_succ theorem
(a : Fin n) : (1 : Fin (n + 2)) < a.succ.succ
Full source
theorem one_lt_succ_succ (a : Fin n) : (1 : Fin (n + 2)) < a.succ.succ := by
  let n+1 := n
  rw [← succ_zero_eq_one, succ_lt_succ_iff]; exact succ_pos a
Double Successor in $\mathrm{Fin}\,n$ Exceeds One: $1 < a.\mathrm{succ}.\mathrm{succ}$
Informal description
For any element $a$ in the finite type $\mathrm{Fin}\,n$, the value $1$ in $\mathrm{Fin}\,(n + 2)$ is strictly less than the double successor of $a$, i.e., $1 < a.\mathrm{succ}.\mathrm{succ}$.
Fin.add_one_lt_iff theorem
{n : Nat} {k : Fin (n + 2)} : k + 1 < k ↔ k = last _
Full source
@[simp] theorem add_one_lt_iff {n : Nat} {k : Fin (n + 2)} : k + 1 < k ↔ k = last _ := by
  simp only [lt_def, val_add, val_last, Fin.ext_iff]
  let ⟨k, hk⟩ := k
  match Nat.eq_or_lt_of_le (Nat.le_of_lt_succ hk) with
  | .inl h => cases h; simp [Nat.succ_pos]
  | .inr hk' => simp [Nat.ne_of_lt hk', Nat.mod_eq_of_lt (Nat.succ_lt_succ hk'), Nat.le_succ]
Characterization of when adding one reverses order in $\mathrm{Fin}(n+2)$: $k + 1 < k \leftrightarrow k = \mathrm{last}(n+1)$
Informal description
For any natural number $n$ and any element $k$ of the finite type $\mathrm{Fin}(n+2)$, the inequality $k + 1 < k$ holds if and only if $k$ is the last element of $\mathrm{Fin}(n+1)$.
Fin.add_one_le_iff theorem
{n : Nat} : ∀ {k : Fin (n + 1)}, k + 1 ≤ k ↔ k = last _
Full source
@[simp] theorem add_one_le_iff {n : Nat} : ∀ {k : Fin (n + 1)}, k + 1 ≤ k ↔ k = last _ := by
  match n with
  | 0 =>
    intro (k : Fin 1)
    exact iff_of_true (Subsingleton.elim (α := Fin 1) (k+1) _ ▸ Nat.le_refl _) (fin_one_eq_zero ..)
  | n + 1 =>
    intro (k : Fin (n+2))
    rw [← add_one_lt_iff, lt_def, le_def, Nat.lt_iff_le_and_ne, and_iff_left]
    rw [val_add_one]
    split <;> simp [*, (Nat.succ_ne_zero _).symm, Nat.ne_of_gt (Nat.lt_succ_self _)]
Characterization of Last Element via Successor Inequality in $\mathrm{Fin}(n+1)$: $k + 1 \leq k \leftrightarrow k = \mathrm{last}(n)$
Informal description
For any natural number $n$ and any element $k$ in the finite type $\mathrm{Fin}(n+1)$, the inequality $k + 1 \leq k$ holds if and only if $k$ is the last element of $\mathrm{Fin}(n+1)$ (i.e., $k$ has value $n$).
Fin.last_le_iff theorem
{n : Nat} {k : Fin (n + 1)} : last n ≤ k ↔ k = last n
Full source
@[simp] theorem last_le_iff {n : Nat} {k : Fin (n + 1)} : lastlast n ≤ k ↔ k = last n := by
  rw [Fin.ext_iff, Nat.le_antisymm_iff, le_def, and_iff_right (by apply le_last)]
Characterization of Last Element in Finite Types: $\mathrm{last}(n) \leq k \leftrightarrow k = \mathrm{last}(n)$
Informal description
For any natural number $n$ and any element $k$ in the finite type $\mathrm{Fin}(n+1)$ (i.e., $k$ is a natural number with $k < n+1$), the inequality $\mathrm{last}(n) \leq k$ holds if and only if $k$ is equal to $\mathrm{last}(n)$, where $\mathrm{last}(n)$ denotes the largest element in $\mathrm{Fin}(n+1)$ (which has value $n$).
Fin.lt_add_one_iff theorem
{n : Nat} {k : Fin (n + 1)} : k < k + 1 ↔ k < last n
Full source
@[simp] theorem lt_add_one_iff {n : Nat} {k : Fin (n + 1)} : k < k + 1 ↔ k < last n := by
  rw [← Decidable.not_iff_not]; simp
Inequality Characterization in Finite Types: $k < k + 1 \leftrightarrow k < \mathrm{last}(n)$
Informal description
For any natural number $n$ and any element $k$ in the finite type $\mathrm{Fin}(n+1)$ (i.e., $k$ is a natural number with $k < n+1$), the inequality $k < k + 1$ holds if and only if $k$ is strictly less than the last element $\mathrm{last}(n)$ (which has value $n$).
Fin.le_zero_iff theorem
{n : Nat} {k : Fin (n + 1)} : k ≤ 0 ↔ k = 0
Full source
@[simp] theorem le_zero_iff {n : Nat} {k : Fin (n + 1)} : k ≤ 0 ↔ k = 0 :=
  ⟨fun h => Fin.eq_of_val_eq <| Nat.eq_zero_of_le_zero h, (· ▸ Nat.le_refl _)⟩
Characterization of Zero in Finite Types: $k \leq 0 \leftrightarrow k = 0$ in $\mathrm{Fin}(n+1)$
Informal description
For any natural number $n$ and any element $k$ of the finite type $\mathrm{Fin}(n+1)$ (i.e., a natural number $k < n+1$), the inequality $k \leq 0$ holds if and only if $k = 0$.
Fin.succ_succ_ne_one theorem
(a : Fin n) : Fin.succ (Fin.succ a) ≠ 1
Full source
theorem succ_succ_ne_one (a : Fin n) : Fin.succFin.succ (Fin.succ a) ≠ 1 :=
  Fin.ne_of_gt (one_lt_succ_succ a)
Double Successor in $\mathrm{Fin}\,n$ is Not One
Informal description
For any element $a$ in the finite type $\mathrm{Fin}\,n$, the double successor of $a$ is not equal to $1$, i.e., $\mathrm{succ}(\mathrm{succ}(a)) \neq 1$.
Fin.coe_castLT theorem
(i : Fin m) (h : i.1 < n) : (castLT i h : Nat) = i
Full source
@[simp] theorem coe_castLT (i : Fin m) (h : i.1 < n) : (castLT i h : Nat) = i := rfl
Natural Number Preservation under Finite Type Casting ($\text{castLT}$)
Informal description
For any element $i$ of the finite type $\text{Fin}\,m$ (i.e., a natural number $i < m$) and any proof $h$ that the underlying natural number $i.1$ is less than $n$, the natural number obtained by casting $i$ to $\text{Fin}\,n$ via $\text{castLT}\,i\,h$ is equal to $i.1$.
Fin.castLT_mk theorem
(i n m : Nat) (hn : i < n) (hm : i < m) : castLT ⟨i, hn⟩ hm = ⟨i, hm⟩
Full source
@[simp] theorem castLT_mk (i n m : Nat) (hn : i < n) (hm : i < m) : castLT ⟨i, hn⟩ hm = ⟨i, hm⟩ :=
  rfl
Cast Preservation of Finite Elements with Different Bounds
Informal description
For natural numbers $i$, $n$, and $m$ with $i < n$ and $i < m$, the cast operation $\text{castLT}$ applied to the element $\langle i, hn \rangle$ of $\text{Fin}\,n$ (where $hn$ is a proof that $i < n$) and a proof $hm$ that $i < m$ yields the element $\langle i, hm \rangle$ of $\text{Fin}\,m$. In other words, when casting an element from $\text{Fin}\,n$ to $\text{Fin}\,m$ (where the underlying natural number $i$ satisfies both bounds), the result is the same element but with the new bound proof $hm$.
Fin.coe_castLE theorem
(h : n ≤ m) (i : Fin n) : (castLE h i : Nat) = i
Full source
@[simp] theorem coe_castLE (h : n ≤ m) (i : Fin n) : (castLE h i : Nat) = i := rfl
Natural Number Preservation under Finite Type Casting ($\text{castLE}$)
Informal description
For any natural numbers $n$ and $m$ with $n \leq m$, and any element $i$ of the finite type $\text{Fin}\,n$ (i.e., a natural number $i < n$), the natural number obtained by casting $i$ to $\text{Fin}\,m$ via $\text{castLE}\,h\,i$ is equal to $i$ itself.
Fin.castLE_mk theorem
(i n m : Nat) (hn : i < n) (h : n ≤ m) : castLE h ⟨i, hn⟩ = ⟨i, Nat.lt_of_lt_of_le hn h⟩
Full source
@[simp] theorem castLE_mk (i n m : Nat) (hn : i < n) (h : n ≤ m) :
    castLE h ⟨i, hn⟩ = ⟨i, Nat.lt_of_lt_of_le hn h⟩ := rfl
Cast of Finite Natural Number Preserves Value Under Weakening of Upper Bound
Informal description
For any natural numbers $i$, $n$, and $m$ such that $i < n$ and $n \leq m$, the cast of the element $\langle i, hn \rangle$ (where $hn$ is a proof that $i < n$) from $\text{Fin}\,n$ to $\text{Fin}\,m$ via $\text{castLE}\,h$ is equal to $\langle i, \text{Nat.lt\_of\_lt\_of\_le}\,hn\,h \rangle$, where the latter is a proof that $i < m$ derived from $i < n$ and $n \leq m$.
Fin.castLE_zero theorem
{n m : Nat} (h : n.succ ≤ m.succ) : castLE h 0 = 0
Full source
@[simp] theorem castLE_zero {n m : Nat} (h : n.succ ≤ m.succ) : castLE h 0 = 0 := by simp [Fin.ext_iff]
Preservation of Zero under Order-Preserving Embedding of Finite Types
Informal description
For any natural numbers $n$ and $m$ such that $n + 1 \leq m + 1$, the order-preserving embedding $\mathrm{castLE}\,h$ maps the zero element of $\mathrm{Fin}\,(n+1)$ to the zero element of $\mathrm{Fin}\,(m+1)$, i.e., $\mathrm{castLE}\,h\,0 = 0$.
Fin.castLE_succ theorem
{m n : Nat} (h : m + 1 ≤ n + 1) (i : Fin m) : castLE h i.succ = (castLE (Nat.succ_le_succ_iff.mp h) i).succ
Full source
@[simp] theorem castLE_succ {m n : Nat} (h : m + 1 ≤ n + 1) (i : Fin m) :
    castLE h i.succ = (castLE (Nat.succ_le_succ_iff.mp h) i).succ := by simp [Fin.ext_iff]
Successor Commutes with Order-Preserving Embedding for Finite Types
Informal description
For any natural numbers $m$ and $n$ such that $m + 1 \leq n + 1$, and for any element $i \in \mathrm{Fin}\,m$, the order-preserving embedding $\mathrm{castLE}\,h$ applied to the successor of $i$ is equal to the successor of $\mathrm{castLE}\,h'\,i$, where $h'$ is the condition $m \leq n$ derived from $h$ via the equivalence of successor inequalities.
Fin.castLE_castLE theorem
{k m n} (km : k ≤ m) (mn : m ≤ n) (i : Fin k) : Fin.castLE mn (Fin.castLE km i) = Fin.castLE (Nat.le_trans km mn) i
Full source
@[simp] theorem castLE_castLE {k m n} (km : k ≤ m) (mn : m ≤ n) (i : Fin k) :
    Fin.castLE mn (Fin.castLE km i) = Fin.castLE (Nat.le_trans km mn) i :=
  Fin.ext (by simp only [coe_castLE])
Composition of Order-Preserving Embeddings for Finite Types
Informal description
For any natural numbers $k$, $m$, and $n$ such that $k \leq m$ and $m \leq n$, and for any element $i \in \mathrm{Fin}\,k$, the composition of the order-preserving embeddings $\mathrm{castLE}_{mn} \circ \mathrm{castLE}_{km}$ applied to $i$ is equal to the direct order-preserving embedding $\mathrm{castLE}_{(k \leq n)}$ applied to $i$, where $(k \leq n)$ is obtained by transitivity from $k \leq m$ and $m \leq n$.
Fin.castLE_comp_castLE theorem
{k m n} (km : k ≤ m) (mn : m ≤ n) : Fin.castLE mn ∘ Fin.castLE km = Fin.castLE (Nat.le_trans km mn)
Full source
@[simp] theorem castLE_comp_castLE {k m n} (km : k ≤ m) (mn : m ≤ n) :
    Fin.castLEFin.castLE mn ∘ Fin.castLE km = Fin.castLE (Nat.le_trans km mn) :=
  funext (castLE_castLE km mn)
Composition of Order-Preserving Embeddings for Finite Types Equals Direct Embedding
Informal description
For any natural numbers $k$, $m$, and $n$ such that $k \leq m$ and $m \leq n$, the composition of the order-preserving embeddings $\mathrm{castLE}_{mn} \circ \mathrm{castLE}_{km}$ is equal to the direct order-preserving embedding $\mathrm{castLE}_{(k \leq n)}$, where $(k \leq n)$ is obtained by transitivity from $k \leq m$ and $m \leq n$.
Fin.coe_cast theorem
(h : n = m) (i : Fin n) : (i.cast h : Nat) = i
Full source
@[simp] theorem coe_cast (h : n = m) (i : Fin n) : (i.cast h : Nat) = i := rfl
Natural Number Casting Preserves Value in Finite Types
Informal description
For any natural numbers $n$ and $m$ with $n = m$, and for any element $i$ of the finite type $\text{Fin }n$, the natural number obtained by casting $i$ to $\text{Fin }m$ via the equality $h$ is equal to $i$ itself, i.e., $(i.\text{cast }h : \mathbb{N}) = i$.
Fin.cast_zero theorem
[NeZero n] [NeZero m] (h : n = m) : Fin.cast h 0 = 0
Full source
@[simp] theorem cast_zero [NeZero n] [NeZero m] (h : n = m) : Fin.cast h 0 = 0 := rfl
Preservation of Zero under Casting in Finite Types
Informal description
For any positive natural numbers $n$ and $m$ (i.e., $n \neq 0$ and $m \neq 0$) and an equality proof $h : n = m$, casting the zero element of $\text{Fin }n$ to $\text{Fin }m$ via $h$ yields the zero element of $\text{Fin }m$, i.e., $\text{cast }h\ 0 = 0$.
Fin.cast_last theorem
{n' : Nat} {h : n + 1 = n' + 1} : (last n).cast h = last n'
Full source
@[simp] theorem cast_last {n' : Nat} {h : n + 1 = n' + 1} : (last n).cast h  = last n' :=
  Fin.ext (by rw [coe_cast, val_last, val_last, Nat.succ.inj h])
Casting Preserves Last Element in Finite Types
Informal description
For any natural numbers $n$ and $n'$ with an equality proof $h : n + 1 = n' + 1$, casting the last element of $\text{Fin}(n+1)$ to $\text{Fin}(n'+1)$ via $h$ yields the last element of $\text{Fin}(n'+1)$.
Fin.cast_mk theorem
(h : n = m) (i : Nat) (hn : i < n) : Fin.cast h ⟨i, hn⟩ = ⟨i, h ▸ hn⟩
Full source
@[simp] theorem cast_mk (h : n = m) (i : Nat) (hn : i < n) : Fin.cast h ⟨i, hn⟩ = ⟨i, h ▸ hn⟩ := rfl
Preservation of Finite Type Elements under Casting
Informal description
For natural numbers $n$ and $m$ with an equality proof $h : n = m$, and for any natural number $i < n$, casting the element $\langle i, hn \rangle$ of $\text{Fin }n$ to $\text{Fin }m$ via $h$ yields the element $\langle i, h \cdot hn \rangle$ of $\text{Fin }m$, where $h \cdot hn$ is the proof that $i < m$ obtained by substituting $h$ into $hn$.
Fin.cast_refl theorem
(n : Nat) (h : n = n) : Fin.cast h = id
Full source
@[simp] theorem cast_refl (n : Nat) (h : n = n) : Fin.cast h = id := by
  ext
  simp
Identity Cast for Finite Types: $\mathrm{Fin.cast}\,h = \mathrm{id}$ when $n = n$
Informal description
For any natural number $n$ and equality proof $h : n = n$, the cast operation $\mathrm{Fin.cast}\,h$ from $\mathrm{Fin}\,n$ to itself is equal to the identity function.
Fin.cast_trans theorem
{k : Nat} (h : n = m) (h' : m = k) {i : Fin n} : (i.cast h).cast h' = i.cast (Eq.trans h h')
Full source
@[simp] theorem cast_trans {k : Nat} (h : n = m) (h' : m = k) {i : Fin n} :
    (i.cast h).cast h' = i.cast (Eq.trans h h') := rfl
Transitivity of Finite Type Casts
Informal description
For natural numbers $n$, $m$, and $k$, given equalities $h : n = m$ and $h' : m = k$, and for any element $i$ of the finite type $\text{Fin }n$, the composition of the cast operations $\text{Fin.cast }h$ followed by $\text{Fin.cast }h'$ applied to $i$ is equal to the single cast operation $\text{Fin.cast }(\text{Eq.trans }h h')$ applied to $i$. In other words, $(i.\text{cast }h).\text{cast }h' = i.\text{cast }(h \circ h')$.
Fin.castLE_of_eq theorem
{m n : Nat} (h : m = n) {h' : m ≤ n} : castLE h' = Fin.cast h
Full source
theorem castLE_of_eq {m n : Nat} (h : m = n) {h' : m ≤ n} : castLE h' = Fin.cast h := rfl
Equality of Cast Operations for Finite Types with Equal Bounds
Informal description
For natural numbers $m$ and $n$ with $m = n$ and $m \leq n$, the cast operation `castLE` (which casts elements of `Fin m` to `Fin n` using the inequality proof $h'$) is equal to the cast operation `Fin.cast` (which casts elements of `Fin m` to `Fin n` using the equality proof $h$).
Fin.coe_castAdd theorem
(m : Nat) (i : Fin n) : (castAdd m i : Nat) = i
Full source
@[simp] theorem coe_castAdd (m : Nat) (i : Fin n) : (castAdd m i : Nat) = i := rfl
Coercion of `castAdd` Preserves Natural Number Value
Informal description
For any natural number $m$ and any element $i$ of the finite type $\text{Fin }n$, the natural number obtained by coercing the result of the `castAdd` operation (which adds $m$ to the bound of $\text{Fin }n$) applied to $i$ is equal to the natural number corresponding to $i$ itself. In other words, $(\text{castAdd }m\ i) = i$ when viewed as natural numbers.
Fin.castAdd_zero theorem
: (castAdd 0 : Fin n → Fin (n + 0)) = Fin.cast rfl
Full source
@[simp] theorem castAdd_zero : (castAdd 0 : Fin n → Fin (n + 0)) = Fin.cast rfl := rfl
Equality of Zero Cast Addition and Identity Cast for Finite Types
Informal description
For any natural number $n$, the function `castAdd 0` that maps elements from `Fin n` to `Fin (n + 0)` is equal to the cast function `Fin.cast` applied to the reflexivity proof `rfl : n = n + 0`.
Fin.castAdd_lt theorem
{m : Nat} (n : Nat) (i : Fin m) : (castAdd n i : Nat) < m
Full source
theorem castAdd_lt {m : Nat} (n : Nat) (i : Fin m) : (castAdd n i : Nat) < m := by simp
Boundedness under $\text{castAdd}$ in $\text{Fin}$ types
Informal description
For any natural numbers $m$ and $n$, and any element $i$ of $\text{Fin}\, m$ (i.e., a natural number $i$ with $i < m$), the natural number obtained by casting $i$ via $\text{castAdd}\, n$ satisfies $(\text{castAdd}\, n\, i) < m$.
Fin.castAdd_mk theorem
(m : Nat) (i : Nat) (h : i < n) : castAdd m ⟨i, h⟩ = ⟨i, Nat.lt_add_right m h⟩
Full source
@[simp] theorem castAdd_mk (m : Nat) (i : Nat) (h : i < n) :
    castAdd m ⟨i, h⟩ = ⟨i, Nat.lt_add_right m h⟩ := rfl
CastAdd Preserves Value with Extended Upper Bound
Informal description
For any natural numbers $m$, $i$, and $n$, if $i < n$, then the operation `castAdd m` applied to the finite natural number $\langle i, h \rangle$ (where $h$ is a proof that $i < n$) yields $\langle i, k \rangle$, where $k$ is a proof that $i < n + m$ obtained via `Nat.lt_add_right m h`.
Fin.castAdd_castLT theorem
(m : Nat) (i : Fin (n + m)) (hi : i.val < n) : castAdd m (castLT i hi) = i
Full source
@[simp] theorem castAdd_castLT (m : Nat) (i : Fin (n + m)) (hi : i.val < n) :
    castAdd m (castLT i hi) = i := rfl
Compatibility of `castAdd` and `castLT` for Fin types
Informal description
Let $m$ be a natural number, and let $i$ be an element of $\text{Fin}(n + m)$ such that the underlying natural number $i.\text{val}$ is less than $n$. Then, the operation $\text{castAdd}\, m$ applied to the cast $\text{castLT}\, i\, \text{hi}$ (where $\text{hi}$ is the proof that $i.\text{val} < n$) returns $i$ itself.
Fin.castLT_castAdd theorem
(m : Nat) (i : Fin n) : castLT (castAdd m i) (castAdd_lt m i) = i
Full source
@[simp] theorem castLT_castAdd (m : Nat) (i : Fin n) :
    castLT (castAdd m i) (castAdd_lt m i) = i := rfl
Inversion Property of $\text{castAdd}$ and $\text{castLT}$ for Finite Types
Informal description
For any natural numbers $m$ and $n$, and any element $i$ of $\text{Fin}\,n$, the composition of the operations $\text{castAdd}\,m$ followed by $\text{castLT}$ (with proof $\text{castAdd\_lt}\,m\,i$) returns $i$ itself. In symbols: $\text{castLT}\,(\text{castAdd}\,m\,i)\,(\text{castAdd\_lt}\,m\,i) = i$.
Fin.castAdd_cast theorem
{n n' : Nat} (m : Nat) (i : Fin n') (h : n' = n) : castAdd m (Fin.cast h i) = Fin.cast (congrArg (. + m) h) (castAdd m i)
Full source
/-- For rewriting in the reverse direction, see `Fin.cast_castAdd_left`. -/
theorem castAdd_cast {n n' : Nat} (m : Nat) (i : Fin n') (h : n' = n) :
    castAdd m (Fin.cast h i) = Fin.cast (congrArg (. + m) h) (castAdd m i) := Fin.ext rfl
Commutativity of Cast and Addition in Finite Types
Informal description
For natural numbers $n$, $n'$, and $m$, and an element $i \in \mathrm{Fin}\,n'$, if $n' = n$, then the operation of first casting $i$ to $\mathrm{Fin}\,n$ and then adding $m$ is equal to first adding $m$ to $i$ and then casting the result with respect to the equality $n' + m = n + m$. In symbols: $$\mathrm{castAdd}\,m\,(\mathrm{Fin.cast}\,h\,i) = \mathrm{Fin.cast}\,(\mathrm{congrArg}\,(\cdot + m)\,h)\,(\mathrm{castAdd}\,m\,i)$$
Fin.cast_castAdd_left theorem
{n n' m : Nat} (i : Fin n') (h : n' + m = n + m) : (i.castAdd m).cast h = (i.cast (Nat.add_right_cancel h)).castAdd m
Full source
theorem cast_castAdd_left {n n' m : Nat} (i : Fin n') (h : n' + m = n + m) :
    (i.castAdd m).cast h = (i.cast (Nat.add_right_cancel h)).castAdd m := rfl
Commutativity of Cast and CastAdd Operations on Finite Natural Numbers
Informal description
Let $n, n', m$ be natural numbers, and let $i$ be an element of $\text{Fin}(n')$. Given an equality $h : n' + m = n + m$, the composition of the cast operation $\text{castAdd}(m)$ followed by $\text{cast}(h)$ on $i$ is equal to the composition of $\text{cast}(\text{Nat.add\_right\_cancel}(h))$ followed by $\text{castAdd}(m)$ on $i$.
Fin.cast_castAdd_right theorem
{n m m' : Nat} (i : Fin n) (h : n + m' = n + m) : (i.castAdd m').cast h = i.castAdd m
Full source
@[simp] theorem cast_castAdd_right {n m m' : Nat} (i : Fin n) (h : n + m' = n + m) :
    (i.castAdd m').cast h = i.castAdd m := rfl
Right Casting Invariance under Addition Adjustment in Finite Types
Informal description
For any natural numbers $n, m, m'$ and any $i \in \mathrm{Fin}(n)$, if $n + m' = n + m$, then casting the element $(i.\mathrm{castAdd} m')$ along the equality $h$ yields the same result as directly applying $\mathrm{castAdd} m$ to $i$.
Fin.castAdd_castAdd theorem
{m n p : Nat} (i : Fin m) : (i.castAdd n).castAdd p = (i.castAdd (n + p)).cast (Nat.add_assoc ..).symm
Full source
theorem castAdd_castAdd {m n p : Nat} (i : Fin m) :
    (i.castAdd n).castAdd p = (i.castAdd (n + p)).cast (Nat.add_assoc ..).symm  := rfl
Associativity of Cast Addition on Finite Types: $(i + n) + p = i + (n + p)$
Informal description
For any natural numbers $m$, $n$, $p$ and any $i \in \text{Fin}\, m$, the following equality holds: $$(i + n) + p = (i + (n + p))$$ where the addition operations are the canonical cast additions on finite types, and the equality is modulo the associativity of natural number addition.
Fin.cast_succ_eq theorem
{n' : Nat} (i : Fin n) (h : n.succ = n'.succ) : i.succ.cast h = (i.cast (Nat.succ.inj h)).succ
Full source
/-- The cast of the successor is the successor of the cast. See `Fin.succ_cast_eq` for rewriting in
the reverse direction. -/
@[simp] theorem cast_succ_eq {n' : Nat} (i : Fin n) (h : n.succ = n'.succ) :
    i.succ.cast h = (i.cast (Nat.succ.inj h)).succ := rfl
Commutativity of Successor and Cast in Finite Types
Informal description
Let $n$ and $n'$ be natural numbers, and let $i$ be an element of $\text{Fin } n$. Given a proof $h$ that $n + 1 = n' + 1$, the cast of the successor of $i$ under $h$ is equal to the successor of the cast of $i$ under the proof that $n = n'$ (which follows from injectivity of the successor function on natural numbers).
Fin.succ_cast_eq theorem
{n' : Nat} (i : Fin n) (h : n = n') : (i.cast h).succ = i.succ.cast (by rw [h])
Full source
theorem succ_cast_eq {n' : Nat} (i : Fin n) (h : n = n') :
    (i.cast h).succ = i.succ.cast (by rw [h]) := rfl
Equality between successor and cast operations on finite types
Informal description
For any natural numbers $n$ and $n'$, given an element $i$ of $\text{Fin}\ n$ and a proof $h$ that $n = n'$, the successor of the cast of $i$ to $\text{Fin}\ n'$ via $h$ is equal to the cast of the successor of $i$ to $\text{Fin}\ n'$ via the proof obtained by rewriting with $h$. In other words: $$(\text{cast}\ h\ i).\text{succ} = \text{cast}\ (\text{by rw [h]})\ (i.\text{succ})$$
Fin.coe_castSucc theorem
(i : Fin n) : (i.castSucc : Nat) = i
Full source
@[simp] theorem coe_castSucc (i : Fin n) : (i.castSucc : Nat) = i := rfl
Natural Number Preservation under `castSucc` in Finite Types
Informal description
For any element $i$ of the finite type $\text{Fin }n$ (natural numbers less than $n$), the natural number obtained by casting $i$ to $\text{Fin }(n+1)$ via the `castSucc` operation is equal to $i$ itself when viewed as a natural number.
Fin.castSucc_mk theorem
(n i : Nat) (h : i < n) : castSucc ⟨i, h⟩ = ⟨i, Nat.lt.step h⟩
Full source
@[simp] theorem castSucc_mk (n i : Nat) (h : i < n) : castSucc ⟨i, h⟩ = ⟨i, Nat.lt.step h⟩ := rfl
Cast of Successor Preserves Fin Element Construction
Informal description
For any natural numbers $n$ and $i$ with $i < n$, the cast of the successor operation applied to the element $\langle i, h \rangle$ of $\text{Fin } n$ (where $h$ is the proof that $i < n$) equals $\langle i, \text{Nat.lt.step } h \rangle$ in $\text{Fin } (n+1)$.
Fin.cast_castSucc theorem
{n' : Nat} {h : n + 1 = n' + 1} {i : Fin n} : i.castSucc.cast h = (i.cast (Nat.succ.inj h)).castSucc
Full source
@[simp] theorem cast_castSucc {n' : Nat} {h : n + 1 = n' + 1} {i : Fin n} :
    i.castSucc.cast h = (i.cast (Nat.succ.inj h)).castSucc := rfl
Commutativity of Cast and CastSucc for Finite Types
Informal description
Let $n$ and $n'$ be natural numbers such that $n + 1 = n' + 1$, and let $i$ be an element of $\text{Fin}~n$. Then the cast of $i.\text{castSucc}$ along the equality $h : n + 1 = n' + 1$ is equal to the cast of $i$ along the equality $\text{Nat.succ.inj}~h : n = n'$, followed by $\text{castSucc}$. In other words, the following diagram commutes: \[ \begin{CD} \text{Fin}~n @>{\text{castSucc}}>> \text{Fin}~(n+1) \\ @V{\text{cast}~(\text{Nat.succ.inj}~h)}VV @VV{\text{cast}~h}V \\ \text{Fin}~n' @>>{\text{castSucc}}> \text{Fin}~(n'+1) \end{CD} \]
Fin.castSucc_lt_succ theorem
(i : Fin n) : i.castSucc < i.succ
Full source
theorem castSucc_lt_succ (i : Fin n) : i.castSucc < i.succ :=
  lt_def.2 <| by simp only [coe_castSucc, val_succ, Nat.lt_succ_self]
Cast Successor is Less Than Successor in Finite Types
Informal description
For any element $i$ of the finite type $\mathrm{Fin}\,n$ (representing natural numbers less than $n$), the cast successor of $i$ is strictly less than the successor of $i$ in $\mathrm{Fin}\,(n+1)$.
Fin.le_castSucc_iff theorem
{i : Fin (n + 1)} {j : Fin n} : i ≤ j.castSucc ↔ i < j.succ
Full source
theorem le_castSucc_iff {i : Fin (n + 1)} {j : Fin n} : i ≤ j.castSucc ↔ i < j.succ := by
  simpa only [lt_def, le_def] using Nat.add_one_le_add_one_iff.symm
Inequality Relation between Cast Successor and Successor in Finite Types
Informal description
For any natural number $n$, and for any elements $i \in \mathrm{Fin}(n+1)$ and $j \in \mathrm{Fin}(n)$, the inequality $i \leq j.\mathrm{castSucc}$ holds if and only if $i < j.\mathrm{succ}$.
Fin.castSucc_lt_iff_succ_le theorem
{n : Nat} {i : Fin n} {j : Fin (n + 1)} : i.castSucc < j ↔ i.succ ≤ j
Full source
theorem castSucc_lt_iff_succ_le {n : Nat} {i : Fin n} {j : Fin (n + 1)} :
    i.castSucc < j ↔ i.succ ≤ j := .rfl
Equivalence between Cast-Succ Order and Succ Order in Finite Types
Informal description
For any natural number $n$, finite natural number $i \in \mathrm{Fin}\,n$, and $j \in \mathrm{Fin}\,(n+1)$, the following equivalence holds: $$ i.\mathrm{castSucc} < j \leftrightarrow i.\mathrm{succ} \leq j $$ where: - $i.\mathrm{castSucc}$ is the canonical embedding of $i$ into $\mathrm{Fin}\,(n+1)$ - $i.\mathrm{succ}$ is the successor of $i$ in $\mathrm{Fin}\,(n+1)$ - $<$ and $\leq$ are the strict and non-strict order relations on $\mathrm{Fin}\,(n+1)$ respectively.
Fin.succ_last theorem
(n : Nat) : (last n).succ = last n.succ
Full source
@[simp] theorem succ_last (n : Nat) : (last n).succ = last n.succ := rfl
Successor of Last Element in $\text{Fin}(n)$ Equals Last Element in $\text{Fin}(n+1)$
Informal description
For any natural number $n$, the successor of the last element in $\text{Fin}(n)$ is equal to the last element in $\text{Fin}(n+1)$. That is, $(\text{last}(n)).\text{succ} = \text{last}(n+1)$.
Fin.succ_eq_last_succ theorem
{n : Nat} {i : Fin n.succ} : i.succ = last (n + 1) ↔ i = last n
Full source
@[simp] theorem succ_eq_last_succ {n : Nat} {i : Fin n.succ} :
    i.succ = last (n + 1) ↔ i = last n := by rw [← succ_last, succ_inj]
Characterization of Last Element via Successor in Finite Types: $i.\mathrm{succ} = \mathrm{last}(n+1) \leftrightarrow i = \mathrm{last}(n)$
Informal description
For any natural number $n$ and any element $i$ of $\mathrm{Fin}(n+1)$, the successor of $i$ equals the last element of $\mathrm{Fin}(n+2)$ if and only if $i$ is the last element of $\mathrm{Fin}(n+1)$. In symbols: $$ i.\mathrm{succ} = \mathrm{last}(n+1) \leftrightarrow i = \mathrm{last}(n) $$
Fin.castSucc_castLT theorem
(i : Fin (n + 1)) (h : (i : Nat) < n) : (castLT i h).castSucc = i
Full source
@[simp] theorem castSucc_castLT (i : Fin (n + 1)) (h : (i : Nat) < n) :
    (castLT i h).castSucc = i := rfl
Compatibility of `castSucc` and `castLT` for finite types
Informal description
For any natural number $n$ and any element $i$ of $\text{Fin}(n+1)$ (the finite type of natural numbers less than $n+1$), if the natural number corresponding to $i$ is less than $n$, then the composition of the `castLT` and `castSucc` operations on $i$ returns $i$ itself. More precisely, if $i \in \text{Fin}(n+1)$ and $h : (i : \mathbb{N}) < n$, then $\text{castSucc}(\text{castLT}(i, h)) = i$.
Fin.castLT_castSucc theorem
{n : Nat} (a : Fin n) (h : (a : Nat) < n) : castLT a.castSucc h = a
Full source
@[simp] theorem castLT_castSucc {n : Nat} (a : Fin n) (h : (a : Nat) < n) :
    castLT a.castSucc h = a := rfl
Casting Successor Preserves Original Element in Finite Types
Informal description
For any natural number $n$ and any element $a$ of the finite type $\text{Fin }n$, if the natural number representation of $a$ is less than $n$ (i.e., $h : (a : \mathbb{N}) < n$ holds), then casting the successor of $a$ back to $\text{Fin }n$ via $\text{castLT}$ recovers the original element $a$. In other words, $\text{castLT}(a.\text{castSucc}, h) = a$.
Fin.castSucc_lt_castSucc_iff theorem
{a b : Fin n} : a.castSucc < b.castSucc ↔ a < b
Full source
@[simp] theorem castSucc_lt_castSucc_iff {a b : Fin n} :
    a.castSucc < b.castSucc ↔ a < b := .rfl
Order Preservation under Cast Successor in Finite Types: $a.\mathrm{castSucc} < b.\mathrm{castSucc} \leftrightarrow a < b$
Informal description
For any two elements $a$ and $b$ of $\mathrm{Fin}\,n$, the cast successor of $a$ is less than the cast successor of $b$ if and only if $a$ is less than $b$. In other words, the order relation is preserved under the cast successor operation on finite natural numbers.
Fin.castSucc_inj theorem
{a b : Fin n} : a.castSucc = b.castSucc ↔ a = b
Full source
theorem castSucc_inj {a b : Fin n} : a.castSucc = b.castSucc ↔ a = b := by simp [Fin.ext_iff]
Injectivity of the Cast Successor Operation on Finite Types: $a.\text{castSucc} = b.\text{castSucc} \leftrightarrow a = b$
Informal description
For any elements $a$ and $b$ of the finite type $\text{Fin}\,n$, the cast successor operation satisfies $a.\text{castSucc} = b.\text{castSucc}$ if and only if $a = b$.
Fin.castSucc_lt_last theorem
(a : Fin n) : a.castSucc < last n
Full source
theorem castSucc_lt_last (a : Fin n) : a.castSucc < last n := a.is_lt
Successor-Cast Element is Less Than Last Element in $\mathrm{Fin}\,n$
Informal description
For any element $a$ of the finite type $\mathrm{Fin}\,n$, the successor-cast element $a.\mathrm{castSucc}$ is strictly less than the last element $\mathrm{last}\,n$ of $\mathrm{Fin}\,(n+1)$.
Fin.castSucc_zero theorem
: castSucc (0 : Fin (n + 1)) = 0
Full source
@[simp] theorem castSucc_zero : castSucc (0 : Fin (n + 1)) = 0 := rfl
Cast Successor Preserves Zero in Finite Types
Informal description
For any natural number $n$, the cast successor operation applied to the zero element of $\mathrm{Fin}(n+1)$ equals zero, i.e., $\mathrm{castSucc}(0) = 0$ in $\mathrm{Fin}(n+1)$.
Fin.castSucc_one theorem
{n : Nat} : castSucc (1 : Fin (n + 2)) = 1
Full source
@[simp] theorem castSucc_one {n : Nat} : castSucc (1 : Fin (n + 2)) = 1 := rfl
Successor-Cast Preserves One in Finite Types
Informal description
For any natural number $n$, the successor-cast operation applied to the element $1$ in $\mathrm{Fin}(n+2)$ equals $1$, i.e., $\mathrm{castSucc}(1) = 1$.
Fin.castSucc_pos theorem
{i : Fin (n + 1)} (h : 0 < i) : 0 < i.castSucc
Full source
/-- `castSucc i` is positive when `i` is positive -/
theorem castSucc_pos {i : Fin (n + 1)} (h : 0 < i) : 0 < i.castSucc := by
  simpa [lt_def] using h
Positivity Preservation under `castSucc` for Finite Types
Informal description
For any element $i$ of the finite type $\mathrm{Fin}(n+1)$ (natural numbers less than $n+1$), if $0 < i$, then $0 < \mathrm{castSucc}(i)$, where $\mathrm{castSucc}(i)$ is the natural embedding of $i$ into $\mathrm{Fin}(n+2)$.
Fin.castSucc_eq_zero_iff theorem
{a : Fin (n + 1)} : a.castSucc = 0 ↔ a = 0
Full source
@[simp] theorem castSucc_eq_zero_iff {a : Fin (n + 1)} : a.castSucc = 0 ↔ a = 0 := by simp [Fin.ext_iff]
Equivalence of Zero under Casting in Finite Types
Informal description
For any element $a$ in the finite type $\text{Fin}(n+1)$, the cast of $a$ into $\text{Fin}(n+2)$ via $\text{castSucc}$ equals zero if and only if $a$ itself equals zero. In symbols: $$ \text{castSucc}(a) = 0 \leftrightarrow a = 0 $$
Fin.castSucc_ne_zero_iff theorem
{a : Fin (n + 1)} : a.castSucc ≠ 0 ↔ a ≠ 0
Full source
theorem castSucc_ne_zero_iff {a : Fin (n + 1)} : a.castSucc ≠ 0a.castSucc ≠ 0 ↔ a ≠ 0 :=
  not_congr <| castSucc_eq_zero_iff
Nonzero Preservation under `castSucc` for Finite Types
Informal description
For any element $a$ in the finite type $\mathrm{Fin}(n+1)$, the cast of $a$ into $\mathrm{Fin}(n+2)$ via $\mathrm{castSucc}$ is nonzero if and only if $a$ itself is nonzero. In symbols: $$ \mathrm{castSucc}(a) \neq 0 \leftrightarrow a \neq 0 $$
Fin.castSucc_fin_succ theorem
(n : Nat) (j : Fin n) : j.succ.castSucc = (j.castSucc).succ
Full source
theorem castSucc_fin_succ (n : Nat) (j : Fin n) :
    j.succ.castSucc = (j.castSucc).succ := by simp [Fin.ext_iff]
Commutativity of Successor and Cast in Finite Types
Informal description
For any natural number $n$ and any element $j$ of the finite type $\text{Fin } n$, the cast of the successor of $j$ into $\text{Fin } (n + 1)$ is equal to the successor of the cast of $j$ into $\text{Fin } (n + 1)$. In symbols: $$ \text{castSucc}(j.\text{succ}) = (\text{castSucc}(j)).\text{succ} $$
Fin.coeSucc_eq_succ theorem
{a : Fin n} : a.castSucc + 1 = a.succ
Full source
@[simp]
theorem coeSucc_eq_succ {a : Fin n} : a.castSucc + 1 = a.succ := by
  cases n
  · exact a.elim0
  · simp [Fin.ext_iff, add_def, Nat.mod_eq_of_lt (Nat.succ_lt_succ a.is_lt)]
Equality between Cast-and-Add and Successor in Finite Types
Informal description
For any element $a$ of the finite type $\text{Fin } n$, the natural number obtained by casting $a$ to $\text{Fin } (n + 1)$ and adding 1 is equal to the successor of $a$ in $\text{Fin } n$. In symbols: $$ \text{castSucc}(a) + 1 = a.\text{succ} $$
Fin.lt_succ theorem
{a : Fin n} : a.castSucc < a.succ
Full source
theorem lt_succ {a : Fin n} : a.castSucc < a.succ := by
  rw [castSucc, lt_def, coe_castAdd, val_succ]; exact Nat.lt_succ_self a.val
Inequality between Cast and Successor in Finite Types: $\mathrm{castSucc}(a) < a.\mathrm{succ}$
Informal description
For any element $a$ of the finite type $\mathrm{Fin}\,n$, the cast of $a$ into $\mathrm{Fin}\,(n+1)$ is strictly less than the successor of $a$ in $\mathrm{Fin}\,(n+1)$. In symbols: $$ \mathrm{castSucc}(a) < a.\mathrm{succ} $$
Fin.exists_castSucc_eq theorem
{n : Nat} {i : Fin (n + 1)} : (∃ j, castSucc j = i) ↔ i ≠ last n
Full source
theorem exists_castSucc_eq {n : Nat} {i : Fin (n + 1)} : (∃ j, castSucc j = i) ↔ i ≠ last n :=
  ⟨fun ⟨j, hj⟩ => hj ▸ Fin.ne_of_lt j.castSucc_lt_last,
   fun hi => ⟨i.castLT <| Fin.val_lt_last hi, rfl⟩⟩
Characterization of Castable Elements in $\mathrm{Fin}(n+1)$ via Inequality with Last Element
Informal description
For any natural number $n$ and any element $i$ of the finite type $\mathrm{Fin}(n+1)$, there exists an element $j$ of $\mathrm{Fin}(n)$ such that $\mathrm{castSucc}(j) = i$ if and only if $i$ is not equal to the last element $\mathrm{last}(n)$ of $\mathrm{Fin}(n+1)$.
Fin.succ_castSucc theorem
{n : Nat} (i : Fin n) : i.castSucc.succ = i.succ.castSucc
Full source
theorem succ_castSucc {n : Nat} (i : Fin n) : i.castSucc.succ = i.succ.castSucc := rfl
Commutativity of Successor and Casting in Finite Types
Informal description
For any natural number $n$ and any element $i$ of the finite type $\text{Fin }n$, the successor of the cast of $i$ into $\text{Fin }(n+1)$ is equal to the cast of the successor of $i$ into $\text{Fin }(n+1)$. In symbols: $$ \text{succ}(\text{castSucc}(i)) = \text{castSucc}(\text{succ}(i)) $$
Fin.coe_addNat theorem
(m : Nat) (i : Fin n) : (addNat i m : Nat) = i + m
Full source
@[simp] theorem coe_addNat (m : Nat) (i : Fin n) : (addNat i m : Nat) = i + m := rfl
Coercion of Addition in Finite Types Preserves Natural Number Addition
Informal description
For any natural number $m$ and any element $i$ of the finite type $\text{Fin}(n)$, the natural number obtained by coercing the result of adding $m$ to $i$ (via $\text{addNat}$) is equal to the sum of $i$ and $m$ as natural numbers, i.e., $\text{addNat}(i, m) = i + m$.
Fin.addNat_zero theorem
(n : Nat) (i : Fin n) : addNat i 0 = i
Full source
@[simp] theorem addNat_zero (n : Nat) (i : Fin n) : addNat i 0 = i := by
  ext
  simp
Adding Zero Preserves Element in Finite Type
Informal description
For any natural number $n$ and any element $i$ of the finite type $\mathrm{Fin}\,n$, adding zero to $i$ via the `addNat` operation leaves $i$ unchanged, i.e., $\mathrm{addNat}\,i\,0 = i$.
Fin.addNat_one theorem
{i : Fin n} : addNat i 1 = i.succ
Full source
@[simp] theorem addNat_one {i : Fin n} : addNat i 1 = i.succ := rfl
Successor via Addition in Finite Types: $\mathrm{addNat}\,i\,1 = \mathrm{succ}\,i$
Informal description
For any element $i$ of the finite type $\mathrm{Fin}\,n$, adding 1 to $i$ via the `addNat` operation yields the successor of $i$, i.e., $\mathrm{addNat}\,i\,1 = \mathrm{succ}\,i$.
Fin.le_coe_addNat theorem
(m : Nat) (i : Fin n) : m ≤ addNat i m
Full source
theorem le_coe_addNat (m : Nat) (i : Fin n) : m ≤ addNat i m :=
  Nat.le_add_left _ _
Lower Bound on Addition in Finite Types: $m \leq i + m$
Informal description
For any natural number $m$ and any element $i$ of $\text{Fin}~n$ (i.e., a natural number $i < n$), we have $m \leq i + m$ where $i + m$ is interpreted as a natural number via the canonical coercion from $\text{Fin}~(n + m)$ to $\mathbb{N}$.
Fin.addNat_mk theorem
(n i : Nat) (hi : i < m) : addNat ⟨i, hi⟩ n = ⟨i + n, Nat.add_lt_add_right hi n⟩
Full source
@[simp] theorem addNat_mk (n i : Nat) (hi : i < m) :
    addNat ⟨i, hi⟩ n = ⟨i + n, Nat.add_lt_add_right hi n⟩ := rfl
Addition on Finite Natural Numbers Preserves Bounds
Informal description
For natural numbers $i$ and $n$, and a proof $hi$ that $i < m$, the operation `addNat` applied to the element $\langle i, hi \rangle$ of `Fin m` and $n$ yields the element $\langle i + n, \text{Nat.add\_lt\_add\_right } hi n \rangle$ of `Fin (m + n)$. In other words, adding $n$ to the finite natural number $\langle i, hi \rangle$ results in the finite natural number $\langle i + n \rangle$ with the proof that $i + n < m + n$.
Fin.cast_addNat_zero theorem
{n n' : Nat} (i : Fin n) (h : n + 0 = n') : (addNat i 0).cast h = i.cast ((Nat.add_zero _).symm.trans h)
Full source
@[simp] theorem cast_addNat_zero {n n' : Nat} (i : Fin n) (h : n + 0 = n') :
    (addNat i 0).cast h = i.cast ((Nat.add_zero _).symm.trans h) := rfl
Compatibility of Zero Addition and Casting in Finite Types
Informal description
For any natural numbers $n$ and $n'$, and any element $i$ of $\text{Fin}(n)$, if $h : n + 0 = n'$, then casting the result of adding zero to $i$ (which is $i$ itself) along $h$ is equal to casting $i$ along the equality $(n + 0 = n) \circ h$. More precisely: $$(\text{addNat}(i, 0)).\text{cast}(h) = i.\text{cast}((\text{Nat.add\_zero } n)^{-1} \circ h)$$
Fin.addNat_cast theorem
{n n' m : Nat} (i : Fin n') (h : n' = n) : addNat (i.cast h) m = (addNat i m).cast (congrArg (. + m) h)
Full source
/-- For rewriting in the reverse direction, see `Fin.cast_addNat_left`. -/
theorem addNat_cast {n n' m : Nat} (i : Fin n') (h : n' = n) :
    addNat (i.cast h) m = (addNat i m).cast (congrArg (. + m) h) := rfl
Commutativity of Casting and Addition in Finite Types
Informal description
For natural numbers $n$, $n'$, and $m$, and an element $i$ of $\text{Fin}(n')$, if $n' = n$, then the operation of first casting $i$ to $\text{Fin}(n)$ and then adding $m$ is equal to first adding $m$ to $i$ and then casting the result to $\text{Fin}(n + m)$. More precisely, if $h : n' = n$, then: $$\text{addNat}(i.\text{cast}(h), m) = (\text{addNat}(i, m)).\text{cast}(\text{congrArg}(\cdot + m, h))$$
Fin.cast_addNat_left theorem
{n n' m : Nat} (i : Fin n') (h : n' + m = n + m) : (addNat i m).cast h = addNat (i.cast (Nat.add_right_cancel h)) m
Full source
theorem cast_addNat_left {n n' m : Nat} (i : Fin n') (h : n' + m = n + m) :
    (addNat i m).cast h = addNat (i.cast (Nat.add_right_cancel h)) m := rfl
Compatibility of Cast and Shift Operations in Finite Types
Informal description
Let $n$, $n'$, and $m$ be natural numbers, and let $i$ be an element of $\text{Fin}(n')$. Given an equality $n' + m = n + m$, the cast of the shifted element $\text{addNat}(i, m)$ along $h$ is equal to the shifted element obtained by first casting $i$ along the equality derived from canceling $m$ on both sides of $h$ (i.e., $n' = n$).
Fin.cast_addNat_right theorem
{n m m' : Nat} (i : Fin n) (h : n + m' = n + m) : (addNat i m').cast h = addNat i m
Full source
@[simp] theorem cast_addNat_right {n m m' : Nat} (i : Fin n) (h : n + m' = n + m) :
    (addNat i m').cast h = addNat i m :=
  Fin.ext <| (congrArg ((· + ·) (i : Nat)) (Nat.add_left_cancel h) : _)
Commutativity of Casting and Right Addition in Finite Types
Informal description
For any natural numbers $n$, $m$, and $m'$, and any element $i \in \mathrm{Fin}\,n$, if $n + m' = n + m$, then casting the result of adding $m'$ to $i$ (as an element of $\mathrm{Fin}\,(n + m')$) to $\mathrm{Fin}\,(n + m)$ using the equality $h$ yields the same result as directly adding $m$ to $i$ (as an element of $\mathrm{Fin}\,(n + m)$). In other words, the following diagram commutes: \[ \begin{CD} \mathrm{Fin}\,n @>{\mathrm{addNat}\,m'}>> \mathrm{Fin}\,(n + m') \\ @V{\mathrm{addNat}\,m}VV @VV{\mathrm{cast}\,h}V \\ \mathrm{Fin}\,(n + m) @= \mathrm{Fin}\,(n + m) \end{CD} \]
Fin.coe_natAdd theorem
(n : Nat) {m : Nat} (i : Fin m) : (natAdd n i : Nat) = n + i
Full source
@[simp] theorem coe_natAdd (n : Nat) {m : Nat} (i : Fin m) : (natAdd n i : Nat) = n + i := rfl
Coercion of Natural Addition in Finite Types to Natural Numbers
Informal description
For any natural numbers $n$ and $m$, and for any element $i$ of the finite type $\text{Fin}(m)$, the canonical coercion of the element $\text{natAdd}\,n\,i$ (which adds $n$ to $i$ in $\text{Fin}(m)$) to a natural number equals the sum $n + i$ in $\mathbb{N}$.
Fin.natAdd_mk theorem
(n i : Nat) (hi : i < m) : natAdd n ⟨i, hi⟩ = ⟨n + i, Nat.add_lt_add_left hi n⟩
Full source
@[simp] theorem natAdd_mk (n i : Nat) (hi : i < m) :
    natAdd n ⟨i, hi⟩ = ⟨n + i, Nat.add_lt_add_left hi n⟩ := rfl
Construction of `natAdd` for Fin Elements
Informal description
For natural numbers $n$, $i$, and $m$, if $i < m$, then the operation `natAdd` applied to $n$ and the pair $\langle i, hi \rangle$ (where $hi$ is a proof that $i < m$) yields the pair $\langle n + i, h \rangle$, where $h$ is a proof that $n + i < n + m$ obtained from the inequality $i < m$ via the theorem `Nat.add_lt_add_left`.
Fin.le_coe_natAdd theorem
(m : Nat) (i : Fin n) : m ≤ natAdd m i
Full source
theorem le_coe_natAdd (m : Nat) (i : Fin n) : m ≤ natAdd m i := Nat.le_add_right ..
Lower Bound on Coerced Natural Addition in Finite Types
Informal description
For any natural number $m$ and any element $i$ of the finite type $\text{Fin}(n)$, the natural number $m$ is less than or equal to the canonical coercion of $\text{natAdd}\,m\,i$ to $\mathbb{N}$.
Fin.natAdd_zero theorem
{n : Nat} : natAdd 0 = Fin.cast (Nat.zero_add n).symm
Full source
@[simp] theorem natAdd_zero {n : Nat} : natAdd 0 = Fin.cast (Nat.zero_add n).symm := by ext; simp
Identity of Zero Addition in Finite Types: $\mathrm{natAdd}\,0 = \mathrm{id}$
Informal description
For any natural number $n$, the function `natAdd 0` (which adds zero to an element of $\mathrm{Fin}\,n$) is equal to the cast function induced by the equality $0 + n = n$ (i.e., the identity function on $\mathrm{Fin}\,n$).
Fin.natAdd_cast theorem
{n n' : Nat} (m : Nat) (i : Fin n') (h : n' = n) : natAdd m (i.cast h) = (natAdd m i).cast (congrArg _ h)
Full source
/-- For rewriting in the reverse direction, see `Fin.cast_natAdd_right`. -/
theorem natAdd_cast {n n' : Nat} (m : Nat) (i : Fin n') (h : n' = n) :
    natAdd m (i.cast h) = (natAdd m i).cast (congrArg _ h) := rfl
Commutativity of Natural Addition with Cast in Finite Types: $\text{natAdd}\,m\,(i.\text{cast}\,h) = (\text{natAdd}\,m\,i).\text{cast}\,(\text{congrArg}\,(\lambda k, m + k)\,h)$
Informal description
For any natural numbers $n, n'$ and $m$, and any element $i$ of the finite type $\text{Fin}(n')$, if $n' = n$, then the operation $\text{natAdd}\,m$ applied to the cast of $i$ (via $h$) is equal to the cast (via $\text{congrArg}\,(\lambda k, m + k)\,h$) of $\text{natAdd}\,m\,i$.
Fin.cast_natAdd_right theorem
{n n' m : Nat} (i : Fin n') (h : m + n' = m + n) : (natAdd m i).cast h = natAdd m (i.cast (Nat.add_left_cancel h))
Full source
theorem cast_natAdd_right {n n' m : Nat} (i : Fin n') (h : m + n' = m + n) :
    (natAdd m i).cast h  = natAdd m (i.cast (Nat.add_left_cancel h)) := rfl
Casting of Right Addition in Finite Types Preserves Equality
Informal description
For natural numbers $n, n', m$ and an element $i$ of $\text{Fin}(n')$, if $m + n' = m + n$, then casting the element $\text{natAdd}(m, i)$ (which adds $m$ to $i$ in $\text{Fin}(m + n')$) along the equality $h$ is equal to adding $m$ to the cast of $i$ along the equality obtained by canceling $m$ from both sides of $h$.
Fin.cast_natAdd_left theorem
{n m m' : Nat} (i : Fin n) (h : m' + n = m + n) : (natAdd m' i).cast h = natAdd m i
Full source
@[simp] theorem cast_natAdd_left {n m m' : Nat} (i : Fin n) (h : m' + n = m + n) :
    (natAdd m' i).cast h = natAdd m i :=
  Fin.ext <| (congrArg (· + (i : Nat)) (Nat.add_right_cancel h) : _)
Left Addition Preserves Cast in Finite Types
Informal description
For any natural numbers $n, m, m'$ and any element $i$ of the finite type $\mathrm{Fin}\,n$, if $m' + n = m + n$, then the cast of the addition of $m'$ to $i$ (i.e., $\mathrm{natAdd}\,m'\,i$) along the equality $h$ is equal to the addition of $m$ to $i$ (i.e., $\mathrm{natAdd}\,m\,i$).
Fin.castAdd_natAdd theorem
(p m : Nat) {n : Nat} (i : Fin n) : castAdd p (natAdd m i) = (natAdd m (castAdd p i)).cast (Nat.add_assoc ..).symm
Full source
theorem castAdd_natAdd (p m : Nat) {n : Nat} (i : Fin n) :
    castAdd p (natAdd m i) = (natAdd m (castAdd p i)).cast (Nat.add_assoc ..).symm := rfl
Commutativity of `castAdd` and `natAdd` with associativity adjustment
Informal description
For natural numbers $p$, $m$, and $n$, and for any $i \in \text{Fin}(n)$, the following equality holds: \[ \text{castAdd}_p(\text{natAdd}_m(i)) = \text{cast}\left(\text{natAdd}_m(\text{castAdd}_p(i)), (\text{Nat.add\_assoc} \ldots)^{-1}\right) \] Here: - $\text{castAdd}_p$ is the operation that adds $p$ to the upper bound of a $\text{Fin}(n)$ element. - $\text{natAdd}_m$ is the operation that adds $m$ to the value of a $\text{Fin}(n)$ element. - $\text{cast}$ adjusts the type of the result to account for the associativity of addition.
Fin.natAdd_castAdd theorem
(p m : Nat) {n : Nat} (i : Fin n) : natAdd m (castAdd p i) = (castAdd p (natAdd m i)).cast (Nat.add_assoc ..)
Full source
theorem natAdd_castAdd (p m : Nat) {n : Nat} (i : Fin n) :
    natAdd m (castAdd p i) = (castAdd p (natAdd m i)).cast (Nat.add_assoc ..) := rfl
Natural Addition and Cast Addition Commute in Finite Types
Informal description
For natural numbers $p$, $m$, and $n$, and for any element $i$ of $\text{Fin}\,n$, the following equality holds: \[ \text{natAdd}\,m\,(\text{castAdd}\,p\,i) = \text{cast}\,(\text{Nat.add\_assoc}\,\ldots)\,(\text{castAdd}\,p\,(\text{natAdd}\,m\,i)) \] where: - $\text{natAdd}\,m$ adds $m$ to the bound of a $\text{Fin}$ type, - $\text{castAdd}\,p$ casts an element of $\text{Fin}\,n$ to $\text{Fin}\,(n + p)$, - $\text{cast}\,h$ casts between $\text{Fin}$ types using a proof $h$ of equality of their bounds, - $\text{Nat.add\_assoc}\,\ldots$ is the associativity of addition on natural numbers.
Fin.natAdd_natAdd theorem
(m n : Nat) {p : Nat} (i : Fin p) : natAdd m (natAdd n i) = (natAdd (m + n) i).cast (Nat.add_assoc ..)
Full source
theorem natAdd_natAdd (m n : Nat) {p : Nat} (i : Fin p) :
    natAdd m (natAdd n i) = (natAdd (m + n) i).cast (Nat.add_assoc ..) :=
  Fin.ext <| (Nat.add_assoc ..).symm
Associativity of Successive Additions in Finite Types: $\mathrm{natAdd}_m \circ \mathrm{natAdd}_n = \mathrm{natAdd}_{m+n}$ via Cast
Informal description
For any natural numbers $m, n$ and any element $i$ of $\mathrm{Fin}\,p$, the operation of adding $m$ after adding $n$ to $i$ is equal to adding $m+n$ to $i$, up to a cast using the associativity of natural number addition.
Fin.cast_natAdd_zero theorem
{n n' : Nat} (i : Fin n) (h : 0 + n = n') : (natAdd 0 i).cast h = i.cast ((Nat.zero_add _).symm.trans h)
Full source
theorem cast_natAdd_zero {n n' : Nat} (i : Fin n) (h : 0 + n = n') :
    (natAdd 0 i).cast h = i.cast ((Nat.zero_add _).symm.trans h) := by simp
Casting Zero Addition in Finite Types: $\mathrm{natAdd}\,0$ via Cast
Informal description
For any natural numbers $n$ and $n'$, and any element $i$ of the finite type $\mathrm{Fin}\,n$, if $0 + n = n'$, then casting the result of adding zero to $i$ (via $\mathrm{natAdd}\,0\,i$) along the equality $h$ yields the same result as casting $i$ along the equality $(0 + n = n) \leftrightarrow (n = n')$ composed with $h$. In symbols: $$(\mathrm{natAdd}\,0\,i).\mathrm{cast}\,h = i.\mathrm{cast}\,((\mathrm{Nat.zero\_add}\,n)^{-1} \circ h)$$
Fin.cast_natAdd theorem
(n : Nat) {m : Nat} (i : Fin m) : (natAdd n i).cast (Nat.add_comm ..) = addNat i n
Full source
@[simp]
theorem cast_natAdd (n : Nat) {m : Nat} (i : Fin m) :
    (natAdd n i).cast (Nat.add_comm ..) = addNat i n := Fin.ext <| Nat.add_comm ..
Commutativity of Addition in Finite Types via Casting
Informal description
For any natural number $n$ and any element $i$ of the finite type $\mathrm{Fin}\,m$, the cast of the element obtained by adding $n$ to $i$ (via `natAdd`) under the commutativity of addition is equal to the element obtained by adding $i$ to $n$ (via `addNat`). In symbols: $$(\mathrm{natAdd}\,n\,i).\mathrm{cast}\,(\mathrm{Nat.add\_comm}\,n\,m) = \mathrm{addNat}\,i\,n$$
Fin.cast_addNat theorem
{n : Nat} (m : Nat) (i : Fin n) : (addNat i m).cast (Nat.add_comm ..) = natAdd m i
Full source
@[simp]
theorem cast_addNat {n : Nat} (m : Nat) (i : Fin n) :
    (addNat i m).cast (Nat.add_comm ..) = natAdd m i := Fin.ext <| Nat.add_comm ..
Commutativity of Addition Casts in Finite Types: $\mathrm{addNat}\,i\,m \sim \mathrm{natAdd}\,m\,i$
Informal description
For any natural number $n$, and for any element $i$ of the finite type $\mathrm{Fin}\,n$, the cast of the operation $\mathrm{addNat}\,i\,m$ (which adds $m$ to $i$ as a natural number) is equal to the operation $\mathrm{natAdd}\,m\,i$ (which adds $m$ to $i$ as a finite natural number), under the commutativity of natural number addition.
Fin.natAdd_last theorem
{m n : Nat} : natAdd n (last m) = last (n + m)
Full source
@[simp] theorem natAdd_last {m n : Nat} : natAdd n (last m) = last (n + m) := rfl
Last Element Preservation under `natAdd` in Finite Types
Informal description
For any natural numbers $m$ and $n$, the operation `natAdd` applied to $n$ and the last element of `Fin m` (i.e., the element corresponding to $m-1$) yields the last element of `Fin (n + m)` (i.e., the element corresponding to $n + m - 1$).
Fin.addNat_last theorem
(n : Nat) : addNat (last n) m = (last (n + m)).cast (by omega)
Full source
@[simp] theorem addNat_last (n : Nat) :
    addNat (last n) m = (last (n + m)).cast (by omega) := by
  ext
  simp
Last Element Preservation under $\mathrm{addNat}$ in Finite Types
Informal description
For any natural numbers $n$ and $m$, the operation $\mathrm{addNat}$ applied to the last element of $\mathrm{Fin}\,n$ (i.e., the element corresponding to $n-1$) and $m$ yields the last element of $\mathrm{Fin}\,(n + m)$ (i.e., the element corresponding to $n + m - 1$), up to a cast that adjusts the type using the equality $n + m = m + n$ (which is handled automatically by the `omega` tactic).
Fin.natAdd_castSucc theorem
{m n : Nat} {i : Fin m} : natAdd n (castSucc i) = castSucc (natAdd n i)
Full source
theorem natAdd_castSucc {m n : Nat} {i : Fin m} : natAdd n (castSucc i) = castSucc (natAdd n i) :=
  rfl
Commutativity of Natural Addition with Cast Successor in Finite Types
Informal description
For any natural numbers $m$ and $n$, and any element $i$ of $\text{Fin}\, m$, the operation $\text{natAdd}\, n$ applied to the cast successor of $i$ equals the cast successor of $\text{natAdd}\, n$ applied to $i$. In other words, $\text{natAdd}\, n (\text{castSucc}\, i) = \text{castSucc}\, (\text{natAdd}\, n\, i)$.
Fin.natAdd_eq_addNat theorem
(n : Nat) (i : Fin n) : Fin.natAdd n i = i.addNat n
Full source
@[simp] theorem natAdd_eq_addNat (n : Nat) (i : Fin n) : Fin.natAdd n i = i.addNat n := by
  ext
  simp
  omega
Equality of Natural Addition and Additive Shift in Finite Types: $\mathrm{natAdd}\,n\,i = i.\mathrm{addNat}\,n$
Informal description
For any natural number $n$ and any element $i$ of the finite type $\mathrm{Fin}\,n$, the operation $\mathrm{natAdd}\,n$ applied to $i$ equals the operation $\mathrm{addNat}$ applied to $i$ and $n$, i.e., $\mathrm{natAdd}\,n\,i = i.\mathrm{addNat}\,n$.
Fin.rev_castAdd theorem
(k : Fin n) (m : Nat) : rev (castAdd m k) = addNat (rev k) m
Full source
theorem rev_castAdd (k : Fin n) (m : Nat) : rev (castAdd m k) = addNat (rev k) m := Fin.ext <| by
  rw [val_rev, coe_castAdd, coe_addNat, val_rev, Nat.sub_add_comm (Nat.succ_le_of_lt k.is_lt)]
Reversal Commutes with Cast Addition in Finite Types: $\mathrm{rev}(\mathrm{castAdd}\,m\,k) = \mathrm{addNat}\,(\mathrm{rev}\,k)\,m$
Informal description
For any element $k$ of the finite type $\mathrm{Fin}\,n$ and any natural number $m$, the reversed element of $\mathrm{castAdd}\,m\,k$ is equal to $\mathrm{addNat}\,(\mathrm{rev}\,k)\,m$.
Fin.rev_addNat theorem
(k : Fin n) (m : Nat) : rev (addNat k m) = castAdd m (rev k)
Full source
theorem rev_addNat (k : Fin n) (m : Nat) : rev (addNat k m) = castAdd m (rev k) := by
  rw [← rev_rev (castAdd ..), rev_castAdd, rev_rev]
Reversal Commutes with Additive Shift in Finite Types: $\mathrm{rev}(\mathrm{addNat}\,k\,m) = \mathrm{castAdd}\,m\,(\mathrm{rev}\,k)$
Informal description
For any element $k$ of the finite type $\mathrm{Fin}\,n$ and any natural number $m$, the reversed element of $\mathrm{addNat}\,k\,m$ is equal to $\mathrm{castAdd}\,m\,(\mathrm{rev}\,k)$.
Fin.rev_castSucc theorem
(k : Fin n) : rev (castSucc k) = succ (rev k)
Full source
theorem rev_castSucc (k : Fin n) : rev (castSucc k) = succ (rev k) := k.rev_castAdd 1
Reversal Commutes with Cast Successor in Finite Types: $\mathrm{rev}(\mathrm{castSucc}\,k) = \mathrm{succ}(\mathrm{rev}\,k)$
Informal description
For any element $k$ of the finite type $\mathrm{Fin}\,n$, the reversal of the cast successor of $k$ is equal to the successor of the reversal of $k$, i.e., $\mathrm{rev}(\mathrm{castSucc}\,k) = \mathrm{succ}(\mathrm{rev}\,k)$.
Fin.rev_succ theorem
(k : Fin n) : rev (succ k) = castSucc (rev k)
Full source
theorem rev_succ (k : Fin n) : rev (succ k) = castSucc (rev k) := k.rev_addNat 1
Reversal Commutes with Successor in Finite Types: $\mathrm{rev}(\mathrm{succ}\,k) = \mathrm{castSucc}(\mathrm{rev}\,k)$
Informal description
For any element $k$ of the finite type $\mathrm{Fin}\,n$, the reversal of the successor of $k$ is equal to the cast successor of the reversal of $k$, i.e., $\mathrm{rev}(\mathrm{succ}\,k) = \mathrm{castSucc}(\mathrm{rev}\,k)$.
Fin.coe_pred theorem
(j : Fin (n + 1)) (h : j ≠ 0) : (j.pred h : Nat) = j - 1
Full source
@[simp] theorem coe_pred (j : Fin (n + 1)) (h : j ≠ 0) : (j.pred h : Nat) = j - 1 := rfl
Natural Number Predecessor via Coercion in Finite Types: $(j.\text{pred}\,h) = j - 1$ for $j \neq 0$
Informal description
For any element $j$ of the finite type $\text{Fin}(n+1)$ (natural numbers less than $n+1$) with $j \neq 0$, the natural number obtained by coercing the predecessor of $j$ (denoted $j.\text{pred}\,h$) is equal to $j - 1$ (where $j$ is interpreted as a natural number via the coercion).
Fin.succ_pred theorem
: ∀ (i : Fin (n + 1)) (h : i ≠ 0), (i.pred h).succ = i
Full source
@[simp] theorem succ_pred : ∀ (i : Fin (n + 1)) (h : i ≠ 0), (i.pred h).succ = i
  | ⟨0, _⟩, hi => by simp only [mk_zero, ne_eq, not_true] at hi
  | ⟨_ + 1, _⟩, _ => rfl
Successor of Predecessor Equals Original in Finite Natural Numbers
Informal description
For any finite natural number $i \in \text{Fin}(n+1)$ such that $i \neq 0$, the successor of the predecessor of $i$ equals $i$ itself, i.e., $(\text{pred}\ i\ h).\text{succ} = i$.
Fin.pred_succ theorem
(i : Fin n) {h : i.succ ≠ 0} : i.succ.pred h = i
Full source
@[simp]
theorem pred_succ (i : Fin n) {h : i.succ ≠ 0} : i.succ.pred h = i := by
  cases i
  rfl
Predecessor of Successor in Finite Types: $\text{pred}(\text{succ}(i)) = i$ when $\text{succ}(i) \neq 0$
Informal description
For any element $i$ of the finite type $\text{Fin } n$ and any proof $h$ that the successor of $i$ is not zero, the predecessor of $i.\text{succ}$ (with the condition $h$) equals $i$ itself. In other words, $\text{pred}(\text{succ}(i)) = i$ when $\text{succ}(i) \neq 0$.
Fin.pred_eq_iff_eq_succ theorem
{n : Nat} {i : Fin (n + 1)} (hi : i ≠ 0) {j : Fin n} : i.pred hi = j ↔ i = j.succ
Full source
theorem pred_eq_iff_eq_succ {n : Nat} {i : Fin (n + 1)} (hi : i ≠ 0) {j : Fin n} :
    i.pred hi = j ↔ i = j.succ :=
  ⟨fun h => by simp only [← h, Fin.succ_pred], fun h => by simp only [h, Fin.pred_succ]⟩
Predecessor-Successor Equivalence in Finite Types: $\text{pred}(i) = j \leftrightarrow i = \text{succ}(j)$
Informal description
For any natural number $n$, any nonzero element $i \in \text{Fin}(n+1)$, and any $j \in \text{Fin}(n)$, the predecessor of $i$ equals $j$ if and only if $i$ is the successor of $j$. In other words, $\text{pred}(i) = j \leftrightarrow i = \text{succ}(j)$.
Fin.pred_mk_succ theorem
(i : Nat) (h : i < n + 1) : Fin.pred ⟨i + 1, Nat.add_lt_add_right h 1⟩ (ne_of_val_ne (Nat.ne_of_gt (mk_succ_pos i h))) = ⟨i, h⟩
Full source
theorem pred_mk_succ (i : Nat) (h : i < n + 1) :
    Fin.pred ⟨i + 1, Nat.add_lt_add_right h 1⟩ (ne_of_val_ne (Nat.ne_of_gt (mk_succ_pos i h))) =
      ⟨i, h⟩ := by
  simp only [Fin.ext_iff, coe_pred, Nat.add_sub_cancel]
Predecessor of Successor in Finite Types: $\mathrm{pred}(i+1) = i$ when $i < n+1$
Informal description
For any natural numbers $i$ and $n$ with $i < n + 1$, the predecessor of the element $\langle i + 1, h' \rangle$ in $\mathrm{Fin}(n + 1 + 1)$ (where $h'$ is the proof that $i + 1 < n + 1 + 1$) equals $\langle i, h \rangle$, where $h$ is the original proof that $i < n + 1$.
Fin.pred_mk_succ' theorem
(i : Nat) (h₁ : i + 1 < n + 1 + 1) (h₂) : Fin.pred ⟨i + 1, h₁⟩ h₂ = ⟨i, Nat.lt_of_succ_lt_succ h₁⟩
Full source
@[simp] theorem pred_mk_succ' (i : Nat) (h₁ : i + 1 < n + 1 + 1) (h₂) :
    Fin.pred ⟨i + 1, h₁⟩ h₂ = ⟨i, Nat.lt_of_succ_lt_succ h₁⟩ := pred_mk_succ i _
Predecessor of Successor in Finite Types: $\mathrm{pred}(i+1) = i$ when $i+1 < n+2$
Informal description
For any natural numbers $i$ and $n$ such that $i + 1 < n + 1 + 1$, and given any proof $h₂$ that $\langle i + 1, h₁ \rangle$ is nonzero, the predecessor of $\langle i + 1, h₁ \rangle$ in $\mathrm{Fin}(n + 1 + 1)$ equals $\langle i, h' \rangle$, where $h'$ is the proof that $i < n + 1$ derived from $h₁$ via the property that $i + 1 < n + 1 + 1$ implies $i < n + 1$.
Fin.pred_mk theorem
{n : Nat} (i : Nat) (h : i < n + 1) (w) : Fin.pred ⟨i, h⟩ w = ⟨i - 1, Nat.sub_lt_right_of_lt_add (Nat.pos_iff_ne_zero.2 (Fin.val_ne_of_ne w)) h⟩
Full source
theorem pred_mk {n : Nat} (i : Nat) (h : i < n + 1) (w) : Fin.pred ⟨i, h⟩ w =
    ⟨i - 1, Nat.sub_lt_right_of_lt_add (Nat.pos_iff_ne_zero.2 (Fin.val_ne_of_ne w)) h⟩ :=
  rfl
Predecessor of Nonzero Finite Natural Number
Informal description
For any natural number $n$ and any $i \in \mathbb{N}$ with $i < n + 1$, if $w$ is a proof that the element $\langle i, h \rangle$ of $\text{Fin}(n + 1)$ is nonzero, then the predecessor of $\langle i, h \rangle$ is equal to $\langle i - 1, h' \rangle$, where $h'$ is a proof that $i - 1 < n + 1$ derived from the fact that $i$ is positive (since $w$ ensures $i \neq 0$) and $h$ ensures $i < n + 1$.
Fin.pred_le_pred_iff theorem
{n : Nat} {a b : Fin n.succ} {ha : a ≠ 0} {hb : b ≠ 0} : a.pred ha ≤ b.pred hb ↔ a ≤ b
Full source
@[simp] theorem pred_le_pred_iff {n : Nat} {a b : Fin n.succ} {ha : a ≠ 0} {hb : b ≠ 0} :
    a.pred ha ≤ b.pred hb ↔ a ≤ b := by rw [← succ_le_succ_iff, succ_pred, succ_pred]
Predecessor Preserves Order in Finite Types: $\mathrm{pred}(a) \leq \mathrm{pred}(b) \leftrightarrow a \leq b$
Informal description
For any nonzero elements $a, b$ in $\mathrm{Fin}(n+1)$, the predecessor of $a$ is less than or equal to the predecessor of $b$ if and only if $a \leq b$.
Fin.pred_lt_pred_iff theorem
{n : Nat} {a b : Fin n.succ} {ha : a ≠ 0} {hb : b ≠ 0} : a.pred ha < b.pred hb ↔ a < b
Full source
@[simp] theorem pred_lt_pred_iff {n : Nat} {a b : Fin n.succ} {ha : a ≠ 0} {hb : b ≠ 0} :
    a.pred ha < b.pred hb ↔ a < b := by rw [← succ_lt_succ_iff, succ_pred, succ_pred]
Predecessor Preserves Strict Order in Finite Types
Informal description
For any nonzero elements $a$ and $b$ in $\mathrm{Fin}(n+1)$, the predecessor of $a$ is strictly less than the predecessor of $b$ if and only if $a$ is strictly less than $b$.
Fin.pred_inj theorem
: ∀ {a b : Fin (n + 1)} {ha : a ≠ 0} {hb : b ≠ 0}, a.pred ha = b.pred hb ↔ a = b
Full source
@[simp] theorem pred_inj :
    ∀ {a b : Fin (n + 1)} {ha : a ≠ 0} {hb : b ≠ 0}, a.pred ha = b.pred hb ↔ a = b
  | ⟨0, _⟩, _, ha, _ => by simp only [mk_zero, ne_eq, not_true] at ha
  | ⟨i + 1, _⟩, ⟨0, _⟩, _, hb => by simp only [mk_zero, ne_eq, not_true] at hb
  | ⟨i + 1, hi⟩, ⟨j + 1, hj⟩, ha, hb => by simp [Fin.ext_iff, Nat.succ.injEq]
Injectivity of Predecessor on Nonzero Elements of $\text{Fin}(n+1)$
Informal description
For any two nonzero elements $a$ and $b$ of $\text{Fin}(n+1)$, the predecessor of $a$ equals the predecessor of $b$ if and only if $a = b$.
Fin.pred_one theorem
{n : Nat} : Fin.pred (1 : Fin (n + 2)) (Ne.symm (Fin.ne_of_lt one_pos)) = 0
Full source
@[simp] theorem pred_one {n : Nat} :
    Fin.pred (1 : Fin (n + 2)) (Ne.symm (Fin.ne_of_lt one_pos)) = 0 := rfl
Predecessor of One in $\mathrm{Fin}(n+2)$ is Zero
Informal description
For any natural number $n$, the predecessor of the element $1$ in the finite type $\mathrm{Fin}(n+2)$ is equal to $0$. Here, the proof that $1 \neq 0$ is derived from the fact that $0 < 1$ in $\mathrm{Fin}(n+2)$.
Fin.pred_add_one theorem
(i : Fin (n + 2)) (h : (i : Nat) < n + 1) : pred (i + 1) (Fin.ne_of_gt (add_one_pos _ (lt_def.2 h))) = castLT i h
Full source
theorem pred_add_one (i : Fin (n + 2)) (h : (i : Nat) < n + 1) :
    pred (i + 1) (Fin.ne_of_gt (add_one_pos _ (lt_def.2 h))) = castLT i h := by
  rw [Fin.ext_iff, coe_pred, coe_castLT, val_add, val_one, Nat.mod_eq_of_lt, Nat.add_sub_cancel]
  exact Nat.add_lt_add_right h 1
Predecessor of Successor in Finite Types: $\mathrm{pred}(i + 1) = \mathrm{castLT}\,i\,h$ for $i < n+1$
Informal description
For any element $i$ of the finite type $\mathrm{Fin}(n+2)$ such that the underlying natural number value of $i$ is less than $n+1$, the predecessor of $i + 1$ (with the proof that $i + 1 \neq 0$) is equal to the cast of $i$ into $\mathrm{Fin}(n+1)$ via $\mathrm{castLT}$.
Fin.coe_subNat theorem
(i : Fin (n + m)) (h : m ≤ i) : (i.subNat m h : Nat) = i - m
Full source
@[simp] theorem coe_subNat (i : Fin (n + m)) (h : m ≤ i) : (i.subNat m h : Nat) = i - m := rfl
Coercion of Finite Subtraction Equals Natural Subtraction
Informal description
For any element $i$ of the finite type $\mathrm{Fin}(n + m)$ and any proof $h$ that $m \leq i$ (as a natural number), the natural number obtained by coercing the result of $\mathrm{subNat}\,m\,i\,h$ is equal to $i - m$.
Fin.subNat_mk theorem
{i : Nat} (h₁ : i < n + m) (h₂ : m ≤ i) : subNat m ⟨i, h₁⟩ h₂ = ⟨i - m, Nat.sub_lt_right_of_lt_add h₂ h₁⟩
Full source
@[simp] theorem subNat_mk {i : Nat} (h₁ : i < n + m) (h₂ : m ≤ i) :
    subNat m ⟨i, h₁⟩ h₂ = ⟨i - m, Nat.sub_lt_right_of_lt_add h₂ h₁⟩ := rfl
Construction of Finite Type Element via Subtraction: $\mathrm{subNat}\,m\,\langle i, h₁ \rangle\,h₂ = \langle i - m, \mathrm{sub\_lt\_right\_of\_lt\_add}\,h₂\,h₁ \rangle$
Informal description
For any natural numbers $n$ and $m$, and any natural number $i$ satisfying $i < n + m$ and $m \leq i$, the operation $\mathrm{subNat}\,m$ applied to the element $\langle i, h₁ \rangle$ of $\mathrm{Fin}\,(n + m)$ (where $h₁$ is a proof that $i < n + m$) and a proof $h₂$ that $m \leq i$ yields the element $\langle i - m, \mathrm{Nat.sub\_lt\_right\_of\_lt\_add}\,h₂\,h₁ \rangle$ of $\mathrm{Fin}\,n$.
Fin.subNat_zero theorem
(i : Fin n) (h : 0 ≤ (i : Nat)) : Fin.subNat 0 i h = i
Full source
@[simp] theorem subNat_zero (i : Fin n) (h : 0 ≤ (i : Nat)): Fin.subNat 0 i h = i := by
  ext
  simp
Subtraction of Zero in Finite Types Preserves Element
Informal description
For any element $i$ of the finite type $\mathrm{Fin}\,n$ and any proof $h$ that $0 \leq i$ (as a natural number), the operation $\mathrm{subNat}\,0\,i\,h$ returns $i$ itself.
Fin.subNat_one_succ theorem
(i : Fin (n + 1)) (h : 1 ≤ (i : Nat)) : (subNat 1 i h).succ = i
Full source
@[simp] theorem subNat_one_succ (i : Fin (n + 1)) (h : 1 ≤ (i : Nat)) : (subNat 1 i h).succ = i := by
  ext
  simp
  omega
Successor of Subtracted One Equals Original in Finite Types
Informal description
For any element $i$ of the finite type $\mathrm{Fin}(n + 1)$ and any proof $h$ that $1 \leq i$ (as a natural number), the successor of the element obtained by subtracting 1 from $i$ equals $i$ itself, i.e., $(\mathrm{subNat}\,1\,i\,h).\mathrm{succ} = i$.
Fin.pred_castSucc_succ theorem
(i : Fin n) : pred (castSucc i.succ) (Fin.ne_of_gt (castSucc_pos i.succ_pos)) = castSucc i
Full source
@[simp] theorem pred_castSucc_succ (i : Fin n) :
    pred (castSucc i.succ) (Fin.ne_of_gt (castSucc_pos i.succ_pos)) = castSucc i := rfl
Predecessor of Successor via $\mathrm{castSucc}$ in Finite Types
Informal description
For any element $i$ of the finite type $\mathrm{Fin}\,n$, the predecessor of the successor of $i$ embedded into $\mathrm{Fin}\,(n+1)$ via $\mathrm{castSucc}$ equals $i$ embedded via $\mathrm{castSucc}$. That is, $\mathrm{pred}(\mathrm{castSucc}(i.\mathrm{succ})) = \mathrm{castSucc}(i)$, where the predecessor is well-defined because $\mathrm{castSucc}(i.\mathrm{succ})$ is strictly positive.
Fin.addNat_subNat theorem
{i : Fin (n + m)} (h : m ≤ i) : addNat (subNat m i h) m = i
Full source
@[simp] theorem addNat_subNat {i : Fin (n + m)} (h : m ≤ i) : addNat (subNat m i h) m = i :=
  Fin.ext <| Nat.sub_add_cancel h
Inverse Property of Addition and Subtraction in Finite Types: $\mathrm{addNat}(\mathrm{subNat}(m, i, h), m) = i$
Informal description
For any element $i$ of the finite type $\mathrm{Fin}(n + m)$ and any natural number $m$ such that $m \leq i$ (when viewed as a natural number), the operation of first subtracting $m$ from $i$ (via `subNat`) and then adding $m$ back (via `addNat`) returns the original element $i$. In other words, $\mathrm{addNat}(\mathrm{subNat}(m, i, h), m) = i$.
Fin.natAdd_subNat_cast theorem
{i : Fin (n + m)} (h : n ≤ i) : natAdd n (subNat n (i.cast (Nat.add_comm ..)) h) = i
Full source
@[simp] theorem natAdd_subNat_cast {i : Fin (n + m)} (h : n ≤ i) :
    natAdd n (subNat n (i.cast (Nat.add_comm ..)) h) = i := by simp [← cast_addNat]
Inverse Property of Addition and Subtraction with Commutative Cast in Finite Types: $\mathrm{natAdd}\,n \circ \mathrm{subNat}\,n \circ \mathrm{cast} = \mathrm{id}$
Informal description
For any element $i$ of the finite type $\mathrm{Fin}(n + m)$ and any natural number $n$ such that $n \leq i$ (when viewed as a natural number), the operation of first casting $i$ via the commutativity of addition (i.e., $i : \mathrm{Fin}(m + n)$), then subtracting $n$ (via `subNat`), and finally adding $n$ back (via `natAdd`) returns the original element $i$. In other words, $\mathrm{natAdd}\,n\,(\mathrm{subNat}\,n\,(i.\mathrm{cast}\,(\mathrm{Nat.add\_comm}\,...))\,h) = i$.
Fin.succRec definition
{motive : ∀ n, Fin n → Sort _} (zero : ∀ n, motive n.succ (0 : Fin (n + 1))) (succ : ∀ n i, motive n i → motive n.succ i.succ) : ∀ {n : Nat} (i : Fin n), motive n i
Full source
/--
An induction principle for `Fin` that considers a given `i : Fin n` as given by a sequence of `i`
applications of `Fin.succ`.

The cases in the induction are:
 * `zero` demonstrates the motive for `(0 : Fin (n + 1))` for all bounds `n`
 * `succ` demonstrates the motive for `Fin.succ` applied to an arbitrary `Fin` for an arbitrary
   bound `n`

Unlike `Fin.induction`, the motive quantifies over the bound, and the bound varies at each inductive
step. `Fin.succRecOn` is a version of this induction principle that takes the `Fin` argument first.
-/
-- FIXME: Performance review
@[elab_as_elim] def succRec {motive : ∀ n, Fin n → Sort _}
    (zero : ∀ n, motive n.succ (0 : Fin (n + 1)))
    (succ : ∀ n i, motive n i → motive n.succ i.succ) : ∀ {n : Nat} (i : Fin n), motive n i
  | 0, i => i.elim0
  | Nat.succ n, ⟨0, _⟩ => by rw [mk_zero]; exact zero n
  | Nat.succ _, ⟨Nat.succ i, h⟩ => succ _ _ (succRec zero succ ⟨i, Nat.lt_of_succ_lt_succ h⟩)
Successor-based induction for finite natural numbers
Informal description
An induction principle for `Fin n` that considers a given element `i : Fin n` as constructed by `i` applications of the successor function `Fin.succ`. The induction has two cases: 1. **Base case (`zero`)**: For any bound `n`, the motive holds for `0 : Fin (n + 1)`. 2. **Inductive step (`succ`)**: For any bound `n` and any `i : Fin n`, if the motive holds for `i`, then it holds for `Fin.succ i`. Unlike `Fin.induction`, the motive depends on the bound `n`, which may vary at each inductive step. This principle is useful for proving properties of `Fin` elements by induction on their construction via `Fin.succ`.
Fin.succRecOn definition
{n : Nat} (i : Fin n) {motive : ∀ n, Fin n → Sort _} (zero : ∀ n, motive (n + 1) 0) (succ : ∀ n i, motive n i → motive (Nat.succ n) i.succ) : motive n i
Full source
/--
An induction principle for `Fin` that considers a given `i : Fin n` as given by a sequence of `i`
applications of `Fin.succ`.

The cases in the induction are:
 * `zero` demonstrates the motive for `(0 : Fin (n + 1))` for all bounds `n`
 * `succ` demonstrates the motive for `Fin.succ` applied to an arbitrary `Fin` for an arbitrary
   bound `n`

Unlike `Fin.induction`, the motive quantifies over the bound, and the bound varies at each inductive
step. `Fin.succRec` is a version of this induction principle that takes the `Fin` argument last.
-/
-- FIXME: Performance review
@[elab_as_elim] def succRecOn {n : Nat} (i : Fin n) {motive : ∀ n, Fin n → Sort _}
    (zero : ∀ n, motive (n + 1) 0) (succ : ∀ n i, motive n i → motive (Nat.succ n) i.succ) :
    motive n i := i.succRec zero succ
Successor-based induction for finite natural numbers (argument-last variant)
Informal description
An induction principle for finite natural numbers `Fin n` where the motive depends on the bound `n`. Given an element `i : Fin n`, the induction proceeds as follows: 1. **Base case (`zero`)**: For any bound `n`, the motive holds for `0 : Fin (n + 1)`. 2. **Inductive step (`succ`)**: For any bound `n` and any `i : Fin n`, if the motive holds for `i`, then it holds for `Fin.succ i`. This is a variant of `Fin.succRec` where the `Fin` argument is taken last, making it more convenient for certain inductive proofs.
Fin.succRecOn_zero theorem
{motive : ∀ n, Fin n → Sort _} {zero succ} (n) : @Fin.succRecOn (n + 1) 0 motive zero succ = zero n
Full source
@[simp] theorem succRecOn_zero {motive : ∀ n, Fin n → Sort _} {zero succ} (n) :
    @Fin.succRecOn (n + 1) 0 motive zero succ = zero n := by
  cases n <;> rfl
Base Case Reduction for Successor-Based Induction on Finite Natural Numbers
Informal description
For any dependent type family `motive` on finite natural numbers and any natural number `n`, the successor-based induction principle `Fin.succRecOn` applied to `0 : Fin (n + 1)` with motive `motive` and induction steps `zero` and `succ` reduces to the base case `zero n`.
Fin.succRecOn_succ theorem
{motive : ∀ n, Fin n → Sort _} {zero succ} {n} (i : Fin n) : @Fin.succRecOn (n + 1) i.succ motive zero succ = succ n i (Fin.succRecOn i zero succ)
Full source
@[simp] theorem succRecOn_succ {motive : ∀ n, Fin n → Sort _} {zero succ} {n} (i : Fin n) :
    @Fin.succRecOn (n + 1) i.succ motive zero succ = succ n i (Fin.succRecOn i zero succ) := by
  cases i; rfl
Successor Case in Finite Natural Number Induction
Informal description
For any dependent type family `motive` indexed by natural numbers `n` and elements of `Fin n`, given base case `zero` and inductive step `succ` functions, applying the successor-based induction `Fin.succRecOn` to `i.succ` (where `i : Fin n`) is equal to applying the inductive step `succ` to `i` and the result of `Fin.succRecOn` applied to `i`. More precisely, let: - `motive : ∀ n, Fin n → Sort _` be a dependent type family, - `zero : ∀ n, motive (n + 1) 0` be the base case, - `succ : ∀ n i, motive n i → motive (n + 1) i.succ` be the inductive step, - `i : Fin n` be a finite natural number. Then: $$\text{Fin.succRecOn } i.\text{succ } \text{motive } \text{zero } \text{succ} = \text{succ } n \ i \ (\text{Fin.succRecOn } i \ \text{motive } \text{zero } \text{succ})$$
Fin.induction definition
{motive : Fin (n + 1) → Sort _} (zero : motive 0) (succ : ∀ i : Fin n, motive (castSucc i) → motive i.succ) : ∀ i : Fin (n + 1), motive i
Full source
/--
Proves a statement by induction on the underlying `Nat` value in a `Fin (n + 1)`.

For the induction:
 * `zero` is the base case, demonstrating `motive 0`.
 * `succ` is the inductive step, assuming the motive for `i : Fin n` (lifted to `Fin (n + 1)` with
   `Fin.castSucc`) and demonstrating it for `i.succ`.

`Fin.inductionOn` is a version of this induction principle that takes the `Fin` as its first
parameter, `Fin.cases` is the corresponding case analysis operator, and `Fin.reverseInduction` is a
version that starts at the greatest value instead of `0`.
-/
-- FIXME: Performance review
@[elab_as_elim] def induction {motive : Fin (n + 1) → Sort _} (zero : motive 0)
    (succ : ∀ i : Fin n, motive (castSucc i) → motive i.succ) :
    ∀ i : Fin (n + 1), motive i
  | ⟨i, hi⟩ => go i hi
where
  -- Use a curried function so that this is structurally recursive
  go : ∀ (i : Nat) (hi : i < n + 1), motive ⟨i, hi⟩
  | 0, hi => by rwa [Fin.mk_zero]
  | i+1, hi => succ ⟨i, Nat.lt_of_succ_lt_succ hi⟩ (go i (Nat.lt_of_succ_lt hi))
Finite natural number induction
Informal description
Given a motive (a dependent type) on `Fin (n + 1)`, a base case `zero : motive 0`, and an inductive step `succ` that for any `i : Fin n` produces `motive i.succ` from `motive (castSucc i)`, this function constructs a proof of `motive i` for all `i : Fin (n + 1)`. The induction proceeds by: - The base case `zero` proves the statement for `0`. - The inductive step `succ` assumes the statement holds for `i : Fin n` (lifted to `Fin (n + 1)` via `castSucc`) and proves it for `i.succ`.
Fin.induction_zero theorem
{motive : Fin (n + 1) → Sort _} (zero : motive 0) (hs : ∀ i : Fin n, motive (castSucc i) → motive i.succ) : (induction zero hs : ∀ i : Fin (n + 1), motive i) 0 = zero
Full source
@[simp] theorem induction_zero {motive : Fin (n + 1) → Sort _} (zero : motive 0)
    (hs : ∀ i : Fin n, motive (castSucc i) → motive i.succ) :
    (induction zero hs : ∀ i : Fin (n + 1), motive i) 0 = zero := rfl
Base Case of Finite Induction: `induction zero hs 0 = zero`
Informal description
Given a dependent type `motive` on `Fin (n + 1)`, a base case `zero : motive 0`, and an inductive step `hs` that for any `i : Fin n` produces `motive i.succ` from `motive (castSucc i)`, the induction principle applied to `0` yields the base case `zero`. In other words, the induction hypothesis holds trivially for the zero case.
Fin.induction_succ theorem
{motive : Fin (n + 1) → Sort _} (zero : motive 0) (succ : ∀ i : Fin n, motive (castSucc i) → motive i.succ) (i : Fin n) : induction (motive := motive) zero succ i.succ = succ i (induction zero succ (castSucc i))
Full source
@[simp] theorem induction_succ {motive : Fin (n + 1) → Sort _} (zero : motive 0)
    (succ : ∀ i : Fin n, motive (castSucc i) → motive i.succ) (i : Fin n) :
    induction (motive := motive) zero succ i.succ = succ i (induction zero succ (castSucc i)) := rfl
Successor Case of Finite Induction Principle
Informal description
For any natural number $n$, given a dependent type family $\text{motive} : \text{Fin}(n+1) \to \text{Sort}_*$, a base case $\text{zero} : \text{motive}(0)$, and an inductive step $\text{succ} : \forall i \in \text{Fin}(n), \text{motive}(\text{castSucc}(i)) \to \text{motive}(i.\text{succ})$, the induction principle satisfies the following property for any $i \in \text{Fin}(n)$: \[ \text{induction}(\text{zero}, \text{succ}, i.\text{succ}) = \text{succ}(i, \text{induction}(\text{zero}, \text{succ}, \text{castSucc}(i))) \]
Fin.inductionOn definition
(i : Fin (n + 1)) {motive : Fin (n + 1) → Sort _} (zero : motive 0) (succ : ∀ i : Fin n, motive (castSucc i) → motive i.succ) : motive i
Full source
/--
Proves a statement by induction on the underlying `Nat` value in a `Fin (n + 1)`.

For the induction:
 * `zero` is the base case, demonstrating `motive 0`.
 * `succ` is the inductive step, assuming the motive for `i : Fin n` (lifted to `Fin (n + 1)` with
   `Fin.castSucc`) and demonstrating it for `i.succ`.

`Fin.induction` is a version of this induction principle that takes the `Fin` as its last
parameter.
-/
-- FIXME: Performance review
@[elab_as_elim] def inductionOn (i : Fin (n + 1)) {motive : Fin (n + 1) → Sort _} (zero : motive 0)
    (succ : ∀ i : Fin n, motive (castSucc i) → motive i.succ) : motive i := induction zero succ i
Finite natural number induction principle
Informal description
Given a natural number $n$, a finite natural number $i \in \text{Fin}(n+1)$, and a dependent type $\text{motive}$ on $\text{Fin}(n+1)$, the function $\text{Fin.inductionOn}$ proves $\text{motive}(i)$ by induction on $i$ as follows: - The base case $\text{zero}$ proves $\text{motive}(0)$. - The inductive step $\text{succ}$ assumes $\text{motive}(j)$ for $j \in \text{Fin}(n)$ (lifted to $\text{Fin}(n+1)$ via $\text{castSucc}$) and proves $\text{motive}(j.\text{succ})$.
Fin.cases definition
{motive : Fin (n + 1) → Sort _} (zero : motive 0) (succ : ∀ i : Fin n, motive i.succ) : ∀ i : Fin (n + 1), motive i
Full source
/--
Proves a statement by cases on the underlying `Nat` value in a `Fin (n + 1)`.

The two cases are:
 * `zero`, used when the value is of the form `(0 : Fin (n + 1))`
 * `succ`, used when the value is of the form `(j : Fin n).succ`

The corresponding induction principle is `Fin.induction`.
-/
@[elab_as_elim] def cases {motive : Fin (n + 1) → Sort _}
    (zero : motive 0) (succ : ∀ i : Fin n, motive i.succ) :
    ∀ i : Fin (n + 1), motive i := induction zero fun i _ => succ i
Case analysis for finite natural numbers
Informal description
Given a motive (dependent type) on `Fin (n + 1)`, a base case `zero : motive 0`, and a successor case `succ` that for any `i : Fin n` produces `motive i.succ`, this function constructs a proof of `motive i` for all `i : Fin (n + 1)`. The function proceeds by: - The base case `zero` proves the statement for `0`. - The successor case `succ` proves the statement for `i.succ` given any `i : Fin n`.
Fin.cases_zero theorem
{n} {motive : Fin (n + 1) → Sort _} {zero succ} : @Fin.cases n motive zero succ 0 = zero
Full source
@[simp] theorem cases_zero {n} {motive : Fin (n + 1) → Sort _} {zero succ} :
    @Fin.cases n motive zero succ 0 = zero := rfl
Case Analysis at Zero for Finite Natural Numbers: `Fin.cases 0 = zero`
Informal description
For any natural number $n$ and any dependent type `motive` on `Fin (n + 1)`, the case analysis function `Fin.cases` applied to the zero case `zero` and successor case `succ` evaluates to `zero` when the input is `0`.
Fin.cases_succ theorem
{n} {motive : Fin (n + 1) → Sort _} {zero succ} (i : Fin n) : @Fin.cases n motive zero succ i.succ = succ i
Full source
@[simp] theorem cases_succ {n} {motive : Fin (n + 1) → Sort _} {zero succ} (i : Fin n) :
    @Fin.cases n motive zero succ i.succ = succ i := rfl
Case Analysis for Successor in Finite Types: `Fin.cases zero succ i.succ = succ i`
Informal description
For any natural number `n`, given a dependent type `motive` on `Fin (n + 1)`, a base case `zero : motive 0`, and a successor case `succ : ∀ i : Fin n, motive i.succ`, the case analysis function `Fin.cases` satisfies `Fin.cases zero succ i.succ = succ i` for any `i : Fin n`.
Fin.cases_succ' theorem
{n} {motive : Fin (n + 1) → Sort _} {zero succ} {i : Nat} (h : i + 1 < n + 1) : @Fin.cases n motive zero succ ⟨i.succ, h⟩ = succ ⟨i, Nat.lt_of_succ_lt_succ h⟩
Full source
@[simp] theorem cases_succ' {n} {motive : Fin (n + 1) → Sort _} {zero succ}
    {i : Nat} (h : i + 1 < n + 1) :
    @Fin.cases n motive zero succ ⟨i.succ, h⟩ = succ ⟨i, Nat.lt_of_succ_lt_succ h⟩ := rfl
Case Analysis for Successor in Finite Types
Informal description
For any natural number `n`, a dependent type `motive` on `Fin (n + 1)`, terms `zero : motive 0` and `succ : ∀ i : Fin n, motive i.succ`, and a natural number `i` such that `i + 1 < n + 1`, the case analysis function `Fin.cases` satisfies: \[ \text{Fin.cases } zero \, succ \, \langle i+1, h \rangle = succ \, \langle i, \text{Nat.lt\_of\_succ\_lt\_succ } h \rangle \] where `⟨i+1, h⟩` denotes the element of `Fin (n + 1)` with value `i+1` and proof `h` that `i+1 < n+1`, and similarly for `⟨i, ...⟩`.
Fin.forall_fin_succ theorem
{P : Fin (n + 1) → Prop} : (∀ i, P i) ↔ P 0 ∧ ∀ i : Fin n, P i.succ
Full source
theorem forall_fin_succ {P : Fin (n + 1) → Prop} : (∀ i, P i) ↔ P 0 ∧ ∀ i : Fin n, P i.succ :=
  ⟨fun H => ⟨H 0, fun _ => H _⟩, fun ⟨H0, H1⟩ i => Fin.cases H0 H1 i⟩
Universal Quantification over Successor in Finite Types: $\forall i \in \text{Fin}(n+1), P(i) \leftrightarrow P(0) \land \forall i \in \text{Fin}(n), P(\text{succ}(i))$
Informal description
For any predicate $P$ on the finite type $\text{Fin}(n+1)$, the universal statement $(\forall i, P(i))$ holds if and only if $P(0)$ holds and for every $i \in \text{Fin}(n)$, $P(\text{succ}(i))$ holds.
Fin.exists_fin_succ theorem
{P : Fin (n + 1) → Prop} : (∃ i, P i) ↔ P 0 ∨ ∃ i : Fin n, P i.succ
Full source
theorem exists_fin_succ {P : Fin (n + 1) → Prop} : (∃ i, P i) ↔ P 0 ∨ ∃ i : Fin n, P i.succ :=
  ⟨fun ⟨i, h⟩ => Fin.cases Or.inl (fun i hi => Or.inr ⟨i, hi⟩) i h, fun h =>
    (h.elim fun h => ⟨0, h⟩) fun ⟨i, hi⟩ => ⟨i.succ, hi⟩⟩
Existence in $\text{Fin}(n+1)$ via Base or Successor Case
Informal description
For any predicate $P$ defined on the finite type $\text{Fin}(n+1)$, there exists an element $i \in \text{Fin}(n+1)$ satisfying $P(i)$ if and only if either $P(0)$ holds or there exists an element $j \in \text{Fin}(n)$ such that $P(j.\text{succ})$ holds.
Fin.forall_fin_one theorem
{p : Fin 1 → Prop} : (∀ i, p i) ↔ p 0
Full source
theorem forall_fin_one {p : Fin 1 → Prop} : (∀ i, p i) ↔ p 0 :=
  ⟨fun h => h _, fun h i => Subsingleton.elim i 0 ▸ h⟩
Universal Quantification over $\mathrm{Fin}\,1$ is Equivalent to Evaluation at Zero
Informal description
For any predicate $p$ defined on the finite type $\mathrm{Fin}\,1$, the universal statement $(\forall i \in \mathrm{Fin}\,1, p(i))$ holds if and only if $p(0)$ holds.
Fin.forall_fin_two theorem
{p : Fin 2 → Prop} : (∀ i, p i) ↔ p 0 ∧ p 1
Full source
theorem forall_fin_two {p : Fin 2 → Prop} : (∀ i, p i) ↔ p 0 ∧ p 1 :=
  forall_fin_succ.trans <| and_congr_right fun _ => forall_fin_one
Universal Quantification over $\mathrm{Fin}\,2$ is Equivalent to Conjunction at 0 and 1
Informal description
For any predicate $p$ defined on the finite type $\mathrm{Fin}\,2$, the universal statement $(\forall i \in \mathrm{Fin}\,2, p(i))$ holds if and only if both $p(0)$ and $p(1)$ hold.
Fin.exists_fin_two theorem
{p : Fin 2 → Prop} : (∃ i, p i) ↔ p 0 ∨ p 1
Full source
theorem exists_fin_two {p : Fin 2 → Prop} : (∃ i, p i) ↔ p 0 ∨ p 1 :=
  exists_fin_succ.trans <| or_congr_right exists_fin_one
Existence in $\mathrm{Fin}\,2$ is equivalent to $p(0) \lor p(1)$
Informal description
For any predicate $p$ defined on the finite type $\mathrm{Fin}\,2$, there exists an element $i \in \mathrm{Fin}\,2$ satisfying $p(i)$ if and only if $p(0)$ or $p(1)$ holds.
Fin.fin_two_eq_of_eq_zero_iff theorem
: ∀ {a b : Fin 2}, (a = 0 ↔ b = 0) → a = b
Full source
theorem fin_two_eq_of_eq_zero_iff : ∀ {a b : Fin 2}, (a = 0 ↔ b = 0) → a = b := by
  simp only [forall_fin_two]; decide
Equality in $\mathrm{Fin}\,2$ via Zero Equivalence
Informal description
For any two elements $a$ and $b$ in $\mathrm{Fin}\,2$ (the finite type with two elements), if $a = 0$ holds if and only if $b = 0$ holds, then $a = b$.
Fin.reverseInduction definition
{motive : Fin (n + 1) → Sort _} (last : motive (Fin.last n)) (cast : ∀ i : Fin n, motive i.succ → motive (castSucc i)) (i : Fin (n + 1)) : motive i
Full source
/--
Proves a statement by reverse induction on the underlying `Nat` value in a `Fin (n + 1)`.

For the induction:
 * `last` is the base case, demonstrating `motive (Fin.last n)`.
 * `cast` is the inductive step, assuming the motive for `(j : Fin n).succ` and demonstrating it for
    the predecessor `j.castSucc`.

`Fin.induction` is the non-reverse induction principle.
-/
@[elab_as_elim] def reverseInduction {motive : Fin (n + 1) → Sort _} (last : motive (Fin.last n))
    (cast : ∀ i : Fin n, motive i.succ → motive (castSucc i)) (i : Fin (n + 1)) : motive i :=
  if hi : i = Fin.last n then _root_.cast (congrArg motive hi.symm) last
  else
    let j : Fin n := ⟨i, Nat.lt_of_le_of_ne (Nat.le_of_lt_succ i.2) fun h => hi (Fin.ext h)⟩
    cast _ (reverseInduction last cast j.succ)
termination_by n + 1 - i
decreasing_by decreasing_with
  -- FIXME: we put the proof down here to avoid getting a dummy `have` in the definition
  try simp only [Nat.succ_sub_succ_eq_sub]
  exact Nat.add_sub_add_right .. ▸ Nat.sub_lt_sub_left i.2 (Nat.lt_succ_self i)
Reverse induction on finite natural numbers
Informal description
Given a natural number \( n \), a dependent type \( \text{motive} \) indexed by \( \text{Fin}(n + 1) \), and two functions: - \( \text{last} \) which proves \( \text{motive} \) for the last element \( \text{Fin.last}\,n \), - \( \text{cast} \) which, for any \( i : \text{Fin}\,n \), proves \( \text{motive}\,(\text{castSucc}\,i) \) assuming \( \text{motive}\,(i.\text{succ}) \), the function \( \text{reverseInduction} \) proves \( \text{motive}\,i \) for any \( i : \text{Fin}(n + 1) \) by reverse induction on the underlying natural number value. The base case is \( \text{Fin.last}\,n \), and the inductive step reduces the problem from \( i.\text{succ} \) to \( \text{castSucc}\,i \).
Fin.reverseInduction_last theorem
{n : Nat} {motive : Fin (n + 1) → Sort _} {zero succ} : (reverseInduction zero succ (Fin.last n) : motive (Fin.last n)) = zero
Full source
@[simp] theorem reverseInduction_last {n : Nat} {motive : Fin (n + 1) → Sort _} {zero succ} :
    (reverseInduction zero succ (Fin.last n) : motive (Fin.last n)) = zero := by
  rw [reverseInduction]; simp
Reverse Induction Base Case for Last Element of $\text{Fin}(n+1)$
Informal description
For any natural number $n$ and any dependent type $\text{motive}$ indexed by $\text{Fin}(n+1)$, the reverse induction function applied to the last element $\text{Fin.last}\,n$ yields the base case value $\text{zero}$.
Fin.reverseInduction_castSucc theorem
{n : Nat} {motive : Fin (n + 1) → Sort _} {zero succ} (i : Fin n) : reverseInduction (motive := motive) zero succ (castSucc i) = succ i (reverseInduction zero succ i.succ)
Full source
@[simp] theorem reverseInduction_castSucc {n : Nat} {motive : Fin (n + 1) → Sort _} {zero succ}
    (i : Fin n) : reverseInduction (motive := motive) zero succ (castSucc i) =
      succ i (reverseInduction zero succ i.succ) := by
  rw [reverseInduction, dif_neg (Fin.ne_of_lt (Fin.castSucc_lt_last i))]; rfl
Recursive Relation for Reverse Induction on Finite Types
Informal description
For any natural number $n$, dependent type family $\text{motive}$ on $\mathrm{Fin}(n+1)$, and functions $\text{zero}$ and $\text{succ}$, the reverse induction principle satisfies the following recursive relation: for any $i \in \mathrm{Fin}\,n$, the value of the reverse induction at $\mathrm{castSucc}\,i$ equals $\text{succ}$ applied to $i$ and the reverse induction value at $i.\text{succ}$.
Fin.lastCases definition
{n : Nat} {motive : Fin (n + 1) → Sort _} (last : motive (Fin.last n)) (cast : ∀ i : Fin n, motive (castSucc i)) (i : Fin (n + 1)) : motive i
Full source
/--
Proves a statement by cases on the underlying `Nat` value in a `Fin (n + 1)`, checking whether the
value is the greatest representable or a predecessor of some other.

The two cases are:
 * `last`, used when the value is `Fin.last n`
 * `cast`, used when the value is of the form `(j : Fin n).succ`

The corresponding induction principle is `Fin.reverseInduction`.
-/
@[elab_as_elim] def lastCases {n : Nat} {motive : Fin (n + 1) → Sort _} (last : motive (Fin.last n))
    (cast : ∀ i : Fin n, motive (castSucc i)) (i : Fin (n + 1)) : motive i :=
  reverseInduction last (fun i _ => cast i) i
Case analysis on finite natural numbers via last and cast
Informal description
Given a natural number \( n \), a dependent type \( \text{motive} \) indexed by \( \text{Fin}(n + 1) \), and two functions: - \( \text{last} \) which proves \( \text{motive} \) for the last element \( \text{Fin.last}\,n \), - \( \text{cast} \) which, for any \( i : \text{Fin}\,n \), proves \( \text{motive}\,(\text{castSucc}\,i) \), the function \( \text{lastCases} \) proves \( \text{motive}\,i \) for any \( i : \text{Fin}(n + 1) \) by considering two cases: 1. If \( i \) is the last element \( \text{Fin.last}\,n \), it uses the proof \( \text{last} \). 2. If \( i \) is of the form \( \text{castSucc}\,j \) for some \( j : \text{Fin}\,n \), it uses the proof \( \text{cast}\,j \). This is implemented via `reverseInduction` by ignoring the inductive hypothesis in the `cast` case.
Fin.lastCases_last theorem
{n : Nat} {motive : Fin (n + 1) → Sort _} {last cast} : (Fin.lastCases last cast (Fin.last n) : motive (Fin.last n)) = last
Full source
@[simp] theorem lastCases_last {n : Nat} {motive : Fin (n + 1) → Sort _} {last cast} :
    (Fin.lastCases last cast (Fin.last n) : motive (Fin.last n)) = last :=
  reverseInduction_last ..
Case Analysis on Last Element of $\text{Fin}(n+1)$ Yields Last Case
Informal description
For any natural number $n$ and any dependent type family $\text{motive}$ on $\text{Fin}(n+1)$, the case analysis function `Fin.lastCases` applied to the last element $\text{Fin.last}\,n$ with arguments $\text{last}$ and $\text{cast}$ returns the value $\text{last}$.
Fin.lastCases_castSucc theorem
{n : Nat} {motive : Fin (n + 1) → Sort _} {last cast} (i : Fin n) : (Fin.lastCases last cast (Fin.castSucc i) : motive (Fin.castSucc i)) = cast i
Full source
@[simp] theorem lastCases_castSucc {n : Nat} {motive : Fin (n + 1) → Sort _} {last cast}
    (i : Fin n) : (Fin.lastCases last cast (Fin.castSucc i) : motive (Fin.castSucc i)) = cast i :=
  reverseInduction_castSucc ..
Behavior of `lastCases` on `castSucc` elements in finite types
Informal description
For any natural number $n$, dependent type family $\text{motive}$ on $\mathrm{Fin}(n+1)$, and functions $\text{last}$ and $\text{cast}$, the case analysis function $\text{lastCases}$ satisfies the following property: for any $i \in \mathrm{Fin}\,n$, the value of $\text{lastCases}$ at $\mathrm{castSucc}\,i$ equals $\text{cast}\,i$.
Fin.addCases definition
{m n : Nat} {motive : Fin (m + n) → Sort u} (left : ∀ i, motive (castAdd n i)) (right : ∀ i, motive (natAdd m i)) (i : Fin (m + n)) : motive i
Full source
/--
A case analysis operator for `i : Fin (m + n)` that separately handles the cases where `i < m` and
where `m ≤ i < m + n`.

The first case, where `i < m`, is handled by `left`. In this case, `i` can be represented as
`Fin.castAdd n (j : Fin m)`.

The second case, where `m ≤ i < m + n`, is handled by `right`. In this case, `i` can be represented
as `Fin.natAdd m (j : Fin n)`.
-/
@[elab_as_elim] def addCases {m n : Nat} {motive : Fin (m + n) → Sort u}
    (left : ∀ i, motive (castAdd n i)) (right : ∀ i, motive (natAdd m i))
    (i : Fin (m + n)) : motive i :=
  if hi : (i : Nat) < m then (castAdd_castLT n i hi) ▸ (left (castLT i hi))
  else (natAdd_subNat_cast (Nat.le_of_not_lt hi)) ▸ (right _)
Case analysis for elements of `Fin (m + n)` based on their position relative to `m`
Informal description
Given natural numbers \( m \) and \( n \), the function `Fin.addCases` provides a case analysis for an element \( i \) of the finite type `Fin (m + n)`. It handles two cases: 1. If \( i < m \), it applies the function `left` to the corresponding element of `Fin m` (obtained via `castAdd n`). 2. If \( m \leq i < m + n \), it applies the function `right` to the corresponding element of `Fin n` (obtained via `natAdd m`).
Fin.addCases_left theorem
{m n : Nat} {motive : Fin (m + n) → Sort _} {left right} (i : Fin m) : addCases (motive := motive) left right (Fin.castAdd n i) = left i
Full source
@[simp] theorem addCases_left {m n : Nat} {motive : Fin (m + n) → Sort _} {left right} (i : Fin m) :
    addCases (motive := motive) left right (Fin.castAdd n i) = left i := by
  rw [addCases, dif_pos (castAdd_lt _ _)]; rfl
Case Analysis Reduction for Left Component in $\text{Fin}(m + n)$
Informal description
For any natural numbers $m$ and $n$, and any function `left` that maps elements of $\text{Fin}\, m$ to a type `motive`, the application of `addCases` with `left` and any function `right` to the element $\text{castAdd}\, n\, i$ (where $i \in \text{Fin}\, m$) reduces to `left i$.
Fin.addCases_right theorem
{m n : Nat} {motive : Fin (m + n) → Sort _} {left right} (i : Fin n) : addCases (motive := motive) left right (natAdd m i) = right i
Full source
@[simp]
theorem addCases_right {m n : Nat} {motive : Fin (m + n) → Sort _} {left right} (i : Fin n) :
    addCases (motive := motive) left right (natAdd m i) = right i := by
  have : ¬(natAdd m i : Nat) < m := Nat.not_lt.2 (le_coe_natAdd ..)
  rw [addCases, dif_neg this]; exact eq_of_heq <| (eqRec_heq _ _).trans (by congr 1; simp)
Right Case Evaluation in Finite Type Addition Decomposition
Informal description
For any natural numbers $m$ and $n$, and any dependent type family $\text{motive} : \text{Fin}(m + n) \to \text{Sort } u$, given functions $\text{left} : \forall i \in \text{Fin}(m), \text{motive}(\text{castAdd}\,n\,i)$ and $\text{right} : \forall i \in \text{Fin}(n), \text{motive}(\text{natAdd}\,m\,i)$, and an element $i \in \text{Fin}(n)$, the application of $\text{addCases}$ to $\text{left}$, $\text{right}$, and $\text{natAdd}\,m\,i$ evaluates to $\text{right}\,i$.
Fin.ofNat'_add theorem
[NeZero n] (x : Nat) (y : Fin n) : Fin.ofNat' n x + y = Fin.ofNat' n (x + y.val)
Full source
theorem ofNat'_add [NeZero n] (x : Nat) (y : Fin n) :
    Fin.ofNat' n x + y = Fin.ofNat' n (x + y.val) := by
  apply Fin.eq_of_val_eq
  simp [Fin.ofNat', Fin.add_def]
Addition of Natural Number Embedding with Finite Type Element
Informal description
For any natural number $x$ and any element $y$ of the finite type $\text{Fin } n$ (where $n$ is non-zero), the sum of the canonical embedding of $x$ into $\text{Fin } n$ and $y$ is equal to the canonical embedding of $x + y$ into $\text{Fin } n$, where $y$ is interpreted as a natural number via the $\text{val}$ function.
Fin.add_ofNat' theorem
[NeZero n] (x : Fin n) (y : Nat) : x + Fin.ofNat' n y = Fin.ofNat' n (x.val + y)
Full source
theorem add_ofNat' [NeZero n] (x : Fin n) (y : Nat) :
    x + Fin.ofNat' n y = Fin.ofNat' n (x.val + y) := by
  apply Fin.eq_of_val_eq
  simp [Fin.ofNat', Fin.add_def]
Addition with Canonical Embedding in Finite Types: $x + \text{ofNat}'\,y = \text{ofNat}'(x.\text{val} + y)$
Informal description
For any natural number $n \neq 0$, any element $x$ of the finite type $\text{Fin } n$, and any natural number $y$, the sum of $x$ and the canonical embedding of $y$ into $\text{Fin } n$ is equal to the canonical embedding of the sum of the underlying natural numbers $x.\text{val} + y$ into $\text{Fin } n$.
Fin.coe_sub theorem
(a b : Fin n) : ((a - b : Fin n) : Nat) = ((n - b) + a) % n
Full source
protected theorem coe_sub (a b : Fin n) : ((a - b : Fin n) : Nat) = ((n - b) + a) % n := by
  cases a; cases b; rfl
Natural Number Representation of Finite Difference: $\text{Fin } n$ Subtraction
Informal description
For any two elements $a$ and $b$ of the finite type $\text{Fin } n$, the natural number obtained by coercing the difference $a - b$ (computed in $\text{Fin } n$) is equal to $((n - b) + a) \mod n$.
Fin.ofNat'_sub theorem
[NeZero n] (x : Nat) (y : Fin n) : Fin.ofNat' n x - y = Fin.ofNat' n ((n - y.val) + x)
Full source
theorem ofNat'_sub [NeZero n] (x : Nat) (y : Fin n) :
    Fin.ofNat' n x - y = Fin.ofNat' n ((n - y.val) + x) := by
  apply Fin.eq_of_val_eq
  simp [Fin.ofNat', Fin.sub_def]
Subtraction of Canonical Embedding in Finite Types: $\text{ofNat'}_n x - y = \text{ofNat'}_n ((n - y) + x)$
Informal description
For any natural number $x$ and any element $y$ of the finite type $\text{Fin } n$ (where $n$ is non-zero), the subtraction of the canonical embedding of $x$ into $\text{Fin } n$ minus $y$ is equal to the canonical embedding of $(n - y) + x$ into $\text{Fin } n$. In symbols, if $\text{ofNat'}_n : \mathbb{N} \to \text{Fin } n$ is the canonical embedding, then for any $x \in \mathbb{N}$ and $y \in \text{Fin } n$, we have: \[ \text{ofNat'}_n x - y = \text{ofNat'}_n ((n - y) + x). \]
Fin.sub_ofNat' theorem
[NeZero n] (x : Fin n) (y : Nat) : x - Fin.ofNat' n y = Fin.ofNat' n ((n - y % n) + x.val)
Full source
theorem sub_ofNat' [NeZero n] (x : Fin n) (y : Nat) :
    x - Fin.ofNat' n y = Fin.ofNat' n ((n - y % n) + x.val) := by
  apply Fin.eq_of_val_eq
  simp [Fin.ofNat', Fin.sub_def]
Subtraction of Natural Number Embedding in Finite Type: $x - \mathrm{ofNat'}_n(y) = \mathrm{ofNat'}_n((n - (y \bmod n)) + x)$
Informal description
For a positive natural number $n$ (i.e., $n \neq 0$) and given $x \in \mathrm{Fin}(n)$ and $y \in \mathbb{N}$, the subtraction $x - \mathrm{ofNat'}_n(y)$ in $\mathrm{Fin}(n)$ equals $\mathrm{ofNat'}_n((n - (y \bmod n)) + x)$, where $\mathrm{ofNat'}_n(k)$ is the canonical embedding of $k \in \mathbb{N}$ into $\mathrm{Fin}(n)$ via modulo reduction.
Fin.sub_self theorem
[NeZero n] {x : Fin n} : x - x = 0
Full source
@[simp] protected theorem sub_self [NeZero n] {x : Fin n} : x - x = 0 := by
  ext
  rw [Fin.sub_def]
  simp
Self-Subtraction in Finite Types: $x - x = 0$
Informal description
For any non-zero natural number $n$ and any element $x$ in the finite type $\mathrm{Fin}\,n$, the subtraction $x - x$ equals $0$.
Fin.coe_sub_iff_le theorem
{a b : Fin n} : (↑(a - b) : Nat) = a - b ↔ b ≤ a
Full source
theorem coe_sub_iff_le {a b : Fin n} : (↑(a - b) : Nat) = a - b ↔ b ≤ a := by
  rw [sub_def, le_def]
  dsimp only
  if h : n ≤ (n - b) + a then
    rw [Nat.mod_eq_sub_of_lt_two_mul h]
    all_goals omega
  else
    rw [Nat.mod_eq_of_lt]
    all_goals omega
Natural Number Subtraction in Finite Types Reflects Order: $\mathrm{val}(a - b) = a - b \leftrightarrow b \leq a$
Informal description
For any two elements $a$ and $b$ in the finite type $\mathrm{Fin}\,n$ (natural numbers less than $n$), the natural number value of $a - b$ equals the natural number subtraction $a - b$ if and only if $b \leq a$ in $\mathrm{Fin}\,n$.
Fin.sub_val_of_le theorem
{a b : Fin n} : b ≤ a → (a - b).val = a.val - b.val
Full source
theorem sub_val_of_le {a b : Fin n} : b ≤ a → (a - b).val = a.val - b.val :=
  coe_sub_iff_le.2
Subtraction Preserves Values in Finite Types under Order Condition: $(a - b).\mathrm{val} = a.\mathrm{val} - b.\mathrm{val}$ when $b \leq a$
Informal description
For any two elements $a$ and $b$ in the finite type $\mathrm{Fin}\,n$ (natural numbers less than $n$), if $b \leq a$, then the underlying natural number value of $a - b$ is equal to the difference of their underlying values, i.e., $(a - b).\mathrm{val} = a.\mathrm{val} - b.\mathrm{val}$.
Fin.coe_sub_iff_lt theorem
{a b : Fin n} : (↑(a - b) : Nat) = n + a - b ↔ a < b
Full source
theorem coe_sub_iff_lt {a b : Fin n} : (↑(a - b) : Nat) = n + a - b ↔ a < b := by
  rw [sub_def, lt_def]
  dsimp only
  if h : n ≤ (n - b) + a then
    rw [Nat.mod_eq_sub_of_lt_two_mul h]
    all_goals omega
  else
    rw [Nat.mod_eq_of_lt]
    all_goals omega
Casting Subtraction in Finite Types: $\mathrm{cast}(a - b) = n + a - b \leftrightarrow a < b$
Informal description
For any two elements $a$ and $b$ in the finite type $\mathrm{Fin}\,n$ (natural numbers less than $n$), the natural number obtained by casting the difference $a - b$ equals $n + a - b$ if and only if $a < b$.
Fin.val_mul theorem
{n : Nat} : ∀ a b : Fin n, (a * b).val = a.val * b.val % n
Full source
theorem val_mul {n : Nat} : ∀ a b : Fin n, (a * b).val = a.val * b.val % n
  | ⟨_, _⟩, ⟨_, _⟩ => rfl
Modular Property of Multiplication in $\text{Fin}\,n$: $(a * b).\text{val} = (a.\text{val} * b.\text{val}) \mod n$
Informal description
For any two elements $a$ and $b$ in the finite type $\text{Fin}\,n$, the underlying natural number value of their product $a * b$ is equal to the product of their underlying values modulo $n$, i.e., $(a * b).\text{val} = (a.\text{val} * b.\text{val}) \mod n$.
Fin.coe_mul theorem
{n : Nat} : ∀ a b : Fin n, ((a * b : Fin n) : Nat) = a * b % n
Full source
theorem coe_mul {n : Nat} : ∀ a b : Fin n, ((a * b : Fin n) : Nat) = a * b % n
  | ⟨_, _⟩, ⟨_, _⟩ => rfl
Modular Multiplication Preserved Under Casting in Finite Types
Informal description
For any natural number $n$ and any elements $a, b$ in the finite type $\text{Fin}\,n$, the natural number obtained by casting the product $a * b$ (computed modulo $n$) to $\mathbb{N}$ equals the product of the natural number values of $a$ and $b$ modulo $n$, i.e., $(a * b : \mathbb{N}) = (a : \mathbb{N}) * (b : \mathbb{N}) \mod n$.
Fin.mul_one theorem
(k : Fin (n + 1)) : k * 1 = k
Full source
protected theorem mul_one (k : Fin (n + 1)) : k * 1 = k := by
  match n with
  | 0 => exact Subsingleton.elim (α := Fin 1) ..
  | n+1 => simp [Fin.ext_iff, mul_def, Nat.mod_eq_of_lt (is_lt k)]
Right Multiplicative Identity in Finite Types: $k \times 1 = k$
Informal description
For any element $k$ in the finite type $\mathrm{Fin}(n+1)$, the product of $k$ and the multiplicative identity $1$ equals $k$, i.e., $k \times 1 = k$.
Fin.mul_comm theorem
(a b : Fin n) : a * b = b * a
Full source
protected theorem mul_comm (a b : Fin n) : a * b = b * a :=
  Fin.ext <| by rw [mul_def, mul_def, Nat.mul_comm]
Commutativity of Multiplication in Finite Types
Informal description
For any two elements $a$ and $b$ in the finite type $\mathrm{Fin}\,n$, the multiplication operation is commutative, i.e., $a * b = b * a$.
Fin.instCommutativeHMul instance
: Std.Commutative (α := Fin n) (· * ·)
Full source
instance : Std.Commutative (α := Fin n) (· * ·) := ⟨Fin.mul_comm⟩
Commutativity of Multiplication in $\mathrm{Fin}\,n$
Informal description
For any natural number $n$, the multiplication operation on the finite type $\mathrm{Fin}\,n$ is commutative. That is, for any elements $a, b \in \mathrm{Fin}\,n$, we have $a * b = b * a$.
Fin.mul_assoc theorem
(a b c : Fin n) : a * b * c = a * (b * c)
Full source
protected theorem mul_assoc (a b c : Fin n) : a * b * c = a * (b * c) := by
  apply eq_of_val_eq
  simp only [val_mul]
  rw [← Nat.mod_eq_of_lt a.isLt, ← Nat.mod_eq_of_lt b.isLt, ← Nat.mod_eq_of_lt c.isLt]
  simp only [← Nat.mul_mod, Nat.mul_assoc]
Associativity of Multiplication in $\text{Fin}\,n$: $(a * b) * c = a * (b * c)$
Informal description
For any elements $a, b, c$ in the finite type $\text{Fin}\,n$, the multiplication operation is associative, i.e., $(a * b) * c = a * (b * c)$.
Fin.instAssociativeHMul instance
: Std.Associative (α := Fin n) (· * ·)
Full source
instance : Std.Associative (α := Fin n) (· * ·) := ⟨Fin.mul_assoc⟩
Associativity of Multiplication in $\text{Fin}\,n$
Informal description
For any natural number $n$, the multiplication operation on the finite type $\text{Fin}\,n$ is associative.
Fin.one_mul theorem
(k : Fin (n + 1)) : (1 : Fin (n + 1)) * k = k
Full source
protected theorem one_mul (k : Fin (n + 1)) : (1 : Fin (n + 1)) * k = k := by
  rw [Fin.mul_comm, Fin.mul_one]
Left Multiplicative Identity in Finite Types: $1 \times k = k$
Informal description
For any element $k$ in the finite type $\mathrm{Fin}(n+1)$, the product of the multiplicative identity $1$ and $k$ equals $k$, i.e., $1 \times k = k$.
Fin.instLawfulIdentityHAddNatOfNatHMul instance
: Std.LawfulIdentity (α := Fin (n + 1)) (· * ·) 1
Full source
instance : Std.LawfulIdentity (α := Fin (n + 1)) (· * ·) 1 where
  left_id := Fin.one_mul
  right_id := Fin.mul_one
Multiplicative Identity in Finite Types
Informal description
For any natural number $n$, the element $1$ is a verified left and right identity for multiplication in the finite type $\mathrm{Fin}(n+1)$. That is, for all $k \in \mathrm{Fin}(n+1)$, we have $1 \cdot k = k$ and $k \cdot 1 = k$.
Fin.mul_zero theorem
(k : Fin (n + 1)) : k * 0 = 0
Full source
protected theorem mul_zero (k : Fin (n + 1)) : 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 element $k$ in the finite type $\text{Fin}(n+1)$, the product of $k$ and $0$ is equal to $0$, i.e., $k \cdot 0 = 0$.
Fin.zero_mul theorem
(k : Fin (n + 1)) : (0 : Fin (n + 1)) * k = 0
Full source
protected theorem zero_mul (k : Fin (n + 1)) : (0 : Fin (n + 1)) * k = 0 := by
  simp [Fin.ext_iff, mul_def]
Zero Multiplication Identity in Finite Types: $0 \cdot k = 0$
Informal description
For any natural number $n$ and any element $k$ in the finite type $\text{Fin}(n+1)$, the product of the zero element $0$ and $k$ is equal to zero, i.e., $0 \cdot k = 0$.