Efficiently sampling the realizations of bounded, irregular degree sequences of bipartite and directed graphs

Since 1997 a considerable effort has been spent on the study of the swap (switch) Markov chains on graphic degree sequences. All of these results assume some kind of regularity in the corresponding degree sequences. Recently, Greenhill and Sfragara published a breakthrough paper about irregular normal and directed degree sequences for which rapid mixing of the swap Markov chain is proved. In this paper we present two groups of results. An example from the first group is the following theorem: let d→ be a directed degree sequence on n vertices. Denote by Δ the maximum value among all in- and out-degrees and denote by |E→| the number of edges in the realization. Assume furthermore that Δ<12|E→|-4. Then the swap Markov chain on the realizations of d→ is rapidly mixing. This result is a slight improvement on one of the results of Greenhill and Sfragara. An example from the second group is the following: let d be a bipartite degree sequence on the vertex set U ⊎ V, and let 0 < c1 ≤ c2 < |U| and 0 < d1 ≤ d2 < |V| be integers, where c1 ≤ d(v) ≤ c2: ∀v ∈ V and d1 ≤ d(u) ≤ d2: ∀u ∈ U. Furthermore assume that (c2 − c1 − 1)(d2 − d1 − 1) < max{c1(|V| − d2), d1(|U| − c2)}. Then the swap Markov chain on the realizations of d is rapidly mixing. A straightforward application of this latter result shows that when a random bipartite or directed graph is generated under the Erdős—Rényi G(n, p) model with mild assumptions on n and p then the degree sequence of the generated graph has, with high probability, a rapidly mixing swap Markov chain on its realizations.


