Dataset Viewer
Auto-converted to Parquet Duplicate
function_signature
stringlengths
15
86
docstring
stringlengths
23
1.07k
test_cases
stringlengths
36
501
problem_spec_nl
stringlengths
59
1.14k
problem_spec_formal_ground_truth
stringlengths
229
1.39k
problem_spec_formal_generated
stringlengths
87
156
isomorphism_theorem
stringlengths
94
188
isomorphism_proof
stringclasses
1 value
implementation_signature
stringlengths
36
77
implementation
stringlengths
5
942
test_cases_lean
stringlengths
27
566
correctness_theorem
stringlengths
63
121
correctness_proof
stringlengths
5
5.72k
helper_definitions
stringclasses
11 values
isomorphism_helper_lemmas
float64
correctness_helper_lemmas
float64
def has_close_elements(numbers: List[float], threshold: float) -> bool
Check if in given list of numbers, are any two numbers closer to each other than given threshold.
[{"input": [[1.0, 2.0, 3.0], 0.5], "expected_output": false}, {"input": [[1.0, 2.8, 3.0, 4.0, 5.0, 2.0], 0.3], "expected_output": true}]
def has_close_elements(numbers: List[float], threshold: float) -> bool """Check if in given list of numbers, are any two numbers closer to each other than given threshold."""
def problem_spec -- function signature (impl: List Rat β†’ Rat β†’ Bool) -- inputs (numbers: List Rat) (threshold: Rat) := -- spec let numbers_within_threshold := (βˆƒ i j, i < numbers.length ∧ j < numbers.length ∧ i β‰  j ∧ |numbers.get! i - numbers.get! j| < threshold); let spec (res: Bool) := numbers.length > 1 β†’ if res the...
def generated_spec -- function signature (impl: List Rat β†’ Rat β†’ Bool) -- inputs (numbers: List Rat) (threshold: Rat) : Prop :=
theorem spec_isomorphism: βˆ€ impl, (βˆ€ numbers threshold, problem_spec impl numbers threshold) ↔ (βˆ€ numbers threshold, generated_spec impl numbers threshold) :=
sorry
def implementation (numbers: List Rat) (threshold: Rat) : Bool :=
match numbers with | [] => false | (x::xs) => (xs.any (fun y => (|x - y| < threshold))) || implementation xs threshold
#test implementation ([1, 2, 3]: List Rat) 0.5 = false #test implementation ([1, 2.8, 3, 4, 5, 2]: List Rat) 0.3 = true
theorem correctness (numbers: List Rat) (threshold: Rat) : problem_spec implementation numbers threshold :=
by unfold problem_spec let result := implementation numbers threshold use result simp [result] induction numbers simp [implementation] rename_i head tail ih simp at * by_cases result = false rename_i h_result_false simp [result] at h_result_false simp [h_result_false] simp [implementation] at h_result_false have h_tail...
null
null
null
def separate_paren_groups(paren_string: str) -> List[str]
Input to this function is a string containing multiple groups of nested parentheses. Your goal is to separate those group into separate strings and return the list of those. Separate groups are balanced (each open brace is properly closed) and not nested within each other Ignore any spaces in the input string.
[{"input": "( ) (( )) (( )( ))", "expected_output": ["()", "(())", "(()())"]}]
def separate_paren_groups(paren_string: str) -> List[str] """Input to this function is a string containing multiple groups of nested parentheses. Your goal is to separate those group into separate strings and return the list of those. Separate groups are balanced (each open brace is properly closed) and not nested with...
def problem_spec -- function signature (impl: String β†’ List String) -- inputs (paren_string: String) := -- spec let paren_string_filtered := (paren_string.toList.filter (fun c => c == '(' ∨ c == ')')).asString; let forward_spec (result_list: List String) := -- every substring of the input string -- that is a balanced ...
def generated_spec -- function signature (impl: String β†’ List String) -- inputs (paren_string: String) : Prop :=
theorem spec_isomorphism: βˆ€ impl, (βˆ€ paren_string, problem_spec impl paren_string) ↔ (βˆ€ paren_string, generated_spec impl paren_string) :=
sorry
def implementation (paren_string: String) : List String :=
-- remove space or any other characters that are not '(' or ')' let filtered := paren_string.toList.filter (fun c => c == '(' ∨ c == ')'); -- auxiliary recursive function: let rec aux (cs : List Char) (cur : List Char) (balance : Int) (acc : List String) : List String := match cs with | [] => acc.reverse -- ...
#test implementation "( ) (( )) (( )( ))" = ["()", "(())", "(()())"]
theorem correctness (paren_string: String) : problem_spec implementation paren_string :=
by unfold problem_spec let result := implementation paren_string use result simp [result] sorry
/-- name: string_is_paren_balanced_helper use: | Helper function to check if a string is balanced with respect to parentheses. problems: - 1 - 6 - 132 sample_problems: - 0 -/ def string_is_paren_balanced_helper (paren_string: String) (num_open: Int): Bool := -- Recursively check if the string is balanced if p...
null
null
def truncate_number(number: float) -> float
Given a positive floating point number, it can be decomposed into and integer part (largest integer smaller than given number) and decimals (leftover part always smaller than 1).
[{"input": 3.5, "expected_output": 0.5}]
def truncate_number(number: float) -> float """Given a positive floating point number, it can be decomposed into and integer part (largest integer smaller than given number) and decimals (leftover part always smaller than 1). """
def problem_spec -- function signature (impl: Rat β†’ Rat) -- inputs (number: Rat) := -- spec let spec (res) := 0 ≀ res ∧ res < 1 ∧ number.floor + res = number; number > 0 β†’ -- program terminates (βˆƒ result, impl number = result ∧ -- return value satisfies spec spec result)
def generated_spec -- function signature (impl: Rat β†’ Rat) -- inputs (number: Rat) : Prop :=
theorem spec_isomorphism: βˆ€ impl, (βˆ€ number, problem_spec impl number) ↔ (βˆ€ number, generated_spec impl number) :=
sorry
def implementation (number: Rat) : Rat :=
number - number.floor
#test implementation 3.5 = 0.5
theorem correctness (number: Rat) : problem_spec implementation number :=
by unfold problem_spec let result := implementation number simp [result] simp [implementation] have h1: βˆ€ x: Rat, x.floor ≀ x := by intro x rw [←Rat.le_floor] intro npos apply And.intro apply h1 have h2 := h1 number sorry
null
null
null
def below_zero(operations: List[int]) -> bool
You're given a list of deposit and withdrawal operations on a bank account that starts with zero balance. Your task is to detect if at any point the balance of account fallls below zero, and at that point function should return True. Otherwise it should return False.
[{"input": [1, 2, 3], "expected_output": false}, {"input": [1, 2, -4, 5], "expected_output": true}]
def below_zero(operations: List[int]) -> bool """You're given a list of deposit and withdrawal operations on a bank account that starts with zero balance. Your task is to detect if at any point the balance of account fallls below zero, and at that point function should return True. Otherwise it should return False. """
def problem_spec -- function signature (impl: List Int β†’ Bool) -- inputs (operations: List Int) := -- spec let below_zero_condition := βˆƒ i, i ≀ operations.length ∧ (operations.take i).sum < 0; let spec (result: Bool) := if result then below_zero_condition else Β¬below_zero_condition; -- program terminates βˆƒ result, impl...
def generated_spec -- function signature (impl: List Int β†’ Bool) -- inputs (operations: List Int) : Prop :=
theorem spec_isomorphism: βˆ€ impl, (βˆ€ operations, problem_spec impl operations) ↔ (βˆ€ operations, generated_spec impl operations) :=
sorry
def implementation (operations: List Int) : Bool :=
let rec check (ops : List Int) (acc : Int) : Bool := match ops with | [] => false | op :: ops' => let new_acc := acc + op if new_acc < 0 then true else check ops' new_acc check operations 0
#test implementation [1, 2, 3] = false #test implementation [1, 2, -4, 5] = true
theorem correctness (operations: List Int) : problem_spec implementation operations :=
by -- sometimes we have to create a temporary variable to use in the proof unfold problem_spec let result := implementation operations use result simp [result] simp [implementation] -- induction at this point will not work -- because the induction hypothesis is not strong enough -- we need to prove a stronger inductive...
null
null
null
def mean_absolute_deviation(numbers: List[float]) -> float
For a given list of input numbers, calculate Mean Absolute Deviation around the mean of this dataset. Mean Absolute Deviation is the average absolute difference between each element and a centerpoint (mean in this case): MAD = average | x - x_mean |
[{"input": [1.0, 2.0, 3.0, 4.0], "expected_output": 1.0}]
def mean_absolute_deviation(numbers: List[float]) -> float """For a given list of input numbers, calculate Mean Absolute Deviation around the mean of this dataset. Mean Absolute Deviation is the average absolute difference between each element and a centerpoint (mean in this case): MAD = average | x - x_mean | """
def problem_spec -- function signature (implementation: List Rat β†’ Rat) -- inputs (numbers: List Rat) := -- spec let spec (result: Rat):= 0 < numbers.length β†’ 0 ≀ result ∧ result * numbers.length * numbers.length = (numbers.map (fun x => |x * numbers.length - numbers.sum|)).sum; -- program terminates βˆƒ result, implemen...
def generated_spec -- function signature (implementation: List Rat β†’ Rat) -- inputs (numbers: List Rat) : Prop :=
theorem spec_isomorphism: βˆ€ implementation, (βˆ€ numbers, problem_spec implementation numbers) ↔ (βˆ€ numbers, generated_spec implementation numbers) :=
sorry
def implementation (numbers: List Rat) : Rat :=
if numbers.length = 0 then 1.0 else let mean := numbers.sum / numbers.length; let abs_diffs := numbers.map (fun x => |x - mean|); abs_diffs.sum / abs_diffs.length
#test implementation [1.0, 2.0, 3.0, 4.0] = 1.0
theorem correctness (numbers: List Rat) : problem_spec implementation numbers :=
by -- sometimes we have to create a temporary variable to use in the proof unfold problem_spec let result := implementation numbers use result simp [result] simp [implementation] by_cases (numbers.length = 0) rename_i h simp [h] rename_i h simp at h have h1: 0 < numbers.length := by by_contra rename_i h2 simp at ...
null
null
null
def intersperse(numbers: List[int], delimeter: int) -> List[int]
Insert a number 'delimeter' between every two consecutive elements of input list `numbers'
[{"input": [[], 4], "expected_output": []}, {"input": [[1, 2, 3], 4], "expected_output": [1, 4, 2, 4, 3]}]
def intersperse(numbers: List[int], delimeter: int) -> List[int] """Insert a number 'delimeter' between every two consecutive elements of input list `numbers' """
def problem_spec -- function signature (implementation: List Int β†’ Int β†’ List Int) -- inputs (numbers: List Int) (delimeter: Int) := -- spec let spec (result: List Int) := (result.length = 0 ∧ result = numbers) ∨ (result.length = 2 ∧ numbers.length = 1 ∧ result[0]! = numbers[0]! ∧ result[1]! = delimeter) ∨ (result.leng...
def generated_spec -- function signature (implementation: List Int β†’ Int β†’ List Int) -- inputs (numbers: List Int) (delimeter: Int) : Prop :=
theorem spec_isomorphism: βˆ€ implementation, (βˆ€ numbers delimeter, problem_spec implementation numbers delimeter) ↔ (βˆ€ numbers delimeter, generated_spec implementation numbers delimeter) :=
sorry
def implementation (numbers: List Int) (delimeter: Int) : List Int :=
numbers.intersperse delimeter
#test implementation [1, 2, 3] 4 = [1, 4, 2, 4, 3] #test implementation [] 4 = [] #test implementation [1] 4 = [1]
theorem correctness (numbers: List Int) (delimeter: Int) : problem_spec implementation numbers delimeter :=
by unfold problem_spec let result := implementation numbers delimeter use result simp [result] sorry
null
null
null
def parse_nested_parens(paren_string: str) -> List[int]
Input to this function is a string represented multiple groups for nested parentheses separated by spaces. For each of the group, output the deepest level of nesting of parentheses. E.g. (()()) has maximum two levels of nesting while ((())) has three.
[{"input": "(()()) ((())) () ((())()())", "expected_output": [2, 3, 1, 3]}]
def parse_nested_parens(paren_string: str) -> List[int] """Input to this function is a string represented multiple groups for nested parentheses separated by spaces. For each of the group, output the deepest level of nesting of parentheses. E.g. (()()) has maximum two levels of nesting while ((())) has three. """
def problem_spec -- function signature (implementation: String β†’ List Int) -- inputs (paren_string: String) := -- spec let spec (result: List Int) := let paren_space_split := paren_string.split (fun x => x = ' '); result.length = paren_space_split.length ∧ βˆ€ i, i < result.length β†’ let group := paren_space_split[i]!; ba...
def generated_spec -- function signature (implementation: String β†’ List Int) -- inputs (paren_string: String) : Prop :=
theorem spec_isomorphism: βˆ€ implementation, (βˆ€ paren_string, problem_spec implementation paren_string) ↔ (βˆ€ paren_string, generated_spec implementation paren_string) :=
sorry
def implementation (paren_string: String) : List Int :=
(paren_string.split (fun x => x = ' ')).map (fun x => count_max_paren_depth x)
#test implementation "(()()) ((())) () ((())()())" = [2, 3, 1, 3]
theorem correctness (paren_string: String) : problem_spec implementation paren_string :=
by unfold problem_spec let result := implementation paren_string use result simp [result] sorry
/-- name: string_is_paren_balanced_helper use: | Helper function to check if a string is balanced with respect to parentheses. problems: - 1 - 6 - 132 sample_problems: - 0 -/ def string_is_paren_balanced_helper (paren_string: String) (num_open: Int): Bool := -- Recursively check if the string is balanced if p...
null
null
def filter_by_substring(strings: List[str], substring: str) -> List[str]
Filter an input list of strings only for ones that contain given substring
[{"input": [[], "a"], "expected_output": []}, {"input": [["abc", "bacd", "cde", "array"], "a"], "expected_output": ["abc", "bacd", "array"]}]
def filter_by_substring(strings: List[str], substring: str) -> List[str] """Filter an input list of strings only for ones that contain given substring """
def problem_spec -- function signature (implementation: List String β†’ String β†’ List String) -- inputs (strings: List String) (substring: String) := -- spec let spec (result: List String) := (βˆ€ i, i < result.length β†’ result[i]!.containsSubstr substring β†’ βˆ€ j, j < strings.length ∧ strings[j]!.containsSubstr substring β†’ s...
def generated_spec -- function signature (implementation: List String β†’ String β†’ List String) -- inputs (strings: List String) (substring: String) : Prop :=
theorem spec_isomorphism: βˆ€ implementation, (βˆ€ strings substring, problem_spec implementation strings substring) ↔ (βˆ€ strings substring, generated_spec implementation strings substring) :=
sorry
def implementation (strings: List String) (substring: String): List String :=
strings.filter (fun x => x.containsSubstr substring)
#test implementation [] "a" = [] #test implementation ["abc", "bacd", "cde", "array"] "a" = ["abc", "bacd", "array"]
theorem correctness (strings: List String) (substring: String) : problem_spec implementation strings substring :=
by unfold problem_spec let result := implementation strings substring use result simp [result] sorry
null
null
null
def sum_product(numbers: List[int]) -> Tuple[int, int]
For a given list of integers, return a tuple consisting of a sum and a product of all the integers in a list. Empty sum should be equal to 0 and empty product should be equal to 1.
[{"input": [], "expected_output": "(0, 1)"}, {"input": [1, 2, 3, 4], "expected_output": "(10, 24)"}]
def sum_product(numbers: List[int]) -> Tuple[int, int] """For a given list of integers, return a tuple consisting of a sum and a product of all the integers in a list. Empty sum should be equal to 0 and empty product should be equal to 1. """
def problem_spec -- function signature (implementation: List Int β†’ (Int Γ— Int)) -- inputs (numbers: List Int) := -- spec let spec (result: (Int Γ— Int)) := let (sum, prod) := result; (numbers = [] β†’ sum = 0 ∧ prod = 1) ∧ (numbers β‰  [] β†’ (let (sum_tail, prod_tail) := implementation numbers.tail; sum - sum_tail = numbers[...
def generated_spec -- function signature (implementation: List Int β†’ (Int Γ— Int)) -- inputs (numbers: List Int) : Prop :=
theorem spec_isomorphism: βˆ€ implementation, (βˆ€ numbers, problem_spec implementation numbers) ↔ (βˆ€ numbers, generated_spec implementation numbers) :=
sorry
def implementation (numbers: List Int) : (Int Γ— Int) :=
(numbers.sum, numbers.prod)
#test implementation [] = (0, 1) #test implementation [1, 2, 3, 4] = (10, 24)
theorem correctness (numbers: List Int) : problem_spec implementation numbers :=
by unfold problem_spec let result := implementation numbers use result simp [result] simp [implementation] sorry
null
null
null
def sum_product(numbers: List[int]) -> Tuple[int, int]
From a given list of integers, generate a list of rolling maximum element found until given moment in the sequence.
[{"input": [1, 2, 3, 2, 3, 4, 2], "expected_output": [1, 2, 3, 3, 3, 4, 4]}]
def sum_product(numbers: List[int]) -> Tuple[int, int] """From a given list of integers, generate a list of rolling maximum element found until given moment in the sequence. """
def problem_spec -- function signature (implementation: List Int β†’ List Int) -- inputs (numbers: List Int) := -- spec let spec (result: List Int) := result.length = numbers.length ∧ βˆ€ i, i < numbers.length β†’ (result[i]! ∈ numbers.take (i + 1) ∧ βˆ€ j, j ≀ i β†’ numbers[j]! ≀ result[i]!); -- program termination βˆƒ result, im...
def generated_spec -- function signature (implementation: List Int β†’ List Int) -- inputs (numbers: List Int) : Prop :=
theorem spec_isomorphism: βˆ€ implementation, (βˆ€ numbers, problem_spec implementation numbers) ↔ (βˆ€ numbers, generated_spec implementation numbers) :=
sorry
def implementation (numbers: List Int) : List Int :=
let rec rolling_max (numbers: List Int) (results: List Int) (acc: Int) : List Int := match numbers with | [] => results | n :: ns => let new_acc := max acc n let new_results := results ++ [new_acc] rolling_max ns new_results new_acc rolling_max numbers [] 0
#test implementation [1, 2, 3, 2, 3, 4, 2] = [1, 2, 3, 3, 3, 4, 4]
theorem correctness (numbers: List Int) : problem_spec implementation numbers :=
by unfold problem_spec let result := implementation numbers use result simp [result] simp [implementation] apply And.intro induction numbers simp simp [implementation.rolling_max] rename_i head tail ih unfold implementation.rolling_max simp -- At this point we will have to -- strengthen the induction hypothesis -- to p...
null
null
null
def make_palindrome(string: str) -> str
Find the shortest palindrome that begins with a supplied string. Algorithm idea is simple: - Find the longest postfix of supplied string that is a palindrome. - Append to the end of the string reverse of a string prefix that comes before the palindromic suffix.
[{"input": "", "expected_output": ""}, {"input": "cat", "expected_output": "catac"}, {"input": "cata", "expected_output": "catac"}]
def make_palindrome(string: str) -> str """Find the shortest palindrome that begins with a supplied string. Algorithm idea is simple: - Find the longest postfix of supplied string that is a palindrome. - Append to the end of the string reverse of a string prefix that comes before the palindromic suffix. """
def problem_spec -- function signature (implementation: String β†’ String) -- inputs (string: String) := -- spec let spec (result: String) := is_palindrome result ∧ result.length β‰₯ string.length ∧ string.isPrefixOf result ∧ -- comprehensive check that the result is the shortest palindrome (βˆ€ (possible_palindrome: String)...
def generated_spec -- function signature (implementation: String β†’ String) -- inputs (string: String) : Prop :=
theorem spec_isomorphism: βˆ€ implementation, (βˆ€ string, problem_spec implementation string) ↔ (βˆ€ string, generated_spec implementation string) :=
sorry
def implementation (string: String) : String :=
sorry
-- #test implementation "" = "" -- #test implementation "cat" = "catac" -- #test implementation "cata" = "catac"
theorem correctness (s: String) : problem_spec implementation s :=
by unfold problem_spec let result := implementation s use result simp [result] sorry
/-- name: is_palindrome use: | Helper to check if a string is a palindrome. problems: - 10 - 48 -/ def is_palindrome (s: String): Bool := s = s.toList.reverse.asString
null
null
def string_xor(a: str, b: str) -> str
Input are two strings a and b consisting only of 1s and 0s. Perform binary XOR on these inputs and return result also as a string.
[{"input": ["010", "110"], "expected_output": "100"}]
def string_xor(a: str, b: str) -> str """Input are two strings a and b consisting only of 1s and 0s. Perform binary XOR on these inputs and return result also as a string. """
def problem_spec -- function signature (implementation: String β†’ String β†’ String) -- inputs (a b: String) := -- spec let spec (result: String) := a.all (fun c => c = '0' ∨ c = '1') β†’ b.all (fun c => c = '0' ∨ c = '1') β†’ a.length = b.length β†’ result.length = a.length ∧ result.all (fun c => c = '0' ∨ c = '1') ∧...
def generated_spec -- function signature (implementation: String β†’ String β†’ String) -- inputs (a b: String) : Prop :=
theorem spec_isomorphism: βˆ€ implementation, (βˆ€ a b, problem_spec implementation a b) ↔ (βˆ€ a b, generated_spec implementation a b) :=
sorry
def implementation (a b: String) : String :=
sorry
-- #test implementation "010" "110" = "100"
theorem correctness (a b: String) : problem_spec implementation a b :=
by unfold problem_spec let result := implementation a b use result simp [result] sorry
null
null
null
def longest(strings: List[str]) -> Optional[str]
Out of list of strings, return the longest one. Return the first one in case of multiple strings of the same length. Return None in case the input list is empty.
[{"input": [], "expected_output": "None"}, {"input": ["a", "b", "c"], "expected_output": "a"}, {"input": ["a", "bb", "ccc"], "expected_output": "ccc"}]
def longest(strings: List[str]) -> Optional[str] """Out of list of strings, return the longest one. Return the first one in case of multiple strings of the same length. Return None in case the input list is empty. """
def problem_spec -- function signature (implementation: List String β†’ Option String) -- inputs (strings: List String) := -- spec let spec (result: Option String) := (result = none ↔ strings.length = 0) ∨ (βˆƒ longest, result = some longest ∧ longest ∈ strings ∧ βˆ€ s, s ∈ strings β†’ s.length ≀ longest.length β†’ (βˆƒ ...
def generated_spec -- function signature (implementation: List String β†’ Option String) -- inputs (strings: List String) : Prop :=
theorem spec_isomorphism: βˆ€ implementation, (βˆ€ strings, problem_spec implementation strings) ↔ (βˆ€ strings, generated_spec implementation strings) :=
sorry
def implementation (strings: List String) : Option String :=
if strings = [] then none else let longest := (strings.map (Ξ» s => s.length)).maximum.get! (strings.find? (Ξ» s => s.length = longest)).get!
#test implementation ["a", "b", "c"] = some "a" #test implementation ["a", "bb", "ccc"] = some "ccc" #test implementation [] = none
theorem correctness (strings: List String) : problem_spec implementation strings :=
by unfold problem_spec let result := implementation strings use result simp [result] sorry
null
null
null
def greatest_common_divisor(a: int, b: int) -> int
Return a greatest common divisor of two integers a and b
[{"input": [25, 15], "expected_output": 5}, {"input": [3, 5], "expected_output": 1}]
def greatest_common_divisor(a: int, b: int) -> int """Return a greatest common divisor of two integers a and b """
def problem_spec -- function signature (implementation: Int β†’ Int β†’ Int) -- inputs (a b: Int) := -- spec let spec (result: Int) := (result ∣ a) ∧ (result ∣ b) ∧ (βˆ€ (d': Int), (d' > 0) β†’ (d' ∣ a) β†’ (d' ∣ b) β†’ d' ≀ result); -- program termination βˆƒ result, implementation a b = result ∧ spec result
def generated_spec -- function signature (implementation: Int β†’ Int β†’ Int) -- inputs (a b: Int) : Prop :=
theorem spec_isomorphism: βˆ€ implementation, (βˆ€ a b, problem_spec implementation a b) ↔ (βˆ€ a b, generated_spec implementation a b) :=
sorry
def implementation (a b: Int) : Int :=
(Int.gcd a b)
#test implementation 25 15 = 5 #test implementation 3 5 = 1
theorem correctness (a b: Int) : problem_spec implementation a b :=
by unfold problem_spec let result := implementation a b use result simp [result] sorry
null
null
null
def all_prefixes(string: str) -> List[str]
Return list of all prefixes from shortest to longest of the input string
[{"input": "abc", "expected_output": ["a", "ab", "abc"]}]
def all_prefixes(string: str) -> List[str] """Return list of all prefixes from shortest to longest of the input string """
def problem_spec -- function signature (implementation: String β†’ List String) -- inputs (string: String) := -- spec let spec (result: List String) := result.length = string.length ∧ βˆ€ i, i < result.length β†’ result[i]! = string.take (i + 1); -- program termination βˆƒ result, implementation string = result ∧ spec result
def generated_spec -- function signature (implementation: String β†’ List String) -- inputs (string: String) : Prop :=
theorem spec_isomorphism: βˆ€ implementation, (βˆ€ string, problem_spec implementation string) ↔ (βˆ€ string, generated_spec implementation string) :=
sorry
def implementation (string: String) : List String :=
let rec aux (chars: List Char) (result: List String) (i: Nat) := if i < chars.length then aux chars (result ++ [(chars.take (i + 1)).asString]) (i + 1) else result; aux string.toList [] 0
#test implementation "abc" = ["a", "ab", "abc"]
theorem correctness (string: String) : problem_spec implementation string :=
by unfold problem_spec let result := implementation string use result simp [result] sorry
null
null
null
def string_sequence(n: int) -> str
Return a string containing space-delimited numbers starting from 0 upto n inclusive.
[{"input": 0, "expected_output": "0"}, {"input": 5, "expected_output": "0 1 2 3 4 5"}]
def string_sequence(n: int) -> str """Return a string containing space-delimited numbers starting from 0 upto n inclusive. """
def problem_spec -- function signature (implementation: Nat β†’ String) -- inputs (n: Nat) := -- spec let spec (result: String) := let result_nums := result.splitOn " "; result_nums.length = n + 1 ∧ βˆ€ i, i < n + 1 β†’ result_nums[i]! = i.repr; -- program termination βˆƒ result, implementation n = result ∧ spec result
def generated_spec -- function signature (implementation: Nat β†’ String) -- inputs (n: Nat) : Prop :=
theorem spec_isomorphism: βˆ€ implementation, (βˆ€ n, problem_spec implementation n) ↔ (βˆ€ n, generated_spec implementation n) :=
sorry
def implementation (n: Nat) : String :=
(String.join (List.map (fun i => String.append i.repr " ") (List.range n))).append (n.repr)
#test implementation 0 = "0" #test implementation 5 = "0 1 2 3 4 5"
theorem correctness (n: Nat) : problem_spec implementation n :=
by unfold problem_spec let result := implementation n use result simp [result] sorry
null
null
null
def count_distinct_characters(string: str) -> int
Given a string, find out how many distinct characters (regardless of case) does it consist of
[{"input": "xyzXYZ", "expected_output": 3}, {"input": "Jerry", "expected_output": 4}]
def count_distinct_characters(string: str) -> int """Given a string, find out how many distinct characters (regardless of case) does it consist of """
def problem_spec -- function signature (implementation: String β†’ Nat) -- inputs (string: String) := -- spec let spec (result: Nat) := let string_idx := {i: Nat | i < string.length}.toFinset let characters := string_idx.image (fun i => string.toList.get! i) let lowercase_characters := characters.image (fun c => c.toLowe...
def generated_spec -- function signature (implementation: String β†’ Nat) -- inputs (string: String) : Prop :=
theorem spec_isomorphism: βˆ€ implementation, (βˆ€ string, problem_spec implementation string) ↔ (βˆ€ string, generated_spec implementation string) :=
sorry
def implementation (string: String) : Nat :=
let char_set := string.toLower.toList.toFinset char_set.card
#test implementation "xyzXYZ" = 3 #test implementation "Jerry" = 4
theorem correctness (string: String) : problem_spec implementation string :=
by unfold problem_spec let result := implementation string use result simp [result] simp [implementation] rcases string with ⟨data⟩ induction data simp have h1: "".toLower = "" := by unfold String.toLower unfold Char.toLower unfold String.map unfold String.mapAux simp intros contradiction simp [h1] rename...
null
null
null
def parse_music(music_string: str) -> List[int]
Input to this function is a string representing musical notes in a special ASCII format. Your task is to parse this string and return list of integers corresponding to how many beats does each not last. Here is a legend: 'o' - whole note, lasts four beats 'o|' - half note, lasts two beats '.|' - quater note, lasts one...
[{"input": "o o| .| o| o| .| .| .| .| o o", "expected_output": [4, 2, 1, 2, 2, 1, 1, 1, 1, 4, 4]}]
def parse_music(music_string: str) -> List[int] """Input to this function is a string representing musical notes in a special ASCII format. Your task is to parse this string and return list of integers corresponding to how many beats does each not last. Here is a legend: 'o' - whole note, lasts four beats 'o|' - half ...
def problem_spec -- function signature (implementation: String β†’ List Nat) -- inputs (string: String) := -- spec let not_map := fun | "o" => 4 | "o|" => 2 | ".|" => 1 | _ => 0; let spec (result: List Nat) := let space_split := string.splitOn " "; space_split.length = result.length ∧ βˆ€ i < result.length, not_map...
def generated_spec -- function signature (implementation: String β†’ List Nat) -- inputs (string: String) : Prop :=
theorem spec_isomorphism: βˆ€ implementation, (βˆ€ string, problem_spec implementation string) ↔ (βˆ€ string, generated_spec implementation string) :=
sorry
def implementation (string: String) : List Nat :=
(string.splitOn " ").map (fun | "o" => 4 | "o|" => 2 | ".|" => 1 | _ => 0)
#test implementation "o o| .| o| o| .| .| .| .| o o" = [4, 2, 1, 2, 2, 1, 1, 1, 1, 4, 4]
theorem correctness (string: String) : problem_spec implementation string :=
by unfold problem_spec let result := implementation string use result simp [result] simp [implementation] intro i by_cases h_i_lt_len: (i < (string.splitOn " ").length) simp [h_i_lt_len] simp [h_i_lt_len]
null
null
null
def how_many_times(string: str, substring: str) -> int
Find how many times a given substring can be found in the original string. Count overlaping cases.
[{"input": ["", "a"], "expected_output": 0}, {"input": ["aaa", "a"], "expected_output": 3}, {"input": ["aaaa", "aa"], "expected_output": 3}]
def how_many_times(string: str, substring: str) -> int """Find how many times a given substring can be found in the original string. Count overlaping cases. """
def problem_spec -- function signature (implementation: String β†’ String β†’ Nat) -- inputs (string substring: String) := -- spec let spec (result: Nat) := (string.length < substring.length β†’ result = 0) ∧ (string.length = substring.length β†’ ((string = substring ↔ result = 1) ∧ (substring β‰  string ↔ result = 0))) ∧ (subst...
def generated_spec -- function signature (implementation: String β†’ String β†’ Nat) -- inputs (string substring: String) : Prop :=
theorem spec_isomorphism: βˆ€ implementation, (βˆ€ string substring, problem_spec implementation string substring) ↔ (βˆ€ string substring, generated_spec implementation string substring) :=
sorry
def implementation (string: String) (substring: String) : Nat :=
(string.findAllSubstr substring).size
#test implementation "aaa" "a" = 3 #test implementation "aaaa" "aa" = 3 #test implementation "" "a" = 0 #test implementation "a" "" = 1 #test implementation "a" "a" = 1
theorem correctness (string: String) (substring: String) : problem_spec implementation string substring :=
by unfold problem_spec let result := implementation string substring use result simp [result] sorry
null
null
null
def sort_numbers(numbers: str) -> str
Input is a space-delimited string of numberals from 'zero' to 'nine'. Valid choices are 'zero', 'one', 'two', 'three', 'four', 'five', 'six', 'seven', 'eight' and 'nine'. Return the string with numbers sorted from smallest to largest
[{"input": "three one five", "expected_output": "one three five"}]
def sort_numbers(numbers: str) -> str """Input is a space-delimited string of numberals from 'zero' to 'nine'. Valid choices are 'zero', 'one', 'two', 'three', 'four', 'five', 'six', 'seven', 'eight' and 'nine'. Return the string with numbers sorted from smallest to largest """
def problem_spec -- function signature (implementation: String β†’ String) -- inputs (numbers: String) := -- spec let word_to_number_map : String β†’ Int := fun word => match word with | "zero" => 0 | "one" => 1 | "two" => 2 | "three" => 3 | "four" => 4 | "five" => 5 | "six" => 6 | "seven" => 7 | "eight...
def generated_spec -- function signature (implementation: String β†’ String) -- inputs (numbers: String) : Prop :=
theorem spec_isomorphism: βˆ€ implementation, (βˆ€ numbers, problem_spec implementation numbers) ↔ (βˆ€ numbers, generated_spec implementation numbers) :=
sorry
def implementation (numbers: String) : String :=
let word_to_number_map : String β†’ Int := fun word => match word with | "zero" => 0 | "one" => 1 | "two" => 2 | "three" => 3 | "four" => 4 | "five" => 5 | "six" => 6 | "seven" => 7 | "eight" => 8 | "nine" => 9 | _ => -1; let number_to_word_map : Int β†’ String := fun number => match number with ...
#test implementation "three one five" = "one three five"
theorem correctness (numbers: String) : problem_spec implementation numbers :=
by unfold problem_spec let result := implementation numbers use result simp [result] sorry
null
null
null
def find_closest_elements(numbers: List[float]) -> Tuple[float, float]
From a supplied list of numbers (of length at least two) select and return two that are the closest to each other and return them in order (smaller number, larger number).
[{"input": [1.0, 2.0, 3.0, 4.0, 5.0, 2.2], "expected_output": "(2.0, 2.2)"}, {"input": [1.0, 2.0, 3.0, 4.0, 5.0, 2.0], "expected_output": "(2.0, 2.0)"}]
def find_closest_elements(numbers: List[float]) -> Tuple[float, float] """From a supplied list of numbers (of length at least two) select and return two that are the closest to each other and return them in order (smaller number, larger number). """
def problem_spec -- function signature (implementation: List Rat β†’ (Rat Γ— Rat)) -- inputs (numbers: List Rat) := -- spec let spec (result: (Rat Γ— Rat)) := 2 ≀ numbers.length β†’ (let (smaller, larger) := result; let abs_diff := |larger - smaller|; smaller ≀ larger ∧ smaller ∈ numbers ∧ larger ∈ numbers ∧ (βˆ€ x y, x ∈ numb...
def generated_spec -- function signature (implementation: List Rat β†’ (Rat Γ— Rat)) -- inputs (numbers: List Rat) : Prop :=
theorem spec_isomorphism: βˆ€ implementation, (βˆ€ numbers, problem_spec implementation numbers) ↔ (βˆ€ numbers, generated_spec implementation numbers) :=
sorry
def implementation (numbers: List Rat): (Rat Γ— Rat) :=
let n := numbers.length; let sorted_numbers := numbers.mergeSort; let min_diff := sorted_numbers.get! 1 - sorted_numbers.get! 0; let min_pair := (sorted_numbers.get! 0, sorted_numbers.get! 1); let rec loop (i: Nat) (min_diff: Rat) (min_pair: (Rat Γ— Rat)): (Rat Γ— Rat) := if i < n - 1 then let diff := sorted_number...
#test implementation [1.0, 2.0, 3.0, 4.0, 5.0, 2.2] = (2.0, 2.2) #test implementation [1.0, 2.0, 3.0, 4.0, 5.0, 2.0] = (2.0, 2.0)
theorem correctness (numbers: List Rat) : problem_spec implementation numbers :=
by unfold problem_spec let result := implementation numbers use result simp [result] sorry
null
null
null
def rescale_to_unit(numbers: List[float]) -> List[float]
Given list of numbers (of at least two elements), apply a linear transform to that list, such that the smallest number will become 0 and the largest will become 1
[{"input": [1.0, 2.0, 3.0, 4.0, 5.0], "expected_output": [0.0, 0.25, 0.5, 0.75, 1.0]}]
def rescale_to_unit(numbers: List[float]) -> List[float] """Given list of numbers (of at least two elements), apply a linear transform to that list, such that the smallest number will become 0 and the largest will become 1 """
def problem_spec -- function signature (implementation: List Rat β†’ List Rat) -- inputs (numbers: List Rat) := -- spec let spec (result: List Rat) := 2 ≀ numbers.length β†’ let min_elem := numbers.min?.get!; let max_elem := numbers.max?.get!; let range := max_elem - min_elem; result.length = numbers.length ∧ βˆ€ i, i < numb...
def generated_spec -- function signature (implementation: List Rat β†’ List Rat) -- inputs (numbers: List Rat) : Prop :=
theorem spec_isomorphism: βˆ€ implementation, (βˆ€ numbers, problem_spec implementation numbers) ↔ (βˆ€ numbers, generated_spec implementation numbers) :=
sorry
def implementation (numbers: List Rat): List Rat :=
sorry
-- #test implementation [1.0, 2.0, 3.0, 4.0, 5.0] = [0.0, 0.25, 0.5, 0.75, 1.0]
theorem correctness (numbers: List Rat) : problem_spec implementation numbers :=
by unfold problem_spec let result := implementation numbers use result simp [result] sorry
null
null
null
def strlen(string: str) -> int
Return length of given string
[{"input": "", "expected_output": 0}, {"input": "abc", "expected_output": 3}]
def strlen(string: str) -> int """Return length of given string """
def problem_spec -- function signature (implementation: String β†’ Nat) -- inputs (string: String) := -- spec let spec (result: Nat) := -- every character in the string is counted once result = 0 ↔ string.isEmpty ∧ (0 < result β†’ result - 1 = implementation (string.drop 1)) -- program termination βˆƒ result, implementation ...
def generated_spec -- function signature (implementation: String β†’ Nat) -- inputs (string: String) : Prop :=
theorem spec_isomorphism: βˆ€ implementation, (βˆ€ string, problem_spec implementation string) ↔ (βˆ€ string, generated_spec implementation string) :=
sorry
def implementation (string: String): Nat :=
string.length
#test implementation "" = 0 #test implementation "abc" = 3
theorem correctness (string: String) : problem_spec implementation string :=
by unfold problem_spec let result := implementation string use result simp [result] sorry
null
null
null
def largest_divisor(n: int) -> int
For a given number n, find the largest number that divides n evenly, smaller than n
[{"input": 15, "expected_output": 5}]
def largest_divisor(n: int) -> int """For a given number n, find the largest number that divides n evenly, smaller than n """
def problem_spec -- function signature (implementation: Nat β†’ Nat) -- inputs (n: Nat) := -- spec let spec (result: Nat) := 0 < n β†’ 0 < result β†’ result ∣ n β†’ βˆ€ x, x ∣ n β†’ x β‰  n β†’ x ≀ result; -- program termination βˆƒ result, implementation n = result ∧ spec result
def generated_spec -- function signature (implementation: Nat β†’ Nat) -- inputs (n: Nat) : Prop :=
theorem spec_isomorphism: βˆ€ implementation, (βˆ€ n, problem_spec implementation n) ↔ (βˆ€ n, generated_spec implementation n) :=
sorry
def implementation (n: Nat) : Nat :=
let possible_divisors := (List.range (n / 2 + 1)).drop 1 let reversed_possible_divisors := List.reverse possible_divisors; Id.run do for i in reversed_possible_divisors do if n % i = 0 then return i return 1
#test implementation 15 = 5
theorem correctness (n: Nat) : problem_spec implementation n :=
by unfold problem_spec let result := implementation n use result simp [result] sorry
null
null
null
def factorize(n: int) -> List[int]
Return list of prime factors of given integer in the order from smallest to largest. Each of the factors should be listed number of times corresponding to how many times it appeares in factorization. Input number should be equal to the product of all factors
[{"input": 8, "expected_output": [2, 2, 2]}, {"input": 25, "expected_output": [5, 5]}, {"input": 70, "expected_output": [2, 5, 7]}]
def factorize(n: int) -> List[int] """Return list of prime factors of given integer in the order from smallest to largest. Each of the factors should be listed number of times corresponding to how many times it appeares in factorization. Input number should be equal to the product of all factors """
def problem_spec -- function signature (implementation: Nat β†’ List Nat) -- inputs (n: Nat) := -- spec let spec (result: List Nat) := 2 ≀ n β†’ (result.prod = n ∧ List.Sorted Nat.le result ∧ result.all (Ξ» i => n % i = 0 ∧ Nat.Prime i)); -- program termination βˆƒ result, implementation n = result ∧ spec result
def generated_spec -- function signature (implementation: Nat β†’ List Nat) -- inputs (n: Nat) : Prop :=
theorem spec_isomorphism: βˆ€ implementation, (βˆ€ n, problem_spec implementation n) ↔ (βˆ€ n, generated_spec implementation n) :=
sorry
def implementation (n: Nat) : List Nat :=
Id.run do let mut result := [] for num in List.range' 2 n.sqrt do let mut n' := n while n' % num = 0 do n' := n' / num result := result ++ [num] result
#test implementation 8 = [2, 2, 2] #test implementation 25 = [5, 5] #test implementation 70 = [2, 5, 7]
theorem correctness (n: Nat) : problem_spec implementation n :=
by unfold problem_spec let result := implementation n use result simp [result] simp [implementation, Id.run] unfold List.foldl intro h_2_lt_n sorry
null
null
null
def remove_duplicates(numbers: List[int]) -> List[int]
From a list of integers, remove all elements that occur more than once. Keep order of elements left the same as in the input.
[{"input": [1, 2, 3, 2, 4], "expected_output": [1, 3, 4]}]
def remove_duplicates(numbers: List[int]) -> List[int] """From a list of integers, remove all elements that occur more than once. Keep order of elements left the same as in the input. """
def problem_spec -- function signature (implementation: List Int β†’ List Int) -- inputs (numbers: List Int) := -- spec let spec (result: List Int) := (βˆ€ i: Int, i ∈ result β†’ numbers.count i = 1) ∧ (βˆ€ i: Int, i ∈ numbers β†’ numbers.count i = 1 β†’ i ∈ result) ∧ (βˆ€ i j : Nat, i < result.length β†’ j < result.length β†’ i < j β†’ βˆƒ...
def generated_spec -- function signature (implementation: List Int β†’ List Int) -- inputs (numbers: List Int) : Prop :=
theorem spec_isomorphism: βˆ€ implementation, (βˆ€ numbers, problem_spec implementation numbers) ↔ (βˆ€ numbers, generated_spec implementation numbers) :=
sorry
def implementation (numbers: List Int) : List Int :=
Id.run do let mut result := [] for number in numbers do if numbers.count number = 1 then result := result ++ [number] return result
#test implementation [1, 2, 3, 2, 4] = [1, 3, 4]
theorem correctness (numbers: List Int) : problem_spec implementation numbers :=
by unfold problem_spec let result := implementation numbers use result simp [result] sorry
null
null
null
def flip_case(string: str) -> str
For a given string, flip lowercase characters to uppercase and uppercase to lowercase.
[{"input": "Hello", "expected_output": "hELLO"}]
def flip_case(string: str) -> str """For a given string, flip lowercase characters to uppercase and uppercase to lowercase. """
def problem_spec -- function signature (implementation: String β†’ String) -- inputs (string: String) := -- spec let spec (result: String) := let chars_in_result := result.toList; let chars_in_string := string.toList; chars_in_result.length = string.length ∧ (βˆ€ i, i < chars_in_result.length β†’ let c := chars_in_result.g...
def generated_spec -- function signature (implementation: String β†’ String) -- inputs (string: String) : Prop :=
theorem spec_isomorphism: βˆ€ implementation, (βˆ€ string, problem_spec implementation string) ↔ (βˆ€ string, generated_spec implementation string) :=
sorry
def implementation (string: String) : String :=
string.map (Ξ» c => if c.isUpper then c.toLower else c.toUpper)
#test implementation "Hello" = "hELLO"
theorem correctness (string: String) : problem_spec implementation string :=
by unfold problem_spec let result := implementation string use result simp [result] sorry
null
null
null
def concatenate(strings: List[str]) -> str
Concatenate list of strings into a single string
[{"input": [], "expected_output": ""}, {"input": ["a", "b", "c"], "expected_output": "abc"}]
def concatenate(strings: List[str]) -> str """Concatenate list of strings into a single string """
def problem_spec -- function signature (implementation: List String β†’ String) -- inputs (strings: List String) := -- spec let spec (result: String) := let result_chars := result.toList; result_chars.length = (strings.map (Ξ» s => s.length)).sum ∧ βˆ€ i, i < strings.length β†’ (let string_in_result := strings.get! i; let end...
def generated_spec -- function signature (implementation: List String β†’ String) -- inputs (strings: List String) : Prop :=
theorem spec_isomorphism: βˆ€ implementation, (βˆ€ strings, problem_spec implementation strings) ↔ (βˆ€ strings, generated_spec implementation strings) :=
sorry
def implementation (strings: List String) : String :=
String.join strings
#test implementation [] = "" #test implementation ["a", "b", "c"] = "abc"
theorem correctness (strings: List String) : problem_spec implementation strings :=
by unfold problem_spec let result := implementation strings use result simp [result] apply And.intro simp [implementation] repeat sorry
null
null
null
def filter_by_prefix(strings: List[str], prefix: str) -> List[str]
Filter an input list of strings only for ones that start with a given prefix.
[{"input": [[], "a"], "expected_output": []}, {"input": [["abc", "bcd", "cde", "array"], "a"], "expected_output": ["abc", "array"]}]
def filter_by_prefix(strings: List[str], prefix: str) -> List[str] """Filter an input list of strings only for ones that start with a given prefix. """
def problem_spec -- function signature (implementation: List String β†’ String β†’ List String) -- inputs (strings: List String) (pref: String) := -- spec let spec (result: List String) := result.all (Ξ» s => s.startsWith pref) ∧ result.all (Ξ» s => s ∈ strings) ∧ strings.all (Ξ» s => s.startsWith pref β†’ s ∈ result) ∧ βˆ€ s : S...
def generated_spec -- function signature (implementation: List String β†’ String β†’ List String) -- inputs (strings: List String) (pref: String) : Prop :=
theorem spec_isomorphism: βˆ€ implementation, (βˆ€ strings pref, problem_spec implementation strings pref) ↔ (βˆ€ strings pref, generated_spec implementation strings pref) :=
sorry
def implementation (strings: List String) (pref: String) : List String :=
strings.filter (Ξ» s => s.startsWith pref)
#test implementation [] "a" = [] #test implementation ["abc", "bcd", "cde", "array"] "a" = ["abc", "array"]
theorem correctness (strings: List String) (pref: String) : problem_spec implementation strings pref :=
by unfold problem_spec let result := implementation strings pref use result simp [result] repeat sorry
null
null
null
def get_positive(l: list)
Return only positive numbers in the list.
[{"input": [-1, 2, -4, 5, 6], "expected_output": [2, 5, 6]}, {"input": [5, 3, -5, 2, -3, 3, 9, 0, 123, 1, -10], "expected_output": [5, 3, 2, 3, 9, 123, 1]}]
def get_positive(l: list) """Return only positive numbers in the list. """
def problem_spec -- function signature (implementation: List Int β†’ List Int) -- inputs (numbers: List Int) := -- spec let spec (result: List Int) := result.all (Ξ» x => x > 0 ∧ x ∈ numbers) ∧ numbers.all (Ξ» x => x > 0 β†’ x ∈ result) ∧ result.all (Ξ» x => result.count x = numbers.count x); -- program termination βˆƒ re...
def generated_spec -- function signature (implementation: List Int β†’ List Int) -- inputs (numbers: List Int) : Prop :=
theorem spec_isomorphism: βˆ€ implementation, (βˆ€ numbers, problem_spec implementation numbers) ↔ (βˆ€ numbers, generated_spec implementation numbers) :=
sorry
def implementation (numbers: List Int): List Int :=
numbers.filter (Ξ» x => x > 0)
#test implementation [(-1), 2, (-4), 5, 6] = [2, 5, 6] #test implementation [5, 3, (-5), 2, (-3), 3, 9, 0, 123, 1, (-10)] = [5, 3, 2, 3, 9, 123, 1]
theorem correctness (numbers: List Int) : problem_spec implementation numbers :=
by unfold problem_spec let result := implementation numbers use result simp [result] repeat sorry
null
null
null
def is_prime(n)
Return true if a given number is prime, and false otherwise.
[{"input": 6, "output": false}, {"input": 101, "output": true}, {"input": 11, "output": true}, {"input": 13441, "output": true}, {"input": 61, "output": true}, {"input": 4, "output": false}, {"input": 1, "output": false}]
def is_prime(n) """Return true if a given number is prime, and false otherwise. """
def problem_spec -- function signature (implementation: Nat β†’ Bool) -- inputs (n: Nat) := -- spec let spec (result: Bool) := result ↔ Β¬ (βˆƒ k, 2 ≀ k ∧ k < n ∧ n % k = 0); -- program termination βˆƒ result, implementation n = result ∧ spec result
def generated_spec -- function signature (implementation: Nat β†’ Bool) -- inputs (n: Nat) : Prop :=
theorem spec_isomorphism: βˆ€ implementation, (βˆ€ n, problem_spec implementation n) ↔ (βˆ€ n, generated_spec implementation n) :=
sorry
def implementation (n: Nat): Bool :=
Nat.Prime n
#test implementation 6 = false #test implementation 101 = true #test implementation 11 = true #test implementation 13441 = true #test implementation 61 = true #test implementation 4 = false #test implementation 1 = false
theorem correctness (n: Nat) : problem_spec implementation n :=
by unfold problem_spec let result := implementation n use result simp [result] simp [implementation] sorry
null
null
null
def find_zero(xs: list)
xs are coefficients of a polynomial. find_zero find x such that poly(x) = 0. find_zero returns only only zero point, even if there are many. Moreover, find_zero only takes list xs having even number of coefficients and largest non zero coefficient as it guarantees a solution. Note(George): This problem has been modifie...
[{"input": [1, 2], "output": -0.5}, {"input": [-6, 11, -6, 1], "output": 1.0}]
def find_zero(xs: list) """xs are coefficients of a polynomial. find_zero find x such that poly(x) = 0. find_zero returns only only zero point, even if there are many. Moreover, find_zero only takes list xs having even number of coefficients and largest non zero coefficient as it guarantees a solution. Note(George): Th...
def problem_spec -- function signature (implementation: List Rat β†’ Rat) -- inputs (xs: List Rat) := -- spec let spec (result: Rat) := let eps := (1: Rat) / 1000000; xs.length β‰₯ 1 β†’ xs.length % 2 = 0 β†’ βˆ€ poly : Polynomial Rat, poly.degree = some (xs.length - 1) β†’ (βˆ€ i, i ≀ xs.length - 1 β†’ poly.coeff i = xs...
def generated_spec -- function signature (implementation: List Rat β†’ Rat) -- inputs (xs: List Rat) : Prop :=
theorem spec_isomorphism: βˆ€ implementation, (βˆ€ xs, problem_spec implementation xs) ↔ (βˆ€ xs, generated_spec implementation xs) :=
sorry
def implementation (xs: List Rat) : Rat :=
let rec poly (xs: List Rat) (x: Rat) := xs.reverse.foldl (Ξ» acc a => acc * x + a) 0; let rec poly' (xs: List Rat) (x: Rat) := (xs.drop 1).reverse.foldl (Ξ» acc a => acc * x + a) 0; let rec eps := (1: Rat) / 1000000; let rec find_zero (xs: List Rat) (guess: Rat) (fuel: Nat) := let eval := poly xs guess; let eval' := poly...
#test implementation [1, 2] = -0.5 #test implementation [-6, 11, -6, 1] = 1.0
theorem correctness (xs: List Rat) : problem_spec implementation xs :=
by unfold problem_spec let result := implementation xs use result simp [result] intros h1 h2 poly h3 h4 repeat sorry
null
null
null
def sort_third(l: list)
This function takes a list l and returns a list l' such that l' is identical to l in the indicies that are not divisible by three, while its values at the indicies that are divisible by three are equal to the values of the corresponding indicies of l, but sorted.
[{"input": [1, 2, 3], "output": [1, 2, 3]}, {"input": [5, 6, 3, 4, 8, 9, 2], "output": [2, 6, 3, 4, 8, 9, 5]}]
def sort_third(l: list) """This function takes a list l and returns a list l' such that l' is identical to l in the indicies that are not divisible by three, while its values at the indicies that are divisible by three are equal to the values of the corresponding indicies of l, but sorted. """
def problem_spec -- function signature (implementation: List Int β†’ List Int) -- inputs (l: List Int) := -- spec let spec (result: List Int) := l.length = result.length ∧ let every_third_idx := (List.range l.length).filter (Ξ» i => i % 3 = 0); let every_third_val_in_result := every_third_idx.map (Ξ» i => result.get!...
def generated_spec -- function signature (implementation: List Int β†’ List Int) -- inputs (l: List Int) : Prop :=
theorem spec_isomorphism: βˆ€ implementation, (βˆ€ l, problem_spec implementation l) ↔ (βˆ€ l, generated_spec implementation l) :=
sorry
def implementation (l: List Int) : List Int :=
let every_third_idx := (List.range l.length).filter (Ξ» i => i % 3 = 0); let every_third_val := every_third_idx.map (Ξ» i => l.get! i); let every_third_val_sorted := List.mergeSort every_third_val; let result := l.mapIdx (Ξ» i v => if i % 3 = 0 then every_third_val_sorted.get! (i / 3) else v); result
#test implementation [1, 2, 3] = [1, 2, 3] #test implementation [5, 6, 3, 4, 8, 9, 2] = [2, 6, 3, 4, 8, 9, 5]
theorem correctness (l: List Int) : problem_spec implementation l :=
by unfold problem_spec let result := implementation l use result simp [result] repeat sorry
null
null
null
def unique(l: list)
Return sorted unique elements in a list.
[{"input": [5, 3, 5, 2, 3, 3, 9, 0, 123], "output": [0, 2, 3, 5, 9, 123]}]
def unique(l: list) """Return sorted unique elements in a list. """
def problem_spec -- function signature (implementation: List Int β†’ List Int) -- inputs (l: List Int) := -- spec let spec (result: List Int) := (βˆ€ x, x ∈ result ↔ x ∈ l ∧ result.count x = 1) ∧ List.Sorted Int.le result -- program termination βˆƒ result, implementation l = result ∧ spec result
def generated_spec -- function signature (implementation: List Int β†’ List Int) -- inputs (l: List Int) : Prop :=
theorem spec_isomorphism: βˆ€ implementation, (βˆ€ l, problem_spec implementation l) ↔ (βˆ€ l, generated_spec implementation l) :=
sorry
def implementation (l: List Int) : List Int :=
l.eraseDup.mergeSort
#test implementation [5, 3, 5, 2, 3, 3, 9, 0, 123] = [0, 2, 3, 5, 9, 123]
theorem correctness (l: List Int) : problem_spec implementation l :=
by unfold problem_spec let result := implementation l use result simp [result] simp [implementation] apply And.intro intro x apply Iff.intro intro h apply And.intro repeat sorry
null
null
null
def max_element(l: list)
Return maximum element in the list.
[{"input": [1, 2, 3], "output": 3}, {"input": [5, 3, -5, 2, -3, 3, 9, 0, 123, 1, -10], "output": 123}]
def max_element(l: list) """Return maximum element in the list. """
def problem_spec -- function signature (implementation: List Int β†’ Int) -- inputs (l: List Int) := -- spec let spec (result: Int) := l.length > 0 β†’ ((βˆ€ i, i < l.length β†’ l.get! i ≀ result) ∧ (βˆƒ i, i < l.length ∧ l.get! i = result)); -- program termination βˆƒ result, implementation l = result ∧ spec result
def generated_spec -- function signature (implementation: List Int β†’ Int) -- inputs (l: List Int) : Prop :=
theorem spec_isomorphism: βˆ€ implementation, (βˆ€ l, problem_spec implementation l) ↔ (βˆ€ l, generated_spec implementation l) :=
sorry
def implementation (l: List Int) : Int :=
match List.maximum l with | none => panic! "empty list" | some x => x
#test implementation [1, 2, 3] = 3 #test implementation [5, 3, -5, 2, -3, 3, 9, 0, 123, 1, -10] = 123
theorem correctness (l: List Int) : problem_spec implementation l :=
by unfold problem_spec let result := implementation l use result simp [result] simp [implementation] by_cases h_l_not_nil: l β‰  [] have h_max_not_none := List.maximum_ne_bot_of_ne_nil h_l_not_nil intro h_len_gt_zero apply And.intro have h_l_max : βˆƒ r, l.maximum = some r := by have h_l_max' : l.maximum β‰  none := h_max_...
null
null
null
def fizz_buzz(n: int)
Return the number of times the digit 7 appears in integers less than n which are divisible by 11 or 13.
[{"input": 50, "output": 0}, {"input": 78, "output": 2}, {"input": 79, "output": 3}]
def fizz_buzz(n: int) """Return the number of times the digit 7 appears in integers less than n which are divisible by 11 or 13. """
def problem_spec -- function signature (implementation: Nat β†’ Nat) -- inputs (n: Nat) := -- spec let spec (result: Nat) := (n = 0 β†’ result = 0) ∧ (0 < n β†’ result = implementation (n - 1) β†’ (n % 11 β‰  0 ∧ n % 13 β‰  0) ∨ n.repr.count '7' = 0) ∧ (0 < n β†’ result β‰  implementation (n - 1) β†’ (n % 11 = 0 ∨ n % ...
def generated_spec -- function signature (implementation: Nat β†’ Nat) -- inputs (n: Nat) : Prop :=
theorem spec_isomorphism: βˆ€ implementation, (βˆ€ n, problem_spec implementation n) ↔ (βˆ€ n, generated_spec implementation n) :=
sorry
def implementation (n: Nat) : Nat :=
let all_numbers_lt_n := {x | x < n}; let multiples_of_11_or_13 := all_numbers_lt_n ∩ {x | x % 11 = 0 ∨ x % 13 = 0}; let possible_multiple_with_7 := multiples_of_11_or_13 ∩ {x | x.repr.contains '7'}; possible_multiple_with_7.toFinset.sum (λ x => x.repr.count '7')
#test implementation 50 = 0 #test implementation 78 = 2 #test implementation 79 = 3
theorem correctness (n: Nat) : problem_spec implementation n :=
by unfold problem_spec let result := implementation n use result simp [result] simp [implementation] sorry
null
null
null
def sort_even(l: list)
This function takes a list l and returns a list l' such that l' is identical to l in the odd indicies, while its values at the even indicies are equal to the values of the even indicies of l, but sorted.
[{"input": [1, 2, 3], "output": [1, 2, 3]}, {"input": [5, 6, 3, 4], "output": [3, 6, 5, 4]}]
def sort_even(l: list) """This function takes a list l and returns a list l' such that l' is identical to l in the odd indicies, while its values at the even indicies are equal to the values of the even indicies of l, but sorted. """
def problem_spec -- function signature (implementation: List Int β†’ List Int) -- inputs (l: List Int) := -- spec let spec (result: List Int) := l.length = result.length ∧ let even_idx := (List.range l.length).filter (Ξ» i => i % 2 = 0); let even_val_in_result := even_idx.map (Ξ» i => result.get! i); let even_val :...
def generated_spec -- function signature (implementation: List Int β†’ List Int) -- inputs (l: List Int) : Prop :=
theorem spec_isomorphism: βˆ€ implementation, (βˆ€ l, problem_spec implementation l) ↔ (βˆ€ l, generated_spec implementation l) :=
sorry
def implementation (l: List Int) : List Int :=
let even_idx := (List.range l.length).filter (Ξ» i => i % 2 = 0); let even_val := even_idx.map (Ξ» i => l.get! i); let even_val_sorted := List.mergeSort even_val; let result := l.mapIdx (Ξ» i v => if i % 2 = 0 then even_val_sorted.get! (i / 2) else v); result
#test implementation [1, 2, 3] = [1, 2, 3] #test implementation [5, 6, 3, 4] = [3, 6, 5, 4]
theorem correctness (l: List Int) : problem_spec implementation l :=
by unfold problem_spec let result := implementation l use result simp [result] sorry
null
null
null
def encode_cyclic(s: str) -> str
Returns an encoded string by cycling each group of three consecutive characters. Specifically, each group of exactly three characters 'abc' is transformed to 'bca'. Groups of fewer than three characters at the end of the string remain unchanged.
[{"input": "abcdef", "expected_output": "bcaefd"}, {"input": "abcde", "expected_output": "bcade"}, {"input": "ab", "expected_output": "ab"}]
def encode_cyclic(s: str) -> str """Returns an encoded string by cycling each group of three consecutive characters. Specifically, each group of exactly three characters 'abc' is transformed to 'bca'. Groups of fewer than three characters at the end of the string remain unchanged. """
def problem_spec (impl: String β†’ String) (s: String) := let n := s.length; let extract (chars: List Char) (start_index: β„•) (end_index: β„•) := (chars.drop start_index).take (end_index - start_index + 1); let spec (result: String) := let encoded_chars := result.toList; let original_chars := s.toList; encoded_chars...
def generated_spec -- function signature (impl: String β†’ String) -- inputs (s: String) : Prop :=
theorem spec_isomorphism: βˆ€ impl, (βˆ€ s, problem_spec impl s) ↔ (βˆ€ s, generated_spec impl s) :=
sorry
def implementation (s: String) : String :=
sorry
-- #test implementation "abcdef" = "bcaefd" -- #test implementation "abcde" = "bcade" -- #test implementation "ab" = "ab"
theorem correctness (s: String) : problem_spec implementation s :=
by unfold problem_spec let result := implementation s use result simp [result] sorry
null
null
null
def prime_fib(n: int)
prime_fib returns n-th prime Fibonacci number. Note(George): A proof of this problem requires the resolution of the open conjecture: there are infinitely many prime Fibonacci numbers.
[{"input": 1, "output": 2}, {"input": 2, "output": 3}, {"input": 3, "output": 5}, {"input": 4, "output": 13}, {"input": 5, "output": 89}]
def prime_fib(n: int) """prime_fib returns n-th prime Fibonacci number. Note(George): A proof of this problem requires the resolution of the open conjecture: there are infinitely many prime Fibonacci numbers. """
def problem_spec -- function signature (implementation: Nat β†’ Nat) -- inputs (n: Nat) := -- spec let spec (result: Nat) := n > 0 β†’ (βˆƒ i, Nat.fib i = result ∧ Nat.Prime result ∧ (βˆƒ! S : Finset Nat, S.card = n - 1 ∧ (βˆ€ y ∈ S, (βˆƒ k, y = Nat.fib k) ∧ y < result ∧ Nat.Prime y)) ) -- program termination...
def generated_spec -- function signature (implementation: Nat β†’ Nat) -- inputs (n: Nat) : Prop :=
theorem spec_isomorphism: βˆ€ implementation, (βˆ€ n, problem_spec implementation n) ↔ (βˆ€ n, generated_spec implementation n) :=
sorry
def implementation (n: Nat) : Nat :=
let rec fib_prime (n: Nat) (i: Nat) : Nat := if Nat.Prime (Nat.fib i) then if n = 1 ∨ n = 0 then Nat.fib i else fib_prime (n - 1) (i + 1) else fib_prime n (i + 1) termination_by n decreasing_by -- Really hard to prove termination here sorry sorry fib_prime n 0
-- NOTE we changed to #eval! instead of #test -- because we can't use #test for implementation -- without a proof of termination #eval! implementation 1 = 2 #eval! implementation 2 = 3 #eval! implementation 3 = 5 #eval! implementation 4 = 13 #eval! implementation 5 = 89
theorem correctness (n: Nat) : problem_spec implementation n :=
by unfold problem_spec let result := implementation n use result simp [result] repeat sorry
null
null
null
def triples_sum_to_zero(numbers: List[int]) -> Bool
triples_sum_to_zero takes a list of integers as an input. it returns True if there are three distinct elements in the list that sum to zero, and False otherwise.
[{"input": [1, 3, 5, 0], "expected_output": false}, {"input": [1, 3, -2, 1], "expected_output": true}]
def triples_sum_to_zero(numbers: List[int]) -> Bool """triples_sum_to_zero takes a list of integers as an input. it returns True if there are three distinct elements in the list that sum to zero, and False otherwise. """
def problem_spec -- function signature (implementation: List Int β†’ Bool) -- inputs (numbers: List Int) := let sum_i_j_k (i j k: Nat) : Bool := numbers[i]! + numbers[j]! + numbers[k]! = 0; let exists_zero := 3 ≀ numbers.length ∧ (βˆƒ i j k, i β‰  j ∧ i β‰  k ∧ j β‰  k ∧ i < numbers.length ∧ j < numbers.length ∧ k < numbers.l...
def generated_spec -- function signature (impl: List Int β†’ Bool) -- inputs (x: List Int) : Prop :=
theorem spec_isomorphism: βˆ€ impl, (βˆ€ x, problem_spec impl x) ↔ (βˆ€ x, generated_spec impl x) :=
sorry
def implementation (numbers: List Int) : Bool :=
sorry
-- #test implementation [1, 3, 5, 0] = false -- #test implementation [1, 3, -2, 1] = true -- #test implementation [1, 2, 3, 7] = false -- #test implementation [2, 4, -5, 3, 9, 7] = true -- #test implementation [1] = false
theorem correctness (numbers : List Int) : problem_spec implementation numbers :=
by unfold problem_spec let result := implementation numbers use result simp [result] sorry
null
null
null
def car_race_collision(x: Nat) -> Nat
Imagine a road that's a perfectly straight infinitely long line. n cars are driving left to right; simultaneously, a different set of n cars are driving right to left. The two sets of cars start out being very far from each other. All cars move in the same speed. Two cars are said to collide when a car that's movi...
[{"input": 0, "expected_output": 0}, {"input": 5, "expected_output": 25}]
def car_race_collision(x: Nat) -> Nat """Imagine a road that's a perfectly straight infinitely long line. n cars are driving left to right; simultaneously, a different set of n cars are driving right to left. The two sets of cars start out being very far from each other. All cars move in the same speed. Two cars a...
def problem_spec -- function signature (implementation: Nat β†’ Nat) -- inputs (x : Nat) := -- spec let spec (result: Nat) := βˆƒ x_list : List Nat, x_list.length = x ∧ x_list.all (fun i => i = x) ∧ x_list.sum = result -- -- program termination βˆƒ result, implementation x = result ∧ spec result --
def generated_spec -- function signature (impl: Nat β†’ Nat) -- inputs (x: Nat) : Prop :=
theorem spec_isomorphism: βˆ€ impl, (βˆ€ x, problem_spec impl x) ↔ (βˆ€ x, generated_spec impl x) :=
sorry
def implementation (x : Nat) : Nat :=
sorry
-- #test implementation 0 = 0 -- #test implementation 5 = 25
theorem correctness (x : Nat) : problem_spec implementation x :=
by unfold problem_spec let result := implementation x use result simp [result] sorry
null
null
null
def incr_list(numbers: List[Int]) -> List[Int]
incr_list takes a list of integers as input and returns a new list where each element is incremented by 1.
[{"input": [], "expected_output": []}, {"input": [1, 3, -2, 1], "expected_output": [2, 4, -1, 2]}]
def incr_list(numbers: List[Int]) -> List[Int] """incr_list takes a list of integers as input and returns a new list where each element is incremented by 1. """
def problem_spec -- function signature (implementation: List Int β†’ List Int) -- inputs (numbers: List Int) := -- spec let spec (result: List Int) := (result.length = numbers.length) ∧ βˆ€ i, i < numbers.length β†’ result[i]! = numbers[i]! + 1 -- -- program termination βˆƒ result, implementation numbers = result ∧ spec ...
def generated_spec -- function signature (impl: List Int β†’ List Int) -- inputs (x: List Int) : Prop :=
theorem spec_isomorphism: βˆ€ impl, (βˆ€ x, problem_spec impl x) ↔ (βˆ€ x, generated_spec impl x) :=
sorry
def implementation (numbers: List Int) : List Int :=
sorry
-- #test implementation [1, 2, 3] = [2, 3, 4] -- #test implementation [5, 3, 5, 2, 3, 3, 9, 0, 123] = [6, 4, 6, 3, 4, 4, 10, 1, 124]
theorem correctness (numbers : List Int) : problem_spec implementation numbers :=
by unfold problem_spec let result := implementation numbers use result simp [result] sorry
null
null
null
def pairs_sum_to_zero(numbers: List[int]) -> Bool
pairs_sum_to_zero takes a list of integers as an input. it returns True if there are two distinct elements in the list that sum to zero, and False otherwise.
[{"input": [1, 3, 5, 0], "expected_output": false}, {"input": [1, 3, -2, 1], "expected_output": false}, {"input": [1], "expected_output": false}, {"input": [2, 4, -5, 3, 5, 7], "expected_output": true}]
def pairs_sum_to_zero(numbers: List[int]) -> Bool """pairs_sum_to_zero takes a list of integers as an input. it returns True if there are two distinct elements in the list that sum to zero, and False otherwise. """
def problem_spec -- function signature (implementation: List Int β†’ Bool) -- inputs (numbers: List Int) := let sum_i_j (i j: Nat) : Bool := numbers[i]! + numbers[j]! = 0; let exists_zero := 2 ≀ numbers.length ∧ (βˆƒ i j, i β‰  j ∧ i < numbers.length ∧ j < numbers.length ∧ sum_i_j i j) -- spec let spec (result: Bool) := ...
def generated_spec -- function signature (impl: List Int β†’ Bool) -- inputs (x: List Int) : Prop :=
theorem spec_isomorphism: βˆ€ impl, (βˆ€ x, problem_spec impl x) ↔ (βˆ€ x, generated_spec impl x) :=
sorry
def implementation (numbers: List Int) : Bool :=
sorry
-- #test implementation [1, 3, 5, 0] = false -- #test implementation [1, 3, -2, 1] = false -- #test implementation [1, 2, 3, 7] = false -- #test implementation [2, 4, -5, 3, 5, 7] = true -- #test implementation [1] = false
theorem correctness (numbers : List Int) : problem_spec implementation numbers :=
by unfold problem_spec let result := implementation numbers use result simp [result] sorry
null
null
null
def change_base(x: Nat, base: Nat) -> String
Change numerical base of input number x to base. return string representation after the conversion. base numbers are less than 10.
[{"input": "(8, 3)", "expected_output": "22"}, {"input": "(8, 2)", "expected_output": "1000"}, {"input": "(7, 2)", "expected_output": "111"}]
def change_base(x: Nat, base: Nat) -> String """Change numerical base of input number x to base. return string representation after the conversion. base numbers are less than 10. """
def problem_spec -- function signature (implementation: Nat β†’ Nat -> String) -- inputs (x base: Nat) := -- spec let spec (result: String) := let result_array := result.toList.map (fun c => c.toNat - '0'.toNat); let pow_array := (List.range result_array.length).map (fun i => base^(result_array.length - i - 1) * result_a...
def generated_spec -- function signature (impl: Nat β†’ Nat β†’ String) -- inputs (x base: Nat) : Prop :=
theorem spec_isomorphism: βˆ€ impl, (βˆ€ x y, problem_spec impl x y) ↔ (βˆ€ x y, generated_spec impl x y) :=
sorry
def implementation (x base: Nat) : String :=
sorry
-- #test implementation 8 3 = '22' -- #test implementation 8 2 = '1000' -- #test implementation 7 2 = '111'
theorem correctness (x base : Nat) : problem_spec implementation x base :=
by unfold problem_spec let result := implementation x base use result simp [result] sorry
null
null
null
def triangle_area(a: float, h: float) -> float
Given length of a side and high return area for a triangle.
[{"input": "(5, 3)", "expected_output": 7.5}, {"input": "(8, 2)", "expected_output": 8.0}]
def triangle_area(a: float, h: float) -> float """Given length of a side and high return area for a triangle. """
def problem_spec -- function signature (implementation: Rat β†’ Rat -> Rat) -- inputs (a h: Rat) := -- spec let spec (result: Rat) := a = 0 β†’ result = 0 ∧ (a β‰  0 β†’ (2 * result) / a = h); -- -- program termination βˆƒ result, implementation a h = result ∧ spec result --
def generated_spec -- function signature (impl: Rat β†’ Rat β†’ Rat) -- inputs (a h: Rat) : Prop :=
theorem spec_isomorphism: βˆ€ impl, (βˆ€ x y, problem_spec impl x y) ↔ (βˆ€ x y, generated_spec impl x y) :=
sorry
def implementation (a h: Rat) : Rat :=
0.5 * a * h
-- #test implementation 5 3 = 7.5 -- #test implementation 8 2 = 8.0
theorem correctness (a h : Rat) : problem_spec implementation a h :=
by unfold problem_spec let result := implementation a h use result simp [result] sorry
null
null
null
def fib4(n: int)
The Fib4 number sequence is a sequence similar to the Fibbonacci sequnece that's defined as follows: fib4(0) -> 0 fib4(1) -> 0 fib4(2) -> 2 fib4(3) -> 0 fib4(n) -> fib4(n-1) + fib4(n-2) + fib4(n-3) + fib4(n-4). Please write a function to efficiently compute the n-th element of the fib4 number sequence. Do not use recu...
[{"input": 5, "output": 4}, {"input": 6, "output": 8}, {"input": 7, "output": 14}]
def fib4(n: int) """The Fib4 number sequence is a sequence similar to the Fibbonacci sequnece that's defined as follows: fib4(0) -> 0 fib4(1) -> 0 fib4(2) -> 2 fib4(3) -> 0 fib4(n) -> fib4(n-1) + fib4(n-2) + fib4(n-3) + fib4(n-4). Please write a function to efficiently compute the n-th element of the fib4 number sequen...
def problem_spec -- function signature (impl: Nat β†’ Nat) -- inputs (n: Nat) := -- spec let spec (result: Nat) := fibonacci_non_computable_4 n result -- program terminates βˆƒ result, impl n = result ∧ -- return value satisfies spec spec result
def generated_spec -- function signature (impl: Nat β†’ Nat) -- inputs (x: Nat) : Prop :=
theorem spec_isomorphism: βˆ€ impl, (βˆ€ x, problem_spec impl x) ↔ (βˆ€ x, generated_spec impl x) :=
sorry
def implementation (n: Nat) : Nat :=
sorry
-- #test implementation 5 = 4 -- #test implementation 6 = 8 -- #test implementation 7 = 14
theorem correctness (n: Nat) : problem_spec implementation n :=
by unfold problem_spec let result := implementation n use result simp [result] repeat sorry
/-- name: fibonacci_non_computable_4 use: | Non-computable definition to check if a number is a Fibonacci number such that fib(n) = fib(n - 1) + fib(n - 2) + fib(n - 3) + fib(n - 4). problems: - 46 -/ inductive fibonacci_non_computable_4 : β„• β†’ β„• β†’ Prop | base0 : fibonacci_non_computable_4 0 0 | base1 : fibonacci_...
null
null
def median(numbers: List[float]) -> float
Return median of elements in the list l
[{"input": [3, 1, 2, 4, 5], "output": 3}, {"input": [-10, 4, 6, 1000, 10, 20], "output": 15.0}]
def median(numbers: List[float]) -> float """Return median of elements in the list l """
def problem_spec -- function signature (implementation: List Rat β†’ Rat) -- inputs (numbers: List Rat) := -- spec let spec (result: Rat) := 0 < numbers.length β†’ let less_eq := (numbers.filter (fun x => x ≀ result)); let more_eq := (numbers.filter (fun x => result ≀ x)); let max_more_eq := more_eq.max?; let min...
def generated_spec -- function signature (impl: List Rat β†’ Rat) -- inputs (x: List Rat) : Prop :=
theorem spec_isomorphism: βˆ€ impl, (βˆ€ x, problem_spec impl x) ↔ (βˆ€ x, generated_spec impl x) :=
sorry
def implementation (numbers: List Rat) : Rat :=
sorry
-- #test implementation [3, 1, 2, 4, 5] = 3 -- #test implementation [-10, 4, 6, 1000, 10, 20] = 15.0
theorem correctness (numbers: List Rat) : problem_spec implementation numbers :=
by unfold problem_spec let result := implementation numbers use result simp [result] repeat sorry
null
null
null
def is_palindrome(string: str) -> Bool
Checks if given string is a palindrome
[{"input": "", "expected_output": true}, {"input": "aba", "expected_output": true}, {"input": "aaaaa", "expected_output": "True"}, {"input": "zbcd", "expected_output": "False"}]
def is_palindrome(string: str) -> Bool """Checks if given string is a palindrome """
def problem_spec -- function signature (implementation: String β†’ Bool) -- inputs (string: String) := -- spec let spec (result: Bool) := result ↔ is_palindrome string -- program termination βˆƒ result, implementation string = result ∧ spec result
def generated_spec -- function signature (impl: String β†’ Bool) -- inputs (x: String) : Prop :=
theorem spec_isomorphism: βˆ€ impl, (βˆ€ x, problem_spec impl x) ↔ (βˆ€ x, generated_spec impl x) :=
sorry
def implementation (string: String) : Bool :=
sorry
-- #test implementation "" = true -- #test implementation "aba" = true -- #test implementation "aaaaa" = true -- #test implementation "zbcd" = false
theorem correctness (s: String) : problem_spec implementation s :=
by unfold problem_spec let result := implementation s use result simp [result] sorry
/-- name: is_palindrome use: | Helper to check if a string is a palindrome. problems: - 10 - 48 -/ def is_palindrome (s: String): Bool := s = s.toList.reverse.asString
null
null
def modp(n: Nat, p: Nat) -> Nat
Return 2^n modulo p (be aware of numerics).
[{"input": [3, 5], "expected_output": 3}, {"input": [1101, 101], "expected_output": 2}, {"input": [0, 101], "expected_output": 0}, {"input": [100, 101], "expected_output": 1}]
def modp(n: Nat, p: Nat) -> Nat """Return 2^n modulo p (be aware of numerics). """
def problem_spec -- function signature (implementation: Nat β†’ Nat β†’ Nat) -- inputs (n p: Nat) := -- spec let spec (result: Nat) := 0 < p ∧ result < p ∧ (βˆƒ k : Nat, p * k + result = Nat.pow 2 n) -- program termination βˆƒ result, implementation n p = result ∧ spec result
def generated_spec -- function signature (impl: Nat β†’ Nat β†’ Nat) -- inputs (n p: Nat) : Prop :=
theorem spec_isomorphism: βˆ€ impl, (βˆ€ x y, problem_spec impl x y) ↔ (βˆ€ x y, generated_spec impl x y) :=
sorry
def implementation (n p: Nat) : Nat :=
sorry
-- #test implementation 3 5 = 3 -- #test implementation 1101 101 = 2 -- #test implementation 0 101 = 1 -- #test implementation 3 11 = 8 -- #test implementation 100 101 = 1
theorem correctness (n p: Nat) : problem_spec implementation n p :=
by unfold problem_spec let result := implementation n p use result simp [result] sorry
null
null
null
def encode_shift(s: String) -> String
returns encoded string by shifting every character by 5 in the alphabet.
[{"input": "abc", "expected_output": "fgh"}, {"input": "xyz", "expected_output": "cde"}, {"input": "aaa", "expected_output": "fff"}]
def encode_shift(s: String) -> String """returns encoded string by shifting every character by 5 in the alphabet. """
def problem_spec -- function signature (implementation: String β†’ String) -- inputs (s : String) := let isAlphabetic (string: String) : Bool := βˆ€ i, i < string.length β†’ let c := string.get! ⟨i⟩; ('a'.toNat ≀ c.toNat ∧ c.toNat ≀ 'z'.toNat) ∨ ('A'.toNat ≀ c.toNat ∧ c.toNat ≀ 'Z'.toNat) -- spec let spec (result: String) :=...
def generated_spec -- function signature (impl: String β†’ String) -- inputs (s: String) : Prop :=
theorem spec_isomorphism: βˆ€ impl, (βˆ€ x, problem_spec impl x) ↔ (βˆ€ x, generated_spec impl x) :=
sorry
def implementation (s: String) : String :=
sorry
-- #test implementation "abc" = "fgh" -- #test implementation "xyz" = "cde" -- #test implementation "aaa" = "fff"
theorem correctness (s: String) : problem_spec implementation s :=
by unfold problem_spec let result := implementation s use result simp [result] sorry
null
null
null
def remove_vowels(string: str) -> string
remove_vowels is a function that takes string and returns string without vowels.
[{"input": "", "expected_output": ""}, {"input": "abcdef\nghijklm", "expected_output": "bcdf\nghjklm"}, {"input": "abcdef", "expected_output": "bcdf"}, {"input": "aaaaa", "expected_output": ""}, {"input": "aaBAA", "expected_output": "B"}]
def remove_vowels(string: str) -> string """remove_vowels is a function that takes string and returns string without vowels. """
def problem_spec -- function signature (implementation: String β†’ String) -- inputs (string: String) := let is_consonant (c: Char): Bool := let vowels := "aeiouAEIOU" not (vowels.contains c); -- spec let spec (result: String) := result.all (Ξ» c => is_consonant c) ∧ result.length ≀ string.length ∧ βˆ€ c, result.contain...
def generated_spec -- function signature (impl: String β†’ String) -- inputs (string : String) : Prop :=
theorem spec_isomorphism: βˆ€ impl, (βˆ€ string, problem_spec impl string) ↔ (βˆ€ string, generated_spec impl string) :=
sorry
def implementation (string: String) : String :=
sorry
-- #test implementation "" = "" -- #test implementation "cat" = "catac" -- #test implementation "cata" = "catac"
theorem correctness (s: String) : problem_spec implementation s :=
by unfold problem_spec let result := implementation s use result simp [result] sorry
null
null
null
def below_threshold(numbers: List[Int], threshold: Int) -> bool
Return True if all numbers in the list l are below threshold t, and False otherwise.
[{"input": [[1, 2, 4, 10], 100], "expected_output": true}, {"input": [[1, 20, 4, 10], 5], "expected_output": false}]
def below_threshold(numbers: List[Int], threshold: Int) -> bool """Return True if all numbers in the list l are below threshold t, and False otherwise."""
def problem_spec -- function signature (impl: List Int β†’ Int β†’ Bool) -- inputs (numbers: List Int) (threshold: Int) := -- spec let numbers_below_threshold := βˆ€ i, i < numbers.length β†’ numbers[i]! < threshold; let spec (res: Bool) := (numbers.length = 0 β†’ res) ∧ (res ↔ numbers_below_threshold) -- program terminates βˆƒ ...
def generated_spec -- function signature (impl: List Int β†’ Int β†’ Bool) -- inputs (numbers : List Int) (threshold : Int) : Prop :=
theorem spec_isomorphism: βˆ€ impl, (βˆ€ numbers threshold, problem_spec impl numbers threshold) ↔ (βˆ€ numbers threshold, generated_spec impl numbers threshold) :=
sorry
def implementation (numbers: List Int) (threshold: Int) : Bool :=
sorry
-- #test implementation ([1, 2, 4, 10]: List Int) 100 = true -- #test implementation ([1, 20, 4, 10]: List Int) 5 = false
theorem correctness (numbers: List Int) (threshold: Int) : problem_spec implementation numbers threshold :=
by unfold problem_spec let result := implementation numbers threshold use result simp [result] sorry
null
null
null
def add(x: Int, y: Int) -> Int
Add two numbers x and y
[{"input": [2, 3], "expected_output": 5}, {"input": [5, 7], "expected_output": 12}]
def add(x: Int, y: Int) -> Int """Add two numbers x and y"""
def problem_spec -- function signature (impl: Int β†’ Int β†’ Int) -- inputs (x y: Int) := -- spec let spec (res: Int) := res - x - y = 0 -- program terminates βˆƒ result, impl x y = result ∧ -- return value satisfies spec spec result -- if result then spec else Β¬spec
def generated_spec -- function signature (impl: Int β†’ Int β†’ Int) -- inputs (x y: Int) : Prop :=
theorem spec_isomorphism: βˆ€ impl, (βˆ€ x y, problem_spec impl x y) ↔ (βˆ€ x y, generated_spec impl x y) :=
sorry
def implementation (x y: Int) : Int :=
sorry
-- #test implementation 2 3 = 5 -- #test implementation 5 7 = 12
theorem correctness (x y: Int) : problem_spec implementation x y :=
by unfold problem_spec let result := implementation x y use result simp [result] sorry
null
null
null
def same_chars(s0: string, s1: string) -> Bool
Check if two words have the same characters.
[{"input": ["eabcdzzzz", "dddzzzzzzzddeddabc"], "expected_output": true}, {"input": ["eabcd", "dddddddabc"], "expected_output": false}]
def same_chars(s0: string, s1: string) -> Bool """Check if two words have the same characters."""
def problem_spec -- function signature (impl: String β†’ String β†’ Bool) -- inputs (s0 s1: String) := -- spec let spec (res: Bool) := res ↔ (βˆ€ c : Char, c ∈ s0.toList ↔ c ∈ s1.toList) -- program terminates βˆƒ result, impl s0 s1 = result ∧ -- return value satisfies spec spec result -- if result then spec else Β¬spec
def generated_spec -- function signature (impl: String β†’ String β†’ Bool) -- inputs (s0 s1: String) : Prop :=
theorem spec_isomorphism: βˆ€ impl, (βˆ€ s0 s1, problem_spec impl s0 s1) ↔ (βˆ€ s0 s1, generated_spec impl s0 s1) :=
sorry
def implementation (s0 s1: String) : Bool :=
sorry
-- #test implementation 'eabcdzzzz' 'dddzzzzzzzddeddabc' = true -- #test implementation 'abcd' 'dddddddabc' = true -- #test implementation 'dddddddabc' 'abcd' = true -- #test implementation 'eabcd' 'dddddddabc' = false -- #test implementation 'abcd' 'dddddddabce' = false -- #test implementation 'eabcdzzzz' 'dddzzzzzzzd...
theorem correctness (s0 s1: String) : problem_spec implementation s0 s1 :=
by unfold problem_spec let result := implementation s0 s1 use result simp [result] sorry
null
null
null
def fib(n: int) -> int
Return n-th Fibonacci number.
[{"input": 10, "expected_output": 55}, {"input": 1, "expected_output": 1}, {"input": 8, "expected_output": 21}]
def fib(n: int) -> int """Return n-th Fibonacci number. """
def problem_spec -- function signature (implementation: Nat β†’ Nat) -- inputs (n: Nat) := -- spec let spec (result: Nat) := fibonacci_non_computable n result -- program termination βˆƒ result, implementation n = result ∧ spec result
def generated_spec -- function signature (impl: Nat β†’ Nat) -- inputs (x : Nat) : Prop :=
theorem spec_isomorphism: βˆ€ impl, (βˆ€ n, problem_spec impl n) ↔ (βˆ€ n, generated_spec impl n) :=
sorry
def implementation (n: Nat) : Nat :=
sorry
-- #test implementation 10 = 55 -- #test implementation 1 = 1 -- #test implementation 8 = 21
theorem correctness (n: Nat) : problem_spec implementation n :=
by unfold problem_spec let result := implementation n use result simp [result] repeat sorry
/-- name: fibonacci_non_computable use: | Non-computable definition to check if a number is a Fibonacci number. problems: - 55 sample_problems: - 3 -/ inductive fibonacci_non_computable : β„• β†’ β„• β†’ Prop | base0 : fibonacci_non_computable 0 0 | base1 : fibonacci_non_computable 1 1 | step : βˆ€ n f₁ fβ‚‚, fibonacci_non_...
null
null
def correct_bracketing(brackets: str) -> Bool
brackets is a string of "<" and ">". return True if every opening bracket has a corresponding closing bracket, i.e., (each open bracket is properly closed)
[{"input": "<", "expected_output": false}, {"input": "<>", "expected_output": true}, {"input": "<<><>>", "expected_output": true}, {"input": "><<>", "expected_output": false}]
def correct_bracketing(brackets: str) -> Bool """brackets is a string of "<" and ">". return True if every opening bracket has a corresponding closing bracket, i.e., (each open bracket is properly closed) """
def problem_spec -- function signature (impl: String β†’ Bool) -- inputs (brackets: String) := -- spec let spec (result: Bool) := brackets.data.all (fun c => c = '<' ∨ c = '>') β†’ (result ↔ balanced_paren_non_computable brackets '<' '>') -- program terminates βˆƒ result, impl brackets = result ∧ -- return value satisfie...
def generated_spec -- function signature (impl: String β†’ Bool) -- inputs (brackets : String) : Prop :=
theorem spec_isomorphism: βˆ€ impl, (βˆ€ brackets, problem_spec impl brackets) ↔ (βˆ€ brackets, generated_spec impl brackets) :=
sorry
def implementation (brackets: String) : Bool :=
sorry
-- #test implementation "<" = false -- #test implementation "<>" = true -- #test implementation "<<><>>" = true -- #test implementation "><<>" = false
theorem correctness (brackets: String) : problem_spec implementation brackets :=
by unfold problem_spec let result := implementation brackets use result simp [result] sorry
null
null
null
def monotonic(numbers: List[int]) -> Bool
Return True if list elements are monotonically increasing or decreasing.
[{"input": [1, 2, 4, 20], "expected_output": true}, {"input": [1, 20, 4, 10], "expected_output": false}, {"input": [4, 1, 0, -10], "expected_output": true}]
def monotonic(numbers: List[int]) -> Bool """Return True if list elements are monotonically increasing or decreasing. """
def problem_spec -- function signature (implementation: List Int β†’ Bool) -- inputs (numbers: List Int) := let non_ordered := βˆƒ i j, i < numbers.length - 1 ∧ j < numbers.length - 1 ∧ (numbers[i]! < numbers[i+1]!) ∧ (numbers[j+1]! < numbers[j]!); -- spec let spec (result: Bool) := 1 < numbers.length β†’ result ↔ Β¬non_o...
def generated_spec -- function signature (impl: List Int β†’ Bool) -- inputs (numbers : List Int) : Prop :=
theorem spec_isomorphism: βˆ€ impl, (βˆ€ numbers, problem_spec impl numbers) ↔ (βˆ€ numbers, generated_spec impl numbers) :=
sorry
def implementation (numbers: List Int) : Bool :=
sorry
-- #test implementation [1, 2, 4, 20] = true -- #test implementation [1, 20, 4, 10] = false -- #test implementation [4, 1, 0, -10] = true
theorem correctness (numbers: List Int) : problem_spec implementation numbers :=
by unfold problem_spec let result := implementation numbers use result simp [result] sorry
null
null
null
def common(l1: List[Int], l2: List[Int]) -> List[Int]
Return sorted unique common elements for two lists.
[{"input": [[1, 4, 3, 34, 653, 2, 5], [5, 7, 1, 5, 9, 653, 121]], "expected_output": [1, 5, 653]}, {"input": [[5, 3, 2, 8], [3, 2]], "expected_output": [2, 3]}]
def common(l1: List[Int], l2: List[Int]) -> List[Int] """Return sorted unique common elements for two lists. """
def problem_spec -- function signature (implementation: List Int β†’ List Int β†’ List Int) -- inputs (l1 l2: List Int) := let is_unique (result: List Int) := βˆ€ i j, i < result.length β†’ j < result.length β†’ i β‰  j β†’ result[i]! β‰  result[j]!; let is_sorted (result: List Int) := βˆ€ i, i < result.length - 1 β†’ result[i]! ≀...
def generated_spec -- function signature (impl: List Int β†’ List Int β†’ List Int) -- inputs (x y: List Int) : Prop :=
theorem spec_isomorphism: βˆ€ impl, (βˆ€ x y, problem_spec impl x y) ↔ (βˆ€ x y, generated_spec impl x y) :=
sorry
def implementation (l1 l2: List Int) : List Int :=
sorry
-- #test implementation [1, 4, 3, 34, 653, 2, 5] [5, 7, 1, 5, 9, 653, 121] = [1, 5, 653] -- #test implementation [5, 3, 2, 8] [3, 2] = [2, 3]
theorem correctness (l1 l2: List Int) : problem_spec implementation l1 l2 :=
by unfold problem_spec let result := implementation l1 l2 use result simp [result] sorry
null
null
null
def largest_prime_factor(n: Nat) -> Nat
Return the largest prime factor of n. Assume n > 1 and is not a prime.
[{"input": 13195, "expected_output": 29}, {"input": 2048, "expected_output": 2}]
def largest_prime_factor(n: Nat) -> Nat """Return the largest prime factor of n. Assume n > 1 and is not a prime. """
def problem_spec -- function signature (implementation: Nat β†’ Nat) -- inputs (n: Nat) := -- spec let spec (result: Nat) := 1 < n ∧ Β¬ Nat.Prime n β†’ (Nat.Prime result ∧ result ∣ n ∧ βˆ€ i, i < n ∧ i ∣ n ∧ Nat.Prime i β†’ i ≀ result); -- program termination βˆƒ result, implementation n = result ∧ spec result
def generated_spec -- function signature (impl: Nat β†’ Nat) -- inputs (x : Nat) : Prop :=
theorem spec_isomorphism: βˆ€ impl, (βˆ€ x, problem_spec impl x) ↔ (βˆ€ x, generated_spec impl x) :=
sorry
def implementation (n: Nat) : Nat :=
sorry
-- #test implementation 13195 = 29 -- #test implementation 2048 = 2
theorem correctness (n: Nat) : problem_spec implementation n :=
by unfold problem_spec let result := implementation n use result simp [result] sorry
null
null
null
def sum_to_n(n: Nat) -> Nat
sum_to_n is a function that sums numbers from 1 to n.
[{"input": 30, "expected_output": 465}, {"input": 100, "expected_output": 4950}]
def sum_to_n(n: Nat) -> Nat """sum_to_n is a function that sums numbers from 1 to n. """
def problem_spec -- function signature (implementation: Nat β†’ Nat) -- inputs (n : Nat) := -- spec let spec (result: Nat) := 0 < n β†’ (result = 1 ↔ n = 1) ∧ (βˆ€ i, implementation (i + 1) - (implementation i) = i + 1) -- program termination βˆƒ result, implementation n = result ∧ spec result
def generated_spec -- function signature (impl: Nat β†’ Nat) -- inputs (n : Nat) : Prop :=
theorem spec_isomorphism: βˆ€ impl, (βˆ€ n, problem_spec impl n) ↔ (βˆ€ n, generated_spec impl n) :=
sorry
def implementation (n: Nat) : Nat :=
sorry
-- #test implementation 30 = 465 -- #test implementation 100 = 5050 -- #test implementation 5 = 15 -- #test implementation 10 = 55 -- #test implementation 1 = 1
theorem correctness (n: Nat) : problem_spec implementation n :=
by unfold problem_spec let result := implementation n use result simp [result] sorry
null
null
null
def correct_bracketing(brackets: str) -> Bool
brackets is a string of "(" and ")". return True if every opening bracket has a corresponding closing bracket.
[{"input": "(", "expected_output": false}, {"input": "()", "expected_output": true}, {"input": "(()())", "expected_output": true}, {"input": ")(()", "expected_output": false}]
def correct_bracketing(brackets: str) -> Bool """brackets is a string of "(" and ")". return True if every opening bracket has a corresponding closing bracket. """
def problem_spec -- function signature (impl: String β†’ Bool) -- inputs (brackets: String) := -- spec let spec (result: Bool) := brackets.data.all (fun c => c = '(' ∨ c = ')') β†’ (result ↔ balanced_paren_non_computable brackets '(' ')') -- program terminates βˆƒ result, impl brackets = result ∧ -- return value satisfie...
def generated_spec -- function signature (impl: String β†’ Bool) -- inputs (x : String) : Prop :=
theorem spec_isomorphism: βˆ€ impl, (βˆ€ x, problem_spec impl x) ↔ (βˆ€ x, generated_spec impl x) :=
sorry
def implementation (paren_string: String) : Bool :=
sorry
-- #test implementation "(" = false -- #test implementation "()" = true -- #test implementation "(()())" = true -- #test implementation ")(()" = false
theorem correctness (brackets: String) : problem_spec implementation brackets :=
by unfold problem_spec let result := implementation brackets use result simp [result] sorry
null
null
null
def derivative(xs: List Int) -> List Int
xs represent coefficients of a polynomial. xs[0] + xs[1] * x + xs[2] * x^2 + .... Return derivative of this polynomial in the same form.
[{"input": [3, 1, 2, 4, 5], "expected_output": [1, 4, 12, 20]}, {"input": [1, 2, 3], "expected_output": [2, 6]}]
def derivative(xs: List Int) -> List Int """xs represent coefficients of a polynomial. xs[0] + xs[1] * x + xs[2] * x^2 + .... Return derivative of this polynomial in the same form. """
def problem_spec -- function signature (impl: List Int β†’ List Int) -- inputs (xs: List Int) := -- spec let spec (result: List Int) := result.length = xs.length - 1 ∧ result = (check_derivative xs.reverse).reverse -- program terminates βˆƒ result, impl xs = result ∧ -- return value satisfies spec spec result
def generated_spec -- function signature (impl: List Int β†’ List Int) -- inputs (xs : List Int) : Prop :=
theorem spec_isomorphism: βˆ€ impl, (βˆ€ xs, problem_spec impl xs) ↔ (βˆ€ xs, generated_spec impl xs) :=
sorry
def implementation (xs: List Int) : List Int :=
sorry
-- #test implementation [3, 1, 2, 4, 5] : List Int = [1, 4, 12, 20] -- #test implementation [1, 2, 3] : List Int = [2, 6]
theorem correctness (xs: List Int) : problem_spec implementation xs :=
by unfold problem_spec let result := implementation xs use result simp [result] sorry
null
null
null
def fibfib(n: int)
The FibFib number sequence is a sequence similar to the Fibbonacci sequnece that's defined as follows: fibfib(0) == 0 fibfib(1) == 0 fibfib(2) == 1 fibfib(n) == fibfib(n-1) + fibfib(n-2) + fibfib(n-3). Please write a function to efficiently compute the n-th element of the fibfib number sequence.
[{"input": 1, "output": 0}, {"input": 5, "output": 4}, {"input": 8, "output": 24}]
def fibfib(n: int) """The FibFib number sequence is a sequence similar to the Fibbonacci sequnece that's defined as follows: fibfib(0) == 0 fibfib(1) == 0 fibfib(2) == 1 fibfib(n) == fibfib(n-1) + fibfib(n-2) + fibfib(n-3). Please write a function to efficiently compute the n-th element of the fibfib number sequence. "...
def problem_spec -- function signature (implementation: Nat β†’ Nat) -- inputs (n: Nat) := -- spec let spec (result: Nat) := fibonacci_non_computable_3 n result -- program termination βˆƒ result, implementation n = result ∧ spec result
def generated_spec -- function signature (impl: Nat β†’ Nat) -- inputs (x : Nat) : Prop :=
theorem spec_isomorphism: βˆ€ impl, (βˆ€ x, problem_spec impl x) ↔ (βˆ€ x, generated_spec impl x) :=
sorry
def implementation (n: Nat) : Nat :=
sorry
-- #test implementation 1 = 0 -- #test implementation 5 = 4 -- #test implementation 8 = 24
theorem correctness (n: Nat) : problem_spec implementation n :=
by unfold problem_spec let result := implementation n use result simp [result] repeat sorry
/-- name: fibonacci_non_computable_3 use: | Non-computable definition to check if a number is a Fibonacci number such that fib(n) = fib(n - 1) + fib(n - 2) + fib(n - 3). problems: - 63 -/ inductive fibonacci_non_computable_3 : β„• β†’ β„• β†’ Prop | base0 : fibonacci_non_computable_3 0 0 | base1 : fibonacci_non_computabl...
null
null
def remove_vowels(string: str) -> Nat
Write a function vowels_count which takes a string representing a word as input and returns the number of vowels in the string. Vowels in this case are 'a', 'e', 'i', 'o', 'u'. Here, 'y' is also a vowel, but only when it is at the end of the given word.
[{"input": "abcde", "expected_output": 2}, {"input": "ACEDY", "expected_output": 3}]
def remove_vowels(string: str) -> Nat """Write a function vowels_count which takes a string representing a word as input and returns the number of vowels in the string. Vowels in this case are 'a', 'e', 'i', 'o', 'u'. Here, 'y' is also a vowel, but only when it is at the end of the given word. """
def problem_spec -- function signature (implementation: String β†’ Nat) -- inputs (string: String) := let isVowel (c : Char) := let vowels := "aeiouAEIOU" vowels.contains c let isY (c : Char) := c = 'y' ∨ c = 'Y' -- spec let spec (result: Nat) := string.data.all (fun c => c.isAlpha) β†’ if string.length = 1 then resu...
def generated_spec -- function signature (impl: String β†’ Nat) -- inputs (x : String) : Prop :=
theorem spec_isomorphism: βˆ€ impl, (βˆ€ x, problem_spec impl x) ↔ (βˆ€ x, generated_spec impl x) :=
sorry
def implementation (string: String) : Nat :=
sorry
-- #test implementation "abcde" = 2 -- #test implementation "ACEDY" = 3
theorem correctness (s: String) : problem_spec implementation s :=
by unfold problem_spec let result := implementation s use result simp [result] sorry
null
null
null
def circular_shift(x: Int, shift: Int) -> String
Circular shift the digits of the integer x, shift the digits right by shift and return the result as a string. If shift > number of digits, return digits reversed.
[{"input": [12, 1], "expected_output": 21}, {"input": [12, 2], "expected_output": 12}]
def circular_shift(x: Int, shift: Int) -> String """Circular shift the digits of the integer x, shift the digits right by shift and return the result as a string. If shift > number of digits, return digits reversed. """
def problem_spec -- function signature (implementation: Nat β†’ Nat β†’ String) -- inputs (x shift: Nat) := let isReverse (s: String) : Bool := let n := s.length; βˆ€ i, i < n / 2 β†’ s.get! ⟨i⟩ = s.get! ⟨n - 1 - i⟩; -- spec let spec (result: String) := let x_str := Nat.repr x; result.length = x_str.length ∧ (x_str.length ...
def generated_spec -- function signature (impl: Nat β†’ Nat β†’ String) -- inputs (x y: Nat) : Prop :=
theorem spec_isomorphism: βˆ€ impl, (βˆ€ x y, problem_spec impl x y) ↔ (βˆ€ x y, generated_spec impl x y) :=
sorry
def implementation (x shift: Nat) : String :=
sorry
-- #test implementation (12 : Int) (1 : Int) = "21" -- #test implementation (12 : Int) (2 : Int) = "12"
theorem correctness (x shift: Nat) : problem_spec implementation x shift :=
by unfold problem_spec let result := implementation x shift use result simp [result] sorry
null
null
null
def digitSum(string: str) -> Nat
Write a function that takes a string as input and returns the sum of the upper characters only' ASCII codes.
[{"input": "", "expected_output": 0}, {"input": "abAB", "expected_output": 131}, {"input": "helloE", "expected_output": 69}]
def digitSum(string: str) -> Nat """Write a function that takes a string as input and returns the sum of the upper characters only' ASCII codes. """
def problem_spec -- function signature (implementation: String β†’ Nat) -- inputs (string: String) := let isUpper (c : Char) := 65 ≀ c.toNat ∧ c.toNat ≀ 90 -- spec let spec (result: Nat) := if string.length = 1 then result = if isUpper string.data[0]! then string.data[0]!.toNat else 0 else result = (if isUpper stri...
def generated_spec -- function signature (impl: String β†’ Nat) -- inputs (x: String) : Prop :=
theorem spec_isomorphism: βˆ€ impl, (βˆ€ x, problem_spec impl x) ↔ (βˆ€ x, generated_spec impl x) :=
sorry
def implementation (string: String) : Nat :=
sorry
-- #test implementation "" = 0 -- #test implementation "abAB" = 131 -- #test implementation "abcCd" = 67 -- #test implementation "helloE" = 69 -- #test implementation "woArBld" = 131 -- #test implementation "aAaaaXa" = 153
theorem correctness (s: String) : problem_spec implementation s :=
by unfold problem_spec let result := implementation s use result simp [result] sorry
null
null
null
def fruit_distribution(string: str, Nat n) -> Nat
In this task, you will be given a string that represents a number of apples and oranges that are distributed in a basket of fruit this basket contains apples, oranges, and mango fruits. Given the string that represents the total number of the oranges and apples and an integer that represent the total number of the frui...
[{"input": ["5 apples and 6 oranges", 19], "expected_output": 8}, {"input": ["0 apples and 1 oranges", 3], "expected_output": 2}, {"input": ["2 apples and 3 oranges", 100], "expected_output": 95}, {"input": ["100 apples and 1 oranges", 120], "expected_output": 19}]
def fruit_distribution(string: str, Nat n) -> Nat """In this task, you will be given a string that represents a number of apples and oranges that are distributed in a basket of fruit this basket contains apples, oranges, and mango fruits. Given the string that represents the total number of the oranges and apples and a...
def problem_spec -- function signature (implementation: String β†’ Nat β†’ Nat) -- inputs (string: String) (n : Nat) := -- spec let spec (result: Nat) := βˆƒ x y : Nat, x + y = n - result ∧ (String.join [x.repr, " apples and ", y.repr, " oranges"] = string) -- program termination βˆƒ result, implementation string n = result ∧ ...
def generated_spec -- function signature (impl: String β†’ Nat β†’ Nat) -- inputs (x: String) (y: Nat) : Prop :=
theorem spec_isomorphism: βˆ€ impl, (βˆ€ x y, problem_spec impl x y) ↔ (βˆ€ x y, generated_spec impl x y) :=
sorry
def implementation (string: String) (n: Nat) : Nat :=
sorry
-- #test implementation "5 apples and 6 oranges" 19 = 8 -- #test implementation "0 apples and 1 oranges" 3 = 2 -- #test implementation "2 apples and 3 oranges" 100 = 95 -- #test implementation "100 apples and 1 oranges" 120 = 19
theorem correctness (s: String) (n : Nat) : problem_spec implementation s n :=
by unfold problem_spec let result := implementation s n use result simp [result] sorry
null
null
null
def pluck(numbers: List[Int]) -> List[Int]
Given an array representing a branch of a tree that has non-negative integer nodes your task is to pluck one of the nodes and return it. The plucked node should be the node with the smallest even value. If multiple nodes with the same smallest even value are found return the node that has smallest index. The plucked n...
[{"input": [4, 2, 3], "expected_output": [2, 1]}, {"input": [1, 2, 3], "expected_output": [2, 1]}, {"input": [], "expected_output": []}, {"input": [5, 0, 3, 0, 4, 2], "expected_output": [0, 1]}]
def pluck(numbers: List[Int]) -> List[Int] """Given an array representing a branch of a tree that has non-negative integer nodes your task is to pluck one of the nodes and return it. The plucked node should be the node with the smallest even value. If multiple nodes with the same smallest even value are found return th...
def problem_spec -- function signature (implementation: List Nat β†’ List Nat) -- inputs (numbers: List Nat) := -- spec let spec (result: List Nat) := (result.length = 0 ↔ βˆ€ i, i < numbers.length β†’ numbers[i]! % 2 = 1) ∧ (result.length = 2 ↔ βˆƒ i, i < numbers.length ∧ numbers[i]! % 2 = 0 ∧ result[0]! = numbers[i]! ∧ ...
def generated_spec -- function signature (impl: List Nat β†’ List Nat) -- inputs (x: List Nat) : Prop :=
theorem spec_isomorphism: βˆ€ impl, (βˆ€ x, problem_spec impl x) ↔ (βˆ€ x, generated_spec impl x) :=
sorry
def implementation (numbers: List Nat) : List Nat :=
sorry
-- #test implementation [4, 2, 3] = [2, 1] -- #test implementation [1, 2, 3] = [2, 1] -- #test implementation [] = [] -- #test implementation [5, 0, 3, 0, 4, 2] = [0, 1] --
theorem correctness (numbers: List Nat) : problem_spec implementation numbers :=
by unfold problem_spec let result := implementation numbers use result simp [result] sorry
null
null
null
def search(numbers: List[int]) -> int
You are given a non-empty list of positive integers. Return the greatest integer that is greater than zero, and has a frequency greater than or equal to the value of the integer itself. The frequency of an integer is the number of times it appears in the list. If no such a value exist, return -1.
[{"input": [4, 1, 2, 2, 3, 1], "expected_output": 2}, {"input": [1, 2, 2, 3, 3, 3, 4, 4, 4], "expected_output": 3}, {"input": [5, 5, 4, 4, 4], "expected_output": -1}]
def search(numbers: List[int]) -> int """You are given a non-empty list of positive integers. Return the greatest integer that is greater than zero, and has a frequency greater than or equal to the value of the integer itself. The frequency of an integer is the number of times it appears in the list. If no such a value...
def problem_spec -- function signature (implementation: List Int β†’ Int) -- inputs (numbers: List Int) := -- spec let spec (result: Int) := 0 < numbers.length ∧ numbers.all (fun n => 0 < n) β†’ (result β‰  -1 ↔ βˆƒ i : Nat, i < numbers.length ∧ numbers[i]! = result ∧ numbers[i]! > 0 ∧ numbers[i]! ≀ (numbers.filter (fun x ...
def generated_spec -- function signature (impl: List Int β†’ Int) -- inputs (x: List Int) : Prop :=
theorem spec_isomorphism: βˆ€ impl, (βˆ€ x, problem_spec impl x) ↔ (βˆ€ x, generated_spec impl x) :=
sorry
def implementation (numbers: List Int) : (Int) :=
sorry
-- #test implementation [4, 1, 2, 2, 3, 1] = 2 -- #test implementation [1, 2, 2, 3, 3, 4, 4, 4] = 3 -- #test implementation [5, 5, 4, 4, 4] = -1
theorem correctness (numbers: List Int) : problem_spec implementation numbers :=
by unfold problem_spec let result := implementation numbers use result simp [result] sorry
null
null
null
def strange_sort_list(lst: List[int]) -> List[int]
Given list of integers, return list in strange order. Strange sorting is when you start with the minimum value, then the maximum of the remaining integers, then the minimum and so on.
[{"input": [1, 2, 3, 4], "expected_output": [1, 4, 2, 3]}, {"input": [5, 5, 5, 5], "expected_output": [5, 5, 5, 5]}, {"input": [], "expected_output": []}]
def strange_sort_list(lst: List[int]) -> List[int] """Given list of integers, return list in strange order. Strange sorting is when you start with the minimum value, then the maximum of the remaining integers, then the minimum and so on. """
def problem_spec -- function signature (implementation: List Int β†’ List Int) -- inputs (lst: List Int) := -- spec let spec (result: List Int) := let sorted_lst := lst.mergeSort; (List.Perm lst result) ∧ (forall i, (0 <= i ∧ i < lst.length ∧ i % 2 = 0) β†’ result[i]! = sorted_lst[i / 2]!) ∧ (forall i, (0 <= i ∧ i ...
def generated_spec -- function signature (impl: List Int β†’ List Int) -- inputs (lst: List Int) : Prop :=
theorem spec_isomorphism: βˆ€ impl, (βˆ€ lst, problem_spec impl lst) ↔ (βˆ€ lst, generated_spec impl lst) :=
sorry
def implementation (lst: List Int): List Int :=
sorry
-- #test implementation [1, 2, 3, 4] = [1, 4, 2, 3] -- #test implementation [5, 6, 7, 8, 9] = [5, 9, 6, 8, 7] -- #test implementation [1, 2, 3, 4, 5] = [1, 5, 2, 4, 3] -- #test implementation [5, 6, 7, 8, 9, 1] = [1, 9, 5, 8, 6, 7] -- #test implementation [5, 5, 5, 5] = [5, 5, 5, 5] -- #test implementation [] = [] -- #...
theorem correctness (lst: List Int) : problem_spec implementation lst :=
by sorry
null
null
null
def triangle_area(a: float, b: float, c: float) -> float
Given the lengths of the three sides of a triangle. Return the area of the triangle rounded to 2 decimal points if the three sides form a valid triangle. Otherwise return -1. Three sides make a valid triangle when the sum of any two sides is greater than the third side.
[{"input": "(3, 4, 5)", "expected_output": 6}, {"input": "(1, 2, 10)", "expected_output": -1}]
def triangle_area(a: float, b: float, c: float) -> float """Given the lengths of the three sides of a triangle. Return the area of the triangle rounded to 2 decimal points if the three sides form a valid triangle. Otherwise return -1. Three sides make a valid triangle when the sum of any two sides is greater than the t...
def problem_spec -- function signature (implementation: Rat β†’ Rat β†’ Rat β†’ Rat) -- inputs (a: Rat) (b: Rat) (c: Rat) := -- spec let spec (result : Rat) := let is_valid_triangle := (a + b > c) ∧ (a + c > b) ∧ (b + c > a); let s := (a + b + c) / 2; if is_valid_triangle then |result^2 - (s * (s-a) * (s-b...
def generated_spec -- function signature (impl: Rat β†’ Rat β†’ Rat β†’ Rat) -- inputs (a: Rat) (b: Rat) (c: Rat) : Prop :=
theorem spec_isomorphism: βˆ€ impl, (βˆ€ a b c, problem_spec impl a b c) ↔ (βˆ€ a b c, generated_spec impl a b c) :=
sorry
def implementation (a: Rat) (b: Rat) (c: Rat): Rat :=
sorry
-- #test implementation 3 4 5 = 6.00 -- #test implementation 1 2 10 = -1 -- #test implementation 4 8 5 = 8.18 -- #test implementation 2 2 2 = 1.73 -- #test implementation 1 2 3 = -1 -- #test implementation 10 5 7 = 16.25 -- #test implementation 2 6 3 = -1 -- #test implementation 1 1 1 = 0.43 -- #test implementation 2 ...
theorem correctness (a: Rat) (b: Rat) (c: Rat) : problem_spec implementation a b c :=
by sorry
null
null
null
def will_it_fly(q: List[int], w: int) -> bool
Write a function that returns True if the object q will fly, and False otherwise. The object q will fly if it's balanced (it is a palindromic list) and the sum of its elements is less than or equal the maximum possible weight w.
[{"input": "([1, 2], 5)", "expected_output": false}, {"input": "([3, 2, 3], 1)", "expected_output": false}, {"input": "([3, 2, 3], 9)", "expected_output": true}, {"input": "([3], 5)", "expected_output": true}]
def will_it_fly(q: List[int], w: int) -> bool """Write a function that returns True if the object q will fly, and False otherwise. The object q will fly if it's balanced (it is a palindromic list) and the sum of its elements is less than or equal the maximum possible weight w. """
def problem_spec -- function signature (implementation: List Int β†’ Int β†’ Bool) -- inputs (q: List Int) (w: Int) := -- spec let spec (result : Bool) := (result β†’ (List.Palindrome q)) ∧ (result β†’ (List.sum q ≀ w)) ∧ (Β¬(List.Palindrome q) β†’ Β¬ result) ∧ (Β¬(List.sum q ≀ w) β†’ Β¬ result) -- program termination βˆƒ result...
def generated_spec -- function signature (impl: List Int β†’ Int β†’ Bool) -- inputs (q: List Int) (w: Int) : Prop :=
theorem spec_isomorphism: βˆ€ impl, (βˆ€ q w, problem_spec impl q w) ↔ (βˆ€ q w, generated_spec impl q w) :=
sorry
def implementation (q: List Int) (w: Int) : Bool :=
(List.Palindrome q) ∧ (List.sum q ≀ w)
-- #test implementation [3, 2, 3] 9 = True -- #test implementation [1, 2] 5 = False -- #test implementation [3] 5 = True -- #test implementation [3, 2, 3] 1 = False -- #test implementation [1, 2, 3] 6 = False -- #test implementation [5] 5 = True
theorem correctness (q: List Int) (w: Int) : problem_spec implementation q w :=
by unfold problem_spec let result := implementation q w use result simp [result] simp [implementation] apply And.intro intro h_is_palindrome h_q_sum assumption apply And.intro intro h_palindrome simp [h_palindrome] intro h_q_sum h_palindrome assumption
null
null
null
def smallest_change(arr: List[int]) -> int
Given an array arr of integers, find the minimum number of elements that need to be changed to make the array palindromic. A palindromic array is an array that is read the same backwards and forwards. In one change, you can change one element to any other element.
[{"input": [1, 2, 3, 5, 4, 7, 9, 6], "expected_output": 4}, {"input": [1, 2, 3, 4, 3, 2, 2], "expected_output": 1}, {"input": [1, 2, 3, 2, 1], "expected_output": 0}]
def smallest_change(arr: List[int]) -> int """Given an array arr of integers, find the minimum number of elements that need to be changed to make the array palindromic. A palindromic array is an array that is read the same backwards and forwards. In one change, you can change one element to any other element. """
def problem_spec -- function signature (implementation: List Int β†’ Int) -- inputs (arr: List Int) := -- spec let spec (result : Int) := let swaps_done (arr1: List Int) (arr2: List Int) := ((List.finRange (arr1.length)).filter (fun idx => arr1[idx]? β‰  arr2[idx]?)).length/2 βˆ€ palin_perm, (List.Perm arr palin_perm...
def generated_spec -- function signature (impl: List Int β†’ Int) -- inputs (arr: List Int) : Prop :=
theorem spec_isomorphism: βˆ€ impl, (βˆ€ arr, problem_spec impl arr) ↔ (βˆ€ arr, generated_spec impl arr) :=
sorry
def implementation (arr: List Int) : Int :=
((List.finRange (arr.length/2)).filter (fun i => arr[i]? != arr[arr.length - 1 - i]?)).length
-- #test implementation [1,2,3,5,4,7,9,6] = 4 -- #test implementation [1, 2, 3, 4, 3, 2, 2] = 1 -- #test implementation [1, 4, 2] = 1 -- #test implementation [1, 4, 4, 2] = 1 -- #test implementation [1, 2, 3, 2, 1] = 0 -- #test implementation [3, 1, 1, 3] = 0 -- #test implementation [1] = 0 -- #test implementation [0, ...
theorem correctness (arr: List Int) : problem_spec implementation arr :=
by sorry
null
null
null
def total_match(lst1: List[str], lst2: List[str]) -> List[str]
Write a function that accepts two lists of strings and returns the list that has total number of chars in the all strings of the list less than the other list. If the two lists have the same number of chars, return the first list.
[{"input": "([], [])", "expected_output": []}, {"input": "(['hi', 'admin'], ['hI', 'Hi'])", "expected_output": ["hI", "Hi"]}, {"input": "(['hi', 'admin'], ['hi', 'hi', 'admin', 'project'])", "expected_output": ["hi", "admin"]}, {"input": "(['hi', 'admin'], ['hI', 'hi', 'hi'])", "expected_output": ["hI", "hi", "hi"]}, {...
def total_match(lst1: List[str], lst2: List[str]) -> List[str] """Write a function that accepts two lists of strings and returns the list that has total number of chars in the all strings of the list less than the other list. If the two lists have the same number of chars, return the first list. """
def problem_spec -- function signature (implementation: List String β†’ List String β†’ List String) -- inputs (lst1: List String) (lst2: List String) := let sum_chars (xs: List String) : Int := xs.foldl (Ξ» acc a => acc + a.length) 0; -- spec let spec (result : List String) := ((result = lst1) ∨ (result = lst2)) ∧ ...
def generated_spec -- function signature (impl: List String β†’ List String β†’ List String) -- inputs (lst1: List String) (lst2: List String) : Prop :=
theorem spec_isomorphism: βˆ€ impl, (βˆ€ lst1 lst2, problem_spec impl lst1 lst2) ↔ (βˆ€ lst1 lst2, generated_spec impl lst1 lst2) :=
sorry
def implementation (lst1: List String) (lst2: List String) : List String :=
sorry
-- #test implementation [] [] = [] -- #test implementation ["hi", "admin"] ["hi", "hi"] = ["hi", "hi"] -- #test implementation ["hi", "admin"] ["hi", "hi", "admin", "project"] = ["hi", "admin"] -- #test implementation ["4"] ["1", "2", "3", "4", "5"] = ["4"] -- #test implementation ["hi", "admin"] ["hI", "Hi"] = ["hI", ...
theorem correctness (lst1: List String) (lst2: List String) : problem_spec implementation lst1 lst2 :=
by sorry
null
null
null
def is_multiply_prime(a: int) -> bool
Write a function that returns true if the given number is the multiplication of 3 prime numbers and false otherwise. Knowing that (a) is less then 100.
[{"input": 30, "expected_output": true}]
def is_multiply_prime(a: int) -> bool """Write a function that returns true if the given number is the multiplication of 3 prime numbers and false otherwise. Knowing that (a) is less then 100. """
def problem_spec -- function signature (implementation: Int β†’ Bool) -- inputs (a: Int) := -- spec let spec (result: Bool) := (a < 100) β†’ result ↔ exists a' b c, (Nat.Prime a') ∧ (Nat.Prime b) ∧ (Nat.Prime c) ∧ (a == a'*b*c) -- program termination βˆƒ result, implementation a = result ∧ spec result
def generated_spec -- function signature (impl: Int β†’ Bool) -- inputs (a: Int) : Prop :=
theorem spec_isomorphism: βˆ€ impl, (βˆ€ a, problem_spec impl a) ↔ (βˆ€ a, generated_spec impl a) :=
sorry
def implementation (a: Int) : Bool :=
sorry
-- #test implementation 5 = False -- #test implementation 30 = True -- #test implementation 8 = True -- #test implementation 10 = False -- #test implementation 125 = True -- #test implementation (3 * 5 * 7) = True -- #test implementation (3 * 6 * 7) = False -- #test implementation (9 * 9 * 9) = False -- #test implement...
theorem correctness (a: Int) : problem_spec implementation a :=
by sorry
null
null
null
def is_simple_power(x: int, n: int) -> bool
Your task is to write a function that returns true if a number x is a simple power of n and false in other cases. x is a simple power of n if n**int=x
[{"input": "(1, 4)", "expected_output": true}, {"input": "(2, 2)", "expected_output": true}, {"input": "(8, 2)", "expected_output": true}, {"input": "(3, 2)", "expected_output": false}, {"input": "(3, 1)", "expected_output": false}, {"input": "(5, 3)", "expected_output": false}]
def is_simple_power(x: int, n: int) -> bool """Your task is to write a function that returns true if a number x is a simple power of n and false in other cases. x is a simple power of n if n**int=x """
def problem_spec -- function signature (implementation: Int β†’ Int β†’ Bool) -- inputs (x: Int) (n: Int) := -- spec let spec (result: Bool) := result ↔ exists k: Nat, x = n^k -- program termination βˆƒ result, implementation x n = result ∧ spec result
def generated_spec -- function signature (impl: Int β†’ Int β†’ Bool) -- inputs (x: Int) (n: Int) : Prop :=
theorem spec_isomorphism: βˆ€ impl, (βˆ€ x n, problem_spec impl x n) ↔ (βˆ€ x n, generated_spec impl x n) :=
sorry
def implementation (x: Int) (n: Int) : Bool :=
sorry
-- #test implementation 16 2 = True -- #test implementation 143214 16 = False -- #test implementation 4 2 = True -- #test implementation 9 3 = True -- #test implementation 16 4 = True -- #test implementation 24 2 = False -- #test implementation 128 4 = False -- #test implementation 12 6 = False -- #test implementation ...
theorem correctness (x: Int) (n: Int) : problem_spec implementation x n :=
by sorry
null
null
null
def iscube(a: int) -> bool
Write a function that takes an integer a and returns True if this integer is a cube of some integer number. Note: you may assume the input is always valid.
[{"input": 1, "expected_output": true}, {"input": 2, "expected_output": false}, {"input": -1, "expected_output": true}, {"input": 64, "expected_output": true}, {"input": 0, "expected_output": true}, {"input": 180, "expected_output": false}]
def iscube(a: int) -> bool """Write a function that takes an integer a and returns True if this integer is a cube of some integer number. Note: you may assume the input is always valid. """
def problem_spec -- function signature (implementation: Int β†’ Bool) -- inputs (a: Int) := -- spec let spec (result: Bool) := result ↔ exists n: Int, a = n^3 -- program termination βˆƒ result, implementation a = result ∧ spec result
def generated_spec -- function signature (impl: Int β†’ Bool) -- inputs (a: Int) : Prop :=
theorem spec_isomorphism: βˆ€ impl, (βˆ€ a, problem_spec impl a) ↔ (βˆ€ a, generated_spec impl a) :=
sorry
def implementation (a: Int) : Bool :=
sorry
-- #test implementation 1 = True -- #test implementation 2 = False -- #test implementation -1 = True -- #test implementation 64 = True -- #test implementation 180 = False -- #test implementation 1000 = True -- #test implementation 0 = True -- #test implementation 1729 = False
theorem correctness (a: Int) : problem_spec implementation a :=
by sorry
null
null
null
def hex_key(num: string) -> int
You have been tasked to write a function that receives a hexadecimal number as a string and counts the number of hexadecimal digits that are primes (prime number, or a prime, is a natural number greater than 1 that is not a product of two smaller natural numbers). Hexadecimal digits are 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, A,...
[{"input": "AB", "expected_output": 1}, {"input": "1077E", "expected_output": 2}, {"input": "ABED1A33", "expected_output": 4}, {"input": "123456789ABCDEF0", "expected_output": 6}, {"input": "2020", "expected_output": 2}]
def hex_key(num: string) -> int """You have been tasked to write a function that receives a hexadecimal number as a string and counts the number of hexadecimal digits that are primes (prime number, or a prime, is a natural number greater than 1 that is not a product of two smaller natural numbers). Hexadecimal digits a...
def problem_spec -- function signature (implementation: String β†’ Int) -- inputs (num: String) := -- spec let spec (result: Int) := let num_val (ch : Char) := if ch.isDigit then (ch.toNat - '0'.toNat) else if ch.isUpper then ((ch.toNat - 'A'.toNat) + 10) else 0; 0 < num.length β†’ ( let c...
def generated_spec -- function signature (impl: String β†’ Int) -- inputs (num: String) : Prop :=
theorem spec_isomorphism: βˆ€ impl, (βˆ€ num, problem_spec impl num) ↔ (βˆ€ num, generated_spec impl num) :=
sorry
def implementation (num: String) : Int :=
let IsPrimeHexDigit (c: Char): Int := if c = '2' ∨ c = '3' ∨ c = '5' ∨ c = '7' ∨ c = 'B' ∨ c = 'D' then 1 else 0; num.foldl (λ acc a => acc + (IsPrimeHexDigit a)) 0
-- #test implementation "AB" = 1 -- #test implementation "1077E" = 2 -- #test implementation "ABED1A33" = 4 -- #test implementation "2020" = 2 -- #test implementation "123456789ABCDEF0" = 6 -- #test implementation "112233445566778899AABBCCDDEEFF00" = 12 -- #test implementation "" = 0
theorem correctness (num: String) : problem_spec implementation num :=
by sorry
null
null
null
def decimal_to_binary(decimal: nat) -> string
You will be given a number in decimal form and your task is to convert it to binary format. The function should return a string, with each character representing a binary number. Each character in the string will be '0' or '1'. There will be an extra couple of characters 'db' at the beginning and at the end of the str...
[{"input": 15, "expected_output": "db1111db"}, {"input": 32, "expected_output": "db100000db"}]
def decimal_to_binary(decimal: nat) -> string """You will be given a number in decimal form and your task is to convert it to binary format. The function should return a string, with each character representing a binary number. Each character in the string will be '0' or '1'. There will be an extra couple of character...
def problem_spec -- function signature (implementation: Nat β†’ String) -- inputs (decimal: Nat) := -- spec let spec (result: String) := 4 < result.length ∧ result.drop (result.length - 2) = "db" ∧ result.take 2 = "db" ∧ let resultTrimmed := (result.toList.drop 2).dropLast.dropLast.map (fun c => c.toNat - '0'.toN...
def generated_spec -- function signature (impl: Nat β†’ String) -- inputs (decimal: Nat) : Prop :=
theorem spec_isomorphism: βˆ€ impl, (βˆ€ decimal, problem_spec impl decimal) ↔ (βˆ€ decimal, generated_spec impl decimal) :=
sorry
def implementation (decimal: Nat) : String :=
"db" ++ (Nat.toDigits 2 decimal).asString ++ "db"
-- #test implementation 0 = "db0db" -- #test implementation 32 = "db100000db" -- #test implementation 103 = "db1100111db" -- #test implementation 15 = "db1111db"
theorem correctness (decimal: Nat) : problem_spec implementation decimal :=
by sorry
null
null
null
def is_happy(s: str) -> bool
You are given a string s. Your task is to check if the string is happy or not. A string is happy if its length is at least 3 and every 3 consecutive letters are distinct
[{"input": "a", "output": false}, {"input": "aa", "output": false}, {"input": "abcd", "output": true}, {"input": "aabb", "output": false}, {"input": "adb", "output": true}]
def is_happy(s: str) -> bool """You are given a string s. Your task is to check if the string is happy or not. A string is happy if its length is at least 3 and every 3 consecutive letters are distinct """
def problem_spec -- function signature (implementation: String β†’ Bool) -- inputs (s: String) := -- spec let spec (result : Bool) := result ↔ (3 ≀ s.length) ∧ Β¬ (βˆƒ i j, i < j ∧ j < s.length ∧ j - i ≀ 2 ∧ s.data.get! i = s.data.get! j) -- program termination βˆƒ result, implementation s = result ∧ spec result
def generated_spec -- function signature (impl: String β†’ Bool) -- inputs (s: String) : Prop :=
theorem spec_isomorphism: βˆ€ impl, (βˆ€ s, problem_spec impl s) ↔ (βˆ€ s, generated_spec impl s) :=
sorry
def implementation (s: String) : Bool :=
sorry
-- #test implementation "a" = False -- #test implementation "aa" = False -- #test implementation "abcd" = True -- #test implementation "aabb" = False -- #test implementation "adb" = True
theorem correctness (s: String) : problem_spec implementation s :=
by sorry
null
null
null
End of preview. Expand in Data Studio

This repository contains the data for the paper CLEVER: A Curated Benchmark for Formally Verified Code Generation.

The benchmark can be found on GitHub: https://github.com/trishullab/clever

Downloads last month
58

Paper for amitayusht/clever