2014-08-28

Zip lists

I've laid off the maths for a while in preparation for this post. You may remember that the last post ended in a rather unsatisfactory manner. Here, I try to rectify the situation. The heart of the issue is that I want to be able to express two different types of equality between functions: the weaker set-wise complete closure and the stronger point-wise extensional equivalence.

I define a function $f$ as being completely closed over a set $S$ iff it satisfies these conditions (in non-mapping notation):\begin{aligned} \forall x\in S.\,& f\ x\in S \\ \forall y\in S.\,\exists x\in S.\,& f\ x=y \end{aligned}In other words, the domain and image of $f$ are equal. If $S$ is a finite set, $f$ essentially reorders the elements. If $S$ is infinite, there may be other things that $f$ could do. For example, if $f=\text{succ}\wedge S=\mathbb Z$, $f$ is a kind of translation function. In any case, $f$ is surjective. My aim is to be able to write this in a concise and generalisable way in mathematical notation.

If two functions are extensionally equivalent, they do the same job, and thus one can replace the other without changing the logic of the situation. However, they may have different computational properties, and hence can't be considered to be totally equal. The conditions for this relation between $f$ and $g$ with respect to set $S$ can be written:$\forall x\in S.\,f\ x=g\ x$This, too, I want to have a concise and generalisable way of writing, since it is a very common relation.

So, why are these related? Well, let's start naïvely applying the principles of the notation without variables. For extensional equivalence, it is intuitive to write $f=g$. Now, we want to limit that to some set? Maybe we say $(f=g)\ S$. That expands to $f\ S=g\ S$ by the fork rule (since equality doesn't act upon functions). But, by implicit mapping, $f\ S$ and $g\ S$ are sets, so correspondences between individual elements are lost. All we've equated are the images for the functions, given a domain. If $g$ is the identity function, the statement is that $f$ is completely closed over $S$.

As the title suggests, the solution lies in using lists, rather than sets. These retain an order, so there is still correspondence between individual elements in the domain and image. In fact, a function can be specified as a pair of lists, as well as a set of pairs. To say that $f$ and $g$ are extensionally equivalent over domain $S$, we just have to make sure that $S$ is cast to be a list. In symbols, $(f=g)\ \text{list}\ S$.

Both $(f=g)\ \text{list}\ S$ and $(f=g)\ S$ are useful. $D\ {}_\cdot^2=2\cdot{}$ is an example of the former, where the implicit argument for the expression is $\text{list}\ \mathbb C$. $(\Pi=(!))\ \text{list}\ \mathbb N$ is an example of where the list argument cannot be reliably inferred, and has a significant effect on the truth of the statement. Finally, $(\text{floor}\ \frac 2 \iota=\iota)\ \mathbb N$, where $\iota$ is the identity function (an example of a non-bijective completely closed function).

List can occur in other situations, too. For example, $\pm$ can be formalised by saying that it returns a 2-element list (as too does $\sqrt \iota$, but not ${}_\cdot^{2/1}$; see an earlier post). Explicitly, $x\pm y=[x+y,x-y]$. This gives $\cos(A\pm B)=\cos A\cdot\sin B\mp\sin A\cdot\cos B$, which boils down to an equivalence between two lists. In fact, lists are so useful that it may be worth assuming that the standard sets are lists, which can be converted to sets as needed. This makes more sense, too, because the $\text{list}$ function essentially introduces new information, whereas functions should lose information (like $\text{set}$ does on lists). Also, in general, expressions like $\text{head}\ \text{list}\ S$ are meaningless. However, given the axiom of choice, $\text{list}$ can be defined for any set, it's just that some operations on it are meaningless.