Documentation

Examples.Ram.GraphDegree

Computing a graph degree from a represented adjacency row #

The executable function is Ram.Source.Array.sumFunctions.function.sum: the same fixed array loop used for ordinary word sums. Its specification here uses mathlib's SimpleGraph and SimpleGraph.degree, without opening that loop's register, call-frame or memory-preservation proofs.

The adjacency row must already be present in memory. adjacencyRow describes that representation; it is not an executable graph loader or a free call to a Lean adjacency predicate. The function receives only a pointer and a length. The address bound ensures both safe traversal and an exact, non-wrapping degree. Correctness uses no proposed step budget. The separate time theorem bounds the same function body; an enclosing call additionally pays its generated overhead.

The mathematical view of one preloaded adjacency row, with one word per vertex. This definition specifies memory contents; the RAM function does not evaluate G.Adj.

Equations
Instances For

    Reinterpret the list sum using mathlib's finite-neighbor-set definition of degree. No implementation-specific invariant is needed in this step.

    The returned word decodes to the exact mathematical degree when the row length fits; the graph-theoretic bound comes directly from mathlib.

    theorem Ram.Examples.GraphDegree.function_contract {n w : ℕ} (G : SimpleGraph (Fin n)) [DecidableRel G.Adj] (v : Fin n) {program : Program} {heapLimit depth : ℕ} {base : Word w} (hw : 0 < w) (hfit : BitVec.toNat base + n < 2 ^ w) :
    Source.FunctionContract program heapLimit depth Source.Array.sumFunctions.function.sum (fun (args : List (Word w)) (entry : Source.State w) => args = Source.Array.sumFunctions.arguments.sum { base := base, length := BitVec.ofNat w n } ∧ Source.ArrayAt heapLimit base (adjacencyRow G v w) entry) fun (x : List (Word w)) (entry : Source.State w) (values : List (Word w)) (finish : Source.State w) => ∃ (value : Word w), values = [value] ∧ BitVec.toNat value = G.degree v ∧ finish = entry

    A graph-valued mathematical specification of the reusable sum function. Only its parameter list, represented input row and returned value are visible; the entire caller state is preserved.

    theorem Ram.Examples.GraphDegree.function_runs {n w : ℕ} (G : SimpleGraph (Fin n)) [DecidableRel G.Adj] (v : Fin n) {program : Program} {heapLimit depth : ℕ} {base : Word w} (hw : 0 < w) (hfit : BitVec.toNat base + n < 2 ^ w) (entry : Source.State w) (represented : Source.ArrayAt heapLimit base (adjacencyRow G v w) entry) :
    ∃ (value : Word w), Source.FunctionExec program heapLimit depth Source.Array.sumFunctions.function.sum (Source.Array.sumFunctions.arguments.sum { base := base, length := BitVec.ofNat w n }) entry [value] entry ∧ BitVec.toNat value = G.degree v

    Compute a graph degree without a main, an input stream or an output instruction. This is an invocation of the actual fixed array-sum function.

    theorem Ram.Examples.GraphDegree.function_timeBound {n w : ℕ} (G : SimpleGraph (Fin n)) [DecidableRel G.Adj] (v : Fin n) {program : Program} {control heapLimit depth : ℕ} {base : Word w} (hw : 0 < w) (hfit : BitVec.toNat base + n < 2 ^ w) :
    Source.FunctionTimeBound control program heapLimit depth Source.Array.sumFunctions.function.sum (fun (args : List (Word w)) (entry : Source.State w) => args = Source.Array.sumFunctions.arguments.sum { base := base, length := BitVec.ofNat w n } ∧ Source.ArrayAt heapLimit base (adjacencyRow G v w) entry) fun (x : List (Word w)) (x_1 : Source.State w) => 18 * n + 8

    The unchanged implementation has a linear body-step bound in the number of vertices. Constructing the represented row and invoking the function from another function are not included in this body count.

    theorem Ram.Examples.GraphDegree.function_runs_with_timeBound {n w : ℕ} (G : SimpleGraph (Fin n)) [DecidableRel G.Adj] (v : Fin n) {program : Program} {control heapLimit depth : ℕ} {base : Word w} (hw : 0 < w) (hfit : BitVec.toNat base + n < 2 ^ w) (entry : Source.State w) (represented : Source.ArrayAt heapLimit base (adjacencyRow G v w) entry) :
    ∃ (bodySteps : ℕ) (value : Word w), Source.FunctionMeasuredExec control program heapLimit depth Source.Array.sumFunctions.function.sum (Source.Array.sumFunctions.arguments.sum { base := base, length := BitVec.ofNat w n }) bodySteps entry [value] entry ∧ BitVec.toNat value = G.degree v ∧ bodySteps ≤ 18 * n + 8

    Correctness and cost hold of one invocation, rather than unrelated mathematical result and time functions.

    theorem Ram.Examples.GraphDegree.sum_eq_degree {n : ℕ} (G : SimpleGraph (Fin n)) [DecidableRel G.Adj] (v : Fin n) {heapLimit : ℕ} {array : ArrayRef 32} {entry : Source.State 32} (fit : BitVec.toNat array.base + n < 2 ^ 32) (hstack : heapLimit + ABI.frameSize Source.Array.sumFunctions.registers < 2 ^ 32) (represented : array.Rep heapLimit (adjacencyRow G v 32) entry) :
    ArraySum.sum array heapLimit entry ⋯ hstack = G.degree v

    The ordinary executable sum returns a graph degree on a represented adjacency row. The proof uses its value equation and mathlib's graph facts; it does not reopen an execution relation, loop or calling convention.