Documentation

CslibFrontier.Foundations.Combinatorics.PacketPacking

Packing the edges of a bipartite multigraph into packets #

Lemma D.3 of [OAI26k] (§D.4.2, pp. 58–59) labels the vertices on each side of a bipartite multigraph by words in [r]^a and places its M edges into packets of L = 2 ^ a slots. Edge e joins the row vertex rowOf e to the column vertex colOf e. A Packing records

These are the structural properties (1)–(2) of Lemma D.3. The construction packing meets the quantitative ones under the size hypotheses (D.6), 2 Δ D² ≤ M and L D ≤ M with D = r ^ (2a) the number of pairs of labels and Δ the maximum degree:

Labels. rowLabels and colLabels fix one whole label at a time by the method of conditional expectations, minimizing the closed-form average partialIncidencePotential of the potential Φ = ∑_γ (X_γ - M / D)², where X_γ counts the edges with the pair of labels γ (Cslib.BalancedSchedules.greedyLabelPassBy). Ties go to the first candidate in radix order (labelCandidates), the order in which a machine streams the candidates by counting. For independent uniform labels, 𝔼 Φ ≤ 2 M Δ (Cslib.BalancedSchedules.expect_incidence_potential_le), so the chosen labels have Φ ≤ 2 M Δ (potential_labels_le), and with 2 Δ D² ≤ M every class has at most 2M / D edges (occupancy_labels_mul_le).