Introduction
An important problem in network science is to algorithmically construct typical instances of networks with predefined properties, often expressed as graph measures. In particular, special attention has been devoted to sampling simple graphs (in our paper only graphs without parallel edges and loops are considered) with a given degree sequence. In 1997 Kannan, Tetali, and Vempala ( [1]) proposed the use of the so-called switch Markov chain approach, which had already been used in statistics. We call this the swap Markov chain approach. a1111111111 a1111111111 a1111111111 a1111111111 a1111111111 The swap operation exchanges two disjoint edges ac and bd in the realization G with ad and bc if the resulting configuration G 0 is again a simple graph (we denote this operation by ac, bd ) ad, bc). (For details see the next section). It is a well-known fact that the set of all possible realizations of a graphic degree sequence is connected under this operation. (See, for example, Petersen [2] or Havel [3] and Hakimi [4]). An analogous result applies for the swap operation defined on bipartite graphs. (See, for example, Gale [5]). Here we have to be careful, as not every edge exchange is eligible: on a bipartite graph we must ensure that vertices a and d belong to different vertex classes.
In the literature, the name switch operation is also used, however, in our approach this latter is an operation on integer matrices slightly generalizing the swap operation. (See the sections on the analysis of the swap sequences).
The situation is more complicated in case of directed degree sequences. In this case for every vertex the number of incoming edges (in-degree) and the number of outgoing edges (out-degree) is given in the degree bi-sequence. Here the ac, bd ) ad, bc type exchange preserves the degree bi-sequence if both before and after the swap operation a and b are tails of the directed edges. However, imagine that our graphG is a directed triangle C 3 ! whileH is the oppositely directed C 3 . Both graphs have the same degree bi-sequence d = ((1, 1, 1); (1, 1, 1)). It is clear that there is only one way to transform the first one into the second one: if we exchange three edges and three non-edges inG. We will call this operation a triple swap and the previously defined "classical" one as a double swap. Kleitman and Wang proved in 1973 ( [6]) that any two realizations of a given graphic degree bi-sequence can be transformed into each other using these two operations. The same fact was re-discovered in 2010 (see [7]). The swap Markov chains corresponding to the most common graph models are irreducible, aperiodic, reversible (obey detailed balance), have symmetric transition matrices, and thus have uniform global stationary distributions.
In their paper [1], Kannan, Tetali and Vempala conjectured that all these Markov chains are rapidly mixing. The first rigorous proof in this topic is due to Cooper, Dyer and Greenhill for regular graphs ( [8]). Now, twenty years after the KTV conjecture, we are still far, probably very far, from proving it in its full generality. However, many partial results have been proved; those which play some role in this paper are summarized in the following theorem: Theorem 1. The swap Markov chain mixes rapidly for the following degree sequences: (A). d is a regular directed degree sequence.
(B). d is a half-regular bipartite degree sequence.
(C). d belongs to an almost-half-regular bipartite graph. There exist similar results on (normal) degree sequences as well, but their proofs are not fully "compatible" with the proof of the above results (except case D). To our knowledge there does not exist a fully developed proof machinery which is applicable for all three cases, that is, for normal, bipartite, and directed degree sequences.
The result (A) was proved by Greenhill ([9]). In the proof it is assumed that the set of all realizations of the regular directed degree bi-sequence is irreducible under the double swap operations. (B) is due to Miklós,Erdős,and Soukup ([10]). Half-regularity means that in one class the degrees are the same (i.e., regular), while in the other class the only restrictions are those imposed by graphicality. (C) is due to Erdős,Miklós,and Toroczkai ([11]). Here almosthalf-regular means that for any pair of vertices on one side we have |d(v 1 ) − d(v 2 )| 1. (D) was proved by Erdős, Kiss, Miklós, and Soukup ( [12]). This model will be introduced in detail and its intrinsic connection with directed graphs will be fully explained in the section starting with Lemma 12. Papers [9] and [12] are using slightly different Markov chains on regular directed degree sequences, therefore (D) does not supersede (A). Finally, (E) was proved recently by Greenhill and Sfragara ([13]). Their result has vastly extended the set of (normal and directed) degree sequences for which the rapid mixing of the Markov chain is known (e.g., power-law density-bounded normal degree sequences with parameter γ > 2.5). The papers [14] and [15] fully characterize those degree bi-sequences where the set of all realizations is irreducible under the double swap operation.
In this paper we improve on the result of Greenhill and Sfragara on directed degree sequences, and we prove the bipartite analogue of their degree sequence result for simple graphs. We achieve this by applying our technique described in [12]. In addition, we further extend the set of bipartite and directed degree sequences with rapidly mixing Markov chain processes, using a condition on minimum and maximum degrees.
Let d be a bipartite degree sequence on the underlying set U ] V. (So the underlying set is equal to the disjoint union of the two classes).
Theorem 2. Let d be a bipartite degree sequence on U and V as classes, let |E| be half of the sum of the degrees, and let Δ = max d. If then the swap Markov chain on the realizations of d is rapidly mixing.
The following result describes another wide range of bipartite degree sequences with rapidly mixing swap Markov chain. Theorem 3. Let 0 < c 1 c 2 < |U| = n and 0 < d 1 d 2 < |V| = m be integer parameters and assume that d satisfies the following properties: Furthermore, assume that holds. Then the swap Markov chain on the realizations of d is rapidly mixing. We conjecture that a very similar result should apply to the case of normal degree sequences.
Our next two results are about directed degree sequencesd on the n element vertex set X. The first one improves the constant 1 4 in the result of Greenhill and Sfragara to 1 ffi ffi 2 p . Moreover, because both double and triple swaps are allowed, the irreducibility condition can be omitted from the theorem. Theorem 4. Letd be a directed degree sequence on the n element V as its vertex set. Let jẼj be half of the sum of the degrees, and let Δ = max{max d out , max d in }. If then the swap Markov chain on the realizations ofd is rapidly mixing.
Lastly, we show that conditions similar to that of Theorem 3 guarantee rapid mixing of the swap Markov chains on a wide class of directed degree sequences.
Theorem 5. Let 0 < c 1 c 2 < n and 0 < d 1 d 2 < n be integer parameters and assume that graphic degree bi-sequenced satisfies the following properties: Furthermore, assume that holds. Then the swap Markov chain, using double and triple swap operations, is rapidly mixing on the realizations ofd.
The proofs of our results strongly support Greenhill's observation about the existing arguments ( [16]): "In each known case, regularity (or half-regularity) was only required for one lemma, which we will call the critical lemma. This is a counting lemma which is used to bound the maximum load of the flow (see [8,Lemma 4] The main task is to prove the critical lemmas (Lemma 11 and 12) for our new conditions (2)(3)(4)(5)(6). To that end, we first list the fundamental details from [12].
We would like to mention that after submitting a preprint of an earlier version of this paper on arXiv, Amanatidis and Kleer have contacted us, claiming to have proved that the degree sequences studied here are also "strongly stable" (see [17]).
The next 3 sections lay down the foundations of the swap Markov chain on bipartite and directed degree sequences. These have been originally described in our own paper [12]. For the sake of readability and convenience, we recall in more detail some results from paper [12], as they are crucial in understanding the presented approach.

