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.length_ofFn
, which tells us the length of such a listList.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
.
@[simp]
The length of a list converted from a function is the size of the domain.
@[simp]
theorem
List.get?_ofFn
{α : Type u}
{n : ℕ}
(f : Fin n → α)
(i : ℕ)
:
List.get? (List.ofFn f) i = List.ofFnNthVal f i
The n
th element of a list
@[deprecated List.get_ofFn]
theorem
List.nthLe_ofFn
{α : Type u}
{n : ℕ}
(f : Fin n → α)
(i : Fin n)
:
List.nthLe (List.ofFn f) ↑i ⋯ = f i
@[simp, deprecated List.get_ofFn]
theorem
List.nthLe_ofFn'
{α : Type u}
{n : ℕ}
(f : Fin n → α)
{i : ℕ}
(h : i < List.length (List.ofFn f))
:
List.nthLe (List.ofFn f) i h = f { val := i, isLt := ⋯ }
theorem
List.ofFn_succ'
{α : Type u}
{n : ℕ}
(f : Fin (Nat.succ n) → α)
:
List.ofFn f = List.concat (List.ofFn fun (i : Fin n) => f (Fin.castSucc i)) (f (Fin.last n))
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.
@[deprecated List.ofFn_get]
theorem
List.ofFn_nthLe
{α : Type u}
(l : List α)
:
(List.ofFn fun (i : Fin (List.length l)) => List.nthLe l ↑i ⋯) = l
@[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.join (List.replicate n (List.ofFn a))
@[simp]
theorem
List.equivSigmaTuple_apply_fst
{α : Type u}
(l : List α)
:
(List.equivSigmaTuple l).fst = List.length l
@[simp]
theorem
List.equivSigmaTuple_apply_snd
{α : Type u}
(l : List α)
:
∀ (a : Fin (List.length l)), (List.equivSigmaTuple l).snd a = List.get l a
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 (List.length l) (List.get l))
Instances For
Note we can only state this when the two functions are indexed by defeq n
.