Dataset Viewer
Auto-converted to Parquet Duplicate
problem_id
stringlengths
3
30
nl_desc
stringlengths
364
2.13k
spec
stringlengths
743
4.72k
ac_automata
Your task is to implement the Aho-Corasick algorithm to find all occurrences of multiple patterns simultaneously within a haystack (text) and verify its functional correctness in Dafny. Preconditions: You can assume the input text and the total length of all patterns are at most 1,000,000 to ensure index arithmetic doe...
// Following is the block for necessary definitions // <preamble> predicate matches_at(haystack: seq<int>, needle: seq<int>, start_index: int) { && 0 <= start_index && start_index + |needle| <= |haystack| && forall i :: 0 <= i < |needle| ==> haystack[start_index + i] == needle[i] } function patter...
bellman_ford
Your task is to implement the Bellman-Ford Algorithm and verify its functional correctness in Dafny. Unlike Dijkstra, this algorithm must handle graphs with negative edge weights. Preconditions: You can assume the graph contains at most 100,000 nodes and edge weights are between -100,000 and 100,000 (inclusive) to prev...
// <preamble> // Define Option datatype since it is not built-in datatype Option<T> = Some(value: T) | None datatype WeightedGraph = WeightedGraph( // Adjacency list: adj[u] contains list of (neighbor, weight) // u ranges from 0 to size - 1. // Weight is int (was i64 in Verus) adj: seq<seq<(int, int)>>...
bfs
Your task is to implement a Breadth First Search (BFS) algorithm to compute the shortest path distance between two nodes and verify its functional correctness in Dafny. You need to implement bfs_shortest_path. The function should return Some(distance) if reachable, and None otherwise. There are several verification cha...
// Following is the block for necessary definitions // <preamble> // Define Option datatype since it is not built-in datatype Option<T> = Some(value: T) | None datatype Graph = Graph(adj: seq<seq<int>>) // Helper predicates/functions for the Graph datatype ghost predicate well_formed(g: Graph) { forall u: int, i: i...
binary_search
Your task is to implement the Binary Search algorithm (specifically the lower_bound variant) and verify its correctness in Dafny. You are given a sorted sequence of integers and a target value. The algorithm must find the first index $k$ such that $s[k] \ge target$ in $O(\log N)$ time logic (using a shrinking window). ...
// Following is the block for necessary definitions // <preamble> predicate is_sorted(s: seq<int>) { forall i, j {:trigger s[i], s[j]} :: 0 <= i <= j < |s| ==> s[i] <= s[j] } // </preamble> // Following is the block for potential helper specifications // <helpers> // </helpers> // Following is the block...
bipartite_check
Your task is to implement an algorithm to check if a graph is Bipartite (2-colorable) and verify its functional correctness in Dafny. You need to implement check_bipartite, which attempts to color the graph with two colors (represented as booleans). It should return Some(colors) if successful, and None if the graph is ...
// Following is the block for necessary definitions // <preamble> datatype Option<T> = Some(value: T) | None datatype Graph = Graph(adj: seq<seq<int>>) // Helper predicates/functions for the Graph datatype ghost predicate well_formed(g: Graph) { forall u: int, i: int :: 0 <= u < |g.adj| && 0 <= i < |g.adj[u]| ...
bracket_matching
Your task is to implement a linear scan algorithm for Bracket Matching and verify its correctness in Dafny. The algorithm determines whether a sequence of characters $s$ (represented as integers) has perfectly balanced parentheses by maintaining a running balance counter. The operation proceeds by iterating through the...
// <preamble> // Assigns a mathematical weight to characters: // '(' (ASCII 40) adds 1 (opening a scope) // ')' (ASCII 41) subtracts 1 (closing a scope) // All other characters are neutral (0). function char_weight(c: int): int { if c == 40 then // ASCII for '(' 1 else if c == 41 then // ASCII for ...
bst_delete
Your task is to implement a Binary Search Tree and verify that it correctly implements a mathematical Set in Dafny. The tree must maintain the BST Invariant: for any node with value $v$, all values in the left subtree are less than $v$ and all values in the right subtree are greater than $v$. Here, you just need to foc...
// Following is the block for necessary definitions // <preamble> datatype Tree = Empty | Node(val: int, left: Tree, right: Tree) function view(tree: Tree): set<int> decreases tree { match tree case Empty => {} case Node(val, left, right) => view(left) + view(right) + {val} } predicate is_bst(tree: Tr...
bst_insert
Your task is to implement a Binary Search Tree and verify that it correctly implements a mathematical Set in Dafny. The tree must maintain the BST Invariant: for any node with value $v$, all values in the left subtree are less than $v$ and all values in the right subtree are greater than $v$. Here, you just need to foc...
// Following is the block for necessary definitions // <preamble> datatype Tree = Empty | Node(val: int, left: Tree, right: Tree) function view(tree: Tree): set<int> decreases tree { match tree case Empty => {} case Node(val, left, right) => view(left) + view(right) + {val} } predicate is_bst(tree: Tr...
bst_search
Your task is to implement a Binary Search Tree and verify that it correctly implements a mathematical Set in Dafny. The tree must maintain the BST Invariant: for any node with value $v$, all values in the left subtree are less than $v$ and all values in the right subtree are greater than $v$. Here, you just need to foc...
// Following is the block for necessary definitions // <preamble> datatype Tree = Empty | Node(val: int, left: Tree, right: Tree) function view(tree: Tree): set<int> decreases tree { match tree case Empty => {} case Node(val, left, right) => view(left) + view(right) + {val} } predicate is_bst(tree: Tr...
bst_zig
Your task is to implement a Binary Search Tree and verify that it correctly implements a mathematical Set in Dafny. The tree must maintain the BST Invariant: for any node with value $v$, all values in the left subtree are less than $v$ and all values in the right subtree are greater than $v$. Here, you just need to foc...
// Following is the block for necessary definitions // <preamble> datatype Tree = Empty | Node(val: int, left: Tree, right: Tree) function view(tree: Tree): set<int> decreases tree { match tree case Empty => {} case Node(val, left, right) => view(left) + view(right) + {val} } predicate is_bst(tree: Tr...
bst_zigzag
Your task is to implement the Zig-Zag operation (Left-Right Rotation) in a binary search tree and verify its correctness in Dafny. A Zig-Zag is a "double" rotation performed when a node $X$, its parent $P$, and its grandparent $G$ form a "kink" (e.g., $X$ is the right child of $P$, but $P$ is the left child of $G$). T...
// Following is the block for necessary definitions // <preamble> datatype Tree = Empty | Node(val: int, left: Tree, right: Tree) function view(tree: Tree): set<int> decreases tree { match tree case Empty => {} case Node(val, left, right) => view(left) + view(right) + {val} } predicate is_bst(tree: Tr...
bst_zigzig
Your task is to implement the Zig-Zig operation (Double Right Rotation) in a binary search tree and verify its correctness in Dafny. A Zig-Zig is a "double" rotation performed when a node $X$, its parent $P$, and its grandparent $G$ form a straight line (e.g., $X$ is the left child of $P$, and $P$ is the left child of ...
// Following is the block for necessary definitions // <preamble> datatype Tree = Empty | Node(val: int, left: Tree, right: Tree) function view(tree: Tree): set<int> decreases tree { match tree case Empty => {} case Node(val, left, right) => view(left) + view(right) + {val} } predicate is_bst(tree: Tr...
bubble_sort
Your task is to implement Bubble Sort and verify its correctness in Dafny. The algorithm works by repeatedly stepping through the list, comparing adjacent elements and swapping them if they are in the wrong order. The pass through the list is repeated until the list is sorted. You must prove two properties: (1) Sortedn...
// Following is the block for necessary definitions // <preamble> ghost predicate is_sorted(s: seq<int>) { forall i, j :: 0 <= i < j < |s| ==> s[i] <= s[j] } ghost predicate is_valid_index_permutation(p: seq<int>, n: int) { && |p| == n && (forall i {:trigger p[i]} :: 0 <= i < n ==> 0 <= p[i] < n) && (f...
coin_change
Your task is to implement the Coin Change algorithm (finding minimum number of coins) and verify its correctness in Dafny. You are given an integer array `coins` representing coins of different denominations and an integer `amount` representing a total amount of money. Return the fewest number of coins that you need to...
// Following is the block for necessary definitions // <preamble> // Calculates total monetary value: sum(counts[i] * coins[i]) function total_amount(counts: seq<int>, coins: seq<int>): int requires |counts| == |coins| decreases |counts| { if |counts| == 0 then 0 else (counts[0] * coins[...
cycle_detection
Your task is to implement an algorithm to detect if a directed graph (unweighted) contains a cycle and verify its functional correctness in Dafny. You need to implement the function has_cycle, which returns true if the graph contains at least one cycle, and false if it is a Directed Acyclic Graph (DAG). The graph is re...
// Following is the block for necessary definitions // <preamble> datatype Graph = Graph(adj: seq<seq<int>>) // Helper predicates/functions for the Graph datatype ghost predicate well_formed(g: Graph) { forall u: int, i: int :: 0 <= u < |g.adj| && 0 <= i < |g.adj[u]| ==> 0 <= g.adj[u][i] < |g.adj| } ...
dfs
Your task is to implement a Depth First Search (DFS) algorithm to determine reachability in a directed graph and verify its functional correctness in Dafny. The graph is represented as an adjacency list (a sequence of sequences). You need to implement dfs_check_reachability, which returns true if and only if a path exi...
// Following is the block for necessary definitions // <preamble> datatype Graph = Graph(adj: seq<seq<int>>) // Helper predicates/functions for the Graph datatype ghost predicate well_formed(g: Graph) { forall u: int, i: int :: 0 <= u < |g.adj| && 0 <= i < |g.adj[u]| ==> 0 <= g.adj[u][i] < |g.adj| } ...
dijkstra
Your task is to implement Dijkstra's Algorithm for single-source shortest paths and verify its functional correctness in Dafny. The input is a WeightedGraph where edge weights are int. Preconditions: You can assume the graph contains at most 100,000 nodes and edge weights are between -100,000 and 100,000 (inclusive). C...
// Following is the block for necessary definitions // <preamble> // Define Option datatype since it is not built-in datatype Option<T> = Some(value: T) | None datatype WeightedGraph = WeightedGraph( // Adjacency list: adj[u] contains list of (neighbor, weight) // u ranges from 0 to size - 1. // Weight is ...
discrete_logarithm
Your task is to implement a solver for the Discrete Logarithm Problem and verify its correctness in Dafny. Preconditions: The inputs g (generator), h (target), and p (modulus) are non-negative integers (simulating u64). Assume p > 1. Requirements: Implement the method discrete_log_naive which returns Option<int>. Goal...
// Following is the block for necessary definitions // <preamble> // Recursive definition of Modular Exponentiation: (b^e) % m function spec_pow_mod(b: int, e: int, m: int): int decreases e requires m > 1 { if e <= 0 then 1 else (b * spec_pow_mod(b, e - 1, m)) % m } // The predicate that defines a vali...
edmond_karp
Your task is to implement the Edmonds-Karp Algorithm to find the maximum flow in a directed graph with edge capacities and verify its functional correctness in Dafny. Preconditions: You can assume the graph contains at most 1,000 nodes. You can assume edge capacities are between 0 and 100,000. The Source s and Sink t a...
// Following is the block for necessary definitions // <preamble> datatype CapacityGraph = CapacityGraph( // Adjacency list: adj[u] contains list of (neighbor, capacity) // u ranges from 0 to size - 1. // Capacity is int (was i64 in Verus) adj: seq<seq<(int, int)>> ) // Helper predicates/functions for ...
fast_exponential
Your task is to implement the "Exponentiation by Squaring" Algorithm and verify its functional correctness in Dafny. Unlike the naive approach, this algorithm computes $b^e$ in $O(\log e)$ time using binary decomposition of the exponent. Preconditions: The input base b and exponent e are of type int and are non-negativ...
// Following is the block for necessary definitions // <preamble> // Pure mathematical definition of power function spec_pow(b: nat, e: nat): nat decreases e { if e == 0 then 1 else b * spec_pow(b, e - 1) } // </preamble> // Following is the block for potential helper specifications // <helpers> // </he...
gcd
Your task is to implement the Euclidean Algorithm to compute the Greatest Common Divisor (GCD) of two integers and verify its correctness in Dafny. Preconditions: The inputs a and b are u64. Requirements: Implement the function compute_gcd which returns a u64. (1) Algorithm: Use the classic Euclidean algorithm: repeate...
// Following is the block for necessary definitions // <preamble> // Mathematical definition of divisibility: // d divides n if there exists some integer k such that d * k = n. ghost predicate divides(d: nat, n: nat) { exists k: nat :: d * k == n } // Predicate defining the properties of the Greatest Common Divisor ...
house_robber
Your task is to implement the "House Robber" algorithm (Dynamic Programming) and verify its correctness in Dafny. You are a professional robber planning to rob houses along a street. Each house has a certain amount of money stashed, the only constraint stopping you from robbing each of them is that adjacent houses have...
// Following is the block for necessary definitions // <preamble> // Calculates total loot: sum of nums[i] for all i in 'houses' function total_loot(houses: seq<int>, nums: seq<int>): int decreases |houses| { if |houses| == 0 then 0 else // Safe indexing check: if houses[0] in bounds, take v...
insertion_sort
Your task is to implement Insertion Sort and verify its correctness in Dafny. The algorithm builds the final sorted array one item at a time. It iterates through the input elements and, for each one, inserts it into its correct position among the previously sorted elements. You must prove: (1) Sortedness: The resulting...
// Following is the block for necessary definitions // <preamble> ghost predicate is_sorted(s: seq<int>) { forall i, j :: 0 <= i < j < |s| ==> s[i] <= s[j] } ghost predicate is_valid_index_permutation(p: seq<int>, n: int) { && |p| == n && (forall i {:trigger p[i]} :: 0 <= i < n ==> 0 <= p[i] < n) && (f...
integer_exponential
Your task is to implement the Naive Exponentiation Algorithm and verify its functional correctness in Dafny. This algorithm computes the power of an integer using a simple linear iteration. Preconditions: The input base b and exponent e are of type int and are non-negative. To ensure safety, you may assume that the mat...
// Following is the block for necessary definitions // <preamble> // Pure mathematical definition of power function spec_pow(b: nat, e: nat): nat decreases e { if e == 0 then 1 else b * spec_pow(b, e - 1) } // </preamble> // Following is the block for potential helper specifications // <helpers> // </he...
jump_game
Your task is to implement the Jump Game algorithm (Greedy/DP) and verify its correctness in Dafny. You are given an integer array `nums`. You are initially positioned at the array's first index. Each element `nums[i]` represents your maximum jump length at that position. Return `true` if you can reach the last index, o...
// Following is the block for necessary definitions // <preamble> // Definition of a valid jump path (sequence of indices) // path[0] == 0 // path[last] == target_index // path[k+1] is reachable from path[k] predicate is_valid_jump_path(path: seq<int>, nums: seq<int>) { if |path| < 1 then false else ...
k_smallest
Your task is to specify the K-th Smallest Element algorithm acting on a vector of integers and verify its correctness properties in Dafny. You need to implement a selection algorithm that rearranges elements to find the value that would occupy the $k$-th position if the array were fully sorted. Specifically, you must p...
// Following is the block for necessary definitions // <preamble> ghost predicate is_sorted(s: seq<int>) { forall i, j {:trigger s[i], s[j]} :: 0 <= i < j < |s| ==> s[i] <= s[j] } ghost predicate is_valid_index_permutation(p: seq<int>, n: int) { && |p| == n && (forall i {:trigger p[i]} :: 0 <= i < n ==> 0 ...
kmp
Your task is to implement the Knuth-Morris-Pratt (KMP) algorithm to efficiently find all occurrences of a needle (pattern) within a haystack (text) and verify its functional correctness in Dafny. Preconditions: You can assume the input text and pattern are sequences of integers (representing bytes) and their lengths ar...
// Following is the block for necessary definitions // <preamble> predicate matches_at(haystack: seq<int>, needle: seq<int>, start_index: int) { && 0 <= start_index && start_index + |needle| <= |haystack| && forall i :: 0 <= i < |needle| ==> haystack[start_index + i] == needle[i] } // </preamble> ...
knapsack_01
Your task is to implement the 0/1 Knapsack algorithm and verify its correctness in Dafny. You are given a sequence of weights and a sequence of values for n items, and a maximum weight capacity W. The goal is to determine the maximum total value of items that can be included in the knapsack such that the total weight d...
// Following is the block for necessary definitions // <preamble> // Calculates the total weight of the selected items function total_weight(selected: seq<bool>, weights: seq<int>): int requires |selected| <= |weights| decreases |selected| { if |selected| == 0 then 0 else (if selected[0]...
knapsack_unbounded
Your task is to implement the Unbounded Knapsack algorithm (also known as the Complete Knapsack problem) and verify its correctness in Dafny. You are given a sequence of weights and a sequence of values for n items, and a maximum weight capacity W. The goal is to determine the maximum total value of items that can be i...
// Following is the block for necessary definitions // <preamble> // Calculates the total weight of the selected items: sum(count[i] * weight[i]) function total_weight(counts: seq<int>, weights: seq<int>): int requires |counts| <= |weights| decreases |counts| { if |counts| == 0 then 0 else ...
kruskal
Your task is to implement Kruskal's Algorithm to find the Minimum Spanning Tree (MST) of a connected, undirected, weighted graph and verify its functional correctness in Dafny. Preconditions: You can assume the graph is connected. You can assume the graph contains at most 100,000 nodes and edge weights are between -100...
// Following is the block for necessary definitions // <preamble> datatype WeightedGraph = WeightedGraph( // Adjacency list: adj[u] contains list of (neighbor, weight) // u ranges from 0 to size - 1. // Weight is int (was i64 in Verus) adj: seq<seq<(int, int)>> ) // Helper predicates/functions for the ...
lca
Implement a function lowest_common_ancestor that finds the lowest common ancestor of two nodes in a binary tree. Inputs: 1. root: A Tree representing the root of a binary tree. 2. p: An int value representing the first target node. 3. q: An int value representing the second target node. Assumptions & Constraints: 1. Ex...
// Following is the block for necessary definitions // <preamble> datatype Tree = Nil | Node(val: int, left: Tree, right: Tree) datatype Option<T> = None | Some(get: T) { predicate is_some() { this.Some? } } // Standard view as a Set of values ghost function view(t: Tree): set<int> decreases t { match t ...
linear_search
Your task is to implement the Linear Search algorithm (specifically the lower_bound variant) and verify its correctness in Dafny. You are given a sorted sequence of integers and a target value. The algorithm finds the first index $k$ such that $s[k] \ge target$ in $O(N)$ time logic. In the incomplete code, the specific...
// Following is the block for necessary definitions // <preamble> predicate is_sorted(s: seq<int>) { forall i, j {:trigger s[i], s[j]} :: 0 <= i <= j < |s| ==> s[i] <= s[j] } // </preamble> // Following is the block for potential helper specifications // <helpers> // </helpers> // Following is the block...
linearsys_gf2
Your task is to implement a linear system solver for the field $GF(2)$ (integers modulo 2) and verify its correctness in Dafny. Preconditions: Inputs: A matrix matrix (size $M \times N$) and a target vector b (size $M$), both represented using seq<int>. Domain: All elements in the input matrix and vector are guarantee...
// Following is the block for necessary definitions // <preamble> // 1. Field Arithmetic Helpers (GF(2)) function add_gf2(a: int, b: int): int { (a + b) % 2 } function mul_gf2(a: int, b: int): int { (a * b) % 2 } // 2. Validity Checks predicate is_binary_vector(v: seq<int>) { forall i :: 0 <= i < |v| ==> ...
llrbt_delete
Your task is to implement and verify the deletion algorithm for a Left-Leaning Red-Black Tree (LLRBT) in Dafny , which requires maintaining the invariant that we never delete a node from a "2-node" (a Black node with no Red children) to avoid violating Black Height, necessitating the implementation of helper logic (mov...
// Following is the block for necessary definitions // <preamble> datatype Option<T> = Some(value: T) | None datatype Node = Node( val: int, // u64 -> int is_red: bool, left: Option<Node>, right: Option<Node> ) { // Standard Set View ghost function view(): set<int> decreases ...
llrbt_flipcolor
Your task is to implement and verify the flip_colors operation for a Left-Leaning Red-Black Tree (LLRBT) in Dafny , which is used to split a "4-node" (a conceptual node with 3 values, represented by a Black parent connected to two Red children) by "pushing" the Red links up the tree (turning the children Black and the ...
// Following is the block for necessary definitions // <preamble> datatype Option<T> = Some(value: T) | None datatype Node = Node( val: int, // u64 -> int is_red: bool, left: Option<Node>, right: Option<Node> ) { // Standard Set View ghost function view(): set<int> decreases ...
llrbt_insert
Your task is to implement and verify the insertion algorithm for a Left-Leaning Red-Black Tree (LLRBT) in Dafny , which performs a standard recursive BST insertion (adding new nodes as Red) and then, during the return phase (unwinding the recursion), applies three specific fixup operations (rotate_left, rotate_right, f...
// Following is the block for necessary definitions // <preamble> datatype Option<T> = Some(value: T) | None datatype Node = Node( val: int, // u64 -> int is_red: bool, left: Option<Node>, right: Option<Node> ) { // Standard Set View ghost function view(): set<int> decreases ...
llrbt_rotateleft
Your task is to implement and verify a left rotation (fixup_rotate_left) that enforces the "Left-Leaning" invariant for a Left-Leaning Red-Black Tree (LLRBT) in Dafny , ensuring that if a Red link appears on the right (Black Parent $\to$ Red Right Child), the edge is rotated to make it a Left Red link; specifically, yo...
// Following is the block for necessary definitions // <preamble> datatype Option<T> = Some(value: T) | None datatype Node = Node( val: int, // u64 -> int is_red: bool, left: Option<Node>, right: Option<Node> ) { // Standard Set View ghost function view(): set<int> decreases ...
llrbt_rotateright
Your task is to implement and verify a right rotation (fixup_rotate_right) that fixes a "Double Red" violation for a Left-Leaning Red-Black Tree (LLRBT) in Dafny , addressing the scenario where a Red node has a Red left child (representing an unbalanced 4-node) by "flattening" it into a balanced triangle; specifically,...
// Following is the block for necessary definitions // <preamble> datatype Option<T> = Some(value: T) | None datatype Node = Node( val: int, // u64 -> int is_red: bool, left: Option<Node>, right: Option<Node> ) { // Standard Set View ghost function view(): set<int> decreases ...
longest_common_subsequence
Your task is to implement the Longest Common Subsequence (LCS) algorithm and verify its correctness in Dafny. You are given two strings s and t. The goal is to determine the length of the longest common subsequence shared by both strings. In the incomplete code, the specification `lcs_spec` defines the correct mathemat...
// Following is the block for necessary definitions // <preamble> // Helper for max function max(a: int, b: int): int { if a > b then a else b } // LCS recursive specification function lcs_spec(s1: seq<char>, s2: seq<char>): int decreases |s1|, |s2| { if |s1| == 0 || |s2| == 0 then 0 else ...
longest_increasing_subsequence
You task is to implement the algorithm for longest increasing subsequence problem and verify its correctness in Dafny. For simplicity, the sequence only contains integer, and we only consider strictly increasing subsequence. The algorithm only needs to return the length of the longest increasing subsequence. In the inc...
// Following is the block for necessary definitions // <preamble> ghost predicate is_valid_is(s: seq<int>, indices: seq<int>) { (forall k: int, m: int :: 0 <= k < m < |indices| ==> indices[k] < indices[m]) && (forall k: int :: 0 <= k < |indices| ==> 0 <= indices[k] < |s|) && (for...
longest_palindrome_substring
Your task is to implement Manacher's algorithm for the Longest Palindromic Substring and verify its correctness in Dafny. The algorithm identifies the substring of maximal length in input $s$ that reads the same forwards and backwards. The operation proceeds as follows: (1) Transformation: Construct a modified string $...
// Following is the block for necessary definitions // <preamble> // Definition of a Palindrome: // A sequence is a palindrome if for every index i, the character at i // is identical to the character at the symmetric position from the end. predicate is_palindrome(s: seq<int>) { // We trigger on s[i] so the solver ...
matrix_multiplication
Your task is to implement Matrix Multiplication and verify its correctness in Dafny. Given two matrices A (size n x m) and B (size m x k), represented as sequences of sequences of integers, return their product C (size n x k). The element at row i, column j of C is defined as the dot product of the i-th row of A and th...
// Following is the block for necessary definitions // <preamble> // Calculate dot product of row A[r] and col B[c] function dot_product(row_vals: seq<int>, B_vals: seq<seq<int>>, c: int, k: int): int // k must be within bounds of the row vector we are iterating requires 0 <= k <= |row_vals| // k must be wi...
max_matching
Your task is to implement an algorithm to find the Maximum Bipartite Matching and verify its functional correctness in Dafny. Preconditions The input is a Bipartite Graph consisting of two disjoint sets of vertices: Left Set (U) with left_size nodes. Right Set (V) with right_size nodes. The graph is represented as an a...
// Following is the block for necessary definitions // <preamble> datatype BipartiteGraph = BipartiteGraph( // Number of nodes on the Left (U) and Right (V) left_size: int, right_size: int, // Adjacency list: adj[u] contains list of neighbors v in Right set. // u ranges from 0 to left_size - 1....
maxheap_popmax
Your task is to implement the Pop Max operation for a binary max-heap (the maximum value is stored at the root), which removes and returns the root element (the maximum value) of the heap, and verify its correctness in Dafny. To maintain the complete binary tree structure, the value at the last position of the sequence...
// Following is the block for necessary definitions // <preamble> class BinaryMaxHeap { var storage: seq<int> var len: int function max_capacity(): int { 1023 } predicate is_heap() reads this { len <= max_capacity() && 0 <= len <= |storage| && // Heap Property: Chil...
maxheap_push
Your task is to implement the Push operation for a binary max-heap (the maximum value is stored at the root) stored in a sequence and verify its correctness in Dafny. When a new value is added, it is initially placed at the first available position at the end of the sequence to maintain the tree's complete binary struc...
// Following is the block for necessary definitions // <preamble> class BinaryMaxHeap { var storage: seq<int> var len: int function max_capacity(): int { 1023 } predicate is_heap() reads this { len <= max_capacity() && 0 <= len <= |storage| && // Heap Property: Chil...
maximum_subarray_sum
Your task is to implement the algorithm for the Maximum Subarray Sum problem (commonly known as Kadane's Algorithm) and verify its correctness in Dafny. For simplicity, the sequence contains signed integers, and we consider contiguous subarrays (including the empty subarray if applicable). The algorithm needs to return...
// Following is the block for necessary definitions // <preamble> // Recursive definition of sum for a sequence slice [start, end) function spec_sum(s: seq<int>, start: int, end: int): int requires 0 <= start <= end <= |s| decreases end - start { if start >= end then 0 else s[end - 1] + ...
merge_sort
Your task is to implement Merge Sort and verify its correctness in Dafny. Merge Sort is a divide-and-conquer algorithm that divides the input array into two halves, calls itself for the two halves, and then merges the two sorted halves. You might implement two functions: (1) merge: Takes two sorted vectors and combines...
// Following is the block for necessary definitions // <preamble> ghost predicate is_sorted(s: seq<int>) { forall i, j :: 0 <= i < j < |s| ==> s[i] <= s[j] } ghost predicate is_valid_index_permutation(p: seq<int>, n: int) { && |p| == n && (forall i {:trigger p[i]} :: 0 <= i < n ==> 0 <= p[i] < n) && (f...
polymul_karatsuba
Your task is to implement the Karatsuba algorithm for fast polynomial multiplication and verify its correctness in Dafny. Preconditions: Inputs a and b are seq<int> representing polynomials. Structure: The length of a and b are equal and must be a power of 2. Size: The total length is at most 1000. Bounds: Input coeff...
// <preamble> // Helper to convert inputs. In Dafny, we use int directly, so this is identity. function to_int(s: seq<int>): seq<int> { s } // Helper: Enforce bounds on coefficients to prevent overflow. predicate coeffs_bounded(s: seq<int>) { forall i :: 0 <= i < |s| ==> -1_000_000 <= s[i] <= 1_000_000 } // R...
polymul_naive
Your task is to implement the standard $O(N^2)$ algorithm for multiplying two polynomials and verify its correctness in Dafny. Preconditions: Inputs a and b are seq<int> representing polynomial coefficients. Size Constraint: The sum of lengths is at most 1000. Value Constraint: Every coefficient is between -1,000,000 ...
// <preamble> // Helper to convert inputs. In Dafny, we use int directly, so this is identity. function to_int(s: seq<int>): seq<int> { s } // Helper: Enforce bounds on coefficients to prevent overflow. predicate coeffs_bounded(s: seq<int>) { forall i :: 0 <= i < |s| ==> -1_000_000 <= s[i] <= 1_000_000 } // R...
prim
Your task is to implement Prim's Algorithm to find the Minimum Spanning Tree (MST) of a connected, undirected, weighted graph and verify its functional correctness in Dafny. The graph is represented as an adjacency list with int weights. Preconditions: You can assume the graph is connected (a path exists between any tw...
// Following is the block for necessary definitions // <preamble> datatype WeightedGraph = WeightedGraph( // Adjacency list: adj[u] contains list of (neighbor, weight) // u ranges from 0 to size - 1. // Weight is int (was i64 in Verus) adj: seq<seq<(int, int)>> ) // Helper predicates/functions for the ...
push_relabel
Your task is to implement the Push-Relabel Algorithm to find the maximum flow in a directed graph and verify its functional correctness in Dafny. Preconditions: You can assume the graph contains at most 1,000 nodes. You can assume edge capacities are between 0 and 100,000. The Source s and Sink t are valid, distinct no...
// Following is the block for necessary definitions // <preamble> datatype CapacityGraph = CapacityGraph( // Adjacency list: adj[u] contains list of (neighbor, capacity) // u ranges from 0 to size - 1. // Capacity is int (was i64 in Verus) adj: seq<seq<(int, int)>> ) // Helper predicates/functions for ...
queue_dequeue
Your task is to implement a Queue and verify its First-In, First-Out correctness in Dafny. The queue is modeled as a sequence where elements enter at the "back" and exit from the "front." Now you should implement and verify the dequeue (pop) operation. Dequeue (Pop): Verify that the operation returns the first element ...
// Following is the block for necessary definitions // <preamble> class VerifiableQueue<T> { var data: seq<T> function view(): seq<T> reads this { data } predicate is_valid() reads this { true } constructor() ensures is_valid() ensures |...
queue_enqueue
Your task is to implement a Queue and verify its First-In, First-Out correctness in Dafny. The queue is modeled as a sequence where elements enter at the "back" and exit from the "front." Now you should implement and verify the enqueue (push) operation. Enqueue (Push): Verify that the item is appended to the end of the...
// <preamble> class VerifiableQueue<T> { var data: seq<T> function view(): seq<T> reads this { data } predicate is_valid() reads this { true } constructor() ensures is_valid() ensures |view()| == 0 { data := []; } me...
quick_sort
Your task is to implement a deterministic variant of Quick Sort and verify its correctness in Dafny. The pivot must always be chosen as the first element of the slice (or sub-slice) being sorted. You need to implement: (1) partition: Reorders the slice such that all elements less than the pivot come before it, and all ...
// Following is the block for necessary definitions // <preamble> ghost predicate is_sorted(s: seq<int>) { forall i, j :: 0 <= i < j < |s| ==> s[i] <= s[j] } ghost predicate is_valid_index_permutation(p: seq<int>, n: int) { && |p| == n && (forall i {:trigger p[i]} :: 0 <= i < n ==> 0 <= p[i] < n) && (f...
ringbuffer_dequeue
Your task is to implement and verify the dequeue (pop) operation for a Ring Buffer data structure in Dafny. Because the ring buffer uses a fixed-size underlying array, the "front" of the queue is not fixed at the array's index 0 but is instead tracked by a moving head pointer. Verification: Verify that the operation re...
// Following is the block for necessary definitions // <preamble> class RingBuffer<T> { var data: seq<T> var head: int var len: int var capacity: int // View function: models the ring buffer as a linear sequence function view(): seq<T> reads this requires capacity > 0 re...
ringbuffer_enqueue
Your task is to implement and verify the circular enqueue (push) operation for the Ring Buffer data structure. Unlike a standard queue which may have an infinite logical capacity or fail when full, this ring buffer is modeled as a fixed-capacity sequence that supports overwriting. Standard Case (Not Full): Verify that ...
// Following is the block for necessary definitions // <preamble> class RingBuffer<T> { var data: seq<T> var head: int var len: int var capacity: int // View function: models the ring buffer as a linear sequence function view(): seq<T> reads this requires capacity > 0 re...
rod_cutting
Your task is to implement the Rod Cutting algorithm (a classic Dynamic Programming problem from CLRS) and verify its correctness in Dafny. You are given a rod of length n and a table of prices where the $i$-th element represents the price of a rod piece of length $i+1$. The goal is to determine the maximum revenue obta...
// Following is the block for necessary definitions // <preamble> // Calculates the total length of the pieces function sum_lengths(cuts: seq<int>): int decreases |cuts| { if |cuts| == 0 then 0 else cuts[0] + sum_lengths(cuts[1..]) } // Helper: Safe price lookup that returns 0 for out-of-bo...
scc_tarjan
our task is to implement Tarjan's Algorithm to find the Strongly Connected Components (SCCs) of a directed graph and verify its functional correctness in Dafny. Preconditions: You can assume the graph contains at most 1,000 nodes. The graph is directed and represented as an adjacency list. Requirements: Implement the f...
// Following is the block for necessary definitions // <preamble> datatype Graph = Graph(adj: seq<seq<int>>) // Helper predicates/functions for the Graph datatype ghost function size(g: Graph): int { |g.adj| } ghost function view(g: Graph): seq<seq<int>> { g.adj } ghost predicate well_formed(g: Graph) { ...
End of preview. Expand in Data Studio

Hugging Face arXiv License Email me

Introduction

We introduce AlgoVeri, a benchmark that evaluates vericoding of $77$ classical algorithms in Dafny, Verus, and Lean. By enforcing identical functional contracts, AlgoVeri reveals critical capability gaps in current models. While frontier models achieve tractable success in Dafny ($40.3$% for Gemini-3 Flash), where high-level abstractions and SMT automation simplify the workflow, performance collapses under the systems-level memory constraints of Verus ($24.7$%) and the explicit proof construction required by Lean (7.8%). Beyond aggregate metrics, we uncover a sharp divergence in test-time compute dynamics: Gemini-3 effectively utilizes iterative repair to boost performance (e.g., tripling pass rates in Dafny), whereas GPT-OSS saturates early. Finally, our error analysis shows that language design affects the refinement trajectory: while Dafny allows models to focus on logical correctness, Verus and Lean trap models in persistent syntactic and semantic barriers.

Quick Start

All of the instructions for environment setup and the evaluation pipeline is released at https://github.com/haoyuzhao123/algoveri

AlgoVeri Benchmark

We provide three splits: dafny, verus, lean. Each split consist of 77 problems.

Citation

@article{zhao2026algoveri,
  title={AlgoVeri: An Aligned Benchmark for Verified Code Generation on Classical Algorithms},
  author={Zhao, Haoyu and Yang, Ziran and Li, Jiawei and He, Deyuan and Li, Zenan and Jin, Chi and Veeravalli, Venugopal V and Gupta, Aarti and Arora, Sanjeev},
  journal={arXiv preprint arXiv:2602.09464},
  year={2026}
}
Downloads last month
32

Paper for zzzzzhy/algoveri