If f
and g
are extensionally equal (equal outputs for all inputs), then unindex f = unindex g
.
Moves between x :: xs
and (x, xs)
.
Given a function that computes an index in the input from the index in the output, produce a Vect o
of elements from the input.
This is the map function of the functor \i => Vect i a
from \i, o => Fin o -> Fin i
to \i, o => Vect i a -> Vect o a
.
Indexing into the table of outputs of f
is like calling f
itself.
Functions with the same tables are the same themselves.
Vect Z a
has only one value: []
.
A Vect (S Z) a
is just an a
.
Given a permutation of the indices, provide an Iso
that can permute a Vect n
the "same" way. More precisely,
if the index i
is sent to j
, then the element at index i
ends up at index j
(indexPermuted
). An
Iso (Fin n) (Fin n)
represents a permutation of the integers [0, n)
because it ensures that no elements
are "lost" or "duplicated".
Note this has the opposite behavior to fromIndices
. This function is more "visceral"; it can be imagined
as shuffling a Vect
in the same way map (to permutation)
shuffles range
. Or, in more categorical terms,
fromIndices
represents a contravariant functor from the category \i, o => Fin i -> Fin o
to \i, o => Vect i a -> Vect o a
,
and permuted
represents that functor restricted to isomorphisms and made covariant with isoSym
.
to (permuted (stimes 2 rotatedDown)) [1, 2, 3, 4, 5] == [3, 4, 5, 1, 2]
to (permuted (swapped 3 0)) [1, 2, 3, 4, 5] == [4, 2, 3, 1, 5]
an Iso
representing the transformation on the indices
An Iso
based on unconcat
and concat
.
from rectangular [[1,2,3],[4,5,6]]
An Iso
based on splitAt
and (++)
.
An Iso
based on transpose
.
Split the Vect
every m
elements, making n
Vect m a
s.
The result is rectangular and has the same order as the original.
This is the inverse of concat
.
Go through all possible inputs and tabulate the outputs in a Vect
.
Or: turn a function from indices to values into a Vect
.
Or: the inverse of index
.
A simpler version of unindexIndex'
which only proves that unindex
is the inverse of index
.
Given a function f
, a Vect
xs
, and a proof that calling f
gives the same result as indexing into xs
,
prove that xs
is the table of outputs of f
.
An Iso
based on zip
and unzip
.
An Iso
based on zip3
and unzip3
.