Definitions and useful facts
In this section, we recall some well-known definitions and results, furthermore we define our swap Markov chains for the bipartite degree sequences and for the directed degree sequences. Let For a ac, bd ) ad, bc swap operation to be valid it is not enough that ac, bd 2 E(G) and ad, bc = 2 E(G), we also need that ad can be an edge in some realization. In other words, we need that a and d are in different vertex classes. We will use the name chord for any vertex pair u, v where uv can be an edge in a realization, even if we do not know or do not care whether it is an edge or a non-edge in the current realization. We can reformulate the definition of the swap operation: it can be done if ac, bd 2 E(G) and ad, bc are chords. Now denote by G the set of all possible realizations of the graphic bipartite degree sequence (d(U), d(V)). Consider two different realizations, G and H, of this bipartite degree sequence. As we already mentioned in the introduction, it is a well-known fact that the first realization can be transformed into the second one (and vice versa) with a sequence of swap operations. Formally, there exists a sequence of realizations G = G 0 , . . ., G i−1 , G i = H, such that for each j = 0, . . ., i − 1 there exists a swap operation which transforms G j into G j+1 . We denote the swap Markov chain as M ¼ ðG; PÞ where the transition matrix P is the following: In any realization with probability 1 2 we stay in the current state (i.e., the chain is lazy) and with probability 1 2 we uniformly choose two-two vertices u 1 , u 2 ;v 1 , v 2 from classes U and V, respectively. We perform the swap and the resulting graph G 0 is simple. Otherwise we do not perform a move. The swap moving from G to G 0 is unique, therefore the jumping probability from G to G 0 6 ¼ G is: The transition probabilities are time-and edge-independent and are also symmetric. The chain is lazy, therefore aperiodic. It is also reversible, and so its globally stable stationary distribution is uniform. Now we turn our attention to the notions and notation to describe Theorems 4 and 5. Literally these theorems are about directed graphs, however, we will use the machinery developed in the paper [12], turning these statements into theorems about bipartite graphs with some restriction on which edges can be used in the realizations.
LetG be a simple directed graph (parallel edges and loops are forbidden, but oppositely directed edges between two vertices are allowed) with vertex set XðGÞ ¼ fx 1 ; x 2 ; . . . ; x n g and edge set EðGÞ. For every vertex x i 2 X we associate two numbers: the in-degree and the outdegree of x i . These numbers form the directed degree bi-sequence D.
We transform the directed graphG into the following bipartite representation: let BðGÞ ¼ ðU; V; EÞ be a bipartite graph where each class consists of one copy of every vertex from XðGÞ. The edges adjacent to a vertex u x in class U represent the out-edges from x, while the edges adjacent to a vertex v x in class V represent the in-edges to x (so a directed edge xy corresponds the edge u x v y ). If a vertex has zero in-(respectively out-) degree inG, then we delete the corresponding vertex from BðGÞ. (Actually, this representation is an old trick used by Gale [5], but one can find it already in [2]). The directed degree bi-sequence D gives rise to a bipartite degree sequence.
Here we make good use of the notion of chords: since there are no loops in our directed graph, there cannot be any (u x , v x ) edge in its bipartite representation-these vertex pairs are non-chords. It is easy to see that these forbidden edges form a forbidden (partial) matching F in the bipartite graph BðGÞ, or in more general terms, in B(D). To make it easier to remember the nature of restriction, we will denote this restricted bipartite degree sequence withd.
We consider all realizations GðdÞ which avoid the non-chords from F . Now it is easy to see that the bipartite graphs in GðdÞ are in one-to-one correspondence with the possible realizations of the directed degree bi-sequence.
Consider now again our example about two oppositely oriented triangles, C 3 ! and C 3 . Consider the bipartite representations BðC 3 ! Þ and BðC 3 Þ, and take their symmetric difference r. In general: if the current symmetric difference r contains a length-6 alternating cycle C 6 such that all opposite vertex pairs form non-chords, then we allow performing the corresponding C 6 -swap. In this notation, the original swap should properly be called a C 4 -swap (for obvious reasons), but for the sake of simplicity we only write swap instead of C 4 -swap. By the constraints posed by the forbidden partial matching, only a subset of all bipartite swaps can be performed. These swaps together with the possible C 6 -swaps we just defined are called the F -compatible swaps or F -swaps for short. We are ready to define our swap Markov chainM ¼ ðGðdÞ; PÞ for the restricted bipartite degree sequenced.
The transition (probability) matrix P of the Markov chain is defined as follows: let the current realization be G. Then 1. with probability 1/2 we stay in the current state, so our Markov chain is lazy; 2. with probability 1/4 we uniformly choose two-two vertices u 1 , u 2 ;v 1 , v 2 from classes U and V respectively and perform the swap if it is possible; 3. finally, with probability 1/4 we choose three-three vertices from U and V and check whether they form three pairs of forbidden chords. If this is the case, then we perform a C 6 -swap if it is possible.
The swap moving from G to G 0 is unique, therefore the probability of this transformation (the jumping probability from G to G 0 6 ¼ G) is: and (These probabilities reflect the fact that G 0 should be derived from G by a C 4 -swap or by a C 6 -swap). The probability of transforming G to G 0 (or vice versa) is time-independent and symmetric. Therefore, P is a symmetric matrix, where the entries in the main diagonal are non-zero, but (possibly) distinct values. Our Markov chain is irreducible (by Lemma 6), and it is clearly aperiodic, since it is lazy. Therefore, as it is well-known, the Markov processM is reversible with the uniform distribution as the globally stable stationary distribution.

