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_advanced_68
-----Description----- This task requires implementing a Run-Length Encoding (RLE) algorithm in Lean 4. The method should take a string as input and return a compressed string where consecutive duplicate characters are replaced by the character followed by its count. The output must strictly alternate between characters and digits, reconstruct to the original input when decoded, and return a non-empty string if and only if the input is non-empty. -----Input----- The input is a string consisting of any characters (including special characters and digits). -----Output----- The output is a string where each sequence of identical characters is replaced by the character followed by its count. The output must: 1. Alternate between characters and digits (e.g., "a3b2"). 2. Reconstruct to the original input when decoded. 3. Be non-empty if and only if the input is 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] def runLengthEncoder_precond (input : String) : Prop := -- !benchmark @start precond True -- !benchmark @end precond -- !benchmark @start code_aux -- !benchmark @end code_aux def runLengthEncoder (input : String) (h_precond : runLengthEncoder_precond (input)) : String := -- !benchmark @start code -- Convert string to character list let chars : String → List Char := fun s => s.data -- Check character equality let charEq : Char → Char → Bool := fun c1 c2 => c1 == c2 -- Convert number to string let numToString : Nat → String := fun n => let rec digits : Nat → List Char := fun n => if n < 10 then [Char.ofNat (n + 48)] -- ASCII '0' is 48 else digits (n / 10) ++ [Char.ofNat (n % 10 + 48)] String.mk (digits n) -- Main encoding logic (fixed version) let rec encode : List Char → Option Char → Nat → String := fun input currentChar count => match input with | [] => -- Process remaining characters match currentChar with | none => "" | some c => String.mk [c] ++ numToString count | c::rest => match currentChar with | none => encode rest c 1 | some c' => if charEq c c' then encode rest c' (count + 1) else let currentPart := String.mk [c'] ++ numToString count currentPart ++ encode rest c 1 -- Handle empty input if input.isEmpty then "" else let firstChar := (chars input).head? encode (chars input).tail firstChar 1 -- !benchmark @end code -- !benchmark @start postcond_aux -- !benchmark @end postcond_aux @[reducible] def runLengthEncoder_postcond (input : String) (result: String) (h_precond : runLengthEncoder_precond (input)) : Prop := -- !benchmark @start postcond -- Helper functions let chars : String → List Char := fun s => s.data -- Parse encoded string into (char, count) pairs let parseEncodedString : String → List (Char × Nat) := let rec parseState : List Char → Option Char → Option Nat → List (Char × Nat) → List (Char × Nat) := fun remaining currentChar currentCount acc => match remaining with | [] => -- Add final pair if we have both char and count match currentChar, currentCount with | some c, some n => (c, n) :: acc | _, _ => acc | c :: cs => if c.isDigit then match currentChar with | none => [] -- Invalid format: digit without preceding character | some ch => -- Update current count let digit := c.toNat - 48 let newCount := match currentCount with | none => digit | some n => n * 10 + digit parseState cs currentChar (some newCount) acc else -- We found a new character, save previous pair if exists let newAcc := match currentChar, currentCount with | some ch, some n => (ch, n) :: acc | _, _ => acc parseState cs (some c) none newAcc fun s => let result := parseState (chars s) none none [] result.reverse -- Format check: characters followed by at least one digit let formatValid : Bool := let rec checkPairs (chars : List Char) (nowDigit : Bool) : Bool := match chars with | [] => true | c :: cs => if nowDigit && c.isDigit then checkPairs cs true else -- Need at least one digit after character match cs with | [] => false -- Ending with character, no digits | d :: ds => if d.isDigit then checkPairs ds true else false -- No digit after character checkPairs (chars result) false -- Content validation let contentValid : Bool := let pairs := parseEncodedString result let expanded := pairs.flatMap (fun (c, n) => List.replicate n c) expanded == chars input -- Empty check let nonEmptyValid : Bool := input.isEmpty = result.isEmpty formatValid && contentValid && nonEmptyValid -- !benchmark @end postcond -- !benchmark @start proof_aux -- !benchmark @end proof_aux theorem runLengthEncoder_spec_satisfied (input: String) (h_precond : runLengthEncoder_precond (input)) : runLengthEncoder_postcond (input) (runLengthEncoder (input) h_precond) h_precond := by -- !benchmark @start proof sorry -- !benchmark @end proof
{ "name": "runLengthEncoder", "parameters": { "param_name": [ "input" ], "param_type": [ "String" ] }, "return_type": "String" }
{ "upstream": { "name": "lab_assignment", "link": "inspired by: https://leetcode.com/problems/string-compression/description/", "task_id": "lab_runLengthEncoder_325008552", "student_id": [ 49 ] } }
{ "input": [ "{\"input\": \"aaabbbcc\"}", "{\"input\": \"!!!$$$%%%\"}", "{\"input\": \"aaaaa\"}", "{\"input\": \"abcd\"}", "{\"input\": \"\"}", "{\"input\": \"AaABb\"}", "{\"input\": \"wwwwwwwwwwwwwwwww\"}", "{\"input\": \"a\"}", "{\"input\": \" \"}" ], "expected": [ [ "a3b3c2" ], [ "!3$3%3" ], [ "a5" ], [ "a1b1c1d1" ], [ "" ], [ "A1a1A1B1b1" ], [ "w17" ], [ "a1" ], [ " 2" ] ], "unexpected": [ [ "a3b3", "a3b3c2x", "abc" ], [ "!3$3%", "!!!$$$%%", "!3$3%4" ], [ "a4", "a6", "a" ], [ "abcd", "a1b1c1", "a1b1c1d2" ], [ "a1", " " ], [ "AaABb", "A1a1A1B1", "A1a1A1B1b2" ], [ "w16", "w18", "w" ], [ "a", "a2", "" ], [ " ", " 1", " 3" ] ] }
{ "input": [] }
advanced
verina_basic_70
-----Description----- This task involves determining the first index in an array where a given condition holds true. The goal is to identify the position of the first element that meets a specified criterion, ensuring that no preceding element does. -----Input----- The input consists of: • a: An array of elements (for testing purposes, you can assume it is an array of integers). • P: A predicate function on the elements (represented as a string for test cases, e.g., "fun x => x > 5"). It is assumed that at least one element in the array satisfies P. -----Output----- The output is a natural number (Nat) which represents the index of the first element in the array that satisfies the predicate P. • The index returned is less than the size of the array. • The element at the returned index satisfies P. • All elements before the returned index do not satisfy P. -----Note----- It is assumed that the array contains at least one element that satisfies P. In cases where this precondition does not hold, the behavior of the function is not guaranteed by the specification.
-- !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 LinearSearch3_precond (a : Array Int) (P : Int -> Bool) : Prop := -- !benchmark @start precond ∃ i, i < a.size ∧ P (a[i]!) -- !benchmark @end precond -- !benchmark @start code_aux -- !benchmark @end code_aux def LinearSearch3 (a : Array Int) (P : Int -> Bool) (h_precond : LinearSearch3_precond (a) (P)) : Nat := -- !benchmark @start code let rec loop (n : Nat) : Nat := if n < a.size then if P (a[n]!) then n else loop (n + 1) else 0 loop 0 -- !benchmark @end code -- !benchmark @start postcond_aux -- !benchmark @end postcond_aux @[reducible, simp] def LinearSearch3_postcond (a : Array Int) (P : Int -> Bool) (result: Nat) (h_precond : LinearSearch3_precond (a) (P)) := -- !benchmark @start postcond result < a.size ∧ P (a[result]!) ∧ (∀ k, k < result → ¬ P (a[k]!)) -- !benchmark @end postcond -- !benchmark @start proof_aux -- !benchmark @end proof_aux theorem LinearSearch3_spec_satisfied (a: Array Int) (P: Int -> Bool) (h_precond : LinearSearch3_precond (a) (P)) : LinearSearch3_postcond (a) (P) (LinearSearch3 (a) (P) h_precond) h_precond := by -- !benchmark @start proof sorry -- !benchmark @end proof
{ "name": "LinearSearch3", "parameters": { "param_name": [ "a", "P" ], "param_type": [ "Array Int", "Int -> Bool" ] }, "return_type": "Nat" }
{ "upstream": { "name": "clover", "link": "https://github.com/ChuyueSun/Clover", "task_id": "Clover_linear_search3", "student_id": null } }
{ "input": [ "{\"a\": \"#[4, 7, 2, 9]\", \"P\": \"fun x => x > 5\"}", "{\"a\": \"#[10, 8, 6, 4, 2]\", \"P\": \"fun x => x < 5\"}", "{\"a\": \"#[5, 3, 1, 2]\", \"P\": \"fun x => x == 1\"}", "{\"a\": \"#[0, 1, 2, 3]\", \"P\": \"fun x => x == 0\"}", "{\"a\": \"#[9, 9, 9, 9]\", \"P\": \"fun x => x == 9\"}" ], "expected": [ [ "1" ], [ "3" ], [ "2" ], [ "0" ], [ "0" ] ], "unexpected": [ [ "0", "2", "3" ], [ "0", "1", "4" ], [ "0", "1", "3" ], [ "1", "2", "3" ], [ "1", "2", "3" ] ] }
{ "input": [ "{'a': '#[1, 2, 3, 4, 5]', 'P': 'fun x => x > 10'}" ] }
basic
verina_advanced_42
-----Description----- This task requires writing a Lean 4 function that takes a list of stock prices and returns the maximum profit achievable by buying on one day and selling on a later day. If no profit is possible, the function should return 0. -----Input----- The input consists of: prices: A list of natural numbers representing stock prices on each day. -----Output----- The output is a natural number: Returns the maximum profit achievable with one transaction (buy once, sell once), or 0 if no profitable transaction is possible.
-- !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 maxProfit_precond (prices : List Nat) : Prop := -- !benchmark @start precond True -- !benchmark @end precond -- !benchmark @start code_aux def updateMinAndProfit (price : Nat) (minSoFar : Nat) (maxProfit : Nat) : (Nat × Nat) := let newMin := Nat.min minSoFar price let profit := if price > minSoFar then price - minSoFar else 0 let newMaxProfit := Nat.max maxProfit profit (newMin, newMaxProfit) def maxProfitAux (prices : List Nat) (minSoFar : Nat) (maxProfit : Nat) : Nat := match prices with | [] => maxProfit | p :: ps => let (newMin, newProfit) := updateMinAndProfit p minSoFar maxProfit maxProfitAux ps newMin newProfit -- !benchmark @end code_aux def maxProfit (prices : List Nat) (h_precond : maxProfit_precond (prices)) : Nat := -- !benchmark @start code match prices with | [] => 0 | p :: ps => maxProfitAux ps p 0 -- !benchmark @end code -- !benchmark @start postcond_aux -- !benchmark @end postcond_aux @[reducible, simp] def maxProfit_postcond (prices : List Nat) (result: Nat) (h_precond : maxProfit_precond (prices)) : Prop := -- !benchmark @start postcond (result = 0 ∧ prices = []) ∨ ( -- All valid transactions have profit ≤ result (using pairwise) List.Pairwise (fun ⟨pi, i⟩ ⟨pj, j⟩ => i < j → pj - pi ≤ result) prices.zipIdx ∧ -- There exists a transaction with profit = result (using any) prices.zipIdx.any (fun ⟨pi, i⟩ => prices.zipIdx.any (fun ⟨pj, j⟩ => i < j ∧ pj - pi = result)) ) -- !benchmark @end postcond -- !benchmark @start proof_aux -- !benchmark @end proof_aux theorem maxProfit_spec_satisfied (prices: List Nat) (h_precond : maxProfit_precond (prices)) : maxProfit_postcond (prices) (maxProfit (prices) h_precond) h_precond := by -- !benchmark @start proof sorry -- !benchmark @end proof
{ "name": "maxProfit", "parameters": { "param_name": [ "prices" ], "param_type": [ "List Nat" ] }, "return_type": "Nat" }
{ "upstream": { "name": "lab_assignment", "link": "", "task_id": "lab_maxProfit_324256904", "student_id": [ 34 ] } }
{ "input": [ "{\"prices\": \"[7, 1, 5, 3, 6, 4]\"}", "{\"prices\": \"[7, 6, 4, 3, 1]\"}", "{\"prices\": \"[2, 4, 1]\"}", "{\"prices\": \"[1, 2]\"}", "{\"prices\": \"[]\"}" ], "expected": [ [ "5" ], [ "0" ], [ "2" ], [ "1" ], [ "0" ] ], "unexpected": [ [ "4", "6" ], [ "1", "2" ], [ "1" ], [ "0" ], [ "1" ] ] }
{ "input": [] }
advanced
verina_basic_100
-----Description----- This task involves determining the triple of a given integer. The goal is to create a function that, for any integer provided as input, returns a value equal to three times that integer, including handling the case when the input is zero. -----Input----- The input consists of: • x: An integer. -----Output----- The output is an integer that represents three times the input integer. • If x = 0, the output will be 0. • Otherwise, the output will be computed as x + 2 * x, which is equivalent to 3 * x. -----Note----- There are no additional preconditions. It is assumed that x is a valid integer.
-- !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 = 0 then 0 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 split_ifs with h₁ . rw [h₁] simp . 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_triple3", "student_id": null } }
{ "input": [ "{\"x\": 0}", "{\"x\": 1}", "{\"x\": -2}", "{\"x\": 10}", "{\"x\": -5}" ], "expected": [ [ "0" ], [ "3" ], [ "-6" ], [ "30" ], [ "-15" ] ], "unexpected": [ [ "1", "-1", "10" ], [ "2", "4", "0" ], [ "-4", "-2", "6" ], [ "20", "40", "0" ], [ "-10", "-5", "15" ] ] }
{ "input": [] }
basic
verina_basic_95
-----Description----- This problem involves swapping two elements in an array of integers at specified positions. Given an array and two indices, the task is to exchange these elements so that the element from the first index moves to the second index and vice versa, while all other elements remain unchanged. -----Input----- The input consists of: • arr: An array of integers. • i: An integer representing the first index (0-indexed) whose element is to be swapped. • j: An integer representing the second index (0-indexed) whose element is to be swapped. -----Output----- The output is an array of integers which: • Has the same size as the input array. • Contains the element originally at index i in position j and the element originally at index j in position i. • Leaves all other elements unchanged. -----Note----- It is assumed that both indices i and j are non-negative and within the bounds of the array (i.e., Int.toNat i and Int.toNat j are less than arr.size).
-- !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 (arr : Array Int) (i : Int) (j : Int) : Prop := -- !benchmark @start precond i ≥ 0 ∧ j ≥ 0 ∧ Int.toNat i < arr.size ∧ Int.toNat j < arr.size -- !benchmark @end precond -- !benchmark @start code_aux -- !benchmark @end code_aux def swap (arr : Array Int) (i : Int) (j : Int) (h_precond : swap_precond (arr) (i) (j)) : Array Int := -- !benchmark @start code let i_nat := Int.toNat i let j_nat := Int.toNat j let arr1 := arr.set! i_nat (arr[j_nat]!) let arr2 := arr1.set! j_nat (arr[i_nat]!) arr2 -- !benchmark @end code -- !benchmark @start postcond_aux -- !benchmark @end postcond_aux @[reducible, simp] def swap_postcond (arr : Array Int) (i : Int) (j : Int) (result: Array Int) (h_precond : swap_precond (arr) (i) (j)) := -- !benchmark @start postcond (result[Int.toNat i]! = arr[Int.toNat j]!) ∧ (result[Int.toNat j]! = arr[Int.toNat i]!) ∧ (∀ (k : Nat), k < arr.size → k ≠ Int.toNat i → k ≠ Int.toNat j → result[k]! = arr[k]!) -- !benchmark @end postcond -- !benchmark @start proof_aux -- !benchmark @end proof_aux theorem swap_spec_satisfied (arr: Array Int) (i: Int) (j: Int) (h_precond : swap_precond (arr) (i) (j)) : swap_postcond (arr) (i) (j) (swap (arr) (i) (j) h_precond) h_precond := by -- !benchmark @start proof unfold swap_postcond swap unfold swap_precond at h_precond obtain ⟨h₁, h₂, h₃, h₄⟩ := h_precond apply And.intro . simp by_cases h_eq : (i = j) . rw [h_eq] rw [Array.getElem!_eq_getD] rw [Array.setIfInBounds] simp [h₄] . rw [Array.setIfInBounds_comm] let arr₁ := arr.setIfInBounds j.toNat arr[i.toNat]! have ha₁ : arr₁ = arr.setIfInBounds j.toNat arr[i.toNat]! := rfl let arr_j := arr[j.toNat]! have hi : arr_j = arr[j.toNat]! := rfl rw [←ha₁, ←hi] have h₃' : i.toNat < (arr₁.setIfInBounds i.toNat arr_j).size := by rw [ha₁] unfold Array.setIfInBounds split . simp split . simp exact h₃ . simp exact h₃ . split . simp exact h₃ . simp exact h₃ rw [Array.getElem!_eq_getD] unfold Array.getD split . simp . simp intro h have h_contr : i = j := by rw [← Int.toNat_of_nonneg h₁, ← Int.toNat_of_nonneg h₂] rw [h] contradiction . apply And.intro . simp by_cases h_eq : (i = j) . rw [h_eq] rw [Array.getElem!_eq_getD] rw [Array.setIfInBounds] simp [h₄] . let arr₁ := arr.setIfInBounds i.toNat arr[j.toNat]! have ha₁ : arr₁ = arr.setIfInBounds i.toNat arr[j.toNat]! := rfl let arr_i := arr[i.toNat]! have hi : arr_i = arr[i.toNat]! := rfl rw [←ha₁, ←hi] have h₃' : j.toNat < (arr₁.setIfInBounds j.toNat arr_i).size := by rw [ha₁] unfold Array.setIfInBounds split . simp split . simp exact h₄ . simp exact h₄ . split . simp exact h₄ . simp exact h₄ rw [Array.getElem!_eq_getD] unfold Array.getD split . simp . rename_i h contradiction . simp intro k hk hki hkj let arr₁ := (arr.setIfInBounds i.toNat arr[j.toNat]!) let harr₁ : arr₁ = (arr.setIfInBounds i.toNat arr[j.toNat]!) := rfl rw [←harr₁] have h₁ : arr₁[k]! = arr[k]! := by rw [Array.getElem!_eq_getD] rw [Array.getD] simp split . rw [Array.getElem_setIfInBounds_ne arr arr[j.toNat]! hk] rw [Array.getElem!_eq_getD] rw [Array.getD] simp split . rfl . rfl apply ne_comm.mp exact hki . rename_i h_contr rw [harr₁] at h_contr simp only [Array.size_setIfInBounds] at h_contr contradiction rw [Array.getElem!_eq_getD] rw [Array.getD] simp split . rw [Array.getElem_setIfInBounds_ne arr₁ arr[i.toNat]!] rw [←h₁] rw [Array.getElem!_eq_getD] rw [Array.getD] simp split . simp . simp rename_i h exact h rw [ne_comm] exact hkj . rename_i h_contr have h : arr.size = arr₁.size := by rw [harr₁] simp rw [←h] at h_contr contradiction -- !benchmark @end proof
{ "name": "swap", "parameters": { "param_name": [ "arr", "i", "j" ], "param_type": [ "Array Int", "Int", "Int" ] }, "return_type": "Array Int" }
{ "upstream": { "name": "clover", "link": "https://github.com/ChuyueSun/Clover", "task_id": "Clover_swap_in_array", "student_id": null } }
{ "input": [ "{\"arr\": \"#[1, 2, 3, 4, 5]\", \"i\": 1, \"j\": 3}", "{\"arr\": \"#[10, 20, 30, 40]\", \"i\": 0, \"j\": 3}", "{\"arr\": \"#[7, 8, 9]\", \"i\": 1, \"j\": 2}", "{\"arr\": \"#[1, 2, 3, 4]\", \"i\": 0, \"j\": 0}", "{\"arr\": \"#[-1, -2, -3]\", \"i\": 0, \"j\": 2}" ], "expected": [ [ "#[1, 4, 3, 2, 5]" ], [ "#[40, 20, 30, 10]" ], [ "#[7, 9, 8]" ], [ "#[1, 2, 3, 4]" ], [ "#[-3, -2, -1]" ] ], "unexpected": [ [ "#[1, 2, 3, 4, 5]", "#[1, 3, 2, 4, 5]" ], [ "#[10, 40, 30, 20]", "#[10, 20, 40, 30]" ], [ "#[8, 7, 9]", "#[9, 8, 7]" ], [ "#[1, 2, 4, 3]", "#[4, 2, 3, 1]" ], [ "#[-1, -2, -3]", "#[-3, -1, -2]" ] ] }
{ "input": [ "{'arr': '#[1, 2, 3, 4]', 'i': -1, 'j': 2}" ] }
basic
verina_advanced_81
-----Description----- Implement a Lean 4 function that, given a list of integers, removes all duplicates and returns the resulting list in ascending order. -----Input----- The input consists of a single list of integers: arr: A list of integers. -----Output----- The output is a list of integers: Returns a list containing the unique elements of the input, sorted in ascending order. The returned list must not contain any duplicates, and every element in the output must appear in the original 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, simp] def uniqueSorted_precond (arr : List Int) : Prop := -- !benchmark @start precond True -- !benchmark @end precond -- !benchmark @start code_aux -- !benchmark @end code_aux def uniqueSorted (arr : List Int) (h_precond : uniqueSorted_precond (arr)) : List Int := -- !benchmark @start code let rec insert (x : Int) (sorted : List Int) : List Int := match sorted with | [] => [x] | head :: tail => if x <= head then x :: head :: tail else head :: insert x tail let rec insertionSort (xs : List Int) : List Int := match xs with | [] => [] | h :: t => let sortedTail := insertionSort t insert h sortedTail let removeDups : List Int → List Int | xs => let rec aux (remaining : List Int) (seen : List Int) (acc : List Int) : List Int := match remaining with | [] => acc.reverse | h :: t => if h ∈ seen then aux t seen acc else aux t (h :: seen) (h :: acc) aux xs [] [] insertionSort (removeDups arr) -- !benchmark @end code -- !benchmark @start postcond_aux -- !benchmark @end postcond_aux @[reducible, simp] def uniqueSorted_postcond (arr : List Int) (result: List Int) (h_precond : uniqueSorted_precond (arr)) : Prop := -- !benchmark @start postcond List.isPerm arr.eraseDups result ∧ List.Pairwise (· ≤ ·) result -- !benchmark @end postcond -- !benchmark @start proof_aux -- !benchmark @end proof_aux theorem uniqueSorted_spec_satisfied (arr: List Int) (h_precond : uniqueSorted_precond (arr)) : uniqueSorted_postcond (arr) (uniqueSorted (arr) h_precond) h_precond := by -- !benchmark @start proof sorry -- !benchmark @end proof
{ "name": "uniqueSorted", "parameters": { "param_name": [ "arr" ], "param_type": [ "List Int" ] }, "return_type": "List Int" }
{ "upstream": { "name": "lab_assignment", "link": "", "task_id": "lab_uniqueSorted_325097530", "student_id": [ 17 ] } }
{ "input": [ "{\"arr\": \"[1, 1, 2, 3]\"}", "{\"arr\": \"[3, 3, 3]\"}", "{\"arr\": \"[]\"}", "{\"arr\": \"[5, 2, 2, 5]\"}", "{\"arr\": \"[1, 2, 3, 4, 5]\"}" ], "expected": [ [ "[1, 2, 3]" ], [ "[3]" ], [ "[]" ], [ "[2, 5]" ], [ "[1, 2, 3, 4, 5]" ] ], "unexpected": [ [ "[1, 1, 2, 3]", "[2, 3, 1]", "[1, 3, 2]" ], [ "[3, 3, 3]", "[3, 3]", "[3, 3, 3, 3]" ], [ "[0]", "[1]", "[999]" ], [ "[5, 2]", "[2, 2, 5]", "[2]" ], [ "[1, 2, 3]", "[2, 3, 4, 5]", "[5, 4, 3, 2, 1]" ] ] }
{ "input": [] }
advanced
verina_basic_46
-----Description----- This task requires writing a Lean 4 method that finds the last occurrence of a specified element in a sorted array of integers. The method should return the index corresponding to the last occurrence of the element if it is present; if the element is absent, it should return -1. Additionally, the array must remain unchanged after the method is executed. -----Input----- The input consists of: arr: A sorted array of integers in non-decreasing order. elem: An integer whose last occurrence position is to be determined. -----Output----- The output is an integer: Returns the index of the last occurrence of the specified integer in the array if it exists. Returns -1 if the integer is not found in the array. -----Note----- The input array is assumed to be sorted in non-decreasing order and remains unchanged by the method.
-- !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 lastPosition_precond (arr : Array Int) (elem : Int) : Prop := -- !benchmark @start precond List.Pairwise (· ≤ ·) arr.toList -- !benchmark @end precond -- !benchmark @start code_aux -- !benchmark @end code_aux def lastPosition (arr : Array Int) (elem : Int) (h_precond : lastPosition_precond (arr) (elem)) : Int := -- !benchmark @start code let rec loop (i : Nat) (pos : Int) : Int := if i < arr.size then let a := arr[i]! if a = elem then loop (i + 1) i else loop (i + 1) pos else pos loop 0 (-1) -- !benchmark @end code -- !benchmark @start postcond_aux -- !benchmark @end postcond_aux @[reducible, simp] def lastPosition_postcond (arr : Array Int) (elem : Int) (result: Int) (h_precond : lastPosition_precond (arr) (elem)) := -- !benchmark @start postcond (result ≥ 0 → arr[result.toNat]! = elem ∧ (arr.toList.drop (result.toNat + 1)).all (· ≠ elem)) ∧ (result = -1 → arr.toList.all (· ≠ elem)) -- !benchmark @end postcond -- !benchmark @start proof_aux -- !benchmark @end proof_aux theorem lastPosition_spec_satisfied (arr: Array Int) (elem: Int) (h_precond : lastPosition_precond (arr) (elem)) : lastPosition_postcond (arr) (elem) (lastPosition (arr) (elem) h_precond) h_precond := by -- !benchmark @start proof sorry -- !benchmark @end proof
{ "name": "lastPosition", "parameters": { "param_name": [ "arr", "elem" ], "param_type": [ "Array Int", "Int" ] }, "return_type": "Int" }
{ "upstream": { "name": "dafny-synthesis", "link": "https://github.com/Mondego/dafny-synthesis", "task_id": "task_id_793", "student_id": null } }
{ "input": [ "{\"arr\": \"#[1, 2, 2, 3, 4, 5]\", \"elem\": 2}", "{\"arr\": \"#[1, 2, 2, 3, 4, 5]\", \"elem\": 6}", "{\"arr\": \"#[1, 2, 2, 3, 4, 5]\", \"elem\": 5}", "{\"arr\": \"#[1]\", \"elem\": 1}", "{\"arr\": \"#[1, 1, 1, 1]\", \"elem\": 1}", "{\"arr\": \"#[2, 2, 3, 3, 3]\", \"elem\": 3}" ], "expected": [ [ "2" ], [ "-1" ], [ "5" ], [ "0" ], [ "3" ], [ "4" ] ], "unexpected": [ [ "0", "1", "3" ], [ "0", "1", "2" ], [ "3", "4", "0" ], [ "1", "-1", "2" ], [ "0", "1", "2" ], [ "2", "3", "5" ] ] }
{ "input": [ "{'arr': '#[3, 2, 1]', 'elem': 2}" ] }
basic
verina_basic_14
-----Description----- This task requires writing a Lean 4 method that determines whether a given string contains the character 'z' or 'Z'. The method should return true if the string includes either the lowercase or uppercase letter 'z', and false otherwise. -----Input----- The input consists of: s: A string. -----Output----- The output is a Boolean value: Returns true if the input string contains the character 'z' or 'Z'. Returns false if the input string does not contain the character 'z' or 'Z'. -----Note----- There are no preconditions; the method will always work as strings and sequences are considered 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 containsZ_precond (s : String) : Prop := -- !benchmark @start precond True -- !benchmark @end precond -- !benchmark @start code_aux -- !benchmark @end code_aux def containsZ (s : String) (h_precond : containsZ_precond (s)) : Bool := -- !benchmark @start code s.toList.any fun c => c = 'z' || c = 'Z' -- !benchmark @end code -- !benchmark @start postcond_aux -- !benchmark @end postcond_aux @[reducible, simp] def containsZ_postcond (s : String) (result: Bool) (h_precond : containsZ_precond (s)) := -- !benchmark @start postcond let cs := s.toList (∃ x, x ∈ cs ∧ (x = 'z' ∨ x = 'Z')) ↔ result -- !benchmark @end postcond -- !benchmark @start proof_aux -- !benchmark @end proof_aux theorem containsZ_spec_satisfied (s: String) (h_precond : containsZ_precond (s)) : containsZ_postcond (s) (containsZ (s) h_precond) h_precond := by -- !benchmark @start proof unfold containsZ containsZ_postcond simp_all -- !benchmark @end proof
{ "name": "containsZ", "parameters": { "param_name": [ "s" ], "param_type": [ "String" ] }, "return_type": "Bool" }
{ "upstream": { "name": "dafny-synthesis", "link": "https://github.com/Mondego/dafny-synthesis", "task_id": "task_id_454", "student_id": null } }
{ "input": [ "{\"s\": \"hello\"}", "{\"s\": \"zebra\"}", "{\"s\": \"Zebra\"}", "{\"s\": \"\"}", "{\"s\": \"crazy\"}", "{\"s\": \"AZ\"}", "{\"s\": \"abc\"}", "{\"s\": \"Zz\"}", "{\"s\": \"no letter\"}" ], "expected": [ [ "False" ], [ "True" ], [ "True" ], [ "False" ], [ "True" ], [ "True" ], [ "False" ], [ "True" ], [ "False" ] ], "unexpected": [ [ "True" ], [ "False" ], [ "False" ], [ "True" ], [ "False" ], [ "False" ], [ "True" ], [ "False" ], [ "True" ] ] }
{ "input": [] }
basic
verina_basic_36
-----Description----- This task requires writing a Lean 4 method that takes a given string and returns a new string where every occurrence of a space, comma, or dot is replaced with a colon. The transformation must preserve the original string’s length and leave all other characters unmodified. -----Input----- The input consists of: s: A string. -----Output----- The output is a string: - The returned string must have the same length as the input string. - Every space, comma, or dot in the input string is replaced with a colon. - All other characters remain unchanged. -----Note----- There are no preconditions; the input string is assumed to be non-null.
-- !benchmark @start import type=solution -- !benchmark @end import -- !benchmark @start solution_aux def isSpaceCommaDot (c : Char) : Bool := if c = ' ' then true else if c = ',' then true else if c = '.' then true else false -- !benchmark @end solution_aux -- !benchmark @start precond_aux -- !benchmark @end precond_aux @[reducible, simp] def replaceWithColon_precond (s : String) : Prop := -- !benchmark @start precond True -- !benchmark @end precond -- !benchmark @start code_aux -- !benchmark @end code_aux def replaceWithColon (s : String) (h_precond : replaceWithColon_precond (s)) : String := -- !benchmark @start code let cs := s.toList let cs' := cs.map (fun c => if isSpaceCommaDot c then ':' else c) String.mk cs' -- !benchmark @end code -- !benchmark @start postcond_aux -- !benchmark @end postcond_aux @[reducible, simp] def replaceWithColon_postcond (s : String) (result: String) (h_precond : replaceWithColon_precond (s)) := -- !benchmark @start postcond let cs := s.toList let cs' := result.toList result.length = s.length ∧ (∀ i, i < s.length → (isSpaceCommaDot cs[i]! → cs'[i]! = ':') ∧ (¬isSpaceCommaDot cs[i]! → cs'[i]! = cs[i]!)) -- !benchmark @end postcond -- !benchmark @start proof_aux -- !benchmark @end proof_aux theorem replaceWithColon_spec_satisfied (s: String) (h_precond : replaceWithColon_precond (s)) : replaceWithColon_postcond (s) (replaceWithColon (s) h_precond) h_precond := by -- !benchmark @start proof unfold replaceWithColon replaceWithColon_postcond simp 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": "replaceWithColon", "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_732", "student_id": null } }
{ "input": [ "{\"s\": \"Hello, world. How are you?\"}", "{\"s\": \"No-changes!\"}", "{\"s\": \",. \"}", "{\"s\": \"\"}" ], "expected": [ [ "Hello::world::How:are:you?" ], [ "No-changes!" ], [ ":::" ], [ "" ] ], "unexpected": [ [ "Hello,world,How,are,you?", "Hello: world: How: are: you?" ], [ "No changes!", "No–changes!" ], [ "::", ";:;", "::: " ], [ " ", "a" ] ] }
{ "input": [] }
basic
verina_advanced_64
-----Description----- This task requires writing a Lean 4 method that removes all occurrences of a given element from a list of natural numbers. The method should return a new list that contains all the elements of the original list except those equal to the target number. The order of the remaining elements must be preserved. -----Input----- The input consists of two elements: lst: A list of natural numbers (List Nat). target: A natural number to be removed from the list. -----Output----- The output is a list of natural numbers: Returns a new list with all occurrences of the target number removed. The relative order of the remaining elements must be the same as 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 removeElement_precond (lst : List Nat) (target : Nat) : Prop := -- !benchmark @start precond True -- !benchmark @end precond -- !benchmark @start code_aux -- !benchmark @end code_aux def removeElement (lst : List Nat) (target : Nat) (h_precond : removeElement_precond (lst) (target)) : List Nat := -- !benchmark @start code let rec helper (lst : List Nat) (target : Nat) : List Nat := match lst with | [] => [] | x :: xs => let rest := helper xs target if x = target then rest else x :: rest helper lst target -- !benchmark @end code -- !benchmark @start postcond_aux -- !benchmark @end postcond_aux @[reducible] def removeElement_postcond (lst : List Nat) (target : Nat) (result: List Nat) (h_precond : removeElement_precond (lst) (target)): Prop := -- !benchmark @start postcond -- 1. All elements equal to target are removed from the result. -- 2. All other elements are preserved in order. -- 3. No new elements are added. -- Helper predicate: result contains exactly the elements of lst that are not equal to target, in order let lst' := lst.filter (fun x => x ≠ target) result.zipIdx.all (fun (x, i) => match lst'[i]? with | some y => x = y | none => false) ∧ result.length = lst'.length -- !benchmark @end postcond -- !benchmark @start proof_aux -- !benchmark @end proof_aux theorem removeElement_spec_satisfied (lst: List Nat) (target: Nat) (h_precond : removeElement_precond (lst) (target)): removeElement_postcond (lst) (target) (removeElement (lst) (target) h_precond) h_precond := by -- !benchmark @start proof sorry -- !benchmark @end proof
{ "name": "removeElement", "parameters": { "param_name": [ "lst", "target" ], "param_type": [ "List Nat", "Nat" ] }, "return_type": "List Nat" }
{ "upstream": { "name": "lab_assignment", "link": "https://leetcode.com/problems/remove-element/", "task_id": "lab_removeElement_323929890", "student_id": [ 47 ] } }
{ "input": [ "{\"lst\": \"[1, 2, 3, 2, 4]\", \"target\": 2}", "{\"lst\": \"[5, 5, 5, 5]\", \"target\": 5}", "{\"lst\": \"[7, 8, 9]\", \"target\": 4}", "{\"lst\": \"[]\", \"target\": 3}", "{\"lst\": \"[0, 1, 0, 2, 0]\", \"target\": 0}" ], "expected": [ [ "[1, 3, 4]" ], [ "[]" ], [ "[7, 8, 9]" ], [ "[]" ], [ "[1, 2]" ] ], "unexpected": [ [ "[1, 2, 3, 4]", "[1, 2, 3]", "[1, 4]" ], [ "[5]", "[0]", "[5, 5]" ], [ "[]", "[7, 8]", "[8, 9]" ], [ "[3]", "[0]", "[1, 2, 3]" ], [ "[0, 1, 2]", "[1]", "[1, 0, 2]" ] ] }
{ "input": [] }
advanced
verina_basic_49
-----Description----- This task requires writing a Lean 4 method that searches an array of integers to locate the first odd number. The method should return a pair where the first element is a Boolean indicating whether an odd number was found, and the second element is the index of that odd number if found, or -1 if no odd number exists. When an odd number is found, the method should return the smallest index at which an odd number occurs. -----Input----- The input consists of: a: An array of integers. -----Output----- The output is a pair (Bool, Int): - If the Boolean is true, then the integer represents the smallest index of an odd number in the array. - If the Boolean is false, then there are no odd numbers in the array, and the accompanying integer is -1. -----Note----- - The input array is assumed to be non-null. - If multiple odd numbers are present, the index returned should correspond to the first occurrence.
-- !benchmark @start import type=solution -- !benchmark @end import -- !benchmark @start solution_aux def isOdd (x : Int) : Bool := x % 2 ≠ 0 -- !benchmark @end solution_aux -- !benchmark @start precond_aux -- !benchmark @end precond_aux @[reducible, simp] def findFirstOdd_precond (a : Array Int) : Prop := -- !benchmark @start precond a.size > 0 -- !benchmark @end precond -- !benchmark @start code_aux -- !benchmark @end code_aux def findFirstOdd (a : Array Int) (h_precond : findFirstOdd_precond (a)) : Option Nat := -- !benchmark @start code -- Creates list of (index, value) pairs let indexed := a.toList.zipIdx -- Find the first pair where the value is odd let found := List.find? (fun (x, _) => isOdd x) indexed -- Extract the index from the found pair (if any) Option.map (fun (_, i) => i) found -- !benchmark @end code -- !benchmark @start postcond_aux -- !benchmark @end postcond_aux @[reducible, simp] def findFirstOdd_postcond (a : Array Int) (result: Option Nat) (h_precond : findFirstOdd_precond (a)) := -- !benchmark @start postcond match result with | some idx => idx < a.size ∧ isOdd (a[idx]!) ∧ (∀ j, j < idx → ¬ isOdd (a[j]!)) | none => ∀ i, i < a.size → ¬ isOdd (a[i]!) -- !benchmark @end postcond -- !benchmark @start proof_aux -- !benchmark @end proof_aux theorem findFirstOdd_spec_satisfied (a: Array Int) (h_precond : findFirstOdd_precond (a)) : findFirstOdd_postcond (a) (findFirstOdd (a) h_precond) h_precond := by -- !benchmark @start proof unfold findFirstOdd findFirstOdd_postcond let la := a.toList have h_la : la = a.toList := by rfl let indexed := la.zipIdx have h_indexed : indexed = la.zipIdx := by rfl let found := List.find? (fun (x, _) => isOdd x) indexed have h_found : found = List.find? (fun (x, _) => isOdd x) indexed := by rfl let res := Option.map (fun (_, i) => i) found have h_res : res = Option.map (fun (_, i) => i) found := by rfl simp_all cases h_rescase : res with | none => rw [← h_res, h_rescase] simp rw [h_rescase] at h_res have h_notfound : found = none := by rw [h_found] exact Option.map_eq_none.mp h_rescase rw [List.find?_eq_none] at h_notfound simp at h_notfound intro i hi have hi' : i < la.length := by exact hi have h_mem : (la[i], i) ∈ indexed := by have : la[i]? = some la[i] := by exact (List.getElem?_eq_some_getElem_iff la i hi').mpr trivial apply List.mem_zipIdx_iff_getElem?.mpr simp have hai : a[i]! = a[i] := by exact getElem!_pos a i hi' rw [hai] exact h_notfound a[i] i h_mem | some i => rw [← h_res, h_rescase] rw [h_res] at h_rescase simp rw [Option.map_eq_some'] at h_rescase rcases h_rescase with ⟨p, ⟨h_found', hp⟩⟩ have h_mem : p ∈ indexed := by exact List.mem_of_find?_eq_some h_found' have ⟨_, hi, hx⟩ := List.mem_zipIdx h_mem have ⟨h_odd, ⟨i', hi', hii', h_prefix⟩⟩ := List.find?_eq_some_iff_getElem.mp h_found' simp_all have hai : a[i]! = a[i] := by exact getElem!_pos a i hi rw [hai] constructor · exact h_odd · intro j hj have hii' : i = i' := by rw [← hii'] at hp simp_all have hj' : j < a.size := by exact Nat.lt_trans hj hi have haj : a[j]! = a[j] := by exact getElem!_pos a j hj' rw [haj] rw [hii'] at hj exact h_prefix j hj -- !benchmark @end proof
{ "name": "findFirstOdd", "parameters": { "param_name": [ "a" ], "param_type": [ "Array Int" ] }, "return_type": "Option Nat" }
{ "upstream": { "name": "dafny-synthesis", "link": "https://github.com/Mondego/dafny-synthesis", "task_id": "task_id_807", "student_id": null } }
{ "input": [ "{\"a\": \"#[2, 4, 6, 8]\"}", "{\"a\": \"#[3, 4, 6, 8]\"}", "{\"a\": \"#[2, 4, 5, 8]\"}", "{\"a\": \"#[7]\"}", "{\"a\": \"#[2]\"}", "{\"a\": \"#[1, 2, 3]\"}" ], "expected": [ [ "none" ], [ "some (0)" ], [ "some (2)" ], [ "some (0)" ], [ "none" ], [ "some (0)" ] ], "unexpected": [ [ "some (0)" ], [ "some (1)", "some (2)", "none" ], [ "some (0)", "some (1)", "some (3)", "none" ], [ "some (1)", "none" ], [ "some (0)" ], [ "some (1)", "some (2)", "none" ] ] }
{ "input": [ "{'a': '#[]'}" ] }
basic
verina_basic_8
-----Description----- This task requires writing a Lean 4 method that determines the minimum of two integers. The method should return the smaller of the two numbers. When both numbers are equal, either one may be returned. -----Input----- The input consists of two integers: a: The first integer. b: The second integer. -----Output----- The output is an integer: Returns the smaller value between the input integers, ensuring that the result is less than or equal to both inputs.
-- !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 myMin_precond (a : Int) (b : Int) : Prop := -- !benchmark @start precond True -- !benchmark @end precond -- !benchmark @start code_aux -- !benchmark @end code_aux def myMin (a : Int) (b : Int) (h_precond : myMin_precond (a) (b)) : Int := -- !benchmark @start code if a <= b then a else b -- !benchmark @end code -- !benchmark @start postcond_aux -- !benchmark @end postcond_aux @[reducible, simp] def myMin_postcond (a : Int) (b : Int) (result: Int) (h_precond : myMin_precond (a) (b)) := -- !benchmark @start postcond (result ≤ a ∧ result ≤ b) ∧ (result = a ∨ result = b) -- !benchmark @end postcond -- !benchmark @start proof_aux -- !benchmark @end proof_aux theorem myMin_spec_satisfied (a: Int) (b: Int) (h_precond : myMin_precond (a) (b)) : myMin_postcond (a) (b) (myMin (a) (b) h_precond) h_precond := by -- !benchmark @start proof unfold myMin myMin_postcond constructor · split case left.isTrue h => simp exact h case left.isFalse h => simp rw [Int.not_le] at h exact Int.le_of_lt h · split <;> simp -- !benchmark @end proof
{ "name": "myMin", "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_404", "student_id": null } }
{ "input": [ "{\"a\": 3, \"b\": 5}", "{\"a\": 10, \"b\": 7}", "{\"a\": 4, \"b\": 4}", "{\"a\": -3, \"b\": 5}", "{\"a\": 3, \"b\": -5}", "{\"a\": -3, \"b\": -5}", "{\"a\": 0, \"b\": 10}", "{\"a\": 0, \"b\": -10}" ], "expected": [ [ "3" ], [ "7" ], [ "4" ], [ "-3" ], [ "-5" ], [ "-5" ], [ "0" ], [ "-10" ] ], "unexpected": [ [ "5", "4", "8" ], [ "10", "8", "9" ], [ "0", "8", "2" ], [ "5", "0", "-5" ], [ "3", "0", "-3" ], [ "-3", "0", "-1" ], [ "10", "1", "-1" ], [ "0", "-1", "-5" ] ] }
{ "input": [] }
basic
verina_advanced_33
-----Description----- This task requires implementing the "Longest Increasing Subsequence" problem in Lean 4. Given a list of integers, the function should compute the length of the longest strictly increasing subsequence. A subsequence is formed by deleting zero or more elements without changing the order. If the list is empty, the function should return 0. -----Input----- - nums: A list of integers. -----Output----- - A natural number representing the length of the longest strictly increasing subsequence. - If there is no increasing subsequence, return 0.
-- !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, simp] 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)) : Nat := -- !benchmark @start code let max2 (a : Nat) (b : Nat) : Nat := if a > b then a else b let rec listLength (l : List Int) : Nat := match l with | [] => 0 | _ :: xs => 1 + listLength xs let rec helper (lst : List Int) (prev : Option Int) : Nat := match lst with | [] => 0 | h :: t => let canTake : Bool := if prev = none then true else if prev.get! < h then true else false let withTake : Nat := if canTake then 1 + helper t (some h) else 0 let withoutTake : Nat := helper t prev max2 withTake withoutTake let result := helper nums none result -- !benchmark @end code -- !benchmark @start postcond_aux -- !benchmark @end postcond_aux @[reducible, simp] def longestIncreasingSubsequence_postcond (nums : List Int) (result: Nat) (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": "Nat" }
{ "upstream": { "name": "lab_assignment", "link": "[{\"text_file_id\"=>804930699}]", "task_id": "lab_longestIncreasingSubsequence_325684656", "student_id": [ 27 ] } }
{ "input": [ "{\"nums\": \"[10, 9, 2, 5, 3, 7, 101, 18]\"}", "{\"nums\": \"[0, 1, 0, 3, 2, 3]\"}", "{\"nums\": \"[7, 7, 7, 7, 7]\"}", "{\"nums\": \"[]\"}", "{\"nums\": \"[4, 10, 4, 3, 8, 9]\"}" ], "expected": [ [ "4" ], [ "4" ], [ "1" ], [ "0" ], [ "3" ] ], "unexpected": [ [ "3", "5" ], [ "3" ], [ "0", "2" ], [ "1" ], [ "2", "4" ] ] }
{ "input": [] }
advanced
verina_basic_59
-----Description----- Given an integer x, determine a pair (a, b) where the first element is twice the value of x and the second element is four times the value of x. -----Input----- The input consists of: • x: An integer. -----Output----- The output is a tuple (a, b) where: • a = 2 * x • b = 4 * x -----Note----- There are no additional preconditions; the method is defined for all 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 DoubleQuadruple_precond (x : Int) : Prop := -- !benchmark @start precond True -- !benchmark @end precond -- !benchmark @start code_aux -- !benchmark @end code_aux def DoubleQuadruple (x : Int) (h_precond : DoubleQuadruple_precond (x)) : (Int × Int) := -- !benchmark @start code let a := 2 * x let b := 2 * a (a, b) -- !benchmark @end code -- !benchmark @start postcond_aux -- !benchmark @end postcond_aux @[reducible, simp] def DoubleQuadruple_postcond (x : Int) (result: (Int × Int)) (h_precond : DoubleQuadruple_precond (x)) := -- !benchmark @start postcond result.fst = 2 * x ∧ result.snd = 2 * result.fst -- !benchmark @end postcond -- !benchmark @start proof_aux -- !benchmark @end proof_aux theorem DoubleQuadruple_spec_satisfied (x: Int) (h_precond : DoubleQuadruple_precond (x)) : DoubleQuadruple_postcond (x) (DoubleQuadruple (x) h_precond) h_precond := by -- !benchmark @start proof sorry -- !benchmark @end proof
{ "name": "DoubleQuadruple", "parameters": { "param_name": [ "x" ], "param_type": [ "Int" ] }, "return_type": "(Int × Int)" }
{ "upstream": { "name": "clover", "link": "https://github.com/ChuyueSun/Clover", "task_id": "Clover_double_quadruple", "student_id": null } }
{ "input": [ "{\"x\": 0}", "{\"x\": 1}", "{\"x\": -1}", "{\"x\": 10}", "{\"x\": -5}" ], "expected": [ [ "(0, 0)" ], [ "(2, 4)" ], [ "(-2, -4)" ], [ "(20, 40)" ], [ "(-10, -20)" ] ], "unexpected": [ [ "(1, 0)", "(0, 1)", "(-1, 0)" ], [ "(2, 2)", "(1, 4)", "(3, 4)" ], [ "(-2, -2)", "(-1, -4)", "(-3, -4)" ], [ "(20, 20)", "(10, 40)", "(20, 0)" ], [ "(-10, -10)", "(-5, -20)", "(-15, -20)" ] ] }
{ "input": [] }
basic
verina_advanced_56
-----Description----- This task requires writing a Lean 4 method that moves all zeroes in a given integer list to the end, while preserving the relative order of the non-zero elements. The method `moveZeroes` processes the input list by separating the non-zero and zero elements. It then returns a new list formed by appending all non-zero elements followed by all the zero elements. -----Input----- The input is a single list of integers: xs: A list of integers (type: List Int), possibly containing zero and non-zero values. -----Output----- The output is a list of integers: Returns a list (type: List Int) with the same elements as the input, where all zeroes appear at the end, and the non-zero elements maintain their original relative 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 moveZeroes_precond (xs : List Int) : Prop := -- !benchmark @start precond True -- !benchmark @end precond -- !benchmark @start code_aux -- Count how many times a specific value appears in the list -- !benchmark @end code_aux def moveZeroes (xs : List Int) (h_precond : moveZeroes_precond (xs)) : List Int := -- !benchmark @start code let nonzeros := xs.filter (fun x => x ≠ 0) let zeros := xs.filter (fun x => x = 0) nonzeros ++ zeros -- !benchmark @end code -- !benchmark @start postcond_aux def countVal (val : Int) : List Int → Nat | [] => 0 | x :: xs => let rest := countVal val xs if x = val then rest + 1 else rest -- Check whether one list is a subsequence of another (preserving relative order) def isSubsequence (xs ys : List Int) : Bool := match xs, ys with | [], _ => true | _ :: _, [] => false | x :: xt, y :: yt => if x = y then isSubsequence xt yt else isSubsequence xs yt -- !benchmark @end postcond_aux @[reducible] def moveZeroes_postcond (xs : List Int) (result: List Int) (h_precond : moveZeroes_precond (xs)) : Prop := -- !benchmark @start postcond -- 1. All non-zero elements must maintain their relative order isSubsequence (xs.filter (fun x => x ≠ 0)) result = true ∧ -- 2. All zeroes must be located at the end of the output list (result.dropWhile (fun x => x ≠ 0)).all (fun x => x = 0) ∧ -- 3. The output must contain the same number of elements, -- and the number of zeroes must remain unchanged countVal 0 xs = countVal 0 result ∧ xs.length = result.length -- !benchmark @end postcond -- !benchmark @start proof_aux -- !benchmark @end proof_aux theorem moveZeroes_spec_satisfied (xs: List Int) (h_precond : moveZeroes_precond (xs)) : moveZeroes_postcond (xs) (moveZeroes (xs) h_precond) h_precond := by -- !benchmark @start proof sorry -- !benchmark @end proof
{ "name": "moveZeroes", "parameters": { "param_name": [ "xs" ], "param_type": [ "List Int" ] }, "return_type": "List Int" }
{ "upstream": { "name": "lab_assignment", "link": "https://leetcode.com/problems/move-zeroes/description/", "task_id": "lab_moveZeroes_324883943", "student_id": [ 41 ] } }
{ "input": [ "{\"xs\": \"[0, 1, 0, 3, 12]\"}", "{\"xs\": \"[0, 0, 1]\"}", "{\"xs\": \"[1, 2, 3]\"}", "{\"xs\": \"[0, 0, 0]\"}", "{\"xs\": \"[]\"}", "{\"xs\": \"[4, 0, 5, 0, 6]\"}", "{\"xs\": \"[0, 1]\"}", "{\"xs\": \"[1, 0]\"}", "{\"xs\": \"[2, 0, 0, 3]\"}" ], "expected": [ [ "[1, 3, 12, 0, 0]" ], [ "[1, 0, 0]" ], [ "[1, 2, 3]" ], [ "[0, 0, 0]" ], [ "[]" ], [ "[4, 5, 6, 0, 0]" ], [ "[1, 0]" ], [ "[1, 0]" ], [ "[2, 3, 0, 0]" ] ], "unexpected": [ [ "[0, 1, 3, 12, 0]" ], [ "[0, 1, 0]" ], [ "[1, 3, 2]", "[0, 1, 2, 3]" ], [ "[0, 0]", "[]", "[0]" ], [ "[0]" ], [ "[0, 4, 5, 6, 0]" ], [ "[0, 1]" ], [ "[0, 1]" ], [ "[0, 0, 2, 3]", "[2, 0, 3, 0]" ] ] }
{ "input": [] }
advanced
verina_basic_60
-----Description----- This task requires writing a function that processes an array of integers and produces a new array containing only the even numbers from the input. The order of these even numbers should remain the same as in the original array, ensuring that every even number from the input appears in the output and that every element in the output is even. -----Input----- The input consists of one parameter: • arr: An array of integers. -----Output----- The output is an array of integers that: • Contains exactly all even numbers from the input array, preserving their original order. • Meets the specified conditions that ensure no extraneous (odd or non-existing) elements are returned. -----Note----- There are no additional preconditions. The function must adhere to the provided specification which enforces evenness and order preservation for the elements in the output array.
-- !benchmark @start import type=solution -- !benchmark @end import -- !benchmark @start solution_aux def isEven (n : Int) : Bool := n % 2 = 0 -- !benchmark @end solution_aux -- !benchmark @start precond_aux -- !benchmark @end precond_aux @[reducible, simp] def FindEvenNumbers_precond (arr : Array Int) : Prop := -- !benchmark @start precond True -- !benchmark @end precond -- !benchmark @start code_aux -- !benchmark @end code_aux def FindEvenNumbers (arr : Array Int) (h_precond : FindEvenNumbers_precond (arr)) : Array Int := -- !benchmark @start code let rec loop (i : Nat) (acc : Array Int) : Array Int := if i < arr.size then if isEven (arr.getD i 0) then loop (i + 1) (acc.push (arr.getD i 0)) else loop (i + 1) acc else acc loop 0 (Array.mkEmpty 0) -- !benchmark @end code -- !benchmark @start postcond_aux -- !benchmark @end postcond_aux @[reducible, simp] def FindEvenNumbers_postcond (arr : Array Int) (result: Array Int) (h_precond : FindEvenNumbers_precond (arr)) := -- !benchmark @start postcond result.all (fun x => isEven x && x ∈ arr) ∧ List.Pairwise (fun (x, i) (y, j) => if i < j then arr.idxOf x ≤ arr.idxOf y else true) (result.toList.zipIdx) -- !benchmark @end postcond -- !benchmark @start proof_aux -- !benchmark @end proof_aux theorem FindEvenNumbers_spec_satisfied (arr: Array Int) (h_precond : FindEvenNumbers_precond (arr)) : FindEvenNumbers_postcond (arr) (FindEvenNumbers (arr) h_precond) h_precond := by -- !benchmark @start proof sorry -- !benchmark @end proof
{ "name": "FindEvenNumbers", "parameters": { "param_name": [ "arr" ], "param_type": [ "Array Int" ] }, "return_type": "Array Int" }
{ "upstream": { "name": "clover", "link": "https://github.com/ChuyueSun/Clover", "task_id": "Clover_even_list", "student_id": null } }
{ "input": [ "{\"arr\": \"#[1, 2, 3, 4, 5, 6]\"}", "{\"arr\": \"#[0, -2, 3, -4, 7]\"}", "{\"arr\": \"#[1, 3, 5, 7]\"}", "{\"arr\": \"#[2, 4, 8, 10]\"}", "{\"arr\": \"#[]\"}" ], "expected": [ [ "#[2, 4, 6]" ], [ "#[0, -2, -4]" ], [ "#[]" ], [ "#[2, 4, 8, 10]" ], [ "#[]" ] ], "unexpected": [ [ "#[2, 4, 5]", "#[1, 2, 3, 4]", "#[2, 3, 6]" ], [ "#[0, 3, -4]", "#[0, -2, 3]" ], [ "#[1]", "#[0, 1]" ], [ "#[2, 4, 8, 9]", "#[2, 4, 8, 10, 12]" ], [ "#[0]", "#[1, 2]" ] ] }
{ "input": [] }
basic
verina_advanced_38
-----Description----- This task requires implementing a Lean 4 method that, given a list of intervals, returns the maximum amount that can be spanned after we removed one of the intervals You may assume you'll receive at least one interval -----Input----- The input consists of a list of ordered pairs of intervals. -----Output----- The output is an integer: Return the largest span that is possible after removing one of the intervals.
-- !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 maxCoverageAfterRemovingOne_precond (intervals : List (Prod Nat Nat)) : Prop := -- !benchmark @start precond intervals.length > 0 -- !benchmark @end precond -- !benchmark @start code_aux -- !benchmark @end code_aux def maxCoverageAfterRemovingOne (intervals : List (Prod Nat Nat)) (h_precond : maxCoverageAfterRemovingOne_precond (intervals)) : Nat := -- !benchmark @start code let n := intervals.length if n ≤ 1 then 0 else (List.range n).foldl (fun acc i => let remaining := List.eraseIdx intervals i let sorted := List.mergeSort remaining (fun (a b : Nat × Nat) => a.1 ≤ b.1) let merged := sorted.foldl (fun acc curr => match acc with | [] => [curr] | (s, e) :: rest => if curr.1 ≤ e then (s, max e curr.2) :: rest else curr :: acc ) [] let coverage := merged.reverse.foldl (fun acc (s, e) => acc + (e - s)) 0 max acc coverage ) 0 -- !benchmark @end code -- !benchmark @start postcond_aux -- !benchmark @end postcond_aux @[reducible, simp] def maxCoverageAfterRemovingOne_postcond (intervals : List (Prod Nat Nat)) (result: Nat) (h_precond : maxCoverageAfterRemovingOne_precond (intervals)) : Prop := -- !benchmark @start postcond ∃ i < intervals.length, let remaining := List.eraseIdx intervals i let sorted := List.mergeSort remaining (fun (a b : Nat × Nat) => a.1 ≤ b.1) let merged := sorted.foldl (fun acc curr => match acc with | [] => [curr] | (s, e) :: rest => if curr.1 ≤ e then (s, max e curr.2) :: rest else curr :: acc ) [] let cov := merged.reverse.foldl (fun acc (s, e) => acc + (e - s)) 0 result = cov ∧ ∀ j < intervals.length, let rem_j := List.eraseIdx intervals j let sort_j := List.mergeSort rem_j (fun (a b : Nat × Nat) => a.1 ≤ b.1) let merged_j := sort_j.foldl (fun acc curr => match acc with | [] => [curr] | (s, e) :: rest => if curr.1 ≤ e then (s, max e curr.2) :: rest else curr :: acc ) [] let cov_j := merged_j.reverse.foldl (fun acc (s, e) => acc + (e - s)) 0 cov ≥ cov_j -- !benchmark @end postcond -- !benchmark @start proof_aux -- !benchmark @end proof_aux theorem maxCoverageAfterRemovingOne_spec_satisfied (intervals: List (Prod Nat Nat)) (h_precond : maxCoverageAfterRemovingOne_precond (intervals)) : maxCoverageAfterRemovingOne_postcond (intervals) (maxCoverageAfterRemovingOne (intervals) h_precond) h_precond := by -- !benchmark @start proof sorry -- !benchmark @end proof
{ "name": "maxCoverageAfterRemovingOne", "parameters": { "param_name": [ "intervals" ], "param_type": [ "List (Prod Nat Nat)" ] }, "return_type": "Nat" }
{ "upstream": { "name": "lab_assignment", "link": "[{\"text_file_id\"=>804563720}]", "task_id": "lab_maxCoverageAfterRemovingOne_325587004", "student_id": [ 31 ] } }
{ "input": [ "{\"intervals\": \"[(1, 3), (2, 5), (6, 8)]\"}", "{\"intervals\": \"[(1, 4), (2, 6), (8, 10), (9, 12)]\"}", "{\"intervals\": \"[(1, 2), (2, 3), (3, 4)]\"}", "{\"intervals\": \"[(1, 10), (2, 3), (4, 5)]\"}", "{\"intervals\": \"[(5, 6), (1, 2), (3, 4)]\"}" ], "expected": [ [ "5" ], [ "8" ], [ "2" ], [ "9" ], [ "2" ] ], "unexpected": [ [ "4", "6" ], [ "7", "6" ], [ "3" ], [ "7", "10" ], [ "5", "3" ] ] }
{ "input": [ "{'intervals': '[]'}" ] }
advanced
verina_basic_68
-----Description----- The task is to determine the position of a target integer in a given array. The goal is to return the index corresponding to the first occurrence of the target value. If the target is not present in the array, the result should indicate that by returning the size of the array. This description focuses entirely on understanding the problem without specifying any particular implementation method. -----Input----- The input consists of: • a: An array of integers. • e: An integer representing the target to search for in the array. -----Output----- The output is a natural number (Nat) which is: • The index of the first occurrence of the target integer if found. • The size of the array if the target integer is not present. -----Note----- There are no strict preconditions on the input; the method should work correctly for any array of integers. The specification ensures that the returned index is always valid: it is either within the array bounds with a matching element or equals the array’s size if the element is absent.
-- !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 LinearSearch_precond (a : Array Int) (e : Int) : Prop := -- !benchmark @start precond True -- !benchmark @end precond -- !benchmark @start code_aux -- !benchmark @end code_aux def LinearSearch (a : Array Int) (e : Int) (h_precond : LinearSearch_precond (a) (e)) : Nat := -- !benchmark @start code let rec loop (n : Nat) : Nat := if n < a.size then if a[n]! = e then n else loop (n + 1) else n loop 0 -- !benchmark @end code -- !benchmark @start postcond_aux -- !benchmark @end postcond_aux @[reducible, simp] def LinearSearch_postcond (a : Array Int) (e : Int) (result: Nat) (h_precond : LinearSearch_precond (a) (e)) := -- !benchmark @start postcond result ≤ a.size ∧ (result = a.size ∨ a[result]! = e) ∧ (∀ i, i < result → a[i]! ≠ e) -- !benchmark @end postcond -- !benchmark @start proof_aux -- !benchmark @end proof_aux theorem LinearSearch_spec_satisfied (a: Array Int) (e: Int) (h_precond : LinearSearch_precond (a) (e)) : LinearSearch_postcond (a) (e) (LinearSearch (a) (e) h_precond) h_precond := by -- !benchmark @start proof unfold LinearSearch_postcond LinearSearch apply And.intro . let aux (x : Nat) : (0 ≤ x) → (x ≤ a.size) → LinearSearch.loop a e x ≤ a.size := by intro hx₀ hx₁ let nx := a.size - x have hn₁ : nx = a.size - x := by rfl have hn₂ : x = a.size - nx := by rw [hn₁, Nat.sub_sub_self] apply hx₁ rw [hn₂] induction nx with | zero => unfold LinearSearch.loop simp | succ n₁ ih => by_cases hp : (a.size ≤ n₁) . rw [Nat.sub_eq_zero_of_le hp] at ih have h_tmp : a.size ≤ n₁ + 1 := Nat.le_add_right_of_le hp rw [Nat.sub_eq_zero_of_le h_tmp] exact ih . have hq : n₁ < a.size := Nat.not_le.mp hp unfold LinearSearch.loop simp split_ifs . simp . rw [Nat.sub_add_eq, Nat.sub_add_cancel] exact ih apply Nat.zero_lt_sub_of_lt exact hq simp have h₀ : 0 ≤ a.size := by simp have h_triv : 0 ≤ 0 := by simp exact aux 0 h_triv h₀ . apply And.intro . let aux (x : Nat) : (x ≥ 0) → (x ≤ a.size) → LinearSearch.loop a e x = a.size ∨ a[LinearSearch.loop a e x]! = e := by intro hx₀ hx₁ let nx := a.size - x have hn₁ : nx = a.size - x := by rfl have hn₂ : x = a.size - nx := by rw [hn₁, Nat.sub_sub_self] apply hx₁ rw [hn₂] induction nx with | zero => unfold LinearSearch.loop simp | succ n₁ ih => -- Ohh boy... by_cases hp : (a.size ≤ n₁) . rw [Nat.sub_eq_zero_of_le hp] at ih have h_tmp : a.size ≤ n₁ + 1 := Nat.le_add_right_of_le hp rw [Nat.sub_eq_zero_of_le h_tmp] exact ih . have hq : n₁ < a.size := Nat.not_le.mp hp apply Or.elim ih -- Didn't find elem, so we're gonna also return a.size... . intro ih₁ unfold LinearSearch.loop split_ifs . rename_i h₁ h₂ rw [h₂] simp . rename_i ha₁ ha₂ rw [Nat.sub_add_eq, Nat.sub_add_cancel] rw [ih₁] simp apply Nat.zero_lt_sub_of_lt exact hq . rename_i h₁ have ha₁ := Nat.not_lt.mp h₁ have ha₂ := Nat.sub_le a.size (n₁ + 1) have ha := Nat.eq_iff_le_and_ge.mpr ⟨ha₁, ha₂⟩ rw [←ha] simp . intro ih₂ unfold LinearSearch.loop split_ifs . rename_i h₁ h₂ rw [h₂] simp . rename_i ha₁ ha₂ rw [Nat.sub_add_eq, Nat.sub_add_cancel] rw [ih₂] simp apply Nat.zero_lt_sub_of_lt exact hq . rename_i h₁ have ha₁ := Nat.not_lt.mp h₁ have ha₂ := Nat.sub_le a.size (n₁ + 1) have ha := Nat.eq_iff_le_and_ge.mpr ⟨ha₁, ha₂⟩ rw [←ha] simp have h₀ : 0 ≤ 0 := by simp have h₁ : 0 ≤ a.size := by simp exact aux 0 h₀ h₁ . let aux (x : Nat) : (0 ≤ x) → (x ≤ a.size) → (∀ i, x ≤ i → i < LinearSearch.loop a e x → a[i]! ≠ e) := by intro hx₀ hx₁ i let nx := a.size - x have hn₁ : nx = a.size - x := by rfl have hn₂ : x = a.size - nx := by rw [hn₁, Nat.sub_sub_self] apply hx₁ rw [hn₂] induction nx with | zero => -- There's no such i unfold LinearSearch.loop simp intro hxi hi have h_contr := Nat.lt_of_le_of_lt hxi hi have h : a.size ≤ a.size := by simp have h : a.size - a.size < a.size - a.size := Nat.sub_lt_sub_right h h_contr simp at h | succ n ih => intro hxi unfold LinearSearch.loop simp split_ifs . rename_i h₁ h₂ intro h_contr have h := Nat.lt_of_le_of_lt hxi h_contr simp at h . rename_i h₁ h₂ by_cases hp : (a.size ≤ n) . rw [Nat.sub_eq_zero_iff_le.mpr hp] at ih intro hi have hp₁ : a.size ≤ n + 1 := by have h₁' : n ≤ n + 1 := by simp exact Nat.le_trans hp h₁' rw [Nat.sub_eq_zero_iff_le.mpr hp₁] at hxi rw [Nat.sub_eq_zero_iff_le.mpr hp₁] at hi rw [Nat.sub_eq_zero_iff_le.mpr hp₁] at h₂ have ih₁ := ih hxi simp at hi unfold LinearSearch.loop at ih₁ split_ifs at ih₁ . rename_i h₁' simp at ih₁ exact ih₁ hi . rename_i h₁' contradiction . have hq : n < a.size := Nat.not_le.mp hp have hq' : 1 ≤ a.size - n := by have h : 0 < a.size - n := by exact Nat.sub_pos_of_lt hq exact Nat.one_le_iff_ne_zero.mpr (Nat.ne_zero_of_lt h) rw [Nat.sub_add_eq, Nat.sub_add_cancel hq'] intro hi by_cases h_bounds : (a.size - n ≤ i) . exact ih h_bounds hi . have h_bounds' : ( i + 1 < a.size - n + 1) := (@Nat.add_lt_add_iff_right 1 i (a.size - n)).mpr (Nat.not_le.mp h_bounds) have h := Nat.le_of_lt_add_one h_bounds' apply Nat.le_sub_of_add_le at h rw [← Nat.sub_add_eq] at h have hi_fixed := Nat.eq_iff_le_and_ge.mpr ⟨hxi, h⟩ rw [hi_fixed] at h₂ exact h₂ . intro h_contr have h := Nat.lt_of_le_of_lt hxi h_contr simp at h have h₀ : 0 ≤ a.size := by simp have h_triv : 0 ≤ 0 := by simp intro i have h_tmp : 0 ≤ i := Nat.zero_le i exact aux 0 h_triv h₀ i h_tmp -- !benchmark @end proof
{ "name": "LinearSearch", "parameters": { "param_name": [ "a", "e" ], "param_type": [ "Array Int", "Int" ] }, "return_type": "Nat" }
{ "upstream": { "name": "clover", "link": "https://github.com/ChuyueSun/Clover", "task_id": "Clover_linear_search1", "student_id": null } }
{ "input": [ "{\"a\": \"#[1, 3, 5, 7, 9]\", \"e\": 5}", "{\"a\": \"#[2, 4, 6, 8]\", \"e\": 5}", "{\"a\": \"#[5, 5, 5]\", \"e\": 5}", "{\"a\": \"#[10, 9, 8, 7]\", \"e\": 10}", "{\"a\": \"#[1, 2, 3, 3, 4]\", \"e\": 3}" ], "expected": [ [ "2" ], [ "4" ], [ "0" ], [ "0" ], [ "2" ] ], "unexpected": [ [ "1", "3", "4" ], [ "1", "3", "5" ], [ "1", "2", "3" ], [ "1", "2", "3" ], [ "1", "3", "4" ] ] }
{ "input": [] }
basic
verina_advanced_71
-----Description----- This task requires writing a Lean 4 method that, given a binary string `s` and an integer `k`, finds the shortest contiguous substring that contains exactly `k` characters `'1'`. Among all substrings of `s` that contain exactly `k` occurrences of `'1'`, return the one that is shortest in length. If there are multiple such substrings with the same length, return the lexicographically smallest one. If no such substring exists, return the empty string. -----Input----- - s: A binary string (only consisting of characters `'0'` and `'1'`) - k: A natural number (k ≥ 0) -----Output----- A string representing the shortest substring of `s` that contains exactly `k` ones. If no such substring exists, return `""`.
-- !benchmark @start import type=solution -- !benchmark @end import -- !benchmark @start solution_aux def countOnes (lst : List Char) : Nat := lst.foldl (fun acc c => if c = '1' then acc + 1 else acc) 0 -- !benchmark @end solution_aux -- !benchmark @start precond_aux -- !benchmark @end precond_aux @[reducible] def shortestBeautifulSubstring_precond (s : String) (k : Nat) : Prop := -- !benchmark @start precond s.toList.all (fun c => c = '0' ∨ c = '1') -- !benchmark @end precond -- !benchmark @start code_aux def listToString (lst : List Char) : String := String.mk lst def isLexSmaller (a b : List Char) : Bool := listToString a < listToString b def allSubstrings (s : List Char) : List (List Char) := let n := s.length (List.range n).flatMap (fun i => (List.range (n - i)).map (fun j => s.drop i |>.take (j + 1))) -- !benchmark @end code_aux def shortestBeautifulSubstring (s : String) (k : Nat) (h_precond : shortestBeautifulSubstring_precond (s) (k)) : String := -- !benchmark @start code let chars := s.data let candidates := allSubstrings chars |>.filter (fun sub => countOnes sub = k) let compare (a b : List Char) : Bool := a.length < b.length ∨ (a.length = b.length ∧ isLexSmaller a b) let best := candidates.foldl (fun acc cur => match acc with | none => some cur | some best => if compare cur best then some cur else some best) none match best with | some b => listToString b | none => "" -- !benchmark @end code -- !benchmark @start postcond_aux -- !benchmark @end postcond_aux @[reducible] def shortestBeautifulSubstring_postcond (s : String) (k : Nat) (result: String) (h_precond : shortestBeautifulSubstring_precond (s) (k)) : Prop := -- !benchmark @start postcond let chars := s.data let substrings := (List.range chars.length).flatMap (fun i => (List.range (chars.length - i + 1)).map (fun len => chars.drop i |>.take len)) let isBeautiful := fun sub => countOnes sub = k let beautiful := substrings.filter (fun sub => isBeautiful sub) let targets := beautiful.map (·.asString) |>.filter (fun s => s ≠ "") (result = "" ∧ targets = []) ∨ (result ∈ targets ∧ ∀ r ∈ targets, r.length ≥ result.length ∨ (r.length = result.length ∧ result ≤ r)) -- !benchmark @end postcond -- !benchmark @start proof_aux -- !benchmark @end proof_aux theorem shortestBeautifulSubstring_spec_satisfied (s: String) (k: Nat) (h_precond : shortestBeautifulSubstring_precond (s) (k)) : shortestBeautifulSubstring_postcond (s) (k) (shortestBeautifulSubstring (s) (k) h_precond) h_precond := by -- !benchmark @start proof sorry -- !benchmark @end proof
{ "name": "shortestBeautifulSubstring", "parameters": { "param_name": [ "s", "k" ], "param_type": [ "String", "Nat" ] }, "return_type": "String" }
{ "upstream": { "name": "lab_assignment", "link": "https://huggingface.co/spaces/livecodebench/code_generation_samples", "task_id": "lab_shortestBeautifulSubstring_325098964", "student_id": [ 32 ] } }
{ "input": [ "{\"s\": \"100011001\", \"k\": 3}", "{\"s\": \"1011\", \"k\": 2}", "{\"s\": \"000\", \"k\": 1}", "{\"s\": \"11111\", \"k\": 3}", "{\"s\": \"10100101\", \"k\": 2}", "{\"s\": \"1001001\", \"k\": 2}", "{\"s\": \"10010001\", \"k\": 1}", "{\"s\": \"1001\", \"k\": 0}" ], "expected": [ [ "11001" ], [ "11" ], [ "" ], [ "111" ], [ "101" ], [ "1001" ], [ "1" ], [ "0" ] ], "unexpected": [ [ "00011", "10001", "" ], [ "101", "01", "" ], [ "0", "00", "000" ], [ "11", "1111", "" ], [ "010", "1001", "0101" ], [ "0010", "0100", "001" ], [ "10", "100", "000" ], [ "10", "100", "1" ] ] }
{ "input": [ "{'s': '2', 'k': 1}" ] }
advanced
verina_advanced_59
-----Description----- This task requires writing a Lean 4 method that determines if a given string is a palindrome, ignoring all non-alphanumeric characters and case differences. For example, the string "A man, a plan, a canal: Panama" should return true. -----Input----- A single string: s: The string to check for palindrome property. -----Output----- A boolean (Bool): true if s is a palindrome when ignoring non-alphanumeric characters and case. false otherwise.
-- !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 palindromeIgnoreNonAlnum_precond (s : String) : Prop := -- !benchmark @start precond True -- !benchmark @end precond -- !benchmark @start code_aux -- !benchmark @end code_aux def palindromeIgnoreNonAlnum (s : String) (h_precond : palindromeIgnoreNonAlnum_precond (s)) : Bool := -- !benchmark @start code let cleaned : List Char := s.data.filter (fun c => c.isAlpha || c.isDigit) |>.map Char.toLower let n := cleaned.length let startIndex := 0 let endIndex := if n = 0 then 0 else n - 1 let rec check (l r : Nat) : Bool := if l >= r then true else if cleaned[l]? = cleaned[r]? then check (l + 1) (r - 1) else false check startIndex endIndex -- !benchmark @end code -- !benchmark @start postcond_aux -- !benchmark @end postcond_aux @[reducible] def palindromeIgnoreNonAlnum_postcond (s : String) (result: Bool) (h_precond : palindromeIgnoreNonAlnum_precond (s)) : Prop := -- !benchmark @start postcond let cleaned := s.data.filter (fun c => c.isAlpha || c.isDigit) |>.map Char.toLower let forward := cleaned let backward := cleaned.reverse if result then forward = backward else forward ≠ backward -- !benchmark @end postcond -- !benchmark @start proof_aux -- !benchmark @end proof_aux theorem palindromeIgnoreNonAlnum_spec_satisfied (s: String) (h_precond : palindromeIgnoreNonAlnum_precond (s)) : palindromeIgnoreNonAlnum_postcond (s) (palindromeIgnoreNonAlnum (s) h_precond) h_precond := by -- !benchmark @start proof sorry -- !benchmark @end proof
{ "name": "palindromeIgnoreNonAlnum", "parameters": { "param_name": [ "s" ], "param_type": [ "String" ] }, "return_type": "Bool" }
{ "upstream": { "name": "lab_assignment", "link": "N/A", "task_id": "lab_palindromeIgnoreNonAlnum_325057855", "student_id": [ 17 ] } }
{ "input": [ "{\"s\": \"\"}", "{\"s\": \"A man, a plan, a canal: Panama\"}", "{\"s\": \"race a car\"}", "{\"s\": \"No 'x' in Nixon\"}", "{\"s\": \"abc!!cba?\"}", "{\"s\": \"Hello, world!\"}" ], "expected": [ [ "True" ], [ "True" ], [ "False" ], [ "True" ], [ "True" ], [ "False" ] ], "unexpected": [ [ "False" ], [ "False" ], [ "True" ], [ "False" ], [ "False" ], [ "True" ] ] }
{ "input": [] }
advanced
verina_advanced_24
-----Description----- This task requires writing a Lean 4 method that determines the length of the longest strictly increasing subsequence in a given array of integers. A subsequence is a sequence that can be derived from the array by deleting some or no elements without changing the order of the remaining elements. The subsequence must be strictly increasing, meaning each element must be greater than the one before it. The goal is to find the length of the longest such subsequence that can be formed from the input array. -----Input----- The input consists of one array: nums: An array of integers where nums[i] represents the ith element of the input sequence. -----Output----- The output is an integer: Returns the length of the longest strictly increasing subsequence in the input 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 lengthOfLIS_precond (nums : List Int) : Prop := -- !benchmark @start precond True -- !benchmark @end precond -- !benchmark @start code_aux -- !benchmark @end code_aux def lengthOfLIS (nums : List Int) (h_precond : lengthOfLIS_precond (nums)) : Int := -- !benchmark @start code let rec lisHelper (dp : List Int) (x : Int) : List Int := let rec replace (l : List Int) (acc : List Int) : List Int := match l with | [] => (acc.reverse ++ [x]) | y :: ys => if x ≤ y then acc.reverse ++ (x :: ys) else replace ys (y :: acc) replace dp [] let finalDP := nums.foldl lisHelper [] finalDP.length -- !benchmark @end code -- !benchmark @start postcond_aux -- !benchmark @end postcond_aux @[reducible, simp] def lengthOfLIS_postcond (nums : List Int) (result: Int) (h_precond : lengthOfLIS_precond (nums)) : Prop := -- !benchmark @start postcond -- Helper function to check strictly increasing let rec isStrictlyIncreasing (l : List Int) : Bool := match l with | [] | [_] => true | x :: y :: rest => x < y && isStrictlyIncreasing (y :: rest) -- Generate all subsequences let rec subsequences (xs : List Int) : List (List Int) := match xs with | [] => [[]] | x :: xs' => let rest := subsequences xs' rest ++ rest.map (fun r => x :: r) let allIncreasing := subsequences nums |>.filter (fun l => isStrictlyIncreasing l) allIncreasing.any (fun l => l.length = result) ∧ allIncreasing.all (fun l => l.length ≤ result) -- !benchmark @end postcond -- !benchmark @start proof_aux -- !benchmark @end proof_aux theorem lengthOfLIS_spec_satisfied (nums: List Int) (h_precond : lengthOfLIS_precond (nums)) : lengthOfLIS_postcond (nums) (lengthOfLIS (nums) h_precond) h_precond := by -- !benchmark @start proof sorry -- !benchmark @end proof
{ "name": "lengthOfLIS", "parameters": { "param_name": [ "nums" ], "param_type": [ "List Int" ] }, "return_type": "Int" }
{ "upstream": { "name": "lab_assignment", "link": "[{\"text_file_id\"=>804740897}]", "task_id": "lab_lengthOfLIS_325627981", "student_id": [ 6 ] } }
{ "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\": \"[4, 10, 4, 3, 8, 9]\"}", "{\"nums\": \"[1, 3, 6, 7, 9, 4, 10, 5, 6]\"}" ], "expected": [ [ "4" ], [ "4" ], [ "1" ], [ "3" ], [ "6" ] ], "unexpected": [ [ "1", "2", "8" ], [ "1", "3", "6" ], [ "0", "6", "7" ], [ "1", "2", "6" ], [ "1", "4", "9" ] ] }
{ "input": [] }
advanced
verina_advanced_69
-----Description----- Given a sorted list of distinct integers and a target value, return the index if the target is found. If it is not found, return the index where it would be inserted to maintain the sorted order. This function must preserve the sorted property of the list. The list is assumed to be strictly increasing and contain no duplicates. -----Input----- xs : List Int — a sorted list of distinct integers in increasing order target : Int — the integer to search for -----Output----- A natural number (Nat) representing the index at which the target is found, or the index at which it should be inserted to maintain 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] def searchInsert_precond (xs : List Int) (target : Int) : Prop := -- !benchmark @start precond List.Pairwise (· < ·) xs -- !benchmark @end precond -- !benchmark @start code_aux -- !benchmark @end code_aux def searchInsert (xs : List Int) (target : Int) (h_precond : searchInsert_precond (xs) (target)) : Nat := -- !benchmark @start code match xs with | [] => 0 | _ :: _ => let rec helper : List Int → Nat → Nat := fun ys idx => match ys with | [] => idx | y :: ys' => let isCurrent := y let currentIndex := idx let targetValue := target let condition := targetValue ≤ isCurrent if condition then currentIndex else let incrementedIndex := currentIndex + 1 let rest := ys' helper rest incrementedIndex let startingIndex := 0 let result := helper xs startingIndex result -- !benchmark @end code -- !benchmark @start postcond_aux -- !benchmark @end postcond_aux @[reducible] def searchInsert_postcond (xs : List Int) (target : Int) (result: Nat) (h_precond : searchInsert_precond (xs) (target)) : Prop := -- !benchmark @start postcond let allBeforeLess := (List.range result).all (fun i => xs[i]! < target) let inBounds := result ≤ xs.length let insertedCorrectly := result < xs.length → target ≤ xs[result]! inBounds ∧ allBeforeLess ∧ insertedCorrectly -- !benchmark @end postcond -- !benchmark @start proof_aux -- !benchmark @end proof_aux theorem searchInsert_spec_satisfied (xs: List Int) (target: Int) (h_precond : searchInsert_precond (xs) (target)) : searchInsert_postcond (xs) (target) (searchInsert (xs) (target) h_precond) h_precond := by -- !benchmark @start proof sorry -- !benchmark @end proof
{ "name": "searchInsert", "parameters": { "param_name": [ "xs", "target" ], "param_type": [ "List Int", "Int" ] }, "return_type": "Nat" }
{ "upstream": { "name": "lab_assignment", "link": "https://leetcode.com/problems/search-insert-position/", "task_id": "lab_searchInsert_325772357", "student_id": [ 50 ] } }
{ "input": [ "{\"xs\": \"[1, 3, 5, 6]\", \"target\": 5}", "{\"xs\": \"[1, 3, 5, 6]\", \"target\": 2}", "{\"xs\": \"[1, 3, 5, 6]\", \"target\": 7}", "{\"xs\": \"[1, 3, 5, 6]\", \"target\": 0}", "{\"xs\": \"[]\", \"target\": 3}", "{\"xs\": \"[10]\", \"target\": 5}", "{\"xs\": \"[10]\", \"target\": 15}" ], "expected": [ [ "2" ], [ "1" ], [ "4" ], [ "0" ], [ "0" ], [ "0" ], [ "1" ] ], "unexpected": [ [ "0", "1", "3", "4" ], [ "0", "2", "3" ], [ "2", "3" ], [ "1", "2" ], [ "1" ], [ "1" ], [ "0" ] ] }
{ "input": [ "{'xs': '[2, 1]', 'target': 5}", "{'xs': '[1, 1]', 'target': 2}" ] }
advanced
verina_advanced_2
-----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, simp] 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, simp] 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": "", "task_id": "lab_LongestCommonSubsequence_324999618", "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_advanced_52
-----Description----- This task requires writing a Lean 4 function that finds the minimum number of operations to collect the integers from 1 to k by performing the following removal operation on a list of integers. A removal operation consists of removing the last element from the list nums and adding it to your collection. The goal is to determine how many elements must be removed from the end of the list until the set of collected elements (that are less than or equal to k) contains all integers from 1 to k, inclusive. -----Input----- The input consists of a list and a positive integer: nums: A list of positive integers. k: A positive integer representing the target upper bound for the collection (i.e., we want to collect 1, 2, ..., k). -----Output----- The output is an integer: Return the minimum number of operations (elements removed from the end of nums) required to have collected all integers from 1 to k. -----Note----- It is assumed that the input list contains all integers from 1 to 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, simp] def minOperations_precond (nums : List Nat) (k : Nat) : Prop := -- !benchmark @start precond let target_nums := (List.range k).map (· + 1) target_nums.all (fun n => List.elem n nums) -- !benchmark @end precond -- !benchmark @start code_aux -- !benchmark @end code_aux def minOperations (nums : List Nat) (k : Nat) (h_precond : minOperations_precond (nums) (k)) : Nat := -- !benchmark @start code -- edge case k=0, requires 0 operations if k == 0 then 0 else -- recursive helper function let rec loop (remaining : List Nat) (collected : List Nat) (collected_count : Nat) (ops : Nat) : Nat := match remaining with | [] => ops -- base case | head :: tail => let ops' := ops + 1 -- check if the element is relevant (1 <= head <= k) and not already collected -- use a list `collected` to keep track of unique numbers found so far if head > 0 && head <= k && !(List.elem head collected) then let collected' := head :: collected -- add new unique element to our tracking list let collected_count' := collected_count + 1 if collected_count' == k then ops' -- found all k distinct required numbers else loop tail collected' collected_count' ops' -- continue searching, count increased else -- element is irrelevant (> k), zero/negative, or a duplicate (already in `collected`) loop tail collected collected_count ops' -- continue searching, count not increased -- start the loop, initially empty collection, 0 count, 0 operations loop nums.reverse [] 0 0 -- !benchmark @end code -- !benchmark @start postcond_aux -- !benchmark @end postcond_aux @[reducible, simp] def minOperations_postcond (nums : List Nat) (k : Nat) (result: Nat) (h_precond : minOperations_precond (nums) (k)) : Prop := -- !benchmark @start postcond -- define the list of elements processed after `result` operations let processed := (nums.reverse).take result -- define the target numbers to collect (1 to k) let target_nums := (List.range k).map (· + 1) -- condition 1: All target numbers must be present in the processed elements let collected_all := target_nums.all (fun n => List.elem n processed) -- condition 2: `result` must be the minimum number of operations. -- This means either result is 0 (which implies k must be 0 as target_nums would be empty) -- or result > 0, and taking one less operation (result - 1) is not sufficient let is_minimal := if result > 0 then -- if one fewer element is taken, not all target numbers should be present let processed_minus_one := (nums.reverse).take (result - 1) ¬ (target_nums.all (fun n => List.elem n processed_minus_one)) else -- if result is 0, it can only be minimal if k is 0 (no targets required) -- So if k=0, `collected_all` is true. If result=0, this condition `k==0` ensures minimality. k == 0 -- overall specification: collected_all ∧ is_minimal -- !benchmark @end postcond -- !benchmark @start proof_aux -- !benchmark @end proof_aux theorem minOperations_spec_satisfied (nums: List Nat) (k: Nat) (h_precond : minOperations_precond (nums) (k)) : minOperations_postcond (nums) (k) (minOperations (nums) (k) h_precond) h_precond := by -- !benchmark @start proof sorry -- !benchmark @end proof
{ "name": "minOperations", "parameters": { "param_name": [ "nums", "k" ], "param_type": [ "List Nat", "Nat" ] }, "return_type": "Nat" }
{ "upstream": { "name": "lab_assignment", "link": "", "task_id": "lab_minOperations_325696322", "student_id": [ 40 ] } }
{ "input": [ "{\"nums\": \"[3, 1, 5, 4, 2]\", \"k\": 2}", "{\"nums\": \"[3, 1, 5, 4, 2]\", \"k\": 5}", "{\"nums\": \"[3, 2, 5, 3, 1]\", \"k\": 3}", "{\"nums\": \"[5, 4, 3, 2, 1]\", \"k\": 1}", "{\"nums\": \"[5, 4, 1, 2, 3]\", \"k\": 3}", "{\"nums\": \"[1, 3, 2, 2, 1]\", \"k\": 2}", "{\"nums\": \"[10, 1, 20, 2]\", \"k\": 2}", "{\"nums\": \"[1, 2, 3]\", \"k\": 0}" ], "expected": [ [ "4" ], [ "5" ], [ "4" ], [ "1" ], [ "3" ], [ "2" ], [ "3" ], [ "0" ] ], "unexpected": [ [ "1", "2", "5" ], [ "1", "2", "3" ], [ "1", "2", "5" ], [ "0", "2", "5" ], [ "1", "4", "5" ], [ "1", "3", "4" ], [ "1", "2", "4" ], [ "1", "2", "3" ] ] }
{ "input": [ "{'nums': '[5, 6, 7, 8, 9]', 'k': 3}" ] }
advanced
verina_advanced_75
-----Description----- Given a sequence of n integers, your task is to find the largest sum obtainable by choosing a contiguous subarray of the sequence. At least one number must be selected. The algorithm uses dynamic programming (Kadane’s Algorithm) to solve the problem: 1. Initialize the current maximum (cur) and the overall maximum (maxSoFar) with the first element. 2. For each subsequent element, update: cur = max(element, cur + element) maxSoFar = max(maxSoFar, cur) 3. Return maxSoFar as the answer. -----Input----- The input is provided as a list of integers: sequence: A list of n integers. -----Output----- The output is a single integer representing the maximum subarray sum.
-- !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 task_code_precond (sequence : List Int) : Prop := -- !benchmark @start precond True -- !benchmark @end precond -- !benchmark @start code_aux -- !benchmark @end code_aux def task_code (sequence : List Int) (h_precond : task_code_precond (sequence)) : Int := -- !benchmark @start code match sequence with | [] => 0 -- If no elements are provided (should not happen according to the problem) | x :: xs => let (_, maxSoFar) := xs.foldl (fun (acc : Int × Int) (x : Int) => let (cur, maxSoFar) := acc let newCur := if cur + x >= x then cur + x else x let newMax := if maxSoFar >= newCur then maxSoFar else newCur (newCur, newMax) ) (x, x) maxSoFar -- !benchmark @end code -- !benchmark @start postcond_aux -- !benchmark @end postcond_aux @[reducible, simp] def task_code_postcond (sequence : List Int) (result: Int) (h_precond : task_code_precond (sequence)) : Prop := -- !benchmark @start postcond let subArrays := List.range (sequence.length + 1) |>.flatMap (fun start => List.range (sequence.length - start + 1) |>.map (fun len => sequence.drop start |>.take len)) let subArraySums := subArrays.filter (· ≠ []) |>.map (·.sum) subArraySums.contains result ∧ subArraySums.all (· ≤ result) -- !benchmark @end postcond -- !benchmark @start proof_aux -- !benchmark @end proof_aux theorem task_code_spec_satisfied (sequence: List Int) (h_precond : task_code_precond (sequence)) : task_code_postcond (sequence) (task_code (sequence) h_precond) h_precond := by -- !benchmark @start proof sorry -- !benchmark @end proof
{ "name": "task_code", "parameters": { "param_name": [ "sequence" ], "param_type": [ "List Int" ] }, "return_type": "Int" }
{ "upstream": { "name": "lab_assignment", "link": "", "task_id": "lab_task_code_325773191", "student_id": [ 53 ] } }
{ "input": [ "{\"sequence\": \"[10, -4, 3, 1, 5, 6, -35, 12, 21, -1]\"}", "{\"sequence\": \"[2, 1, -4, 3, 4, -4, 6, 5, -5, 1]\"}", "{\"sequence\": \"[-1, -2, -3, -4, -5]\"}", "{\"sequence\": \"[7]\"}", "{\"sequence\": \"[1, 2, 3, 4, 5]\"}" ], "expected": [ [ "33" ], [ "14" ], [ "-1" ], [ "7" ], [ "15" ] ], "unexpected": [ [ "32", "34", "0" ], [ "13", "15", "0" ], [ "-2", "0", "1" ], [ "0", "1", "-7" ], [ "14", "16", "0" ] ] }
{ "input": [] }
advanced
verina_basic_39
-----Description----- This task requires writing a Lean 4 method that rotates a list of integers to the right by a specified number of positions. The method should produce a new list where each element is shifted to the right while preserving the original list's length. -----Input----- The input consists of: • l: A list of integers. • n: A non-negative natural number that indicates the number of positions by which to rotate the list. -----Output----- The output is a list of integers: • Returns a list with the same length as the input list, where the elements have been rotated to the right by n positions. -----Note----- • The precondition requires that n is non-negative. • If the input list is empty, it should be returned unchanged.
-- !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 rotateRight_precond (l : List Int) (n : Nat) : Prop := -- !benchmark @start precond True -- !benchmark @end precond -- !benchmark @start code_aux -- !benchmark @end code_aux def rotateRight (l : List Int) (n : Nat) (h_precond : rotateRight_precond (l) (n)) : List Int := -- !benchmark @start code let len := l.length if len = 0 then l else (List.range len).map (fun i : Nat => let idx_int : Int := ((Int.ofNat i - Int.ofNat n + Int.ofNat len) % Int.ofNat len) let idx_nat : Nat := Int.toNat idx_int l.getD idx_nat (l.headD 0) ) -- !benchmark @end code -- !benchmark @start postcond_aux -- !benchmark @end postcond_aux @[reducible, simp] def rotateRight_postcond (l : List Int) (n : Nat) (result: List Int) (h_precond : rotateRight_precond (l) (n)) := -- !benchmark @start postcond result.length = l.length ∧ (∀ i : Nat, i < l.length → let len := l.length let rotated_index := Int.toNat ((Int.ofNat i - Int.ofNat n + Int.ofNat len) % Int.ofNat len) result[i]? = l[rotated_index]?) -- !benchmark @end postcond -- !benchmark @start proof_aux -- !benchmark @end proof_aux theorem rotateRight_spec_satisfied (l: List Int) (n: Nat) (h_precond : rotateRight_precond (l) (n)) : rotateRight_postcond (l) (n) (rotateRight (l) (n) h_precond) h_precond := by -- !benchmark @start proof sorry -- !benchmark @end proof
{ "name": "rotateRight", "parameters": { "param_name": [ "l", "n" ], "param_type": [ "List Int", "Nat" ] }, "return_type": "List Int" }
{ "upstream": { "name": "dafny-synthesis", "link": "https://github.com/Mondego/dafny-synthesis", "task_id": "task_id_743", "student_id": null } }
{ "input": [ "{\"l\": \"[1, 2, 3, 4, 5]\", \"n\": 2}", "{\"l\": \"[1, 2, 3, 4, 5]\", \"n\": 7}", "{\"l\": \"[1, 2, 3, 4, 5]\", \"n\": 0}", "{\"l\": \"[]\", \"n\": 2}" ], "expected": [ [ "4", "5", "1", "2", "3" ], [ "4", "5", "1", "2", "3" ], [ "1", "2", "3", "4", "5" ], [] ], "unexpected": [ [ "[5, 1, 2, 3, 4]", "[3, 4, 5, 1, 2]" ], [ "[5, 1, 2, 3, 4]", "[3, 4, 5, 1, 2]" ], [ "[5, 1, 2, 3, 4]", "[4, 5, 1, 2, 3]" ], [ "[0]", "[42]" ] ] }
{ "input": [] }
basic
verina_basic_15
-----Description----- This task requires writing a Lean 4 method that determines whether an array of integers contains at least one pair of consecutive numbers. The method should return true if there is any index where an element, when increased by one, equals the next element in the array. If no such consecutive pair exists, the method should return false. -----Input----- The input consists of: a: An array of integers (the array may be empty or non-empty). -----Output----- The output is a Boolean value: Returns true if there is at least one index where an element plus one equals the following element. Returns false if the array does not contain any consecutive numbers. -----Note----- There are no additional preconditions; the method will function correctly regardless of the array's size.
-- !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 containsConsecutiveNumbers_precond (a : Array Int) : Prop := -- !benchmark @start precond True -- !benchmark @end precond -- !benchmark @start code_aux -- !benchmark @end code_aux def containsConsecutiveNumbers (a : Array Int) (h_precond : containsConsecutiveNumbers_precond (a)) : Bool := -- !benchmark @start code if a.size ≤ 1 then false else let withIndices := a.mapIdx (fun i x => (i, x)) withIndices.any (fun (i, x) => i < a.size - 1 && x + 1 == a[i+1]!) -- !benchmark @end code -- !benchmark @start postcond_aux -- !benchmark @end postcond_aux @[reducible, simp] def containsConsecutiveNumbers_postcond (a : Array Int) (result: Bool) (h_precond : containsConsecutiveNumbers_precond (a)) := -- !benchmark @start postcond (∃ i, i < a.size - 1 ∧ a[i]! + 1 = a[i + 1]!) ↔ result -- !benchmark @end postcond -- !benchmark @start proof_aux -- !benchmark @end proof_aux theorem containsConsecutiveNumbers_spec_satisfied (a: Array Int) (h_precond : containsConsecutiveNumbers_precond (a)) : containsConsecutiveNumbers_postcond (a) (containsConsecutiveNumbers (a) h_precond) h_precond := by -- !benchmark @start proof unfold containsConsecutiveNumbers containsConsecutiveNumbers_postcond constructor · simp_all intro i hi hconsec have hi' : 1 + i < a.size := by rw [Nat.add_comm] exact Nat.add_lt_of_lt_sub hi have hi'' : i < a.size := by have : i < 1 + i := by simp [Nat.lt_add_of_pos_left] exact Nat.lt_trans this hi' constructor · exact Nat.lt_of_add_right_lt hi' · apply Array.any_iff_exists.mpr simp exists i simp [hi, hi''] have : a[i]! = a[i] := by exact getElem!_pos a i hi'' rw [←this] exact hconsec · simp intro ha h have h' := Array.any_iff_exists.mp h simp at h' rcases h' with ⟨i, hi, ⟨hi', hconsec⟩⟩ have : a[i]! = a[i] := by exact getElem!_pos a i hi exists i rw [this] simp_all -- !benchmark @end proof
{ "name": "containsConsecutiveNumbers", "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_472", "student_id": null } }
{ "input": [ "{\"a\": \"#[1, 2, 3, 5]\"}", "{\"a\": \"#[1, 3, 5, 7]\"}", "{\"a\": \"#[]\"}", "{\"a\": \"#[10]\"}", "{\"a\": \"#[5, 6]\"}", "{\"a\": \"#[5, 7, 8, 10]\"}", "{\"a\": \"#[9, 9, 10]\"}", "{\"a\": \"#[3, 3, 3]\"}" ], "expected": [ [ "True" ], [ "False" ], [ "False" ], [ "False" ], [ "True" ], [ "True" ], [ "True" ], [ "False" ] ], "unexpected": [ [ "False" ], [ "True" ], [ "True" ], [ "True" ], [ "False" ], [ "False" ], [ "False" ], [ "True" ] ] }
{ "input": [] }
basic
verina_advanced_80
-----Description----- This task requires writing a Lean 4 method that finds the indices of two numbers in an array that add up to a target value. Given an array of integers and a target integer, the function should return the indices of the two numbers such that they add up to the target. You may assume that each input has exactly one solution, and you may not use the same element twice. -----Input----- The input consists of: nums: An array of integers. target: An integer representing the target sum. -----Output----- The output is an array of two integers: Returns the indices of the two numbers in the array that add up to the target. The indices should be sorted.
-- !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 : Array Int) (target : Int) : Prop := -- !benchmark @start precond -- The array must have at least 2 elements nums.size ≥ 2 ∧ -- There exists exactly one pair of indices whose values sum to the target (List.range nums.size).any (fun i => (List.range i).any (fun j => nums[i]! + nums[j]! = target)) ∧ -- No other pair sums to the target (ensuring uniqueness of solution) ((List.range nums.size).flatMap (fun i => (List.range i).filter (fun j => nums[i]! + nums[j]! = target))).length = 1 -- !benchmark @end precond -- !benchmark @start code_aux -- !benchmark @end code_aux def twoSum (nums : Array Int) (target : Int) (h_precond : twoSum_precond (nums) (target)) : Array Nat := -- !benchmark @start code let rec findIndices (i : Nat) (j : Nat) (fuel : Nat) : Array Nat := match fuel with | 0 => #[] -- Fuel exhausted, return empty array | fuel+1 => if i >= nums.size then #[] -- No solution found else if j >= nums.size then findIndices (i + 1) (i + 2) fuel -- Move to next i and reset j else if nums[i]! + nums[j]! == target then #[i, j] -- Found solution else findIndices i (j + 1) fuel -- Try next j findIndices 0 1 (nums.size * nums.size) -- !benchmark @end code -- !benchmark @start postcond_aux -- !benchmark @end postcond_aux @[reducible] def twoSum_postcond (nums : Array Int) (target : Int) (result: Array Nat) (h_precond : twoSum_precond (nums) (target)) : Prop := -- !benchmark @start postcond -- Result contains exactly 2 indices result.size = 2 ∧ -- The indices are valid (within bounds of the nums array) result[0]! < nums.size ∧ result[1]! < nums.size ∧ -- The indices are in ascending order (sorted) result[0]! < result[1]! ∧ -- The values at these indices sum to the target nums[result[0]!]! + nums[result[1]!]! = target -- !benchmark @end postcond -- !benchmark @start proof_aux -- !benchmark @end proof_aux theorem twoSum_spec_satisfied (nums: Array 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": [ "Array Int", "Int" ] }, "return_type": "Array Nat" }
{ "upstream": { "name": "lab_assignment", "link": "https://leetcode.com/problems/two-sum/description/", "task_id": "lab_twoSum_325585735", "student_id": [ 31 ] } }
{ "input": [ "{\"nums\": \"#[2, 7, 11, 15]\", \"target\": 9}", "{\"nums\": \"#[3, 2, 4]\", \"target\": 6}", "{\"nums\": \"#[3, 3]\", \"target\": 6}", "{\"nums\": \"#[1, 2, 3, 4, 5]\", \"target\": 9}", "{\"nums\": \"#[0, 4, 3, 0]\", \"target\": 0}" ], "expected": [ [ "#[0, 1]" ], [ "#[1, 2]" ], [ "#[0, 1]" ], [ "#[3, 4]" ], [ "#[0, 3]" ] ], "unexpected": [ [ "#[1, 0]", "#[2, 3]", "#[0, 3]" ], [ "#[0, 1]", "#[0, 2]", "#[0, 3]" ], [ "#[1, 0]", "#[2, 2]" ], [ "#[0, 4]", "#[1, 3]", "#[2, 2]" ], [ "#[1, 2]", "#[2, 1]" ] ] }
{ "input": [ "{'nums': '#[0]', 'target': 2}" ] }
advanced
verina_advanced_77
-----Description----- This task requires writing a Lean 4 function that calculates how much water can be trapped between elevations after it rains. The input is a list of non-negative integers representing an elevation map. Each index traps water depending on the min of max heights to its left and right. -----Input----- - height: A list of natural numbers representing elevations. -----Output----- - A natural number: total units of water that can be trapped.
-- !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 trapRainWater_precond (height : List Nat) : Prop := -- !benchmark @start precond True -- !benchmark @end precond -- !benchmark @start code_aux -- !benchmark @end code_aux def trapRainWater (height : List Nat) (h_precond : trapRainWater_precond (height)) : Nat := -- !benchmark @start code Id.run do let mut left := 0 let mut right := height.length - 1 let mut leftMax := 0 let mut rightMax := 0 let mut water := 0 while left < right do let hLeft := height[left]! let hRight := height[right]! if hLeft < hRight then if hLeft >= leftMax then leftMax := hLeft else water := water + (leftMax - hLeft) left := left + 1 else if hRight >= rightMax then rightMax := hRight else water := water + (rightMax - hRight) right := right - 1 return water -- !benchmark @end code -- !benchmark @start postcond_aux -- !benchmark @end postcond_aux @[reducible, simp] def trapRainWater_postcond (height : List Nat) (result: Nat) (h_precond : trapRainWater_precond (height)) : Prop := -- !benchmark @start postcond let waterAt := List.range height.length |>.map (fun i => let lmax := List.take (i+1) height |>.foldl Nat.max 0 let rmax := List.drop i height |>.foldl Nat.max 0 Nat.min lmax rmax - height[i]!) result - (waterAt.foldl (· + ·) 0) = 0 ∧ (waterAt.foldl (· + ·) 0) ≤ result -- !benchmark @end postcond -- !benchmark @start proof_aux -- !benchmark @end proof_aux theorem trapRainWater_spec_satisfied (height: List Nat) (h_precond : trapRainWater_precond (height)) : trapRainWater_postcond (height) (trapRainWater (height) h_precond) h_precond := by -- !benchmark @start proof sorry -- !benchmark @end proof
{ "name": "trapRainWater", "parameters": { "param_name": [ "height" ], "param_type": [ "List Nat" ] }, "return_type": "Nat" }
{ "upstream": { "name": "lab_assignment", "link": "", "task_id": "lab_trapRainWater_325601349", "student_id": [ 22 ] } }
{ "input": [ "{\"height\": \"[0, 1, 0, 2, 1, 0, 1, 3, 2, 1, 2, 1]\"}", "{\"height\": \"[4, 2, 0, 3, 2, 5]\"}", "{\"height\": \"[1, 0, 2]\"}", "{\"height\": \"[3, 0, 1, 3, 0, 5]\"}", "{\"height\": \"[0, 1, 2, 3, 4, 5]\"}", "{\"height\": \"[]\"}" ], "expected": [ [ "6" ], [ "9" ], [ "1" ], [ "8" ], [ "0" ], [ "0" ] ], "unexpected": [ [ "5", "7" ], [ "8" ], [ "0", "2" ], [ "6" ], [ "1" ], [ "1" ] ] }
{ "input": [] }
advanced
verina_basic_30
-----Description----- This task requires writing a Lean 4 method that computes the element-wise modulo between two arrays of integers. The method should produce a new array where each element is the remainder after dividing the corresponding element from the first array by the element from the second array. -----Input----- The input consists of: a: An array of integers. b: An array of integers. -----Output----- The output is an array of integers: Returns a new array in which each element is the result of taking the modulo of the corresponding elements from the two input arrays. -----Note----- Preconditions: - Both arrays must be non-null. - Both arrays must have the same length. - All elements in the second array should be non-zero. Postconditions: - The length of the resulting array is the same as the length of the input arrays. - Each element in the resulting array is the modulo of the corresponding elements in the input arrays.
-- !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 elementWiseModulo_precond (a : Array Int) (b : Array Int) : Prop := -- !benchmark @start precond a.size = b.size ∧ a.size > 0 ∧ (∀ i, i < b.size → b[i]! ≠ 0) -- !benchmark @end precond -- !benchmark @start code_aux -- !benchmark @end code_aux def elementWiseModulo (a : Array Int) (b : Array Int) (h_precond : elementWiseModulo_precond (a) (b)) : Array Int := -- !benchmark @start code a.mapIdx (fun i x => x % b[i]!) -- !benchmark @end code -- !benchmark @start postcond_aux -- !benchmark @end postcond_aux @[reducible, simp] def elementWiseModulo_postcond (a : Array Int) (b : Array Int) (result: Array Int) (h_precond : elementWiseModulo_precond (a) (b)) := -- !benchmark @start postcond result.size = a.size ∧ (∀ i, i < result.size → result[i]! = a[i]! % b[i]!) -- !benchmark @end postcond -- !benchmark @start proof_aux -- !benchmark @end proof_aux theorem elementWiseModulo_spec_satisfied (a: Array Int) (b: Array Int) (h_precond : elementWiseModulo_precond (a) (b)) : elementWiseModulo_postcond (a) (b) (elementWiseModulo (a) (b) h_precond) h_precond := by -- !benchmark @start proof unfold elementWiseModulo elementWiseModulo_postcond unfold elementWiseModulo_precond at h_precond simp_all intro i hi have h_maplen : (Array.mapIdx (fun i x => x % b[i]!) a).size = a.size := by apply Array.size_mapIdx have h1 : (Array.mapIdx (fun i x => x % b[i]!) a)[i] = (fun i x => x % b[i]!) i a[i] := by apply Array.getElem_mapIdx have h_eq : (Array.mapIdx (fun i x => x % b[i]!) a)[i] = (Array.mapIdx (fun i x => x % b[i]!) a)[i]! := by have hi' : i < (Array.mapIdx (fun i x => x % b[i]!) a).size := by simp only [h_precond, hi, h_maplen] rw [Array.getElem!_eq_getD] unfold Array.getD simp [hi', hi, h_precond] rw [← h_eq] simp only [h1] have h_eq' : a[i] = a[i]! := by have hi_a : i < a.size := by simp only [h_precond, hi] simp_all [Array.getElem!_eq_getD] simp only [h_eq'] -- !benchmark @end proof
{ "name": "elementWiseModulo", "parameters": { "param_name": [ "a", "b" ], "param_type": [ "Array Int", "Array Int" ] }, "return_type": "Array Int" }
{ "upstream": { "name": "dafny-synthesis", "link": "https://github.com/Mondego/dafny-synthesis", "task_id": "task_id_616", "student_id": null } }
{ "input": [ "{\"a\": \"#[10, 20, 30]\", \"b\": \"#[3, 7, 5]\"}", "{\"a\": \"#[100, 200, 300, 400]\", \"b\": \"#[10, 20, 30, 50]\"}", "{\"a\": \"#[-10, -20, 30]\", \"b\": \"#[3, -7, 5]\"}" ], "expected": [ [ "#[1, 6, 0]" ], [ "#[0, 0, 0, 0]" ], [ "#[2, 1, 0]" ] ], "unexpected": [ [ "#[1, 0, 0]", "#[0, 6, 0]" ], [ "#[0, 0, 0, 1]", "#[1, 0, 0, 0]" ], [ "#[-1, -5, 0]", "#[-1, -6, 1]", "#[0, -6, 0]" ] ] }
{ "input": [ "{'a': '#[1]', 'b': '#[4, 0]'}" ] }
basic
verina_advanced_18
-----Description----- This task requires writing a Lean 4 method that determines whether a given number `n` is an Armstrong number (also known as a Narcissistic number). An Armstrong number is a number that is equal to the sum of its own digits raised to the power of the number of digits. -----Input----- The input consists of one natural number: - `n: Nat`: The number to check if it satisfies the Armstrong property. -----Output----- The output is a boolean value: - `Bool`: Return `true` if `n` is an Armstrong number, otherwise return `false`.
-- !benchmark @start import type=solution -- !benchmark @end import -- !benchmark @start solution_aux def countDigits (n : Nat) : Nat := let rec go (n acc : Nat) : Nat := if n = 0 then acc else go (n / 10) (acc + 1) go n (if n = 0 then 1 else 0) -- !benchmark @end solution_aux -- !benchmark @start precond_aux -- !benchmark @end precond_aux @[reducible] def isArmstrong_precond (n : Nat) : Prop := -- !benchmark @start precond True -- !benchmark @end precond -- !benchmark @start code_aux def sumPowers (n : Nat) (k : Nat) : Nat := let rec go (n acc : Nat) : Nat := if n = 0 then acc else let digit := n % 10 go (n / 10) (acc + digit ^ k) go n 0 -- !benchmark @end code_aux def isArmstrong (n : Nat) (h_precond : isArmstrong_precond (n)) : Bool := -- !benchmark @start code let k := countDigits n sumPowers n k = n -- !benchmark @end code -- !benchmark @start postcond_aux -- !benchmark @end postcond_aux @[reducible] def isArmstrong_postcond (n : Nat) (result: Bool) (h_precond : isArmstrong_precond (n)) : Prop := -- !benchmark @start postcond let n' := List.foldl (fun acc d => acc + d ^ countDigits n) 0 (List.map (fun c => c.toNat - '0'.toNat) (toString n).toList) (result → (n = n')) ∧ (¬ result → (n ≠ n')) -- !benchmark @end postcond -- !benchmark @start proof_aux -- !benchmark @end proof_aux theorem isArmstrong_spec_satisfied (n: Nat) (h_precond : isArmstrong_precond (n)) : isArmstrong_postcond (n) (isArmstrong (n) h_precond) h_precond := by -- !benchmark @start proof sorry -- !benchmark @end proof
{ "name": "isArmstrong", "parameters": { "param_name": [ "n" ], "param_type": [ "Nat" ] }, "return_type": "Bool" }
{ "upstream": { "name": "lab_assignment", "link": "leetcode 1134: https://leetcode.ca/all/1134.html", "task_id": "lab_isArmstrong_325011347", "student_id": [ 7 ] } }
{ "input": [ "{\"n\": 0}", "{\"n\": 1}", "{\"n\": 10}", "{\"n\": 153}", "{\"n\": 9474}", "{\"n\": 9475}" ], "expected": [ [ "True" ], [ "True" ], [ "False" ], [ "True" ], [ "True" ], [ "False" ] ], "unexpected": [ [ "False" ], [ "False" ], [ "True" ], [ "False" ], [ "False" ], [ "True" ] ] }
{ "input": [] }
advanced
verina_advanced_21
-----Description----- Implement a Lean 4 function that checks if a given string is a palindrome. A string is considered a palindrome if it reads the same forward and backward. -----Input----- The input consists of a single string: s: A string -----Output----- The output is a boolean: Returns true if s is a palindrome, false otherwise.
-- !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 (s : String) : Prop := -- !benchmark @start precond True -- !benchmark @end precond -- !benchmark @start code_aux -- !benchmark @end code_aux def isPalindrome (s : String) (h_precond : isPalindrome_precond (s)) : Bool := -- !benchmark @start code let length := s.length if length <= 1 then true else let arr := s.toList let rec checkIndices (left : Nat) (right : Nat) (chars : List Char) : Bool := if left >= right then true else match chars[left]?, chars[right]? with | some cLeft, some cRight => if cLeft == cRight then checkIndices (left + 1) (right - 1) chars else false | _, _ => false let approach1 := checkIndices 0 (length - 1) arr let rec reverseList (acc : List Char) (xs : List Char) : List Char := match xs with | [] => acc | h :: t => reverseList (h :: acc) t let reversed := reverseList [] arr let approach2 := (arr == reversed) approach1 && approach2 -- !benchmark @end code -- !benchmark @start postcond_aux -- !benchmark @end postcond_aux @[reducible, simp] def isPalindrome_postcond (s : String) (result: Bool) (h_precond : isPalindrome_precond (s)) : Prop := -- !benchmark @start postcond (result → (s.toList == s.toList.reverse)) ∧ (¬ result → (s.toList ≠ [] ∧ s.toList != s.toList.reverse)) -- !benchmark @end postcond -- !benchmark @start proof_aux -- !benchmark @end proof_aux theorem isPalindrome_spec_satisfied (s: String) (h_precond : isPalindrome_precond (s)) : isPalindrome_postcond (s) (isPalindrome (s) h_precond) h_precond := by -- !benchmark @start proof sorry -- !benchmark @end proof
{ "name": "isPalindrome", "parameters": { "param_name": [ "s" ], "param_type": [ "String" ] }, "return_type": "Bool" }
{ "upstream": { "name": "lab_assignment", "link": "", "task_id": "lab_isPalindrome_325097530", "student_id": [ 17 ] } }
{ "input": [ "{\"s\": \"racecar\"}", "{\"s\": \"abba\"}", "{\"s\": \"abc\"}", "{\"s\": \"\"}", "{\"s\": \"a\"}" ], "expected": [ [ "True" ], [ "True" ], [ "False" ], [ "True" ], [ "True" ] ], "unexpected": [ [ "False" ], [ "False" ], [ "True" ], [ "False" ], [ "False" ] ] }
{ "input": [] }
advanced
verina_basic_52
-----Description----- This task requires developing a solution that sorts an array of integers in non-decreasing order. The solution must return an array that is a rearrangement of the input, containing exactly the same elements but ordered from smallest to largest. -----Input----- The input consists of: • a: An array of integers. This array can be empty or non-empty. -----Output----- The output is an array of integers that: • Is sorted in non-decreasing order (i.e., for any indices i and j with i < j, a[i]! ≤ a[j]!). • Has the same size as the input array. • Contains exactly the same elements as the input array, ensuring that the multiset of elements is preserved. -----Note----- The implementation uses helper functions for swapping elements and performing inner and outer loops of the bubble sort algorithm. No additional preconditions are required as the function should correctly handle empty and non-empty arrays.
-- !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 BubbleSort_precond (a : Array Int) : Prop := -- !benchmark @start precond True -- !benchmark @end precond -- !benchmark @start code_aux def swap (a : Array Int) (i j : Nat) : Array Int := let temp := a[i]! let a₁ := a.set! i (a[j]!) a₁.set! j temp def bubbleInner (j i : Nat) (a : Array Int) : Array Int := if j < i then let a' := if a[j]! > a[j+1]! then swap a j (j+1) else a bubbleInner (j+1) i a' else a def bubbleOuter (i : Nat) (a : Array Int) : Array Int := if i > 0 then let a' := bubbleInner 0 i a bubbleOuter (i - 1) a' else a -- !benchmark @end code_aux def BubbleSort (a : Array Int) (h_precond : BubbleSort_precond (a)) : Array Int := -- !benchmark @start code if a.size = 0 then a else bubbleOuter (a.size - 1) a -- !benchmark @end code -- !benchmark @start postcond_aux -- !benchmark @end postcond_aux @[reducible, simp] def BubbleSort_postcond (a : Array Int) (result: Array Int) (h_precond : BubbleSort_precond (a)) := -- !benchmark @start postcond List.Pairwise (· ≤ ·) result.toList ∧ List.isPerm result.toList a.toList -- !benchmark @end postcond -- !benchmark @start proof_aux -- !benchmark @end proof_aux theorem BubbleSort_spec_satisfied (a: Array Int) (h_precond : BubbleSort_precond (a)) : BubbleSort_postcond (a) (BubbleSort (a) h_precond) h_precond := by -- !benchmark @start proof sorry -- !benchmark @end proof
{ "name": "BubbleSort", "parameters": { "param_name": [ "a" ], "param_type": [ "Array Int" ] }, "return_type": "Array Int" }
{ "upstream": { "name": "clover", "link": "https://github.com/ChuyueSun/Clover", "task_id": "Clover_bubble_sort", "student_id": null } }
{ "input": [ "{\"a\": \"#[5, 4, 3, 2, 1]\"}", "{\"a\": \"#[1, 2, 3, 4, 5]\"}", "{\"a\": \"#[3, 1, 2, 1, 5]\"}", "{\"a\": \"#[10]\"}", "{\"a\": \"#[4, 4, 4, 2, 2, 8]\"}" ], "expected": [ [ "#[1, 2, 3, 4, 5]" ], [ "#[1, 2, 3, 4, 5]" ], [ "#[1, 1, 2, 3, 5]" ], [ "#[10]" ], [ "#[2, 2, 4, 4, 4, 8]" ] ], "unexpected": [ [ "#[5, 4, 3, 2, 1]", "#[2, 3, 1, 4, 5]" ], [ "#[5, 4, 3, 2, 1]", "#[1, 3, 2, 4, 5]" ], [ "#[1, 2, 3, 1, 5]", "#[3, 1, 2, 5, 1]" ], [ "#[0]", "#[10, 10]" ], [ "#[2, 4, 4, 2, 4, 8]", "#[4, 2, 4, 2, 4, 8]", "#[2, 4, 2, 4, 4, 8]" ] ] }
{ "input": [] }
basic
verina_basic_71
-----Description----- This problem involves determining the longest common prefix shared by two lists of characters. Given two sequences, the goal is to identify and return the maximal contiguous sequence of characters from the beginning of both lists that are identical. -----Input----- The input consists of: • str1: A list of characters. • str2: A list of characters. -----Output----- The output is a list of characters representing the longest common prefix of the two input lists. The output list satisfies the following conditions: • Its length is less than or equal to the length of each input list. • It is exactly the prefix of both str1 and str2. • It is empty if the first characters of the inputs differ or if one of the lists is empty. -----Note----- It is assumed that both inputs are provided as valid lists of characters. The function always returns the correct longest common prefix based on the inputs.
-- !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 LongestCommonPrefix_precond (str1 : List Char) (str2 : List Char) : Prop := -- !benchmark @start precond True -- !benchmark @end precond -- !benchmark @start code_aux -- !benchmark @end code_aux def LongestCommonPrefix (str1 : List Char) (str2 : List Char) (h_precond : LongestCommonPrefix_precond (str1) (str2)) : List Char := -- !benchmark @start code let minLength := Nat.min str1.length str2.length let rec aux (idx : Nat) (acc : List Char) : List Char := if idx < minLength then match str1[idx]?, str2[idx]? with | some c1, some c2 => if c1 ≠ c2 then acc else aux (idx + 1) (acc ++ [c1]) | _, _ => acc else acc aux 0 [] -- !benchmark @end code -- !benchmark @start postcond_aux -- !benchmark @end postcond_aux @[reducible, simp] def LongestCommonPrefix_postcond (str1 : List Char) (str2 : List Char) (result: List Char) (h_precond : LongestCommonPrefix_precond (str1) (str2)) := -- !benchmark @start postcond (result.length ≤ str1.length) ∧ (result = str1.take result.length) ∧ (result.length ≤ str2.length) ∧ (result = str2.take result.length) ∧ (result.length = str1.length ∨ result.length = str2.length ∨ (str1[result.length]? ≠ str2[result.length]?)) -- !benchmark @end postcond -- !benchmark @start proof_aux -- !benchmark @end proof_aux theorem LongestCommonPrefix_spec_satisfied (str1: List Char) (str2: List Char) (h_precond : LongestCommonPrefix_precond (str1) (str2)) : LongestCommonPrefix_postcond (str1) (str2) (LongestCommonPrefix (str1) (str2) h_precond) h_precond := by -- !benchmark @start proof sorry -- !benchmark @end proof
{ "name": "LongestCommonPrefix", "parameters": { "param_name": [ "str1", "str2" ], "param_type": [ "List Char", "List Char" ] }, "return_type": "List Char" }
{ "upstream": { "name": "clover", "link": "https://github.com/ChuyueSun/Clover", "task_id": "Clover_longest_prefix", "student_id": null } }
{ "input": [ "{\"str1\": \"['a', 'b', 'c']\", \"str2\": \"['a', 'b', 'd']\"}", "{\"str1\": \"['x', 'y', 'z']\", \"str2\": \"['x', 'y', 'z']\"}", "{\"str1\": \"['w', 'o']\", \"str2\": \"['w', 'o', 'w']\"}", "{\"str1\": \"['a', 'x']\", \"str2\": \"['b', 'y']\"}", "{\"str1\": \"[]\", \"str2\": \"['h', 'e', 'l', 'l', 'o']\"}" ], "expected": [ [ "['a', 'b']" ], [ "['x', 'y', 'z']" ], [ "['w', 'o']" ], [ "[]" ], [ "[]" ] ], "unexpected": [ [ "['a']", "['a', 'b', 'c']" ], [ "['x', 'y']", "['x', 'z']" ], [ "['w']", "['o']", "['w', 'o', 'w']" ], [ "['a']", "['b']" ], [ "['h']", "['e']" ] ] }
{ "input": [] }
basic
verina_basic_56
-----Description----- The problem is to update a destination array by replacing a specific segment with values taken from a source array. Given two arrays, starting positions, and a length, the task is to construct a new array where the segment in the destination from the specified starting index for the given length is replaced by the corresponding segment from the source, while all other elements remain unchanged. -----Input----- The input consists of: • src: An array of integers representing the source array. • sStart: A natural number indicating the starting index in src from where to begin copying. • dest: An array of integers representing the destination array. • dStart: A natural number indicating the starting index in dest where the segment will be replaced. • len: A natural number specifying the number of elements to copy. -----Output----- The output is an array of integers that: • Has the same size as the destination array (dest). • Preserves the original elements of dest except for the segment starting at index dStart of length len, which is replaced by the corresponding segment from src. • Under the preconditions that src.size ≥ sStart + len and dest.size ≥ dStart + len, guarantees that: - All elements with indices less than dStart remain as in dest. - All elements with indices greater than or equal to dStart + len remain as in dest. - For each index i with 0 ≤ i < len, the element at index dStart + i in the output equals the element at index sStart + i in src. -----Note----- It is assumed that the input arrays satisfy the preconditions: the source array has enough elements starting from sStart and the destination array has enough space starting from dStart to accommodate the copied segment.
-- !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 copy_precond (src : Array Int) (sStart : Nat) (dest : Array Int) (dStart : Nat) (len : Nat) : Prop := -- !benchmark @start precond src.size ≥ sStart + len ∧ dest.size ≥ dStart + len -- !benchmark @end precond -- !benchmark @start code_aux def updateSegment : Array Int → Array Int → Nat → Nat → Nat → Array Int | r, src, sStart, dStart, 0 => r | r, src, sStart, dStart, n+1 => let rNew := r.set! (dStart + n) (src[sStart + n]!) updateSegment rNew src sStart dStart n -- !benchmark @end code_aux def copy (src : Array Int) (sStart : Nat) (dest : Array Int) (dStart : Nat) (len : Nat) (h_precond : copy_precond (src) (sStart) (dest) (dStart) (len)) : Array Int := -- !benchmark @start code if len = 0 then dest else let r := dest updateSegment r src sStart dStart len -- !benchmark @end code -- !benchmark @start postcond_aux -- !benchmark @end postcond_aux @[reducible, simp] def copy_postcond (src : Array Int) (sStart : Nat) (dest : Array Int) (dStart : Nat) (len : Nat) (result: Array Int) (h_precond : copy_precond (src) (sStart) (dest) (dStart) (len)) := -- !benchmark @start postcond result.size = dest.size ∧ (∀ i, i < dStart → result[i]! = dest[i]!) ∧ (∀ i, dStart + len ≤ i → i < result.size → result[i]! = dest[i]!) ∧ (∀ i, i < len → result[dStart + i]! = src[sStart + i]!) -- !benchmark @end postcond -- !benchmark @start proof_aux -- !benchmark @end proof_aux theorem copy_spec_satisfied (src: Array Int) (sStart: Nat) (dest: Array Int) (dStart: Nat) (len: Nat) (h_precond : copy_precond (src) (sStart) (dest) (dStart) (len)) : copy_postcond (src) (sStart) (dest) (dStart) (len) (copy (src) (sStart) (dest) (dStart) (len) h_precond) h_precond := by -- !benchmark @start proof sorry -- !benchmark @end proof
{ "name": "copy", "parameters": { "param_name": [ "src", "sStart", "dest", "dStart", "len" ], "param_type": [ "Array Int", "Nat", "Array Int", "Nat", "Nat" ] }, "return_type": "Array Int" }
{ "upstream": { "name": "clover", "link": "https://github.com/ChuyueSun/Clover", "task_id": "Clover_copy_part", "student_id": null } }
{ "input": [ "{\"src\": \"#[10, 20, 30, 40, 50]\", \"sStart\": 1, \"dest\": \"#[1, 2, 3, 4, 5, 6]\", \"dStart\": 3, \"len\": 2}", "{\"src\": \"#[5, 6, 7, 8]\", \"sStart\": 0, \"dest\": \"#[9, 9, 9, 9, 9]\", \"dStart\": 1, \"len\": 3}", "{\"src\": \"#[100, 200]\", \"sStart\": 0, \"dest\": \"#[1, 2, 3]\", \"dStart\": 1, \"len\": 0}", "{\"src\": \"#[10, 20, 30, 40, 50]\", \"sStart\": 0, \"dest\": \"#[0, 0, 0, 0, 0]\", \"dStart\": 0, \"len\": 5}", "{\"src\": \"#[7, 8, 9, 10]\", \"sStart\": 2, \"dest\": \"#[1, 2, 3, 4, 5, 6]\", \"dStart\": 4, \"len\": 2}" ], "expected": [ [ "#[1, 2, 3, 20, 30, 6]" ], [ "#[9, 5, 6, 7, 9]" ], [ "#[1, 2, 3]" ], [ "#[10, 20, 30, 40, 50]" ], [ "#[1, 2, 3, 4, 9, 10]" ] ], "unexpected": [ [ "#[1, 2, 3, 10, 30, 6]", "#[1, 2, 3, 20, 40, 6]", "#[1, 2, 20, 30, 6, 0]" ], [ "#[9, 9, 5, 7, 9]", "#[9, 5, 7, 6, 9]", "#[9, 5, 6, 9, 9]" ], [ "#[1, 0, 3]", "#[0, 2, 3]", "#[1, 2, 0]" ], [ "#[10, 20, 30, 40, 60]", "#[0, 20, 30, 40, 50]", "#[10, 20, 30, 40, 0]" ], [ "#[1, 2, 3, 9, 4, 10]", "#[1, 2, 9, 4, 3, 10]", "#[1, 2, 3, 4, 10, 9]" ] ] }
{ "input": [ "{'src': '#[10, 20, 30]', 'sStart': 1, 'dest': '#[1, 2, 3, 4]', 'dStart': 2, 'len': 3}" ] }
basic
verina_basic_34
-----Description----- This task requires writing a Lean 4 method that extracts even numbers from an array of integers. The method should return a new array containing only the even numbers found in the input array, while preserving the order in which they appear. -----Input----- The input consists of: arr: An array of integers. -----Output----- The output is an array of integers: Returns an array containing all the even numbers from the input array. Specifically: - Every element in the output array is an even integer. - All even integers present in the input array are included in the output array. - The relative order of the even integers is preserved as in the input array. -----Note----- There are no preconditions for this task; the method will work with any array, including empty arrays (which are not null).
-- !benchmark @start import type=solution -- !benchmark @end import -- !benchmark @start solution_aux def isEven (n : Int) : Bool := n % 2 = 0 -- !benchmark @end solution_aux -- !benchmark @start precond_aux -- !benchmark @end precond_aux @[reducible, simp] def findEvenNumbers_precond (arr : Array Int) : Prop := -- !benchmark @start precond True -- !benchmark @end precond -- !benchmark @start code_aux -- !benchmark @end code_aux def findEvenNumbers (arr : Array Int) (h_precond : findEvenNumbers_precond (arr)) : Array Int := -- !benchmark @start code arr.foldl (fun acc x => if isEven x then acc.push x else acc) #[] -- !benchmark @end code -- !benchmark @start postcond_aux -- !benchmark @end postcond_aux @[reducible, simp] def findEvenNumbers_postcond (arr : Array Int) (result: Array Int) (h_precond : findEvenNumbers_precond (arr)) := -- !benchmark @start postcond (∀ x, x ∈ result → isEven x ∧ x ∈ arr.toList) ∧ (∀ x, x ∈ arr.toList → isEven x → x ∈ result) ∧ (∀ x y, x ∈ arr.toList → y ∈ arr.toList → isEven x → isEven y → arr.toList.idxOf x ≤ arr.toList.idxOf y → result.toList.idxOf x ≤ result.toList.idxOf y) -- !benchmark @end postcond -- !benchmark @start proof_aux -- !benchmark @end proof_aux theorem findEvenNumbers_spec_satisfied (arr: Array Int) (h_precond : findEvenNumbers_precond (arr)) : findEvenNumbers_postcond (arr) (findEvenNumbers (arr) h_precond) h_precond := by -- !benchmark @start proof sorry -- !benchmark @end proof
{ "name": "findEvenNumbers", "parameters": { "param_name": [ "arr" ], "param_type": [ "Array Int" ] }, "return_type": "Array Int" }
{ "upstream": { "name": "dafny-synthesis", "link": "https://github.com/Mondego/dafny-synthesis", "task_id": "task_id_629", "student_id": null } }
{ "input": [ "{\"arr\": \"#[1, 2, 3, 4, 5, 6]\"}", "{\"arr\": \"#[7, 8, 10, 13, 14]\"}", "{\"arr\": \"#[1, 3, 5, 7]\"}", "{\"arr\": \"#[]\"}", "{\"arr\": \"#[0, -2, -3, -4, 5]\"}" ], "expected": [ [ "#[2, 4, 6]" ], [ "#[8, 10, 14]" ], [ "#[]" ], [ "#[]" ], [ "#[0, -2, -4]" ] ], "unexpected": [ [ "#[1, 2, 3]", "#[2, 3, 4, 6]" ], [ "#[7, 8, 10]", "#[8, 14]" ], [ "#[1]", "#[1, 3]" ], [ "#[0]", "#[1]" ], [ "#[0, -3, -4]", "#[-2, -4]" ] ] }
{ "input": [] }
basic
verina_basic_65
-----Description----- This task involves computing the integer square root of a given natural number. The goal is to determine the largest natural number r that satisfies r * r ≤ N and N < (r + 1) * (r + 1). -----Input----- The input consists of: • N: A natural number. -----Output----- The output is a natural number r that meets the following conditions: • r * r ≤ N • N < (r + 1) * (r + 1) -----Note----- The implementation relies on a recursive strategy to iteratively increment r until (r + 1)*(r + 1) exceeds N. Edge cases, such as N = 0, should be handled correctly.
-- !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 SquareRoot_precond (N : Nat) : Prop := -- !benchmark @start precond True -- !benchmark @end precond -- !benchmark @start code_aux -- !benchmark @end code_aux def SquareRoot (N : Nat) (h_precond : SquareRoot_precond (N)) : Nat := -- !benchmark @start code let rec boundedLoop : Nat → Nat → Nat | 0, r => r | bound+1, r => if (r + 1) * (r + 1) ≤ N then boundedLoop bound (r + 1) else r boundedLoop (N+1) 0 -- !benchmark @end code -- !benchmark @start postcond_aux -- !benchmark @end postcond_aux @[reducible, simp] def SquareRoot_postcond (N : Nat) (result: Nat) (h_precond : SquareRoot_precond (N)) := -- !benchmark @start postcond result * result ≤ N ∧ N < (result + 1) * (result + 1) -- !benchmark @end postcond -- !benchmark @start proof_aux -- !benchmark @end proof_aux theorem SquareRoot_spec_satisfied (N: Nat) (h_precond : SquareRoot_precond (N)) : SquareRoot_postcond (N) (SquareRoot (N) h_precond) h_precond := by -- !benchmark @start proof sorry -- !benchmark @end proof
{ "name": "SquareRoot", "parameters": { "param_name": [ "N" ], "param_type": [ "Nat" ] }, "return_type": "Nat" }
{ "upstream": { "name": "clover", "link": "https://github.com/ChuyueSun/Clover", "task_id": "Clover_integer_square_root", "student_id": null } }
{ "input": [ "{\"N\": 0}", "{\"N\": 1}", "{\"N\": 15}", "{\"N\": 16}", "{\"N\": 26}" ], "expected": [ [ "0" ], [ "1" ], [ "3" ], [ "4" ], [ "5" ] ], "unexpected": [ [ "1", "2" ], [ "0", "2" ], [ "2", "4", "5" ], [ "3", "5", "6" ], [ "4", "6", "7" ] ] }
{ "input": [] }
basic
verina_advanced_35
-----Description----- This task requires writing a Lean 4 function that finds the majority element in a list of integers. The majority element is the element that appears more than ⌊n/2⌋ times, where n is the list’s length. You may assume that a majority element always exists in the input. -----Input----- - nums: A list of integers of length ≥ 1, containing a majority element. -----Output----- - An integer: the element that appears more than ⌊n/2⌋ times.
-- !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 majorityElement_precond (nums : List Int) : Prop := -- !benchmark @start precond nums.length > 0 ∧ nums.any (fun x => nums.count x > nums.length / 2) -- !benchmark @end precond -- !benchmark @start code_aux -- !benchmark @end code_aux def majorityElement (nums : List Int) (h_precond : majorityElement_precond (nums)) : Int := -- !benchmark @start code Id.run do let mut counts : HashMap Int Nat := {} let n := nums.length for x in nums do let count := counts.getD x 0 counts := counts.insert x (count + 1) match counts.toList.find? (fun (_, c) => c > n / 2) with | some (k, _) => k | none => 0 -- !benchmark @end code -- !benchmark @start postcond_aux -- !benchmark @end postcond_aux @[reducible] def majorityElement_postcond (nums : List Int) (result: Int) (h_precond : majorityElement_precond (nums)) : Prop := -- !benchmark @start postcond let n := nums.length (nums.count result) > n / 2 ∧ ∀ x, x ≠ result → nums.count x ≤ n / 2 -- !benchmark @end postcond -- !benchmark @start proof_aux -- !benchmark @end proof_aux theorem majorityElement_spec_satisfied (nums: List Int) (h_precond : majorityElement_precond (nums)) : majorityElement_postcond (nums) (majorityElement (nums) h_precond) h_precond := by -- !benchmark @start proof sorry -- !benchmark @end proof
{ "name": "majorityElement", "parameters": { "param_name": [ "nums" ], "param_type": [ "List Int" ] }, "return_type": "Int" }
{ "upstream": { "name": "lab_assignment", "link": "https://leetcode.com/problems/majority-element/description/", "task_id": "lab_majorityElement_324976035", "student_id": [ 22 ] } }
{ "input": [ "{\"nums\": \"[3, 2, 3]\"}", "{\"nums\": \"[2, 2, 1, 1, 1, 2, 2]\"}", "{\"nums\": \"[1, 1, 1, 2, 3, 1]\"}", "{\"nums\": \"[0, 0, 0, 0]\"}", "{\"nums\": \"[7]\"}" ], "expected": [ [ "3" ], [ "2" ], [ "1" ], [ "0" ], [ "7" ] ], "unexpected": [ [ "2" ], [ "1" ], [ "2", "3" ], [ "1" ], [] ] }
{ "input": [ "{'nums': '[1, 2, 3]'}", "{'nums': '[]'}" ] }
advanced
verina_advanced_8
-----Description----- This task requires writing a Lean 4 method that determines whether it is possible to complete a circular journey around a set of gas stations. Each gas station provides a certain amount of gas, and traveling from one station to the next consumes a certain amount of gas. You start the journey at one of the gas stations with an empty tank. The goal is to find the starting station's index that allows completing the entire circuit once in the clockwise direction without running out of gas. If such a station exists, return its index. Otherwise, return -1. If multiple solutions exist, return the one with the smallest starting gas station index. -----Input----- The input consists of two arrays: gas: An array of integers where gas[i] represents the amount of gas available at the ith station. cost: An array of integers where cost[i] is the amount of gas required to travel from station i to station i + 1. -----Output----- The output is an integer: Returns the index of the starting gas station that allows a complete trip around the circuit. If it is not possible to complete the circuit, return -1.
-- !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 canCompleteCircuit_precond (gas : List Int) (cost : List Int) : Prop := -- !benchmark @start precond True -- !benchmark @end precond -- !benchmark @start code_aux -- !benchmark @end code_aux def canCompleteCircuit (gas : List Int) (cost : List Int) (h_precond : canCompleteCircuit_precond (gas) (cost)) : Int := -- !benchmark @start code let totalGas := gas.foldl (· + ·) 0 let totalCost := cost.foldl (· + ·) 0 if totalGas < totalCost then -1 else let rec loop (g c : List Int) (idx : Nat) (tank : Int) (start : Nat) : Int := match g, c with | [], [] => start | gi :: gs, ci :: cs => let tank' := tank + gi - ci if tank' < 0 then loop gs cs (idx + 1) 0 (idx + 1) else loop gs cs (idx + 1) tank' start | _, _ => -1 -- lengths don’t match let zipped := List.zip gas cost let rec walk (pairs : List (Int × Int)) (i : Nat) (tank : Int) (start : Nat) : Int := match pairs with | [] => start | (g, c) :: rest => let newTank := tank + g - c if newTank < 0 then walk rest (i + 1) 0 (i + 1) else walk rest (i + 1) newTank start walk zipped 0 0 0 -- !benchmark @end code -- !benchmark @start postcond_aux -- !benchmark @end postcond_aux @[reducible] def canCompleteCircuit_postcond (gas : List Int) (cost : List Int) (result: Int) (h_precond : canCompleteCircuit_precond (gas) (cost)) : Prop := -- !benchmark @start postcond let valid (start : Nat) := List.range gas.length |>.all (fun i => let acc := List.range (i + 1) |>.foldl (fun t j => let jdx := (start + j) % gas.length t + gas[jdx]! - cost[jdx]!) 0 acc ≥ 0) -- For result = -1: It's impossible to complete the circuit starting from any index -- In other words, there's no starting point from which we can always maintain a non-negative gas tank (result = -1 → (List.range gas.length).all (fun start => ¬ valid start)) ∧ -- For result ≥ 0: This is the valid starting point -- When starting from this index, the gas tank never becomes negative during the entire circuit (result ≥ 0 → result < gas.length ∧ valid result.toNat ∧ (List.range result.toNat).all (fun start => ¬ valid start)) -- !benchmark @end postcond -- !benchmark @start proof_aux -- !benchmark @end proof_aux theorem canCompleteCircuit_spec_satisfied (gas: List Int) (cost: List Int) (h_precond : canCompleteCircuit_precond (gas) (cost)) : canCompleteCircuit_postcond (gas) (cost) (canCompleteCircuit (gas) (cost) h_precond) h_precond := by -- !benchmark @start proof sorry -- !benchmark @end proof
{ "name": "canCompleteCircuit", "parameters": { "param_name": [ "gas", "cost" ], "param_type": [ "List Int", "List Int" ] }, "return_type": "Int" }
{ "upstream": { "name": "lab_assignment", "link": "https://leetcode.com/problems/gas-station", "task_id": "lab_canCompleteCircuit_324678911", "student_id": [ 6 ] } }
{ "input": [ "{\"gas\": \"[1, 2, 3, 4, 5]\", \"cost\": \"[3, 4, 5, 1, 2]\"}", "{\"gas\": \"[2, 3, 4]\", \"cost\": \"[3, 4, 3]\"}", "{\"gas\": \"[5, 1, 2, 3, 4]\", \"cost\": \"[4, 4, 1, 5, 1]\"}", "{\"gas\": \"[3, 3, 4]\", \"cost\": \"[3, 4, 4]\"}", "{\"gas\": \"[1, 2, 3]\", \"cost\": \"[1, 2, 3]\"}", "{\"gas\": \"[1, 2, 3, 4]\", \"cost\": \"[2, 2, 2, 2]\"}", "{\"gas\": \"[0, 0, 0]\", \"cost\": \"[1, 1, 1]\"}" ], "expected": [ [ "3" ], [ "-1" ], [ "4" ], [ "-1" ], [ "0" ], [ "1" ], [ "-1" ] ], "unexpected": [ [ "-1", "0", "1", "2", "4" ], [ "0", "1", "2", "3" ], [ "-1", "0", "1", "2", "3" ], [ "0", "1", "2" ], [ "-1", "1", "2" ], [ "-1", "0", "2", "3" ], [ "0", "1", "2" ] ] }
{ "input": [] }
advanced
verina_advanced_12
-----Description----- Write a Lean 4 function that returns the first duplicate integer found in a list. The function should return the value of the first duplicate it encounters, scanning from left to right. If no duplicates exist, return -1. -----Input----- lst: A list of integers. -----Output----- An integer representing the first duplicated value if any exists, otherwise -1.
-- !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 firstDuplicate_precond (lst : List Int) : Prop := -- !benchmark @start precond True -- !benchmark @end precond -- !benchmark @start code_aux -- !benchmark @end code_aux def firstDuplicate (lst : List Int) (h_precond : firstDuplicate_precond (lst)) : Int := -- !benchmark @start code let rec helper (seen : List Int) (rem : List Int) : Int := match rem with | [] => -1 | h :: t => if seen.contains h then h else helper (h :: seen) t helper [] lst -- !benchmark @end code -- !benchmark @start postcond_aux -- !benchmark @end postcond_aux @[reducible] def firstDuplicate_postcond (lst : List Int) (result: Int) (h_precond : firstDuplicate_precond (lst)) : Prop := -- !benchmark @start postcond -- if result = -1, then lst does not contain any duplicates (result = -1 → List.Nodup lst) ∧ -- if result is not -1, then it is the first duplicate in lst (result ≠ -1 → lst.count result > 1 ∧ (lst.filter (fun x => lst.count x > 1)).head? = some result ) -- !benchmark @end postcond -- !benchmark @start proof_aux -- !benchmark @end proof_aux theorem firstDuplicate_spec_satisfied (lst: List Int) (h_precond : firstDuplicate_precond (lst)) : firstDuplicate_postcond (lst) (firstDuplicate (lst) h_precond) h_precond := by -- !benchmark @start proof sorry -- !benchmark @end proof
{ "name": "firstDuplicate", "parameters": { "param_name": [ "lst" ], "param_type": [ "List Int" ] }, "return_type": "Int" }
{ "upstream": { "name": "lab_assignment", "link": "NA-These are typical problems we solve, im sure their links exist, I just didn't copy directly from any link", "task_id": "lab_firstDuplicate_325276763", "student_id": [ 10 ] } }
{ "input": [ "{\"lst\": \"[1, 2, 3, 2, 4]\"}", "{\"lst\": \"[5, 1, 2, 3, 4, 5]\"}", "{\"lst\": \"[1, 2, 3, 4, 5]\"}", "{\"lst\": \"[7, 7, 7, 7]\"}", "{\"lst\": \"[]\"}" ], "expected": [ [ "2" ], [ "5" ], [ "-1" ], [ "7" ], [ "-1" ] ], "unexpected": [ [ "1", "3", "-1" ], [ "1", "0" ], [ "1", "2", "3" ], [ "-1" ], [ "0", "1", "2" ] ] }
{ "input": [] }
advanced
verina_advanced_11
-----Description----- This task requires writing a Lean 4 method that finds the **majority element** in a list of integers. A majority element is defined as an element that appears **strictly more than half** the number of times in the list. If such an element exists, the method should return that element. Otherwise, it should return `-1`. The implementation must ensure that the result is either the majority element (if one exists) or `-1` (when no such element appears more than ⌊n/2⌋ times). -----Input----- The input consists of a list of integers: - lst: A list of integers, which may include duplicates and negative numbers. The list may also be empty. -----Output----- The output is a single integer: - If a majority element exists in the input list, return that element. - If no majority element exists, return `-1`.
-- !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 findMajorityElement_precond (lst : List Int) : Prop := -- !benchmark @start precond True -- !benchmark @end precond -- !benchmark @start code_aux def countOccurrences (n : Int) (lst : List Int) : Nat := lst.foldl (fun acc x => if x = n then acc + 1 else acc) 0 -- !benchmark @end code_aux def findMajorityElement (lst : List Int) (h_precond : findMajorityElement_precond (lst)) : Int := -- !benchmark @start code let n := lst.length let majority := lst.find? (fun x => countOccurrences x lst > n / 2) match majority with | some x => x | none => -1 -- !benchmark @end code -- !benchmark @start postcond_aux -- !benchmark @end postcond_aux @[reducible, simp] def findMajorityElement_postcond (lst : List Int) (result: Int) (h_precond : findMajorityElement_precond (lst)) : Prop := -- !benchmark @start postcond let count := fun x => (lst.filter (fun y => y = x)).length let n := lst.length let majority := count result > n / 2 ∧ lst.all (fun x => count x ≤ n / 2 ∨ x = result) (result = -1 → lst.all (count · ≤ n / 2) ∨ majority) ∧ (result ≠ -1 → majority) -- !benchmark @end postcond -- !benchmark @start proof_aux -- !benchmark @end proof_aux theorem findMajorityElement_spec_satisfied (lst: List Int) (h_precond : findMajorityElement_precond (lst)) : findMajorityElement_postcond (lst) (findMajorityElement (lst) h_precond) h_precond := by -- !benchmark @start proof sorry -- !benchmark @end proof
{ "name": "findMajorityElement", "parameters": { "param_name": [ "lst" ], "param_type": [ "List Int" ] }, "return_type": "Int" }
{ "upstream": { "name": "lab_assignment", "link": "[{\"text_file_id\"=>803067667}]", "task_id": "lab_findMajorityElement_325106966", "student_id": [ 9 ] } }
{ "input": [ "{\"lst\": \"[1, 2, 1, 1]\"}", "{\"lst\": \"[1, 2, 3, 4]\"}", "{\"lst\": \"[2, 2, 2, 2, 3, 3]\"}", "{\"lst\": \"[]\"}", "{\"lst\": \"[5, 5, 5, 5, 5, 5]\"}", "{\"lst\": \"[-1, -1, -1, 2, 2]\"}", "{\"lst\": \"[-3, -3, -3, -3, 1]\"}" ], "expected": [ [ "1" ], [ "-1" ], [ "2" ], [ "-1" ], [ "5" ], [ "-1" ], [ "-3" ] ], "unexpected": [ [ "2", "-1" ], [ "1", "2", "3", "4" ], [ "3", "-1" ], [ "0", "1" ], [ "0", "-1" ], [ "2" ], [ "1", "-1" ] ] }
{ "input": [] }
advanced
verina_basic_66
-----Description----- This task focuses on determining if a given integer is even. The problem requires checking whether the integer can be represented as twice another integer, meaning it is divisible by 2 without any remainder. -----Input----- The input consists of a single integer: • x: An integer to be evaluated. -----Output----- The output is a boolean value: • true if x is even (x mod 2 equals 0). • false if x is odd. -----Note----- No additional preconditions are required. The method should work correctly for any integer value.
-- !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 ComputeIsEven_precond (x : Int) : Prop := -- !benchmark @start precond True -- !benchmark @end precond -- !benchmark @start code_aux -- !benchmark @end code_aux def ComputeIsEven (x : Int) (h_precond : ComputeIsEven_precond (x)) : Bool := -- !benchmark @start code if x % 2 = 0 then true else false -- !benchmark @end code -- !benchmark @start postcond_aux -- !benchmark @end postcond_aux @[reducible, simp] def ComputeIsEven_postcond (x : Int) (result: Bool) (h_precond : ComputeIsEven_precond (x)) := -- !benchmark @start postcond result = true ↔ ∃ k : Int, x = 2 * k -- !benchmark @end postcond -- !benchmark @start proof_aux -- !benchmark @end proof_aux theorem ComputeIsEven_spec_satisfied (x: Int) (h_precond : ComputeIsEven_precond (x)) : ComputeIsEven_postcond (x) (ComputeIsEven (x) h_precond) h_precond := by -- !benchmark @start proof unfold ComputeIsEven ComputeIsEven_postcond simp rfl -- !benchmark @end proof
{ "name": "ComputeIsEven", "parameters": { "param_name": [ "x" ], "param_type": [ "Int" ] }, "return_type": "Bool" }
{ "upstream": { "name": "clover", "link": "https://github.com/ChuyueSun/Clover", "task_id": "Clover_is_even", "student_id": null } }
{ "input": [ "{\"x\": 4}", "{\"x\": 7}", "{\"x\": 0}", "{\"x\": -2}", "{\"x\": -3}" ], "expected": [ [ "True" ], [ "False" ], [ "True" ], [ "True" ], [ "False" ] ], "unexpected": [ [ "False" ], [ "True" ], [ "False" ], [ "False" ], [ "True" ] ] }
{ "input": [] }
basic
verina_advanced_32
-----Description----- This test implements a function in Lean 4 that finds the length of the longest increasing subsequence in a list of integers. A subsequence is a sequence that can be derived from another sequence by deleting some or no elements without changing the order of the remaining elements. An increasing subsequence is one in which the elements are in strictly increasing order. -----Input----- numbers: A list of integers. -----Output----- A natural number representing the length of the longest increasing subsequence in the input list. If the list is empty, the function returns 0.
-- !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 longestIncreasingSubsequence_precond (numbers : List Int) : Prop := -- !benchmark @start precond True -- !benchmark @end precond -- !benchmark @start code_aux -- !benchmark @end code_aux def longestIncreasingSubsequence (numbers : List Int) (h_precond : longestIncreasingSubsequence_precond (numbers)) : Nat := -- !benchmark @start code let rec buildTables : List Int → List Int → List Nat → Nat → Nat | [], _, lengths, _ => let rec findMaxLength : List Nat → Nat | [] => 0 | x :: xs => let maxRest := findMaxLength xs if x > maxRest then x else maxRest findMaxLength lengths | currNum :: restNums, prevNums, lengths, idx => let rec findLengthEndingAtCurr : List Int → List Nat → Nat → Nat | [], _, best => best | prevVal :: restVals, prevLen :: restLens, best => if prevVal < currNum then findLengthEndingAtCurr restVals restLens (max best prevLen) else findLengthEndingAtCurr restVals restLens best | _, _, best => best let bestPrevLen := findLengthEndingAtCurr prevNums lengths 0 let currLength := bestPrevLen + 1 buildTables restNums (prevNums ++ [currNum]) (lengths ++ [currLength]) (idx + 1) match numbers with | [] => 0 | [x] => 1 | first :: rest => buildTables rest [first] [1] 1 -- !benchmark @end code -- !benchmark @start postcond_aux -- !benchmark @end postcond_aux @[reducible, simp] def longestIncreasingSubsequence_postcond (numbers : List Int) (result: Nat) (h_precond : longestIncreasingSubsequence_precond (numbers)) : Prop := -- !benchmark @start postcond let allSubseq := (numbers.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 (numbers: List Int) (h_precond : longestIncreasingSubsequence_precond (numbers)) : longestIncreasingSubsequence_postcond (numbers) (longestIncreasingSubsequence (numbers) h_precond) h_precond := by -- !benchmark @start proof sorry -- !benchmark @end proof
{ "name": "longestIncreasingSubsequence", "parameters": { "param_name": [ "numbers" ], "param_type": [ "List Int" ] }, "return_type": "Nat" }
{ "upstream": { "name": "lab_assignment", "link": "", "task_id": "lab_longestIncreasingSubsequence_324969521", "student_id": [ 26 ] } }
{ "input": [ "{\"numbers\": \"[10, 22, 9, 33, 21, 50, 41, 60]\"}", "{\"numbers\": \"[3, 10, 2, 1, 20]\"}", "{\"numbers\": \"[50, 3, 10, 7, 40, 80]\"}", "{\"numbers\": \"[10, 9, 8, 7, 6, 5, 4, 3, 2, 1]\"}", "{\"numbers\": \"[1, 2, 3, 4, 5]\"}", "{\"numbers\": \"[]\"}", "{\"numbers\": \"[5]\"}", "{\"numbers\": \"[5, 5, 5, 5]\"}" ], "expected": [ [ "5" ], [ "3" ], [ "4" ], [ "1" ], [ "5" ], [ "0" ], [ "1" ], [ "1" ] ], "unexpected": [ [ "4", "6", "8" ], [ "2", "4", "5" ], [ "3", "5", "6" ], [ "0", "2", "10" ], [ "1", "4", "6" ], [ "1", "2", "3" ], [ "0", "2" ], [ "0", "4" ] ] }
{ "input": [] }
advanced
verina_basic_84
-----Description----- You are given an array of integers and a threshold value k. The problem is to create a new array where every element greater than k is replaced with -1 while every other element remains unchanged. -----Input----- The input consists of: • arr: An array of integers. • k: An integer used as the threshold for replacement. -----Output----- The output is an array of integers that satisfies the following conditions: • For every index i, if arr[i] is greater than k, then the returned array at index i is -1. • For every index i, if arr[i] is less than or equal to k, then the returned array at index i remains unchanged. -----Note----- It is assumed that the input array may be empty or non-empty, and that k can be any integer. 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 replace_precond (arr : Array Int) (k : Int) : Prop := -- !benchmark @start precond True -- !benchmark @end precond -- !benchmark @start code_aux def replace_loop (oldArr : Array Int) (k : Int) : Nat → Array Int → Array Int | i, acc => if i < oldArr.size then if (oldArr[i]!) > k then replace_loop oldArr k (i+1) (acc.set! i (-1)) else replace_loop oldArr k (i+1) acc else acc -- !benchmark @end code_aux def replace (arr : Array Int) (k : Int) (h_precond : replace_precond (arr) (k)) : Array Int := -- !benchmark @start code replace_loop arr k 0 arr -- !benchmark @end code -- !benchmark @start postcond_aux -- !benchmark @end postcond_aux @[reducible, simp] def replace_postcond (arr : Array Int) (k : Int) (result: Array Int) (h_precond : replace_precond (arr) (k)) := -- !benchmark @start postcond (∀ i : Nat, i < arr.size → (arr[i]! > k → result[i]! = -1)) ∧ (∀ i : Nat, i < arr.size → (arr[i]! ≤ k → result[i]! = arr[i]!)) -- !benchmark @end postcond -- !benchmark @start proof_aux -- !benchmark @end proof_aux theorem replace_spec_satisfied (arr: Array Int) (k: Int) (h_precond : replace_precond (arr) (k)) : replace_postcond (arr) (k) (replace (arr) (k) h_precond) h_precond := by -- !benchmark @start proof sorry -- !benchmark @end proof
{ "name": "replace", "parameters": { "param_name": [ "arr", "k" ], "param_type": [ "Array Int", "Int" ] }, "return_type": "Array Int" }
{ "upstream": { "name": "clover", "link": "https://github.com/ChuyueSun/Clover", "task_id": "Clover_replace", "student_id": null } }
{ "input": [ "{\"arr\": \"#[1, 5, 3, 10]\", \"k\": 4}", "{\"arr\": \"#[-1, 0, 1, 2]\", \"k\": 2}", "{\"arr\": \"#[100, 50, 100]\", \"k\": 100}", "{\"arr\": \"#[-5, -2, 0, 3]\", \"k\": -3}", "{\"arr\": \"#[1, 2, 3]\", \"k\": 5}" ], "expected": [ [ "#[1, -1, 3, -1]" ], [ "#[-1, 0, 1, 2]" ], [ "#[100, 50, 100]" ], [ "#[-5, -1, -1, -1]" ], [ "#[1, 2, 3]" ] ], "unexpected": [ [ "#[1, 5, 3, 10]", "#[1, -1, 3, 10]" ], [ "#[0, 0, 1, 2]", "#[-1, 0, 1, 1]" ], [ "#[100, 50, -1]", "#[100, 50, 50]" ], [ "#[-5, -2, -1, -1]", "#[-5, -1, 0, -1]" ], [ "#[1, 3, 3]", "#[1, 2, -1]" ] ] }
{ "input": [] }
basic
verina_basic_35
-----Description----- This task requires writing a Lean 4 method that rearranges an array of integers by moving all zero values to the end of the array. The method should ensure that the relative order of the non-zero elements remains the same, the overall size of the array is unchanged, and the number of zeroes in the array stays constant. -----Input----- The input consists of: arr: An array of integers. -----Output----- The output is an array of integers: Returns an array where: - The length is the same as that of the input array. - All zero values are positioned at the end. - The relative order of non-zero elements is preserved. - The count of zero values remains the same as in the input array. -----Note----- There are no preconditions; the method will always work 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 MoveZeroesToEnd_precond (arr : Array Int) : Prop := -- !benchmark @start precond True -- !benchmark @end precond -- !benchmark @start code_aux -- !benchmark @end code_aux def MoveZeroesToEnd (arr : Array Int) (h_precond : MoveZeroesToEnd_precond (arr)) : Array Int := -- !benchmark @start code let nonZeros := arr.toList.filter (· ≠ 0) let zeros := arr.toList.filter (· = 0) Array.mk (nonZeros ++ zeros) -- !benchmark @end code -- !benchmark @start postcond_aux -- !benchmark @end postcond_aux @[reducible, simp] def MoveZeroesToEnd_postcond (arr : Array Int) (result: Array Int) (h_precond : MoveZeroesToEnd_precond (arr)) := -- !benchmark @start postcond let firstResZeroIdx := result.toList.idxOf 0 List.isPerm result.toList arr.toList ∧ result.toList.take firstResZeroIdx = arr.toList.filter (· ≠ 0) ∧ result.toList.drop firstResZeroIdx = arr.toList.filter (· = 0) -- !benchmark @end postcond -- !benchmark @start proof_aux -- !benchmark @end proof_aux theorem MoveZeroesToEnd_spec_satisfied (arr: Array Int) (h_precond : MoveZeroesToEnd_precond (arr)) : MoveZeroesToEnd_postcond (arr) (MoveZeroesToEnd (arr) h_precond) h_precond := by -- !benchmark @start proof sorry -- !benchmark @end proof
{ "name": "MoveZeroesToEnd", "parameters": { "param_name": [ "arr" ], "param_type": [ "Array Int" ] }, "return_type": "Array Int" }
{ "upstream": { "name": "dafny-synthesis", "link": "https://github.com/Mondego/dafny-synthesis", "task_id": "task_id_632", "student_id": null } }
{ "input": [ "{\"arr\": \"#[0, 1, 0, 3, 12]\"}", "{\"arr\": \"#[0, 0, 1]\"}", "{\"arr\": \"#[1, 2, 3]\"}", "{\"arr\": \"#[0, 0, 0]\"}", "{\"arr\": \"#[]\"}" ], "expected": [ [ "#[1, 3, 12, 0, 0]" ], [ "#[1, 0, 0]" ], [ "#[1, 2, 3]" ], [ "#[0, 0, 0]" ], [ "#[]" ] ], "unexpected": [ [ "#[0, 1, 0, 3, 12]", "#[1, 0, 3, 12, 0]" ], [ "#[0, 0, 1]", "#[0, 1, 0]" ], [ "#[1, 3, 2]", "#[2, 1, 3]" ], [ "#[1, 0, 0]", "#[0, 1, 0]" ], [ "#[0]", "#[1]" ] ] }
{ "input": [] }
basic
verina_basic_93
-----Description----- This task requires swapping two 8-bit unsigned integers. Given two unsigned integer inputs, the goal is to produce an output pair where the first element is the original second input and the second element is the original first input. The problem focuses solely on exchanging the values without specifying any particular method to achieve the swap. -----Input----- The input consists of: • X: A UInt8 value. • Y: A UInt8 value. -----Output----- The output is a pair of UInt8 values (newX, newY) where: • newX is equal to the original Y. • newY is equal to the original X. -----Note----- There are no additional preconditions; the function is meant to work correctly for any pair of UInt8 values by leveraging bitwise xor 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 SwapBitvectors_precond (X : UInt8) (Y : UInt8) : Prop := -- !benchmark @start precond True -- !benchmark @end precond -- !benchmark @start code_aux -- !benchmark @end code_aux def SwapBitvectors (X : UInt8) (Y : UInt8) (h_precond : SwapBitvectors_precond (X) (Y)) : UInt8 × UInt8 := -- !benchmark @start code let temp := X.xor Y let newY := temp.xor Y let newX := temp.xor newY (newX, newY) -- !benchmark @end code -- !benchmark @start postcond_aux -- !benchmark @end postcond_aux @[reducible, simp] def SwapBitvectors_postcond (X : UInt8) (Y : UInt8) (result: UInt8 × UInt8) (h_precond : SwapBitvectors_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 SwapBitvectors_spec_satisfied (X: UInt8) (Y: UInt8) (h_precond : SwapBitvectors_precond (X) (Y)) : SwapBitvectors_postcond (X) (Y) (SwapBitvectors (X) (Y) h_precond) h_precond := by -- !benchmark @start proof sorry -- !benchmark @end proof
{ "name": "SwapBitvectors", "parameters": { "param_name": [ "X", "Y" ], "param_type": [ "UInt8", "UInt8" ] }, "return_type": "UInt8 × UInt8" }
{ "upstream": { "name": "clover", "link": "https://github.com/ChuyueSun/Clover", "task_id": "Clover_swap_bitvector", "student_id": null } }
{ "input": [ "{\"X\": 0, \"Y\": 0}", "{\"X\": 5, \"Y\": 10}", "{\"X\": 255, \"Y\": 1}", "{\"X\": 128, \"Y\": 64}", "{\"X\": 15, \"Y\": 15}" ], "expected": [ [ "(0, 0)" ], [ "(10, 5)" ], [ "(1, 255)" ], [ "(64, 128)" ], [ "(15, 15)" ] ], "unexpected": [ [ "(0, 1)", "(1, 0)" ], [ "(5, 10)", "(10, 10)", "(5, 5)" ], [ "(255, 1)", "(1, 254)", "(0, 255)" ], [ "(128, 64)", "(64, 64)", "(0, 128)" ], [ "(15, 16)", "(16, 15)", "(14, 15)" ] ] }
{ "input": [] }
basic
verina_advanced_7
-----Description----- This task requires writing a Lean 4 function that converts a binary number represented as a list of digits (0 or 1) into its corresponding decimal value. The list is ordered in big-endian format, meaning the most significant digit comes first. The function should interpret the list as a binary number and return its decimal representation as a natural number. -----Input----- The input is a list of natural numbers: digits: A list of digits, each of which is either 0 or 1, representing a binary number in big-endian order. -----Output----- The output is a natural number: Returns the decimal value of the binary number represented by 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 binaryToDecimal_precond (digits : List Nat) : Prop := -- !benchmark @start precond digits.all (fun d => d = 0 ∨ d = 1) -- !benchmark @end precond -- !benchmark @start code_aux -- !benchmark @end code_aux def binaryToDecimal (digits : List Nat) (h_precond : binaryToDecimal_precond (digits)) : Nat := -- !benchmark @start code let rec helper (digits : List Nat) : Nat := match digits with | [] => 0 | first :: rest => first * Nat.pow 2 rest.length + helper rest helper digits -- !benchmark @end code -- !benchmark @start postcond_aux -- !benchmark @end postcond_aux @[reducible] def binaryToDecimal_postcond (digits : List Nat) (result: Nat) (h_precond : binaryToDecimal_precond (digits)) : Prop := -- !benchmark @start postcond result - List.foldl (λ acc bit => acc * 2 + bit) 0 digits = 0 ∧ List.foldl (λ acc bit => acc * 2 + bit) 0 digits - result = 0 -- !benchmark @end postcond -- !benchmark @start proof_aux -- !benchmark @end proof_aux theorem binaryToDecimal_spec_satisfied (digits: List Nat) (h_precond : binaryToDecimal_precond (digits)) : binaryToDecimal_postcond (digits) (binaryToDecimal (digits) h_precond) h_precond := by -- !benchmark @start proof sorry -- !benchmark @end proof
{ "name": "binaryToDecimal", "parameters": { "param_name": [ "digits" ], "param_type": [ "List Nat" ] }, "return_type": "Nat" }
{ "upstream": { "name": "lab_assignment", "link": "https://leetcode.com/problems/convert-binary-number-in-a-linked-list-to-integer/description/", "task_id": "lab_binaryToDecimal_325751702", "student_id": [ 5 ] } }
{ "input": [ "{\"digits\": \"[1, 0, 1]\"}", "{\"digits\": \"[1, 1, 1, 1]\"}", "{\"digits\": \"[0, 0, 0]\"}", "{\"digits\": \"[1, 0, 0, 0, 0]\"}", "{\"digits\": \"[]\"}", "{\"digits\": \"[1]\"}" ], "expected": [ [ "5" ], [ "15" ], [ "0" ], [ "16" ], [ "0" ], [ "1" ] ], "unexpected": [ [ "3", "4", "6" ], [ "14", "16" ], [ "1", "2" ], [ "8", "0" ], [ "1" ], [ "0" ] ] }
{ "input": [ "{'digits': '[2]'}" ] }
advanced
verina_advanced_54
-----Description----- This task requires writing a Lean 4 function that finds the one missing number in a list of distinct natural numbers from 0 to n. The list contains exactly n numbers and all numbers are in the range [0, n], but one number in that range is missing. Your function must return the missing number. You may assume the input list contains no duplicates and only one number is missing. -----Input----- - nums: A list of natural numbers of length n, each in the range [0, n] with exactly one number missing. -----Output----- - A natural number: the missing number in the range [0, n] not present 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 missingNumber_precond (nums : List Nat) : Prop := -- !benchmark @start precond nums.all (fun x => x ≤ nums.length) ∧ List.Nodup nums -- !benchmark @end precond -- !benchmark @start code_aux -- !benchmark @end code_aux def missingNumber (nums : List Nat) (h_precond : missingNumber_precond (nums)) : Nat := -- !benchmark @start code let n := nums.length let expectedSum := (n * (n + 1)) / 2 let actualSum := nums.foldl (· + ·) 0 expectedSum - actualSum -- !benchmark @end code -- !benchmark @start postcond_aux -- !benchmark @end postcond_aux @[reducible] def missingNumber_postcond (nums : List Nat) (result: Nat) (h_precond : missingNumber_precond (nums)) : Prop := -- !benchmark @start postcond let n := nums.length (result ∈ List.range (n + 1)) ∧ ¬(result ∈ nums) ∧ ∀ x, (x ∈ List.range (n + 1)) → x ≠ result → x ∈ nums -- !benchmark @end postcond -- !benchmark @start proof_aux -- !benchmark @end proof_aux theorem missingNumber_spec_satisfied (nums: List Nat) (h_precond : missingNumber_precond (nums)) : missingNumber_postcond (nums) (missingNumber (nums) h_precond) h_precond := by -- !benchmark @start proof sorry -- !benchmark @end proof
{ "name": "missingNumber", "parameters": { "param_name": [ "nums" ], "param_type": [ "List Nat" ] }, "return_type": "Nat" }
{ "upstream": { "name": "lab_assignment", "link": "https://leetcode.com/problems/missing-number/description/", "task_id": "lab_missingNumber_324976035", "student_id": [ 22 ] } }
{ "input": [ "{\"nums\": \"[3, 0, 1]\"}", "{\"nums\": \"[0, 1]\"}", "{\"nums\": \"[9, 6, 4, 2, 3, 5, 7, 0, 1]\"}", "{\"nums\": \"[0]\"}", "{\"nums\": \"[1]\"}" ], "expected": [ [ "2" ], [ "2" ], [ "8" ], [ "1" ], [ "0" ] ], "unexpected": [ [ "0", "1", "3" ], [ "0", "1" ], [ "1", "9" ], [ "0" ], [ "1" ] ] }
{ "input": [ "{'nums': '[0, 0, 1]'}" ] }
advanced
verina_basic_22
-----Description----- This task requires writing a Lean 4 method that identifies the dissimilar elements between two arrays of integers. In other words, the method should return an array containing all elements that appear in one input array but not in the other. The output array must contain no duplicate elements and the order of elements does not matter. -----Input----- The input consists of: a: An array of integers. b: An array of integers. -----Output----- The output is an array of integers: Returns an array containing all distinct elements from both input arrays that are not present in the other array and should be sorted
-- !benchmark @start import type=solution import Std.Data.HashSet -- !benchmark @end import -- !benchmark @start solution_aux def inArray (a : Array Int) (x : Int) : Bool := a.any (fun y => y = x) -- !benchmark @end solution_aux -- !benchmark @start precond_aux -- !benchmark @end precond_aux @[reducible, simp] def dissimilarElements_precond (a : Array Int) (b : Array Int) : Prop := -- !benchmark @start precond True -- !benchmark @end precond -- !benchmark @start code_aux -- !benchmark @end code_aux def dissimilarElements (a : Array Int) (b : Array Int) (h_precond : dissimilarElements_precond (a) (b)) : Array Int := -- !benchmark @start code let res := a.foldl (fun acc x => if !inArray b x then acc.insert x else acc) Std.HashSet.empty let res := b.foldl (fun acc x => if !inArray a x then acc.insert x else acc) res res.toArray.insertionSort -- !benchmark @end code -- !benchmark @start postcond_aux -- !benchmark @end postcond_aux @[reducible, simp] def dissimilarElements_postcond (a : Array Int) (b : Array Int) (result: Array Int) (h_precond : dissimilarElements_precond (a) (b)) := -- !benchmark @start postcond result.all (fun x => inArray a x ≠ inArray b x)∧ result.toList.Pairwise (· ≤ ·) ∧ a.all (fun x => if x ∈ b then x ∉ result else x ∈ result) ∧ b.all (fun x => if x ∈ a then x ∉ result else x ∈ result) -- !benchmark @end postcond -- !benchmark @start proof_aux -- !benchmark @end proof_aux theorem dissimilarElements_spec_satisfied (a: Array Int) (b: Array Int) (h_precond : dissimilarElements_precond (a) (b)) : dissimilarElements_postcond (a) (b) (dissimilarElements (a) (b) h_precond) h_precond := by -- !benchmark @start proof sorry -- !benchmark @end proof
{ "name": "dissimilarElements", "parameters": { "param_name": [ "a", "b" ], "param_type": [ "Array Int", "Array Int" ] }, "return_type": "Array Int" }
{ "upstream": { "name": "dafny-synthesis", "link": "https://github.com/Mondego/dafny-synthesis", "task_id": "task_id_579", "student_id": null } }
{ "input": [ "{\"a\": \"#[1, 2, 3, 4]\", \"b\": \"#[3, 4, 5, 6]\"}", "{\"a\": \"#[1, 1, 2]\", \"b\": \"#[2, 3]\"}", "{\"a\": \"#[]\", \"b\": \"#[4, 5]\"}", "{\"a\": \"#[7, 8]\", \"b\": \"#[]\"}", "{\"a\": \"#[1, 2, 3]\", \"b\": \"#[1, 2, 3]\"}", "{\"a\": \"#[1, 2, 3]\", \"b\": \"#[4, 5, 6]\"}", "{\"a\": \"#[-1, 0, 1]\", \"b\": \"#[0]\"}" ], "expected": [ [ "#[1, 2, 5, 6]" ], [ "#[1, 3]" ], [ "#[4, 5]" ], [ "#[7, 8]" ], [ "#[]" ], [ "#[1, 2, 3, 4, 5, 6]" ], [ "#[-1, 1]" ] ], "unexpected": [ [ "#[1,2,3,4,5,6]", "#[3,4]", "#[1,3,5]" ], [ "#[1]", "#[3]", "#[1,2,3]" ], [ "#[4]", "#[5]", "#[]" ], [ "#[7]", "#[8]", "#[7, 8, 9]" ], [ "#[1]", "#[1,2]", "#[1,2,3]" ], [ "#[1,2,3,4]", "#[4,5,6]", "#[1,2,3]" ], [ "#[0]", "#[-1,0,1]", "#[-1]" ] ] }
{ "input": [] }
basic
verina_advanced_66
-----Description----- Given an input string "words_str", this task requires writing a Lean 4 function that reverses the order of its words. A word is defined as a contiguous sequence of non-space characters. The function must remove any extra spaces so that the output string contains words separated by a single space and has no leading or trailing spaces. The characters within each word must stay the same as the original input. -----Input----- words_str: A string that may contain leading, trailing, or multiple spaces between words. -----Output----- A string with the words from the input reversed, where words are separated by a single space, with no extra spaces at the beginning or end.
-- !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 reverseWords_precond (words_str : String) : Prop := -- !benchmark @start precond True -- !benchmark @end precond -- !benchmark @start code_aux -- !benchmark @end code_aux def reverseWords (words_str : String) (h_precond : reverseWords_precond (words_str)) : String := -- !benchmark @start code let rawWords : List String := words_str.splitOn " " let rec filterNonEmpty (words : List String) : List String := match words with | [] => [] | h :: t => if h = "" then filterNonEmpty t else h :: filterNonEmpty t let filteredWords : List String := filterNonEmpty rawWords let revWords : List String := filteredWords.reverse let rec joinWithSpace (words : List String) : String := match words with | [] => "" | [w] => w | h :: t => -- Append the current word with a space and continue joining the rest. h ++ " " ++ joinWithSpace t let result : String := joinWithSpace revWords result -- !benchmark @end code -- !benchmark @start postcond_aux -- !benchmark @end postcond_aux @[reducible] def reverseWords_postcond (words_str : String) (result: String) (h_precond : reverseWords_precond (words_str)) : Prop := -- !benchmark @start postcond ∃ words : List String, (words = (words_str.splitOn " ").filter (fun w => w ≠ "")) ∧ result = String.intercalate " " (words.reverse) -- !benchmark @end postcond -- !benchmark @start proof_aux -- !benchmark @end proof_aux theorem reverseWords_spec_satisfied (words_str: String) (h_precond : reverseWords_precond (words_str)) : reverseWords_postcond (words_str) (reverseWords (words_str) h_precond) h_precond := by -- !benchmark @start proof sorry -- !benchmark @end proof
{ "name": "reverseWords", "parameters": { "param_name": [ "words_str" ], "param_type": [ "String" ] }, "return_type": "String" }
{ "upstream": { "name": "lab_assignment", "link": "https://leetcode.com/problems/reverse-words-in-a-string/description/", "task_id": "lab_reverseWords_324895224", "student_id": [ 48 ] } }
{ "input": [ "{\"words_str\": \"the sky is blue\"}", "{\"words_str\": \" hello world \"}", "{\"words_str\": \"a good example\"}", "{\"words_str\": \" Bob Loves Alice \"}", "{\"words_str\": \"this lab is interesting\"}" ], "expected": [ [ "blue is sky the" ], [ "world hello" ], [ "example good a" ], [ "Alice Loves Bob" ], [ "interesting is lab this" ] ], "unexpected": [ [ "the sky is blue", "sky the blue is" ], [ "hello world", "worldhello" ], [ "a good example", "example a good" ], [ "Bob Loves Alice", "Alice Loves Bob " ], [ "gnitseretni si bal siht" ] ] }
{ "input": [] }
advanced
verina_basic_69
-----Description----- This problem involves determining the index of the first occurrence of a specified element within an array of integers. The objective is to identify the correct position where the target element appears for the first time, ensuring that all elements prior to that index are different from the target. -----Input----- The input consists of: • a: An array of integers. • e: An integer representing the element to search for. -----Output----- The output is a natural number (Nat) representing the index of the first occurrence of e in the array. • If the element e exists in the array, the index n will satisfy the conditions specified above. -----Note----- It is assumed that the input satisfies the precondition where at least one index i in a exists such that a[i]! = e. The implementation uses a helper function to iterate through the array recursively.
-- !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 LinearSearch_precond (a : Array Int) (e : Int) : Prop := -- !benchmark @start precond ∃ i, i < a.size ∧ a[i]! = e -- !benchmark @end precond -- !benchmark @start code_aux def linearSearchAux (a : Array Int) (e : Int) (n : Nat) : Nat := if n < a.size then if a[n]! = e then n else linearSearchAux a e (n + 1) else 0 -- !benchmark @end code_aux def LinearSearch (a : Array Int) (e : Int) (h_precond : LinearSearch_precond (a) (e)) : Nat := -- !benchmark @start code linearSearchAux a e 0 -- !benchmark @end code -- !benchmark @start postcond_aux -- !benchmark @end postcond_aux @[reducible, simp] def LinearSearch_postcond (a : Array Int) (e : Int) (result: Nat) (h_precond : LinearSearch_precond (a) (e)) := -- !benchmark @start postcond (result < a.size) ∧ (a[result]! = e) ∧ (∀ k : Nat, k < result → a[k]! ≠ e) -- !benchmark @end postcond -- !benchmark @start proof_aux -- !benchmark @end proof_aux theorem LinearSearch_spec_satisfied (a: Array Int) (e: Int) (h_precond : LinearSearch_precond (a) (e)) : LinearSearch_postcond (a) (e) (LinearSearch (a) (e) h_precond) h_precond := by -- !benchmark @start proof sorry -- !benchmark @end proof
{ "name": "LinearSearch", "parameters": { "param_name": [ "a", "e" ], "param_type": [ "Array Int", "Int" ] }, "return_type": "Nat" }
{ "upstream": { "name": "clover", "link": "https://github.com/ChuyueSun/Clover", "task_id": "Clover_linear_search2", "student_id": null } }
{ "input": [ "{\"a\": \"#[1, 2, 3, 4, 5]\", \"e\": 3}", "{\"a\": \"#[10, 20, 30, 40, 50]\", \"e\": 10}", "{\"a\": \"#[5, 4, 3, 2, 1]\", \"e\": 1}", "{\"a\": \"#[-1, 0, 1, 2]\", \"e\": -1}", "{\"a\": \"#[7, 8, 7, 9, 7]\", \"e\": 7}" ], "expected": [ [ "2" ], [ "0" ], [ "4" ], [ "0" ], [ "0" ] ], "unexpected": [ [ "0", "1", "3" ], [ "1", "2", "3" ], [ "0", "1", "2" ], [ "1", "2", "3" ], [ "2", "3", "4" ] ] }
{ "input": [ "{'a': '#[1, 2, 3, 4, 5]', 'e': 6}" ] }
basic
verina_basic_7
-----Description----- This task requires writing a Lean 4 method that computes the sum of the squares of the first n odd natural numbers. The result should match the formula: (n * (2 * n - 1) * (2 * n + 1)) / 3. -----Input----- The input consists of: n: A natural number representing the count of odd natural numbers to consider (n should be non-negative). -----Output----- The output is a natural number: Returns the sum of the squares of the first n odd natural numbers, as defined by the formula: (n * (2 * n - 1) * (2 * n + 1)) / 3.
-- !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 sumOfSquaresOfFirstNOddNumbers_precond (n : Nat) : Prop := -- !benchmark @start precond True -- !benchmark @end precond -- !benchmark @start code_aux -- !benchmark @end code_aux def sumOfSquaresOfFirstNOddNumbers (n : Nat) (h_precond : sumOfSquaresOfFirstNOddNumbers_precond (n)) : Nat := -- !benchmark @start code let rec loop (k : Nat) (sum : Nat) : Nat := if k = 0 then sum else loop (k - 1) (sum + (2 * k - 1) * (2 * k - 1)) loop n 0 -- !benchmark @end code -- !benchmark @start postcond_aux -- !benchmark @end postcond_aux @[reducible, simp] def sumOfSquaresOfFirstNOddNumbers_postcond (n : Nat) (result: Nat) (h_precond : sumOfSquaresOfFirstNOddNumbers_precond (n)) := -- !benchmark @start postcond result - (n * (2 * n - 1) * (2 * n + 1)) / 3 = 0 ∧ (n * (2 * n - 1) * (2 * n + 1)) / 3 - result = 0 -- !benchmark @end postcond -- !benchmark @start proof_aux -- !benchmark @end proof_aux theorem sumOfSquaresOfFirstNOddNumbers_spec_satisfied (n: Nat) (h_precond : sumOfSquaresOfFirstNOddNumbers_precond (n)) : sumOfSquaresOfFirstNOddNumbers_postcond (n) (sumOfSquaresOfFirstNOddNumbers (n) h_precond) h_precond := by -- !benchmark @start proof sorry -- !benchmark @end proof
{ "name": "sumOfSquaresOfFirstNOddNumbers", "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_267", "student_id": null } }
{ "input": [ "{\"n\": 0}", "{\"n\": 1}", "{\"n\": 2}", "{\"n\": 3}", "{\"n\": 4}", "{\"n\": 5}", "{\"n\": 10}" ], "expected": [ [ "0" ], [ "1" ], [ "10" ], [ "35" ], [ "84" ], [ "165" ], [ "1330" ] ], "unexpected": [ [ "1", "2" ], [ "0", "2", "3" ], [ "9", "11", "12" ], [ "30", "34", "36" ], [ "80", "85", "90" ], [ "160", "166", "170" ], [ "1320", "1331", "1340" ] ] }
{ "input": [] }
basic
verina_basic_106
-----Description----- The task is to compute the element-wise sum of two integer arrays. The result should be a new array where each element is the sum of the corresponding elements from the two input arrays. The problem assumes that both arrays have the same length. -----Input----- The input consists of two parameters: • a: An array of integers. • b: An array of integers. Note: Both arrays must have the same length. -----Output----- The output is an array of integers that: • Has the same size as the input arrays. • Contains elements where each element at index i is computed as a[i]! + b[i]! from the input arrays. -----Note----- It is assumed that the two input arrays have equal lengths.
-- !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) (b : Array Int) : Prop := -- !benchmark @start precond a.size = b.size -- !benchmark @end precond -- !benchmark @start code_aux -- !benchmark @end code_aux def arraySum (a : Array Int) (b : Array Int) (h_precond : arraySum_precond (a) (b)) : Array Int := -- !benchmark @start code if a.size ≠ b.size then panic! "Array lengths mismatch" else let n := a.size; let c := Array.mkArray n 0; let rec loop (i : Nat) (c : Array Int) : Array Int := if i < n then let c' := c.set! i (a[i]! + b[i]!); loop (i + 1) c' else c; loop 0 c -- !benchmark @end code -- !benchmark @start postcond_aux -- !benchmark @end postcond_aux @[reducible, simp] def arraySum_postcond (a : Array Int) (b : Array Int) (result: Array Int) (h_precond : arraySum_precond (a) (b)) := -- !benchmark @start postcond (result.size = a.size) ∧ (∀ i : Nat, i < a.size → a[i]! + b[i]! = result[i]!) -- !benchmark @end postcond -- !benchmark @start proof_aux -- !benchmark @end proof_aux theorem arraySum_spec_satisfied (a: Array Int) (b: Array Int) (h_precond : arraySum_precond (a) (b)) : arraySum_postcond (a) (b) (arraySum (a) (b) h_precond) h_precond := by -- !benchmark @start proof sorry -- !benchmark @end proof
{ "name": "arraySum", "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_sum", "student_id": null } }
{ "input": [ "{\"a\": \"#[1, 2, 3]\", \"b\": \"#[4, 5, 6]\"}", "{\"a\": \"#[0, 0, 0]\", \"b\": \"#[0, 0, 0]\"}", "{\"a\": \"#[-1, 2, 3]\", \"b\": \"#[1, -2, 4]\"}", "{\"a\": \"#[10]\", \"b\": \"#[-10]\"}", "{\"a\": \"#[100, 200, 300]\", \"b\": \"#[100, 200, 300]\"}" ], "expected": [ [ "#[5, 7, 9]" ], [ "#[0, 0, 0]" ], [ "#[0, 0, 7]" ], [ "#[0]" ], [ "#[200, 400, 600]" ] ], "unexpected": [ [ "#[5, 6, 9]", "#[4, 7, 9]" ], [ "#[0, 0, 1]", "#[1, 0, 0]" ], [ "#[0, 1, 7]", "#[0, 0, 6]" ], [ "#[1]", "#[-1]" ], [ "#[200, 400, 601]", "#[199, 400, 600]", "#[200, 399, 600]" ] ] }
{ "input": [ "{'a': '#[1, 2, 3, 4]', 'b': '#[5, 6, 7]'}" ] }
basic
verina_advanced_23
-----Description----- This task requires writing a Lean 4 method that determines whether a given integer is a power of two. An integer n is a power of two if there exists an integer x such that n = 2^x. The method should return true if n is a power of two, and false otherwise. Note that negative numbers and zero are not powers of two. -----Input----- The input consists of one integer: n: The integer to be tested. -----Output----- The output is a boolean: Returns true if there exists an integer x such that n = 2^x (with n > 0), otherwise 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 isPowerOfTwo_precond (n : Int) : Prop := -- !benchmark @start precond True -- !benchmark @end precond -- !benchmark @start code_aux -- !benchmark @end code_aux def isPowerOfTwo (n : Int) (h_precond : isPowerOfTwo_precond (n)) : Bool := -- !benchmark @start code if n <= 0 then false else let rec aux (m : Int) (fuel : Nat) : Bool := if fuel = 0 then false else if m = 1 then true else if m % 2 ≠ 0 then false else aux (m / 2) (fuel - 1) aux n n.natAbs -- !benchmark @end code -- !benchmark @start postcond_aux def pow (base : Int) (exp : Nat) : Int := match exp with | 0 => 1 | n+1 => base * pow base n -- !benchmark @end postcond_aux @[reducible] def isPowerOfTwo_postcond (n : Int) (result: Bool) (h_precond : isPowerOfTwo_precond (n)) : Prop := -- !benchmark @start postcond if result then ∃ (x : Nat), (pow 2 x = n) ∧ (n > 0) else ¬ (∃ (x : Nat), (pow 2 x = n) ∧ (n > 0)) -- !benchmark @end postcond -- !benchmark @start proof_aux -- !benchmark @end proof_aux theorem isPowerOfTwo_spec_satisfied (n: Int) (h_precond : isPowerOfTwo_precond (n)) : isPowerOfTwo_postcond (n) (isPowerOfTwo (n) h_precond) h_precond := by -- !benchmark @start proof sorry -- !benchmark @end proof
{ "name": "isPowerOfTwo", "parameters": { "param_name": [ "n" ], "param_type": [ "Int" ] }, "return_type": "Bool" }
{ "upstream": { "name": "lab_assignment", "link": "https://leetcode.com/problems/power-of-two/description/", "task_id": "lab_isPowerOfTwo_324854887", "student_id": [ 18 ] } }
{ "input": [ "{\"n\": 1}", "{\"n\": 16}", "{\"n\": 3}", "{\"n\": 0}", "{\"n\": -2}", "{\"n\": 8}", "{\"n\": 10}" ], "expected": [ [ "True" ], [ "True" ], [ "False" ], [ "False" ], [ "False" ], [ "True" ], [ "False" ] ], "unexpected": [ [ "False" ], [ "False" ], [ "True" ], [ "True" ], [ "True" ], [ "False" ], [ "True" ] ] }
{ "input": [] }
advanced
verina_basic_23
-----Description----- This task requires writing a Lean 4 method that calculates the difference between the maximum and minimum values in an array of integers. In other words, the method should determine the highest and lowest numbers in the array and return the result of subtracting the minimum from the maximum. -----Input----- The input consists of: a: An array of integers. -----Output----- The output is an integer: Returns the difference between the largest and the smallest values in the input array. -----Note----- The input 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 differenceMinMax_precond (a : Array Int) : Prop := -- !benchmark @start precond a.size > 0 -- !benchmark @end precond -- !benchmark @start code_aux -- !benchmark @end code_aux def differenceMinMax (a : Array Int) (h_precond : differenceMinMax_precond (a)) : Int := -- !benchmark @start code let rec loop (i : Nat) (minVal maxVal : Int) : Int := if i < a.size then let x := a[i]! let newMin := if x < minVal then x else minVal let newMax := if x > maxVal then x else maxVal loop (i + 1) newMin newMax else maxVal - minVal loop 1 (a[0]!) (a[0]!) -- !benchmark @end code -- !benchmark @start postcond_aux -- !benchmark @end postcond_aux @[reducible, simp] def differenceMinMax_postcond (a : Array Int) (result: Int) (h_precond : differenceMinMax_precond (a)) := -- !benchmark @start postcond result + (a.foldl (fun acc x => if x < acc then x else acc) (a[0]!)) = (a.foldl (fun acc x => if x > acc then x else acc) (a[0]!)) -- !benchmark @end postcond -- !benchmark @start proof_aux -- !benchmark @end proof_aux theorem differenceMinMax_spec_satisfied (a: Array Int) (h_precond : differenceMinMax_precond (a)) : differenceMinMax_postcond (a) (differenceMinMax (a) h_precond) h_precond := by -- !benchmark @start proof sorry -- !benchmark @end proof
{ "name": "differenceMinMax", "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_588", "student_id": null } }
{ "input": [ "{\"a\": \"#[3, 1, 4, 1, 5, 9, 2, 6, 5, 3, 5]\"}", "{\"a\": \"#[10, 20, 30, 40, 50]\"}", "{\"a\": \"#[-10, -20, -30, -40, -50]\"}", "{\"a\": \"#[7]\"}", "{\"a\": \"#[5, 5, 5, 5]\"}", "{\"a\": \"#[1, -1, 2, -2]\"}" ], "expected": [ [ "8" ], [ "40" ], [ "40" ], [ "0" ], [ "0" ], [ "4" ] ], "unexpected": [ [ "7", "9", "10" ], [ "30", "35", "45" ], [ "30", "41", "20" ], [ "1", "-1", "2" ], [ "1", "5", "-1" ], [ "3", "0", "5" ] ] }
{ "input": [ "{'a': '#[]'}" ] }
basic
verina_basic_48
-----Description----- This task requires writing a Lean 4 method that determines whether a given non-negative natural number is a perfect square. In other words, the method should return true if there exists a natural number whose square is equal to the input number, and false if no such number exists. -----Input----- The input consists of a single natural number: n: A non-negative natural number (Nat). -----Output----- The output is a Boolean value: Returns true if there exists an integer such that its square equals the input n. Returns false if no integer squared equals the input n.
-- !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 isPerfectSquare_precond (n : Nat) : Prop := -- !benchmark @start precond True -- !benchmark @end precond -- !benchmark @start code_aux -- !benchmark @end code_aux def isPerfectSquare (n : Nat) : Bool := -- !benchmark @start code if n = 0 then true else let rec check (x : Nat) (fuel : Nat) : Bool := match fuel with | 0 => false | fuel + 1 => if x * x > n then false else if x * x = n then true else check (x + 1) fuel check 1 n -- !benchmark @end code -- !benchmark @start postcond_aux -- !benchmark @end postcond_aux @[reducible, simp] def isPerfectSquare_postcond (n : Nat) (result : Bool) : Prop := -- !benchmark @start postcond result ↔ ∃ i : Nat, i * i = n -- !benchmark @end postcond -- !benchmark @start proof_aux theorem check_correct (n : Nat) (x fuel : Nat) : isPerfectSquare.check n x fuel = true → ∃ i, x ≤ i ∧ i * i = n := by induction fuel generalizing x with | zero => -- In the base case, check always returns false, so this is a contradiction unfold isPerfectSquare.check simp | succ fuel ih => -- Unfold the definition of check for the successor case unfold isPerfectSquare.check simp_all -- Split into cases based on comparison of x*x with n if hgt : x * x > n then -- If x*x > n, check returns false, contradiction simp_all else if heq : x * x = n then -- If x*x = n, we found our witness simp_all exists x else -- Otherwise, we need to apply the induction hypothesis simp_all have h_rec := ih (x + 1) -- Complete the proof by transitivity of ≤ intro h have ⟨i, hi, heqi⟩ := h_rec h exists i constructor · -- Show x ≤ i by transitivity: x ≤ x+1 ≤ i exact Nat.le_trans (Nat.le_succ x) hi · -- Pass through the equality i * i = n exact heqi theorem check_complete (n : Nat) (x fuel : Nat) (i : Nat) (hx : x ≤ i) (hi : i * i = n) (hfuel : i < x + fuel) : isPerfectSquare.check n x fuel = true := by induction fuel generalizing x with | zero => -- In the zero fuel case, we have a contradiction: -- i < x + 0 implies i < x, which contradicts x ≤ i unfold isPerfectSquare.check simp_all exact absurd hfuel (Nat.not_lt_of_le hx) | succ fuel ih => -- For the successor case, unfold the definition unfold isPerfectSquare.check simp -- Check the first condition: x * x > n if hgt : x * x > n then -- This contradicts x ≤ i and i * i = n have x_le_i_squared : x * x ≤ i * i := Nat.mul_le_mul hx hx rw [hi] at x_le_i_squared exact absurd hgt (Nat.not_lt_of_ge x_le_i_squared) else if heq : x * x = n then -- Found a perfect square directly simp_all else -- Need to continue searching -- Check if x = i if hxi : x = i then -- If x = i, then x * x = i * i = n, contradicting heq rw [hxi] at heq exact absurd hi heq else simp_all -- x < i case: continue searching with x + 1 have x_lt_i : x < i := Nat.lt_of_le_of_ne hx hxi have x_succ_le_i : x + 1 ≤ i := Nat.succ_le_of_lt x_lt_i -- Show i < (x + 1) + fuel have i_lt_next_fuel : i < (x + 1) + fuel := by rw [Nat.add_assoc, Nat.add_comm _ fuel] exact hfuel -- Apply induction hypothesis exact ih (x + 1) x_succ_le_i i_lt_next_fuel -- !benchmark @end proof_aux theorem isPerfectSquare_spec_satisfied (n : Nat) : isPerfectSquare_postcond n (isPerfectSquare n) := by -- !benchmark @start proof unfold isPerfectSquare_postcond isPerfectSquare simp cases n with | zero => simp | succ n' => -- We'll prove both directions of the biconditional apply Iff.intro -- Forward direction: isPerfectSquare (n' + 1) = true → ∃ i, i * i = n' + 1 · intro h simp at h -- We know check 1 (n' + 1) evaluates to true have ⟨i, ⟨hi_le, hi_eq⟩⟩ := check_correct (n' + 1) 1 (n' + 1) h exists i -- Backward direction: (∃ i, i * i = n' + 1) → isPerfectSquare (n' + 1) = true · intro h simp -- We have some i where i * i = n' + 1 have ⟨i, hi⟩ := h -- We need to show check 1 (n' + 1) = true -- First, show i ≥ 1 (which is needed for check to find i) have i_pos : i > 0 := by apply Nat.pos_of_ne_zero intro h_zero rw [h_zero, zero_mul] at hi exact Nat.succ_ne_zero n' hi.symm have i_ge_1 : i ≥ 1 := Nat.succ_le_of_lt i_pos -- Show that i < 1 + (n' + 1) so check has enough fuel to reach i have i_lt_bound : i < 1 + (n' + 1) := by -- Since i*i = n' + 1, we know i ≤ n' + 1 have i_le_n_plus_1 : i ≤ n' + 1 := by apply Nat.le_of_mul_le_mul_left · rw [hi] simp exact i_ge_1 · exact i_pos apply Nat.lt_succ_of_le at i_le_n_plus_1 simp_all +arith -- Apply the completeness lemma exact check_complete (n' + 1) 1 (n' + 1) i i_ge_1 hi i_lt_bound -- !benchmark @end proof
{ "name": "isPerfectSquare", "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_803", "student_id": null } }
{ "input": [ "{\"n\": 0}", "{\"n\": 1}", "{\"n\": 4}", "{\"n\": 9}", "{\"n\": 2}", "{\"n\": 3}", "{\"n\": 10}", "{\"n\": 16}", "{\"n\": 25}", "{\"n\": 26}" ], "expected": [ [ "True" ], [ "True" ], [ "True" ], [ "True" ], [ "False" ], [ "False" ], [ "False" ], [ "True" ], [ "True" ], [ "False" ] ], "unexpected": [ [ "False" ], [ "False" ], [ "False" ], [ "False" ], [ "True" ], [ "True" ], [ "True" ], [ "False" ], [ "False" ], [ "True" ] ] }
{ "input": [] }
basic
verina_advanced_73
-----Description----- This task requires writing a Lean 4 method that finds the first missing natural number in an increasingly sorted list. The method should return the smallest natural number that is not in the list, ensuring that all natural numbers that are smaller is inside the list. -----Input----- The input consists of a list of natural numbers sorted in increasing order: l: The sorted list -----Output----- The output is a natural number: Returns the smallest natural number that is not in the list, which means all natural numbers that are smaller than the returned value should be inside 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 smallestMissing_precond (l : List Nat) : Prop := -- !benchmark @start precond List.Pairwise (· < ·) l -- !benchmark @end precond -- !benchmark @start code_aux -- !benchmark @end code_aux def smallestMissing (l : List Nat) (h_precond : smallestMissing_precond (l)) : Nat := -- !benchmark @start code let sortedList := l let rec search (lst : List Nat) (n : Nat) : Nat := match lst with | [] => n | x :: xs => let isEqual := x = n let isGreater := x > n let nextCand := n + 1 if isEqual then search xs nextCand else if isGreater then n else search xs n let result := search sortedList 0 result -- !benchmark @end code -- !benchmark @start postcond_aux -- !benchmark @end postcond_aux @[reducible] def smallestMissing_postcond (l : List Nat) (result: Nat) (h_precond : smallestMissing_precond (l)) : Prop := -- !benchmark @start postcond result ∉ l ∧ ∀ candidate : Nat, candidate < result → candidate ∈ l -- !benchmark @end postcond -- !benchmark @start proof_aux -- !benchmark @end proof_aux theorem smallestMissing_spec_satisfied (l: List Nat) (h_precond : smallestMissing_precond (l)) : smallestMissing_postcond (l) (smallestMissing (l) h_precond) h_precond := by -- !benchmark @start proof sorry -- !benchmark @end proof
{ "name": "smallestMissing", "parameters": { "param_name": [ "l" ], "param_type": [ "List Nat" ] }, "return_type": "Nat" }
{ "upstream": { "name": "lab_assignment", "link": "NA, idea from ed stem comment", "task_id": "lab_smallestMissing_325415996", "student_id": [ 51 ] } }
{ "input": [ "{\"l\": \"[0, 1, 2, 4, 5]\"}", "{\"l\": \"[]\"}", "{\"l\": \"[1, 2, 3, 4]\"}", "{\"l\": \"[0, 1, 2, 3, 4]\"}", "{\"l\": \"[2, 3, 4, 5, 6]\"}" ], "expected": [ [ "3" ], [ "0" ], [ "0" ], [ "5" ], [ "0" ] ], "unexpected": [ [ "1", "2", "0" ], [ "1", "2", "3" ], [ "1", "2", "3", "4" ], [ "0", "1", "2", "3", "4" ], [ "1", "2", "3", "4", "5", "6" ] ] }
{ "input": [ "{'l': '[1, 1]'}", "{'l': '[1, 0]'}" ] }
advanced
verina_advanced_45
-----Description----- This task requires writing a Lean 4 function that finds the maximum subarray sum from a given list of integers. A subarray is a contiguous sequence of elements within the list. The function should return the maximum sum that can be obtained from any subarray. -----Input----- The input is a list of integers: xs: A list of integers (can include negative numbers). -----Output----- The output is an integer: Returns the maximum sum among all contiguous subarrays of xs. If the list is empty, the result should be 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 (xs : List Int) : Prop := -- !benchmark @start precond True -- !benchmark @end precond -- !benchmark @start code_aux -- !benchmark @end code_aux def maxSubarraySum (xs : List Int) (h_precond : maxSubarraySum_precond (xs)) : Int := -- !benchmark @start code let rec helper (lst : List Int) (curMax : Int) (globalMax : Int) : Int := match lst with | [] => globalMax | x :: rest => let newCurMax := max x (curMax + x) let newGlobal := max globalMax newCurMax helper rest newCurMax newGlobal match xs with | [] => 0 | x :: rest => helper rest x x -- !benchmark @end code -- !benchmark @start postcond_aux -- !benchmark @end postcond_aux @[reducible, simp] def maxSubarraySum_postcond (xs : List Int) (result: Int) (h_precond : maxSubarraySum_precond (xs)) : Prop := -- !benchmark @start postcond -- Find all possible subarrays and their sums let subarray_sums := List.range (xs.length + 1) |>.flatMap (fun start => List.range' 1 (xs.length - start) |>.map (fun len => ((xs.drop start).take len).sum )) -- Check if there exists a subarray with sum equal to result let has_result_subarray := subarray_sums.any (fun sum => sum == result) -- Check if result is the maximum among all subarray sums let is_maximum := subarray_sums.all (· ≤ result) match xs with | [] => result == 0 | _ => has_result_subarray ∧ is_maximum -- !benchmark @end postcond -- !benchmark @start proof_aux -- !benchmark @end proof_aux theorem maxSubarraySum_spec_satisfied (xs: List Int) (h_precond : maxSubarraySum_precond (xs)) : maxSubarraySum_postcond (xs) (maxSubarraySum (xs) h_precond) h_precond := by -- !benchmark @start proof sorry -- !benchmark @end proof
{ "name": "maxSubarraySum", "parameters": { "param_name": [ "xs" ], "param_type": [ "List Int" ] }, "return_type": "Int" }
{ "upstream": { "name": "lab_assignment", "link": "", "task_id": "lab_maxSubarraySum_324785655", "student_id": [ 37 ] } }
{ "input": [ "{\"xs\": \"[1, -2, 3, 4, -1]\"}", "{\"xs\": \"[-2, -3, -1, -5]\"}", "{\"xs\": \"[5, -1, 2, -1, 3]\"}", "{\"xs\": \"[]\"}", "{\"xs\": \"[4, -1, -2, 1, 5]\"}" ], "expected": [ [ "7" ], [ "-1" ], [ "8" ], [ "0" ], [ "7" ] ], "unexpected": [ [ "6", "5" ], [ "-2", "0" ], [ "9" ], [ "1" ], [ "8" ] ] }
{ "input": [] }
advanced
verina_basic_74
-----Description----- This task involves identifying the maximum value in a non-empty array of integers. The objective is to determine which element in the array is greater than or equal to every other element, ensuring that the selected value is one of the elements in the array. -----Input----- The input consists of: • a: An array of integers. It is assumed that the array is non-empty (i.e., its size is at least 1). -----Output----- The output is an integer that represents the maximum element in the array. This value is guaranteed to satisfy the following: • It is greater than or equal to every element in the array. • It is exactly equal to one of the elements in the array. -----Note----- It is assumed that the provided array is non-empty. In cases where the array is empty, the function's behavior is not defined.
-- !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 maxArray_precond (a : Array Int) : Prop := -- !benchmark @start precond a.size > 0 -- !benchmark @end precond -- !benchmark @start code_aux def maxArray_aux (a : Array Int) (index : Nat) (current : Int) : Int := if index < a.size then let new_current := if current > a[index]! then current else a[index]! maxArray_aux a (index + 1) new_current else current -- !benchmark @end code_aux def maxArray (a : Array Int) (h_precond : maxArray_precond (a)) : Int := -- !benchmark @start code maxArray_aux a 1 a[0]! -- !benchmark @end code -- !benchmark @start postcond_aux -- !benchmark @end postcond_aux @[reducible, simp] def maxArray_postcond (a : Array Int) (result: Int) (h_precond : maxArray_precond (a)) := -- !benchmark @start postcond (∀ (k : Nat), k < a.size → result >= a[k]!) ∧ (∃ (k : Nat), k < a.size ∧ result = a[k]!) -- !benchmark @end postcond -- !benchmark @start proof_aux -- !benchmark @end proof_aux theorem maxArray_spec_satisfied (a: Array Int) (h_precond : maxArray_precond (a)) : maxArray_postcond (a) (maxArray (a) h_precond) h_precond := by -- !benchmark @start proof sorry -- !benchmark @end proof
{ "name": "maxArray", "parameters": { "param_name": [ "a" ], "param_type": [ "Array Int" ] }, "return_type": "Int" }
{ "upstream": { "name": "clover", "link": "https://github.com/ChuyueSun/Clover", "task_id": "Clover_max_array", "student_id": null } }
{ "input": [ "{\"a\": \"#[1, 2, 3, 4, 5]\"}", "{\"a\": \"#[5, 3, 4, 1, 2]\"}", "{\"a\": \"#[7]\"}", "{\"a\": \"#[-1, -5, -3, -4]\"}", "{\"a\": \"#[-10, -20, -30, -5, -15]\"}" ], "expected": [ [ "5" ], [ "5" ], [ "7" ], [ "-1" ], [ "-5" ] ], "unexpected": [ [ "4", "3" ], [ "4", "3", "2" ], [ "6", "8" ], [ "-3", "-4" ], [ "-10", "-15", "-20" ] ] }
{ "input": [ "{'a': '#[]'}" ] }
basic
verina_basic_82
-----Description----- This task is about processing an array of integers by producing a new array that excludes the first element. The objective is to define a clear behavior: if the array contains at least one element, return a modified array starting from the second element. -----Input----- The input consists of: • a: An array of integers. -----Output----- The output is an array of integers that: • Has a length equal to the original array's length minus one. • Contains the same elements as the input array except for the first element. • Satisfies the condition that for every index i in the output array, the element at position i is equal to the element at position i+1 in the input array. -----Note----- It is assumed that the input array is 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 remove_front_precond (a : Array Int) : Prop := -- !benchmark @start precond a.size > 0 -- !benchmark @end precond -- !benchmark @start code_aux def copyFrom (a : Array Int) (i : Nat) (acc : Array Int) : Array Int := if i < a.size then copyFrom a (i + 1) (acc.push (a[i]!)) else acc -- !benchmark @end code_aux def remove_front (a : Array Int) (h_precond : remove_front_precond (a)) : Array Int := -- !benchmark @start code if a.size > 0 then let c := copyFrom a 1 (Array.mkEmpty (a.size - 1)) c else panic "Precondition violation: array is empty" -- !benchmark @end code -- !benchmark @start postcond_aux -- !benchmark @end postcond_aux @[reducible, simp] def remove_front_postcond (a : Array Int) (result: Array Int) (h_precond : remove_front_precond (a)) := -- !benchmark @start postcond a.size > 0 ∧ result.size = a.size - 1 ∧ (∀ i : Nat, i < result.size → result[i]! = a[i + 1]!) -- !benchmark @end postcond -- !benchmark @start proof_aux -- !benchmark @end proof_aux theorem remove_front_spec_satisfied (a: Array Int) (h_precond : remove_front_precond (a)) : remove_front_postcond (a) (remove_front (a) h_precond) h_precond := by -- !benchmark @start proof sorry -- !benchmark @end proof
{ "name": "remove_front", "parameters": { "param_name": [ "a" ], "param_type": [ "Array Int" ] }, "return_type": "Array Int" }
{ "upstream": { "name": "clover", "link": "https://github.com/ChuyueSun/Clover", "task_id": "Clover_remove_front", "student_id": null } }
{ "input": [ "{\"a\": \"#[1, 2, 3, 4, 5]\"}", "{\"a\": \"#[10, 20, 30]\"}", "{\"a\": \"#[0, -1, -2, -3]\"}", "{\"a\": \"#[7]\"}", "{\"a\": \"#[100, 0, 50]\"}" ], "expected": [ [ "#[2, 3, 4, 5]" ], [ "#[20, 30]" ], [ "#[-1, -2, -3]" ], [ "#[]" ], [ "#[0, 50]" ] ], "unexpected": [ [ "#[1, 2, 3, 4, 5]", "#[3, 4, 5]", "#[2, 3, 4]" ], [ "#[10, 20, 30]", "#[10, 30]", "#[10, 20]" ], [ "#[0, -1, -2, -3]", "#[-1, -3]", "#[-2, -3]" ], [ "#[7]", "#[0]", "#[7, 7]" ], [ "#[100, 0, 50]", "#[50]", "#[0]" ] ] }
{ "input": [ "{'a': '#[]'}" ] }
basic
verina_basic_1
-----Description----- This task requires writing a Lean 4 method that determines whether two given integers have opposite signs. In other words, the method should return true if one integer is positive and the other is negative. Note that zero is considered neither positive nor negative; therefore, if either integer is zero, the method should return false. -----Input----- The input consists of two integers: a: An integer. b: An integer. -----Output----- The output is a Boolean value: Returns true if one of the integers is positive and the other is negative (i.e., they have opposite signs). Returns false if both integers are either non-negative or non-positive, or if one (or both) is zero.
-- !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 hasOppositeSign_precond (a : Int) (b : Int) : Prop := -- !benchmark @start precond True -- !benchmark @end precond -- !benchmark @start code_aux -- !benchmark @end code_aux def hasOppositeSign (a : Int) (b : Int) (h_precond : hasOppositeSign_precond (a) (b)) : Bool := -- !benchmark @start code a * b < 0 -- !benchmark @end code -- !benchmark @start postcond_aux -- !benchmark @end postcond_aux @[reducible, simp] def hasOppositeSign_postcond (a : Int) (b : Int) (result: Bool) (h_precond : hasOppositeSign_precond (a) (b)) := -- !benchmark @start postcond (((a < 0 ∧ b > 0) ∨ (a > 0 ∧ b < 0)) → result) ∧ (¬((a < 0 ∧ b > 0) ∨ (a > 0 ∧ b < 0)) → ¬result) -- !benchmark @end postcond -- !benchmark @start proof_aux -- !benchmark @end proof_aux theorem hasOppositeSign_spec_satisfied (a: Int) (b: Int) (h_precond : hasOppositeSign_precond (a) (b)) : hasOppositeSign_postcond (a) (b) (hasOppositeSign (a) (b) h_precond) h_precond := by -- !benchmark @start proof unfold hasOppositeSign hasOppositeSign_postcond constructor · intro h cases h with | inl h1 => simp have ⟨ha, hb⟩ := h1 exact Int.mul_neg_of_neg_of_pos ha hb | inr h2 => simp have ⟨ha, hb⟩ := h2 rw [Int.mul_comm] exact Int.mul_neg_of_neg_of_pos hb ha · rw [Bool.decide_iff, mul_neg_iff] simp_all -- !benchmark @end proof
{ "name": "hasOppositeSign", "parameters": { "param_name": [ "a", "b" ], "param_type": [ "Int", "Int" ] }, "return_type": "Bool" }
{ "upstream": { "name": "dafny-synthesis", "link": "https://github.com/Mondego/dafny-synthesis", "task_id": "task_id_58", "student_id": null } }
{ "input": [ "{\"a\": -5, \"b\": 10}", "{\"a\": 5, \"b\": -10}", "{\"a\": 5, \"b\": 10}", "{\"a\": -5, \"b\": -10}", "{\"a\": 0, \"b\": 10}", "{\"a\": 10, \"b\": 0}", "{\"a\": 0, \"b\": -10}", "{\"a\": -10, \"b\": 0}", "{\"a\": 0, \"b\": 0}", "{\"a\": -1, \"b\": 1}", "{\"a\": 1, \"b\": -1}" ], "expected": [ [ "True" ], [ "True" ], [ "False" ], [ "False" ], [ "False" ], [ "False" ], [ "False" ], [ "False" ], [ "False" ], [ "True" ], [ "True" ] ], "unexpected": [ [ "False" ], [ "False" ], [ "True" ], [ "True" ], [ "True" ], [ "True" ], [ "True" ], [ "True" ], [ "True" ], [ "False" ], [ "False" ] ] }
{ "input": [] }
basic
verina_advanced_14
-----Description----- This task requires writing a Lean 4 method that determines whether a natural number is a power of four. The method should return a boolean value that indicates whether the given natural number is a power of four. An integer n is a power of four, if there exists an natural number x such that n = 4^x. -----Input----- The input consists of one natural number: n: A natural number. -----Output----- The output is a boolean value: Return a boolean value that indicates whether the given natural number is a power of four. Return "true" if it is a power of four. Otherwise, return "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 ifPowerOfFour_precond (n : Nat) : Prop := -- !benchmark @start precond True -- !benchmark @end precond -- !benchmark @start code_aux -- !benchmark @end code_aux def ifPowerOfFour (n : Nat) (h_precond : ifPowerOfFour_precond (n)) : Bool := -- !benchmark @start code let rec helper (n : Nat) : Bool := match n with | 0 => false | Nat.succ m => match m with | 0 => true | Nat.succ l => if (l+2)%4=0 then helper ((l+2)/4) else false helper n -- !benchmark @end code -- !benchmark @start postcond_aux -- !benchmark @end postcond_aux @[reducible] def ifPowerOfFour_postcond (n : Nat) (result: Bool) (h_precond : ifPowerOfFour_precond (n)) : Prop := -- !benchmark @start postcond result ↔ (∃ m:Nat, n=4^m) -- !benchmark @end postcond -- !benchmark @start proof_aux -- !benchmark @end proof_aux theorem ifPowerOfFour_spec_satisfied (n: Nat) (h_precond : ifPowerOfFour_precond (n)) : ifPowerOfFour_postcond (n) (ifPowerOfFour (n) h_precond) h_precond := by -- !benchmark @start proof sorry -- !benchmark @end proof
{ "name": "ifPowerOfFour", "parameters": { "param_name": [ "n" ], "param_type": [ "Nat" ] }, "return_type": "Bool" }
{ "upstream": { "name": "lab_assignment", "link": "https://leetcode.com/problems/power-of-four/", "task_id": "lab_ifPowerOfFour_325708699", "student_id": [ 12 ] } }
{ "input": [ "{\"n\": 0}", "{\"n\": 1}", "{\"n\": 2}", "{\"n\": 3}", "{\"n\": 4}", "{\"n\": 8}", "{\"n\": 16}", "{\"n\": 64}", "{\"n\": 95}", "{\"n\": 100}", "{\"n\": 256}", "{\"n\": 520}", "{\"n\": 1024}" ], "expected": [ [ "False" ], [ "True" ], [ "False" ], [ "False" ], [ "True" ], [ "False" ], [ "True" ], [ "True" ], [ "False" ], [ "False" ], [ "True" ], [ "False" ], [ "True" ] ], "unexpected": [ [ "True" ], [ "False" ], [ "True" ], [ "True" ], [ "False" ], [ "True" ], [ "False" ], [ "False" ], [ "True" ], [ "True" ], [ "False" ], [ "True" ], [ "False" ] ] }
{ "input": [] }
advanced
verina_advanced_4
-----Description----- This task requires writing a Lean 4 method that finds the length of the longest increasing sequence in a given array. The method should return the length of the longest increasing subsequence, in which every element is strictly less than the latter element. -----Input----- The input consists of an arrat: a: The input array. -----Output----- The output is an integer: Returns the length of the longest increasing subsequence, assuring that it is a subsequence of the input sequence and that every element in it is strictly less than the latter one.
-- !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 LongestIncreasingSubsequence_precond (a : 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 LongestIncreasingSubsequence (a : Array Int) (h_precond : LongestIncreasingSubsequence_precond (a)) : Int := -- !benchmark @start code let n := a.size let dp := Id.run do let mut dp := Array.mkArray n 1 for i in [1:n] do for j in [0:i] do if a[j]! < a[i]! then let newVal := intMax (dp[i]!) (dp[j]! + 1) dp := dp.set! i newVal return dp match dp with | #[] => 0 | _ => dp.foldl intMax 0 -- !benchmark @end code -- !benchmark @start postcond_aux -- !benchmark @end postcond_aux @[reducible, simp] def LongestIncreasingSubsequence_postcond (a : Array Int) (result: Int) (h_precond : LongestIncreasingSubsequence_precond (a)) : Prop := -- !benchmark @start postcond let allSubseq := (a.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 (a: Array Int) (h_precond : LongestIncreasingSubsequence_precond (a)) : LongestIncreasingSubsequence_postcond (a) (LongestIncreasingSubsequence (a) h_precond) h_precond := by -- !benchmark @start proof sorry -- !benchmark @end proof
{ "name": "LongestIncreasingSubsequence", "parameters": { "param_name": [ "a" ], "param_type": [ "Array Int" ] }, "return_type": "Int" }
{ "upstream": { "name": "lab_assignment", "link": "", "task_id": "lab_LongestIncreasingSubsequence_324999618", "student_id": [ 2 ] } }
{ "input": [ "{\"a\": \"#[5, 2, 8, 6, 3, 6, 9, 7]\"}", "{\"a\": \"#[3, 1, 2, 1, 0]\"}", "{\"a\": \"#[2, 3, -2, -1, 7, 19, 3, 6, -4, 6, -7, 0, 9, 12, 10]\"}", "{\"a\": \"#[5, -5, -3, 2, 4, 1, 0, -1, 3, 2, 0]\"}", "{\"a\": \"#[1, 7, 23, 14, -4, 21, 8, 2, -1, 9, 12, 2]\"}", "{\"a\": \"#[]\"}" ], "expected": [ [ "4" ], [ "2" ], [ "6" ], [ "4" ], [ "5" ], [ "0" ] ], "unexpected": [ [ "2", "3" ], [ "1", "3" ], [ "5", "3", "10" ], [ "2", "5" ], [ "2", "4" ], [ "1", "2" ] ] }
{ "input": [] }
advanced
verina_advanced_22
-----Description----- This task requires writing a Lean 4 method that determines whether a list of integers follows a peak-valley pattern. A list follows this pattern if: A. It strictly increases at first, B. Then strictly decreases, C. Both parts are non-empty. Examples: - [1, 3, 5, 4, 2] -> true - [1, 2, 3] -> false - [5, 4, 3] -> false - [1, 2, 2, 1] -> false -----Input----- The input consists of a list of integers: -----Output----- The output is an integer: Returns true if the list has a peak-valley structure, false otherwise.
-- !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 isPeakValley_precond (lst : List Int) : Prop := -- !benchmark @start precond True -- !benchmark @end precond -- !benchmark @start code_aux -- !benchmark @end code_aux def isPeakValley (lst : List Int) (h_precond : isPeakValley_precond (lst)) : Bool := -- !benchmark @start code let rec aux (l : List Int) (increasing : Bool) (startedDecreasing : Bool) : Bool := match l with | x :: y :: rest => if x < y then if startedDecreasing then false else aux (y :: rest) true startedDecreasing else if x > y then if increasing then aux (y :: rest) increasing true else false else false | _ => increasing && startedDecreasing aux lst false false -- !benchmark @end code -- !benchmark @start postcond_aux -- !benchmark @end postcond_aux @[reducible, simp] def isPeakValley_postcond (lst : List Int) (result: Bool) (h_precond : isPeakValley_precond (lst)) : Prop := -- !benchmark @start postcond let len := lst.length let validPeaks := List.range len |>.filter (fun p => 1 ≤ p ∧ p < len - 1 ∧ -- check strictly increasing before peak (List.range p).all (fun i => lst[i]! < lst[i + 1]! ) ∧ -- check strictly decreasing after peak (List.range (len - 1 - p)).all (fun i => lst[p + i]! > lst[p + i + 1]! ) ) (validPeaks != [] → result) ∧ (validPeaks.length = 0 → ¬ result) -- !benchmark @end postcond -- !benchmark @start proof_aux -- !benchmark @end proof_aux theorem isPeakValley_spec_satisfied (lst: List Int) (h_precond : isPeakValley_precond (lst)) : isPeakValley_postcond (lst) (isPeakValley (lst) h_precond) h_precond := by -- !benchmark @start proof sorry -- !benchmark @end proof
{ "name": "isPeakValley", "parameters": { "param_name": [ "lst" ], "param_type": [ "List Int" ] }, "return_type": "Bool" }
{ "upstream": { "name": "lab_assignment", "link": "", "task_id": "lab_isPeakValley_325583306", "student_id": [ 4 ] } }
{ "input": [ "{\"lst\": \"[1, 3, 5, 2, 1]\"}", "{\"lst\": \"[1, 2, 3, 4, 5]\"}", "{\"lst\": \"[]\"}", "{\"lst\": \"[1]\"}", "{\"lst\": \"[1, 1, 1, 1, 1]\"}", "{\"lst\": \"[1, 10, 100, 1]\"}" ], "expected": [ [ "True" ], [ "False" ], [ "False" ], [ "False" ], [ "False" ], [ "True" ] ], "unexpected": [ [ "False" ], [ "True" ], [ "True" ], [ "True" ], [ "True" ], [ "False" ] ] }
{ "input": [] }
advanced
verina_basic_19
-----Description----- This task requires writing a Lean 4 method that checks whether an array of integers is sorted in non-decreasing order. The method should return true if every element is less than or equal to the element that follows it, and false otherwise. -----Input----- The input consists of: a: An array of integers. The array can be empty or have any length. -----Output----- The output is a Boolean value: Returns true if the array is sorted in non-decreasing order. Returns false if the array is not sorted in non-decreasing order. -----Note----- A true result guarantees that for every valid pair of indices i and j (with i < j), the element at position i is less than or equal to the element at position j. A false result indicates that there exists at least one adjacent pair of elements where the first element is greater than the second.
-- !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 isSorted_precond (a : Array Int) : Prop := -- !benchmark @start precond True -- !benchmark @end precond -- !benchmark @start code_aux -- !benchmark @end code_aux def isSorted (a : Array Int) (h_precond : isSorted_precond (a)) : Bool := -- !benchmark @start code if a.size ≤ 1 then true else a.mapIdx (fun i x => if h : i + 1 < a.size then decide (x ≤ a[i + 1]) else true) |>.all id -- !benchmark @end code -- !benchmark @start postcond_aux -- !benchmark @end postcond_aux @[reducible, simp] def isSorted_postcond (a : Array Int) (result: Bool) (h_precond : isSorted_precond (a)) := -- !benchmark @start postcond (∀ i, (hi : i < a.size - 1) → a[i] ≤ a[i + 1]) ↔ result -- !benchmark @end postcond -- !benchmark @start proof_aux -- !benchmark @end proof_aux theorem isSorted_spec_satisfied (a: Array Int) (h_precond : isSorted_precond (a)) : isSorted_postcond (a) (isSorted (a) h_precond) h_precond := by -- !benchmark @start proof unfold isSorted isSorted_postcond simp_all cases a with | mk a => simp cases a with | nil => simp | cons x xs => simp cases xs with | nil => simp | cons x' xs => simp constructor <;> simp_all -- !benchmark @end proof
{ "name": "isSorted", "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_567", "student_id": null } }
{ "input": [ "{\"a\": \"#[1, 2, 3, 4, 5]\"}", "{\"a\": \"#[5, 4, 3, 2, 1]\"}", "{\"a\": \"#[1, 3, 2, 4, 5]\"}", "{\"a\": \"#[]\"}", "{\"a\": \"#[10]\"}", "{\"a\": \"#[2, 2, 2, 2]\"}", "{\"a\": \"#[1, 2, 2, 3]\"}" ], "expected": [ [ "True" ], [ "False" ], [ "False" ], [ "True" ], [ "True" ], [ "True" ], [ "True" ] ], "unexpected": [ [ "False" ], [ "True" ], [ "True" ], [ "False" ], [ "False" ], [ "False" ], [ "False" ] ] }
{ "input": [] }
basic
verina_basic_76
-----Description----- This task requires determining the smaller of two integers. Given two input numbers, the goal is to compare them and return the one that is less than or equal to the other. -----Input----- The input consists of two integers: • x: The first integer. • y: The second integer. -----Output----- The output is an integer representing the minimum of the two input integers: • Returns x if x is less than or equal to y. • Returns y if x is greater than y.
-- !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 myMin_precond (x : Int) (y : Int) : Prop := -- !benchmark @start precond True -- !benchmark @end precond -- !benchmark @start code_aux -- !benchmark @end code_aux def myMin (x : Int) (y : Int) (h_precond : myMin_precond (x) (y)) : Int := -- !benchmark @start code if x < y then x else y -- !benchmark @end code -- !benchmark @start postcond_aux -- !benchmark @end postcond_aux @[reducible, simp] def myMin_postcond (x : Int) (y : Int) (result: Int) (h_precond : myMin_precond (x) (y)) := -- !benchmark @start postcond (x ≤ y → result = x) ∧ (x > y → result = y) -- !benchmark @end postcond -- !benchmark @start proof_aux -- !benchmark @end proof_aux theorem myMin_spec_satisfied (x: Int) (y: Int) (h_precond : myMin_precond (x) (y)) : myMin_postcond (x) (y) (myMin (x) (y) h_precond) h_precond := by -- !benchmark @start proof unfold myMin_postcond myMin simp have h_left : (x ≤ y → y ≤ x → y = x) := by intro h₁ h₂ exact Int.le_antisymm h₂ h₁ have h_right : (y < x → x < y → x = y) := by intro h₁ h₂ have h_contr : False := Int.lt_irrefl x (Int.lt_trans h₂ h₁) contradiction exact ⟨h_left, h_right⟩ -- !benchmark @end proof
{ "name": "myMin", "parameters": { "param_name": [ "x", "y" ], "param_type": [ "Int", "Int" ] }, "return_type": "Int" }
{ "upstream": { "name": "clover", "link": "https://github.com/ChuyueSun/Clover", "task_id": "Clover_min_of_two", "student_id": null } }
{ "input": [ "{\"x\": 3, \"y\": 5}", "{\"x\": 10, \"y\": 7}", "{\"x\": 4, \"y\": 4}", "{\"x\": -5, \"y\": 0}", "{\"x\": 0, \"y\": -10}" ], "expected": [ [ "3" ], [ "7" ], [ "4" ], [ "-5" ], [ "-10" ] ], "unexpected": [ [ "5", "8" ], [ "10", "17" ], [ "0", "8" ], [ "0", "-4" ], [ "0", "-8" ] ] }
{ "input": [] }
basic
verina_advanced_39
-----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, simp] def maxOfList_precond (lst : List Nat) : Prop := -- !benchmark @start precond lst.length > 0 -- !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, simp] 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": "", "task_id": "lab_maxOfList_325053133", "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_63
-----Description----- The task is to determine whether there exists at least one pair of different floating-point numbers in a list such that the absolute difference between them is less than a given threshold. The focus is solely on deciding if such a pair is present in the list. -----Input----- The input consists of: • numbers: A list of floating-point numbers. • threshold: A floating-point number representing the maximum allowed difference between two numbers for them to be considered "close." -----Output----- The output is a boolean value: • true – if there exists at least one pair of distinct elements in the list such that the absolute difference between them is less than the threshold. • false – if for every possible pair of elements, the absolute difference is greater than or equal to the threshold. -----Note----- It is assumed that the list of numbers is provided and that the threshold is non-negative.
-- !benchmark @start import type=solution -- !benchmark @end import -- !benchmark @start solution_aux def absDiff (a b : Float) : Float := if a - b < 0.0 then b - a else a - b -- !benchmark @end solution_aux -- !benchmark @start precond_aux -- !benchmark @end precond_aux @[reducible, simp] def has_close_elements_precond (numbers : List Float) (threshold : Float) : Prop := -- !benchmark @start precond threshold ≥ 0.0 -- !benchmark @end precond -- !benchmark @start code_aux -- !benchmark @end code_aux def has_close_elements (numbers : List Float) (threshold : Float) (h_precond : has_close_elements_precond (numbers) (threshold)) : Bool := -- !benchmark @start code let len := numbers.length let rec outer (idx : Nat) : Bool := if idx < len then let rec inner (idx2 : Nat) : Bool := if idx2 < idx then let a := numbers.getD idx2 0.0 let b := numbers.getD idx 0.0 let d := absDiff a b if d < threshold then true else inner (idx2 + 1) else false if inner 0 then true else outer (idx + 1) else false outer 0 -- !benchmark @end code -- !benchmark @start postcond_aux -- !benchmark @end postcond_aux @[reducible, simp] def has_close_elements_postcond (numbers : List Float) (threshold : Float) (result: Bool) (h_precond : has_close_elements_precond (numbers) (threshold)) := -- !benchmark @start postcond ¬ result ↔ (List.Pairwise (fun a b => absDiff a b ≥ threshold) numbers) -- !benchmark @end postcond -- !benchmark @start proof_aux -- !benchmark @end proof_aux theorem has_close_elements_spec_satisfied (numbers: List Float) (threshold: Float) (h_precond : has_close_elements_precond (numbers) (threshold)) : has_close_elements_postcond (numbers) (threshold) (has_close_elements (numbers) (threshold) h_precond) h_precond := by -- !benchmark @start proof sorry -- !benchmark @end proof
{ "name": "has_close_elements", "parameters": { "param_name": [ "numbers", "threshold" ], "param_type": [ "List Float", "Float" ] }, "return_type": "Bool" }
{ "upstream": { "name": "clover", "link": "https://github.com/ChuyueSun/Clover", "task_id": "Clover_has_close_elements", "student_id": null } }
{ "input": [ "{\"numbers\": \"[1.0, 2.0, 3.0]\", \"threshold\": 1.5}", "{\"numbers\": \"[10.0, 12.0, 15.0]\", \"threshold\": 1.5}", "{\"numbers\": \"[5.0, 5.0]\", \"threshold\": 0.1}", "{\"numbers\": \"[]\", \"threshold\": 2.0}", "{\"numbers\": \"[0.0, 0.5, 1.1, 2.2]\", \"threshold\": 0.6}" ], "expected": [ [ "True" ], [ "False" ], [ "True" ], [ "False" ], [ "True" ] ], "unexpected": [ [], [], [], [], [] ] }
{ "input": [ "{'numbers': '[1.0, 2.0, 3.0]', 'threshold': -1.0}" ] }
basic
verina_advanced_19
-----Description----- This task requires writing a Lean 4 method that checks whether a given string is a palindrome. A palindrome is a string that reads the same forwards and backwards. The function should ignore whitespace, punctuation, and capitalization when checking for palindromes. -----Input----- The input consists of: s: A string to be checked. -----Output----- The output is a boolean: Returns true if the input string is a palindrome when non-alphabetic characters are removed and letters are treated case-insensitively, and false otherwise.
-- !benchmark @start import type=solution -- !benchmark @end import -- !benchmark @start solution_aux -- Check if a character is an uppercase alphabet letter def isUpperAlpha (c : Char) : Bool := 'A' ≤ c ∧ c ≤ 'Z' -- Check if a character is a lowercase alphabet letter def isLowerAlpha (c : Char) : Bool := 'a' ≤ c ∧ c ≤ 'z' -- Determine if a character is alphabetic def isAlpha (c : Char) : Bool := isUpperAlpha c ∨ isLowerAlpha c -- Convert a single character to lowercase def toLower (c : Char) : Char := if isUpperAlpha c then Char.ofNat (c.toNat + 32) else c -- Normalize a character: keep only lowercase letters def normalizeChar (c : Char) : Option Char := if isAlpha c then some (toLower c) else none -- Normalize a string into a list of lowercase alphabetic characters def normalizeString (s : String) : List Char := s.toList.foldr (fun c acc => match normalizeChar c with | some c' => c' :: acc | none => acc ) [] -- !benchmark @end solution_aux -- !benchmark @start precond_aux -- !benchmark @end precond_aux @[reducible] def isCleanPalindrome_precond (s : String) : Prop := -- !benchmark @start precond True -- !benchmark @end precond -- !benchmark @start code_aux -- Reverse the list def reverseList (xs : List Char) : List Char := xs.reverse -- !benchmark @end code_aux def isCleanPalindrome (s : String) (h_precond : isCleanPalindrome_precond (s)) : Bool := -- !benchmark @start code let norm := normalizeString s norm = reverseList norm -- !benchmark @end code -- !benchmark @start postcond_aux -- !benchmark @end postcond_aux @[reducible] def isCleanPalindrome_postcond (s : String) (result: Bool) (h_precond : isCleanPalindrome_precond (s)) : Prop := -- !benchmark @start postcond let norm := normalizeString s (result = true → norm = norm.reverse) ∧ (result = false → norm ≠ norm.reverse) -- !benchmark @end postcond -- !benchmark @start proof_aux -- !benchmark @end proof_aux theorem isCleanPalindrome_spec_satisfied (s: String) (h_precond : isCleanPalindrome_precond (s)) : isCleanPalindrome_postcond (s) (isCleanPalindrome (s) h_precond) h_precond := by -- !benchmark @start proof sorry -- !benchmark @end proof
{ "name": "isCleanPalindrome", "parameters": { "param_name": [ "s" ], "param_type": [ "String" ] }, "return_type": "Bool" }
{ "upstream": { "name": "lab_assignment", "link": "https://leetcode.com/problems/valid-palindrome/", "task_id": "lab_isCleanPalindrome_325752578", "student_id": [ 15 ] } }
{ "input": [ "{\"s\": \"A man, a plan, a canal, Panama\"}", "{\"s\": \"No lemon, no melon\"}", "{\"s\": \"OpenAI\"}", "{\"s\": \"Was it a car or a cat I saw?\"}", "{\"s\": \"Hello, World!\"}" ], "expected": [ [ "True" ], [ "True" ], [ "False" ], [ "True" ], [ "False" ] ], "unexpected": [ [ "False" ], [ "False" ], [ "True" ], [ "False" ], [ "True" ] ] }
{ "input": [] }
advanced
verina_basic_89
-----Description----- This problem asks you to design a solution that transforms a list with possible duplicate entries into a new list where each element appears only once, maintaining the order of its first occurrence. -----Input----- The input consists of: • s: A list of integers (or any type supporting decidable equality) that may contain duplicate elements. -----Output----- The output is a list of integers (or the original type) in which every duplicate element is removed. The order of elements is preserved based on their first appearance in the input list, ensuring that the set of elements in the output is identical to the set in the input. -----Note----- No additional preconditions are required. The method should correctly handle any list, including an empty 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, simp] def SetToSeq_precond (s : List Int) : Prop := -- !benchmark @start precond True -- !benchmark @end precond -- !benchmark @start code_aux -- !benchmark @end code_aux def SetToSeq (s : List Int) (h_precond : SetToSeq_precond (s)) : List Int := -- !benchmark @start code s.foldl (fun acc x => if acc.contains x then acc else acc ++ [x]) [] -- !benchmark @end code -- !benchmark @start postcond_aux -- !benchmark @end postcond_aux @[reducible, simp] def SetToSeq_postcond (s : List Int) (result: List Int) (h_precond : SetToSeq_precond (s)) := -- !benchmark @start postcond -- Contains exactly the elements of the set result.all (fun a => a ∈ s) ∧ s.all (fun a => a ∈ result) ∧ -- All elements are unique in the result result.all (fun a => result.count a = 1) ∧ -- The order of elements in the result is preserved List.Pairwise (fun a b => (result.idxOf a < result.idxOf b) → (s.idxOf a < s.idxOf b)) result -- !benchmark @end postcond -- !benchmark @start proof_aux -- !benchmark @end proof_aux theorem SetToSeq_spec_satisfied (s: List Int) (h_precond : SetToSeq_precond (s)) : SetToSeq_postcond (s) (SetToSeq (s) h_precond) h_precond := by -- !benchmark @start proof sorry -- !benchmark @end proof
{ "name": "SetToSeq", "parameters": { "param_name": [ "s" ], "param_type": [ "List Int" ] }, "return_type": "List Int" }
{ "upstream": { "name": "clover", "link": "https://github.com/ChuyueSun/Clover", "task_id": "Clover_set_to_seq", "student_id": null } }
{ "input": [ "{\"s\": \"[1, 2, 2, 3, 1]\"}", "{\"s\": \"[5, 5, 5, 5]\"}", "{\"s\": \"[]\"}", "{\"s\": \"[11, 22, 33]\"}", "{\"s\": \"[3, 1, 4, 1, 5, 9, 2, 6, 5]\"}" ], "expected": [ [ "[1, 2, 3]" ], [ "[5]" ], [ "[]" ], [ "[11, 22, 33]" ], [ "[3, 1, 4, 5, 9, 2, 6]" ] ], "unexpected": [ [ "[1, 3, 2]", "[1, 2, 2, 3]", "[2, 1, 3]" ], [ "[5, 5]", "[]", "[6]" ], [ "[1]", "[2]", "[0]" ], [ "[33, 22, 11]", "[11, 11, 22, 33]", "[11, 33]" ], [ "[3, 1, 4, 1, 5, 9, 2, 6, 5]", "[1, 3, 4, 5, 9, 2, 6]", "[3, 1, 4, 5, 9, 6]" ] ] }
{ "input": [] }
basic
verina_basic_40
-----Description----- This task requires writing a Lean 4 method that finds the second-smallest number in an array of integers. The method should determine and return the number that is larger than the smallest element in the array. It is crucial that the input array remains unchanged after the computation. -----Input----- The input consists of: s: An array of integers containing at least two elements. -----Output----- The output is an integer: Returns the second-smallest number in the input array. -----Note----- - The input array is guaranteed to contain at least two elements and is non-null. - It is assumed that there exist at least two distinct values in the array to ensure a unique second-smallest element. - The original array must remain unmodified.
-- !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 secondSmallest_precond (s : Array Int) : Prop := -- !benchmark @start precond s.size > 1 -- !benchmark @end precond -- !benchmark @start code_aux def minListHelper : List Int → Int | [] => panic! "minListHelper: empty list" | [_] => panic! "minListHelper: singleton list" | a :: b :: [] => if a ≤ b then a else b | a :: b :: c :: xs => let m := minListHelper (b :: c :: xs) if a ≤ m then a else m def minList (l : List Int) : Int := minListHelper l def secondSmallestAux (s : Array Int) (i minIdx secondIdx : Nat) : Int := if i ≥ s.size then s[secondIdx]! else let x := s[i]! let m := s[minIdx]! let smin := s[secondIdx]! if x < m then secondSmallestAux s (i + 1) i minIdx else if x < smin then secondSmallestAux s (i + 1) minIdx i else secondSmallestAux s (i + 1) minIdx secondIdx termination_by s.size - i -- !benchmark @end code_aux def secondSmallest (s : Array Int) (h_precond : secondSmallest_precond (s)) : Int := -- !benchmark @start code let (minIdx, secondIdx) := if s[1]! < s[0]! then (1, 0) else (0, 1) secondSmallestAux s 2 minIdx secondIdx -- !benchmark @end code -- !benchmark @start postcond_aux -- !benchmark @end postcond_aux @[reducible, simp] def secondSmallest_postcond (s : Array Int) (result: Int) (h_precond : secondSmallest_precond (s)) := -- !benchmark @start postcond (∃ i, i < s.size ∧ s[i]! = result) ∧ (∃ j, j < s.size ∧ s[j]! < result ∧ ∀ k, k < s.size → s[k]! ≠ s[j]! → s[k]! ≥ result) -- !benchmark @end postcond -- !benchmark @start proof_aux -- !benchmark @end proof_aux theorem secondSmallest_spec_satisfied (s: Array Int) (h_precond : secondSmallest_precond (s)) : secondSmallest_postcond (s) (secondSmallest (s) h_precond) h_precond := by -- !benchmark @start proof sorry -- !benchmark @end proof
{ "name": "secondSmallest", "parameters": { "param_name": [ "s" ], "param_type": [ "Array Int" ] }, "return_type": "Int" }
{ "upstream": { "name": "dafny-synthesis", "link": "https://github.com/Mondego/dafny-synthesis", "task_id": "task_id_755", "student_id": null } }
{ "input": [ "{\"s\": \"#[5, 3, 1, 4, 2]\"}", "{\"s\": \"#[7, 2, 5, 3]\"}", "{\"s\": \"#[10, 20]\"}", "{\"s\": \"#[20, 10]\"}", "{\"s\": \"#[3, 1, 2]\"}" ], "expected": [ [ "2" ], [ "3" ], [ "20" ], [ "20" ], [ "2" ] ], "unexpected": [ [ "1", "3", "4" ], [ "2", "5", "7" ], [ "10", "30", "25" ], [ "10", "30", "15" ], [ "1", "3", "4" ] ] }
{ "input": [ "{'s': '#[1]'}" ] }
basic
verina_basic_97
-----Description----- This task involves updating an array of integers such that the element at a specified index is set to 60 while all other elements remain unchanged. -----Input----- The input consists of: • a: An array of integers. • j: A natural number representing the index (0-indexed) to update. It is assumed that j is a valid index (j < a.size). -----Output----- The output is an array of integers where: • The element at index j is set to 60. • All other elements remain the same as in the input array. -----Note----- It is assumed that j is a valid index (0 ≤ j < a.size).
-- !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 TestArrayElements_precond (a : Array Int) (j : Nat) : Prop := -- !benchmark @start precond j < a.size -- !benchmark @end precond -- !benchmark @start code_aux -- !benchmark @end code_aux def TestArrayElements (a : Array Int) (j : Nat) (h_precond : TestArrayElements_precond (a) (j)) : Array Int := -- !benchmark @start code a.set! j 60 -- !benchmark @end code -- !benchmark @start postcond_aux -- !benchmark @end postcond_aux @[reducible, simp] def TestArrayElements_postcond (a : Array Int) (j : Nat) (result: Array Int) (h_precond : TestArrayElements_precond (a) (j)) := -- !benchmark @start postcond (result[j]! = 60) ∧ (∀ k, k < a.size → k ≠ j → result[k]! = a[k]!) -- !benchmark @end postcond -- !benchmark @start proof_aux -- !benchmark @end proof_aux theorem TestArrayElements_spec_satisfied (a: Array Int) (j: Nat) (h_precond : TestArrayElements_precond (a) (j)) : TestArrayElements_postcond (a) (j) (TestArrayElements (a) (j) h_precond) h_precond := by -- !benchmark @start proof unfold TestArrayElements_postcond TestArrayElements unfold TestArrayElements_precond at h_precond apply And.intro . rw [Array.getElem!_eq_getD, Array.getD] simp exact h_precond . intro k intro hk hxk simp [Array.getElem!_eq_getD, Array.getD] split . rw [Array.getElem_setIfInBounds] split . rename_i h h₁ rw [eq_comm] at h₁ contradiction . rfl . rw [Array.getElem_setIfInBounds] split . rename_i h h₁ rw [eq_comm] at h₁ contradiction . rfl -- !benchmark @end proof
{ "name": "TestArrayElements", "parameters": { "param_name": [ "a", "j" ], "param_type": [ "Array Int", "Nat" ] }, "return_type": "Array Int" }
{ "upstream": { "name": "clover", "link": "https://github.com/ChuyueSun/Clover", "task_id": "Clover_test_array", "student_id": null } }
{ "input": [ "{\"a\": \"#[1, 2, 3, 4, 5]\", \"j\": 2}", "{\"a\": \"#[60, 30, 20]\", \"j\": 1}", "{\"a\": \"#[10, 20, 30]\", \"j\": 0}", "{\"a\": \"#[5, 10, 15]\", \"j\": 2}", "{\"a\": \"#[0]\", \"j\": 0}" ], "expected": [ [ "#[1, 2, 60, 4, 5]" ], [ "#[60, 60, 20]" ], [ "#[60, 20, 30]" ], [ "#[5, 10, 60]" ], [ "#[60]" ] ], "unexpected": [ [ "#[1, 2, 3, 4, 5]", "#[1, 60, 3, 4, 5]" ], [ "#[60, 30, 20]", "#[60, 30, 60]" ], [ "#[10, 20, 30]", "#[10, 60, 30]" ], [ "#[5, 10, 15]", "#[5, 60, 15]" ], [ "#[0]", "#[70]" ] ] }
{ "input": [ "{'a': '#[1, 2, 3, 4]', 'j': 5}" ] }
basic
verina_basic_78
-----Description----- Given two integers, the task is to compute two output values: one being the sum of the integers and the other being their difference. -----Input----- The input consists of two integers: • x: An integer. • y: An integer. -----Output----- The output is a tuple of two integers: • The first element is x + y. • The second element is x - y. -----Note----- It is assumed that x and y are valid integers. There are no additional constraints on the inputs.
-- !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 MultipleReturns_precond (x : Int) (y : Int) : Prop := -- !benchmark @start precond True -- !benchmark @end precond -- !benchmark @start code_aux -- !benchmark @end code_aux def MultipleReturns (x : Int) (y : Int) (h_precond : MultipleReturns_precond (x) (y)) : (Int × Int) := -- !benchmark @start code let more := x + y let less := x - y (more, less) -- !benchmark @end code -- !benchmark @start postcond_aux -- !benchmark @end postcond_aux @[reducible, simp] def MultipleReturns_postcond (x : Int) (y : Int) (result: (Int × Int)) (h_precond : MultipleReturns_precond (x) (y)) := -- !benchmark @start postcond result.1 = x + y ∧ result.2 + y = x -- !benchmark @end postcond -- !benchmark @start proof_aux -- !benchmark @end proof_aux theorem MultipleReturns_spec_satisfied (x: Int) (y: Int) (h_precond : MultipleReturns_precond (x) (y)) : MultipleReturns_postcond (x) (y) (MultipleReturns (x) (y) h_precond) h_precond := by -- !benchmark @start proof unfold MultipleReturns_postcond MultipleReturns simp -- !benchmark @end proof
{ "name": "MultipleReturns", "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_multi_return", "student_id": null } }
{ "input": [ "{\"x\": 3, \"y\": 2}", "{\"x\": -2, \"y\": 3}", "{\"x\": 0, \"y\": 0}", "{\"x\": 10, \"y\": 5}", "{\"x\": -5, \"y\": -10}" ], "expected": [ [ "(5, 1)" ], [ "(1, -5)" ], [ "(0, 0)" ], [ "(15, 5)" ], [ "(-15, 5)" ] ], "unexpected": [ [ "(6, 2)", "(5, 2)", "(4, 1)" ], [ "(-1, 5)", "(2, -3)", "(1, 5)" ], [ "(1, 0)", "(0, 1)", "(-1, 0)" ], [ "(14, 5)", "(15, 6)", "(10, 5)" ], [ "(-15, -5)", "(-5, 15)", "(-10, 0)" ] ] }
{ "input": [] }
basic
verina_advanced_65
-----Description----- This task requires writing a Lean 4 method that reverses a given string. The method should return a new string which consists of the characters of the input string in reverse order. -----Input----- The input consists of: s: A string (which may be empty). -----Output----- The output is a string: Returns a string where the characters are in reverse order from the original 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] def reverseString_precond (s : String) : Prop := -- !benchmark @start precond True -- !benchmark @end precond -- !benchmark @start code_aux -- !benchmark @end code_aux def reverseString (s : String) (h_precond : reverseString_precond (s)) : String := -- !benchmark @start code let rec reverseAux (chars : List Char) (acc : List Char) : List Char := match chars with | [] => acc | h::t => reverseAux t (h::acc) String.mk (reverseAux (s.toList) []) -- !benchmark @end code -- !benchmark @start postcond_aux -- !benchmark @end postcond_aux @[reducible] def reverseString_postcond (s : String) (result: String) (h_precond : reverseString_precond (s)) : Prop := -- !benchmark @start postcond result.length = s.length ∧ result.toList = s.toList.reverse -- !benchmark @end postcond -- !benchmark @start proof_aux -- !benchmark @end proof_aux theorem reverseString_spec_satisfied (s: String) (h_precond : reverseString_precond (s)) : reverseString_postcond (s) (reverseString (s) h_precond) h_precond := by -- !benchmark @start proof sorry -- !benchmark @end proof
{ "name": "reverseString", "parameters": { "param_name": [ "s" ], "param_type": [ "String" ] }, "return_type": "String" }
{ "upstream": { "name": "lab_assignment", "link": "https://leetcode.com/problems/reverse-string/", "task_id": "lab_reverseString_325766147", "student_id": [ 33 ] } }
{ "input": [ "{\"s\": \"hello\"}", "{\"s\": \"a\"}", "{\"s\": \"\"}", "{\"s\": \"racecar\"}", "{\"s\": \"Lean\"}" ], "expected": [ [ "olleh" ], [ "a" ], [ "" ], [ "racecar" ], [ "naeL" ] ], "unexpected": [ [ "hello", "helo", "hell" ], [ "", "aa" ], [ " ", "a" ], [ "rceacar", "raeccar" ], [ "Lean", "aenL" ] ] }
{ "input": [] }
advanced
verina_advanced_67
-----Description----- This task requires writing a Lean 4 method that performs run-length encoding on a given string. The method should scan the string from left to right and group consecutive identical characters into pairs. Each pair consists of the character itself and the number of times it appears consecutively. For example, "aaabbc" becomes [(’a’, 3), (’b’, 2), (’c’, 1)]. The resulting encoded list must satisfy the following properties: 1. No pair has a zero or negative run-length. 2. Consecutive pairs in the encoding list must not have the same character. 3. Decoding the output should return the original string. -----Input----- The input is a single string, `s`. -----Output----- The output is a list of pairs `(Char, Nat)`, which represents the run-length-encoded form of the input string.
-- !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 runLengthEncode_precond (s : String) : Prop := -- !benchmark @start precond True -- !benchmark @end precond -- !benchmark @start code_aux -- !benchmark @end code_aux def runLengthEncode (s : String) (h_precond : runLengthEncode_precond (s)) : List (Char × Nat) := -- !benchmark @start code let chars := s.data let rec encodeAux (acc : List (Char × Nat)) (rest : List Char) : List (Char × Nat) := match rest with | [] => acc.reverse | h :: t => match acc with | (ch, count) :: accTail => if ch = h then encodeAux ((ch, count + 1) :: accTail) t else encodeAux ((h, 1) :: (ch, count) :: accTail) t | [] => encodeAux ([(h, 1)]) t let encoded := encodeAux [] chars encoded -- !benchmark @end code -- !benchmark @start postcond_aux def decodeRLE (lst : List (Char × Nat)) : String := match lst with | [] => "" | (ch, cnt) :: tail => let repeated := String.mk (List.replicate cnt ch) repeated ++ decodeRLE tail -- !benchmark @end postcond_aux @[reducible, simp] def runLengthEncode_postcond (s : String) (result: List (Char × Nat)) (h_precond : runLengthEncode_precond (s)) : Prop := -- !benchmark @start postcond (∀ pair ∈ result, pair.snd > 0) ∧ (∀ i : Nat, i < result.length - 1 → (result[i]!).fst ≠ (result[i+1]!).fst) ∧ decodeRLE result = s -- !benchmark @end postcond -- !benchmark @start proof_aux -- !benchmark @end proof_aux theorem runLengthEncode_spec_satisfied (s: String) (h_precond : runLengthEncode_precond (s)) : runLengthEncode_postcond (s) (runLengthEncode (s) h_precond) h_precond := by -- !benchmark @start proof sorry -- !benchmark @end proof
{ "name": "runLengthEncode", "parameters": { "param_name": [ "s" ], "param_type": [ "String" ] }, "return_type": "List (Char × Nat)" }
{ "upstream": { "name": "lab_assignment", "link": "[{\"text_file_id\"=>802373105}]", "task_id": "lab_runLengthEncode_324976093", "student_id": [ 13 ] } }
{ "input": [ "{\"s\": \"\"}", "{\"s\": \"aaa\"}", "{\"s\": \"abbbcccaa\"}", "{\"s\": \"xyz\"}", "{\"s\": \"aabbaa\"}" ], "expected": [ [ "[]" ], [ "[('a', 3)]" ], [ "[('a', 1), ('b', 3), ('c', 3), ('a', 2)]" ], [ "[('x', 1), ('y', 1), ('z', 1)]" ], [ "[('a', 2), ('b', 2), ('a', 2)]" ] ], "unexpected": [ [ "[('x', 1)]" ], [ "[('a', 2), ('b', 3)]" ], [ "[('a', 2), ('b', 3), ('c', 3), ('a', 2)]" ], [ "[('x', 3)]", "[('z', 1)]" ], [ "[('a', 2), ('b', 2), ('a', 3)]" ] ] }
{ "input": [] }
advanced
verina_advanced_60
-----Description----- This task requires writing a Lean 4 method that takes a list of natural numbers and partitions it into two separate lists: one containing all the even numbers and the other containing all the odd numbers. The order of elements in each sublist should match their appearance in the original list. Assume there are no duplicates in the input. -----Input----- The input consists of a single list with no duplicate natural numbers: - nums: A list of natural numbers (Nat) -----Output----- The output is a tuple of two lists: - The first list contains all even numbers from the input list, in order. - The second list contains all odd numbers from the input list, in 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 partitionEvensOdds_precond (nums : List Nat) : Prop := -- !benchmark @start precond True -- !benchmark @end precond -- !benchmark @start code_aux -- !benchmark @end code_aux def partitionEvensOdds (nums : List Nat) (h_precond : partitionEvensOdds_precond (nums)) : (List Nat × List Nat) := -- !benchmark @start code let rec helper (nums : List Nat) : (List Nat × List Nat) := match nums with | [] => ([], []) | x :: xs => let (evens, odds) := helper xs if x % 2 == 0 then (x :: evens, odds) else (evens, x :: odds) helper nums -- !benchmark @end code -- !benchmark @start postcond_aux -- !benchmark @end postcond_aux @[reducible] def partitionEvensOdds_postcond (nums : List Nat) (result: (List Nat × List Nat)) (h_precond : partitionEvensOdds_precond (nums)): Prop := -- !benchmark @start postcond let evens := result.fst let odds := result.snd -- All elements from nums are in evens ++ odds, no extras evens ++ odds = nums.filter (fun n => n % 2 == 0) ++ nums.filter (fun n => n % 2 == 1) ∧ evens.all (fun n => n % 2 == 0) ∧ odds.all (fun n => n % 2 == 1) -- !benchmark @end postcond -- !benchmark @start proof_aux -- !benchmark @end proof_aux theorem partitionEvensOdds_spec_satisfied (nums: List Nat) (h_precond : partitionEvensOdds_precond (nums)) : partitionEvensOdds_postcond (nums) (partitionEvensOdds (nums) h_precond) h_precond := by -- !benchmark @start proof sorry -- !benchmark @end proof
{ "name": "partitionEvensOdds", "parameters": { "param_name": [ "nums" ], "param_type": [ "List Nat" ] }, "return_type": "(List Nat × List Nat)" }
{ "upstream": { "name": "lab_assignment", "link": "https://leetcode.com/problems/sort-array-by-parity/description/", "task_id": "lab_partitionEvensOdds_325775567", "student_id": [ 44 ] } }
{ "input": [ "{\"nums\": \"[1, 2, 3, 4, 5, 6]\"}", "{\"nums\": \"[0, 7, 8, 9, 10]\"}", "{\"nums\": \"[]\"}", "{\"nums\": \"[2, 4, 6, 8]\"}", "{\"nums\": \"[1, 3, 5, 7]\"}" ], "expected": [ [ "([2, 4, 6], [1, 3, 5])" ], [ "([0, 8, 10], [7, 9])" ], [ "([], [])" ], [ "([2, 4, 6, 8], [])" ], [ "([], [1, 3, 5, 7])" ] ], "unexpected": [ [ "([1, 3, 5], [2, 4, 6])" ], [ "([8, 0, 10], [9, 7])" ], [ "([0], [1])" ], [ "([], [2, 4, 6, 8])" ], [ "([1, 3, 5, 7], [])" ] ] }
{ "input": [] }
advanced
verina_advanced_61
-----Description----- This task requires writing a Lean 4 function that takes a list of integers and returns a new list. For each index i in the input list, the output at i is equal to the product of all numbers in the list except the number at index i. The solution must run in O(n) time without using the division operation. -----Input----- The input is a list of integers. For example, [1,2,3,4]. -----Output----- The output is a list of integers where each element at index i is the product of every input element except the one at that index. For example, for the input [1,2,3,4], the output should be [24,12,8,6]. Each intermediate product is guaranteed to fit in a 32-bit 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 productExceptSelf_precond (nums : List Int) : Prop := -- !benchmark @start precond True -- !benchmark @end precond -- !benchmark @start code_aux -- Helper: Compute prefix products. -- prefix[i] is the product of all elements in nums before index i. def computepref (nums : List Int) : List Int := nums.foldl (fun acc x => acc ++ [acc.getLast! * x]) [1] -- Helper: Compute suffix products. -- suffix[i] is the product of all elements in nums from index i (inclusive) to the end. -- We reverse the list and fold, then reverse back. def computeSuffix (nums : List Int) : List Int := let revSuffix := nums.reverse.foldl (fun acc x => acc ++ [acc.getLast! * x]) [1] revSuffix.reverse -- !benchmark @end code_aux def productExceptSelf (nums : List Int) (h_precond : productExceptSelf_precond (nums)) : List Int := -- !benchmark @start code let n := nums.length if n = 0 then [] else let pref := computepref nums -- length = n + 1, where prefix[i] = product of nums[0 ... i-1] let suffix := computeSuffix nums -- length = n + 1, where suffix[i] = product of nums[i ... n-1] -- For each index i (0 ≤ i < n): result[i] = prefix[i] * suffix[i+1] -- Use array-style indexing as get! is deprecated List.range n |>.map (fun i => pref[i]! * suffix[i+1]!) -- !benchmark @end code -- !benchmark @start postcond_aux -- Specification Helper: Product of a list of Ints -- Defined locally if not available/imported def List.myprod : List Int → Int | [] => 1 | x :: xs => x * xs.myprod -- !benchmark @end postcond_aux @[reducible] def productExceptSelf_postcond (nums : List Int) (result: List Int) (h_precond : productExceptSelf_precond (nums)) : Prop := -- !benchmark @start postcond nums.length = result.length ∧ (List.range nums.length |>.all (fun i => result[i]! = some (((List.take i nums).myprod) * ((List.drop (i+1) nums).myprod)))) -- !benchmark @end postcond -- !benchmark @start proof_aux -- !benchmark @end proof_aux theorem productExceptSelf_spec_satisfied (nums: List Int) (h_precond : productExceptSelf_precond (nums)) : productExceptSelf_postcond (nums) (productExceptSelf (nums) h_precond) h_precond := by -- !benchmark @start proof sorry -- !benchmark @end proof
{ "name": "productExceptSelf", "parameters": { "param_name": [ "nums" ], "param_type": [ "List Int" ] }, "return_type": "List Int" }
{ "upstream": { "name": "lab_assignment", "link": "https://leetcode.com/problems/product-of-array-except-self/description/", "task_id": "lab_productExceptSelf_325619864", "student_id": [ 45 ] } }
{ "input": [ "{\"nums\": \"[1, 2, 3, 4]\"}", "{\"nums\": \"[-1, 1, 0, -3, 3]\"}", "{\"nums\": \"[2, 3]\"}", "{\"nums\": \"[5, 5, 5, 5]\"}", "{\"nums\": \"[0, 1, 2]\"}" ], "expected": [ [ "[24, 12, 8, 6]" ], [ "[0, 0, 9, 0, 0]" ], [ "[3, 2]" ], [ "[125, 125, 125, 125]" ], [ "[2, 0, 0]" ] ], "unexpected": [ [ "[24, 12, 8, 0]", "[1, 2, 3, 4]" ], [ "[0, 0, 0, 0, 0]" ], [ "[6]", "[6, 6]" ], [ "[5]", "[25, 25, 25, 25]" ], [ "[2, 1, 0]", "[2, 0]" ] ] }
{ "input": [] }
advanced
verina_advanced_31
-----Description----- This task requires writing a Lean 4 function that finds the length of the longest strictly increasing subsequence in a list of integers. A subsequence is any sequence that can be derived from the list by deleting zero or more elements without changing the order of the remaining elements. The function must return the length of the longest possible such sequence. -----Input----- The input consists of a single value: xs: A list of integers of type `List Int`. -----Output----- The output is a natural number: Returns the length of the longest strictly increasing subsequence found in the 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 longestIncreasingSubseqLength_precond (xs : List Int) : Prop := -- !benchmark @start precond True -- !benchmark @end precond -- !benchmark @start code_aux -- Generate all subsequences def subsequences {α : Type} : List α → List (List α) | [] => [[]] | x :: xs => let subs := subsequences xs subs ++ subs.map (fun s => x :: s) -- Check if a list is strictly increasing def isStrictlyIncreasing : List Int → Bool | [] => true | [_] => true | x :: y :: rest => if x < y then isStrictlyIncreasing (y :: rest) else false -- !benchmark @end code_aux def longestIncreasingSubseqLength (xs : List Int) (h_precond : longestIncreasingSubseqLength_precond (xs)) : Nat := -- !benchmark @start code let subs := subsequences xs let increasing := subs.filter isStrictlyIncreasing increasing.foldl (fun acc s => max acc s.length) 0 -- !benchmark @end code -- !benchmark @start postcond_aux -- !benchmark @end postcond_aux @[reducible] def longestIncreasingSubseqLength_postcond (xs : List Int) (result: Nat) (h_precond : longestIncreasingSubseqLength_precond (xs)) : Prop := -- !benchmark @start postcond let allSubseq := (xs.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 longestIncreasingSubseqLength_spec_satisfied (xs: List Int) (h_precond : longestIncreasingSubseqLength_precond (xs)) : longestIncreasingSubseqLength_postcond (xs) (longestIncreasingSubseqLength (xs) h_precond) h_precond := by -- !benchmark @start proof sorry -- !benchmark @end proof
{ "name": "longestIncreasingSubseqLength", "parameters": { "param_name": [ "xs" ], "param_type": [ "List Int" ] }, "return_type": "Nat" }
{ "upstream": { "name": "lab_assignment", "link": "https://leetcode.com/problems/valid-parentheses/description/", "task_id": "lab_longestIncreasingSubseqLength_325618023", "student_id": [ 25 ] } }
{ "input": [ "{\"xs\": \"[1, 2, 3, 4]\"}", "{\"xs\": \"[4, 3, 2, 1]\"}", "{\"xs\": \"[1, 3, 2, 4, 0, 5]\"}", "{\"xs\": \"[]\"}", "{\"xs\": \"[5, 1, 6, 2, 7]\"}" ], "expected": [ [ "4" ], [ "1" ], [ "4" ], [ "0" ], [ "3" ] ], "unexpected": [ [ "3", "2", "1" ], [ "2", "3", "4" ], [ "3", "5" ], [ "1" ], [ "2", "4" ] ] }
{ "input": [] }
advanced
verina_basic_6
-----Description----- This task requires writing a Lean 4 method that finds the minimum among three given integers. The method should return the smallest value, ensuring that the result is less 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 minimum of the three input numbers, assuring that the returned value is less than or equal to a, b, and c, and that it matches one of these values.
-- !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 minOfThree_precond (a : Int) (b : Int) (c : Int) : Prop := -- !benchmark @start precond True -- !benchmark @end precond -- !benchmark @start code_aux -- !benchmark @end code_aux def minOfThree (a : Int) (b : Int) (c : Int) (h_precond : minOfThree_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, simp] def minOfThree_postcond (a : Int) (b : Int) (c : Int) (result: Int) (h_precond : minOfThree_precond (a) (b) (c)) := -- !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 minOfThree_spec_satisfied (a: Int) (b: Int) (c: Int) (h_precond : minOfThree_precond (a) (b) (c)) : minOfThree_postcond (a) (b) (c) (minOfThree (a) (b) (c) h_precond) h_precond := by -- !benchmark @start proof unfold minOfThree minOfThree_postcond split -- Case 1: a is the minimum · by_cases h1: a <= b && a <= c · constructor · simp_all · simp · contradiction split -- Case 2: b is the minimum · by_cases h2: b <= a && b <= c · constructor · simp_all · simp · contradiction -- Case 3: c is the minimum · by_cases h3: c < a && c < b · constructor · simp_all constructor · exact le_of_lt h3.1 · exact le_of_lt h3.2 · simp · constructor · simp_all by_cases h': a <= b · simp_all have h'': a <= c := by exact le_trans h' h3 rw [← not_lt] at h'' contradiction · simp_all have _: b <= a := by exact le_of_lt h' simp_all have h'': c < b := by assumption have h''': c < a := by exact lt_trans h'' h' apply h3 at h''' rw [← not_lt] at h''' contradiction · simp -- !benchmark @end proof
{ "name": "minOfThree", "parameters": { "param_name": [ "a", "b", "c" ], "param_type": [ "Int", "Int", "Int" ] }, "return_type": "Int" }
{ "upstream": { "name": "dafny-synthesis", "link": "https://github.com/Mondego/dafny-synthesis", "task_id": "task_id_227", "student_id": null } }
{ "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\": 2, \"b\": -3, \"c\": 4}", "{\"a\": 2, \"b\": 3, \"c\": -5}", "{\"a\": 0, \"b\": 0, \"c\": 1}", "{\"a\": 0, \"b\": -1, \"c\": 1}", "{\"a\": -5, \"b\": -2, \"c\": -3}" ], "expected": [ [ "1" ], [ "5" ], [ "10" ], [ "-1" ], [ "-3" ], [ "-5" ], [ "0" ], [ "-1" ], [ "-5" ] ], "unexpected": [ [ "2", "3", "0" ], [ "4", "6" ], [ "15", "20", "5" ], [ "2", "3", "0" ], [ "2", "4", "0" ], [ "2", "3", "0" ], [ "1", "-1", "2" ], [ "0", "1", "2" ], [ "-2", "-3", "0" ] ] }
{ "input": [] }
basic
verina_basic_50
-----Description----- This task is about calculating the absolute value of an integer. The goal is to determine the non-negative value of a given integer: if the integer is non-negative, it remains unchanged; if it is negative, its positive counterpart is returned. -----Input----- The input consists of: • x: An integer. -----Output----- The output is an integer that represents the absolute value of the input. Specifically: • If x is non-negative, the output is x. • If x is negative, the output is the negation of x (that is, a value y such that x + y = 0). -----Note----- This function should correctly handle zero, positive, and negative integers.
-- !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 Abs_precond (x : Int) : Prop := -- !benchmark @start precond True -- !benchmark @end precond -- !benchmark @start code_aux -- !benchmark @end code_aux def Abs (x : Int) (h_precond : Abs_precond (x)) : Int := -- !benchmark @start code if x < 0 then -x else x -- !benchmark @end code -- !benchmark @start postcond_aux -- !benchmark @end postcond_aux @[reducible, simp] def Abs_postcond (x : Int) (result: Int) (h_precond : Abs_precond (x)) := -- !benchmark @start postcond (x ≥ 0 → x = result) ∧ (x < 0 → x + result = 0) -- !benchmark @end postcond -- !benchmark @start proof_aux -- !benchmark @end proof_aux theorem Abs_spec_satisfied (x: Int) (h_precond : Abs_precond (x)) : Abs_postcond (x) (Abs (x) h_precond) h_precond := by -- !benchmark @start proof simp [Abs_postcond, Abs] apply And.intro . intro h split case isTrue ht => have h': ¬0 ≤ x := not_le.mpr ht contradiction case isFalse => rfl . intro h split case isTrue => simp case isFalse => contradiction -- !benchmark @end proof
{ "name": "Abs", "parameters": { "param_name": [ "x" ], "param_type": [ "Int" ] }, "return_type": "Int" }
{ "upstream": { "name": "clover", "link": "https://github.com/ChuyueSun/Clover", "task_id": "Clover_abs", "student_id": null } }
{ "input": [ "{\"x\": 5}", "{\"x\": 0}", "{\"x\": -5}", "{\"x\": 10}", "{\"x\": -10}" ], "expected": [ [ "5" ], [ "0" ], [ "5" ], [ "10" ], [ "10" ] ], "unexpected": [ [ "-5", "0", "10" ], [ "-1", "1", "-5" ], [ "-5", "-10", "0" ], [ "-10", "0", "5" ], [ "-10", "-1", "0" ] ] }
{ "input": [] }
basic
verina_advanced_10
-----Description----- his task requires writing a Lean 4 method decomposes a natural number `n` into its prime factorization components based on a user-provided list of primes. Specifically, it calculates the exponents for each prime in the factorization such that: \[ n = \prod p^e \] In other words, it determines the exponent e for each prime p. -----Input----- The input consists of a natural number n, and a list of prime numbers. The input n is obtained by multiplying together any powers of the prime numbers from the provided list. n: The natural number to be factorized. primes: A list of primes to decompose n into. -----Output----- The output is `List (Nat × Nat)`: Return a list of pair/Cartesian product of two natural numbers (p, e), where p is the prime and e is the exponent of p in the factorization. Each prime in the output must be from the input list, and every prime in the input list must appear in the output.
-- !benchmark @start import type=solution import Mathlib.Data.Nat.Prime.Defs -- !benchmark @end import -- !benchmark @start solution_aux -- !benchmark @end solution_aux -- !benchmark @start precond_aux -- !benchmark @end precond_aux @[reducible] def findExponents_precond (n : Nat) (primes : List Nat) : Prop := -- !benchmark @start precond primes.all (fun p => Nat.Prime p) -- !benchmark @end precond -- !benchmark @start code_aux -- !benchmark @end code_aux def findExponents (n : Nat) (primes : List Nat) (h_precond : findExponents_precond (n) (primes)) : List (Nat × Nat) := -- !benchmark @start code let rec countFactors (n : Nat) (primes : List Nat) : List (Nat × Nat) := match primes with | [] => [] | p :: ps => let (count, n') := countFactor n p 0 (p, count) :: countFactors n' ps countFactors n primes where countFactor : Nat → Nat → Nat → Nat × Nat | 0, _, count => (count, 0) | n, p, count => if h : n > 0 ∧ p > 1 then have : n / p < n := Nat.div_lt_self h.1 h.2 if n % p == 0 then countFactor (n / p) p (count + 1) else (count, n) else (count, n) termination_by n _ _ => n -- !benchmark @end code -- !benchmark @start postcond_aux -- !benchmark @end postcond_aux @[reducible] def findExponents_postcond (n : Nat) (primes : List Nat) (result: List (Nat × Nat)) (h_precond : findExponents_precond (n) (primes)) : Prop := -- !benchmark @start postcond (n = result.foldl (fun acc (p, e) => acc * p ^ e) 1) ∧ result.all (fun (p, _) => p ∈ primes) ∧ primes.all (fun p => result.any (fun pair => pair.1 = p)) -- !benchmark @end postcond -- !benchmark @start proof_aux -- !benchmark @end proof_aux theorem findExponents_spec_satisfied (n: Nat) (primes: List Nat) (h_precond : findExponents_precond (n) (primes)) : findExponents_postcond (n) (primes) (findExponents (n) (primes) h_precond) h_precond := by -- !benchmark @start proof sorry -- !benchmark @end proof
{ "name": "findExponents", "parameters": { "param_name": [ "n", "primes" ], "param_type": [ "Nat", "List Nat" ] }, "return_type": "List (Nat × Nat)" }
{ "upstream": { "name": "lab_assignment", "link": "N/A", "task_id": "lab_findExponents_325706703", "student_id": [ 8 ] } }
{ "input": [ "{\"n\": 6, \"primes\": \"[2, 3]\"}", "{\"n\": 6285195213566005335561053533150026217291776, \"primes\": \"[2, 3, 5]\"}", "{\"n\": 360, \"primes\": \"[2, 3, 5]\"}", "{\"n\": 18903812908, \"primes\": \"[2, 43, 823, 133543]\"}", "{\"n\": 114514, \"primes\": \"[2, 31, 1847]\"}", "{\"n\": 20241147794175, \"primes\": \"[3, 5, 7, 11, 31, 47]\"}" ], "expected": [ [ "[(2, 1), (3, 1)]" ], [ "[(2, 55), (3, 55), (5, 0)]" ], [ "[(2, 3), (3, 2), (5, 1)]" ], [ "[(2, 2), (43, 1), (823, 1), (133543, 1)]" ], [ "[(2, 1), (31, 1), (1847, 1)]" ], [ "[(3, 3), (5, 2), (7, 1), (11, 3), (31, 1), (47, 3)]" ] ], "unexpected": [ [ "[(1, 2), (2, 3)]", "[(2, 1), (3, 2)]" ], [ "[(2, 2), (3, 55), (5, 59)]", "[(2, 55), (3, 55), (7, 0)]" ], [ "[(2, 3), (3, 2), (5, 0)]", "[(2, 3), (3, 2), (7, 5)]" ], [ "[(2, 2), (43, 4), (823, 0), (133543, 1)]", "[(2, 2), (43, 1), (823, 2)]" ], [ "[(2, 1), (31, 1), (1847, 0)]", "[(2, 1), (33, 1), (1847, 1)]" ], [ "[(0, 77), (17, 7)]", "[(3, 3), (5, 2), (7, 1), (11, 3), (31, 1), (33, 2)]" ] ] }
{ "input": [ "{'n': 6, 'primes': '[6]'}" ] }
advanced
verina_advanced_62
-----Description----- This task requires writing a Lean 4 method that calculates how much rainwater would be trapped by a terrain represented as an array of heights. Imagine rainwater falls onto a terrain with varying elevation levels. The water can only be trapped between higher elevation points. Given an array of non-negative integers representing the elevation map where the width of each bar is 1 unit, calculate how much water can be trapped after it rains. -----Input----- The input consists of one array: heights: An array of non-negative integers representing elevation levels. -----Output----- The output is an integer: Returns the total amount of rainwater that can be trapped.
-- !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 rain_precond (heights : List (Int)) : Prop := -- !benchmark @start precond heights.all (fun h => h >= 0) -- !benchmark @end precond -- !benchmark @start code_aux -- !benchmark @end code_aux def rain (heights : List (Int)) (h_precond : rain_precond (heights)) : Int := -- !benchmark @start code -- Handle edge cases: need at least 3 elements to trap water if heights.length < 3 then 0 else let n := heights.length -- Use two pointers approach for O(n) time with O(1) space let rec aux (left : Nat) (right : Nat) (leftMax : Int) (rightMax : Int) (water : Int) : Int := if left >= right then water -- Base case: all elements processed else if heights[left]! <= heights[right]! then -- Process from the left let newLeftMax := max leftMax (heights[left]!) let newWater := water + max 0 (leftMax - heights[left]!) aux (left+1) right newLeftMax rightMax newWater else -- Process from the right let newRightMax := max rightMax (heights[right]!) let newWater := water + max 0 (rightMax - heights[right]!) aux left (right-1) leftMax newRightMax newWater termination_by right - left -- Initialize with two pointers at the ends aux 0 (n-1) (heights[0]!) (heights[n-1]!) 0 -- !benchmark @end code -- !benchmark @start postcond_aux -- !benchmark @end postcond_aux @[reducible] def rain_postcond (heights : List (Int)) (result: Int) (h_precond : rain_precond (heights)) : Prop := -- !benchmark @start postcond -- The result is the total amount of rainwater trapped by the given terrain -- If there are fewer than 3 elements, no water can be trapped result >= 0 ∧ -- The result is non-negative if heights.length < 3 then result = 0 else -- Water trapped at each position is min(maxLeft, maxRight) - height result = let max_left_at := λ i => let rec ml (j : Nat) (max_so_far : Int) : Int := if j > i then max_so_far else ml (j+1) (max max_so_far (heights[j]!)) termination_by i + 1 - j ml 0 0 let max_right_at := λ i => let rec mr (j : Nat) (max_so_far : Int) : Int := if j >= heights.length then max_so_far else mr (j+1) (max max_so_far (heights[j]!)) termination_by heights.length - j mr i 0 let water_at := λ i => max 0 (min (max_left_at i) (max_right_at i) - heights[i]!) let rec sum_water (i : Nat) (acc : Int) : Int := if i >= heights.length then acc else sum_water (i+1) (acc + water_at i) termination_by heights.length - i sum_water 0 0 -- !benchmark @end postcond -- !benchmark @start proof_aux -- !benchmark @end proof_aux theorem rain_spec_satisfied (heights: List (Int)) (h_precond : rain_precond (heights)) : rain_postcond (heights) (rain (heights) h_precond) h_precond := by -- !benchmark @start proof sorry -- !benchmark @end proof
{ "name": "rain", "parameters": { "param_name": [ "heights" ], "param_type": [ "List (Int)" ] }, "return_type": "Int" }
{ "upstream": { "name": "lab_assignment", "link": "https://leetcode.com/problems/trapping-rain-water/description/", "task_id": "lab_rain_327045007", "student_id": [ 46 ] } }
{ "input": [ "{\"heights\": \"[0, 1, 0, 2, 1, 0, 1, 3, 2, 1, 2, 1]\"}", "{\"heights\": \"[4, 2, 0, 3, 2, 5]\"}", "{\"heights\": \"[1, 1, 1]\"}", "{\"heights\": \"[10, 5]\"}", "{\"heights\": \"[1, 10, 9, 11]\"}", "{\"heights\": \"[]\"}" ], "expected": [ [ "6" ], [ "9" ], [ "0" ], [ "0" ], [ "1" ], [ "0" ] ], "unexpected": [ [ "-1", "5", "7" ], [ "-1", "8", "10" ], [ "-1", "3", "1" ], [ "-1", "5", "10" ], [ "-1", "9", "2" ], [ "-1", "100" ] ] }
{ "input": [ "{'heights': '[-1]'}" ] }
advanced
verina_basic_11
-----Description----- This task requires writing a Lean 4 method that extracts the last digit of a given non-negative integer. The method should return the last digit, which is obtained by computing the remainder when the number is divided by 10. The result must always be between 0 and 9. -----Input----- The input consists of a single value: n: A non-negative integer. -----Output----- The output is an integer: Returns the last digit of the input number, ensuring that the digit lies within the range 0 to 9. -----Note----- It is assumed that the input number n is non-negative.
-- !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 lastDigit_precond (n : Nat) : Prop := -- !benchmark @start precond True -- !benchmark @end precond -- !benchmark @start code_aux -- !benchmark @end code_aux def lastDigit (n : Nat) (h_precond : lastDigit_precond (n)) : Nat := -- !benchmark @start code n % 10 -- !benchmark @end code -- !benchmark @start postcond_aux -- !benchmark @end postcond_aux @[reducible, simp] def lastDigit_postcond (n : Nat) (result: Nat) (h_precond : lastDigit_precond (n)) := -- !benchmark @start postcond (0 ≤ result ∧ result < 10) ∧ (n % 10 - result = 0 ∧ result - n % 10 = 0) -- !benchmark @end postcond -- !benchmark @start proof_aux -- !benchmark @end proof_aux theorem lastDigit_spec_satisfied (n: Nat) (h_precond : lastDigit_precond (n)) : lastDigit_postcond (n) (lastDigit (n) h_precond) h_precond := by -- !benchmark @start proof unfold lastDigit lastDigit_postcond constructor · constructor · simp · exact Nat.mod_lt n (by decide) · simp -- !benchmark @end proof
{ "name": "lastDigit", "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_435", "student_id": null } }
{ "input": [ "{\"n\": 123}", "{\"n\": 0}", "{\"n\": 987654321}", "{\"n\": 10}", "{\"n\": 999}", "{\"n\": 45}", "{\"n\": 100}", "{\"n\": 5}" ], "expected": [ [ "3" ], [ "0" ], [ "1" ], [ "0" ], [ "9" ], [ "5" ], [ "0" ], [ "5" ] ], "unexpected": [ [ "2", "1", "23" ], [ "10", "5", "9" ], [ "9", "0", "2" ], [ "1", "10", "5" ], [ "8", "99", "0" ], [ "4", "0", "55" ], [ "1", "10", "5" ], [ "4", "0", "6" ] ] }
{ "input": [] }
basic
verina_basic_33
-----Description----- This task requires writing a Lean 4 method that returns the smallest natural number missing from a given sorted list of natural numbers. In other words, starting from 0, the method should identify the first natural number that does not appear in the list. The input list is assumed to be sorted in non-decreasing order and contains only natural numbers (including 0). -----Input----- The input consists of: s: A list of natural numbers sorted in non-decreasing order. -----Output----- The output is a natural number: Returns the smallest natural number that does not appear in the input list. -----Note----- It is assumed that the input list is sorted and contains only natural numbers.
-- !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 smallestMissingNumber_precond (s : List Nat) : Prop := -- !benchmark @start precond List.Pairwise (· ≤ ·) s -- !benchmark @end precond -- !benchmark @start code_aux -- !benchmark @end code_aux def smallestMissingNumber (s : List Nat) (h_precond : smallestMissingNumber_precond (s)) : Nat := -- !benchmark @start code let rec findMissing (v : Nat) (l : List Nat) : Nat := match l with | [] => v | x :: xs => if x > v then v else if x = v then findMissing (v + 1) xs else findMissing v xs findMissing 0 s -- !benchmark @end code -- !benchmark @start postcond_aux -- !benchmark @end postcond_aux @[reducible, simp] def smallestMissingNumber_postcond (s : List Nat) (result: Nat) (h_precond : smallestMissingNumber_precond (s)) := -- !benchmark @start postcond ¬ List.elem result s ∧ (∀ k : Nat, k < result → List.elem k s) -- !benchmark @end postcond -- !benchmark @start proof_aux -- !benchmark @end proof_aux theorem smallestMissingNumber_spec_satisfied (s: List Nat) (h_precond : smallestMissingNumber_precond (s)) : smallestMissingNumber_postcond (s) (smallestMissingNumber (s) h_precond) h_precond := by -- !benchmark @start proof sorry -- !benchmark @end proof
{ "name": "smallestMissingNumber", "parameters": { "param_name": [ "s" ], "param_type": [ "List Nat" ] }, "return_type": "Nat" }
{ "upstream": { "name": "dafny-synthesis", "link": "https://github.com/Mondego/dafny-synthesis", "task_id": "task_id_627", "student_id": null } }
{ "input": [ "{\"s\": \"[0, 1, 2, 6, 9]\"}", "{\"s\": \"[4, 5, 10, 11]\"}", "{\"s\": \"[0, 1, 2, 3, 4, 5]\"}", "{\"s\": \"[]\"}", "{\"s\": \"[0, 2, 3, 4]\"}" ], "expected": [ [ "3" ], [ "0" ], [ "6" ], [ "0" ], [ "1" ] ], "unexpected": [ [ "2", "4", "5" ], [ "1", "2" ], [ "5", "7" ], [ "1", "2" ], [ "0", "2", "3" ] ] }
{ "input": [ "{'s': '[3, 2, 1]'}" ] }
basic
verina_advanced_72
-----Description----- This task requires writing a Lean 4 method that given an natural number n, returns the smallest prime factor that is less than 10. If none exist, return 0 -----Input----- The input consists of one natural number: n: The main natural number. -----Output----- The output is an natural number: Returns the smallest prime factor that is less than 10 or, if none exist, 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 singleDigitPrimeFactor_precond (n : Nat) : Prop := -- !benchmark @start precond True -- !benchmark @end precond -- !benchmark @start code_aux -- !benchmark @end code_aux def singleDigitPrimeFactor (n : Nat) (h_precond : singleDigitPrimeFactor_precond (n)) : Nat := -- !benchmark @start code if n == 0 then 0 else if n % 2 == 0 then 2 else if n % 3 == 0 then 3 else if n % 5 == 0 then 5 else if n % 7 == 0 then 7 else 0 -- !benchmark @end code -- !benchmark @start postcond_aux -- !benchmark @end postcond_aux @[reducible, simp] def singleDigitPrimeFactor_postcond (n : Nat) (result: Nat) (h_precond : singleDigitPrimeFactor_precond (n)) : Prop := -- !benchmark @start postcond result ∈ [0, 2, 3, 5, 7] ∧ (result = 0 → (n = 0 ∨ [2, 3, 5, 7].all (n % · ≠ 0))) ∧ (result ≠ 0 → n ≠ 0 ∧ n % result == 0 ∧ (List.range result).all (fun x => x ∈ [2, 3, 5, 7] → n % x ≠ 0)) -- !benchmark @end postcond -- !benchmark @start proof_aux -- !benchmark @end proof_aux theorem singleDigitPrimeFactor_spec_satisfied (n: Nat) (h_precond : singleDigitPrimeFactor_precond (n)) : singleDigitPrimeFactor_postcond (n) (singleDigitPrimeFactor (n) h_precond) h_precond := by -- !benchmark @start proof sorry -- !benchmark @end proof
{ "name": "singleDigitPrimeFactor", "parameters": { "param_name": [ "n" ], "param_type": [ "Nat" ] }, "return_type": "Nat" }
{ "upstream": { "name": "lab_assignment", "link": "", "task_id": "lab_singleDigitPrimeFactor_324367187", "student_id": [ 16 ] } }
{ "input": [ "{\"n\": 0}", "{\"n\": 98}", "{\"n\": 9}", "{\"n\": 73}", "{\"n\": 529}", "{\"n\": 161}", "{\"n\": 0}" ], "expected": [ [ "0" ], [ "2" ], [ "3" ], [ "0" ], [ "0" ], [ "7" ], [ "0" ] ], "unexpected": [ [ "1", "2", "3" ], [ "7", "8", "9" ], [ "4", "5", "6" ], [ "1", "2", "3" ], [ "7", "8", "9" ], [ "0", "1", "2" ], [ "1", "2", "3" ] ] }
{ "input": [] }
advanced
verina_basic_38
-----Description----- This task requires writing a Lean 4 method that checks whether all characters in an input string are identical. The method should return true if every character in the string is the same, and false if at least one character differs. An empty string or a single-character string is considered to have all characters identical. -----Input----- The input consists of: s: A string. -----Output----- The output is a Boolean value: Returns true if every character in the string is identical. Returns false if there is at least one differing character.
-- !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 allCharactersSame_precond (s : String) : Prop := -- !benchmark @start precond True -- !benchmark @end precond -- !benchmark @start code_aux -- !benchmark @end code_aux def allCharactersSame (s : String) (h_precond : allCharactersSame_precond (s)) : Bool := -- !benchmark @start code match s.toList with | [] => true | c :: cs => cs.all (fun x => x = c) -- !benchmark @end code -- !benchmark @start postcond_aux -- !benchmark @end postcond_aux @[reducible, simp] def allCharactersSame_postcond (s : String) (result: Bool) (h_precond : allCharactersSame_precond (s)) := -- !benchmark @start postcond let cs := s.toList (result → List.Pairwise (· = ·) cs) ∧ (¬ result → (cs ≠ [] ∧ cs.any (fun x => x ≠ cs[0]!))) -- !benchmark @end postcond -- !benchmark @start proof_aux -- !benchmark @end proof_aux theorem allCharactersSame_spec_satisfied (s: String) (h_precond : allCharactersSame_precond (s)) : allCharactersSame_postcond (s) (allCharactersSame (s) h_precond) h_precond := by -- !benchmark @start proof sorry -- !benchmark @end proof
{ "name": "allCharactersSame", "parameters": { "param_name": [ "s" ], "param_type": [ "String" ] }, "return_type": "Bool" }
{ "upstream": { "name": "dafny-synthesis", "link": "https://github.com/Mondego/dafny-synthesis", "task_id": "task_id_741", "student_id": null } }
{ "input": [ "{\"s\": \"aaa\"}", "{\"s\": \"aba\"}", "{\"s\": \"\"}", "{\"s\": \"a\"}", "{\"s\": \"bbbb\"}", "{\"s\": \"bbab\"}" ], "expected": [ [ "True" ], [ "False" ], [ "True" ], [ "True" ], [ "True" ], [ "False" ] ], "unexpected": [ [ "False" ], [ "True" ], [ "False" ], [ "False" ], [ "False" ], [ "True" ] ] }
{ "input": [] }
basic
verina_advanced_55
-----Description----- This task requires writing a Lean 4 method that returns the integer that appears most frequently in the input list. If multiple integers have the same maximum frequency, return the one that appears first in the original list. You should implement a frequency counter using a fold over the list, extract the maximum frequency, and return the first element in the list that matches it. -----Input----- The input consists of: xs: A list of integers (possibly with duplicates). The list is guaranteed to be non-empty. -----Output----- The output is an integer: Returns the number that appears the most frequently in the list. If there is a tie, the element that occurs first in the original list should be returned.
-- !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 mostFrequent_precond (xs : List Int) : Prop := -- !benchmark @start precond xs ≠ [] -- !benchmark @end precond -- !benchmark @start code_aux -- Build a frequency map from the list def countMap (xs : List Int) : HashMap Int Nat := let step := fun m x => let current := m.getD x 0 m.insert x (current + 1) let init := (HashMap.empty : HashMap Int Nat) xs.foldl step init -- Compute the maximum frequency in the map def getMaxFrequency (m : HashMap Int Nat) : Nat := let step := fun acc (_k, v) => if v > acc then v else acc let init := 0 m.toList.foldl step init -- Extract all keys whose frequency == maxFreq def getCandidates (m : HashMap Int Nat) (maxFreq : Nat) : List Int := let isTarget := fun (_k, v) => v = maxFreq let extract := fun (k, _) => k m.toList.filter isTarget |>.map extract -- Return the first candidate element from original list def getFirstWithFreq (xs : List Int) (candidates : List Int) : Int := match xs.find? (fun x => candidates.contains x) with | some x => x | none => 0 -- !benchmark @end code_aux def mostFrequent (xs : List Int) (h_precond : mostFrequent_precond (xs)) : Int := -- !benchmark @start code let freqMap := countMap xs let maxF := getMaxFrequency freqMap let candidates := getCandidates freqMap maxF getFirstWithFreq xs candidates -- !benchmark @end code -- !benchmark @start postcond_aux -- !benchmark @end postcond_aux @[reducible] def mostFrequent_postcond (xs : List Int) (result: Int) (h_precond : mostFrequent_precond (xs)) : Prop := -- !benchmark @start postcond let count := fun x => xs.countP (fun y => y = x) result ∈ xs ∧ xs.all (fun x => count x ≤ count result) ∧ ((xs.filter (fun x => count x = count result)).head? = some result) -- !benchmark @end postcond -- !benchmark @start proof_aux -- !benchmark @end proof_aux theorem mostFrequent_spec_satisfied (xs: List Int) (h_precond : mostFrequent_precond (xs)) : mostFrequent_postcond (xs) (mostFrequent (xs) h_precond) h_precond := by -- !benchmark @start proof sorry -- !benchmark @end proof
{ "name": "mostFrequent", "parameters": { "param_name": [ "xs" ], "param_type": [ "List Int" ] }, "return_type": "Int" }
{ "upstream": { "name": "lab_assignment", "link": "https://leetcode.com/problems/majority-element/", "task_id": "lab_mostFrequent_325752578", "student_id": [ 15 ] } }
{ "input": [ "{\"xs\": \"[1, 2, 2, 3]\"}", "{\"xs\": \"[4, 4, 5, 5, 4]\"}", "{\"xs\": \"[9]\"}", "{\"xs\": \"[1, 2, 3, 1, 2, 3, 2]\"}", "{\"xs\": \"[7, 7, 8, 8, 9, 9, 7]\"}" ], "expected": [ [ "2" ], [ "4" ], [ "9" ], [ "2" ], [ "7" ] ], "unexpected": [ [ "1", "3" ], [ "5" ], [ "0" ], [ "1", "3" ], [ "8", "9" ] ] }
{ "input": [ "{'xs': '[]'}" ] }
advanced
verina_basic_25
-----Description----- This task requires writing a Lean 4 method that calculates both the sum and the average of the first n natural numbers. The method should compute the sum of numbers from 0 to n (which equals n * (n + 1) / 2) and then determine the average by dividing this sum by n. The specification assumes that the input n is a positive integer. -----Input----- The input consists of: n: A natural number representing the count of the first natural numbers. The value of n is assumed to be positive. -----Output----- The output is a pair consisting of: - An integer representing the sum of the first n natural numbers. - A floating-point number representing the average of the first n natural numbers. -----Note----- The input n must be a positive 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 sumAndAverage_precond (n : Nat) : Prop := -- !benchmark @start precond True -- !benchmark @end precond -- !benchmark @start code_aux -- !benchmark @end code_aux def sumAndAverage (n : Nat) (h_precond : sumAndAverage_precond (n)) : Int × Float := -- !benchmark @start code if n ≤ 0 then (0, 0.0) else let sum := (List.range (n + 1)).sum let average : Float := sum.toFloat / (n.toFloat) (sum, average) -- !benchmark @end code -- !benchmark @start postcond_aux -- !benchmark @end postcond_aux @[reducible, simp] def sumAndAverage_postcond (n : Nat) (result: Int × Float) (h_precond : sumAndAverage_precond (n)) := -- !benchmark @start postcond (n = 0 → result == (0, 0.0)) ∧ (n > 0 → result.1 == n * (n + 1) / 2 ∧ result.2 == ((n * (n + 1) / 2).toFloat) / (n.toFloat)) -- !benchmark @end postcond -- !benchmark @start proof_aux -- !benchmark @end proof_aux theorem sumAndAverage_spec_satisfied (n: Nat) (h_precond : sumAndAverage_precond (n)) : sumAndAverage_postcond (n) (sumAndAverage (n) h_precond) h_precond := by -- !benchmark @start proof sorry -- !benchmark @end proof
{ "name": "sumAndAverage", "parameters": { "param_name": [ "n" ], "param_type": [ "Nat" ] }, "return_type": "Int × Float" }
{ "upstream": { "name": "dafny-synthesis", "link": "https://github.com/Mondego/dafny-synthesis", "task_id": "task_id_599", "student_id": null } }
{ "input": [ "{\"n\": 5}", "{\"n\": 1}", "{\"n\": 10}", "{\"n\": 0}", "{\"n\": 2}" ], "expected": [ [ "(15, 3.0)" ], [ "(1, 1.0)" ], [ "(55, 5.5)" ], [ "(0, 0.0)" ], [ "(3, 1.5)" ] ], "unexpected": [ [ "(14, 2.8)", "(16, 3.2)" ], [ "(0, 0.0)", "(2, 2.0)" ], [ "(50, 5.0)", "(60, 6.0)" ], [ "(1, 0.1)", "(-1, -0.1)" ], [ "(2, 1.0)", "(4, 2.0)" ] ] }
{ "input": [] }
basic
verina_advanced_17
-----Description----- This task requires implementing the insertion sort algorithm to sort a list of integers in ascending order. The function should take a list of integers as input and return a new list containing the same elements sorted in non-decreasing order. -----Input----- The input is: l: A list of integers to be sorted. -----Output----- The output is: A list of integers that is sorted in non-decreasing order and is a permutation of 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 insertionSort_precond (l : List Int) : Prop := -- !benchmark @start precond True -- !benchmark @end precond -- !benchmark @start code_aux -- Helper function to insert an integer into a sorted list def insertElement (x : Int) (l : List Int) : List Int := match l with | [] => [x] | y :: ys => if x <= y then x :: y :: ys else y :: insertElement x ys -- Helper function to sort a list using insertion sort def sortList (l : List Int) : List Int := match l with | [] => [] | x :: xs => insertElement x (sortList xs) -- !benchmark @end code_aux def insertionSort (l : List Int) (h_precond : insertionSort_precond (l)) : List Int := -- !benchmark @start code let result := sortList l result -- !benchmark @end code -- !benchmark @start postcond_aux -- !benchmark @end postcond_aux @[reducible] def insertionSort_postcond (l : List Int) (result: List Int) (h_precond : insertionSort_precond (l)) : Prop := -- !benchmark @start postcond List.Pairwise (· ≤ ·) result ∧ List.isPerm l result -- !benchmark @end postcond -- !benchmark @start proof_aux -- !benchmark @end proof_aux theorem insertionSort_spec_satisfied (l: List Int) (h_precond : insertionSort_precond (l)) : insertionSort_postcond (l) (insertionSort (l) h_precond) h_precond := by -- !benchmark @start proof sorry -- !benchmark @end proof
{ "name": "insertionSort", "parameters": { "param_name": [ "l" ], "param_type": [ "List Int" ] }, "return_type": "List Int" }
{ "upstream": { "name": "lab_assignment", "link": "https://leetcode.com/problems/insertion-sort-list/", "task_id": "lab_insertionSort_325670071", "student_id": [ 14 ] } }
{ "input": [ "{\"l\": \"[]\"}", "{\"l\": \"[5]\"}", "{\"l\": \"[1, 2, 3]\"}", "{\"l\": \"[3, 2, 1]\"}", "{\"l\": \"[4, 2, 2, 3]\"}" ], "expected": [ [ "[]" ], [ "[5]" ], [ "[1, 2, 3]" ], [ "[1, 2, 3]" ], [ "[2, 2, 3, 4]" ] ], "unexpected": [ [ "[0]", "[1]" ], [ "[]", "[5, 5]" ], [ "[3, 2, 1]", "[2, 1, 3]" ], [ "[3, 2, 1]", "[2, 1, 3]" ], [ "[4, 3, 2, 2]", "[2, 3, 2, 4]" ] ] }
{ "input": [] }
advanced
verina_basic_43
-----Description----- This task requires writing a Lean 4 method that computes the sum of the fourth power of the first n odd natural numbers. In other words, given a non-negative integer n, the method should calculate the sum: 1⁴ + 3⁴ + 5⁴ + ... for the first n odd numbers. -----Input----- The input consists of: n: A non-negative natural number representing the number of odd natural numbers to consider. -----Output----- The output is a natural number: Returns the sum of the fourth power of the first n odd natural numbers. -----Note----- The input n is assumed to be a non-negative integer. The correctness of the result is established by a theorem that relates the computed sum to a specific formula.
-- !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 sumOfFourthPowerOfOddNumbers_precond (n : Nat) : Prop := -- !benchmark @start precond True -- !benchmark @end precond -- !benchmark @start code_aux -- !benchmark @end code_aux def sumOfFourthPowerOfOddNumbers (n : Nat) (h_precond : sumOfFourthPowerOfOddNumbers_precond (n)) : Nat := -- !benchmark @start code match n with | 0 => 0 | n + 1 => let prev := sumOfFourthPowerOfOddNumbers n h_precond let nextOdd := 2 * n + 1 prev + nextOdd^4 -- !benchmark @end code -- !benchmark @start postcond_aux -- !benchmark @end postcond_aux @[reducible, simp] def sumOfFourthPowerOfOddNumbers_postcond (n : Nat) (result: Nat) (h_precond : sumOfFourthPowerOfOddNumbers_precond (n)) := -- !benchmark @start postcond 15 * result = n * (2 * n + 1) * (7 + 24 * n^3 - 12 * n^2 - 14 * n) -- !benchmark @end postcond -- !benchmark @start proof_aux -- !benchmark @end proof_aux theorem sumOfFourthPowerOfOddNumbers_spec_satisfied (n: Nat) (h_precond : sumOfFourthPowerOfOddNumbers_precond (n)) : sumOfFourthPowerOfOddNumbers_postcond (n) (sumOfFourthPowerOfOddNumbers (n) h_precond) h_precond := by -- !benchmark @start proof sorry -- !benchmark @end proof
{ "name": "sumOfFourthPowerOfOddNumbers", "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_770", "student_id": null } }
{ "input": [ "{\"n\": 0}", "{\"n\": 1}", "{\"n\": 2}", "{\"n\": 3}", "{\"n\": 4}", "{\"n\": 5}" ], "expected": [ [ "0" ], [ "1" ], [ "82" ], [ "707" ], [ "3108" ], [ "9669" ] ], "unexpected": [ [ "1", "10" ], [ "2", "0", "5" ], [ "81", "83", "80" ], [ "706", "708", "700" ], [ "3107", "3109", "3000" ], [ "9668", "9670", "9000" ] ] }
{ "input": [] }
basic
verina_basic_88
-----Description----- This task involves converting a list of integers into an array such that the array contains all the elements of the list in the exact same order. The objective is to ensure that the array has the same number of elements as the list and that each element in the array corresponds exactly to the element at the same position in the list. -----Input----- The input consists of: • xs: A list of integer elements. -----Output----- The output is an array of elements of type integer that: • Has a size equal to the length of the input list xs. • Contains all the elements from xs in the same order, ensuring that for every valid index i, the array element at i is equal to the list element at i. -----Note----- There are no additional preconditions; the method should work correctly for any list of elements. A corresponding specification is provided stating that the array’s size equals the list’s length and that each element is preserved.
-- !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 ToArray_precond (xs : List Int) : Prop := -- !benchmark @start precond True -- !benchmark @end precond -- !benchmark @start code_aux -- !benchmark @end code_aux def ToArray (xs : List Int) (h_precond : ToArray_precond (xs)) : Array Int := -- !benchmark @start code xs.toArray -- !benchmark @end code -- !benchmark @start postcond_aux -- !benchmark @end postcond_aux @[reducible, simp] def ToArray_postcond (xs : List Int) (result: Array Int) (h_precond : ToArray_precond (xs)) := -- !benchmark @start postcond result.size = xs.length ∧ ∀ (i : Nat), i < xs.length → result[i]! = xs[i]! -- !benchmark @end postcond -- !benchmark @start proof_aux -- !benchmark @end proof_aux theorem ToArray_spec_satisfied (xs: List Int) (h_precond : ToArray_precond (xs)) : ToArray_postcond (xs) (ToArray (xs) h_precond) h_precond := by -- !benchmark @start proof sorry -- !benchmark @end proof
{ "name": "ToArray", "parameters": { "param_name": [ "xs" ], "param_type": [ "List Int" ] }, "return_type": "Array Int" }
{ "upstream": { "name": "clover", "link": "https://github.com/ChuyueSun/Clover", "task_id": "Clover_seq_to_array", "student_id": null } }
{ "input": [ "{\"xs\": \"[1, 2, 3]\"}", "{\"xs\": \"[]\"}", "{\"xs\": \"[0, -1, 5]\"}", "{\"xs\": \"[7]\"}", "{\"xs\": \"[100, 200, 300, 400]\"}" ], "expected": [ [ "#[1, 2, 3]" ], [ "#[]" ], [ "#[0, -1, 5]" ], [ "#[7]" ], [ "#[100, 200, 300, 400]" ] ], "unexpected": [ [ "#[1, 2]", "#[1, 2, 3, 4]", "#[3, 2, 1]" ], [ "#[0]", "#[1]", "#[1, 0]" ], [ "#[-1, 0, 5]", "#[0, 5]", "#[0, -1, 4]" ], [ "#[]", "#[0, 7]", "#[8]" ], [ "#[100, 200, 300]", "#[100, 300, 200, 400]", "#[400, 300, 200, 100]" ] ] }
{ "input": [] }
basic
verina_advanced_53
-----Description----- This task requires writing a Lean 4 function that calculates the minimum number of right shifts required to sort a given list of distinct positive integers. A right shift operation on a list nums of length n moves the element at index i to index (i + 1) % n for all indices i. Effectively, the last element moves to the first position, and all other elements shift one position to the right. The function should return the minimum number of right shifts needed to make the list sorted in ascending order. If the list is already sorted, the function should return 0. If it's impossible to sort the list using only right shifts, the function should return -1. -----Input----- The input consists of a single list of integers: nums: A list (List Int) containing distinct positive integers. -----Output----- The output is a single integer (Int): - If the list can be sorted using right shifts, return the minimum number of shifts required (an integer >= 0). - If the list cannot be sorted using right shifts, return -1.
-- !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 minimumRightShifts_precond (nums : List Int) : Prop := -- !benchmark @start precond List.Nodup nums -- !benchmark @end precond -- !benchmark @start code_aux -- !benchmark @end code_aux def minimumRightShifts (nums : List Int) (h_precond : minimumRightShifts_precond (nums)) : Int := -- !benchmark @start code let n := nums.length -- base cases: empty or single element list is already sorted if n <= 1 then 0 else -- local helper function to check if a list is sorted in ascending order let rec isSortedAux (l : List Int) : Bool := match l with | [] => true -- empty list is sorted | [_] => true -- single element list is sorted | x :: y :: xs => if x <= y then isSortedAux (y :: xs) else false -- check pairwise -- check if the input list is already sorted if isSortedAux nums then 0 else -- local helper function to perform a single right shift -- assume the list `l` is non-empty based on the initial n > 1 check let rightShiftOnce (l : List Int) : List Int := match l.reverse with | [] => [] -- should not happen for n > 1 | last :: revInit => last :: revInit.reverse -- `last` is the original last element -- recursive function to check subsequent shifts -- `shifts_count` is the number of shifts already performed to get `current_list` -- we are checking if `current_list` is sorted let rec checkShifts (shifts_count : Nat) (current_list : List Int) : Int := -- base case: stop recursion if we've checked n-1 shifts (count goes from 1 to n) -- the original list (0 shifts) has already been checked if shifts_count >= n then -1 else -- check if the current state is sorted if isSortedAux current_list then (shifts_count : Int) -- found it after 'shifts_count' shifts else -- recursion: increment shift count, apply next shift checkShifts (shifts_count + 1) (rightShiftOnce current_list) -- specify the decreasing measure for the termination checker: n - shifts_count termination_by n - shifts_count -- start the checking process by performing the first shift and checking subsequent states -- the initial list (0 shifts) hass already been checked and is not sorted checkShifts 1 (rightShiftOnce nums) -- start checking from the state after 1 shift -- !benchmark @end code -- !benchmark @start postcond_aux -- !benchmark @end postcond_aux @[reducible, simp] def minimumRightShifts_postcond (nums : List Int) (result: Int) (h_precond : minimumRightShifts_precond (nums)) : Prop := -- !benchmark @start postcond let n := nums.length let isSorted (l : List Int) := List.Pairwise (· ≤ ·) l let rightShift (k : Nat) (l : List Int) := l.rotateRight k -- specification logic based on the result value if n <= 1 then result = 0 else -- specification for base cases -- case 1: a non-negative result means a solution was found (result ≥ 0 ∧ -- result corresponds to a valid shift count result < n result < n ∧ -- applying result shifts results in a sorted list isSorted (rightShift result.toNat nums) ∧ -- result is the minimum such non-negative shift count (List.range result.toNat |>.all (fun j => ¬ isSorted (rightShift j nums))) ) ∨ -- case 2: result is -1 means no solution exists within n shifts (result = -1 ∧ -- for all possible shift counts k from 0 to n-1, the resulting list is not sorted (List.range n |>.all (fun k => ¬ isSorted (rightShift k nums))) ) -- !benchmark @end postcond -- !benchmark @start proof_aux -- !benchmark @end proof_aux theorem minimumRightShifts_spec_satisfied (nums: List Int) (h_precond : minimumRightShifts_precond (nums)) : minimumRightShifts_postcond (nums) (minimumRightShifts (nums) h_precond) h_precond := by -- !benchmark @start proof sorry -- !benchmark @end proof
{ "name": "minimumRightShifts", "parameters": { "param_name": [ "nums" ], "param_type": [ "List Int" ] }, "return_type": "Int" }
{ "upstream": { "name": "lab_assignment", "link": "", "task_id": "lab_minimumRightShifts_325696322", "student_id": [ 40 ] } }
{ "input": [ "{\"nums\": \"[3, 4, 5, 1, 2]\"}", "{\"nums\": \"[1, 3, 5]\"}", "{\"nums\": \"[2, 1, 4]\"}", "{\"nums\": \"[1]\"}", "{\"nums\": \"[2, 1]\"}", "{\"nums\": \"[1, 2, 3, 4, 5]\"}", "{\"nums\": \"[5, 1, 2, 3, 4]\"}", "{\"nums\": \"[1, 5, 2, 3, 4]\"}" ], "expected": [ [ "2" ], [ "0" ], [ "-1" ], [ "0" ], [ "1" ], [ "0" ], [ "4" ], [ "-1" ] ], "unexpected": [ [ "-1", "4", "5" ], [ "-1", "3" ], [ "0", "2", "3" ], [ "-1", "1" ], [ "-1", "0", "2" ], [ "-1", "1", "5" ], [ "-1", "0", "5" ], [ "0", "1", "5" ] ] }
{ "input": [ "{'nums': '[1, 1]'}" ] }
advanced
verina_advanced_6
-----Description----- This task requires writing a Lean 4 method that determines whether a given string contains all 5 English vowels: a, e, i, o, u. The check is case-insensitive, meaning that both uppercase and lowercase vowels count. -----Input----- The input consists of a string: s: A string of alphabetic characters (may include uppercase and lowercase) -----Output----- The output is true or false: Returns true if the input string contains all 5 vowels (a, e, i, o, u), false otherwise.
-- !benchmark @start import type=solution -- !benchmark @end import -- !benchmark @start solution_aux def toLower (c : Char) : Char := if 'A' ≤ c && c ≤ 'Z' then Char.ofNat (Char.toNat c + 32) else c def normalize_str (s : String) : List Char := s.data.map toLower -- !benchmark @end solution_aux -- !benchmark @start precond_aux -- !benchmark @end precond_aux @[reducible] def allVowels_precond (s : String) : Prop := -- !benchmark @start precond True -- !benchmark @end precond -- !benchmark @start code_aux -- !benchmark @end code_aux def allVowels (s : String) (h_precond : allVowels_precond (s)) : Bool := -- !benchmark @start code let chars := normalize_str s let vowelSet := ['a', 'e', 'i', 'o', 'u'] vowelSet.all (fun v => chars.contains v) -- !benchmark @end code -- !benchmark @start postcond_aux -- !benchmark @end postcond_aux @[reducible] def allVowels_postcond (s : String) (result: Bool) (h_precond : allVowels_precond (s)) : Prop := -- !benchmark @start postcond let chars := normalize_str s (result ↔ List.all ['a', 'e', 'i', 'o', 'u'] (fun v => chars.contains v)) -- !benchmark @end postcond -- !benchmark @start proof_aux -- !benchmark @end proof_aux theorem allVowels_spec_satisfied (s: String) (h_precond : allVowels_precond (s)) : allVowels_postcond (s) (allVowels (s) h_precond) h_precond := by -- !benchmark @start proof sorry -- !benchmark @end proof
{ "name": "allVowels", "parameters": { "param_name": [ "s" ], "param_type": [ "String" ] }, "return_type": "Bool" }
{ "upstream": { "name": "lab_assignment", "link": "https://leetcode.com/problems/check-if-the-sentence-is-prangram/", "task_id": "lab_allVowels_325657053", "student_id": [ 4 ] } }
{ "input": [ "{\"s\": \"education\"}", "{\"s\": \"education123\"}", "{\"s\": \"AEIOU\"}", "{\"s\": \"hello\"}", "{\"s\": \"\"}", "{\"s\": \"apple orange union\"}" ], "expected": [ [ "True" ], [ "True" ], [ "True" ], [ "False" ], [ "False" ], [ "True" ] ], "unexpected": [ [ "False" ], [ "False" ], [ "False" ], [ "True" ], [ "True" ], [ "False" ] ] }
{ "input": [] }
advanced
verina_advanced_37
-----Description----- This task requires writing a Lean 4 method that returns the majority element from a list of integers. The majority element is the one that appears more than ⌊n / 2⌋ times in the list, where n is the list's length. You may assume that a majority element always exists in the input. -----Input----- - nums: A list of integers (with at least one majority element). -----Output----- Returns the majority element — the value that appears more than ⌊n / 2⌋ 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 majorityElement_precond (nums : List Int) : Prop := -- !benchmark @start precond True -- !benchmark @end precond -- !benchmark @start code_aux -- !benchmark @end code_aux def majorityElement (nums : List Int) (h_precond : majorityElement_precond (nums)) : Int := -- !benchmark @start code let rec insert (x : Int) (xs : List Int) : List Int := match xs with | [] => [x] | h :: t => if x ≤ h then x :: h :: t else h :: insert x t let rec insertionSort (xs : List Int) : List Int := match xs with | [] => [] | h :: t => let sortedTail := insertionSort t let sorted := insert h sortedTail sorted let getAt := fun (xs : List Int) (i : Nat) => match xs.drop i with | [] => 0 | h :: _ => h let sorted := insertionSort nums let len := sorted.length let mid := len / 2 getAt sorted mid -- !benchmark @end code -- !benchmark @start postcond_aux -- !benchmark @end postcond_aux @[reducible, simp] def majorityElement_postcond (nums : List Int) (result: Int) (h_precond : majorityElement_precond (nums)) : Prop := -- !benchmark @start postcond let n := nums.length (List.count result nums > n / 2) ∧ nums.all (fun x => x = result ∨ List.count x nums ≤ n / 2) -- !benchmark @end postcond -- !benchmark @start proof_aux -- !benchmark @end proof_aux theorem majorityElement_spec_satisfied (nums: List Int) (h_precond : majorityElement_precond (nums)) : majorityElement_postcond (nums) (majorityElement (nums) h_precond) h_precond := by -- !benchmark @start proof sorry -- !benchmark @end proof
{ "name": "majorityElement", "parameters": { "param_name": [ "nums" ], "param_type": [ "List Int" ] }, "return_type": "Int" }
{ "upstream": { "name": "lab_assignment", "link": "[{\"text_file_id\"=>805208302}]", "task_id": "lab_majorityElement_325759376", "student_id": [ 30 ] } }
{ "input": [ "{\"nums\": \"[3, 2, 3]\"}", "{\"nums\": \"[2, 2, 1, 1, 1, 2, 2]\"}", "{\"nums\": \"[1]\"}", "{\"nums\": \"[4, 4, 4, 4, 4, 2, 2, 3, 3]\"}", "{\"nums\": \"[9, 8, 9, 9, 7, 9, 6, 9, 9]\"}", "{\"nums\": \"[0, 0, 0, 0, 1]\"}", "{\"nums\": \"[100000, 100000, 100000, 100000, -100000]\"}", "{\"nums\": \"[-1, -1, -1, -1, 0, 1, 2]\"}", "{\"nums\": \"[5, 5, 5, 5, 5, 5, 5]\"}", "{\"nums\": \"[1, 2, 3, 3, 3, 3, 3]\"}" ], "expected": [ [ "3" ], [ "2" ], [ "1" ], [ "4" ], [ "9" ], [ "0" ], [ "100000" ], [ "-1" ], [ "5" ], [ "3" ] ], "unexpected": [ [ "2" ], [ "1" ], [ "0" ], [ "2", "3" ], [ "6", "7", "8" ], [ "1" ], [ "-100000" ], [ "0", "1", "2" ], [ "0" ], [ "1", "2" ] ] }
{ "input": [] }
advanced
verina_basic_94
-----Description----- This task involves taking an array as input and producing a new array that has the same size and identical elements in the same order as the input. -----Input----- The input consists of: • s: An array of elements (for testing purposes, assume an array of integers, i.e., Array Int). -----Output----- The output is an array of the same type as the input: • The output array has the same size as the input array. • Each element in the output array is identical to the corresponding element in the input array. -----Note----- There are no special preconditions for the input array (it can be empty or non-empty); the function simply performs a straightforward copy operation on 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 iter_copy_precond (s : Array Int) : Prop := -- !benchmark @start precond True -- !benchmark @end precond -- !benchmark @start code_aux -- !benchmark @end code_aux def iter_copy (s : Array Int) (h_precond : iter_copy_precond (s)) : Array Int := -- !benchmark @start code let rec loop (i : Nat) (acc : Array Int) : Array Int := if i < s.size then match s[i]? with | some val => loop (i + 1) (acc.push val) | none => acc -- This case shouldn't happen when i < s.size else acc loop 0 Array.empty -- !benchmark @end code -- !benchmark @start postcond_aux -- !benchmark @end postcond_aux @[reducible, simp] def iter_copy_postcond (s : Array Int) (result: Array Int) (h_precond : iter_copy_precond (s)) := -- !benchmark @start postcond (s.size = result.size) ∧ (∀ i : Nat, i < s.size → s[i]! = result[i]!) -- !benchmark @end postcond -- !benchmark @start proof_aux -- !benchmark @end proof_aux theorem iter_copy_spec_satisfied (s: Array Int) (h_precond : iter_copy_precond (s)) : iter_copy_postcond (s) (iter_copy (s) h_precond) h_precond := by -- !benchmark @start proof sorry -- !benchmark @end proof
{ "name": "iter_copy", "parameters": { "param_name": [ "s" ], "param_type": [ "Array Int" ] }, "return_type": "Array Int" }
{ "upstream": { "name": "clover", "link": "https://github.com/ChuyueSun/Clover", "task_id": "Clover_array_copy", "student_id": null } }
{ "input": [ "{\"s\": \"#[1, 2, 3]\"}", "{\"s\": \"#[10, 20, 30, 40]\"}", "{\"s\": \"#[]\"}", "{\"s\": \"#[-1, -2, -3]\"}", "{\"s\": \"#[5, 5, 5, 5]\"}" ], "expected": [ [ "#[1, 2, 3]" ], [ "#[10, 20, 30, 40]" ], [ "#[]" ], [ "#[-1, -2, -3]" ], [ "#[5, 5, 5, 5]" ] ], "unexpected": [ [ "#[1, 3, 2]", "#[1, 2]" ], [ "#[10, 20, 30]", "#[10, 20, 40, 30]" ], [ "#[0]", "#[1]" ], [ "#[-1, -3, -2]", "#[-1, -2]" ], [ "#[5, 5, 5]", "#[5, 5, 5, 0]", "#[0, 5, 5, 5]" ] ] }
{ "input": [] }
basic
verina_advanced_50
-----Description----- This task involves merging two sorted arrays of natural numbers (it is ill defined if inputs aren't sorted.) -----Input----- The input consists of two arrays: a1: A sorted array of natural numbers a2: A sorted array of natural numbers -----Output----- The output is an array: Returns a new array with all elements from both input arrays (included once and only once) The resulting array is sorted itself
-- !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 mergeSorted_precond (a1 : Array Nat) (a2 : Array Nat) : Prop := -- !benchmark @start precond List.Pairwise (· ≤ ·) a1.toList ∧ List.Pairwise (· ≤ ·) a2.toList -- !benchmark @end precond -- !benchmark @start code_aux -- !benchmark @end code_aux def mergeSorted (a1 : Array Nat) (a2 : Array Nat) : Array Nat := -- !benchmark @start code Id.run <| do let mut i := 0 let mut j := 0 let mut result := #[] while i < a1.size ∧ j < a2.size do if a1[i]! ≤ a2[j]! then result := result.push a1[i]! i := i + 1 else result := result.push a2[j]! j := j + 1 while i < a1.size do result := result.push a1[i]! i := i + 1 while j < a2.size do result := result.push a2[j]! j := j + 1 return result -- !benchmark @end code -- !benchmark @start postcond_aux -- !benchmark @end postcond_aux @[reducible] def mergeSorted_postcond (a1 : Array Nat) (a2 : Array Nat) (result: Array Nat) : Prop := -- !benchmark @start postcond List.Pairwise (· ≤ ·) result.toList ∧ result.toList.isPerm (a1.toList ++ a2.toList) -- !benchmark @end postcond -- !benchmark @start proof_aux -- !benchmark @end proof_aux theorem mergeSorted_spec_satisfied (a1: Array Nat) (a2: Array Nat) : mergeSorted_postcond (a1) (a2) (mergeSorted (a1) (a2)) := by -- !benchmark @start proof sorry -- !benchmark @end proof
{ "name": "mergeSorted", "parameters": { "param_name": [ "a1", "a2" ], "param_type": [ "Array Nat", "Array Nat" ] }, "return_type": "Array Nat" }
{ "upstream": { "name": "lab_assignment", "link": "https://leetcode.com/problems/merge-sorted-array/description/", "task_id": "lab_mergeSorted_325695851", "student_id": [ 39 ] } }
{ "input": [ "{\"a1\": \"#[1, 3, 5]\", \"a2\": \"#[2, 4, 6]\"}", "{\"a1\": \"#[]\", \"a2\": \"#[1, 2, 3]\"}", "{\"a1\": \"#[1, 2, 3]\", \"a2\": \"#[]\"}", "{\"a1\": \"#[]\", \"a2\": \"#[]\"}", "{\"a1\": \"#[1, 1, 2]\", \"a2\": \"#[1, 2, 2]\"}", "{\"a1\": \"#[10, 20, 30]\", \"a2\": \"#[5, 15, 25]\"}", "{\"a1\": \"#[1, 3, 5, 7, 9]\", \"a2\": \"#[2, 4, 6, 8, 10]\"}", "{\"a1\": \"#[5, 5, 5]\", \"a2\": \"#[5, 5, 5]\"}" ], "expected": [ [ "#[1, 2, 3, 4, 5, 6]" ], [ "#[1, 2, 3]" ], [ "#[1, 2, 3]" ], [ "#[]" ], [ "#[1, 1, 1, 2, 2, 2]" ], [ "#[5, 10, 15, 20, 25, 30]" ], [ "#[1, 2, 3, 4, 5, 6, 7, 8, 9, 10]" ], [ "#[5, 5, 5, 5, 5, 5]" ] ], "unexpected": [ [ "#[1, 3, 5, 2, 4, 6]", "#[2, 1, 3, 4, 5, 6]" ], [ "#[]", "#[3, 2, 1]" ], [ "#[]", "#[3, 2, 1]" ], [ "#[1]" ], [ "#[1, 1, 2, 1, 2, 2]", "#[1, 2]" ], [ "#[10, 20, 30, 5, 15, 25]" ], [ "#[1, 3, 5, 7, 9, 2, 4, 6, 8, 10]" ], [ "#[5, 5, 5]" ] ] }
{ "input": [ "{'a1': '#[3, 2, 1]', 'a2': '#[6, 5, 4]'}" ] }
advanced
verina_basic_16
-----Description----- This task requires writing a Lean 4 method that replaces every occurrence of a specified character within a string with a new character. The output should be a new string that maintains the same length as the input string, with all instances of the designated character replaced by the given substitute, and all other characters preserved unchanged. -----Input----- The input consists of: s: A string in which the replacement will occur. oldChar: The character within the string that needs to be replaced. newChar: The character that will substitute for every occurrence of oldChar. -----Output----- The output is a string that meets the following: - It has the same length as the input string. - All occurrences of oldChar in the input string are replaced with newChar. - All characters other than oldChar remain unchanged. -----Note----- There are no preconditions; the method will always work. It is assumed that the input string is valid and 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 replaceChars_precond (s : String) (oldChar : Char) (newChar : Char) : Prop := -- !benchmark @start precond True -- !benchmark @end precond -- !benchmark @start code_aux -- !benchmark @end code_aux def replaceChars (s : String) (oldChar : Char) (newChar : Char) (h_precond : replaceChars_precond (s) (oldChar) (newChar)) : String := -- !benchmark @start code let cs := s.toList let cs' := cs.map (fun c => if c = oldChar then newChar else c) String.mk cs' -- !benchmark @end code -- !benchmark @start postcond_aux -- !benchmark @end postcond_aux @[reducible, simp] def replaceChars_postcond (s : String) (oldChar : Char) (newChar : Char) (result: String) (h_precond : replaceChars_precond (s) (oldChar) (newChar)) := -- !benchmark @start postcond let cs := s.toList let cs' := result.toList result.length = s.length ∧ (∀ i, i < cs.length → (cs[i]! = oldChar → cs'[i]! = newChar) ∧ (cs[i]! ≠ oldChar → cs'[i]! = cs[i]!)) -- !benchmark @end postcond -- !benchmark @start proof_aux -- !benchmark @end proof_aux theorem replaceChars_spec_satisfied (s: String) (oldChar: Char) (newChar: Char) (h_precond : replaceChars_precond (s) (oldChar) (newChar)) : replaceChars_postcond (s) (oldChar) (newChar) (replaceChars (s) (oldChar) (newChar) h_precond) h_precond := by -- !benchmark @start proof -- Unfold the definitions of replaceChars and replaceChars_postcond unfold replaceChars replaceChars_postcond -- Split the goal into two parts constructor · -- First part: length is preserved simp [String.length] · -- Second part: character replacement specification simp_all -- !benchmark @end proof
{ "name": "replaceChars", "parameters": { "param_name": [ "s", "oldChar", "newChar" ], "param_type": [ "String", "Char", "Char" ] }, "return_type": "String" }
{ "upstream": { "name": "dafny-synthesis", "link": "https://github.com/Mondego/dafny-synthesis", "task_id": "task_id_474", "student_id": null } }
{ "input": [ "{\"s\": \"hello, world!\", \"oldChar\": \",\", \"newChar\": \";\"}", "{\"s\": \"a,b.c\", \"oldChar\": \",\", \"newChar\": \":\"}", "{\"s\": \"hello, world!\", \"oldChar\": \"o\", \"newChar\": \"O\"}", "{\"s\": \"\", \"oldChar\": \"x\", \"newChar\": \"y\"}", "{\"s\": \"test\", \"oldChar\": \"x\", \"newChar\": \"y\"}", "{\"s\": \"unchanged\", \"oldChar\": \"u\", \"newChar\": \"u\"}", "{\"s\": \"aaa\", \"oldChar\": \"a\", \"newChar\": \"b\"}" ], "expected": [ [ "hello; world!" ], [ "a:b.c" ], [ "hellO, wOrld!" ], [ "" ], [ "test" ], [ "unchanged" ], [ "bbb" ] ], "unexpected": [ [ "hello, world!", "hello world!", "hello;world!" ], [ "a,b.c", "a;b.c", "ab:c" ], [ "hello, world!", "hellO, world!", "hello, wOrld!" ], [ " ", "abc" ], [ "testy", "tset", "yxest" ], [ "nchanged", "unchanged!", "unchangEd" ], [ "aaa", "abb", "bba" ] ] }
{ "input": [] }
basic
verina_basic_102
-----Description----- This task involves identifying the first occurrence of a pair of indices in an array of integers such that the sum of the corresponding elements equals the given target value. The focus is on determining the earliest valid pair (i, j), with 0 ≤ i < j < nums.size, where the sum of the two numbers equals the target, without considering any language-specific or implementation details. -----Input----- The input consists of: • nums: An array of integers. • target: An integer representing the desired sum. -----Output----- The output is a pair of natural numbers (i, j) that satisfy: • 0 ≤ i < j < nums.size. • nums[i] + nums[j] = target. • Any valid pair with indices preceding (i, j) does not yield the target sum, and no index between i and j forms a valid sum with nums[i]. -----Note----- It is assumed that the array has at least two elements and that there exists at least one valid pair whose sum is equal 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, simp] def twoSum_precond (nums : Array Int) (target : Int) : Prop := -- !benchmark @start precond nums.size > 1 ∧ ¬ List.Pairwise (fun a b => a + b ≠ target) nums.toList -- !benchmark @end precond -- !benchmark @start code_aux -- !benchmark @end code_aux def twoSum (nums : Array Int) (target : Int) (h_precond : twoSum_precond (nums) (target)) : (Nat × Nat) := -- !benchmark @start code let n := nums.size let rec outer (i : Nat) : Option (Nat × Nat) := if i < n - 1 then let rec inner (j : Nat) : Option (Nat × Nat) := if j < n then if nums[i]! + nums[j]! = target then some (i, j) else inner (j + 1) else none match inner (i + 1) with | some pair => some pair | none => outer (i + 1) else none match outer 0 with | some pair => pair | none => panic "twoSum: no solution found" -- !benchmark @end code -- !benchmark @start postcond_aux -- !benchmark @end postcond_aux @[reducible, simp] def twoSum_postcond (nums : Array Int) (target : Int) (result: (Nat × Nat)) (h_precond : twoSum_precond (nums) (target)) := -- !benchmark @start postcond let (i, j) := result -- two sum holds i < j ∧ j < nums.size ∧ nums[i]! + nums[j]! = target ∧ -- i must be the first i List.Pairwise (fun a b => a + b ≠ target) (nums.toList.take i) ∧ List.all (nums.toList.take i) (fun a => List.all (nums.toList.drop i) (fun b => a + b ≠ target) ) ∧ -- j must be the first j List.all (nums.toList.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: Array 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": [ "Array Int", "Int" ] }, "return_type": "(Nat × Nat)" }
{ "upstream": { "name": "clover", "link": "https://github.com/ChuyueSun/Clover", "task_id": "Clover_two_sum", "student_id": null } }
{ "input": [ "{\"nums\": \"#[2, 7, 11, 15]\", \"target\": 9}", "{\"nums\": \"#[3, 2, 4]\", \"target\": 6}", "{\"nums\": \"#[-1, 0, 1, 2]\", \"target\": 1}", "{\"nums\": \"#[5, 75, 25]\", \"target\": 100}", "{\"nums\": \"#[1, 2, 3, 4, 5]\", \"target\": 9}" ], "expected": [ [ "(0, 1)" ], [ "(1, 2)" ], [ "(0, 3)" ], [ "(1, 2)" ], [ "(3, 4)" ] ], "unexpected": [ [ "(0, 2)", "(1, 3)" ], [ "(0, 2)", "(0, 1)" ], [ "(1, 2)", "(2, 3)" ], [ "(0, 2)", "(0, 1)" ], [ "(2, 4)", "(1, 3)" ] ] }
{ "input": [ "{'nums': '#[1]', 'target': 11}" ] }
basic
verina_advanced_25
-----Description----- This task requires implementing a Lean 4 method that finds the length of the longest strictly increasing subsequence in an array of integers. A subsequence is a sequence that can be derived from an array by deleting some or no elements without changing the order of the remaining elements. -----Input----- The input consists of one parameter: nums: A list of integers representing the input array. -----Output----- The output is an integer: Returns the length of the longest strictly increasing subsequence in the input array.
-- !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 lengthOfLIS_precond (nums : List Int) : Prop := -- !benchmark @start precond True -- !benchmark @end precond -- !benchmark @start code_aux def maxInArray (arr : Array Nat) : Nat := arr.foldl (fun a b => if a ≥ b then a else b) 0 -- !benchmark @end code_aux def lengthOfLIS (nums : List Int) (h_precond : lengthOfLIS_precond (nums)) : Nat := -- !benchmark @start code if nums.isEmpty then 0 else let n := nums.length Id.run do let mut dp : Array Nat := Array.mkArray n 1 for i in [1:n] do for j in [0:i] do if nums[j]! < nums[i]! && dp[j]! + 1 > dp[i]! then dp := dp.set! i (dp[j]! + 1) maxInArray dp -- !benchmark @end code -- !benchmark @start postcond_aux -- !benchmark @end postcond_aux @[reducible] def lengthOfLIS_postcond (nums : List Int) (result: Nat) (h_precond : lengthOfLIS_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 lengthOfLIS_spec_satisfied (nums: List Int) (h_precond : lengthOfLIS_precond (nums)) : lengthOfLIS_postcond (nums) (lengthOfLIS (nums) h_precond) h_precond := by -- !benchmark @start proof sorry -- !benchmark @end proof
{ "name": "lengthOfLIS", "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_lengthOfLIS_325743927", "student_id": [ 19 ] } }
{ "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\": \"[]\"}", "{\"nums\": \"[4, 10, 4, 3, 8, 9]\"}", "{\"nums\": \"[1, 3, 6, 7, 9, 4, 10, 5, 6]\"}", "{\"nums\": \"[10, 22, 9, 33, 21, 50, 41, 60, 80]\"}", "{\"nums\": \"[0, 8, 4, 12, 2, 10, 6, 14, 1, 9, 5, 13, 3, 11, 7, 15]\"}", "{\"nums\": \"[-2, -1]\"}" ], "expected": [ [ "4" ], [ "4" ], [ "1" ], [ "0" ], [ "3" ], [ "6" ], [ "6" ], [ "6" ], [ "2" ] ], "unexpected": [ [ "3", "5", "8" ], [ "3", "5" ], [ "0", "7" ], [ "1" ], [ "2", "4", "6" ], [ "5", "7", "9" ], [ "5", "7", "9" ], [ "5", "7", "16" ], [ "1", "0" ] ] }
{ "input": [] }
advanced
verina_basic_9
-----Description----- This task requires writing a Lean 4 method that checks whether two arrays of integers have any elements in common. In other words, the method should return true if there is at least one element that appears in both arrays, and false if no such element exists. -----Input----- The input consists of: a: An array of integers. b: An array of integers. -----Output----- The output is a Boolean value: Returns true if there is at least one common element between the two arrays. Returns false if there are no common elements shared by the arrays. -----Note----- Both arrays are 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 hasCommonElement_precond (a : Array Int) (b : Array Int) : Prop := -- !benchmark @start precond a.size > 0 ∧ b.size > 0 -- !benchmark @end precond -- !benchmark @start code_aux -- !benchmark @end code_aux def hasCommonElement (a : Array Int) (b : Array Int) (h_precond : hasCommonElement_precond (a) (b)) : Bool := -- !benchmark @start code a.any fun x => b.any fun y => x = y -- !benchmark @end code -- !benchmark @start postcond_aux -- !benchmark @end postcond_aux @[reducible, simp] def hasCommonElement_postcond (a : Array Int) (b : Array Int) (result: Bool) (h_precond : hasCommonElement_precond (a) (b)) := -- !benchmark @start postcond (∃ i j, i < a.size ∧ j < b.size ∧ a[i]! = b[j]!) ↔ result -- !benchmark @end postcond -- !benchmark @start proof_aux -- !benchmark @end proof_aux theorem hasCommonElement_spec_satisfied (a: Array Int) (b: Array Int) (h_precond : hasCommonElement_precond (a) (b)) : hasCommonElement_postcond (a) (b) (hasCommonElement (a) (b) h_precond) h_precond := by -- !benchmark @start proof unfold hasCommonElement hasCommonElement_postcond constructor · intro h rcases h with ⟨i, j, hi, hj, heq⟩ simp [Array.any_eq] exists i exists hi exists j exists hj have heqa : a[i]! = a[i] := by exact getElem!_pos a i hi have heqb : b[j]! = b[j] := by exact getElem!_pos b j hj rw [heqa, heqb] at heq exact heq · intro h simp [Array.any_eq] at h rcases h with ⟨i, hi, j, hj, heq⟩ exists i exists j simp [hi, hj] have heqa : a[i]! = a[i] := by exact getElem!_pos a i hi have heqb : b[j]! = b[j] := by exact getElem!_pos b j hj rw [heqa, heqb] exact heq -- !benchmark @end proof
{ "name": "hasCommonElement", "parameters": { "param_name": [ "a", "b" ], "param_type": [ "Array Int", "Array Int" ] }, "return_type": "Bool" }
{ "upstream": { "name": "dafny-synthesis", "link": "https://github.com/Mondego/dafny-synthesis", "task_id": "task_id_431", "student_id": null } }
{ "input": [ "{\"a\": \"#[1, 2, 3]\", \"b\": \"#[4, 5, 6]\"}", "{\"a\": \"#[1, 2, 3]\", \"b\": \"#[3, 4, 5]\"}", "{\"a\": \"#[7, 8, 9]\", \"b\": \"#[10, 11, 7]\"}", "{\"a\": \"#[1, 2, 3, 4]\", \"b\": \"#[5, 6, 7, 8]\"}", "{\"a\": \"#[1, 2, 3, 4]\", \"b\": \"#[4, 5, 6]\"}", "{\"a\": \"#[1, 1, 1]\", \"b\": \"#[1, 2, 1]\"}", "{\"a\": \"#[0]\", \"b\": \"#[0]\"}", "{\"a\": \"#[0]\", \"b\": \"#[-1, 1]\"}" ], "expected": [ [ "False" ], [ "True" ], [ "True" ], [ "False" ], [ "True" ], [ "True" ], [ "True" ], [ "False" ] ], "unexpected": [ [ "True" ], [ "False" ], [ "False" ], [ "True" ], [ "False" ], [ "False" ], [ "False" ], [ "True" ] ] }
{ "input": [ "{'a': '#[]', 'b': '#[]'}" ] }
basic