Inversion (discrete mathematics)

From testwiki
Jump to navigation Jump to search
A permutation, its inversion set and its left inversion count

Inversion is a concept in discrete mathematics to measure how much a sequence is out of its natural order.

(An inversion of a permutation is not to be confused with the inverse of a permutation. Also not with point reflection.)



Definitions

Map from the place-based to the element-based inversions of a permutation of four elements
The element-based inversion multiset of this sequence contains (2,1) twice.

A permutation π has an inversion for each pair of elements that are out of their natural order, i.e. when i<j but π(i)>π(j).
It may be identified by the pair of places (i,j) or by the pair of elements (π(i),π(j)).
This article favours the former convention (although the latter seems to be more common).


The inversion set of a permutation is the set of all its inversions.
For an n-element permutation the number of potential elements is the triangular number (n2).

The element-based inversion set is essentially the place-based inversion set of the inverse permutation, just with the elements of the pairs exchanged.

For sequences the element-based inversion set has to be defined as a multiset, as many pairs of places can have the same pair of elements.


The permutation graph has the elements of the permutation as vertices and an edge between elements that are out of order,
i.e. an edge is an inversion according to the element-based definition: {π(i),π(j)} is an edge iff i<jπ(i)>π(j).
It is more common to write that {i,j} is an edge iff i<jπ1(i)>π1(j). The latter is often written as (ij)(π1(i)π1(j))<0.

The permutation graphs of inverse permutations are isomorphic. That of π1 can be generated from that of π by changing each vertex i to π(i).

It seems that the permutation graph is only defined with place-based inversions. If it were generalized to apply to sequences, it would thus have to be defined as a multigraph.


The inversion number (Template:Oeis) is the cardinality of the inversion set;
thus also the digit sum of the inversion related vectors;
and also the number of crossings in the arrow diagram of the permutation.


The parity of a permutation is the parity of its inversion number.
The sign of a permutation (the determinant of its matrix) corresponds to the parity: Even permutations have sign 1, odd permutations sign −1.


There are four ways to condense the inversions of a permutation into a vector that uniquely determines it. Three of them are in use. (See sources below).

This article uses the terms left inversion count (Template:Invvect) and right inversion count (Template:Invvect) like Gnedin (similar to Calude and Deutsch), and the term inversion vector (Template:Invvect) like Wolfram.

The left and right inversion counts have the feature that interpreted as factorial numbers they determine the permutation's reverse colexicographic and lexicographic index.
The inversion vector does not appear to have a similar advantage, but it is widely used anyway.


Left inversion count Template:Invvect:
With the place-based definition l(i) is the number of inversions whose bigger (right) component is i.

l(i) is the number of elements in π greater than π(i) before π(i).
l(i)=#{kk<iπ(k)>π(i)}


Right inversion count Template:Invvect, often called Template:W:
With the place-based definition r(i) is the number of inversions whose smaller (left) component is i.

r(i) is the number of elements in π smaller than π(i) after π(i).
r(i)=#{kk>iπ(k)<π(i)}


Inversion vector Template:Invvect:
With the element-based definition v(i) is the number of inversions whose smaller (right) component is i.

v(i) is the number of elements in π greater than i before i.
v(i)=#{kk>iπ1(k)<π1(i)}

A different way to say the same thing may be more intuitive:

v(π(i)) is the number of elements in π greater than π(i) before π(i).
v(π(i))=#{kk<iπ(k)>π(i)}=l(i)

The latter definition would also work for a sequence, which does not have an inverse.


Relationship between Template:Invvect and Template:Invvect:

v=l.π=l(π1)
v(i)=l(π1(i)) (vector x permuted by α is x.α=x(α1), compare Permutation notation)
l=v.π1=v(π)
l(i)=v(π(i))

The first digit of Template:Invvect and the last digit of Template:Invvect are always 0, and can be omitted.
When these vectors are permuted into each other, the omissible 0 from one does not necessarily become the omissible 0 in the other.


Relationship between Template:Invvect and Template:Invvect:
Both Template:Invvect and Template:Invvect can be found with the help of a Rothe diagram,
which is a permutation matrix with the 1s represented by dots, and an inversion in every position that has a dot to the right and below it.
r(i) is the sum of inversions in row i of the Rothe diagram, while v(i) is the sum of inversions in column i.
The permutation matrix of the inverse is the transpose. Therefore Template:Invvect of a permutation is Template:Invvect of its inverse, and vice versa.


