Dijkstra's algorithm: the invariant #
This file proves the graph theory behind Dijkstra's algorithm Dijkstra
Cormen et al., Section 24.3, independently of the machine. The algorithm keeps a set
S of visited vertices and a tentative distance D v for every vertex, and
Cslib.Algorithms.WordRAM.Dijkstra.Instance.Inv states what it maintains: D bounds the
distance from above, is exact on S, and is already relaxed along every edge out of S.
The key step (Cslib.Algorithms.WordRAM.Dijkstra.Instance.Inv.step) is the classical cut
argument: on every path from the source to an unvisited vertex, either the source is unvisited,
with tentative distance 0, or the path has an edge from S to an unvisited vertex. Either way
its weight is at least the least tentative distance outside S. Hence an unvisited
vertex of least finite tentative distance has the exact distance, and relaxing its edges keeps
the invariant with that vertex visited.
Main definitions #
Cslib.Algorithms.WordRAM.Dijkstra.decodeDist: the distance a word encodes.Cslib.Algorithms.WordRAM.Dijkstra.Instance.relax: relaxation of the edges out of a vertex.Cslib.Algorithms.WordRAM.Dijkstra.Instance.Inv: the invariant of Dijkstra's algorithm.
Main results #
Cslib.Algorithms.WordRAM.Dijkstra.decodeDist_encodeDist: decoding inverts the encoding of distances.Cslib.Algorithms.WordRAM.Dijkstra.decodeDist_le: decoding preserves order between nonzero words.Cslib.Algorithms.WordRAM.Dijkstra.Instance.le_maxWeight: every edge weight is at most the largest one.Cslib.Algorithms.WordRAM.Dijkstra.Instance.dist_le_edge: the distance to the head of an edge is at most the distance to its tail plus its weight.Cslib.Algorithms.WordRAM.Dijkstra.Instance.Inv.init: the invariant holds initially.Cslib.Algorithms.WordRAM.Dijkstra.Instance.Inv.step: visiting an unvisited vertex of least finite tentative distance and relaxing its edges keeps the invariant.Cslib.Algorithms.WordRAM.Dijkstra.Instance.Inv.eq_dist: once every unvisited vertex has infinite tentative distance, the tentative distances are the distances.
References #
The distance a word encodes: ⊤ for 0 and d for d + 1.
Instances For
Decoding inverts the encoding of distances: a distance word decodes to its distance.
A nonzero distance word decodes to a finite distance.
Decoding preserves order between nonzero distance words.
The invariant of Dijkstra's algorithm, for the visited set S and the tentative
distances D.
The source has tentative distance
0.Tentative distances bound the distances from above.
Tentative distances are exact on visited vertices.
Every edge from a visited vertex to an unvisited one is relaxed.
Finite tentative distances are at most
|S|times the largest weight.
Instances For
The invariant holds with no vertex visited, the source at tentative distance 0 and every
other vertex at ⊤.
Dijkstra's step. Visiting an unvisited vertex u of least finite tentative distance and
relaxing its edges keeps the invariant.