note
blokhead
I would call this a special case of a <i>ranking algorithm for combinations</i>. An "unordered pair" as you have is simply a "subset of size 2" (or "combination of size 2"). A ranking algorithm is a 1-to-1 mapping from a set of N combinatorial objects to the integers {1...N}, with the additional property that it preserves some sort of "ordering" among the combinatorial objects.
<p>
In this case, your ranking algorithm preserves a form of lexicographic ordering. When you write the pairs as (M,N) with M>N, then you have that rank(M,N)<rank(R,S) if and only if (M,N) appears before (R,S) in lexicographic order. You may not actually use this property, but you got it for free. ;)
<p>
Look at the ranking algorithm I gave in [id://475645] (for general combinations):
<c>
sub rank {
my @comb = sort { $a <=> $b } @_;
sum map { binomial( $comb[$_]-1, $_+1 ) } 0 .. $#comb;
}
</c>
For combinations of size 2, ours both compute the same thing:
<c>
binomial(X,2)+binomial(Y,1) = X(X-1)/2 + Y
</c>
I got the algorithm from a PDF draft version of a textbook that may never get published (which would be a shame). That PDF is not available online anymore, but if you are curious, I can send you the copy I have archived (hopefully that's kosher). I would be surprised if these kinds of things don't also show up somewhere in Knuth TAoCP volume 4 (if it's out yet, that is), where it deals with the related topics of combinatorial generation.
<!-- Node text goes above. Div tags should contain sig only -->
<div class="pmsig"><div class="pmsig-137386">
<p>
blokhead
</div></div>
607755
607755