Documentation

CslibFrontier.Algorithms.ShortestPaths.Walk

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 #

Main results #

References #

Walks #

def Cslib.Algorithms.ShortestPaths.walkWeight {V : Type u_2} {α : Type u_3} [Mul α] [One α] (W : Matrix V V α) :
V → List V → α

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.

@[simp]
theorem Cslib.Algorithms.ShortestPaths.walkWeight_nil {V : Type u_2} {α : Type u_3} [Mul α] [One α] (W : Matrix V V α) (i : V) :
@[simp]
theorem Cslib.Algorithms.ShortestPaths.walkWeight_cons {V : Type u_2} {α : Type u_3} [Mul α] [One α] (W : Matrix V V α) (i v : V) (l : List V) :
walkWeight W i (v :: l) = W i v * walkWeight W v l
theorem Cslib.Algorithms.ShortestPaths.walkWeight_append {V : Type u_2} {α : Type u_3} [Monoid α] (W : Matrix V V α) (i : V) (l₁ l₂ : List V) :
walkWeight W i (l₁ ++ l₂) = walkWeight W i l₁ * walkWeight W (l₁.getLastD i) l₂

The weight of a concatenation of walks.

theorem Cslib.Algorithms.ShortestPaths.walkWeight_submatrix {V : Type u_2} {U : Type u_3} {α : Type u_4} [Mul α] [One α] (W : Matrix V V α) (e : U → V) (u : U) (l : List U) :
walkWeight (W.submatrix e e) u l = walkWeight W (e u) (List.map e l)

Relabelling the vertices of a walk.

W has no negative cycles: every closed walk has weight at least 1, that is, tropical weight at least 0 in R.

Instances For
    theorem Cslib.Algorithms.ShortestPaths.exists_nodup_walk {R : Type u_1} [LinearOrderedAddCommMonoidWithTop R] {V : Type u_2} {W : Matrix V V (MinTropical R)} (hW : NoNegCycle W) (i : V) (l : List V) :
    ∃ (l' : List V), (i :: l').Nodup ∧ l'.getLastD i = l.getLastD i ∧ walkWeight W i l' ≤ walkWeight W i l

    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.

    theorem Cslib.Algorithms.ShortestPaths.NoNegCycle.submatrix {R : Type u_1} [LinearOrderedAddCommMonoidWithTop R] {V : Type u_2} {W : Matrix V V (MinTropical R)} {U : Type u_3} (hW : NoNegCycle W) (e : U ≃ V) :
    NoNegCycle (W.submatrix ⇑e ⇑e)

    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).

    theorem Cslib.Algorithms.ShortestPaths.IsShortestDistances.unique {R : Type u_1} [LinearOrderedAddCommMonoidWithTop R] {V : Type u_2} {W D₁ D₂ : Matrix V V (MinTropical R)} (h₁ : IsShortestDistances W D₁) (h₂ : IsShortestDistances W D₂) :
    D₁ = D₂

    Shortest distances are unique.

    theorem Cslib.Algorithms.ShortestPaths.isShortestDistances_of_sound_complete {R : Type u_1} [LinearOrderedAddCommMonoidWithTop R] {V : Type u_2} {W D : Matrix V V (MinTropical R)} (hW : NoNegCycle W) (hsound : ∀ (i j : V), D i j = 0 ∨ ∃ (l : List V), l.getLastD i = j ∧ walkWeight W i l = D i j) (hcomplete : ∀ (i : V) (l : List V), (i :: l).Nodup → D i (l.getLastD i) ≤ walkWeight W i l) :

    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).

    theorem Cslib.Algorithms.ShortestPaths.IsShortestDistances.submatrix {R : Type u_1} [LinearOrderedAddCommMonoidWithTop R] {V : Type u_2} {W : Matrix V V (MinTropical R)} {U : Type u_3} {D : Matrix V V (MinTropical R)} (h : IsShortestDistances W D) (e : U ≃ V) :
    IsShortestDistances (W.submatrix ⇑e ⇑e) (D.submatrix ⇑e ⇑e)

    Relabelling the vertices preserves shortest distances.