Pairwise Order of a Sequence of Elements

April 19, 2026
Vibrant flat lay featuring notebook, eyeglasses, and wooden numbers on colorful background.
Photo by Black ice on Pexels

A simple idea is having a second moment. A short Hacker News thread pointed to a blog post that revisits an old toy: the pairwise order of a sequence. The author starts with a three-way comparator — output 1 if xy, 0 otherwise — and applies it to every adjacent pair in a sequence. Boring on the surface. But then the post leans in and asks: what if this tiny transform is actually the core of many measures of presortedness?

Definition(s) and properties

The write-up rephrases the comparator as the sign of the discrete difference operator — think of it as a "discrete derivative" of the sequence. That reframing cleans up a confusing negation in the original wording and makes several neat properties pop out: the pairwise order has length |X|−1; a sorted sequence produces no −1 values (and vice versa); a strictly reverse-sorted sequence produces no 1 values; distinct elements yield no zeros. There’s even a tidy symmetry for reversed sequences: Order_i(Reversed(X)) = −Order_{|X|−i}(X). Elegant, compact, and satisfying.

Pairwise order and measures of disorder

Here’s the kicker: it has been reported that the pairwise order alone suffices to compute the Amp measure the author introduced years ago. Runs — the count of "steps down" — is nothing more than the count of −1s in the pairwise order. The post goes on to show, allegedly, that other measures such as Mono (how many monotonic blocks a sequence decomposes into) can be expressed or at least reframed in terms of the pairwise order too. In short: a tiny transform, big expressive power.

Why care? Because repackaging chaos into a short, discrete signal can simplify reasoning about adaptive sorts and presortedness measures. Does it make sorting magically faster? Not by itself. But it turns a handful of messy definitions into a single, shareable fingerprint of a sequence — and sometimes that’s half the battle. Who knew a humble three-way comparator could look so decisive?

Sources: morwenn.github.io, Hacker News