Lists from functions #
Theorems and lemmas for dealing with List.ofFn
, which converts a function on Fin n
to a list
of length n
.
Main Statements #
The main statements pertain to lists generated using List.ofFn
List.get?_ofFn
, which tells us the nth element of such a listList.equivSigmaTuple
, which is anEquiv
between lists and the functions that generate them viaList.ofFn
.
theorem
List.get?_ofFn
{α : Type u}
{n : ℕ}
(f : Fin n → α)
(i : ℕ)
:
(List.ofFn f).get? i = List.ofFnNthVal f i
The n
th element of a list
theorem
List.ofFn_add
{α : Type u}
{m n : ℕ}
(f : Fin (m + n) → α)
:
List.ofFn f = (List.ofFn fun (i : Fin m) => f (Fin.castAdd n i)) ++ List.ofFn fun (j : Fin n) => f (Fin.natAdd m j)
Note this matches the convention of List.ofFn_succ'
, putting the Fin m
elements first.
@[simp]
theorem
List.ofFn_const
{α : Type u}
(n : ℕ)
(c : α)
:
(List.ofFn fun (x : Fin n) => c) = List.replicate n c
@[simp]
theorem
List.ofFn_fin_repeat
{α : Type u}
{m : ℕ}
(a : Fin m → α)
(n : ℕ)
:
List.ofFn (Fin.repeat n a) = (List.replicate n (List.ofFn a)).flatten
Lists are equivalent to the sigma type of tuples of a given length.
Equations
Instances For
@[simp]
theorem
List.equivSigmaTuple_apply_fst
{α : Type u}
(l : List α)
:
(List.equivSigmaTuple l).fst = l.length
def
List.ofFnRec
{α : Type u}
{C : List α → Sort u_1}
(h : (n : ℕ) → (f : Fin n → α) → C (List.ofFn f))
(l : List α)
:
C l
A recursor for lists that expands a list into a function mapping to its elements.
This can be used with induction l using List.ofFnRec
.
Equations
- List.ofFnRec h l = cast ⋯ (h l.length l.get)
Instances For
Note we can only state this when the two functions are indexed by defeq n
.