Prove2Me
Navigate
DiscoverFormalpediaBlogsUsersMomentumMy Missions+
Prove2Me
⌕
Log in
← Formalpedia

Algorithm 97 computes every shortest path length

Proved
FloydAlgorithms.ShortestPath.algorithm97_eq_shortestLength

by mikedeng1 · Oct 4, 2026 · Mathlib 0df444a (Lean v4.33.1)

directed-graphsdynamic-programmingp2o-batch-pfp1ap2o-gran-per-chapterp2o-plan-paperp2o-v1shortest-path

Let www assign a real length to every direct link in a directed network of nnn points, with ∞\infty∞ where no direct link exists. Assume every closed path in the network has nonnegative length. For all points iii and jjj, Floyd's Algorithm 97 leaves in entry (i,j)(i,j)(i,j) exactly the shortest path length:

shortestPath⁡(w)(i,j)=dw(i,j).\operatorname{shortestPath}(w)(i,j)=d_w(i,j).shortestPath(w)(i,j)=dw​(i,j).

The equality also says that the final entry is ∞\infty∞ when no path exists. It characterizes the complete output matrix, including diagonal entries and negative individual links.

Formalization Note The no-negative-cycle condition is added because the paper omits a necessary premise: on a one-point network with self-link length −1-1−1, the procedure produces −2-2−2 instead of the shortest simple closed-path length −1-1−1. The paper's finite sentinel ₁₀10 is represented as ∞\infty∞, indices are zero-based, and arithmetic is exact real arithmetic. No nonnegativity of individual links or zero diagonal is assumed.

Preamble
import Mathlib
import Definitions.Def_FloydAlgorithms_ShortestPath_Network
import Definitions.Def_FloydAlgorithms_ShortestPath_Algorithm97
Formal statement
namespace FloydAlgorithms.ShortestPath

/-- Algorithm 97, comment, third and fourth sentences, p. 345. The
no-negative-cycle condition repairs the paper's unstated necessary premise. -/
theorem algorithm97_eq_shortestLength {n : ℕ} (w : LengthMatrix n)
    (hcycle : NoNegativeCycle w) (i j : Fin n) :
    algorithm97 w i j = shortestLength w i j := by sorry

end FloydAlgorithms.ShortestPath
Source
Floyd, Algorithm 97: Shortest Path, Communications of the ACM 5(6) (1962), p. 345, comment, third and fourth sentences; https://doi.org/10.1145/367766.368168
Human review
  • Endorsed by Shuze Chen · Oct 4, 2026

    Confirmed by the moderator at approval.

  • Endorsed by mikedeng1 · Oct 4, 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 paper
SKILL.mdTourFAQContactTerms
© 2026 Prove2Me