The general properties of the swap Markov chain on bipartite degree sequences
The proofs of our theorems closely follow the proof of Theorem 10 in [12], which, in turn, is based on the proof method developed in [10]. Supposed is a directed degree sequence and d is the degree sequence of bipartite representations corresponding to the realizations ofd.
As we saw earlier the sets of all realizations GðdÞ and GðdÞ are slightly different: while GðdÞ & GðdÞ but there are realizations in GðdÞ that contain edges which are forbidden in the realizations in GðdÞ: However, the following reasoning from [12] applies to both bipartite and directed degree sequences. Therefore the notation G is used to refer either of the two realization sets.
Consider two realizations X; Y 2 G, and take the symmetric difference r = E(X)ΔE(Y). Now for each vertex in the bipartite graph (U, V; r) the number of incident X-edges (= E(X)\E(Y)) and the number of the incident Y-edges are equal. Therefore r can be decomposed into alternating circuits and later into alternating cycles. The way the decomposition is performed is described in detail in Section 5 of the paper [10]. Here we just summarize the highlights: First, we decompose the symmetric difference r into alternating circuits in all possible ways. In each case we get an ordered sequence W 1 , W 2 , . . ., W κ of circuits. Each circuit is endorsed with a fixed cyclic order. Now we fix one circuit decomposition. Each circuit W i in the ordered decomposition has a unique alternating cycle decomposition: (This unique decomposition is a quite delicate point and was discussed in detail in Section 5.2 of the paper [10]).
The ordered circuit decomposition of r together with the ordered cycle decompositions of all circuits provide a well-defined ordered cycle decomposition C 1 , . . ., C l of r. This decomposition does not depend on any swap operations, only on the symmetric difference of realizations X and Y.
This ordered cycle decomposition singles out l − 1 different realizations H 1 , . . ., H l−1 from G with the following property: for each j = 0, . . ., l − 1 we have E(H j )ΔE(H j+1 ) = C j+1 if we apply the notation H 0 = X and H l = Y. This means that It remains to design a unique canonical path from X to Y determined by the circuit decomposition, which uses the realizations H j as milestones along the path. In other words, for each pair H j , H j+1 we should design a swap sequence which turns H j into H j+1 .
Here we slightly abuse the general naming conventions: in the original canonical path method for any pair X; Y 2 G exactly one X ! Y path is defined. In Sinclair's multicommodity flow method ( [19]) a (usually large) set of paths is defined, equipped with a probability distribution. In our presentation we use the expression canonical path to denote these paths, differentiating the paths in G and the paths in some realizations.
So, the canonical path under construction is a sequence where each G i can be derived from G i−1 with exactly one swap operation, and there exists an increasing subscript subsequence 0 = n 0 < n 1 < n 2 < Á Á Á < n ℓ = m, such that we have G n k ¼ H k for every 0 k ℓ.

