Motivation
Routing and network optimization often require the length of the best route between every ordered pair of points. Robert W. Floyd's Algorithm 97 gives a compact procedure for this task: it receives a matrix of direct-link lengths and changes the matrix in place until each entry is meant to represent a shortest-path length. The procedure is a small historical source for an algorithm now used as a standard all-pairs shortest-path routine. Its published text consists of the ALGOL code and a short explanatory comment, without a correctness proof.
The same page contains Floyd's Algorithm 96, a Boolean procedure for ancestor relations. Its output records whether a chain of parent links connects two individuals. Floyd cites Warshall's theorem on Boolean matrices in both comments. The Boolean procedure and the length procedure use the same order of three loops; together they expose the distinction between discovering that a route exists and determining its best length. This mission formalizes both claims from Floyd's published page, with the shortest-path statement as its goal.
Setting
A directed network has n numbered points. Its length matrix w assigns a real number w(i,j) to a direct link from i to j. The value ∞ means that the direct link is absent. Links may have negative lengths, and the initial diagonal entries w(i,i) are unrestricted. The paper's matrix index range is 1,…,n; the Lean development uses 0,…,n−1 in the same order.
A path from i to j is a sequence p0=i,p1,…,pL=j with L≥1 links. The points p0,…,pL−1 are distinct, as are p1,…,pL. Thus a path between different points has no repeated point, while a path from a point to itself is a simple closed path with at least one link. Its length is ℓw(p)=∑t=0L−1w(pt,pt+1); a missing link gives length ∞. Write dw(i,j) for the minimum length among these paths, taking dw(i,j)=∞ when there is no finite-length path. Since L≤n, this is a minimum over a finite family.
The no-negative-cycle condition says that every closed path has nonnegative length. Individual links can still be negative. This condition matters because, in a network with a negative cycle, repeated travel around that cycle can keep reducing a walk's length. Floyd's comment does not state the condition, although the claimed output needs it.
Algorithm 97 scans a pivot i, then row j, then column k, each in increasing order. It enters the column scan when the current m(j,i) is finite; if the current m(i,k) is also finite, it computes s=m(j,i)+m(i,k) and replaces m(j,k) when s<m(j,k). Every replacement affects subsequent reads of the same matrix. Algorithm 96 makes the corresponding Boolean update: when m(j,i) and m(i,k) are true, it sets m(j,k) to true.
Formalization targets
Reachability and missing paths
For Algorithm 96, let b+ be the transitive closure of the initial parent relation b, using chains of one or more links. Its comment asserts
ancestor(b)(i,j)=true⟺ib+j.
For Algorithm 97, the separate unreachable-pair sentence asserts that, whenever no finite-length path runs from i to j,
shortestPath(w)(i,j)=∞.
This second target needs no condition on cycle lengths. Both statements are milestones because they are claims printed in the two algorithm comments, rather than lemmas invented for the formalization.
Complete shortest-path matrix
The goal is the whole output claim of Algorithm 97. For every n, every matrix w with no negative cycle, and all points i,j,
shortestPath(w)(i,j)=dw(i,j).
The equality includes paths with negative individual links, diagonal entries, and unreachable pairs. It fixes the entire final matrix, rather than only an upper or lower bound.
Significance
The goal connects an explicit in-place matrix program with a route-based definition of shortest length. Once established, it permits later formal developments to use the procedure as a justified all-pairs distance computation, including networks whose individual links have negative lengths. The Boolean milestone similarly identifies the final state of an ancestor procedure with the transitive closure of the initial relation. Neither assertion requires treating an implementation's output as the definition of the mathematical answer.
Floyd's 1962 paper states these outcomes but supplies no proof. This mission supplies precise Lean statements and definitions for a proof to target. A completed machine-checked development would establish the published procedure's correctness under the missing necessary premise. The statements in this proposal are currently open theorem targets; compiling their declarations checks syntax and types, not their proofs. Supporting work on finite paths, cycle decompositions, and matrix updates can be reused in other finite directed-network arguments.
Difficulty
The array is changed in place. During a pivot's sweep, an entry used in a later update may already differ from its value at the start of that pivot. The test on m(j,i) is evaluated before the column loop, but the same entry is read again within every column iteration. A proof based only on a simultaneous, out-of-place matrix recurrence does not directly describe these reads. Negative individual links also prevent arguments that rely on every update decreasing only through a nonnegative segment. The no-negative-cycle condition must control what happens when a proposed route returns to a point already visited.
Formalization scope
Points are Fin n, including the empty network at n=0 and the single-point network at n=1. Lengths are WithTop ℝ, where ⊤ represents the paper's ₁₀10 sentinel as mathematical infinity. The paper's literal sentinel is 1010; a finite bound cannot represent arbitrarily long paths, so this mission uses infinity in its goal. The ALGOL real operations are represented by exact real arithmetic. The printed procedure's loop order, strict comparison, two finiteness guards, and immediate assignments are part of the Lean definition.
The initial diagonal is not normalized. Therefore a path from i to itself has at least one link, and the final diagonal denotes a shortest closed-path length when one exists. The Boolean comment's “is true if” is read as an equivalence, supported by its following explanation of the final matrix; chains have one or more links, matching Lean's Relation.TransGen.
The sole added hypothesis in the main goal is absence of negative cycles. It is necessary: with one point and self-link length −1, the procedure changes that entry to −2, although the shortest simple closed path has length −1. No nonnegative-link or zero-diagonal premise is imposed. The unreachable-pair milestone omits the cycle hypothesis because its claim holds without it. The benchmark dw is a finite minimum of summed link lengths, defined independently of Algorithm 97; defining it from the procedure or its recurrence would empty the goal of its intended content. Contributions proving the printed algorithms' statements, or establishing reusable finite-path and update results needed for them, fit this scope.
Selected references