Formal definition of "unnesting" a nested list.

35 Views Asked by At

This is very much related to my previous question on the iterated Kleene closure, here: The iterated Kleene closure of an alphabet. Someone in the comments called elements of my construction "nested lists". My current question is about the formal definition of "unnesting" a nested list. Let me give some examples so as to clarify what I intuitively mean. Let our alphabet be $\{a,b\}$. The unnesting of the nested list $(a,b,a,b,b)$ is itself, because it is just a regular list. The unnesting of $(a,(b,a))$ is $(a,b,a)$. The unnesting of $((()))$ is $()$, the empty list. The unnesting of $((),a,())$ is $(a)$. The unnesting of $(a,(b,(a,(b))))$ is $(a,b,a,b)$. The unnesting of $((),a,(),b)$ is $(a,b)$. I could give some more examples, but I hope these examples are sufficient to get the general idea of what I mean. So, what is the corresponding formal and rigorous definition of this notion?

1

There are 1 best solutions below

0
On BEST ANSWER

The "unnest" operation only makes sense if we have a way to distinguish lists from non-lists, via types or some other criterion, so that you know when to "stop flattening". We can define it recursively as:

$$ u(x)= \begin{cases} \text{the concatenation of the list of lists $(u(y))_{y\in x}$} &\text{if $x$ is a list}\\ \text{the singleton list $(x)$} &\text{otherwise.} \end{cases} $$