# Documentation

Mathlib.Data.Fin.Fin2

# Inductive type variant of Fin#

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 of Fin n. fz corresponds to 0 and fs n corresponds to n.
• Fin2.toNat, Fin2.optOfNat, Fin2.ofNat': Conversions to and from ℕ. ofNat' m takes a proof that m < n through the class Fin2.IsLT.
• Fin2.add k: Takes i : Fin2 n to i + k : Fin2 (n + k).
• Fin2.left: Embeds Fin2 n into Fin2 (n + k).
• Fin2.insertPerm a: Permutation of Fin2 n which cycles 0, ..., a - 1 and leaves a, ..., n - 1 unchanged.
• Fin2.remapLeft f: Function Fin2 (m + k) → Fin2 (n + k)→ Fin2 (n + k) by applying f : Fin m → Fin n→ Fin n to 0, ..., m - 1 and sending m + i to n + i.
inductive Fin2 :
• 0 as a member of Fin (succ n) (Fin 0 is empty)

fz: {n : } → Fin2 ()
• n as a member of Fin (succ n)

fs: {n : } → Fin2 nFin2 ()

An alternate definition of Fin n defined as an inductive type instead of a subtype of ℕ.

Instances For
def Fin2.cases' {n : } {C : Fin2 ()Sort u} (H1 : C Fin2.fz) (H2 : (n : Fin2 n) → C ()) (i : Fin2 ()) :
C 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
def Fin2.elim0 {C : Fin2 0Sort u} (i : Fin2 0) :
C i

Ex falso. The dependent eliminator for the empty Fin2 0 type.

Equations
• = nomatch a
def Fin2.toNat {n : } :
Fin2 n

Converts a Fin2 into a natural.

Equations
def Fin2.optOfNat {n : } :
Option (Fin2 n)

Converts a natural into a Fin2 if it is in range

Equations
def Fin2.add {n : } (i : Fin2 n) (k : ) :
Fin2 (n + k)

i + k : Fin2 (n + k) when i : Fin2 n and k : ℕ

Equations
def Fin2.left (k : ) {n : } :
Fin2 nFin2 (k + n)

left k is the embedding Fin2 n → Fin2 (k + n)→ Fin2 (k + n)

Equations
def Fin2.insertPerm {n : } :
Fin2 nFin2 nFin2 n

insertPerm a is a permutation of Fin2 n with the following properties:

• insertPerm a i = i+1 if i < a
• insertPerm a a = 0
• insertPerm a i = i if i > a
Equations
def Fin2.remapLeft {m : } {n : } (f : Fin2 mFin2 n) (k : ) :
Fin2 (m + k)Fin2 (n + k)

remapLeft f k : Fin2 (m + k) → Fin2 (n + k)→ Fin2 (n + k) applies the function f : Fin2 m → Fin2 n→ Fin2 n to inputs less than m, and leaves the right part on the right (that is, remapLeft f k (m + i) = n + i).

Equations
class Fin2.IsLT (m : ) (n : ) :
• The unique field of Fin2.IsLT, a proof that m < n.

h : m < n

This is a simple type class inference prover for proof obligations of the form m < n where m n : ℕ.

Instances
instance Fin2.IsLT.zero (n : ) :
Equations
• = { h := (_ : 0 < ) }
instance Fin2.IsLT.succ (m : ) (n : ) [l : ] :
Fin2.IsLT () ()
Equations
• = { h := (_ : ) }
def Fin2.ofNat' {n : } (m : ) [inst : ] :

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