The Mathlib Handbook

The volumes of the handbook are not written yet. This site shows the map of Mathlib that they will follow, at Mathlib 4472534b60.

The areas / V02. Numbers

Mathlib.Data.Fin.Fin2

47 declarations. Mathlib docs · Source

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) by applying f : Fin m → Fin n to 0, ..., m - 1 and sending m + i to n + i.

theorem Fin2.fs.inj E1 #

∀ {n : ℕ} {a a_1 : Fin2 n}, a.fs = a_1.fs → a = a_1

theorem Fin2.fs.injEq E0 #

∀ {n : ℕ} (a a_1 : Fin2 n), (a.fs = a_1.fs) = (a = a_1)

theorem Fin2.add.match_1.congr_eq_1 E1 #

∀ (motive : ℕ → Sort u_1) (x : ℕ) (h_1 : Unit → motive 0) (h_2 : (k : ℕ) → motive k.succ),
  x = 0 →
    (match x with
      | 0 => h_1 ()
      | k.succ => h_2 k) ≍
      h_1 ()

theorem Fin2.add.match_1.congr_eq_2 E1 #

∀ (motive : ℕ → Sort u_1) (x : ℕ) (h_1 : Unit → motive 0) (h_2 : (k : ℕ) → motive k.succ) (k : ℕ),
  x = k.succ →
    (match x with
      | 0 => h_1 ()
      | k.succ => h_2 k) ≍
      h_2 k

abbrev Fin2.brecOn.go E1 #

{motive : (a : ℕ) → Fin2 a → Sort u} →
  {a : ℕ} → (t : Fin2 a) → ((a : ℕ) → (t : Fin2 a) → Fin2.below t → motive a t) → motive a t ×' Fin2.below t

theorem Fin2.toNat.match_1.congr_eq_1 E1 #

∀ (motive : (x : ℕ) → Fin2 x → Sort u_1) (x : ℕ) (x_1 : Fin2 x) (h_1 : (n : ℕ) → motive (n + 1) Fin2.fz)
  (h_2 : (n : ℕ) → (i : Fin2 n) → motive (n + 1) i.fs) (n : ℕ),
  x = n + 1 →
    x_1 ≍ Fin2.fz →
      (match x, x_1 with
        | .(n + 1), Fin2.fz => h_1 n
        | .(n + 1), i.fs => h_2 n i) ≍
        h_1 n

def Fin2.ctorIdx E1 #

{a : ℕ} → Fin2 a → ℕ

theorem Fin2.toNat.match_1.congr_eq_2 E1 #

∀ (motive : (x : ℕ) → Fin2 x → Sort u_1) (x : ℕ) (x_1 : Fin2 x) (h_1 : (n : ℕ) → motive (n + 1) Fin2.fz)
  (h_2 : (n : ℕ) → (i : Fin2 n) → motive (n + 1) i.fs) (n : ℕ) (i : Fin2 n),
  x = n + 1 →
    x_1 ≍ i.fs →
      (match x, x_1 with
        | .(n + 1), Fin2.fz => h_1 n
        | .(n + 1), i.fs => h_2 n i) ≍
        h_2 n i

abbrev Fin2.ctorElimType E1 #

{motive : (a : ℕ) → Fin2 a → Sort u} → ℕ → Sort (max 1 u)

theorem Fin2.brecOn.eq E1 #

∀ {motive : (a : ℕ) → Fin2 a → Sort u} {a : ℕ} (t : Fin2 a) (F_1 : (a : ℕ) → (t : Fin2 a) → Fin2.below t → motive a t),
  Fin2.brecOn t F_1 = F_1 a t (Fin2.brecOn.go t F_1).2

inductive Fin2 E1 #

ℕ → Type

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

ctor Fin2.fz E3 #

{n : ℕ} → Fin2 (n + 1)

0 as a member of Fin (n + 1) (Fin 0 is empty)

ctor Fin2.fs E0 #

{n : ℕ} → Fin2 n → Fin2 (n + 1)

n as a member of Fin (n + 1)

def Fin2.cases' E1 #

{n : ℕ} → {C : Fin2 n.succ → Sort u} → C Fin2.fz → ((n_1 : Fin2 n) → C n_1.fs) → (i : Fin2 n.succ) → 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).

def Fin2.elim0 E1 #

{C : Fin2 0 → Sort u} → (i : Fin2 0) → C i

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

def Fin2.toNat E3 #

