Skip to content

feat(ch25): complete Floyd-Warshall path-reconstruction weight equality - #114

Merged
TankTechnology merged 1 commit into
mainfrom
feat/fw-path-weight-equality
Jul 22, 2026
Merged

feat(ch25): complete Floyd-Warshall path-reconstruction weight equality#114
TankTechnology merged 1 commit into
mainfrom
feat/fw-path-weight-equality

Conversation

@TankTechnology

Copy link
Copy Markdown
Owner

Summary

Prove that the path reconstructed from the final Floyd-Warshall predecessor matrix floydWarshallPi has weight exactly floydWarshall i j. This resolves the path-reconstruction weight-equality gap tracked in issue #95.

New lemmas

  • D_diag_eq_zero — Under NoNegCycle, D ks i i = 0 for any intermediate set ks.
  • Pi_D_ge — Optimal-substructure lower bound: if Pi ks i j = some k with i ≠ j, then D ks i k + w(k,j) ≤ D ks i j. Proved by induction on ks using only min_le_left/min_le_right from the D recurrence — avoids the difficult D-edge inequality entirely.
  • isShortestDist_edge_ineq — Edge inequality for shortest-path distances: δ(v) ≤ δ(u) + w(u,v).
  • floydWarshallPi_D_eq — Equality for the final matrices: floydWarshall i j = floydWarshall i k + w(k,j). Combines Pi_D_ge (lower bound) with isShortestDist_edge_ineq (upper bound).
  • reconstructPathFuel_isWalkFrom — The reconstructed path is a valid walk.
  • reconstructPathFuel_weight_eqMain result: the reconstructed path has weight floydWarshall i j.

Key insight

The equality is proved by separating the optimal-substructure argument into two independent bounds:

  • Lower bound (Pi_D_ge): uses only the algebraic min structure of the DP recurrence
  • Upper bound (isShortestDist_edge_ineq): uses the existing IsShortestDist property of the final Floyd-Warshall matrices

No D-edge inequality or semantic walk-through-ks lemma is required.

Verification

lake build CLRSLean        # ✓ Build completed successfully
uv run python scripts/check_repository.py  # ✓ All checks passed

Closes #95.

🤖 Generated with Claude Code

Prove that the path reconstructed from the final predecessor matrix
floydWarshallPi has weight exactly floydWarshall i j.

New lemmas:
- D_diag_eq_zero: diagonal of D is zero under NoNegCycle
- Pi_D_ge: optimal-substructure lower bound D(i,k)+w(k,j) ≤ D(i,j)
- floydWarshallPi_D_eq: equality floydWarshall i j = floydWarshall i k + w(k,j)
- reconstructPathFuel_isWalkFrom: reconstructed path is a valid walk
- reconstructPathFuel_weight_eq: reconstructed path weight equals floydWarshall

The key insight is Pi_D_ge — it proves only the lower-bound direction
by induction on ks, using min_le_left/min_le_right from the D recurrence
and entirely avoiding the difficult D-edge inequality.  The upper bound
comes from the existing isShortestDist_edge_ineq.  Together they give
equality for the final matrices.

Resolves the path-reconstruction gap in issue #95.

Co-Authored-By: Claude <noreply@anthropic.com>
@TankTechnology
TankTechnology merged commit 6663c71 into main Jul 22, 2026
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Ch25: predecessor matrix, path reconstruction, and negative-cycle detection

1 participant