Datasets:
task_id stringlengths 3 79 | question_id int64 2 3.24k | difficulty stringclasses 3
values | tags listlengths 1 8 | description stringlengths 224 3.74k | leetcode_signature stringlengths 18 130 | rust_signature stringlengths 25 141 | lean_function stringlengths 13 102 | rust_solution stringlengths 52 8.38k | lean_types stringlengths 716 1.17k | lean_funs stringlengths 921 54.6k | lean_funs_external stringclasses 151
values | lean_eval stringlengths 420 114k | test_cases listlengths 3 450 | num_test_cases int64 3 450 | order_insensitive bool 2
classes | rust_cases_passed int64 3 450 | lean_check stringclasses 2
values | lean_check_cases int64 3 10 | lean_check_cases_true int64 3 10 | num_llm_calls int64 1 7 | total_completion_tokens int64 41 176k | trajectory listlengths 7 27 | lean_specs stringlengths 0 31k | num_specs int64 0 20 |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
add-two-numbers | 2 | Medium | [
"Recursion",
"Linked List",
"Math"
] | You are given two non-empty linked lists representing two non-negative integers. The digits are stored in reverse order, and each of their nodes contains a single digit. Add the two numbers and return the sum as a linked list.
You may assume the two numbers do not contain any leading zero, except the number 0 itself.
... | addTwoNumbers(l1: linkedlist, l2: linkedlist) -> linkedlist | pub fn add_two_numbers(l1: &List, l2: &List) -> List | Aegis.AddTwoNumbers.add_two_numbers | pub fn add_two_numbers(l1: &List, l2: &List) -> List {
let mut a: Vec<i64> = Vec::new();
let mut cur1 = l1;
let mut done1 = false;
while !done1 {
match cur1 {
List::Nil => {
done1 = true;
}
List::Cons(v, next) => {
a.push(*v);
... | -- THIS FILE WAS AUTOMATICALLY GENERATED BY AENEAS
-- [add_two_numbers]: type definitions
module
public import Aeneas
@[expose] public section
open Aeneas Aeneas.Std Result ControlFlow Error
set_option linter.dupNamespace false
set_option linter.hashCommand false
set_option linter.unusedVariables false
set_option linte... | -- THIS FILE WAS AUTOMATICALLY GENERATED BY AENEAS
-- [add_two_numbers]: function definitions
module
public import Aeneas
public import Aegis.AddTwoNumbers.Code.Types
@[expose] public section
open Aeneas Aeneas.Std Result ControlFlow Error
set_option linter.dupNamespace false
set_option linter.hashCommand false
set_opt... | import Aegis.AddTwoNumbers.Code.Funs
open Aeneas Aeneas.Std Result
set_option maxHeartbeats 4000000
set_option maxRecDepth 4096
def aegisCase (path : String) (i : Nat) (b : Bool) : IO Unit := do
let h ← IO.FS.Handle.mk path .append
h.putStrLn s!"CASE {i} {b}"
h.flush
IO.println s!"CASE {i} {b}"
deriving inst... | [
{
"input": "[[0], [0]]",
"output": "[0]"
},
{
"input": "[[5], [5]]",
"output": "[0, 1]"
},
{
"input": "[[1], [9]]",
"output": "[0, 1]"
},
{
"input": "[[9], [1]]",
"output": "[0, 1]"
},
{
"input": "[[1, 8], [0]]",
"output": "[1, 8]"
},
{
"input": "[[1, ... | 59 | false | 59 | verified | 10 | 10 | 1 | 11,442 | [
{
"type": "run_start",
"phase": "",
"model": null,
"messages": null,
"response": null,
"reasoning": null,
"finish_reason": null,
"prompt_tokens": null,
"completion_tokens": null,
"cached_prompt_tokens": null,
"command": null,
"exit_code": null,
"timed_out": null,
... | import Aegis.AddTwoNumbers.Code.Funs
/-!
# Specifications of `Aegis.AddTwoNumbers.add_two_numbers`
LeetCode problem `add-two-numbers`. Each `spec_<n>` theorem states one property of the function.
-/
open Aeneas Aeneas.Std Result
namespace AegisSpec.AddTwoNumbers
def digits : Aegis.AddTwoNumbers.List → List Int... | 6 | |
longest-substring-without-repeating-characters | 3 | Medium | [
"Hash Table",
"String",
"Sliding Window"
] | Given a string s, find the length of the longest substring without repeating characters.
Example 1:
Input: s = "abcabcbb"
Output: 3
Explanation: The answer is "abc", with the length of 3.
Example 2:
Input: s = "bbbbb"
Output: 1
Explanation: The answer is "b", with the length of 1.
Example 3:
Input: s = "pwwkew"
... | lengthOfLongestSubstring(s: str) -> int | pub fn length_of_longest_substring(s: &[u8]) -> i64 | Aegis.LengthOfLongestSubstring.length_of_longest_substring | pub fn length_of_longest_substring(s: &[u8]) -> i64 {
let n = s.len();
// last[c] stores the most recent index of byte c, or -1 if unseen.
let mut last: Vec<i64> = Vec::new();
let mut i: usize = 0;
while i < 256 {
last.push(-1);
i += 1;
}
let mut best: i64 = 0;
let mut ... | -- THIS FILE WAS AUTOMATICALLY GENERATED BY AENEAS
-- [length_of_longest_substring]: type definitions
module
public import Aeneas
@[expose] public section
open Aeneas Aeneas.Std Result ControlFlow Error
set_option linter.dupNamespace false
set_option linter.hashCommand false
set_option linter.unusedVariables false
set_... | -- THIS FILE WAS AUTOMATICALLY GENERATED BY AENEAS
-- [length_of_longest_substring]: function definitions
module
public import Aeneas
public import Aegis.LengthOfLongestSubstring.Code.Types
@[expose] public section
open Aeneas Aeneas.Std Result ControlFlow Error
set_option linter.dupNamespace false
set_option linter.ha... | import Aegis.LengthOfLongestSubstring.Code.Funs
open Aeneas Aeneas.Std Result
set_option maxHeartbeats 4000000
set_option maxRecDepth 4096
def aegisCase (path : String) (i : Nat) (b : Bool) : IO Unit := do
let h ← IO.FS.Handle.mk path .append
h.putStrLn s!"CASE {i} {b}"
h.flush
IO.println s!"CASE {i} {b}"
#e... | [
{
"input": "[\"abcabcbb\"]",
"output": "3"
},
{
"input": "[\"bbbbb\"]",
"output": "1"
},
{
"input": "[\"pwwkew\"]",
"output": "3"
},
{
"input": "[\"abcdabcabcabcd\"]",
"output": "4"
},
{
"input": "[\"abcdefgabcdefgabcdefgabcdefg\"]",
"output": "7"
},
{
... | 36 | false | 36 | verified | 10 | 10 | 1 | 2,478 | [
{
"type": "run_start",
"phase": "",
"model": null,
"messages": null,
"response": null,
"reasoning": null,
"finish_reason": null,
"prompt_tokens": null,
"completion_tokens": null,
"cached_prompt_tokens": null,
"command": null,
"exit_code": null,
"timed_out": null,
... | import Aegis.LengthOfLongestSubstring.Code.Funs
/-!
# Specifications of `Aegis.LengthOfLongestSubstring.length_of_longest_substring`
LeetCode problem `longest-substring-without-repeating-characters`. Each `spec_<n>` theorem states one property of the function.
-/
open Aeneas Aeneas.Std Result
namespace AegisSpec.Le... | 13 | |
reverse-integer | 7 | Medium | [
"Math"
] | Given a signed 32-bit integer x, return x with its digits reversed. If reversing x causes the value to go outside the signed 32-bit integer range [-231, 231 - 1], then return 0.
Assume the environment does not allow you to store 64-bit integers (signed or unsigned).
Example 1:
Input: x = 123
Output: 321
Example 2:
... | reverse(x: int) -> int | pub fn reverse(x: i64) -> i64 | Aegis.Reverse.reverse | pub fn reverse(x: i64) -> i64 {
let limit: i64 = 2147483647;
let min_limit: i64 = -2147483648;
let negative = x < 0;
let mut n = x;
if negative {
n = -n;
}
let mut rev: i64 = 0;
while n != 0 {
let digit = n % 10;
n = n / 10;
rev = rev * 10 + digit;
}... | -- THIS FILE WAS AUTOMATICALLY GENERATED BY AENEAS
-- [reverse]: type definitions
module
public import Aeneas
@[expose] public section
open Aeneas Aeneas.Std Result ControlFlow Error
set_option linter.dupNamespace false
set_option linter.hashCommand false
set_option linter.unusedVariables false
set_option linter.style.... | -- THIS FILE WAS AUTOMATICALLY GENERATED BY AENEAS
-- [reverse]: function definitions
module
public import Aeneas
public import Aegis.Reverse.Code.Types
@[expose] public section
open Aeneas Aeneas.Std Result ControlFlow Error
set_option linter.dupNamespace false
set_option linter.hashCommand false
set_option linter.unu... | import Aegis.Reverse.Code.Funs
open Aeneas Aeneas.Std Result
set_option maxHeartbeats 4000000
set_option maxRecDepth 4096
def aegisCase (path : String) (i : Nat) (b : Bool) : IO Unit := do
let h ← IO.FS.Handle.mk path .append
h.putStrLn s!"CASE {i} {b}"
h.flush
IO.println s!"CASE {i} {b}"
#eval aegisCase "ev... | [
{
"input": "[-2147483412]",
"output": "-2143847412"
},
{
"input": "[2147483647]",
"output": "0"
},
{
"input": "[120]",
"output": "21"
},
{
"input": "[-123]",
"output": "-321"
},
{
"input": "[1534236469]",
"output": "0"
},
{
"input": "[0]",
"output"... | 61 | false | 61 | verified | 10 | 10 | 1 | 464 | [
{
"type": "run_start",
"phase": "",
"model": null,
"messages": null,
"response": null,
"reasoning": null,
"finish_reason": null,
"prompt_tokens": null,
"completion_tokens": null,
"cached_prompt_tokens": null,
"command": null,
"exit_code": null,
"timed_out": null,
... | import Aegis.Reverse.Code.Funs
/-!
# Specifications of `Aegis.Reverse.reverse`
LeetCode problem `reverse-integer`. Each `spec_<n>` theorem states one property of the function.
-/
open Aeneas Aeneas.Std Result
namespace AegisSpec.Reverse
def InI32 (n : ℤ) : Prop := -2147483648 ≤ n ∧ n ≤ 2147483647
instance inI32_d... | 16 | |
string-to-integer-atoi | 8 | Medium | [
"String"
] | "Implement the myAtoi(string s) function, which converts a string to a 32-bit signed integer.\nThe a(...TRUNCATED) | myAtoi(s: str) -> int | pub fn my_atoi(s: &[u8]) -> i64 | Aegis.MyAtoi.my_atoi | "pub fn my_atoi(s: &[u8]) -> i64 {\n let n = s.len();\n let mut i: usize = 0;\n\n while i <(...TRUNCATED) | "-- THIS FILE WAS AUTOMATICALLY GENERATED BY AENEAS\n-- [my_atoi]: type definitions\nmodule\npublic (...TRUNCATED) | "-- THIS FILE WAS AUTOMATICALLY GENERATED BY AENEAS\n-- [my_atoi]: function definitions\nmodule\npub(...TRUNCATED) | "import Aegis.MyAtoi.Code.Funs\nopen Aeneas Aeneas.Std Result\n\nset_option maxHeartbeats 4000000\ns(...TRUNCATED) | [{"input":"[\"2147483647\"]","output":"2147483647"},{"input":"[\"42 with words\"]","output":"42"},{"(...TRUNCATED) | 185 | false | 185 | verified | 10 | 10 | 1 | 1,623 | [{"type":"run_start","phase":"","model":null,"messages":null,"response":null,"reasoning":null,"finis(...TRUNCATED) | "import Aegis.MyAtoi.Code.Funs\n\n/-!\n# Specifications of `Aegis.MyAtoi.my_atoi`\n\nLeetCode proble(...TRUNCATED) | 14 | |
palindrome-number | 9 | Easy | [
"Math"
] | "Given an integer x, return true if x is a palindrome, and false otherwise.\n \nExample 1:\n\nInput(...TRUNCATED) | isPalindrome(x: int) -> bool | pub fn is_palindrome(x: i64) -> bool | Aegis.IsPalindrome.is_palindrome | "pub fn is_palindrome(x: i64) -> bool {\n if x < 0 {\n return false;\n }\n if x != 0(...TRUNCATED) | "-- THIS FILE WAS AUTOMATICALLY GENERATED BY AENEAS\n-- [is_palindrome]: type definitions\nmodule\np(...TRUNCATED) | "-- THIS FILE WAS AUTOMATICALLY GENERATED BY AENEAS\n-- [is_palindrome]: function definitions\nmodul(...TRUNCATED) | "import Aegis.IsPalindrome.Code.Funs\nopen Aeneas Aeneas.Std Result\n\nset_option maxHeartbeats 4000(...TRUNCATED) | [{"input":"[1221]","output":"true"},{"input":"[10]","output":"false"},{"input":"[123421]","output":"(...TRUNCATED) | 54 | false | 54 | verified | 10 | 10 | 1 | 2,511 | [{"type":"run_start","phase":"","model":null,"messages":null,"response":null,"reasoning":null,"finis(...TRUNCATED) | "import Aegis.IsPalindrome.Code.Funs\n\n/-!\n# Specifications of `Aegis.IsPalindrome.is_palindrome`\(...TRUNCATED) | 6 | |
regular-expression-matching | 10 | Hard | [
"Recursion",
"String",
"Dynamic Programming"
] | "Given an input string s and a pattern p, implement regular expression matching with support for '.(...TRUNCATED) | isMatch(s: str, p: str) -> bool | pub fn is_match(s: &[u8], p: &[u8]) -> bool | Aegis.IsMatch.is_match | "pub fn is_match(s: &[u8], p: &[u8]) -> bool {\n let n: usize = s.len();\n let m: usize = p.le(...TRUNCATED) | "-- THIS FILE WAS AUTOMATICALLY GENERATED BY AENEAS\n-- [is_match]: type definitions\nmodule\npublic(...TRUNCATED) | "-- THIS FILE WAS AUTOMATICALLY GENERATED BY AENEAS\n-- [is_match]: function definitions\nmodule\npu(...TRUNCATED) | "import Aegis.IsMatch.Code.Funs\nopen Aeneas Aeneas.Std Result\n\nset_option maxHeartbeats 4000000\n(...TRUNCATED) | [{"input":"[\"aa\", \"a*\"]","output":"true"},{"input":"[\"aab\", \"c*a*b\"]","output":"true"},{"inp(...TRUNCATED) | 151 | false | 151 | verified | 10 | 10 | 1 | 2,769 | [{"type":"run_start","phase":"","model":null,"messages":null,"response":null,"reasoning":null,"finis(...TRUNCATED) | "import Aegis.IsMatch.Code.Funs\n\n/-!\n# Specifications of `Aegis.IsMatch.is_match`\n\nLeetCode pro(...TRUNCATED) | 11 | |
container-with-most-water | 11 | Medium | [
"Greedy",
"Array",
"Two Pointers"
] | "You are given an integer array height of length n. There are n vertical lines drawn such that the t(...TRUNCATED) | maxArea(height: list_int) -> int | pub fn max_area(height: &[i64]) -> i64 | Aegis.MaxArea.max_area | "pub fn max_area(height: &[i64]) -> i64 {\n let n = height.len();\n if n < 2 {\n return(...TRUNCATED) | "-- THIS FILE WAS AUTOMATICALLY GENERATED BY AENEAS\n-- [max_area]: type definitions\nmodule\npublic(...TRUNCATED) | "-- THIS FILE WAS AUTOMATICALLY GENERATED BY AENEAS\n-- [max_area]: function definitions\nmodule\npu(...TRUNCATED) | "import Aegis.MaxArea.Code.Funs\nopen Aeneas Aeneas.Std Result\n\nset_option maxHeartbeats 4000000\n(...TRUNCATED) | [{"input":"[[1, 1]]","output":"1"},{"input":"[[1, 2, 1]]","output":"2"},{"input":"[[1, 2, 4, 3]]","o(...TRUNCATED) | 116 | false | 116 | verified | 10 | 10 | 1 | 591 | [{"type":"run_start","phase":"","model":null,"messages":null,"response":null,"reasoning":null,"finis(...TRUNCATED) | "import Aegis.MaxArea.Code.Funs\n\n/-!\n# Specifications of `Aegis.MaxArea.max_area`\n\nLeetCode pro(...TRUNCATED) | 14 | |
roman-to-integer | 13 | Easy | [
"Hash Table",
"Math",
"String"
] | "Roman numerals are represented by seven different symbols: I, V, X, L, C, D and M.\n\nSymbol (...TRUNCATED) | romanToInt(s: str) -> int | pub fn roman_to_int(s: &[u8]) -> i64 | Aegis.RomanToInt.roman_to_int | "fn roman_value(c: u8) -> i64 {\n if c == b'I' {\n 1\n } else if c == b'V' {\n 5(...TRUNCATED) | "-- THIS FILE WAS AUTOMATICALLY GENERATED BY AENEAS\n-- [roman_to_int]: type definitions\nmodule\npu(...TRUNCATED) | "-- THIS FILE WAS AUTOMATICALLY GENERATED BY AENEAS\n-- [roman_to_int]: function definitions\nmodule(...TRUNCATED) | "import Aegis.RomanToInt.Code.Funs\nopen Aeneas Aeneas.Std Result\n\nset_option maxHeartbeats 400000(...TRUNCATED) | [{"input":"[\"XCIX\"]","output":"99"},{"input":"[\"MMCMXCIX\"]","output":"2999"},{"input":"[\"MMMCMX(...TRUNCATED) | 94 | false | 94 | verified | 10 | 10 | 1 | 516 | [{"type":"run_start","phase":"","model":null,"messages":null,"response":null,"reasoning":null,"finis(...TRUNCATED) | "import Aegis.RomanToInt.Code.Funs\n\n/-!\n# Specifications of `Aegis.RomanToInt.roman_to_int`\n\nLe(...TRUNCATED) | 9 | |
3sum | 15 | Medium | [
"Array",
"Two Pointers",
"Sorting"
] | "Given an integer array nums, return all the triplets [nums[i], nums[j], nums[k]] such that i != j, (...TRUNCATED) | threeSum(nums: list_int) -> list_list_int | pub fn three_sum(nums: &[i64]) -> Vec<Vec<i64>> | Aegis.ThreeSum.three_sum | "#![allow(unused_macros)]\n\n// A crate-local `vec!` shadowing the prelude one.\n// The empty arm is(...TRUNCATED) | "-- THIS FILE WAS AUTOMATICALLY GENERATED BY AENEAS\n-- [three_sum]: type definitions\nmodule\npubli(...TRUNCATED) | "-- THIS FILE WAS AUTOMATICALLY GENERATED BY AENEAS\n-- [three_sum]: function definitions\nmodule\np(...TRUNCATED) | "import Aegis.ThreeSum.Code.Funs\nopen Aeneas Aeneas.Std Result\n\nset_option maxHeartbeats 4000000\(...TRUNCATED) | [{"input":"[[0, 1, 1]]","output":"[]"},{"input":"[[1, 2, -2, -1]]","output":"[]"},{"input":"[[0, 0, (...TRUNCATED) | 103 | false | 103 | verified | 10 | 10 | 2 | 32,449 | [{"type":"run_start","phase":"","model":null,"messages":null,"response":null,"reasoning":null,"finis(...TRUNCATED) | "import Aegis.ThreeSum.Code.Funs\n\n/-!\n# Specifications of `Aegis.ThreeSum.three_sum`\n\nLeetCode (...TRUNCATED) | 8 | |
3sum-closest | 16 | Medium | [
"Array",
"Two Pointers",
"Sorting"
] | "Given an integer array nums of length n and an integer target, find three integers in nums such tha(...TRUNCATED) | threeSumClosest(nums: list_int, target: int) -> int | pub fn three_sum_closest(nums: &[i64], target: i64) -> i64 | Aegis.ThreeSumClosest.three_sum_closest | "pub fn three_sum_closest(nums: &[i64], target: i64) -> i64 {\n let n = nums.len();\n\n let mu(...TRUNCATED) | "-- THIS FILE WAS AUTOMATICALLY GENERATED BY AENEAS\n-- [three_sum_closest]: type definitions\nmodul(...TRUNCATED) | "-- THIS FILE WAS AUTOMATICALLY GENERATED BY AENEAS\n-- [three_sum_closest]: function definitions\nm(...TRUNCATED) | "import Aegis.ThreeSumClosest.Code.Funs\nopen Aeneas Aeneas.Std Result\n\nset_option maxHeartbeats 4(...TRUNCATED) | [{"input":"[[0, 0, 0], 1]","output":"0"},{"input":"[[1, 1, 1, 0], -100]","output":"2"},{"input":"[[-(...TRUNCATED) | 99 | false | 99 | verified | 10 | 10 | 2 | 2,631 | [{"type":"run_start","phase":"","model":null,"messages":null,"response":null,"reasoning":null,"finis(...TRUNCATED) | "import Aegis.ThreeSumClosest.Code.Funs\n\n/-!\n# Specifications of `Aegis.ThreeSumClosest.three_sum(...TRUNCATED) | 14 |
LeetCode Rust-to-Lean (unofficial)
Unofficial. This dataset is an independent reproduction of the methodology of Scaling Lean Theorem Proving for Real-World Code Verification, made by the paper's first author. It is not an official release of the paper. If you use it, please cite the paper (BibTeX at the bottom).
Theorem provers are now very good at competition mathematics, and the benchmarks for it are close to saturated. Proving that real code is correct is a different and much harder problem, and it is the one that matters for software. This dataset applies the methodology of the paper above from scratch and contributes 24,617 new theorems about real code for the community to prove.
It contains 2,126 programs and 24,617 theorems about them:
- Each program is a Rust solution to a LeetCode problem that passes every test case of the problem, together with its translation to Lean 4 by the Aeneas tool. The Lean code is the program itself, with machine integers, overflow checks, loops and panics, not a clean mathematical model of it. The translation was run on test cases and reproduces the Rust program's answers.
- Each theorem states one property of one of these programs, in natural language and in Lean 4: functional correctness, absence of failure, bounds, edge cases, relations between inputs and outputs, and more. Each program's theorems include one main theorem, which relates its result to the answer the problem asks for.
The task is to prove the theorems. The release contains the statements only; the proofs are open.
What it is for
- Benchmarking provers on code. Every theorem is a self-contained, mechanically checked task.
- Reinforcement learning. A proof is accepted or rejected by Lean's kernel, so every theorem is a reward signal that cannot be gamed by a judge model.
- Autoformalization. Every theorem comes in natural language and in Lean, against the same program: 24,617 aligned pairs for learning to turn a specification into a formal statement.
- Verified code generation. Every program comes with its problem, its test cases, its Lean translation and the full record of how it was written.
The task
You are given one program (its Lean translation) and one theorem about it, stated in Lean with
sorry as its proof. Prove the theorem, or prove its negation. Every theorem comes with its
negation already stated (lean_negation), so a refutation always targets the same statement.
A solution is a copy of the program's specification file (lean_specs) in which that one
theorem (or its negation) has a proof. You may add any definitions and lemmas you need before
it, and you may add imports from the same Lean, Mathlib and Aeneas versions. You may not change
the statement. The proof must not use sorry, and it may only use the standard axioms
propext, Quot.sound and Classical.choice. This rules out native_decide, which adds an
axiom of its own.
The check is mechanical. Lean's built-in lake comparator compares the solution with the
original statement, checks the axioms, and replays the proof in the Lean kernel (see "Checking a
proof" below). Nothing is graded by hand or by a model.
An example
LeetCode 633, sum-of-square-numbers: given c, decide whether c = a² + b² for some integers
a and b. The Rust program:
pub fn judge_square_sum(c: i64) -> bool {
let mut b: i64 = 0;
while (b + 1) * (b + 1) <= c {
b += 1;
}
let mut a: i64 = 0;
while a <= b {
let sum = a * a + b * b;
if sum == c {
return true;
}
if sum < c {
a += 1;
} else {
b -= 1;
}
}
false
}
Its main theorem, spec_1, and the theorem that it never fails, spec_2:
/-- Whenever judge_square_sum(c) returns a result r, r = true if and only if there exist integers a and b such that a*a + b*b = c.
Preconditions: c is an integer with 0 <= c <= 2147483647 (2^31 - 1). -/
theorem spec_1 (c : Std.I64) (r : Bool)
(hc0 : 0 ≤ c.val) (hc1 : c.val ≤ 2147483647)
(hr : judge_square_sum c = ok r) :
(r = true ↔ ∃ a b : ℤ, a * a + b * b = c.val) := by
sorry
/-- The function judge_square_sum(c) returns a result r; it does not fail, panic, or overflow.
Preconditions: c is an integer with 0 <= c <= 2147483647 (2^31 - 1). -/
theorem spec_2 (c : Std.I64)
(hc0 : 0 ≤ c.val) (hc1 : c.val ≤ 2147483647) :
∃ r : Bool, judge_square_sum c = ok r := by
sorry
Together the two say that the program always returns, and that what it returns is the right
answer. Neither says anything about how the program works. To prove spec_1 you need an
invariant for the two-pointer loop: it never skips a pair (a, b) that could sum to c. To
prove spec_2 you need to show that both loops terminate and that (b + 1) * (b + 1) and
a * a + b * b never overflow 64 bits for any c in the range. The program has 6 more
theorems, about witnesses, invariance and the relation between inputs and outputs.
Why this is hard
The Lean code is a faithful model of the Rust program, so a proof has to deal with everything the program does:
- Integers are 64-bit machine integers. Every
+,*and-can overflow, and the proof must show it does not. - Every operation that can panic in Rust (overflow, index out of bounds, division by zero)
returns a
Resultin Lean, and the proof must rule the failure out or reason about it. - Loops become recursive functions. Each one needs an invariant and a termination argument.
- Vectors are lists, mutation becomes passing updated copies, and the code is written for execution, not for proofs.
- The theorems are stated against the problem, not the code. The main theorems relate the program to a mathematical definition of the answer (a maximum over all subsets, the existence of a valid ordering, the least number of insertions that makes a string a palindrome), so a proof must connect the algorithm to that definition.
The paper that introduced this methodology found that tasks of this kind stay hard even for
provers that nearly saturate competition benchmarks. For a sense of scale here: a machine-found
proof of the main theorem of
maximum-tastiness-of-candy-basket, a Medium problem solved by binary search with a greedy
check, is about 1,000 lines of Lean with 44 lemmas and definitions.
Quick start
from datasets import load_dataset
programs = load_dataset("Debargha/leetcode-rust-lean", "programs")
specs = load_dataset("Debargha/leetcode-rust-lean", "specs")
s = specs["test"][0]
print(s["task_id"], s["theorem"]) # e.g. shortest-distance-after-road-addition-queries-i AegisSpec.ShortestDistanceAfterQueries.spec_1
print(s["statement"]) # the property in natural language
print(s["lean_statement"]) # the same property in Lean
p = programs["test"].filter(lambda r: r["task_id"] == s["task_id"])[0]
print(p["lean_specs"]) # the Lean file with every theorem of this program
The two subsets
programs has one row per program. specs has one row per theorem. They join on task_id.
programs
| Column | What it is |
|---|---|
task_id, question_id |
LeetCode slug and number, e.g. running-sum-of-1d-array, 1480 |
difficulty |
Easy, Medium or Hard |
tags |
LeetCode topic tags |
description |
the problem statement |
leetcode_signature |
the original (Python-style) signature, e.g. runningSum(nums: list_int) -> list_int |
rust_signature |
the Rust signature the solution implements, e.g. pub fn running_sum(nums: &[i64]) -> Vec<i64> |
rust_solution |
the Rust program (safe Rust only; see "The Rust subset") |
lean_function |
full Lean name of the translated function, e.g. Aegis.RunningSum.running_sum |
lean_types |
Lean type definitions produced by Aeneas (Types.lean) |
lean_funs |
Lean function definitions produced by Aeneas (Funs.lean). This is the main Lean file. |
lean_funs_external |
Lean models of Rust library functions Aeneas cannot translate itself (e.g. Vec::pop, sort). Empty for most rows (non-empty for 168). |
lean_specs |
the Lean file stating this program's theorems (see below) |
num_specs |
number of theorems in lean_specs |
lean_eval |
a Lean file that runs the Lean function on test cases and prints CASE <i> true/false |
test_cases |
all test cases: list of {input, output} (JSON strings), sorted from smallest to largest input |
num_test_cases |
how many test cases (3 to 450, median 97) |
order_insensitive |
true if the problem says "return the answer in any order". Then outputs were compared as multisets (64 rows). |
rust_cases_passed |
test cases the Rust passes. Always equal to num_test_cases. |
lean_check |
result of running the Lean translation on the 10 smallest test cases: verified or verified_partial (see "How the programs were checked") |
lean_check_cases, lean_check_cases_true |
how many cases that check used, and how many the Lean reproduced |
num_llm_calls |
how many times the model was called to write this program (1 for 1,801 rows) |
total_completion_tokens |
total tokens the model generated for it, reasoning included |
trajectory |
the full history of how the program was written; see "The trajectory" |
specs
| Column | What it is |
|---|---|
task_id |
the program this theorem is about |
spec_id |
n in spec_n, numbered in file order |
theorem |
full Lean name, e.g. AegisSpec.JudgeSquareSum.spec_1 |
main |
true for the program's main theorem (exactly one per program) |
category |
what kind of property it is (table below) |
statement |
the property in natural language |
preconditions |
the assumptions on the inputs, in natural language (usually the problem's constraints) |
lean_statement |
the theorem in Lean, exactly as in lean_specs |
lean_negation |
its negation, theorem spec_n_neg : ¬ (∀ ..., ...), to prove if the theorem is false |
difficulty |
difficulty of the problem |
category |
Theorems | 24,617 (train 22,557 / test 2,060), on 2,124 programs |
|---|---|---|
relational |
4,683 | how the output relates to the input or to itself (e.g. the output is a permutation of the input) |
edge |
4,429 | behaviour on special inputs (empty, single element, all equal, ...) |
bounds |
4,102 | the output lies in a range |
invariance |
3,015 | the output does not change under some change of the input (reversal, relabelling, ...) |
functional |
2,904 | the output is exactly a mathematically defined answer. All main theorems are here. |
witness |
2,140 | the output is achieved by some explicit object (a subset, a path, an index) |
no_failure |
2,100 | the program returns a result: no overflow, no out-of-bounds access, no panic |
shape |
1,183 | length, sortedness or structure of the output |
monotonicity |
61 | the output grows or shrinks with the input |
The Lean specification file
lean_specs is a complete Lean file. It imports the program (import Aegis.<Problem>.Code.Funs),
defines the helper notions the theorems need, and states every theorem of the program inside
namespace AegisSpec.<Problem>, each with its natural-language statement as its docstring and
sorry as its proof. Some files also contain small helper lemmas with complete proofs. Every
file in the dataset builds, and so does every theorem's negation.
As in all Aeneas-based verification, the theorems are about the Lean translation of the program,
with the definitions in lean_funs_external taken as given.
Checking a proof
Lay out a Lake project like this (<Problem> is the second component of lean_function):
lakefile.toml
lean-toolchain leanprover/lean4:v4.36.0
config.json
Aegis/<Problem>/Code/Types.lean lean_types
Aegis/<Problem>/Code/Funs.lean lean_funs
Aegis/<Problem>/Code/FunsExternal.lean lean_funs_external (only if non-empty)
Proofs/Challenge.lean lean_specs, unchanged
Proofs/Solution.lean your copy of lean_specs, with the proof
lakefile.toml:
name = "aegis"
[[lean_lib]]
name = "Aegis"
globs = ["Aegis.+"]
[[lean_lib]]
name = "Proofs"
globs = ["Proofs.+"]
[[require]]
name = "aeneas"
git = "https://github.com/AeneasVerif/aeneas.git"
rev = "0c19cd5bff9298565362c6ca9c4f48a29033a0e9"
subDir = "backends/lean"
config.json, naming the theorem you proved:
{
"challenge_module": "Proofs.Challenge",
"solution_module": "Proofs.Solution",
"theorem_names": ["AegisSpec.JudgeSquareSum.spec_2"],
"permitted_axioms": ["propext", "Quot.sound", "Classical.choice"]
}
Then:
lake update && lake exe cache get # fetch Aeneas and Mathlib, download the Mathlib cache
lake build Proofs.Challenge Proofs.Solution
lake comparator --config config.json # needs bwrap (Bubblewrap) on PATH
The last command prints Your solution is okay! when the proof is accepted. To refute a theorem
instead, add its lean_negation right after the theorem in both files, prove it in
Solution.lean, and name spec_n_neg in config.json. Several theorems of the same
program can be checked at once by listing them all in theorem_names.
How the theorems were written
The theorems were written the way the paper describes, in three steps:
- A model wrote 5 to 20 properties per program in natural language, from the problem statement, the function signature and examples, but not from the code. The properties describe what the program should do, not what it happens to do.
- A second, independent review pass checked every property, fixed or removed unclear and redundant ones, and added the ones that were missing.
- A Lean agent stated each property as a Lean theorem about the extracted program.
Every resulting file was then checked mechanically: it builds from scratch, every property has
its theorem, every theorem's negation elaborates, the only sorrys are the theorem proofs, and
every theorem constrains the program's actual behaviour (statements that never mention the
program or never use its result were removed). The model is DeepSeek-V4.1-Flash throughout.
The theorems were fixed before any proof was attempted. A theorem that claims more than the program guarantees is solved by proving its negation.
Evaluating a prover
We suggest reporting results on the test split: 2,060 theorems about 175 programs. Report
the fraction of theorems solved (a proof of the theorem or of its negation), overall and for the
main theorems, by difficulty and by category, together with the attempt and time budget per
theorem. The paper uses 30 minutes per theorem. A prover may read everything in the dataset
row: the problem, the Rust code, the Lean code and the other theorems of the same program.
How the programs were checked
Rust: every program passes all of its test cases with cargo test (debug build, so an
integer overflow counts as a failure, not a silent wrap-around).
Lean: Aeneas translates the Rust program into Lean. We then run the Lean version with
Lean's #eval on the 10 smallest test cases and check that it returns the same answers:
verified: the Lean reproduced all 10 (2,094 rows).verified_partial: the Lean reproduced at least 3, never gave a wrong answer, and the rest were too slow or too big to finish (32 rows, mostly dynamic programming).
Lean is slow on large inputs because its version of the program is written for proofs, not
speed. Aeneas represents a Rust vector as a list (so v[i] takes time proportional to i)
and every integer as a bit-vector with overflow checks.
How to read the Lean code
Aeneas turns each Rust function into a Lean function that returns a Result:
def running_sum (nums : Slice Std.I64) : Result (alloc.vec.Vec Std.I64) :=
...
Result αis "either a value of typeα, or an error".ok xmeans success with valuex.fail emeans the Rust program would have panicked: integer overflow, index out of bounds, division by zero, and so on.doand←chain steps that can fail, like Rust's?.let x ← f yrunsf y, stops with the error if it fails, and otherwise names the resultx.- Machine integers are
Std.I64,Std.Usize,Std.U8, ...x.valis the value ofxas a mathematical integer, which is how the theorems talk about numbers. Literals look like5#i64. Arithmetic such asx + yreturns aResult, because it can overflow. Slice αis a Rust slice&[α], andalloc.vec.Vec αis a RustVec<α>. Their contents as a plain Lean list ares.val.- Loops become two functions:
f_loop0.body(one iteration) andf_loop0(the loop), built fromloop, which repeats the body until it returnsdone. - Strings are byte arrays: Rust
&[u8]/Vec<u8>, LeanSlice Std.U8. - Trees and linked lists are Rust enums, translated to Lean inductive types in
lean_types. lean_funs_externalholds hand-written Lean models of the few Rust library functions Aeneas cannot translate (Vec::pop,[T]::sort,Veccomparison, the panic raised by%on zero). These are trusted definitions, not machine translations.
The trajectory
trajectory (in programs) is the list of events recorded while the program was produced.
type |
Meaning | Main fields |
|---|---|---|
run_start |
start of an attempt. A retry says what failed before in note. |
note |
llm |
one call to the language model | messages (full input), response, reasoning, finish_reason, prompt_tokens, completion_tokens, cached_prompt_tokens |
tool |
one tool run | command, exit_code, timed_out, output, duration_ms |
llm_error |
an API error that was retried | note |
run_end |
end of an attempt | verdict, note |
phase tells you which step an event belongs to: rust (write the program and run
cargo test), extract (translate with Charon and Aeneas), lean (build the Lean and
evaluate it), or lean_repair_rust / lean_repair_extract (rewrite the program after the
Lean failed to build). When a step fails, its error output goes back to the model, which
writes a new version. The model is DeepSeek-V4.1-Flash at its default reasoning effort.
The Rust subset
Aeneas only translates part of Rust. The solutions therefore use plain code only: i64,
usize, bool, u8 values; slices and Vecs; while/for loops with explicit indexing;
no HashMap/HashSet, no String (strings are &[u8] bytes), no closures or iterator
chains, no unsafe. Backtracking is written with an explicit stack rather than recursion
inside a loop. The code can look unusual compared to idiomatic Rust.
Numbers
| Programs | 2,126 (train 1,951 / test 175, the split of the source dataset) |
| Difficulty | Easy 523, Medium 1,124, Hard 479 |
| Theorems | 24,617 (train 22,557 / test 2,060), on 2,124 programs |
| Theorems per program | 2 to 20, median 12 |
| Theorems by difficulty | Easy 5,600, Medium 13,319, Hard 5,698 |
| Test cases | 202,511 (3 to 450 per program, median 97) |
| Median size | Rust 49 lines, Lean Funs.lean 172 lines |
The train/test split follows the source dataset. Theorems inherit the split of their program, so no program or theorem appears in both splits.
Versions
Lean 4 v4.36.0, Aeneas 0c19cd5b, Charon 5a2a17bd, Mathlib at the revision Aeneas pins
(fc4f59e5).
Source and license
Problems, statements and test cases come from newfacade/LeetCodeDataset (Apache-2.0). The problems themselves are from LeetCode. This dataset is released under the MIT license.
Citation
If you use this dataset, please cite:
@misc{ganguly2026scalingleantheoremproving,
title={Scaling Lean Theorem Proving for Real-World Code Verification},
author={Debargha Ganguly and Divya Raghunathan and Dejan Jovanović and Vikash Singh and Soonho Kong and Aaron Tomb and Aman Goel and Ferhat Erata and Sam Bayless},
year={2026},
eprint={2610.38174},
archivePrefix={arXiv},
primaryClass={cs.CL},
url={https://arxiv.org/abs/2610.38174},
}
- Downloads last month
- 61