The construction of swap sequences between consecutive milestones
Next we define the canonical path corresponding to the cycle C i . The procedure described here is slightly different from the one in [12], since the excluded edge set F in [12] is slightly larger than the one used here.
For convenience, we will use the names G; G 0 2 G instead of H i and H i+1 . These two graphs have almost the same edge set: We refer to the elements of C i \ E(X) as X-edges, while the rest of the edges of C i are Y-edges. We denote the cycle C i by C, which has 2ℓ edges and its vertices are u 1 , v 1 , u 2 , v 2 , . . ., u ℓ , v ℓ . Finally, w.l.o.g. we may assume that the chord u 1 v 1 is a Y-edge (and, of course, v ℓ u 1 is an Xedge).
We will build our canonical path from G towards G 0 . At any particular step, the last constructed realization is denoted by Z. (At the beginning of the process we have Z = G). We are looking for the next realization, denoted by Z 0 . We will control the canonical path system with an auxiliary structure, originally introduced by Kannan, Tetali and Vempala in [1]: The matrix M G denotes the adjacency matrix of the bipartite realization G where the rows and columns are indexed by the vertices of U and V, respectively, with the slight alteration that a position corresponding to a forbidden edge (a non-chord) is indicated with a Ã. There is a natural correspondence between the entries of matrices on U × V and the chords of G. Our auxiliary structure is the matrix Summation does not change the positions with a Ã. Since the non-Ã entries of a bipartite adjacency matrix are 0 or 1, the possible entries of b M are Ã, −1, 0, 1, 2. An entry is Ã if it corresponds to a forbidden edge, and it is −1 if the edge is missing from both X and Y but it exists in Z. It is 2 if the edge is missing from Z but exists in both X and Y. It is 1 if the edge exists in all three graphs (X, Y, Z) or it is there only in one of X and Y but not in Z. Finally, it is 0 if the edge is missing from all three graphs, or the edge exists in exactly one of X and Y and in Z.
(Therefore, if an edge exists in exactly one of X and Y then the corresponding chord in b M is always 0 or 1). It is easy to see that the row and column sums of b MðX þ Y À ZÞ are the same as the row and column sums in M X (or M Y , or M Z ). Now we are ready to determine the F -swap sequence between G and G 0 and this is the point where realizations from GðdÞ and GðdÞ start behave slightly differently. From now on we will work with realizations from GðdÞ but we will point out those turning points where there are real differences. The first such difference is that in the case of a directed realization G 2 GðdÞ there may be a vertex v i along the cycle C s.t. u 1 v i is a non-chord, while for a simple bipartite realization G 2 GðdÞ this does not happen.
We determine the F -swap sequence between G and G 0 from GðdÞ through an iterative algorithm. In the first iteration we check, step by step, the positions (u 1 , v 2 ), (u 1 , v 3 ), . . ., (u 1 , v ℓ ) and take the smallest j for which (u 1 , v i ) is an actual edge in G. Since (u 1 , v ℓ ) is an edge in G, such an i always exists. A typical configuration is shown in Fig 1. We call the chord u 1 v i the start-chord of the current sub-process and u 1 v 1 is the endchord. We will sweep the alternating chords along the cycle. The vertex u 1 will be the cornerstone of this operation. This process works from the start-chord u 1 v i , v i u i (non-edge), u i v i−1 (an edge) toward the end-chord v 1 u 1 (non-edge)-switching their status in twos and fours. We check positions u 1 v i−1 , u 1 v i−2 (all are non-edges) and choose the first chord among them, which we call the current-chord. (Since u 1 belongs to at most one non-chord we never have to check more than two positions to find a chord).

