Documentation

CslibFrontier.Computability.PolyTime.PacketPacking

Computing the packing of Lemma D.3 in polynomial time #

Cslib.PacketPacking.packing packs the edges of a bipartite multigraph into packets (Lemma D.3 of [OAI26k], §D.4.2, pp. 58–59). This file computes it natively, on vertices and edges numbered by natural numbers, and proves that the result is exactly packing (nativePacking_eq), so Lemma D.3 (1) and (3), numPackets_packing_mul_le and the 2M / r port bounds row_ports_packing_le and col_ports_packing_le, hold for the native output.

Labels. labelPass runs the conditional-expectation pass of partialLabels over the rows, then the columns. For each slot it streams the r ^ a candidates in radix order with Cslib.BalancedSchedules.streamBestSlotLabel, the selector of Lemma 4.5, scoring them by the cleared incidence potential alone: the group term vanishes for zero variables (clearedJointScore_zero_one). The candidate count is capped (cappedLength): when r ^ a ≤ M, for M the number of edges, the selector streams all candidates, and otherwise it streams one empty word. So every step runs in polynomial time, and under r ^ a ≤ M, which (D.6) implies (pow_le_card_of_packing), the pass is exactly partialLabels (labelPass_eq).

Packets. packingOfWords follows Packing.ofLabels: it numbers the edges within their classes (classIndices), takes the largest class (maxLoadOf) and the number of packets (numPacketsOf), and gives each edge its packet (packetOf) and slot (slotOf) by the arithmetic of packetEquiv and BitString.equivFin. packetSymbols decodes the symbols of a packet. These are exact for any labels (packingOfWords_eq, packetSymbols_eq).

Inputs. The numbers of rows and columns and the label length are in unary, the alphabet size and the (row, column) edges in binary (encPackingInput). The bound r ^ a ≤ M is not checked: without it the native output is still computed in polynomial time, but it need not be packing.

Main definitions #

Main results #

References #

The label pass #

@[reducible, inline]

Partial row and column words, none where no label is fixed yet.

@[reducible, inline]

The parameters of the pass: (a, r) and the incidences (column, row).

The label length that the selector streams: a when r ^ a ≤ m, so that there are at most m candidates, and 0 otherwise.

The label of a slot chosen by the conditional expectation of the incidence potential: streamBestSlotLabel with no group term (zero variables) and unit weight, over the capped label length.

One step of the pass: a slot without a word gets bestLabel.

The slots of the pass: the rows (false, v), then the columns (true, w).

The label pass on nR rows and nC columns, with the edges given as (row, column) pairs.

def Cslib.PacketPacking.labelWords (nR nC a r : ℕ) (edges : List (ℕ × ℕ)) :

The row and column words: the pass, with the zero word where none was fixed.

Correctness #

The words [r]^a with digits in base r, in the radix order of the selector.

The enumeration of Fin n lists 0, …, n - 1.

theorem Cslib.PacketPacking.pow_le_card_of_packing {a r M : ℕ} (hr : 1 ≤ r) (hL : 2 ^ a * r ^ (2 * a) ≤ M) :
r ^ a ≤ M

The second inequality of (D.6), L D ≤ M, implies that there are at most M candidate labels.

theorem Cslib.PacketPacking.clearedJointScore_zero_one {E nC nR a r : ℕ} (hr : 1 ≤ r) (hE : 0 < E) (edge : Fin E → Fin nC × Fin nR) (rows : Fin nR → Option (Fin a → Fin r)) (cols : Fin nC → Option (Fin a → Fin r)) :

With zero variables and unit weight, the joint score of the selector is the cleared incidence potential scaled by r, so it orders the candidates as partialIncidencePotential does.

def Cslib.PacketPacking.toWords {nR nC a r : ℕ} (assigned : (Fin nR → Option (Fin a → Fin r)) × (Fin nC → Option (Fin a → Fin r))) :

Partial labels on Fin vertices as lists of words.

A row or column of Fin vertices as a slot of the pass.

