Documentation

CslibFrontier.Computability.Circuit.Frontier.Layouts.Matching

Ordering a cubic multigraph by matched-edge pair insertion #

In CslibFrontier.Computability.Circuit.Frontier.Layouts.Median, every vertex of a loopless cubic multigraph is placed at the median of the three scores of its incident edges, yielding a cut bound of #(vertices straddling t) at each threshold t.

Keeping a matching M : Set E (a set of pairwise vertex-disjoint edges) unsubdivided yields a threshold cost bound Multigraph.matchingCost that is pointwise at most the naive straddling count (Multigraph.matchingCost_le_edgeStraddles). Equality holds for the empty matching (Multigraph.matchingCost_empty), while concrete examples exhibit strict savings (e.g., exists_twoVertexCost_lt_starCost_add and the K₄ test comparing the two threshold cost bounds rather than full layout widths). Each unpaired vertex v keeps its median3 key, while each matched edge e ∈ M with endpoints u = G.src e and v = G.tgt e and outer incident pairs G.incidenceSet u \ {e} = {a, b} and G.incidenceSet v \ {e} = {c, d} places u and v at the single pair keys pairKey (score a) (score b) (score c) (score d) and pairKey (score c) (score d) (score a) (score b), where pairKey a b c d := min (max a b) (max (min a b) (min c d)).

This single pair of real keys simultaneously attains the optimal two-vertex cut energy at every threshold t (twoVertexEnergy_pairKey):

Decomposing twoVertexCost into the two binary events Multigraph.PairStraddlesAny (the four outer edges straddle t) and Multigraph.PairStraddlesBoth (both outer pairs straddle t) avoids any ordering choice on incident edges, handles parallel edges without requiring a simple graph, and lets every cut of a threshold layout be bounded pointwise by Multigraph.matchingCost. This weak pointwise bound is always at most the naive straddling count (Multigraph.matchingCost_le_edgeStraddles), with equality possible (e.g., M = ∅, Multigraph.matchingCost_empty) and strict improvement in concrete examples where a matched pair has a (1, 0) outer split whose shared edge lands on the minority side (exists_twoVertexCost_lt_starCost_add).

This adapts the deterministic pair-insertion key (pairKey / pairColor) from the Apache 2.0 companion repository SamuelSchlesinger/the-frontier-method (modules Frontier.Layouts.Pair and Frontier.Layouts.MatchingLayout) to the loopless cubic Multigraph setting used in this library (allowing parallel edges). It is also the combinatorial layout mechanism underlying the 4.6155n matched-edge branch-and-bound bound (rrwilliams0/circuit-lb-4.6155n).

Main definitions #

Main results #

Boolean energy and canonical pair keys #

Optimal Boolean color for the first endpoint of a matched pair with outer colors (a, b) at the first endpoint and (c, d) at the second. Swap (a, b) and (c, d) for the other endpoint.

def Cslib.Circuits.Frontier.pairKey {α : Type u_1} [LinearOrder α] (a b c d : α) :
α

Canonical real threshold key for the first endpoint of a matched pair with outer edge scores a, b at that endpoint and c, d at its mate. Swapping a ↔ b or c ↔ d leaves it unchanged.

theorem Cslib.Circuits.Frontier.pairKey_comm_left {α : Type u_1} [LinearOrder α] (a b c d : α) :
pairKey a b c d = pairKey b a c d
theorem Cslib.Circuits.Frontier.pairKey_comm_right {α : Type u_1} [LinearOrder α] (a b c d : α) :
pairKey a b c d = pairKey a b d c
theorem Cslib.Circuits.Frontier.pairKey_mem {α : Type u_1} [LinearOrder α] (a b c d : α) :
pairKey a b c d = a ∨ pairKey a b c d = b ∨ pairKey a b c d = c ∨ pairKey a b c d = d

A pair key is always equal to one of the four outer edge scores.

Disagreement count at a single cubic vertex with three incident edge colors a, b, c and vertex color x.

Minimum cut cost of a single cubic vertex: 0 when all three incident edges share a color, 1 when they straddle.

Total disagreement count of a matched edge {u, v} with outer edge colors a, b at u and c, d at v, when u receives color x and v receives color y.

Minimum disagreement cost of a matched edge pair over all choices of (x, y : Bool): 0 when all four outer colors match, 2 when both pairs disagree (a ≠ b and c ≠ d), and 1 when the four outer colors are not all equal but at least one pair matches (a = b or c = d).

theorem Cslib.Circuits.Frontier.decide_median3_lt {α : Type u_1} [LinearOrder α] (a b c t : α) :
decide (median3 a b c < t) = (decide (a < t) && decide (b < t) || decide (a < t) && decide (c < t) || decide (b < t) && decide (c < t))

median3 thresholds to majority vote at every threshold t.

