Documentation

CslibFrontier.Algorithms.WordRAM.Arborescence.Internal.BasicProg

Low-level Word-RAM subroutines and Realizes certificates (internal) #

Defines array copy/zero, argmin, minimum-cost incoming/outgoing parent selection, cycle detection, and cycle-mask programs over Memory.Prog, together with their Realizes .exact certificates.

Subroutines and Realizes certificates #

Parameters for copying len contiguous words from src to dst.

  • src : ℕ

    Source base address.

  • dst : ℕ

    Destination base address.

  • len : ℕ

    Number of words to copy.

@[reducible, inline]

The tuple word encoding of the fields of encCopyArgs.

Word encoding of CopyArgs into 3 consecutive registers.

@[reducible, inline]

Address-fit safety precondition for one step of copyStep.

Parameters for zero-filling len contiguous words starting at dst.

  • dst : ℕ

    Destination base address.

  • len : ℕ

    Number of words to zero.

Word encoding of ZeroArgs into 2 consecutive registers.

@[reducible, inline]

The tuple word encoding of the fields of encZeroArgs.

@[reducible, inline]

Address-fit safety precondition for one step of zeroStep.

Parameters for finding the minimum-cost active index across length n.

  • n : ℕ

    Array length and sentinel value for no active index.

  • predBase : ℕ

    Base address of the 0/1 candidate indicator array.

  • costBase : ℕ

    Base address of the Signed.encode-valued candidate cost array.

@[reducible, inline]

The tuple word encoding of the fields of encArgMinArgs.

Loop state carried by argMinStep.

  • idx : ℕ

    Current index being inspected.

  • bestIdx : ℕ

    Best active index seen so far (n if none).

  • bestCost : ℕ

    Encoded cost of bestIdx.

@[reducible, inline]

Address-fit safety precondition for one step of argMinStep.

Returns the minimum-cost active index in [0, a.n), or a.n if none is active.

Parameters for scanning vertex v's incoming arcs in row v into candPred/candCost.

  • n : ℕ

    Matrix dimension (number of vertices).

  • v : ℕ

    Row index (target vertex).

  • adjBase : ℕ

    Base address of the working n × n adjacency table.

  • costBase : ℕ

    Base address of the working n × n cost table.

  • predOut : ℕ

    Output base address for candidate feasibility indicators (n words).

  • costOut : ℕ

    Output base address for candidate signed costs (n words).

Writes candidate feasibility (avw = 1 ∧ col ≠ v) and cost for column col of row v.

@[reducible, inline]

Address-fit safety precondition for one step of selectRowStep.

Parameters for greedy parent selection across all non-root vertices at frame k.

  • n : ℕ

    Matrix dimension (number of vertices).

  • r : ℕ

    Designated root vertex index.

  • ws : ℕ

    Workspace base address.

  • k : ℕ

    Active contraction stack frame index.

@[reducible, inline]

The tuple word encoding of the fields of encSelectArgs.

Outer-loop state tracking current vertex v and feasibility flag feas (1 iff feasible).

  • v : ℕ

    Current vertex index being processed.

  • feas : ℕ

    Feasibility flag (1 if every vertex processed so far found a parent, 0 otherwise).

Selects the minimum-cost active non-self outgoing parent for vertex st.v.

@[reducible, inline]

Safety precondition for one vertex step of selectOuterStep.

Populates frame a.k's greedy parent table and returns 1 iff all non-root vertices have an active outgoing edge.

Parameters for checking whether vertex start lies on a directed cycle in parentBase.

  • n : ℕ

    Number of vertices and maximum pointer-walk length.

  • parentBase : ℕ

    Base address of the n-word parent array.

  • start : ℕ

    Starting vertex to follow for n steps.

Loop state carried by hasCycleStep.

  • step : ℕ

    Step counter along the walk.

  • cur : ℕ

    Current vertex in the parent pointer walk.

  • hit : ℕ

    Indicator (1 once the walk has returned to start).

Advances the parent pointer walk by one step and records if it returned to env.start.

@[reducible, inline]

Address-fit safety precondition for one step of hasCycleStep.

Walks a.n parent pointers from a.start and returns 1 iff a.start lies on a cycle.

Parameters for finding the smallest cycle vertex in parentBase (excluding root r).

  • n : ℕ

    Number of vertices and sentinel when acyclic.

  • r : ℕ

    Root vertex index (never tested).

  • parentBase : ℕ

    Base address of the n-word parent array.

@[reducible, inline]

The tuple word encoding of the fields of encFindCycleArgs.

Outer-loop state tracking candidate vertex v and first cycle vertex found.

  • v : ℕ

    Current vertex index being tested.

  • found : ℕ

    First cycle vertex found (n if none yet).

Tests st.v ≠ env.r for cycle membership unless an earlier cycle vertex was already found.

Returns the least non-root vertex lying on a cycle, or a.n if the parent map is acyclic.

Parameters for marking all vertices of the cycle containing x0 into maskBase.

  • n : ℕ

    Number of vertices and walk bound.

  • parentBase : ℕ

    Base address of the n-word parent array.

  • maskBase : ℕ

    Output base address of the n-word 0/1 cycle-membership mask array.

  • x0 : ℕ

    Representative vertex known to lie on the target cycle.

@[reducible, inline]

The tuple word encoding of the fields of encCycleMaskArgs.

Loop state carried by cycleMaskStep.

  • step : ℕ

    Step counter along the cycle walk.

  • cur : ℕ

    Current cycle vertex being marked.

@[reducible, inline]

Address-fit safety precondition for one step of cycleMaskStep.

Walks a.n steps from a.x0, setting maskBase[v] := 1 along the cycle.

Zeros a.maskBase[0..a.n) and marks every vertex on a.x0's cycle with 1.