Case 1:
As we just explained the typical situation is that the current-chord is the "next" one, so when we start this is typically u 1 v i−1 . Assume that this is a chord. Then we can proceed with the swap operation v i−1 u i , v i u 1 ) u 1 v i−1 , u i v i . We just produced the first "new" realization in our sequence, this is G 0 1 . For the next swap operation this will be our new current realization. This operation will be called a single-step.
In a realization Z we call a chord bad if its state in Z (being edge or non-edge) is different from its state in G, or equivalently, different from its state in G 0 , since G and G 0 differ only on the chords along the cycle C (recall that in our nomenclature a chord is a pair of vertices which may form an edge). After the previous swap, we have two bad chords in G 0 1 , namely u 1 v i−1 and v i u 1 .
Consider now the auxiliary matrix b MðX þ Y À ZÞ (here Z ¼ G 0 1 ). As we saw earlier, any chord not contained in C has the same state in X, Y and Z. Accordingly, the corresponding M always corresponds to a bad chord). Since we switch the start-chord into a non-edge, it may become 2 in b M (in case the start-chord is an edge in both X and Y). Furthermore, the current-chord turned into an edge. If it is a non-edge in both X and Y then its corresponding value in b M becomes −1. After this step, we have at most two bad positions in the matrix, at most one with 2-value and at most one with −1-value. Finishing our swap operation, the previous current-chord becomes the new start-chord, so it is the edge u 1 , v i−1 .
Case 2: If the position below the start-chord (this is now u 1 v i−2 ) is a non-chord, then we cannot produce the previous swap. Then the non-edge u 1 v i−3 is the current-chord. For sake of simplicity we assume that i − 3 = 2 so we are in Fig 1. (That is, i − 1 = 4). Consider now the Efficiently sampling the realizations of bounded, irregular degree sequences of bipartite and directed graphs alternating C 6 cycle: u 1 , v 2 , u 3 , v 3 , u 4 , v 4 . It has altogether three vertex pairs which may be used to perform an F -swap operation. We know already that u 1 v 3 is a non-chord. If neither v 2 u 4 nor u 3 v 4 are chords, then this alternating cycle provides an F -compatible circular C 6 -swap. Again, we found the valid swap v 2 u 3 , v 3 u 4 , v 4 u 1 ) u 1 v 2 , u 3 v 3 , u 4 v 4 . After that we again have 2 bad chords, namely u 1 v 2 and v 4 u 1 , and together we have at most two bad positions in the new b MðX þ Y À ZÞ, with at most one 2-value and at most one −1-value.
Finally, if one position, say v 2 u 4 , is a chord then we can process this C 6 with two swap operations. If this chord is, say, an actual edge, then we swap v 2 u 4 , v 4 u 1 ) u 1 v 2 , u 4 v 4 . After this we can take care of the v 2 , u 3 , v 3 , u 4 cycle. Along this sequence we never create more than 3 bad chords: the first swap makes chords v 2 u 4 , v 4 u 1 , and u 1 v 2 bad ones, and the second cures v 2 u 4 but does not touch u 1 v 2 and v 4 u 1 . So, along this swap sequence we have 3 bad chords, and in the end we have only 2. On the other hand, if the chord v 2 u 4 is not an edge, then we can swap v 2 u 3 , v 3 u 4 ) u 3 v 3 , u 4 v 2 , creating one bad edge, then by swapping the four cycle u 1 , v 2 , u 4 , v 4 we cure v 2 u 4 but we switch u 1 v 2 and v 4 u 1 into bad chords. We finished our double-step along the cycle.
In a double-step we create at most three bad chords. When the first swap uses three chords along the cycle then we may have at most one bad chord (with b M-value 0 or −1) and then the next swap switches back the chord into its original status, and makes two new bad chords (with at most one 2-value and one −1-value). When the first swap uses only one chord from the cycle, then it creates three bad chords (changing two chords into non-edges and one into an edge), therefore it may create at most two 2-values and one −1-value. After the second swap, there will be only two bad chords, with at most one 2-value, and at most one −1-value.
When only the third position corresponds to a chord in our C 6 then after the first swap we may have two −1-values and one 2-value. However, after the next swap we will have at most one of both types.
After finishing our single-or double-step, the previous current-chord becomes the new start-chord and we look for the new current-chord. Then we repeat our procedure. There is one important point to be mentioned: along the step, the start-chord switches back into its original status, so it will not be a bad chord anymore. So even if we face a double-step the number of bad chords will never be larger than three (together with the chord v i u 1 which is still in the wrong state, so it is a bad chord), and we always have at most two 2-values and at most one MðX þ Y À ZÞ. When our current-chord becomes v 1 u 2 then the last step will switch back the last startchord into its correct state, and the last current-chord cannot be in a bad state. So, when we finish our sweep from u 1 v i to v 1 u 1 , we will only have one bad chord (with a possible 2-value in b M). This concludes the first iteration of our algorithm.
For the next iteration, we seek a new start-chord between v i u 1 and v ℓ u 1 and the chord v i u 1 becomes the new end-chord. We repeat our sweeping procedure until there are no more unprocessed chords. Upon completion, we find a realization sequence from G to G 0 . If in the first sweep we had a double-step, then such a step will never occur later, so altogether with the (new) bad end-chord we never have more than three bad chords (corresponding to at most two 2-values and at most one −1-value).
However, if the double-step occurs sometime later, for example in the second sweep, then we face to the following situation: if we perform a circular C 6 -swap, then all together we have at most two 2-values and one −1-value. Thus, we may assume that there is a chord suitable for a swap in our C 6 . If this chord is a non-edge, then the swap around it produces one bad chord, and at most one bad position in b M. The only remaining case is when that chord is an edge. After the first swap there will be four bad chords, and there may be at most three 2-values and at most one −1 value. However, after the next swap (finishing the double step) we annihilate one of the 2-values, and after that swap there are at most two 2-values and at most one −1-value along the entire swap sequence. When we finish our second sweep, then chord v i u 1 will be switched back into its original state and it will not be bad anymore.
Iteratively applying the algorithm, the entire cycle C is processed after at most ℓ sweep sequences. This finishes the construction of the required F -swap sequence (and the required realization sequence).
Meanwhile we also proved the following important observations: MðX þ Y À ZÞ occurring along our procedure is at most swap-distance one from a matrix with at most three bad positions: with at most two 2-values and with at most one −1-value in the same column.
Now we are ready to describe the following, highly technical theorem from [10] which is required to show that the defined swap Markov-chains are rapidly mixing.
Theorem 9 (Section 4 in [10]). If the designed canonical path system satisfies the three conditions below, then the MCMC process is rapidly mixing. The conditions are: (X). For each vertex G 0 j in the path being traversed the following three objects together uniquely determine the realizations X, Y and the path itself: • and a polynomial size parameter set B.
The meaning of condition (X) is that these structures can be used to control certain features of the canonical path system; namely, their numbers give a bound on the number of canonical paths between any realization pair X, Y which traverses G 0 j . Condition (O) implies that the space of auxiliary matrices is larger than VðGÞ by a multiplicative factor of at most ðnmÞ 2O 2 .
To use this theorem we have to show that the defined swap sequences between H i and H i+1 , using the cornerstone u 1 chosen in (F), satisfy conditions (Θ), (O), and (X) of Theorem 9. The first one is easy to see, since we can process any cycle of length 2ℓ in ℓ − 1 swaps. Therefore, we may choose c = 1 in (Θ). Condition (X) holds for the same reason as it holds in paper [12]. Thus only condition (O) remains to be checked.
Until this very moment the choice of the cornerstone vertex u 1 was arbitrary. Before we turn to the analysis of the swap sequences, we choose which particular vertex of the cycle C will serve as its cornerstone.
Let the submatrix A contain those positions from any adjacency or any auxiliary matrix which correspond to the positions u i v j defined by the vertices from C. Furthermore, denote by