Relationship between Template:Invvect and Template:Invvect:

π(i)=i+r(i)l(i)

This is proven in Gnedin & Olshanski 2012, and mentioned as R[i]+i=p[i]+L[i] in Template:Oeis.


Permutations that are equal up to fixed points can be seen as equal. Equivalently, inversion related vectors that are equal up to trailing 0s can be seen as equal.
While for Template:Invvect and Template:Invvect the omissible 0 on the right is part of the trailing 0s, for Template:Invvect the omissible 0 on the left is separate from them.

Example: Permutations of six elements

The following images show two inverse permutations, their 9 inversions and the corresponding vectors.

v=l.π=l(π1)
v(3)=l(π1(3))=l(5)=3
l=v.π1=v(π)
l(3)=v(π(3))=v(4)=1
π=674=(125346)=(123456254631)

Permutation matrix
Rothe diagram
Place-based inversion set

Template:Invvect = (0, 0, 1, 0, 3, 5)
rev colex rank: 530100! = 674
Template:Invvect = (1, 3, 2, 2, 1, 0)
lex rank: 132210! = 209

Element-based inversion set

Permutation graph
v=l.π=l(π1)
v(3)=l(π1(3))=l(4)=2
l=v.π1=v(π)
l(3)=v(π(3))=v(5)=1
π=327=(164352)=(123456615324)

Permutation matrix
Rothe diagram
File:Inversion example; invset p-b 2.svg
Place-based inversion set

Template:Invvect = (0, 1, 1, 2, 3, 2)
rev colex rank: 232110! = 327
Template:Invvect = (5, 0, 3, 1, 0, 0)
lex rank: 503100! = 620

Error creating thumbnail:
Element-based inversion set

Permutation graph



Mathematica omits the 0 at the end of the inversion vector. Compare p1 and p2 in Wolfram Alpha.

I: p1 = {2,5,4,6,3,1}
I: p2 = {6,1,5,3,2,4}

I: ToInversionVector[p1]
O: {5,0,3,1,0}
I: ToInversionVector[p2]
O: {1,3,2,2,1}

I: ToOrderedPairs[PermutationGraph[p1]]
O: {{2,1},{3,1},{4,1},{5,1},{6,1},{4,3},{5,3},{6,3},{5,4},{1,2},{1,3},{1,4},{1,5},{1,6},{3,4},{3,5},{3,6},{4,5}}
I: ToOrderedPairs[PermutationGraph[p2]]
O: {{6,1},{3,2},{5,2},{6,2},{5,3},{6,3},{5,4},{6,4},{6,5},{1,6},{2,3},{2,5},{2,6},{3,5},{3,6},{4,5},{4,6},{5,6}}

Example: All permutations of four elements

The six possible inversions of a 4-element permutation

The following sortable table shows the 24 permutations of four elements with their place-based inversion sets, inversion related vectors and inversion numbers.

It is shown twice, so different orders can be compared to each other. (The Python script used to create it is shown here.)

The columns with small text are the reflections of the main columns. Sorting by them gives the colexicographic order of the corresponding main column.


Inversion vector Template:Invvect and left inversion count Template:Invvect are shown next to each other, because they have the same digits.

Left and right inversion counts are related to the place-based inversion sets shown between them:
The nontrivial elements of Template:Invvect are the sums of the descending diagonals of the triangle, and those of Template:Invvect are the sums of the of the ascending diagonals.


The default order of the table is the reverse colex order by π, which is the same as the colex order by Template:Invvect. (This header cell is highlighted by a darker gray.)

Lex order by π is the same as lex order by Template:Invvect.


Ordering one table by Template:Invvect and the other one by Template:Invvect brings inverse permutations next to each other, i.e. those whose matrices are reflected at the main diagonal.

Ordering one table by reflected Template:Invvect and the other one by Template:Invvect brings permutations next to each other whose permutation matrices are reflected at the antidiagonal.