theorem Cslib.Circuits.Frontier.starEnergy_median3 {α : Type u_1} [LinearOrder α] (a b c t : α) :
starEnergy (decide (a < t)) (decide (b < t)) (decide (c < t)) (decide (median3 a b c < t)) = starCost (decide (a < t)) (decide (b < t)) (decide (c < t))

The median of three incident edge scores attains starCost at every threshold t.

theorem Cslib.Circuits.Frontier.decide_pairKey_lt {α : Type u_1} [LinearOrder α] (a b c d t : α) :
decide (pairKey a b c d < t) = pairColor (decide (a < t)) (decide (b < t)) (decide (c < t)) (decide (d < t))

Thresholding pairKey yields pairColor simultaneously at every threshold t.

The pair coloring attains twoVertexCost and is minimal over all (x, y : Bool).

twoVertexCost is the minimum of twoVertexEnergy over all vertex colorings (x, y).

theorem Cslib.Circuits.Frontier.twoVertexEnergy_pairKey {α : Type u_1} [LinearOrder α] (a b c d t : α) :
twoVertexEnergy (decide (a < t)) (decide (b < t)) (decide (c < t)) (decide (d < t)) (decide (pairKey a b c d < t)) (decide (pairKey c d a b < t)) = twoVertexCost (decide (a < t)) (decide (b < t)) (decide (c < t)) (decide (d < t))

Simultaneous optimality. One pair of real keys attains the optimal two-vertex cut cost at every threshold t at once.

For every choice of shared-edge color m, the pair cost is at most the sum of the two endpoint star costs.

On a (1, 0) outer split whose shared edge receives the minority color (m = true), keeping the matched edge unsubdivided strictly saves 1 over naive median-of-3 edge scores (1 < 2).

Matchings in a multigraph #

def Cslib.Circuits.Frontier.Multigraph.IsMatching {V : Type u_1} {E : Type u_2} (G : Multigraph V E) (M : Set E) :

A set of edges M is a matching when its edges are pairwise vertex-disjoint: no vertex is incident to two distinct edges in M.

def Cslib.Circuits.Frontier.Multigraph.matchedVertices {V : Type u_1} {E : Type u_2} (G : Multigraph V E) (M : Set E) :
Set V

The set of vertices incident to some edge in M.

def Cslib.Circuits.Frontier.Multigraph.PairStraddlesAny {V : Type u_1} {E : Type u_2} (G : Multigraph V E) {α : Type u_3} [LinearOrder α] (score : E → α) (t : α) (e : E) :

PairStraddlesAny holds at a matched edge e when the four outer edges at G.src e and G.tgt e (excluding e) straddle t: one scores below t and one at least t.

def Cslib.Circuits.Frontier.Multigraph.PairStraddlesBoth {V : Type u_1} {E : Type u_2} (G : Multigraph V E) {α : Type u_3} [LinearOrder α] (score : E → α) (t : α) (e : E) :

PairStraddlesBoth holds at a matched edge e when both outer pairs G.incidenceSet (G.src e) \ {e} and G.incidenceSet (G.tgt e) \ {e} straddle t.

noncomputable def Cslib.Circuits.Frontier.Multigraph.matchingCost {V : Type u_1} {E : Type u_2} (G : Multigraph V E) {α : Type u_3} [LinearOrder α] (M : Set E) (score : E → α) (t : α) :

The threshold cost of a matching M at threshold t: each unpaired straddling vertex pays 1, each matched edge whose outer edges straddle t pays 1, and each matched edge whose two outer pairs both straddle t pays an additional 1 (matching twoVertexCost).

theorem Cslib.Circuits.Frontier.Multigraph.matchingCost_empty {V : Type u_1} {E : Type u_2} (G : Multigraph V E) {α : Type u_3} [LinearOrder α] (score : E → α) (t : α) :
G.matchingCost ∅ score t = {v : V | G.EdgeStraddles score t v}.ncard
theorem Cslib.Circuits.Frontier.Multigraph.pairStraddlesAny_congr {V : Type u_1} {E : Type u_2} (G : Multigraph V E) {α : Type u_3} [LinearOrder α] {score score' : E → α} {t : α} {e : E} (h : ∀ f ∈ G.incidenceSet (G.src e) \ {e} ∪ G.incidenceSet (G.tgt e) \ {e}, score f = score' f) :
G.PairStraddlesAny score t e ↔ G.PairStraddlesAny score' t e
theorem Cslib.Circuits.Frontier.Multigraph.pairStraddlesBoth_congr {V : Type u_1} {E : Type u_2} (G : Multigraph V E) {α : Type u_3} [LinearOrder α] {score score' : E → α} {t : α} {e : E} (h : ∀ f ∈ G.incidenceSet (G.src e) \ {e} ∪ G.incidenceSet (G.tgt e) \ {e}, score f = score' f) :
G.PairStraddlesBoth score t e ↔ G.PairStraddlesBoth score' t e
noncomputable def Cslib.Circuits.Frontier.Multigraph.mate {V : Type u_1} {E : Type u_2} (G : Multigraph V E) (M : Set E) (v : V) :
V