The analysis of the swap sequences between milestones in M
In this section, we will analyze the undirected case. We introduce the new switch operation on integer matrices: we fix the four corners of a submatrix, and we add 1 to two corners in a diagonal, and add −1 to the corners on the other diagonal. This operation clearly does not change the column and row sums of the matrix. (We will use this operation on adjacency matrices or on auxiliary matrices of realizations). For example, if we consider the adjacency matrix M G of a realization of d and make a valid swap operation, then this is equivalent to a switch in this matrix. The next statement is trivial but very useful: 2ðD À 1ÞðD À 2Þ: The number of entries of 1 in b M 0 that are incident on the same row as u 0 or u 1 , on the same column as v 0 or v 1 , or in the above counted set is at most For any v 2 V 0 and u 2 U\U@, we have b M 0 u;v ¼ 1. Also, for any u 2 U 0 and v 2 V\V@, we have b M 0 u;v ¼ 1. Therefore n À c 1 À 2 ! jU n U 0 n fu 0 gj ! jU 00 j ! n À c 2 ; m À d 1 À 2 ! jV n V 0 n fu 0 gj ! jV 00 j ! m À d 2 : Clearly, if c 2 c 1 + 1 or d 2 d 1 + 1 (i.e., G is almost half-regular), we already have a contradiction. We also have & ðu; vÞ 2 U 00 Â ðV n V 00 n fv 0 gÞj b M 0 u;v ¼ 0 ' ! ! ðn À c 2 Þðm À jV 00 j À 1Þ À jU n U 0 n U 00 j Á jV n V 0 n V 00 n fv 0 gj ! ! ðn À c 2 Þðm À jV 00 j À 1Þ À ðn À c 1 À 1 À jU 00 jÞ Á ðm À d 1 À 2 À jV 00 jÞ: Combining Eqs 11 and 12, jU 00 j Á ðm À d 1 Þ ! ðn À c 2 Þ Á ðm À jV 00 j À 1Þ þ jU 00 jðm À d 1 À 1Þþ þ ðjV 00 j þ 1Þ Á ðn À c 1 À 1Þ À ðn À c 1 À 1Þ Á ðm À d 1 À 1Þ: Further simplifying: jU 00 j ! ðjV 00 j þ 1Þðc 2 À c 1 À 1Þ þ ðc 1 þ 1 À c 2 Þm þ ðd 1 þ 1Þn À ðc 1 þ 1Þðd 1 þ 1Þ: Since we may suppose that c 2 ! c 1 + 2, we can substitute |V@| ! m − d 2 and |U@| n − c 1 − 2 into the inequality, yielding Symmetrically, a similar derivation gives The last two inequalities clearly contradict the assumptions of this claim.
In summary, in every case there exist at most 4 switches which transform b M into a 0 − 1 matrix, which is a matrix with suitable row-and column sums, therefore it is the adjacency matrix of a realization K of the degree sequence d.

