Documentation

CslibFrontier.Algorithms.ShortestPaths.Power

Shortest distances as (min,+) matrix powers #

Over MinTropical R the matrix product is the (min,+) product, so (W ^ m) i j is the least weight of a walk from i to j with exactly m edges, and ((1 + W) ^ k) i j is the least weight of a walk with at most k edges. Without negative cycles a shortest walk can be taken without repeated vertices, hence with at most card V - 1 edges: (1 + W) ^ k is the shortest-distance matrix for every k ≥ card V - 1. The same powers detect negative cycles: W has none iff the diagonal of (1 + W) ^ card V is at least the tropical one.

Without negative cycles 1 + W is withOneDiag W, the weight matrix with zero-weight loops, which is the initial matrix of Floyd–Warshall and of repeated squaring.

Main definitions #

Main results #

References #

def Cslib.Algorithms.ShortestPaths.withOneDiag {V : Type u_2} [DecidableEq V] {α : Type u_3} [One α] (W : Matrix V V α) :
Matrix V V α

W with every diagonal entry replaced by 1, the tropical 0: the matrix of W with a zero-weight loop at every vertex.

Without negative cycles, adding the tropical identity replaces the diagonal by 1.

(W ^ m) i j is at most the weight of every walk from i to j with m edges.

theorem Cslib.Algorithms.ShortestPaths.exists_walk_of_pow {R : Type u_1} [LinearOrderedAddCommMonoidWithTop R] {V : Type u_2} [Fintype V] [DecidableEq V] (W : Matrix V V (MinTropical R)) (m : ℕ) (i j : V) :
(W ^ m) i j = 0 ∨ ∃ (l : List V), l.length = m ∧ l.getLastD i = j ∧ walkWeight W i l = (W ^ m) i j

(W ^ m) i j is 0 or the weight of a walk from i to j with m edges.

theorem Cslib.Algorithms.ShortestPaths.one_add_pow_apply_le {R : Type u_1} [LinearOrderedAddCommMonoidWithTop R] {V : Type u_2} [Fintype V] [DecidableEq V] (W : Matrix V V (MinTropical R)) (k : ℕ) (i : V) (l : List V) :
l.length ≤ k → ((1 + W) ^ k) i (l.getLastD i) ≤ walkWeight W i l

((1 + W) ^ k) i j is at most the weight of every walk from i to j with at most k edges.

theorem Cslib.Algorithms.ShortestPaths.exists_walk_of_one_add_pow {R : Type u_1} [LinearOrderedAddCommMonoidWithTop R] {V : Type u_2} [Fintype V] [DecidableEq V] (W : Matrix V V (MinTropical R)) (k : ℕ) (i j : V) :
((1 + W) ^ k) i j = 0 ∨ ∃ (l : List V), l.length ≤ k ∧ l.getLastD i = j ∧ walkWeight W i l = ((1 + W) ^ k) i j

((1 + W) ^ k) i j is 0 or the weight of a walk from i to j with at most k edges.

Shortest distances as tropical powers. Without negative cycles, (1 + W) ^ k is the shortest-distance matrix of W for every k ≥ card V - 1.

theorem Cslib.Algorithms.ShortestPaths.one_add_pow_eq_of_le {R : Type u_1} [LinearOrderedAddCommMonoidWithTop R] {V : Type u_2} [Fintype V] [DecidableEq V] {W : Matrix V V (MinTropical R)} (hW : NoNegCycle W) {k : ℕ} (hk : Fintype.card V - 1 ≤ k) :
(1 + W) ^ k = (1 + W) ^ (Fintype.card V - 1)

Without negative cycles the powers of 1 + W are constant from card V - 1 on.

Without negative cycles, withOneDiag W ^ k is the shortest-distance matrix of W for every k ≥ card V - 1.

Negative-cycle detection. W has no negative cycles iff every diagonal entry of (1 + W) ^ card V is at least 1, the tropical 0.