Mate of a vertex v under matching M (returning v when v is unmatched).

noncomputable def Cslib.Circuits.Frontier.Multigraph.matchingKey {V : Type u_1} {E : Type u_2} {α : Type u_3} [LinearOrder α] [Inhabited α] (G : Multigraph V E) (M : Set E) (score : E → α) (v : V) :
α

Canonical threshold key for a vertex of a cubic multigraph under edge scores score and matching M: unpaired vertices use median3 of their three incident edge scores; endpoints of e ∈ M use pairKey of their outer pair and their mate's outer pair.

theorem Cslib.Circuits.Frontier.Multigraph.matchingKey_matched {V : Type u_1} {E : Type u_2} {G : Multigraph V E} [Finite E] {α : Type u_3} [LinearOrder α] [Inhabited α] {M : Set E} (hM : G.IsMatching M) (hloop : G.Loopless) (h3 : ∀ (v : V), (G.incidenceSet v).ncard = 3) (score : E → α) {e a b c d : E} (he : e ∈ M) (hsrc : G.incidenceSet (G.src e) \ {e} = {a, b}) (htgt : G.incidenceSet (G.tgt e) \ {e} = {c, d}) :
G.matchingKey M score (G.src e) = pairKey (score a) (score b) (score c) (score d) ∧ G.matchingKey M score (G.tgt e) = pairKey (score c) (score d) (score a) (score b)

At any matched edge e ∈ M with outer incident edge pairs {a, b} at G.src e and {c, d} at G.tgt e, matchingKey evaluates to pairKey of the four outer edge scores.

theorem Cslib.Circuits.Frontier.Multigraph.matchingCost_le_edgeStraddles {V : Type u_1} {E : Type u_2} {G : Multigraph V E} [Finite V] [Finite E] {α : Type u_3} [LinearOrder α] (hloop : G.Loopless) (h3 : ∀ (v : V), (G.incidenceSet v).ncard = 3) {M : Set E} (hM : G.IsMatching M) (score : E → α) (t : α) :
G.matchingCost M score t ≤ {v : V | G.EdgeStraddles score t v}.ncard

Comparison with median edge scores. For every matching M in a loopless cubic multigraph, matchingCost M score t is at most the total number of vertices straddling t. Equality holds for M = ∅ (matchingCost_empty).

theorem Cslib.Circuits.Frontier.Multigraph.ncard_edgeCut_threshold_add_slack_le_matchingCost {V : Type u_1} {E : Type u_2} {G : Multigraph V E} [Finite V] [Finite E] {α : Type u_3} [LinearOrder α] [Inhabited α] (hloop : G.Loopless) (h3 : ∀ (v : V), (G.incidenceSet v).ncard = 3) {M : Set E} (hM : G.IsMatching M) (score : E → α) (t : α) :
have P₀ := {v : V | G.matchingKey M score v < t}; (G.edgeCut P₀).ncard + 2 * {f : E | f ∉ M ∧ G.src f ∈ P₀ ∧ G.tgt f ∈ P₀ ∧ t ≤ score f}.ncard ≤ G.matchingCost M score t

Refined threshold cut bound. For every threshold t, the cut of P₀ = {v | matchingKey G M score v < t} in a loopless cubic multigraph plus twice the number of unmatched edges inside P₀ with t ≤ score f is at most G.matchingCost M score t.

theorem Cslib.Circuits.Frontier.Multigraph.ncard_edgeCut_threshold_le_matchingCost {V : Type u_1} {E : Type u_2} {G : Multigraph V E} [Finite V] [Finite E] {α : Type u_3} [LinearOrder α] [Inhabited α] (hloop : G.Loopless) (h3 : ∀ (v : V), (G.incidenceSet v).ncard = 3) {M : Set E} (hM : G.IsMatching M) (score : E → α) (t : α) :
(G.edgeCut {v : V | G.matchingKey M score v < t}).ncard ≤ G.matchingCost M score t

Threshold cut bound. For every threshold t, the cut of {v | matchingKey G M score v < t} in a loopless cubic multigraph (parallel edges allowed) is at most G.matchingCost M score t.

Prefix cuts and grid layout bound #

theorem Cslib.Circuits.Frontier.Multigraph.ncard_matchingKey_pred_le {V : Type u_1} {E : Type u_2} {G : Multigraph V E} [Finite V] [Finite E] {α : Type u_3} [LinearOrder α] [Inhabited α] (hloop : G.Loopless) (h3 : ∀ (v : V), (G.incidenceSet v).ncard = 3) {M : Set E} (hM : G.IsMatching M) (score : E → α) (p : α → Prop) :
{v : V | p (G.matchingKey M score v)}.ncard ≤ 4 * {e : E | p (score e)}.ncard

