The finite type with n elements #
Fin n is the type whose elements are natural numbers smaller than n.
This file expands on the development in the core library.
Main definitions #
finZeroElim: Elimination principle for the empty setFin 0, generalizesFin.elim0. Further definitions and eliminators can be found inInit.Data.Fin.LemmasFin.equivSubtype: Equivalence betweenFin nand{ i // i < n }.
Elimination principle for the empty set Fin 0, dependent version.
Instances For
A dependent variant of Fin.elim0.
Instances For
If you actually have an element of Fin n, then the n is always positive
Equivalence between Fin n and { i // i < n }.
Instances For
coercions and constructions #
Assume k = l. If two functions defined on Fin k and Fin l are equal on each element,
then they coincide (in the heq sense).
Assume k = l and k' = l'.
If two functions Fin k → Fin k' → α and Fin l → Fin l' → α are equal on each pair,
then they coincide (in the heq sense).
Two elements of Fin k and Fin l are heq iff their values in ℕ coincide. This requires
k = l. For the left implication without this assumption, see val_eq_val_of_heq.
order #
Fin.lt_or_ge is an alias of Fin.lt_or_le.
It is preferred since it follows the mathlib naming convention.
Fin.le_or_gt is an alias of Fin.le_or_lt.
It is preferred since it follows the mathlib naming convention.
a < b as natural numbers if and only if a < b in Fin n.
a ≤ b as natural numbers if and only if a ≤ b in Fin n.
Use the ordering on Fin n for checking recursive definitions.
For example, the following definition is not accepted by the termination checker,
unless we declare the WellFoundedRelation instance:
def factorial {n : ℕ} : Fin n → ℕ
| ⟨0, _⟩ := 1
| ⟨i + 1, hi⟩ := (i + 1) * factorial ⟨i, i.lt_succ_self.trans hi⟩
Fin.mk_zero in Lean only applies in Fin (n + 1).
This one instead uses a NeZero n typeclass hypothesis.
The Fin.pos_iff_ne_zero in Lean only applies in Fin (n+1).
This one instead uses a NeZero n typeclass hypothesis.
Coercions to ℤ and the fin_omega tactic. #
fin_omega is a preprocessor for omega to handle inequalities in Fin.
It rewrites all hypotheses and the goal, turning statements about addition, subtraction and
inequalities in Fin n into statements that omega can use/solve.
Note that this involves a lot of case splitting, so may be slow.
Instances For
addition, numerals, and coercion from Nat #
If working with more than two elements, we can always pick a third distinct from two existing elements.
Converting an in-range number to Fin (n + 1) produces a result
whose value is the original number.
Converting the value of a Fin n to Fin n results in the same value.
recursion and induction principles #
mul #
Alias of Fin.mul_one.
Alias of Fin.one_mul.
Alias of Fin.mul_zero.
Alias of Fin.zero_mul.