Skip to content

Commit 27538c0

Browse files
nikswamyCopilot
andcommitted
BFS: prove shortest-path optimality (∀w k. reachable_in(w,k) ⟹ dist[w] ≤ k)
Added dist_optimal, layer_complete, queue_dist_min predicates and pigeonhole-based proof to BFS.Impl.fst. The .fsti now exposes the optimality postcondition. A 4-vertex diamond multi-path test exercises it in ImplTest. TEST_REVIEW_REPORT.md and REVIEW.md updated; BFS is classified as Relational (pred array is non-deterministic). Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
1 parent fe934c0 commit 27538c0

6 files changed

Lines changed: 962 additions & 20 deletions

File tree

autoclrs/TEST_REVIEW_REPORT.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,7 @@ Each `ImplTest.fst` file serves as a **spec-precision validation test**: it cons
187187
| 16 | Huffman Tree | **Precise Relational** | ✅ Precise | **Comprehensive** | Cost + multiset + optimality + leaf labels | 0 | None — optimality + leaf label mapping |
188188
| 16 | Huffman Codec | Deterministic | ✅ Precise | **Comprehensive** | Encode + Decode | 0 | None |
189189
| 21 | Union-Find | Relational | ✅ Precise | Moderate | 3 ops (make, find, 2× union) | 0 | Rank bound degrades per union (log bound unformalized) |
190-
| 22 | BFS | Relational | ✅ Precise | Moderate | 1 (3-vertex, distance precision) | 0 | Shortest-path follows from unique paths; general graphs need optimality clause |
190+
| 22 | BFS | Relational | ✅ Precise | Moderate | 2 (3-vertex chain, 4-vertex diamond) | 0 | None — shortest-path optimality proven |
191191
| 22 | DFS | Relational | ✅ Precise | Moderate | 2 (3-vertex chain, timestamps + predecessors) | 0 | Edge classification not exposed; white-path theorem not in Impl |
192192
| 22 | Topological Sort | **Relational** | ✅ Precise | Moderate | 1 Pulse + 2 pure helpers (3-vertex DAG) | 0 | None — correctly relational |
193193
| 23 | Kruskal | Relational | ✅ Precise | Moderate | 1 Pulse + 6 helper lemmas (3-vertex triangle) | 0 | None — `is_mst` proven, unique MST edges derived |
@@ -233,7 +233,7 @@ Many specs were improved in this revision cycle. Key improvements include:
233233
| LCS | Range constraints (`0 ≤ result ≤ min(m,n)`) added to postcondition |
234234
| Huffman Tree | `tree_leaf_labels_valid` added to postcondition |
235235
| Union-Find | Rank bound clauses + membership clause added; multi-step unions tested |
236-
| BFS | Distance precision proven via uniqueness lemmas; predecessor consistency tested |
236+
| BFS | Shortest-path optimality proven (`∀w k. reachable_in(source,w,k) ⟹ dist[w] ≤ k`); 4-vertex diamond multi-path test added exercising optimality postcondition; distance precision via upper+lower bounds |
237237
| DFS | Timestamp bounds (`d[u] ≤ 2n`, `f[u] ≤ 2n`) added; predecessor finish ordering (`f[v] < f[pred[v]]`); predecessor values derived from graph structure; postcondition now **Precise** — uniquely determines all timestamps |
238238
| Prim | Full MST property proven via `prim_mst_result``is_mst`; concrete output uniqueness (`key[1]=1, parent[1]=0, key[2]=2, parent[2]=1`); `key_parent_consistent` tracked; ImplTestHelper with witness spanning tree and uniqueness lemmas |
239239
| Kruskal | Full MST property proven via `kruskal_mst_result``is_mst`; unique MST edges derived (`{(0,1) w=1, (1,2) w=2}`); ImplTestHelper with `kruskal_witness_spanning_tree`, `kruskal_mst_edges`, connectivity lemmas |
@@ -279,6 +279,7 @@ These specs allow multiple correct outputs by design — the algorithm has legit
279279
| Algorithm | Why Relational | Constraining Properties |
280280
|-----------|---------------|------------------------|
281281
| Partition (Ch07) | Pivot choice not prescribed | Left ≤ pivot < right, permutation preserved |
282+
| BFS (Ch22) | Multiple shortest-path predecessors possible | `dist` uniquely determined (optimal), `pred` satisfies `dist[v] == dist[pred[v]] + 1` |
282283
| Activity Selection (Ch16) | Multiple maximum-cardinality selections | Count optimal, earliest-compatible |
283284
| Huffman Tree (Ch16) | Multiple trees with same optimal WPL | Multiset preserved, WPL optimal, leaf labels valid |
284285
| Kruskal (Ch23) | Multiple MSTs possible for equal-weight edges | `is_mst` (spanning + minimum weight), forest, edge membership |

0 commit comments

Comments
 (0)