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
- 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.succEmb n = OrderEmbedding.ofStrictMono Fin.succ (_ : StrictMono 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
- 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 #
castPred i
sends i : Fin (n + 1)
to Fin n
as long as i ≠ last n.
Equations
- Fin.castPred i h = Fin.castLT i (_ : ↑i < n)
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 (_ : ∀ (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 }
mul #
Equations
- One or more equations did not get rendered due to their size.