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;Fin.succAboveCases: giveni : Fin (n + 1), define a function onFin (n + 1)by separately handling the casesj = iandj = Fin.succAbove i k, same asFin.insertNthbut marked as eliminator and works forSort*. -- Porting note: this is in another file
Order embeddings and an order isomorphism #
Fin.orderIsoSubtype: coercion to{ i // i < n }as anOrderIso;Fin.valEmbedding: coercion to natural numbers as anEmbedding;Fin.valOrderEmbedding: coercion to natural numbers as anOrderEmbedding;Fin.succEmbedding:Fin.succas anOrderEmbedding;Fin.castLEEmb h:Fin.castLEas anOrderEmbedding, embedFin nintoFin m,h : n ≤ m;Fin.castIso:Fin.castas anOrderIso, order isomorphism betweenFin nandFin mprovided thatn = m, see alsoEquiv.finCongr;Fin.castAddEmb m:Fin.castAddas anOrderEmbedding, embedFin nintoFin (n+m);Fin.castSuccEmb:Fin.castSuccas anOrderEmbedding, embedFin nintoFin (n+1);Fin.succAboveEmb p:Fin.auccAboveas anOrderEmbedding, embedFin nintoFin (n + 1)with a hole aroundp;Fin.addNatEmb m i:Fin.addNatas anOrderEmbedding, addmonion the right, generalizesFin.succ;Fin.natAddEmb n i:Fin.natAddas anOrderEmbedding, 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;
Misc definitions #
Fin.revPerm : Equiv.Perm (Fin n):Fin.revas anEquiv.Perm, the antitone involution given byi ↦ n-(i+1)
Elimination principle for the empty set Fin 0, dependent version.
Equations
- finZeroElim x = Fin.elim0 x
Instances For
coercions and constructions #
order #
Equations
- One or more equations did not get rendered due to their size.
Equations
- Fin.instPartialOrderFin = inferInstance
The inclusion map Fin n → ℕ is an embedding.
Equations
- Fin.valEmbedding = { toFun := Fin.val, inj' := (_ : Function.Injective Fin.val) }
Instances For
The ordering on Fin n is a well order.
Equations
- (_ : IsWellOrder (Fin n) fun (x x_1 : Fin n) => x < x_1) = (_ : IsWellOrder (Fin n) fun (x x_1 : Fin n) => x < x_1)
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 = { val := i % n, isLt := (_ : i % n < n) }
Instances For
Equations
- Fin.instZeroFin = { zero := Fin.ofNat'' 0 }
Equations
- Fin.instOneFin = { one := Fin.ofNat'' 1 }
The Fin.val_zero in Std only applies in Fin (n+1).
This one instead uses a NeZero n typeclass hypothesis.
The Fin.zero_le in Std only applies in Fin (n+1).
This one instead uses a NeZero n typeclass hypothesis.
Fin.rev as an Equiv.Perm, the antitone involution Fin n → Fin n given by
i ↦ n-(i+1).
Equations
- Fin.revPerm = Function.Involutive.toPerm Fin.rev (_ : Function.Involutive Fin.rev)
Instances For
Equations
- Fin.instBoundedOrderFinHAddNatInstHAddInstAddNatOfNatInstLEFin = BoundedOrder.mk
Equations
- (_ : Subsingleton (Fin n ≃o α)) = (_ : Subsingleton (Fin n ≃o α))
Equations
- (_ : Subsingleton (α ≃o Fin n)) = (_ : Subsingleton (α ≃o Fin n))
Two strictly monotone functions from Fin n are equal provided that their ranges
are equal.
addition, numerals, and coercion from Nat #
Equations
- (_ : Nontrivial (Fin (n + 2))) = (_ : Nontrivial (Fin (n + 2)))
Equations
- One or more equations did not get rendered due to their size.
Equations
- Fin.instOfNatFin = { ofNat := Fin.ofNat' a (_ : 0 < n) }
Equations
- Fin.inhabited n = { default := 0 }
Equations
- Fin.inhabitedFinOneAdd n = inferInstance
Equations
- Fin.addCommMonoid n = let src := Fin.addCommSemigroup n; AddCommMonoid.mk (_ : ∀ (a b : Fin n), a + b = b + a)
Equations
- Fin.instAddMonoidWithOne n = let src := inferInstanceAs (AddCommMonoid (Fin n)); AddMonoidWithOne.mk
succ and casts into larger Fin types #
Fin.succ as an OrderEmbedding
Equations
- Fin.succEmbedding n = OrderEmbedding.ofStrictMono Fin.succ (_ : ∀ (x x_1 : Fin n), x < x_1 → Nat.succ ↑x < Nat.succ ↑x_1)
Instances For
The Fin.succ_one_eq_two in Std only applies in Fin (n+2).
This one instead uses a NeZero n typeclass hypothesis.
Fin.castLE as an OrderEmbedding, castLEEmb h i embeds i into a larger Fin type.
Equations
- Fin.castLEEmb h = OrderEmbedding.ofStrictMono (Fin.castLE h) (_ : StrictMono (Fin.castLE h))
Instances For
While in many cases Fin.castIso is better than Equiv.cast/cast, sometimes we want to apply
a generic theorem about cast.
Fin.castAdd as an OrderEmbedding, castAddEmb m i embeds i : Fin n in Fin (n+m).
See also Fin.natAddEmb and Fin.addNatEmb.
Equations
- Fin.castAddEmb m = OrderEmbedding.ofStrictMono (Fin.castAdd m) (_ : StrictMono (Fin.castAdd m))
Instances For
Fin.castSucc as an OrderEmbedding, castSuccEmb i embeds i : Fin n in Fin (n+1).
Equations
- Fin.castSuccEmb = OrderEmbedding.ofStrictMono Fin.castSucc (_ : StrictMono Fin.castSucc)
Instances For
The Fin.castSucc_zero in Std only applies in Fin (n+1).
This one instead uses a NeZero n typeclass hypothesis.
castSucc i is positive when i is positive.
The Fin.castSucc_pos in Std only applies in Fin (n+1).
This one instead uses a NeZero n typeclass hypothesis.
The Fin.castSucc_eq_zero_iff in Std only applies in Fin (n+1).
This one instead uses a NeZero n typeclass hypothesis.
The Fin.castSucc_ne_zero_iff in Std only applies in Fin (n+1).
This one instead uses a NeZero n typeclass hypothesis.
Fin.addNat as an OrderEmbedding, addNatEmb m i adds m to i, generalizes
Fin.succ.
Equations
- Fin.addNatEmb m = OrderEmbedding.ofStrictMono (fun (x : Fin n) => Fin.addNat x m) (_ : StrictMono fun (x : Fin n) => Fin.addNat x m)
Instances For
Fin.natAdd as an OrderEmbedding, natAddEmb n i adds n to i "on the left".
Equations
- Fin.natAddEmb n = OrderEmbedding.ofStrictMono (Fin.natAdd n) (_ : StrictMono (Fin.natAdd n))
Instances For
pred #
recursion and induction principles #
A function f on Fin (n + 1) is strictly monotone if and only if f i < f (i + 1)
for all i.
A function f on Fin (n + 1) is strictly antitone if and only if f (i + 1) < f i
for all i.
Abelian group structure on Fin n.
Equations
- Fin.addCommGroup n = let src := Fin.addCommMonoid n; let src_1 := Fin.neg n; AddCommGroup.mk (_ : ∀ (a b : Fin n), a + b = b + a)
Note this is more general than Fin.addCommGroup as it applies (vacuously) to Fin 0 too.
Equations
- Fin.instInvolutiveNeg n = InvolutiveNeg.mk (_ : ∀ (x : Fin n), - -x = x)
Note this is more general than Fin.addCommGroup as it applies (vacuously) to Fin 0 too.
Equations
- (_ : IsCancelAdd (Fin n)) = (_ : IsCancelAdd (Fin n))
Note this is more general than Fin.addCommGroup as it applies (vacuously) to Fin 0 too.
Equations
- Fin.instAddLeftCancelSemigroup n = let src := Fin.addCommSemigroup n; let src_1 := (_ : IsCancelAdd (Fin n)); AddLeftCancelSemigroup.mk (_ : ∀ (a b c : Fin n), a + b = a + c → b = c)
Note this is more general than Fin.addCommGroup as it applies (vacuously) to Fin 0 too.
Equations
- Fin.instAddRightCancelSemigroup n = let src := Fin.addCommSemigroup n; let src_1 := (_ : IsCancelAdd (Fin n)); AddRightCancelSemigroup.mk (_ : ∀ (a b c : Fin n), a + b = c + b → a = c)
Equations
- Fin.uniqueFinOne = { toInhabited := Fin.inhabited 1, uniq := Fin.uniqueFinOne.proof_2 }
Fin.auccAbove as an OrderEmbedding, succAboveEmb p i embeds Fin n into Fin (n + 1)
with a hole around p.
Equations
- Fin.succAboveEmb p = OrderEmbedding.ofStrictMono (Fin.succAbove p) (_ : StrictMono (Fin.succAbove p))
Instances For
Embedding i : Fin n into Fin (n + 1) with a hole around p : Fin (n + 1)
embeds i by castSucc when the resulting i.castSucc < p.
Embedding i : Fin n into Fin (n + 1) with a hole around p : Fin (n + 1)
embeds i by succ when the resulting p < i.succ.
Embedding i : Fin n into Fin (n + 1) is always about some hole p.
Embedding i : Fin n into Fin (n + 1) using a pivot p that is greater
results in a value that is less than p.
Embedding i : Fin n into Fin (n + 1) using a pivot p that is lesser
results in a value that is greater than p.
The range of p.succAbove is everything except p.
Given a fixed pivot x : Fin (n + 1), x.succAbove is injective
succAbove is injective at the pivot
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.
predAbove p i embeds i : Fin (n+1) into Fin n by subtracting one if p < i.
Equations
- Fin.predAbove p i = if h : Fin.castSucc p < i then Fin.pred i (_ : i ≠ 0) else Fin.castLT i (_ : ↑i < n)
Instances For
castPred embeds i : Fin (n + 2) into Fin (n + 1)
by lowering just last (n + 1) to last n.
Equations
- Fin.castPred i = Fin.predAbove (Fin.last n) i
Instances For
Sending Fin (n+1) to Fin n by subtracting one from anything above p
then back to Fin (n+1) with a gap around p is the identity away from p.
Sending Fin n into Fin (n + 1) with a gap at p
then back to Fin n by subtracting one from anything above p is the identity.
pred commutes with succAbove.
succ commutes with predAbove.
mul #
Equations
- One or more equations did not get rendered due to their size.