AlgoVeri: An Aligned Benchmark for Verified Code Generation on Classical Algorithms
Paper • 2602.09464 • Published
task_id stringlengths 3 30 | lean_code stringlengths 950 3.96k |
|---|---|
ac_automata | import Mathlib
-- Precondition definitions
@[reducible, simp]
def ac_automata_search_precond (haystack : Array UInt8) (patterns : Array (Array UInt8)) : Prop :=
-- !benchmark @start precond
haystack.size < 1000000 ∧
patterns.size > 0 ∧
patterns.size < 1000000 ∧
(∀ i : Nat, i < patterns.size →
let p := p... |
bellman_ford | import Mathlib
structure WeightedGraph where
adj : Array (Array (Nat × Int))
def WeightedGraph.size (g : WeightedGraph) : Nat :=
g.adj.size
def WeightedGraph.has_edge (g : WeightedGraph) (u v : Nat) (w : Int) : Prop :=
u < g.size ∧
∃ pair, pair ∈ g.adj.getD u #[] ∧ pair.1 = v ∧ pair.2 = w
def WeightedGraph.... |
bfs | import Mathlib
structure BFSGraph where
adj : Array (Array Nat)
def BFSGraph.well_formed (g : BFSGraph) : Prop :=
∀ u, u < g.adj.size →
∀ v, v ∈ g.adj.getD u #[] → v < g.adj.size
def BFSGraph.size (g : BFSGraph) : Nat :=
g.adj.size
def BFSGraph.has_edge (g : BFSGraph) (u v : Nat) : Prop :=
u < g.adj.siz... |
binary_search | import Mathlib
-- Precondition definitions
@[reducible, simp]
def binary_search_lower_bound_precond (seq : Array Int) (target : Int) : Prop :=
-- !benchmark @start precond
seq.size ≤ 0x7FFFFFFF ∧
(∀ i j : Nat, i < j ∧ j < seq.size → seq.getD i 0 ≤ seq.getD j 0)
-- !benchmark @end precond
-- !benchmark @start ... |
bipartite_check | import Mathlib
structure BipartiteGraph where
adj : Array (Array Nat)
def BipartiteGraph.well_formed (g : BipartiteGraph) : Prop :=
∀ u, u < g.adj.size →
∀ v, v ∈ g.adj.getD u #[] → v < g.adj.size
def BipartiteGraph.size (g : BipartiteGraph) : Nat :=
g.adj.size
def BipartiteGraph.has_edge (g : BipartiteGr... |
bracket_matching | import Mathlib
-- Precondition definitions
@[reducible, simp]
def bracket_match_precond (s : Array UInt8) : Prop :=
-- !benchmark @start precond
s.size ≤ 1000000
-- !benchmark @end precond
-- !benchmark @start auxcode
-- !benchmark @end auxcode
-- Main function definition
def bracket_match (s : Array UInt8) (_... |
bst_delete | import Mathlib
inductive BinarySearchTree : Type
| Empty : BinarySearchTree
| Node : Int → BinarySearchTree → BinarySearchTree → BinarySearchTree
def view (t : BinarySearchTree) : Set Int :=
match t with
| BinarySearchTree.Empty => ∅
| BinarySearchTree.Node v l r => view l ∪ view r ∪ {v}
def is_bst (t : Binary... |
bst_insert | import Mathlib
inductive BinarySearchTree : Type
| Empty : BinarySearchTree
| Node : Int → BinarySearchTree → BinarySearchTree → BinarySearchTree
def view (t : BinarySearchTree) : Set Int :=
match t with
| BinarySearchTree.Empty => ∅
| BinarySearchTree.Node v l r => view l ∪ view r ∪ {v}
def is_bst (t : Binary... |
bst_search | import Mathlib
inductive BinarySearchTree : Type
| Empty : BinarySearchTree
| Node : Int → BinarySearchTree → BinarySearchTree → BinarySearchTree
def view (t : BinarySearchTree) : Set Int :=
match t with
| BinarySearchTree.Empty => ∅
| BinarySearchTree.Node v l r => view l ∪ view r ∪ {v}
def is_bst (t : Binary... |
bst_zig | import Mathlib
inductive BinarySearchTree : Type
| Empty : BinarySearchTree
| Node : Int → BinarySearchTree → BinarySearchTree → BinarySearchTree
deriving Inhabited
def view (t : BinarySearchTree) : Set Int :=
match t with
| BinarySearchTree.Empty => ∅
| BinarySearchTree.Node v l r => view l ∪ view r ∪ {v}
def... |
bst_zigzag | import Mathlib
inductive BinarySearchTree : Type
| Empty : BinarySearchTree
| Node : Int → BinarySearchTree → BinarySearchTree → BinarySearchTree
deriving Inhabited
def view (t : BinarySearchTree) : Set Int :=
match t with
| BinarySearchTree.Empty => ∅
| BinarySearchTree.Node v l r => view l ∪ view r ∪ {v}
def... |
bst_zigzig | import Mathlib
inductive BinarySearchTree : Type
| Empty : BinarySearchTree
| Node : Int → BinarySearchTree → BinarySearchTree → BinarySearchTree
deriving Inhabited
def view (t : BinarySearchTree) : Set Int :=
match t with
| BinarySearchTree.Empty => ∅
| BinarySearchTree.Node v l r => view l ∪ view r ∪ {v}
def... |
bubble_sort | import Mathlib
-- Precondition definitions
@[reducible, simp]
def bubble_sort_precond (v : List Int) : Prop :=
-- !benchmark @start precond
True
-- !benchmark @end precond
-- !benchmark @start auxcode
-- !benchmark @end auxcode
-- Main function definitions
def bubble_sort (v : List Int) (h_precond : bubble_sor... |
coin_change | import Mathlib
-- Precondition definitions
@[reducible, simp]
def coin_change_precond (coins : List Nat) (amount : Nat) : Prop :=
coins.length > 0 ∧
coins.length ≤ 100 ∧
amount ≤ 10000 ∧
∀ i, i < coins.length → (coins.getD i 0 > 0 ∧ coins.getD i 0 ≤ 10000)
-- !benchmark @start auxcode
-- !benchmark @end auxco... |
cycle_detection | import Mathlib
structure CycleGraph where
adj : Array (Array Nat)
def CycleGraph.well_formed (g : CycleGraph) : Prop :=
∀ u, u < g.adj.size →
∀ v, v ∈ g.adj.getD u #[] → v < g.adj.size
def CycleGraph.size (g : CycleGraph) : Nat :=
g.adj.size
def CycleGraph.has_edge (g : CycleGraph) (u v : Nat) : Prop :=
... |
dfs | import Mathlib
structure DFSGraph where
adj : Array (Array Nat)
def DFSGraph.well_formed (g : DFSGraph) : Prop :=
∀ u, u < g.adj.size →
∀ v, v ∈ g.adj.getD u #[] → v < g.adj.size
def DFSGraph.size (g : DFSGraph) : Nat :=
g.adj.size
def DFSGraph.has_edge (g : DFSGraph) (u v : Nat) : Prop :=
u < g.adj.siz... |
dijkstra | import Mathlib
structure WeightedGraph where
adj : Array (Array (Nat × Int))
def WeightedGraph.size (g : WeightedGraph) : Nat :=
g.adj.size
def WeightedGraph.has_edge (g : WeightedGraph) (u v : Nat) (w : Int) : Prop :=
u < g.size ∧
∃ pair, pair ∈ g.adj.getD u #[] ∧ pair.1 = v ∧ pair.2 = w
def WeightedGraph.... |
discrete_logarithm | import Mathlib
-- Precondition definitions
@[reducible, simp]
def discrete_log_naive_precond (g h p : UInt64) : Prop :=
-- !benchmark @start precond
p.toNat > 1
-- !benchmark @end precond
def is_discrete_log (g h p : Nat) (x : Nat) : Prop :=
(Nat.pow g x) % p = h % p
-- !benchmark @start auxcode
-- !benchmar... |
edmond_karp | import Mathlib
structure CapacityGraph where
adj : Array (Array (Nat × Int))
def CapacityGraph.size (g : CapacityGraph) : Nat :=
g.adj.size
def CapacityGraph.has_capacity (g : CapacityGraph) (u v : Nat) (c : Int) : Prop :=
u < g.size ∧
∃ pair, pair ∈ g.adj.getD u #[] ∧ pair.1 = v ∧ pair.2 = c
def CapacityGr... |
fast_exponential | import Mathlib
-- Precondition definitions
@[reducible, simp]
def exponentiation_precond (b e : UInt64) : Prop :=
-- !benchmark @start precond
b.toNat ^ e.toNat ≤ (2 ^ 64 - 1)
-- !benchmark @end precond
-- !benchmark @start auxcode
-- !benchmark @end auxcode
-- Main function definitions
def exponentiation (b e... |
gcd | import Mathlib
-- Precondition definitions
@[reducible, simp]
def compute_gcd_precond (a : UInt64) (b : UInt64) : Prop :=
-- !benchmark @start precond
True
-- !benchmark @end precond
-- !benchmark @start auxcode
-- !benchmark @end auxcode
-- Main function definitions
def compute_gcd (a : UInt64) (b : UInt64) (... |
gcd_new | import Mathlib
-- Precondition definitions
@[reducible, simp]
def compute_gcd_precond (a b : UInt64) : Prop :=
-- !benchmark @start precond
True
-- !benchmark @end precond
-- Mathematical definition of divisibility
def divides (d n : Nat) : Prop :=
∃ k, d * k = n
-- Predicate defining the properties of the G... |
house_robber | import Mathlib
def seq_u64_to_int (xs : List Nat) : List Nat := xs
def is_valid_robbery (houses : List Nat) (len : Nat) : Prop :=
(∀ i, i < houses.length → houses.getD i 0 < len) ∧
(∀ i, i < houses.length - 1 → houses.getD (i+1) 0 ≥ houses.getD i 0 + 2)
def total_loot (houses : List Nat) (values : List Nat) : Na... |
insertion_sort | import Mathlib
-- Precondition definitions
@[reducible, simp]
def insertionSort_precond (v : List Int) : Prop :=
-- !benchmark @start precond
True
-- !benchmark @end precond
-- !benchmark @start auxcode
-- !benchmark @end auxcode
-- Main function definitions
def insertionSort (v : List Int) (h_precond : insert... |
integer_exponential | import Mathlib
-- Precondition definitions
@[reducible, simp]
def exponentiation_precond (b e : Nat) : Prop :=
-- !benchmark @start precond
True
-- !benchmark @end precond
-- !benchmark @start auxcode
-- !benchmark @end auxcode
-- Main function definitions
def exponentiation (b e : Nat) (h_precond : exponentia... |
jump_game | import Mathlib
-- Precondition definition
@[reducible, simp]
def can_jump_precond (nums : List Nat) : Prop :=
-- !benchmark @start precond
0 < nums.length ∧
nums.length ≤ 10000 ∧
(∀ i, i < nums.length → nums.getD i 0 ≤ 10000)
-- !benchmark @end precond
def is_valid_jump_path (path : List Nat) (nums : List N... |
k_smallest | import Mathlib
-- Precondition definitions
@[reducible, simp]
def quick_select_precond (v : Array Int) (k : Nat) : Prop :=
-- !benchmark @start precond
k < v.size
-- !benchmark @end precond
-- !benchmark @start auxcode
-- !benchmark @end auxcode
-- Main function definitions
def quick_select (v : Array Int) (k ... |
kmp | import Mathlib
-- Precondition definitions
@[reducible, simp]
def kmpSearch_precond (haystack : Array UInt8) (needle : Array UInt8) : Prop :=
-- !benchmark @start precond
haystack.size < 1000000 ∧
needle.size < 1000000
-- !benchmark @end precond
-- !benchmark @start auxcode
-- !benchmark @end auxcode
-- Mai... |
knapsack_01 | import Mathlib
def total_weight (selected : List Bool) (weights : List Nat) : Nat :=
match selected, weights with
| [], _ => 0
| _, [] => 0
| b :: bs, w :: ws => (if b then w else 0) + total_weight bs ws
def total_value (selected : List Bool) (values : List Nat) : Nat :=
match selected, values with
| [], ... |
knapsack_unbounded | import Mathlib
/-! ### Precondition definitions -/
def solve_knapsack_unbounded_precond (weights values : List Nat) (capacity : Nat) : Prop :=
(weights.length = values.length) ∧
(weights.length > 0) ∧
(capacity ≤ 1000) ∧
(∀ i, i < weights.length → weights.getD i 0 > 0) ∧
(∀ i, i < weights.length → weights.g... |
kruskal | import Mathlib
structure WeightedGraph where
adj : Array (Array (Nat × Int))
def WeightedGraph.size (g : WeightedGraph) : Nat :=
g.adj.size
def WeightedGraph.has_edge (g : WeightedGraph) (u v : Nat) (w : Int) : Prop :=
u < g.size ∧
∃ pair, pair ∈ g.adj.getD u #[] ∧ pair.1 = v ∧ pair.2 = w
def WeightedGraph.... |
lca | import Mathlib
inductive Node where
| nil
| node (val : Nat) (left : Node) (right : Node)
deriving Inhabited, Repr
open Node
def view (t : Node) : Set Nat :=
match t with
| nil => ∅
| node v l r => {v} ∪ view l ∪ view r
def tree_contains (t : Node) (target : Nat) : Bool :=
match t with
| nil => false
... |
linear_search | import Mathlib
-- Precondition definitions
@[reducible, simp]
def linear_search_lower_bound_precond (seq : Array Int) (target : Int) : Prop :=
-- !benchmark @start precond
seq.size ≤ 0x7FFFFFFF ∧
(∀ i j : Nat, i < j ∧ j < seq.size → seq.getD i 0 ≤ seq.getD j 0)
-- !benchmark @end precond
-- !benchmark @start ... |
linearsys_gf2 | import Mathlib
-- Precondition definitions
@[reducible, simp]
def solve_linear_system_gf2_precond (matrix : List (List Nat)) (b : List Nat) : Prop :=
-- !benchmark @start precond
matrix.length > 0 ∧
(matrix.getD 0 []).length > 0 ∧
matrix.length = b.length ∧
matrix.length ≤ 100 ∧
(matrix.getD 0 []).length ≤... |
llrbt_delete | import Mathlib
inductive Color
| Red
| Black
deriving Inhabited, BEq
inductive Node
| Empty : Node
| Tree (color : Color) (val : Int) (left : Node) (right : Node) : Node
deriving Inhabited
def view (t : Node) : Set Int :=
match t with
| Node.Empty => ∅
| Node.Tree _ v l r => view l ∪ view r ∪ {v}
def is_red ... |
llrbt_flipcolor | import Mathlib
inductive Color
| Red
| Black
deriving Inhabited, BEq
inductive Node
| Empty : Node
| Tree (color : Color) (val : Int) (left : Node) (right : Node) : Node
deriving Inhabited
def view (t : Node) : Set Int :=
match t with
| Node.Empty => ∅
| Node.Tree _ v l r => view l ∪ view r ∪ {v}
def is_red ... |
llrbt_insert | import Mathlib
inductive Color
| Red
| Black
deriving Inhabited, BEq
inductive Node
| Empty : Node
| Tree (color : Color) (val : Int) (left : Node) (right : Node) : Node
deriving Inhabited
def view (t : Node) : Set Int :=
match t with
| Node.Empty => ∅
| Node.Tree _ v l r => view l ∪ view r ∪ {v}
def is_red ... |
llrbt_rotateleft | import Mathlib
inductive Color
| Red
| Black
deriving Inhabited, BEq
inductive Node
| Empty : Node
| Tree (color : Color) (val : Int) (left : Node) (right : Node) : Node
deriving Inhabited
def view (t : Node) : Set Int :=
match t with
| Node.Empty => ∅
| Node.Tree _ v l r => view l ∪ view r ∪ {v}
def is_red ... |
llrbt_rotateright | import Mathlib
inductive Color
| Red
| Black
deriving Inhabited, BEq
inductive Node
| Empty : Node
| Tree (color : Color) (val : Int) (left : Node) (right : Node) : Node
deriving Inhabited
def view (t : Node) : Set Int :=
match t with
| Node.Empty => ∅
| Node.Tree _ v l r => view l ∪ view r ∪ {v}
def is_red ... |
longest_common_subsequence | import Mathlib
def lcs_spec (s t : List Char) : Nat :=
match s, t with
| [], _ => 0
| _, [] => 0
| x :: xs, y :: ys =>
if x = y then 1 + lcs_spec xs ys
else max (lcs_spec xs (y :: ys)) (lcs_spec (x :: xs) ys)
-- Precondition definitions
@[reducible, simp]
def solve_longest_common_subsequence_precond (... |
longest_increasing_subsequence | import Mathlib
-- Precondition definitions
@[reducible, simp]
def longest_increasing_subsequence_precond (seq : List Int) : Prop :=
-- !benchmark @start precond
True
-- !benchmark @end precond
-- !benchmark @start auxcode
-- !benchmark @end auxcode
-- Main function definition
def longest_increasing_subsequenc... |
longest_palindrome_substring | import Mathlib
-- Precondition definitions
@[reducible, simp]
def longest_palindromic_substring_precond (s : Array UInt8) : Prop :=
-- !benchmark @start precond
s.size ≤ 1000000
-- !benchmark @end precond
-- !benchmark @start auxcode
-- !benchmark @end auxcode
-- Main function definitions
def longest_palindrom... |
matrix_multiplication | import Mathlib
-- Precondition definitions
@[reducible, simp]
def matrix_multiply_precond (A B : List (List Nat)) : Prop :=
-- !benchmark @start precond
A.length > 0 ∧
A.length ≤ 10 ∧ -- Aligned with Dafny/Verus (10)
(∀ row, row ∈ A → row.length > 0) ∧
(∀ row, row ∈ A → row.length ≤ 10) ∧
(∀ i j, i < A.len... |
max_matching | import Mathlib
structure MaxMatchingGraph where
left_size : Nat
right_size : Nat
adj : Array (Array Nat)
def MaxMatchingGraph.well_formed (g : MaxMatchingGraph) : Prop :=
g.adj.size = g.left_size ∧
∀ u, u < g.left_size →
∀ v, v ∈ g.adj.getD u #[] → v < g.right_size
def MaxMatchingGraph.has_edge (g : Ma... |
maxheap_popmax | import Mathlib
structure BinaryMaxHeap where
storage : List Int
deriving Inhabited
namespace BinaryMaxHeap
def len (h : BinaryMaxHeap) : Nat :=
h.storage.length
def get (h : BinaryMaxHeap) (i : Nat) : Int :=
h.storage.getD i 0
def parent (i : Nat) : Nat := (i - 1) / 2
def is_heap (h : BinaryMaxHeap) : Prop ... |
maxheap_push | import Mathlib
structure BinaryMaxHeap where
storage : List Int
deriving Inhabited
namespace BinaryMaxHeap
def len (h : BinaryMaxHeap) : Nat :=
h.storage.length
def get (h : BinaryMaxHeap) (i : Nat) : Int :=
h.storage.getD i 0 -- Safe access with default
def parent (i : Nat) : Nat := (i - 1) / 2
def is_heap... |
maximum_subarray_sum | import Mathlib
-- Precondition definitions
@[reducible, simp]
def maxSubarraySum_precond (seq : List Int) : Prop :=
-- !benchmark @start precond
0 < seq.length ∧ seq.length ≤ 100000
-- !benchmark @end precond
def spec_sum (seq : List Int) (i j : Nat) : Int :=
((seq.drop i).take (j - i)).foldl (fun acc x => ac... |
merge_sort | import Mathlib
-- Precondition definitions
@[reducible, simp]
def mergeSort_precond (v : List Int) : Prop :=
-- !benchmark @start precond
True
-- !benchmark @end precond
-- !benchmark @start auxcode
-- !benchmark @end auxcode
-- Main function definitions
def mergeSort (v : List Int) (h_precond : mergeSort_prec... |
polymul_karatsuba | import Mathlib
-- Precondition definitions
@[reducible, simp]
def karatsuba_mul_precond (a b : List Int) : Prop :=
-- !benchmark @start precond
a.length > 0 ∧
b.length > 0 ∧
a.length + b.length ≤ 1000 ∧
(∃ k : Nat, 2 ^ k = a.length) ∧
(∃ k : Nat, 2 ^ k = b.length) ∧
a.length = b.length ∧
(∀ c, c ∈ a → ... |
polymul_naive | import Mathlib
-- Precondition definitions
@[reducible, simp]
def poly_multiply_precond (a b : List Int) : Prop :=
-- !benchmark @start precond
a.length > 0 ∧
b.length > 0 ∧
a.length + b.length ≤ 1000 ∧
(∀ c, c ∈ a → -1000000 ≤ c ∧ c ≤ 1000000) ∧
(∀ c, c ∈ b → -1000000 ≤ c ∧ c ≤ 1000000)
-- !benchmark @e... |
prim | import Mathlib
structure WeightedGraph where
adj : Array (Array (Nat × Int))
def WeightedGraph.size (g : WeightedGraph) : Nat :=
g.adj.size
def WeightedGraph.has_edge (g : WeightedGraph) (u v : Nat) (w : Int) : Prop :=
u < g.size ∧
∃ pair, pair ∈ g.adj.getD u #[] ∧ pair.1 = v ∧ pair.2 = w
def WeightedGraph.... |
push_relabel | import Mathlib
structure CapacityGraph where
adj : Array (Array (Nat × Int))
def CapacityGraph.size (g : CapacityGraph) : Nat :=
g.adj.size
def CapacityGraph.has_capacity (g : CapacityGraph) (u v : Nat) (c : Int) : Prop :=
u < g.size ∧
∃ pair, pair ∈ g.adj.getD u #[] ∧ pair.1 = v ∧ pair.2 = c
def CapacityGr... |
queue_dequeue | import Mathlib
structure VerifiableQueue (T : Type) where
data : List T
def VerifiableQueue.view {T} (q : VerifiableQueue T) : List T :=
q.data
def VerifiableQueue.is_valid {T} (q : VerifiableQueue T) : Prop :=
True
-- Precondition definitions
@[reducible, simp]
def dequeue_precond {T} (q : VerifiableQueue T)... |
queue_enqueue | import Mathlib
structure VerifiableQueue (T : Type) where
data : List T
def VerifiableQueue.view {T} (q : VerifiableQueue T) : List T :=
q.data
def VerifiableQueue.is_valid {T} (q : VerifiableQueue T) : Prop :=
True
-- Precondition definitions
@[reducible, simp]
def enqueue_precond {T} (q : VerifiableQueue T)... |
quick_sort | import Mathlib
-- Precondition definitions
@[reducible, simp]
def quickSort_precond (v : List Int) : Prop :=
-- !benchmark @start precond
True
-- !benchmark @end precond
-- !benchmark @start auxcode
-- !benchmark @end auxcode
-- Main function definitions
def quickSort (v : List Int) (h_precond : quickSort_prec... |
ringbuffer_dequeue | import Mathlib
structure RingBuffer (T : Type) where
capacity : Nat
view : List T
def RingBuffer.is_valid {T} (rb : RingBuffer T) : Prop :=
rb.capacity > 0 ∧ rb.view.length ≤ rb.capacity
-- Precondition definitions
@[reducible, simp]
def dequeue_precond {T} (rb : RingBuffer T) : Prop :=
-- !benchmark @start ... |
ringbuffer_enqueue | import Mathlib
structure RingBuffer (T : Type) where
capacity : Nat
view : List T
def RingBuffer.is_valid {T} (rb : RingBuffer T) : Prop :=
rb.capacity > 0 ∧ rb.view.length ≤ rb.capacity
-- Precondition definitions
@[reducible, simp]
def enqueue_precond {T} (rb : RingBuffer T) (v : T) : Prop :=
-- !benchmark... |
rod_cutting | import Mathlib
def sum_lengths (cuts : List Nat) : Nat :=
cuts.foldl (· + ·) 0
def get_price (prices : List Nat) (len : Nat) : Nat :=
if len > 0 then prices.getD (len - 1) 0 else 0
def calculate_revenue (cuts : List Nat) (prices : List Nat) : Nat :=
cuts.foldl (fun acc len => acc + get_price prices len) 0
def... |
scc_tarjan | import Mathlib
structure SCCGraph where
adj : Array (Array Nat)
def SCCGraph.well_formed (g : SCCGraph) : Prop :=
∀ u, u < g.adj.size →
∀ v, v ∈ g.adj.getD u #[] → v < g.adj.size
def SCCGraph.size (g : SCCGraph) : Nat :=
g.adj.size
def SCCGraph.has_edge (g : SCCGraph) (u v : Nat) : Prop :=
u < g.adj.siz... |
segmenttree_build | import Mathlib
inductive Node
| mk (val : Int) (low high : Int) (left right : Option Node)
deriving Inhabited
namespace Node
def val (t : Node) : Int :=
match t with | Node.mk v _ _ _ _ => v
def low (t : Node) : Int :=
match t with | Node.mk _ l _ _ _ => l
def high (t : Node) : Int :=
match t with | Node.mk ... |
segmenttree_modify | import Mathlib
inductive Node
| mk (val : Int) (low high : Int) (left right : Option Node)
deriving Inhabited
namespace Node
def val (t : Node) : Int :=
match t with | Node.mk v _ _ _ _ => v
def low (t : Node) : Int :=
match t with | Node.mk _ l _ _ _ => l
def high (t : Node) : Int :=
match t with | Node.mk ... |
segmenttree_query | import Mathlib
inductive Node
| mk (val : Int) (low high : Int) (left right : Option Node)
deriving Inhabited
namespace Node
def val (t : Node) : Int :=
match t with | Node.mk v _ _ _ _ => v
def low (t : Node) : Int :=
match t with | Node.mk _ l _ _ _ => l
def high (t : Node) : Int :=
match t with | Node.mk ... |
sieve_method | import Mathlib
-- Precondition definitions
@[reducible, simp]
def sieve_of_eratosthenes_precond (n : Nat) : Prop :=
-- !benchmark @start precond
n ≤ 100_000
-- !benchmark @end precond
-- !benchmark @start auxcode
-- !benchmark @end auxcode
-- Main function definitions
def sieve_of_eratosthenes (n : Nat) (h_pre... |
splaytree_splay | import Mathlib
inductive SplayTree
| empty
| node (val : Int) (left right : SplayTree)
deriving Inhabited
namespace SplayTree
def view (t : SplayTree) : Set Int :=
match t with
| empty => ∅
| node v l r => view l ∪ view r ∪ {v}
termination_by sizeOf t
def is_bst (t : SplayTree) : Prop :=
match t with
| em... |
stack_pop | import Mathlib
structure VerifiableStack (T : Type) where
data : List T
def VerifiableStack.view {T} (s : VerifiableStack T) : List T :=
s.data
def VerifiableStack.is_valid {T} (s : VerifiableStack T) : Prop :=
True
-- Precondition definitions
@[reducible, simp]
def pop_precond {T} (s : VerifiableStack T) : P... |
stack_push | import Mathlib
structure VerifiableStack (T : Type) where
data : List T
def VerifiableStack.view {T} (s : VerifiableStack T) : List T :=
s.data
def VerifiableStack.is_valid {T} (s : VerifiableStack T) : Prop :=
True
-- Precondition definitions
@[reducible, simp]
def push_precond {T} (s : VerifiableStack T) (v... |
string_search_naive | import Mathlib
-- Precondition definitions
@[reducible, simp]
def naive_search_precond (haystack : Array UInt8) (needle : Array UInt8) : Prop :=
-- !benchmark @start precond
haystack.size < 1000000 ∧
needle.size < 1000000
-- !benchmark @end precond
-- !benchmark @start auxcode
-- !benchmark @end auxcode
-- ... |
ternarysearchtree_delete | import Mathlib
inductive Node
| mk (val : Int) (is_end : Bool) (left mid right : Option Node)
deriving Inhabited
namespace Node
def val (t : Node) : Int :=
match t with | Node.mk v _ _ _ _ => v
def is_end (t : Node) : Bool :=
match t with | Node.mk _ b _ _ _ => b
def left (t : Node) : Option Node :=
match t ... |
ternarysearchtree_insert | import Mathlib
inductive Node
| mk (val : Int) (is_end : Bool) (left mid right : Option Node)
deriving Inhabited
namespace Node
def val (t : Node) : Int :=
match t with | Node.mk v _ _ _ _ => v
def is_end (t : Node) : Bool :=
match t with | Node.mk _ b _ _ _ => b
def left (t : Node) : Option Node :=
match t ... |
ternarysearchtree_search | import Mathlib
inductive Node
| mk (val : Int) (is_end : Bool) (left mid right : Option Node)
deriving Inhabited
namespace Node
def val (t : Node) : Int :=
match t with | Node.mk v _ _ _ _ => v
def is_end (t : Node) : Bool :=
match t with | Node.mk _ b _ _ _ => b
def left (t : Node) : Option Node :=
match t ... |
topological_sort | import Mathlib
structure TopoGraph where
adj : Array (Array Nat)
def TopoGraph.well_formed (g : TopoGraph) : Prop :=
∀ u, u < g.adj.size →
∀ v, v ∈ g.adj.getD u #[] → v < g.adj.size
def TopoGraph.size (g : TopoGraph) : Nat :=
g.adj.size
def TopoGraph.has_edge (g : TopoGraph) (u v : Nat) : Prop :=
u < g.... |
trial_division_naive | import Mathlib
-- Precondition definitions
@[reducible, simp]
def check_prime_precond (n : Nat) : Prop :=
-- !benchmark @start precond
True
-- !benchmark @end precond
-- !benchmark @start auxcode
-- !benchmark @end auxcode
-- Main function definitions
def check_prime (n : Nat) (h_precond : check_prime_precond ... |
trial_division_optimized | import Mathlib
-- Precondition definitions
@[reducible, simp]
def check_prime_precond (n : Nat) : Prop :=
-- !benchmark @start precond
True
-- !benchmark @end precond
-- !benchmark @start auxcode
-- !benchmark @end auxcode
-- Main function definitions
def check_prime (n : Nat) (h_precond : check_prime_precond ... |
trie_delete | import Mathlib
inductive Node
| mk (is_end : Bool) (children : List (Option Node))
deriving Inhabited
namespace Node
def is_end (t : Node) : Bool :=
match t with
| Node.mk b _ => b
def children (t : Node) : List (Option Node) :=
match t with
| Node.mk _ c => c
end Node
-- Helper for enum behavior
def enum... |
trie_insert | import Mathlib
inductive Node
| mk (is_end : Bool) (children : List (Option Node))
deriving Inhabited
namespace Node
def is_end (t : Node) : Bool :=
match t with
| Node.mk b _ => b
def children (t : Node) : List (Option Node) :=
match t with
| Node.mk _ c => c
end Node
-- Helper for enum behavior
def enum... |
trie_search | import Mathlib
inductive Node
| mk (is_end : Bool) (children : List (Option Node))
deriving Inhabited
namespace Node
def is_end (t : Node) : Bool :=
match t with
| Node.mk b _ => b
def children (t : Node) : List (Option Node) :=
match t with
| Node.mk _ c => c
end Node
-- Helper for enum behavior
def enum... |
unionfind_find | import Mathlib
structure UnionFind where
parent : List Nat
rank : List Nat -- Added to match Dafny/Verus
deriving Inhabited
namespace UnionFind
def len (uf : UnionFind) : Nat := uf.parent.length
def is_valid (uf : UnionFind) : Prop :=
uf.parent.length = uf.rank.length ∧
∀ i, i < uf.len →
let p := uf.p... |
unionfind_linkroots | import Mathlib
structure UnionFind where
parent : List Nat
rank : List Nat
len : Nat
deriving Inhabited
namespace UnionFind
-- 1. Correct Invariant (Matches Dafny/Verus)
-- Must enforce rank monotonicity to prevent cycles.
def is_valid (uf : UnionFind) : Prop :=
uf.parent.length = uf.len ∧
uf.rank.len... |
This is the Lean 4 subset of the AlgoVeri benchmark — a cross-language benchmark for vericoding (generating formally verified code from specifications).
Each task provides a Lean 4 specification that includes:
sorry'd implementation to be filled insorry'd correctness proof to be completedThe goal: implement the algorithm and prove the postconditions hold — all in Lean 4.
| Tasks | 77 algorithm problems |
| Files | 78 .lean specs (gcd has two variants) |
| Lean toolchain | 4.25.0-rc2 + Mathlib |
| Best model score | 7.8% pass rate (Gemini-3 Flash) |
| Category | Tasks |
|---|---|
| Sorting | bubble_sort, insertion_sort, merge_sort, quick_sort, k_smallest |
| Search | binary_search, linear_search, string_search_naive, kmp, ac_automata |
| Graph | bfs, dfs, dijkstra, bellman_ford, kruskal, prim, topological_sort, scc_tarjan, cycle_detection, bipartite_check, push_relabel, edmond_karp, max_matching, lca |
| DP | coin_change, house_robber, jump_game, knapsack_01, knapsack_unbounded, longest_common_subsequence, longest_increasing_subsequence, longest_palindrome_substring, maximum_subarray_sum, rod_cutting |
| Data structures | bst_insert, bst_search, bst_delete, bst_zig, bst_zigzag, bst_zigzig, splaytree_splay, llrbt_insert, llrbt_delete, llrbt_flipcolor, llrbt_rotateleft, llrbt_rotateright, maxheap_push, maxheap_popmax, trie_insert, trie_search, trie_delete, ternarysearchtree_insert, ternarysearchtree_search, ternarysearchtree_delete, segmenttree_build, segmenttree_modify, segmenttree_query, stack_push, stack_pop, queue_enqueue, queue_dequeue, ringbuffer_enqueue, ringbuffer_dequeue, unionfind_find, unionfind_linkroots |
| Math / number theory | gcd, fast_exponential, integer_exponential, trial_division_naive, trial_division_optimized, sieve_method, discrete_logarithm |
| Other | bracket_matching, matrix_multiplication, linearsys_gf2, polymul_naive, polymul_karatsuba |
from datasets import load_dataset
ds = load_dataset("lizn-zn/algoveri-lean", split="train")
print(ds[0]["task_id"], ds[0]["lean_code"][:200])
binary_search)
Every .lean file follows the same pattern:
import Mathlib
-- Precondition
def binary_search_lower_bound_precond (seq : Array Int) (target : Int) : Prop :=
seq.size ≤ 0x7FFFFFFF ∧
(∀ i j : Nat, i < j ∧ j < seq.size → seq.getD i 0 ≤ seq.getD j 0)
-- Implementation stub (fill this in)
def binary_search_lower_bound (seq : Array Int) (target : Int)
(h_precond : ...) : Nat :=
sorry
-- Postcondition
def binary_search_lower_bound_postcond (seq : Array Int) (target : Int)
(result : Nat) (h_precond : ...) : Prop :=
result ≤ seq.size ∧
(∀ i : Nat, i < result → seq.getD i 0 < target) ∧
(∀ i : Nat, result ≤ i ∧ i < seq.size → seq.getD i 0 ≥ target)
-- Prove correctness
theorem binary_search_lower_bound_postcond_satisfied ... := by
sorry
@article{zhao2026algoveri,
title = {AlgoVeri: An Aligned Benchmark for Verified Code Generation on Classical Algorithms},
author = {Haoyu Zhao and Ziran Yang and Jiawei Li and Deyuan He and Zenan Li and Chi Jin and Venugopal V. Veeravalli and Aarti Gupta and Sanjeev Arora},
journal = {arXiv preprint arXiv:2602.09464},
year = {2026}
}
Apache 2.0 — same as the upstream AlgoVeri repository.