Documentation

CslibFrontier.Algorithms.Reachability.DoubleCounting.ControllerClock

Callback-action bounds for the controller #

The actual controller runs in OptionT (StateM σ): a callback can return either Boolean or reject, while its state records the charge even on rejection. The chosen clock can count edge calls, membership calls, or actions inside the callbacks. No correctness hypothesis on replies or tallies is used. Every initial provider state is covered, including ties, rejecting calls and fuel exhaustion.

Main results #

These are bounds on the state clock, not physical runtime or workspace. In particular they do not implement the callbacks or certify native halting; those obligations remain in #6747. A primitive callback can record one action before returning a value or rejection. The weighted bound also composes with a membership routine's own action bound. See the ordinary-import client CslibFrontierTests.DoubleCountingControllerClock for separate counters and composition with Scan.tallyM_clock.

theorem Cslib.DoubleCounting.scanNextRound_clock {σ : Type} {n : ℕ} (clock : σ → ℕ) (E M : ℕ) (edge : Fin n → Fin n → OptionT (StateM σ) Bool) (member : MembershipScan (OptionT (StateM σ)) n) (k : ℕ) (t : Tally) (he : ∀ (u v : Fin n) (s : σ), clock ((edge u v).run s).2 ≤ clock s + E) (hm : ∀ (v : Fin n) (s : σ), clock ((member k t v).run s).2 ≤ clock s + M) (s : σ) :
clock ((scanNextRound edge member k t).run s).2 ≤ clock s + n * (M + n * (E + M))

Arbitrary replying or rejecting callbacks cost at most one membership test per vertex, then at most one edge and one membership test per predecessor. Tied rounds are covered.

theorem Cslib.DoubleCounting.runRounds_clock {σ : Type} {n : ℕ} (clock : σ → ℕ) (E M limit : ℕ) (edge : Fin n → Fin n → OptionT (StateM σ) Bool) (member : MembershipScan (OptionT (StateM σ)) n) (he : ∀ (u v : Fin n) (s : σ), clock ((edge u v).run s).2 ≤ clock s + E) (hm : ∀ k < limit, ∀ (t : Tally) (v : Fin n) (s : σ), clock ((member k t v).run s).2 ≤ clock s + M) (target : Fin n) (fuel k : ℕ) (t : Tally) (hk : k + fuel ≤ limit) (s : σ) :
clock ((runRounds edge member target fuel k t).run s).2 ≤ clock s + fuel * (n * (M + n * (E + M))) + M

A fuel-bounded run spends at most the round budget per unit of fuel, plus one terminal membership budget. Only radii below limit need a membership certificate.

theorem Cslib.DoubleCounting.runController_clock {σ : Type} {n : ℕ} (clock : σ → ℕ) (E M : ℕ) (edge : Fin n → Fin n → OptionT (StateM σ) Bool) (member : MembershipScan (OptionT (StateM σ)) n) (he : ∀ (u v : Fin n) (s : σ), clock ((edge u v).run s).2 ≤ clock s + E) (hm : ∀ k < n, ∀ (t : Tally) (v : Fin n) (s : σ), clock ((member k t v).run s).2 ≤ clock s + M) (target : Fin n) (s : σ) :
clock ((runController edge member target).run s).2 ≤ clock s + n * n * n * E + (n * n * n + n * n + 1) * M

The actual controller uses at most n³ edge calls and n³+n²+1 membership calls. Set (E,M) to (1,0) or (0,1) for separate counters; arbitrary weighted callback clocks compose through the same statement. The final state includes charges on rejecting branches.

theorem Cslib.DoubleCounting.runController_scan_clock {σ : Type} {n : ℕ} (clock : σ → ℕ) (edge : Fin n → Fin n → OptionT (StateM σ) Bool) (select : Fin n → StateM σ Bool) (next : StateM σ (Option (Fin n))) (scanEdge : Fin n → Fin n → StateM σ Bool) (source target : Fin n) (he : ∀ (u v : Fin n) (s : σ), clock ((edge u v).run s).2 ≤ clock s + 1) (hs : ∀ (v : Fin n) (s : σ), clock (select v s).2 ≤ clock s + 1) (hn : ∀ (s : σ), clock (next s).2 ≤ clock s + 1) (hse : ∀ (u v : Fin n) (s : σ), clock (scanEdge u v s).2 ≤ clock s + 1) (s : σ) :
clock ((runController edge (fun (k : ℕ) (t : Tally) (v : Fin n) => OptionT.mk (Scan.runM select next scanEdge source v k t)) target).run s).2 ≤ clock s + n * n * n + (n * n * n + n * n + 1) * (n * (2 * n + 2))

Composing the real membership scan costs at most a degree-five polynomial in n primitive callback actions. Each inner selection, destination read and edge callback costs at most one; the final tally check costs none. The outer edge query also costs at most one. Rejection retains its charge. This composes action clocks, not physical runtime or native workspace.