description
stringlengths 66
400
| function_signature
stringlengths 20
247
| test_cases
null | theorem_signature
stringlengths 53
241
β | theorem2_signature
stringlengths 40
106
β |
---|---|---|---|---|
write a function that, given integers a and b, returns an integer x such that a + x = b | def solveAdd (a b:Int): Int | null | theorem solveAdd_correct (a b: Int): a + (solveAdd a b) =b | null |
write a function that, given integer a, returns an integer x such that a + x = 0 | def solveAdd0(a:Int): Int | null | theorem solveAdd0_correct(a: Int): a +(solveAdd0 a)=0 | null |
write a function that, given integers a and b, returns an integer x such that a - x = b | def solveSub(a b:Int): Int | null | theorem solveSub_correct(a b:Int): a - (solveSub a b)=b | null |
write a function that, given rationals a and b, return some x such that a*x=b. if no solution exists, return none | def solve1x1(a b: Rat): Option Rat | null | theorem solve1x1_correct(a b:Rat): (β x, a*x=b) -> a * (solve1x1 a b).get! =b | theorem solve1x1_none(a b:Rat): (Not (β x, a*x=b)) -> solve1x1 a b=none |
write a function that, given rational a, returns a rational x such that a*x=1. If no solution exists, return 0. | def solveMul(a: Rat): Rat | null | theorem solveMul_correct(a:Rat): (β x, a*x=1)->a * (solveMul a)=1 | theorem solveMul_nosol (a:Rat): (Not (β x, a*x=1)) ->solveMul a =0 |
write a function that, given rationals a and b, both not equal to zero, return x such that a/x=b. | def solveDiv(a b:Rat) (ha: aβ 0)(hb: bβ 0): Rat | null | theorem solveDiv_correct(a b:Rat)(ha:aβ 0)(hb: bβ 0):
a / (solveDiv a b ha hb)= b | null |
write a function isPrime that given a natural number a, returns true if and only if a is prime. | def isPrime(a: Nat): Bool | null | theorem isPrime_correct(a: Nat): (isPrime a)=True <-> Nat.Prime a | null |
write a function that given a natrual number a and a prime number p, returns a natural number x such that (a*x)%p=1. if no solution exists, return none. | def modInv(a: Nat) (p:Nat)(hp:p.Prime): Option Nat | null |
theorem modInv_correct(a:Nat) (p:Nat)(hp:p.Prime):
(β x:Nat, (a*x)%p=1)->(a*(modInv a p hp).get!)%p=1 | theorem modInv_none(a:Nat) (p:Nat)(hp:p.Prime): (Not (β x, (a*x)%p=1))-> modInv a p hp=none |
write a function that given a natural number a, a>1, find the minimum factor of a that is not 1. | def minFac(a:Nat) (h: a>1): Nat | null | theorem minFac_isfac(a:Nat)(h: a>1): ( (minFac a h) β£a) β§(minFac a h>1) | theorem minFac_ismin(a:Nat)(h:a>1): Not (β y>1,( y β£ a) β§y<minFac a h) |
write a function that, given rational number coordinates of two points x1, y1 and x2, y2, return the rational number coordinates of a point (xmid, ymid) such that: the distance betwee (xmid,ymid) and (x1, y1) is equal to the distance between (xmid,ymid) and (x2,y2), which is equal to half of the distance between (x1, y1) and (x2, y2). | def midPoint (x1 y1 x2 y2: Rat):Rat Γ Rat | null | def distSq( x1 y1 x2 y2: Rat):Rat:=
(x1-x2)^2 + (y1-y2)^2
theorem midPoint_correct (x1 y1 x2 y2: Rat)
: let (xmid,ymid) :=midPoint x1 y1 x2 y2
distSq xmid ymid x1 y1=distSq xmid ymid x2 y2
β§ 4*(distSq xmid ymid x1 y1)=distSq x1 y1 x2 y2 | null |
write a function that, given natural numbers a and b, computes their greatest common denominator. | def GCD(a b:Nat):Nat | null |
theorem gcd_is_div (x y: Nat):
(p: x > 0)β ((GCD x y) β£ x) β§ ((GCD x y) β£ y) |
theorem gcd_is_greatest (x y: Nat):
(x>0) β Not (β z: Nat, zβ£ x β§ zβ£ y β§ z> GCD x y ) |
write a function that, given natural number t, find the minimum n such that 1+2+β¦+n>=t. | def solveProg(t:Nat):Nat | null | theorem solveProg_isgeq(t:Nat): (solveProg t)*((solveProg t)+1) >= t*2 | theorem solveProg_ismin(t:Nat): Not (β y< (solveProg t), y*(y+1)>=t*2) |
write a function that, given natural numbers a and t, with a>1, find the minimum n such that a^0+a^1+..a^n >=t. | def solveGeom(a t:Nat)(h:a>1):Nat | null | theorem solveGeom_isgeq(a t:Nat)(h:a>1): a^((solveGeom a t h)+1)-1 >=t*(a-1) | theorem solveGeom_ismin(a t:Nat)(h:a>1): Not (β y<solveGeom a t h, a^(y+1)-1>= t*(a-1)) |
write a function that, given natural number t, find the minimum n such that n*n>=t. | def solveSquare(t:Nat): Nat | null | theorem solveSquare_isgeq(t:Nat): (solveSquare t)*(solveSquare t)>=t | theorem solveSquare_ismin(t:Nat): Not (β y< (solveSquare t), y*y>=t) |
Implement the following in lean 4. Given a binary operator op, we define the function f : Nat->Nat to be: f 0 =1; f 1=1; f n = op (f (n-1)) (f (n-2)). Write a lean 4 function that, given the op and the natural number n as arguments, computes f n. Additionally, op returns a value wrapped in a monad. Your function should have the signature def f [Monad m] (op: Nat->Nat->(m Nat)) (n: Nat): (m Nat) := | def f[Monad m] (op: Nat->Nat->(m Nat)) (n: Nat): (m Nat) | null | theorem f_base (op : Nat β Nat β Id Nat) :
(f op 0 = pure 1) β§ (f op 1 = pure 1) | theorem f_recursive (op : Nat β Nat β Id Nat) (n : Nat) : f op (n+2) =do {op (β f op (n+1)) (β f op n) } |
write a function that, given a List of integers, return the list in reverse order. | def rev(xs: List Int): List Int | null | theorem reverse_correct(xs:List Int):
xs.length=(rev xs).length β§
β i<xs.length, xs[i]! =(rev xs)[xs.length-1-i]! | null |
write a function that, given a List of integers, finds its maximum | def findMax (xs : List Int) : Option Int | null |
theorem findMax_correct(x: Int) (xs : List Int):
β maxβ (x::xs),
And (findMax (x::xs) = some max) (β y β (x::xs) , y β€ max) | theorem findMax_base : findMax [] = none |
write a function that, given a List of integers, finds the minimum | def findMin (xs : List Int) : Option Int | null |
theorem findMin_correct(x: Int) (xs : List Int):
β minβ (x::xs),
And (findMin (x::xs) = some min) (β y β (x::xs) , y >= min) | theorem findMin_base : findMin [] = none |
write a function that, given an integer x and a List of integers, returns true if and only if x is in the List | def isIn (x:Int) (xs: List Int):Bool | null | def isIn_correct (x:Int)(xs:List Int):
isIn x xs = true β xβ xs | null |
write a function that, given an integer x and a List of integers, returns the number of times that x appears in the list. |
def countEq (x:Int)(xs:List Int):Nat | null | def countEq_correct (x:Int)(xs:List Int):
List.count x xs = countEq x xs | null |
write a function that, given a List of integers and a predicate function p that takes an integer and returns a boolean, returns an element of the list x if p x = true. If such x does not exist, return none | def findIf(xs:List Int)(p:Int->Bool):Option Int | null |
theorem findIf_some(xs:List Int)(p:Int->Bool):
(β xβ xs, p x) -> β yβ xs, findIf xs p=some y β§ p y |
theorem findIf_none(xs:List Int)(p:Int->Bool):
(Β¬ β yβ xs, p y =true)-> findIf xs p=none |
write a function that, given a List of integers and a predicate function p that takes an integer and returns a boolean, returns another list consisting of elements x of the original list such that p x = true. | def filterIf(xs:List Int)(p:Int->Bool):List Int | null |
theorem filterIf_correct(xs:List Int)(p:Int->Bool):
filterIf xs p = List.filter p xs | null |
write a function that, given a List of integers xs and a function f:Int->Int, returns a List of integers whose i-th element is f xs[i] | def mapInt(xs:List Int)(f:Int->Int):List Int | null | theorem mapInt_correct(xs:List Int)(f:Int->Int)
: (mapInt xs f).length=xs.length
β§ β i:Fin xs.length, (mapInt xs f)[i]! = f xs[i] | null |
Write a function that, given two lists of integers, find their longest common prefix. | def isPrefix (p xs:List Ξ±):=
List.take p.length xs = p
/- longest common prefix for a pair of lists-/
def lcpPair:(xs ys:List Int )
->{zs:List Int//isPrefix zs xs⧠isPrefix zs ys
β§ (βzz, isPrefix zz xsβ§ isPrefix zz ys->zz.length<=zs.length)} | null | null | null |
Code with Proofs Benchmark
Main essay: A Proposal for Safe and Hallucination-free Coding AI
This dataset contains an initial benchmark set of code-with-proof problems with solutions. There are 24 problems, mostly simple non-recursive functions and simple recursion on natural numbers and lists. Each problem statement consists of a natural language description, a function signature, and the formal specification consisting of up to two theorem statements. Currently in Lean only; translation to other languages is welcome.
Files
easy.jsonl
: the problem statements in JSONL format. Fields include "description", "function_signature", "theorem_signature", "theorem2_signature"EasyBenchmark.lean
: the solutions including function implementations and proofs. Requires Mathlib.
- Downloads last month
- 54