Documentation

CslibFrontier.DataStructure.AdjacencyList.Spec

Adjacency-list queries as a state-transition specification #

AdjacencyList.spec n is a read-only interface to a weighted directed graph on Fin n, given by its adjacency lists of (target, weight) pairs. A client asks for the out-degree of a vertex (degree) and for the i-th edge out of it (edge). The graph itself stays behind the interface: a client sees one vertex and one weight per query, never a whole list. The state is never changed. An edge query is admissible only below the out-degree.

An implementation stores the graph as it likes, for example as the offset and edge arrays that a word RAM reads from its input. Its correctness and its charges are then proved against step.

Main definitions #

Main results #

@[reducible, inline]

The adjacency lists of a weighted directed graph on Fin n: adj u holds a pair (v, c) for each edge from u to v of weight c.

Queries to the adjacency lists of a graph on Fin n.

  • degree {n : ℕ} (u : Fin n) : Op n

    The number of edges out of u.

  • edge {n : ℕ} (u : Fin n) (i : ℕ) : Op n

    The i-th edge out of u, as its target and its weight.

Instances For
    @[instance_reducible]
    def Cslib.DataStructure.AdjacencyList.instDecidableEqOp.decEq {n✝ : ℕ} (x✝ x✝¹ : Op n✝) :
    Decidable (x✝ = x✝¹)
    @[instance_reducible]
    @[reducible, inline]

    The answer types of the queries.

    The answers of the queries; the state never changes. An edge query past the out-degree is inadmissible, and its answer (u, 0) is a placeholder.

    An edge query is admissible below the out-degree.

    @[reducible, inline]

    The adjacency-list interface of graphs on Fin n.

    @[simp]
    theorem Cslib.DataStructure.AdjacencyList.step_degree {n : ℕ} (adj : State n) (u : Fin n) :
    step adj (Op.degree u) = (adj, (adj u).length)

    A degree query returns the length of the adjacency list.

    @[simp]
    theorem Cslib.DataStructure.AdjacencyList.step_edge {n : ℕ} (adj : State n) (u : Fin n) {i : ℕ} (hi : i < (adj u).length) :
    step adj (Op.edge u i) = (adj, (adj u)[i])

    An admissible edge query returns that entry of the adjacency list.