Every vertex whose matchingKey lies in a predicate p is either an endpoint or the M-mate of an endpoint of some edge whose score satisfies p. Thus each such edge produces at most 4 vertices.

theorem Cslib.Circuits.Frontier.Multigraph.le_of_matchingKey_separated_grid {V : Type u_1} {E : Type u_2} {G : Multigraph V E} [Finite V] [Finite E] (hloop : G.Loopless) (h3 : ∀ (v : V), (G.incidenceSet v).ncard = 3) {M : Set E} (hM : G.IsMatching M) (score : E → ℝ) {P : Set V} {m : ℝ} (hP : ∀ v ∈ P, G.matchingKey M score v ≤ m) (hPc : ∀ v ∉ P, m ≤ G.matchingKey M score v) {f : ℝ} (hf_cut : f ≤ ↑(G.edgeCut P).ncard) {a δ : ℝ} (hδ : 0 < δ) {K : ℕ} {B : ℝ} (cost : ℝ → ℝ) (hf_step : ∀ (t : ℝ), {v : V | G.matchingKey M score v < t} ⊆ P → f ≤ cost t + 3 * ↑(P \ {v : V | G.matchingKey M score v < t}).ncard) (low : 12 * ↑{e : E | score e < a}.ncard ≤ B) (high : 12 * ↑{e : E | a + ↑K * δ ≤ score e}.ncard ≤ B) (mid : ∀ i < K, cost (a + ↑i * δ) + 12 * ↑{e : E | a + ↑i * δ ≤ score e ∧ score e < a + (↑i + 1) * δ}.ncard ≤ B) :
f ≤ B

Threshold-grid reduction for matchingKey-separated sets. Given any quantity f : ℝ bounded by ((G.edgeCut P).ncard : ℝ) for a set P separated by m under matchingKey, f ≤ B whenever the lower tail, upper tail, and grid windows are bounded by B.

theorem Cslib.Circuits.Frontier.Multigraph.ncard_edgeCut_le_matchingCost_add {V : Type u_1} {E : Type u_2} {G : Multigraph V E} [Finite V] [Finite E] (hloop : G.Loopless) (h3 : ∀ (v : V), (G.incidenceSet v).ncard = 3) {M : Set E} (hM : G.IsMatching M) (score : E → ℝ) {P : Set V} {m : ℝ} (hP : ∀ v ∈ P, G.matchingKey M score v ≤ m) (hPc : ∀ v ∉ P, m ≤ G.matchingKey M score v) {a δ : ℝ} (hδ : 0 < δ) {K : ℕ} {B : ℝ} (low : 12 * ↑{e : E | score e < a}.ncard ≤ B) (high : 12 * ↑{e : E | a + ↑K * δ ≤ score e}.ncard ≤ B) (mid : ∀ i < K, ↑(G.matchingCost M score (a + ↑i * δ)) + 12 * ↑{e : E | a + ↑i * δ ≤ score e ∧ score e < a + (↑i + 1) * δ}.ncard ≤ B) :
↑(G.edgeCut P).ncard ≤ B

Cut bound for a threshold prefix. For any set P separated by a threshold m of matchingKey, its cut size is bounded by a lower tail, upper tail, or the matching cost at the grid threshold below m plus 12 times the window edge count.

theorem Cslib.Circuits.Frontier.Multigraph.exists_width_le_of_matching_edgeScore {V : Type u_1} {E : Type u_2} {G : Multigraph V E} [Finite V] [Finite E] (hloop : G.Loopless) (h3 : ∀ (v : V), (G.incidenceSet v).ncard = 3) {M : Set E} (hM : G.IsMatching M) (score : E → ℝ) {a δ : ℝ} (hδ : 0 < δ) (K : ℕ) {B : ℝ} (low : 12 * ↑{e : E | score e < a}.ncard ≤ B) (high : 12 * ↑{e : E | a + ↑K * δ ≤ score e}.ncard ≤ B) (mid : ∀ i < K, ↑(G.matchingCost M score (a + ↑i * δ)) + 12 * ↑{e : E | a + ↑i * δ ≤ score e ∧ score e < a + (↑i + 1) * δ}.ncard ≤ B) :
∃ (π : Layout V), ↑(G.width π) ≤ B

The matched-edge pair-insertion layout. Given a loopless cubic multigraph (parallel edges allowed), any matching M, any edge scores score : E → ℝ, and a grid a, a + δ, ..., a + K δ, sorting vertices by matchingKey gives a layout whose width is bounded by the worst tail bound 12 * tail and window bound matchingCost + 12 * window.