Documentation

CslibFrontier.Computability.PolyTime.GreedySlotScore

Greedy slot-score arithmetic and streaming candidate selection #

In §4.4, Lemma 4.5 of [OAI26k] (printed pp. 30–32), schedules a_v, d_f ∈ [r]^Q are chosen one slot at a time over K = r ^ Q candidates per slot. Executing bestVariableLabel and bestFactorLabel on a native machine clears denominators to bounded integers and streams 0 .. r ^ Q - 1 in polynomial workspace.

Encoded ComputableInPolyTime, NativeCertificate, ComputableInO, and ComputableInPolySpace results in Cslib.BalancedSchedules govern the concrete list/integer algorithms (decodeLabelWord, clearedJointScore, updateSlotSchedules, readSlotSchedule, streamBestSlotLabel, streamBestSlotCertificate), while labelWordEquiv, wordToSchedule, scheduleToWord, candidateScheduleList, edgesOfFin, partialScheduleListOfFin, and candidateSlotScore are unencoded typed specification bridges. Total fallback conventions: wordToSchedule clamps digits ≥ r and missing positions to 0; streamBestSlotLabel returns List.replicate Q 0 when r ^ Q = 0; clearedPartialCollision, updateSlotSchedules, and readSlotSchedule use total List.getD / List.set defaults on out-of-bounds indices; scoreDenom replaces zero normalizers numEdges * C or Q * n by 1, and is 0 when r = 0; and clearedIncidencePotential and clearedGroupPotential use truncated subtraction in ℕ. They and clearedJointScore are exact cleared numerators for 1 ≤ r and K = r ^ Q on the typed bridge lists edgesOfFin and partialScheduleListOfFin, where no subtraction truncates.

Main definitions #

Main results #

References #

Section 1: Radix-r candidate word decoder and bijections #

Binary bit-length bound for r ^ Q: at most Q * |encNat r| + 1.

Decode binary candidate index j into the length-Q radix-r word of digits via Cslib.Radix.digit ([OAI26k], Lemma 4.5, p. 31).

theorem Cslib.BalancedSchedules.mem_decodeLabelWord_lt {r Q j x : ℕ} (hr : 1 ≤ r) (hx : x ∈ decodeLabelWord r Q j) :
x < r

Every digit of decodeLabelWord r Q j is strictly less than r whenever 1 ≤ r.

theorem Cslib.BalancedSchedules.mem_decodeLabelWord_lt_max {r Q j x : ℕ} (hj : j < r ^ Q) (hx : x ∈ decodeLabelWord r Q j) :
x < max r 1

For any j < r ^ Q (even when r = 0, Q = 0), every digit of decodeLabelWord r Q j is < max r 1.

theorem Cslib.BalancedSchedules.decodeLabelWord_ofDigits {r : ℕ} (hr : 1 ≤ r) {w : List ℕ} (hw : ∀ x ∈ w, x < r) :

Decoding Nat.ofDigits r w for any bounded word w recovers w.

Nat.ofDigits r on decodeLabelWord r Q j recovers j for all j < r ^ Q (including Q = 0 and r = 1).

