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 i
by induction oni : Fin n
interpreted as(0 : Fin (n - i)).succ.succ…
. This function has two arguments:H0 n
defines0
-th elementC (n+1) 0
of an(n+1)
-tuple, andHs n i
defines(i+1)
-st element of(n+1)
-tuple based onn
,i
, andi
-th element ofn
-tuple.Fin.succRecOn
: same asFin.succRec
buti : Fin n
is the first argument;Fin.induction
: DefineC i
by induction oni : Fin (n + 1)
, separating into theNat
-like base cases ofC 0
andC (i.succ)
.Fin.inductionOn
: same asFin.induction
but withi : Fin (n + 1)
as the first argument.Fin.cases
: definef : Π i : Fin n.succ, C i
by separately handling the casesi = 0
andi = 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 i
by going down;Fin.lastCases
: definef : Π i, Fin (n + 1), C i
by separately handling the casesi = Fin.last n
andi = Fin.castSucc j
, a special case ofFin.reverseInduction
;Fin.addCases
: define a function onFin (m + n)
by separately handling the casesFin.castAdd n i
andFin.natAdd m i
;Fin.succAboveCases
: giveni : Fin (n + 1)
, define a function onFin (n + 1)
by separately handling the casesj = i
andj = Fin.succAbove i k
, same asFin.insertNth
but 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.succEmb
:Fin.succ
as anOrderEmbedding
; -
Fin.castLEEmb h
:Fin.castLE
as anOrderEmbedding
, embedFin n
intoFin m
,h : n ≤ m
; -
Fin.castIso
:Fin.cast
as anOrderIso
, order isomorphism betweenFin n
andFin m
provided thatn = m
, see alsoEquiv.finCongr
; -
Fin.castAddEmb m
:Fin.castAdd
as anOrderEmbedding
, embedFin n
intoFin (n+m)
; -
Fin.castSuccEmb
:Fin.castSucc
as anOrderEmbedding
, embedFin n
intoFin (n+1)
; -
Fin.addNatEmb m i
:Fin.addNat
as anOrderEmbedding
, addm
oni
on the right, generalizesFin.succ
; -
Fin.natAddEmb n i
:Fin.natAdd
as anOrderEmbedding
, addsn
oni
on the left;
Other casts #
Fin.ofNat'
: given a positive numbern
(deduced from[NeZero n]
),Fin.ofNat' i
isi % n
interpreted 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.rev
as 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
- Fin.instLinearOrderFin = LinearOrder.liftWithOrd Fin.val ⋯ ⋯ ⋯ ⋯
Equations
- Fin.instPartialOrderFin = inferInstance
The equivalence Fin n ≃ { i // i < n }
is an order isomorphism.
Equations
- Fin.orderIsoSubtype = Equiv.toOrderIso Fin.equivSubtype ⋯ ⋯
Instances For
The inclusion map Fin n → ℕ
is an order embedding.
Equations
- Fin.valOrderEmbedding n = { toEmbedding := Fin.valEmbedding, map_rel_iff' := ⋯ }
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 = { val := i % n, isLt := ⋯ }
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 ⋯
Instances For
Equations
- Fin.instBoundedOrderFinHAddNatInstHAddInstAddNatOfNatInstLEFin = BoundedOrder.mk
Equations
- ⋯ = ⋯
Equations
- ⋯ = ⋯
Two strictly monotone functions from Fin n
are equal provided that their ranges
are equal.
addition, numerals, and coercion from Nat #
Equations
Equations
- Fin.instOfNatFin = { ofNat := Fin.ofNat' a ⋯ }
Equations
- Fin.inhabited n = { default := 0 }
Equations
- Fin.inhabitedFinOneAdd n = inferInstance
Equations
Equations
- Fin.addCommMonoid n = let __spread.0 := Fin.addCommSemigroup n; AddCommMonoid.mk ⋯
Equations
- Fin.instAddMonoidWithOne n = let __spread.0 := inferInstanceAs (AddCommMonoid (Fin n)); AddMonoidWithOne.mk ⋯ ⋯
succ and casts into larger Fin types #
Fin.succ
as an OrderEmbedding
Equations
- Fin.succEmb n = OrderEmbedding.ofStrictMono Fin.succ ⋯
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
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
Instances For
Fin.castSucc
as an OrderEmbedding
, castSuccEmb i
embeds i : Fin n
in Fin (n+1)
.
Equations
- Fin.castSuccEmb = OrderEmbedding.ofStrictMono 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) ⋯
Instances For
pred #
castPred i
sends i : Fin (n + 1)
to Fin n
as long as i ≠ last n.
Equations
- Fin.castPred i h = Fin.castLT i ⋯
Instances For
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 ⋯
Note this is more general than Fin.addCommGroup
as it applies (vacuously) to Fin 0
too.
Equations
Note this is more general than Fin.addCommGroup
as it applies (vacuously) to Fin 0
too.
Equations
- ⋯ = ⋯
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 := ⋯; AddLeftCancelSemigroup.mk ⋯
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 := ⋯; AddRightCancelSemigroup.mk ⋯
Equations
- Fin.uniqueFinOne = { toInhabited := Fin.inhabited 1, uniq := Fin.uniqueFinOne.proof_2 }
mul #
Equations
- One or more equations did not get rendered due to their size.