Packets. Packing.ofLabels packs the edges for any labels. Number the edges with each pair of labels γ from zero in the order of E (classIndex), and pad each class to h L slots, the largest class size rounded up to a multiple of L (numBlocks). An edge with number k = b L + o goes to block b. In a coordinate where its two symbols differ, its slot digit is their orientation; where they agree, it is the corresponding digit of o. Its packet is determined by the block, the unordered pairs of symbols, and the digits of o in the coordinates where the symbols differ. So each packet holds 2 ^ (a - a') slots of each of the 2 ^ a' orientations of its pairs, as in the source, and there are h D packets.

The source's padded size H_pad is our h L. All constructions are executable finite computations with mathematical correctness proofs. A native polynomial-time computation of packing is in CslibFrontier/Computability/PolyTime/PacketPacking.lean.

Main definitions #

Main results #

References #

Packings #

structure Cslib.PacketPacking.Packing {E : Type u_1} {R : Type u_2} {C : Type u_3} (rowOf : E → R) (colOf : E → C) (a r : ℕ) :
Type (max (max u_1 u_2) u_3)

A packing of the edges of a bipartite multigraph into packets of 2 ^ a slots, where edge e joins the row vertex rowOf e to the column vertex colOf e. It labels the vertices on each side by words in [r]^a, places each edge in a slot of a packet with no two edges in the same place, and gives each packet a pair of symbols in each coordinate. An edge whose slot has binary digit i equal to 0 has the packet's pair as its row and column symbols in coordinate i; one whose digit i is 1 has the pair swapped.

def Cslib.PacketPacking.pairLabel {E : Type u_1} {R : Type u_2} {C : Type u_3} (rowOf : E → R) (colOf : E → C) {a r : ℕ} (ρ : R → Fin a → Fin r) (κ : C → Fin a → Fin r) (e : E) :
(Fin a → Fin r) × (Fin a → Fin r)

The pair of labels of the row and column ends of an edge.

Numbering the edges within their classes #

def Cslib.PacketPacking.classIndex {E : Type u_1} {R : Type u_2} {C : Type u_3} [Fintype E] [LinearOrder E] (rowOf : E → R) (colOf : E → C) {a r : ℕ} (ρ : R → Fin a → Fin r) (κ : C → Fin a → Fin r) (e : E) :

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

def Cslib.PacketPacking.maxLoad {E : Type u_1} {R : Type u_2} {C : Type u_3} [Fintype E] [LinearOrder E] (rowOf : E → R) (colOf : E → C) {a r : ℕ} (ρ : R → Fin a → Fin r) (κ : C → Fin a → Fin r) :

The largest class size: one more than the largest number of an edge in its class, or zero without edges.

def Cslib.PacketPacking.numBlocks {E : Type u_1} {R : Type u_2} {C : Type u_3} [Fintype E] [LinearOrder E] (rowOf : E → R) (colOf : E → C) {a r : ℕ} (ρ : R → Fin a → Fin r) (κ : C → Fin a → Fin r) :

The number of blocks of 2 ^ a slots needed for the largest class: ⌈maxLoad / 2 ^ a⌉.

theorem Cslib.PacketPacking.classIndex_lt_occupancy {E : Type u_1} {R : Type u_2} {C : Type u_3} [Fintype E] [LinearOrder E] (rowOf : E → R) (colOf : E → C) {a r : ℕ} (ρ : R → Fin a → Fin r) (κ : C → Fin a → Fin r) (e : E) :
classIndex rowOf colOf ρ κ e < BalancedSchedules.occupancy (pairLabel rowOf colOf ρ κ) (pairLabel rowOf colOf ρ κ e)

An edge is numbered below the size of its class.

theorem Cslib.PacketPacking.classIndex_injective {E : Type u_1} {R : Type u_2} {C : Type u_3} [Fintype E] [LinearOrder E] (rowOf : E → R) (colOf : E → C) {a r : ℕ} (ρ : R → Fin a → Fin r) (κ : C → Fin a → Fin r) {e e' : E} (hlabel : pairLabel rowOf colOf ρ κ e = pairLabel rowOf colOf ρ κ e') (hindex : classIndex rowOf colOf ρ κ e = classIndex rowOf colOf ρ κ e') :
e = e'

Distinct edges in the same class have distinct numbers.

theorem Cslib.PacketPacking.classIndex_lt_maxLoad {E : Type u_1} {R : Type u_2} {C : Type u_3} [Fintype E] [LinearOrder E] (rowOf : E → R) (colOf : E → C) {a r : ℕ} (ρ : R → Fin a → Fin r) (κ : C → Fin a → Fin r) (e : E) :
classIndex rowOf colOf ρ κ e < maxLoad rowOf colOf ρ κ

An edge is numbered below the largest class size.

theorem Cslib.PacketPacking.maxLoad_le_numBlocks_mul {E : Type u_1} {R : Type u_2} {C : Type u_3} [Fintype E] [LinearOrder E] (rowOf : E → R) (colOf : E → C) {a r : ℕ} (ρ : R → Fin a → Fin r) (κ : C → Fin a → Fin r) :
maxLoad rowOf colOf ρ κ ≤ numBlocks rowOf colOf ρ κ * 2 ^ a

The blocks hold the largest class.

theorem Cslib.PacketPacking.numBlocks_mul_le {E : Type u_1} {R : Type u_2} {C : Type u_3} [Fintype E] [LinearOrder E] (rowOf : E → R) (colOf : E → C) {a r : ℕ} (ρ : R → Fin a → Fin r) (κ : C → Fin a → Fin r) :
numBlocks rowOf colOf ρ κ * 2 ^ a ≤ maxLoad rowOf colOf ρ κ + 2 ^ a

Rounding up to whole blocks adds fewer than 2 ^ a slots.

theorem Cslib.PacketPacking.maxLoad_mul_le {E : Type u_1} {R : Type u_2} {C : Type u_3} [Fintype E] [LinearOrder E] (rowOf : E → R) (colOf : E → C) {a r : ℕ} (ρ : R → Fin a → Fin r) (κ : C → Fin a → Fin r) {B : ℕ} (hocc : ∀ (γ : (Fin a → Fin r) × (Fin a → Fin r)), BalancedSchedules.occupancy (pairLabel rowOf colOf ρ κ) γ * r ^ (2 * a) ≤ B) :
maxLoad rowOf colOf ρ κ * r ^ (2 * a) ≤ B

A bound B on the class sizes, in the form X_γ D ≤ B, bounds the largest class.

The packing for given labels #

def Cslib.PacketPacking.slotBits {E : Type u_1} {R : Type u_2} {C : Type u_3} [Fintype E] [LinearOrder E] (rowOf : E → R) (colOf : E → C) {a r : ℕ} (ρ : R → Fin a → Fin r) (κ : C → Fin a → Fin r) (e : E) (i : Fin a) :

The digits of the slot of an edge. Where its row and column symbols differ, digit i is 1 when the row symbol is the larger; where they agree, it is digit i of the number of the edge in its class.

def Cslib.PacketPacking.packetData {E : Type u_1} {R : Type u_2} {C : Type u_3} [Fintype E] [LinearOrder E] (rowOf : E → R) (colOf : E → C) {a r : ℕ} (ρ : R → Fin a → Fin r) (κ : C → Fin a → Fin r) (e : E) :
ℕ × (Fin a → Fin r × Fin r)

The packet data of an edge: its block, and in each coordinate its sorted pair of symbols, swapped when digit i of its number in its class is 1. This determines the unordered pairs of symbols and, where they differ, digit i of the number.

def Cslib.PacketPacking.packetEquiv (h a r : ℕ) :
Fin h × (Fin a → Fin r × Fin r) ≃ Fin (h * (r * r) ^ a)

The packets: blocks, together with words of pairs of symbols, numbered in Fin.

theorem Cslib.PacketPacking.packetData_fst_lt {E : Type u_1} {R : Type u_2} {C : Type u_3} [Fintype E] [LinearOrder E] (rowOf : E → R) (colOf : E → C) {a r : ℕ} (ρ : R → Fin a → Fin r) (κ : C → Fin a → Fin r) (e : E) :
(packetData rowOf colOf ρ κ e).1 < numBlocks rowOf colOf ρ κ

The block of an edge is below the number of blocks.

def Cslib.PacketPacking.Packing.ofLabels {E : Type u_1} {R : Type u_2} {C : Type u_3} [Fintype E] [LinearOrder E] (rowOf : E → R) (colOf : E → C) {a r : ℕ} (ρ : R → Fin a → Fin r) (κ : C → Fin a → Fin r) :
Packing rowOf colOf a r

The packing for given labels.

theorem Cslib.PacketPacking.Packing.numPackets_ofLabels_mul_le {E : Type u_1} {R : Type u_2} {C : Type u_3} [Fintype E] [LinearOrder E] (rowOf : E → R) (colOf : E → C) {a r : ℕ} (ρ : R → Fin a → Fin r) (κ : C → Fin a → Fin r) (hocc : ∀ (γ : (Fin a → Fin r) × (Fin a → Fin r)), BalancedSchedules.occupancy (pairLabel rowOf colOf ρ κ) γ * r ^ (2 * a) ≤ 2 * Fintype.card E) (hM : 2 ^ a * r ^ (2 * a) ≤ Fintype.card E) :
(ofLabels rowOf colOf ρ κ).numPackets * 2 ^ a ≤ 3 * Fintype.card E

Lemma D.3 (1) from class sizes. If every class has at most 2M / D edges and L D ≤ M, then there are at most 3M / L packets.

theorem Cslib.PacketPacking.Packing.row_ports_ofLabels_le {E : Type u_1} {R : Type u_2} {C : Type u_3} [Fintype E] [LinearOrder E] (rowOf : E → R) (colOf : E → C) {a r : ℕ} (ρ : R → Fin a → Fin r) (κ : C → Fin a → Fin r) (hocc : ∀ (γ : (Fin a → Fin r) × (Fin a → Fin r)), BalancedSchedules.occupancy (pairLabel rowOf colOf ρ κ) γ * r ^ (2 * a) ≤ 2 * Fintype.card E) (i : Fin a) (σ : Fin r) :
r * {e : E | (ofLabels rowOf colOf ρ κ).rowLabel (rowOf e) i = σ}.card ≤ 2 * Fintype.card E

From a bound on the class sizes, each symbol in each coordinate labels the row ends of at most 2M / r edges.

theorem Cslib.PacketPacking.Packing.col_ports_ofLabels_le {E : Type u_1} {R : Type u_2} {C : Type u_3} [Fintype E] [LinearOrder E] (rowOf : E → R) (colOf : E → C) {a r : ℕ} (ρ : R → Fin a → Fin r) (κ : C → Fin a → Fin r) (hocc : ∀ (γ : (Fin a → Fin r) × (Fin a → Fin r)), BalancedSchedules.occupancy (pairLabel rowOf colOf ρ κ) γ * r ^ (2 * a) ≤ 2 * Fintype.card E) (i : Fin a) (σ : Fin r) :
r * {e : E | (ofLabels rowOf colOf ρ κ).colLabel (colOf e) i = σ}.card ≤ 2 * Fintype.card E

From a bound on the class sizes, each symbol in each coordinate labels the column ends of at most 2M / r edges.

Labels by conditional expectations #

The candidate labels in radix order: the word numbered j < r ^ a has as its digit i the digit i of j in base r, least significant first (finFunctionFinEquiv). A machine streams them by counting j.

theorem Cslib.PacketPacking.mem_labelCandidates {a r : ℕ} (word : Fin a → Fin r) :

Every label is a candidate.

def Cslib.PacketPacking.partialLabels {E : Type u_1} {R : Type u_2} {C : Type u_3} [Fintype E] [DecidableEq R] [FinEnum R] [DecidableEq C] [FinEnum C] (rowOf : E → R) (colOf : E → C) (a r : ℕ) :
(R → Option (Fin a → Fin r)) × (C → Option (Fin a → Fin r))

The partial labels after the conditional-expectation pass: every row vertex, then every column vertex, receives the first candidate label minimizing the conditional expectation of the collision potential of the pairs of labels, partialIncidencePotential. (In the convention of Cslib.BalancedSchedules, rows are the variables and columns the factors.)

def Cslib.PacketPacking.rowLabels {E : Type u_1} {R : Type u_2} {C : Type u_3} [Fintype E] [DecidableEq R] [FinEnum R] [DecidableEq C] [FinEnum C] (rowOf : E → R) (colOf : E → C) (a r : ℕ) [NeZero r] :
R → Fin a → Fin r

The row labels chosen by conditional expectations.

def Cslib.PacketPacking.colLabels {E : Type u_1} {R : Type u_2} {C : Type u_3} [Fintype E] [DecidableEq R] [FinEnum R] [DecidableEq C] [FinEnum C] (rowOf : E → R) (colOf : E → C) (a r : ℕ) [NeZero r] :
C → Fin a → Fin r

The column labels chosen by conditional expectations.

theorem Cslib.PacketPacking.potential_labels_le {E : Type u_1} {R : Type u_2} {C : Type u_3} [Fintype E] [DecidableEq R] [FinEnum R] [DecidableEq C] [FinEnum C] (rowOf : E → R) (colOf : E → C) (a r : ℕ) [NeZero r] {Δ : ℕ} (hrow : ∀ (v : R), {e : E | rowOf e = v}.card ≤ Δ) (hcol : ∀ (w : C), {e : E | colOf e = w}.card ≤ Δ) :
BalancedSchedules.potential (pairLabel rowOf colOf (rowLabels rowOf colOf a r) (colLabels rowOf colOf a r)) ≤ 2 * ↑(Fintype.card E) * ↑Δ

The collision potential of the chosen labels. If every vertex has degree at most Δ, the potential Φ = ∑_γ (X_γ - M / D)² of the pairs of labels is at most 2 M Δ, a bound on its average for independent uniform labels.

theorem Cslib.PacketPacking.occupancy_labels_mul_le {E : Type u_1} {R : Type u_2} {C : Type u_3} [Fintype E] [DecidableEq R] [FinEnum R] [DecidableEq C] [FinEnum C] (rowOf : E → R) (colOf : E → C) (a r : ℕ) [NeZero r] {Δ : ℕ} (hrow : ∀ (v : R), {e : E | rowOf e = v}.card ≤ Δ) (hcol : ∀ (w : C), {e : E | colOf e = w}.card ≤ Δ) (hM : 2 * Δ * (r ^ (2 * a)) ^ 2 ≤ Fintype.card E) (γ : (Fin a → Fin r) × (Fin a → Fin r)) :
BalancedSchedules.occupancy (pairLabel rowOf colOf (rowLabels rowOf colOf a r) (colLabels rowOf colOf a r)) γ * r ^ (2 * a) ≤ 2 * Fintype.card E

Class sizes of the chosen labels. Under the size hypothesis 2 Δ D² ≤ M of (D.6), where D = r ^ (2a) is the number of pairs of labels, every class has at most 2M / D edges.

Lemma D.3 #

def Cslib.PacketPacking.packing {E : Type u_1} {R : Type u_2} {C : Type u_3} [Fintype E] [LinearOrder E] [DecidableEq R] [FinEnum R] [DecidableEq C] [FinEnum C] (rowOf : E → R) (colOf : E → C) (a r : ℕ) [NeZero r] :
Packing rowOf colOf a r

The packing of Lemma D.3: the packing for the labels chosen by conditional expectations.

theorem Cslib.PacketPacking.numPackets_packing_mul_le {E : Type u_1} {R : Type u_2} {C : Type u_3} [Fintype E] [LinearOrder E] [DecidableEq R] [FinEnum R] [DecidableEq C] [FinEnum C] (rowOf : E → R) (colOf : E → C) (a r : ℕ) [NeZero r] {Δ : ℕ} (hrow : ∀ (v : R), {e : E | rowOf e = v}.card ≤ Δ) (hcol : ∀ (w : C), {e : E | colOf e = w}.card ≤ Δ) (hM : 2 * Δ * (r ^ (2 * a)) ^ 2 ≤ Fintype.card E) (hL : 2 ^ a * r ^ (2 * a) ≤ Fintype.card E) :
(packing rowOf colOf a r).numPackets * 2 ^ a ≤ 3 * Fintype.card E

Lemma D.3 (1). Under (D.6), 2 Δ D² ≤ M and L D ≤ M, there are at most 3M / L packets.

theorem Cslib.PacketPacking.row_ports_packing_le {E : Type u_1} {R : Type u_2} {C : Type u_3} [Fintype E] [LinearOrder E] [DecidableEq R] [FinEnum R] [DecidableEq C] [FinEnum C] (rowOf : E → R) (colOf : E → C) (a r : ℕ) [NeZero r] {Δ : ℕ} (hrow : ∀ (v : R), {e : E | rowOf e = v}.card ≤ Δ) (hcol : ∀ (w : C), {e : E | colOf e = w}.card ≤ Δ) (hM : 2 * Δ * (r ^ (2 * a)) ^ 2 ≤ Fintype.card E) (i : Fin a) (σ : Fin r) :
r * {e : E | (packing rowOf colOf a r).rowLabel (rowOf e) i = σ}.card ≤ 2 * Fintype.card E

Lemma D.3 (3), rows. Under (D.6), in every coordinate the row vertices with a given symbol have at most 2M / r ports.

theorem Cslib.PacketPacking.col_ports_packing_le {E : Type u_1} {R : Type u_2} {C : Type u_3} [Fintype E] [LinearOrder E] [DecidableEq R] [FinEnum R] [DecidableEq C] [FinEnum C] (rowOf : E → R) (colOf : E → C) (a r : ℕ) [NeZero r] {Δ : ℕ} (hrow : ∀ (v : R), {e : E | rowOf e = v}.card ≤ Δ) (hcol : ∀ (w : C), {e : E | colOf e = w}.card ≤ Δ) (hM : 2 * Δ * (r ^ (2 * a)) ^ 2 ≤ Fintype.card E) (i : Fin a) (σ : Fin r) :
r * {e : E | (packing rowOf colOf a r).colLabel (colOf e) i = σ}.card ≤ 2 * Fintype.card E

Lemma D.3 (3), columns. Under (D.6), in every coordinate the column vertices with a given symbol have at most 2M / r ports.

theorem Cslib.PacketPacking.exists_packing {E : Type u_1} {R : Type u_2} {C : Type u_3} [Fintype E] [DecidableEq R] [DecidableEq C] [Finite R] [Finite C] (rowOf : E → R) (colOf : E → C) (a r : ℕ) [NeZero r] {Δ : ℕ} (hrow : ∀ (v : R), {e : E | rowOf e = v}.card ≤ Δ) (hcol : ∀ (w : C), {e : E | colOf e = w}.card ≤ Δ) (hM : 2 * Δ * (r ^ (2 * a)) ^ 2 ≤ Fintype.card E) (hL : 2 ^ a * r ^ (2 * a) ≤ Fintype.card E) :
∃ (P : Packing rowOf colOf a r), P.numPackets * 2 ^ a ≤ 3 * Fintype.card E ∧ (∀ (i : Fin a) (σ : Fin r), r * {e : E | P.rowLabel (rowOf e) i = σ}.card ≤ 3 * Fintype.card E) ∧ ∀ (i : Fin a) (σ : Fin r), r * {e : E | P.colLabel (colOf e) i = σ}.card ≤ 3 * Fintype.card E

Lemma D.3 (packing into packets). Let a bipartite multigraph have M edges, joining row vertices to column vertices, and maximum degree at most Δ, and let D = r ^ (2a) and L = 2 ^ a satisfy (D.6): 2 Δ D² ≤ M and L D ≤ M. Then there is a packing of its edges into at most 3M / L packets of L slots, oriented as in Packing, such that in every coordinate the vertices with a given symbol have at most 3M / r ports on each side. packing constructs it.