Lists as Functions #
THIS FILE IS SYNCHRONIZED WITH MATHLIB4. Any changes to this file require a corresponding PR to mathlib4.
Definitions for using lists as finite representations of finitely-supported functions with domain ℕ.
These include pointwise operations on lists, as well as get and set operations.
Notations #
An index notation is introduced in this file for setting a particular element of a list. With as
as a list m
as an index, and a
as a new element, the notation is as {m ↦ a}
.
So, for example
[1, 3, 5] {1 ↦ 9}
would result in [1, 9, 5]
This notation is in the locale list.func
.
Elementwise negation of a list
Equations
- list.func.neg as = list.map (λ (a : α), -a) as
Update element of a list by index. If the index is out of range, extend the list with default elements
Equations
- list.func.set a (h :: as) (k + 1) = h :: list.func.set a as k
- list.func.set a (_x :: as) 0 = a :: as
- list.func.set a list.nil (k + 1) = inhabited.default :: list.func.set a list.nil k
- list.func.set a list.nil 0 = [a]
Get element of a list by index. If the index is out of range, return the default element
Equations
- list.func.get (n + 1) (a :: as) = list.func.get n as
- list.func.get n.succ list.nil = inhabited.default
- list.func.get 0 (a :: as) = a
- list.func.get 0 list.nil = inhabited.default
Pointwise equality of lists. If lists are different lengths, compare with the default element.
Equations
- list.func.equiv as1 as2 = ∀ (m : ℕ), list.func.get m as1 = list.func.get m as2
Pointwise operations on lists. If lists are different lengths, use the default element.
Equations
- list.func.pointwise f (a :: as) (b :: bs) = f a b :: list.func.pointwise f as bs
- list.func.pointwise f (a :: as) list.nil = list.map (λ (x : α), f x inhabited.default) (a :: as)
- list.func.pointwise f list.nil (b :: bs) = list.map (f inhabited.default) (b :: bs)
- list.func.pointwise f list.nil list.nil = list.nil
Pointwise addition on lists. If lists are different lengths, use zero.
Equations
Pointwise subtraction on lists. If lists are different lengths, use zero.