Documentation

CslibFrontier.Algorithms.Reachability.DoubleCounting.Controller

Bounded outer double-counting controller #

This is the outer step of Figures 2 and 3 in the March 31, 1999 version of [RA00], Section 2, pp. 6–7. Given adjacency and current-round membership callbacks, count qualifying predecessors of each vertex outside the round. Add a single tally contribution for a positive count and flag any count greater than one. Figure 2 counts once per qualifying predecessor, yielding the same tally whenever the tie flag is clear.

The controller returns the first bad round, or tests the target after stabilization. In the list monad, each entry represents a successful replay, so the singleton equations in runController_correct account for multiplicity even when branches return equal values. Rejected replays contribute no list entries. The native LogSpace.DoubleCounting module certifies the binary update. Callback and branch-preserving native composition are tracked in #6747.

See the checked caller in CslibFrontierTests.LayeredDigraph.

The registers accumulated by the outer vertex scan.

  • tally : Tally

    Count and distance sum after adding new vertices.

  • bad : Bool

    Whether some new vertex has multiple qualifying predecessors.

Accumulate a single vertex's contribution using its predecessor count.

@[reducible, inline]

The Figure 1 callback takes the radius, current tally, and queried vertex.

def Cslib.DoubleCounting.predecessorStep {m : Type → Type} [Monad m] {α : Type} (edge : α → α → m Bool) (member : α → m Bool) (v : α) (c : ℕ) (u : α) :
m ℕ

One predecessor test: count only when both callbacks answer true. An arbitrary index type lets typed scans and binary scalar query controllers share this dispatch.

def Cslib.DoubleCounting.countPredecessors {m : Type → Type} [Monad m] {n : ℕ} (edge : Fin n → Fin n → m Bool) (member : Fin n → m Bool) (v : Fin n) :
m ℕ

Scan all predecessors using the same handler as each finite prefix.

def Cslib.DoubleCounting.scanVertex {m : Type → Type} [Monad m] {n : ℕ} (edge : Fin n → Fin n → m Bool) (member : Fin n → m Bool) (k : ℕ) (a : RoundUpdate) (v : Fin n) :

Process one vertex, adding its contribution once even when its predecessors tie.

def Cslib.DoubleCounting.scanNextRound {m : Type → Type} [Monad m] {n : ℕ} (edge : Fin n → Fin n → m Bool) (member : MembershipScan m n) (k : ℕ) (t : Tally) :

Update the tally and check for ties by scanning vertices and their predecessors. Only scalar registers persist across calls.

theorem Cslib.DoubleCounting.scanNextRound_correct {m : Type → Type} [Monad m] [LawfulMonad m] {n : ℕ} {r : Fin n → Fin n → Prop} {s : Fin n} {k : ℕ} {edge : Fin n → Fin n → m Bool} {member : MembershipScan m n} (he : ∀ (u v : Fin n), edge u v = pure (decide (r u v))) (hm : ∀ (v : Fin n), member k (expected r s k) v = pure (decide (v ∈ round r s k))) (hw : ∃! w : Transcript (Fin n), Passes r s k w) :
∃ (a : RoundUpdate), scanNextRound edge member k (expected r s k) = pure a ∧ a.tally = expected r s (k + 1) ∧ (a.bad = false ↔ ∃! w : Transcript (Fin n), Passes r s (k + 1) w)

With correct callback replies, the bounded scans compute the exact next tally and flag exactly the failure of next-round uniqueness, provided the current round is unique.

A terminal verdict distinguishes a tied graph from a reachability answer.

Instances For
    @[reducible, inline]
    abbrev Cslib.DoubleCounting.ControllerVerdict.Correct {n : ℕ} (r : Fin n → Fin n → Prop) (s target : Fin n) :

    A verdict identifies the first nonunique round or decides reachability when all rounds have unique passing transcripts.

    theorem Cslib.DoubleCounting.ControllerVerdict.Correct.eq {n : ℕ} {r : Fin n → Fin n → Prop} {s target : Fin n} {a b : ControllerVerdict} (ha : Correct r s target a) (hb : Correct r s target b) :
    a = b

    Two verdicts satisfying the exact controller specification agree.

    def Cslib.DoubleCounting.runRoundsWith {m : Type → Type} [Monad m] (nextRound : ℕ → ℕ → Tally → m RoundUpdate) (member : ℕ → ℕ → Tally → m Bool) :

    Run the fuel-bounded controller with a supplied round and final membership action.

    def Cslib.DoubleCounting.runRounds {m : Type → Type} [Monad m] {n : ℕ} (edge : Fin n → Fin n → m Bool) (member : MembershipScan m n) (target : Fin n) :

    Fuel-bounded round loop used by runController.

    def Cslib.DoubleCounting.runController {m : Type → Type} [Monad m] {n : ℕ} (edge : Fin n → Fin n → m Bool) (member : MembershipScan m n) (target : Fin n) :

    Run at most one update per vertex, starting with the source alone. The correctness theorem excludes fuel exhaustion when the callback contract holds.

    theorem Cslib.DoubleCounting.radius_succ_lt_of_expected_count_ne {n : ℕ} {r : Fin n → Fin n → Prop} {s : Fin n} {k : ℕ} (h : (expected r s (k + 1)).count ≠ (expected r s k).count) :
    k + 1 < n

    A change in the expected count means the next radius is below the vertex count.

    theorem Cslib.DoubleCounting.runController_correct {m : Type → Type} [Monad m] [LawfulMonad m] {n : ℕ} {r : Fin n → Fin n → Prop} {s target : Fin n} {edge : Fin n → Fin n → m Bool} {member : MembershipScan m n} (he : ∀ (u v : Fin n), edge u v = pure (decide (r u v))) (hm : ∀ (k : ℕ), (∃! w : Transcript (Fin n), Passes r s k w) → ∀ (v : Fin n), member k (expected r s k) v = pure (decide (v ∈ round r s k))) :
    ∃ (verdict : ControllerVerdict), runController edge member target = pure (some verdict) ∧ ControllerVerdict.Correct r s target verdict

    Under the adjacency and unique membership-replay contracts, the controller returns the first nonunique round, or the reachability answer when all rounds are unique. Fuel suffices for either outcome.