def Cslib.BalancedSchedules.labelWordEquiv {r : ℕ} (hr : 1 ≤ r) (Q : ℕ) :
Fin (r ^ Q) ≃ { w : List ℕ // w.length = Q ∧ ∀ x ∈ w, x < r }

Exact bijection between binary indices Fin (r ^ Q) and length-Q words over {0, …, r - 1} (including Q = 0 and r = 1).

def Cslib.BalancedSchedules.wordToSchedule {r : ℕ} (hr : 1 ≤ r) (Q : ℕ) (w : List ℕ) (t : Fin Q) :
Fin r

Convert a concrete digit list w : List ℕ into a typed schedule Fin Q → Fin r, clamping out-of-range digits to 0.

Convert a typed schedule a : Fin Q → Fin r into its length-Q digit list.

theorem Cslib.BalancedSchedules.mem_scheduleToWord_lt {r Q : ℕ} (a : Fin Q → Fin r) {x : ℕ} (hx : x ∈ scheduleToWord a) :
x < r
@[simp]
theorem Cslib.BalancedSchedules.wordToSchedule_scheduleToWord {r : ℕ} (hr : 1 ≤ r) {Q : ℕ} (a : Fin Q → Fin r) :
theorem Cslib.BalancedSchedules.scheduleToWord_inj {r : ℕ} (hr : 1 ≤ r) {Q : ℕ} {a b : Fin Q → Fin r} (h : scheduleToWord a = scheduleToWord b) :
a = b
theorem Cslib.BalancedSchedules.scheduleToWord_wordToSchedule {r : ℕ} (hr : 1 ≤ r) {Q : ℕ} {w : List ℕ} (hlen : w.length = Q) (hw : ∀ x ∈ w, x < r) :

wordToSchedule composed with decodeLabelWord agrees identically with the standard bijection finFunctionFinEquiv.symm : Fin (r ^ Q) ≃ (Fin Q → Fin r).

def Cslib.BalancedSchedules.candidateScheduleList {r : ℕ} (hr : 1 ≤ r) (Q : ℕ) :
List (Fin Q → Fin r)

Exhaustive list of candidate schedules Fin Q → Fin r in 0 .. r ^ Q - 1 radix order.

Encoded bit-length bound for any word of length Q with digits < max r 1.

Section 2: Cleared-integer collision scores and exact rational bridge #

def Cslib.BalancedSchedules.clearedPartialCollision {α : Type u_1} [DecidableEq α] (cardL : ℕ) (assigned : List (Option α)) (i j : ℕ) :

Cleared-integer collision count for two indices i, j over a label space of size cardL: returns cardL when i = j or both assigned values agree, 0 when both are assigned and distinct, and 1 when at least one slot is unassigned (1 = cardL * (1 / cardL)).

def Cslib.BalancedSchedules.clearedIncidenceCollisions (K : ℕ) (edges : List (ℕ × ℕ)) (varSched facSched : List (Option (List ℕ))) :

Sum of cleared incidence-pair collisions over edges : List (ℕ × ℕ) ((f, v) pairs), scaled by K ^ 2 = (r ^ Q) ^ 2.

def Cslib.BalancedSchedules.clearedIncidencePotential (K : ℕ) (edges : List (ℕ × ℕ)) (varSched facSched : List (Option (List ℕ))) :

clearedIncidenceCollisions minus edges.length ^ 2, with truncated subtraction in ℕ. For 1 ≤ r and K = r ^ Q, on edgesOfFin and partialScheduleListOfFin lists it is the cleared-integer numerator of partialIncidencePotential over common denominator K ^ 2 (clearedIncidencePotential_eq_mul); otherwise the subtraction can truncate to 0.

Sum of cleared variable-coordinate collisions across t < Q and v, v' < n, scaled by r.

clearedGroupCollisions minus Q * n ^ 2, with truncated subtraction in ℕ. For 1 ≤ r, on partialScheduleListOfFin lists it is the cleared-integer numerator of partialGroupPotential over common denominator r; otherwise the subtraction can truncate to 0.

def Cslib.BalancedSchedules.scoreDenom (numEdges n Q r C : ℕ) :

Common integer denominator clearing normalizedPartialScore across all candidate evaluations without rational GCD reductions ([OAI26k], Lemma 4.5, p. 31). It is positive when 1 ≤ r (scoreDenom_pos) and 0 when r = 0.

def Cslib.BalancedSchedules.clearedJointScore (n Q r C : ℕ) (edges : List (ℕ × ℕ)) (varSched facSched : List (Option (List ℕ))) :

Natural-number numerator of normalizedPartialScore over scoreDenom: exact for 1 ≤ r on edgesOfFin and partialScheduleListOfFin lists (normalizedPartialScore_eq_clearedJointScore_div). It is built from clearedIncidencePotential and clearedGroupPotential, whose subtractions can truncate to 0 otherwise.

theorem Cslib.BalancedSchedules.scoreDenom_pos (numEdges n Q : ℕ) {r : ℕ} (hr : 1 ≤ r) (C : ℕ) :
0 < scoreDenom numEdges n Q r C
def Cslib.BalancedSchedules.edgesOfFin {E m n : ℕ} (edge : Fin E → Fin m × Fin n) :

Concrete incidence list [(f₀, v₀), …] extracted from edge : Fin E → Fin m × Fin n.

@[simp]
theorem Cslib.BalancedSchedules.length_edgesOfFin {E m n : ℕ} (edge : Fin E → Fin m × Fin n) :
def Cslib.BalancedSchedules.partialScheduleListOfFin {N Q r : ℕ} (assigned : Fin N → Option (Fin Q → Fin r)) :

Concrete partial schedule list extracted from Fin N → Option (Fin Q → Fin r).

@[simp]
theorem Cslib.BalancedSchedules.clearedJointScore_le (n Q r C : ℕ) (edges : List (ℕ × ℕ)) (varSched facSched : List (Option (List ℕ))) :
clearedJointScore n Q r C edges varSched facSched ≤ edges.length ^ 2 * (r ^ Q + 1) ^ 2 * (r * (Q * n + 1)) + Q * n ^ 2 * (r + 1) * ((r ^ Q) ^ 2 * (edges.length * C + 1))

Unconditional upper bound on clearedJointScore, independent of (varSched, facSched).

Logarithmic bit-length bound on encNat (clearedJointScore ...) matching Lemma 4.5's O(log(2D) + log(2M) + log(2n) + log(2Q) + log(2 + b + w)) bit bound (p. 31), independent of (varSched, facSched).

theorem Cslib.BalancedSchedules.clearedPartialCollision_eq_mul_partialCollision {N Q r : ℕ} (hr : 1 ≤ r) (assigned : Fin N → Option (Fin Q → Fin r)) (i j : Fin N) :
↑(clearedPartialCollision (r ^ Q) (partialScheduleListOfFin assigned) ↑i ↑j) = ↑(r ^ Q) * partialCollision assigned i j

Exact rational collision identity on whole-word schedules (L = Fin Q → Fin r).

theorem Cslib.BalancedSchedules.clearedIncidencePotential_eq_mul {E m n Q r : ℕ} (hr : 1 ≤ r) (edge : Fin E → Fin m × Fin n) (varLabels : Fin n → Option (Fin Q → Fin r)) (factorLabels : Fin m → Option (Fin Q → Fin r)) :
↑(clearedIncidencePotential (r ^ Q) (edgesOfFin edge) (partialScheduleListOfFin varLabels) (partialScheduleListOfFin factorLabels)) = ↑(r ^ Q) ^ 2 * partialIncidencePotential edge varLabels factorLabels

Exact cleared incidence potential: clearedIncidencePotential is partialIncidencePotential times the common denominator (r ^ Q) ^ 2.

theorem Cslib.BalancedSchedules.normalizedPartialScore_eq_clearedJointScore_div {E m n Q r : ℕ} (hr : 1 ≤ r) (edge : Fin E → Fin m × Fin n) (varLabels : Fin n → Option (Fin Q → Fin r)) (factorLabels : Fin m → Option (Fin Q → Fin r)) (C : ℕ) :
normalizedPartialScore edge varLabels factorLabels C = ↑(clearedJointScore n Q r C (edgesOfFin edge) (partialScheduleListOfFin varLabels) (partialScheduleListOfFin factorLabels)) / ↑(scoreDenom E n Q r C)

Exact cleared-integer score identity: for any 1 ≤ r, normalizedPartialScore equals clearedJointScore / scoreDenom identically (including when E = 0, C = 0, Q = 0, or n = 0).

theorem Cslib.BalancedSchedules.clearedJointScore_lt_iff_normalizedPartialScore_lt {E m n Q r : ℕ} (hr : 1 ≤ r) (edge : Fin E → Fin m × Fin n) (v₁ v₂ : Fin n → Option (Fin Q → Fin r)) (f₁ f₂ : Fin m → Option (Fin Q → Fin r)) (C : ℕ) :

Strict < on clearedJointScore : ℕ is equivalent to < on normalizedPartialScore : ℚ.

theorem Cslib.BalancedSchedules.clearedJointScore_le_iff_normalizedPartialScore_le {E m n Q r : ℕ} (hr : 1 ≤ r) (edge : Fin E → Fin m × Fin n) (v₁ v₂ : Fin n → Option (Fin Q → Fin r)) (f₁ f₂ : Fin m → Option (Fin Q → Fin r)) (C : ℕ) :

Non-strict ≤ on clearedJointScore : ℕ is equivalent to ≤ on normalizedPartialScore : ℚ.

Polynomial-time certificate for clearedJointScore #

Encoding of a pair (varSched, facSched) of partial schedule tables.

Encoding of score parameters ((n, Q), (r, C), edges).

clearedJointScore is computable in polynomial time in its encoded inputs.

Section 3: Streaming IndexFold slot selector and rational minimizer bridges #

Update a variable ((false, v)) or factor ((true, f)) slot in (varSched, facSched).

Read a variable ((false, v)) or factor ((true, f)) slot from (varSched, facSched).

@[reducible, inline]

Live accumulator for inner IndexFold.run candidate streaming over j ∈ 0 .. r ^ Q - 1.

Inner IndexFold.run callback evaluating candidate decodeLabelWord r Q j under clearedJointScore and retaining the first strict minimizer (candScore < best.2).

def Cslib.BalancedSchedules.streamBestSlotLabel (n Q r C : ℕ) (edges : List (ℕ × ℕ)) (scheds : List (Option (List ℕ)) × List (Option (List ℕ))) (slot : Bool × ℕ) :

Stream j ∈ 0 .. r ^ Q - 1 via Cslib.GenericRAM.IndexFold.run to select the first candidate word minimizing clearedJointScore for slot, falling back to List.replicate Q 0 if r ^ Q = 0 ([OAI26k], Lemma 4.5, p. 31).

def Cslib.BalancedSchedules.candidateSlotScore (n Q r C : ℕ) (edges : List (ℕ × ℕ)) (scheds : List (Option (List ℕ)) × List (Option (List ℕ))) (slot : Bool × ℕ) (j : ℕ) :

Cleared-integer score of candidate decodeLabelWord r Q j placed in slot.

theorem Cslib.BalancedSchedules.exists_min_index_streamBestSlotLabel (n Q r C : ℕ) (edges : List (ℕ × ℕ)) (scheds : List (Option (List ℕ)) × List (Option (List ℕ))) (slot : Bool × ℕ) (hpos : 0 < r ^ Q) :
∃ jStar < r ^ Q, streamBestSlotLabel n Q r C edges scheds slot = decodeLabelWord r Q jStar ∧ (∀ j < r ^ Q, candidateSlotScore n Q r C edges scheds slot jStar ≤ candidateSlotScore n Q r C edges scheds slot j) ∧ ∀ j < jStar, candidateSlotScore n Q r C edges scheds slot jStar < candidateSlotScore n Q r C edges scheds slot j

First-minimizer characterization of streamBestSlotLabel when 0 < r ^ Q.

@[simp]
theorem Cslib.BalancedSchedules.length_streamBestSlotLabel (n Q r C : ℕ) (edges : List (ℕ × ℕ)) (scheds : List (Option (List ℕ)) × List (Option (List ℕ))) (slot : Bool × ℕ) :
(streamBestSlotLabel n Q r C edges scheds slot).length = Q
theorem Cslib.BalancedSchedules.mem_streamBestSlotLabel_lt_max (n Q r C : ℕ) (edges : List (ℕ × ℕ)) (scheds : List (Option (List ℕ)) × List (Option (List ℕ))) (slot : Bool × ℕ) {x : ℕ} (hx : x ∈ streamBestSlotLabel n Q r C edges scheds slot) :
x < max r 1
theorem Cslib.BalancedSchedules.mem_streamBestSlotLabel_lt {r : ℕ} (hr : 1 ≤ r) (n Q C : ℕ) (edges : List (ℕ × ℕ)) (scheds : List (Option (List ℕ)) × List (Option (List ℕ))) (slot : Bool × ℕ) {x : ℕ} (hx : x ∈ streamBestSlotLabel n Q r C edges scheds slot) :
x < r
theorem Cslib.BalancedSchedules.set_partialScheduleListOfFin {N Q r : ℕ} {hr : 1 ≤ r} (assigned : Fin N → Option (Fin Q → Fin r)) (k : Fin N) (w : List ℕ) (hlen : w.length = Q) (hw : ∀ x ∈ w, x < r) :

Updating partialScheduleListOfFin at index k.val with a valid length-Q word w commutes with Function.update via wordToSchedule.

theorem Cslib.BalancedSchedules.streamBestSlotLabel_false_eq_bestVariableLabel {E m n Q r : ℕ} (hr : 1 ≤ r) (edge : Fin E → Fin m × Fin n) (varLabels : Fin n → Option (Fin Q → Fin r)) (factorLabels : Fin m → Option (Fin Q → Fin r)) (C : ℕ) (v : Fin n) :
some (wordToSchedule hr Q (streamBestSlotLabel n Q r C (edgesOfFin edge) (partialScheduleListOfFin varLabels, partialScheduleListOfFin factorLabels) (false, ↑v))) = bestVariableLabel edge varLabels factorLabels C v (candidateScheduleList hr Q)

Exact agreement between streamBestSlotLabel at variable slot (false, v.val) and bestVariableLabel over candidateScheduleList hr Q.

theorem Cslib.BalancedSchedules.streamBestSlotLabel_true_eq_bestFactorLabel {E m n Q r : ℕ} (hr : 1 ≤ r) (edge : Fin E → Fin m × Fin n) (varLabels : Fin n → Option (Fin Q → Fin r)) (factorLabels : Fin m → Option (Fin Q → Fin r)) (C : ℕ) (f : Fin m) :
some (wordToSchedule hr Q (streamBestSlotLabel n Q r C (edgesOfFin edge) (partialScheduleListOfFin varLabels, partialScheduleListOfFin factorLabels) (true, ↑f))) = bestFactorLabel edge varLabels factorLabels C f (candidateScheduleList hr Q)

Exact agreement between streamBestSlotLabel at factor slot (true, f.val) and bestFactorLabel over candidateScheduleList hr Q.

Section 4: All-prefix bit-length bounds, NativeCertificate, and ComputableInPolySpace #

@[reducible, inline]

Runtime input tuple for streamBestSlotLabel.

All-prefix live-state bit-length bound for the inner IndexFold.run selectSlotStep loop across every visited prefix j ≤ r ^ Q (never multiplying workspace by r ^ Q).

Uniform native machine certificate for single-slot candidate streaming streamBestSlotLabel.

streamBestSlotCertificate runs in (r ^ Q + 1) * poly(|input|) native time and polynomial workspace.

Trajectory-maximum time and polynomial-workspace bounds for streamBestSlotCertificate.

theorem Cslib.BalancedSchedules.computableInO_streamBestSlotLabel :
∃ (poly : ℕ → ℕ), PolynomiallyBounded poly ∧ Turing.MultiTapeTM.ComputableInO (fun (x : StreamSlotIn) => match x with | (((n, Q), (r, C), edges), slot, scheds) => streamBestSlotLabel n Q r C edges scheds slot) encStreamSlotIn (Turing.MultiTapeTM.encList Turing.MultiTapeTM.encNat) (fun (a : StreamSlotIn) => match a with | (((fst, Q), (r, snd), snd_1), snd_2) => (r ^ Q + 1) * poly (encStreamSlotIn a).length) fun (a : StreamSlotIn) => poly (encStreamSlotIn a).length

streamBestSlotLabel runs in O((r ^ Q + 1) * poly(|input|)) native time and polynomial workspace.

streamBestSlotLabel runs in polynomial workspace (ComputableInPolySpace) without materializing r ^ Q candidate words.