theorem Cslib.PacketPacking.labelStep_toWords {m nR nC a r : ℕ} [NeZero r] (rowOf : Fin m → Fin nR) (colOf : Fin m → Fin nC) (hK : r ^ a ≤ m) (assigned : (Fin nR → Option (Fin a → Fin r)) × (Fin nC → Option (Fin a → Fin r))) (s : Fin nR ⊕ Fin nC) :

One step of the pass is one step of greedyLabelPassBy for the incidence potential, when r ^ a ≤ m.

def Cslib.PacketPacking.edgeList {m nR nC : ℕ} (rowOf : Fin m → Fin nR) (colOf : Fin m → Fin nC) :

The edges of rowOf and colOf as (row, column) pairs.

theorem Cslib.PacketPacking.labelPass_eq {m nR nC a r : ℕ} [NeZero r] (rowOf : Fin m → Fin nR) (colOf : Fin m → Fin nC) (hK : r ^ a ≤ m) :
labelPass nR nC a r (edgeList rowOf colOf) = toWords (partialLabels rowOf colOf a r)

The pass computes partialLabels when r ^ a ≤ m.

theorem Cslib.PacketPacking.labelWords_eq {m nR nC a r : ℕ} [NeZero r] (rowOf : Fin m → Fin nR) (colOf : Fin m → Fin nC) (hK : r ^ a ≤ m) :
labelWords nR nC a r (edgeList rowOf colOf) = (List.ofFn fun (v : Fin nR) => BalancedSchedules.scheduleToWord (rowLabels rowOf colOf a r v), List.ofFn fun (w : Fin nC) => BalancedSchedules.scheduleToWord (colLabels rowOf colOf a r w))

The words are rowLabels and colLabels when r ^ a ≤ m.

Polynomial time #

The parameters ((a, r), incidences) of the pass: a in unary, r and the incidences in binary.

@[reducible, inline]

The inputs ((nR, nC, a), (r, edges)) of the packing: the numbers of rows and columns and the label length a in unary, the alphabet size r and the (row, column) edges in binary.

@[reducible, inline]

The encoding of the arguments of bestLabel and labelStep.

bestLabel is polynomial-time: the capped selector streams at most m + 1 candidates.

Packets and slots #

def Cslib.PacketPacking.edgeWordPairs (rowWords colWords : List (List ℕ)) (edges : List (ℕ × ℕ)) :

The pairs of words at the two ends of the (row, column) edges.

The number of each edge within its class: how many earlier edges have the same pair of words.

The largest class size: one more than the largest class number, or zero without edges.

The number of packets: the blocks of 2 ^ a slots needed for the largest class, times the (r * r) ^ a words of pairs of symbols.

def Cslib.PacketPacking.slotOf (a : ℕ) (ρ κ : List ℕ) (c : ℕ) :

The slot of an edge with row word ρ, column word κ and class number c. Where the two symbols differ, digit i is 1 when the row symbol is the larger; where they agree, it is digit i of c.

def Cslib.PacketPacking.packetOf (a r : ℕ) (ρ κ : List ℕ) (c : ℕ) :

The packet of an edge with row word ρ, column word κ and class number c: its block c / 2 ^ a, and in each coordinate the sorted pair of symbols, swapped when digit i of c is 1, numbered as Cslib.PacketPacking.packetEquiv numbers them.

def Cslib.PacketPacking.packingOfWords (a r : ℕ) (rowWords colWords : List (List ℕ)) (edges : List (ℕ × ℕ)) :

The packing for given words: the number of packets, and the packet and slot of each (row, column) edge.

The packing of Lemma D.3, natively: the row and column words, the number of packets, and the packet and slot of each (row, column) edge.

The symbols of packet p in coordinate i, as Packing.symbols decodes them: digit i of p mod (r * r) ^ a in base r * r, split into two digits in base r and sorted.

