feat: add 12 CS algorithm implementations with correctness proofs#383
feat: add 12 CS algorithm implementations with correctness proofs#383brando90 wants to merge 12 commits intoleanprover:mainfrom
Conversation
…eteness proofs Add depth-first search on directed adjacency-list graphs with: - `dfsAux`/`dfs` implementation with fuel-based termination - `Reachable` inductive predicate for graph reachability - `dfs_soundness`: dfs returns true → target is reachable - `ReachableAvoiding` + `dfsAux_complete_avoiding`: completeness for simple paths - Unit tests on small graphs verified via `decide` Adapted from the VeriBench benchmark. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Add breadth-first search on directed adjacency-list graphs with: - `bfsAux`/`bfs` returning shortest distance as `Option Nat` - `IsPath` inductive predicate for directed walks with path list - `IsPath.trans`/`IsPath.snoc` for path composition - `bfs_soundness`: BFS returns `some d` → a path of length `d` exists - Queue invariant `QueueInv` tracking path witnesses through BFS loop - Unit tests verified via `decide` Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
- `binarySearchAux`/`binarySearch` with fuel-based termination - `binarySearch_found`: returned index points to target element - `binarySearch_bounds`: returned index is within array bounds - Unit tests verified via `decide` Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
…oofs Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Proves sorted output, permutation preservation, and length preservation via extractMin properties (minimum bound, permutation, length decrease). Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Proves sorted output, permutation preservation, and length preservation via partition properties (element bounds, permutation, length). Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Proves sorted output, permutation preservation (via count equality), and length preservation using buildSorted and findMax properties. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Proves sublist of both inputs, length bounds, and self-LCS identity via fuel-based induction on the LCS computation. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Proves reflexivity (self-distance is 0), empty list properties, and upper bound (distance ≤ sum of lengths) via fuel-based induction. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
…oofs Implements fuel-based Dijkstra's algorithm on weighted adjacency-list graphs. Includes extractMin, dijkstraAux, dijkstra, IsWeightedPath inductive definition, weighted_path_refl, and dijkstra_start_self theorem. All proofs complete (no sorry). Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Implements fuel-based heap sort on lists of natural numbers with findLargest, heapify, buildMaxHeap, and heapSortAux. Proves swap_perm via count_set, heapSort_perm and heapSort_length. All proofs complete (no sorry). Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
|
It would be better to split the PR into multiple PRs and have one for every single algorithm so that it is easier to review. |
| def dfs (g : Graph) (start target : Nat) : Bool := | ||
| dfsAux g start target [] (g.length + 1) |
There was a problem hiding this comment.
I think a better definition would not have a target as dfs would also be of interest in further algorithms like finding connected components where one does not really search for a specific vertex.
| `g[i]` is the list of `(neighbor, weight)` pairs for node `i`. -/ | ||
| abbrev Graph := List (List (Nat × Nat)) | ||
|
|
||
| /-- Extract the minimum-distance entry from a priority queue (list of (distance, node) pairs). |
There was a problem hiding this comment.
For Dijkstra a class offering the extract and update functions might be preferable so that you can use the same algorithm with arrays, heaps and search trees.
| @@ -0,0 +1,132 @@ | |||
| /- | |||
There was a problem hiding this comment.
Several major points with this PR, hence offering the review here:
- Please use Mathlib graph definitions as a baseline.
- Please make separate PRs for the 20 algorithms
- This PR duplicates insertion sort and LCS with other PRs.
- Please space out these PRs. Dealing with a tonne of AI generated PRs is infeasible for any maintainer team of any OSS project.
- The pure Levenshtein distance already exists in mathlib. Please use this version for correctness.
yes I can seperate them latter with @patternscientist who is helping. |
@jt0202 also, I saw this: https://github.com/leanprover/cslib/blob/main/Cslib/Languages/Boole/README.md but it's empty. I anecdotally heard it's the language for CSLiB that has been already developed...when will it be pushed? So I don't have to redo the work in this PR. |
Summary
Adds 12 formally verified CS algorithm implementations ported from the VeriBench benchmark to CSLiB format. All proofs are complete (zero
sorry), all tests usedecide(notnative_decide). All files passlake build,lint-style, andmk_all.Sorting (6 files)
Graph (3 files)
Search (1 file)
Dynamic Programming (2 files)
Test plan
lake builddecidetests passlake exe lint-stylepasseslake exe mk_all --modulesucceeds🤖 Generated with Claude Code