A computed stable adjacent-exchange trace #
AdjacentSortTrace.compute instruments the existing List.orderedInsert: sort the tail,
shift its requests, then move the original head past strictly smaller keys. Equal keys are
never crossed. Requests act on arbitrary accompanying payloads, not changing variable names.
The first substantive property is replay_compute: the actual computed requests replay the
existing stable insertion sort on any payload/key map. components_compute supplies valid
indices and a triangular bound; indices_payload identifies the actual original-index
permutation. This is original trace instrumentation, reusing the library's sorting proofs.
The actual accumulator and output: sorted original binary keys, followed by the adjacent positions to execute in order. Repeated keys remain repeated occurrences.
Original keys in stable nondecreasing order.
Binary positions of adjacent exchanges, in execution order.
Insert one original head key. The existing tail trace is shifted below it; the new requests cross exactly the strictly smaller prefix, and hence never cross equal keys.
Compute a stable trace by a literal fold over the original keys from right to left. All traversal clocks come from lists; binary key magnitudes are only compared.
Exact sorted original keys, at most choose P 2 requests, and every emitted request
valid for the original length P. These facts hold for every raw binary key list.
The literal requests replay stable insertion sort on any accompanying payload. Only its original key map is inspected; payloads, including equal-key occurrences, are retained.
The computed index word is a permutation of all original indices. Applying the SAME
requests to any indexed payload gives that word mapped by the payload, not a chosen sorting
permutation. Equal-key original-index pairs remain sublists, by the existing
List.pair_sublist_insertionSort stability theorem.
Already sorted keys produce no requests at all; execution therefore preserves the ENTIRE raw payload State, rather than just canceling its value permutation.