Ordering one table by reflected Template:Invvect and the other one by Template:Invvect brings permutations next to each other whose permutation matrices are rotated by 180°.
(It can be seen, that these permutations' inversion sets are symmetric to each other, which corresponds to Template:Invvect and Template:Invvect being symmetric to each other.)


Note that the set of all Template:Invvect, the set of all Template:Invvect and the set of all reflected Template:Invvect for the same symmetric group are equal.
So sorting by two columns that have the omissible 0 at the same end makes these columns equal.

Template:4-el perm inversions Template:4-el perm inversions

(A more detailled version of this table, including element-based inversion sets and the unused fourth vector, can be found here.)

Weak order of permutations

The Hasse diagram below in the middle shows the 24 inversion sets ordered by the subset relation.

If a permutation is assigned to each inversion set using the place-based definition, the resulting order of permutations is that of the permutohedron,
where (π,σ) is an edge iff i<jπ(i)+1=π(j)(ij)π=σ, i.e. when only two elements with consecutive values are swapped.
(In the central diagram it can be seen on which positions the swapped elements are, by looking which digit changes for the edge.)

The bitwise ordering of the left and right inversion counts of these permutations gives the same order (because both are diagonal sums of the inversion set triangles).

Permutations and left inversion counts Template:Invvect
Inversion sets (place-based)
Permutations and right inversion counts Template:Invvect


If a permutation were assigned to each inversion set using the element-based definition, the resulting order of permutations would be that of a Cayley graph,
where (π,σ) is an edge iff i+1=jπ(i)<π(j)(ij)π=σ, i.e. when only two elements on consecutive places are swapped.

This Cayley graph of the symmetric group is similar to its permutohedron, but with each permutation replaced by its inverse.

For sequences inversion sets and the related vectors are not unique. Their place-based inversion sets are multisets, and their inversion vectors can have bigger digits than would be allowed in a factorial number.

Template:4-el sequence inversions; permutations of 0011

Error creating thumbnail:

Similar permutations have similar inversion sets and corresponding vectors.

Some can be ordered in arrays, like the one on the right, corresponding to the number triangle Template:Oeis.

Template:Multiple image

Template:Multiple image

Template:Multiple image

Sources

Template:Multiple image

Books

Cramer 1750

Cramer defines the inversion under the name dérangement to calculate the sign of a permutation.

For the permutation 3 1 2 the dérangements are given as 3 before 1 and 3 before 2.

Cramer, Gabriel: Introduction à l'analyse des lignes courbes algébriques. Genève : chez les Frères Cramer & Cl. Philibert 1750 — Appendice (p. 658)

Template:Cite book — 9.1 Cramers rule (p. 286)

Rothe 1800

Rothe essentially defines the right inversion count Template:Invvect under the name Stellenexponenten — but with each place bigger by 1.

si is the position of πi among the πk with ki in numerical order. (p. 163)

Strangely he counts from 1 rather than 0, which later leads to avoidable additions and subtractions by 1:

si+1=#{πkk>iπk<πi} (p. 165)
Each permutation has sign + when the sum of the si1 is even, and sign when it is odd. (p. 266)

For the permutation 64398101725 the Stellenexponenten are given as 6436551311.

Muir translates Stellenexponent as place-index and calls it “an ill-advised and purposeless modification of Cramers idea of a ‘derangement’”. (The Theory of the Determinant..., p. 55)

"Ueber Permutationen, in Beziehung auf die Stellen ihrer Elemente. Anwendung der daraus abgeleiteten Satze auf das Eliminationsproblem". In Hindenburg, Carl, ed., Sammlung Combinatorisch-Analytischer Abhandlungen, pp. 263–305, Bey G. Fleischer dem jüngern, 1800.

Laisant 1888

After defining the factorial number system Laisant defines the right inversion count Template:Invvect under the name signe figuratif.

For the permutation 436512 the signe figuratif is given as (32320).

Template:Citation


Aigner 2007

Template:Textbox

Now we look at permutations of {1,2,...,n} in word form σ=a1,a2...an,ai=σ(i).
The pair {i,j} is called an inversion if i<j but ai>aj.

A moment's thought shows that {i,j} is an inversion if and only if the edges iai and jaj cross in the diagram.
Hence the inversion number inv(σ) equals the number of crossings.

Template:Cite bookWord Representation (p. 27 ff)


Comtet 1974

Template:Textbox

An inversion of a permutation σ𝔖[n] is a pair (i,j) such that 1i<jn and σ(i)>σ(j). In this case we say that σ has an inversion in (i,j).

He uses the same definition for a non-bijective map in exercise 21 on permutations (p. 266).

Template:Cite book — 6.4 Inversions of a permutation of [n] (p. 237)


Cormen et al. 2001

Template:Textbox

Let A[1..n] be an array of n distinct numbers. If i<j and A[i]>A[j], then the pair (i,j) is called an inversion of A.

Template:Cite book — 2-4 Inversions (p. 41) and 5.2-5 (p. 122)


Knuth 1973

Template:Textbox

If i<j and ai>aj, the pair (ai,aj) is called an inversion of the permutation; for example the permutation 3 1 4 2 has three inversions: (3, 1), (3, 2) and (4, 2).

The inversion table b1b2...bn of the permutation a1a2...an is obtained by letting bj be the number of elements to the left of j that are greater than j.
In other words, bj is the number of inversions whose second component is j.

Template:Cite book — 5.1.1 Inversions (p. 11)


Pemmaraju & Skiena 2003

Template:Textbox

A pair of elements (π(i),π(j)) in a permutation π represents an inversion if i>j and π(i)<π(j).
An inversion is a pair of elements that are out of order Template:Ellipsis

For any n-permutation π, we can define an inversion vector v as follows. For each integer i, 1in1, the ith element of v is the number of elements in π greater than i to the left of i.

Template:Cite book — 2.2 Inversions and Inversion Vectors (p. 69)


Vitter & Flajolet 1990

Template:Textbox

An inversion in permutation σ is an “out of order” pair (σk,σj) of elements, in which k<j but σk>σj.
The number of inversions is thus a measure of the amount of disorder in a permutation.

The inversion table of the permutation σ=σ1σ2σn is the ordered sequence

b1,b2,,bn, where bk=|{1j<σk1|σj>k}|.

Template:Cite book — 3.1 Inversions (p. 459)


Grätzer 2016

Template:Textbox The authors define the usual strict linear ordering 1<2<<i<i+1<<n on [n] as n={(i,j)[n]×[n]|i<j}.

Let σ be a permutation on [n]. An inversion of σ is an ordered pair (i,j)n satisfying σ1(i)>σ1(j).
The inversion set of σ is then defined as inv(σ)={(i,j)n|σ1(i)>σ1(j)}.

The inversion set of (1234535412) is given as {(1,3),(1,4),(1,5),(2,3),(2,4),(2,5),(4,5)}.

In the footnote it is mentioned that other authors often use the definition as an ordered pair (i,j)n such that σ(i)>σ(j).
TAoCP is given as an example — despite the fact that Knuth uses essentially the same definition (see above).

Template:Cite book — 7-2 Basic objects (p. 221)


Joshi 1989

Template:Textbox

Let x=x1x2xn be a sequence of real numbers.
By an inversion in x, we mean a pair (xi,xj) such that i<j but xi>xj.
For each i, let di = the number of inversions whose first entry is xi, i.e.

di=|{xj:i<j,xi>xj}|.

Then the sequence (d1d2dn) is called the inversion table or inversion vector of x. Template:Ellipsis
The permutation 24351 has (1,2,1,1,0) as its inversion table.

Template:Cite book — Definition 3.12 (p. 188)


Bóna 2012

Template:Textbox Bóna first uses the definition with elements:

Let p=p1p2pn be a permutation. We say that (pi,pj) is an inversion of p if i<j but pi>pj.
Permutation 31524 has four inversions, namely (3, 1), (3, 2), (5, 2), and (5,4).

2.1 Inversions (p. 43)

Template:Textbox But for multisets he uses places instead:

An inversion of a permutation p=p1p2pn of a multiset is defined just as it was for permutations of sets, that is, (i,j) is a inversion if i<j, but pi>pj·
The multiset-permutation 1322 has two inversions, (2, 3), and (2, 4).

2.2 Inversions in Permutations of Multisets (p. 57)

The definition of non-inversions also uses places:

Template:Ellipsis look at all non-inversions of a generic permutation p=p1p2pn; that is, pairs so that i<j and pi<pj.

4.4.1.1 An exponential upper bound (p. 141)

Template:Cite book


Calude et al. 2003

Template:Textbox

For permutations, an inversion vector is used as an auxiliary array because it fills in the holes made by the elements of the prefix in its defining sequence.
For the permutation (p[i],,p[n]) the right-inversion vector (g[i],,g[n1]) is defined by the rule that g[i] is the number of p[j] to the right of but smaller than p[i];
in the left-inversion vector, g[i] is the number of p[j] to the left of but larger than p[i].

Template:Cite bookGenerating Gray codes... (p. 81)


Lothaire 2002

Template:Textbox

If σ=σ(1)σ(2)σ(k) is [a permutation of [k]] an inversion of σ is a pair (i,j) such that 1i<jk and σ(i)>σ(j).

11.1. Prelimiaries (p. 367)

Let σ be a permutation of [n]. For 1in, let li be the number of indices j<i such that σ(j)>σ(i). The word l=l1l2ln will be called the Lehmer encoding of σ.

To the permutation σ=684593127 corresponds the Lehmer encoding l=002205662.

11.4. Inversions of permutations with a given shape (p. 372)

Template:Cite book

Papers

Vajnovszki 2011

Template:Textbox

The pair (i,j) is an inversion of π𝔖n if i<j but πi>πj. Template:Ellipsis

An integer sequence t1t2tn is said to be subexcedent if 0tii1 for 1in, and the set of lenth-n subexcedent sequences is denoted by Sn Template:Ellipsis.
The Lehmer code [5] is a bijection code : 𝔖nSn which maps each permutation π=π1π2πn to a subexcedent sequence t1t2tn
where, for all i,1in, ti is the number of inversions (j,i) in π (or equivalently, the number of entries in π larger than πi and on its left).
[5]      D. H. Lehmer, Teaching combinatorial tricks to a computer, in Proc. Sympos. Appl. Math., 10 (1960), Amer. Math. Soc., 179-193.

Vajnovszki. A new Euler–Mahonian constructive bijection — pp. 1-2


Gnedin & Olshanski 2012

Template:Textbox

For σ𝔖, a pair of positions (i,j)× is an inversion in σ if i<j and σ(i)>σ(j).
If (i,j) is an inversion, we say that it is a left inversion for j, and a right inversion for i.
Introduce the counts of left and right inversions,

𝓁i:=#{j:j<i,σ(j)>σ(i)},𝓇i:=#{j:j>i,σ(j)<σ(i)},i,

respectively (of course, for the general σ𝔖 these quantities may be infinite).

4. A construction from independent geometric variables (p. 624)

The authors proof the following formula for balanced permutations, which include finite permutations:

σ(i)=i+𝓇i𝓁i,i

Lemma 4.6 (p. 627)

Gnedin; Olshanski. The two-sided infinite extension of the Mallows model for random permutations


Deutsch et al. 2008

Template:Textbox

In a permutation π=π1π2πn, an inversion is a pair i<j such that πi>πj. Template:Ellipsis
If ci is the number of j>i with πj<πi, then (c1,c2,,cn) is called the right inversion vector of π Template:Ellipsis.

Deutsch; Pergola; Pinzani. Six bijections between deco polyominoes and permutations — p. 5


Barth & Mutzel 2004

Template:Textbox

File:Bilayer cross counting, non-map.svg
Crossings in a bilayer graph...
...correspond to inversions of a non-bijective map.

In a sequence π=a0,a1,,at1 of pairwise comparable elements ai(i=0,1,,t1), a pair (ai,aj) is called an inversion if i<j and ai>aj.

A crucial point of the article is illustrated by the images on the right: A bilayer graph that does not describe a map corresponds to a map that has the edges (green) as its domain and one layer of the vertices (blue) as its codomain. The number of crossings in the bilayer graph can be calculated as the number of inversions of the map.
In this example the map is π=0,1,2,0,3,4,0,2,3,2,4.

π2=2, π3=0 and π6=0, so with the place-based definition the sequence would have the inversions (2,3) and (2,6).
With the element-based definition, chosen by the authors, one could say that the sequence has the inversion (2,0) twice.

Template:Cite journal — 2 Bilayer Cross Counts and Inversion Numbers (p. 183)