id
stringlengths 14
18
| description
stringlengths 321
1.77k
| lean_code
stringlengths 1.1k
7.34k
| signature
dict | metadata
dict | tests
sequence | reject_inputs
sequence | difficulty
stringclasses 2
values |
---|---|---|---|---|---|---|---|
verina_basic_53 | -----Description-----
This problem asks for a method to determine the sum of the first N natural numbers. The task focuses on computing the total when given an input N, ensuring that the value is 0 when N is 0 and correctly calculated for positive values of N.
-----Input-----
The input consists of:
• N: A natural number (Nat) representing the count of the first natural numbers to sum.
-----Output-----
The output is a natural number (Nat), which is the sum of the first N natural numbers computed as: N * (N + 1) / 2.
-----Note-----
The computation leverages a recursive implementation. There are no additional preconditions beyond providing a valid natural number. | -- !benchmark @start import type=solution
-- !benchmark @end import
-- !benchmark @start solution_aux
-- !benchmark @end solution_aux
-- !benchmark @start precond_aux
-- !benchmark @end precond_aux
@[reducible, simp]
def CalSum_precond (N : Nat) : Prop :=
-- !benchmark @start precond
True
-- !benchmark @end precond
-- !benchmark @start code_aux
-- !benchmark @end code_aux
def CalSum (N : Nat) (h_precond : CalSum_precond (N)) : Nat :=
-- !benchmark @start code
let rec loop (n : Nat) : Nat :=
if n = 0 then 0
else n + loop (n - 1)
loop N
-- !benchmark @end code
-- !benchmark @start postcond_aux
-- !benchmark @end postcond_aux
@[reducible, simp]
def CalSum_postcond (N : Nat) (result: Nat) (h_precond : CalSum_precond (N)) :=
-- !benchmark @start postcond
2 * result = N * (N + 1)
-- !benchmark @end postcond
-- !benchmark @start proof_aux
-- !benchmark @end proof_aux
theorem CalSum_spec_satisfied (N: Nat) (h_precond : CalSum_precond (N)) :
CalSum_postcond (N) (CalSum (N) h_precond) h_precond := by
-- !benchmark @start proof
unfold CalSum_postcond CalSum
induction N with
| zero =>
unfold CalSum.loop
simp
| succ n ih =>
unfold CalSum_precond at ih
simp at ih
unfold CalSum.loop
simp
rw [Nat.mul_add]
rw [ih]
rw [← Nat.add_mul]
rw [Nat.add_comm, Nat.mul_comm]
-- !benchmark @end proof
| {
"name": "CalSum",
"parameters": {
"param_name": [
"N"
],
"param_type": [
"Nat"
]
},
"return_type": "Nat"
} | {
"upstream": {
"name": "clover",
"link": "https://github.com/ChuyueSun/Clover",
"task_id": "Clover_cal_sum",
"student_id": null
}
} | {
"input": [
"{\"N\": 0}",
"{\"N\": 1}",
"{\"N\": 5}",
"{\"N\": 10}",
"{\"N\": 20}"
],
"expected": [
[
"0"
],
[
"1"
],
[
"15"
],
[
"55"
],
[
"210"
]
],
"unexpected": [
[
"1",
"2",
"3"
],
[
"0",
"2",
"3"
],
[
"10",
"16",
"20"
],
[
"54",
"56",
"50"
],
[
"200",
"220",
"205"
]
]
} | {
"input": []
} | basic |
verina_advanced_9 | -----Description-----
This task requires writing a Lean 4 method of which given a number n and divisor d, it counts all the number that is smaller than
n whose sum of digits is divisible by d.
-----Input-----
The input consists of three Nat:
n: Nat
d:Nat where d > 0
-----Output-----
The output is an Natural number:
Ensure this match the count that satisfy the property.
| -- !benchmark @start import type=solution
-- !benchmark @end import
-- !benchmark @start solution_aux
def sumOfDigits (x : Nat) : Nat :=
let rec go (n acc : Nat) : Nat :=
if n = 0 then acc
else go (n / 10) (acc + (n % 10))
go x 0
-- !benchmark @end solution_aux
-- !benchmark @start precond_aux
-- !benchmark @end precond_aux
@[reducible]
def countSumDivisibleBy_precond (n : Nat) (d : Nat) : Prop :=
-- !benchmark @start precond
d > 0
-- !benchmark @end precond
-- !benchmark @start code_aux
def isSumDivisibleBy (x : Nat) (d:Nat) : Bool :=
(sumOfDigits x) % d = 0
-- !benchmark @end code_aux
def countSumDivisibleBy (n : Nat) (d : Nat) (h_precond : countSumDivisibleBy_precond (n) (d)) : Nat :=
-- !benchmark @start code
let rec go (i acc : Nat) : Nat :=
match i with
| 0 => acc
| i'+1 =>
let acc' := if isSumDivisibleBy i' d then acc + 1 else acc
go i' acc'
go n 0
-- !benchmark @end code
-- !benchmark @start postcond_aux
-- !benchmark @end postcond_aux
@[reducible]
def countSumDivisibleBy_postcond (n : Nat) (d : Nat) (result: Nat) (h_precond : countSumDivisibleBy_precond (n) (d)) : Prop :=
-- !benchmark @start postcond
(List.length (List.filter (fun x => x < n ∧ (sumOfDigits x) % d = 0) (List.range n))) - result = 0 ∧
result ≤ (List.length (List.filter (fun x => x < n ∧ (sumOfDigits x) % d = 0) (List.range n)))
-- !benchmark @end postcond
-- !benchmark @start proof_aux
-- !benchmark @end proof_aux
theorem countSumDivisibleBy_spec_satisfied (n: Nat) (d: Nat) (h_precond : countSumDivisibleBy_precond (n) (d)) :
countSumDivisibleBy_postcond (n) (d) (countSumDivisibleBy (n) (d) h_precond) h_precond := by
-- !benchmark @start proof
sorry
-- !benchmark @end proof
| {
"name": "countSumDivisibleBy",
"parameters": {
"param_name": [
"n",
"d"
],
"param_type": [
"Nat",
"Nat"
]
},
"return_type": "Nat"
} | {
"upstream": {
"name": "lab_assignment",
"link": "this is a leetcode style problem but not a specifc one. similar to this: https://leetcode.com/problems/count-the-digits-that-divide-a-number/description/",
"task_id": "lab_countSumDivisibleBy_325011347",
"student_id": [
7
]
}
} | {
"input": [
"{\"n\": 0, \"d\": 2}",
"{\"n\": 1, \"d\": 2}",
"{\"n\": 10, \"d\": 3}",
"{\"n\": 12, \"d\": 2}",
"{\"n\": 20, \"d\": 5}"
],
"expected": [
[
"0"
],
[
"1"
],
[
"4"
],
[
"6"
],
[
"4"
]
],
"unexpected": [
[
"1"
],
[
"0"
],
[
"3",
"5"
],
[
"3",
"5"
],
[
"0",
"10"
]
]
} | {
"input": [
"{'n': 1, 'd': 0}"
]
} | advanced |
verina_advanced_34 | -----Description-----
This task requires writing a Lean 4 method that finds the length of the longest strictly increasing subsequence from a given list of integers.
-----Input-----
The input consists of a list of integers called nums
-----Output-----
The output is an integer:
Returns a number representing the length of the longest strictly increasing subsequence found in the input list.
| -- !benchmark @start import type=solution
import Mathlib.Data.List.Basic
-- !benchmark @end import
-- !benchmark @start solution_aux
-- !benchmark @end solution_aux
-- !benchmark @start precond_aux
-- !benchmark @end precond_aux
@[reducible]
def longestIncreasingSubsequence_precond (nums : List Int) : Prop :=
-- !benchmark @start precond
True
-- !benchmark @end precond
-- !benchmark @start code_aux
-- !benchmark @end code_aux
def longestIncreasingSubsequence (nums : List Int) (h_precond : longestIncreasingSubsequence_precond (nums)) : Int :=
-- !benchmark @start code
Id.run do
if nums.isEmpty then return 0
let mut sub : Array Int := Array.empty
sub := sub.push nums.head!
for num in nums.tail do
if num > sub[sub.size - 1]! then
sub := sub.push num
else
-- << binary search >>
let mut left : Nat := 0
let mut right : Nat := sub.size - 1
while left < right do
let mid := (left + right) / 2
if sub[mid]! == num then
right := mid
else if sub[mid]! < num then
left := mid + 1
else
right := mid
sub := sub.set! left num
return Int.ofNat sub.size
-- !benchmark @end code
-- !benchmark @start postcond_aux
-- !benchmark @end postcond_aux
@[reducible]
def longestIncreasingSubsequence_postcond (nums : List Int) (result: Int) (h_precond : longestIncreasingSubsequence_precond (nums)) : Prop :=
-- !benchmark @start postcond
let allSubseq := (nums.foldl fun acc x => acc ++ acc.map (fun sub => x :: sub)) [[]] |>.map List.reverse
let increasingSubseqLens := allSubseq.filter (fun l => List.Pairwise (· < ·) l) |>.map (·.length)
increasingSubseqLens.contains result ∧ increasingSubseqLens.all (· ≤ result)
-- !benchmark @end postcond
-- !benchmark @start proof_aux
-- !benchmark @end proof_aux
theorem longestIncreasingSubsequence_spec_satisfied (nums: List Int) (h_precond : longestIncreasingSubsequence_precond (nums)) :
longestIncreasingSubsequence_postcond (nums) (longestIncreasingSubsequence (nums) h_precond) h_precond := by
-- !benchmark @start proof
sorry
-- !benchmark @end proof
| {
"name": "longestIncreasingSubsequence",
"parameters": {
"param_name": [
"nums"
],
"param_type": [
"List Int"
]
},
"return_type": "Int"
} | {
"upstream": {
"name": "lab_assignment",
"link": "https://leetcode.com/problems/longest-increasing-subsequence/description/",
"task_id": "lab_longestIncreasingSubsequence_325773003",
"student_id": [
28
]
}
} | {
"input": [
"{\"nums\": \"[10, 9, 2, 5, 3, 7, 101, 18]\"}",
"{\"nums\": \"[0, 1, 0, 3, 2, 3]\"}",
"{\"nums\": \"[7, 7, 7, 7, 7, 7, 7]\"}",
"{\"nums\": \"[1, 3, 2, 4]\"}",
"{\"nums\": \"[10]\"}"
],
"expected": [
[
"4"
],
[
"4"
],
[
"1"
],
[
"3"
],
[
"1"
]
],
"unexpected": [
[
"3",
"100"
],
[
"3",
"100"
],
[
"7",
"7"
],
[
"2",
"4"
],
[
"0"
]
]
} | {
"input": []
} | advanced |
verina_advanced_13 | -----Description-----
This task requires writing a Lean 4 method that determines whether there are any intersections between chords on a circle. The method should return true if at least one pair of chords intersects, and false otherwise.
A chord is defined as a line segment connecting two distinct points on a circle. Two chords intersect if they cross each other inside the circle. The points are numbered from 1 to 2N in a clockwise direction, where N is the number of chords.
Constraints
- 2\leq N \leq 2\times 10^5
- 1\leq A_i,B_i \leq 2N
- A_1,\dots,A_N,B_1,\dots,B_N are all distinct
- All input values are integers
-----Input-----
The input consists of two parameters:
N: A natural number representing the number of chords (2 ≤ N ≤ 2×10^5).
chords: A list of N pairs of natural numbers, where each pair represents the endpoints of a chord. All endpoint values are distinct and range from 1 to 2N.
-----Output-----
The output is a boolean value:
- Returns true if there exists at least one pair of intersecting chords.
- Returns false if no chords intersect.
| -- !benchmark @start import type=solution
-- !benchmark @end import
-- !benchmark @start solution_aux
-- !benchmark @end solution_aux
-- !benchmark @start precond_aux
-- !benchmark @end precond_aux
@[reducible]
def hasChordIntersection_precond (N : Nat) (chords : List (List Nat)) : Prop :=
-- !benchmark @start precond
N ≥ 2 ∧
chords.all (fun chord => chord.length = 2 ∧ chord[0]! ≥ 1 ∧ chord[0]! ≤ 2 * N ∧ chord[1]! ≥ 1 ∧ chord[1]! ≤ 2 * N) ∧
List.Nodup (chords.flatMap id)
-- !benchmark @end precond
-- !benchmark @start code_aux
-- !benchmark @end code_aux
def hasChordIntersection (N : Nat) (chords : List (List Nat)) (h_precond : hasChordIntersection_precond (N) (chords)) : Bool :=
-- !benchmark @start code
let sortedChords := chords.map (fun chord =>
let a := chord[0]!
let b := chord[1]!
if a > b then [b, a] else [a, b]
)
let rec checkIntersection (stack : List (List Nat)) (remaining : List (List Nat)) : Bool :=
match remaining with
| [] => false
| chord :: rest =>
let a := chord[0]!
let b := chord[1]!
let newStack := stack.dropWhile (fun c => (c)[1]! < a)
match newStack with
| [] => checkIntersection (chord :: newStack) rest
| top :: _ =>
if top[1]! > a && top[1]! < b then
true
else
checkIntersection (chord :: newStack) rest
let rec insert (x : List Nat) (xs : List (List Nat)) : List (List Nat) :=
match xs with
| [] => [x]
| y :: ys => if x[0]! < y[0]! then x :: xs else y :: insert x ys
let rec sort (xs : List (List Nat)) : List (List Nat) :=
match xs with
| [] => []
| x :: xs => insert x (sort xs)
let sortedChords := sort sortedChords
checkIntersection [] sortedChords
-- !benchmark @end code
-- !benchmark @start postcond_aux
-- !benchmark @end postcond_aux
@[reducible]
def hasChordIntersection_postcond (N : Nat) (chords : List (List Nat)) (result: Bool) (h_precond : hasChordIntersection_precond (N) (chords)) : Prop :=
-- !benchmark @start postcond
let sortedChords := chords.map (fun chord =>
let a := chord[0]!
let b := chord[1]!
if a > b then [b, a] else [a, b]
)
let rec hasIntersection (chord1 : List Nat) (chord2 : List Nat) : Bool :=
let a1 := chord1[0]!
let b1 := chord1[1]!
let a2 := chord2[0]!
let b2 := chord2[1]!
(a1 < a2 && a2 < b1 && b1 < b2) || (a2 < a1 && a1 < b2 && b2 < b1)
let rec checkAllPairs (chords : List (List Nat)) : Bool :=
match chords with
| [] => false
| x :: xs =>
if xs.any (fun y => hasIntersection x y) then true
else checkAllPairs xs
((List.Pairwise (fun x y => !hasIntersection x y) sortedChords) → ¬ result) ∧
((sortedChords.any (fun x => chords.any (fun y => hasIntersection x y))) → result)
-- !benchmark @end postcond
-- !benchmark @start proof_aux
-- !benchmark @end proof_aux
theorem hasChordIntersection_spec_satisfied (N: Nat) (chords: List (List Nat)) (h_precond : hasChordIntersection_precond (N) (chords)) :
hasChordIntersection_postcond (N) (chords) (hasChordIntersection (N) (chords) h_precond) h_precond := by
-- !benchmark @start proof
sorry
-- !benchmark @end proof
| {
"name": "hasChordIntersection",
"parameters": {
"param_name": [
"N",
"chords"
],
"param_type": [
"Nat",
"List (List Nat)"
]
},
"return_type": "Bool"
} | {
"upstream": {
"name": "lab_assignment",
"link": "https://huggingface.co/spaces/livecodebench/code_generation_samples",
"task_id": "lab_hasChordIntersection_325324847",
"student_id": [
11
]
}
} | {
"input": [
"{\"N\": 3, \"chords\": \"[[1, 3], [4, 2], [5, 6]]\"}",
"{\"N\": 3, \"chords\": \"[[6, 1], [4, 3], [2, 5]]\"}",
"{\"N\": 4, \"chords\": \"[[2, 4], [3, 7], [8, 6], [5, 1]]\"}",
"{\"N\": 2, \"chords\": \"[[1, 2], [3, 4]]\"}"
],
"expected": [
[
"True"
],
[
"False"
],
[
"True"
],
[
"False"
]
],
"unexpected": [
[
"False"
],
[
"True"
],
[
"False"
],
[
"True"
]
]
} | {
"input": [
"{'N': 3, 'chords': '[[1, 1]]'}",
"{'N': 3, 'chords': '[[7, 1]]'}",
"{'N': 3, 'chords': '[[0, 1]]'}",
"{'N': 3, 'chords': '[[1, 0]]'}",
"{'N': 3, 'chords': '[[1, 7]]'}",
"{'N': 0, 'chords': '[]'}"
]
} | advanced |
verina_basic_92 | -----Description-----
This problem involves swapping the values of two integers. Given two integers as inputs, the objective is to return the two numbers in reversed order.
-----Input-----
The input consists of two integers:
• X: The first integer.
• Y: The second integer.
-----Output-----
The output is a tuple of two integers (Int × Int) where:
• The first element is equal to Y.
• The second element is equal to X.
-----Note-----
There are no restrictions on the input values. The function must correctly swap the inputs regardless of whether they are positive, negative, or zero. | -- !benchmark @start import type=solution
-- !benchmark @end import
-- !benchmark @start solution_aux
-- !benchmark @end solution_aux
-- !benchmark @start precond_aux
-- !benchmark @end precond_aux
@[reducible, simp]
def SwapArithmetic_precond (X : Int) (Y : Int) : Prop :=
-- !benchmark @start precond
True
-- !benchmark @end precond
-- !benchmark @start code_aux
-- !benchmark @end code_aux
def SwapArithmetic (X : Int) (Y : Int) (h_precond : SwapArithmetic_precond (X) (Y)) : (Int × Int) :=
-- !benchmark @start code
let x1 := X
let y1 := Y
let x2 := y1 - x1
let y2 := y1 - x2
let x3 := y2 + x2
(x3, y2)
-- !benchmark @end code
-- !benchmark @start postcond_aux
-- !benchmark @end postcond_aux
@[reducible, simp]
def SwapArithmetic_postcond (X : Int) (Y : Int) (result: (Int × Int)) (h_precond : SwapArithmetic_precond (X) (Y)) :=
-- !benchmark @start postcond
result.1 = Y ∧ result.2 = X ∧
(X ≠ Y → result.fst ≠ X ∧ result.snd ≠ Y)
-- !benchmark @end postcond
-- !benchmark @start proof_aux
-- !benchmark @end proof_aux
theorem SwapArithmetic_spec_satisfied (X: Int) (Y: Int) (h_precond : SwapArithmetic_precond (X) (Y)) :
SwapArithmetic_postcond (X) (Y) (SwapArithmetic (X) (Y) h_precond) h_precond := by
-- !benchmark @start proof
unfold SwapArithmetic_postcond SwapArithmetic
simp
rw [Int.sub_sub_self]
simp_all
exact fun a a_1 => a (id (Eq.symm a_1))
-- !benchmark @end proof
| {
"name": "SwapArithmetic",
"parameters": {
"param_name": [
"X",
"Y"
],
"param_type": [
"Int",
"Int"
]
},
"return_type": "(Int × Int)"
} | {
"upstream": {
"name": "clover",
"link": "https://github.com/ChuyueSun/Clover",
"task_id": "Clover_swap_arith",
"student_id": null
}
} | {
"input": [
"{\"X\": 3, \"Y\": 4}",
"{\"X\": -1, \"Y\": 10}",
"{\"X\": 0, \"Y\": 0}",
"{\"X\": 100, \"Y\": 50}",
"{\"X\": -5, \"Y\": -10}"
],
"expected": [
[
"(4, 3)"
],
[
"(10, -1)"
],
[
"(0, 0)"
],
[
"(50, 100)"
],
[
"(-10, -5)"
]
],
"unexpected": [
[
"(3, 4)",
"(3, 3)",
"(4, 4)"
],
[
"(-1, 10)",
"(10, 1)",
"(-10, -1)"
],
[
"(0, 1)",
"(1, 0)",
"(-1, 0)"
],
[
"(100, 50)",
"(50, 50)",
"(100, 100)"
],
[
"(-5, -10)",
"(-10, -10)",
"(-5, -5)"
]
]
} | {
"input": []
} | basic |
verina_basic_45 | -----Description-----
This task requires writing a Lean 4 method that computes the product of the first even and the first odd number encountered in a list of integers. The method should search the list for the earliest even number and the earliest odd number, then return the product of these two numbers.
-----Input-----
The input consists of:
lst: A list of integers.
-----Output-----
The output is an integer:
Returns the product resulting from multiplying the first even number and the first odd number found in the list.
-----Note-----
The input list is assumed to contain at least one even number and one odd number. | -- !benchmark @start import type=solution
-- !benchmark @end import
-- !benchmark @start solution_aux
def isEven (n : Int) : Bool :=
n % 2 = 0
def isOdd (n : Int) : Bool :=
n % 2 ≠ 0
def firstEvenOddIndices (lst : List Int) : Option (Nat × Nat) :=
let evenIndex := lst.findIdx? isEven
let oddIndex := lst.findIdx? isOdd
match evenIndex, oddIndex with
| some ei, some oi => some (ei, oi)
| _, _ => none
-- !benchmark @end solution_aux
-- !benchmark @start precond_aux
-- !benchmark @end precond_aux
@[reducible, simp]
def findProduct_precond (lst : List Int) : Prop :=
-- !benchmark @start precond
lst.length > 1 ∧
(∃ x ∈ lst, isEven x) ∧
(∃ x ∈ lst, isOdd x)
-- !benchmark @end precond
-- !benchmark @start code_aux
-- !benchmark @end code_aux
def findProduct (lst : List Int) (h_precond : findProduct_precond (lst)) : Int :=
-- !benchmark @start code
match firstEvenOddIndices lst with
| some (ei, oi) => lst[ei]! * lst[oi]!
| none => 0
-- !benchmark @end code
-- !benchmark @start postcond_aux
-- !benchmark @end postcond_aux
@[reducible, simp]
def findProduct_postcond (lst : List Int) (result: Int) (h_precond : findProduct_precond (lst)) :=
-- !benchmark @start postcond
match firstEvenOddIndices lst with
| some (ei, oi) => result = lst[ei]! * lst[oi]!
| none => True
-- !benchmark @end postcond
-- !benchmark @start proof_aux
-- !benchmark @end proof_aux
theorem findProduct_spec_satisfied (lst: List Int) (h_precond : findProduct_precond (lst)) :
findProduct_postcond (lst) (findProduct (lst) h_precond) h_precond := by
-- !benchmark @start proof
unfold findProduct findProduct_postcond
split
case h_1 _ ei oi _ =>
split
case h_1 _ ei' oi' heq =>
have : ei = ei' ∧ oi = oi' := by
rw [Option.some_inj] at heq
cases heq with
| refl => exact ⟨rfl, rfl⟩
simp [this]
case h_2 _ heq => contradiction
case h_2 => simp
-- !benchmark @end proof
| {
"name": "findProduct",
"parameters": {
"param_name": [
"lst"
],
"param_type": [
"List Int"
]
},
"return_type": "Int"
} | {
"upstream": {
"name": "dafny-synthesis",
"link": "https://github.com/Mondego/dafny-synthesis",
"task_id": "task_id_784",
"student_id": null
}
} | {
"input": [
"{\"lst\": \"[2, 3, 4, 5]\"}",
"{\"lst\": \"[2, 4, 3, 6]\"}",
"{\"lst\": \"[1, 2, 5, 4]\"}"
],
"expected": [
[
"6"
],
[
"6"
],
[
"2"
]
],
"unexpected": [
[
"8",
"0",
"10"
],
[
"8",
"0",
"24"
],
[
"5",
"0",
"10"
]
]
} | {
"input": [
"{'lst': '[2]'}"
]
} | basic |
verina_advanced_51 | -----Description-----
This task requires writing a Lean 4 method that takes two sorted (non-decreasing) integer lists and merges them into a single sorted list. The output must preserve order and include all elements from both input lists.
-----Input-----
The input consists of:
a: A list of integers sorted in non-decreasing order.
b: Another list of integers sorted in non-decreasing order.
-----Output-----
The output is a list of integers:
Returns a merged list that contains all elements from both input lists, sorted in non-decreasing order.
| -- !benchmark @start import type=solution
-- !benchmark @end import
-- !benchmark @start solution_aux
-- !benchmark @end solution_aux
-- !benchmark @start precond_aux
-- !benchmark @end precond_aux
@[reducible, simp]
def mergeSorted_precond (a : List Int) (b : List Int) : Prop :=
-- !benchmark @start precond
List.Pairwise (· ≤ ·) a ∧ List.Pairwise (· ≤ ·) b
-- !benchmark @end precond
-- !benchmark @start code_aux
def mergeSortedAux : List Int → List Int → List Int
| [], ys => ys
| xs, [] => xs
| x :: xs', y :: ys' =>
if x ≤ y then
let merged := mergeSortedAux xs' (y :: ys')
x :: merged
else
let merged := mergeSortedAux (x :: xs') ys'
y :: merged
-- !benchmark @end code_aux
def mergeSorted (a : List Int) (b : List Int) (h_precond : mergeSorted_precond (a) (b)) : List Int :=
-- !benchmark @start code
let merged := mergeSortedAux a b
merged
-- !benchmark @end code
-- !benchmark @start postcond_aux
-- !benchmark @end postcond_aux
@[reducible, simp]
def mergeSorted_postcond (a : List Int) (b : List Int) (result: List Int) (h_precond : mergeSorted_precond (a) (b)) : Prop :=
-- !benchmark @start postcond
List.Pairwise (· ≤ ·) result ∧
List.isPerm result (a ++ b)
-- !benchmark @end postcond
-- !benchmark @start proof_aux
-- !benchmark @end proof_aux
theorem mergeSorted_spec_satisfied (a: List Int) (b: List Int) (h_precond : mergeSorted_precond (a) (b)) :
mergeSorted_postcond (a) (b) (mergeSorted (a) (b) h_precond) h_precond := by
-- !benchmark @start proof
sorry
-- !benchmark @end proof
| {
"name": "mergeSorted",
"parameters": {
"param_name": [
"a",
"b"
],
"param_type": [
"List Int",
"List Int"
]
},
"return_type": "List Int"
} | {
"upstream": {
"name": "lab_assignment",
"link": "",
"task_id": "lab_mergeSorted_325769371",
"student_id": [
15
]
}
} | {
"input": [
"{\"a\": \"[1, 3, 5]\", \"b\": \"[2, 4, 6]\"}",
"{\"a\": \"[1, 2]\", \"b\": \"[1, 2, 3]\"}",
"{\"a\": \"[]\", \"b\": \"[4, 5]\"}",
"{\"a\": \"[0, 3, 4]\", \"b\": \"[]\"}",
"{\"a\": \"[1, 4, 6]\", \"b\": \"[2, 3, 5]\"}"
],
"expected": [
[
"[1, 2, 3, 4, 5, 6]"
],
[
"[1, 1, 2, 2, 3]"
],
[
"[4, 5]"
],
[
"[0, 3, 4]"
],
[
"[1, 2, 3, 4, 5, 6]"
]
],
"unexpected": [
[
"[1, 3, 5]",
"[2, 4, 6]",
"[6, 5, 4]"
],
[
"[1, 2, 3]"
],
[
"[]"
],
[
"[4, 3, 0]"
],
[
"[1, 4, 6, 2, 3, 5]"
]
]
} | {
"input": [
"{'a': '[1, 2, 3]', 'b': '[6, 5, 4]'}",
"{'a': '[3, 2, 1]', 'b': '[6, 5, 4]'}"
]
} | advanced |
verina_advanced_40 | -----Description-----
This task requires writing a Lean 4 function that returns the maximum element from a non-empty list of natural numbers.
-----Input-----
The input consists of:
lst: a non-empty list of natural numbers.
-----Output-----
The output is:
A natural number representing the largest element in the list.
| -- !benchmark @start import type=solution
-- !benchmark @end import
-- !benchmark @start solution_aux
-- !benchmark @end solution_aux
-- !benchmark @start precond_aux
-- !benchmark @end precond_aux
@[reducible]
def maxOfList_precond (lst : List Nat) : Prop :=
-- !benchmark @start precond
lst ≠ [] -- Ensure the list is non-empty
-- !benchmark @end precond
-- !benchmark @start code_aux
-- !benchmark @end code_aux
def maxOfList (lst : List Nat) (h_precond : maxOfList_precond (lst)) : Nat :=
-- !benchmark @start code
let rec helper (lst : List Nat) : Nat :=
match lst with
| [] => 0 -- technically shouldn't happen if input is always non-empty
| [x] => x
| x :: xs =>
let maxTail := helper xs
if x > maxTail then x else maxTail
helper lst
-- !benchmark @end code
-- !benchmark @start postcond_aux
-- !benchmark @end postcond_aux
@[reducible]
def maxOfList_postcond (lst : List Nat) (result: Nat) (h_precond : maxOfList_precond (lst)) : Prop :=
-- !benchmark @start postcond
result ∈ lst ∧ ∀ x ∈ lst, x ≤ result
-- !benchmark @end postcond
-- !benchmark @start proof_aux
-- !benchmark @end proof_aux
theorem maxOfList_spec_satisfied (lst: List Nat) (h_precond : maxOfList_precond (lst)) :
maxOfList_postcond (lst) (maxOfList (lst) h_precond) h_precond := by
-- !benchmark @start proof
sorry
-- !benchmark @end proof
| {
"name": "maxOfList",
"parameters": {
"param_name": [
"lst"
],
"param_type": [
"List Nat"
]
},
"return_type": "Nat"
} | {
"upstream": {
"name": "lab_assignment",
"link": "Original",
"task_id": "lab_maxOfList_325098964",
"student_id": [
32
]
}
} | {
"input": [
"{\"lst\": \"[1, 2, 3]\"}",
"{\"lst\": \"[5, 5, 5]\"}",
"{\"lst\": \"[10, 1, 9]\"}",
"{\"lst\": \"[7]\"}",
"{\"lst\": \"[0, 0, 0, 0]\"}"
],
"expected": [
[
"3"
],
[
"5"
],
[
"10"
],
[
"7"
],
[
"0"
]
],
"unexpected": [
[
"2",
"1",
"0"
],
[
"4",
"0"
],
[
"1",
"9"
],
[
"0",
"6"
],
[
"1"
]
]
} | {
"input": [
"{'lst': '[]'}"
]
} | advanced |
verina_basic_5 | -----Description-----
This task requires writing a Lean 4 method that multiplies two integers. The method should return the product of the two input numbers.
-----Input-----
The input consists of:
a: The first integer.
b: The second integer.
-----Output-----
The output is an integer:
Returns the product of the two input integers (a * b). | -- !benchmark @start import type=solution
-- !benchmark @end import
-- !benchmark @start solution_aux
-- !benchmark @end solution_aux
-- !benchmark @start precond_aux
-- !benchmark @end precond_aux
@[reducible, simp]
def multiply_precond (a : Int) (b : Int) : Prop :=
-- !benchmark @start precond
True
-- !benchmark @end precond
-- !benchmark @start code_aux
-- !benchmark @end code_aux
def multiply (a : Int) (b : Int) (h_precond : multiply_precond (a) (b)) : Int :=
-- !benchmark @start code
a * b
-- !benchmark @end code
-- !benchmark @start postcond_aux
-- !benchmark @end postcond_aux
@[reducible, simp]
def multiply_postcond (a : Int) (b : Int) (result: Int) (h_precond : multiply_precond (a) (b)) :=
-- !benchmark @start postcond
result - a * b = 0 ∧ a * b - result = 0
-- !benchmark @end postcond
-- !benchmark @start proof_aux
-- !benchmark @end proof_aux
theorem multiply_spec_satisfied (a: Int) (b: Int) (h_precond : multiply_precond (a) (b)) :
multiply_postcond (a) (b) (multiply (a) (b) h_precond) h_precond := by
-- !benchmark @start proof
unfold multiply multiply_postcond
simp
-- !benchmark @end proof
| {
"name": "multiply",
"parameters": {
"param_name": [
"a",
"b"
],
"param_type": [
"Int",
"Int"
]
},
"return_type": "Int"
} | {
"upstream": {
"name": "dafny-synthesis",
"link": "https://github.com/Mondego/dafny-synthesis",
"task_id": "task_id_127",
"student_id": null
}
} | {
"input": [
"{\"a\": 3, \"b\": 4}",
"{\"a\": 3, \"b\": -4}",
"{\"a\": -3, \"b\": 4}",
"{\"a\": -3, \"b\": -4}",
"{\"a\": 0, \"b\": 5}",
"{\"a\": 5, \"b\": 0}",
"{\"a\": 0, \"b\": 0}"
],
"expected": [
[
"12"
],
[
"-12"
],
[
"-12"
],
[
"12"
],
[
"0"
],
[
"0"
],
[
"0"
]
],
"unexpected": [
[
"0",
"11",
"15"
],
[
"0",
"-11",
"12"
],
[
"0",
"-11",
"12"
],
[
"0",
"11",
"-12"
],
[
"1",
"-1",
"5"
],
[
"1",
"-1",
"5"
],
[
"1",
"-1",
"5"
]
]
} | {
"input": []
} | basic |
verina_basic_85 | -----Description-----
This problem focuses on reversing an array of integers. The goal is to take an input array and produce a new array with the elements arranged in the reverse order.
-----Input-----
The input consists of:
• a: An array of integers, which may be empty, contain one element, or many elements.
-----Output-----
The output is an array of integers that:
• Has the same length as the input array.
• Contains the same elements as the input array, but in reverse order.
• For every valid index i in the input array, the output at index i is equal to the element at index (a.size - 1 - i) from the input array.
-----Note-----
There are no specific preconditions; the method should correctly handle any array of integers. | -- !benchmark @start import type=solution
-- !benchmark @end import
-- !benchmark @start solution_aux
-- !benchmark @end solution_aux
-- !benchmark @start precond_aux
-- !benchmark @end precond_aux
@[reducible, simp]
def reverse_precond (a : Array Int) : Prop :=
-- !benchmark @start precond
True
-- !benchmark @end precond
-- !benchmark @start code_aux
def reverse_core (arr : Array Int) (i : Nat) : Array Int :=
if i < arr.size / 2 then
let j := arr.size - 1 - i
let temp := arr[i]!
let arr' := arr.set! i (arr[j]!)
let arr'' := arr'.set! j temp
reverse_core arr'' (i + 1)
else
arr
-- !benchmark @end code_aux
def reverse (a : Array Int) (h_precond : reverse_precond (a)) : Array Int :=
-- !benchmark @start code
reverse_core a 0
-- !benchmark @end code
-- !benchmark @start postcond_aux
-- !benchmark @end postcond_aux
@[reducible, simp]
def reverse_postcond (a : Array Int) (result: Array Int) (h_precond : reverse_precond (a)) :=
-- !benchmark @start postcond
(result.size = a.size) ∧ (∀ i : Nat, i < a.size → result[i]! = a[a.size - 1 - i]!)
-- !benchmark @end postcond
-- !benchmark @start proof_aux
-- !benchmark @end proof_aux
theorem reverse_spec_satisfied (a: Array Int) (h_precond : reverse_precond (a)) :
reverse_postcond (a) (reverse (a) h_precond) h_precond := by
-- !benchmark @start proof
sorry
-- !benchmark @end proof
| {
"name": "reverse",
"parameters": {
"param_name": [
"a"
],
"param_type": [
"Array Int"
]
},
"return_type": "Array Int"
} | {
"upstream": {
"name": "clover",
"link": "https://github.com/ChuyueSun/Clover",
"task_id": "Clover_reverse",
"student_id": null
}
} | {
"input": [
"{\"a\": \"#[1, 2, 3, 4, 5]\"}",
"{\"a\": \"#[10, 20, 30, 40]\"}",
"{\"a\": \"#[]\"}",
"{\"a\": \"#[7]\"}",
"{\"a\": \"#[-1, 0, 1]\"}"
],
"expected": [
[
"#[5, 4, 3, 2, 1]"
],
[
"#[40, 30, 20, 10]"
],
[
"#[]"
],
[
"#[7]"
],
[
"#[1, 0, -1]"
]
],
"unexpected": [
[
"#[1, 2, 3, 4, 5]",
"#[5, 3, 4, 2, 1]",
"#[2, 3, 4, 5, 6]"
],
[
"#[10, 20, 30, 40]",
"#[40, 20, 30, 10]",
"#[30, 20, 10, 40]"
],
[
"#[0]",
"#[-1]",
"#[1]"
],
[
"#[0]",
"#[7, 7]",
"#[1]"
],
[
"#[-1, 0, 1]",
"#[0, 1, -1]",
"#[1, -1, 0]"
]
]
} | {
"input": []
} | basic |
verina_basic_17 | -----Description-----
This task requires writing a Lean 4 method that converts all uppercase characters in a given string to their lowercase equivalents while keeping the other characters unchanged. The output string must have the same length as the input string.
-----Input-----
The input consists of:
s: A string that may contain both uppercase and lowercase characters.
-----Output-----
The output is a string:
Returns a new string where every uppercase letter has been converted to lowercase, and every non-uppercase character remains exactly as in the input.
-----Note-----
There are no preconditions; the method is expected to work for any non-null string. | -- !benchmark @start import type=solution
-- !benchmark @end import
-- !benchmark @start solution_aux
def isUpperCase (c : Char) : Bool :=
'A' ≤ c ∧ c ≤ 'Z'
def shift32 (c : Char) : Char :=
Char.ofNat (c.toNat + 32)
-- !benchmark @end solution_aux
-- !benchmark @start precond_aux
-- !benchmark @end precond_aux
@[reducible, simp]
def toLowercase_precond (s : String) : Prop :=
-- !benchmark @start precond
True
-- !benchmark @end precond
-- !benchmark @start code_aux
-- !benchmark @end code_aux
def toLowercase (s : String) (h_precond : toLowercase_precond (s)) : String :=
-- !benchmark @start code
let cs := s.toList
let cs' := cs.map (fun c => if isUpperCase c then shift32 c else c)
String.mk cs'
-- !benchmark @end code
-- !benchmark @start postcond_aux
-- !benchmark @end postcond_aux
@[reducible, simp]
def toLowercase_postcond (s : String) (result: String) (h_precond : toLowercase_precond (s)) :=
-- !benchmark @start postcond
let cs := s.toList
let cs' := result.toList
(result.length = s.length) ∧
(∀ i : Nat, i < s.length →
(isUpperCase cs[i]! → cs'[i]! = shift32 cs[i]!) ∧
(¬isUpperCase cs[i]! → cs'[i]! = cs[i]!))
-- !benchmark @end postcond
-- !benchmark @start proof_aux
-- !benchmark @end proof_aux
theorem toLowercase_spec_satisfied (s: String) (h_precond : toLowercase_precond (s)) :
toLowercase_postcond (s) (toLowercase (s) h_precond) h_precond := by
-- !benchmark @start proof
unfold toLowercase toLowercase_postcond
simp_all
constructor
· unfold String.length
simp
· intro i hi
have hi' : i < s.data.length := by
unfold String.length at hi
simp at hi
exact hi
constructor <;> simp_all
-- !benchmark @end proof
| {
"name": "toLowercase",
"parameters": {
"param_name": [
"s"
],
"param_type": [
"String"
]
},
"return_type": "String"
} | {
"upstream": {
"name": "dafny-synthesis",
"link": "https://github.com/Mondego/dafny-synthesis",
"task_id": "task_id_477",
"student_id": null
}
} | {
"input": [
"{\"s\": \"Hello, World!\"}",
"{\"s\": \"ABC\"}",
"{\"s\": \"abc\"}",
"{\"s\": \"\"}",
"{\"s\": \"1234!@\"}",
"{\"s\": \"MixedCASE123\"}"
],
"expected": [
[
"hello, world!"
],
[
"abc"
],
[
"abc"
],
[
""
],
[
"1234!@"
],
[
"mixedcase123"
]
],
"unexpected": [
[
"Hello, world!",
"HELLO, WORLD!",
"hello, World!"
],
[
"ABC",
"Abc",
"aBC"
],
[
"ABC",
"aBc",
"abC"
],
[
" ",
"empty",
"null"
],
[
"1234!#",
"12345!@"
],
[
"Mixedcase123",
"mixedCASE123",
"MIXEDCASE123"
]
]
} | {
"input": []
} | basic |
verina_advanced_36 | -----Description-----
This task requires writing a Lean 4 method that finds the majority element in a list of natural numbers. The majority element is defined as the element that appears more than ⌊n / 2⌋ times in the list, where n is the total number of elements.
You may assume that the input list always contains a majority element.
-----Input-----
The input consists of one list:
xs: A list of natural numbers (List Nat), where a majority element is guaranteed to exist.
-----Output-----
The output is a natural number:
Returns the element that appears more than half the time in the input list.
| -- !benchmark @start import type=solution
-- !benchmark @end import
-- !benchmark @start solution_aux
-- !benchmark @end solution_aux
-- !benchmark @start precond_aux
-- !benchmark @end precond_aux
@[reducible]
def majorityElement_precond (xs : List Nat) : Prop :=
-- !benchmark @start precond
xs.length > 0 ∧ xs.any (fun x => xs.count x > xs.length / 2)
-- !benchmark @end precond
-- !benchmark @start code_aux
-- !benchmark @end code_aux
def majorityElement (xs : List Nat) (h_precond : majorityElement_precond (xs)) : Nat :=
-- !benchmark @start code
let rec countOccurrences (target : Nat) (lst : List Nat) : Nat :=
match lst with
| [] => 0
| y :: ys =>
if y = target then 1 + countOccurrences target ys
else countOccurrences target ys
let rec findCandidate (lst : List Nat) (candidate : Option Nat) (count : Nat) : Nat :=
match lst with
| [] =>
match candidate with
| some c => c
| none => 0 -- unreachable since we assume majority element exists
| x :: xs =>
match candidate with
| some c =>
if x = c then
findCandidate xs (some c) (count + 1)
else if count = 0 then
findCandidate xs (some x) 1
else
findCandidate xs (some c) (count - 1)
| none =>
findCandidate xs (some x) 1
let cand := findCandidate xs none 0
cand
-- !benchmark @end code
-- !benchmark @start postcond_aux
-- !benchmark @end postcond_aux
@[reducible]
def majorityElement_postcond (xs : List Nat) (result: Nat) (h_precond : majorityElement_precond (xs)) : Prop :=
-- !benchmark @start postcond
let count := xs.count result
count > xs.length / 2
-- !benchmark @end postcond
-- !benchmark @start proof_aux
-- !benchmark @end proof_aux
theorem majorityElement_spec_satisfied (xs: List Nat) (h_precond : majorityElement_precond (xs)) :
majorityElement_postcond (xs) (majorityElement (xs) h_precond) h_precond := by
-- !benchmark @start proof
sorry
-- !benchmark @end proof
| {
"name": "majorityElement",
"parameters": {
"param_name": [
"xs"
],
"param_type": [
"List Nat"
]
},
"return_type": "Nat"
} | {
"upstream": {
"name": "lab_assignment",
"link": "https://leetcode.com/problems/majority-element/description/",
"task_id": "lab_majorityElement_325005413",
"student_id": [
29
]
}
} | {
"input": [
"{\"xs\": \"[3, 3, 4, 2, 3, 3, 3]\"}",
"{\"xs\": \"[1, 1, 2, 1, 3, 1, 1]\"}",
"{\"xs\": \"[2, 2, 2, 1, 1]\"}",
"{\"xs\": \"[9, 9, 9, 9, 1, 2, 3]\"}",
"{\"xs\": \"[5, 5, 5, 5, 5, 6, 7]\"}"
],
"expected": [
[
"3"
],
[
"1"
],
[
"2"
],
[
"9"
],
[
"5"
]
],
"unexpected": [
[
"2",
"4"
],
[
"2",
"3"
],
[
"1"
],
[
"1",
"2",
"3"
],
[
"6",
"7"
]
]
} | {
"input": [
"{'xs': '[1, 2, 3]'}",
"{'xs': '[]'}"
]
} | advanced |
verina_basic_73 | -----Description-----
Determine whether two strings match based on a specific pattern: for each position in the strings, either the characters are the same, or the character in p is a wildcard represented by a question mark '?' that may match any character.
-----Input-----
The input consists of:
• s: A string that is to be matched.
• p: A pattern string of equal length, where each character is either a specific character or the wildcard '?'.
-----Output-----
The output is a Boolean value:
• Returns true if the length of s is equal to the length of p and each corresponding character in s and p are either identical or the character in p is a '?'.
• Returns false if any character in s does not match the corresponding character in p and the character in p is not a '?'.
-----Note-----
It is assumed that both strings provided have the same length. | -- !benchmark @start import type=solution
-- !benchmark @end import
-- !benchmark @start solution_aux
-- !benchmark @end solution_aux
-- !benchmark @start precond_aux
-- !benchmark @end precond_aux
@[reducible, simp]
def Match_precond (s : String) (p : String) : Prop :=
-- !benchmark @start precond
s.toList.length = p.toList.length
-- !benchmark @end precond
-- !benchmark @start code_aux
-- !benchmark @end code_aux
def Match (s : String) (p : String) (h_precond : Match_precond (s) (p)) : Bool :=
-- !benchmark @start code
let sList := s.toList
let pList := p.toList
let rec loop (i : Nat) : Bool :=
if i < sList.length then
if (sList[i]! ≠ pList[i]!) ∧ (pList[i]! ≠ '?') then false
else loop (i + 1)
else true
loop 0
-- !benchmark @end code
-- !benchmark @start postcond_aux
-- !benchmark @end postcond_aux
@[reducible, simp]
def Match_postcond (s : String) (p : String) (result: Bool) (h_precond : Match_precond (s) (p)) :=
-- !benchmark @start postcond
(result = true ↔ ∀ n : Nat, n < s.toList.length → ((s.toList[n]! = p.toList[n]!) ∨ (p.toList[n]! = '?')))
-- !benchmark @end postcond
-- !benchmark @start proof_aux
-- !benchmark @end proof_aux
theorem Match_spec_satisfied (s: String) (p: String) (h_precond : Match_precond (s) (p)) :
Match_postcond (s) (p) (Match (s) (p) h_precond) h_precond := by
-- !benchmark @start proof
sorry
-- !benchmark @end proof
| {
"name": "Match",
"parameters": {
"param_name": [
"s",
"p"
],
"param_type": [
"String",
"String"
]
},
"return_type": "Bool"
} | {
"upstream": {
"name": "clover",
"link": "https://github.com/ChuyueSun/Clover",
"task_id": "Clover_match",
"student_id": null
}
} | {
"input": [
"{\"s\": \"abc\", \"p\": \"a?c\"}",
"{\"s\": \"hello\", \"p\": \"he?lo\"}",
"{\"s\": \"world\", \"p\": \"w?rld\"}",
"{\"s\": \"test\", \"p\": \"te?t\"}",
"{\"s\": \"abc\", \"p\": \"abd\"}"
],
"expected": [
[
"True"
],
[
"True"
],
[
"True"
],
[
"True"
],
[
"False"
]
],
"unexpected": [
[
"False"
],
[
"False"
],
[
"False"
],
[
"False"
],
[
"True"
]
]
} | {
"input": [
"{'s': 'abc', 'p': 'ac'}"
]
} | basic |
verina_basic_61 | -----Description-----
This task involves determining whether every character in a provided string is a digit. The objective is to check if all characters fall within the standard digit range, returning true if they do and false otherwise.
-----Input-----
The input consists of:
• s: A string whose characters will be analyzed to determine if they are all digits.
-----Output-----
The output is a boolean value:
• true if every character in the string is a digit;
• false if at least one character is not a digit (note that the empty string returns true).
-----Note-----
It is assumed that the input is a well-formed string. The function uses an iterator to examine every character. | -- !benchmark @start import type=solution
-- !benchmark @end import
-- !benchmark @start solution_aux
def isDigit (c : Char) : Bool :=
(c ≥ '0') && (c ≤ '9')
-- !benchmark @end solution_aux
-- !benchmark @start precond_aux
-- !benchmark @end precond_aux
@[reducible, simp]
def allDigits_precond (s : String) : Prop :=
-- !benchmark @start precond
True
-- !benchmark @end precond
-- !benchmark @start code_aux
-- !benchmark @end code_aux
def allDigits (s : String) (h_precond : allDigits_precond (s)) : Bool :=
-- !benchmark @start code
let rec loop (it : String.Iterator) : Bool :=
if it.atEnd then
true
else
if !isDigit it.curr then
false
else
loop it.next
loop s.iter
-- !benchmark @end code
-- !benchmark @start postcond_aux
-- !benchmark @end postcond_aux
@[reducible, simp]
def allDigits_postcond (s : String) (result: Bool) (h_precond : allDigits_precond (s)) :=
-- !benchmark @start postcond
(result = true ↔ ∀ c ∈ s.toList, isDigit c)
-- !benchmark @end postcond
-- !benchmark @start proof_aux
-- !benchmark @end proof_aux
theorem allDigits_spec_satisfied (s: String) (h_precond : allDigits_precond (s)) :
allDigits_postcond (s) (allDigits (s) h_precond) h_precond := by
-- !benchmark @start proof
sorry
-- !benchmark @end proof
| {
"name": "allDigits",
"parameters": {
"param_name": [
"s"
],
"param_type": [
"String"
]
},
"return_type": "Bool"
} | {
"upstream": {
"name": "clover",
"link": "https://github.com/ChuyueSun/Clover",
"task_id": "Clover_all_digits",
"student_id": null
}
} | {
"input": [
"{\"s\": \"123456\"}",
"{\"s\": \"123a56\"}",
"{\"s\": \"\"}",
"{\"s\": \"007\"}",
"{\"s\": \"98 76\"}"
],
"expected": [
[
"True"
],
[
"False"
],
[
"True"
],
[
"True"
],
[
"False"
]
],
"unexpected": [
[
"False"
],
[
"True"
],
[
"False"
],
[
"False"
],
[
"True"
]
]
} | {
"input": []
} | basic |
verina_basic_20 | -----Description-----
This task requires writing a Lean 4 method that calculates the product of all distinct integers in an array. The method should consider each unique integer only once when computing the product and return the resulting value. If the array is empty, the method should return 1.
-----Input-----
The input consists of:
arr: An array of integers.
-----Output-----
The output is an integer:
Returns the product of all unique integers from the input array.
-----Note-----
The order in which the unique integers are multiplied does not affect the final product. | -- !benchmark @start import type=solution
import Std.Data.HashSet
-- !benchmark @end import
-- !benchmark @start solution_aux
-- !benchmark @end solution_aux
-- !benchmark @start precond_aux
-- !benchmark @end precond_aux
@[reducible, simp]
def uniqueProduct_precond (arr : Array Int) : Prop :=
-- !benchmark @start precond
True
-- !benchmark @end precond
-- !benchmark @start code_aux
-- !benchmark @end code_aux
def uniqueProduct (arr : Array Int) (h_precond : uniqueProduct_precond (arr)) : Int :=
-- !benchmark @start code
let rec loop (i : Nat) (seen : Std.HashSet Int) (product : Int) : Int :=
if i < arr.size then
let x := arr[i]!
if seen.contains x then
loop (i + 1) seen product
else
loop (i + 1) (seen.insert x) (product * x)
else
product
loop 0 Std.HashSet.empty 1
-- !benchmark @end code
-- !benchmark @start postcond_aux
-- !benchmark @end postcond_aux
@[reducible, simp]
def uniqueProduct_postcond (arr : Array Int) (result: Int) (h_precond : uniqueProduct_precond (arr)) :=
-- !benchmark @start postcond
result - (arr.toList.eraseDups.foldl (· * ·) 1) = 0 ∧
(arr.toList.eraseDups.foldl (· * ·) 1) - result = 0
-- !benchmark @end postcond
-- !benchmark @start proof_aux
-- !benchmark @end proof_aux
theorem uniqueProduct_spec_satisfied (arr: Array Int) (h_precond : uniqueProduct_precond (arr)) :
uniqueProduct_postcond (arr) (uniqueProduct (arr) h_precond) h_precond := by
-- !benchmark @start proof
sorry
-- !benchmark @end proof
| {
"name": "uniqueProduct",
"parameters": {
"param_name": [
"arr"
],
"param_type": [
"Array Int"
]
},
"return_type": "Int"
} | {
"upstream": {
"name": "dafny-synthesis",
"link": "https://github.com/Mondego/dafny-synthesis",
"task_id": "task_id_573",
"student_id": null
}
} | {
"input": [
"{\"arr\": \"#[2, 3, 2, 4]\"}",
"{\"arr\": \"#[5, 5, 5, 5]\"}",
"{\"arr\": \"#[]\"}",
"{\"arr\": \"#[1, 2, 3]\"}",
"{\"arr\": \"#[0, 2, 3]\"}",
"{\"arr\": \"#[-1, -2, -1, -3]\"}",
"{\"arr\": \"#[10, 10, 20, 20, 30]\"}"
],
"expected": [
[
"24"
],
[
"5"
],
[
"1"
],
[
"6"
],
[
"0"
],
[
"-6"
],
[
"6000"
]
],
"unexpected": [
[
"12",
"30",
"0"
],
[
"25",
"0",
"10"
],
[
"0",
"-1",
"2"
],
[
"5",
"7",
"2"
],
[
"1",
"-1",
"10"
],
[
"-1",
"6",
"-3"
],
[
"600",
"0",
"5000"
]
]
} | {
"input": []
} | basic |
verina_basic_4 | -----Description-----
This task requires writing a Lean 4 method that finds the kth element in a given array using 1-based indexing. The method should return the element at the specified position, where the first element is at position 1.
-----Input-----
The input consists of:
arr: An array of integers.
k: An integer representing the position (1-based index) of the element to find.
-----Output-----
The output is an integer:
Returns the element at the kth position in the array.
-----Note-----
The input k is assumed to be valid (between 1 and array length inclusive).
The array is assumed to be non-empty. | -- !benchmark @start import type=solution
-- !benchmark @end import
-- !benchmark @start solution_aux
-- !benchmark @end solution_aux
-- !benchmark @start precond_aux
-- !benchmark @end precond_aux
@[reducible, simp]
def kthElement_precond (arr : Array Int) (k : Nat) : Prop :=
-- !benchmark @start precond
k ≥ 1 ∧ k ≤ arr.size
-- !benchmark @end precond
-- !benchmark @start code_aux
-- !benchmark @end code_aux
def kthElement (arr : Array Int) (k : Nat) (h_precond : kthElement_precond (arr) (k)) : Int :=
-- !benchmark @start code
arr[k - 1]!
-- !benchmark @end code
-- !benchmark @start postcond_aux
-- !benchmark @end postcond_aux
@[reducible, simp]
def kthElement_postcond (arr : Array Int) (k : Nat) (result: Int) (h_precond : kthElement_precond (arr) (k)) :=
-- !benchmark @start postcond
arr.any (fun x => x = result ∧ x = arr[k - 1]!)
-- !benchmark @end postcond
-- !benchmark @start proof_aux
-- !benchmark @end proof_aux
theorem kthElement_spec_satisfied (arr: Array Int) (k: Nat) (h_precond : kthElement_precond (arr) (k)) :
kthElement_postcond (arr) (k) (kthElement (arr) (k) h_precond) h_precond := by
-- !benchmark @start proof
unfold kthElement kthElement_postcond
unfold kthElement_precond at h_precond
have ⟨hp1, hp2⟩ := h_precond
simp_all
have h': k - 1 < arr.size := by
exact Nat.sub_one_lt_of_le hp1 hp2
exists k - 1
exists h'
exact Eq.symm (getElem!_pos arr (k - 1) ((Iff.of_eq (Eq.refl (k - 1 < arr.size))).mpr h'))
-- !benchmark @end proof
| {
"name": "kthElement",
"parameters": {
"param_name": [
"arr",
"k"
],
"param_type": [
"Array Int",
"Nat"
]
},
"return_type": "Int"
} | {
"upstream": {
"name": "dafny-synthesis",
"link": "https://github.com/Mondego/dafny-synthesis",
"task_id": "task_id_101",
"student_id": null
}
} | {
"input": [
"{\"arr\": \"#[10, 20, 30, 40, 50]\", \"k\": 1}",
"{\"arr\": \"#[10, 20, 30, 40, 50]\", \"k\": 3}",
"{\"arr\": \"#[10, 20, 30, 40, 50]\", \"k\": 5}",
"{\"arr\": \"#[5]\", \"k\": 1}",
"{\"arr\": \"#[1, 2, 3]\", \"k\": 3}",
"{\"arr\": \"#[1, 2, 3]\", \"k\": 2}",
"{\"arr\": \"#[9, 9, 9]\", \"k\": 2}",
"{\"arr\": \"#[0, -1, -2]\", \"k\": 1}",
"{\"arr\": \"#[0, -1, -2]\", \"k\": 2}",
"{\"arr\": \"#[0, -1, -2]\", \"k\": 3}"
],
"expected": [
[
"10"
],
[
"30"
],
[
"50"
],
[
"5"
],
[
"3"
],
[
"2"
],
[
"9"
],
[
"0"
],
[
"-1"
],
[
"-2"
]
],
"unexpected": [
[
"20",
"30"
],
[
"10",
"40",
"50"
],
[
"10",
"40"
],
[
"0",
"1"
],
[
"1",
"2"
],
[
"1",
"3",
"0"
],
[
"0",
"7"
],
[
"1",
"-1",
"2"
],
[
"0",
"-2"
],
[
"0",
"-1"
]
]
} | {
"input": [
"{'arr': '#[1, 2, 3]', 'k': 0}"
]
} | basic |
verina_advanced_48 | -----Description-----
This task requires implementing the merge sort algorithm in Lean 4 to sort a list of integers in ascending order. Merge sort is a divide-and-conquer algorithm that recursively splits the input list into two halves, sorts them separately, and then merges the sorted halves to produce the final sorted result.
The merge sort algorithm works as follows:
1. If the list has one element or is empty, it is already sorted.
2. Otherwise, divide the list into two roughly equal parts.
3. Recursively sort both halves.
4. Merge the two sorted halves to produce a single sorted list.
The key operation in merge sort is the merging step, which takes two sorted lists and combines them into a single sorted list by repeatedly taking the smaller of the two elements at the front of the lists.
-----Input-----
The input consists of one parameter:
list: A list of integers that needs to be sorted.
-----Output-----
The output is a list of integers:
Returns a new list containing all elements from the input list, sorted in ascending order.
| -- !benchmark @start import type=solution
-- !benchmark @end import
-- !benchmark @start solution_aux
-- !benchmark @end solution_aux
-- !benchmark @start precond_aux
-- !benchmark @end precond_aux
@[reducible, simp]
def mergeSort_precond (list : List Int) : Prop :=
-- !benchmark @start precond
True
-- !benchmark @end precond
-- !benchmark @start code_aux
-- !benchmark @end code_aux
def mergeSort (list : List Int) (h_precond : mergeSort_precond (list)) : List Int :=
-- !benchmark @start code
-- Implementation using insertion sort instead of merge sort
-- for simplicity and to avoid termination issues
-- Helper to insert an element into a sorted list
let rec insert (x : Int) (sorted : List Int) : List Int :=
match sorted with
| [] => [x]
| y :: ys =>
if x ≤ y then
x :: sorted
else
y :: insert x ys
termination_by sorted.length
-- Main insertion sort function
let rec sort (l : List Int) : List Int :=
match l with
| [] => []
| x :: xs =>
let sortedRest := sort xs
insert x sortedRest
termination_by l.length
sort list
-- !benchmark @end code
-- !benchmark @start postcond_aux
-- !benchmark @end postcond_aux
@[reducible, simp]
def mergeSort_postcond (list : List Int) (result: List Int) (h_precond : mergeSort_precond (list)) : Prop :=
-- !benchmark @start postcond
List.Pairwise (· ≤ ·) result ∧ List.isPerm list result
-- !benchmark @end postcond
-- !benchmark @start proof_aux
-- !benchmark @end proof_aux
theorem mergeSort_spec_satisfied (list: List Int) (h_precond : mergeSort_precond (list)) :
mergeSort_postcond (list) (mergeSort (list) h_precond) h_precond := by
-- !benchmark @start proof
sorry
-- !benchmark @end proof
| {
"name": "mergeSort",
"parameters": {
"param_name": [
"list"
],
"param_type": [
"List Int"
]
},
"return_type": "List Int"
} | {
"upstream": {
"name": "lab_assignment",
"link": "[{\"text_file_id\"=>805010081}]",
"task_id": "lab_mergeSort_325707390",
"student_id": [
38
]
}
} | {
"input": [
"{\"list\": \"[5, 2, 9, 1, 5, 6]\"}",
"{\"list\": \"[3, 1, 4, 1, 5, 9, 2, 6]\"}",
"{\"list\": \"[]\"}",
"{\"list\": \"[1]\"}",
"{\"list\": \"[5, 5, 5, 5]\"}",
"{\"list\": \"[9, 8, 7, 6, 5, 4, 3, 2, 1]\"}",
"{\"list\": \"[1, 2, 3, 4, 5]\"}",
"{\"list\": \"[-3, -1, -5, -2]\"}"
],
"expected": [
[
"[1, 2, 5, 5, 6, 9]"
],
[
"[1, 1, 2, 3, 4, 5, 6, 9]"
],
[
"[]"
],
[
"[1]"
],
[
"[5, 5, 5, 5]"
],
[
"[1, 2, 3, 4, 5, 6, 7, 8, 9]"
],
[
"[1, 2, 3, 4, 5]"
],
[
"[-5, -3, -2, -1]"
]
],
"unexpected": [
[
"[5, 2, 9, 1, 5, 6]",
"[9, 6, 5, 5, 2, 1]"
],
[
"[3, 1, 4, 1, 5, 9, 2, 6]",
"[9, 6, 5, 4, 3, 2, 1, 1]"
],
[
"[1]"
],
[
"[]"
],
[
"[5, 5, 5]",
"[5, 5, 5, 5, 5]"
],
[
"[9, 8, 7, 6, 5, 4, 3, 2, 1]"
],
[
"[5, 4, 3, 2, 1]"
],
[
"[-3, -1, -5, -2]",
"[-1, -2, -3, -5]"
]
]
} | {
"input": []
} | advanced |
verina_basic_90 | -----Description-----
The task is to search for a specific integer in a 2D array where the rows and columns are sorted in non-decreasing order. The goal is to locate the key and return its position as row and column indices, or return (-1, -1) if the algorithm fails to find the key.
-----Input-----
The input consists of:
• a: A non-empty 2D array of integers (Array (Array Int)). The array is guaranteed to contain at least one element.
• key: An integer value (Int) to search for in the array.
-----Output-----
The output is a pair of integers (Int × Int):
• If the key is found, the first element represents the row index and the second element represents the column index such that get2d a row col = key.
• If the key is not found, the function returns (-1, -1).
-----Note-----
It is assumed that the input 2D array is sorted by rows and columns.
| -- !benchmark @start import type=solution
-- !benchmark @end import
-- !benchmark @start solution_aux
@[reducible, simp]
def get2d (a : Array (Array Int)) (i j : Int) : Int :=
(a[Int.toNat i]!)[Int.toNat j]!
-- !benchmark @end solution_aux
-- !benchmark @start precond_aux
-- !benchmark @end precond_aux
@[reducible, simp]
def SlopeSearch_precond (a : Array (Array Int)) (key : Int) : Prop :=
-- !benchmark @start precond
List.Pairwise (·.size = ·.size) a.toList ∧
a.all (fun x => List.Pairwise (· ≤ ·) x.toList) ∧
(
a.size = 0 ∨ (
(List.range (a[0]!.size)).all (fun i =>
List.Pairwise (· ≤ ·) (a.map (fun x => x[i]!)).toList
)
)
)
-- !benchmark @end precond
-- !benchmark @start code_aux
-- !benchmark @end code_aux
def SlopeSearch (a : Array (Array Int)) (key : Int) (h_precond : SlopeSearch_precond (a) (key)) : (Int × Int) :=
-- !benchmark @start code
let rows := a.size
let cols := if rows > 0 then (a[0]!).size else 0
let rec aux (m n : Int) (fuel : Nat) : (Int × Int) :=
if fuel = 0 then (-1, -1)
else if m ≥ Int.ofNat rows || n < 0 then (-1, -1)
else if get2d a m n = key then (m, n)
else if get2d a m n < key then
aux (m + 1) n (fuel - 1)
else
aux m (n - 1) (fuel - 1)
aux 0 (Int.ofNat (cols - 1)) (rows + cols)
-- !benchmark @end code
-- !benchmark @start postcond_aux
-- !benchmark @end postcond_aux
@[reducible, simp]
def SlopeSearch_postcond (a : Array (Array Int)) (key : Int) (result: (Int × Int)) (h_precond : SlopeSearch_precond (a) (key)) :=
-- !benchmark @start postcond
let (m, n) := result;
(m ≥ 0 ∧ m < a.size ∧ n ≥ 0 ∧ n < (a[0]!).size ∧ get2d a m n = key) ∨
(m = -1 ∧ n = -1 ∧ a.all (fun x => x.all (fun e => e ≠ key)))
-- !benchmark @end postcond
-- !benchmark @start proof_aux
-- !benchmark @end proof_aux
theorem SlopeSearch_spec_satisfied (a: Array (Array Int)) (key: Int) (h_precond : SlopeSearch_precond (a) (key)) :
SlopeSearch_postcond (a) (key) (SlopeSearch (a) (key) h_precond) h_precond := by
-- !benchmark @start proof
sorry
-- !benchmark @end proof
| {
"name": "SlopeSearch",
"parameters": {
"param_name": [
"a",
"key"
],
"param_type": [
"Array (Array Int)",
"Int"
]
},
"return_type": "(Int × Int)"
} | {
"upstream": {
"name": "clover",
"link": "https://github.com/ChuyueSun/Clover",
"task_id": "Clover_slope_search",
"student_id": null
}
} | {
"input": [
"{\"a\": \"#[#[1, 2, 3], #[4, 5, 6], #[7, 8, 9]]\", \"key\": 5}",
"{\"a\": \"#[#[1, 2, 3], #[4, 5, 6], #[7, 8, 9]]\", \"key\": 3}",
"{\"a\": \"#[#[1, 2, 3], #[4, 5, 6], #[7, 8, 9]]\", \"key\": 10}",
"{\"a\": \"#[#[1, 2, 3, 4]]\", \"key\": 4}",
"{\"a\": \"#[#[1], #[2], #[3], #[4]]\", \"key\": 3}"
],
"expected": [
[
"(1, 1)"
],
[
"(0, 2)"
],
[
"(-1, -1)"
],
[
"(0, 3)"
],
[
"(2, 0)"
]
],
"unexpected": [
[
"(1, 2)",
"(0, 1)"
],
[
"(0, 1)",
"(1, 2)"
],
[
"(1, 1)",
"(2, 2)"
],
[
"(0, 2)",
"(1, 3)",
"(0, 4)"
],
[
"(1, 0)",
"(2, 1)"
]
]
} | {
"input": [
"{'a': '#[#[1, 3, 2], #[0, 6, 5], #[7, 8, 9]]', 'key': 2}"
]
} | basic |
verina_basic_104 | -----Description-----
This problem involves combining two maps by creating a new map that includes every key from both inputs. When a key is found in both maps, the value from the second map is used in the result.
-----Input-----
The input consists of:
• m1: A Map (represented as a list of key-value pairs) where each key is of type Int and each value is of type Int.
• m2: A Map (similarly represented) where keys may overlap with m1.
-----Output-----
The output is a Map that meets the following conditions:
• Every key present in m2 is present in the result.
• Every key present in m1 is also present in the result.
• For keys that appear in both maps, the resulting value is the one from m2.
• For keys that appear only in m1, the resulting value remains unchanged.
• No keys outside those present in m1 or m2 are included in the result.
• The entries in the map should be sorted
-----Note-----
It is assumed that the Map structure ensures key uniqueness in the final result using BEq for key comparison. | -- !benchmark @start import type=solution
-- !benchmark @end import
-- !benchmark @start task_aux
structure Map (K V : Type) [BEq K] [BEq V] where
entries : List (K × V)
deriving Inhabited
instance (K V : Type) [BEq K] [BEq V] : BEq (Map K V) where
beq m1 m2 := List.length m1.entries = List.length m2.entries ∧ List.beq m1.entries m2.entries
def empty {K V : Type} [BEq K] [BEq V] : Map K V := ⟨[]⟩
def insert {K V : Type} [BEq K] [BEq V] (m : Map K V) (k : K) (v : V) : Map K V :=
let entries := m.entries.filter (fun p => ¬(p.1 == k)) ++ [(k, v)]
⟨entries⟩
-- !benchmark @end task_aux
-- !benchmark @start solution_aux
-- !benchmark @end solution_aux
-- !benchmark @start precond_aux
-- !benchmark @end precond_aux
@[reducible, simp]
def update_map_precond (m1 : Map Int Int) (m2 : Map Int Int) : Prop :=
-- !benchmark @start precond
True
-- !benchmark @end precond
-- !benchmark @start code_aux
-- !benchmark @end code_aux
def update_map (m1 : Map Int Int) (m2 : Map Int Int) (h_precond : update_map_precond (m1) (m2)) : Map Int Int :=
-- !benchmark @start code
let foldFn := fun (acc : Map Int Int) (entry : Int × Int) =>
insert acc entry.1 entry.2
let updated := m2.entries.foldl foldFn m1
⟨updated.entries.mergeSort (fun a b => a.1 ≤ b.1)⟩
-- !benchmark @end code
-- !benchmark @start postcond_aux
def find? {K V : Type} [BEq K] [BEq V] (m : Map K V) (k : K) : Option V :=
m.entries.find? (fun p => p.1 == k) |>.map (·.2)
-- !benchmark @end postcond_aux
@[reducible, simp]
def update_map_postcond (m1 : Map Int Int) (m2 : Map Int Int) (result: Map Int Int) (h_precond : update_map_precond (m1) (m2)) : Prop :=
-- !benchmark @start postcond
List.Pairwise (fun a b => a.1 ≤ b.1) result.entries ∧
m2.entries.all (fun x => find? result x.1 = some x.2) ∧
m1.entries.all (fun x =>
match find? m2 x.1 with
| some _ => true
| none => find? result x.1 = some x.2
) ∧
result.entries.all (fun x =>
match find? m1 x.1 with
| some v => match find? m2 x.1 with
| some v' => x.2 = v'
| none => x.2 = v
| none => find? m2 x.1 = some x.2
)
-- !benchmark @end postcond
-- !benchmark @start proof_aux
-- !benchmark @end proof_aux
theorem update_map_spec_satisfied (m1: Map Int Int) (m2: Map Int Int) (h_precond : update_map_precond (m1) (m2)) :
update_map_postcond (m1) (m2) (update_map (m1) (m2) h_precond) h_precond := by
-- !benchmark @start proof
sorry
-- !benchmark @end proof
| {
"name": "update_map",
"parameters": {
"param_name": [
"m1",
"m2"
],
"param_type": [
"Map Int Int",
"Map Int Int"
]
},
"return_type": "Map Int Int"
} | {
"upstream": {
"name": "clover",
"link": "https://github.com/ChuyueSun/Clover",
"task_id": "Clover_update_map",
"student_id": null
}
} | {
"input": [
"{\"m1\": \"\\u27e8[(1, 10), (2, 20)]\\u27e9\", \"m2\": \"\\u27e8[(2, 30), (3, 40)]\\u27e9\"}",
"{\"m1\": \"\\u27e8[(1, 100)]\\u27e9\", \"m2\": \"\\u27e8[(1, 200)]\\u27e9\"}",
"{\"m1\": \"\\u27e8[(5, 50), (6, 60)]\\u27e9\", \"m2\": \"\\u27e8[]\\u27e9\"}",
"{\"m1\": \"\\u27e8[]\\u27e9\", \"m2\": \"\\u27e8[(7, 70)]\\u27e9\"}",
"{\"m1\": \"\\u27e8[(1, 1), (2, 2), (3, 3)]\\u27e9\", \"m2\": \"\\u27e8[(2, 20), (4, 40)]\\u27e9\"}"
],
"expected": [
[
"⟨[(1, 10), (2, 30), (3, 40)]⟩"
],
[
"⟨[(1, 200)]⟩"
],
[
"⟨[(5, 50), (6, 60)]⟩"
],
[
"⟨[(7, 70)]⟩"
],
[
"⟨[(1, 1), (2, 20), (3, 3), (4, 40)]⟩"
]
],
"unexpected": [
[
"⟨[(1, 10), (2, 20), (3, 40)]⟩",
"⟨[(1, 10), (2, 20)]⟩",
"⟨[(2, 30), (3, 40)]⟩"
],
[
"⟨[(1, 100)]⟩",
"⟨[(1, 200), (1, 100)]⟩",
"⟨[]⟩"
],
[
"⟨[(5, 50)]⟩",
"⟨[(6, 60)]⟩",
"⟨[(5, 50), (6, 60), (7, 70)]⟩"
],
[
"⟨[]⟩",
"⟨[(0, 70)]⟩",
"⟨[(7, 0)]⟩"
],
[
"⟨[(1, 1), (2, 2), (3, 3)]⟩",
"⟨[(1, 1), (2, 20), (3, 3)]⟩",
"⟨[(1, 1), (2, 20), (3, 3), (4, 30)]⟩"
]
]
} | {
"input": []
} | basic |
verina_basic_58 | -----Description-----
This task involves transforming an array of integers by doubling each element.
-----Input-----
The input consists of:
• s: An array of integers.
-----Output-----
The output is an array of integers where for each valid index i, the element at position i is equal to twice the corresponding element in the input array.
-----Note-----
The implementation makes use of a recursive helper function to update the array in place. It is assumed that the input array is valid and that the doubling operation does not lead to any overflow issues. | -- !benchmark @start import type=solution
-- !benchmark @end import
-- !benchmark @start solution_aux
-- !benchmark @end solution_aux
-- !benchmark @start precond_aux
-- !benchmark @end precond_aux
@[reducible, simp]
def double_array_elements_precond (s : Array Int) : Prop :=
-- !benchmark @start precond
True
-- !benchmark @end precond
-- !benchmark @start code_aux
def double_array_elements_aux (s_old s : Array Int) (i : Nat) : Array Int :=
if i < s.size then
let new_s := s.set! i (2 * (s_old[i]!))
double_array_elements_aux s_old new_s (i + 1)
else
s
-- !benchmark @end code_aux
def double_array_elements (s : Array Int) (h_precond : double_array_elements_precond (s)) : Array Int :=
-- !benchmark @start code
double_array_elements_aux s s 0
-- !benchmark @end code
-- !benchmark @start postcond_aux
-- !benchmark @end postcond_aux
@[reducible, simp]
def double_array_elements_postcond (s : Array Int) (result: Array Int) (h_precond : double_array_elements_precond (s)) :=
-- !benchmark @start postcond
result.size = s.size ∧ ∀ i, i < s.size → result[i]! = 2 * s[i]!
-- !benchmark @end postcond
-- !benchmark @start proof_aux
-- !benchmark @end proof_aux
theorem double_array_elements_spec_satisfied (s: Array Int) (h_precond : double_array_elements_precond (s)) :
double_array_elements_postcond (s) (double_array_elements (s) h_precond) h_precond := by
-- !benchmark @start proof
sorry
-- !benchmark @end proof
| {
"name": "double_array_elements",
"parameters": {
"param_name": [
"s"
],
"param_type": [
"Array Int"
]
},
"return_type": "Array Int"
} | {
"upstream": {
"name": "clover",
"link": "https://github.com/ChuyueSun/Clover",
"task_id": "Clover_double_array_elements",
"student_id": null
}
} | {
"input": [
"{\"s\": \"#[]\"}",
"{\"s\": \"#[1, 2, 3, 4, 5]\"}",
"{\"s\": \"#[0, -1, 5]\"}",
"{\"s\": \"#[100]\"}",
"{\"s\": \"#[-3, -4]\"}"
],
"expected": [
[
"#[]"
],
[
"#[2, 4, 6, 8, 10]"
],
[
"#[0, -2, 10]"
],
[
"#[200]"
],
[
"#[-6, -8]"
]
],
"unexpected": [
[
"#[1]",
"#[0]",
"#[-1]"
],
[
"#[1, 2, 3, 4, 5]",
"#[2, 4, 6, 8, 9]",
"#[0, 4, 6, 8, 10]"
],
[
"#[0, -1, 5]",
"#[1, -2, 10]",
"#[0, 0, 10]"
],
[
"#[100]",
"#[0]",
"#[201]"
],
[
"#[3, -4]",
"#[-6, -7]",
"#[-6, -9]"
]
]
} | {
"input": []
} | basic |
verina_advanced_57 | -----Description-----
This task requires writing a Lean 4 function that finds the next greater element for a given array of numbers. The next greater element for an element x is defined as the first element greater than x that appears to the right of x in the array.
Given two distinct 0-indexed integer arrays `nums1` and `nums2`, where `nums1` is a subset of `nums2`, the function should determine the next greater element for each value in `nums1` as it appears in `nums2`.
All integers in both arrays are unique, and the length constraints are.
-----Input-----
The input consists of two lists of integers:
nums1: A list of integers, which is a subset of nums2.
nums2: A list of integers containing all elements from nums1 and possibly additional elements.
-----Output-----
The output is a list of integers:
- An array of the same length as nums1.
- For each element nums1[i], the corresponding output element is:
- The next greater element of nums1[i] in nums2 if one exists
- -1 if there is no next greater element
| -- !benchmark @start import type=solution
-- !benchmark @end import
-- !benchmark @start solution_aux
-- !benchmark @end solution_aux
-- !benchmark @start precond_aux
-- !benchmark @end precond_aux
@[reducible]
def nextGreaterElement_precond (nums1 : List Int) (nums2 : List Int) : Prop :=
-- !benchmark @start precond
List.Nodup nums1 ∧
List.Nodup nums2 ∧
nums1.all (fun x => x ∈ nums2)
-- !benchmark @end precond
-- !benchmark @start code_aux
-- !benchmark @end code_aux
def nextGreaterElement (nums1 : List Int) (nums2 : List Int) (h_precond : nextGreaterElement_precond (nums1) (nums2)) : List Int :=
-- !benchmark @start code
let len1 := nums1.length
let buildNextGreaterMap : List (Int × Int) :=
let rec mapLoop (index : Nat) (stack : List Nat) (map : List (Int × Int)) : List (Int × Int) :=
if h : index >= nums2.length then
stack.foldl (fun acc pos => (nums2[pos]!, -1) :: acc) map
else
let currentValue := nums2[index]!
let rec processStack (s : List Nat) (m : List (Int × Int)) : List Nat × List (Int × Int) :=
match s with
| [] => ([], m)
| topIndex :: rest =>
let topValue := nums2[topIndex]!
if currentValue > topValue then
let newMap := (topValue, currentValue) :: m
processStack rest newMap
else
(s, m)
let (newStack, newMap) := processStack stack map
mapLoop (index + 1) (index :: newStack) newMap
termination_by nums2.length - index
mapLoop 0 [] []
let buildResult : List Int :=
let rec resultLoop (i : Nat) (result : List Int) : List Int :=
if i >= len1 then
result.reverse
else
let val := nums1[i]!
let rec findInMap (m : List (Int × Int)) : Int :=
match m with
| [] => -1
| (num, nextGreater) :: rest =>
if num == val then nextGreater
else findInMap rest
let nextGreater := findInMap buildNextGreaterMap
resultLoop (i + 1) (nextGreater :: result)
termination_by len1 - i
resultLoop 0 []
buildResult
-- !benchmark @end code
-- !benchmark @start postcond_aux
-- !benchmark @end postcond_aux
@[reducible]
def nextGreaterElement_postcond (nums1 : List Int) (nums2 : List Int) (result: List Int) (h_precond : nextGreaterElement_precond (nums1) (nums2)) : Prop :=
-- !benchmark @start postcond
result.length = nums1.length ∧
(List.range nums1.length |>.all (fun i =>
let val := nums1[i]!
let resultVal := result[i]!
let j := nums2.findIdx? (fun x => x == val)
match j with
| none => false
| some idx =>
let nextGreater := (List.range (nums2.length - idx - 1)).find? (fun k =>
let pos := idx + k + 1
nums2[pos]! > val
)
match nextGreater with
| none => resultVal = -1
| some offset => resultVal = nums2[idx + offset + 1]!
)) ∧
(result.all (fun val =>
val = -1 ∨ val ∈ nums2
))
-- !benchmark @end postcond
-- !benchmark @start proof_aux
-- !benchmark @end proof_aux
theorem nextGreaterElement_spec_satisfied (nums1: List Int) (nums2: List Int) (h_precond : nextGreaterElement_precond (nums1) (nums2)) :
nextGreaterElement_postcond (nums1) (nums2) (nextGreaterElement (nums1) (nums2) h_precond) h_precond := by
-- !benchmark @start proof
sorry
-- !benchmark @end proof
| {
"name": "nextGreaterElement",
"parameters": {
"param_name": [
"nums1",
"nums2"
],
"param_type": [
"List Int",
"List Int"
]
},
"return_type": "List Int"
} | {
"upstream": {
"name": "lab_assignment",
"link": "https://leetcode.com/problems/spiral-matrix-ii/",
"task_id": "lab_nextGreaterElement_324720188",
"student_id": [
42
]
}
} | {
"input": [
"{\"nums1\": \"[4, 1, 2]\", \"nums2\": \"[1, 3, 4, 2]\"}",
"{\"nums1\": \"[2, 4]\", \"nums2\": \"[1, 2, 3, 4]\"}",
"{\"nums1\": \"[1]\", \"nums2\": \"[1, 2]\"}",
"{\"nums1\": \"[5]\", \"nums2\": \"[5, 4, 3, 2, 1]\"}",
"{\"nums1\": \"[1, 3, 5, 2, 4]\", \"nums2\": \"[6, 5, 4, 3, 2, 1]\"}",
"{\"nums1\": \"[1, 2, 3]\", \"nums2\": \"[3, 2, 1, 4]\"}",
"{\"nums1\": \"[4, 3, 2, 1]\", \"nums2\": \"[4, 3, 2, 1]\"}"
],
"expected": [
[
"[-1, 3, -1]"
],
[
"[3, -1]"
],
[
"[2]"
],
[
"[-1]"
],
[
"[-1, -1, -1, -1, -1]"
],
[
"[4, 4, 4]"
],
[
"[-1, -1, -1, -1]"
]
],
"unexpected": [
[
"[3, -1, 3]"
],
[
"[-1, 3]"
],
[
"[-1]"
],
[
"[4]"
],
[
"[6, 5, 6, 3, 6]"
],
[
"[-1, -1, -1]"
],
[
"[3, 2, 1, -1]"
]
]
} | {
"input": [
"{'nums1': '[1, 3]', 'nums2': '[1, 2]'}",
"{'nums1': '[1, 1]', 'nums2': '[1, 2]'}"
]
} | advanced |
verina_basic_47 | -----Description-----
This task requires writing a Lean 4 method that calculates the sum of all the elements in an array of integers. The method should process the entire array and return the total sum of its elements.
-----Input-----
The input consists of:
a: An array of integers.
-----Output-----
The output is an integer:
Returns the sum of all elements in the input array.
-----Note-----
- The input array is assumed not to be null. | -- !benchmark @start import type=solution
-- !benchmark @end import
-- !benchmark @start solution_aux
-- !benchmark @end solution_aux
-- !benchmark @start precond_aux
-- !benchmark @end precond_aux
@[reducible, simp]
def arraySum_precond (a : Array Int) : Prop :=
-- !benchmark @start precond
a.size > 0
-- !benchmark @end precond
-- !benchmark @start code_aux
-- !benchmark @end code_aux
def arraySum (a : Array Int) (h_precond : arraySum_precond (a)) : Int :=
-- !benchmark @start code
a.toList.sum
-- !benchmark @end code
-- !benchmark @start postcond_aux
def sumTo (a : Array Int) (n : Nat) : Int :=
if n = 0 then 0
else sumTo a (n - 1) + a[n - 1]!
-- !benchmark @end postcond_aux
@[reducible, simp]
def arraySum_postcond (a : Array Int) (result: Int) (h_precond : arraySum_precond (a)) :=
-- !benchmark @start postcond
result - sumTo a a.size = 0 ∧
result ≥ sumTo a a.size
-- !benchmark @end postcond
-- !benchmark @start proof_aux
theorem eq_of_sub_zero_and_ge (a b : Int) : a = b → a - b = 0 ∧ a ≥ b := by
omega
-- !benchmark @end proof_aux
theorem arraySum_spec_satisfied (a: Array Int) (h_precond : arraySum_precond (a)) :
arraySum_postcond (a) (arraySum (a) h_precond) h_precond := by
-- !benchmark @start proof
unfold arraySum arraySum_postcond
apply eq_of_sub_zero_and_ge a.toList.sum (sumTo a a.size)
cases a with | mk d =>
induction d with
| nil => simp [sumTo]
| cons x xs ih =>
simp [ih]
have h1 : sumTo ⟨x::xs⟩ (xs.length + 1) = sumTo ⟨x::xs⟩ xs.length + (x::xs)[xs.length] := by
rw [sumTo]
simp
rw [h1]
have h2 : xs = List.nil → (x::xs)[xs.length] = x := by
intro h_nil
simp [h_nil]
have h3 (x' : Int) (xs' : List Int): xs'.length ≠ 0 → sumTo ⟨x'::xs'⟩ xs'.length = x' + sumTo ⟨xs'⟩ (xs'.length - 1) := by
induction xs'.length with
| zero => simp
| succ n ih_len =>
simp
cases n with
| zero => simp [sumTo]
| succ n' =>
simp at ih_len
unfold sumTo
simp_all
rw [Int.add_assoc]
cases xs with
| nil => simp [h2, sumTo]
| cons y ys =>
simp_all
have h4 : sumTo ⟨x::y::ys⟩ (ys.length + 1) = x + sumTo ⟨y::ys⟩ ys.length := by
apply h3 x (y::ys)
simp
rw [h4, sumTo]
simp
rw [Int.add_assoc]
-- !benchmark @end proof
| {
"name": "arraySum",
"parameters": {
"param_name": [
"a"
],
"param_type": [
"Array Int"
]
},
"return_type": "Int"
} | {
"upstream": {
"name": "dafny-synthesis",
"link": "https://github.com/Mondego/dafny-synthesis",
"task_id": "task_id_798",
"student_id": null
}
} | {
"input": [
"{\"a\": \"#[1, 2, 3, 4, 5]\"}",
"{\"a\": \"#[13, 14, 15, 16, 17]\"}",
"{\"a\": \"#[-1, -2, -3]\"}",
"{\"a\": \"#[10, -10]\"}"
],
"expected": [
[
"15"
],
[
"75"
],
[
"-6"
],
[
"0"
]
],
"unexpected": [
[
"14",
"10",
"16"
],
[
"74",
"76",
"70"
],
[
"-5",
"-7",
"0"
],
[
"5",
"-5",
"10"
]
]
} | {
"input": [
"{'a': '#[]'}"
]
} | basic |
verina_basic_75 | -----Description-----
This task involves finding the minimum element in a non-empty array of integers. The goal is to identify and return the smallest number present in the array.
-----Input-----
The input consists of:
• a: An array of integers (the array is assumed to be non-empty).
-----Output-----
The output is an integer that:
• Is the smallest element from the input array.
• Satisfies the property that it is less than or equal to every element in the array and is exactly equal to at least one element of the array.
-----Note-----
It is assumed that the input array contains at least one element. The implementation uses a helper function (loop) to recursively compare elements and determine the minimum value. | -- !benchmark @start import type=solution
-- !benchmark @end import
-- !benchmark @start solution_aux
-- !benchmark @end solution_aux
-- !benchmark @start precond_aux
-- !benchmark @end precond_aux
@[reducible, simp]
def minArray_precond (a : Array Int) : Prop :=
-- !benchmark @start precond
a.size > 0
-- !benchmark @end precond
-- !benchmark @start code_aux
def loop (a : Array Int) (i : Nat) (currentMin : Int) : Int :=
if i < a.size then
let newMin := if currentMin > a[i]! then a[i]! else currentMin
loop a (i + 1) newMin
else
currentMin
-- !benchmark @end code_aux
def minArray (a : Array Int) (h_precond : minArray_precond (a)) : Int :=
-- !benchmark @start code
loop a 1 (a[0]!)
-- !benchmark @end code
-- !benchmark @start postcond_aux
-- !benchmark @end postcond_aux
@[reducible, simp]
def minArray_postcond (a : Array Int) (result: Int) (h_precond : minArray_precond (a)) :=
-- !benchmark @start postcond
(∀ i : Nat, i < a.size → result <= a[i]!) ∧ (∃ i : Nat, i < a.size ∧ result = a[i]!)
-- !benchmark @end postcond
-- !benchmark @start proof_aux
-- !benchmark @end proof_aux
theorem minArray_spec_satisfied (a: Array Int) (h_precond : minArray_precond (a)) :
minArray_postcond (a) (minArray (a) h_precond) h_precond := by
-- !benchmark @start proof
sorry
-- !benchmark @end proof
| {
"name": "minArray",
"parameters": {
"param_name": [
"a"
],
"param_type": [
"Array Int"
]
},
"return_type": "Int"
} | {
"upstream": {
"name": "clover",
"link": "https://github.com/ChuyueSun/Clover",
"task_id": "Clover_min_array",
"student_id": null
}
} | {
"input": [
"{\"a\": \"#[5, 3, 8, 2, 7]\"}",
"{\"a\": \"#[10, 10, 10]\"}",
"{\"a\": \"#[-1, -5, 3, 0]\"}",
"{\"a\": \"#[42]\"}",
"{\"a\": \"#[3, -2, 0, -2, 5]\"}"
],
"expected": [
[
"2"
],
[
"10"
],
[
"-5"
],
[
"42"
],
[
"-2"
]
],
"unexpected": [
[
"3",
"5",
"7"
],
[
"0",
"5",
"11"
],
[
"-1",
"0",
"3"
],
[
"0",
"-42",
"100"
],
[
"0",
"3",
"5"
]
]
} | {
"input": [
"{'a': '#[]'}"
]
} | basic |
verina_basic_108 | -----Description-----
The problem is about processing a sequence of integer operations to determine cumulative results and identify potential negative outcomes. Given a list of integers, the task is to generate an array where the first element is 0 and each subsequent element is the cumulative sum of the operations performed sequentially. Additionally, the solution should check whether any of these cumulative values (after the initial 0) is negative, and return a corresponding boolean flag.
-----Input-----
The input consists of:
• operations: A list of integers representing sequential operations.
-----Output-----
The output is a tuple consisting of:
• An array of integers representing the partial sums. The array’s size is one more than the number of operations, starting with 0 and where for each index i such that 0 ≤ i < operations.length, the element at index i+1 is equal to the element at index i added to operations[i].
• A boolean value that is true if there exists an index i (with 1 ≤ i ≤ operations.length) such that the i-th partial sum is negative, and false otherwise.
-----Note-----
The function should also correctly handle an empty list of operations. | -- !benchmark @start import type=solution
-- !benchmark @end import
-- !benchmark @start solution_aux
-- !benchmark @end solution_aux
-- !benchmark @start precond_aux
-- !benchmark @end precond_aux
@[reducible, simp]
def below_zero_precond (operations : List Int) : Prop :=
-- !benchmark @start precond
True
-- !benchmark @end precond
-- !benchmark @start code_aux
def buildS (operations : List Int) : Array Int :=
let sList := operations.foldl
(fun (acc : List Int) (op : Int) =>
let last := acc.getLast? |>.getD 0
acc.append [last + op])
[0]
Array.mk sList
-- !benchmark @end code_aux
def below_zero (operations : List Int) (h_precond : below_zero_precond (operations)) : (Array Int × Bool) :=
-- !benchmark @start code
let s := buildS operations
let rec check_negative (lst : List Int) : Bool :=
match lst with
| [] => false
| x :: xs => if x < 0 then true else check_negative xs
let result := check_negative (s.toList)
(s, result)
-- !benchmark @end code
-- !benchmark @start postcond_aux
-- !benchmark @end postcond_aux
@[reducible, simp]
def below_zero_postcond (operations : List Int) (result: (Array Int × Bool)) (h_precond : below_zero_precond (operations)) :=
-- !benchmark @start postcond
let s := result.1
let result := result.2
s.size = operations.length + 1 ∧
s[0]? = some 0 ∧
(List.range (s.size - 1)).all (fun i => s[i + 1]? = some (s[i]! + operations[i]!)) ∧
((result = true) → ((List.range (operations.length)).any (fun i => s[i + 1]! < 0))) ∧
((result = false) → s.all (· ≥ 0))
-- !benchmark @end postcond
-- !benchmark @start proof_aux
-- !benchmark @end proof_aux
theorem below_zero_spec_satisfied (operations: List Int) (h_precond : below_zero_precond (operations)) :
below_zero_postcond (operations) (below_zero (operations) h_precond) h_precond := by
-- !benchmark @start proof
sorry
-- !benchmark @end proof
| {
"name": "below_zero",
"parameters": {
"param_name": [
"operations"
],
"param_type": [
"List Int"
]
},
"return_type": "(Array Int × Bool)"
} | {
"upstream": {
"name": "clover",
"link": "https://github.com/ChuyueSun/Clover",
"task_id": "Clover_below_zero",
"student_id": null
}
} | {
"input": [
"{\"operations\": \"[1, 2, 3]\"}",
"{\"operations\": \"[-1, 2, -1]\"}",
"{\"operations\": \"[]\"}",
"{\"operations\": \"[0, 0, 0]\"}",
"{\"operations\": \"[10, -20, 5]\"}"
],
"expected": [
[
"(#[0, 1, 3, 6], false)"
],
[
"(#[0, -1, 1, 0], true)"
],
[
"(#[0], false)"
],
[
"(#[0, 0, 0, 0], false)"
],
[
"(#[0, 10, -10, -5], true)"
]
],
"unexpected": [
[
"(#[0, 1, 3, 5], false)",
"(#[0, 2, 3, 6], false)",
"(#[0, 1, 3, 6], true)"
],
[
"(#[0, -1, 1, 0], false)",
"(#[0, -1, 0, 0], true)",
"(#[0, -2, 1, 0], true)"
],
[
"(#[0], true)",
"(#[0, 0], false)",
"(#[0, 1], false)"
],
[
"(#[0, 0, 0, 0], true)",
"(#[0, 0, 0], false)",
"(#[0, 0, 1, 0], false)"
],
[
"(#[0, 10, -10, -5], false)",
"(#[0, 10, -9, -5], true)",
"(#[0, 10, -10, -6], true)"
]
]
} | {
"input": []
} | basic |
verina_basic_37 | -----Description-----
This task requires writing a Lean 4 method that locates the first occurrence of a specified integer within a sorted array of integers. The method returns the index corresponding to the first time the target value appears in the array; if the target is absent, it returns -1. It is also essential that the original array remains unchanged.
-----Input-----
The input consists of:
• arr: An array of integers sorted in non-decreasing order.
• target: An integer representing the value to search for.
-----Output-----
The output is an integer:
• If the target is found, the method returns the index of its first occurrence.
• If the target is not found, the method returns -1.
-----Note-----
• The input array must be sorted in non-decreasing order.
• The array is guaranteed to remain unmodified after the method executes. | -- !benchmark @start import type=solution
-- !benchmark @end import
-- !benchmark @start solution_aux
-- !benchmark @end solution_aux
-- !benchmark @start precond_aux
-- !benchmark @end precond_aux
@[reducible, simp]
def findFirstOccurrence_precond (arr : Array Int) (target : Int) : Prop :=
-- !benchmark @start precond
List.Pairwise (· ≤ ·) arr.toList
-- !benchmark @end precond
-- !benchmark @start code_aux
-- !benchmark @end code_aux
def findFirstOccurrence (arr : Array Int) (target : Int) (h_precond : findFirstOccurrence_precond (arr) (target)) : Int :=
-- !benchmark @start code
let rec loop (i : Nat) : Int :=
if i < arr.size then
let a := arr[i]!
if a = target then i
else if a > target then -1
else loop (i + 1)
else -1
loop 0
-- !benchmark @end code
-- !benchmark @start postcond_aux
-- !benchmark @end postcond_aux
@[reducible, simp]
def findFirstOccurrence_postcond (arr : Array Int) (target : Int) (result: Int) (h_precond : findFirstOccurrence_precond (arr) (target)) :=
-- !benchmark @start postcond
(result ≥ 0 →
arr[result.toNat]! = target ∧
(∀ i : Nat, i < result.toNat → arr[i]! ≠ target)) ∧
(result = -1 →
(∀ i : Nat, i < arr.size → arr[i]! ≠ target))
-- !benchmark @end postcond
-- !benchmark @start proof_aux
-- !benchmark @end proof_aux
theorem findFirstOccurrence_spec_satisfied (arr: Array Int) (target: Int) (h_precond : findFirstOccurrence_precond (arr) (target)) :
findFirstOccurrence_postcond (arr) (target) (findFirstOccurrence (arr) (target) h_precond) h_precond := by
-- !benchmark @start proof
sorry
-- !benchmark @end proof
| {
"name": "findFirstOccurrence",
"parameters": {
"param_name": [
"arr",
"target"
],
"param_type": [
"Array Int",
"Int"
]
},
"return_type": "Int"
} | {
"upstream": {
"name": "dafny-synthesis",
"link": "https://github.com/Mondego/dafny-synthesis",
"task_id": "task_id_733",
"student_id": null
}
} | {
"input": [
"{\"arr\": \"#[1, 2, 2, 3, 4, 5]\", \"target\": 2}",
"{\"arr\": \"#[1, 2, 2, 3, 4, 5]\", \"target\": 6}",
"{\"arr\": \"#[1, 2, 3, 4, 5]\", \"target\": 1}",
"{\"arr\": \"#[1, 2, 3, 4, 5]\", \"target\": 5}",
"{\"arr\": \"#[1, 2, 3, 4, 5]\", \"target\": 0}"
],
"expected": [
[
"1"
],
[
"-1"
],
[
"0"
],
[
"4"
],
[
"-1"
]
],
"unexpected": [
[
"0",
"2",
"-1"
],
[
"0",
"1",
"2"
],
[
"1",
"-1",
"2"
],
[
"3",
"5",
"0"
],
[
"0",
"1",
"2"
]
]
} | {
"input": [
"{'arr': '#[3, 2, 1]', 'target': 2}"
]
} | basic |
verina_basic_98 | -----Description-----
This task involves computing three times a given integer. Given an integer, the goal is to produce a value that is exactly three times its value.
-----Input-----
The input consists of a single integer:
x: An integer.
-----Output-----
The output is an integer:
Returns the product of the input integer and 3.
-----Note-----
There are no additional preconditions. | -- !benchmark @start import type=solution
-- !benchmark @end import
-- !benchmark @start solution_aux
-- !benchmark @end solution_aux
-- !benchmark @start precond_aux
-- !benchmark @end precond_aux
@[reducible, simp]
def Triple_precond (x : Int) : Prop :=
-- !benchmark @start precond
True
-- !benchmark @end precond
-- !benchmark @start code_aux
-- !benchmark @end code_aux
def Triple (x : Int) (h_precond : Triple_precond (x)) : Int :=
-- !benchmark @start code
x * 3
-- !benchmark @end code
-- !benchmark @start postcond_aux
-- !benchmark @end postcond_aux
@[reducible, simp]
def Triple_postcond (x : Int) (result: Int) (h_precond : Triple_precond (x)) :=
-- !benchmark @start postcond
result / 3 = x ∧ result / 3 * 3 = result
-- !benchmark @end postcond
-- !benchmark @start proof_aux
-- !benchmark @end proof_aux
theorem Triple_spec_satisfied (x: Int) (h_precond : Triple_precond (x)) :
Triple_postcond (x) (Triple (x) h_precond) h_precond := by
-- !benchmark @start proof
unfold Triple_postcond Triple
simp +arith
-- !benchmark @end proof
| {
"name": "Triple",
"parameters": {
"param_name": [
"x"
],
"param_type": [
"Int"
]
},
"return_type": "Int"
} | {
"upstream": {
"name": "clover",
"link": "https://github.com/ChuyueSun/Clover",
"task_id": "Clover_triple",
"student_id": null
}
} | {
"input": [
"{\"x\": 0}",
"{\"x\": 2}",
"{\"x\": -4}",
"{\"x\": 10}",
"{\"x\": -1}"
],
"expected": [
[
"0"
],
[
"6"
],
[
"-12"
],
[
"30"
],
[
"-3"
]
],
"unexpected": [
[
"-1",
"1",
"2"
],
[
"4",
"5",
"7"
],
[
"-8",
"-10",
"-16"
],
[
"20",
"25",
"35"
],
[
"-2",
"-4",
"0"
]
]
} | {
"input": []
} | basic |
verina_advanced_46 | -----Description-----
This test implements a function in Lean 4 that finds the maximum sum of any contiguous subarray within a list of integers. A subarray is a continuous section of the original array. If all integers in the list are negative, the function should return 0 (representing the empty subarray).
-----Input-----
numbers: A list of integers that may contain positive, negative, or zero values.
-----Output-----
An integer representing the maximum sum of any contiguous subarray. If the list is empty or contains only negative numbers, the function returns 0.
| -- !benchmark @start import type=solution
-- !benchmark @end import
-- !benchmark @start solution_aux
-- !benchmark @end solution_aux
-- !benchmark @start precond_aux
-- !benchmark @end precond_aux
@[reducible, simp]
def maxSubarraySum_precond (numbers : List Int) : Prop :=
-- !benchmark @start precond
True
-- !benchmark @end precond
-- !benchmark @start code_aux
-- !benchmark @end code_aux
def maxSubarraySum (numbers : List Int) (h_precond : maxSubarraySum_precond (numbers)) : Int :=
-- !benchmark @start code
let rec isAllNegative : List Int → Bool
| [] => true
| x :: xs => if x >= 0 then false else isAllNegative xs
let rec findMaxProduct : List Int → Int → Int → Int
| [], currMax, _ => currMax
| [x], currMax, _ => max currMax x
| x :: y :: rest, currMax, currSum =>
let newSum := max y (currSum + y)
let newMax := max currMax newSum
findMaxProduct (y :: rest) newMax newSum
let handleList : List Int → Nat
| [] => 0
| xs =>
if isAllNegative xs then
0
else
match xs with
| [] => 0
| x :: rest =>
let initialMax := max 0 x
let startSum := max 0 x
let result := findMaxProduct (x :: rest) initialMax startSum
result.toNat
handleList numbers
-- !benchmark @end code
-- !benchmark @start postcond_aux
-- !benchmark @end postcond_aux
@[reducible, simp]
def maxSubarraySum_postcond (numbers : List Int) (result: Int) (h_precond : maxSubarraySum_precond (numbers)) : Prop :=
-- !benchmark @start postcond
let subArraySums :=
List.range (numbers.length + 1) |>.flatMap (fun start =>
List.range (numbers.length - start + 1) |>.map (fun len =>
numbers.drop start |>.take len |>.sum))
subArraySums.contains result ∧ subArraySums.all (· ≤ result)
-- !benchmark @end postcond
-- !benchmark @start proof_aux
-- !benchmark @end proof_aux
theorem maxSubarraySum_spec_satisfied (numbers: List Int) (h_precond : maxSubarraySum_precond (numbers)) :
maxSubarraySum_postcond (numbers) (maxSubarraySum (numbers) h_precond) h_precond := by
-- !benchmark @start proof
sorry
-- !benchmark @end proof
| {
"name": "maxSubarraySum",
"parameters": {
"param_name": [
"numbers"
],
"param_type": [
"List Int"
]
},
"return_type": "Int"
} | {
"upstream": {
"name": "lab_assignment",
"link": "",
"task_id": "lab_maxSubarraySum_324969521",
"student_id": [
26
]
}
} | {
"input": [
"{\"numbers\": \"[1, 2, 3, -2, 5]\"}",
"{\"numbers\": \"[-2, -3, 4, -1, -2, 1, 5, -3]\"}",
"{\"numbers\": \"[-1, -2, -3, -4]\"}",
"{\"numbers\": \"[5, -3, 2, 1, -2]\"}",
"{\"numbers\": \"[0, 0, 0, 0]\"}",
"{\"numbers\": \"[]\"}",
"{\"numbers\": \"[10]\"}",
"{\"numbers\": \"[-5, 8, -3, 4, -1]\"}"
],
"expected": [
[
"9"
],
[
"7"
],
[
"0"
],
[
"5"
],
[
"0"
],
[
"0"
],
[
"10"
],
[
"9"
]
],
"unexpected": [
[
"6",
"10",
"1"
],
[
"5",
"4",
"9"
],
[
"1",
"-1",
"-10"
],
[
"3",
"6",
"4"
],
[
"1",
"-1"
],
[
"1"
],
[
"0",
"5"
],
[
"8",
"3",
"0"
]
]
} | {
"input": []
} | advanced |
verina_basic_57 | -----Description-----
This task involves determining how many numbers within an array are less than a specified threshold. The problem is focused on identifying and counting such numbers based purely on their value in relation to the threshold.
-----Input-----
The input consists of:
• numbers: An array of integers (which may be empty or non-empty).
• threshold: An integer that serves as the comparison threshold.
-----Output-----
The output is a natural number (Nat) representing the count of elements in the array that are less than the given threshold.
-----Note-----
There are no additional preconditions; the function should work correctly for any array of integers and any integer threshold. | -- !benchmark @start import type=solution
-- !benchmark @end import
-- !benchmark @start solution_aux
-- !benchmark @end solution_aux
-- !benchmark @start precond_aux
-- !benchmark @end precond_aux
@[reducible, simp]
def CountLessThan_precond (numbers : Array Int) (threshold : Int) : Prop :=
-- !benchmark @start precond
True
-- !benchmark @end precond
-- !benchmark @start code_aux
def countLessThan (numbers : Array Int) (threshold : Int) : Nat :=
let rec count (i : Nat) (acc : Nat) : Nat :=
if i < numbers.size then
let new_acc := if numbers[i]! < threshold then acc + 1 else acc
count (i + 1) new_acc
else
acc
count 0 0
-- !benchmark @end code_aux
def CountLessThan (numbers : Array Int) (threshold : Int) (h_precond : CountLessThan_precond (numbers) (threshold)) : Nat :=
-- !benchmark @start code
countLessThan numbers threshold
-- !benchmark @end code
-- !benchmark @start postcond_aux
-- !benchmark @end postcond_aux
@[reducible, simp]
def CountLessThan_postcond (numbers : Array Int) (threshold : Int) (result: Nat) (h_precond : CountLessThan_precond (numbers) (threshold)) :=
-- !benchmark @start postcond
result - numbers.foldl (fun count n => if n < threshold then count + 1 else count) 0 = 0 ∧
numbers.foldl (fun count n => if n < threshold then count + 1 else count) 0 - result = 0
-- !benchmark @end postcond
-- !benchmark @start proof_aux
-- !benchmark @end proof_aux
theorem CountLessThan_spec_satisfied (numbers: Array Int) (threshold: Int) (h_precond : CountLessThan_precond (numbers) (threshold)) :
CountLessThan_postcond (numbers) (threshold) (CountLessThan (numbers) (threshold) h_precond) h_precond := by
-- !benchmark @start proof
sorry
-- !benchmark @end proof
| {
"name": "CountLessThan",
"parameters": {
"param_name": [
"numbers",
"threshold"
],
"param_type": [
"Array Int",
"Int"
]
},
"return_type": "Nat"
} | {
"upstream": {
"name": "clover",
"link": "https://github.com/ChuyueSun/Clover",
"task_id": "Clover_count_lessthan",
"student_id": null
}
} | {
"input": [
"{\"numbers\": \"#[1, 2, 3, 4, 5]\", \"threshold\": 3}",
"{\"numbers\": \"#[]\", \"threshold\": 10}",
"{\"numbers\": \"#[-1, 0, 1]\", \"threshold\": 0}",
"{\"numbers\": \"#[5, 6, 7, 2, 1]\", \"threshold\": 5}",
"{\"numbers\": \"#[3, 3, 3, 3]\", \"threshold\": 3}"
],
"expected": [
[
"2"
],
[
"0"
],
[
"1"
],
[
"2"
],
[
"0"
]
],
"unexpected": [
[
"3",
"1",
"0"
],
[
"1",
"2",
"3"
],
[
"0",
"2",
"3"
],
[
"3",
"4",
"1"
],
[
"1",
"2",
"3"
]
]
} | {
"input": []
} | basic |
verina_advanced_20 | -----Description-----
This task requires writing a Lean 4 method that returns true if the input n is divisible by 8 or has 8 as one of it's digits.
-----Input-----
The input consists of one integer:
n: The main integer.
-----Output-----
The output is an boolean:
Returns true if the input is divisible by 8 or has 8 as one of it's digits.
| -- !benchmark @start import type=solution
-- !benchmark @end import
-- !benchmark @start solution_aux
-- !benchmark @end solution_aux
-- !benchmark @start precond_aux
-- !benchmark @end precond_aux
@[reducible]
def isItEight_precond (n : Int) : Prop :=
-- !benchmark @start precond
True
-- !benchmark @end precond
-- !benchmark @start code_aux
-- !benchmark @end code_aux
def isItEight (n : Int) (h_precond : isItEight_precond (n)) : Bool :=
-- !benchmark @start code
let rec hasDigitEight (m : Nat) : Bool :=
if m <= 0 then false
else if m % 10 == 8 then true
else hasDigitEight (m / 10)
termination_by m
let absN := Int.natAbs n
n % 8 == 0 || hasDigitEight absN
-- !benchmark @end code
-- !benchmark @start postcond_aux
-- !benchmark @end postcond_aux
@[reducible]
def isItEight_postcond (n : Int) (result: Bool) (h_precond : isItEight_precond (n)) : Prop :=
-- !benchmark @start postcond
let absN := Int.natAbs n;
(n % 8 == 0 ∨ ∃ i, absN / (10^i) % 10 == 8) ↔ result
-- !benchmark @end postcond
-- !benchmark @start proof_aux
-- !benchmark @end proof_aux
theorem isItEight_spec_satisfied (n: Int) (h_precond : isItEight_precond (n)) :
isItEight_postcond (n) (isItEight (n) h_precond) h_precond := by
-- !benchmark @start proof
sorry
-- !benchmark @end proof
| {
"name": "isItEight",
"parameters": {
"param_name": [
"n"
],
"param_type": [
"Int"
]
},
"return_type": "Bool"
} | {
"upstream": {
"name": "lab_assignment",
"link": "N/A Problem I came up with",
"task_id": "lab_isItEight_324366300",
"student_id": [
16
]
}
} | {
"input": [
"{\"n\": 8}",
"{\"n\": 98}",
"{\"n\": 1224}",
"{\"n\": 73}",
"{\"n\": 208}",
"{\"n\": 0}",
"{\"n\": -123456780}",
"{\"n\": 1}",
"{\"n\": -9999}",
"{\"n\": -123453}"
],
"expected": [
[
"True"
],
[
"True"
],
[
"True"
],
[
"False"
],
[
"True"
],
[
"True"
],
[
"True"
],
[
"False"
],
[
"False"
],
[
"False"
]
],
"unexpected": [
[
"False"
],
[
"False"
],
[
"False"
],
[
"True"
],
[
"False"
],
[
"False"
],
[
"False"
],
[
"True"
],
[
"True"
],
[
"True"
]
]
} | {
"input": []
} | advanced |
verina_basic_77 | -----Description-----
This task involves updating an element within a 2-dimensional array. The goal is to modify only a specific inner array by changing one of its elements to a new value while keeping every other element and all other inner arrays unchanged.
-----Input-----
The input consists of:
• arr: An array of arrays of natural numbers.
• index1: A natural number representing the index in the outer array identifying which inner array to modify (0-indexed).
• index2: A natural number representing the index within the selected inner array that should be updated (0-indexed).
• val: A natural number which is the new value to set at the specified inner index.
-----Output-----
The output is an array of arrays of natural numbers that:
• Has the same overall structure as the input.
• Contains all original inner arrays unchanged except for the inner array at position index1.
• In the modified inner array, only the element at index2 is replaced with val, while all other elements remain the same.
-----Note-----
It is assumed that index1 is a valid index for the outer array and that index2 is a valid index within the corresponding inner array. | -- !benchmark @start import type=solution
-- !benchmark @end import
-- !benchmark @start solution_aux
-- !benchmark @end solution_aux
-- !benchmark @start precond_aux
-- !benchmark @end precond_aux
@[reducible, simp]
def modify_array_element_precond (arr : Array (Array Nat)) (index1 : Nat) (index2 : Nat) (val : Nat) : Prop :=
-- !benchmark @start precond
index1 < arr.size ∧
index2 < (arr[index1]!).size
-- !benchmark @end precond
-- !benchmark @start code_aux
def updateInner (a : Array Nat) (idx val : Nat) : Array Nat :=
a.set! idx val
-- !benchmark @end code_aux
def modify_array_element (arr : Array (Array Nat)) (index1 : Nat) (index2 : Nat) (val : Nat) (h_precond : modify_array_element_precond (arr) (index1) (index2) (val)) : Array (Array Nat) :=
-- !benchmark @start code
let inner := arr[index1]!
let inner' := updateInner inner index2 val
arr.set! index1 inner'
-- !benchmark @end code
-- !benchmark @start postcond_aux
-- !benchmark @end postcond_aux
@[reducible, simp]
def modify_array_element_postcond (arr : Array (Array Nat)) (index1 : Nat) (index2 : Nat) (val : Nat) (result: Array (Array Nat)) (h_precond : modify_array_element_precond (arr) (index1) (index2) (val)) :=
-- !benchmark @start postcond
(∀ i, i < arr.size → i ≠ index1 → result[i]! = arr[i]!) ∧
(∀ j, j < (arr[index1]!).size → j ≠ index2 → (result[index1]!)[j]! = (arr[index1]!)[j]!) ∧
((result[index1]!)[index2]! = val)
-- !benchmark @end postcond
-- !benchmark @start proof_aux
-- !benchmark @end proof_aux
theorem modify_array_element_spec_satisfied (arr: Array (Array Nat)) (index1: Nat) (index2: Nat) (val: Nat) (h_precond : modify_array_element_precond (arr) (index1) (index2) (val)) :
modify_array_element_postcond (arr) (index1) (index2) (val) (modify_array_element (arr) (index1) (index2) (val) h_precond) h_precond := by
-- !benchmark @start proof
sorry
-- !benchmark @end proof
| {
"name": "modify_array_element",
"parameters": {
"param_name": [
"arr",
"index1",
"index2",
"val"
],
"param_type": [
"Array (Array Nat)",
"Nat",
"Nat",
"Nat"
]
},
"return_type": "Array (Array Nat)"
} | {
"upstream": {
"name": "clover",
"link": "https://github.com/ChuyueSun/Clover",
"task_id": "Clover_modify_2d_array",
"student_id": null
}
} | {
"input": [
"{\"arr\": \"#[#[1, 2, 3], #[4, 5, 6]]\", \"index1\": 0, \"index2\": 1, \"val\": 99}",
"{\"arr\": \"#[#[7, 8], #[9, 10]]\", \"index1\": 1, \"index2\": 0, \"val\": 0}",
"{\"arr\": \"#[#[0, 0, 0]]\", \"index1\": 0, \"index2\": 2, \"val\": 5}",
"{\"arr\": \"#[#[3, 4, 5], #[6, 7, 8], #[9, 10, 11]]\", \"index1\": 2, \"index2\": 1, \"val\": 100}",
"{\"arr\": \"#[#[1]]\", \"index1\": 0, \"index2\": 0, \"val\": 42}"
],
"expected": [
[
"#[#[1, 99, 3], #[4, 5, 6]]"
],
[
"#[#[7, 8], #[0, 10]]"
],
[
"#[#[0, 0, 5]]"
],
[
"#[#[3, 4, 5], #[6, 7, 8], #[9, 100, 11]]"
],
[
"#[#[42]]"
]
],
"unexpected": [
[
"#[#[1, 2, 3], #[4, 99, 6]]",
"#[#[1, 99, 3], #[4, 5, 7]]",
"#[#[99, 1, 3], #[4, 5, 6]]"
],
[
"#[#[7, 0], #[9, 10]]",
"#[#[7, 8], #[9, 0]]",
"#[#[0, 8], #[9, 10]]"
],
[
"#[#[0, 5, 0]]",
"#[#[5, 0, 0]]"
],
[
"#[#[3, 4, 5], #[6, 7, 8], #[9, 10, 11]]",
"#[#[3, 4, 5], #[6, 7, 8], #[9, 7, 11]]",
"#[#[3, 4, 5], #[6, 7, 8], #[100, 10, 11]]"
],
[
"#[#[1]]",
"#[#[0]]",
"#[#[99]]"
]
]
} | {
"input": [
"{'arr': '#[#[1, 2, 3], #[4, 5, 6]]', 'index1': 1, 'index2': 3, 'val': 99}"
]
} | basic |
verina_advanced_49 | -----Description-----
Implement a Lean 4 function that merges two ascendingly sorted lists of integers into one single sorted list (ascending). The resulting list must contain all elements from both input lists, preserving their ascending order.
-----Input-----
The input consists of two lists of integers:
arr1: A sorted list of integers (ascending)
arr2: Another sorted list of integers (ascending)
-----Output-----
The output is a list of integers:
Returns a new list containing all elements from arr1 and arr2, sorted in ascending order.
| -- !benchmark @start import type=solution
-- !benchmark @end import
-- !benchmark @start solution_aux
-- !benchmark @end solution_aux
-- !benchmark @start precond_aux
-- !benchmark @end precond_aux
@[reducible]
def mergeSortedLists_precond (arr1 : List Int) (arr2 : List Int) : Prop :=
-- !benchmark @start precond
List.Pairwise (· ≤ ·) arr1 ∧ List.Pairwise (· ≤ ·) arr2
-- !benchmark @end precond
-- !benchmark @start code_aux
-- !benchmark @end code_aux
def mergeSortedLists (arr1 : List Int) (arr2 : List Int) (h_precond : mergeSortedLists_precond (arr1) (arr2)) : List Int :=
-- !benchmark @start code
let rec merge (xs : List Int) (ys : List Int) : List Int :=
match xs, ys with
| [], _ => ys
| _, [] => xs
| x :: xt, y :: yt =>
if x <= y then
x :: merge xt (y :: yt)
else
y :: merge (x :: xt) yt
merge arr1 arr2
-- !benchmark @end code
-- !benchmark @start postcond_aux
-- !benchmark @end postcond_aux
@[reducible]
def mergeSortedLists_postcond (arr1 : List Int) (arr2 : List Int) (result: List Int) (h_precond : mergeSortedLists_precond (arr1) (arr2)) : Prop :=
-- !benchmark @start postcond
List.Pairwise (· ≤ ·) result ∧ List.isPerm (arr1 ++ arr2) result
-- !benchmark @end postcond
-- !benchmark @start proof_aux
-- !benchmark @end proof_aux
theorem mergeSortedLists_spec_satisfied (arr1: List Int) (arr2: List Int) (h_precond : mergeSortedLists_precond (arr1) (arr2)) :
mergeSortedLists_postcond (arr1) (arr2) (mergeSortedLists (arr1) (arr2) h_precond) h_precond := by
-- !benchmark @start proof
sorry
-- !benchmark @end proof
| {
"name": "mergeSortedLists",
"parameters": {
"param_name": [
"arr1",
"arr2"
],
"param_type": [
"List Int",
"List Int"
]
},
"return_type": "List Int"
} | {
"upstream": {
"name": "lab_assignment",
"link": "N/A",
"task_id": "lab_mergeSortedLists_325057855",
"student_id": [
17
]
}
} | {
"input": [
"{\"arr1\": \"[1, 3, 5]\", \"arr2\": \"[2, 4, 6]\"}",
"{\"arr1\": \"[]\", \"arr2\": \"[]\"}",
"{\"arr1\": \"[-2, 0, 1]\", \"arr2\": \"[-3, -1]\"}",
"{\"arr1\": \"[10, 20, 30]\", \"arr2\": \"[5, 25, 35]\"}",
"{\"arr1\": \"[1, 2, 2]\", \"arr2\": \"[2, 3, 3]\"}"
],
"expected": [
[
"[1, 2, 3, 4, 5, 6]"
],
[
"[]"
],
[
"[-3, -2, -1, 0, 1]"
],
[
"[5, 10, 20, 25, 30, 35]"
],
[
"[1, 2, 2, 2, 3, 3]"
]
],
"unexpected": [
[
"[1, 3, 5]",
"[2, 4, 6]",
"[1, 3, 2, 4, 5, 6]"
],
[
"[0]",
"[999]"
],
[
"[-3, -1]",
"[0, 1]",
"[-2, 0, 1]"
],
[
"[10, 20, 30]",
"[5, 25, 35]",
"[10, 20, 25, 30, 35]"
],
[
"[1, 2, 3]",
"[2, 2, 2, 3, 3]"
]
]
} | {
"input": [
"{'arr1': '[3, 2, 1]', 'arr2': '[6, 5, 4]'}"
]
} | advanced |
verina_advanced_28 | -----Description-----
This task requires writing a Lean 4 function that finds the length of the longest sequence of consecutive integers present in a given list. The numbers do not need to appear in order. The elements are unique.
A consecutive sequence consists of integers that can be arranged in increasing order with no gaps. Your function should find the longest such streak.
-----Input-----
- nums: A list of integers (no duplicates).
-----Output-----
- A natural number: the length of the longest consecutive sequence.
| -- !benchmark @start import type=solution
import Std.Data.HashSet
import Mathlib
open Std
-- !benchmark @end import
-- !benchmark @start solution_aux
-- !benchmark @end solution_aux
-- !benchmark @start precond_aux
-- !benchmark @end precond_aux
@[reducible, simp]
def longestConsecutive_precond (nums : List Int) : Prop :=
-- !benchmark @start precond
List.Nodup nums
-- !benchmark @end precond
-- !benchmark @start code_aux
-- !benchmark @end code_aux
def longestConsecutive (nums : List Int) (h_precond : longestConsecutive_precond (nums)) : Nat :=
-- !benchmark @start code
Id.run do
let mut set := HashSet.empty
for x in nums do
set := set.insert x
let mut maxLen := 0
for x in nums do
if !set.contains (x - 1) then
let mut curr := x
let mut length := 1
while set.contains (curr + 1) do
curr := curr + 1
length := length + 1
maxLen := Nat.max maxLen length
return maxLen
-- !benchmark @end code
-- !benchmark @start postcond_aux
def isConsecutive (seq : List Int) : Bool :=
seq.length = 0 ∨ seq.zipIdx.all (fun (x, i) => x = i + seq[0]!)
-- !benchmark @end postcond_aux
@[reducible, simp]
def longestConsecutive_postcond (nums : List Int) (result: Nat) (h_precond : longestConsecutive_precond (nums)) : Prop :=
-- !benchmark @start postcond
let sorted_nums := nums.mergeSort
let consec_sublist_lens := List.range nums.length |>.flatMap (fun start =>
List.range (nums.length - start + 1) |>.map (fun len => sorted_nums.extract start (start + len))) |>.filter isConsecutive |>.map (·.length)
(nums = [] → result = 0) ∧
(nums ≠ [] → consec_sublist_lens.contains result ∧ consec_sublist_lens.all (· ≤ result))
-- !benchmark @end postcond
-- !benchmark @start proof_aux
-- !benchmark @end proof_aux
theorem longestConsecutive_spec_satisfied (nums: List Int) (h_precond : longestConsecutive_precond (nums)) :
longestConsecutive_postcond (nums) (longestConsecutive (nums) h_precond) h_precond := by
-- !benchmark @start proof
sorry
-- !benchmark @end proof
| {
"name": "longestConsecutive",
"parameters": {
"param_name": [
"nums"
],
"param_type": [
"List Int"
]
},
"return_type": "Nat"
} | {
"upstream": {
"name": "lab_assignment",
"link": "",
"task_id": "lab_longestConsecutive_325601349",
"student_id": [
22
]
}
} | {
"input": [
"{\"nums\": \"[100, 4, 200, 1, 3, 2]\"}",
"{\"nums\": \"[0, 3, 7, 2, 5, 8, 4, 6, 1]\"}",
"{\"nums\": \"[1, 2, 0]\"}",
"{\"nums\": \"[]\"}",
"{\"nums\": \"[10]\"}"
],
"expected": [
[
"4"
],
[
"9"
],
[
"3"
],
[
"0"
],
[
"1"
]
],
"unexpected": [
[
"3",
"5"
],
[
"8"
],
[
"2"
],
[
"1"
],
[
"0"
]
]
} | {
"input": [
"{'nums': '[1, 1]'}"
]
} | advanced |
verina_basic_44 | -----Description-----
This task requires writing a Lean 4 method that verifies if every odd index in an array of integers holds an odd number. In other words, for each index in the array that is odd, the number located at that index must also be odd. The method should return true if this condition is satisfied for every odd index; otherwise, it should return false.
-----Input-----
The input consists of:
a: An array of integers.
-----Output-----
The output is a Boolean value:
Returns true if, for every odd index in the array, the corresponding element is odd.
Returns false if there is at least one odd index where the corresponding element is not odd.
-----Note-----
There are no preconditions; the method will work for any array of integers. | -- !benchmark @start import type=solution
-- !benchmark @end import
-- !benchmark @start solution_aux
def isOdd (n : Int) : Bool :=
n % 2 == 1
-- !benchmark @end solution_aux
-- !benchmark @start precond_aux
-- !benchmark @end precond_aux
@[reducible, simp]
def isOddAtIndexOdd_precond (a : Array Int) : Prop :=
-- !benchmark @start precond
True
-- !benchmark @end precond
-- !benchmark @start code_aux
-- !benchmark @end code_aux
def isOddAtIndexOdd (a : Array Int) (h_precond : isOddAtIndexOdd_precond (a)) : Bool :=
-- !benchmark @start code
-- First create pairs of (index, value) for all elements in the array
let indexedArray := a.mapIdx fun i x => (i, x)
-- Check if all elements at odd indices are odd numbers
indexedArray.all fun (i, x) => !(isOdd i) || isOdd x
-- !benchmark @end code
-- !benchmark @start postcond_aux
-- !benchmark @end postcond_aux
@[reducible, simp]
def isOddAtIndexOdd_postcond (a : Array Int) (result: Bool) (h_precond : isOddAtIndexOdd_precond (a)) :=
-- !benchmark @start postcond
result ↔ (∀ i, (hi : i < a.size) → isOdd i → isOdd (a[i]))
-- !benchmark @end postcond
-- !benchmark @start proof_aux
-- !benchmark @end proof_aux
theorem isOddAtIndexOdd_spec_satisfied (a: Array Int) (h_precond : isOddAtIndexOdd_precond (a)) :
isOddAtIndexOdd_postcond (a) (isOddAtIndexOdd (a) h_precond) h_precond := by
-- !benchmark @start proof
unfold isOddAtIndexOdd isOddAtIndexOdd_postcond
simp_all
constructor
· intro h
intro i hi h_odd
-- Since the function returns true, all elements in satisfy the predicate
have h_all_odd : (a.mapIdx (fun j x => (j, x))).all (fun (i, x) => !(isOdd i) || isOdd x) = true := by
simp_all
-- Apply the property of Array.all
rw [Array.all_iff_forall] at h_all_odd
simp_all
have h_sat_i : !(isOdd i) || isOdd a[i] := by
simp
apply h_all_odd i hi
simp [h_odd] at h_sat_i
exact h_sat_i
· intro h
apply Array.all_iff_forall.mpr
intro i hi
simp
intro hi'
have h_sat : isOdd i → isOdd a[i] := by
apply h i hi'
rw [Decidable.imp_iff_not_or] at h_sat
simp at h_sat
exact h_sat
-- !benchmark @end proof
| {
"name": "isOddAtIndexOdd",
"parameters": {
"param_name": [
"a"
],
"param_type": [
"Array Int"
]
},
"return_type": "Bool"
} | {
"upstream": {
"name": "dafny-synthesis",
"link": "https://github.com/Mondego/dafny-synthesis",
"task_id": "task_id_775",
"student_id": null
}
} | {
"input": [
"{\"a\": \"#[1, 2, 3, 4, 5]\"}",
"{\"a\": \"#[1, 3, 5, 7, 9]\"}",
"{\"a\": \"#[2, 4, 6, 8, 10]\"}",
"{\"a\": \"#[]\"}",
"{\"a\": \"#[7]\"}",
"{\"a\": \"#[0, 1, 0, 1]\"}",
"{\"a\": \"#[0, 2, 4, 6]\"}"
],
"expected": [
[
"False"
],
[
"True"
],
[
"False"
],
[
"True"
],
[
"True"
],
[
"True"
],
[
"False"
]
],
"unexpected": [
[
"True"
],
[
"False"
],
[
"True"
],
[
"False"
],
[
"False"
],
[
"False"
],
[
"True"
]
]
} | {
"input": []
} | basic |
verina_basic_79 | -----Description-----
Given a nonempty array of integers and a valid index x (with 1 ≤ x < array size), the task is to identify two key pieces of information. First, determine the maximum value among the first x elements of the array. Second, select an index p within the range [x, array size) that satisfies the following conditions: if there exists an element in the segment starting from index x that is strictly greater than the previously determined maximum, then p should be the index of the first such occurrence; otherwise, p should be set to the last index of the array. The focus of the problem is solely on correctly identifying the maximum and choosing the appropriate index based on these order conditions.
-----Input-----
The input consists of:
• a: An array of integers (assumed to be nonempty).
• x: A natural number (Nat) such that 1 ≤ x < a.size.
-----Output-----
The output is a pair (m, p) where:
• m is the maximum value among the first x elements of the array.
• p is an index in the array, with x ≤ p < a.size, determined based on the ordering condition where a[p] is the first element (from index x onward) that is strictly greater than m. If no such element exists, then p is set to a.size − 1.
-----Note-----
It is assumed that the array a is nonempty and that the parameter x meets the precondition 1 ≤ x < a.size. The function relies on helper functions to compute the maximum among the first x elements and to select the appropriate index p based on the given conditions. | -- !benchmark @start import type=solution
-- !benchmark @end import
-- !benchmark @start solution_aux
-- !benchmark @end solution_aux
-- !benchmark @start precond_aux
-- !benchmark @end precond_aux
@[reducible, simp]
def onlineMax_precond (a : Array Int) (x : Nat) : Prop :=
-- !benchmark @start precond
a.size > 0 ∧ x < a.size
-- !benchmark @end precond
-- !benchmark @start code_aux
def findBest (a : Array Int) (x : Nat) (i : Nat) (best : Int) : Int :=
if i < x then
let newBest := if a[i]! > best then a[i]! else best
findBest a x (i + 1) newBest
else best
def findP (a : Array Int) (x : Nat) (m : Int) (i : Nat) : Nat :=
if i < a.size then
if a[i]! > m then i else findP a x m (i + 1)
else a.size - 1
-- !benchmark @end code_aux
def onlineMax (a : Array Int) (x : Nat) (h_precond : onlineMax_precond (a) (x)) : Int × Nat :=
-- !benchmark @start code
let best := a[0]!
let m := findBest a x 1 best;
let p := findP a x m x;
(m, p)
-- !benchmark @end code
-- !benchmark @start postcond_aux
-- !benchmark @end postcond_aux
@[reducible, simp]
def onlineMax_postcond (a : Array Int) (x : Nat) (result: Int × Nat) (h_precond : onlineMax_precond (a) (x)) :=
-- !benchmark @start postcond
let (m, p) := result;
(x ≤ p ∧ p < a.size) ∧
(∀ i, i < x → a[i]! ≤ m) ∧
(∃ i, i < x ∧ a[i]! = m) ∧
((p < a.size - 1) → (∀ i, i < p → a[i]! < a[p]!)) ∧
((∀ i, x ≤ i → i < a.size → a[i]! ≤ m) → p = a.size - 1)
-- !benchmark @end postcond
-- !benchmark @start proof_aux
-- !benchmark @end proof_aux
theorem onlineMax_spec_satisfied (a: Array Int) (x: Nat) (h_precond : onlineMax_precond (a) (x)) :
onlineMax_postcond (a) (x) (onlineMax (a) (x) h_precond) h_precond := by
-- !benchmark @start proof
sorry
-- !benchmark @end proof
| {
"name": "onlineMax",
"parameters": {
"param_name": [
"a",
"x"
],
"param_type": [
"Array Int",
"Nat"
]
},
"return_type": "Int × Nat"
} | {
"upstream": {
"name": "clover",
"link": "https://github.com/ChuyueSun/Clover",
"task_id": "Clover_online_max",
"student_id": null
}
} | {
"input": [
"{\"a\": \"#[3, 7, 5, 2, 9]\", \"x\": 3}",
"{\"a\": \"#[10, 10, 5, 1]\", \"x\": 2}",
"{\"a\": \"#[1, 3, 3, 3, 1]\", \"x\": 2}",
"{\"a\": \"#[5, 4, 4, 6, 2]\", \"x\": 2}",
"{\"a\": \"#[2, 8, 7, 7, 7]\", \"x\": 3}"
],
"expected": [
[
"(7, 4)"
],
[
"(10, 3)"
],
[
"(3, 4)"
],
[
"(5, 3)"
],
[
"(8, 4)"
]
],
"unexpected": [
[
"(7, 3)",
"(5, 4)"
],
[
"(10, 2)",
"(7, 3)"
],
[
"(2, 4)",
"(3, 3)"
],
[
"(4, 2)",
"(5, 2)",
"(6, 3)"
],
[
"(7, 4)",
"(8, 3)"
]
]
} | {
"input": [
"{'a': '#[]', 'x': 2}"
]
} | basic |
verina_basic_81 | -----Description-----
This task involves performing integer division with remainder on natural numbers. Given two natural numbers, x (the dividend) and y (the divisor), the objective is to determine the quotient and remainder. When y is non-zero, the quotient and remainder should satisfy the condition that the dividend equals the divisor multiplied by the quotient plus the remainder, with the remainder being nonnegative and strictly less than y. In the case where y is zero, the result should indicate that no division is performed by returning x as the quotient and 0 as the remainder.
-----Input-----
The input consists of two natural numbers:
• x: A natural number representing the dividend.
• y: A natural number representing the divisor.
-----Output-----
The output is a pair of integers (r, q) where:
• If y ≠ 0, then q is the quotient and r is the remainder such that:
- q * Int.ofNat y + r = Int.ofNat x
- 0 ≤ r < Int.ofNat y
- 0 ≤ q
• If y = 0, then the output is (Int.ofNat x, 0).
-----Note-----
The specification regarding the division properties applies only when y is non-zero. When y = 0, the function safely returns (x, 0) in its integer form. | -- !benchmark @start import type=solution
import Mathlib
-- !benchmark @end import
-- !benchmark @start solution_aux
-- !benchmark @end solution_aux
-- !benchmark @start precond_aux
-- !benchmark @end precond_aux
@[reducible, simp]
def DivisionFunction_precond (x : Nat) (y : Nat) : Prop :=
-- !benchmark @start precond
True
-- !benchmark @end precond
-- !benchmark @start code_aux
def divMod (x y : Nat) : Int × Int :=
let q : Int := Int.ofNat (x / y)
let r : Int := Int.ofNat (x % y)
(r, q)
-- !benchmark @end code_aux
def DivisionFunction (x : Nat) (y : Nat) (h_precond : DivisionFunction_precond (x) (y)) : Int × Int :=
-- !benchmark @start code
if y = 0 then (Int.ofNat x, 0) else divMod x y
-- !benchmark @end code
-- !benchmark @start postcond_aux
-- !benchmark @end postcond_aux
@[reducible, simp]
def DivisionFunction_postcond (x : Nat) (y : Nat) (result: Int × Int) (h_precond : DivisionFunction_precond (x) (y)) :=
-- !benchmark @start postcond
let (r, q) := result;
(y = 0 → r = Int.ofNat x ∧ q = 0) ∧
(y ≠ 0 → (q * Int.ofNat y + r = Int.ofNat x) ∧ (0 ≤ r ∧ r < Int.ofNat y) ∧ (0 ≤ q))
-- !benchmark @end postcond
-- !benchmark @start proof_aux
-- !benchmark @end proof_aux
theorem DivisionFunction_spec_satisfied (x: Nat) (y: Nat) (h_precond : DivisionFunction_precond (x) (y)) :
DivisionFunction_postcond (x) (y) (DivisionFunction (x) (y) h_precond) h_precond := by
-- !benchmark @start proof
unfold DivisionFunction_postcond DivisionFunction
simp
split
{
simp
intro h₁
contradiction
}
{
have h_left : (¬y = 0 →
(divMod x y).snd * ↑y + (divMod x y).fst = ↑x ∧
(0 ≤ (divMod x y).fst ∧ (divMod x y).fst < ↑y) ∧ 0 ≤ (divMod x y).snd) := by
intro h₁
have h₁_left : (divMod x y).snd * ↑y + (divMod x y).fst = ↑x := by
unfold divMod
simp
have h₁ := Int.ediv_add_emod' x y
apply h₁
have h₁_right : (0 ≤ (divMod x y).1 ∧ (divMod x y).1 < ↑y) ∧ 0 ≤ (divMod x y).2 := by
have h₂_left : (0 ≤ (divMod x y).1 ∧ (divMod x y).1 < ↑y) := by
have h₃_left : 0 ≤ (divMod x y).1 := by
unfold divMod
simp
rw [←Int.natCast_mod, ←Int.ofNat_eq_natCast]
have ha := Int.zero_le_ofNat (x % y)
apply ha
have h₃_right : (divMod x y).1 < ↑y := by
unfold divMod
simp
rw [←Int.natCast_mod]
have ha := @Int.natMod_lt x y h₁
rw [Int.natMod, ←Int.natCast_mod, Int.toNat_ofNat] at ha
rw [←Mathlib.Tactic.Zify.natCast_lt]
apply ha
exact ⟨h₃_left, h₃_right⟩
have h₂_right : 0 ≤ (divMod x y).2 := by
unfold divMod
simp
rw [←Int.natCast_div]
have ha := Int.natCast_nonneg (x / y)
apply ha
exact ⟨h₂_left, h₂_right⟩
exact ⟨h₁_left, h₁_right⟩
have h_right : (y = 0 → (divMod x y).fst = ↑x ∧ (divMod x y).snd = 0) := by
intro h₀
have h₁_left : (divMod x y).1 = ↑x := by
unfold divMod
simp
rw [←Int.natCast_mod, h₀, Nat.mod_zero]
have h₁_right : (divMod x y).snd = 0 := by
unfold divMod
simp
rw [←Int.natCast_div, h₀, Nat.div_zero, ←@Int.cast_id 0]
rfl
exact ⟨h₁_left, h₁_right⟩
constructor
· simp_all [h_left]
· simp_all [h_right]
}
-- !benchmark @end proof
| {
"name": "DivisionFunction",
"parameters": {
"param_name": [
"x",
"y"
],
"param_type": [
"Nat",
"Nat"
]
},
"return_type": "Int × Int"
} | {
"upstream": {
"name": "clover",
"link": "https://github.com/ChuyueSun/Clover",
"task_id": "Clover_quotient",
"student_id": null
}
} | {
"input": [
"{\"x\": 10, \"y\": 3}",
"{\"x\": 15, \"y\": 5}",
"{\"x\": 7, \"y\": 2}",
"{\"x\": 0, \"y\": 4}",
"{\"x\": 10, \"y\": 0}"
],
"expected": [
[
"(1, 3)"
],
[
"(0, 3)"
],
[
"(1, 3)"
],
[
"(0, 0)"
],
[
"(10, 0)"
]
],
"unexpected": [
[
"(2, 2)",
"(0, 3)",
"(1, 4)"
],
[
"(3, 0)",
"(1, 1)",
"(0, 4)"
],
[
"(3, 1)",
"(0, 7)",
"(1, 2)"
],
[
"(0, 1)",
"(1, 0)",
"(2, 0)"
],
[
"(0, 10)",
"(10, 1)",
"(5, 5)"
]
]
} | {
"input": []
} | basic |
verina_basic_51 | -----Description-----
This task requires creating a function that determines the correct insertion index for a given integer in a sorted array. The goal is to identify an index where every number before it is less than the specified value, and every number from that index onward is greater than or equal to the value. If the given integer is larger than all elements in the array, the function should return the array’s size.
-----Input-----
The input consists of:
• a: An array of integers that is assumed to be sorted in non-decreasing order.
• key: An integer to search for in the array.
-----Output-----
The output is a natural number (Nat) representing the index determined by the binary search. The index satisfies the following postconditions:
• It is between 0 and the size of the array.
• Every element before the returned index is less than the key.
• If the returned index equals the size of the array, then all elements are less than the key.
• Every element from the index onwards is greater than or equal to the key.
-----Note-----
It is assumed that the input array is sorted in non-decreasing order. The function returns the first index where the key could be inserted while maintaining the sorted order. | -- !benchmark @start import type=solution
-- !benchmark @end import
-- !benchmark @start solution_aux
-- !benchmark @end solution_aux
-- !benchmark @start precond_aux
-- !benchmark @end precond_aux
@[reducible, simp]
def BinarySearch_precond (a : Array Int) (key : Int) : Prop :=
-- !benchmark @start precond
List.Pairwise (· ≤ ·) a.toList
-- !benchmark @end precond
-- !benchmark @start code_aux
def binarySearchLoop (a : Array Int) (key : Int) (lo hi : Nat) : Nat :=
if lo < hi then
let mid := (lo + hi) / 2
if (a[mid]! < key) then binarySearchLoop a key (mid + 1) hi
else binarySearchLoop a key lo mid
else
lo
-- !benchmark @end code_aux
def BinarySearch (a : Array Int) (key : Int) (h_precond : BinarySearch_precond (a) (key)) : Nat :=
-- !benchmark @start code
binarySearchLoop a key 0 a.size
-- !benchmark @end code
-- !benchmark @start postcond_aux
-- !benchmark @end postcond_aux
@[reducible, simp]
def BinarySearch_postcond (a : Array Int) (key : Int) (result: Nat) (h_precond : BinarySearch_precond (a) (key)) :=
-- !benchmark @start postcond
result ≤ a.size ∧
((a.take result).all (fun x => x < key)) ∧
((a.drop result).all (fun x => x ≥ key))
-- !benchmark @end postcond
-- !benchmark @start proof_aux
-- !benchmark @end proof_aux
theorem BinarySearch_spec_satisfied (a: Array Int) (key: Int) (h_precond : BinarySearch_precond (a) (key)) :
BinarySearch_postcond (a) (key) (BinarySearch (a) (key) h_precond) h_precond := by
-- !benchmark @start proof
sorry
-- !benchmark @end proof
| {
"name": "BinarySearch",
"parameters": {
"param_name": [
"a",
"key"
],
"param_type": [
"Array Int",
"Int"
]
},
"return_type": "Nat"
} | {
"upstream": {
"name": "clover",
"link": "https://github.com/ChuyueSun/Clover",
"task_id": "Clover_binary_search",
"student_id": null
}
} | {
"input": [
"{\"a\": \"#[1, 3, 5, 7, 9]\", \"key\": 5}",
"{\"a\": \"#[1, 3, 5, 7, 9]\", \"key\": 6}",
"{\"a\": \"#[2, 4, 6, 8]\", \"key\": 1}",
"{\"a\": \"#[2, 4, 6, 8]\", \"key\": 10}",
"{\"a\": \"#[1, 1, 1, 1]\", \"key\": 1}"
],
"expected": [
[
"2"
],
[
"3"
],
[
"0"
],
[
"4"
],
[
"0"
]
],
"unexpected": [
[
"1",
"3",
"4"
],
[
"2",
"4",
"5"
],
[
"1",
"2",
"3"
],
[
"3",
"5",
"6"
],
[
"1",
"2",
"3"
]
]
} | {
"input": [
"{'a': '#[3, 2, 1]', 'key': 2}"
]
} | basic |
verina_basic_13 | -----Description-----
This task requires writing a Lean 4 method that transforms an array of integers by replacing every element with its cube. In other words, for each element in the input array, the output array should contain the result of multiplying that element by itself three times.
-----Input-----
The input consists of:
a: An array of integers (which may be empty or non-empty).
-----Output-----
The output is an array of integers:
Returns an array with the same length as the input, where each element is the cube of the corresponding element in the input array.
-----Note-----
There are no additional preconditions; the method should work correctly for any array of integers. | -- !benchmark @start import type=solution
-- !benchmark @end import
-- !benchmark @start solution_aux
-- !benchmark @end solution_aux
-- !benchmark @start precond_aux
-- !benchmark @end precond_aux
@[reducible, simp]
def cubeElements_precond (a : Array Int) : Prop :=
-- !benchmark @start precond
True
-- !benchmark @end precond
-- !benchmark @start code_aux
-- !benchmark @end code_aux
def cubeElements (a : Array Int) (h_precond : cubeElements_precond (a)) : Array Int :=
-- !benchmark @start code
a.map (fun x => x * x * x)
-- !benchmark @end code
-- !benchmark @start postcond_aux
-- !benchmark @end postcond_aux
@[reducible, simp]
def cubeElements_postcond (a : Array Int) (result: Array Int) (h_precond : cubeElements_precond (a)) :=
-- !benchmark @start postcond
(result.size = a.size) ∧
(∀ i, i < a.size → result[i]! = a[i]! * a[i]! * a[i]!)
-- !benchmark @end postcond
-- !benchmark @start proof_aux
-- !benchmark @end proof_aux
theorem cubeElements_spec_satisfied (a: Array Int) (h_precond : cubeElements_precond (a)) :
cubeElements_postcond (a) (cubeElements (a) h_precond) h_precond := by
-- !benchmark @start proof
unfold cubeElements cubeElements_postcond
simp_all
intro i hi
have h_maplen : (Array.map (fun x => x * x * x) a).size = a.size := by
apply Array.size_map
have h1 : (Array.map (fun x => x * x * x) a)[i] = (fun x => x * x * x) a[i] := by
apply Array.getElem_map
have h_eq : (Array.map (fun x => x * x * x) a)[i] = (Array.map (fun x => x * x * x) a)[i]! := by
have hi' : i < (Array.map (fun x => x * x * x) a).size := by
simp only [hi, h_maplen]
rw [Array.getElem!_eq_getD]
simp [hi', hi]
rw [← h_eq]
simp only [h1]
have h_eq' : a[i] = a[i]! := by
have hi_a : i < a.size := by
simp only [hi]
rw [Array.getElem!_eq_getD]
simp [hi_a]
simp only [h_eq']
-- !benchmark @end proof
| {
"name": "cubeElements",
"parameters": {
"param_name": [
"a"
],
"param_type": [
"Array Int"
]
},
"return_type": "Array Int"
} | {
"upstream": {
"name": "dafny-synthesis",
"link": "https://github.com/Mondego/dafny-synthesis",
"task_id": "task_id_447",
"student_id": null
}
} | {
"input": [
"{\"a\": \"#[1, 2, 3, 4]\"}",
"{\"a\": \"#[0, -1, -2, 3]\"}",
"{\"a\": \"#[]\"}",
"{\"a\": \"#[5]\"}",
"{\"a\": \"#[-3, -3]\"}"
],
"expected": [
[
"#[1, 8, 27, 64]"
],
[
"#[0, -1, -8, 27]"
],
[
"#[]"
],
[
"#[125]"
],
[
"#[-27, -27]"
]
],
"unexpected": [
[
"#[1, 4, 9, 16]",
"#[1, 8, 27, 63]",
"#[0, 0, 0, 0]"
],
[
"#[0, 1, 8, -27]",
"#[0, -1, -8, 26]",
"#[1, -1, -8, 27]"
],
[
"#[1]",
"#[-1]",
"#[0]"
],
[
"#[5]",
"#[25]",
"#[0]"
],
[
"#[27, 27]",
"#[-9, -9]",
"#[-27, 27]"
]
]
} | {
"input": []
} | basic |
verina_basic_87 | -----Description-----
This problem requires sorting an array of integers into non-decreasing order, ensuring that the output contains exactly the same elements as the input (i.e., it is a permutation of the original array).
-----Input-----
The input consists of:
• a: An array of integers (Array Int).
-----Output-----
The output is an array of integers that is:
• Sorted in non-decreasing order.
• A permutation of the input, meaning it contains exactly the same elements (with the same multiplicities) as the original array.
-----Note-----
It is assumed that the input array is valid and that the swap operations, along with the helper functions, correctly implement the selection sort algorithm. | -- !benchmark @start import type=solution
-- !benchmark @end import
-- !benchmark @start solution_aux
-- !benchmark @end solution_aux
-- !benchmark @start precond_aux
-- !benchmark @end precond_aux
@[reducible, simp]
def SelectionSort_precond (a : Array Int) : Prop :=
-- !benchmark @start precond
True
-- !benchmark @end precond
-- !benchmark @start code_aux
def findMinIndexInRange (arr : Array Int) (start finish : Nat) : Nat :=
let indices := List.range (finish - start)
indices.foldl (fun minIdx i =>
let currIdx := start + i
if arr[currIdx]! < arr[minIdx]! then currIdx else minIdx
) start
def swap (a : Array Int) (i j : Nat) : Array Int :=
if i < a.size && j < a.size && i ≠ j then
let temp := a[i]!
let a' := a.set! i a[j]!
a'.set! j temp
else a
-- !benchmark @end code_aux
def SelectionSort (a : Array Int) (h_precond : SelectionSort_precond (a)) : Array Int :=
-- !benchmark @start code
let indices := List.range a.size
indices.foldl (fun arr i =>
let minIdx := findMinIndexInRange arr i a.size
swap arr i minIdx
) a
-- !benchmark @end code
-- !benchmark @start postcond_aux
-- !benchmark @end postcond_aux
@[reducible, simp]
def SelectionSort_postcond (a : Array Int) (result: Array Int) (h_precond : SelectionSort_precond (a)) :=
-- !benchmark @start postcond
List.Pairwise (· ≤ ·) result.toList ∧ List.isPerm a.toList result.toList
-- !benchmark @end postcond
-- !benchmark @start proof_aux
-- !benchmark @end proof_aux
theorem SelectionSort_spec_satisfied (a: Array Int) (h_precond : SelectionSort_precond (a)) :
SelectionSort_postcond (a) (SelectionSort (a) h_precond) h_precond := by
-- !benchmark @start proof
sorry
-- !benchmark @end proof
| {
"name": "SelectionSort",
"parameters": {
"param_name": [
"a"
],
"param_type": [
"Array Int"
]
},
"return_type": "Array Int"
} | {
"upstream": {
"name": "clover",
"link": "https://github.com/ChuyueSun/Clover",
"task_id": "Clover_selectionsort",
"student_id": null
}
} | {
"input": [
"{\"a\": \"#[3, 1, 2]\"}",
"{\"a\": \"#[0]\"}",
"{\"a\": \"#[5, 4, 3, 2, 1]\"}",
"{\"a\": \"#[2, 2, 1, 4]\"}",
"{\"a\": \"#[10, -5, 0, 3]\"}"
],
"expected": [
[
"#[1, 2, 3]"
],
[
"#[0]"
],
[
"#[1, 2, 3, 4, 5]"
],
[
"#[1, 2, 2, 4]"
],
[
"#[-5, 0, 3, 10]"
]
],
"unexpected": [
[
"#[3, 1, 2]",
"#[2, 3, 1]"
],
[
"#[0, 0]",
"#[1]"
],
[
"#[5, 4, 3, 2, 1]",
"#[1, 5, 4, 3, 2]",
"#[1, 2, 4, 3, 5]"
],
[
"#[2, 1, 2, 4]",
"#[1, 2, 4, 2]"
],
[
"#[10, -5, 3, 0]",
"#[0, -5, 3, 10]",
"#[3, -5, 10, 0]"
]
]
} | {
"input": []
} | basic |
verina_basic_83 | -----Description-----
This task involves concatenating two arrays of integers by appending the second array to the end of the first array. The goal is to produce a new array that sequentially contains all elements from the first array followed by all elements from the second array.
-----Input-----
The input consists of two parameters:
• a: An Array of integers representing the first part of the concatenated array.
• b: An Array of integers representing the second part of the concatenated array.
-----Output-----
The output is an Array of integers that satisfies the following:
• The length of the output array is equal to the sum of the lengths of arrays a and b.
• The first part of the output array (indices 0 to a.size - 1) is identical to array a.
• The remaining part of the output array (indices a.size to a.size + b.size - 1) is identical to array b.
-----Note-----
No additional preconditions are required since the function uses the sizes of the input arrays to build the resulting array. | -- !benchmark @start import type=solution
-- !benchmark @end import
-- !benchmark @start solution_aux
-- !benchmark @end solution_aux
-- !benchmark @start precond_aux
-- !benchmark @end precond_aux
@[reducible, simp]
def concat_precond (a : Array Int) (b : Array Int) : Prop :=
-- !benchmark @start precond
True
-- !benchmark @end precond
-- !benchmark @start code_aux
-- !benchmark @end code_aux
def concat (a : Array Int) (b : Array Int) (h_precond : concat_precond (a) (b)) : Array Int :=
-- !benchmark @start code
let n := a.size + b.size
let rec loop (i : Nat) (c : Array Int) : Array Int :=
if i < n then
let value := if i < a.size then a[i]! else b[i - a.size]!
loop (i + 1) (c.set! i value)
else
c
loop 0 (Array.mkArray n 0)
-- !benchmark @end code
-- !benchmark @start postcond_aux
-- !benchmark @end postcond_aux
@[reducible, simp]
def concat_postcond (a : Array Int) (b : Array Int) (result: Array Int) (h_precond : concat_precond (a) (b)) :=
-- !benchmark @start postcond
result.size = a.size + b.size
∧ (∀ k, k < a.size → result[k]! = a[k]!)
∧ (∀ k, k < b.size → result[k + a.size]! = b[k]!)
-- !benchmark @end postcond
-- !benchmark @start proof_aux
-- !benchmark @end proof_aux
theorem concat_spec_satisfied (a: Array Int) (b: Array Int) (h_precond : concat_precond (a) (b)) :
concat_postcond (a) (b) (concat (a) (b) h_precond) h_precond := by
-- !benchmark @start proof
sorry
-- !benchmark @end proof
| {
"name": "concat",
"parameters": {
"param_name": [
"a",
"b"
],
"param_type": [
"Array Int",
"Array Int"
]
},
"return_type": "Array Int"
} | {
"upstream": {
"name": "clover",
"link": "https://github.com/ChuyueSun/Clover",
"task_id": "Clover_array_concat",
"student_id": null
}
} | {
"input": [
"{\"a\": \"#[1, 2, 3]\", \"b\": \"#[4, 5]\"}",
"{\"a\": \"#[]\", \"b\": \"#[]\"}",
"{\"a\": \"#[10]\", \"b\": \"#[20, 30, 40]\"}",
"{\"a\": \"#[-1, -2]\", \"b\": \"#[0]\"}",
"{\"a\": \"#[7, 8, 9]\", \"b\": \"#[]\"}"
],
"expected": [
[
"#[1, 2, 3, 4, 5]"
],
[
"#[]"
],
[
"#[10, 20, 30, 40]"
],
[
"#[-1, -2, 0]"
],
[
"#[7, 8, 9]"
]
],
"unexpected": [
[
"#[1, 2, 3, 5, 4]",
"#[4, 5, 1, 2, 3]",
"#[1, 2, 4, 3, 5]"
],
[
"#[1]",
"#[1, 2]"
],
[
"#[10, 20, 30]",
"#[20, 30, 40, 10]"
],
[
"#[-1, 0, -2]",
"#[0, -1, -2]"
],
[
"#[7, 8]",
"#[8, 9]",
"#[]"
]
]
} | {
"input": []
} | basic |
verina_advanced_43 | ------Description-----
This task requires writing a Lean 4 method that given a 0-indexed integer array `nums` representing the scores of students in an exam. A teacher wants to select a non empty group of students such that the strength of group is maximized.
The strength of a group is defined as the product of the selected student scores.
You can choose any non-empty subset of students. The goal is to compute the maximum product of any such subset.
----Input---
nums: An non-empty list of integers.
-----Output-----
An integer representing the maximum strength.
| -- !benchmark @start import type=solution
import Mathlib
-- !benchmark @end import
-- !benchmark @start solution_aux
-- !benchmark @end solution_aux
-- !benchmark @start precond_aux
-- !benchmark @end precond_aux
@[reducible]
def maxStrength_precond (nums : List Int) : Prop :=
-- !benchmark @start precond
nums ≠ []
-- !benchmark @end precond
-- !benchmark @start code_aux
-- !benchmark @end code_aux
def maxStrength (nums : List Int) (h_precond : maxStrength_precond (nums)) : Int :=
-- !benchmark @start code
let powerSet := fun (l : List Int) =>
let n := l.length
let masks := List.range (2^n)
masks.map fun mask =>
(List.range n).foldr (fun i acc =>
if (mask.shiftRight i).land 1 == 1 then l[i]! :: acc else acc
) []
let subsets := powerSet nums
let nonEmpty := subsets.filter (· ≠ [])
let products := List.map (fun subset =>
List.foldl (fun acc x =>
acc * x) (1 : Int) subset)
nonEmpty
(List.max? products).getD (-1000000)
-- !benchmark @end code
-- !benchmark @start postcond_aux
-- !benchmark @end postcond_aux
@[reducible]
def maxStrength_postcond (nums : List Int) (result: Int) (h_precond : maxStrength_precond (nums)) : Prop :=
-- !benchmark @start postcond
let sublists := nums.sublists.filter (· ≠ [])
let products := sublists.map (List.foldl (· * ·) 1)
products.contains result ∧ products.all (· ≤ result)
-- !benchmark @end postcond
-- !benchmark @start proof_aux
-- !benchmark @end proof_aux
theorem maxStrength_spec_satisfied (nums: List Int) (h_precond : maxStrength_precond (nums)) :
maxStrength_postcond (nums) (maxStrength (nums) h_precond) h_precond := by
-- !benchmark @start proof
sorry
-- !benchmark @end proof
| {
"name": "maxStrength",
"parameters": {
"param_name": [
"nums"
],
"param_type": [
"List Int"
]
},
"return_type": "Int"
} | {
"upstream": {
"name": "lab_assignment",
"link": "Livecodebench has problem, but couldn't find that link so using leetcode: https://leetcode.com/problems/maximum-product-subarray/description/",
"task_id": "lab_maxStrength_324857110",
"student_id": [
35
]
}
} | {
"input": [
"{\"nums\": \"[-2]\"}",
"{\"nums\": \"[3, -1, -5, 2, 5, -9]\"}",
"{\"nums\": \"[-4, -5, -4]\"}",
"{\"nums\": \"[0, -3, 4]\"}",
"{\"nums\": \"[1, -1, -1]\"}"
],
"expected": [
[
"-2"
],
[
"1350"
],
[
"20"
],
[
"4"
],
[
"1"
]
],
"unexpected": [
[
"2",
"0"
],
[
"270",
"0",
"-1"
],
[
"80",
"-80",
"-5"
],
[
"0",
"-12"
],
[
"-1",
"-2"
]
]
} | {
"input": [
"{'nums': '[]'}"
]
} | advanced |
verina_basic_105 | -----Description-----
This task involves computing the element-wise product of two integer arrays. For each position in the arrays, the corresponding numbers are multiplied together. If an element is missing in one of the arrays at a given index, the missing value is treated as 0. When both arrays provide values for every index, the resulting array will contain the product of the two numbers at each corresponding index.
-----Input-----
The input consists of two arrays:
• a: An array of integers.
• b: An array of integers (should be of equal length to a for the specification to hold).
-----Output-----
The output is an array of integers that:
• Has the same length as the input arrays.
• For each index i, the output array contains the product a[i] * b[i].
• In cases where one of the arrays might be shorter, missing elements default to 0 during multiplication.
-----Note-----
It is assumed that the arrays are of equal length for the theorem specification, although the implementation defaults missing indices to 0. | -- !benchmark @start import type=solution
-- !benchmark @end import
-- !benchmark @start solution_aux
-- !benchmark @end solution_aux
-- !benchmark @start precond_aux
-- !benchmark @end precond_aux
@[reducible, simp]
def arrayProduct_precond (a : Array Int) (b : Array Int) : Prop :=
-- !benchmark @start precond
a.size = b.size
-- !benchmark @end precond
-- !benchmark @start code_aux
def loop (a b : Array Int) (len : Nat) : Nat → Array Int → Array Int
| i, c =>
if i < len then
let a_val := if i < a.size then a[i]! else 0
let b_val := if i < b.size then b[i]! else 0
let new_c := Array.set! c i (a_val * b_val)
loop a b len (i+1) new_c
else c
-- !benchmark @end code_aux
def arrayProduct (a : Array Int) (b : Array Int) (h_precond : arrayProduct_precond (a) (b)) : Array Int :=
-- !benchmark @start code
let len := a.size
let c := Array.mkArray len 0
loop a b len 0 c
-- !benchmark @end code
-- !benchmark @start postcond_aux
-- !benchmark @end postcond_aux
@[reducible, simp]
def arrayProduct_postcond (a : Array Int) (b : Array Int) (result: Array Int) (h_precond : arrayProduct_precond (a) (b)) :=
-- !benchmark @start postcond
(result.size = a.size) ∧ (∀ i, i < a.size → a[i]! * b[i]! = result[i]!)
-- !benchmark @end postcond
-- !benchmark @start proof_aux
-- !benchmark @end proof_aux
theorem arrayProduct_spec_satisfied (a: Array Int) (b: Array Int) (h_precond : arrayProduct_precond (a) (b)) :
arrayProduct_postcond (a) (b) (arrayProduct (a) (b) h_precond) h_precond := by
-- !benchmark @start proof
sorry
-- !benchmark @end proof
| {
"name": "arrayProduct",
"parameters": {
"param_name": [
"a",
"b"
],
"param_type": [
"Array Int",
"Array Int"
]
},
"return_type": "Array Int"
} | {
"upstream": {
"name": "clover",
"link": "https://github.com/ChuyueSun/Clover",
"task_id": "Clover_array_product",
"student_id": null
}
} | {
"input": [
"{\"a\": \"#[1, 2, 3]\", \"b\": \"#[4, 5, 6]\"}",
"{\"a\": \"#[0, 0, 0]\", \"b\": \"#[1, 2, 3]\"}",
"{\"a\": \"#[-1, 2, -3]\", \"b\": \"#[3, -4, 5]\"}",
"{\"a\": \"#[2]\", \"b\": \"#[10]\"}",
"{\"a\": \"#[1, 2, 3, 4]\", \"b\": \"#[2, 2, 2, 2]\"}"
],
"expected": [
[
"#[4, 10, 18]"
],
[
"#[0, 0, 0]"
],
[
"#[-3, -8, -15]"
],
[
"#[20]"
],
[
"#[2, 4, 6, 8]"
]
],
"unexpected": [
[
"#[4, 10, 17]",
"#[0, 10, 18]",
"#[4, 10, 20]"
],
[
"#[1, 0, 0]",
"#[0, 1, 0]",
"#[0, 0, 1]"
],
[
"#[-3, -8, -14]",
"#[-3, -7, -15]",
"#[-2, -8, -15]"
],
[
"#[10]",
"#[0]",
"#[30]"
],
[
"#[2, 4, 6, 9]",
"#[1, 4, 6, 8]",
"#[2, 5, 6, 8]"
]
]
} | {
"input": [
"{'a': '#[1, 2, 3]', 'b': '#[4, 5]'}"
]
} | basic |
verina_basic_42 | -----Description-----
This task requires writing a Lean 4 method that counts the number of digit characters within a given string. A digit is any character between '0' and '9'. The method should determine how many such digit characters appear in the input.
-----Input-----
The input consists of:
s: A string.
-----Output-----
The output is a natural number (Nat):
Returns a non-negative count representing the number of digit characters found in the input string.
-----Note-----
There are no additional preconditions; the method works for any provided string. | -- !benchmark @start import type=solution
-- !benchmark @end import
-- !benchmark @start solution_aux
def isDigit (c : Char) : Bool :=
'0' ≤ c ∧ c ≤ '9'
-- !benchmark @end solution_aux
-- !benchmark @start precond_aux
-- !benchmark @end precond_aux
@[reducible, simp]
def countDigits_precond (s : String) : Prop :=
-- !benchmark @start precond
True
-- !benchmark @end precond
-- !benchmark @start code_aux
-- !benchmark @end code_aux
def countDigits (s : String) (h_precond : countDigits_precond (s)) : Nat :=
-- !benchmark @start code
List.length (List.filter isDigit s.toList)
-- !benchmark @end code
-- !benchmark @start postcond_aux
-- !benchmark @end postcond_aux
@[reducible, simp]
def countDigits_postcond (s : String) (result: Nat) (h_precond : countDigits_precond (s)) :=
-- !benchmark @start postcond
result - List.length (List.filter isDigit s.toList) = 0 ∧
List.length (List.filter isDigit s.toList) - result = 0
-- !benchmark @end postcond
-- !benchmark @start proof_aux
-- !benchmark @end proof_aux
theorem countDigits_spec_satisfied (s: String) (h_precond : countDigits_precond (s)) :
countDigits_postcond (s) (countDigits (s) h_precond) h_precond := by
-- !benchmark @start proof
unfold countDigits countDigits_postcond
simp
-- !benchmark @end proof
| {
"name": "countDigits",
"parameters": {
"param_name": [
"s"
],
"param_type": [
"String"
]
},
"return_type": "Nat"
} | {
"upstream": {
"name": "dafny-synthesis",
"link": "https://github.com/Mondego/dafny-synthesis",
"task_id": "task_id_764",
"student_id": null
}
} | {
"input": [
"{\"s\": \"123abc456\"}",
"{\"s\": \"no digits here!\"}",
"{\"s\": \"1234567890\"}",
"{\"s\": \"\"}",
"{\"s\": \"a1b2c3\"}",
"{\"s\": \"0\"}",
"{\"s\": \"abc\"}"
],
"expected": [
[
"6"
],
[
"0"
],
[
"10"
],
[
"0"
],
[
"3"
],
[
"1"
],
[
"0"
]
],
"unexpected": [
[
"5",
"7",
"0"
],
[
"1",
"2",
"3"
],
[
"9",
"11",
"0"
],
[
"1",
"2",
"10"
],
[
"2",
"4",
"5"
],
[
"0",
"2",
"10"
],
[
"1",
"8",
"9"
]
]
} | {
"input": []
} | basic |
verina_advanced_47 | -----Description-----
This task requires writing a Lean 4 method that merges all overlapping intervals from a given list of intervals.
Each interval is represented as a pair [start, end], indicating the start and end of the interval. If two intervals overlap, they should be merged into a single interval that spans from the minimum start to the maximum end of the overlapping intervals.
The goal is to return a list of non-overlapping intervals that cover all the input intervals after merging.
-----Input-----
The input consists of one array:
intervals: An array of pairs of integers where intervals[i] = [startᵢ, endᵢ] represents the start and end of the ith interval.
-----Output-----
The output is an array of pairs of integers:
Returns the list of merged, non-overlapping intervals sorted by their start times.
| -- !benchmark @start import type=solution
-- !benchmark @end import
-- !benchmark @start solution_aux
-- !benchmark @end solution_aux
-- !benchmark @start precond_aux
-- !benchmark @end precond_aux
@[reducible, simp]
def mergeIntervals_precond (intervals : List (Prod Int Int)) : Prop :=
-- !benchmark @start precond
True
-- !benchmark @end precond
-- !benchmark @start code_aux
-- !benchmark @end code_aux
def mergeIntervals (intervals : List (Prod Int Int)) (h_precond : mergeIntervals_precond (intervals)) : List (Prod Int Int) :=
-- !benchmark @start code
-- Insertion sort based on the start of intervals
let rec insert (x : Prod Int Int) (sorted : List (Prod Int Int)) : List (Prod Int Int) :=
match sorted with
| [] => [x]
| y :: ys => if x.fst ≤ y.fst then x :: sorted else y :: insert x ys
let rec sort (xs : List (Prod Int Int)) : List (Prod Int Int) :=
match xs with
| [] => []
| x :: xs' => insert x (sort xs')
let sorted := sort intervals
-- Merge sorted intervals
let rec merge (xs : List (Prod Int Int)) (acc : List (Prod Int Int)) : List (Prod Int Int) :=
match xs, acc with
| [], _ => acc.reverse
| (s, e) :: rest, [] => merge rest [(s, e)]
| (s, e) :: rest, (ps, pe) :: accTail =>
if s ≤ pe then
merge rest ((ps, max pe e) :: accTail)
else
merge rest ((s, e) :: (ps, pe) :: accTail)
merge sorted []
-- !benchmark @end code
-- !benchmark @start postcond_aux
-- !benchmark @end postcond_aux
@[reducible, simp]
def mergeIntervals_postcond (intervals : List (Prod Int Int)) (result: List (Prod Int Int)) (h_precond : mergeIntervals_precond (intervals)) : Prop :=
-- !benchmark @start postcond
-- Check that all original intervals are covered by some result interval
let covered := intervals.all (fun (s, e) =>
result.any (fun (rs, re) => rs ≤ s ∧ e ≤ re))
-- Check that no intervals in the result overlap
let rec noOverlap (l : List (Prod Int Int)) : Bool :=
match l with
| [] | [_] => true
| (_, e1) :: (s2, e2) :: rest => e1 < s2 && noOverlap ((s2, e2) :: rest)
covered ∧ noOverlap result
-- !benchmark @end postcond
-- !benchmark @start proof_aux
-- !benchmark @end proof_aux
theorem mergeIntervals_spec_satisfied (intervals: List (Prod Int Int)) (h_precond : mergeIntervals_precond (intervals)) :
mergeIntervals_postcond (intervals) (mergeIntervals (intervals) h_precond) h_precond := by
-- !benchmark @start proof
sorry
-- !benchmark @end proof
| {
"name": "mergeIntervals",
"parameters": {
"param_name": [
"intervals"
],
"param_type": [
"List (Prod Int Int)"
]
},
"return_type": "List (Prod Int Int)"
} | {
"upstream": {
"name": "lab_assignment",
"link": "[{\"text_file_id\"=>804740898}]",
"task_id": "lab_mergeIntervals_325627981",
"student_id": [
6
]
}
} | {
"input": [
"{\"intervals\": \"[(1, 3), (2, 6), (8, 10), (15, 18)]\"}",
"{\"intervals\": \"[(1, 4), (4, 5)]\"}",
"{\"intervals\": \"[(1, 10), (2, 3), (4, 5)]\"}",
"{\"intervals\": \"[(1, 2), (3, 4), (5, 6)]\"}",
"{\"intervals\": \"[(5, 6), (1, 3), (2, 4)]\"}"
],
"expected": [
[
"[(1, 6), (8, 10), (15, 18)]"
],
[
"[(1, 5)]"
],
[
"[(1, 10)]"
],
[
"[(1, 2), (3, 4), (5, 6)]"
],
[
"[(1, 4), (5, 6)]"
]
],
"unexpected": [
[
"[(1, 3), (2, 6), (15, 19)]"
],
[
"[(1, 4), (4, 5), (1, 6)]"
],
[
"[(2, 3), (4, 5), (1, 5)]"
],
[
"[(1, 4), (5, 6), (1, 6)]"
],
[
"[(1, 3), (2, 4), (1, 6)]"
]
]
} | {
"input": []
} | advanced |
verina_advanced_70 | -----Description---
This task requires writing a Lean 4 method that's goal is to determine the minimum number of adjacent swaps needed to make the array semi-ordered. You may repeatedly swap 2 adjacent elements in the array. A permutation is called semi-ordered if the first number equals 1 and the last number equals n.
-----Input-----
The input consists of:
- nums: A list of integeris.
----Output-----
The output is an integer.
| -- !benchmark @start import type=solution
-- !benchmark @end import
-- !benchmark @start solution_aux
-- !benchmark @end solution_aux
-- !benchmark @start precond_aux
-- !benchmark @end precond_aux
@[reducible]
def semiOrderedPermutation_precond (nums : List Int) : Prop :=
-- !benchmark @start precond
True
-- !benchmark @end precond
-- !benchmark @start code_aux
-- !benchmark @end code_aux
def semiOrderedPermutation (nums : List Int) (h_precond : semiOrderedPermutation_precond (nums)) : Int :=
-- !benchmark @start code
let lengthList := nums.length
let numOne : Int := 1
let largestNum : Int := Int.ofNat lengthList
let firstIndex := nums.idxOf numOne
let lastIndex := nums.idxOf largestNum
let startPosition := 0
let endPosition := lengthList - 1
let shouldMoveOne := firstIndex != startPosition
let shouldMoveLast := lastIndex != endPosition
let distanceOne := if shouldMoveOne then firstIndex else 0
let distanceLast := if shouldMoveLast then endPosition - lastIndex else 0
let totalMoves := distanceOne + distanceLast
let needAdjustment := firstIndex > lastIndex
let adjustedMoves := if needAdjustment then totalMoves - 1 else totalMoves
adjustedMoves
-- !benchmark @end code
-- !benchmark @start postcond_aux
-- !benchmark @end postcond_aux
@[reducible]
def semiOrderedPermutation_postcond (nums : List Int) (result: Int) (h_precond : semiOrderedPermutation_precond (nums)) : Prop :=
-- !benchmark @start postcond
let n := nums.length
let pos1 := nums.idxOf 1
let posn := nums.idxOf (Int.ofNat n)
if pos1 > posn then
pos1 + n = result + 2 + posn
else
pos1 + n = result + 1 + posn
-- !benchmark @end postcond
-- !benchmark @start proof_aux
-- !benchmark @end proof_aux
theorem semiOrderedPermutation_spec_satisfied (nums: List Int) (h_precond : semiOrderedPermutation_precond (nums)) :
semiOrderedPermutation_postcond (nums) (semiOrderedPermutation (nums) h_precond) h_precond := by
-- !benchmark @start proof
sorry
-- !benchmark @end proof
| {
"name": "semiOrderedPermutation",
"parameters": {
"param_name": [
"nums"
],
"param_type": [
"List Int"
]
},
"return_type": "Int"
} | {
"upstream": {
"name": "lab_assignment",
"link": "Found on livecodebench, but similar problem on leetcode: https://leetcode.com/problems/minimum-adjacent-swaps-to-make-a-valid-array/description/",
"task_id": "lab_semiOrderedPermutation_324857110",
"student_id": [
35
]
}
} | {
"input": [
"{\"nums\": \"[2, 1, 4, 3]\"}",
"{\"nums\": \"[2, 4, 1, 3]\"}",
"{\"nums\": \"[1, 3, 4, 2, 5]\"}",
"{\"nums\": \"[3, 1, 2]\"}",
"{\"nums\": \"[2, 3, 1, 5, 4]\"}"
],
"expected": [
[
"2"
],
[
"3"
],
[
"0"
],
[
"2"
],
[
"3"
]
],
"unexpected": [
[
"0",
"1",
"3"
],
[
"2",
"4"
],
[
"1",
"2"
],
[
"0",
"1"
],
[
"4",
"5"
]
]
} | {
"input": []
} | advanced |
verina_basic_18 | -----Description-----
This task requires writing a Lean 4 method that computes the sum of the digits of a non-negative integer. The method should process each digit of the input number and return the total sum. The output is guaranteed to be a non-negative natural number.
-----Input-----
The input consists of:
n: A non-negative integer.
-----Output-----
The output is a natural number:
Returns the sum of the digits of the input integer.
-----Note-----
The input is assumed to be a valid non-negative integer. | -- !benchmark @start import type=solution
-- !benchmark @end import
-- !benchmark @start solution_aux
-- !benchmark @end solution_aux
-- !benchmark @start precond_aux
-- !benchmark @end precond_aux
@[reducible, simp]
def sumOfDigits_precond (n : Nat) : Prop :=
-- !benchmark @start precond
True
-- !benchmark @end precond
-- !benchmark @start code_aux
-- !benchmark @end code_aux
def sumOfDigits (n : Nat) (h_precond : sumOfDigits_precond (n)) : Nat :=
-- !benchmark @start code
let rec loop (n : Nat) (acc : Nat) : Nat :=
if n = 0 then acc
else loop (n / 10) (acc + n % 10)
loop n 0
-- !benchmark @end code
-- !benchmark @start postcond_aux
-- !benchmark @end postcond_aux
@[reducible, simp]
def sumOfDigits_postcond (n : Nat) (result: Nat) (h_precond : sumOfDigits_precond (n)) :=
-- !benchmark @start postcond
result - List.sum (List.map (fun c => Char.toNat c - Char.toNat '0') (String.toList (Nat.repr n))) = 0 ∧
List.sum (List.map (fun c => Char.toNat c - Char.toNat '0') (String.toList (Nat.repr n))) - result = 0
-- !benchmark @end postcond
-- !benchmark @start proof_aux
-- !benchmark @end proof_aux
theorem sumOfDigits_spec_satisfied (n: Nat) (h_precond : sumOfDigits_precond (n)) :
sumOfDigits_postcond (n) (sumOfDigits (n) h_precond) h_precond := by
-- !benchmark @start proof
sorry
-- !benchmark @end proof
| {
"name": "sumOfDigits",
"parameters": {
"param_name": [
"n"
],
"param_type": [
"Nat"
]
},
"return_type": "Nat"
} | {
"upstream": {
"name": "dafny-synthesis",
"link": "https://github.com/Mondego/dafny-synthesis",
"task_id": "task_id_566",
"student_id": null
}
} | {
"input": [
"{\"n\": 12345}",
"{\"n\": 0}",
"{\"n\": 987654321}",
"{\"n\": 11111}",
"{\"n\": 1001}",
"{\"n\": 9999}"
],
"expected": [
[
"15"
],
[
"0"
],
[
"45"
],
[
"5"
],
[
"2"
],
[
"36"
]
],
"unexpected": [
[
"12",
"16",
"14"
],
[
"1",
"10",
"5"
],
[
"44",
"46",
"50"
],
[
"6",
"4",
"7"
],
[
"1",
"3",
"11"
],
[
"35",
"37",
"34"
]
]
} | {
"input": []
} | basic |
verina_basic_10 | -----Description-----
This task requires writing a Lean 4 method that determines if a given integer is strictly greater than every element in a provided array. The method should return true only if the integer is larger than each element in the array; otherwise, it should return false.
-----Input-----
The input consists of:
n: An integer.
a: An array of integers.
-----Output-----
The output is a Boolean value:
Returns true if the integer is greater than all elements in the array.
Returns false if there is at least one element in the array that is greater than or equal to the integer.
-----Note-----
The array is assumed to be non-null. | -- !benchmark @start import type=solution
-- !benchmark @end import
-- !benchmark @start solution_aux
-- !benchmark @end solution_aux
-- !benchmark @start precond_aux
-- !benchmark @end precond_aux
@[reducible, simp]
def isGreater_precond (n : Int) (a : Array Int) : Prop :=
-- !benchmark @start precond
a.size > 0
-- !benchmark @end precond
-- !benchmark @start code_aux
-- !benchmark @end code_aux
def isGreater (n : Int) (a : Array Int) (h_precond : isGreater_precond (n) (a)) : Bool :=
-- !benchmark @start code
a.all fun x => n > x
-- !benchmark @end code
-- !benchmark @start postcond_aux
-- !benchmark @end postcond_aux
@[reducible, simp]
def isGreater_postcond (n : Int) (a : Array Int) (result: Bool) (h_precond : isGreater_precond (n) (a)) :=
-- !benchmark @start postcond
(∀ i, (hi : i < a.size) → n > a[i]) ↔ result
-- !benchmark @end postcond
-- !benchmark @start proof_aux
-- !benchmark @end proof_aux
theorem isGreater_spec_satisfied (n: Int) (a: Array Int) (h_precond : isGreater_precond (n) (a)) :
isGreater_postcond (n) (a) (isGreater (n) (a) h_precond) h_precond := by
-- !benchmark @start proof
unfold isGreater isGreater_postcond
simp [Array.all_eq]
-- !benchmark @end proof
| {
"name": "isGreater",
"parameters": {
"param_name": [
"n",
"a"
],
"param_type": [
"Int",
"Array Int"
]
},
"return_type": "Bool"
} | {
"upstream": {
"name": "dafny-synthesis",
"link": "https://github.com/Mondego/dafny-synthesis",
"task_id": "task_id_433",
"student_id": null
}
} | {
"input": [
"{\"n\": 6, \"a\": \"#[1, 2, 3, 4, 5]\"}",
"{\"n\": 3, \"a\": \"#[1, 2, 3, 4, 5]\"}",
"{\"n\": 5, \"a\": \"#[5, 5, 5]\"}",
"{\"n\": -1, \"a\": \"#[-10, -5, -3]\"}",
"{\"n\": -3, \"a\": \"#[-1, -2, -3]\"}",
"{\"n\": 0, \"a\": \"#[0, -1, -2]\"}",
"{\"n\": 10, \"a\": \"#[1, 2, 9, 3]\"}"
],
"expected": [
[
"True"
],
[
"False"
],
[
"False"
],
[
"True"
],
[
"False"
],
[
"False"
],
[
"True"
]
],
"unexpected": [
[
"False"
],
[
"True"
],
[
"True"
],
[
"False"
],
[
"True"
],
[
"True"
],
[
"False"
]
]
} | {
"input": [
"{'n': 0, 'a': '#[]'}"
]
} | basic |
verina_advanced_16 | -----Description-----
Implement the insertion sort algorithm in Lean 4. The function takes a single list of integers
as input and returns a new list that contains the same integers in ascending order.
Implementation must follow a standard insertion sort approach, placing each element into its correct position.
The resulting list must be sorted in ascending order.
The returned list must be a permutation of the input list (i.e., contain exactly the same elements).
-----Input-----
A single list of integers, denoted as xs.
-----Output-----
A list of integers, sorted in ascending order.
Example:
Input: [3, 1, 4, 2]
Output: [1, 2, 3, 4]
| -- !benchmark @start import type=solution
-- !benchmark @end import
-- !benchmark @start solution_aux
-- !benchmark @end solution_aux
-- !benchmark @start precond_aux
-- !benchmark @end precond_aux
@[reducible]
def insertionSort_precond (xs : List Int) : Prop :=
-- !benchmark @start precond
True
-- !benchmark @end precond
-- !benchmark @start code_aux
-- !benchmark @end code_aux
def insertionSort (xs : List Int) (h_precond : insertionSort_precond (xs)) : List Int :=
-- !benchmark @start code
let rec insert (x : Int) (ys : List Int) : List Int :=
match ys with
| [] => [x]
| y :: ys' =>
if x <= y then
x :: y :: ys'
else
y :: insert x ys'
let rec sort (arr : List Int) : List Int :=
match arr with
| [] => []
| x :: xs => insert x (sort xs)
sort xs
-- !benchmark @end code
-- !benchmark @start postcond_aux
-- !benchmark @end postcond_aux
@[reducible]
def insertionSort_postcond (xs : List Int) (result: List Int) (h_precond : insertionSort_precond (xs)) : Prop :=
-- !benchmark @start postcond
List.Pairwise (· ≤ ·) result ∧ List.isPerm xs result
-- !benchmark @end postcond
-- !benchmark @start proof_aux
-- !benchmark @end proof_aux
theorem insertionSort_spec_satisfied (xs: List Int) (h_precond : insertionSort_precond (xs)) :
insertionSort_postcond (xs) (insertionSort (xs) h_precond) h_precond := by
-- !benchmark @start proof
sorry
-- !benchmark @end proof
| {
"name": "insertionSort",
"parameters": {
"param_name": [
"xs"
],
"param_type": [
"List Int"
]
},
"return_type": "List Int"
} | {
"upstream": {
"name": "lab_assignment",
"link": "https://leetcode.com/problems/insertion-sort-list/description/",
"task_id": "lab_insertionSort_324868790",
"student_id": [
13
]
}
} | {
"input": [
"{\"xs\": \"[]\"}",
"{\"xs\": \"[42]\"}",
"{\"xs\": \"[3, 1, 4, 2]\"}",
"{\"xs\": \"[5, -1, 0, 10, -1]\"}",
"{\"xs\": \"[2, 2, 2, 2, 2]\"}"
],
"expected": [
[
"[]"
],
[
"[42]"
],
[
"[1, 2, 3, 4]"
],
[
"[-1, -1, 0, 5, 10]"
],
[
"[2, 2, 2, 2, 2]"
]
],
"unexpected": [
[
"[0]",
"[1, 2, 3]"
],
[
"[24]",
"[]",
"[42, 42]"
],
[
"[1, 3, 2, 4]",
"[4, 3, 2, 1]"
],
[
"[-1, -1, 0, 10, 5]",
"[10, 5, 0, -1, -1]"
],
[
"[2, 2, 2, 2]",
"[]"
]
]
} | {
"input": []
} | advanced |
verina_advanced_44 | -----Description-----
Given an integer array arr and a positive integer k, this task requires writing a Lean 4 method that finds the
maximum sum of a subarray of arr, such that the length of the subarray is divisible by k.
If the array is empty, or generally if there exists no subarray with length divisible by k,
the default return value should be 0.
-----Input-----
The input consists of:
arr: The array of integers.
k: An integer larger than 1.
-----Output-----
The output is an integer:
Returns the maximum positive integer x such that there exists a subarray where the sum equals x, and the length
of the subarray is divisible by k.
| -- !benchmark @start import type=solution
-- !benchmark @end import
-- !benchmark @start solution_aux
-- !benchmark @end solution_aux
-- !benchmark @start precond_aux
-- !benchmark @end precond_aux
@[reducible]
def maxSubarraySumDivisibleByK_precond (arr : Array Int) (k : Int) : Prop :=
-- !benchmark @start precond
k > 0
-- !benchmark @end precond
-- !benchmark @start code_aux
-- !benchmark @end code_aux
def maxSubarraySumDivisibleByK (arr : Array Int) (k : Int) : Int :=
-- !benchmark @start code
let n := arr.size
if n = 0 || k = 0 then 0
else
--compute prefix sums for efficient subarray sum calculation
let prefixSums := Id.run do
let mut prefixSums := Array.mkArray (n + 1) 0
for i in [0:n] do
prefixSums := prefixSums.set! (i+1) (prefixSums[i]! + arr[i]!)
prefixSums
let minElem := Id.run do -- find minimum element
let mut minElem := arr[0]!
for elem in arr do
minElem := min minElem elem
minElem
let maxSum := Id.run do
let mut maxSum := minElem - 1
--check all subarrays with length divisible by k
for len in List.range (n+1) do
if len % k = 0 && len > 0 then
for start in [0:(n - len + 1)] do
let endIdx := start + len
let subarraySum := prefixSums[endIdx]! - prefixSums[start]!
maxSum := max maxSum subarraySum
maxSum
let default : Int := minElem - 1
if maxSum = default then 0 else maxSum
-- !benchmark @end code
-- !benchmark @start postcond_aux
-- !benchmark @end postcond_aux
@[reducible]
def maxSubarraySumDivisibleByK_postcond (arr : Array Int) (k : Int) (result: Int) : Prop :=
-- !benchmark @start postcond
let subarrays := List.range (arr.size) |>.flatMap (fun start =>
List.range (arr.size - start + 1) |>.map (fun len => arr.extract start (start + len)))
let divisibleSubarrays := subarrays.filter (fun subarray => subarray.size % k = 0 && subarray.size > 0)
let subarraySums := divisibleSubarrays.map (fun subarray => subarray.sum)
(result = 0 → subarraySums.length = 0) ∧
(result ≠ 0 → result ∈ subarraySums ∧ subarraySums.all (fun sum => sum ≤ result))
-- !benchmark @end postcond
-- !benchmark @start proof_aux
-- !benchmark @end proof_aux
theorem maxSubarraySumDivisibleByK_spec_satisfied (arr: Array Int) (k: Int) :
maxSubarraySumDivisibleByK_postcond (arr) (k) (maxSubarraySumDivisibleByK (arr) (k)) := by
-- !benchmark @start proof
sorry
-- !benchmark @end proof
| {
"name": "maxSubarraySumDivisibleByK",
"parameters": {
"param_name": [
"arr",
"k"
],
"param_type": [
"Array Int",
"Int"
]
},
"return_type": "Int"
} | {
"upstream": {
"name": "lab_assignment",
"link": "https://leetcode.com/problems/maximum-subarray-sum-with-length-divisible-by-k/description/",
"task_id": "lab_maxSubarraySumDivisibleByK_325772368",
"student_id": [
36
]
}
} | {
"input": [
"{\"arr\": \"#[1, 2, 3, 4, 5]\", \"k\": 2}",
"{\"arr\": \"#[1, -2, 3, -4, 5]\", \"k\": 3}",
"{\"arr\": \"#[]\", \"k\": 5}",
"{\"arr\": \"#[1, 2, 3, 4]\", \"k\": 1}",
"{\"arr\": \"#[-2, 7, 1, 3]\", \"k\": 2}",
"{\"arr\": \"#[-100, 0, 1]\", \"k\": 5}",
"{\"arr\": \"#[1999, 1, -1023, 12351, -9999]\", \"k\": 2}"
],
"expected": [
[
"14"
],
[
"4"
],
[
"0"
],
[
"10"
],
[
"9"
],
[
"0"
],
[
"13328"
]
],
"unexpected": [
[
"9",
"5",
"15",
"10"
],
[
"2",
"5",
"3"
],
[
"-1"
],
[
"3",
"4",
"7",
"9"
],
[
"8",
"11",
"7"
],
[
"1",
"-99"
],
[
"1999",
"12351",
"3329",
"2352"
]
]
} | {
"input": []
} | advanced |
verina_basic_72 | -----Description-----
The problem asks you to construct a new list by adding an extra number to the end of an existing list of numbers. The focus is on understanding what the final list should look like when a given number is included as the last element.
-----Input-----
The input consists of:
• a: An array of integers.
• b: An integer to be appended to the array.
-----Output-----
The output is an array of integers which represents the original array with the element b added at the end. That is, the output array’s list representation equals a.toList concatenated with [b].
-----Note-----
There are no special preconditions; the method is expected to work correctly for any array of integers and any integer b. | -- !benchmark @start import type=solution
-- !benchmark @end import
-- !benchmark @start solution_aux
-- !benchmark @end solution_aux
-- !benchmark @start precond_aux
-- !benchmark @end precond_aux
@[reducible, simp]
def append_precond (a : Array Int) (b : Int) : Prop :=
-- !benchmark @start precond
True
-- !benchmark @end precond
-- !benchmark @start code_aux
def copy (a : Array Int) (i : Nat) (acc : Array Int) : Array Int :=
if i < a.size then
copy a (i + 1) (acc.push (a[i]!))
else
acc
-- !benchmark @end code_aux
def append (a : Array Int) (b : Int) (h_precond : append_precond (a) (b)) : Array Int :=
-- !benchmark @start code
let c_initial := copy a 0 (Array.empty)
let c_full := c_initial.push b
c_full
-- !benchmark @end code
-- !benchmark @start postcond_aux
-- !benchmark @end postcond_aux
@[reducible, simp]
def append_postcond (a : Array Int) (b : Int) (result: Array Int) (h_precond : append_precond (a) (b)) :=
-- !benchmark @start postcond
(List.range' 0 a.size |>.all (fun i => result[i]! = a[i]!)) ∧
result[a.size]! = b ∧
result.size = a.size + 1
-- !benchmark @end postcond
-- !benchmark @start proof_aux
-- !benchmark @end proof_aux
theorem append_spec_satisfied (a: Array Int) (b: Int) (h_precond : append_precond (a) (b)) :
append_postcond (a) (b) (append (a) (b) h_precond) h_precond := by
-- !benchmark @start proof
sorry
-- !benchmark @end proof
| {
"name": "append",
"parameters": {
"param_name": [
"a",
"b"
],
"param_type": [
"Array Int",
"Int"
]
},
"return_type": "Array Int"
} | {
"upstream": {
"name": "clover",
"link": "https://github.com/ChuyueSun/Clover",
"task_id": "Clover_array_append",
"student_id": null
}
} | {
"input": [
"{\"a\": \"#[1, 2, 3]\", \"b\": 4}",
"{\"a\": \"#[]\", \"b\": 0}",
"{\"a\": \"#[5, 6]\", \"b\": -1}",
"{\"a\": \"#[0, 0, 0]\", \"b\": 1}",
"{\"a\": \"#[-2, -3]\", \"b\": -4}"
],
"expected": [
[
"#[1, 2, 3, 4]"
],
[
"#[0]"
],
[
"#[5, 6, -1]"
],
[
"#[0, 0, 0, 1]"
],
[
"#[-2, -3, -4]"
]
],
"unexpected": [
[
"#[1, 2, 3, 0]",
"#[1, 2, 4, 3]",
"#[4, 1, 2, 3]"
],
[
"#[1]",
"#[]",
"#[0, 0]"
],
[
"#[5, -1, 6]",
"#[5, 6, 0]",
"#[6, 5, -1]"
],
[
"#[1, 0, 0, 0]",
"#[0, 1, 0, 0]",
"#[0, 0, 1, 0]"
],
[
"#[-2, -4, -3]",
"#[-2, -3, 0]",
"#[-3, -2, -4]"
]
]
} | {
"input": []
} | basic |
verina_basic_26 | -----Description-----
This task requires writing a Lean 4 method that determines whether a given integer is even. In other words, the method should return true if the number is even and false if the number is odd.
-----Input-----
The input consists of:
n: An integer.
-----Output-----
The output is a Boolean value:
Returns true if the input number is even.
Returns false if the input number is odd.
-----Note-----
There are no preconditions; the method will always work for any integer input. | -- !benchmark @start import type=solution
-- !benchmark @end import
-- !benchmark @start solution_aux
-- !benchmark @end solution_aux
-- !benchmark @start precond_aux
-- !benchmark @end precond_aux
@[reducible, simp]
def isEven_precond (n : Int) : Prop :=
-- !benchmark @start precond
True
-- !benchmark @end precond
-- !benchmark @start code_aux
-- !benchmark @end code_aux
def isEven (n : Int) (h_precond : isEven_precond (n)) : Bool :=
-- !benchmark @start code
n % 2 == 0
-- !benchmark @end code
-- !benchmark @start postcond_aux
-- !benchmark @end postcond_aux
@[reducible, simp]
def isEven_postcond (n : Int) (result: Bool) (h_precond : isEven_precond (n)) :=
-- !benchmark @start postcond
(result → n % 2 = 0) ∧ (¬ result → n % 2 ≠ 0)
-- !benchmark @end postcond
-- !benchmark @start proof_aux
-- !benchmark @end proof_aux
theorem isEven_spec_satisfied (n: Int) (h_precond : isEven_precond (n)) :
isEven_postcond (n) (isEven (n) h_precond) h_precond := by
-- !benchmark @start proof
unfold isEven isEven_postcond
simp
-- !benchmark @end proof
| {
"name": "isEven",
"parameters": {
"param_name": [
"n"
],
"param_type": [
"Int"
]
},
"return_type": "Bool"
} | {
"upstream": {
"name": "dafny-synthesis",
"link": "https://github.com/Mondego/dafny-synthesis",
"task_id": "task_id_600",
"student_id": null
}
} | {
"input": [
"{\"n\": 4}",
"{\"n\": 7}",
"{\"n\": 0}",
"{\"n\": -2}",
"{\"n\": -3}"
],
"expected": [
[
"True"
],
[
"False"
],
[
"True"
],
[
"True"
],
[
"False"
]
],
"unexpected": [
[
"False"
],
[
"True"
],
[
"False"
],
[
"False"
],
[
"True"
]
]
} | {
"input": []
} | basic |
verina_advanced_29 | -----Description-----
You are given a natural number array nums and a natural number k.
The frequency of an element x is the number of times it occurs in an array.
An array is called good if the frequency of each element in this array is less than or equal to k.
Return the length of the longest good subarray of nums.
A subarray is a contiguous non-empty sequence of elements within an array.
-----Input-----
The input consists of an array of natural numbers nums and a natural number k:
nums: an array of natural numbers.
k: a natural number
-----Output-----
The output is a natural number:
Return the length of the longest good subarray of nums.
| -- !benchmark @start import type=solution
import Std.Data.HashMap
open Std
-- !benchmark @end import
-- !benchmark @start solution_aux
-- !benchmark @end solution_aux
-- !benchmark @start precond_aux
-- !benchmark @end precond_aux
@[reducible]
def longestGoodSubarray_precond (nums : List Nat) (k : Nat) : Prop :=
-- !benchmark @start precond
True
-- !benchmark @end precond
-- !benchmark @start code_aux
-- !benchmark @end code_aux
def longestGoodSubarray (nums : List Nat) (k : Nat) (h_precond : longestGoodSubarray_precond (nums) (k)) : Nat :=
-- !benchmark @start code
Id.run do
let arr := nums.toArray
let mut left := 0
let mut maxLen := 0
let mut freq : HashMap Nat Nat := {}
for right in [0:arr.size] do
let num := arr[right]!
let count := freq.getD num 0
freq := freq.insert num (count + 1)
-- If any frequency > k, shrink the window from the left
while freq.toList.any (fun (_, v) => v > k) do
let lnum := arr[left]!
let lcount := freq.getD lnum 0
if lcount = 1 then
freq := freq.erase lnum
else
freq := freq.insert lnum (lcount - 1)
left := left + 1
maxLen := max maxLen (right - left + 1)
return maxLen
-- !benchmark @end code
-- !benchmark @start postcond_aux
-- !benchmark @end postcond_aux
@[reducible]
def longestGoodSubarray_postcond (nums : List Nat) (k : Nat) (result: Nat) (h_precond : longestGoodSubarray_precond (nums) (k)) : Prop :=
-- !benchmark @start postcond
let subArrays :=
List.range (nums.length + 1) |>.flatMap (fun start =>
List.range (nums.length - start + 1) |>.map (fun len =>
nums.drop start |>.take len))
let subArrayFreqs := subArrays.map (fun arr => arr.map (fun x => arr.count x))
let validSubArrays := subArrayFreqs.filter (fun arr => arr.all (fun x => x ≤ k))
(nums = [] ∧ result = 0) ∨
(nums ≠ [] ∧
validSubArrays.any (fun arr => arr.length = result) ∧
validSubArrays.all (fun arr => arr.length ≤ result))
-- !benchmark @end postcond
-- !benchmark @start proof_aux
-- !benchmark @end proof_aux
theorem longestGoodSubarray_spec_satisfied (nums: List Nat) (k: Nat) (h_precond : longestGoodSubarray_precond (nums) (k)) :
longestGoodSubarray_postcond (nums) (k) (longestGoodSubarray (nums) (k) h_precond) h_precond := by
-- !benchmark @start proof
sorry
-- !benchmark @end proof
| {
"name": "longestGoodSubarray",
"parameters": {
"param_name": [
"nums",
"k"
],
"param_type": [
"List Nat",
"Nat"
]
},
"return_type": "Nat"
} | {
"upstream": {
"name": "lab_assignment",
"link": "https://leetcode.com/problems/length-of-longest-subarray-with-at-most-k-frequency/description/",
"task_id": "lab_longestGoodSubarray_325744111",
"student_id": [
23
]
}
} | {
"input": [
"{\"nums\": \"[1, 2, 3, 1, 2, 3, 1, 2]\", \"k\": 2}",
"{\"nums\": \"[1, 2, 1, 2, 1, 2, 1, 2]\", \"k\": 1}",
"{\"nums\": \"[5, 5, 5, 5, 5, 5, 5]\", \"k\": 4}",
"{\"nums\": \"[1]\", \"k\": 1}",
"{\"nums\": \"[2, 2, 1, 1, 3]\", \"k\": 2}"
],
"expected": [
[
"6"
],
[
"2"
],
[
"4"
],
[
"1"
],
[
"5"
]
],
"unexpected": [
[
"5",
"7",
"8"
],
[
"1",
"3",
"4"
],
[
"3",
"5",
"7"
],
[
"0",
"2"
],
[
"2",
"3",
"4",
"6"
]
]
} | {
"input": []
} | advanced |
verina_advanced_1 | -----Description-----
This task requires writing a Lean 4 function that finds the single number in a non-empty list of integers, where every element appears exactly twice except for one element that appears only once. The function
should return the integer that appears only once.
-----Input-----
The input is a non-empty list of integers:
- nums: A list in which each integer appears exactly twice except for one element that appears only once.
-----Output-----
The output is a single integer:
Returns the unique integer that appears exactly once in the list.
| -- !benchmark @start import type=solution
-- !benchmark @end import
-- !benchmark @start solution_aux
def filterlist (x : Int) (nums : List Int) : List Int :=
let rec aux (lst : List Int) : List Int :=
match lst with
| [] => []
| y :: ys => if y = x then y :: aux ys else aux ys
aux nums
-- !benchmark @end solution_aux
-- !benchmark @start precond_aux
-- !benchmark @end precond_aux
@[reducible]
def FindSingleNumber_precond (nums : List Int) : Prop :=
-- !benchmark @start precond
let numsCount := nums.map (fun x => nums.count x)
numsCount.all (fun count => count = 1 ∨ count = 2) ∧ numsCount.count 1 = 1
-- !benchmark @end precond
-- !benchmark @start code_aux
-- !benchmark @end code_aux
def FindSingleNumber (nums : List Int) (h_precond : FindSingleNumber_precond (nums)) : Int :=
-- !benchmark @start code
let rec findUnique (remaining : List Int) : Int :=
match remaining with
| [] =>
0
| x :: xs =>
let filtered : List Int :=
filterlist x nums
let count : Nat :=
filtered.length
if count = 1 then
x
else
findUnique xs
findUnique nums
-- !benchmark @end code
-- !benchmark @start postcond_aux
-- !benchmark @end postcond_aux
@[reducible]
def FindSingleNumber_postcond (nums : List Int) (result: Int) (h_precond : FindSingleNumber_precond (nums)) : Prop :=
-- !benchmark @start postcond
(nums.length > 0)
∧
((filterlist result nums).length = 1)
∧
(∀ (x : Int),
x ∈ nums →
(x = result) ∨ ((filterlist x nums).length = 2))
-- !benchmark @end postcond
-- !benchmark @start proof_aux
-- !benchmark @end proof_aux
theorem FindSingleNumber_spec_satisfied (nums: List Int) (h_precond : FindSingleNumber_precond (nums)) :
FindSingleNumber_postcond (nums) (FindSingleNumber (nums) h_precond) h_precond := by
-- !benchmark @start proof
sorry
-- !benchmark @end proof
| {
"name": "FindSingleNumber",
"parameters": {
"param_name": [
"nums"
],
"param_type": [
"List Int"
]
},
"return_type": "Int"
} | {
"upstream": {
"name": "lab_assignment",
"link": "N/A",
"task_id": "lab_FindSingleNumber_324594979",
"student_id": [
1
]
}
} | {
"input": [
"{\"nums\": \"[2, 2, 3]\"}",
"{\"nums\": \"[1, 2, 2]\"}",
"{\"nums\": \"[3, 3, 4, 4, 1]\"}",
"{\"nums\": \"[0, 1, 3, 1, 3, 88, 88, 100, 100]\"}",
"{\"nums\": \"[-1, -1, 7, 9, 7]\"}"
],
"expected": [
[
"3"
],
[
"1"
],
[
"1"
],
[
"0"
],
[
"9"
]
],
"unexpected": [
[
"2",
"1",
"4"
],
[
"2",
"-1"
],
[
"3",
"4"
],
[
"1",
"2",
"100"
],
[
"-1",
"7",
"10"
]
]
} | {
"input": [
"{'nums': '[2, 2]'}",
"{'nums': '[2, 2, 3, 3]'}"
]
} | advanced |
verina_basic_41 | -----Description-----
This task requires writing a Lean 4 method that determines whether an array of integers contains only one distinct element. The method should return true if the array is empty or if every element in the array is the same, and false if there are at least two different elements.
-----Input-----
The input consists of:
a: An array of integers.
-----Output-----
The output is a Boolean value:
Returns true if the array is empty or if all elements in the array are identical.
Returns false if the array contains at least two distinct elements.
-----Note-----
The input array is assumed to be non-null. | -- !benchmark @start import type=solution
-- !benchmark @end import
-- !benchmark @start solution_aux
-- !benchmark @end solution_aux
-- !benchmark @start precond_aux
-- !benchmark @end precond_aux
@[reducible, simp]
def hasOnlyOneDistinctElement_precond (a : Array Int) : Prop :=
-- !benchmark @start precond
a.size > 0
-- !benchmark @end precond
-- !benchmark @start code_aux
-- !benchmark @end code_aux
def hasOnlyOneDistinctElement (a : Array Int) (h_precond : hasOnlyOneDistinctElement_precond (a)) : Bool :=
-- !benchmark @start code
if a.size = 0 then
true
else
let firstElement := a[0]!
let rec loop (i : Nat) : Bool :=
if h : i < a.size then
if a[i]! = firstElement then loop (i + 1) else false
else
true
loop 1
-- !benchmark @end code
-- !benchmark @start postcond_aux
-- !benchmark @end postcond_aux
@[reducible, simp]
def hasOnlyOneDistinctElement_postcond (a : Array Int) (result: Bool) (h_precond : hasOnlyOneDistinctElement_precond (a)) :=
-- !benchmark @start postcond
let l := a.toList
(result → List.Pairwise (· = ·) l) ∧
(¬ result → (l.any (fun x => x ≠ l[0]!)))
-- !benchmark @end postcond
-- !benchmark @start proof_aux
-- !benchmark @end proof_aux
theorem hasOnlyOneDistinctElement_spec_satisfied (a: Array Int) (h_precond : hasOnlyOneDistinctElement_precond (a)) :
hasOnlyOneDistinctElement_postcond (a) (hasOnlyOneDistinctElement (a) h_precond) h_precond := by
-- !benchmark @start proof
sorry
-- !benchmark @end proof
| {
"name": "hasOnlyOneDistinctElement",
"parameters": {
"param_name": [
"a"
],
"param_type": [
"Array Int"
]
},
"return_type": "Bool"
} | {
"upstream": {
"name": "dafny-synthesis",
"link": "https://github.com/Mondego/dafny-synthesis",
"task_id": "task_id_760",
"student_id": null
}
} | {
"input": [
"{\"a\": \"#[1, 1, 1]\"}",
"{\"a\": \"#[1, 2, 1]\"}",
"{\"a\": \"#[3, 4, 5, 6]\"}",
"{\"a\": \"#[7]\"}",
"{\"a\": \"#[0, 0, 0, 0]\"}",
"{\"a\": \"#[0, 0, 1, 0]\"}"
],
"expected": [
[
"True"
],
[
"False"
],
[
"False"
],
[
"True"
],
[
"True"
],
[
"False"
]
],
"unexpected": [
[
"False"
],
[
"True"
],
[
"True"
],
[
"False"
],
[
"False"
],
[
"True"
]
]
} | {
"input": [
"{'a': '#[]'}"
]
} | basic |
verina_advanced_79 | -----Description-----
This task requires writing a Lean 4 method that implementing the "Two Sum" problem. Given a list of integers
and a target integer, the function should return the indices of the two numbers that add up to
the target. If no valid pair exists, the function should return none. And the indices returned must
be within the bounds of the list. If multiple pair exists, return the first pair.
-----Input-----
- nums: A list of integers.
- target: An integer representing the target sum.
-----Output-----
- An option type containing a pair of natural numbers (indices) such that
nums[i] + nums[j] = target, if such a pair exists. Otherwise, it returns none.
| -- !benchmark @start import type=solution
-- !benchmark @end import
-- !benchmark @start solution_aux
-- !benchmark @end solution_aux
-- !benchmark @start precond_aux
-- !benchmark @end precond_aux
@[reducible]
def twoSum_precond (nums : List Int) (target : Int) : Prop :=
-- !benchmark @start precond
True
-- !benchmark @end precond
-- !benchmark @start code_aux
-- !benchmark @end code_aux
def twoSum (nums : List Int) (target : Int) (h_precond : twoSum_precond (nums) (target)) : Option (Nat × Nat) :=
-- !benchmark @start code
let rec outer (lst : List Int) (i : Nat)
: Option (Nat × Nat) :=
match lst with
| [] =>
none
| x :: xs =>
let rec inner (lst' : List Int) (j : Nat)
: Option Nat :=
match lst' with
| [] =>
none
| y :: ys =>
if x + y = target then
some j
else
inner ys (j + 1)
match inner xs (i + 1) with
| some j =>
some (i, j)
| none =>
outer xs (i + 1)
outer nums 0
-- !benchmark @end code
-- !benchmark @start postcond_aux
-- !benchmark @end postcond_aux
@[reducible]
def twoSum_postcond (nums : List Int) (target : Int) (result: Option (Nat × Nat)) (h_precond : twoSum_precond (nums) (target)) : Prop :=
-- !benchmark @start postcond
match result with
| none => List.Pairwise (· + · ≠ target) nums
| some (i, j) =>
i < j ∧
j < nums.length ∧
nums[i]! + nums[j]! = target ∧
-- i must be the first i
List.Pairwise (fun a b => a + b ≠ target) (nums.take i) ∧
List.all (nums.take i) (fun a => List.all (nums.drop i) (fun b => a + b ≠ target) ) ∧
-- j must be the first j
List.all (nums.drop (j + 1)) (fun a => a + nums[j]! ≠ target)
-- !benchmark @end postcond
-- !benchmark @start proof_aux
-- !benchmark @end proof_aux
theorem twoSum_spec_satisfied (nums: List Int) (target: Int) (h_precond : twoSum_precond (nums) (target)) :
twoSum_postcond (nums) (target) (twoSum (nums) (target) h_precond) h_precond := by
-- !benchmark @start proof
sorry
-- !benchmark @end proof
| {
"name": "twoSum",
"parameters": {
"param_name": [
"nums",
"target"
],
"param_type": [
"List Int",
"Int"
]
},
"return_type": "Option (Nat × Nat)"
} | {
"upstream": {
"name": "lab_assignment",
"link": "https://leetcode.com/problems/two-sum/description/",
"task_id": "lab_twoSum_325525518",
"student_id": [
27
]
}
} | {
"input": [
"{\"nums\": \"[2, 7, 11, 15]\", \"target\": 9}",
"{\"nums\": \"[3, 2, 4]\", \"target\": 6}",
"{\"nums\": \"[3, 3]\", \"target\": 6}",
"{\"nums\": \"[1, 2, 3]\", \"target\": 7}",
"{\"nums\": \"[0, 4, 3, 0]\", \"target\": 0}"
],
"expected": [
[
"some (0, 1)"
],
[
"some (1, 2)"
],
[
"some (0, 1)"
],
[
"none"
],
[
"some (0, 3)"
]
],
"unexpected": [
[
"some (1, 2)",
"none"
],
[
"some (0, 2)",
"none"
],
[
"some (1, 1)",
"none"
],
[
"some (0, 2)"
],
[
"some (1, 2)",
"none"
]
]
} | {
"input": []
} | advanced |
verina_advanced_58 | -----Description-----
This task requires writing a Lean 4 function that returns the nth "ugly number". Ugly numbers are positive integers whose only prime factors are 2, 3, or 5.
The function should generate ugly numbers in ascending order and return the nth one. The first ugly number is 1.
-----Input-----
The input is a natural number:
n: The index (1-based) of the ugly number to return.
-----Output-----
The output is a natural number:
The nth smallest ugly number.
| -- !benchmark @start import type=solution
-- !benchmark @end import
-- !benchmark @start solution_aux
-- !benchmark @end solution_aux
-- !benchmark @start precond_aux
-- !benchmark @end precond_aux
@[reducible, simp]
def nthUglyNumber_precond (n : Nat) : Prop :=
-- !benchmark @start precond
n > 0
-- !benchmark @end precond
-- !benchmark @start code_aux
def nextUgly (seq : List Nat) (c2 c3 c5 : Nat) : (Nat × Nat × Nat × Nat) :=
let i2 := seq[c2]! * 2
let i3 := seq[c3]! * 3
let i5 := seq[c5]! * 5
let next := min i2 (min i3 i5)
let c2' := if next = i2 then c2 + 1 else c2
let c3' := if next = i3 then c3 + 1 else c3
let c5' := if next = i5 then c5 + 1 else c5
(next, c2', c3', c5')
-- !benchmark @end code_aux
def nthUglyNumber (n : Nat) (h_precond : nthUglyNumber_precond (n)) : Nat :=
-- !benchmark @start code
let rec loop (i : Nat) (seq : List Nat) (c2 c3 c5 : Nat) : List Nat :=
match i with
| 0 => seq
| Nat.succ i' =>
let (next, c2', c3', c5') := nextUgly seq c2 c3 c5
loop i' (seq ++ [next]) c2' c3' c5'
(loop (n - 1) [1] 0 0 0)[(n - 1)]!
-- !benchmark @end code
-- !benchmark @start postcond_aux
def divideOut : Nat → Nat → Nat
| n, p =>
if h : p > 1 ∧ n > 0 ∧ n % p = 0 then
have : n / p < n := by
apply Nat.div_lt_self
· exact h.2.1 -- n > 0
· exact Nat.lt_of_succ_le (Nat.succ_le_of_lt h.1) -- 1 < p, so 2 ≤ p
divideOut (n / p) p
else n
termination_by n p => n
def isUgly (x : Nat) : Bool :=
if x = 0 then
false
else
let n1 := divideOut x 2
let n2 := divideOut n1 3
let n3 := divideOut n2 5
n3 = 1
-- !benchmark @end postcond_aux
@[reducible, simp]
def nthUglyNumber_postcond (n : Nat) (result: Nat) (h_precond : nthUglyNumber_precond (n)) : Prop :=
-- !benchmark @start postcond
isUgly result = true ∧
((List.range (result)).filter (fun i => isUgly i)).length = n - 1
-- !benchmark @end postcond
-- !benchmark @start proof_aux
-- !benchmark @end proof_aux
theorem nthUglyNumber_spec_satisfied (n: Nat) (h_precond : nthUglyNumber_precond (n)) :
nthUglyNumber_postcond (n) (nthUglyNumber (n) h_precond) h_precond := by
-- !benchmark @start proof
sorry
-- !benchmark @end proof
| {
"name": "nthUglyNumber",
"parameters": {
"param_name": [
"n"
],
"param_type": [
"Nat"
]
},
"return_type": "Nat"
} | {
"upstream": {
"name": "lab_assignment",
"link": "",
"task_id": "lab_nthUglyNumber_324647099",
"student_id": [
43
]
}
} | {
"input": [
"{\"n\": 1}",
"{\"n\": 10}",
"{\"n\": 15}",
"{\"n\": 5}",
"{\"n\": 7}"
],
"expected": [
[
"1"
],
[
"12"
],
[
"24"
],
[
"5"
],
[
"8"
]
],
"unexpected": [
[
"0",
"2"
],
[
"13",
"10",
"15"
],
[
"20",
"25"
],
[
"6",
"7"
],
[
"9",
"10"
]
]
} | {
"input": []
} | advanced |
verina_advanced_3 | -----Description-----
This task requires writing a Lean 4 method that finds the length of the logest common subsequence of two input arrays.
-----Input-----
The input consists of two arrays:
a: The first array.
b: The second array.
-----Output-----
The output is an integer:
Returns the length of array a and b's longest common subsequence.
| -- !benchmark @start import type=solution
-- !benchmark @end import
-- !benchmark @start solution_aux
-- !benchmark @end solution_aux
-- !benchmark @start precond_aux
-- !benchmark @end precond_aux
@[reducible]
def LongestCommonSubsequence_precond (a : Array Int) (b : Array Int) : Prop :=
-- !benchmark @start precond
True
-- !benchmark @end precond
-- !benchmark @start code_aux
def intMax (x y : Int) : Int :=
if x < y then y else x
-- !benchmark @end code_aux
def LongestCommonSubsequence (a : Array Int) (b : Array Int) (h_precond : LongestCommonSubsequence_precond (a) (b)) : Int :=
-- !benchmark @start code
let m := a.size
let n := b.size
let dp := Id.run do
let mut dp := Array.mkArray (m + 1) (Array.mkArray (n + 1) 0)
for i in List.range (m + 1) do
for j in List.range (n + 1) do
if i = 0 ∨ j = 0 then
()
else if a[i - 1]! = b[j - 1]! then
let newVal := ((dp[i - 1]!)[j - 1]!) + 1
dp := dp.set! i (dp[i]!.set! j newVal)
else
let newVal := intMax ((dp[i - 1]!)[j]!) ((dp[i]!)[j - 1]!)
dp := dp.set! i (dp[i]!.set! j newVal)
return dp
(dp[m]!)[n]!
-- !benchmark @end code
-- !benchmark @start postcond_aux
-- !benchmark @end postcond_aux
@[reducible]
def LongestCommonSubsequence_postcond (a : Array Int) (b : Array Int) (result: Int) (h_precond : LongestCommonSubsequence_precond (a) (b)) : Prop :=
-- !benchmark @start postcond
let allSubseq (arr : Array Int) := (arr.foldl fun acc x => acc ++ acc.map (fun sub => x :: sub)) [[]] |>.map List.reverse
let subseqA := allSubseq a
let subseqB := allSubseq b
let commonSubseqLens := subseqA.filter (fun l => subseqB.contains l) |>.map (·.length)
commonSubseqLens.contains result ∧ commonSubseqLens.all (· ≤ result)
-- !benchmark @end postcond
-- !benchmark @start proof_aux
-- !benchmark @end proof_aux
theorem LongestCommonSubsequence_spec_satisfied (a: Array Int) (b: Array Int) (h_precond : LongestCommonSubsequence_precond (a) (b)) :
LongestCommonSubsequence_postcond (a) (b) (LongestCommonSubsequence (a) (b) h_precond) h_precond := by
-- !benchmark @start proof
sorry
-- !benchmark @end proof
| {
"name": "LongestCommonSubsequence",
"parameters": {
"param_name": [
"a",
"b"
],
"param_type": [
"Array Int",
"Array Int"
]
},
"return_type": "Int"
} | {
"upstream": {
"name": "lab_assignment",
"link": "longest common subsequence from cs170 hw07",
"task_id": "lab_LongestCommonSubsequence_325033255",
"student_id": [
2
]
}
} | {
"input": [
"{\"a\": \"#[1, 2, 3]\", \"b\": \"#[1, 2, 3]\"}",
"{\"a\": \"#[1, 3, 5, 7]\", \"b\": \"#[1, 2, 3, 4, 5, 6, 7]\"}",
"{\"a\": \"#[1, 2, 3]\", \"b\": \"#[4, 5, 6]\"}",
"{\"a\": \"#[]\", \"b\": \"#[1, 2, 3]\"}",
"{\"a\": \"#[1, 2, 3, 4]\", \"b\": \"#[2, 4, 6, 8]\"}"
],
"expected": [
[
"3"
],
[
"4"
],
[
"0"
],
[
"0"
],
[
"2"
]
],
"unexpected": [
[
"2",
"4"
],
[
"2",
"5"
],
[
"1",
"2"
],
[
"1"
],
[
"1",
"3",
"4"
]
]
} | {
"input": []
} | advanced |
verina_basic_2 | -----Description-----
This task requires writing a Lean 4 method that finds the smallest number in an array of integers.
-----Input-----
The input consists of:
s: An array of integers.
-----Output-----
The output is an option integer:
Returns the smallest number found in the input array or none if the array is empty.
| -- !benchmark @start import type=solution
-- !benchmark @end import
-- !benchmark @start solution_aux
-- !benchmark @end solution_aux
-- !benchmark @start precond_aux
-- !benchmark @end precond_aux
@[reducible, simp]
def findSmallest_precond (s : Array Nat) : Prop :=
-- !benchmark @start precond
True
-- !benchmark @end precond
-- !benchmark @start code_aux
-- !benchmark @end code_aux
def findSmallest (s : Array Nat) (h_precond : findSmallest_precond (s)) : Option Nat :=
-- !benchmark @start code
s.toList.min?
-- !benchmark @end code
-- !benchmark @start postcond_aux
-- !benchmark @end postcond_aux
@[reducible, simp]
def findSmallest_postcond (s : Array Nat) (result: Option Nat) (h_precond : findSmallest_precond (s)) :=
-- !benchmark @start postcond
let xs := s.toList
match result with
| none => xs = []
| some r => r ∈ xs ∧ (∀ x, x ∈ xs → r ≤ x)
-- !benchmark @end postcond
-- !benchmark @start proof_aux
-- !benchmark @end proof_aux
theorem findSmallest_spec_satisfied (s: Array Nat) (h_precond : findSmallest_precond (s)) :
findSmallest_postcond (s) (findSmallest (s) h_precond) h_precond := by
-- !benchmark @start proof
unfold findSmallest_postcond findSmallest
cases res : s.toList.min? with
| none =>
simp only [res]
rw [List.min?_eq_none_iff] at res
exact res
| some r =>
simp only [res]
rw [List.min?_eq_some_iff'] at res
exact res
-- !benchmark @end proof
| {
"name": "findSmallest",
"parameters": {
"param_name": [
"s"
],
"param_type": [
"Array Nat"
]
},
"return_type": "Option Nat"
} | {
"upstream": {
"name": "dafny-synthesis",
"link": "https://github.com/Mondego/dafny-synthesis",
"task_id": "task_id_62",
"student_id": null
}
} | {
"input": [
"{\"s\": \"#[3, 1, 4, 1, 5, 9, 2, 6, 5, 3, 5]\"}",
"{\"s\": \"#[0, 1, 2, 3, 4, 5]\"}",
"{\"s\": \"#[1]\"}",
"{\"s\": \"#[10, 10, 10]\"}",
"{\"s\": \"#[3, 2, 2, 2, 2, 2, 2, 1]\"}",
"{\"s\": \"#[0]\"}",
"{\"s\": \"#[100, 99, 98]\"}",
"{\"s\": \"#[]\"}"
],
"expected": [
[
"some (1)"
],
[
"some (0)"
],
[
"some (1)"
],
[
"some (10)"
],
[
"some (1)"
],
[
"some (0)"
],
[
"some (98)"
],
[
"none"
]
],
"unexpected": [
[
"some (2)",
"some (0)",
"none"
],
[
"some (1)",
"none"
],
[
"some (0)",
"some (2)",
"none"
],
[
"some (9)",
"some (0)",
"none"
],
[
"some (2)",
"some (0)",
"none"
],
[
"some (1)",
"none"
],
[
"some (99)",
"some (97)",
"none"
],
[
"some (0)"
]
]
} | {
"input": []
} | basic |
verina_basic_103 | -----Description-----
This problem involves updating an array of integers by modifying two specific positions. Specifically, the element at index 4 should be increased by 3, and the element at index 7 should be changed to 516. The goal is to correctly update these positions while leaving the rest of the array unchanged. The description assumes that the array contains at least 8 elements.
-----Input-----
The input consists of:
• a: An array of integers. The array must contain at least 8 elements.
-----Output-----
The output is an array of integers that meets the following criteria:
• The element at index 4 is updated to its original value plus 3.
• The element at index 7 is set to 516.
• All other elements in the array remain the same as in the input array.
-----Note-----
It is assumed that the input array has a size of at least 8 elements. Indices are 0-indexed. | -- !benchmark @start import type=solution
-- !benchmark @end import
-- !benchmark @start solution_aux
-- !benchmark @end solution_aux
-- !benchmark @start precond_aux
-- !benchmark @end precond_aux
@[reducible, simp]
def UpdateElements_precond (a : Array Int) : Prop :=
-- !benchmark @start precond
a.size ≥ 8
-- !benchmark @end precond
-- !benchmark @start code_aux
-- !benchmark @end code_aux
def UpdateElements (a : Array Int) (h_precond : UpdateElements_precond (a)) : Array Int :=
-- !benchmark @start code
let a1 := a.set! 4 ((a[4]!) + 3)
let a2 := a1.set! 7 516
a2
-- !benchmark @end code
-- !benchmark @start postcond_aux
-- !benchmark @end postcond_aux
@[reducible, simp]
def UpdateElements_postcond (a : Array Int) (result: Array Int) (h_precond : UpdateElements_precond (a)) :=
-- !benchmark @start postcond
result[4]! = (a[4]!) + 3 ∧
result[7]! = 516 ∧
(∀ i, i < a.size → i ≠ 4 → i ≠ 7 → result[i]! = a[i]!)
-- !benchmark @end postcond
-- !benchmark @start proof_aux
-- !benchmark @end proof_aux
theorem UpdateElements_spec_satisfied (a: Array Int) (h_precond : UpdateElements_precond (a)) :
UpdateElements_postcond (a) (UpdateElements (a) h_precond) h_precond := by
-- !benchmark @start proof
sorry
-- !benchmark @end proof
| {
"name": "UpdateElements",
"parameters": {
"param_name": [
"a"
],
"param_type": [
"Array Int"
]
},
"return_type": "Array Int"
} | {
"upstream": {
"name": "clover",
"link": "https://github.com/ChuyueSun/Clover",
"task_id": "Clover_update_array",
"student_id": null
}
} | {
"input": [
"{\"a\": \"#[0, 1, 2, 3, 4, 5, 6, 7, 8]\"}",
"{\"a\": \"#[10, 20, 30, 40, 50, 60, 70, 80]\"}",
"{\"a\": \"#[-1, -2, -3, -4, -5, -6, -7, -8, -9, -10]\"}",
"{\"a\": \"#[0, 0, 0, 0, 0, 0, 0, 0]\"}",
"{\"a\": \"#[5, 5, 5, 5, 5, 5, 5, 5]\"}"
],
"expected": [
[
"#[0, 1, 2, 3, 7, 5, 6, 516, 8]"
],
[
"#[10, 20, 30, 40, 53, 60, 70, 516]"
],
[
"#[-1, -2, -3, -4, -2, -6, -7, 516, -9, -10]"
],
[
"#[0, 0, 0, 0, 3, 0, 0, 516]"
],
[
"#[5, 5, 5, 5, 8, 5, 5, 516]"
]
],
"unexpected": [
[
"#[0, 1, 2, 3, 4, 5, 6, 516, 8]",
"#[0, 1, 2, 3, 7, 5, 6, 7, 8]"
],
[
"#[10, 20, 30, 40, 50, 60, 70, 80]",
"#[10, 20, 30, 40, 53, 60, 70, 80]"
],
[
"#[-1, -2, -3, -4, -5, -6, -7, 516, -9, -10]",
"#[-1, -2, -3, -4, -2, -6, -7, -8, -9, -10]"
],
[
"#[0, 0, 0, 0, 0, 0, 0, 516]",
"#[0, 0, 0, 0, 3, 0, 0, 0]"
],
[
"#[5, 5, 5, 5, 5, 5, 5, 5]",
"#[5, 5, 5, 5, 8, 5, 5, 5]"
]
]
} | {
"input": [
"{'a': '#[1, 2, 3, 4, 5, 6]'}"
]
} | basic |
verina_basic_67 | -----Description-----
This task requires determining whether a given list of characters is a palindrome; that is, whether the sequence reads the same forward and backward.
-----Input-----
The input consists of:
• x: A list of characters (List Char). The list can be empty or non-empty.
-----Output-----
The output is a Boolean value (Bool):
• Returns true if the input list is a palindrome.
• Returns false otherwise.
-----Note-----
An empty list is considered a palindrome. The function does not impose any additional preconditions. | -- !benchmark @start import type=solution
-- !benchmark @end import
-- !benchmark @start solution_aux
-- !benchmark @end solution_aux
-- !benchmark @start precond_aux
-- !benchmark @end precond_aux
@[reducible, simp]
def IsPalindrome_precond (x : List Char) : Prop :=
-- !benchmark @start precond
True
-- !benchmark @end precond
-- !benchmark @start code_aux
def isPalindromeHelper (x : List Char) (i j : Nat) : Bool :=
if i < j then
match x[i]?, x[j]? with
| some ci, some cj =>
if ci ≠ cj then false else isPalindromeHelper x (i + 1) (j - 1)
| _, _ => false -- This case should not occur due to valid indices
else true
-- !benchmark @end code_aux
def IsPalindrome (x : List Char) (h_precond : IsPalindrome_precond (x)) : Bool :=
-- !benchmark @start code
if x.length = 0 then true else isPalindromeHelper x 0 (x.length - 1)
-- !benchmark @end code
-- !benchmark @start postcond_aux
-- !benchmark @end postcond_aux
@[reducible, simp]
def IsPalindrome_postcond (x : List Char) (result: Bool) (h_precond : IsPalindrome_precond (x)) :=
-- !benchmark @start postcond
result ↔ ∀ i : Nat, i < x.length → (x[i]! = x[x.length - i - 1]!)
-- !benchmark @end postcond
-- !benchmark @start proof_aux
-- !benchmark @end proof_aux
theorem IsPalindrome_spec_satisfied (x: List Char) (h_precond : IsPalindrome_precond (x)) :
IsPalindrome_postcond (x) (IsPalindrome (x) h_precond) h_precond := by
-- !benchmark @start proof
sorry
-- !benchmark @end proof
| {
"name": "IsPalindrome",
"parameters": {
"param_name": [
"x"
],
"param_type": [
"List Char"
]
},
"return_type": "Bool"
} | {
"upstream": {
"name": "clover",
"link": "https://github.com/ChuyueSun/Clover",
"task_id": "Clover_is_palindrome",
"student_id": null
}
} | {
"input": [
"{\"x\": \"[]\"}",
"{\"x\": \"['a']\"}",
"{\"x\": \"['a', 'b', 'a']\"}",
"{\"x\": \"['a', 'b', 'c']\"}",
"{\"x\": \"['r', 'a', 'c', 'e', 'c', 'a', 'r']\"}"
],
"expected": [
[
"true"
],
[
"true"
],
[
"true"
],
[
"false"
],
[
"true"
]
],
"unexpected": [
[
"false"
],
[
"false"
],
[
"false"
],
[
"true"
],
[
"false"
]
]
} | {
"input": []
} | basic |
verina_basic_96 | -----Description-----
This task requires swapping two integer values. Given two integers as input, the objective is to produce an output where their order is reversed: the first element of the output corresponds to the second input and the second element corresponds to the first input.
-----Input-----
The input consists of two integers:
• X: An integer value.
• Y: Another integer value.
-----Output-----
The output is a tuple (Int × Int) where:
• The first element is equal to Y.
• The second element is equal to X.
-----Note-----
There are no additional preconditions for this task. The function simply returns a swapped tuple of its two input integers. | -- !benchmark @start import type=solution
-- !benchmark @end import
-- !benchmark @start solution_aux
-- !benchmark @end solution_aux
-- !benchmark @start precond_aux
-- !benchmark @end precond_aux
@[reducible, simp]
def SwapSimultaneous_precond (X : Int) (Y : Int) : Prop :=
-- !benchmark @start precond
True
-- !benchmark @end precond
-- !benchmark @start code_aux
-- !benchmark @end code_aux
def SwapSimultaneous (X : Int) (Y : Int) (h_precond : SwapSimultaneous_precond (X) (Y)) : Int × Int :=
-- !benchmark @start code
(Y, X)
-- !benchmark @end code
-- !benchmark @start postcond_aux
-- !benchmark @end postcond_aux
@[reducible, simp]
def SwapSimultaneous_postcond (X : Int) (Y : Int) (result: Int × Int) (h_precond : SwapSimultaneous_precond (X) (Y)) :=
-- !benchmark @start postcond
result.1 = Y ∧ result.2 = X ∧
(X ≠ Y → result.fst ≠ X ∧ result.snd ≠ Y)
-- !benchmark @end postcond
-- !benchmark @start proof_aux
-- !benchmark @end proof_aux
theorem SwapSimultaneous_spec_satisfied (X: Int) (Y: Int) (h_precond : SwapSimultaneous_precond (X) (Y)) :
SwapSimultaneous_postcond (X) (Y) (SwapSimultaneous (X) (Y) h_precond) h_precond := by
-- !benchmark @start proof
unfold SwapSimultaneous_postcond SwapSimultaneous
simp_all
exact fun a a_1 => a (id (Eq.symm a_1))
-- !benchmark @end proof
| {
"name": "SwapSimultaneous",
"parameters": {
"param_name": [
"X",
"Y"
],
"param_type": [
"Int",
"Int"
]
},
"return_type": "Int × Int"
} | {
"upstream": {
"name": "clover",
"link": "https://github.com/ChuyueSun/Clover",
"task_id": "Clover_swap_sim",
"student_id": null
}
} | {
"input": [
"{\"X\": 3, \"Y\": 4}",
"{\"X\": -10, \"Y\": 20}",
"{\"X\": 0, \"Y\": 0}",
"{\"X\": 123, \"Y\": -456}",
"{\"X\": -1, \"Y\": -2}"
],
"expected": [
[
"(4, 3)"
],
[
"(20, -10)"
],
[
"(0, 0)"
],
[
"(-456, 123)"
],
[
"(-2, -1)"
]
],
"unexpected": [
[
"(3, 4)",
"(3, 3)"
],
[
"(20, -20)",
"(-10, 20)"
],
[
"(0, 1)",
"(1, 0)"
],
[
"(123, -456)",
"(-123, 456)"
],
[
"(-1, -2)",
"(-2, 2)"
]
]
} | {
"input": []
} | basic |
verina_advanced_30 | -----Description-----
This task requires writing a Lean 4 function that computes the length of the longest strictly increasing contiguous subarray in a list of integers. A subarray is a sequence of consecutive elements, and it is strictly increasing if each element is greater than the previous one.
The function should correctly handle empty lists, lists with all equal elements, and long stretches of increasing numbers.
-----Input-----
The input consists of a single list:
nums: A list of integers.
-----Output-----
The output is a natural number:
Returns the length of the longest strictly increasing contiguous subarray. If the list is empty, the function should return 0.
| -- !benchmark @start import type=solution
-- !benchmark @end import
-- !benchmark @start solution_aux
-- !benchmark @end solution_aux
-- !benchmark @start precond_aux
-- !benchmark @end precond_aux
@[reducible]
def longestIncreasingStreak_precond (nums : List Int) : Prop :=
-- !benchmark @start precond
True
-- !benchmark @end precond
-- !benchmark @start code_aux
-- !benchmark @end code_aux
def longestIncreasingStreak (nums : List Int) (h_precond : longestIncreasingStreak_precond (nums)) : Nat :=
-- !benchmark @start code
let rec aux (lst : List Int) (prev : Option Int) (currLen : Nat) (maxLen : Nat) : Nat :=
match lst with
| [] => max currLen maxLen
| x :: xs =>
match prev with
| none => aux xs (some x) 1 (max 1 maxLen)
| some p =>
if x > p then aux xs (some x) (currLen + 1) (max (currLen + 1) maxLen)
else aux xs (some x) 1 (max currLen maxLen)
aux nums none 0 0
-- !benchmark @end code
-- !benchmark @start postcond_aux
-- !benchmark @end postcond_aux
@[reducible]
def longestIncreasingStreak_postcond (nums : List Int) (result: Nat) (h_precond : longestIncreasingStreak_precond (nums)) : Prop :=
-- !benchmark @start postcond
-- Case 1: Empty list means result = 0
(nums = [] → result = 0) ∧
-- Case 2: If result > 0, there exists a streak of exactly that length
(result > 0 →
(List.range (nums.length - result + 1) |>.any (fun start =>
-- Check bounds are valid
start + result ≤ nums.length ∧
-- Check all consecutive pairs in this streak are increasing
(List.range (result - 1) |>.all (fun i =>
nums[start + i]! < nums[start + i + 1]!)) ∧
-- Check this streak can't be extended left (if possible)
(start = 0 ∨ nums[start - 1]! ≥ nums[start]!) ∧
-- Check this streak can't be extended right (if possible)
(start + result = nums.length ∨ nums[start + result - 1]! ≥ nums[start + result]!)))) ∧
-- Case 3: No streak longer than result exists
(List.range (nums.length - result) |>.all (fun start =>
List.range result |>.any (fun i =>
start + i + 1 ≥ nums.length ∨ nums[start + i]! ≥ nums[start + i + 1]!)))
-- !benchmark @end postcond
-- !benchmark @start proof_aux
-- !benchmark @end proof_aux
theorem longestIncreasingStreak_spec_satisfied (nums: List Int) (h_precond : longestIncreasingStreak_precond (nums)) :
longestIncreasingStreak_postcond (nums) (longestIncreasingStreak (nums) h_precond) h_precond := by
-- !benchmark @start proof
sorry
-- !benchmark @end proof
| {
"name": "longestIncreasingStreak",
"parameters": {
"param_name": [
"nums"
],
"param_type": [
"List Int"
]
},
"return_type": "Nat"
} | {
"upstream": {
"name": "lab_assignment",
"link": "https://leetcode.com/problems/longest-increasing-subsequence/description/",
"task_id": "lab_longestIncreasingStreak_324801033",
"student_id": [
24
]
}
} | {
"input": [
"{\"nums\": \"[1, 2, 3, 2, 4, 5, 6]\"}",
"{\"nums\": \"[10, 20, 30, 40]\"}",
"{\"nums\": \"[5, 5, 5, 5]\"}",
"{\"nums\": \"[10, 9, 8, 7]\"}",
"{\"nums\": \"[]\"}",
"{\"nums\": \"[1, 2, 1, 2, 3, 0, 1, 2, 3, 4]\"}"
],
"expected": [
[
"4"
],
[
"4"
],
[
"1"
],
[
"1"
],
[
"0"
],
[
"5"
]
],
"unexpected": [
[
"3",
"5"
],
[
"3"
],
[
"0",
"2"
],
[
"0",
"2"
],
[
"1"
],
[
"4"
]
]
} | {
"input": []
} | advanced |
verina_basic_91 | -----Description-----
This task involves creating a function that swaps two integer values. Given two integers, the function should return a pair where the first element is the second input value and the second element is the first input value.
-----Input-----
The input consists of two integers:
• X: An integer representing the first value.
• Y: An integer representing the second value.
-----Output-----
The output is a pair (Int × Int) that:
• Contains the original Y as the first element.
• Contains the original X as the second element.
-----Note-----
There are no additional preconditions. The function simply swaps the two input values. | -- !benchmark @start import type=solution
-- !benchmark @end import
-- !benchmark @start solution_aux
-- !benchmark @end solution_aux
-- !benchmark @start precond_aux
-- !benchmark @end precond_aux
@[reducible, simp]
def Swap_precond (X : Int) (Y : Int) : Prop :=
-- !benchmark @start precond
True
-- !benchmark @end precond
-- !benchmark @start code_aux
-- !benchmark @end code_aux
def Swap (X : Int) (Y : Int) (h_precond : Swap_precond (X) (Y)) : Int × Int :=
-- !benchmark @start code
let x := X
let y := Y
let tmp := x
let x := y
let y := tmp
(x, y)
-- !benchmark @end code
-- !benchmark @start postcond_aux
-- !benchmark @end postcond_aux
@[reducible, simp]
def Swap_postcond (X : Int) (Y : Int) (result: Int × Int) (h_precond : Swap_precond (X) (Y)) :=
-- !benchmark @start postcond
result.fst = Y ∧ result.snd = X ∧
(X ≠ Y → result.fst ≠ X ∧ result.snd ≠ Y)
-- !benchmark @end postcond
-- !benchmark @start proof_aux
-- !benchmark @end proof_aux
theorem Swap_spec_satisfied (X: Int) (Y: Int) (h_precond : Swap_precond (X) (Y)) :
Swap_postcond (X) (Y) (Swap (X) (Y) h_precond) h_precond := by
-- !benchmark @start proof
unfold Swap_postcond Swap
simp_all
exact fun a a_1 => a (id (Eq.symm a_1))
-- !benchmark @end proof
| {
"name": "Swap",
"parameters": {
"param_name": [
"X",
"Y"
],
"param_type": [
"Int",
"Int"
]
},
"return_type": "Int × Int"
} | {
"upstream": {
"name": "clover",
"link": "https://github.com/ChuyueSun/Clover",
"task_id": "Clover_swap",
"student_id": null
}
} | {
"input": [
"{\"X\": 1, \"Y\": 2}",
"{\"X\": 0, \"Y\": 0}",
"{\"X\": -1, \"Y\": 5}",
"{\"X\": 100, \"Y\": -100}",
"{\"X\": 42, \"Y\": 42}"
],
"expected": [
[
"(2, 1)"
],
[
"(0, 0)"
],
[
"(5, -1)"
],
[
"(-100, 100)"
],
[
"(42, 42)"
]
],
"unexpected": [
[
"(1, 2)",
"(2, 2)"
],
[
"(0, 1)",
"(1, 0)"
],
[
"(-1, 5)",
"(5, 5)"
],
[
"(100, -100)",
"(-100, -100)"
],
[
"(41, 42)",
"(42, 41)"
]
]
} | {
"input": []
} | basic |
verina_basic_3 | -----Description-----
This task requires writing a Lean 4 method that determines whether a given integer is divisible by 11. The method should return true if the number is divisible by 11 and false otherwise.
-----Input-----
The input consists of:
n: An integer to check for divisibility by 11.
-----Output-----
The output is a Boolean value:
Returns true if the input number is divisible by 11.
Returns false if the input number is not divisible by 11. | -- !benchmark @start import type=solution
import Mathlib
-- !benchmark @end import
-- !benchmark @start solution_aux
-- !benchmark @end solution_aux
-- !benchmark @start precond_aux
-- !benchmark @end precond_aux
@[reducible, simp]
def isDivisibleBy11_precond (n : Int) : Prop :=
-- !benchmark @start precond
True
-- !benchmark @end precond
-- !benchmark @start code_aux
-- !benchmark @end code_aux
def isDivisibleBy11 (n : Int) (h_precond : isDivisibleBy11_precond (n)) : Bool :=
-- !benchmark @start code
n % 11 == 0
-- !benchmark @end code
-- !benchmark @start postcond_aux
-- !benchmark @end postcond_aux
@[reducible, simp]
def isDivisibleBy11_postcond (n : Int) (result: Bool) (h_precond : isDivisibleBy11_precond (n)) :=
-- !benchmark @start postcond
(result → (∃ k : Int, n = 11 * k)) ∧ (¬ result → (∀ k : Int, ¬ n = 11 * k))
-- !benchmark @end postcond
-- !benchmark @start proof_aux
-- !benchmark @end proof_aux
theorem isDivisibleBy11_spec_satisfied (n: Int) (h_precond : isDivisibleBy11_precond (n)) :
isDivisibleBy11_postcond (n) (isDivisibleBy11 (n) h_precond) h_precond := by
-- !benchmark @start proof
unfold isDivisibleBy11 isDivisibleBy11_postcond
constructor
· simp_all
exact fun a => a
· apply Not.imp_symm
rw [not_forall_not]
intro h
rw [beq_iff_eq]
exact Int.emod_eq_zero_of_dvd h
-- !benchmark @end proof
| {
"name": "isDivisibleBy11",
"parameters": {
"param_name": [
"n"
],
"param_type": [
"Int"
]
},
"return_type": "Bool"
} | {
"upstream": {
"name": "dafny-synthesis",
"link": "https://github.com/Mondego/dafny-synthesis",
"task_id": "task_id_77",
"student_id": null
}
} | {
"input": [
"{\"n\": 0}",
"{\"n\": 11}",
"{\"n\": 22}",
"{\"n\": 23}",
"{\"n\": 33}",
"{\"n\": 44}",
"{\"n\": -11}",
"{\"n\": -22}",
"{\"n\": 1}",
"{\"n\": -1}",
"{\"n\": 121}",
"{\"n\": 123}"
],
"expected": [
[
"True"
],
[
"True"
],
[
"True"
],
[
"False"
],
[
"True"
],
[
"True"
],
[
"True"
],
[
"True"
],
[
"False"
],
[
"False"
],
[
"True"
],
[
"False"
]
],
"unexpected": [
[
"False"
],
[
"False"
],
[
"False"
],
[
"True"
],
[
"False"
],
[
"False"
],
[
"False"
],
[
"False"
],
[
"True"
],
[
"True"
],
[
"False"
],
[
"True"
]
]
} | {
"input": []
} | basic |
verina_basic_32 | -----Description-----
This task requires writing a Lean 4 method that swaps the first and last elements of an array of integers. The method should produce a new array where the first element of the output is the last element of the input, the last element of the output is the first element of the input, and all other elements remain in their original positions.
-----Input-----
The input consists of:
a: An array of integers (assumed to be non-empty).
-----Output-----
The output is an array of integers:
Returns a new array where:
- The former last element becomes the first element.
- The former first element becomes the last element.
- All other elements remain unchanged. | -- !benchmark @start import type=solution
import Mathlib
-- !benchmark @end import
-- !benchmark @start import type=llm
-- !benchmark @end import
-- !benchmark @start import type=test
-- !benchmark @end import
-- !benchmark @start solution_aux
-- !benchmark @end solution_aux
-- !benchmark @start precond_aux
-- !benchmark @end precond_aux
def swapFirstAndLast_precond (a : Array Int) : Prop :=
-- !benchmark @start precond
a.size > 0
-- !benchmark @end precond
-- !benchmark @start code_aux
-- !benchmark @end code_aux
def swapFirstAndLast (a : Array Int) (h_precond: swapFirstAndLast_precond a) : Array Int :=
-- !benchmark @start code
let first := a[0]!
let last := a[a.size - 1]!
a.set! 0 last |>.set! (a.size - 1) first
-- !benchmark @end code
-- !benchmark @start postcond_aux
-- !benchmark @end postcond_aux
-- Theorem: The last element of the input array should be the first element of the modified array; The first element of the input array should be the last element of the modified array; All other elements remain unchanged
@[reducible, simp]
def swapFirstAndLast_postcond (a : Array Int) (result : Array Int) (h_precond: swapFirstAndLast_precond a) : Prop :=
-- !benchmark @start postcond
result.size = a.size ∧
result[0]! = a[a.size - 1]! ∧
result[result.size - 1]! = a[0]! ∧
(List.range (result.size - 2)).all (fun i => result[i + 1]! = a[i + 1]!)
-- !benchmark @end postcond
-- !benchmark @start proof_aux
-- !benchmark @end proof_aux
theorem swapFirstAndLast_spec_satisfied (a : Array Int) (h_precond: swapFirstAndLast_precond a) :
swapFirstAndLast_postcond a (swapFirstAndLast a h_precond) h_precond := by
-- !benchmark @start proof
unfold swapFirstAndLast swapFirstAndLast_postcond
unfold swapFirstAndLast_precond at h_precond
simp_all
-- have ha : 0 < a.toList.length := by simp [h_precond]
constructor
· simp [Array.getElem!_eq_getD]
rw [← Array.getElem?_toList, ← Array.getElem?_toList]
simp
rw [List.getElem?_set]
cases ha' : a.size with
| zero => simp_all
| succ n =>
cases hn : n with
| zero =>
simp [h_precond]
| succ n' => simp_all
· constructor
· simp_all [Array.getElem!_eq_getD]
· intro i hi
simp [Array.getElem!_eq_getD]
rw [← Array.getElem?_toList, ← Array.getElem?_toList]
simp
rw [List.getElem?_set, List.length_set]
simp_all
have : i + 2 < a.size := by
exact Nat.add_lt_of_lt_sub hi
have : a.size ≠ i + 2 := by
exact Ne.symm (Nat.ne_of_lt this)
simp [this]
-- !benchmark @end proof
| {
"name": "swapFirstAndLast",
"parameters": {
"param_name": [
"a"
],
"param_type": [
"Array Int"
]
},
"return_type": "Array Int"
} | {
"upstream": {
"name": "dafny-synthesis",
"link": "https://github.com/Mondego/dafny-synthesis",
"task_id": "task_id_625",
"student_id": null
}
} | {
"input": [
"{\"a\": \"#[1, 2, 3, 4, 5]\"}",
"{\"a\": \"#[10]\"}",
"{\"a\": \"#[1, 2]\"}",
"{\"a\": \"#[1, 2, 3]\"}"
],
"expected": [
[
"#[5, 2, 3, 4, 1]"
],
[
"#[10]"
],
[
"#[2, 1]"
],
[
"#[3, 2, 1]"
]
],
"unexpected": [
[
"#[1, 2, 3, 4, 5]",
"#[5, 4, 3, 2, 1]",
"#[2, 3, 4, 5, 1]"
],
[
"#[0]",
"#[5]",
"#[11]"
],
[
"#[1, 2]",
"#[2, 2]",
"#[1, 1]"
],
[
"#[1, 2, 3]",
"#[3, 1, 2]",
"#[2, 1, 3]"
]
]
} | {
"input": [
"{'a': '#[]'}"
]
} | basic |
verina_basic_86 | -----Description-----
This task requires writing a Lean 4 method that rotates an array of integers to the left by a specified offset.
-----Input-----
The input consists of:
• a: An array of integers (which may be empty or non-empty).
• offset: An integer representing the number of positions to rotate the array. The offset is assumed to be non-negative.
-----Output-----
The output is an array of integers that:
• Has the same length as the input array.
• For every valid index i, the output element at index i is equal to the input element at index ((i + offset) mod n), where n is the array size.
-----Note-----
If the array is empty, the method should return an empty array. | -- !benchmark @start import type=solution
-- !benchmark @end import
-- !benchmark @start solution_aux
-- !benchmark @end solution_aux
-- !benchmark @start precond_aux
-- !benchmark @end precond_aux
@[reducible, simp]
def rotate_precond (a : Array Int) (offset : Int) : Prop :=
-- !benchmark @start precond
offset ≥ 0
-- !benchmark @end precond
-- !benchmark @start code_aux
def rotateAux (a : Array Int) (offset : Int) (i : Nat) (len : Nat) (b : Array Int) : Array Int :=
if i < len then
let idx_int : Int := (Int.ofNat i + offset) % (Int.ofNat len)
let idx_int_adjusted := if idx_int < 0 then idx_int + Int.ofNat len else idx_int
let idx_nat : Nat := Int.toNat idx_int_adjusted
let new_b := b.set! i (a[idx_nat]!)
rotateAux a offset (i + 1) len new_b
else b
-- !benchmark @end code_aux
def rotate (a : Array Int) (offset : Int) (h_precond : rotate_precond (a) (offset)) : Array Int :=
-- !benchmark @start code
let len := a.size
let default_val : Int := if len > 0 then a[0]! else 0
let b0 := Array.mkArray len default_val
rotateAux a offset 0 len b0
-- !benchmark @end code
-- !benchmark @start postcond_aux
-- !benchmark @end postcond_aux
@[reducible, simp]
def rotate_postcond (a : Array Int) (offset : Int) (result: Array Int) (h_precond : rotate_precond (a) (offset)) :=
-- !benchmark @start postcond
result.size = a.size ∧
(∀ i : Nat, i < a.size →
result[i]! = a[Int.toNat ((Int.ofNat i + offset) % (Int.ofNat a.size))]!)
-- !benchmark @end postcond
-- !benchmark @start proof_aux
-- !benchmark @end proof_aux
theorem rotate_spec_satisfied (a: Array Int) (offset: Int) (h_precond : rotate_precond (a) (offset)) :
rotate_postcond (a) (offset) (rotate (a) (offset) h_precond) h_precond := by
-- !benchmark @start proof
sorry
-- !benchmark @end proof
| {
"name": "rotate",
"parameters": {
"param_name": [
"a",
"offset"
],
"param_type": [
"Array Int",
"Int"
]
},
"return_type": "Array Int"
} | {
"upstream": {
"name": "clover",
"link": "https://github.com/ChuyueSun/Clover",
"task_id": "Clover_rotate",
"student_id": null
}
} | {
"input": [
"{\"a\": \"#[1, 2, 3, 4, 5]\", \"offset\": 2}",
"{\"a\": \"#[10, 20, 30, 40]\", \"offset\": 1}",
"{\"a\": \"#[]\", \"offset\": 5}",
"{\"a\": \"#[7]\", \"offset\": 0}",
"{\"a\": \"#[-1, -2, -3, -4]\", \"offset\": 3}",
"{\"a\": \"#[5, 10, 15]\", \"offset\": 5}"
],
"expected": [
[
"#[3, 4, 5, 1, 2]"
],
[
"#[20, 30, 40, 10]"
],
[
"#[]"
],
[
"#[7]"
],
[
"#[-4, -1, -2, -3]"
],
[
"#[15, 5, 10]"
]
],
"unexpected": [
[
"#[1, 2, 3, 4, 5]",
"#[2, 3, 4, 5, 1]"
],
[
"#[10, 20, 30, 40]",
"#[40, 10, 20, 30]"
],
[
"#[0]",
"#[1]"
],
[
"#[0]",
"#[8]"
],
[
"#[-1, -2, -3, -4]",
"#[-3, -4, -1, -2]"
],
[
"#[5, 10, 15]",
"#[10, 15, 5]"
]
]
} | {
"input": [
"{'a': '#[1, 2, 3, 4, 5]', 'offset': -1}"
]
} | basic |
verina_basic_99 | -----Description-----
This task requires computing three times the given integer. The goal is to determine the product of the input integer and 3.
-----Input-----
The input consists of:
• x: An integer.
-----Output-----
The output is an integer that represents three times the input value.
-----Note-----
The implementation uses two different branches based on the value of x (i.e., x < 18 or x ≥ 18), but both branches guarantee that the result equals 3*x. | -- !benchmark @start import type=solution
import Mathlib
-- !benchmark @end import
-- !benchmark @start solution_aux
-- !benchmark @end solution_aux
-- !benchmark @start precond_aux
-- !benchmark @end precond_aux
@[reducible, simp]
def Triple_precond (x : Int) : Prop :=
-- !benchmark @start precond
True
-- !benchmark @end precond
-- !benchmark @start code_aux
-- !benchmark @end code_aux
def Triple (x : Int) (h_precond : Triple_precond (x)) : Int :=
-- !benchmark @start code
if x < 18 then
let a := 2 * x
let b := 4 * x
(a + b) / 2
else
let y := 2 * x
x + y
-- !benchmark @end code
-- !benchmark @start postcond_aux
-- !benchmark @end postcond_aux
@[reducible, simp]
def Triple_postcond (x : Int) (result: Int) (h_precond : Triple_precond (x)) :=
-- !benchmark @start postcond
result / 3 = x ∧ result / 3 * 3 = result
-- !benchmark @end postcond
-- !benchmark @start proof_aux
-- !benchmark @end proof_aux
theorem Triple_spec_satisfied (x: Int) (h_precond : Triple_precond (x)) :
Triple_postcond (x) (Triple (x) h_precond) h_precond := by
-- !benchmark @start proof
unfold Triple_postcond Triple
simp
split_ifs with h₁
. rw [←Int.add_mul]
simp
have h : (6: ℤ) = 3 * 2 := by simp
rw [h, Int.mul_comm, Int.mul_ediv_assoc, Int.mul_ediv_assoc]
simp
rw [Int.mul_comm]
rfl
simp
. rw (occs := [1]) [←Int.one_mul x]
rw [←Int.add_mul]
simp +arith
-- !benchmark @end proof
| {
"name": "Triple",
"parameters": {
"param_name": [
"x"
],
"param_type": [
"Int"
]
},
"return_type": "Int"
} | {
"upstream": {
"name": "clover",
"link": "https://github.com/ChuyueSun/Clover",
"task_id": "Clover_triple2",
"student_id": null
}
} | {
"input": [
"{\"x\": 10}",
"{\"x\": 18}",
"{\"x\": 0}",
"{\"x\": -5}",
"{\"x\": 25}"
],
"expected": [
[
"30"
],
[
"54"
],
[
"0"
],
[
"-15"
],
[
"75"
]
],
"unexpected": [
[
"20",
"25",
"35"
],
[
"50",
"56",
"60"
],
[
"1",
"-1",
"5"
],
[
"-10",
"-20",
"0"
],
[
"70",
"80",
"65"
]
]
} | {
"input": []
} | basic |
verina_basic_107 | -----Description-----
This task involves computing the average of two integers. The objective is to determine a value that closely approximates the true arithmetic mean when using integer division, ensuring that the result reflects the necessary rounding behavior.
-----Input-----
The input consists of:
• a: An integer.
• b: An integer.
-----Output-----
The output is an integer representing the computed average of a and b using integer division.
-----Note-----
The specification requires that the computed average satisfies the condition that 2 * avg is between (a + b - 1) and (a + b + 1), ensuring that the result meets the expected rounding boundaries. | -- !benchmark @start import type=solution
-- !benchmark @end import
-- !benchmark @start solution_aux
-- !benchmark @end solution_aux
-- !benchmark @start precond_aux
-- !benchmark @end precond_aux
@[reducible, simp]
def ComputeAvg_precond (a : Int) (b : Int) : Prop :=
-- !benchmark @start precond
True
-- !benchmark @end precond
-- !benchmark @start code_aux
-- !benchmark @end code_aux
def ComputeAvg (a : Int) (b : Int) (h_precond : ComputeAvg_precond (a) (b)) : Int :=
-- !benchmark @start code
(a + b) / 2
-- !benchmark @end code
-- !benchmark @start postcond_aux
-- !benchmark @end postcond_aux
@[reducible, simp]
def ComputeAvg_postcond (a : Int) (b : Int) (result: Int) (h_precond : ComputeAvg_precond (a) (b)) :=
-- !benchmark @start postcond
2 * result = a + b - ((a + b) % 2)
-- !benchmark @end postcond
-- !benchmark @start proof_aux
-- !benchmark @end proof_aux
theorem ComputeAvg_spec_satisfied (a: Int) (b: Int) (h_precond : ComputeAvg_precond (a) (b)) :
ComputeAvg_postcond (a) (b) (ComputeAvg (a) (b) h_precond) h_precond := by
-- !benchmark @start proof
sorry
-- !benchmark @end proof
| {
"name": "ComputeAvg",
"parameters": {
"param_name": [
"a",
"b"
],
"param_type": [
"Int",
"Int"
]
},
"return_type": "Int"
} | {
"upstream": {
"name": "clover",
"link": "https://github.com/ChuyueSun/Clover",
"task_id": "Clover_avg",
"student_id": null
}
} | {
"input": [
"{\"a\": 4, \"b\": 6}",
"{\"a\": 3, \"b\": 5}",
"{\"a\": 3, \"b\": 4}",
"{\"a\": -3, \"b\": 7}",
"{\"a\": -5, \"b\": 5}"
],
"expected": [
[
"5"
],
[
"4"
],
[
"3"
],
[
"2"
],
[
"0"
]
],
"unexpected": [
[
"4",
"6",
"7"
],
[
"3",
"5",
"6"
],
[
"2",
"4",
"5"
],
[
"1",
"3",
"0"
],
[
"1",
"-1",
"2"
]
]
} | {
"input": []
} | basic |
verina_advanced_5 | -----Description-----
This task requires writing a Lean 4 method that adds two non-empty linked lists representing non-negative integers.
The digits are stored in reverse order (i.e., the first element is the least significant digit).
Each node (list element) holds a single digit (ranging from 0 to 9). The function should add the two numbers and return the sum
as a linked list, also in reverse order.
-----Input-----
The input consists of:
- l1: A list of natural numbers representing the digits of the first number in reverse order.
- l2: A list of natural numbers representing the digits of the second number in reverse order.
-----Output-----
The output is a list of natural numbers:
Returns a list of digits (in reverse order) representing the sum of the two input numbers.
| -- !benchmark @start import type=solution
-- !benchmark @end import
-- !benchmark @start solution_aux
def listToNat : List Nat → Nat
| [] => 0
| d :: ds => d + 10 * listToNat ds
-- !benchmark @end solution_aux
-- !benchmark @start precond_aux
-- !benchmark @end precond_aux
@[reducible]
def addTwoNumbers_precond (l1 : List Nat) (l2 : List Nat) : Prop :=
-- !benchmark @start precond
l1.length > 0 ∧ l2.length > 0 ∧
(∀ d ∈ l1, d < 10) ∧ (∀ d ∈ l2, d < 10) ∧
(l1.getLast! ≠ 0 ∨ l1 = [0]) ∧
(l2.getLast! ≠ 0 ∨ l2 = [0])
-- !benchmark @end precond
-- !benchmark @start code_aux
-- !benchmark @end code_aux
def addTwoNumbers (l1 : List Nat) (l2 : List Nat) (h_precond : addTwoNumbers_precond (l1) (l2)) : List Nat :=
-- !benchmark @start code
let rec addAux (l1 l2 : List Nat) (carry : Nat) : List Nat :=
match l1, l2 with
| [], [] =>
if carry = 0 then [] else [carry]
| h1::t1, [] =>
let sum := h1 + carry
(sum % 10) :: addAux t1 [] (sum / 10)
| [], h2::t2 =>
let sum := h2 + carry
(sum % 10) :: addAux [] t2 (sum / 10)
| h1::t1, h2::t2 =>
let sum := h1 + h2 + carry
(sum % 10) :: addAux t1 t2 (sum / 10)
addAux l1 l2 0
-- !benchmark @end code
-- !benchmark @start postcond_aux
-- !benchmark @end postcond_aux
@[reducible]
def addTwoNumbers_postcond (l1 : List Nat) (l2 : List Nat) (result: List Nat) (h_precond : addTwoNumbers_precond (l1) (l2)) : Prop :=
-- !benchmark @start postcond
listToNat result = listToNat l1 + listToNat l2 ∧
(∀ d ∈ result, d < 10) ∧
-- No leading zeros unless the result is zero
(result.getLast! ≠ 0 ∨ (l1 = [0] ∧ l2 = [0] ∧ result = [0]))
-- !benchmark @end postcond
-- !benchmark @start proof_aux
-- !benchmark @end proof_aux
theorem addTwoNumbers_spec_satisfied (l1: List Nat) (l2: List Nat) (h_precond : addTwoNumbers_precond (l1) (l2)) :
addTwoNumbers_postcond (l1) (l2) (addTwoNumbers (l1) (l2) h_precond) h_precond := by
-- !benchmark @start proof
sorry
-- !benchmark @end proof
| {
"name": "addTwoNumbers",
"parameters": {
"param_name": [
"l1",
"l2"
],
"param_type": [
"List Nat",
"List Nat"
]
},
"return_type": "List Nat"
} | {
"upstream": {
"name": "lab_assignment",
"link": "https://leetcode.com/problems/add-two-numbers/description/",
"task_id": "lab_addTwoNumbers_324428059",
"student_id": [
3
]
}
} | {
"input": [
"{\"l1\": \"[2,4,3]\", \"l2\": \"[5,6,4]\"}",
"{\"l1\": \"[0]\", \"l2\": \"[0]\"}",
"{\"l1\": \"[9,9,9,9,9,9,9]\", \"l2\": \"[9,9,9,9]\"}",
"{\"l1\": \"[1,2,3]\", \"l2\": \"[4,5]\"}"
],
"expected": [
[
"[7,0,8]"
],
[
"[0]"
],
[
"[8,9,9,9,0,0,0,1]"
],
[
"[5,7,3]"
]
],
"unexpected": [
[
"[2,4,3]",
"[0]"
],
[
"[0,0]"
],
[
"[9,9,9,9,9,9,9,9]"
],
[
"[5,7]",
"[5,7,4]"
]
]
} | {
"input": [
"{'l1': '[]', 'l2': '[]'}",
"{'l1': '[0, 0]', 'l2': '[0, 0]'}"
]
} | advanced |
verina_basic_101 | -----Description-----
This problem involves computing the triple of a given integer. The goal is to produce an output that is exactly three times the input value.
-----Input-----
The input consists of:
• x: An integer representing the value to be tripled.
-----Output-----
The output is an integer that is three times the input value (i.e., 3 * x).
-----Note-----
The implementation uses a local variable to first compute double the input and then adds the original input to get the final result. The accompanying theorem asserts that the function satisfies the specification of computing 3 * x. | -- !benchmark @start import type=solution
-- !benchmark @end import
-- !benchmark @start solution_aux
-- !benchmark @end solution_aux
-- !benchmark @start precond_aux
-- !benchmark @end precond_aux
@[reducible, simp]
def Triple_precond (x : Int) : Prop :=
-- !benchmark @start precond
True
-- !benchmark @end precond
-- !benchmark @start code_aux
-- !benchmark @end code_aux
def Triple (x : Int) (h_precond : Triple_precond (x)) : Int :=
-- !benchmark @start code
let y := x * 2
y + x
-- !benchmark @end code
-- !benchmark @start postcond_aux
-- !benchmark @end postcond_aux
@[reducible, simp]
def Triple_postcond (x : Int) (result: Int) (h_precond : Triple_precond (x)) :=
-- !benchmark @start postcond
result / 3 = x ∧ result / 3 * 3 = result
-- !benchmark @end postcond
-- !benchmark @start proof_aux
-- !benchmark @end proof_aux
theorem Triple_spec_satisfied (x: Int) (h_precond : Triple_precond (x)) :
Triple_postcond (x) (Triple (x) h_precond) h_precond := by
-- !benchmark @start proof
unfold Triple_postcond Triple
simp
rw (occs := [2]) [←Int.mul_one x]
rw [←Int.mul_add]
simp +arith
-- !benchmark @end proof
| {
"name": "Triple",
"parameters": {
"param_name": [
"x"
],
"param_type": [
"Int"
]
},
"return_type": "Int"
} | {
"upstream": {
"name": "clover",
"link": "https://github.com/ChuyueSun/Clover",
"task_id": "Clover_triple4",
"student_id": null
}
} | {
"input": [
"{\"x\": 0}",
"{\"x\": 1}",
"{\"x\": -1}",
"{\"x\": 5}",
"{\"x\": -10}"
],
"expected": [
[
"0"
],
[
"3"
],
[
"-3"
],
[
"15"
],
[
"-30"
]
],
"unexpected": [
[
"1",
"-1",
"2"
],
[
"2",
"4",
"5"
],
[
"-2",
"0",
"-1"
],
[
"14",
"16",
"10"
],
[
"-20",
"-40",
"-10"
]
]
} | {
"input": []
} | basic |
verina_advanced_41 | -----Description-----
This task requires writing a Lean 4 method that finds the maximum among three given integers. The method should return the largest value, ensuring that the result is greater than or equal to each of the input numbers and that it is one of the provided integers.
-----Input-----
The input consists of three integers:
a: The first integer.
b: The second integer.
c: The third integer.
-----Output-----
The output is an integer:
Returns the maximum of the three input numbers, assuring that the returned value is greater than or equal to a, b, and c, and that it matches one of these values.
| -- !benchmark @start import type=solution
-- !benchmark @end import
-- !benchmark @start solution_aux
-- !benchmark @end solution_aux
-- !benchmark @start precond_aux
-- !benchmark @end precond_aux
@[reducible]
def maxOfThree_precond (a : Int) (b : Int) (c : Int) : Prop :=
-- !benchmark @start precond
True
-- !benchmark @end precond
-- !benchmark @start code_aux
-- !benchmark @end code_aux
def maxOfThree (a : Int) (b : Int) (c : Int) (h_precond : maxOfThree_precond (a) (b) (c)) : Int :=
-- !benchmark @start code
if a >= b && a >= c then a
else if b >= a && b >= c then b
else c
-- !benchmark @end code
-- !benchmark @start postcond_aux
-- !benchmark @end postcond_aux
@[reducible]
def maxOfThree_postcond (a : Int) (b : Int) (c : Int) (result: Int) (h_precond : maxOfThree_precond (a) (b) (c)) : Prop :=
-- !benchmark @start postcond
(result >= a ∧ result >= b ∧ result >= c) ∧ (result = a ∨ result = b ∨ result = c)
-- !benchmark @end postcond
-- !benchmark @start proof_aux
-- !benchmark @end proof_aux
theorem maxOfThree_spec_satisfied (a: Int) (b: Int) (c: Int) (h_precond : maxOfThree_precond (a) (b) (c)) :
maxOfThree_postcond (a) (b) (c) (maxOfThree (a) (b) (c) h_precond) h_precond := by
-- !benchmark @start proof
sorry
-- !benchmark @end proof
| {
"name": "maxOfThree",
"parameters": {
"param_name": [
"a",
"b",
"c"
],
"param_type": [
"Int",
"Int",
"Int"
]
},
"return_type": "Int"
} | {
"upstream": {
"name": "lab_assignment",
"link": "https://leetcode.com/problems/maximum-product-of-three-numbers/",
"task_id": "lab_maxOfThree_325766147",
"student_id": [
33
]
}
} | {
"input": [
"{\"a\": 3, \"b\": 2, \"c\": 1}",
"{\"a\": 5, \"b\": 5, \"c\": 5}",
"{\"a\": 10, \"b\": 20, \"c\": 15}",
"{\"a\": -1, \"b\": -2, \"c\": -3}",
"{\"a\": 0, \"b\": -10, \"c\": -5}"
],
"expected": [
[
"3"
],
[
"5"
],
[
"20"
],
[
"-1"
],
[
"0"
]
],
"unexpected": [
[
"2",
"1",
"-1"
],
[
"6",
"4"
],
[
"10",
"15"
],
[
"-2",
"-3"
],
[
"-5",
"-10"
]
]
} | {
"input": []
} | advanced |
verina_basic_27 | -----Description-----
This task requires writing a Lean 4 method that identifies the first repeated character in a given string. The method should return a tuple containing a Boolean value and a character. The Boolean value indicates whether any character in the string is repeated. If it is true, the accompanying character is the first character that appears more than once. If it is false, it indicates that there are no repeated characters in the string.
-----Input-----
The input consists of:
s: A string.
-----Output-----
The output is a tuple (Bool × Char):
- Returns true and the first repeated character in the string if any repeated character is found.
- Returns false and an arbitrary character if no repeated characters are present.
-----Note-----
There are no preconditions; the method is expected to work for any non-null string. | -- !benchmark @start import type=solution
import Std.Data.HashSet
-- !benchmark @end import
-- !benchmark @start solution_aux
-- !benchmark @end solution_aux
-- !benchmark @start precond_aux
-- !benchmark @end precond_aux
@[reducible, simp]
def findFirstRepeatedChar_precond (s : String) : Prop :=
-- !benchmark @start precond
True
-- !benchmark @end precond
-- !benchmark @start code_aux
-- !benchmark @end code_aux
def findFirstRepeatedChar (s : String) (h_precond : findFirstRepeatedChar_precond (s)) : Option Char :=
-- !benchmark @start code
let cs := s.toList
let rec loop (i : Nat) (seen : Std.HashSet Char) : Option Char :=
if i < cs.length then
let c := cs[i]!
if seen.contains c then
some c
else
loop (i + 1) (seen.insert c)
else
-- When no repeated char is found, return (false, arbitrary char)
none
loop 0 Std.HashSet.empty
-- !benchmark @end code
-- !benchmark @start postcond_aux
-- !benchmark @end postcond_aux
@[reducible, simp]
def findFirstRepeatedChar_postcond (s : String) (result: Option Char) (h_precond : findFirstRepeatedChar_precond (s)) :=
-- !benchmark @start postcond
let cs := s.toList
match result with
| some c =>
let secondIdx := cs.zipIdx.findIdx (fun (x, i) => x = c && i ≠ cs.idxOf c)
-- Exists repeated char
cs.count c ≥ 2 ∧
-- There is no other repeated char before the found one
List.Pairwise (· ≠ ·) (cs.take secondIdx)
| none =>
-- There is no repeated char
List.Pairwise (· ≠ ·) cs
-- !benchmark @end postcond
-- !benchmark @start proof_aux
-- !benchmark @end proof_aux
theorem findFirstRepeatedChar_spec_satisfied (s: String) (h_precond : findFirstRepeatedChar_precond (s)) :
findFirstRepeatedChar_postcond (s) (findFirstRepeatedChar (s) h_precond) h_precond := by
-- !benchmark @start proof
sorry
-- !benchmark @end proof
| {
"name": "findFirstRepeatedChar",
"parameters": {
"param_name": [
"s"
],
"param_type": [
"String"
]
},
"return_type": "Option Char"
} | {
"upstream": {
"name": "dafny-synthesis",
"link": "https://github.com/Mondego/dafny-synthesis",
"task_id": "task_id_602",
"student_id": null
}
} | {
"input": [
"{\"s\": \"abca\"}",
"{\"s\": \"abcdef\"}",
"{\"s\": \"aabbcc\"}",
"{\"s\": \"\"}",
"{\"s\": \"abbc\"}",
"{\"s\": \"Aa\"}"
],
"expected": [
[
"some ('a')"
],
[
"none"
],
[
"some ('a')"
],
[
"none"
],
[
"some ('b')"
],
[
"none"
]
],
"unexpected": [
[
"some ('b')",
"some ('c')",
"none"
],
[
"some ('a')",
"some ('z')"
],
[
"some ('b')",
"some ('c')",
"none"
],
[
"some ('x')",
"some ('y')"
],
[
"some ('a')",
"some ('c')",
"none"
],
[
"some ('A')",
"some ('a')"
]
]
} | {
"input": []
} | basic |
verina_basic_28 | -----Description-----
This task requires writing a Lean 4 method that determines whether a given natural number is prime. A number (with n ≥ 2) is considered prime if it is divisible only by 1 and itself. The method should return true when the input number is prime and false otherwise.
-----Input-----
The input consists of:
n: A natural number (Nat) such that n ≥ 2.
-----Output-----
The output is a Boolean value:
Returns true if the input number is prime (i.e., there is no integer k with 1 < k < n that divides n).
Returns false if the input number is not prime (i.e., there exists an integer k with 1 < k < n that divides n).
-----Note-----
The input is expected to satisfy the condition n ≥ 2. | -- !benchmark @start import type=solution
-- !benchmark @end import
-- !benchmark @start solution_aux
-- !benchmark @end solution_aux
-- !benchmark @start precond_aux
-- !benchmark @end precond_aux
@[reducible, simp]
def isPrime_precond (n : Nat) : Prop :=
-- !benchmark @start precond
n ≥ 2
-- !benchmark @end precond
-- !benchmark @start code_aux
-- !benchmark @end code_aux
def isPrime (n : Nat) (h_precond : isPrime_precond (n)) : Bool :=
-- !benchmark @start code
let bound := n
let rec check (i : Nat) (fuel : Nat) : Bool :=
if fuel = 0 then true
else if i * i > n then true
else if n % i = 0 then false
else check (i + 1) (fuel - 1)
check 2 bound
-- !benchmark @end code
-- !benchmark @start postcond_aux
-- !benchmark @end postcond_aux
@[reducible, simp]
def isPrime_postcond (n : Nat) (result: Bool) (h_precond : isPrime_precond (n)) :=
-- !benchmark @start postcond
(result → (List.range' 2 (n - 2)).all (fun k => n % k ≠ 0)) ∧
(¬ result → (List.range' 2 (n - 2)).any (fun k => n % k = 0))
-- !benchmark @end postcond
-- !benchmark @start proof_aux
-- !benchmark @end proof_aux
theorem isPrime_spec_satisfied (n: Nat) (h_precond : isPrime_precond (n)) :
isPrime_postcond (n) (isPrime (n) h_precond) h_precond := by
-- !benchmark @start proof
sorry
-- !benchmark @end proof
| {
"name": "isPrime",
"parameters": {
"param_name": [
"n"
],
"param_type": [
"Nat"
]
},
"return_type": "Bool"
} | {
"upstream": {
"name": "dafny-synthesis",
"link": "https://github.com/Mondego/dafny-synthesis",
"task_id": "task_id_605",
"student_id": null
}
} | {
"input": [
"{\"n\": 2}",
"{\"n\": 3}",
"{\"n\": 4}",
"{\"n\": 5}",
"{\"n\": 9}",
"{\"n\": 11}",
"{\"n\": 12}",
"{\"n\": 13}"
],
"expected": [
[
"True"
],
[
"True"
],
[
"False"
],
[
"True"
],
[
"False"
],
[
"True"
],
[
"False"
],
[
"True"
]
],
"unexpected": [
[
"False"
],
[
"False"
],
[
"True"
],
[
"False"
],
[
"True"
],
[
"False"
],
[
"True"
],
[
"False"
]
]
} | {
"input": [
"{'n': 0}"
]
} | basic |
verina_basic_64 | -----Description-----
This task requires writing a Lean 4 method that inserts a subarray of characters into another array of characters at a specified index. The method takes the original array (oline) and, given the effective length l to consider, inserts another array of characters (nl) of effective length p starting at the index atPos. The resulting array is of length l + p and is constructed as follows:
• All characters before the insertion position (atPos) remain unchanged.
• The new characters from nl are inserted starting at index atPos.
• The remaining characters from the original array (starting at atPos) are shifted right by p positions.
-----Input-----
The input consists of:
• oline: An array of characters representing the original sequence.
• l: A natural number indicating how many characters from oline to consider.
• nl: An array of characters to be inserted into oline.
• p: A natural number indicating how many characters from nl to consider for insertion.
• atPos: A natural number indicating the position in oline where the insertion should occur (0-indexed).
-----Output-----
The output is an array of characters that is the result of inserting nl into oline at the given atPos. Specifically, the output array should:
• Contain the original characters from index 0 up to (but not including) atPos.
• Have the next p characters equal to the characters from nl.
• Contain the remaining characters from oline (starting from atPos) shifted right by p positions.
-----Note-----
It is assumed that:
• atPos is within the range [0, l].
• l does not exceed the size of oline.
• p does not exceed the size of nl. | -- !benchmark @start import type=solution
-- !benchmark @end import
-- !benchmark @start solution_aux
-- !benchmark @end solution_aux
-- !benchmark @start precond_aux
-- !benchmark @end precond_aux
@[reducible, simp]
def insert_precond (oline : Array Char) (l : Nat) (nl : Array Char) (p : Nat) (atPos : Nat) : Prop :=
-- !benchmark @start precond
l ≤ oline.size ∧
p ≤ nl.size ∧
atPos ≤ l
-- !benchmark @end precond
-- !benchmark @start code_aux
-- !benchmark @end code_aux
def insert (oline : Array Char) (l : Nat) (nl : Array Char) (p : Nat) (atPos : Nat) (h_precond : insert_precond (oline) (l) (nl) (p) (atPos)) : Array Char :=
-- !benchmark @start code
let result := Array.mkArray (l + p) ' '
let result := Array.foldl
(fun acc i =>
if i < atPos then acc.set! i (oline[i]!) else acc)
result
(Array.range l)
let result := Array.foldl
(fun acc i =>
acc.set! (atPos + i) (nl[i]!))
result
(Array.range p)
let result := Array.foldl
(fun acc i =>
if i >= atPos then acc.set! (i + p) (oline[i]!) else acc)
result
(Array.range l)
result
-- !benchmark @end code
-- !benchmark @start postcond_aux
-- !benchmark @end postcond_aux
@[reducible, simp]
def insert_postcond (oline : Array Char) (l : Nat) (nl : Array Char) (p : Nat) (atPos : Nat) (result: Array Char) (h_precond : insert_precond (oline) (l) (nl) (p) (atPos)) :=
-- !benchmark @start postcond
result.size = l + p ∧
(List.range p).all (fun i => result[atPos + i]! = nl[i]!) ∧
(List.range atPos).all (fun i => result[i]! = oline[i]!) ∧
(List.range (l - atPos)).all (fun i => result[atPos + p + i]! = oline[atPos + i]!)
-- !benchmark @end postcond
-- !benchmark @start proof_aux
-- !benchmark @end proof_aux
theorem insert_spec_satisfied (oline: Array Char) (l: Nat) (nl: Array Char) (p: Nat) (atPos: Nat) (h_precond : insert_precond (oline) (l) (nl) (p) (atPos)) :
insert_postcond (oline) (l) (nl) (p) (atPos) (insert (oline) (l) (nl) (p) (atPos) h_precond) h_precond := by
-- !benchmark @start proof
sorry
-- !benchmark @end proof
| {
"name": "insert",
"parameters": {
"param_name": [
"oline",
"l",
"nl",
"p",
"atPos"
],
"param_type": [
"Array Char",
"Nat",
"Array Char",
"Nat",
"Nat"
]
},
"return_type": "Array Char"
} | {
"upstream": {
"name": "clover",
"link": "https://github.com/ChuyueSun/Clover",
"task_id": "Clover_insert",
"student_id": null
}
} | {
"input": [
"{\"oline\": \"#['a','b','c','d','e']\", \"l\": 5, \"nl\": \"#['X','Y']\", \"p\": 2, \"atPos\": 2}",
"{\"oline\": \"#['H','e','l','l','o']\", \"l\": 5, \"nl\": \"#['W','o','r','l','d']\", \"p\": 5, \"atPos\": 0}",
"{\"oline\": \"#['L','e','a','n']\", \"l\": 4, \"nl\": \"#['4']\", \"p\": 1, \"atPos\": 4}",
"{\"oline\": \"#['T','e','s','t']\", \"l\": 4, \"nl\": \"#[]\", \"p\": 0, \"atPos\": 2}",
"{\"oline\": \"#['1','2','3','4','5','6']\", \"l\": 5, \"nl\": \"#['a','b','c']\", \"p\": 3, \"atPos\": 3}"
],
"expected": [
[
"#['a','b','X','Y','c','d','e']"
],
[
"#['W','o','r','l','d','H','e','l','l','o']"
],
[
"#['L','e','a','n','4']"
],
[
"#['T','e','s','t']"
],
[
"#['1','2','3','a','b','c','4','5']"
]
],
"unexpected": [
[
"#['a','b','X','Y','c','d']",
"#['a','b','X','Y','c','d','f']",
"#['a','X','b','Y','c','d','e']"
],
[
"#['H','e','l','l','o','W','o','r','l','d']",
"#['W','o','r','l','d','H','e','l','l','o','!']",
"#['W','o','r','l','d','W','o','r','l','d']"
],
[
"#['L','e','a','n']",
"#['L','e','a','n',' ']",
"#['4','L','e','a','n']"
],
[
"#['T','e','s']",
"#['T','s','t','e']",
"#['t','e','s','T']"
],
[
"#['1','2','3','a','b','c','4','5','6']",
"#['1','2','3','4','a','b','c','5','6']",
"#['1','2','3','a','b','4','c','5','6']"
]
]
} | {
"input": [
"{'oline': \"#['a','b','c']\", 'l': 5, 'nl': \"#['X','Y']\", 'p': 3, 'atPos': 2}"
]
} | basic |
verina_advanced_78 | -----Description-----
This task requires writing a Lean 4 method that solves the Two Sum problem. Given a list of integers and a target integer, the method must return a pair of indices such that the sum of the numbers at those indices equals the target. You may assume that each input has exactly one solution and that you may not use the same element twice. The answer should be returned with first index is smaller than the second.
-----Input-----
The input consists of:
- nums: A list of integers.
- target: An integer representing the target sum.
-----Output-----
The output is a pair (tuple) of integers representing the indices of the two numbers in the input list that add up to the target.
| -- !benchmark @start import type=solution
-- !benchmark @end import
-- !benchmark @start solution_aux
-- !benchmark @end solution_aux
-- !benchmark @start precond_aux
-- !benchmark @end precond_aux
@[reducible]
def twoSum_precond (nums : List Int) (target : Int) : Prop :=
-- !benchmark @start precond
let pairwiseSum := List.range nums.length |>.flatMap (fun i =>
nums.drop (i + 1) |>.map (fun y => nums[i]! + y))
nums.length > 1 ∧ pairwiseSum.count target = 1
-- !benchmark @end precond
-- !benchmark @start code_aux
def findComplement (nums : List Int) (target : Int) (i : Nat) (x : Int) : Option Nat :=
let rec aux (nums : List Int) (j : Nat) : Option Nat :=
match nums with
| [] => none
| y :: ys => if x + y = target then some (i + j + 1) else aux ys (j + 1)
aux nums 0
def twoSumAux (nums : List Int) (target : Int) (i : Nat) : Prod Nat Nat :=
match nums with
| [] => panic! "No solution exists"
| x :: xs =>
match findComplement xs target i x with
| some j => (i, j)
| none => twoSumAux xs target (i + 1)
-- !benchmark @end code_aux
def twoSum (nums : List Int) (target : Int) (h_precond : twoSum_precond (nums) (target)) : Prod Nat Nat :=
-- !benchmark @start code
twoSumAux nums target 0
-- !benchmark @end code
-- !benchmark @start postcond_aux
-- !benchmark @end postcond_aux
@[reducible]
def twoSum_postcond (nums : List Int) (target : Int) (result: Prod Nat Nat) (h_precond : twoSum_precond (nums) (target)) : Prop :=
-- !benchmark @start postcond
let i := result.fst;
let j := result.snd;
(i < j) ∧
(i < nums.length) ∧ (j < nums.length) ∧
(nums[i]!) + (nums[j]!) = target
-- !benchmark @end postcond
-- !benchmark @start proof_aux
-- !benchmark @end proof_aux
theorem twoSum_spec_satisfied (nums: List Int) (target: Int) (h_precond : twoSum_precond (nums) (target)) :
twoSum_postcond (nums) (target) (twoSum (nums) (target) h_precond) h_precond := by
-- !benchmark @start proof
sorry
-- !benchmark @end proof
| {
"name": "twoSum",
"parameters": {
"param_name": [
"nums",
"target"
],
"param_type": [
"List Int",
"Int"
]
},
"return_type": "Prod Nat Nat"
} | {
"upstream": {
"name": "lab_assignment",
"link": "https://leetcode.com/problems/two-sum/description/",
"task_id": "lab_twoSum_324854887",
"student_id": [
18
]
}
} | {
"input": [
"{\"nums\": \"[2, 7, 11, 15]\", \"target\": 9}",
"{\"nums\": \"[3, 2, 4]\", \"target\": 6}",
"{\"nums\": \"[3, 3]\", \"target\": 6}",
"{\"nums\": \"[1, 2, 3, 4]\", \"target\": 7}",
"{\"nums\": \"[0, 4, 3, 0]\", \"target\": 0}"
],
"expected": [
[
"(0, 1)"
],
[
"(1, 2)"
],
[
"(0, 1)"
],
[
"(2, 3)"
],
[
"(0, 3)"
]
],
"unexpected": [
[
"(2, 3)"
],
[
"(0, 2)"
],
[
"(1, 0)"
],
[
"(0, 1)"
],
[
"(1, 2)"
]
]
} | {
"input": [
"{'nums': '[1, 2]', 'target': 0}"
]
} | advanced |
verina_advanced_63 | -----Description-----
This task requires writing a Lean 4 method that counts the unique elements from a sorted array.
-----Input-----
The input is a single list of integers:
nums: An array of integers sorted in non-decreasing order.
-----Output-----
The output is a single integer:
Returns the number of unique elements (k). | -- !benchmark @start import type=solution
-- !benchmark @end import
-- !benchmark @start solution_aux
-- !benchmark @end solution_aux
-- !benchmark @start precond_aux
-- !benchmark @end precond_aux
@[reducible]
def removeDuplicates_precond (nums : List Int) : Prop :=
-- !benchmark @start precond
-- nums are sorted in non-decreasing order
List.Pairwise (· ≤ ·) nums
-- !benchmark @end precond
-- !benchmark @start code_aux
-- !benchmark @end code_aux
def removeDuplicates (nums : List Int) (h_precond : removeDuplicates_precond (nums)) : Nat :=
-- !benchmark @start code
match nums with
| [] =>
0
| h :: t =>
let init := h
let initCount := 1
let rec countUniques (prev : Int) (xs : List Int) (k : Nat) : Nat :=
match xs with
| [] =>
k
| head :: tail =>
let isDuplicate := head = prev
if isDuplicate then
countUniques prev tail k
else
let newK := k + 1
countUniques head tail newK
countUniques init t initCount
-- !benchmark @end code
-- !benchmark @start postcond_aux
-- !benchmark @end postcond_aux
@[reducible]
def removeDuplicates_postcond (nums : List Int) (result: Nat) (h_precond : removeDuplicates_precond (nums)) : Prop :=
-- !benchmark @start postcond
result - nums.eraseDups.length = 0 ∧
nums.eraseDups.length ≤ result
-- !benchmark @end postcond
-- !benchmark @start proof_aux
-- !benchmark @end proof_aux
theorem removeDuplicates_spec_satisfied (nums: List Int) (h_precond : removeDuplicates_precond (nums)) :
removeDuplicates_postcond (nums) (removeDuplicates (nums) h_precond) h_precond := by
-- !benchmark @start proof
sorry
-- !benchmark @end proof
| {
"name": "removeDuplicates",
"parameters": {
"param_name": [
"nums"
],
"param_type": [
"List Int"
]
},
"return_type": "Nat"
} | {
"upstream": {
"name": "lab_assignment",
"link": "https://leetcode.com/problems/remove-duplicates-from-sorted-array/description/",
"task_id": "lab_removeDuplicates_325739229",
"student_id": [
30
]
}
} | {
"input": [
"{\"nums\": \"[1, 1, 2]\"}",
"{\"nums\": \"[0, 0, 1, 1, 1, 2, 2, 3, 3, 4]\"}",
"{\"nums\": \"[-1, -1, 0, 1, 2, 2, 3]\"}",
"{\"nums\": \"[1, 2, 3, 4, 5]\"}",
"{\"nums\": \"[1, 1, 1, 1]\"}",
"{\"nums\": \"[]\"}",
"{\"nums\": \"[1]\"}",
"{\"nums\": \"[-100, -100, -100]\"}",
"{\"nums\": \"[-100, -99, -99, -50, 0, 0, 100, 100]\"}",
"{\"nums\": \"[-1, 0, 0, 0, 1, 2, 2, 3, 4, 4, 5]\"}",
"{\"nums\": \"[100, 100, 100, 101, 102, 102, 103, 104, 105, 105]\"}"
],
"expected": [
[
"2"
],
[
"5"
],
[
"5"
],
[
"5"
],
[
"1"
],
[
"0"
],
[
"1"
],
[
"1"
],
[
"5"
],
[
"7"
],
[
"6"
]
],
"unexpected": [
[
"1",
"3"
],
[
"4",
"10"
],
[
"3"
],
[
"4"
],
[
"2",
"4"
],
[
"1"
],
[
"0",
"2"
],
[
"2",
"3"
],
[
"6",
"7"
],
[
"6",
"10"
],
[
"5",
"7"
]
]
} | {
"input": [
"{'nums': '[3, 2, 1]'}"
]
} | advanced |
verina_basic_21 | -----Description-----
This task requires writing a Lean 4 method that determines whether one list is a sublist of another. In other words, the method should check if the first list appears as a contiguous sequence within the second list and return true if it does, and false otherwise.
-----Input-----
The input consists of two lists of integers:
sub: A list of integers representing the potential sublist.
main: A list of integers in which to search for the sublist.
-----Output-----
The output is a Boolean value:
Returns true if the first list appears as a contiguous sequence within the second list.
Returns false if the first list does not appear as a contiguous sequence in the second list.
-----Note-----
There are no preconditions for this method; the sequences are always non-null. | -- !benchmark @start import type=solution
-- !benchmark @end import
-- !benchmark @start solution_aux
-- !benchmark @end solution_aux
-- !benchmark @start precond_aux
-- !benchmark @end precond_aux
@[reducible, simp]
def isSublist_precond (sub : List Int) (main : List Int) : Prop :=
-- !benchmark @start precond
True
-- !benchmark @end precond
-- !benchmark @start code_aux
-- !benchmark @end code_aux
def isSublist (sub : List Int) (main : List Int) (h_precond : isSublist_precond (sub) (main)) : Bool :=
-- !benchmark @start code
let subLen := sub.length
let mainLen := main.length
if subLen > mainLen then
false
else
let rec check (i : Nat) : Bool :=
if i + subLen > mainLen then
false
else if sub = (main.drop i).take subLen then
true
else if i + 1 ≤ mainLen then
check (i + 1)
else
false
termination_by mainLen - i
check 0
-- !benchmark @end code
-- !benchmark @start postcond_aux
-- !benchmark @end postcond_aux
@[reducible, simp]
def isSublist_postcond (sub : List Int) (main : List Int) (result: Bool) (h_precond : isSublist_precond (sub) (main)) :=
-- !benchmark @start postcond
(∃ i, i + sub.length ≤ main.length ∧ sub = (main.drop i).take sub.length) ↔ result
-- !benchmark @end postcond
-- !benchmark @start proof_aux
-- !benchmark @end proof_aux
theorem isSublist_spec_satisfied (sub: List Int) (main: List Int) (h_precond : isSublist_precond (sub) (main)) :
isSublist_postcond (sub) (main) (isSublist (sub) (main) h_precond) h_precond := by
-- !benchmark @start proof
sorry
-- !benchmark @end proof
| {
"name": "isSublist",
"parameters": {
"param_name": [
"sub",
"main"
],
"param_type": [
"List Int",
"List Int"
]
},
"return_type": "Bool"
} | {
"upstream": {
"name": "dafny-synthesis",
"link": "https://github.com/Mondego/dafny-synthesis",
"task_id": "task_id_576",
"student_id": null
}
} | {
"input": [
"{\"sub\": \"[1, 2]\", \"main\": \"[3, 1, 2, 4]\"}",
"{\"sub\": \"[2, 3]\", \"main\": \"[3, 1, 2, 4]\"}",
"{\"sub\": \"[3, 1]\", \"main\": \"[3, 1, 2, 4]\"}",
"{\"sub\": \"[4]\", \"main\": \"[3, 1, 2, 4]\"}",
"{\"sub\": \"[5]\", \"main\": \"[3, 1, 2, 4]\"}",
"{\"sub\": \"[]\", \"main\": \"[3, 1, 2, 4]\"}",
"{\"sub\": \"[1, 2]\", \"main\": \"[]\"}",
"{\"sub\": \"[]\", \"main\": \"[]\"}"
],
"expected": [
[
"True"
],
[
"False"
],
[
"True"
],
[
"True"
],
[
"False"
],
[
"True"
],
[
"False"
],
[
"True"
]
],
"unexpected": [
[
"False"
],
[
"True"
],
[
"False"
],
[
"False"
],
[
"True"
],
[
"False"
],
[
"True"
],
[
"False"
]
]
} | {
"input": []
} | basic |
verina_basic_31 | -----Description-----
This task requires writing a Lean 4 method that converts a given string to uppercase. The method should replace every lowercase letter in the input string with its corresponding uppercase character while leaving all other characters unchanged. The output string must have the same length as the input string.
-----Input-----
The input consists of:
s: A string.
-----Output-----
The output is a string:
Returns a new string in which every lowercase letter from the input string is converted to uppercase, and all other characters are exactly the same as in the input string, ensuring the output string has the same length as the input.
-----Note-----
There are no preconditions since the method assumes that the input string is always valid (i.e., non-null). | -- !benchmark @start import type=solution
-- !benchmark @end import
-- !benchmark @start solution_aux
def isLowerCase (c : Char) : Bool :=
'a' ≤ c ∧ c ≤ 'z'
def shiftMinus32 (c : Char) : Char :=
Char.ofNat ((c.toNat - 32) % 128)
-- !benchmark @end solution_aux
-- !benchmark @start precond_aux
-- !benchmark @end precond_aux
@[reducible, simp]
def toUppercase_precond (s : String) : Prop :=
-- !benchmark @start precond
True
-- !benchmark @end precond
-- !benchmark @start code_aux
-- !benchmark @end code_aux
def toUppercase (s : String) (h_precond : toUppercase_precond (s)) : String :=
-- !benchmark @start code
let cs := s.toList
let cs' := cs.map (fun c => if isLowerCase c then shiftMinus32 c else c)
String.mk cs'
-- !benchmark @end code
-- !benchmark @start postcond_aux
-- !benchmark @end postcond_aux
@[reducible, simp]
def toUppercase_postcond (s : String) (result: String) (h_precond : toUppercase_precond (s)) :=
-- !benchmark @start postcond
let cs := s.toList
let cs' := result.toList
(result.length = s.length) ∧
(∀ i, i < s.length →
(isLowerCase cs[i]! → cs'[i]! = shiftMinus32 cs[i]!) ∧
(¬isLowerCase cs[i]! → cs'[i]! = cs[i]!))
-- !benchmark @end postcond
-- !benchmark @start proof_aux
-- !benchmark @end proof_aux
theorem toUppercase_spec_satisfied (s: String) (h_precond : toUppercase_precond (s)) :
toUppercase_postcond (s) (toUppercase (s) h_precond) h_precond := by
-- !benchmark @start proof
unfold toUppercase toUppercase_postcond
simp_all
constructor
· unfold String.length
simp
· intro i hi
have hi' : i < s.data.length := by
unfold String.length at hi
simp at hi
exact hi
constructor <;> simp_all
-- !benchmark @end proof
| {
"name": "toUppercase",
"parameters": {
"param_name": [
"s"
],
"param_type": [
"String"
]
},
"return_type": "String"
} | {
"upstream": {
"name": "dafny-synthesis",
"link": "https://github.com/Mondego/dafny-synthesis",
"task_id": "task_id_624",
"student_id": null
}
} | {
"input": [
"{\"s\": \"Hello, World!\"}",
"{\"s\": \"abc\"}",
"{\"s\": \"ABC\"}",
"{\"s\": \"123!?@\"}",
"{\"s\": \"\"}"
],
"expected": [
[
"HELLO, WORLD!"
],
[
"ABC"
],
[
"ABC"
],
[
"123!?@"
],
[
""
]
],
"unexpected": [
[
"hello, world!",
"HeLLo, WORld!"
],
[
"AbC",
"abc"
],
[
"abc",
"aBC",
"Abc"
],
[
"123!@?",
"321!?@"
],
[
" ",
"a"
]
]
} | {
"input": []
} | basic |
verina_basic_54 | -----Description-----
This task is about determining the minimum absolute difference between any pair of integers, where one integer is taken from the first sorted array and the other integer is taken from the second sorted array. The focus is on accurately finding the smallest absolute difference between any two elements from the arrays, independent of the specific techniques or programming language used.
-----Input-----
The input consists of:
• a: An array of integers, sorted in non-decreasing order and guaranteed to be non-empty.
• b: An array of integers, also sorted in non-decreasing order and non-empty.
-----Output-----
The output is a natural number (Nat) representing the minimum absolute difference between any element a[i] from the first array and b[j] from the second array.
-----Note-----
• It is assumed that both arrays are non-empty.
• The arrays are assumed to be sorted in non-decreasing order. | -- !benchmark @start import type=solution
-- !benchmark @end import
-- !benchmark @start solution_aux
-- !benchmark @end solution_aux
-- !benchmark @start precond_aux
-- !benchmark @end precond_aux
@[reducible, simp]
def CanyonSearch_precond (a : Array Int) (b : Array Int) : Prop :=
-- !benchmark @start precond
a.size > 0 ∧ b.size > 0 ∧ List.Pairwise (· ≤ ·) a.toList ∧ List.Pairwise (· ≤ ·) b.toList
-- !benchmark @end precond
-- !benchmark @start code_aux
def canyonSearchAux (a : Array Int) (b : Array Int) (m n d : Nat) : Nat :=
if m < a.size ∧ n < b.size then
let diff : Nat := ((a[m]! - b[n]!).natAbs)
let new_d := if diff < d then diff else d
if a[m]! <= b[n]! then
canyonSearchAux a b (m + 1) n new_d
else
canyonSearchAux a b m (n + 1) new_d
else
d
termination_by a.size + b.size - m - n
-- !benchmark @end code_aux
def CanyonSearch (a : Array Int) (b : Array Int) (h_precond : CanyonSearch_precond (a) (b)) : Nat :=
-- !benchmark @start code
let init : Nat :=
if a[0]! < b[0]! then (b[0]! - a[0]!).natAbs
else (a[0]! - b[0]!).natAbs
canyonSearchAux a b 0 0 init
-- !benchmark @end code
-- !benchmark @start postcond_aux
-- !benchmark @end postcond_aux
@[reducible, simp]
def CanyonSearch_postcond (a : Array Int) (b : Array Int) (result: Nat) (h_precond : CanyonSearch_precond (a) (b)) :=
-- !benchmark @start postcond
(a.any (fun ai => b.any (fun bi => result = (ai - bi).natAbs))) ∧
(a.all (fun ai => b.all (fun bi => result ≤ (ai - bi).natAbs)))
-- !benchmark @end postcond
-- !benchmark @start proof_aux
-- !benchmark @end proof_aux
theorem CanyonSearch_spec_satisfied (a: Array Int) (b: Array Int) (h_precond : CanyonSearch_precond (a) (b)) :
CanyonSearch_postcond (a) (b) (CanyonSearch (a) (b) h_precond) h_precond := by
-- !benchmark @start proof
sorry
-- !benchmark @end proof
| {
"name": "CanyonSearch",
"parameters": {
"param_name": [
"a",
"b"
],
"param_type": [
"Array Int",
"Array Int"
]
},
"return_type": "Nat"
} | {
"upstream": {
"name": "clover",
"link": "https://github.com/ChuyueSun/Clover",
"task_id": "Clover_canyon_search",
"student_id": null
}
} | {
"input": [
"{\"a\": \"#[1, 3, 5]\", \"b\": \"#[2, 4, 6]\"}",
"{\"a\": \"#[-5, -2, 0]\", \"b\": \"#[1, 3]\"}",
"{\"a\": \"#[10, 20, 30]\", \"b\": \"#[5, 15, 25]\"}",
"{\"a\": \"#[1, 2, 3, 4, 5]\", \"b\": \"#[3]\"}",
"{\"a\": \"#[-10, -5, 0, 5, 10]\", \"b\": \"#[-3, 2, 8]\"}"
],
"expected": [
[
"1"
],
[
"1"
],
[
"5"
],
[
"0"
],
[
"2"
]
],
"unexpected": [
[
"0",
"2",
"3"
],
[
"0",
"2",
"5"
],
[
"3",
"7",
"10"
],
[
"1",
"2",
"3"
],
[
"1",
"3",
"4"
]
]
} | {
"input": [
"{'a': '#[]', 'b': '#[]'}"
]
} | basic |
verina_basic_12 | -----Description-----
This task requires writing a Lean 4 method that calculates the surface area of a cube based on the length of one of its edges. The method should compute the surface area using the standard formula for a cube.
-----Input-----
The input consists of:
size: An natural number representing the length of an edge of the cube.
-----Output-----
The output is an natural number:
Returns the surface area of the cube.
| -- !benchmark @start import type=solution
-- !benchmark @end import
-- !benchmark @start solution_aux
-- !benchmark @end solution_aux
-- !benchmark @start precond_aux
-- !benchmark @end precond_aux
@[reducible, simp]
def cubeSurfaceArea_precond (size : Nat) : Prop :=
-- !benchmark @start precond
True
-- !benchmark @end precond
-- !benchmark @start code_aux
-- !benchmark @end code_aux
def cubeSurfaceArea (size : Nat) (h_precond : cubeSurfaceArea_precond (size)) : Nat :=
-- !benchmark @start code
6 * size * size
-- !benchmark @end code
-- !benchmark @start postcond_aux
-- !benchmark @end postcond_aux
@[reducible, simp]
def cubeSurfaceArea_postcond (size : Nat) (result: Nat) (h_precond : cubeSurfaceArea_precond (size)) :=
-- !benchmark @start postcond
result - 6 * size * size = 0 ∧ 6 * size * size - result = 0
-- !benchmark @end postcond
-- !benchmark @start proof_aux
-- !benchmark @end proof_aux
theorem cubeSurfaceArea_spec_satisfied (size: Nat) (h_precond : cubeSurfaceArea_precond (size)) :
cubeSurfaceArea_postcond (size) (cubeSurfaceArea (size) h_precond) h_precond := by
-- !benchmark @start proof
unfold cubeSurfaceArea cubeSurfaceArea_postcond
simp
-- !benchmark @end proof
| {
"name": "cubeSurfaceArea",
"parameters": {
"param_name": [
"size"
],
"param_type": [
"Nat"
]
},
"return_type": "Nat"
} | {
"upstream": {
"name": "dafny-synthesis",
"link": "https://github.com/Mondego/dafny-synthesis",
"task_id": "task_id_441",
"student_id": null
}
} | {
"input": [
"{\"size\": 3}",
"{\"size\": 1}",
"{\"size\": 10}",
"{\"size\": 5}",
"{\"size\": 2}"
],
"expected": [
[
"54"
],
[
"6"
],
[
"600"
],
[
"150"
],
[
"24"
]
],
"unexpected": [
[
"27",
"48",
"60"
],
[
"1",
"2",
"3"
],
[
"100",
"500",
"610"
],
[
"25",
"100",
"125"
],
[
"8",
"16",
"20"
]
]
} | {
"input": []
} | basic |
verina_basic_29 | -----Description-----
This task requires writing a Lean 4 method that removes an element from a given array of integers at a specified index. The resulting array should contain all the original elements except for the one at the given index. Elements before the removed element remain unchanged, and elements after it are shifted one position to the left.
-----Input-----
The input consists of:
• s: An array of integers.
• k: A natural number representing the index of the element to remove (0-indexed).
-----Output-----
The output is an array of integers that:
• Has a length one less than the input array.
• Contains the same elements as the input array, except that the element at index k is omitted.
• Preserves the original order with elements after the removed element shifted left by one position.
-----Note-----
It is assumed that k is a valid index (0 ≤ k < the length of the array). | -- !benchmark @start import type=solution
-- !benchmark @end import
-- !benchmark @start solution_aux
-- !benchmark @end solution_aux
-- !benchmark @start precond_aux
-- !benchmark @end precond_aux
@[reducible, simp]
def removeElement_precond (s : Array Int) (k : Nat) : Prop :=
-- !benchmark @start precond
k < s.size
-- !benchmark @end precond
-- !benchmark @start code_aux
-- !benchmark @end code_aux
def removeElement (s : Array Int) (k : Nat) (h_precond : removeElement_precond (s) (k)) : Array Int :=
-- !benchmark @start code
s.eraseIdx! k
-- !benchmark @end code
-- !benchmark @start postcond_aux
-- !benchmark @end postcond_aux
@[reducible, simp]
def removeElement_postcond (s : Array Int) (k : Nat) (result: Array Int) (h_precond : removeElement_precond (s) (k)) :=
-- !benchmark @start postcond
result.size = s.size - 1 ∧
(∀ i, i < k → result[i]! = s[i]!) ∧
(∀ i, i < result.size → i ≥ k → result[i]! = s[i + 1]!)
-- !benchmark @end postcond
-- !benchmark @start proof_aux
-- !benchmark @end proof_aux
theorem removeElement_spec_satisfied (s: Array Int) (k: Nat) (h_precond : removeElement_precond (s) (k)) :
removeElement_postcond (s) (k) (removeElement (s) (k) h_precond) h_precond := by
-- !benchmark @start proof
unfold removeElement removeElement_postcond
unfold removeElement_precond at h_precond
simp_all
unfold Array.eraseIdx!
simp [h_precond]
constructor
· intro i hi
have hi' : i < s.size - 1 := by
have hk := Nat.le_sub_one_of_lt h_precond
exact Nat.lt_of_lt_of_le hi hk
rw [Array.getElem!_eq_getD, Array.getElem!_eq_getD]
unfold Array.getD
simp [hi', Nat.lt_trans hi h_precond, Array.getElem_eraseIdx, hi]
· intro i hi hi'
rw [Array.getElem!_eq_getD, Array.getElem!_eq_getD]
unfold Array.getD
have hi'' : i + 1 < s.size := by exact Nat.add_lt_of_lt_sub hi
simp [hi, hi'']
have : ¬ i < k := by simp [hi']
simp [Array.getElem_eraseIdx, this]
-- !benchmark @end proof
| {
"name": "removeElement",
"parameters": {
"param_name": [
"s",
"k"
],
"param_type": [
"Array Int",
"Nat"
]
},
"return_type": "Array Int"
} | {
"upstream": {
"name": "dafny-synthesis",
"link": "https://github.com/Mondego/dafny-synthesis",
"task_id": "task_id_610",
"student_id": null
}
} | {
"input": [
"{\"s\": \"#[1, 2, 3, 4, 5]\", \"k\": 2}",
"{\"s\": \"#[10, 20, 30, 40]\", \"k\": 0}",
"{\"s\": \"#[10, 20, 30, 40]\", \"k\": 3}",
"{\"s\": \"#[7]\", \"k\": 0}"
],
"expected": [
[
"#[1, 2, 4, 5]"
],
[
"#[20, 30, 40]"
],
[
"#[10, 20, 30]"
],
[
"#[]"
]
],
"unexpected": [
[
"#[1, 2, 3, 5]",
"#[1, 3, 4, 5]",
"#[2, 3, 4, 5]"
],
[
"#[10, 30, 40]",
"#[10, 20, 30, 40]",
"#[20, 30, 40, 0]"
],
[
"#[20, 30, 40]",
"#[10, 20, 40]",
"#[10, 30, 40]"
],
[
"#[7]",
"#[0]"
]
]
} | {
"input": [
"{'s': '#[1]', 'k': 2}"
]
} | basic |
verina_basic_62 | -----Description-----
The problem involves finding the first occurrence of a specified key in an array of integers. Your task is to identify the index at which the key appears for the first time in the array and return that index. If the key is not found, return -1.
-----Input-----
The input consists of:
• a: An array of integers.
• key: An integer representing the value to search for in the array.
-----Output-----
The output is an integer which represents:
• The index in the array where the key is found, provided that the index is in the range [0, a.size).
• -1 if the key is not present in the array.
In addition, if the output is not -1, then a[(Int.toNat result)]! equals key and every element in the array prior to this index is not equal to key.
-----Note-----
The function performs a linear search beginning at index 0 and returns the first occurrence of the key. There are no additional preconditions on the input array; it can be empty or non-empty. | -- !benchmark @start import type=solution
-- !benchmark @end import
-- !benchmark @start solution_aux
-- !benchmark @end solution_aux
-- !benchmark @start precond_aux
-- !benchmark @end precond_aux
@[reducible, simp]
def Find_precond (a : Array Int) (key : Int) : Prop :=
-- !benchmark @start precond
True
-- !benchmark @end precond
-- !benchmark @start code_aux
-- !benchmark @end code_aux
def Find (a : Array Int) (key : Int) (h_precond : Find_precond (a) (key)) : Int :=
-- !benchmark @start code
let rec search (index : Nat) : Int :=
if index < a.size then
if a[index]! = key then Int.ofNat index
else search (index + 1)
else -1
search 0
-- !benchmark @end code
-- !benchmark @start postcond_aux
-- !benchmark @end postcond_aux
@[reducible, simp]
def Find_postcond (a : Array Int) (key : Int) (result: Int) (h_precond : Find_precond (a) (key)) :=
-- !benchmark @start postcond
(result = -1 ∨ (result ≥ 0 ∧ result < Int.ofNat a.size))
∧ ((result ≠ -1) → (a[(Int.toNat result)]! = key ∧ ∀ (i : Nat), i < Int.toNat result → a[i]! ≠ key))
∧ ((result = -1) → ∀ (i : Nat), i < a.size → a[i]! ≠ key)
-- !benchmark @end postcond
-- !benchmark @start proof_aux
-- !benchmark @end proof_aux
theorem Find_spec_satisfied (a: Array Int) (key: Int) (h_precond : Find_precond (a) (key)) :
Find_postcond (a) (key) (Find (a) (key) h_precond) h_precond := by
-- !benchmark @start proof
sorry
-- !benchmark @end proof
| {
"name": "Find",
"parameters": {
"param_name": [
"a",
"key"
],
"param_type": [
"Array Int",
"Int"
]
},
"return_type": "Int"
} | {
"upstream": {
"name": "clover",
"link": "https://github.com/ChuyueSun/Clover",
"task_id": "Clover_find",
"student_id": null
}
} | {
"input": [
"{\"a\": \"#[1, 2, 3, 4, 5]\", \"key\": 3}",
"{\"a\": \"#[5, 7, 5, 9]\", \"key\": 5}",
"{\"a\": \"#[2, 4, 6, 8]\", \"key\": 5}",
"{\"a\": \"#[]\", \"key\": 10}",
"{\"a\": \"#[0, -3, -1, -3]\", \"key\": -3}"
],
"expected": [
[
"2"
],
[
"0"
],
[
"-1"
],
[
"-1"
],
[
"1"
]
],
"unexpected": [
[
"1",
"3",
"0"
],
[
"2",
"-1"
],
[
"0",
"1",
"3"
],
[
"0",
"1",
"10"
],
[
"0",
"2",
"3"
]
]
} | {
"input": []
} | basic |
verina_basic_55 | -----Description-----
This task involves determining whether two integer values are equal. The goal is simply to compare the two provided numbers and indicate with a Boolean result whether they are the same.
-----Input-----
The input consists of two elements:
• a: An element of type Int.
• b: An element of type Int.
-----Output-----
The output is a Boolean:
• Returns true if a equals b.
• Returns false if a does not equal b.
| -- !benchmark @start import type=solution
-- !benchmark @end import
-- !benchmark @start solution_aux
-- !benchmark @end solution_aux
-- !benchmark @start precond_aux
-- !benchmark @end precond_aux
@[reducible, simp]
def Compare_precond (a : Int) (b : Int) : Prop :=
-- !benchmark @start precond
True
-- !benchmark @end precond
-- !benchmark @start code_aux
-- !benchmark @end code_aux
def Compare (a : Int) (b : Int) (h_precond : Compare_precond (a) (b)) : Bool :=
-- !benchmark @start code
if a = b then true else false
-- !benchmark @end code
-- !benchmark @start postcond_aux
-- !benchmark @end postcond_aux
@[reducible, simp]
def Compare_postcond (a : Int) (b : Int) (result: Bool) (h_precond : Compare_precond (a) (b)) :=
-- !benchmark @start postcond
(a = b → result = true) ∧ (a ≠ b → result = false)
-- !benchmark @end postcond
-- !benchmark @start proof_aux
-- !benchmark @end proof_aux
theorem Compare_spec_satisfied (a: Int) (b: Int) (h_precond : Compare_precond (a) (b)) :
Compare_postcond (a) (b) (Compare (a) (b) h_precond) h_precond := by
-- !benchmark @start proof
unfold Compare_postcond Compare
simp
-- !benchmark @end proof
| {
"name": "Compare",
"parameters": {
"param_name": [
"a",
"b"
],
"param_type": [
"Int",
"Int"
]
},
"return_type": "Bool"
} | {
"upstream": {
"name": "clover",
"link": "https://github.com/ChuyueSun/Clover",
"task_id": "Clover_compare",
"student_id": null
}
} | {
"input": [
"{\"a\": 1, \"b\": 1}",
"{\"a\": 1, \"b\": 2}"
],
"expected": [
[
"True"
],
[
"False"
]
],
"unexpected": [
[
"False"
],
[
"True"
]
]
} | {
"input": []
} | basic |
verina_advanced_74 | -----Description-----
This task requires writing a Lean 4 function called `solution` that takes a list of natural numbers `nums`. The function should calculate and return the sum of values obtained for each subarray, where the value for a subarray is the square of the count of distinct elements within that subarray.
-----Input-----
The input is a list of natural numbers:
`nums`: A list where each element is a natural number.
Constraints:
- The length of the list `nums` (n) is between 1 and 100 (inclusive).
- Each element in `nums` is between 1 and 100 (inclusive).
-----Output-----
The output is a natural number:
Returns the total sum of squared distinct counts for all subarrays.
| -- !benchmark @start import type=solution
import Std.Data.HashSet
open Std
-- !benchmark @end import
-- !benchmark @start solution_aux
-- !benchmark @end solution_aux
-- !benchmark @start precond_aux
-- !benchmark @end precond_aux
@[reducible]
def solution_precond (nums : List Nat) : Prop :=
-- !benchmark @start precond
1 ≤ nums.length ∧ nums.length ≤ 100 ∧ nums.all (fun x => 1 ≤ x ∧ x ≤ 100)
-- !benchmark @end precond
-- !benchmark @start code_aux
-- !benchmark @end code_aux
def solution (nums : List Nat) : Nat :=
-- !benchmark @start code
let n := nums.length
let subarray := fun (i j : Nat) => (nums.drop i).take (j - i + 1)
let distinctCount := fun (l : List Nat) =>
let hashSet := l.foldl (fun (s : HashSet Nat) a => s.insert a) HashSet.empty
hashSet.size
List.range n |>.foldl (fun acc i =>
acc +
(List.range (n - i) |>.foldl (fun acc' d =>
let subarr := subarray i (i + d)
let cnt := distinctCount subarr
acc' + cnt * cnt
) 0)
) 0
-- !benchmark @end code
-- !benchmark @start postcond_aux
-- !benchmark @end postcond_aux
@[reducible]
def solution_postcond (nums : List Nat) (result: Nat) : Prop :=
-- !benchmark @start postcond
let n := nums.length;
let getSubarray_local := fun (i j : Nat) =>
(nums.drop i).take (j - i + 1);
let distinctCount_local := fun (l : List Nat) =>
let foldFn := fun (seen : List Nat) (x : Nat) =>
if seen.elem x then seen else x :: seen;
let distinctElems := l.foldl foldFn [];
distinctElems.length;
let square_local := fun (n : Nat) => n * n;
(1 <= n ∧ n <= 100 ∧ nums.all (fun x => 1 <= x ∧ x <= 100)) ->
(
result >= 0
∧
let expectedSum : Nat :=
List.range n |>.foldl (fun (outerSum : Nat) (i : Nat) =>
let innerSum : Nat :=
List.range (n - i) |>.foldl (fun (currentInnerSum : Nat) (d : Nat) =>
let j := i + d;
let subarr := getSubarray_local i j;
let count := distinctCount_local subarr;
currentInnerSum + square_local count
) 0
outerSum + innerSum
) 0;
result = expectedSum
)
-- !benchmark @end postcond
-- !benchmark @start proof_aux
-- !benchmark @end proof_aux
theorem solution_spec_satisfied (nums: List Nat) :
solution_postcond (nums) (solution (nums)) := by
-- !benchmark @start proof
sorry
-- !benchmark @end proof
| {
"name": "solution",
"parameters": {
"param_name": [
"nums"
],
"param_type": [
"List Nat"
]
},
"return_type": "Nat"
} | {
"upstream": {
"name": "lab_assignment",
"link": "https://leetcode.com/problems/subarrays-distinct-element-sum-of-squares-i/",
"task_id": "lab_solution_324856546",
"student_id": [
52
]
}
} | {
"input": [
"{\"nums\": \"[1]\"}",
"{\"nums\": \"[1, 1, 1]\"}",
"{\"nums\": \"[1, 2, 1]\"}",
"{\"nums\": \"[1, 2, 3, 4]\"}",
"{\"nums\": \"[1, 2, 2, 3, 1]\"}"
],
"expected": [
[
"1"
],
[
"6"
],
[
"15"
],
[
"50"
],
[
"62"
]
],
"unexpected": [
[
"2"
],
[
"1",
"2",
"3"
],
[
"12"
],
[],
[
"1",
"2",
"2",
"3",
"1"
]
]
} | {
"input": [
"{'nums': '[]'}",
"{'nums': '[101]'}"
]
} | advanced |
verina_advanced_27 | -----Description-----
This task requires writing a Lean 4 function that computes the longest common subsequence (LCS) of two input strings.
A subsequence of a string is a sequence that can be derived from the original string by deleting zero or more characters (not necessarily contiguous) without changing the order of the remaining characters.
The function should return a string that is:
1) A subsequence of both input strings.
2) As long as possible among all such common subsequences.
If multiple LCS answers exist (with the same maximum length), returning any one of them is acceptable.
-----Input-----
s1: The first input string.
s2: The second input string.
-----Output-----
A string representing a longest common subsequence of s1 and s2.
| -- !benchmark @start import type=solution
-- !benchmark @end import
-- !benchmark @start solution_aux
-- !benchmark @end solution_aux
-- !benchmark @start precond_aux
-- !benchmark @end precond_aux
@[reducible]
def longestCommonSubsequence_precond (s1 : String) (s2 : String) : Prop :=
-- !benchmark @start precond
True
-- !benchmark @end precond
-- !benchmark @start code_aux
partial def toCharList (s : String) : List Char :=
s.data
partial def fromCharList (cs : List Char) : String :=
cs.foldl (fun acc c => acc.push c) ""
partial def lcsAux (xs : List Char) (ys : List Char) : List Char :=
match xs, ys with
| [], _ => []
| _, [] => []
| x :: xs', y :: ys' =>
if x == y then
x :: lcsAux xs' ys'
else
let left := lcsAux xs' (y :: ys')
let right := lcsAux (x :: xs') ys'
if left.length >= right.length then left else right
-- !benchmark @end code_aux
def longestCommonSubsequence (s1 : String) (s2 : String) (h_precond : longestCommonSubsequence_precond (s1) (s2)) : String :=
-- !benchmark @start code
let xs := toCharList s1
let ys := toCharList s2
let resultList := lcsAux xs ys
fromCharList resultList
-- !benchmark @end code
-- !benchmark @start postcond_aux
-- !benchmark @end postcond_aux
@[reducible]
def longestCommonSubsequence_postcond (s1 : String) (s2 : String) (result: String) (h_precond : longestCommonSubsequence_precond (s1) (s2)) : Prop :=
-- !benchmark @start postcond
let allSubseq (arr : List Char) := (arr.foldl fun acc x => acc ++ acc.map (fun sub => x :: sub)) [[]] |>.map List.reverse
let subseqA := allSubseq s1.toList
let subseqB := allSubseq s2.toList
let commonSubseq := subseqA.filter (fun l => subseqB.contains l)
commonSubseq.contains result.toList ∧ commonSubseq.all (fun l => l.length ≤ result.length)
-- !benchmark @end postcond
-- !benchmark @start proof_aux
-- !benchmark @end proof_aux
theorem longestCommonSubsequence_spec_satisfied (s1: String) (s2: String) (h_precond : longestCommonSubsequence_precond (s1) (s2)) :
longestCommonSubsequence_postcond (s1) (s2) (longestCommonSubsequence (s1) (s2) h_precond) h_precond := by
-- !benchmark @start proof
sorry
-- !benchmark @end proof
| {
"name": "longestCommonSubsequence",
"parameters": {
"param_name": [
"s1",
"s2"
],
"param_type": [
"String",
"String"
]
},
"return_type": "String"
} | {
"upstream": {
"name": "lab_assignment",
"link": "https://leetcode.com/problems/longest-common-subsequence/description/",
"task_id": "lab_longestCommonSubsequence_325767793",
"student_id": [
21
]
}
} | {
"input": [
"{\"s1\": \"abcde\", \"s2\": \"ace\"}",
"{\"s1\": \"aaaa\", \"s2\": \"bbaaa\"}",
"{\"s1\": \"xyz\", \"s2\": \"abc\"}",
"{\"s1\": \"axbxc\", \"s2\": \"abxc\"}",
"{\"s1\": \"AGGTAB\", \"s2\": \"GXTXAYB\"}"
],
"expected": [
[
"ace"
],
[
"aaa"
],
[
""
],
[
"abxc"
],
[
"GTAB"
]
],
"unexpected": [
[
"ab",
"abc",
"bce"
],
[
"aaaaa",
"b",
"aaab"
],
[
"x",
"y",
"a",
"abc"
],
[
"axc",
"abcx"
],
[
"GGTAB",
"AGGTA"
]
]
} | {
"input": []
} | advanced |
verina_advanced_15 | -----Description-----
Given an integer array nums, return true if there exists a triple of indices (i, j, k) such that i < j < k and nums[i] < nums[j] < nums[k]. If no such indices exist, return false.
-----Input-----
The input consists of a single list:
nums: A list of integers.
-----Output-----
The output is a boolean:
Returns true if there exists a triplet (i, j, k) where i < j < k and nums[i] < nums[j] < nums[k]; otherwise, returns false.
| -- !benchmark @start import type=solution
-- !benchmark @end import
-- !benchmark @start solution_aux
-- !benchmark @end solution_aux
-- !benchmark @start precond_aux
-- !benchmark @end precond_aux
@[reducible]
def increasingTriplet_precond (nums : List Int) : Prop :=
-- !benchmark @start precond
True
-- !benchmark @end precond
-- !benchmark @start code_aux
-- !benchmark @end code_aux
def increasingTriplet (nums : List Int) (h_precond : increasingTriplet_precond (nums)) : Bool :=
-- !benchmark @start code
-- must have at least 3 elements to form a triplet
let rec lengthCheck : List Int → Nat → Nat
| [], acc => acc
| _ :: rest, acc => lengthCheck rest (acc + 1)
let len := lengthCheck nums 0
if len < 3 then
false
else
-- scan for increasing triplet
let rec loop (xs : List Int) (first : Int) (second : Int) : Bool :=
match xs with
| [] => false
| x :: rest =>
let nextFirst := if x ≤ first then x else first
let nextSecond := if x > first ∧ x ≤ second then x else second
if x ≤ first then
loop rest nextFirst second
else if x ≤ second then
loop rest first nextSecond
else
true -- found triplet
match nums with
| [] => false
| _ :: rest1 =>
match rest1 with
| [] => false
| _ :: rest2 =>
match rest2 with
| [] => false
| _ =>
loop nums 2147483647 2147483647
-- !benchmark @end code
-- !benchmark @start postcond_aux
-- !benchmark @end postcond_aux
@[reducible]
def increasingTriplet_postcond (nums : List Int) (result: Bool) (h_precond : increasingTriplet_precond (nums)) : Prop :=
-- !benchmark @start postcond
let nums' := nums.zipIdx
(result →
nums'.any (fun (x, i) =>
nums'.any (fun (y, j) =>
nums'.any (fun (z, k) =>
i < j ∧ j < k ∧ x < y ∧ y < z
)
)
))
∧
(¬ result → nums'.all (fun (x, i) =>
nums'.all (fun (y, j) =>
nums'.all (fun (z, k) =>
i ≥ j ∨ j ≥ k ∨ x ≥ y ∨ y ≥ z
)
)
))
-- !benchmark @end postcond
-- !benchmark @start proof_aux
-- !benchmark @end proof_aux
theorem increasingTriplet_spec_satisfied (nums: List Int) (h_precond : increasingTriplet_precond (nums)) :
increasingTriplet_postcond (nums) (increasingTriplet (nums) h_precond) h_precond := by
-- !benchmark @start proof
sorry
-- !benchmark @end proof
| {
"name": "increasingTriplet",
"parameters": {
"param_name": [
"nums"
],
"param_type": [
"List Int"
]
},
"return_type": "Bool"
} | {
"upstream": {
"name": "lab_assignment",
"link": "https://leetcode.com/problems/increasing-triplet-subsequence?envType=study-plan-v2&envId=leetcode-75",
"task_id": "lab_increasingTriplet_324678911",
"student_id": [
6
]
}
} | {
"input": [
"{\"nums\": \"[1, 2, 3]\"}",
"{\"nums\": \"[5, 4, 3, 2, 1]\"}",
"{\"nums\": \"[2, 1, 5, 0, 4, 6]\"}",
"{\"nums\": \"[1, 5, 0, 4, 1, 3]\"}",
"{\"nums\": \"[5, 4, 3]\"}",
"{\"nums\": \"[]\"}"
],
"expected": [
[
"True"
],
[
"False"
],
[
"True"
],
[
"True"
],
[
"False"
],
[
"False"
]
],
"unexpected": [
[
"False"
],
[
"True"
],
[
"False"
],
[
"False"
],
[
"True"
],
[
"True"
]
]
} | {
"input": []
} | advanced |
verina_basic_24 | -----Description-----
This task requires writing a Lean 4 method that finds the difference between the first even number and the first odd number in an array of integers. The method should process the array sequentially until it identifies the first even number and the first odd number, and then return the difference calculated as (first even number) minus (first odd number).
-----Input-----
The input consists of:
a: An array of integers.
-----Output-----
The output is an integer:
Returns the difference computed as the first even number minus the first odd number found in the array.
-----Note-----
The input array is assumed to be non-empty and to contain at least one even number and one odd number. | -- !benchmark @start import type=solution
-- !benchmark @end import
-- !benchmark @start solution_aux
def isEven (n : Int) : Bool :=
n % 2 == 0
def isOdd (n : Int) : Bool :=
n % 2 != 0
-- !benchmark @end solution_aux
-- !benchmark @start precond_aux
-- !benchmark @end precond_aux
@[reducible, simp]
def firstEvenOddDifference_precond (a : Array Int) : Prop :=
-- !benchmark @start precond
a.size > 1 ∧
(∃ x ∈ a, isEven x) ∧
(∃ x ∈ a, isOdd x)
-- !benchmark @end precond
-- !benchmark @start code_aux
-- !benchmark @end code_aux
def firstEvenOddDifference (a : Array Int) (h_precond : firstEvenOddDifference_precond (a)) : Int :=
-- !benchmark @start code
let rec findFirstEvenOdd (i : Nat) (firstEven firstOdd : Option Nat) : Int :=
if i < a.size then
let x := a[i]!
let firstEven := if firstEven.isNone && isEven x then some i else firstEven
let firstOdd := if firstOdd.isNone && isOdd x then some i else firstOdd
match firstEven, firstOdd with
| some e, some o => a[e]! - a[o]!
| _, _ => findFirstEvenOdd (i + 1) firstEven firstOdd
else
-- This case is impossible due to h2, but we need a value
0
findFirstEvenOdd 0 none none
-- !benchmark @end code
-- !benchmark @start postcond_aux
-- !benchmark @end postcond_aux
@[reducible, simp]
def firstEvenOddDifference_postcond (a : Array Int) (result: Int) (h_precond : firstEvenOddDifference_precond (a)) :=
-- !benchmark @start postcond
∃ i j, i < a.size ∧ j < a.size ∧ isEven (a[i]!) ∧ isOdd (a[j]!) ∧
result = a[i]! - a[j]! ∧
(∀ k, k < i → isOdd (a[k]!)) ∧ (∀ k, k < j → isEven (a[k]!))
-- !benchmark @end postcond
-- !benchmark @start proof_aux
-- !benchmark @end proof_aux
theorem firstEvenOddDifference_spec_satisfied (a: Array Int) (h_precond : firstEvenOddDifference_precond (a)) :
firstEvenOddDifference_postcond (a) (firstEvenOddDifference (a) h_precond) h_precond := by
-- !benchmark @start proof
sorry
-- !benchmark @end proof
| {
"name": "firstEvenOddDifference",
"parameters": {
"param_name": [
"a"
],
"param_type": [
"Array Int"
]
},
"return_type": "Int"
} | {
"upstream": {
"name": "dafny-synthesis",
"link": "https://github.com/Mondego/dafny-synthesis",
"task_id": "task_id_594",
"student_id": null
}
} | {
"input": [
"{\"a\": \"#[2, 3, 4, 5]\"}",
"{\"a\": \"#[1, 4, 6, 8]\"}",
"{\"a\": \"#[7, 2, 9, 4]\"}",
"{\"a\": \"#[2, 2, 3, 3]\"}",
"{\"a\": \"#[1, 1, 2, 2]\"}"
],
"expected": [
[
"-1"
],
[
"3"
],
[
"-5"
],
[
"-1"
],
[
"1"
]
],
"unexpected": [
[
"-2",
"1",
"-3"
],
[
"2",
"4",
"5"
],
[
"-3",
"-6",
"5"
],
[
"1",
"0",
"-2"
],
[
"0",
"2",
"-1"
]
]
} | {
"input": [
"{'a': '#[2]'}"
]
} | basic |
verina_advanced_76 | -----Description-----
This task requires writing a Lean 4 method that returns the k most frequent elements from a list of integers. The method should count the frequency of each distinct element in the list and return the k elements with the highest frequency.
-----Input-----
The input consists of two values:
nums: A list of integers, possibly with duplicates.
k: A natural number indicating how many of the most frequent elements to return. Assimng k <= # of distinct elements in nums.
-----Output-----
The output is a list of integers:
Returns exactly k integers representing the elements that appear most frequently in the input list in the order form the higher frequency to lower frequency.
If two numbers have the same frequency, use the order of the first occurance in nums.
| -- !benchmark @start import type=solution
import Std
open Std
-- !benchmark @end import
-- !benchmark @start solution_aux
-- !benchmark @end solution_aux
-- !benchmark @start precond_aux
-- !benchmark @end precond_aux
@[reducible]
def topKFrequent_precond (nums : List Int) (k : Nat) : Prop :=
-- !benchmark @start precond
k ≤ nums.eraseDups.length
-- !benchmark @end precond
-- !benchmark @start code_aux
-- !benchmark @end code_aux
def topKFrequent (nums : List Int) (k : Nat) (h_precond : topKFrequent_precond (nums) (k)) : List Int :=
-- !benchmark @start code
let freqMap : HashMap Int Nat :=
nums.foldl (init := {}) fun acc n =>
let oldVal := match acc.toList.find? (fun (key, _) => key == n) with
| some (_, c) => c
| none => 0
acc.insert n (oldVal + 1)
let sorted := freqMap.toList.foldl
(fun acc pair =>
let (x, cx) := pair
let rec insertSorted (xs : List (Int × Nat)) : List (Int × Nat) :=
match xs with
| [] => [pair]
| (y, cy) :: ys =>
if cx > cy then
pair :: (y, cy) :: ys
else
(y, cy) :: insertSorted ys
insertSorted acc
) []
sorted.take k |>.map (fun (n, _) => n)
-- !benchmark @end code
-- !benchmark @start postcond_aux
-- !benchmark @end postcond_aux
@[reducible]
def topKFrequent_postcond (nums : List Int) (k : Nat) (result: List Int) (h_precond : topKFrequent_precond (nums) (k)) : Prop :=
-- !benchmark @start postcond
-- Result contains exactly k elements
result.length = k ∧
-- All elements in result appear in the original list
result.all (· ∈ nums) ∧
-- All elements in result are distinct
List.Pairwise (· ≠ ·) result ∧
-- For any element in result and any element not in result, the frequency of the
-- element in result is greater or equal
(result.all (fun x =>
nums.all (fun y =>
y ∉ result →
nums.count x > nums.count y ∨
(nums.count x == nums.count y ∧ nums.idxOf x < nums.idxOf y)
))) ∧
-- Elements in result are ordered by decreasing frequency
List.Pairwise (fun (x, i) (y, j) =>
i < j → nums.count x > nums.count y ∨
(nums.count x == nums.count y ∧ nums.idxOf x < nums.idxOf y)
) result.zipIdx
-- !benchmark @end postcond
-- !benchmark @start proof_aux
-- !benchmark @end proof_aux
theorem topKFrequent_spec_satisfied (nums: List Int) (k: Nat) (h_precond : topKFrequent_precond (nums) (k)) :
topKFrequent_postcond (nums) (k) (topKFrequent (nums) (k) h_precond) h_precond := by
-- !benchmark @start proof
sorry
-- !benchmark @end proof
| {
"name": "topKFrequent",
"parameters": {
"param_name": [
"nums",
"k"
],
"param_type": [
"List Int",
"Nat"
]
},
"return_type": "List Int"
} | {
"upstream": {
"name": "lab_assignment",
"link": "https://leetcode.com/problems/top-k-frequent-elements/description/",
"task_id": "lab_topKFrequent_325315163",
"student_id": [
54
]
}
} | {
"input": [
"{\"nums\": \"[1, 1, 1, 2, 2, 3]\", \"k\": 2}",
"{\"nums\": \"[4, 1, -1, 2, -1, 2, 3]\", \"k\": 2}",
"{\"nums\": \"[5]\", \"k\": 1}",
"{\"nums\": \"[7, 7, 7, 8, 8, 9]\", \"k\": 1}",
"{\"nums\": \"[]\", \"k\": 0}"
],
"expected": [
[
"[1, 2]"
],
[
"[-1, 2]"
],
[
"[5]"
],
[
"[7]"
],
[
"[]"
]
],
"unexpected": [
[
"[1, 3]",
"[2, 3]"
],
[
"[-1, 4]",
"[4, 3]"
],
[
"[]"
],
[
"[8]"
],
[
"[0]"
]
]
} | {
"input": [
"{'nums': '[1, 2, 3]', 'k': 4}"
]
} | advanced |
verina_advanced_26 | -----Description-----
This task requires writing a Lean 4 method that generates all possible letter combinations from a string of digits based on the traditional telephone keypad letter mappings.
-----Input-----
The input consists of a string (String). The string may be empty.
-----Output-----
The output is a list of strings (List String) where each string represents a unique combination of letters corresponding to the input digits. If the input string is empty, the output is an empty list.
-----Note-----
Here is the mapping from the number to possible letters:
2: a or b or c
3: d or e or f
4: g or h or i
5: j or k or l
6: m or n or o
7: p or q or r or s
8: t or u or v
9: w or x or y or z
other number or not a number: no letters | -- !benchmark @start import type=solution
-- !benchmark @end import
-- !benchmark @start solution_aux
def digitToLetters (c : Char) : List Char :=
match c with
| '2' => ['a', 'b', 'c']
| '3' => ['d', 'e', 'f']
| '4' => ['g', 'h', 'i']
| '5' => ['j', 'k', 'l']
| '6' => ['m', 'n', 'o']
| '7' => ['p', 'q', 'r', 's']
| '8' => ['t', 'u', 'v']
| '9' => ['w', 'x', 'y', 'z']
| _ => []
-- !benchmark @end solution_aux
-- !benchmark @start precond_aux
-- !benchmark @end precond_aux
@[reducible]
def letterCombinations_precond (digits : String) : Prop :=
-- !benchmark @start precond
True
-- !benchmark @end precond
-- !benchmark @start code_aux
-- !benchmark @end code_aux
def letterCombinations (digits : String) (h_precond : letterCombinations_precond (digits)) : List String :=
-- !benchmark @start code
let chars := digits.toList
go chars
where
go : List Char → List String
| [] => []
| (d :: ds) =>
let restCombinations := go ds
let currentLetters := digitToLetters d
match restCombinations with
| [] => currentLetters.map (λ c => String.singleton c)
| _ => currentLetters.flatMap (λ c => restCombinations.map (λ s => String.singleton c ++ s))
-- !benchmark @end code
-- !benchmark @start postcond_aux
-- !benchmark @end postcond_aux
@[reducible]
def letterCombinations_postcond (digits : String) (result: List String) (h_precond : letterCombinations_precond (digits)) : Prop :=
-- !benchmark @start postcond
if digits.isEmpty then
result = []
else if digits.toList.any (λ c => ¬(c ∈ ['2','3','4','5','6','7','8','9'])) then
result = []
else
let expected := digits.toList.map digitToLetters |>.foldl (λ acc ls => acc.flatMap (λ s => ls.map (λ c => s ++ String.singleton c)) ) [""]
result.length = expected.length ∧ result.all (λ s => s ∈ expected) ∧ expected.all (λ s => s ∈ result)
-- !benchmark @end postcond
-- !benchmark @start proof_aux
-- !benchmark @end proof_aux
theorem letterCombinations_spec_satisfied (digits: String) (h_precond : letterCombinations_precond (digits)) :
letterCombinations_postcond (digits) (letterCombinations (digits) h_precond) h_precond := by
-- !benchmark @start proof
sorry
-- !benchmark @end proof
| {
"name": "letterCombinations",
"parameters": {
"param_name": [
"digits"
],
"param_type": [
"String"
]
},
"return_type": "List String"
} | {
"upstream": {
"name": "lab_assignment",
"link": "https://leetcode.com/problems/letter-combinations-of-a-phone-number/description/",
"task_id": "lab_letterCombinations_325016944",
"student_id": [
20
]
}
} | {
"input": [
"{\"digits\": \"\"}",
"{\"digits\": \"2\"}",
"{\"digits\": \"9\"}",
"{\"digits\": \"23\"}",
"{\"digits\": \"27\"}",
"{\"digits\": \"0\"}"
],
"expected": [
[
"[]"
],
[
"[\"a\", \"b\", \"c\"]"
],
[
"[\"w\", \"x\", \"y\", \"z\"]"
],
[
"[\"ad\", \"ae\", \"af\", \"bd\", \"be\", \"bf\", \"cd\", \"ce\", \"cf\"]"
],
[
"[\"ap\", \"aq\", \"ar\", \"as\", \"bp\", \"bq\", \"br\", \"bs\", \"cp\", \"cq\", \"cr\", \"cs\"]"
],
[
"[]"
]
],
"unexpected": [
[
"[\"a\"]",
"[\"b\"]"
],
[
"[\"a\"]",
"[\"b\"]",
"[\"c\"]"
],
[
"[\"w\"]",
"[\"x\"]",
"[\"y\"]",
"[\"z\"]"
],
[
"[\"a\"]",
"[\"b\"]",
"[\"c\"]"
],
[
"[\"p\"]",
"[\"q\"]",
"[\"r\"]",
"[\"s\"]"
],
[
"[\"a\"]",
"[\"b\"]"
]
]
} | {
"input": []
} | advanced |
verina_basic_80 | -----Description-----
This task involves determining whether a specified key appears exactly once in an array. The goal is to verify the uniqueness of the key's occurrence without prescribing any specific approach or implementation method.
-----Input-----
The input consists of:
• a: An array of integers.
• key: An integer representing the element whose occurrence is to be checked.
-----Output-----
The output is a Boolean value that:
• Is true if the key appears exactly once in the array.
• Is false otherwise.
-----Note-----
The function should correctly handle arrays with no occurrences of the key, multiple occurrences, and exactly one occurrence. | -- !benchmark @start import type=solution
-- !benchmark @end import
-- !benchmark @start solution_aux
-- !benchmark @end solution_aux
-- !benchmark @start precond_aux
-- !benchmark @end precond_aux
@[reducible, simp]
def only_once_precond (a : Array Int) (key : Int) : Prop :=
-- !benchmark @start precond
True
-- !benchmark @end precond
-- !benchmark @start code_aux
def only_once_loop {T : Type} [DecidableEq T] (a : Array T) (key : T) (i keyCount : Nat) : Bool :=
if i < a.size then
match a[i]? with
| some val =>
let newCount := if val = key then keyCount + 1 else keyCount
only_once_loop a key (i + 1) newCount
| none => keyCount == 1
else
keyCount == 1
-- !benchmark @end code_aux
def only_once (a : Array Int) (key : Int) (h_precond : only_once_precond (a) (key)) : Bool :=
-- !benchmark @start code
only_once_loop a key 0 0
-- !benchmark @end code
-- !benchmark @start postcond_aux
def count_occurrences {T : Type} [DecidableEq T] (a : Array T) (key : T) : Nat :=
a.foldl (fun cnt x => if x = key then cnt + 1 else cnt) 0
-- !benchmark @end postcond_aux
@[reducible, simp]
def only_once_postcond (a : Array Int) (key : Int) (result: Bool) (h_precond : only_once_precond (a) (key)) :=
-- !benchmark @start postcond
((count_occurrences a key = 1) → result) ∧
((count_occurrences a key ≠ 1) → ¬ result)
-- !benchmark @end postcond
-- !benchmark @start proof_aux
-- !benchmark @end proof_aux
theorem only_once_spec_satisfied (a: Array Int) (key: Int) (h_precond : only_once_precond (a) (key)) :
only_once_postcond (a) (key) (only_once (a) (key) h_precond) h_precond := by
-- !benchmark @start proof
sorry
-- !benchmark @end proof
| {
"name": "only_once",
"parameters": {
"param_name": [
"a",
"key"
],
"param_type": [
"Array Int",
"Int"
]
},
"return_type": "Bool"
} | {
"upstream": {
"name": "clover",
"link": "https://github.com/ChuyueSun/Clover",
"task_id": "Clover_only_once",
"student_id": null
}
} | {
"input": [
"{\"a\": \"#[1, 2, 3, 4]\", \"key\": 2}",
"{\"a\": \"#[1, 2, 2, 3, 4]\", \"key\": 2}",
"{\"a\": \"#[1, 1, 1, 1]\", \"key\": 1}",
"{\"a\": \"#[10]\", \"key\": 10}",
"{\"a\": \"#[]\", \"key\": 5}"
],
"expected": [
[
"true"
],
[
"false"
],
[
"false"
],
[
"true"
],
[
"false"
]
],
"unexpected": [
[
"False"
],
[
"True"
],
[
"True"
],
[
"False"
],
[
"True"
]
]
} | {
"input": []
} | basic |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.