The analysis of the swap sequences between milestones inM
Now we turn to discussing the directed case. As in the previous section, condition (O) is the only remaining assumption of Theorem 9 which does not immediately follow from the construction of swap sequences between consecutive milestones. Lemma 12. For any realization Z along the constructed swap sequence from G to G 0 there exists a realization K = K(Z) such that MðX þ Y À ZÞ; M K 20: Proof. As described by Lemma 8, it is possible that realization Z is derived by an F -swap which is a first C 4 -swap to resolve an alternating C 6 cycle along the sweep. It may introduce an extra 2-value and/or a −1-value into the auxiliary structure. But Lemma 8 also shows that the next C 4 swap will revert these extra bad positions. Therefore let Z S denote the realization Z itself if this extra swap is not needed, or the new realization if it is needed. Then b MðX þ Y À Z S Þ has at most two entries of 2 and at most one entry of −1. Now we have to show that there is a realization K such that MðX þ Y À Z S Þ; M K 16: As before we will use the shorthand b MðX þ Y À Z S Þ ¼ b M: The swap sequence transforming the bipartite representation G to G 0 (also, the previous extra swap) only touches chords induced by VðCÞ. Therefore, the row and column sums in follows. Since the row and column sums of b M 0 are the same as that of M X , we have Also, n À c 1 À 2 ! jU n U 0 n fu 0 gj ! jU 00 j ! n À c 2 À 1; n À d 1 À 2 ! jV n V 0 n fu 0 gj ! jV 00 j ! n À d 2 À 1: Clearly, if c 2 = c 1 or d 2 = d 1 (i.e., G is half-regular), we already have a contradiction. Each column in V \ V@ may contain at most one Ã, therefore & ðu; vÞ 2 U 00 Â ðV n V 00 n fv 0 gÞj b M 0 u;v 2 f0; Ãg ' ! ! ðn À c 2 Þðn À jV 00 j À 1Þ À jU n U 0 n U 00 j Á jV n V 0 n V 00 n fv 0 gj: Moreover, b M 0 u;v 0 2 f0; Ãg for any u 2 U@. Combining these inequalities, we get jU 00 j Á ðn À d 1 Þ ! ðjU 00 Â V 00 j À jV 00 jÞ þ jU 00 jþ þðn À c 2 Þðn À jV 00 j À 1Þ À jU n U 0 n U 00 j Á jV n V 0 n V 00 n fv 0 gj: A few lines of computation similar to those in the previous section give ðc 2 À c 1 Þðd 2 À d 1 Þ ! d 1 ðn À c 2 À 1Þ þ 3 þ c 1 þ d 2 À n: Symmetrically, we also have ðc 2 À c 1 Þðd 2 À d 1 Þ ! c 1 ðn À d 2 À 1Þ þ 3 þ d 1 þ c 2 À n: The last two inequalities clearly contradict the assumptions of this claim.
In summary, in every case there exist at most 4 switches which transform b M into a 0 − 1 matrix, which is a matrix with suitable row-and column sums, therefore it is the adjacency matrix of a realization K of the degree sequenced.

Erdős-Rényi random graphs
The following statement is a straightforward, easy consequence of Theorem 3. then the swap Markov chain is rapidly mixing on the bipartite degree sequence of G with probability at least 1 À 1 n À 1 m . (The roles of m and n can be interchanged). Proof. Let p = p(n, m), ε c ¼ 1 3 pn and ε d ¼ 1 3 ð1 À pÞm. Also, let c 1 = pn − ε c , c 2 = pn+ ε c , d 1 = pm − ε d , d 2 = pm+ ε d . Eq 3 holds, we only need to check that 4ε c ε d ðpn À ε c Þ Á ðm À pm À ε d Þ: