Inductive type variant of fin
#
THIS FILE IS SYNCHRONIZED WITH MATHLIB4. Any changes to this file require a corresponding PR to mathlib4.
fin
is defined as a subtype of ℕ
. This file defines an equivalent type, fin2
, which is
defined inductively. This is useful for its induction principle and different definitional
equalities.
Main declarations #
fin2 n
: Inductive type variant offin n
.fz
corresponds to0
andfs n
corresponds ton
.to_nat
,opt_of_nat
,of_nat'
: Conversions to and fromℕ
.of_nat' m
takes a proof thatm < n
through the classis_lt
.add k
: Takesi : fin2 n
toi + k : fin2 (n + k)
.left
: Embedsfin2 n
intofin2 (n + k)
.insert_perm a
: Permutation offin2 n
which cycles0, ..., a - 1
and leavesa, ..., n - 1
unchanged.remap_left f
: Functionfin2 (m + k) → fin2 (n + k)
by applyingf : fin m → fin n
to0, ..., m - 1
and sendingm + i
ton + i
.
Define a dependent function on fin2 (succ n)
by giving its value at
zero (H1
) and by giving a dependent function on the rest (H2
).
Equations
- fin2.cases' H1 H2 n_1.fs = H2 n_1
- fin2.cases' H1 H2 fin2.fz = H1
Converts a natural into a fin2
if it is in range
Equations
insert_perm a
is a permutation of fin2 n
with the following properties:
insert_perm a i = i+1
ifi < a
insert_perm a a = 0
insert_perm a i = i
ifi > a
remap_left f k : fin2 (m + k) → fin2 (n + k)
applies the function
f : fin2 m → fin2 n
to inputs less than m
, and leaves the right part
on the right (that is, remap_left f k (m + i) = n + i
).
Equations
- fin2.remap_left f k.succ i.fs = (fin2.remap_left f k i).fs
- fin2.remap_left f k.succ fin2.fz = fin2.fz
- fin2.remap_left f 0 i = f i
- h : m < n
This is a simple type class inference prover for proof obligations
of the form m < n
where m n : ℕ
.
Instances of this typeclass
Instances of other typeclasses for fin2.is_lt
- fin2.is_lt.has_sizeof_inst
Equations
- fin2.is_lt.zero n = {h := _}
Equations
- fin2.is_lt.succ m n = {h := _}
Use type class inference to infer the boundedness proof, so that we can directly convert a
nat
into a fin2 n
. This supports notation like &1 : fin 3
.
Equations
- fin2.of_nat' m.succ = (fin2.of_nat' m).fs
- fin2.of_nat' 0 = fin2.fz
- fin2.of_nat' m = absurd h _
Equations
- fin2.inhabited = {default := fin2.fz 0}