Mapping over Subsets of Elements
The new function SubsetMap allows extracting a subset of elements from an expression, manipulating them and finally reinserting them again in the same positions of the expression. In this example, SubsetMap is used to build sorting networks.
As a simple example, take a list of integers and accumulate the elements at even positions.
Now reverse the elements at even positions in the list.
As a more interesting application, implement a sorting network that randomly sorts pairs of elements until all elements are sorted.
For longer lists, finding the last elements to reorder may take many steps.
Therefore a logarithmic representation is more appropriate.