Vector and List in Mathlib#
Tip
Use the Mathlib documentation website for easy browsing of module contents and definitions.
Data/Vector/
#
📁 Mathlib/Data/Vector/Basic.lean
.
Vector α n
represents a list of elements of typeα
that is known to have lengthn
.
Well suited to plaintexts, keys, and ciphertexts where length is fixed and equal.
🧰 Useful functions
Vector.map (f : α → β) : Vector α n → Vector β n
Vector.map₂ (f : α → β → γ) : Vector α n → Vector β n → Vector γ n
, perfect for XORing two vectors.Vector.get : Vector α n → Fin n → α
to get an element at an index.Vector.ofFn : ((i : Fin n) → α) → Vector α n
to construct a vector from a function.- Literals like
![a, b, c]
can often be coerced toVector α 3
if the type is known.
Data/List/
#
-
In
Mathlib/Data/List/Basic.lean
and other files inMathlib/Data/List/
. -
While
Vector
is likely better for fixed-length crypto primitives,List α
is the standard list type. -
Good to know its API (e.g.,
map
,zipWith
,length
) asVector
often mirrors or builds uponList
concepts.