theorem Cslib.PacketPacking.packingOfWords_eq {m nR nC a r : ℕ} (rowOf : Fin m → Fin nR) (colOf : Fin m → Fin nC) (ρ : Fin nR → Fin a → Fin r) (κ : Fin nC → Fin a → Fin r) [NeZero r] :
packingOfWords a r (List.ofFn fun (v : Fin nR) => BalancedSchedules.scheduleToWord (ρ v)) (List.ofFn fun (w : Fin nC) => BalancedSchedules.scheduleToWord (κ w)) (edgeList rowOf colOf) = ((Packing.ofLabels rowOf colOf ρ κ).numPackets, List.ofFn fun (e : Fin m) => (↑((Packing.ofLabels rowOf colOf ρ κ).packet e), ↑((Packing.ofLabels rowOf colOf ρ κ).slot e)))

The packing for given words is Packing.ofLabels.

theorem Cslib.PacketPacking.packetSymbols_eq {m nR nC a r : ℕ} (rowOf : Fin m → Fin nR) (colOf : Fin m → Fin nC) (ρ : Fin nR → Fin a → Fin r) (κ : Fin nC → Fin a → Fin r) (p : Fin (Packing.ofLabels rowOf colOf ρ κ).numPackets) (i : Fin a) :
packetSymbols a r ↑p ↑i = (↑((Packing.ofLabels rowOf colOf ρ κ).symbols p i).1, ↑((Packing.ofLabels rowOf colOf ρ κ).symbols p i).2)

The symbols of a packet are those of Packing.ofLabels.

theorem Cslib.PacketPacking.nativePacking_eq {m nR nC a r : ℕ} [NeZero r] (rowOf : Fin m → Fin nR) (colOf : Fin m → Fin nC) (hK : r ^ a ≤ m) :
nativePacking nR nC a r (edgeList rowOf colOf) = ((List.ofFn fun (v : Fin nR) => BalancedSchedules.scheduleToWord ((packing rowOf colOf a r).rowLabel v), List.ofFn fun (w : Fin nC) => BalancedSchedules.scheduleToWord ((packing rowOf colOf a r).colLabel w)), (packing rowOf colOf a r).numPackets, List.ofFn fun (e : Fin m) => (↑((packing rowOf colOf a r).packet e), ↑((packing rowOf colOf a r).slot e)))

The native packing is the packing of Lemma D.3 when r ^ a ≤ m, which (D.6) implies (pow_le_card_of_packing): the words of rowLabels and colLabels, the number of packets, and the packet and slot of each edge. So Lemma D.3 (1) and (3) hold for its output.

theorem Cslib.PacketPacking.numPackets_nativePacking_mul_le {m nR nC a r Δ : ℕ} [NeZero r] (rowOf : Fin m → Fin nR) (colOf : Fin m → Fin nC) (hrow : ∀ (v : Fin nR), {e : Fin m | rowOf e = v}.card ≤ Δ) (hcol : ∀ (w : Fin nC), {e : Fin m | colOf e = w}.card ≤ Δ) (hM : 2 * Δ * (r ^ (2 * a)) ^ 2 ≤ m) (hL : 2 ^ a * r ^ (2 * a) ≤ m) :
match nativePacking nR nC a r (edgeList rowOf colOf) with | (fst, numPackets, snd) => numPackets * 2 ^ a ≤ 3 * m

Lemma D.3 (1) for the native packing. Under (D.6), 2 Δ D² ≤ M and L D ≤ M, the native packing has at most 3M / L packets.

Polynomial time of the packets #

@[reducible, inline]

The inputs (((a, r), (rowWords, colWords)), edges) of packingOfWords: a in unary and the rest in binary.

The output encoding of packingOfWords: the number of packets and the (packet, slot) pairs, in binary.

theorem Cslib.PacketPacking.computableInPolyTime_packingOfWords :
Turing.MultiTapeTM.ComputableInPolyTime (fun (x : WordsInput) => match x with | (((a, r), rowWords, colWords), edges) => packingOfWords a r rowWords colWords edges) encWordsInput encPlacements

The packing for given words is polynomial-time.

The native packing is polynomial-time. With nativePacking_eq, Lemma D.3's packing is computable in polynomial time whenever r ^ a is at most the number of edges.