The finite type with n elements #
Fin n is the type whose elements are natural numbers smaller than n.
This file expands on the development in the core library.
Main definitions #
Induction principles #
finZeroElim: Elimination principle for the empty setFin 0, generalizesFin.elim0.Fin.succRec: DefineC n iby induction oni : Fin ninterpreted as(0 : Fin (n - i)).succ.succ…. This function has two arguments:H0 ndefines0-th elementC (n+1) 0of an(n+1)-tuple, andHs n idefines(i+1)-st element of(n+1)-tuple based onn,i, andi-th element ofn-tuple.Fin.succRecOn: same asFin.succRecbuti : Fin nis the first argument;Fin.induction: DefineC iby induction oni : Fin (n + 1), separating into theNat-like base cases ofC 0andC (i.succ).Fin.inductionOn: same asFin.inductionbut withi : Fin (n + 1)as the first argument.Fin.cases: definef : Π i : Fin n.succ, C iby separately handling the casesi = 0andi = Fin.succ j,j : Fin n, defined usingFin.induction.Fin.reverseInduction: reverse induction oni : Fin (n + 1); givenC (Fin.last n)and∀ i : Fin n, C (Fin.succ i) → C (Fin.castSucc i), constructs all valuesC iby going down;Fin.lastCases: definef : Π i, Fin (n + 1), C iby separately handling the casesi = Fin.last nandi = Fin.castSucc j, a special case ofFin.reverseInduction;Fin.addCases: define a function onFin (m + n)by separately handling the casesFin.castAdd n iandFin.natAdd m i.
Embeddings and isomorphisms #
Fin.valEmbedding: coercion to natural numbers as anEmbedding;Fin.succEmb:Fin.succas anEmbedding;Fin.castLEEmb h:Fin.castLEas anEmbedding, embedFin nintoFin m,h : n ≤ m;finCongr:Fin.castas anEquiv, equivalence betweenFin nandFin mwhenn = m;Fin.castAddEmb m:Fin.castAddas anEmbedding, embedFin nintoFin (n+m);Fin.castSuccEmb:Fin.castSuccas anEmbedding, embedFin nintoFin (n+1);Fin.addNatEmb m i:Fin.addNatas anEmbedding, addmonion the right, generalizesFin.succ;Fin.natAddEmb n i:Fin.natAddas anEmbedding, addsnonion the left;
Other casts #
Fin.ofNat': given a positive numbern(deduced from[NeZero n]),Fin.ofNat' iisi % ninterpreted as an element ofFin n;Fin.divNat i: dividesi : Fin (m * n)byn;Fin.modNat i: takes the mod ofi : Fin (m * n)byn;
Elimination principle for the empty set Fin 0, dependent version.
Equations
- finZeroElim x = x.elim0
Instances For
coercions and constructions #
order #
The inclusion map Fin n → ℕ is an embedding.
Equations
- Fin.valEmbedding = { toFun := Fin.val, inj' := ⋯ }
Instances For
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⟩
Given a positive n, Fin.ofNat' i is i % n as an element of Fin n.
Equations
- Fin.ofNat'' i = ⟨i % n, ⋯⟩
Instances For
Alias of Fin.val_zero.
Fin.mk_zero in Lean only applies in Fin (n + 1).
This one instead uses a NeZero n typeclass hypothesis.
The Fin.zero_le in Lean only applies in Fin (n+1).
This one instead uses a NeZero n typeclass hypothesis.
Coercions to ℤ and the fin_omega tactic. #
Preprocessor for omega to handle inequalities in Fin.
Note that this involves a lot of case splitting, so may be slow.
Equations
- Fin.tacticFin_omega = Lean.ParserDescr.node `Fin.tacticFin_omega 1024 (Lean.ParserDescr.nonReservedSymbol "fin_omega" false)
Instances For
addition, numerals, and coercion from Nat #
Equations
Equations
- Fin.instNatCast = { natCast := fun (i : ℕ) => Fin.ofNat' n i }
succ and casts into larger Fin types #
The Fin.succ_one_eq_two in Lean only applies in Fin (n+2).
This one instead uses a NeZero n typeclass hypothesis.
Fin.castLE as an Embedding, castLEEmb h i embeds i into a larger Fin type.
Equations
- Fin.castLEEmb h = { toFun := Fin.castLE h, inj' := ⋯ }
Instances For
While in many cases finCongr is better than Equiv.cast/cast, sometimes we want to apply
a generic theorem about cast.
Fin.castAdd as an Embedding, castAddEmb m i embeds i : Fin n in Fin (n+m).
See also Fin.natAddEmb and Fin.addNatEmb.
Equations
Instances For
The Fin.castSucc_zero in Lean only applies in Fin (n+1).
This one instead uses a NeZero n typeclass hypothesis.
Fin.addNat as an Embedding, addNatEmb m i adds m to i, generalizes Fin.succ.
Equations
- Fin.addNatEmb m = { toFun := fun (x : Fin n) => x.addNat m, inj' := ⋯ }
Instances For
Fin.natAdd as an Embedding, natAddEmb n i adds n to i "on the left".
Equations
- Fin.natAddEmb n = { toFun := Fin.natAdd n, inj' := ⋯ }
Instances For
pred #
Fin.succAbove p as an Embedding.
Equations
- p.succAboveEmb = { toFun := p.succAbove, inj' := ⋯ }
Instances For
succAbove is injective at the pivot
By moving succ to the outside of this expression, we create opportunities for further
simplification using succAbove_zero or succ_succAbove_zero.