Walks, negative cycles and shortest distances #
A weighted digraph on a vertex type V is a matrix W : Matrix V V (MinTropical R): the entry
W i j is the weight of the edge i → j, the tropical zero 0 = ⊤ means that there is no edge,
the tropical product * adds weights and the tropical sum + takes minima. A walk from i is a
list l of the vertices visited after i; it ends at l.getLastD i, has l.length edges and
tropical weight walkWeight W i l, the sum of its edge weights.
IsShortestDistances W D says that each D i j is the greatest lower bound of the weights of
the walks from i to j. Under NoNegCycle W (every closed walk has weight at least the
tropical one, that is, at least 0 in R) the lower bound is attained by a walk without repeated
vertices, so it suffices to check that D is achieved by walks and lies below every such simple
walk (isShortestDistances_of_sound_complete). Closed walks of length at most card V already
decide NoNegCycle (noNegCycle_of_forall_length_le).
Walks are vertex lists rather than Mathlib's Quiver.Path, which the word-RAM Dijkstra
development uses with Quiver.Path.addWeight. A matrix has an entry for every ordered pair, so
the underlying quiver would be complete and its arrows would carry no information. Lists make
the arguments here direct: List.Nodup states that a walk is simple, splitting a list at a
repeated vertex removes a closed sub-walk, and induction on length bounds the closed walks that
decide NoNegCycle, which Power.lean then turns into a decision procedure. A lemma identifying
walkWeight with Quiver.Path.weightOfEPs on the complete quiver on V is left as a follow-up
(#3076).
Main definitions #
Cslib.Algorithms.ShortestPaths.walkWeight: the weight of a walk.Cslib.Algorithms.ShortestPaths.NoNegCycle: every closed walk has nonnegative weight.Cslib.Algorithms.ShortestPaths.IsShortestDistances:Dis the shortest-distance matrix.
Main results #
Cslib.Algorithms.ShortestPaths.exists_nodup_walk: without negative cycles, every walk can be shortened to a walk with the same endpoints, no repeated vertex and no larger weight.Cslib.Algorithms.ShortestPaths.isShortestDistances_of_sound_complete: the criterion above.Cslib.Algorithms.ShortestPaths.IsShortestDistances.unique: shortest distances are unique.Cslib.Algorithms.ShortestPaths.noNegCycle_of_forall_length_le: short closed walks suffice.Cslib.Algorithms.ShortestPaths.NoNegCycle.submatrix,Cslib.Algorithms.ShortestPaths.IsShortestDistances.submatrix: invariance under relabelling.
References #
- Cormen, Leiserson, Rivest and Stein, Introduction to Algorithms, Chapter 24 (introduction, on negative-weight cycles and cycle-free shortest paths) and Section 25.1.
Walks #
The weight of the walk that starts at i and then visits the vertices of l in order: the
product of its edge entries, which over MinTropical R is the sum of the edge weights.
W has no negative cycles: every closed walk has weight at least 1, that is, tropical
weight at least 0 in R.
Instances For
Cycle removal. Without negative cycles, every walk can be replaced by a walk with the same endpoints, no repeated vertex and no larger weight.
Closed walks are nonnegative as soon as closed walks with at most card V edges are.
Relabelling the vertices preserves the absence of negative cycles.
Shortest distances #
D is the shortest-distance matrix of W: each D i j is the greatest lower bound of the
weights of the walks from i to j (the tropical 0 = ⊤ if there is no such walk).
Shortest distances are unique.
Shortest-distance criterion. Without negative cycles, D is the shortest-distance matrix
as soon as each entry is 0 or the weight of a walk with the right endpoints (soundness), and
each entry lies below the weight of every walk without repeated vertices (completeness).
Relabelling the vertices preserves shortest distances.