package incremental_cycles
Install
dune-project
Dependency
Authors
Maintainers
Sources
sha256=3d26be7af7fd470d246872ed8ead2dd1ef0534ea95286a54aea4857ba6fb1c3e
Description
A formally verified algorithm for checking the acyclicity of a graph while incrementally adding new edges and vertices to the graph.
This particular algorithm is optimized for the case of sparse graphs.
The (amortized) complexity of m arc insertions and n vertex insertions is O(m min(m^(1/2), n^(2/3)) + n), i.e.:
- O(m sqrt(m) + n) for sparse graphs;
- O(m n^(2/3) + n) for dense graphs.
(See the companion paper for more details.)
Published: 09 Oct 2025
README
Formalisation of an Incremental Cycle Detection algorithm
This is a formalisation of an incremental cycle detection algorithm, which is a minor variant of the algorithm described in Section 2 of A New Approach to Incremental Cycle Detection and Related Problems by Bender, M. A., Fineman, J. T., Gilbert, S., & Tarjan, R. E. (2015).
NB: the aforementioned paper can alternatively be found on sci-hub. Note also that this is not the version that can be found on arXiv. The arXiv version is quite older and has not been updated with the latest improvements from the authors.
The development in this repository is described in our paper Formal Proof and Analysis of an Incremental Cycle Detection Algorithm, published at ITP'19.
OCaml library
To install the library using opam:
opam pin incremental_cycles https://gitlab.inria.fr/agueneau/incremental-cycles.git
Building the proofs
Installing the dependencies
You need to have opam >= 2.0 installed.
Option A: If you already have an opam switch with Coq >= 8.8 and the coq-released opam repository:
opam install -y --deps-only .
Option B: create a fresh local opam switch with everything needed:
opam switch create -y --deps-only --repositories=default,coq-released=https://coq.inria.fr/opam/released . eval $(opam env)
Troubleshooting
For Option B, if the invocation fails at some point, either remove the _opam
directory and re-run the command (this will redo everything), or do eval $(opam env)
and then opam install -y --deps-only .
(this will continue from where it failed).
Building
make proofs
Organisation of the development
OCaml implementation
The src/
directory contains the OCaml implementations that we verify.
simple_sparse.ml
implements the cycle detection algorithm for sparse graphs, without strong components (Section 2 of the paper)raw_graph.ml
provides an implementation for the graph structure assumed bySimple_sparse
Coq proofs
The proofs/
directory contains the Coq proofs.
IncrementalCycleDetection.v
: Exports the toplevel theorems and specifications
Proofs directly relating OCaml functions to their specification
BackwardSearch_proof.v
: Proof of the backward search: functionsvisit_backward
andbackward_search
ForwardSearch_proof.v
: Proof of the forward search: functionsvisit_forward
andforward_search
ComputeCycle_proof.v
: Proof of the code that returns the edges of the cycle when one is detected: functionslist_of_parents
andcompute_cycle
SimpleSparse_proof.v
: Proof of the toplevel functions:add_edge_or_detect_cycle
andadd_vertex
IFold_proof.v
: Proof ofinterruptible_fold
RawGraph.v
: Gives specifications for theRaw_graph
interface. Proves them and implements theIsRawGraph
predicate for the implementation inraw_graph.ml
.
Logical definitions, invariants and lemmas related to the algorithm
GraphFunctionalInvariants.v
: Functional invariants of the algorithm (Inv
)GraphCostInvariants.v
: Potential function for the amortized complexity analysis (net
,received
,spent
...)Graph.v
: Separation logic predicate for the whole graph structureIsGraph
, including functional invariants and potentialTraversal.v
: Generic invariants for a graph search, used by both the backward and forward searchPaths.v
: Auxiliary definitions for the different notions of reachability in a graph (with levels and marks) used at the specification level
Generic auxiliary definitions, lemmas and tactics
GraphModel.v
: Interface for a standard model of a directed graph, at the logical level. The development is parameterized by any specific logical graph satisfying this interface.GraphModelInst.v
: Provides one possible instantiation forGraphModel.v
, just to ensure that the interface can be implemented.PowerTwoThird.v
: Lemmas about the function x -> x^2/3SqrtAsymptotics.v
: Asymptotic properties of square rootLibRelationExtra.v
: Lemmas about relationsTLCBuffer.v
: Auxiliary lemmas about lists, sets that should ultimately be integrated in TLCLibTacticsExtra.v
: auxiliary generic tacticsHeapTacticsExtra.v
: auxiliary tactics to handle time credits