{n : ℕ} → Fin2 n → ℕ

Converts a Fin2 into a natural.

def Fin2.optOfNat E3 #

{n : ℕ} → ℕ → Option (Fin2 n)

Converts a natural into a Fin2 if it is in range

def Fin2.add E1 #

{n : ℕ} → Fin2 n → (k : ℕ) → Fin2 (n + k)

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

def Fin2.left E3 #

(k : ℕ) → {n : ℕ} → Fin2 n → Fin2 (k + n)

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

def Fin2.insertPerm E1 #

{n : ℕ} → Fin2 n → Fin2 n → Fin2 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

def Fin2.remapLeft E1 #

{m n : ℕ} → (Fin2 m → Fin2 n) → (k : ℕ) → Fin2 (m + k) → Fin2 (n + k)

remapLeft 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, remapLeft f k (m + i) = n + i).

class Fin2.IsLT E3 #

ℕ → ℕ → Prop

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

ctor Fin2.IsLT.mk E0 #

∀ {m n : ℕ}, m < n → Fin2.IsLT m n

theorem Fin2.IsLT.h E1 #

∀ {m n : ℕ} [self : Fin2.IsLT m n], m < n

The unique field of Fin2.IsLT, a proof that m < n.

instance Fin2.IsLT.zero E0 #

∀ (n : ℕ), Fin2.IsLT 0 n.succ

instance Fin2.IsLT.succ E0 #

∀ (m n : ℕ) [l : Fin2.IsLT m n], Fin2.IsLT m.succ n.succ

def Fin2.ofNat' E3 #

{n : ℕ} → (m : ℕ) → [Fin2.IsLT m n] → Fin2 n

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.

def Fin2.castSucc E1 #

{n : ℕ} → Fin2 n → Fin2 (n + 1)

castSucc i embeds i : Fin2 n in Fin2 (n+1).

def Fin2.last E1 #

{n : ℕ} → Fin2 (n + 1)

The greatest value of Fin2 (n+1).

def Fin2.rev E1 #

{n : ℕ} → Fin2 n → Fin2 n

Maps 0 to n-1, 1 to n-2, ..., n-1 to 0.

theorem Fin2.rev_last E0 #

∀ {n : ℕ}, Fin2.last.rev = Fin2.fz

theorem Fin2.rev_castSucc E0 #

∀ {n : ℕ} (i : Fin2 n), i.castSucc.rev = i.rev.fs

theorem Fin2.rev_rev E0 #

∀ {n : ℕ} (i : Fin2 n), i.rev.rev = i

theorem Fin2.rev_involutive E1 #

∀ {n : ℕ}, Function.Involutive Fin2.rev

instance Fin2.instInhabitedOfNatNat E0 #

Inhabited (Fin2 1)

instance Fin2.instFintype E0 #

(n : ℕ) → Fintype (Fin2 n)

def Fin2.toFin E1 #

{n : ℕ} → Fin2 n → Fin n

Converts a Fin2 into a Fin.

theorem Fin2.toFin_fz E0 #

∀ (n : ℕ), Fin2.fz.toFin = 0

theorem Fin2.toFin_fs E0 #

∀ {n : ℕ} (i : Fin2 n), i.fs.toFin = i.toFin.succ

def Fin2.ofFin E1 #

{n : ℕ} → Fin n → Fin2 n

Converts a Fin into a Fin2.

theorem Fin2.ofFin_zero E0 #

∀ (n : ℕ), Fin2.ofFin 0 = Fin2.fz

theorem Fin2.ofFin_succ E0 #

∀ {n : ℕ} (i : Fin n), Fin2.ofFin i.succ = (Fin2.ofFin i).fs

theorem Fin2.toFin_ofFin E0 #

∀ {n : ℕ} (i : Fin n), (Fin2.ofFin i).toFin = i

theorem Fin2.ofFin_toFin E0 #

∀ {n : ℕ} (i : Fin2 n), Fin2.ofFin i.toFin = i

def Fin2.equivFin E1 #

(n : ℕ) → Fin2 n ≃ Fin n

Fin2 is equivalent to the usual encoding of Fin as a subtype of ℕ.

theorem Fin2.equivFin_apply E0 #

∀ (n : ℕ) (i : Fin2 n), (Fin2.equivFin n) i = i.toFin

theorem Fin2.equivFin_symm_apply E0 #

∀ (n : ℕ) (i : Fin n), (Fin2.equivFin n).symm i = Fin2.ofFin i