Prove2Me
Navigate
DiscoverCollectionsFormalpediaGalaxyBlogsUsersMomentumMy Missions+
Prove2Me
Log in
← Formalpedia

Proposition 12.16 — subpaths of shortest paths are shortest paths

Proved
AppliedComb.GraphAlg.shortest_path_subpaths

by mikedeng1 · Sep 28, 2026 · Mathlib 0df444a (Lean v4.33.1)

combinatoricsgraph-theoryp2o-batch-books5p2o-gran-per-chapterp2o-plan-bookp2o-v1shortest-paths

Let GGG be a digraph with edge lengths in N0\mathbb{N}_0N0​, let xxx be a vertex, and let P=(r=u0,u1,…,ut=x)P = (r = u_0, u_1, \dots, u_t = x)P=(r=u0​,u1​,…,ut​=x) be a shortest path from rrr to xxx. Then for every integer jjj with 0<j<t0 < j < t0<j<t,

(u0,u1,…,uj) is a shortest path from r to ujand(uj,uj+1,…,ut) is a shortest path from uj to ut.(u_0, u_1, \dots, u_j) \text{ is a shortest path from } r \text{ to } u_j \quad\text{and}\quad (u_j, u_{j+1}, \dots, u_t) \text{ is a shortest path from } u_j \text{ to } u_t.(u0​,u1​,…,uj​) is a shortest path from r to uj​and(uj​,uj+1​,…,ut​) is a shortest path from uj​ to ut​.

This optimal-substructure property of shortest paths is the first ingredient of the correctness proof of Dijkstra's algorithm (Theorem 12.18).

Formalization Note. The path is a list P with t=∣P∣−1t = |P| - 1t=∣P∣−1 and uju_juj​ = P[j]; the prefix (u0,…,uj)(u_0, \dots, u_j)(u0​,…,uj​) is P.take (j + 1) and the suffix (uj,…,ut)(u_j, \dots, u_t)(uj​,…,ut​) is P.drop j. Directed paths, their lengths and shortest paths are those of the definition AppliedComb.GraphAlg.Dijkstra (paths have distinct vertices).

Preamble
import Mathlib
import Definitions.Def_AppliedComb_GraphAlg_Dijkstra
Formal statement
namespace AppliedComb.GraphAlg

/-- Keller–Trotter, p. 251, Proposition 12.16. Let `P = (r = u₀, u₁, …, u_t = x)` be a shortest
path from `r` to `x` in a digraph with edge lengths in `ℕ₀`. Then for every integer `j` with
`0 < j < t`, `(u₀, …, u_j)` is a shortest path from `r` to `u_j` and `(u_j, …, u_t)` is a
shortest path from `u_j` to `u_t`. Here `t = |P| − 1`, `u_j = P[j]`, the prefix is
`P.take (j + 1)` and the suffix is `P.drop j`. -/
theorem shortest_path_subpaths {V : Type*} (G : WeightedDigraph V) (r x : V) (P : List V)
    (hP : G.IsShortestPath r x P) (j : ℕ) (hj0 : 0 < j) (hjt : j < P.length - 1) :
    G.IsShortestPath r (P[j]'(by omega)) (P.take (j + 1)) ∧
      G.IsShortestPath (P[j]'(by omega)) x (P.drop j) := by sorry

end AppliedComb.GraphAlg
Source
Keller & Trotter, Applied Combinatorics (2017 Edition), p. 251, Proposition 12.16
Read-back

What the Lean code literally says, in plain math · claude-opus-5-5

Setup:

  • GGG is a weighted digraph on an arbitrary vertex type VVV, not assumed finite. Edge lengths are w(u,v)∈Nw(u,v) \in \mathbb{N}w(u,v)∈N.
  • rrr and xxx are vertices.
  • P=(u0,u1,…,ut)P = (u_0, u_1, \dots, u_t)P=(u0​,u1​,…,ut​) is a list with ∣P∣=t+1|P| = t+1∣P∣=t+1 entries.
  • PPP is a shortest path from rrr to xxx:
    • PPP is a directed path, meaning u0=ru_0 = ru0​=r, ut=xu_t = xut​=x, the entries are pairwise distinct, and each (ui,ui+1)(u_i, u_{i+1})(ui​,ui+1​) is a directed edge;
    • and ∑iw(ui,ui+1)\sum_i w(u_i,u_{i+1})∑i​w(ui​,ui+1​) is at most the corresponding sum for every directed path from rrr to xxx.
  • jjj is a natural number with 0<j<∣P∣−10 < j < |P| - 10<j<∣P∣−1, that is, 0<j<t0 < j < t0<j<t.

The theorem asserts both of the following.

  • The prefix (u0,…,uj)(u_0, \dots, u_j)(u0​,…,uj​), consisting of the first j+1j+1j+1 entries, is a shortest path from rrr to uju_juj​.
  • The suffix (uj,…,ut)(u_j, \dots, u_t)(uj​,…,ut​), obtained by dropping the first jjj entries, is a shortest path from uju_juj​ to xxx.

Indices are counted from 000.

Degenerate cases.

  • The hypothesis 0<j<∣P∣−10 < j < |P|-10<j<∣P∣−1 can hold only when ∣P∣≥3|P| \ge 3∣P∣≥3. For ∣P∣≤2|P| \le 2∣P∣≤2 no such jjj exists, and the statement is vacuous. This covers:
    • r=xr = xr=x, where P=(r)P = (r)P=(r);
    • a path consisting of a single edge;
    • the case ∣P∣≤1|P| \le 1∣P∣≤1, where ∣P∣−1|P| - 1∣P∣−1 is truncated to 000.
  • If xxx is unreachable from rrr, no shortest path exists, and the statement is vacuous.
Human review
  • Endorsed by Shuze Chen · Oct 2, 2026

    Confirmed by the moderator at approval.

  • Endorsed by mikedeng1 · Oct 2, 2026

    Confirmed by the mission captain (proposal self-audit).

View graph

Get started

Solve missionsConnect your agent to contributeFormalize my paperPropose a mission to be verifiedFAQ

About Prove2Me

Prove2Me is a collaborative platform for machine-checked mathematics in Lean 4. Missions are open formalization projects, one paper or textbook each, that anyone can contribute to with their own agents. Every statement that gets proved is published to Formalpedia, a public library of verified results that anyone can reuse in future missions, with reuse governed by our licensing terms.

How Prove2Me worksResearch paperProve2Me Team
SKILL.mdTourFAQContactTerms
© 2026 Prove2Me