Datasets:
| function_signature,docstring,test_cases,problem_spec_nl,problem_spec_formal_ground_truth,problem_spec_formal_generated,isomorphism_theorem,isomorphism_proof,implementation_signature,implementation,test_cases_lean,correctness_theorem,correctness_proof,helper_definitions,isomorphism_helper_lemmas,correctness_helper_lemmas | |
| "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 then numbers_within_threshold else Β¬numbers_within_threshold; | |
| -- program terminates | |
| β result, impl numbers threshold = result β§ | |
| -- return value satisfies spec | |
| spec result | |
| -- if result then spec else Β¬spec","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_impl_false := And.right h_result_false | |
| have h_head_in_threshold := And.left h_result_false | |
| simp [h_tail_impl_false] at ih | |
| by_cases h_1_lt_tail: 1 < tail.length | |
| have h_0_lt_tail_len : 0 < tail.length := by linarith | |
| simp [h_0_lt_tail_len, h_1_lt_tail] | |
| simp [h_1_lt_tail] at ih | |
| intros i h_i j h_j h_i_neq_j | |
| by_cases i = 0 | |
| rename_i h_i_eq_0 | |
| simp [h_i_eq_0] | |
| simp [h_i_eq_0] at h_i_neq_j | |
| have h_0_lt_j : 0 < j := by | |
| contrapose! h_i_neq_j | |
| linarith | |
| let j' := j - 1 | |
| have h_j'_tail : (head::tail)[j' + 1]! = tail[j']! := by | |
| rw [List.getElem!_cons_succ] | |
| have h_j'_j : j' + 1 = j := by | |
| simp [j'] | |
| rw [Nat.sub_add_cancel h_0_lt_j] | |
| rw [βh_j'_j] | |
| simp [h_j'_tail] | |
| have h_j'_lt_tail_len : j' < tail.length := by | |
| linarith | |
| simp [h_j'_lt_tail_len] | |
| apply h_head_in_threshold | |
| simp | |
| rename_i h_i_neq_0 | |
| have h_0_lt_i : 0 < i := by | |
| contrapose! h_i_neq_0 | |
| linarith | |
| let i' := i - 1 | |
| have h_i'_tail : (head::tail)[i' + 1]! = tail[i']! := by | |
| rw [List.getElem!_cons_succ] | |
| have h_i'_i : i' + 1 = i := by | |
| simp [i'] | |
| rw [Nat.sub_add_cancel h_0_lt_i] | |
| rw [βh_i'_i] | |
| simp [h_i'_tail] | |
| have h_i'_lt_tail_len : i' < tail.length := by | |
| linarith | |
| simp [h_i'_lt_tail_len] | |
| by_cases 0 < j | |
| rename_i h_0_lt_j | |
| let j' := j - 1 | |
| have h_j'_tail : (head::tail)[j' + 1]! = tail[j']! := by | |
| rw [List.getElem!_cons_succ] | |
| have h_j'_j : j' + 1 = j := by | |
| simp [j'] | |
| rw [Nat.sub_add_cancel h_0_lt_j] | |
| rw [βh_j'_j] | |
| simp [h_j'_tail] | |
| have h_j'_lt_tail_len : j' < tail.length := by | |
| linarith | |
| simp [h_j'_lt_tail_len] | |
| have h_i'_neq_j' : i' β j' := by | |
| contrapose! h_i_neq_j | |
| linarith | |
| have h_final := ih i' | |
| simp [h_i'_lt_tail_len] at h_final | |
| have h_final' := h_final j' h_j'_lt_tail_len | |
| simp [h_i'_neq_j'] at h_final' | |
| simp [h_j'_lt_tail_len] at h_final' | |
| assumption | |
| rename_i h_j_le_0 | |
| have h_j_eq_0 : j = 0 := by | |
| linarith | |
| simp [h_j_eq_0] | |
| have h_head_minus_tail : tail[i'] - head = -(head - tail[i']) := by | |
| simp | |
| rw [h_head_minus_tail] | |
| have h_head_minus_tail_lt_threshold : |-(head - tail[i'])| = |head - tail[i']| := by | |
| rw [abs_neg] | |
| rw [h_head_minus_tail_lt_threshold] | |
| apply h_head_in_threshold | |
| simp | |
| have h_tl_eq_0 : tail.length β€ 1 := by | |
| linarith | |
| by_cases tail.length = 1 | |
| rename_i h_tl_eq_1 | |
| simp [h_tl_eq_1] | |
| intros i h_i j h_j h_i_neq_j | |
| by_cases i = 0 | |
| rename_i h_i_eq_0 | |
| simp [h_i_eq_0] | |
| by_cases j = 0 | |
| rename_i h_j_eq_0 | |
| rw [h_j_eq_0] at h_i_neq_j | |
| contradiction | |
| by_cases j = 1 | |
| rename_i h_j_eq_1 | |
| simp [h_j_eq_1] | |
| simp [h_tl_eq_1] | |
| apply h_head_in_threshold | |
| simp | |
| rename_i h_j_neq_1 h_j_neq_0 | |
| have h_0_lt_j : 0 < j := by | |
| contrapose! h_j_neq_0 | |
| simp at h_j_neq_0 | |
| contradiction | |
| have h_1_lt_j : 1 < j := by | |
| contrapose! h_j_neq_1 | |
| have h_j_eq_1' : j = 1 := by | |
| linarith | |
| contradiction | |
| linarith | |
| rename_i h_i_neq_0 | |
| by_cases i = 1 | |
| rename_i h_i_eq_1 | |
| simp [h_i_eq_1] | |
| simp [h_tl_eq_1] | |
| by_cases j = 0 | |
| rename_i h_j_eq_0 | |
| simp [h_j_eq_0] | |
| have h_head_minus_tail : tail[0] - head = -(head - tail[0]) := by | |
| simp | |
| rw [h_head_minus_tail] | |
| rw [abs_neg] | |
| apply h_head_in_threshold | |
| simp | |
| by_cases j = 1 | |
| rename_i h_j_neq_0 h_j_eq_1 | |
| rw [h_j_eq_1] at h_i_neq_j | |
| contradiction | |
| rename_i h_j_neq_1 h_j_neq_0 | |
| have h_0_lt_j : 0 < j := by | |
| contrapose! h_j_neq_0 | |
| simp at h_j_neq_0 | |
| contradiction | |
| have h_1_lt_j : 1 < j := by | |
| contrapose! h_j_neq_1 | |
| have h_j_eq_1' : j = 1 := by | |
| linarith | |
| contradiction | |
| linarith | |
| rename_i h_i_neq_1 | |
| have h_0_lt_i : 0 < i := by | |
| contrapose! h_i_neq_1 | |
| simp at h_i_neq_1 | |
| contradiction | |
| have h_1_lt_i : 1 < i := by | |
| contrapose! h_i_neq_0 | |
| have h_i_eq_1' : i = 1 := by | |
| linarith | |
| contradiction | |
| linarith | |
| rename_i h_tl_neq_1 | |
| rw [Nat.le_one_iff_eq_zero_or_eq_one] at h_tl_eq_0 | |
| by_cases tail.length = 0 | |
| rename_i h_tl_eq_0 | |
| simp [h_tl_eq_0] | |
| rename_i h_tl_neq_0 | |
| cases h_tl_eq_0 | |
| contradiction | |
| contradiction | |
| -- case when tail has two elements that are close to each other | |
| rename_i h_result_true | |
| simp at h_result_true | |
| simp [result] at h_result_true | |
| simp [h_result_true] | |
| simp [implementation] at h_result_true | |
| by_cases h_0_lt_tail_len : 0 < tail.length | |
| rw [List.exists_mem_iff_getElem] at h_result_true | |
| simp [h_0_lt_tail_len] | |
| cases h_result_true | |
| use 0 | |
| simp | |
| rename_i h_head_in_threshold | |
| obtain β¨ j, h_j_lt_len, h_j_in_threshold β© := h_head_in_threshold | |
| use j + 1 | |
| simp [h_j_lt_len] | |
| assumption | |
| rename_i h_tail_has_close_elements | |
| simp [h_tail_has_close_elements] at ih | |
| by_cases h_1_lt_tail : 1 < tail.length | |
| simp [h_1_lt_tail] at ih | |
| obtain β¨ i, h_i_lt_tail_len, h_i_in_threshold β© := ih | |
| use i + 1 | |
| have h_i_lt_tail_len' : i + 1 < tail.length + 1 := by linarith | |
| simp [h_i_lt_tail_len'] | |
| obtain β¨ j, h_j_lt_tail_len, h_i_neq_j, h_j_in_threshold β© := h_i_in_threshold | |
| use j + 1 | |
| simp [h_j_lt_tail_len] | |
| simp [h_i_neq_j] | |
| simp [h_i_lt_tail_len, h_j_lt_tail_len] at h_j_in_threshold | |
| assumption | |
| use 0 | |
| simp | |
| use 1 | |
| simp | |
| unfold implementation at h_tail_has_close_elements | |
| by_cases h_1_tail: tail.length = 0 | |
| have h_tail_empty := List.eq_nil_of_length_eq_zero h_1_tail | |
| simp [h_tail_empty] at h_tail_has_close_elements | |
| simp at h_1_lt_tail | |
| have h_0_lt_tail_len : tail.length = 1 := by linarith | |
| have h_tail_singleton: β x, tail = [x] := by | |
| rw [List.length_eq_one] at h_0_lt_tail_len | |
| assumption | |
| obtain β¨ x, h_tail_singleton β© := h_tail_singleton | |
| simp [h_0_lt_tail_len] | |
| simp [h_tail_singleton] | |
| try (simp [h_tail_singleton] at h_tail_has_close_elements) | |
| unfold implementation at h_tail_has_close_elements | |
| simp at h_tail_has_close_elements | |
| simp at h_0_lt_tail_len | |
| have h_tail_ln_eq_0 : tail.length = 0 := by | |
| rw [h_0_lt_tail_len] | |
| simp | |
| simp [h_tail_ln_eq_0]",,, | |
| 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 within each other | |
| Ignore any spaces in the input string. | |
| """"""","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 paren group is in | |
| -- the result list | |
| β i j, j < paren_string_filtered.length β i β€ j β | |
| let substr_ij := (paren_string_filtered.take (j + 1)).drop i; | |
| balanced_paren_non_computable substr_ij '(' ')' β | |
| count_paren_groups substr_ij = 1 β | |
| substr_ij β result_list; | |
| let backward_spec (result_list: List String) := | |
| -- every string in the result list is a | |
| -- balanced paren group and is a substring | |
| -- of the input string i.e. there is no | |
| -- extra substring in the result list | |
| -- that is not from the input string | |
| β str, str β result_list β | |
| paren_string_filtered.containsSubstr str = true β§ | |
| balanced_paren_non_computable str '(' ')' β§ | |
| count_paren_groups str = 1; | |
| let spec (result_list: List String) := | |
| forward_spec result_list β§ backward_spec result_list; | |
| -- program terminates | |
| β result, impl paren_string = result β§ | |
| -- return value satisfies spec | |
| spec result","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 -- when finished, return accumulated groups in original order | |
| | c::rest => | |
| let new_cur := cur ++ [c] | |
| let new_balance:= if c = '(' then | |
| balance + 1 | |
| else | |
| balance - 1 | |
| if new_balance = 0 then | |
| let group := new_cur.asString | |
| aux rest [] 0 (group :: acc) | |
| else | |
| aux rest new_cur new_balance acc; | |
| aux filtered [] 0 []","#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 paren_string.isEmpty then | |
| num_open = 0 | |
| else | |
| let c := paren_string.get! 0 | |
| if c == '(' then | |
| string_is_paren_balanced_helper (paren_string.drop 1) (num_open + 1) | |
| else if c == ')' then | |
| string_is_paren_balanced_helper (paren_string.drop 1) (num_open - 1) | |
| else | |
| string_is_paren_balanced_helper (paren_string.drop 1) num_open | |
| termination_by paren_string.length | |
| decreasing_by | |
| all_goals | |
| { | |
| rename_i h_non_empty_string | |
| rw [String.drop_eq, String.length] | |
| simp | |
| rw [String.isEmpty_iff] at h_non_empty_string | |
| by_cases h_paren_nil : paren_string.length β€ 0 | |
| rw [Nat.le_zero_eq] at h_paren_nil | |
| rw [βstring_eq_iff_data_eq] at h_non_empty_string | |
| have h_temp : """".data = [] := by simp | |
| rw [h_temp] at h_non_empty_string | |
| rw [String.length] at h_paren_nil | |
| rw [List.length_eq_zero] at h_paren_nil | |
| contradiction | |
| have h_temp : paren_string.length > 0 := by linarith | |
| assumption | |
| } | |
| /-- | |
| name: string_is_paren_balanced | |
| use: | | |
| Function to check if a string is balanced with respect to parentheses. | |
| problems: | |
| - 1 | |
| - 6 | |
| - 132 | |
| sample_problems: | |
| - 0 | |
| -/ | |
| def string_is_paren_balanced | |
| (paren_string: String): Bool | |
| := | |
| string_is_paren_balanced_helper paren_string 0 | |
| /-- | |
| name: count_paren_groups_helper | |
| use: | | |
| Helper to count the number of groups of parentheses in a string. | |
| problems: | |
| - 1 | |
| -/ | |
| def count_paren_groups_helper | |
| (paren_string: String) (num_open: Int) (num_groups: Nat): Nat := | |
| -- Recursively count the number of paren groups | |
| if paren_string.isEmpty then | |
| num_groups | |
| else | |
| let c := paren_string.get! 0 | |
| if c == '(' then | |
| count_paren_groups_helper (paren_string.drop 1) (num_open + 1) num_groups | |
| else if c == ')' then | |
| let new_num_groups := | |
| if num_open == 1 then num_groups + 1 else num_groups | |
| count_paren_groups_helper (paren_string.drop 1) (num_open - 1) new_num_groups | |
| else | |
| count_paren_groups_helper (paren_string.drop 1) num_open num_groups | |
| termination_by paren_string.length | |
| decreasing_by | |
| all_goals | |
| { | |
| rename_i h_non_empty_string | |
| rw [String.drop_eq, String.length] | |
| simp | |
| rw [String.isEmpty_iff] at h_non_empty_string | |
| by_cases h_paren_nil : paren_string.length β€ 0 | |
| rw [Nat.le_zero_eq] at h_paren_nil | |
| rw [βstring_eq_iff_data_eq] at h_non_empty_string | |
| have h_temp : """".data = [] := by simp | |
| rw [h_temp] at h_non_empty_string | |
| rw [String.length] at h_paren_nil | |
| rw [List.length_eq_zero] at h_paren_nil | |
| contradiction | |
| have h_temp : paren_string.length > 0 := by linarith | |
| assumption | |
| } | |
| /-- | |
| name: count_paren_groups | |
| use: | | |
| Function to count the number of groups of parentheses in a string. | |
| problems: | |
| - 1 | |
| -/ | |
| def count_paren_groups | |
| (paren_string: String): Nat := | |
| count_paren_groups_helper paren_string 0 0",, | |
| 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",,, | |
| 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 operations = result β§ | |
| -- return value satisfies spec | |
| spec result","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 hypothesis | |
| have h_harder_inductive_hypothesis_true: | |
| β h, β ops, | |
| implementation.check ops h = true β | |
| β i, i β€ ops.length β§ h + (ops.take i).sum < 0 := by | |
| intros h ops h_check | |
| induction' ops generalizing h | |
| simp [implementation.check] at h_check | |
| rename_i head tail ih | |
| simp [implementation.check] at h_check | |
| by_cases h_head_lt_0 : h + head < 0 | |
| use 1 | |
| simp | |
| assumption | |
| simp at h_head_lt_0 | |
| cases h_check | |
| linarith | |
| rename_i h_tail_sum_gt_0 | |
| specialize ih (h + head) | |
| simp [h_tail_sum_gt_0] at ih | |
| obtain β¨i, h_i_lt_tail_len, h_tail_sum_lt_0β© := ih | |
| use i + 1 | |
| simp [h_i_lt_tail_len] | |
| linarith | |
| by_cases h_if_pos: (implementation.check operations 0 = true) | |
| simp [h_if_pos] | |
| obtain β¨i, h_i_lt_tail_len, h_tail_sum_lt_0β© := h_harder_inductive_hypothesis_true 0 operations h_if_pos | |
| simp at h_tail_sum_lt_0 | |
| use i | |
| have h_harder_inductive_hypothesis_false: | |
| β h, β ops, h β₯ 0 β | |
| implementation.check ops h = false β | |
| β i, i β€ ops.length β h + (ops.take i).sum β₯ 0 := by | |
| intros h ops h_ge_0 h_check | |
| induction' ops generalizing h | |
| intros i h_i_lt_tail_len | |
| simp [implementation.check] at h_check | |
| simp | |
| linarith | |
| rename_i head tail ih | |
| simp [implementation.check] at h_check | |
| by_cases h_head_lt_0 : h + head < 0 | |
| simp at h_head_lt_0 | |
| cases h_check | |
| linarith | |
| simp at h_head_lt_0 | |
| apply And.right at h_check | |
| specialize ih (h + head) | |
| simp at ih | |
| simp [h_head_lt_0, h_check] at ih | |
| intros i h_i_lt_tail_len | |
| simp at h_i_lt_tail_len | |
| simp | |
| specialize ih (i - 1) | |
| by_cases h_i_1_lt_i: 1 β€ i | |
| let i' := i - 1 | |
| have h_i'_lt_tail_len: i = i' + 1 := by | |
| simp [i'] | |
| rw [Nat.sub_add_cancel] | |
| linarith | |
| simp [h_i'_lt_tail_len] | |
| rw [βInt.add_assoc] | |
| have h_i_minus_1_lt_tail_len: i - 1 β€ tail.length := by | |
| linarith | |
| simp [h_i_minus_1_lt_tail_len] at ih | |
| simp [i'] | |
| assumption | |
| simp at h_i_1_lt_i | |
| simp [h_i_1_lt_i] at ih | |
| simp [h_i_1_lt_i] | |
| linarith | |
| simp at h_if_pos | |
| simp [h_if_pos] | |
| have h_harder' := h_harder_inductive_hypothesis_false 0 operations | |
| simp at h_harder' | |
| simp [h_if_pos] at h_harder' | |
| intros i h_i_lt_tail_len | |
| apply h_harder' | |
| assumption",,, | |
| 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, implementation numbers = result β§ | |
| -- return value satisfies spec | |
| spec result","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 h2 | |
| contradiction | |
| simp [h1] | |
| simp [h] | |
| sorry",,, | |
| "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.length = 2 * numbers.length - 1 β§ | |
| β i, i < numbers.length β | |
| result[2 * i]! = numbers[i]! β§ | |
| (0 < 2*i - 1 β result[2 * i - 1]! = delimeter)); | |
| -- program termination | |
| β result, implementation numbers delimeter = result β§ | |
| spec result","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",,, | |
| 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]!; | |
| balanced_paren_non_computable group '(' ')' β | |
| 0 < result[i]! β§ count_max_paren_depth group = result[i]!.toNat; | |
| -- program termination | |
| β result, implementation paren_string = result β§ | |
| spec result","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 paren_string.isEmpty then | |
| num_open = 0 | |
| else | |
| let c := paren_string.get! 0 | |
| if c == '(' then | |
| string_is_paren_balanced_helper (paren_string.drop 1) (num_open + 1) | |
| else if c == ')' then | |
| string_is_paren_balanced_helper (paren_string.drop 1) (num_open - 1) | |
| else | |
| string_is_paren_balanced_helper (paren_string.drop 1) num_open | |
| termination_by paren_string.length | |
| decreasing_by | |
| all_goals | |
| { | |
| rename_i h_non_empty_string | |
| rw [String.drop_eq, String.length] | |
| simp | |
| rw [String.isEmpty_iff] at h_non_empty_string | |
| by_cases h_paren_nil : paren_string.length β€ 0 | |
| rw [Nat.le_zero_eq] at h_paren_nil | |
| rw [βstring_eq_iff_data_eq] at h_non_empty_string | |
| have h_temp : """".data = [] := by simp | |
| rw [h_temp] at h_non_empty_string | |
| rw [String.length] at h_paren_nil | |
| rw [List.length_eq_zero] at h_paren_nil | |
| contradiction | |
| have h_temp : paren_string.length > 0 := by linarith | |
| assumption | |
| } | |
| /-- | |
| name: string_is_paren_balanced | |
| use: | | |
| Function to check if a string is balanced with respect to parentheses. | |
| problems: | |
| - 1 | |
| - 6 | |
| - 132 | |
| sample_problems: | |
| - 0 | |
| -/ | |
| def string_is_paren_balanced | |
| (paren_string: String): Bool | |
| := | |
| string_is_paren_balanced_helper paren_string 0 | |
| /-- | |
| name: count_max_paren_depth_helper | |
| use: | | |
| Helper to count the maximum depth of parentheses in a string. | |
| problems: | |
| - 6 | |
| - 132 | |
| -/ | |
| def count_max_paren_depth_helper | |
| (paren_string: String) (num_open: Int) (max_depth: Nat): Nat := | |
| -- Recursively count the maximum depth of parentheses | |
| if paren_string.isEmpty then | |
| max_depth | |
| else | |
| let c := paren_string.get! 0 | |
| if c == '(' then | |
| let new_num_open := num_open + 1 | |
| count_max_paren_depth_helper (paren_string.drop 1) (new_num_open) (max_depth.max new_num_open.toNat) | |
| else if c == ')' then | |
| count_max_paren_depth_helper (paren_string.drop 1) (num_open - 1) max_depth | |
| else | |
| count_max_paren_depth_helper (paren_string.drop 1) num_open max_depth | |
| termination_by paren_string.length | |
| decreasing_by | |
| all_goals | |
| { | |
| rename_i h_non_empty_string | |
| rw [String.drop_eq, String.length] | |
| simp | |
| rw [String.isEmpty_iff] at h_non_empty_string | |
| by_cases h_paren_nil : paren_string.length β€ 0 | |
| rw [Nat.le_zero_eq] at h_paren_nil | |
| rw [βstring_eq_iff_data_eq] at h_non_empty_string | |
| have h_temp : """".data = [] := by simp | |
| rw [h_temp] at h_non_empty_string | |
| rw [String.length] at h_paren_nil | |
| rw [List.length_eq_zero] at h_paren_nil | |
| contradiction | |
| have h_temp : paren_string.length > 0 := by linarith | |
| assumption | |
| } | |
| /-- | |
| name: count_max_paren_depth | |
| use: | | |
| Function to count the maximum depth of parentheses in a string. | |
| problems: | |
| - 6 | |
| - 132 | |
| -/ | |
| def count_max_paren_depth | |
| (paren_string: String): Nat := | |
| count_max_paren_depth_helper paren_string 0 0",, | |
| "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 β strings[j]! β result β | |
| β j, j < result.length β result.count result[j]! = strings.count result[j]!); | |
| -- program termination | |
| β result, implementation strings substring = result β§ | |
| spec result","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",,, | |
| "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[0]! β§ | |
| sum_tail * prod_tail + prod = sum * prod_tail)); | |
| -- program termination | |
| β result, implementation numbers = result β§ | |
| spec result","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",,, | |
| "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, implementation numbers = result β§ | |
| spec result","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 prove the correctness of the implementation | |
| sorry | |
| sorry",,, | |
| 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), | |
| string.isPrefixOf possible_palindrome β | |
| is_palindrome possible_palindrome β | |
| result.length β€ possible_palindrome.length); | |
| -- program termination | |
| β result, implementation string = result β§ | |
| spec result","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",, | |
| "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') β§ | |
| (β i, i < a.length β | |
| let i_pos := String.Pos.mk i; | |
| (a.get i_pos = b.get i_pos β result.get i_pos = '0') β§ | |
| (a.get i_pos β b.get i_pos β result.get i_pos = '1')); | |
| -- program termination | |
| β result, implementation a b = result β§ | |
| spec result","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",,, | |
| 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 β | |
| (β i, i < strings.length β§ | |
| strings[i]! = longest β§ β j < i, strings[j]!.length < longest.length)); | |
| -- program termination | |
| β result, implementation strings = result β§ | |
| spec result","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",,, | |
| "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",,, | |
| 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",,, | |
| 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",,, | |
| 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.toLower) | |
| result = lowercase_characters.card; | |
| -- program termination | |
| β result, implementation string = result β§ | |
| spec result","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_i head tail ih | |
| unfold String.toLower | |
| rw [String.map_eq] | |
| simp | |
| sorry",,, | |
| 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 beat | |
| ","[{""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 note, lasts two beats | |
| '.|' - quater note, lasts one beat | |
| """"""","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 (space_split.get! i) = result.get! i; | |
| -- program termination | |
| β result, implementation string = result β§ | |
| spec result","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]",,, | |
| "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))) | |
| β§ | |
| (substring.length < string.length β | |
| let subtring_start_idx := {i: Nat | i β€ string.length - substring.length}; | |
| let substring_occurrences := {i β subtring_start_idx | (string.take (i + substring.length)).drop i = substring }; | |
| result = substring_occurrences.toFinset.card); | |
| -- program termination | |
| β result, implementation string substring = result β§ | |
| spec result","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",,, | |
| 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"" => 8 | |
| | ""nine"" => 9 | |
| | _ => -1; | |
| let is_sorted_asc : List Int β Bool := fun numbers => | |
| let rec is_sorted_asc_helper : List Int β Bool β Bool := fun numbers is_sorted => | |
| match numbers with | |
| | [] => is_sorted | |
| | [x] => is_sorted | |
| | x::y::rest => if x <= y then is_sorted_asc_helper (y::rest) true else false; | |
| is_sorted_asc_helper numbers false; | |
| let spec (result: String) := | |
| let result_split := result.splitOn "" ""; | |
| let numbers_split := numbers.splitOn "" ""; | |
| let result_mapped_to_numbers := result_split.map word_to_number_map; | |
| let numbers_as_str_mapped_to_numbers := numbers_split.map word_to_number_map; | |
| Β¬ -1 β numbers_as_str_mapped_to_numbers β | |
| result_split.length = numbers_split.length β§ | |
| (β n, n β numbers_as_str_mapped_to_numbers β | |
| β m, m β result_mapped_to_numbers) β§ | |
| (β n, n β result_mapped_to_numbers β | |
| β m, m β numbers_as_str_mapped_to_numbers) β§ | |
| (β n, numbers_as_str_mapped_to_numbers.count n = result_mapped_to_numbers.count n) β§ | |
| is_sorted_asc result_mapped_to_numbers = true; | |
| -- program termination | |
| β result, implementation numbers = result β§ | |
| spec result","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 | |
| | 0 => ""zero"" | |
| | 1 => ""one"" | |
| | 2 => ""two"" | |
| | 3 => ""three"" | |
| | 4 => ""four"" | |
| | 5 => ""five"" | |
| | 6 => ""six"" | |
| | 7 => ""seven"" | |
| | 8 => ""eight"" | |
| | 9 => ""nine"" | |
| | _ => ""invalid""; | |
| let numbers_split := numbers.splitOn "" ""; | |
| let numbers_mapped_to_numbers := numbers_split.map word_to_number_map; | |
| let sorted_numbers := numbers_mapped_to_numbers.mergeSort; | |
| let sorted_numbers_mapped_to_words := sorted_numbers.map number_to_word_map; | |
| let join: List String β String := fun words => | |
| let head := words.get! 0; | |
| let tail := words.drop 1; | |
| tail.foldl (fun acc word => acc ++ "" "" ++ word) head; | |
| join sorted_numbers_mapped_to_words","#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",,, | |
| "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 β numbers β y β numbers β abs_diff β€ |x - y|) β§ | |
| (smaller = larger β 1 β€ (numbers.filter (fun z => z = smaller)).length)); | |
| -- program termination | |
| β result, implementation numbers = result β§ | |
| spec result","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_numbers.get! (i + 1) - sorted_numbers.get! i; | |
| if diff < min_diff then | |
| loop (i + 1) diff (sorted_numbers.get! i, sorted_numbers.get! (i + 1)) | |
| else | |
| loop (i + 1) min_diff min_pair | |
| else | |
| min_pair; | |
| loop 1 min_diff min_pair","#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",,, | |
| 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 < numbers.length β | |
| (min_elem β max_elem β | |
| result[i]! = (numbers[i]! - min_elem) / range) β§ | |
| (min_elem = max_elem β | |
| result[i]! = 0); | |
| -- program termination | |
| β result, implementation numbers = result β§ | |
| spec result","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",,, | |
| 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 string = result β§ | |
| spec result","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",,, | |
| 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",,, | |
| 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",,, | |
| 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 β | |
| β ip jp : Nat, ip < jp β§ result[i]! = numbers[ip]! β§ result[j]! = numbers[jp]!) | |
| -- program termination | |
| β result, implementation numbers = result β§ | |
| spec result","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",,, | |
| 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.get! i; | |
| let c' := chars_in_string.get! i; | |
| (c.isUpper β c'.isLower) β§ | |
| (c.isLower β c'.isUpper) β§ | |
| ((Β¬ c.isUpper β§ Β¬ c.isLower) β c = c') | |
| ); | |
| -- program termination | |
| β result, implementation string = result β§ | |
| spec result","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",,, | |
| 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_idx := ((strings.take (i + 1)).map (Ξ» s => s.length)).sum; | |
| let start_idx := end_idx - string_in_result.length; | |
| let corresponding_string_in_result := ((result_chars.take end_idx).drop start_idx).asString; | |
| corresponding_string_in_result = string_in_result); | |
| -- program termination | |
| β result, implementation strings = result β§ | |
| spec result","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",,, | |
| "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 : String, s β result β result.count s = strings.count s; | |
| -- program termination | |
| β result, implementation strings pref = result β§ | |
| spec result","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",,, | |
| 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 | |
| β result, | |
| implementation numbers = result β§ | |
| spec result","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",,, | |
| 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",,, | |
| 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 modified from the original HumanEval spec because of Real is not a computable type, but a zero does not necessarily exist over the rationals. | |
| ","[{""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): This problem has been modified from the original HumanEval spec because of Real is not a computable type, but a zero does not necessarily exist over the rationals. | |
| """"""","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.get! i) β | |
| |poly.eval result| β€ eps; | |
| -- program termination | |
| β result, | |
| implementation xs = result β§ | |
| spec result","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' xs guess; | |
| if eval β€ eps β¨ fuel = 0 then (guess, fuel) | |
| else | |
| let guess' := (eval' * guess - eval) / eval'; | |
| find_zero xs guess' (fuel - 1); | |
| (find_zero xs 1.0 1000000).1 | |
| -- Note: The above implementation can fail to converge in some cases. For example, | |
| -- on the test case [-6, 11, -6, 1] as the derivative of the polynomial | |
| -- can be zero at if the guess is 0. In such cases, the implementation will not | |
| -- converge. The implementation can be improved by using a better guess.","#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",,, | |
| 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! i); | |
| let every_third_val := every_third_idx.map (Ξ» i => l.get! i); | |
| (β i, i < l.length β (i % 3 β 0 β l.get! i = result.get! i)) β§ | |
| List.Sorted Int.le every_third_val_in_result β§ | |
| every_third_val.all (Ξ» x => every_third_val_in_result.count x = every_third_val.count x); | |
| -- 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 :=,"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",,, | |
| 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",,, | |
| 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_not_none | |
| rw [Option.ne_none_iff_exists] at h_l_max' | |
| obtain β¨r, h_l_maxβ© := h_l_max' | |
| use r | |
| simp [h_l_max] | |
| obtain β¨r, h_l_max β© := h_l_max | |
| simp [h_l_max] | |
| induction l | |
| intro i h_i_lt_len | |
| simp | |
| simp at h_len_gt_zero | |
| rename_i head tail ih | |
| rw [List.maximum_cons] at h_l_max | |
| by_cases h_tail_nil: tail = [] | |
| simp [h_tail_nil] at * | |
| have h_head_eq_r : head = r := by | |
| simp [WithBot.some] at h_l_max | |
| rw [Option.some_inj] at h_l_max | |
| exact h_l_max | |
| rw [h_head_eq_r] | |
| simp [h_tail_nil] at ih | |
| have h_0_lt_len: 0 < tail.length := | |
| List.length_pos_of_ne_nil h_tail_nil | |
| simp [h_0_lt_len] at ih | |
| repeat sorry",,, | |
| 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 % 13 = 0) β§ | |
| result - implementation (n - 1) = n.repr.count '7') | |
| -- 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 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",,, | |
| 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 := even_idx.map (Ξ» i => l.get! i); | |
| (β i, i < l.length β (i % 2 β 0 β l.get! i = result.get! i)) β§ | |
| List.Sorted Int.le even_val_in_result β§ | |
| even_val.all (Ξ» x => even_val_in_result.count x = even_val.count x); | |
| -- 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 :=,"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",,, | |
| 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.length = n β§ | |
| (β i : β, i * 3 + 3 β€ n β | |
| extract encoded_chars (i * 3) (i * 3 + 2) = | |
| [original_chars.get! (i * 3 + 1), original_chars.get! (i * 3 + 2), original_chars.get! (i * 3)]) β§ | |
| (n % 3 β 0 β extract encoded_chars (n - n % 3) (n - 1) = | |
| extract original_chars (n - n % 3) (n - 1)); | |
| -- program termination | |
| β result, | |
| impl s = result β§ | |
| spec result","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",,, | |
| 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 | |
| β 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 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",,, | |
| 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.length β§ | |
| sum_i_j_k i j k) | |
| -- spec | |
| let spec (result: Bool) := | |
| result β exists_zero | |
| -- -- program termination | |
| β result, implementation numbers = result β§ | |
| spec result | |
| --","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",,, | |
| 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 moving left to right hits a car that's moving right to left. | |
| However, the cars are infinitely sturdy and strong; as a result, they continue moving | |
| in their trajectory as if they did not collide. | |
| This function outputs the number of such collisions. | |
| ","[{""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 are said to collide | |
| when a car that's moving left to right hits a car that's moving right to left. | |
| However, the cars are infinitely sturdy and strong; as a result, they continue moving | |
| in their trajectory as if they did not collide. | |
| This function outputs the number of such collisions. | |
| """"""","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",,, | |
| 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 result | |
| --","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",,, | |
| 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) := | |
| result β exists_zero | |
| -- -- program termination | |
| β result, implementation numbers = result β§ | |
| spec result | |
| --","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",,, | |
| "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_array[i]!); | |
| let pow_sum := pow_array.sum; | |
| (0 < base β§ base β€ 10) β§ | |
| (β i, i < result_array.length β | |
| result_array[i]! < base β§ 0 β€ result_array[i]! β | |
| pow_sum = x); | |
| -- program termination | |
| β result, implementation x base = result β§ | |
| spec result","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",,, | |
| "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",,, | |
| 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 recursion. | |
| ","[{""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 sequence. Do not use recursion. | |
| """"""","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_non_computable_4 1 0 | |
| | base2 : fibonacci_non_computable_4 2 2 | |
| | base3 : fibonacci_non_computable_4 3 0 | |
| | step : β n fβ fβ fβ fβ, fibonacci_non_computable_4 n fβ β | |
| fibonacci_non_computable_4 (n + 1) fβ β | |
| fibonacci_non_computable_4 (n + 2) fβ β | |
| fibonacci_non_computable_4 (n + 3) fβ β | |
| fibonacci_non_computable_4 (n + 4) (fβ + fβ + fβ + fβ)",, | |
| 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_less_eq := less_eq.min?; | |
| let less_eq_count := less_eq.length; | |
| let more_eq_count := more_eq.length; | |
| let eq_count := (numbers.filter (fun x => x = result)).length; | |
| (less_eq_count + more_eq_count - eq_count = numbers.length β | |
| numbers.length β€ 2 * less_eq_count β | |
| numbers.length β€ 2 * more_eq_count) β§ | |
| ((numbers.length % 2 = 1 β | |
| result β numbers) β§ | |
| (numbers.length % 2 = 0 β max_more_eq.isSome β§ | |
| min_less_eq.isSome β§ | |
| 2 * result = max_more_eq.get! + min_less_eq.get!)); | |
| -- program termination | |
| β result, implementation numbers = result β§ | |
| spec result","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",,, | |
| 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",, | |
| "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",,, | |
| 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) := | |
| isAlphabetic result β§ isAlphabetic s β§ | |
| result.length = s.length β§ | |
| β k : Nat, k < 26 β§ | |
| β i : Nat, i < s.length β | |
| ((s.get! β¨iβ©).toNat + k) % 26 = (result.get! β¨iβ©).toNat | |
| β k = 5 | |
| -- program termination | |
| β result, implementation s = result β§ | |
| spec result","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",,, | |
| 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.contains c β string.contains c β§ | |
| β c , string.contains c β§ is_consonant c β (result.contains c); | |
| -- program termination | |
| β result, implementation string = result β§ | |
| spec result","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",,, | |
| "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 | |
| β result, impl numbers threshold = result β§ | |
| -- return value satisfies spec | |
| spec result | |
| -- if result then spec else Β¬spec","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",,, | |
| "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",,, | |
| "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' 'dddzzzzzzzddddabc' = false","theorem correctness | |
| (s0 s1: String) | |
| : problem_spec implementation s0 s1 :=","by | |
| unfold problem_spec | |
| let result := implementation s0 s1 | |
| use result | |
| simp [result] | |
| sorry",,, | |
| 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_computable n fβ β | |
| fibonacci_non_computable (n + 1) fβ β | |
| fibonacci_non_computable (n + 2) (fβ + fβ)",, | |
| 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 satisfies spec | |
| spec result","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",,, | |
| 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_ordered; | |
| -- program termination | |
| β result, implementation numbers = result β§ | |
| spec result","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",,, | |
| "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]! β€ result[i + 1]!; | |
| -- spec | |
| let spec (result: List Int) := | |
| is_unique result β§ | |
| is_sorted result β§ | |
| (β i : Int, i β result β i β l1 β§ i β l2) | |
| -- program termination | |
| β result, implementation l1 l2 = result β§ | |
| spec result","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",,, | |
| 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",,, | |
| 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",,, | |
| 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 satisfies spec | |
| 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 (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",,, | |
| 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",,, | |
| 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_computable_3 1 0 | |
| | base2 : fibonacci_non_computable_3 2 1 | |
| | step : β n fβ fβ fβ, fibonacci_non_computable_3 n fβ β | |
| fibonacci_non_computable_3 (n + 1) fβ β | |
| fibonacci_non_computable_3 (n + 2) fβ β | |
| fibonacci_non_computable_3 (n + 3) (fβ + fβ + fβ)",, | |
| 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 | |
| result = if isVowel string.data[0]! β¨ isY string.data[0]! then 1 else 0 | |
| else | |
| result = (if isVowel string.data[0]! then 1 else 0) + implementation (string.drop 1); | |
| -- program termination | |
| β result, implementation string = result β§ | |
| spec result","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",,, | |
| "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 < shift β isReverse x_str) β§ | |
| (shift β€ x_str.length β | |
| x_str.take shift = result.drop (x_str.length - shift) β§ | |
| x_str.drop shift = result.take (x_str.length - shift)); | |
| -- program termination | |
| β result, implementation x shift = result β§ | |
| spec result","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",,, | |
| 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 string.data[0]! then string.data[0]!.toNat else 0) + implementation (string.drop 1); | |
| -- program termination | |
| β result, implementation string = result β§ | |
| spec result","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",,, | |
| "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 fruits | |
| in the basket return the number of the mango fruits in the basket. | |
| ","[{""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 an integer that represent the total number of the fruits | |
| in the basket return the number of the mango fruits in the basket. | |
| """"""","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 β§ | |
| spec 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",,, | |
| 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 node should be returned in a list, [ smallest_value, its index ], | |
| If there are no even values or the given array is empty, return []. | |
| ","[{""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 the node that has smallest index. | |
| The plucked node should be returned in a list, [ smallest_value, its index ], | |
| If there are no even values or the given array is empty, return []. | |
| """"""","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]! β§ | |
| result[1]! = i β§ | |
| (β j, j < numbers.length β j < i β (numbers[j]! % 2 = 1 β¨ numbers[i]! < numbers[j]!)) β§ | |
| (β k, k < numbers.length β numbers[k]! % 2 = 0 β numbers[i]! β€ numbers[k]!)); | |
| -- program termination | |
| β result, implementation numbers = result β§ | |
| spec result","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",,, | |
| 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 exist, return -1. | |
| """"""","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 => x = numbers[i]!)).length β§ | |
| (Β¬β j : Nat, j < numbers.length β§ | |
| numbers[i]! < numbers[j]! β§ numbers[j]! β€ numbers.count numbers[j]!)); | |
| -- program termination | |
| β result, implementation numbers = result β§ | |
| spec result","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",,, | |
| 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 < lst.length β§ i % 2 = 1) β result[i]! = sorted_lst[lst.length - (i-1)/2 - 1]!) | |
| -- program termination | |
| β result, implementation lst = result β§ spec result","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 [] = [] | |
| -- #test implementation [1,2,3,4,5,6,7,8] = [1, 8, 2, 7, 3, 6, 4, 5] | |
| -- #test implementation [0,2,2,2,5,5,-5,-5] = [-5, 5, -5, 5, 0, 2, 2, 2] | |
| -- #test implementation [111111] = [111111]","theorem correctness | |
| (lst: List Int) | |
| : problem_spec implementation lst | |
| :=","by | |
| sorry",,, | |
| "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 third side. | |
| """"""","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) * (s-c))| β€ ((1: Rat)/10000) | |
| else | |
| result = -1 | |
| -- program termination | |
| β result, implementation a b c = result β§ | |
| spec result","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 2 10 = -1","theorem correctness | |
| (a: Rat) (b: Rat) (c: Rat) | |
| : problem_spec implementation a b c | |
| :=","by | |
| sorry",,, | |
| "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, implementation q w = result β§ | |
| spec 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",,, | |
| 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) β§ (List.Palindrome palin_perm) β | |
| result β€ (swaps_done arr palin_perm) | |
| -- program termination | |
| β result, implementation arr = result β§ | |
| spec result","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, 1] = 1","theorem correctness | |
| (arr: List Int) | |
| : problem_spec implementation arr | |
| :=","by | |
| sorry",,, | |
| "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""]}, {""input"": ""(['4'], ['1', '2', '3', '4', '5'])"", ""expected_output"": [""4""]}]","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)) | |
| β§ | |
| (sum_chars result β€ sum_chars lst1) | |
| β§ | |
| (sum_chars result β€ sum_chars lst2) | |
| β§ | |
| ((sum_chars lst1 = sum_chars lst2) β (result = lst1)) | |
| -- program termination | |
| β result, implementation lst1 lst2 = result β§ | |
| spec result","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"", ""Hi""] | |
| -- #test implementation [""hi"", ""admin""] [""hI"", ""hi"", ""hi""] = [""hI"", ""hi"", ""hi""] | |
| -- #test implementation [""hi"", ""admin""] [""hI"", ""hi"", ""hii""] = [""hi"", ""admin""] | |
| -- #test implementation [] [""this""] = [] | |
| -- #test implementation [""this""] [] == []","theorem correctness | |
| (lst1: List String) (lst2: List String) | |
| : problem_spec implementation lst1 lst2 | |
| :=","by | |
| sorry",,, | |
| 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 implementation (11 * 9 * 9) = False | |
| -- #test implementation (11*13*7) = True","theorem correctness | |
| (a: Int) | |
| : problem_spec implementation a | |
| :=","by | |
| sorry",,, | |
| "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 1 1 = True | |
| -- #test implementation 1 12 = True","theorem correctness | |
| (x: Int) (n: Int) | |
| : problem_spec implementation x n | |
| :=","by | |
| sorry",,, | |
| 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",,, | |
| 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, B, C, D, E, F. | |
| Prime numbers are 2, 3, 5, 7, 11, 13, 17,... | |
| So you have to determine a number of the following digits: 2, 3, 5, 7, | |
| B (=decimal 11), D (=decimal 13). | |
| Note: you may assume the input is always correct or empty string, | |
| and symbols A,B,C,D,E,F are always uppercase. | |
| ","[{""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 are 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, A, B, C, D, E, F. | |
| Prime numbers are 2, 3, 5, 7, 11, 13, 17,... | |
| So you have to determine a number of the following digits: 2, 3, 5, 7, | |
| B (=decimal 11), D (=decimal 13). | |
| Note: you may assume the input is always correct or empty string, | |
| and symbols A,B,C,D,E,F are always uppercase. | |
| """"""","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 char_val := num_val num.toList[0]!; | |
| (Nat.Prime char_val β | |
| (1 < num.length β result = char_val + implementation (num.drop 1)) β§ | |
| (1 = num.length β result = char_val)) β§ | |
| (Β¬Nat.Prime char_val β | |
| (1 < num.length β result = implementation (num.drop 1)) β§ | |
| (1 = num.length β result = 0)) | |
| ) | |
| -- program termination | |
| β result, implementation num = result β§ | |
| spec result","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",,, | |
| 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 string. | |
| The extra characters are there to help with the format. | |
| ","[{""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 characters 'db' at the beginning and at the end of the string. | |
| The extra characters are there to help with the format. | |
| """"""","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'.toNat) | |
| decimal = Nat.ofDigits 2 resultTrimmed.reverse | |
| -- program termination | |
| β result, implementation decimal = result β§ | |
| spec result","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",,, | |
| 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",,, | |
| def numerical_letter_grade(grades: list[float]) -> list[str],"It is the last week of the semester and the teacher has to give the grades | |
| to students. The teacher has been making her own algorithm for grading. | |
| The only problem is, she has lost the code she used for grading. | |
| She has given you a list of GPAs for some students and you have to write | |
| a function that can output a list of letter grades using the following table: | |
| GPA | Letter grade | |
| 4.0 A+ | |
| > 3.7 A | |
| > 3.3 A- | |
| > 3.0 B+ | |
| > 2.7 B | |
| > 2.3 B- | |
| > 2.0 C+ | |
| > 1.7 C | |
| > 1.3 C- | |
| > 1.0 D+ | |
| > 0.7 D | |
| > 0.0 D- | |
| 0.0 E | |
| Note: I have included a hypothesis that Float is hashable, not sure if this will mess up proving attempts but we can modify it if so. Reviewer: please think if there's a better way. | |
| Example: | |
| grade_equation([4.0, 3, 1.7, 2, 3.5]) ==> ['A+', 'B', 'C-', 'C', 'A-'] | |
| ","[{""input"": [4.0, 3, 1.7, 2, 3.5], ""output"": [""A+"", ""B"", ""C-"", ""C"", ""A-""]}]","def numerical_letter_grade(grades: list[float]) -> list[str] | |
| """"""It is the last week of the semester and the teacher has to give the grades | |
| to students. The teacher has been making her own algorithm for grading. | |
| The only problem is, she has lost the code she used for grading. | |
| She has given you a list of GPAs for some students and you have to write | |
| a function that can output a list of letter grades using the following table: | |
| GPA | Letter grade | |
| 4.0 A+ | |
| > 3.7 A | |
| > 3.3 A- | |
| > 3.0 B+ | |
| > 2.7 B | |
| > 2.3 B- | |
| > 2.0 C+ | |
| > 1.7 C | |
| > 1.3 C- | |
| > 1.0 D+ | |
| > 0.7 D | |
| > 0.0 D- | |
| 0.0 E | |
| Note: I have included a hypothesis that Float is hashable, not sure if this will mess up proving attempts but we can modify it if so. Reviewer: please think if there's a better way. | |
| Example: | |
| grade_equation([4.0, 3, 1.7, 2, 3.5]) ==> ['A+', 'B', 'C-', 'C', 'A-'] | |
| """"""","def problem_spec | |
| -- function signature | |
| (implementation: List Float β List String) | |
| -- inputs | |
| (grades: List Float) := | |
| -- spec | |
| let grade_dict : List (Float Γ String) := | |
| [ | |
| (4.0, ""A+""), | |
| (3.7, ""A""), | |
| (3.3, ""A-""), | |
| (3.0, ""B+""), | |
| (2.7, ""B""), | |
| (2.3, ""B-""), | |
| (2.0, ""C+""), | |
| (1.7, ""C""), | |
| (1.3, ""C-""), | |
| (1.0, ""D+""), | |
| (0.7, ""D""), | |
| (0.0, ""D-"") | |
| ] | |
| let spec (result : List String) := | |
| grades.all (fun grade => 0.0 β€ grade β§ grade β€ 4.0) β§ | |
| result.length = grades.length β§ | |
| β i, i < grades.length β | |
| let number_grade := grades[i]! | |
| let number_grade_keys := grade_dict.map (fun (g, _) => g) | |
| if 0.0 < number_grade then | |
| β i : Nat, i < number_grade_keys.length β§ | |
| number_grade_keys[i]! β€ number_grade β§ | |
| (β k' : Nat, k' < number_grade_keys.length β number_grade_keys[k']! β€ number_grade β number_grade_keys[k']! β€ number_grade_keys[i]!) β§ | |
| result[i]! = (grade_dict[i]!).snd | |
| else | |
| result[i]! = ""E"" | |
| -- program termination | |
| β result, | |
| implementation grades = result β§ | |
| spec result","def generated_spec | |
| -- function signature | |
| (impl: List Float β List String) | |
| -- inputs | |
| (grades: List Float) : Prop :=","theorem spec_isomorphism: | |
| β impl, | |
| (β grades, problem_spec impl grades) β | |
| (β grades, generated_spec impl grades) :=",sorry,def implementation (grades: List Float) : List String :=,sorry,"-- #test implementation [4.0, 3, 1.7, 2, 3.5] = ['A+', 'B', 'C-', 'C', 'A-']","theorem correctness | |
| (grades: List Float) | |
| : problem_spec implementation grades | |
| :=","by | |
| sorry",,, | |
| def prime_length(s: str) -> bool,"Write a function that takes a string and returns True if the string | |
| length is a prime number or False otherwise | |
| ","[{""input"": ""Hello"", ""output"": true}, {""input"": ""abcdcba"", ""output"": true}, {""input"": ""kittens"", ""output"": true}, {""input"": ""orange"", ""output"": false}]","def prime_length(s: str) -> bool | |
| """"""Write a function that takes a string and returns True if the string | |
| length is a prime number or False otherwise | |
| """"""","def problem_spec | |
| -- function signature | |
| (implementation: String β Bool) | |
| -- inputs | |
| (s: String) := | |
| -- spec | |
| let spec (result : Bool) := | |
| let is_prime (n: Nat) : Prop := | |
| Β¬ (β k, 2 β€ k β§ k < n β§ n % k = 0); | |
| result β is_prime s.length | |
| -- 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 :=,Nat.Prime s.length,"-- #test implementation ""Hello"" = True | |
| -- #test implementation ""abcdcba"" = True | |
| -- #test implementation ""kittens"" = True | |
| -- #test implementation ""orange"" = False","theorem correctness | |
| (s: String) | |
| : problem_spec implementation s | |
| :=","by | |
| unfold problem_spec | |
| let result := implementation s | |
| use result | |
| simp [result] | |
| simp [implementation] | |
| apply Iff.intro | |
| intro h_is_prime | |
| simp [Nat.prime_def] at h_is_prime | |
| intro x h_2_le_x h_x_lt_s_len | |
| have h_p' := h_is_prime.2 x | |
| by_contra h_s_len_mod_x | |
| have h_x_dvd_s_len: x β£ s.length := by | |
| apply Nat.dvd_of_mod_eq_zero | |
| exact h_s_len_mod_x | |
| simp [h_x_dvd_s_len] at h_p' | |
| have h_x_eq_s_len_false: Β¬ (x = s.length) := by | |
| linarith | |
| simp [h_x_eq_s_len_false] at h_p' | |
| have h_x_ne_1: Β¬ (x = 1) := by | |
| linarith | |
| simp [h_x_ne_1] at h_p' | |
| sorry",,, | |
| def starts_one_ends(n: int) -> int,"Given a positive integer n, return the count of the numbers of n-digit | |
| positive integers that start or end with 1. | |
| Note: For reviewer, I believe this is the most straightforward spec, and I am relying on Set cardianlity not being computable in general. The point of this problem is really to privide a formula. | |
| Note: But I guess a program that goes through each number and adds 1 will be the same as a program that computes in O(1) under this view. | |
| ","[{""input"": 1, ""output"": 1}, {""input"": 2, ""output"": 18}]","def starts_one_ends(n: int) -> int | |
| """"""Given a positive integer n, return the count of the numbers of n-digit | |
| positive integers that start or end with 1. | |
| Note: For reviewer, I believe this is the most straightforward spec, and I am relying on Set cardianlity not being computable in general. The point of this problem is really to privide a formula. | |
| Note: But I guess a program that goes through each number and adds 1 will be the same as a program that computes in O(1) under this view. | |
| """"""","def problem_spec | |
| -- function signature | |
| (implementation: Nat β Nat) | |
| -- inputs | |
| (n: Nat) := | |
| -- spec | |
| let spec (result : Nat) := | |
| 0 < n β | |
| result = {k : β | 10 ^ (n - 1) β€ k β§ k < 10 ^ n β§ (k.repr.front = '1' β¨ k.repr.back = '1')}.ncard | |
| -- 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 1 = 1 | |
| -- #test implementation 2 = 18","theorem correctness | |
| (n: Nat) | |
| : problem_spec implementation n | |
| :=","by | |
| sorry",,, | |
| def solve(n: int) -> str,"Given a positive integer N, return the total sum of its digits in binary. | |
| ","[{""input"": 1000, ""output"": ""1""}, {""input"": 150, ""output"": ""110""}, {""input"": 147, ""output"": ""1100""}]","def solve(n: int) -> str | |
| """"""Given a positive integer N, return the total sum of its digits in binary. | |
| """"""","def problem_spec | |
| -- function signature | |
| (implementation: Nat β String) | |
| -- inputs | |
| (n: Nat) := | |
| -- spec | |
| let spec (result : String) := | |
| 0 < n β | |
| result.all (fun c => c = '0' β¨ c = '1') β | |
| Nat.ofDigits 2 (result.data.map (fun c => if c = '0' then 0 else 1)).reverse = (Nat.digits 10 n).sum | |
| -- program termination | |
| β result, | |
| implementation n = result β§ | |
| spec result","def generated_spec | |
| -- function signature | |
| (impl: Nat β String) | |
| -- inputs | |
| (n: Nat) : Prop :=","theorem spec_isomorphism: | |
| β impl, | |
| (β n, problem_spec impl n) β | |
| (β n, generated_spec impl n) :=",sorry,def implementation (n: Nat) : String :=,sorry,"-- #test implementation 1000 = ""1"" | |
| -- #test implementation 150 = ""110"" | |
| -- #test implementation 147 = ""1100""","theorem correctness | |
| (n: Nat) | |
| : problem_spec implementation n | |
| :=","by | |
| sorry",,, | |
| def solve(n: list[int]) -> int,"Given a non-empty list of integers lst, add the even elements that are at odd indices. | |
| ","[{""input"": [4, 2, 6, 7], ""output"": 2}]","def solve(n: list[int]) -> int | |
| """"""Given a non-empty list of integers lst, add the even elements that are at odd indices. | |
| """"""","def problem_spec | |
| -- function signature | |
| (implementation: List Int β Int) | |
| -- inputs | |
| (lst: List Int) := | |
| -- spec | |
| let spec (result : Int) := | |
| lst.length = 0 β result = 0 β§ | |
| lst.length > 0 β | |
| if lst.length > 1 then | |
| result = (if Even lst[1]! then lst[1]! else 0) + implementation (lst.drop 2) | |
| else | |
| result = (if Even lst[1]! then lst[1]! else 0) | |
| -- program termination | |
| β result, | |
| implementation lst = result β§ | |
| spec result","def generated_spec | |
| -- function signature | |
| (impl: List Int β 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) : Int :=,sorry,"-- #test implementation [4, 2, 6, 7] = 2","theorem correctness | |
| (lst: List Int) | |
| : problem_spec implementation lst | |
| :=","by | |
| sorry",,, | |
| def anti_shuffle(s : str) -> str,""""""" | |
| Write a function that takes a string and returns an ordered version of it. | |
| Ordered version of string, is a string where all words (separated by space) | |
| are replaced by a new word where all the characters arranged in | |
| ascending order based on ascii value. | |
| Note: You should keep the order of words and blank spaces in the sentence. | |
| ","[{""input"": ""Hi"", ""output"": ""Hi""}, {""input"": ""hello"", ""output"": ""ehllo""}, {""input"": ""Hello World!!!"", ""output"": ""Hello !!!Wdlor""}]","def anti_shuffle(s : str) -> str | |
| """""""""""" | |
| Write a function that takes a string and returns an ordered version of it. | |
| Ordered version of string, is a string where all words (separated by space) | |
| are replaced by a new word where all the characters arranged in | |
| ascending order based on ascii value. | |
| Note: You should keep the order of words and blank spaces in the sentence. | |
| """"""","def problem_spec | |
| -- function signature | |
| (implementation: String β String) | |
| -- inputs | |
| (s: String) := | |
| -- spec | |
| let spec (result : String) := | |
| result.length = s.length β§ | |
| let words := result.split (fun c => c = ' '); | |
| let s_words := s.split (fun c => c = ' '); | |
| s_words.length = words.length β§ | |
| β i, i < words.length β | |
| words[i]!.length = s_words[i]!.length β§ | |
| ((β j, j < words[i]!.length β | |
| (words[i]!.data[j]! β s_words[i]!.data β§ | |
| s_words[i]!.data[j]! β words[i]!.data β§ | |
| words[i]!.data.count (words[i]!.data[j]!) = s_words[i]!.data.count (s_words[i]!.data[j]!))) β§ | |
| List.Sorted Nat.le (words[i]!.data.map (fun c => c.val.toNat))) | |
| -- program termination | |
| β result, | |
| implementation s = result β§ | |
| spec result","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 ""Hi"" = ""Hi"" | |
| -- #test implementation ""hello"" = ""ehllo"" | |
| -- #test implementation ""Hello World!!!"" = ""Hello !!!Wdlor""","theorem correctness | |
| (s: String) | |
| : problem_spec implementation s | |
| :=","by | |
| sorry",,, | |
| "def get_coords_sorted(lst : list(list(int)), x : int) -> list((int, int))","You are given a 2 dimensional data, as a nested lists, | |
| which is similar to matrix, however, unlike matrices, | |
| each row may contain a different number of columns. | |
| Given lst, and integer x, find integers x in the list, | |
| and return list of tuples, [(x1, y1), (x2, y2) ...] such that | |
| each tuple is a coordinate - (row, columns), starting with 0. | |
| Sort coordinates initially by rows in ascending order. | |
| Also, sort coordinates of the row by columns in descending order. | |
| ","[{""input"": [[[1, 2, 3, 4, 5, 6], [1, 2, 3, 4, 1, 6], [1, 2, 3, 4, 5, 1]], 1], ""output"": [""(0"", ""0)"", ""(1"", ""4)"", ""(1"", ""0)"", ""(2"", ""5)"", ""(2"", ""0)""]}, {""input"": [[], 1], ""output"": []}, {""input"": [[[], [1], [1, 2, 3]], 3], ""output"": [""(2"", ""2)""]}]","def get_coords_sorted(lst : list(list(int)), x : int) -> list((int, int)) | |
| """"""You are given a 2 dimensional data, as a nested lists, | |
| which is similar to matrix, however, unlike matrices, | |
| each row may contain a different number of columns. | |
| Given lst, and integer x, find integers x in the list, | |
| and return list of tuples, [(x1, y1), (x2, y2) ...] such that | |
| each tuple is a coordinate - (row, columns), starting with 0. | |
| Sort coordinates initially by rows in ascending order. | |
| Also, sort coordinates of the row by columns in descending order. | |
| """"""","def problem_spec | |
| -- function signature | |
| (implementation: List (List Int) β Int β List (Nat Γ Nat)) | |
| -- inputs | |
| (lst: List (List Int)) | |
| (x: Int) := | |
| -- spec | |
| let spec (result : List (Nat Γ Nat)) := | |
| (β i, i < result.length β | |
| let (row, col) := result[i]! | |
| row < lst.length β§ | |
| col < lst[row]!.length β§ | |
| (lst[row]!)[col]! = x) β§ | |
| (βα΅ (i < lst.length) (j < lst[i]!.length), | |
| (lst[i]!)[j]! = x β (i, j) β result) β§ | |
| (result.map (fun (r, c) => r)).Sorted Nat.le β§ | |
| (β i < result.length, | |
| let (row, col) := result[i]! | |
| ((result.filter (fun (r, c) => r = row)).map (fun (r, c) => c)).Sorted (fun a b => a β₯ b)) | |
| -- program termination | |
| β result, | |
| implementation lst x = result β§ | |
| spec result","def generated_spec | |
| -- function signature | |
| (impl: List (List Int) β Int β List (Nat Γ Nat)) | |
| -- inputs | |
| (lst: List (List Int)) | |
| (x: Int) : Prop :=","theorem spec_isomorphism: | |
| β impl, | |
| (β lst x, problem_spec impl lst x) β | |
| (β lst x, generated_spec impl lst x) :=",sorry,def implementation (lst: List (List Int)) (x: Int) : List (Nat Γ Nat) :=,sorry,"-- #test implementation ""Hi"" = ""Hi"" | |
| -- #test implementation ""hello"" = ""ehllo"" | |
| -- #test implementation ""Hello World!!!"" = ""Hello !!!Wdlor""","theorem correctness | |
| (lst: List (List Int)) | |
| (x: Int) | |
| : problem_spec implementation lst x | |
| :=","by | |
| sorry",,, | |
| def sort_array(lst : list(int)) -> list(int),""""""" | |
| Given an array of non-negative integers, return a copy of the given array after sorting, | |
| you will sort the given array in ascending order if the sum( first index value, last index value) is odd, | |
| or sort it in descending order if the sum( first index value, last index value) is even. | |
| Note(George): I have elected to ignore the copy part. | |
| ","[{""input"": [], ""output"": []}, {""input"": [5], ""output"": [5]}, {""input"": [2, 4, 3, 0, 1, 5], ""output"": [0, 1, 2, 3, 4, 5]}, {""input"": [2, 4, 3, 0, 1, 5, 6], ""output"": [6, 5, 4, 3, 2, 1, 0]}]","def sort_array(lst : list(int)) -> list(int) | |
| """""""""""" | |
| Given an array of non-negative integers, return a copy of the given array after sorting, | |
| you will sort the given array in ascending order if the sum( first index value, last index value) is odd, | |
| or sort it in descending order if the sum( first index value, last index value) is even. | |
| Note(George): I have elected to ignore the copy part. | |
| """"""","def problem_spec | |
| -- function signature | |
| (implementation: List Nat β List Nat) | |
| -- inputs | |
| (lst: List Nat) := | |
| -- spec | |
| let spec (result : List Nat) := | |
| lst.length > 0 β | |
| result.length = lst.length β§ | |
| (β i, i < result.length β | |
| result[i]! β lst β§ | |
| lst[i]! β result β§ | |
| result.count (lst[i]!) = lst.count (lst[i]!)) β§ | |
| (lst.head! + lst.getLast!) β‘ 1 [MOD 2] β | |
| result.Sorted Nat.le β§ | |
| (lst.head! + lst.getLast!) β‘ 0 [MOD 2] β | |
| result.Sorted (fun a b => a β₯ b) | |
| -- program termination | |
| β result, | |
| implementation lst = result β§ | |
| spec result","def generated_spec | |
| -- function signature | |
| (impl: List Nat β List Nat) | |
| -- inputs | |
| (lst: List Nat) : Prop :=","theorem spec_isomorphism: | |
| β impl, | |
| (β lst, problem_spec impl lst) β | |
| (β lst, generated_spec impl lst) :=",sorry,def implementation (lst: List Nat) : List Nat :=,sorry,"-- #test implementation [] = [] | |
| -- #test implementation [5] = [5] | |
| -- #test implementation [2, 4, 3, 0, 1, 5] = [0, 1, 2, 3, 4, 5] | |
| -- #test implementation [2, 4, 3, 0, 1, 5, 6] = [6, 5, 4, 3, 2, 1, 0]","theorem correctness | |
| (lst: List Nat) | |
| : problem_spec implementation lst | |
| :=","by | |
| sorry",,, | |
| def encrypt(str : str) -> str,"Create a function encrypt that takes a string as an argument and | |
| returns a string encrypted with the alphabet being rotated. | |
| The alphabet should be rotated in a manner such that the letters | |
| shift down by two multiplied to two places. | |
| ","[{""input"": ""hi"", ""output"": ""lm""}, {""input"": ""asdfghjkl"", ""output"": ""ewhjklnop""}, {""input"": ""gf"", ""output"": ""kj""}, {""input"": ""et"", ""output"": ""ix""}]","def encrypt(str : str) -> str | |
| """"""Create a function encrypt that takes a string as an argument and | |
| returns a string encrypted with the alphabet being rotated. | |
| The alphabet should be rotated in a manner such that the letters | |
| shift down by two multiplied to two places. | |
| """"""","def problem_spec | |
| -- function signature | |
| (implementation: String β String) | |
| -- inputs | |
| (str: String) := | |
| -- spec | |
| let spec (result : String) := | |
| result.data.all (fun c => c.isLower) β | |
| result.length = str.length β§ | |
| (β i, i < str.length β | |
| let c := str.data[i]! | |
| let c' := result.data[i]! | |
| ((c'.toNat - 97) + 2 * 2) % 26 = (c.toNat - 97)) | |
| -- program termination | |
| β result, | |
| implementation str = result β§ | |
| spec result","def generated_spec | |
| -- function signature | |
| (impl: String β String) | |
| -- inputs | |
| (str: String) : Prop :=","theorem spec_isomorphism: | |
| β impl, | |
| (β str, problem_spec impl str) β | |
| (β str, generated_spec impl str) :=",sorry,def implementation (str: String) : String :=,sorry,"-- #test implementation ""hi"" = ""lm"" | |
| -- #test implementation ""asdfghjkl"" = ""ewhjklnop"" | |
| -- #test implementation ""gf"" = ""kj"" | |
| -- #test implementation ""et"" = ""ix""","theorem correctness | |
| (str: String) | |
| : problem_spec implementation str | |
| :=","by | |
| sorry",,, | |
| def next_smallest(lst: List[int]) -> Optional[int],"You are given a list of integers. | |
| Write a function next_smallest() that returns the 2nd smallest element of the list. | |
| Return None if there is no such element. | |
| TODO(George): Remove this when being reviewed | |
| The spec is defined as: if result is none there is no second smallest element, which | |
| exists in a finite list iff there are at least two distinct elements in the list. | |
| If result is some x, then x is the second smallest element of the list, the spec | |
| obtains the sublist of elements smaller than the result, and checks that this | |
| sublist does not contain two distinct elements (they are all the same). | |
| ","[{""input"": [1, 2, 3, 4, 5], ""output"": 2}, {""input"": [5, 1, 4, 3, 2], ""output"": 2}, {""input"": [], ""output"": ""None""}, {""input"": [1, 1], ""output"": ""None""}]","def next_smallest(lst: List[int]) -> Optional[int] | |
| """"""You are given a list of integers. | |
| Write a function next_smallest() that returns the 2nd smallest element of the list. | |
| Return None if there is no such element. | |
| TODO(George): Remove this when being reviewed | |
| The spec is defined as: if result is none there is no second smallest element, which | |
| exists in a finite list iff there are at least two distinct elements in the list. | |
| If result is some x, then x is the second smallest element of the list, the spec | |
| obtains the sublist of elements smaller than the result, and checks that this | |
| sublist does not contain two distinct elements (they are all the same). | |
| """"""","def problem_spec | |
| -- function signature | |
| (implementation: List Int β Option Int) | |
| -- inputs | |
| (lst: List Int) := | |
| -- spec | |
| let spec (result : Option Int) := | |
| match result with | |
| | none => Β¬ (β i j, i < lst.length β§ j < lst.length β§ i β j β§ lst.get! i < lst.get! j) | |
| | some result => | |
| let smaller_els := lst.filter (Β· < result); | |
| 0 < smaller_els.length β§ | |
| smaller_els.all (Ξ» x => x = smaller_els.get! 0); | |
| -- program termination | |
| β result, | |
| implementation lst = result β§ | |
| spec result","def generated_spec | |
| -- function signature | |
| (impl: List Int β Option 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) : Option Int :=,sorry,"-- #test implementation [1, 2, 3, 4, 5] = some 2 | |
| -- #test implementation [5, 1, 4, 3, 2] = some 2 | |
| -- #test implementation [] = none | |
| -- #test implementation [1, 1] = none","theorem correctness | |
| (lst: List Int) | |
| : problem_spec implementation lst | |
| :=","by | |
| sorry",,, | |
| def is_bored(s: str) -> int,"You'll be given a string of words, and your task is to count the number | |
| of boredoms. A boredom is a sentence that starts with the word ""I"". | |
| Sentences are delimited by '.', '?' or '!'. | |
| ","[{""input"": ""Hello world"", ""expected_output"": 0}, {""input"": ""The sky is blue. The sun is shining. I love this weather"", ""expected_output"": 1}]","def is_bored(s: str) -> int | |
| """"""You'll be given a string of words, and your task is to count the number | |
| of boredoms. A boredom is a sentence that starts with the word ""I"". | |
| Sentences are delimited by '.', '?' or '!'. | |
| """"""","def problem_spec | |
| -- function signature | |
| (implementation: String β Nat) | |
| -- inputs | |
| (s: String) := | |
| -- spec | |
| let spec (result : Nat) := | |
| let is_sentence_is_boredom (s: String) : Bool := | |
| (s.startsWith ""I "" β¨ s.startsWith "" I"") β§ '.' β s.data β§ '?' β s.data β§ '!' β s.data | |
| match s.data.findIdx? (Ξ» c => c = '.' β¨ c = '?' β¨ c = '!') with | |
| | some i => | |
| let j := i + 1; | |
| let substring := s.drop j; | |
| result = (if is_sentence_is_boredom substring then 1 else 0) + implementation substring | |
| | none => | |
| result = if is_sentence_is_boredom s then 1 else 0 | |
| -- program termination | |
| β result, | |
| implementation s = result β§ | |
| spec result","def generated_spec | |
| -- function signature | |
| (impl: String β Nat) | |
| -- inputs | |
| (s: String) : Prop :=","theorem spec_isomorphism: | |
| β impl, | |
| (β s, problem_spec impl s) β | |
| (β s, generated_spec impl s) :=",sorry,def implementation (s: String) : Nat :=,sorry,"-- #test implementation ""Hello world"" = 0 | |
| -- #test implementation ""The sky is blue. The sun is shining. I love this weather"" = 1","theorem correctness | |
| (s: String) | |
| : problem_spec implementation s | |
| :=","by | |
| sorry",,, | |
| "def any_int(a: float, b: float, c: float) -> bool","Create a function that takes 3 numbers. | |
| Returns true if one of the numbers is equal to the sum of the other two, and all numbers are integers. | |
| Returns false in any other cases. | |
| ","[{""input"": [5, 2, 7], ""expected_output"": true}, {""input"": [3, 2, 2], ""expected_output"": false}, {""input"": [3, -2, 1], ""expected_output"": true}, {""input"": [3.6, -2.2, 2], ""expected_output"": false}]","def any_int(a: float, b: float, c: float) -> bool | |
| """"""Create a function that takes 3 numbers. | |
| Returns true if one of the numbers is equal to the sum of the other two, and all numbers are integers. | |
| Returns false in any other cases. | |
| """"""","def problem_spec | |
| -- function signature | |
| (implementation: Rat β Rat β Rat β Bool) | |
| -- inputs | |
| (a: Rat) (b: Rat) (c: Rat) := | |
| -- spec | |
| let spec (result : Bool) := | |
| let nums := [a, b, c]; | |
| result = true β β i j k : β, {i, j, k} β ({0, 1, 2} : Set β) β§ i β j β§ j β k β§ k β i β§ (nums[i]! + nums[j]! = nums[k]!) β§ a.den = 1 β§ a.den = b.den β§ a.den = c.den | |
| -- program termination | |
| β result, | |
| implementation a b c = result β§ | |
| spec result","def generated_spec | |
| -- function signature | |
| (impl: Rat β Rat β Rat β Bool) | |
| -- 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) : Bool :=,sorry,"-- #test implementation 5 2 7 = true | |
| -- #test implementation 3 2 2 = false | |
| -- #test implementation 3 (-2) 1 = true | |
| -- #test implementation 3.6 (-2.2) 2 = false","theorem correctness | |
| (a: Rat) (b: Rat) (c: Rat) | |
| : problem_spec implementation a b c | |
| :=","by | |
| sorry",,, | |
| def encode(s : str) -> str,"Write a function that takes a message, and encodes in such a | |
| way that it swaps case of all letters, replaces all vowels in | |
| the message with the letter that appears 2 places ahead of that | |
| vowel in the english alphabet. | |
| Assume only letters. | |
| ","[{""input"": ""test"", ""expected_output"": ""TGST""}, {""input"": ""This is a message"", ""expected_output"": ""tHKS KS C MGSSCGG""}]","def encode(s : str) -> str | |
| """"""Write a function that takes a message, and encodes in such a | |
| way that it swaps case of all letters, replaces all vowels in | |
| the message with the letter that appears 2 places ahead of that | |
| vowel in the english alphabet. | |
| Assume only letters. | |
| """"""","def problem_spec | |
| -- function signature | |
| (implementation: String β String) | |
| -- inputs | |
| (s: String) := | |
| -- spec | |
| let spec (result : String) := | |
| s.data.all (Ξ» c => c.isAlpha) β | |
| result.length = s.length β§ | |
| (β i, i < s.length β | |
| let c := s.data.get! i; | |
| let c' := result.data.get! i; | |
| match c with | |
| | 'a' | 'e' | 'i' | 'o' | 'u' | 'A' | 'E' | 'I' | 'O' | 'U' => | |
| c.isUpper β c'.val = c.toLower.val + 2 β§ | |
| c.isLower β c'.val = c.toUpper.val + 2 | |
| | _ => | |
| c.isUpper β c' = c.toLower β§ | |
| c.isLower β c' = c.toUpper) | |
| -- program termination | |
| β result, | |
| implementation s = result β§ | |
| spec result","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 ""test"" = ""TGST"" | |
| -- #test implementation ""This is a message"" = ""tHKS KS C MGSSCGG""","theorem correctness | |
| (s: String) | |
| : problem_spec implementation s | |
| :=","by | |
| sorry",,, | |
| def sum_largest_prime(lst : list[int]) -> int,"You are given a list of integers. | |
| You need to find the largest prime value and return the sum of its digits. | |
| Note(George): Modified to use List of nats because all examples are nats. | |
| ","[{""input"": [0, 3, 2, 1, 3, 5, 7, 4, 5, 5, 5, 2, 181, 32, 4, 32, 3, 2, 32, 324, 4, 3], ""expected_output"": 10}, {""input"": [1, 0, 1, 8, 2, 4597, 2, 1, 3, 40, 1, 2, 1, 2, 4, 2, 5, 1], ""expected_output"": 25}, {""input"": [1, 3, 1, 32, 5107, 34, 83278, 109, 163, 23, 2323, 32, 30, 1, 9, 3], ""expected_output"": 13}, {""input"": [0, 724, 32, 71, 99, 32, 6, 0, 5, 91, 83, 0, 5, 6], ""expected_output"": 11}, {""input"": [0, 81, 12, 3, 1, 21], ""expected_output"": 3}, {""input"": [0, 8, 1, 2, 1, 7], ""expected_output"": 7}]","def sum_largest_prime(lst : list[int]) -> int | |
| """"""You are given a list of integers. | |
| You need to find the largest prime value and return the sum of its digits. | |
| Note(George): Modified to use List of nats because all examples are nats. | |
| """"""","def problem_spec | |
| -- function signature | |
| (implementation: List Nat β Nat) | |
| -- inputs | |
| (lst: List Nat) := | |
| -- spec | |
| let spec (result : Nat) := | |
| lst.any (fun num => Nat.Prime num) β | |
| result > 0 β§ β i, i < lst.length β§ Prime (lst.get! i) β§ | |
| (β j, j < lst.length β§ Prime (lst.get! j) β lst.get! i β€ lst.get! j) β§ | |
| result = (Nat.digits 10 (lst.get! i)).sum | |
| -- program termination | |
| β result, | |
| implementation lst = result β§ | |
| spec result","def generated_spec | |
| -- function signature | |
| (impl: List Nat β Nat) | |
| -- inputs | |
| (lst: List Nat) : Prop :=","theorem spec_isomorphism: | |
| β impl, | |
| (β lst, problem_spec impl lst) β | |
| (β lst, generated_spec impl lst) :=",sorry,def implementation (lst: List Nat) : Nat :=,sorry,"-- #test implementation [0,3,2,1,3,5,7,4,5,5,5,2,181,32,4,32,3,2,32,324,4,3] = 10 | |
| -- #test implementation [1,0,1,8,2,4597,2,1,3,40,1,2,1,2,4,2,5,1] = 25 | |
| -- #test implementation [1,3,1,32,5107,34,83278,109,163,23,2323,32,30,1,9,3] = 13 | |
| -- #test implementation [0,724,32,71,99,32,6,0,5,91,83,0,5,6] = 11 | |
| -- #test implementation [0,81,12,3,1,21] = 3 | |
| -- #test implementation [0,8,1,2,1,7] = 7","theorem correctness | |
| (lst: List Nat) | |
| : problem_spec implementation lst | |
| :=","by | |
| sorry",,, | |
| "def check_dict_case(s : dict[str, str]) -> bool","Given a dictionary, return True if all keys are strings in lower | |
| case or all keys are strings in upper case, else return False. | |
| The function should return False is the given dictionary is empty. | |
| Note(George): Modified the problem to use strings only for both keys and values. | |
| ","[{""input"": {""a"": ""apple"", ""b"": ""banana""}, ""expected_output"": true}, {""input"": {""a"": ""apple"", ""A"": ""banana"", ""B"": ""banana""}, ""expected_output"": false}, {""input"": {""a"": ""apple"", ""b"": ""banana""}, ""expected_output"": false}, {""input"": {""Name"": ""John"", ""Age"": ""36"", ""City"": ""Houston""}, ""expected_output"": false}, {""input"": {""STATE"": ""NC"", ""ZIP"": ""12345""}, ""expected_output"": true}]","def check_dict_case(s : dict[str, str]) -> bool | |
| """"""Given a dictionary, return True if all keys are strings in lower | |
| case or all keys are strings in upper case, else return False. | |
| The function should return False is the given dictionary is empty. | |
| Note(George): Modified the problem to use strings only for both keys and values. | |
| """"""","def problem_spec | |
| -- function signature | |
| (implementation: Std.HashMap String String β Bool) | |
| -- inputs | |
| (D: Std.HashMap String String) := | |
| -- spec | |
| let spec (result : Bool) := | |
| match D.isEmpty with | |
| | true => result = false | |
| | false => | |
| let keys := D.keys | |
| let all_lower := keys.all (fun s => s.toLower = s) | |
| let all_upper := keys.all (fun s => s.toUpper = s) | |
| result = true β all_lower || all_upper | |
| -- program termination | |
| β result, | |
| implementation D = result β§ | |
| spec result","def generated_spec | |
| -- function signature | |
| (impl: Std.HashMap String String β Bool) | |
| -- inputs | |
| (D: Std.HashMap String String) : Prop :=","theorem spec_isomorphism: | |
| β impl, | |
| (β D, problem_spec impl D) β | |
| (β D, generated_spec impl D) :=",sorry,def implementation (D: Std.HashMap String String) : Bool :=,sorry,"-- #test implementation (Std.HashMap.ofList [(""a"", ""apple""), (""b"", ""banana"")]) = true | |
| -- #test implementation (Std.HashMap.ofList [(""a"", ""apple""), (""A"", ""banana""), (""B"", ""banana"")]) = false | |
| -- #test implementation (Std.HashMap.ofList [(""a"", ""apple""), (""b"", ""banana""), (""a"", ""apple"")]) = false | |
| -- #test implementation (Std.HashMap.ofList [(""Name"", ""John""), (""Age"", ""36""), (""City"", ""Houston"")]) = false | |
| -- #test implementation (Std.HashMap.ofList [(""STATE"", ""NC""), (""ZIP"", ""12345"")]) = true","theorem correctness | |
| (D: Std.HashMap String String) | |
| : problem_spec implementation D | |
| :=","by | |
| sorry",,, | |
| def count_up_to(n : int) -> list[int],"Implement a function that takes an non-negative integer and returns an array of the first n | |
| integers that are prime numbers and less than n. | |
| ","[{""input"": 5, ""expected_output"": [2, 3]}, {""input"": 11, ""expected_output"": [2, 3, 5, 7]}, {""input"": 0, ""expected_output"": []}, {""input"": 20, ""expected_output"": [2, 3, 5, 7, 11, 13, 17, 19]}, {""input"": 1, ""expected_output"": []}, {""input"": 18, ""expected_output"": [2, 3, 5, 7, 11, 13, 17]}]","def count_up_to(n : int) -> list[int] | |
| """"""Implement a function that takes an non-negative integer and returns an array of the first n | |
| integers that are prime numbers and less than n. | |
| """"""","def problem_spec | |
| -- function signature | |
| (implementation: Nat β List Nat) | |
| -- inputs | |
| (n: Nat) := | |
| -- spec | |
| let spec (result : List Nat) := | |
| match n with | |
| | 0 => result = [] | |
| | n => n > 0 β (β i, i < result.length β (Nat.Prime (result.get! i)) β§ (result.get! i) < n) β§ | |
| (β i : Nat, i < n β Nat.Prime i β i β result) | |
| -- program termination | |
| β result, | |
| implementation n = result β§ | |
| spec result","def generated_spec | |
| -- function signature | |
| (impl: Nat β List Nat) | |
| -- inputs | |
| (n: Nat) : Prop :=","theorem spec_isomorphism: | |
| β impl, | |
| (β n, problem_spec impl n) β | |
| (β n, generated_spec impl n) :=",sorry,def implementation (n: Nat) : List Nat :=,sorry,"-- #test implementation 5 = [2,3] | |
| -- #test implementation 11 = [2,3,5,7] | |
| -- #test implementation 0 = [] | |
| -- #test implementation 20 = [2,3,5,7,11,13,17,19] | |
| -- #test implementation 1 = [] | |
| -- #test implementation 18 = [2,3,5,7,11,13,17]","theorem correctness | |
| (n: Nat) | |
| : problem_spec implementation n | |
| :=","by | |
| sorry",,, | |
| "def multiply(a : Int, b : Int) -> Int","Complete the function that takes two integers and returns | |
| the product of their unit digits. | |
| Assume the input is always valid. | |
| -- Note(George): I'm finding it hard to not leak the implementation here, so I opted to make the spec more convoluted. | |
| ","[{""input"": ""148, 412"", ""expected_output"": 16}, {""input"": ""19, 28"", ""expected_output"": 72}, {""input"": ""2020, 1851"", ""expected_output"": 0}, {""input"": ""14, -15"", ""expected_output"": 20}]","def multiply(a : Int, b : Int) -> Int | |
| """"""Complete the function that takes two integers and returns | |
| the product of their unit digits. | |
| Assume the input is always valid. | |
| -- Note(George): I'm finding it hard to not leak the implementation here, so I opted to make the spec more convoluted. | |
| """"""","def problem_spec | |
| -- function signature | |
| (implementation: Int β Int β Int) | |
| -- inputs | |
| (a b: Int) := | |
| -- spec | |
| let spec (result : Int) := | |
| |result| β€ 81 β§ | |
| result % 10 = (a * b) % 10 β§ | |
| ((b%10) β 0 β (result % (b%10) = 0 β§ (result/ (b%10)) % 100 = (a%10))) β§ | |
| ((a%10) β 0 β (result % (a%10) = 0 β§ (result/ (a%10)) % 100 = (b%10))) β§ | |
| ((a%10 = 0) β¨ (b%10 = 0) β result = 0) | |
| -- program termination | |
| β result, | |
| implementation a b = result β§ | |
| spec result","def generated_spec | |
| -- function signature | |
| (impl: Int β Int β Int) | |
| -- inputs | |
| (a b: Int) : Prop :=","theorem spec_isomorphism: | |
| β impl, | |
| (β a b, problem_spec impl a b) β | |
| (β a b, generated_spec impl a b) :=",sorry,def implementation (a b: Int) : Int :=,sorry,"-- #test implementation 148 412 = 16 | |
| -- #test implementation 19 28 = 72 | |
| -- #test implementation 2020 1851 = 0 | |
| -- #test implementation 14 -15 = 20","theorem correctness | |
| (a b: Int) | |
| : problem_spec implementation a b | |
| :=","by | |
| sorry",,, | |
| def count_upper(s : String) -> Int,"Given a string s, count the number of uppercase vowels in even indices. | |
| -- Note(George): I also feel like this one is hard to not leak, I tried a trick about keeping implementation for a recursive call in the spec. Let me know if this doesn't work.. | |
| ","[{""input"": ""aBCdEf"", ""expected_output"": 1}, {""input"": ""abcdefg"", ""expected_output"": 0}, {""input"": ""dBBE"", ""expected_output"": 0}]","def count_upper(s : String) -> Int | |
| """"""Given a string s, count the number of uppercase vowels in even indices. | |
| -- Note(George): I also feel like this one is hard to not leak, I tried a trick about keeping implementation for a recursive call in the spec. Let me know if this doesn't work.. | |
| """"""","def problem_spec | |
| -- function signature | |
| (implementation: String β Int) | |
| -- inputs | |
| (s: String) := | |
| -- spec | |
| let uppercase_vowels := ['A', 'E', 'I', 'O', 'U'] | |
| let spec (result : Int) := | |
| let chars := s.toList | |
| (result = 0 β β i, i < chars.length β chars[i]! β uppercase_vowels) β§ | |
| (1 < chars.length β | |
| (result - 1 = implementation (chars.drop 2).toString β chars[0]! β uppercase_vowels) β¨ | |
| (result = implementation (chars.drop 2).toString β chars[0]! β uppercase_vowels) | |
| ) | |
| -- program termination | |
| β result, | |
| implementation s = result β§ | |
| spec result","def generated_spec | |
| -- function signature | |
| (impl: String β Int) | |
| -- inputs | |
| (s: String) : Prop :=","theorem spec_isomorphism: | |
| β impl, | |
| (β s, problem_spec impl s) β | |
| (β s, generated_spec impl s) :=",sorry,def implementation (s: String) : Int :=,sorry,"-- #test implementation ""aBCdEf"" = 1 | |
| -- #test implementation ""abcdefg"" = 0 | |
| -- #test implementation ""dBBE"" = 0","theorem correctness | |
| (s: String) | |
| : problem_spec implementation s | |
| :=","by | |
| sorry",,, | |
| def closest_integer(s : String) -> Option Int,"Create a function that takes a value (string) representing a number | |
| and returns the closest integer to it. If the number is equidistant | |
| from two integers, round it away from zero. | |
| ","[{""input"": ""10"", ""expected_output"": 10}, {""input"": ""15.3"", ""expected_output"": 15}]","def closest_integer(s : String) -> Option Int | |
| """"""Create a function that takes a value (string) representing a number | |
| and returns the closest integer to it. If the number is equidistant | |
| from two integers, round it away from zero. | |
| """"""","def problem_spec | |
| -- function signature | |
| (implementation: String β Option Int) | |
| -- inputs | |
| (s: String) := | |
| -- spec | |
| let numeric_characters := [""-"", ""0"", ""1"", ""2"", ""3"", ""4"", ""5"", ""6"", ""7"", ""8"", ""9"", "".""] | |
| let is_valid_string := | |
| s.length > 0 β§ | |
| s.count (""."".get! 0) β€ 1 β§ | |
| s.count (""-"".get! 0) β€ 1 β§ | |
| s.data.all (fun c => numeric_characters.contains (String.mk [c])) β§ | |
| (s.count (""-"".get! 0) = 1 β s.data.head! = '-') | |
| let spec (result : Option Int) := match result with | |
| | some result => | |
| is_valid_string β§ | |
| let parts := s.split (fun c => c = '.') | |
| (parts.length = 1 β result = s.toInt!) β§ | |
| (parts.length = 2 β | |
| let integer_part := parts.get! 0 | |
| let is_negative := s.data.head! = '-' | |
| |((integer_part.toInt! - result) : β)| β€ 0.5 β§ | |
| (is_negative β |((integer_part.toInt! - result) : β)| = 0.5 β integer_part.toInt? < result) β§ | |
| (Β¬is_negative β |((integer_part.toInt! - result) : β)| = 0.5 β integer_part.toInt? > result) | |
| ) | |
| | none => Β¬ is_valid_string | |
| -- program termination | |
| β result, | |
| implementation s = result β§ | |
| spec result","def generated_spec | |
| -- function signature | |
| (impl: String β Option Int) | |
| -- inputs | |
| (s: String) : Prop :=","theorem spec_isomorphism: | |
| β impl, | |
| (β s, problem_spec impl s) β | |
| (β s, generated_spec impl s) :=",sorry,def implementation (s: String) : Option Int :=,sorry,"-- #test implementation ""10"" = some 10 | |
| -- #test implementation ""15.3"" = some 15","theorem correctness | |
| (s: String) | |
| : problem_spec implementation s | |
| :=","by | |
| sorry",,, | |
| def make_a_pile(n: int) -> List[int],"Given a positive integer n, you have to make a pile of n levels of stones. | |
| The first level has n stones. | |
| The number of stones in the next level is: | |
| - the next odd number if n is odd. | |
| - the next even number if n is even. | |
| Return the number of stones in each level in a list, where element at index | |
| i represents the number of stones in the level (i+1). | |
| ","[{""input"": 3, ""expected_output"": [3, 5, 7]}]","def make_a_pile(n: int) -> List[int] | |
| """"""Given a positive integer n, you have to make a pile of n levels of stones. | |
| The first level has n stones. | |
| The number of stones in the next level is: | |
| - the next odd number if n is odd. | |
| - the next even number if n is even. | |
| Return the number of stones in each level in a list, where element at index | |
| i represents the number of stones in the level (i+1). | |
| """"""","def problem_spec | |
| -- function signature | |
| (implementation: Int β List Int) | |
| -- inputs | |
| (n: Int) := | |
| -- spec | |
| let spec (result: List Int) := | |
| result.length = n β§ | |
| (forall i: Nat, (1 <= i β§ i < n) β (result[i]! = result[i-1]! + 2)) β§ | |
| result[0]! = n | |
| -- program termination | |
| β result, implementation n = result β§ | |
| spec result","def generated_spec | |
| -- function signature | |
| (impl: Int β List Int) | |
| -- inputs | |
| (n: Int) : Prop :=","theorem spec_isomorphism: | |
| β impl, | |
| (β n, problem_spec impl n) β | |
| (β n, generated_spec impl n) :=",sorry,def implementation (n: Int) : List Int :=,sorry,"-- #test implementation 3 = [3, 5, 7] | |
| -- #test implementation 4 = [4,6,8,10] | |
| -- #test implementation 5 = [5, 7, 9, 11, 13] | |
| -- #test implementation 6 = [6, 8, 10, 12, 14, 16] | |
| -- #test implementation 8 = [8, 10, 12, 14, 16, 18, 20, 22]","theorem correctness | |
| (n: Int) | |
| : problem_spec implementation n | |
| :=","by | |
| sorry",,, | |
| def words_string(s: string) -> List[string],"You will be given a string of words separated by commas or spaces. Your task is | |
| to split the string into words and return an array of the words. | |
| ","[{""input"": ""Hi, my name is John"", ""expected_output"": [""Hi"", ""my"", ""name"", ""is"", ""John""]}, {""input"": ""One, two, three, four, five, six"", ""expected_output"": [""One"", ""two"", ""three"", ""four"", ""five"", ""six""]}]","def words_string(s: string) -> List[string] | |
| """"""You will be given a string of words separated by commas or spaces. Your task is | |
| to split the string into words and return an array of the words. | |
| """"""","def problem_spec | |
| -- function signature | |
| (implementation: String β List String) | |
| -- inputs | |
| (s: String) := | |
| -- spec | |
| let spec (result: List String) := | |
| let chars := s.toList; | |
| let first := s.takeWhile (fun c => c β ',' β§ c β ' '); | |
| (result = [] β (β x β chars, x = ' ' β¨ x = ',') β¨ s = """") β§ | |
| (result β [] β result = [first] ++ (implementation (s.drop (first.length + 1)))) | |
| -- program termination | |
| β result, implementation s = result β§ | |
| spec result","def generated_spec | |
| -- function signature | |
| (impl: String β List String) | |
| -- inputs | |
| (s: String) : Prop :=","theorem spec_isomorphism: | |
| β impl, | |
| (β s, problem_spec impl s) β | |
| (β s, generated_spec impl s) :=",sorry,def implementation (s: String) : List String :=,"List.map (fun s => (s.toList.filter (fun c => c != ',')).asString) ((s.splitOn).filter (fun s => s != """" β§ s != "",""))","-- #test implementation ""Hi, my name is John"" = [""Hi"", ""my"", ""name"", ""is"", ""John""] | |
| -- #test implementation ""One, two, three, four, five, six"" = [""One"", ""two"", ""three"", ""four"", ""five"", ""six""] | |
| -- #test implementation ""Hi, my name"" = [""Hi"", ""my"", ""name""] | |
| -- #test implementation ""One,, two, three, four, five, six,"" = [""One"", ""two"", ""three"", ""four"", ""five"", ""six""] | |
| -- #test implementation """" = [] | |
| -- #test implementation ""ahmed , gamal"" = [""ahmed"", ""gamal""]","theorem correctness | |
| (s: String) | |
| : problem_spec implementation s | |
| :=","by | |
| sorry",,, | |
| "def choose_num(x: int, y: int) -> int","This function takes two positive numbers x and y and returns the | |
| biggest even integer number that is in the range [x, y] inclusive. If | |
| there's no such number, then the function should return -1. | |
| ","[{""input"": ""(12, 15)"", ""expected_output"": 14}, {""input"": ""(13, 12)"", ""expected_output"": -1}]","def choose_num(x: int, y: int) -> int | |
| """"""This function takes two positive numbers x and y and returns the | |
| biggest even integer number that is in the range [x, y] inclusive. If | |
| there's no such number, then the function should return -1. | |
| """"""","def problem_spec | |
| -- function signature | |
| (implementation: Int β Int β Int) | |
| -- inputs | |
| (x: Int) (y: Int) := | |
| -- spec | |
| let spec (result: Int) := | |
| (result = -1 β¨ (x β€ result β§ result β€ y β§ Even result)) β§ | |
| (result = -1 β¨ (forall i: Int, (x β€ i β§ i β€ y β§ Even i) β result β₯ i)) β§ | |
| (result = -1 β (x > y β¨ (x == y β§ Odd x β§ Odd y))) | |
| -- program termination | |
| β result, implementation x y = result β§ | |
| spec result","def generated_spec | |
| -- function signature | |
| (impl: Int β Int β Int) | |
| -- inputs | |
| (x: Int) (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: Int) (y: Int) : Int :=,sorry,"-- #test implementation 12 15 = 14 | |
| -- #test implementation 13 12 = -1 | |
| -- #test implementation 33 12354 = 12354 | |
| -- #test implementation 5234 5233 = -1 | |
| -- #test implementation 6 29 = 28 | |
| -- #test implementation 27 10 = (-1) | |
| -- #test implementation 7 7 = -1 | |
| -- #test implementation 546 546 = 546","theorem correctness | |
| (x: Int) (y: Int) | |
| : problem_spec implementation x y | |
| :=","by | |
| sorry",,, | |
| "def rounded_avg(n: nat, m: nat) -> Option[string]","You are given two positive integers n and m, and your task is to compute the | |
| average of the integers from n through m (including n and m). | |
| Round the answer to the nearest integer and convert that to binary. | |
| If n is greater than m, return none. | |
| ","[{""input"": ""(1, 5)"", ""expected_output"": ""0b11""}, {""input"": ""(7, 5)"", ""expected_output"": ""None""}, {""input"": ""(10, 20)"", ""expected_output"": ""0b1111""}, {""input"": ""(20, 33)"", ""expected_output"": ""0b11010""}]","def rounded_avg(n: nat, m: nat) -> Option[string] | |
| """"""You are given two positive integers n and m, and your task is to compute the | |
| average of the integers from n through m (including n and m). | |
| Round the answer to the nearest integer and convert that to binary. | |
| If n is greater than m, return none. | |
| """"""","def problem_spec | |
| -- function signature | |
| (implementation: Nat β Nat β Option String) | |
| -- inputs | |
| (n: Nat) (m: Nat) := | |
| -- spec | |
| let spec (result: Option String) := | |
| (n > m β result.isNone) β§ | |
| (n β€ m β result.isSome) β§ | |
| (n β€ m β | |
| (result.isSome β§ | |
| let val := Option.getD result """"; | |
| let xs := List.Ico n (m+1); | |
| let avg := xs.sum / xs.length; | |
| (val.take 2 = ""0b"") β§ | |
| (Nat.ofDigits 2 ((val.drop 2).toList.map (fun c => c.toNat - '0'.toNat)).reverse = avg))) | |
| -- program termination | |
| β result, implementation n m = result β§ | |
| spec result","def generated_spec | |
| -- function signature | |
| (impl: Nat β Nat β Option String) | |
| -- inputs | |
| (n: Nat) (m: Nat) : Prop :=","theorem spec_isomorphism: | |
| β impl, | |
| (β n m, problem_spec impl n m) β | |
| (β n m, generated_spec impl n m) :=",sorry,def implementation (n: Nat) (m: Nat) : Option String :=,"if n > m then | |
| none | |
| else | |
| let xs := List.Ico n (m+1); | |
| let avg := xs.sum / xs.length; | |
| some (""0b"" ++ (Nat.toDigits 2 avg).asString)","-- #test implementation 1 5 = some ""0b11"" | |
| -- #test implementation 7 13 = some ""0b1010"" | |
| -- #test implementation 964 977 = some ""0b1111001010"" | |
| -- #test implementation 996 997 = some ""0b1111100100"" | |
| -- #test implementation 185 546 = some ""0b101101110"" | |
| -- #test implementation 362 496 = some ""0b110101101"" | |
| -- #test implementation 350 902 = some ""0b1001110010"" | |
| -- #test implementation 197 233 = some ""0b11010111"" | |
| -- #test implementation 7 5 = none | |
| -- #test implementation 5 1 = none | |
| -- #test implementation 5 5 = some ""0b101""","theorem correctness | |
| (n: Nat) (m: Nat) | |
| : problem_spec implementation n m | |
| :=","by | |
| sorry",,, | |
| def unique_digits(x: List[nat]) -> List[nat],"Given a list of positive integers x. return a sorted list of all | |
| elements that hasn't any even digit. | |
| Note: Returned list should be sorted in increasing order. | |
| ","[{""input"": [15, 33, 1422, 1], ""expected_output"": [1, 15, 33]}, {""input"": [152, 323, 1422, 10], ""expected_output"": []}]","def unique_digits(x: List[nat]) -> List[nat] | |
| """"""Given a list of positive integers x. return a sorted list of all | |
| elements that hasn't any even digit. | |
| Note: Returned list should be sorted in increasing order. | |
| """"""","def problem_spec | |
| -- function signature | |
| (implementation: List Nat β List Nat) | |
| -- inputs | |
| (x: List Nat) := | |
| -- spec | |
| let spec (result: List Nat) := | |
| let has_even_digits(i: Nat): Bool := | |
| (List.filter (fun d => Even d) (Nat.digits 10 i)).length > 0; | |
| (List.Sorted Nat.le result) β§ | |
| (forall i, i β result β (i β x β§ !(has_even_digits i))) | |
| -- program termination | |
| β result, implementation x = result β§ | |
| spec result","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 (x: List Nat) : List Nat :=,sorry,"-- #test implementation [15, 33, 1422, 1] = [1, 15, 33] | |
| -- #test implementation [152, 323, 1422, 10] = [] | |
| -- #test implementation [12345, 2033, 111, 151] = [111, 151] | |
| -- #test implementation [135, 103, 31] = [31, 135]","theorem correctness | |
| (x: List Nat) | |
| : problem_spec implementation x | |
| :=","by | |
| sorry",,, | |
| def by_length(arr: List[int]) -> List[string],"Given an array of integers, sort the integers that are between 1 and 9 inclusive, | |
| reverse the resulting array, and then replace each digit by its corresponding name from | |
| ""One"", ""Two"", ""Three"", ""Four"", ""Five"", ""Six"", ""Seven"", ""Eight"", ""Nine"". | |
| ","[{""input"": [2, 1, 1, 4, 5, 8, 2, 3], ""expected_output"": [""Eight"", ""Five"", ""Four"", ""Three"", ""Two"", ""Two"", ""One"", ""One""]}, {""input"": [], ""expected_output"": []}, {""input"": [1, -1, 55], ""expected_output"": [""One""]}]","def by_length(arr: List[int]) -> List[string] | |
| """"""Given an array of integers, sort the integers that are between 1 and 9 inclusive, | |
| reverse the resulting array, and then replace each digit by its corresponding name from | |
| ""One"", ""Two"", ""Three"", ""Four"", ""Five"", ""Six"", ""Seven"", ""Eight"", ""Nine"". | |
| """"""","def problem_spec | |
| -- function signature | |
| (implementation: List Int β List String) | |
| -- inputs | |
| (arr: List Int) := | |
| -- spec | |
| let spec (result: List String) := | |
| let digits: List String := [""One"", ""Two"", ""Three"", ""Four"", ""Five"", ""Six"", ""Seven"", ""Eight"", ""Nine""]; | |
| (forall s: String, (s β result β s β digits)) β§ | |
| (arr.length β₯ result.length) β§ | |
| (forall x: Nat, ((x: Int) β arr β§ 1 β€ x β§ x β€ 9) β (digits[x-1]! β result)) β§ | |
| (List.Sorted Int.le (List.map (fun (s: String) => (List.indexOf s digits) + 1) result).reverse) | |
| -- program termination | |
| β result, implementation arr = result β§ | |
| spec result","def generated_spec | |
| -- function signature | |
| (impl: List Int β List String) | |
| -- 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) : List String :=,sorry,"-- #test implementation [2, 1, 1, 4, 5, 8, 2, 3] = [""Eight"", ""Five"", ""Four"", ""Three"", ""Two"", ""Two"", ""One"", ""One""] | |
| -- #test implementation [] = [] | |
| -- #test implementation [1, -1 , 55] = [""One""] | |
| -- #test implementation [1, -1, 3, 2] = [""Three"", ""Two"", ""One""] | |
| -- #test implementation [9, 4, 8] = [""Nine"", ""Eight"", ""Four""]","theorem correctness | |
| (arr: List Int) | |
| : problem_spec implementation arr | |
| :=","by | |
| sorry",,, | |
| def f(n: int) -> List[int],"Implement the function f that takes n as a parameter, | |
| and returns a list of size n, such that the value of the element at index i is the factorial of i if i is even | |
| or the sum of numbers from 1 to i otherwise. | |
| i starts from 1. | |
| the factorial of i is the multiplication of the numbers from 1 to i (1 * 2 * ... * i). | |
| ","[{""input"": 5, ""expected_output"": [1, 2, 6, 24, 15]}]","def f(n: int) -> List[int] | |
| """"""Implement the function f that takes n as a parameter, | |
| and returns a list of size n, such that the value of the element at index i is the factorial of i if i is even | |
| or the sum of numbers from 1 to i otherwise. | |
| i starts from 1. | |
| the factorial of i is the multiplication of the numbers from 1 to i (1 * 2 * ... * i). | |
| """"""","def problem_spec | |
| -- function signature | |
| (implementation: Int β List Int) | |
| -- inputs | |
| (n: Int) := | |
| -- spec | |
| let spec (result: List Int) := | |
| (result.length = n) β§ | |
| (forall i: Nat, (1 β€ i β§ i β€ n β§ Even i) β (result[i-1]! = Nat.factorial i)) β§ | |
| (forall i: Nat, (1 β€ i β§ i β€ n β§ Odd i) β (result[i-1]! = (List.range (i+1)).sum)) | |
| -- program termination | |
| β result, implementation n = result β§ | |
| spec result","def generated_spec | |
| -- function signature | |
| (impl: Int β List Int) | |
| -- inputs | |
| (n: Int) : Prop :=","theorem spec_isomorphism: | |
| β impl, | |
| (β n, problem_spec impl n) β | |
| (β n, generated_spec impl n) :=",sorry,def implementation (n: Int) : List Int :=,sorry,"-- #test implementation 5 = [1, 2, 6, 24, 15] | |
| -- #test implementation 7 = [1, 2, 6, 24, 15, 720, 28] | |
| -- #test implementation 1 = [1] | |
| -- #test implementation 3 = [1, 2, 6]","theorem correctness | |
| (n: Int) | |
| : problem_spec implementation n | |
| :=","by | |
| sorry",,, | |
| "def even_odd_palindrome(n: nat) -> (nat, nat)","Given a positive integer n, return a tuple that has the number of even and odd | |
| integer palindromes that fall within the range(1, n), inclusive. | |
| ","[{""input"": 3, ""expected_output"": ""(1, 2)""}, {""input"": 12, ""expected_output"": ""(4, 6)""}]","def even_odd_palindrome(n: nat) -> (nat, nat) | |
| """"""Given a positive integer n, return a tuple that has the number of even and odd | |
| integer palindromes that fall within the range(1, n), inclusive. | |
| """"""","def problem_spec | |
| -- function signature | |
| (implementation: Nat β Nat Γ Nat) | |
| -- inputs | |
| (n: Nat) := | |
| -- spec | |
| let spec (result: Nat Γ Nat) := | |
| let is_palindrome (k: Nat): Prop := | |
| List.Palindrome (Nat.digits 10 k); | |
| let even_palindrome (k: Nat): Prop := | |
| (Even k) β§ (is_palindrome k); | |
| let odd_palindrome (k: Nat): Prop := | |
| (Odd k) β§ (is_palindrome k); | |
| n > 0 β | |
| (1 < n β | |
| let impl_n_minus_1 := implementation (n - 1); | |
| ((even_palindrome n) β result.1 = 1 + impl_n_minus_1.1) β§ | |
| ((odd_palindrome n) β result.2 = 1 + impl_n_minus_1.2) β§ | |
| (Β¬ (odd_palindrome n) β result.2 = impl_n_minus_1.2) β§ | |
| (Β¬ (even_palindrome n) β result.1 = impl_n_minus_1.1)) | |
| β§ | |
| (n = 1 β (result.1 = 0) β§ (result.2 = 1)); | |
| -- program termination | |
| β result, implementation n = result β§ | |
| spec result","def generated_spec | |
| -- function signature | |
| (impl: Nat β 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 Γ Nat :=,sorry,"-- #test implementation 123 = (8, 13) | |
| -- #test implementation 12 = (4, 6) | |
| -- #test implementation 3 = (1, 2) | |
| -- #test implementation 63 = (6, 8) | |
| -- #test implementation 25 = (5, 6) | |
| -- #test implementation 19 = (4, 6) | |
| -- #test implementation 9 = (4, 5)","theorem correctness | |
| (n: Nat) | |
| : problem_spec implementation n | |
| :=","by | |
| sorry",,, | |
| def count_nums(arr: List[int]) -> int,"Write a function count_nums which takes an array of integers and returns | |
| the number of elements which has a sum of digits > 0. | |
| If a number is negative, then its first signed digit will be negative: | |
| e.g. -123 has signed digits -1, 2, and 3. | |
| ","[{""input"": [], ""expected_output"": 0}, {""input"": [-1, 11, -11], ""expected_output"": 1}, {""input"": [1, 1, 2], ""expected_output"": 3}]","def count_nums(arr: List[int]) -> int | |
| """"""Write a function count_nums which takes an array of integers and returns | |
| the number of elements which has a sum of digits > 0. | |
| If a number is negative, then its first signed digit will be negative: | |
| e.g. -123 has signed digits -1, 2, and 3. | |
| """"""","def problem_spec | |
| -- function signature | |
| (implementation: List Int β Int) | |
| -- inputs | |
| (arr: List Int) := | |
| -- spec | |
| let spec (result: Int) := | |
| let dig_sum (x: Int): Int := | |
| let digs := x.natAbs.digits 10; | |
| if x >= 0 then | |
| (List.map (fun t => (t: Int)) digs).sum | |
| else | |
| (List.map (fun t => (t: Int)) (digs.drop 1)).sum - (digs[0]! : Int); | |
| (arr = [] β result = 0) β§ | |
| (arr β [] β 0 < (dig_sum arr[0]!) β result = 1 + implementation (arr.drop 1)) β§ | |
| (arr β [] β (dig_sum arr[0]!) β€ 0 β result = implementation (arr.drop 1)); | |
| -- program termination | |
| β result, implementation arr = result β§ | |
| spec result","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 :=,"let signed_digits(x: Int): List Int := | |
| let x': Nat := Int.natAbs x; | |
| let xs: List Nat := Nat.digits 10 x'; | |
| if x >= 0 then | |
| xs | |
| else | |
| (-Int.ofNat (xs[0]!)) :: xs.tail; | |
| ((List.map (fun (x: Int) => (signed_digits x).sum) arr).filter (fun (x: Int) => x > 0)).length","-- #test implementation [] = 0 | |
| -- #test implementation [-1, -2, 0] = 0 | |
| -- #test implementation [1, 1, 2, -2, 3, 4, 5] = 6 | |
| -- #test implementation [1, 6, 9, -6, 0, 1, 5] = 5 | |
| -- #test implementation [1, 100, 98, -7, 1, -1] = 4 | |
| -- #test implementation [12, 23, 34, -45, -56, 0] = 5 | |
| -- #test implementation [-0, 1^0] = 1 | |
| -- #test implementation [1] = 1","theorem correctness | |
| (arr: List Int) | |
| : problem_spec implementation arr | |
| :=","by | |
| sorry",,, | |
| def move_one_ball(arr: List[int]) -> bool,"We have an array 'arr' of N integers arr[1], arr[2], ..., arr[N].The | |
| numbers in the array will be randomly ordered. Your task is to determine if | |
| it is possible to get an array sorted in non-decreasing order by performing | |
| the following operation on the given array: | |
| You are allowed to perform right shift operation any number of times. | |
| One right shift operation means shifting all elements of the array by one | |
| position in the right direction. The last element of the array will be moved to | |
| the starting position in the array i.e. 0th index. | |
| If it is possible to obtain the sorted array by performing the above operation | |
| then return True else return False. | |
| If the given array is empty then return True. | |
| Note: The given list is guaranteed to have unique elements. | |
| ","[{""input"": [3, 4, 5, 1, 2], ""expected_output"": true}, {""input"": [3, 5, 4, 1, 2], ""expected_output"": false}]","def move_one_ball(arr: List[int]) -> bool | |
| """"""We have an array 'arr' of N integers arr[1], arr[2], ..., arr[N].The | |
| numbers in the array will be randomly ordered. Your task is to determine if | |
| it is possible to get an array sorted in non-decreasing order by performing | |
| the following operation on the given array: | |
| You are allowed to perform right shift operation any number of times. | |
| One right shift operation means shifting all elements of the array by one | |
| position in the right direction. The last element of the array will be moved to | |
| the starting position in the array i.e. 0th index. | |
| If it is possible to obtain the sorted array by performing the above operation | |
| then return True else return False. | |
| If the given array is empty then return True. | |
| Note: The given list is guaranteed to have unique elements. | |
| """"""","def problem_spec | |
| -- function signature | |
| (implementation: List Int β Bool) | |
| -- inputs | |
| (arr: List Int) := | |
| let is_shifted (xs: List Int) (ys: List Int) (i: Nat) := | |
| (xs.length = ys.length) β§ | |
| (0 <= i) β§ | |
| (i < xs.length) β§ | |
| (forall j, (0 <= j β§ j < ys.length) β (ys[j]! = xs[(j-i) % xs.length]!)) | |
| -- spec | |
| let spec (result: Bool) := | |
| ((arr = []) β (result = True)) β§ | |
| result β (exists i, exists arr_shifted, (is_shifted arr arr_shifted i) β§ (List.Sorted Int.le arr_shifted)) | |
| -- program termination | |
| β result, implementation arr = result β§ | |
| spec result","def generated_spec | |
| -- function signature | |
| (impl: List Int β Bool) | |
| -- 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) : Bool :=,sorry,"-- #test implementation [3, 4, 5, 1, 2] = True | |
| -- #test implementation [3, 5, 10, 1, 2] = True | |
| -- #test implementation [4, 3, 1, 2] = False | |
| -- #test implementation [3, 5, 4, 1, 2] = False | |
| -- #test implementation [] = True","theorem correctness | |
| (arr: List Int) | |
| : problem_spec implementation arr | |
| :=","by | |
| sorry",,, | |
| "def exchange(lst1: list[int], lst2: list[int]) -> str","In this problem, you will implement a function that takes two lists of numbers, | |
| and determines whether it is possible to perform an exchange of elements | |
| between them to make lst1 a list of only even numbers. | |
| There is no limit on the number of exchanged elements between lst1 and lst2. | |
| If it is possible to exchange elements between the lst1 and lst2 to make | |
| all the elements of lst1 to be even, return ""YES"". | |
| Otherwise, return ""NO"". It is assumed that the input lists will be non-empty. | |
| ","[{""input"": ""([1, 2, 3, 4], [1, 2, 3, 4])"", ""expected_output"": ""YES""}, {""input"": ""([1, 2, 3, 4], [1, 5, 3, 4])"", ""expected_output"": ""NO""}]","def exchange(lst1: list[int], lst2: list[int]) -> str | |
| """"""In this problem, you will implement a function that takes two lists of numbers, | |
| and determines whether it is possible to perform an exchange of elements | |
| between them to make lst1 a list of only even numbers. | |
| There is no limit on the number of exchanged elements between lst1 and lst2. | |
| If it is possible to exchange elements between the lst1 and lst2 to make | |
| all the elements of lst1 to be even, return ""YES"". | |
| Otherwise, return ""NO"". It is assumed that the input lists will be non-empty. | |
| """"""","def problem_spec | |
| -- function signature | |
| (implementation: List Int β List Int β String) | |
| -- inputs | |
| (lst1: List Int) | |
| (lst2: List Int) := | |
| -- spec | |
| let spec (result : String) := | |
| lst1 β [] β lst2 β [] β | |
| let bool_result := β exchange: List (Nat Γ Nat), | |
| let lst1_idxs := exchange.map (fun (a, b) => a) | |
| let lst2_idxs := exchange.map (fun (a, b) => b) | |
| lst1_idxs.all (fun i => i < lst1.length) β§ | |
| lst2_idxs.all (fun i => i < lst2.length) β§ | |
| lst1_idxs.Nodup β§ | |
| lst2_idxs.Nodup β§ | |
| β i, i < lst1.length β | |
| (i β lst1_idxs β Even (lst1.get! i)) β§ | |
| (i β lst1_idxs β | |
| -- find the (a, b) in exchange where a = i | |
| let i_idx := (lst1_idxs.indexesOf i).head! | |
| Even (lst2.get! (lst2_idxs.get! i_idx))) | |
| (bool_result β result = ""YES"") β§ | |
| (result = ""NO"" β Β¬ bool_result) β§ | |
| (result β ""YES"" β§ result β ""NO"" β False) | |
| -- program termination | |
| β result, | |
| implementation lst1 lst2 = result β§ | |
| spec result","def generated_spec | |
| -- function signature | |
| (impl: List Int β List Int β String) | |
| -- inputs | |
| (lst1: List Int) | |
| (lst2: List Int) : Prop :=","theorem spec_isomorphism: | |
| β impl, | |
| (β lst1 lst2, problem_spec impl lst1 lst2) β | |
| (β lst1 lst2, generated_spec impl lst1 lst2) :=",sorry,def implementation (lst1: List Int) (lst2: List Int) : String :=,sorry,"-- #test implementation ([1, 2, 3, 4], [1, 2, 3, 4]) = ""YES"" | |
| -- #test implementation ([1, 2, 3, 4], [1, 5, 3, 4]) = ""NO""","theorem correctness | |
| (lst1: List Int) | |
| (lst2: List Int) | |
| : problem_spec implementation lst1 lst2 | |
| :=","by | |
| sorry",,, | |
| "def histogram(s : str) -> Dict[str, int]","Given a string representing a space separated lowercase letters, return a dictionary | |
| of the letter with the most repetition and containing the corresponding count. | |
| If several letters have the same occurrence, return all of them. | |
| -- Note(George): I believe the equality extensionality for HashMaps makes this spec true. | |
| ","[{""input"": ""a b c"", ""expected_output"": {""a"": 1, ""b"": 1, ""c"": 1}}, {""input"": ""a b b a"", ""expected_output"": {""a"": 2, ""b"": 2}}, {""input"": ""a b c a b"", ""expected_output"": {""a"": 2, ""b"": 2}}, {""input"": ""b b b b a"", ""expected_output"": {""b"": 4}}, {""input"": """", ""expected_output"": {}}]","def histogram(s : str) -> Dict[str, int] | |
| """"""Given a string representing a space separated lowercase letters, return a dictionary | |
| of the letter with the most repetition and containing the corresponding count. | |
| If several letters have the same occurrence, return all of them. | |
| -- Note(George): I believe the equality extensionality for HashMaps makes this spec true. | |
| """"""","def problem_spec | |
| -- function signature | |
| (implementation: String β Std.HashMap Char Nat) | |
| -- inputs | |
| (s: String) := | |
| -- spec | |
| let spec (result : Std.HashMap Char Nat) := | |
| let chars := s.splitOn "" "" | |
| chars.all (fun c => c.length = 1) β§ s.all (fun c => c.isLower β¨ c = ' ') β | |
| β key β result.keys, | |
| (key.isLower β§ | |
| key β s.data β§ | |
| result.get! key = s.count key) β§ | |
| (β char β s.data, char.isLower β | |
| ((β char2 β s.data, char2.isLower β§ char2 β char β§ | |
| s.count char < s.count char2) β char β result.keys)) | |
| -- program termination | |
| β result, | |
| implementation s = result β§ | |
| spec result","def generated_spec | |
| -- function signature | |
| (impl: String β Std.HashMap Char Nat) | |
| -- inputs | |
| (s: String) : Prop :=","theorem spec_isomorphism: | |
| β impl, | |
| (β s, problem_spec impl s) β | |
| (β s, generated_spec impl s) :=",sorry,def implementation (s: String) : Std.HashMap Char Nat :=,sorry,"-- #test implementation 'a b c' = {'a': 1, 'b': 1, 'c': 1} | |
| -- #test implementation 'a b b a' = {'a': 2, 'b': 2} | |
| -- #test implementation 'a b c a b' = {'a': 2, 'b': 2} | |
| -- #test implementation 'b b b b a' = {'b': 4} | |
| -- #test implementation '' = {}","theorem correctness | |
| (s: String) | |
| : problem_spec implementation s | |
| :=","by | |
| sorry",,, | |
| "def reverse_delete(s : str, c : str) -> (str, bool)","We are given two strings s and c, you have to deleted all the characters in s that are equal to any character in c | |
| then check if the result string is palindrome. | |
| A string is called palindrome if it reads the same backward as forward. | |
| You should return a tuple containing the result string and True/False for the check. | |
| -- Note: We assume the deletions preserve the order of the remaining characters. | |
| ","[{""input"": [""abcde"", ""ae""], ""expected_output"": ""(\""bcd\"", False)""}, {""input"": [""abcdef"", ""b""], ""expected_output"": ""(\""acdef\"", False)""}, {""input"": [""abcdedcba"", ""ab""], ""expected_output"": ""('cdedc', True)""}]","def reverse_delete(s : str, c : str) -> (str, bool) | |
| """"""We are given two strings s and c, you have to deleted all the characters in s that are equal to any character in c | |
| then check if the result string is palindrome. | |
| A string is called palindrome if it reads the same backward as forward. | |
| You should return a tuple containing the result string and True/False for the check. | |
| -- Note: We assume the deletions preserve the order of the remaining characters. | |
| """"""","def problem_spec | |
| -- function signature | |
| (implementation: String β String β (String Γ Bool)) | |
| -- inputs | |
| (s: String) | |
| (c: String) := | |
| -- spec | |
| let spec (result : String Γ Bool) := | |
| let (result_str, result_bool) := result | |
| result_bool = (List.Palindrome result_str.data) β§ | |
| (c.data.length = 0 β result_str = s) β§ | |
| (c.data.length > 0 β | |
| result_str = | |
| (implementation | |
| (String.join ((s.data.filter (fun x => x β c.data.head!)).map (fun c => String.mk [c]))) | |
| (c.drop 1)).fst) | |
| -- program termination | |
| β result, | |
| implementation s c = result β§ | |
| spec result","def generated_spec | |
| -- function signature | |
| (impl: String β String β (String Γ Bool)) | |
| -- inputs | |
| (s: String) | |
| (c: String) : Prop :=","theorem spec_isomorphism: | |
| β impl, | |
| (β s c, problem_spec impl s c) β | |
| (β s c, generated_spec impl s c) :=",sorry,def implementation (s: String) (c: String) : String Γ Bool :=,sorry,"-- #test implementation ""abcde"" ""ae"" = (""bcd"", False) | |
| -- #test implementation ""abcdef"" ""b"" = (""acdef"", False) | |
| -- #test implementation ""abcdedcba"" ""ab"" = (""cdedc"", True)","theorem correctness | |
| (s c: String) | |
| : problem_spec implementation s c | |
| :=","by | |
| sorry",,, | |
| def odd_count(lst : list[str]) -> list[str],"Given a list of strings, where each string consists of only digits, return a list. | |
| Each element i of the output should be ""the number of odd elements in the | |
| string i of the input."" where all the i's should be replaced by the number | |
| of odd digits in the i'th string of the input. | |
| Note(George): Found it hard to not leak the implementation, so I opted for a recursive statement. | |
| ","[{""input"": [""1234567""], ""expected_output"": [""the number of odd elements 4n the str4ng 4 of the 4nput.""]}, {""input"": [""3"", ""11111111""], ""expected_output"": [""the number of odd elements 1n the str1ng 1 of the 1nput."", ""the number of odd elements 8n the str8ng 8 of the 8nput.""]}]","def odd_count(lst : list[str]) -> list[str] | |
| """"""Given a list of strings, where each string consists of only digits, return a list. | |
| Each element i of the output should be ""the number of odd elements in the | |
| string i of the input."" where all the i's should be replaced by the number | |
| of odd digits in the i'th string of the input. | |
| Note(George): Found it hard to not leak the implementation, so I opted for a recursive statement. | |
| """"""","def problem_spec | |
| -- function signature | |
| (implementation: List String β List String) | |
| -- inputs | |
| (lst: List String) := | |
| -- spec | |
| let spec (result : List String) := | |
| lst.all (fun s => s.data.all (fun c => c.isDigit)) β | |
| (result.length = 0 β lst.length = 0) β§ | |
| (result.length > 0 β | |
| let num_odd_digits := (lst.head!.data.filter (fun c => c.isDigit β§ c.toNat % 2 = 1)).length | |
| result.head! = ""the number of odd elements "" ++ num_odd_digits.repr ++ ""n the str"" ++ num_odd_digits.repr ++ ""ng "" ++ num_odd_digits.repr ++ "" of the "" ++ num_odd_digits.repr ++ ""nput."" | |
| β§ result.tail! = implementation lst.tail!) | |
| -- program termination | |
| β result, | |
| implementation lst = result β§ | |
| spec result","def generated_spec | |
| -- function signature | |
| (impl: List String β List String) | |
| -- inputs | |
| (lst: List String) : Prop :=","theorem spec_isomorphism: | |
| β impl, | |
| (β lst, problem_spec impl lst) β | |
| (β lst, generated_spec impl lst) :=",sorry,def implementation (lst: List String) : List String :=,sorry,"-- #test implementation ['1234567'] = [""the number of odd elements 4n the str4ng 4 of the 4nput.""] | |
| -- #test implementation ['3',""11111111""] = [""the number of odd elements 1n the str1ng 1 of the 1nput."", | |
| -- ""the number of odd elements 8n the str8ng 8 of the 8nput.""]","theorem correctness | |
| (lst: List String) | |
| : problem_spec implementation lst | |
| :=","by | |
| sorry",,, | |
| def minSubArraySum(nums : list[int]) -> int,"Given an array of integers nums, find the minimum sum of any non-empty sub-array | |
| of nums. | |
| ","[{""input"": [2, 3, 4, 1, 2, 4], ""expected_output"": 1}, {""input"": [-1, -2, -3], ""expected_output"": -6}]","def minSubArraySum(nums : list[int]) -> int | |
| """"""Given an array of integers nums, find the minimum sum of any non-empty sub-array | |
| of nums. | |
| """"""","def problem_spec | |
| -- function signature | |
| (implementation: List Int β Int) | |
| -- inputs | |
| (nums: List Int) := | |
| -- spec | |
| let spec (result : Int) := | |
| (β subarray β nums.sublists, | |
| subarray.length > 0 β | |
| result β€ subarray.sum) β§ | |
| (β subarray β nums.sublists, | |
| subarray.length > 0 β§ | |
| result = subarray.sum) | |
| -- program termination | |
| β result, | |
| implementation nums = result β§ | |
| spec result","def generated_spec | |
| -- function signature | |
| (impl: List Int β Int) | |
| -- inputs | |
| (nums: List Int) : Prop :=","theorem spec_isomorphism: | |
| β impl, | |
| (β nums, problem_spec impl nums) β | |
| (β nums, generated_spec impl nums) :=",sorry,def implementation (nums: List Int) : Int :=,sorry,"-- #test implementation [2, 3, 4, 1, 2, 4] = 1 | |
| -- #test implementation [-1, -2, -3] = -6","theorem correctness | |
| (nums: List Int) | |
| : problem_spec implementation nums | |
| :=","by | |
| sorry",,, | |
| "def max_fill_count(grid : list[list[int]], capacity : int) -> int","You are given a rectangular grid of wells. Each row represents a single well, | |
| and each 1 in a row represents a single unit of water. | |
| Each well has a corresponding bucket that can be used to extract water from it, | |
| and all buckets have the same capacity. | |
| Your task is to use the buckets to empty the wells. | |
| Output the number of times you need to lower the buckets. | |
| Constraints: | |
| * all wells have the same length | |
| * 1 <= grid.length <= 10^2 | |
| * 1 <= grid[:,1].length <= 10^2 | |
| * grid[i][j] -> 0 | 1 | |
| * 1 <= capacity <= 10 | |
| ","[{""input"": ""([[0,0,1,0], [0,1,0,0], [1,1,1,1]], 1)"", ""expected_output"": 6}, {""input"": ""([[0,0,1,1], [0,0,0,0], [1,1,1,1], [0,1,1,1]], 2)"", ""expected_output"": 5}, {""input"": ""([[0,0,0], [0,0,0]], 5)"", ""expected_output"": 0}]","def max_fill_count(grid : list[list[int]], capacity : int) -> int | |
| """"""You are given a rectangular grid of wells. Each row represents a single well, | |
| and each 1 in a row represents a single unit of water. | |
| Each well has a corresponding bucket that can be used to extract water from it, | |
| and all buckets have the same capacity. | |
| Your task is to use the buckets to empty the wells. | |
| Output the number of times you need to lower the buckets. | |
| Constraints: | |
| * all wells have the same length | |
| * 1 <= grid.length <= 10^2 | |
| * 1 <= grid[:,1].length <= 10^2 | |
| * grid[i][j] -> 0 | 1 | |
| * 1 <= capacity <= 10 | |
| """"""","def problem_spec | |
| -- function signature | |
| (implementation: List (List Nat) β Nat β Nat) | |
| -- inputs | |
| (grid: List (List Nat)) | |
| (capacity: Nat) := | |
| -- spec | |
| let spec (result : Nat) := | |
| (grid.all (fun row => row.all (fun cell => cell = 0 β¨ cell = 1))) β | |
| (β len : Nat, grid.all (fun row => row.length = len)) β | |
| (result = 0 β grid.length = 0) β§ | |
| (grid.length > 0 β | |
| let well_water_count := grid.head!.sum; | |
| result - (well_water_count / capacity) - (if well_water_count % capacity > 0 then 1 else 0) = implementation grid.tail! capacity) | |
| -- program termination | |
| β result, | |
| implementation grid capacity = result β§ | |
| spec result","def generated_spec | |
| -- function signature | |
| (impl: List (List Nat) β Nat β Nat) | |
| -- inputs | |
| (grid: List (List Nat)) | |
| (capacity: Nat) : Prop :=","theorem spec_isomorphism: | |
| β impl, | |
| (β grid capacity, problem_spec impl grid capacity) β | |
| (β grid capacity, generated_spec impl grid capacity) :=",sorry,def implementation (grid: List (List Nat)) (capacity: Nat) : Nat :=,sorry,"-- #test implementation [[0,0,1,0], [0,1,0,0], [1,1,1,1]] 1 = 6 | |
| -- #test implementation [[0,0,1,1], [0,0,0,0], [1,1,1,1], [0,1,1,1]] 2 = 5 | |
| -- #test implementation [[0,0,0], [0,0,0]] 5 = 0","theorem correctness | |
| (grid: List (List Nat)) | |
| (capacity: Nat) | |
| : problem_spec implementation grid capacity | |
| :=","by | |
| sorry",,, | |
| "def max_fill_count(grid : list[list[int]], capacity : int) -> int","Please write a function that sorts an array of non-negative integers according to | |
| number of ones in their binary representation in ascending order. | |
| For similar number of ones, sort based on decimal value. | |
| ","[{""input"": [1, 5, 2, 3, 4], ""expected_output"": [1, 2, 3, 4, 5]}, {""input"": [1, 0, 2, 3, 4], ""expected_output"": [0, 1, 2, 3, 4]}]","def max_fill_count(grid : list[list[int]], capacity : int) -> int | |
| """"""Please write a function that sorts an array of non-negative integers according to | |
| number of ones in their binary representation in ascending order. | |
| For similar number of ones, sort based on decimal value. | |
| """"""","def problem_spec | |
| -- function signature | |
| (implementation: List Nat β List Nat) | |
| -- inputs | |
| (lst: List Nat) := | |
| -- spec | |
| let spec (result : List Nat) := | |
| β x : Nat, lst.count x = result.count x β§ | |
| result.length = lst.length β§ | |
| (β i j : Nat, i < j β j < result.length β | |
| Nat.digits 2 (result.get! i) < Nat.digits 2 (result.get! j) β¨ | |
| (Nat.digits 2 (result.get! i) = Nat.digits 2 (result.get! j) β§ result.get! i < result.get! j)) | |
| -- program termination | |
| β result, | |
| implementation lst = result β§ | |
| spec result","def generated_spec | |
| -- function signature | |
| (impl: List Nat β List Nat) | |
| -- inputs | |
| (lst: List Nat) : Prop :=","theorem spec_isomorphism: | |
| β impl, | |
| (β lst, problem_spec impl lst) β | |
| (β lst, generated_spec impl lst) :=",sorry,def implementation (lst: List Nat) : List Nat :=,sorry,"-- #test implementation [1, 5, 2, 3, 4] = [1, 2, 3, 4, 5] | |
| -- #test implementation [1, 0, 2, 3, 4] = [0, 1, 2, 3, 4]","theorem correctness | |
| (lst: List Nat) | |
| : problem_spec implementation lst | |
| :=","by | |
| sorry",,, | |
| "def select_words(s : str, n : int) -> list[str]","Given a string s and a natural number n, you have been tasked to implement | |
| a function that returns a list of all words from string s that contain exactly | |
| n consonants, in order these words appear in the string s. | |
| If the string s is empty then the function should return an empty list. | |
| Note: you may assume the input string contains only letters and spaces. | |
| ","[{""input"": ""(\""Mary had a little lamb\"", 4)"", ""expected_output"": [""little""]}, {""input"": ""(\""Mary had a little lamb\"", 3)"", ""expected_output"": [""Mary"", ""lamb""]}, {""input"": ""(\""simple white space\"", 2)"", ""expected_output"": []}, {""input"": ""(\""Hello world\"", 4)"", ""expected_output"": [""world""]}, {""input"": ""(\""Uncle sam\"", 3)"", ""expected_output"": [""Uncle""]}]","def select_words(s : str, n : int) -> list[str] | |
| """"""Given a string s and a natural number n, you have been tasked to implement | |
| a function that returns a list of all words from string s that contain exactly | |
| n consonants, in order these words appear in the string s. | |
| If the string s is empty then the function should return an empty list. | |
| Note: you may assume the input string contains only letters and spaces. | |
| """"""","def problem_spec | |
| -- function signature | |
| (implementation: String β Nat β List String) | |
| -- inputs | |
| (s: String) | |
| (n: Nat) := | |
| -- spec | |
| let spec (result : List String) := | |
| let is_consonant (c: Char) := | |
| c β ['a', 'e', 'i', 'o', 'u'] β§ | |
| c β ['A', 'E', 'I', 'O', 'U'] β§ | |
| c.isAlpha | |
| s.all (fun c => c = ' ' β¨ c.isAlpha) β | |
| let words := s.splitOn "" "" | |
| (result = [] β (s.length = 0 β¨ words.all (fun word => (word.data.filter (fun c => is_consonant c)).length β n))) β§ | |
| (result.length > 0 β | |
| let first_word := result[0]! | |
| first_word β words β§ | |
| (first_word.data.filter (fun c => is_consonant c)).length = n β§ | |
| let first_word_idx := words.indexOf first_word | |
| (β i, i < first_word_idx β | |
| (words[i]!.data.filter (fun c => is_consonant c)).length β n) β§ | |
| result.tail! = | |
| implementation ((words.drop (first_word_idx + 1)).foldl (fun acc word => acc ++ "" "" ++ word) """") n | |
| ) | |
| -- program termination | |
| β result, | |
| implementation s n = result β§ | |
| spec result","def generated_spec | |
| -- function signature | |
| (impl: String β Nat β List String) | |
| -- inputs | |
| (s: String) | |
| (n: Nat) : Prop :=","theorem spec_isomorphism: | |
| β impl, | |
| (β s n, problem_spec impl s n) β | |
| (β s n, generated_spec impl s n) :=",sorry,def implementation (s: String) (n: Nat) : List String :=,sorry,"-- #test implementation ""Mary had a little lamb"" 4 = [""little""] | |
| -- #test implementation ""Mary had a little lamb"" 3 = [""Mary"", ""lamb""] | |
| -- #test implementation ""simple white space"" 2 = [] | |
| -- #test implementation ""Hello world"" 4 = [""world""] | |
| -- #test implementation ""Uncle sam"" 3 = [""Uncle""]","theorem correctness | |
| (s: String) | |
| (n: Nat) | |
| : problem_spec implementation s n | |
| :=","by | |
| sorry",,, | |
| def get_closest_vowel(s : str) -> str,"You are given a word. Your task is to find the closest vowel that stands between | |
| two consonants from the right side of the word (case sensitive). | |
| Vowels in the beginning and ending doesn't count. Return empty string if you didn't | |
| find any vowel met the above condition. | |
| You may assume that the given string contains English letter only. | |
| Note: The ""closest"" is interpreted as the closest to the end of the word, not the closest to the consonants. | |
| ","[{""input"": ""yogurt"", ""expected_output"": ""u""}, {""input"": ""FULL"", ""expected_output"": ""U""}, {""input"": ""quick"", ""expected_output"": ""i""}, {""input"": ""ab"", ""expected_output"": """"}]","def get_closest_vowel(s : str) -> str | |
| """"""You are given a word. Your task is to find the closest vowel that stands between | |
| two consonants from the right side of the word (case sensitive). | |
| Vowels in the beginning and ending doesn't count. Return empty string if you didn't | |
| find any vowel met the above condition. | |
| You may assume that the given string contains English letter only. | |
| Note: The ""closest"" is interpreted as the closest to the end of the word, not the closest to the consonants. | |
| """"""","def problem_spec | |
| -- function signature | |
| (implementation: String β String) | |
| -- inputs | |
| (s: String) := | |
| -- spec | |
| let spec (result : String) := | |
| s.data.all (fun c => c.isAlpha) β | |
| let is_consonant (c: Char) := | |
| c β ['a', 'e', 'i', 'o', 'u'] β§ | |
| c β ['A', 'E', 'I', 'O', 'U'] β§ | |
| c.isAlpha | |
| (result = """" β Β¬ β (i j k : Nat), i < j β§ j < k β§ k < s.length β§ is_consonant s.data[i]! β§ Β¬ is_consonant s.data[j]! β§ is_consonant s.data[k]!) β§ | |
| (result β """" β | |
| result.length = 1 β§ | |
| result.data[0]! β s.data β§ | |
| Β¬ is_consonant result.data[0]! β§ | |
| β (i j k : Nat), | |
| i < j β§ j < k β§ k < s.length β§ | |
| is_consonant s.data[i]! β§ Β¬ is_consonant s.data[j]! β§ is_consonant s.data[k]! β§ | |
| result.data[0]! = s.data[j]! β§ | |
| (β (i' j' k' : Nat), | |
| i' < j' β§ j' < k' β§ k' < s.length β§ is_consonant s.data[i']! β§ Β¬ is_consonant s.data[j']! β§ is_consonant s.data[k']! β | |
| j' β€ j) | |
| ) | |
| -- program termination | |
| β result, | |
| implementation s = result β§ | |
| spec result","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 ""yogurt"" = ""u"" | |
| -- #test implementation ""FULL"" = ""U"" | |
| -- #test implementation ""quick"" = ""i"" | |
| -- #test implementation ""ab"" = """"","theorem correctness | |
| (s: String) | |
| : problem_spec implementation s | |
| :=","by | |
| sorry",,, | |
| def match_parens(l : list[str]) -> str,"You are given a list of two strings, both strings consist of open | |
| parentheses '(' or close parentheses ')' only. | |
| Your job is to check if it is possible to concatenate the two strings in | |
| some order, that the resulting string will be good. | |
| A string S is considered to be good if and only if all parentheses in S | |
| are balanced. For example: the string '(())()' is good, while the string | |
| '())' is not. | |
| Return 'Yes' if there's a way to make a good string, and return 'No' otherwise. | |
| ","[{""input"": [""()("", "")""], ""expected_output"": ""Yes""}, {""input"": ["")"", "")""], ""expected_output"": ""No""}]","def match_parens(l : list[str]) -> str | |
| """"""You are given a list of two strings, both strings consist of open | |
| parentheses '(' or close parentheses ')' only. | |
| Your job is to check if it is possible to concatenate the two strings in | |
| some order, that the resulting string will be good. | |
| A string S is considered to be good if and only if all parentheses in S | |
| are balanced. For example: the string '(())()' is good, while the string | |
| '())' is not. | |
| Return 'Yes' if there's a way to make a good string, and return 'No' otherwise. | |
| """"""","def problem_spec | |
| -- function signature | |
| (implementation: List String β String) | |
| -- inputs | |
| (l: List String) := | |
| -- spec | |
| let spec (result : String) := | |
| l.length = 2 β | |
| l[0]!.all (fun c => c = '(' β¨ c = ')') β | |
| l[1]!.all (fun c => c = '(' β¨ c = ')') β | |
| let res := (balanced_paren_non_computable (l[0]! ++ l[1]!) '(' ')' β¨ | |
| balanced_paren_non_computable (l[1]! ++ l[0]!) '(' ')') | |
| (res β result = ""Yes"") β§ | |
| (Β¬ res β result = ""No"") | |
| -- program termination | |
| β result, | |
| implementation l = result β§ | |
| spec result","def generated_spec | |
| -- function signature | |
| (impl: List String β String) | |
| -- inputs | |
| (l: List String) : Prop :=","theorem spec_isomorphism: | |
| β impl, | |
| (β l, problem_spec impl l) β | |
| (β l, generated_spec impl l) :=",sorry,def implementation (l: List String) : String :=,sorry,"-- #test implementation ['()(', ')'] = ""Yes"" | |
| -- #test implementation [')', ')'] = ""No""","theorem correctness | |
| (l: List String) | |
| : problem_spec implementation l | |
| :=","by | |
| sorry",,, | |
| "def maximum(arr: List[int], k: int) -> List[int]","Given an array arr of integers and a positive integer k, return a sorted list of length | |
| k with the maximum k numbers in arr. | |
| Note: | |
| 1. The length of the array will be in the range of [1, 1000]. | |
| 2. The elements in the array will be in the range of [-1000, 1000]. | |
| 3. 0 <= k <= len(arr) | |
| ","[{""input"": [[2, 4, 3, 1], 3], ""expected_output"": [2, 3, 4]}, {""input"": [[2, 4, 3, 1], 0], ""expected_output"": []}]","def maximum(arr: List[int], k: int) -> List[int] | |
| """"""Given an array arr of integers and a positive integer k, return a sorted list of length | |
| k with the maximum k numbers in arr. | |
| Note: | |
| 1. The length of the array will be in the range of [1, 1000]. | |
| 2. The elements in the array will be in the range of [-1000, 1000]. | |
| 3. 0 <= k <= len(arr) | |
| """"""","def problem_spec | |
| -- function signature | |
| (impl: List Int β Int β List Int) | |
| -- inputs | |
| (arr: List Int) | |
| (k: Int) := | |
| -- spec | |
| let spec (result: List Int) := | |
| 1 β€ arr.length β arr.length β€ 1000 β arr.all (fun x => -1000 β€ x β§ x β€ 1000) β 0 β€ k β k β€ arr.length β | |
| result.length = k β§ | |
| result.Sorted (Β· β€ Β·) β§ | |
| β x β result, x β arr β§ | |
| let result_reversed := result.reverse; -- reverse to get last element | |
| match result_reversed with | |
| | [] => k = 0 | |
| | max :: remaining_reversed => | |
| arr.max? = some max β§ | |
| impl (arr.erase max) (k-1) = (remaining_reversed.reverse) | |
| -- program terminates | |
| β result, impl arr k = result β§ | |
| -- return value satisfies spec | |
| spec result","def generated_spec | |
| -- function signature | |
| (impl: List Int β Int β List Int) | |
| -- inputs | |
| (arr: List Int) | |
| (k: Int) : Prop :=","theorem spec_isomorphism: | |
| β impl, | |
| (β arr k, problem_spec impl arr k) β | |
| (β arr k, generated_spec impl arr k) :=",sorry,def implementation (arr: List Int) (k: Int) : List Int :=,sorry,"-- #test implementation [2, 4, 3, 1] 3 = [2, 3, 4] | |
| -- #test implementation [2, 4, 3, 1] 0 = []","theorem correctness | |
| (arr: List Int) | |
| (k: Int) | |
| : problem_spec implementation arr k :=",sorry,,, | |
| def solution(lst: List[int]) -> int,"Given a non-empty list of integers, return the sum of all of the odd elements that | |
| are in even positions. | |
| ","[{""input"": [5, 8, 7, 1], ""expected_output"": 12}, {""input"": [3, 3, 3, 3, 3], ""expected_output"": 9}, {""input"": [30, 13, 24, 321], ""expected_output"": 0}]","def solution(lst: List[int]) -> int | |
| """"""Given a non-empty list of integers, return the sum of all of the odd elements that | |
| are in even positions. | |
| """"""","def problem_spec | |
| -- function signature | |
| (impl: List Int β Int) | |
| -- inputs | |
| (lst: List Int) := | |
| -- spec | |
| let spec (result : Int) := | |
| lst β [] β β i, i < lst.length β§ i % 2 = 0 β | |
| (lst.length = 1 β impl lst = 0) β§ | |
| (i + 1 < lst.length β | |
| (lst[i + 1]! % 2 = 1 β | |
| impl (lst.drop i) = lst[i + 1]! + (if i + 2 < lst.length then impl (lst.drop (i+2)) else 0)) β§ | |
| (lst[i + 1]! % 2 = 0 β | |
| impl (lst.drop i) = if i + 2 < lst.length then impl (lst.drop (i+2)) else 0) | |
| ) | |
| -- program terminates | |
| β result, impl lst = result β§ | |
| -- return value satisfies spec | |
| spec result","def generated_spec | |
| -- function signature | |
| (impl: List Int β 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) : Int :=,sorry,"-- #test implementation ([5, 8, 7, 1]: List Int) = 12 | |
| -- #test implementation ([3, 3, 3, 3, 3]: List Int) = 9 | |
| -- #test implementation ([30, 13, 24, 321]: List Int) = 0","theorem correctness | |
| (lst: List Int) | |
| : problem_spec implementation lst :=",sorry,,, | |
| "def add_elements(arr: List[int], k: int) -> int","Given a non-empty array of integers arr and an integer k, return | |
| the sum of the elements with at most two digits from the first k elements of arr. | |
| Constraints: | |
| 1. 1 <= len(arr) <= 100 | |
| 2. 1 <= k <= len(arr) | |
| ","[{""input"": [[111, 21, 3, 4000, 5, 6, 7, 8, 9], 4], ""expected_output"": 24}]","def add_elements(arr: List[int], k: int) -> int | |
| """"""Given a non-empty array of integers arr and an integer k, return | |
| the sum of the elements with at most two digits from the first k elements of arr. | |
| Constraints: | |
| 1. 1 <= len(arr) <= 100 | |
| 2. 1 <= k <= len(arr) | |
| """"""","def problem_spec | |
| -- function signature | |
| (impl: List Int β Nat β Int) | |
| -- inputs | |
| (arr: List Int) | |
| (k: Nat) := | |
| -- spec | |
| let spec (result: Int) := | |
| 1 β€ arr.length β arr.length β€ 100 β 1 β€ k β k β€ arr.length β | |
| ((β i, 0 β€ i β§ i < k β Β¬(arr[i]! β€ 99 β§ -99 β€ arr[i]!)) β result = 0) β§ | |
| β i, i < k | |
| β§ arr[i]! β€ 99 β§ -99 β€ arr[i]! | |
| β§ result = arr[i]! + (if i = 0 then 0 else impl arr i) | |
| β§ β i', i < i' β§ i' < k β Β¬(arr[i']! β€ 99 β§ -99 β€ arr[i']!) | |
| -- program termination | |
| β result, impl arr k = result β§ | |
| -- return value satisfies spec | |
| spec result","def generated_spec | |
| -- function signature | |
| (impl: List Int β Nat β Int) | |
| -- inputs | |
| (arr: List Int) | |
| (k: Nat) : Prop :=","theorem spec_isomorphism: | |
| β impl, | |
| (β arr k, problem_spec impl arr k) β | |
| (β arr k, generated_spec impl arr k) :=",sorry,def implementation (arr: List Int) (k: Nat) : Int :=,sorry,"-- #test implementation ([111, 21, 3, 4000, 5, 6, 7, 8, 9]: List Int) 4 = 24","theorem correctness | |
| (arr: List Int) | |
| (k: Nat) | |
| : problem_spec implementation arr k :=",sorry,,, | |
| def get_odd_collatz (n: int) -> List[int],"Given a positive integer n, return a sorted list that has the odd numbers in collatz sequence. | |
| The Collatz conjecture is a conjecture in mathematics that concerns a sequence defined | |
| as follows: start with any positive integer n. Then each term is obtained from the | |
| previous term as follows: if the previous term is even, the next term is one half of | |
| the previous term. If the previous term is odd, the next term is 3 times the previous | |
| term plus 1. The conjecture is that no matter what value of n, the sequence will always reach 1. | |
| Note: | |
| 1. Collatz(1) is [1]. | |
| 2. returned list sorted in increasing order. | |
| ","[{""input"": 5, ""expected_output"": [1, 5]}]","def get_odd_collatz (n: int) -> List[int] | |
| """"""Given a positive integer n, return a sorted list that has the odd numbers in collatz sequence. | |
| The Collatz conjecture is a conjecture in mathematics that concerns a sequence defined | |
| as follows: start with any positive integer n. Then each term is obtained from the | |
| previous term as follows: if the previous term is even, the next term is one half of | |
| the previous term. If the previous term is odd, the next term is 3 times the previous | |
| term plus 1. The conjecture is that no matter what value of n, the sequence will always reach 1. | |
| Note: | |
| 1. Collatz(1) is [1]. | |
| 2. returned list sorted in increasing order. | |
| """"""","def problem_spec | |
| -- function signature | |
| (impl: Nat β List Nat) | |
| -- inputs | |
| (n: Nat) := | |
| -- spec | |
| let spec (result: List Nat) := | |
| n > 0 β | |
| result.Sorted (Β· < Β·) β§ | |
| β m, m β result β Odd m β§ collatz_reachable n m -- m is reachable from starting point n | |
| -- program termination | |
| β result, impl n = result β§ | |
| -- return value satisfies spec | |
| spec result","def generated_spec | |
| -- function signature | |
| (impl: Nat β List Nat) | |
| -- inputs | |
| (n: Nat) : Prop :=","theorem spec_isomorphism: | |
| β impl, | |
| (β n, problem_spec impl n) β | |
| (β n, generated_spec impl n) :=",sorry,def implementation (n: Nat) : List Nat :=,sorry,"-- #test implementation 5 = [1, 5]","theorem correctness | |
| (n: Nat) | |
| : problem_spec implementation n :=",sorry,"/-- | |
| name: collatz_reachable | |
| use: | | |
| Helper to check if a natural number m is reachable in the Collatz sequence starting at n. | |
| problems: | |
| - 123 | |
| -/ | |
| def collatz_reachable (n m : Nat) : Prop := | |
| β k, Nat.iterate (fun x => if x % 2 = 0 then x / 2 else x * 3 + 1) k n = m",, | |
| def valid_date(date: str) -> Bool,"You have to write a function which validates a given date string and | |
| returns True if the date is valid otherwise False. | |
| The date is valid if all of the following rules are satisfied: | |
| 1. The date string is not empty. | |
| 2. The number of days is not less than 1 or higher than 31 days for months 1,3,5,7,8,10,12. And the number of days is not less than 1 or higher than 30 days for months 4,6,9,11. And, the number of days is not less than 1 or higher than 29 for the month 2. | |
| 3. The months should not be less than 1 or higher than 12. | |
| 4. The date should be in the format: mm-dd-yyyy | |
| ","[{""input"": ""03-11-2000"", ""expected_output"": true}, {""input"": ""15-01-2012"", ""expected_output"": false}, {""input"": ""04-0-2040"", ""expected_output"": false}, {""input"": ""06-04-2020"", ""expected_output"": true}, {""input"": ""06/04/2020"", ""expected_output"": false}]","def valid_date(date: str) -> Bool | |
| """"""You have to write a function which validates a given date string and | |
| returns True if the date is valid otherwise False. | |
| The date is valid if all of the following rules are satisfied: | |
| 1. The date string is not empty. | |
| 2. The number of days is not less than 1 or higher than 31 days for months 1,3,5,7,8,10,12. And the number of days is not less than 1 or higher than 30 days for months 4,6,9,11. And, the number of days is not less than 1 or higher than 29 for the month 2. | |
| 3. The months should not be less than 1 or higher than 12. | |
| 4. The date should be in the format: mm-dd-yyyy | |
| """"""","def problem_spec | |
| -- function signature | |
| (impl: String β Bool) | |
| -- inputs | |
| (date: String) := | |
| -- spec | |
| let spec (result: Bool) := | |
| result = true β | |
| β m1 m2 sep1 d1 d2 sep2 y1 y2 y3 y4 : Char, | |
| date = String.mk [m1, m2, sep1, d1, d2, sep2, y1, y2, y3, y4] β§ | |
| sep1 = '-' β§ sep2 = '-' β§ | |
| [m1, m2, d1, d2, y1, y2, y3, y4].all Char.isDigit β§ | |
| let month := (String.mk [m1, m2]).toNat!; | |
| let day := (String.mk [d1, d2]).toNat!; | |
| 1 β€ month β§ month β€ 12 β§ | |
| (month β ({4, 6, 9, 11}: List Nat) β 1 β€ day β§ day β€ 30) β§ | |
| (month β ({1, 3, 5, 7, 8, 10, 12}: List Nat) β 1 β€ day β§ day β€ 31) β§ | |
| (month β ({2}: List Nat) β 1 β€ day β§ day β€ 29) | |
| -- program terminates | |
| β result, impl date = result β§ | |
| -- return value satisfies spec | |
| spec result","def generated_spec | |
| -- function signature | |
| (impl: String β Bool) | |
| -- inputs | |
| (date: String) : Prop :=","theorem spec_isomorphism: | |
| β impl, | |
| (β date, problem_spec impl date) β | |
| (β date, generated_spec impl date) :=",sorry,def implementation (date: String) : Bool :=,sorry,"-- #test implementation ""03-11-2000"" = true | |
| -- #test implementation ""15-01-2012"" = false | |
| -- #test implementation ""04-0-2040"" = false | |
| -- #test implementation ""06-04-2020"" = true | |
| -- #test implementation ""06/04/2020"" = false","theorem correctness | |
| (date: String) | |
| : problem_spec implementation date :=",sorry,,, | |
| "def minPath(grid, k)","Given a grid with N rows and N columns (N >= 2) and a positive integer k, | |
| each cell of the grid contains a value. Every integer in the range [1, N * N] | |
| inclusive appears exactly once on the cells of the grid. | |
| You have to find the minimum path of length k in the grid. You can start | |
| from any cell, and in each step you can move to any of the neighbor cells, | |
| in other words, you can go to cells which share an edge with you current | |
| cell. | |
| Please note that a path of length k means visiting exactly k cells (not | |
| necessarily distinct). | |
| You CANNOT go off the grid. | |
| A path A (of length k) is considered less than a path B (of length k) if | |
| after making the ordered lists of the values on the cells that A and B go | |
| through (let's call them lst_A and lst_B), lst_A is lexicographically less | |
| than lst_B, in other words, there exist an integer index i (1 <= i <= k) | |
| such that lst_A[i] < lst_B[i] and for any j (1 <= j < i) we have | |
| lst_A[j] = lst_B[j]. | |
| It is guaranteed that the answer is unique. | |
| Return an ordered list of the values on the cells that the minimum path go through. | |
| ","[{""input"": [[[1, 2, 3], [4, 5, 6], [7, 8, 9]], 3], ""expected_output"": [1, 2, 3]}, {""input"": [[5, 9, 3], [4, 1, 6], [7, 8, 2], 1], ""expected_output"": [1]}]","def minPath(grid, k) | |
| """"""Given a grid with N rows and N columns (N >= 2) and a positive integer k, | |
| each cell of the grid contains a value. Every integer in the range [1, N * N] | |
| inclusive appears exactly once on the cells of the grid. | |
| You have to find the minimum path of length k in the grid. You can start | |
| from any cell, and in each step you can move to any of the neighbor cells, | |
| in other words, you can go to cells which share an edge with you current | |
| cell. | |
| Please note that a path of length k means visiting exactly k cells (not | |
| necessarily distinct). | |
| You CANNOT go off the grid. | |
| A path A (of length k) is considered less than a path B (of length k) if | |
| after making the ordered lists of the values on the cells that A and B go | |
| through (let's call them lst_A and lst_B), lst_A is lexicographically less | |
| than lst_B, in other words, there exist an integer index i (1 <= i <= k) | |
| such that lst_A[i] < lst_B[i] and for any j (1 <= j < i) we have | |
| lst_A[j] = lst_B[j]. | |
| It is guaranteed that the answer is unique. | |
| Return an ordered list of the values on the cells that the minimum path go through. | |
| """"""","def problem_spec | |
| -- function signature | |
| (impl: List (List Nat) β Nat β List Nat) | |
| -- inputs | |
| (grid: List (List Nat)) | |
| (k: Nat) := | |
| -- spec | |
| let lexographically_less (a b: List Nat) : Prop := | |
| a.length = b.length β§ a.length = k β§ | |
| (β i, i < k β§ a.get! i < b.get! i β§ | |
| (β j, j < i β a.get! j = b.get! j)); | |
| let rec is_valid_path (k': Nat) (path: List Nat) (grid: List (List Nat)) : Prop := | |
| let n := grid.length; | |
| path.length = k' β | |
| (β i j, | |
| (i < n β§ j < n β§ path.get! 0 = (grid.get! i).get! j) β§ | |
| (1 < path.length β | |
| ( β i' j', i' < n β§ j' < n β§ | |
| (path.get! 1 = (grid.get! i').get! j') β§ | |
| ((abs ((i: Int) - (i': Int)) = 1 β§ j = j') β¨ | |
| (abs ((j: Int) - (j': Int)) = 1 β§ i = i'))) β§ | |
| (is_valid_path (k' - 1) (path.drop 1) grid)) | |
| ); | |
| let spec (result: List Nat) := | |
| let n := grid.length; | |
| (β i, i < n β (grid.get! i).length = n) β | |
| (β i j, i < n β j < n β ((grid.get! i).get! j) β [1, n^2]) β | |
| is_valid_path k result grid β§ (β path, is_valid_path k path grid β lexographically_less result path); | |
| -- program terminates | |
| β result, impl grid k = result β§ | |
| -- return value satisfies spec | |
| spec result","def generated_spec | |
| -- function signature | |
| (impl: List (List Nat) β Nat β List Nat) | |
| -- inputs | |
| (grid: List (List Nat)) | |
| (k: Nat): Prop :=","theorem spec_isomorphism: | |
| β impl, | |
| (β grid k, problem_spec impl grid k) β | |
| (β grid k, generated_spec impl grid k) :=",sorry,def implementation (grid: List (List Nat)) (k: Nat) : List Nat :=,sorry,"-- #test implementation [[1,2,3], [4,5,6], [7,8,9]] 3 = [1,2,3] | |
| -- #test implementation [[5,9,3], [4,1,6], [7,8,2]] 1 = [1]","theorem correctness | |
| (grid: List (List Nat)) | |
| (k: Nat) | |
| : problem_spec implementation grid k :=",sorry,,, | |
| def is_sorted(lst: List[int]) -> Bool,"Given a list of numbers, return whether or not they are sorted | |
| in ascending order. If list has more than 1 duplicate of the same | |
| number, return False. Assume no negative numbers and only integers. | |
| ","[{""input"": [5], ""expected_output"": true}, {""input"": [1, 2, 3, 4, 5], ""expected_output"": true}, {""input"": [1, 3, 2, 4, 5], ""expected_output"": false}, {""input"": [1, 2, 3, 4, 5, 6], ""expected_outupt"": true}, {""input"": [1, 2, 3, 4, 5, 6, 7], ""expected_output"": true}, {""input"": [1, 3, 2, 4, 5, 6, 7], ""expected_output"": false}, {""input"": [1, 2, 2, 3, 3, 4], ""expected_output"": true}, {""input"": [1, 2, 2, 2, 3, 4], ""expected_output"": false}]","def is_sorted(lst: List[int]) -> Bool | |
| """"""Given a list of numbers, return whether or not they are sorted | |
| in ascending order. If list has more than 1 duplicate of the same | |
| number, return False. Assume no negative numbers and only integers. | |
| """"""","def problem_spec | |
| -- function signature | |
| (impl: List Int β Bool) | |
| -- inputs | |
| (lst: List Int) := | |
| -- spec | |
| let sorted_ascending := lst.Sorted (Β· β€ Β·); | |
| let ms := Multiset.ofList lst; | |
| let multiple_duplicates := β i, i β lst β§ 2 < ms.count i; | |
| let spec (res: Bool) := | |
| res β sorted_ascending β§ | |
| res β Β¬multiple_duplicates β§ | |
| multiple_duplicates β Β¬res β§ | |
| Β¬sorted_ascending β Β¬res; | |
| -- program terminates | |
| β result, impl lst = result β§ | |
| -- return value satisfies spec | |
| spec result","def generated_spec | |
| -- function signature | |
| (impl: List Int β Bool) | |
| -- 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) : Bool :=,sorry,"-- #test implementation [5] = true | |
| -- #test implementation [1, 2, 3, 4, 5] = true | |
| -- #test implementation [1, 3, 2, 4, 5] = false | |
| -- #test implementation [1, 2, 3, 4, 5, 6] = true | |
| -- #test implementation [1, 2, 3, 4, 5, 6, 7] = true | |
| -- #test implementation [1, 3, 2, 4, 5, 6, 7] = false | |
| -- #test implementation [1, 2, 2, 3, 3, 4] = true | |
| -- #test implementation [1, 2, 2, 2, 3, 4] = false","theorem correctness | |
| (lst: List Int) | |
| : problem_spec implementation lst :=",sorry,,, | |
| "def intersection(interval1: Tuple[Int, Int], interval2: Tuple[Int, Int]) -> str","You are given two intervals, | |
| where each interval is a pair of integers. For example, interval = (start, end) = (1, 2). | |
| The given intervals are closed which means that the interval (start, end) | |
| includes both start and end. | |
| For each given interval, it is assumed that its start is less or equal its end. | |
| Your task is to determine whether the length of intersection of these two | |
| intervals is a prime number. | |
| Example, the intersection of the intervals (1, 3), (2, 4) is (2, 3) | |
| which its length is 1, which not a prime number. | |
| If the length of the intersection is a prime number, return ""YES"", | |
| otherwise, return ""NO"". | |
| If the two intervals don't intersect, return ""NO"". | |
| ","[{""input"": [""(1"", ""2)"", ""(2"", ""3)""], ""expected_output"": ""NO""}, {""input"": [""(-1"", ""1)"", ""(0"", ""4)""], ""expected_output"": ""NO""}, {""input"": [""(-3"", ""-1)"", ""(-5"", ""5)""], ""expected_output"": ""YES""}]","def intersection(interval1: Tuple[Int, Int], interval2: Tuple[Int, Int]) -> str | |
| """"""You are given two intervals, | |
| where each interval is a pair of integers. For example, interval = (start, end) = (1, 2). | |
| The given intervals are closed which means that the interval (start, end) | |
| includes both start and end. | |
| For each given interval, it is assumed that its start is less or equal its end. | |
| Your task is to determine whether the length of intersection of these two | |
| intervals is a prime number. | |
| Example, the intersection of the intervals (1, 3), (2, 4) is (2, 3) | |
| which its length is 1, which not a prime number. | |
| If the length of the intersection is a prime number, return ""YES"", | |
| otherwise, return ""NO"". | |
| If the two intervals don't intersect, return ""NO"". | |
| """"""","def problem_spec | |
| -- function signature | |
| (impl: Int Γ Int β Int Γ Int β String) | |
| -- inputs | |
| (interval1: Int Γ Int) | |
| (interval2: Int Γ Int) := | |
| -- spec | |
| let spec (result: String) := | |
| let (s1, e1) := interval1; | |
| let (s2, e2) := interval2; | |
| s1 β€ e1 β s2 β€ e2 β | |
| let intersectionStart := max s1 s2; | |
| let intersectionEnd := min e1 e2; | |
| let hasIntersection := intersectionStart β€ intersectionEnd; | |
| let isPrime := Nat.Prime (intersectionEnd - intersectionStart).toNat; | |
| (result = ""YES"" β hasIntersection β§ isPrime) β§ | |
| (result = ""NO"" β Β¬hasIntersection β¨ Β¬isPrime) β§ | |
| (result = ""YES"" β¨ result = ""NO"") | |
| -- program terminates | |
| β result, impl interval1 interval2 = result β§ | |
| -- return value satisfies spec | |
| spec result","def generated_spec | |
| -- function signature | |
| (impl: Int Γ Int β Int Γ Int β String) | |
| -- inputs | |
| (interval1: Int Γ Int) | |
| (interval2: Int Γ Int) : Prop :=","theorem spec_isomorphism: | |
| β impl, | |
| (β interval1 interval2, problem_spec impl interval1 interval2) β | |
| (β interval1 interval2, generated_spec impl interval1 interval2) :=",sorry,def implementation (interval1: Int Γ Int) (interval2: Int Γ Int) : String :=,sorry,"-- #test implementation (1, 2) (2, 3) = ""NO"" | |
| -- #test implementation (-1, 1) (0, 4) = ""NO"" | |
| -- #test implementation (-3, -1) (-5, 5) = ""YES""","theorem correctness | |
| (interval1: Int Γ Int) | |
| (interval2: Int Γ Int) | |
| : problem_spec implementation interval1 interval2 :=",sorry,,, | |
| def prod_signs(arr: List[int]) -> Optional[int],"You are given an array arr of integers and you need to return | |
| sum of magnitudes of integers multiplied by product of all signs | |
| of each number in the array, represented by 1, -1 or 0. | |
| Note: return None for empty arr. | |
| ","[{""input"": [1, 2, 2, -4], ""expected_output"": -9}, {""input"": [0, 1], ""expected_output"": 0}, {""input"": [], ""expected_output"": ""None""}]","def prod_signs(arr: List[int]) -> Optional[int] | |
| """"""You are given an array arr of integers and you need to return | |
| sum of magnitudes of integers multiplied by product of all signs | |
| of each number in the array, represented by 1, -1 or 0. | |
| Note: return None for empty arr. | |
| """"""","def problem_spec | |
| -- function signature | |
| (impl: List Int β Option Int) | |
| -- inputs | |
| (arr: List Int) := | |
| -- spec | |
| let spec (result: Option Int) := | |
| match result with | |
| | none => arr = [] | |
| | some result => | |
| let magnitude_sum := (arr.map (fun x => Int.ofNat x.natAbs)).sum; | |
| let neg_count_odd := (arr.filter (fun x => x < 0)).length % 2 = 1; | |
| let has_zero := 0 β arr; | |
| (result < 0 β (neg_count_odd β§ Β¬has_zero) | |
| β§ result = magnitude_sum * -1) β§ | |
| (0 < result β (Β¬neg_count_odd β§ Β¬has_zero) | |
| β§ result = magnitude_sum) β§ | |
| (result = 0 β has_zero) | |
| -- program terminates | |
| β result, impl arr = result β§ | |
| -- return value satisfies spec | |
| spec result","def generated_spec | |
| -- function signature | |
| (impl: List Int β Option 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) : Option Int :=,sorry,"-- #test implementation ([1, 2, 2, -4]: List Int) = (-9: Int) | |
| -- #test implementation ([0, 1]: List Int) = (0: Int) | |
| -- #test implementation ([]: List Int) = none","theorem correctness | |
| (arr: List Int) | |
| : problem_spec implementation arr :=",sorry,,, | |
| def split_words(txt),"Given a string of words, return a list of words split on whitespace, if no whitespaces exists in the text you | |
| should split on commas ',' if no commas exists you should return the number of lower-case letters with odd order in the | |
| alphabet, ord('a') = 0, ord('b') = 1, ... ord('z') = 25 | |
| ","[{""input"": ""Hello world!"", ""expected_output"": [""Hello"", ""world!""]}, {""input"": ""Hello,world!"", ""expected_output"": [""Hello"", ""world!""]}, {""input"": ""abcdef"", ""expected_output"": 3}]","def split_words(txt) | |
| """"""Given a string of words, return a list of words split on whitespace, if no whitespaces exists in the text you | |
| should split on commas ',' if no commas exists you should return the number of lower-case letters with odd order in the | |
| alphabet, ord('a') = 0, ord('b') = 1, ... ord('z') = 25 | |
| """"""","def problem_spec | |
| -- function signature | |
| -- return a tuple of Option (List String) and Option Nat | |
| (impl: String β Option (List String) Γ Option Nat) | |
| -- inputs | |
| (text: String) := | |
| -- spec | |
| let spec (result: Option (List String) Γ Option Nat) := | |
| -- both cannot be None | |
| let words := result.fst; | |
| let ord := result.snd; | |
| 0 < text.length β | |
| Β¬ (words = none β§ ord = none) β§ | |
| (words = none β β ch, ch β text.toList β (ch = ',' β¨ ch = ' ')) β§ | |
| (β num, ord = some num β (text.get! 0).toNat = num) β§ | |
| (β lst, words = some lst β β i, i < lst.length β | |
| let str := lst.get! i; | |
| text.containsSubstr str) β§ | |
| (β lst, words = some lst β | |
| let first := text.takeWhile (fun c => c β ',' β§ c β ' '); | |
| let nextImpl := impl (text.drop (first.length + 1)); | |
| let nextWords := nextImpl.fst; | |
| (β nextLst, nextWords = some nextLst β§ | |
| lst = [first] ++ nextLst)) | |
| -- program terminates | |
| β result, impl text = result β§ | |
| -- return value satisfies spec | |
| spec result","def generated_spec | |
| -- function signature | |
| (impl: String β Option (List String) Γ Option Nat) | |
| -- inputs | |
| (text: String) : Prop :=","theorem spec_isomorphism: | |
| β impl, | |
| (β text, problem_spec impl text) β | |
| (β text, generated_spec impl text) :=",sorry,def implementation (text: String) : Option (List String) Γ Option Nat :=,sorry,"-- #test implementation ""Hello world!"" = (some [""Hello"", ""world!""], none) | |
| -- #test implementation ""Hello,world!"" = (some [""Hello"", ""world!""], none) | |
| -- #test implementation ""abcdef"" = (none, some 3)","theorem correctness | |
| (text: String) | |
| : problem_spec implementation text :=",sorry,,, | |
| def tri(n: int) -> List[int],"Everyone knows Fibonacci sequence, it was studied deeply by mathematicians in | |
| the last couple centuries. However, what people don't know is Tribonacci sequence. | |
| Tribonacci sequence is defined by the recurrence: | |
| tri(1) = 3 | |
| tri(n) = 1 + n / 2, if n is even. | |
| tri(n) = tri(n - 1) + tri(n - 2) + tri(n + 1), if n is odd. | |
| For example: | |
| tri(2) = 1 + (2 / 2) = 2 | |
| tri(4) = 3 | |
| tri(3) = tri(2) + tri(1) + tri(4) | |
| = 2 + 3 + 3 = 8 | |
| You are given a non-negative integer number n, you have to a return a list of the | |
| first n + 1 numbers of the Tribonacci sequence. | |
| ","[{""input"": 3, ""expected_output"": [1, 3, 2, 8]}]","def tri(n: int) -> List[int] | |
| """"""Everyone knows Fibonacci sequence, it was studied deeply by mathematicians in | |
| the last couple centuries. However, what people don't know is Tribonacci sequence. | |
| Tribonacci sequence is defined by the recurrence: | |
| tri(1) = 3 | |
| tri(n) = 1 + n / 2, if n is even. | |
| tri(n) = tri(n - 1) + tri(n - 2) + tri(n + 1), if n is odd. | |
| For example: | |
| tri(2) = 1 + (2 / 2) = 2 | |
| tri(4) = 3 | |
| tri(3) = tri(2) + tri(1) + tri(4) | |
| = 2 + 3 + 3 = 8 | |
| You are given a non-negative integer number n, you have to a return a list of the | |
| first n + 1 numbers of the Tribonacci sequence. | |
| """"""","def problem_spec | |
| -- function signature | |
| (impl: Nat β List Int) | |
| -- inputs | |
| (n: Nat) := | |
| -- spec | |
| let spec (result: List Int) := | |
| 0 < result.length β§ | |
| result.length = n β§ | |
| let i := result.length-1; | |
| (i = 0 β result[0]! = 1) β§ -- base case | |
| (i = 1 β result[1]! = 3) β§ | |
| (2 β€ i β§ i % 2 = 0 β result[i]! = 1 + i / 2) β§ | |
| (2 β€ i β§ i % 2 = 1 β result[i]! = result[i-2]! + result[i-1]! + (1 + (i+1) / 2)) β§ | |
| if i = 0 then true else result.take i = impl (i-1) | |
| -- program termination | |
| β result, impl n = result β§ | |
| -- return value satisfies spec | |
| spec result","def generated_spec | |
| -- function signature | |
| (impl: Nat β List Int) | |
| -- inputs | |
| (n: Nat) : Prop :=","theorem spec_isomorphism: | |
| β impl, | |
| (β n, problem_spec impl n) β | |
| (β n, generated_spec impl n) :=",sorry,def implementation (n: Nat) : List Int:=,sorry,"-- #test implementation 3 = [1, 3, 2, 8]","theorem correctness | |
| (n: Nat) | |
| : problem_spec implementation n :=",sorry,,, | |
| def digits(n: int) -> int,"Given a positive integer n, return the product of the odd digits. | |
| Return 0 if all digits are even. | |
| ","[{""input"": 1, ""expected_output"": 1}, {""input"": 4, ""expected_output"": 0}, {""input"": 235, ""expected_output"": 15}]","def digits(n: int) -> int | |
| """"""Given a positive integer n, return the product of the odd digits. | |
| Return 0 if all digits are even. | |
| """"""","def problem_spec | |
| -- function signature | |
| (impl: Nat β Nat) | |
| -- inputs | |
| (n: Nat) := | |
| -- spec | |
| let spec (result: Nat) := | |
| 0 < n β | |
| (n < 10 β (n % 2 = 1 β result = n) β§ (n % 2 = 0 β result = 0)) β§ | |
| (10 β€ n β | |
| let digit := n % 10; | |
| let rest := n / 10; | |
| (digit % 2 = 1 β | |
| if (Nat.toDigits 10 rest).all (fun x => Even (x.toNat - '0'.toNat)) | |
| then impl rest = 0 β§ result = digit | |
| else | |
| result = impl rest * digit) | |
| β§ | |
| (digit % 2 = 0 β | |
| result = impl rest)) | |
| -- program termination | |
| β result, impl n = result β§ | |
| -- return value satisfies spec | |
| 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 1 = 1 | |
| -- #test implementation 4 = 0 | |
| -- #test implementation 235 = 15","theorem correctness | |
| (n: Nat) | |
| : problem_spec implementation n :=",sorry,,, | |
| def is_nested(string: str) -> Bool,"Create a function that takes a string as input which contains only parentheses. | |
| The function should return True if and only if there is a valid subsequence of parentheses | |
| where at least one parenthesis in the subsequence is nested. | |
| ","[{""input"": ""(())"", ""expected_output"": true}, {""input"": ""()))))))((((()"", ""expected_output"": false}, {""input"": ""()()"", ""expected_output"": false}, {""input"": ""()"", ""expected_output"": false}, {""input"": ""(()())"", ""expected_output"": true}, {""input"": ""(())(("", ""expected_output"": true}]","def is_nested(string: str) -> Bool | |
| """"""Create a function that takes a string as input which contains only parentheses. | |
| The function should return True if and only if there is a valid subsequence of parentheses | |
| where at least one parenthesis in the subsequence is nested. | |
| """"""","def problem_spec | |
| -- function signature | |
| (impl: String β Bool) | |
| -- inputs | |
| (string: String) := | |
| -- spec | |
| let spec (result: Bool) := | |
| string.toList.all (fun x => x = '(' β¨ x = ')') β | |
| result = true β | |
| β x : String, | |
| is_subsequence x.toList string.toList β§ | |
| balanced_paren_non_computable x '(' ')' β§ | |
| 2 β€ count_max_paren_depth x | |
| -- program termination | |
| β result, impl string = result β§ | |
| -- return value satisfies spec | |
| spec result","def generated_spec | |
| -- function signature | |
| (impl: String β Bool) | |
| -- inputs | |
| (lst: String) : Prop :=","theorem spec_isomorphism: | |
| β impl, | |
| (β string, problem_spec impl string) β | |
| (β string, generated_spec impl string) :=",sorry,def implementation (lst: String) : Bool :=,sorry,"-- #test implementation ""(())"" = true | |
| -- #test implementation ""()))))))((((()"" = false | |
| -- #test implementation ""()()"" = false | |
| -- #test implementation ""()"" = false | |
| -- #test implementation ""(()())"" = true | |
| -- #test implementation ""(())(("" = true","theorem correctness | |
| (string: String) | |
| : problem_spec implementation string :=",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 paren_string.isEmpty then | |
| num_open = 0 | |
| else | |
| let c := paren_string.get! 0 | |
| if c == '(' then | |
| string_is_paren_balanced_helper (paren_string.drop 1) (num_open + 1) | |
| else if c == ')' then | |
| string_is_paren_balanced_helper (paren_string.drop 1) (num_open - 1) | |
| else | |
| string_is_paren_balanced_helper (paren_string.drop 1) num_open | |
| termination_by paren_string.length | |
| decreasing_by | |
| all_goals | |
| { | |
| rename_i h_non_empty_string | |
| rw [String.drop_eq, String.length] | |
| simp | |
| rw [String.isEmpty_iff] at h_non_empty_string | |
| by_cases h_paren_nil : paren_string.length β€ 0 | |
| rw [Nat.le_zero_eq] at h_paren_nil | |
| rw [βstring_eq_iff_data_eq] at h_non_empty_string | |
| have h_temp : """".data = [] := by simp | |
| rw [h_temp] at h_non_empty_string | |
| rw [String.length] at h_paren_nil | |
| rw [List.length_eq_zero] at h_paren_nil | |
| contradiction | |
| have h_temp : paren_string.length > 0 := by linarith | |
| assumption | |
| } | |
| /-- | |
| name: string_is_paren_balanced | |
| use: | | |
| Function to check if a string is balanced with respect to parentheses. | |
| problems: | |
| - 1 | |
| - 6 | |
| - 132 | |
| sample_problems: | |
| - 0 | |
| -/ | |
| def string_is_paren_balanced | |
| (paren_string: String): Bool | |
| := | |
| string_is_paren_balanced_helper paren_string 0 | |
| /-- | |
| name: count_max_paren_depth_helper | |
| use: | | |
| Helper to count the maximum depth of parentheses in a string. | |
| problems: | |
| - 6 | |
| - 132 | |
| -/ | |
| def count_max_paren_depth_helper | |
| (paren_string: String) (num_open: Int) (max_depth: Nat): Nat := | |
| -- Recursively count the maximum depth of parentheses | |
| if paren_string.isEmpty then | |
| max_depth | |
| else | |
| let c := paren_string.get! 0 | |
| if c == '(' then | |
| let new_num_open := num_open + 1 | |
| count_max_paren_depth_helper (paren_string.drop 1) (new_num_open) (max_depth.max new_num_open.toNat) | |
| else if c == ')' then | |
| count_max_paren_depth_helper (paren_string.drop 1) (num_open - 1) max_depth | |
| else | |
| count_max_paren_depth_helper (paren_string.drop 1) num_open max_depth | |
| termination_by paren_string.length | |
| decreasing_by | |
| all_goals | |
| { | |
| rename_i h_non_empty_string | |
| rw [String.drop_eq, String.length] | |
| simp | |
| rw [String.isEmpty_iff] at h_non_empty_string | |
| by_cases h_paren_nil : paren_string.length β€ 0 | |
| rw [Nat.le_zero_eq] at h_paren_nil | |
| rw [βstring_eq_iff_data_eq] at h_non_empty_string | |
| have h_temp : """".data = [] := by simp | |
| rw [h_temp] at h_non_empty_string | |
| rw [String.length] at h_paren_nil | |
| rw [List.length_eq_zero] at h_paren_nil | |
| contradiction | |
| have h_temp : paren_string.length > 0 := by linarith | |
| assumption | |
| } | |
| /-- | |
| name: count_max_paren_depth | |
| use: | | |
| Function to count the maximum depth of parentheses in a string. | |
| problems: | |
| - 6 | |
| - 132 | |
| -/ | |
| def count_max_paren_depth | |
| (paren_string: String): Nat := | |
| count_max_paren_depth_helper paren_string 0 0 | |
| /-- | |
| name: is_subsequence | |
| use: | | |
| Helper to check if List Char xs is a subsequence of List Char ys. | |
| problems: | |
| - 132 | |
| -/ | |
| def is_subsequence (xs ys : List Char) : Bool := | |
| match xs, ys with | |
| | [], _ => true | |
| | _, [] => false | |
| | x::xs', y::ys' => | |
| if x = y then is_subsequence xs' ys' else is_subsequence xs ys'",, | |
| def sum_squares(lst: List[float]) -> int,"You are given a list of numbers. | |
| You need to return the sum of squared numbers in the given list, | |
| round each element in the list to the upper int(Ceiling) first. | |
| ","[{""input"": [1, 2, 3], ""expected_output"": 14}, {""input"": [1, 4, 9], ""expected_output"": 98}, {""input"": [1, 3, 5, 7], ""expected_output"": 84}, {""input"": [1.4, 4.2, 0], ""expected_output"": 29}, {""input"": [-2.4, 1, 1], ""expected_output"": 6}]","def sum_squares(lst: List[float]) -> int | |
| """"""You are given a list of numbers. | |
| You need to return the sum of squared numbers in the given list, | |
| round each element in the list to the upper int(Ceiling) first. | |
| """"""","def problem_spec | |
| -- function signature | |
| (impl: List Rat β Int) | |
| -- inputs | |
| (lst: List Rat) := | |
| -- spec | |
| let spec (result: Int) := | |
| (lst = [] β result = 0) β§ | |
| (lst != [] β 0 β€ result - lst[0]!.ceil^2 β§ (impl (lst.drop 1) = (result - lst[0]!.ceil^2))) | |
| -- program termination | |
| β result, impl lst = result β§ | |
| -- return value satisfies spec | |
| spec result","def generated_spec | |
| -- function signature | |
| (impl: List Rat β Int) | |
| -- inputs | |
| (lst: List Rat) : Prop :=","theorem spec_isomorphism: | |
| β impl, | |
| (β lst, problem_spec impl lst) β | |
| (β lst, generated_spec impl lst) :=",sorry,def implementation (lst: List Rat) : Int :=,sorry,"-- #test implementation [1, 2, 3] = 14 | |
| -- #test implementation [1, 4, 9] = 98 | |
| -- #test implementation [1, 3, 5, 7] = 84 | |
| -- #test implementation [1.4, 4.2, 0] = 29 | |
| -- #test implementation [-2.4, 1, 1] = 6","theorem correctness | |
| (lst: List Rat) | |
| : problem_spec implementation lst :=",sorry,,, | |
| def check_if_last_char_is_a_letter(txt: str) -> Bool,"Create a function that returns True if the last character | |
| of a given string is an alphabetical character and is not | |
| a part of a word, and False otherwise. | |
| Note: ""word"" is a group of characters separated by space. | |
| ","[{""input"": ""apple pie"", ""expected_output"": false}, {""input"": ""apple pi e"", ""expected_output"": true}, {""input"": ""apple pi e "", ""expected_output"": false}, {""input"": """", ""expected_output"": false}]","def check_if_last_char_is_a_letter(txt: str) -> Bool | |
| """"""Create a function that returns True if the last character | |
| of a given string is an alphabetical character and is not | |
| a part of a word, and False otherwise. | |
| Note: ""word"" is a group of characters separated by space. | |
| """"""","def problem_spec | |
| -- function signature | |
| (impl: String β Bool) | |
| -- inputs | |
| (txt: String) := | |
| -- spec | |
| let spec (result: Bool) := | |
| let words := txt.splitOn "" ""; | |
| match words with | |
| | [] => result = False | |
| | [last_word] => (result β last_word.length = 1 β§ (let diff := (last_word.get 0).toLower.toNat - 'a'.toNat; 0 β€ diff β§ diff β€ 25)) | |
| | head::tail => result β (let tail_txt := String.join tail; impl tail_txt); | |
| -- program terminates | |
| β result, impl txt = result β§ | |
| -- return value satisfies spec | |
| spec result","def generated_spec | |
| -- function signature | |
| (impl: String β Bool) | |
| -- inputs | |
| (txt: String) : Prop :=","theorem spec_isomorphism: | |
| β impl, | |
| (β txt, problem_spec impl txt) β | |
| (β txt, generated_spec impl txt) :=",sorry,def implementation (txt: String) : Bool :=,sorry,"-- #test implementation ""apple pie"" = false | |
| -- #test implementation ""apple pi e"" = true | |
| -- #test implementation ""apple pi e "" = false | |
| -- #test implementation """" = false","theorem correctness | |
| (txt: String) | |
| : problem_spec implementation txt :=",sorry,,, | |
| def can_arrange(arr: List[int]) -> int,"Create a function which returns the largest index of an element which | |
| is not greater than or equal to the element immediately preceding it. If | |
| no such element exists then return -1. The given array will not contain | |
| duplicate values. | |
| ","[{""input"": [1, 2, 4, 3, 5], ""expected_output"": 3}, {""input"": [1, 2, 3], ""expected_output"": -1}]","def can_arrange(arr: List[int]) -> int | |
| """"""Create a function which returns the largest index of an element which | |
| is not greater than or equal to the element immediately preceding it. If | |
| no such element exists then return -1. The given array will not contain | |
| duplicate values. | |
| """"""","def problem_spec | |
| -- function signature | |
| (impl: List Int β Int) | |
| -- inputs | |
| (arr: List Int) := | |
| -- spec | |
| let spec (result: Int) := | |
| Β¬arr.any (fun x => 1 < arr.count x) β | |
| (arr.length = 0 β¨ arr.length = 1 β result = -1) β§ | |
| (1 < arr.length β | |
| let last := arr.length-1; | |
| let i := if arr[last]! < arr[last-1]! then Int.ofNat last else -1; | |
| result = max (impl (arr.take last)) i); | |
| -- program termination | |
| β result, impl arr = result β§ | |
| -- return value satisfies spec | |
| spec result","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 :=,sorry,"-- #test implementation [1, 2, 4, 3, 5] = 3 | |
| -- #test implementation [1, 2, 3] = -1","theorem correctness | |
| (arr: List Int) | |
| : problem_spec implementation arr :=",sorry,,, | |
| "def largest_smallest_integers(lst: List[int]) -> Tuple[ Optional[Int], Optional[Int] ]","Create a function that returns a tuple (a, b), where 'a' is | |
| the largest of negative integers, and 'b' is the smallest | |
| of positive integers in a list. | |
| If there is no negative or positive integers, return them as None. | |
| ","[{""input"": [2, 4, 1, 3, 5, 7], ""expected_output"": ""(None, 1)""}, {""input"": [], ""expected_output"": ""(None, None)""}, {""input"": [0], ""expected_output"": ""(None, None)""}]","def largest_smallest_integers(lst: List[int]) -> Tuple[ Optional[Int], Optional[Int] ] | |
| """"""Create a function that returns a tuple (a, b), where 'a' is | |
| the largest of negative integers, and 'b' is the smallest | |
| of positive integers in a list. | |
| If there is no negative or positive integers, return them as None. | |
| """"""","def problem_spec | |
| -- function signature | |
| (impl: List Int β Option Int Γ Option Int) | |
| -- inputs | |
| (lst: List Int) := | |
| -- spec | |
| let spec (result: Option Int Γ Option Int) := | |
| let (a, b) := result; | |
| (match a with | |
| | none => Β¬(β i, i β lst β§ i < 0) | |
| | some a => a < 0 β§ a β lst β§ β i, i β lst β§ i < 0 β i β€ a) β§ | |
| (match b with | |
| | none => Β¬(β i, i β lst β§ 0 < i) | |
| | some b => 0 < b β§ b β lst β§ β i, i β lst β§ 0 < i β b β€ i) | |
| -- program termination | |
| β result, impl lst = result β§ | |
| -- return value satisfies spec | |
| spec result","def generated_spec | |
| -- function signature | |
| (impl: List Int β Option Int Γ Option 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) : (Option Int Γ Option Int) :=,sorry,"-- #test implementation [2, 4, 1, 3, 5, 7] = (none, some 1) | |
| -- #test implementation [] = (none, none) | |
| -- #test implementation [0] = (none, none)","theorem correctness | |
| (lst: List Int) | |
| : problem_spec implementation lst :=",sorry,,, | |
| def is_equal_to_sum_even(n: int) -> Bool,"Evaluate whether the given number n can be written as the sum of exactly 4 positive even numbers | |
| ","[{""input"": 4, ""expected_output"": false}, {""input"": 6, ""expected_output"": false}, {""input"": 8, ""expected_output"": true}]","def is_equal_to_sum_even(n: int) -> Bool | |
| """"""Evaluate whether the given number n can be written as the sum of exactly 4 positive even numbers | |
| """"""","def problem_spec | |
| -- function signature | |
| (impl: Int β Bool) | |
| -- inputs | |
| (n: Int) := | |
| -- spec | |
| let spec (result: Bool) := | |
| let sum_exists := β a b c d : Nat, | |
| Even a β§ | |
| Even b β§ | |
| Even c β§ | |
| Even d β§ | |
| (a + b + c + d = n); | |
| result = true β sum_exists | |
| -- program termination | |
| β result, impl n = result β§ | |
| -- return value satisfies spec | |
| spec result","def generated_spec | |
| -- function signature | |
| (impl: Int β Bool) | |
| -- inputs | |
| (n: Int) : Prop :=","theorem spec_isomorphism: | |
| β impl, | |
| (β n, problem_spec impl n) β | |
| (β n, generated_spec impl n) :=",sorry,def implementation (n: Int) : Bool :=,sorry,"-- #test implementation 4 = false | |
| -- #test implementation 6 = false | |
| -- #test implementation 8 = true","theorem correctness | |
| (n: Int) | |
| : problem_spec implementation n :=",sorry,,, | |
| def special_factorial(n: int) -> int,"The Brazilian factorial is defined as: | |
| brazilian_factorial(n) = n! * (n-1)! * (n-2)! * ... * 1! | |
| where n > 0. Please write a function that computes the Brazilian factorial. | |
| ","[{""input"": 4, ""expected_output"": 288}]","def special_factorial(n: int) -> int | |
| """"""The Brazilian factorial is defined as: | |
| brazilian_factorial(n) = n! * (n-1)! * (n-2)! * ... * 1! | |
| where n > 0. Please write a function that computes the Brazilian factorial. | |
| """"""","def problem_spec | |
| -- function signature | |
| (impl: Nat β Nat) | |
| -- inputs | |
| (n: Nat) := | |
| -- spec | |
| let spec (result: Nat) := | |
| let factorial := Nat.factorial n; | |
| (0 < n β result / factorial = impl (n - 1)) β§ | |
| (n = 0 β result = 1); | |
| -- program termination | |
| β result, impl n = result β§ | |
| -- return value satisfies spec | |
| spec result","def generated_spec | |
| -- function signature | |
| (impl: Nat β Nat) | |
| -- inputs | |
| (n: Int) : Prop :=","theorem spec_isomorphism: | |
| β impl, | |
| (β n, problem_spec impl n) β | |
| (β n, generated_spec impl n) :=",sorry,def implementation (n: Nat) : Nat :=,sorry,-- #test implementation 4 = 288,"theorem correctness | |
| (n: Nat) | |
| : problem_spec implementation n :=",sorry,,, | |
| def fix_spaces(text: str) -> str,"Given a string text, replace all spaces in it with underscores, | |
| and if a string has more than 2 consecutive spaces, | |
| then replace all consecutive spaces with - | |
| ","[{""input"": ""Example"", ""expected_output"": ""Example""}, {""input"": ""Example 1"", ""expected_output"": ""Example_1""}, {""input"": "" Example 2"", ""expected_output"": ""_Example_2""}, {""input"": "" Example 3"", ""expected_output"": ""_Example-3""}]","def fix_spaces(text: str) -> str | |
| """"""Given a string text, replace all spaces in it with underscores, | |
| and if a string has more than 2 consecutive spaces, | |
| then replace all consecutive spaces with - | |
| """"""","def problem_spec | |
| -- function signature | |
| (impl: String β String) | |
| -- inputs | |
| (text: String) := | |
| -- spec | |
| let spec (result: String) := | |
| (result = """" β text = """") β§ | |
| (result β """" β ( | |
| (β pref s, text = pref ++ s | |
| β§ pref.length = 1 | |
| β§ pref β "" "" | |
| β§ result = pref ++ impl s) | |
| β¨ | |
| (β pref s : String, text = pref ++ s β§ pref β """" β§ (β ch, ch β pref.toList β ch = ' ') | |
| β§ let k := pref.length; | |
| (k β€ 2 β result = (String.replicate k '_') ++ (impl (text.drop k))) | |
| β§ (2 < k β result = ""-"" ++ (impl (text.drop k)))) ) | |
| ) | |
| -- program termination | |
| β result, impl text = result β§ | |
| -- return value satisfies spec | |
| spec result","def generated_spec | |
| -- function signature | |
| (impl: String β String) | |
| -- inputs | |
| (text: String) : Prop :=","theorem spec_isomorphism: | |
| β impl, | |
| (β text, problem_spec impl text) β | |
| (β text, generated_spec impl text) :=",sorry,def implementation (text: String) : String :=,sorry,"-- #test implementation ""Example"" = ""Example"" | |
| -- #test implementation ""Example 1"" = ""Example_1"" | |
| -- #test implementation "" Example 2"" = ""_Example_2"" | |
| -- #test implementation "" Example 3"" = ""_Example-3""","theorem correctness | |
| (text: String) | |
| : problem_spec implementation text :=",sorry,,, | |
| def file_name_check(file_name: str) -> str,"Create a function which takes a string representing a file's name, and returns | |
| 'Yes' if the the file's name is valid, and returns 'No' otherwise. | |
| A file's name is considered to be valid if and only if all the following conditions | |
| are met: | |
| - There should not be more than three digits ('0'-'9') in the file's name. | |
| - The file's name contains exactly one dot '.' | |
| - The substring before the dot should not be empty, and it starts with a letter from | |
| the latin alphapet ('a'-'z' and 'A'-'Z'). | |
| - The substring after the dot should be one of these: ['txt', 'exe', 'dll'] | |
| ","[{""input"": ""example.txt"", ""expected_output"": ""Yes""}, {""input"": ""1example.dll"", ""expected_output"": ""No""}]","def file_name_check(file_name: str) -> str | |
| """"""Create a function which takes a string representing a file's name, and returns | |
| 'Yes' if the the file's name is valid, and returns 'No' otherwise. | |
| A file's name is considered to be valid if and only if all the following conditions | |
| are met: | |
| - There should not be more than three digits ('0'-'9') in the file's name. | |
| - The file's name contains exactly one dot '.' | |
| - The substring before the dot should not be empty, and it starts with a letter from | |
| the latin alphapet ('a'-'z' and 'A'-'Z'). | |
| - The substring after the dot should be one of these: ['txt', 'exe', 'dll'] | |
| """"""","def problem_spec | |
| -- function signature | |
| (impl: String β String) | |
| -- inputs | |
| (file_name : String) := | |
| -- spec | |
| let spec (result: String) := | |
| let valid := (file_name.toList.filter Char.isDigit).length β€ 3 β§ | |
| (file_name.toList.filter (Β· = '.')).length = 1 β§ | |
| β before after : String, | |
| file_name = before ++ ""."" ++ after β§ | |
| before != """" β§ | |
| Char.isAlpha (before.get! 0) β§ | |
| (after = ""txt"" β¨ after = ""exe"" β¨ after = ""dll"") | |
| (result = ""Yes"" β valid) β§ | |
| (result = ""No"" β Β¬valid) | |
| -- program termination | |
| β result, impl file_name = result β§ | |
| -- return value satisfies spec | |
| spec result","def generated_spec | |
| -- function signature | |
| (impl: String β String) | |
| -- inputs | |
| (file_name: String) : Prop :=","theorem spec_isomorphism: | |
| β impl, | |
| (β file_name, problem_spec impl file_name) β | |
| (β file_name, generated_spec impl file_name) :=",sorry,def implementation (file_name : String) : String :=,sorry,"-- #test implementation ""example.txt"" = ""Yes"" | |
| -- #test implementation ""1example.dll"" = ""No""","theorem correctness | |
| (file_name : String) | |
| : problem_spec implementation file_name :=",sorry,,, | |
| def sum_squares(lst: List[int]) -> int,"This function will take a list of integers. For all entries in the list, the function shall square the integer entry if its index is a | |
| multiple of 3 and will cube the integer entry if its index is a multiple of 4 and not a multiple of 3. The function will not | |
| change the entries in the list whose indexes are not a multiple of 3 or 4. The function shall then return the sum of all entries. | |
| ","[{""input"": [1, 2, 3], ""expected_output"": 6}, {""input"": [], ""expected_output"": 0}, {""input"": [-1, -5, 2, -1, -5], ""expected_output"": -126}]","def sum_squares(lst: List[int]) -> int | |
| """"""This function will take a list of integers. For all entries in the list, the function shall square the integer entry if its index is a | |
| multiple of 3 and will cube the integer entry if its index is a multiple of 4 and not a multiple of 3. The function will not | |
| change the entries in the list whose indexes are not a multiple of 3 or 4. The function shall then return the sum of all entries. | |
| """"""","def problem_spec | |
| -- function signature | |
| (impl: List Int β Int) | |
| -- inputs | |
| (lst : List Int) := | |
| -- spec | |
| let spec (result : Int) := | |
| let last := lst.length-1; | |
| (lst = [] β result = 0) β§ | |
| (lst β [] β§ last % 3 = 0 β result = lst[last]! ^ 2 + impl (lst.take last)) β§ | |
| (lst β [] β§ last % 4 = 0 β§ last % 3 != 0 β result = lst[last]! ^ 3 + impl (lst.take last)) β§ | |
| (lst β [] β§ last % 3 != 0 β§ last % 4 != 0 β result = lst[last]! + impl (lst.take last)) | |
| -- program termination | |
| β result, impl lst = result β§ | |
| -- return value satisfies spec | |
| spec result","def generated_spec | |
| -- function signature | |
| (impl: List Int β 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) : Int :=,sorry,"-- #test implementation [1, 2, 3] = 6 | |
| -- #test implementation [] = 0 | |
| -- #test implementation [-1, -5, 2, -1, -5] = -126","theorem correctness | |
| (lst : List Int) | |
| : problem_spec implementation lst :=",sorry,,, | |
| def words_in_sentence(sentence: str) -> str,"You are given a string representing a sentence, | |
| the sentence contains some words separated by a space, | |
| and you have to return a string that contains the words from the original sentence, | |
| whose lengths are prime numbers, | |
| the order of the words in the new string should be the same as the original one. | |
| Constraints: | |
| * 1 <= len(sentence) <= 100 | |
| * sentence contains only letters | |
| ","[{""input"": ""This is a test"", ""expected_output"": ""is""}, {""input"": ""lets go for swimming"", ""expected_output"": ""go for""}]","def words_in_sentence(sentence: str) -> str | |
| """"""You are given a string representing a sentence, | |
| the sentence contains some words separated by a space, | |
| and you have to return a string that contains the words from the original sentence, | |
| whose lengths are prime numbers, | |
| the order of the words in the new string should be the same as the original one. | |
| Constraints: | |
| * 1 <= len(sentence) <= 100 | |
| * sentence contains only letters | |
| """"""","def problem_spec | |
| -- function signature | |
| (impl: String β String) | |
| -- inputs | |
| (sentence: String) := | |
| -- spec | |
| let spec (result: String) := | |
| let words := sentence.splitOn; | |
| let result_words := result.splitOn; | |
| 1 β€ sentence.length β sentence.length β€ 100 β | |
| sentence.all (fun x => Char.isAlpha x) β | |
| result_words.length β€ words.length β§ | |
| (β word β result_words, word β words β§ Nat.Prime word.length) β§ | |
| match result_words with | |
| | [] => β word β words, Β¬(Nat.Prime word.length) | |
| | head :: tail => if Nat.Prime head.length β§ head = words[0]! then String.join tail = impl (String.join (words.drop 1)) | |
| else result = impl (String.join (words.drop 1)) | |
| -- program termination | |
| β result, impl sentence = result β§ | |
| -- return value satisfies spec | |
| spec result","def generated_spec | |
| -- function signature | |
| (impl: String β String) | |
| -- inputs | |
| (sentence: String) : Prop :=","theorem spec_isomorphism: | |
| β impl, | |
| (β sentence, problem_spec impl sentence) β | |
| (β sentence, generated_spec impl sentence) :=",sorry,def implementation (sentence : String) : String :=,sorry,"-- #test implementation ""This is a test"" = ""is"" | |
| -- #test implementation ""lets go for swimming"" = ""go for""","theorem correctness | |
| (sentence : String) | |
| : problem_spec implementation sentence :=",sorry,,, | |
| "def simplify(x: str, n: str) -> Bool","Your task is to implement a function that will simplify the expression | |
| x * n. The function returns True if x * n evaluates to a whole number and False | |
| otherwise. Both x and n, are string representation of a fraction, and have the following format, | |
| <numerator>/<denominator> where both numerator and denominator are positive whole numbers. | |
| You can assume that x, and n are valid fractions, and do not have zero as denominator. | |
| ","[{""input"": [""1/5"", ""5/1""], ""expected_output"": true}, {""input"": [""1/6"", ""2/1""], ""expected_output"": false}, {""input"": [""7/10"", ""10/2""], ""expected_output"": false}]","def simplify(x: str, n: str) -> Bool | |
| """"""Your task is to implement a function that will simplify the expression | |
| x * n. The function returns True if x * n evaluates to a whole number and False | |
| otherwise. Both x and n, are string representation of a fraction, and have the following format, | |
| <numerator>/<denominator> where both numerator and denominator are positive whole numbers. | |
| You can assume that x, and n are valid fractions, and do not have zero as denominator. | |
| """"""","def problem_spec | |
| -- function signature | |
| (impl: String β String β Bool) | |
| -- inputs | |
| (x: String) (n: String) := | |
| -- spec | |
| let spec (result: Bool) := | |
| let fx := x.splitOn ""/""; | |
| let fn := n.splitOn ""/""; | |
| fx.length = 2 β fn.length = 2 β | |
| fx.all String.isNat β fn.all String.isNat β | |
| let p1 := fx[0]!.toNat!; | |
| let q1 := fx[1]!.toNat!; | |
| let p2 := fn[0]!.toNat!; | |
| let q2 := fn[1]!.toNat!; | |
| q1 β 0 β q2 β 0 β | |
| (result β (β k, k * p1 * p2 = q1 * q2)) | |
| -- program termination | |
| β result, impl x n = result β§ | |
| -- return value satisfies spec | |
| spec result","def generated_spec | |
| -- function signature | |
| (impl: String β String β Bool) | |
| -- inputs | |
| (x: String) (n: String) : Prop :=","theorem spec_isomorphism: | |
| β impl, | |
| (β x n, problem_spec impl x n) β | |
| (β x n, generated_spec impl x n) :=",sorry,def implementation (x: String) (n: String) : Bool :=,sorry,"-- #test implementation ""1/5"" ""5/1"" = True | |
| -- #test implementation ""1/6"" ""2/1"" = False | |
| -- #test implementation ""7/10"" ""10/2"" = False","theorem correctness | |
| (x: String) (n: String) | |
| : problem_spec implementation x n :=",sorry,,, | |
| def order_by_points(nums: List[int]) -> List[int],"Write a function which sorts the given list of integers | |
| in ascending order according to the sum of their digits. | |
| Note: if there are several items with similar sum of their digits, | |
| order them based on their index in original list. | |
| ","[{""input"": [1, 11, -1, -11, -12], ""expected_output"": [-1, -11, 1, -12, 11]}, {""input"": [], ""expected_output"": []}]","def order_by_points(nums: List[int]) -> List[int] | |
| """"""Write a function which sorts the given list of integers | |
| in ascending order according to the sum of their digits. | |
| Note: if there are several items with similar sum of their digits, | |
| order them based on their index in original list. | |
| """"""","def problem_spec | |
| -- function signature | |
| (impl: List Int β List Int) | |
| -- inputs | |
| (nums: List Int) := | |
| -- spec | |
| let spec (result: List Int) := | |
| List.Perm nums result β§ | |
| match result with | |
| | [] => nums = [] | |
| | head::tail => | |
| let head_sum := digit_sum head; | |
| (β num β nums, | |
| let sum := digit_sum num; | |
| sum > head_sum β¨ | |
| (sum = head_sum β§ nums.indexOf num β₯ nums.indexOf head)) | |
| β§ impl (nums.erase head) = tail | |
| -- program termination | |
| β result, impl nums = result β§ | |
| -- return value satisfies spec | |
| spec result","def generated_spec | |
| -- function signature | |
| (impl: List Int β List Int) | |
| -- inputs | |
| (nums: List Int) : Prop :=","theorem spec_isomorphism: | |
| β impl, | |
| (β nums, problem_spec impl nums) β | |
| (β nums, generated_spec impl nums) :=",sorry,def implementation (nums: List Int) : List Int :=,sorry,"-- #test implementation [1, 11, -1, -11, -12] = [-1, -11, 1, -12, 11] | |
| -- #test implementation [] = []","theorem correctness | |
| (nums: List Int) | |
| : problem_spec implementation nums :=",sorry,"/-- | |
| name: digit_sum | |
| use: | | |
| Helper to sum the digits of a number. If the number is negative, the | |
| negative sign is treated as part of the first digit. | |
| problems: | |
| - 145 | |
| -/ | |
| def digit_sum (n : Int) : Int := | |
| let ds := (toString n.natAbs).toList.map fun c => c.toNat - Char.toNat '0' | |
| match ds with | |
| | [] => 0 | |
| | d :: ds' => | |
| let tail := ds'.foldl (Β· + Β·) 0 | |
| if n < 0 then Int.ofNat tail - Int.ofNat d | |
| else Int.ofNat (d + tail)",, | |
| def specialFilter(nums: List[int]) -> int,"Write a function that takes an array of numbers as input and returns | |
| the number of elements in the array that are greater than 10 and both | |
| first and last digits of a number are odd (1, 3, 5, 7, 9). | |
| ","[{""input"": [15, -73, 14, -15], ""expected_output"": 1}, {""input"": [33, -2, -3, 45, 21, 109], ""expected_output"": 2}]","def specialFilter(nums: List[int]) -> int | |
| """"""Write a function that takes an array of numbers as input and returns | |
| the number of elements in the array that are greater than 10 and both | |
| first and last digits of a number are odd (1, 3, 5, 7, 9). | |
| """"""","def problem_spec | |
| -- function signature | |
| (impl: List Int β Int) | |
| -- inputs | |
| (nums: List Int) := | |
| -- spec | |
| let spec (result: Int) := | |
| match nums with | |
| | [] => result = 0 | |
| | head::tail => | |
| let first_digit := (toString head.natAbs).toList[0]!.toNat - Char.toNat '0'; | |
| let last_digit := head % 10; | |
| let valid := head > 10 β§ Odd first_digit β§ Odd last_digit | |
| if valid then result = 1 + impl tail else result = impl tail | |
| -- program termination | |
| β result, impl nums = result β§ | |
| -- return value satisfies spec | |
| spec result","def generated_spec | |
| -- function signature | |
| (impl: List Int β Int) | |
| -- inputs | |
| (nums: List Int) : Prop :=","theorem spec_isomorphism: | |
| β impl, | |
| (β nums, problem_spec impl nums) β | |
| (β nums, generated_spec impl nums) :=",sorry,def implementation (nums: List Int) : Int :=,sorry,"-- #test implementation [15, -73, 14, -15] = 1 | |
| -- #test implementation [33, -2, -3, 45, 21, 109] = 2","theorem correctness | |
| (nums: List Int) | |
| : problem_spec implementation nums :=",sorry,,, | |
| def get_max_triples(n: int) -> int,"You are given a positive integer n. You have to create an integer array a of length n. | |
| For each i (1 β€ i β€ n), the value of a[i] = i * i - i + 1. | |
| Return the number of triples (a[i], a[j], a[k]) of a where i < j < k, | |
| and a[i] + a[j] + a[k] is a multiple of 3. | |
| ","[{""input"": 5, ""expected_output"": 1}]","def get_max_triples(n: int) -> int | |
| """"""You are given a positive integer n. You have to create an integer array a of length n. | |
| For each i (1 β€ i β€ n), the value of a[i] = i * i - i + 1. | |
| Return the number of triples (a[i], a[j], a[k]) of a where i < j < k, | |
| and a[i] + a[j] + a[k] is a multiple of 3. | |
| """"""","def problem_spec | |
| -- function signature | |
| (impl: Nat β Nat) | |
| -- inputs | |
| (n: Nat) := | |
| -- spec | |
| let spec (result: Nat) := | |
| β (S : Finset (Nat Γ Nat Γ Nat)), S.card = result β§ | |
| β (triple: Nat Γ Nat Γ Nat), | |
| let (i, j, k) := triple; | |
| let a_i := i * i - i + 1; | |
| let a_j := j * j - j + 1; | |
| let a_k := k * k - k + 1; | |
| (1 β€ i β§ i < j β§ j < k β§ k β€ n β§ | |
| (a_i + a_j + a_k) % 3 = 0) | |
| β triple β S | |
| -- program termination | |
| β result, impl n = result β§ | |
| -- return value satisfies spec | |
| spec result","def generated_spec | |
| -- function signature | |
| (impl: Nat β Nat) | |
| -- inputs | |
| (nums: 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 5 = 1,"theorem correctness | |
| (n: Nat) | |
| : problem_spec implementation n :=",sorry,,, | |
| "def bf(planet1: str, planet2: str) -> List[str]","There are eight planets in our solar system: the closest to the Sun | |
| is Mercury, the next one is Venus, then Earth, Mars, Jupiter, Saturn, | |
| Uranus, Neptune. | |
| Write a function that takes two planet names as strings planet1 and planet2. | |
| The function should return a tuple containing all planets whose orbits are | |
| located between the orbit of planet1 and the orbit of planet2, sorted by | |
| the proximity to the sun. | |
| The function should return an empty tuple if planet1 or planet2 | |
| are not correct planet names. | |
| ","[{""input"": ""(\""Jupiter\"", \""Neptune\"")"", ""expected_output"": ""(\""Saturn\"", \""Uranus\"")""}, {""input"": ""(\""Earth\"", \""Mercury\"")"", ""expected_output"": ""(\""Venus\"")""}, {""input"": ""(\""Mercury\"", \""Uranus\"")"", ""expected_output"": ""(\""Venus\"", \""Earth\"", \""Mars\"", \""Jupiter\"", \""Saturn\"")""}]","def bf(planet1: str, planet2: str) -> List[str] | |
| """"""There are eight planets in our solar system: the closest to the Sun | |
| is Mercury, the next one is Venus, then Earth, Mars, Jupiter, Saturn, | |
| Uranus, Neptune. | |
| Write a function that takes two planet names as strings planet1 and planet2. | |
| The function should return a tuple containing all planets whose orbits are | |
| located between the orbit of planet1 and the orbit of planet2, sorted by | |
| the proximity to the sun. | |
| The function should return an empty tuple if planet1 or planet2 | |
| are not correct planet names. | |
| """"""","def problem_spec | |
| -- function signature | |
| (impl: String β String β List String) | |
| -- inputs | |
| (planet1: String) | |
| (planet2: String) := | |
| -- spec | |
| let spec (result: List String) := | |
| let planets := [""Mercury"", ""Venus"", ""Earth"", ""Mars"", ""Jupiter"", ""Saturn"", ""Uranus"", ""Neptune""]; | |
| if planet1 β planets β¨ planet2 β planets then | |
| result = [] | |
| else | |
| let index1 := planets.indexOf planet1; | |
| let index2 := planets.indexOf planet2; | |
| let minIdx := if index1 < index2 then index1 else index2; | |
| let maxIdx := if index1 < index2 then index2 else index1; | |
| (β str β result, str β planets) β§ | |
| (β planet β planets, planet β result β | |
| planets.indexOf planet < maxIdx β§ | |
| minIdx < planets.indexOf planet) β§ | |
| result.Sorted (fun a b => planets.indexOf a < planets.indexOf b) | |
| -- program termination | |
| β result, impl planet1 planet2 = result β§ | |
| -- return value satisfies spec | |
| spec result","def generated_spec | |
| -- function signature | |
| (impl: String β String β List String) | |
| -- inputs | |
| (planet1: String) | |
| (planet2: String) : Prop :=","theorem spec_isomorphism: | |
| β impl, | |
| (β planet1 planet2, problem_spec impl planet1 planet2) β | |
| (β planet1 planet2, generated_spec impl planet1 planet2) :=",sorry,def implementation (planet1: String) (planet2: String) : List String :=,sorry,"-- #test implementation ""Jupiter"" ""Neptune"" = [""Saturn"", ""Uranus""] | |
| -- #test implementation ""Earth"" ""Mercury"" = [""Venus""] | |
| -- #test implementation ""Mercury"" ""Uranus"" = [""Venus"", ""Earth"", ""Mars"", ""Jupiter"", ""Saturn""]","theorem correctness | |
| (planet1: String) | |
| (planet2: String) | |
| : problem_spec implementation planet1 planet2 :=",sorry,,, | |
| def sorted_list_sum(lst: List[str]) -> List[str],"Write a function that accepts a list of strings as a parameter, | |
| deletes the strings that have odd lengths from it, | |
| and returns the resulted list with a sorted order, | |
| The list is always a list of strings and never an array of numbers, | |
| and it may contain duplicates. | |
| The order of the list should be ascending by length of each word, and you | |
| should return the list sorted by that rule. | |
| If two words have the same length, sort the list alphabetically. | |
| The function should return a list of strings in sorted order. | |
| You may assume that all words will have the same length. | |
| ","[{""input"": [""aa"", ""a"", ""aaa""], ""output"": [""aa""]}, {""input"": [""ab"", ""a"", ""aaa"", ""cd""], ""output"": [""ab"", ""cd""]}]","def sorted_list_sum(lst: List[str]) -> List[str] | |
| """"""Write a function that accepts a list of strings as a parameter, | |
| deletes the strings that have odd lengths from it, | |
| and returns the resulted list with a sorted order, | |
| The list is always a list of strings and never an array of numbers, | |
| and it may contain duplicates. | |
| The order of the list should be ascending by length of each word, and you | |
| should return the list sorted by that rule. | |
| If two words have the same length, sort the list alphabetically. | |
| The function should return a list of strings in sorted order. | |
| You may assume that all words will have the same length. | |
| """"""","def problem_spec | |
| -- function signature | |
| (impl: List String β List String) | |
| -- inputs | |
| (lst: List String) := | |
| -- spec | |
| let spec (result: List String) := | |
| match result with | |
| | [] => β str β lst, Odd str.length | |
| | head::tail => | |
| Even head.length β§ | |
| (β str β lst, | |
| Odd str.length β¨ | |
| str.length > head.length β¨ | |
| str.length = head.length β§ str β₯ head) | |
| β§ impl (lst.erase head) = tail | |
| -- program termination | |
| β result, impl lst = result β§ | |
| -- return value satisfies spec | |
| spec result","def generated_spec | |
| -- function signature | |
| (impl: List String β List String) | |
| -- inputs | |
| (lst: List String) : Prop :=","theorem spec_isomorphism: | |
| β impl, | |
| (β lst, problem_spec impl lst) β | |
| (β lst, generated_spec impl lst) :=",sorry,def implementation (lst: List String) : List String :=,sorry,"-- #test implementation [""aa"", ""a"", ""aaa""] = [""aa""] | |
| -- #test implementation [""ab"", ""a"", ""aaa"", ""cd""] = [""ab"", ""cd""]","theorem correctness | |
| (lst: List String) | |
| : problem_spec implementation lst :=",sorry,,, | |
| "def x_or_y(int n, int x, int y) -> int","A simple program which should return the value of x if n is | |
| a prime number and should return the value of y otherwise. | |
| ","[{""input"": [7, 34, 12], ""expected_output"": 34}, {""input"": [15, 8, 5], ""expected_output"": 5}]","def x_or_y(int n, int x, int y) -> int | |
| """"""A simple program which should return the value of x if n is | |
| a prime number and should return the value of y otherwise. | |
| """"""","def problem_spec | |
| -- function signature | |
| (impl: Int β Int β Int β Int) | |
| -- inputs | |
| (n x y: Int) := | |
| -- spec | |
| let spec (result: Int) := | |
| (result = x β Nat.Prime n.toNat) β§ | |
| (result = y β (Β¬ Nat.Prime n.toNat β¨ n β€ 1)) | |
| -- program terminates | |
| β result, impl n x y = result β§ | |
| -- return value satisfies spec | |
| spec result","def generated_spec | |
| -- function signature | |
| (impl: Int β Int β Int β Int) | |
| -- inputs | |
| (n x y: Int) : Prop :=","theorem spec_isomorphism: | |
| β impl, | |
| (β n x y, problem_spec impl n x y) β | |
| (β n x y, generated_spec impl n x y) :=",sorry,def implementation (n x y: Int) : Int :=,sorry,"-- #test implementation 7 34 12 = 34 | |
| -- #test implementation 15 8 5 = 5","theorem correctness | |
| (n x y: Int) | |
| : problem_spec implementation n x y :=",sorry,,, | |
| def double_the_difference(numbers: List[float]) -> Int,"Given a list of numbers, return the sum of squares of the numbers | |
| in the list that are odd. Ignore numbers that are negative or not integers. | |
| ","[{""input"": [1, 3, 2, 0], ""expected_output"": 10}, {""input"": [""-1. -2"", 0], ""expected_output"": 0}, {""input"": [9, -2], ""expected_output"": 81}, {""input"": [0], ""expected_output"": 0}]","def double_the_difference(numbers: List[float]) -> Int | |
| """"""Given a list of numbers, return the sum of squares of the numbers | |
| in the list that are odd. Ignore numbers that are negative or not integers. | |
| """"""","def problem_spec | |
| -- function signature | |
| (impl: List Rat β Int) | |
| -- inputs | |
| (numbers: List Rat) := | |
| let isEven (n : Rat) := n % 2 = 0; | |
| let isNegative (n : Rat) := n < 0; | |
| let isNotInteger (n : Rat) := Β¬ n.isInt; | |
| -- spec | |
| let spec (result: Int) := | |
| 0 < numbers.length β | |
| 0 β€ result β§ | |
| if numbers.length = 1 | |
| then result = if (isEven numbers[0]! β¨ isNegative numbers[0]! β¨ isNotInteger numbers[0]!) then (0 : Int) else numbers[0]!.floor ^ 2 | |
| else result = if (isEven numbers[0]! β¨ isNegative numbers[0]! β¨ isNotInteger numbers[0]!) then (0 : Int) else numbers[0]!.floor ^ 2 + impl numbers.tail | |
| -- program terminates | |
| β result, impl numbers = result β§ | |
| -- return value satisfies spec | |
| spec result","def generated_spec | |
| -- function signature | |
| (impl: List Rat β Int) | |
| -- inputs | |
| (numbers: List Rat) : Prop :=","theorem spec_isomorphism: | |
| β impl, | |
| (β numbers, problem_spec impl numbers) β | |
| (β numbers, generated_spec impl numbers) :=",sorry,def implementation (numbers: List Rat) : Int :=,sorry,"-- #test implementation ([1, 3, 2, 0]: List Rat) = (10: Int) | |
| -- #test implementation ([-1, -2, 0]: List Int) = (0: Int) | |
| -- #test implementation ([9, -2]: List Int) = 81 | |
| -- #test implementation ([0]: List Int) = 0","theorem correctness | |
| (numbers: List Rat) | |
| : problem_spec implementation numbers :=",sorry,,, | |
| "def compare(scores: List float, guesses: List float) -> List [float]","I think we all remember that feeling when the result of some long-awaited | |
| event is finally known. The feelings and thoughts you have at that moment are | |
| definitely worth noting down and comparing. | |
| Your task is to determine if a person correctly guessed the results of a number of matches. | |
| You are given two arrays of scores and guesses of equal length, where each index shows a match. | |
| Return an array of the same length denoting how far off each guess was. If they have guessed correctly, | |
| the value is 0, and if not, the value is the absolute difference between the guess and the score. | |
| Note: to reviewer, the reason for not using |.| to get the absolute value is to avoid leaking the implementation. | |
| ","[{""input"": [[1, 2, 3, 4, 5, 1], [1, 2, 3, 4, 2, -2]], ""expected_output"": [0, 0, 0, 0, 3, 3]}, {""input"": [[0, 5, 0, 0, 0, 4], [4, 1, 1, 0, 0, -2]], ""expected_output"": [4, 4, 1, 0, 0, 6]}]","def compare(scores: List float, guesses: List float) -> List [float] | |
| """"""I think we all remember that feeling when the result of some long-awaited | |
| event is finally known. The feelings and thoughts you have at that moment are | |
| definitely worth noting down and comparing. | |
| Your task is to determine if a person correctly guessed the results of a number of matches. | |
| You are given two arrays of scores and guesses of equal length, where each index shows a match. | |
| Return an array of the same length denoting how far off each guess was. If they have guessed correctly, | |
| the value is 0, and if not, the value is the absolute difference between the guess and the score. | |
| Note: to reviewer, the reason for not using |.| to get the absolute value is to avoid leaking the implementation. | |
| """"""","def problem_spec | |
| -- function signature | |
| (impl: List Rat β List Rat β List Rat) | |
| -- inputs | |
| (scores guesses: List Rat) := | |
| -- spec | |
| let spec (result: List Rat) := | |
| result.length = scores.length β§ | |
| scores.length = guesses.length β§ | |
| β i, i < scores.length β | |
| if scores[i]! > guesses[i]! then result[i]! + guesses[i]! = scores[i]! | |
| else result[i]! + scores[i]! = guesses[i]! | |
| -- program terminates | |
| β result, impl scores guesses = result β§ | |
| -- return value satisfies spec | |
| spec result","def generated_spec | |
| -- function signature | |
| (impl: List Rat β List Rat β List Rat) | |
| -- inputs | |
| (scores guesses: List Rat) : Prop :=","theorem spec_isomorphism: | |
| β impl, | |
| (β scores guesses, problem_spec impl scores guesses) β | |
| (β scores guesses, generated_spec impl scores guesses) :=",sorry,def implementation (scores guesses: List Rat) : List Rat :=,sorry,"-- #test implementation [1,2,3,4,5,1] [1,2,3,4,2,-2] = [0,0,0,0,3,3] | |
| -- #test implementation [0,5,0,0,0,4] [4,1,1,0,0,-2] = [4,4,1,0,0,6]","theorem correctness | |
| (scores guesses: List Rat) | |
| : problem_spec implementation scores guesses :=",sorry,,, | |
| "def Strongest_Extension(class_name: String, extensions: List[String]) -> String","You will be given the name of a class (a string) and a list of extensions. | |
| The extensions are to be used to load additional classes to the class. The | |
| strength of the extension is as follows: Let CAP be the number of the uppercase | |
| letters in the extension's name, and let SM be the number of lowercase letters | |
| in the extension's name, the strength is given by the fraction CAP - SM. | |
| You should find the strongest extension and return a string in this | |
| format: ClassName.StrongestExtensionName. | |
| If there are two or more extensions with the same strength, you should | |
| choose the one that comes first in the list. | |
| For example, if you are given ""Slices"" as the class and a list of the | |
| extensions: ['SErviNGSliCes', 'Cheese', 'StuFfed'] then you should | |
| return 'Slices.SErviNGSliCes' since 'SErviNGSliCes' is the strongest extension | |
| (its strength is -1). | |
| ","[{""input"": [""my_class"", [""AA"", ""Be"", ""CC""]], ""expected_output"": ""my_class.AA""}]","def Strongest_Extension(class_name: String, extensions: List[String]) -> String | |
| """"""You will be given the name of a class (a string) and a list of extensions. | |
| The extensions are to be used to load additional classes to the class. The | |
| strength of the extension is as follows: Let CAP be the number of the uppercase | |
| letters in the extension's name, and let SM be the number of lowercase letters | |
| in the extension's name, the strength is given by the fraction CAP - SM. | |
| You should find the strongest extension and return a string in this | |
| format: ClassName.StrongestExtensionName. | |
| If there are two or more extensions with the same strength, you should | |
| choose the one that comes first in the list. | |
| For example, if you are given ""Slices"" as the class and a list of the | |
| extensions: ['SErviNGSliCes', 'Cheese', 'StuFfed'] then you should | |
| return 'Slices.SErviNGSliCes' since 'SErviNGSliCes' is the strongest extension | |
| (its strength is -1). | |
| """"""","def problem_spec | |
| -- function signature | |
| (impl: String β List String β String) | |
| -- inputs | |
| (class_name: String) | |
| (extensions: List String) := | |
| let strength (extension: String) := | |
| let cap := (extension.toList.filter (fun c => c.isUpper)).length; | |
| let sm := (extension.toList.filter (fun c => c.isLower)).length; | |
| cap - sm; | |
| -- spec | |
| let spec (result: String) := | |
| let last_pos := result.revPosOf '.'; | |
| 0 < extensions.length β§ extensions.all (fun x => 0 < x.length) β§ 0 < class_name.length β | |
| 0 < result.length β§ | |
| last_pos.isSome β§ | |
| let class_name' := result.take (last_pos.get!).byteIdx; | |
| let extension_name := result.drop ((last_pos.get!).byteIdx + 1); | |
| class_name' = class_name β§ | |
| extension_name β extensions β§ | |
| let strength_of_extensions := extensions.map (fun ext => strength ext); | |
| β j : Nat, j < extensions.length β§ | |
| extensions[j]! = extension_name β§ | |
| (β i : Nat, i < j β strength_of_extensions[i]! < strength_of_extensions[j]!) | |
| β§ strength_of_extensions[j]! = strength_of_extensions.max?.get!; | |
| -- program terminates | |
| β result, impl class_name extensions = result β§ | |
| -- return value satisfies spec | |
| spec result","def generated_spec | |
| -- function signature | |
| (impl: String β List String β String) | |
| -- inputs | |
| (class_name: String) | |
| (extensions: List String) : Prop :=","theorem spec_isomorphism: | |
| β impl, | |
| (β class_name extensions, problem_spec impl class_name extensions) β | |
| (β class_name extensions, generated_spec impl class_name extensions) :=",sorry,def implementation (class_name: String) (extensions: List String) : String :=,sorry,"-- #test implementation 'my_class', ['AA', 'Be', 'CC'] = 'my_class.AA'","theorem correctness | |
| (class_name: String) | |
| (extensions: List String) | |
| : problem_spec implementation class_name extensions :=",sorry,,, | |
| "def cycpattern_check(String a, String b) -> Bool","You are given 2 words. You need to return True if the second word or any of its rotations is a substring in the first word, else False | |
| ","[{""input"": [""abcd"", ""abd""], ""expected_output"": false}, {""input"": [""hello"", ""ell""], ""expected_output"": true}, {""input"": [""whassup"", ""psus""], ""expected_output"": false}, {""input"": [""abab"", ""baa""], ""expected_output"": true}, {""input"": [""efef"", ""eeff""], ""expected_output"": false}, {""input"": [""himenss"", ""simen""], ""expected_output"": true}]","def cycpattern_check(String a, String b) -> Bool | |
| """"""You are given 2 words. You need to return True if the second word or any of its rotations is a substring in the first word, else False | |
| """"""","def problem_spec | |
| -- function signature | |
| (impl: String β String β Bool) | |
| -- inputs | |
| (a b: String) := | |
| -- spec | |
| let spec (result: Bool) := | |
| (b.length = 0 β result) β§ | |
| (0 < b.length β | |
| result β ((b.length β€ a.length) β§ | |
| (β i : Nat, i < b.length β§ | |
| let b_rotation := b.drop i ++ b.take i; | |
| a.containsSubstr b_rotation))); | |
| -- program terminates | |
| β result, impl a b = result β§ | |
| -- return value satisfies spec | |
| spec result","def generated_spec | |
| -- function signature | |
| (impl: String β String β Bool) | |
| -- inputs | |
| (a b: String) : Prop :=","theorem spec_isomorphism: | |
| β impl, | |
| (β a b, problem_spec impl a b) β | |
| (β a b, generated_spec impl a b) :=",sorry,def implementation (a b: String) : Bool :=,sorry,"-- #test implementation ""abcd"" ""abd"" = False | |
| -- #test implementation ""hello"" ""ell"" = True | |
| -- #test implementation ""whassup"" ""psus"" = False | |
| -- #test implementation ""abab"" ""baa"" = True | |
| -- #test implementation ""efef"" ""eeff"" = False | |
| -- #test implementation ""himenss"" ""simen"" = True","theorem correctness | |
| (a b: String) | |
| : problem_spec implementation a b :=",sorry,,, | |
| "def even_odd_count(num: int) -> Tuple[int, int]","Given an integer. return a tuple that has the number of even and odd digits respectively. | |
| ","[{""input"": -12, ""expected_output"": [1, 1]}, {""input"": 123, ""expected_output"": [1, 2]}]","def even_odd_count(num: int) -> Tuple[int, int] | |
| """"""Given an integer. return a tuple that has the number of even and odd digits respectively. | |
| """"""","def problem_spec | |
| -- function signature | |
| (impl: Int β Int Γ Int) | |
| -- inputs | |
| (num: Int) := | |
| -- spec | |
| let spec (result: Int Γ Int) := | |
| let (even_count, odd_count) := result; | |
| let numAbs := |num|.toNat; | |
| let numBy10 := numAbs/10; | |
| let (even_count', odd_count') := impl numBy10; | |
| (result = impl numAbs) β§ | |
| (0 β€ num β (Even num β 1 + even_count' = even_count) β§ (Odd num β even_count' = even_count)) β§ | |
| (0 β€ num β (Odd num β 1 + odd_count' = odd_count) β§ (Even num β odd_count' = odd_count)); | |
| -- program terminates | |
| β result, impl num = result β§ | |
| -- return value satisfies spec | |
| spec result","def generated_spec | |
| -- function signature | |
| (impl: Int β Int Γ Int) | |
| -- inputs | |
| (num: Int) : Prop :=","theorem spec_isomorphism: | |
| β impl, | |
| (β num, problem_spec impl num) β | |
| (β num, generated_spec impl num) :=",sorry,def implementation (num: Int) : Int Γ Int :=,sorry,"-- #test implementation -12 = (1, 1) | |
| -- #test implementation 123 = (1, 2)","theorem correctness | |
| (num: Int) | |
| : problem_spec implementation num :=",sorry,,, | |
| def int_to_mini_roman(num: Nat) -> String,"Given a positive integer, obtain its roman numeral equivalent as a string, | |
| and return it in lowercase. | |
| Restrictions: 1 <= num <= 1000 | |
| ","[{""input"": 19, ""expected_output"": ""xix""}, {""input"": 152, ""expected_output"": ""clii""}, {""input"": 426, ""expected_output"": ""cdxxvi""}]","def int_to_mini_roman(num: Nat) -> String | |
| """"""Given a positive integer, obtain its roman numeral equivalent as a string, | |
| and return it in lowercase. | |
| Restrictions: 1 <= num <= 1000 | |
| """"""","def problem_spec | |
| -- function signature | |
| (impl: Nat β String) | |
| -- inputs | |
| (num: Nat) := | |
| -- spec | |
| let spec (result: String) := | |
| 1 β€ num β§ num β€ 1000 β§ (result.data.all (fun c => c.isLower)) β | |
| isValidRoman result β§ romanToDecimal result = num | |
| -- program terminates | |
| β result, impl num = result β§ | |
| -- return value satisfies spec | |
| spec result","def generated_spec | |
| -- function signature | |
| (impl: Nat β String) | |
| -- inputs | |
| (num: Nat) : Prop :=","theorem spec_isomorphism: | |
| β impl, | |
| (β num, problem_spec impl num) β | |
| (β num, generated_spec impl num) :=",sorry,def implementation (num: Nat) : String :=,sorry,"-- #test implementation 19 = ""xix"" | |
| -- #test implementation 152 = ""clii"" | |
| -- #test implementation 426 = ""cdxxvi""","theorem correctness | |
| (num: Nat) | |
| : problem_spec implementation num :=",sorry,"/-- | |
| name: romanCharToValue | |
| use: | | |
| Map from valid characters and their values | |
| problems: | |
| - 156 | |
| sample_problems: [] | |
| -/ | |
| def romanCharToValue : Char β Nat | |
| | 'i' => 1 | |
| | 'v' => 5 | |
| | 'x' => 10 | |
| | 'l' => 50 | |
| | 'c' => 100 | |
| | 'd' => 500 | |
| | 'm' => 1000 | |
| | _ => 0 | |
| /-- | |
| name: validSubtractivePairs | |
| use: | | |
| Legal subtractive pairs: first char can precede second for subtraction (in roman numerals) | |
| problems: | |
| - 156 | |
| sample_problems: [] | |
| -/ | |
| def validSubtractivePairs : List (Char Γ Char) := | |
| [('i', 'v'), ('i', 'x'), ('x', 'l'), ('x', 'c'), ('c', 'd'), ('c', 'm')] | |
| /-- | |
| name: maxRepetitions | |
| use: | | |
| Max allowed repetitions for each character (in roman numerals) | |
| problems: | |
| - 156 | |
| sample_problems: [] | |
| -/ | |
| def maxRepetitions : Char β Nat | |
| | 'i' | 'x' | 'c' | 'm' => 3 | |
| | 'v' | 'l' | 'd' => 1 | |
| | _ => 0 | |
| /-- | |
| name: countRepetitions | |
| use: | | |
| Helper to count consecutive repetitions (in roman numerals) | |
| problems: | |
| - 156 | |
| sample_problems: [] | |
| -/ | |
| def countRepetitions : List Char β Char β Nat β Nat | |
| | [], _, n => n | |
| | (h :: t), c, n => if h = c then countRepetitions t c (n + 1) else n | |
| /-- | |
| name: validRepetition | |
| use: | | |
| Helper to validate proper use of repetitions (in roman numerals) | |
| problems: | |
| - 156 | |
| sample_problems: [] | |
| -/ | |
| partial def validRepetition : List Char β Bool | |
| | [] => true | |
| | c :: rest => | |
| let max := maxRepetitions c | |
| let count := countRepetitions rest c 1 | |
| count β€ max β§ validRepetition (rest.drop (count - 1)) | |
| /-- | |
| name: validSubtractiveOrder | |
| use: | | |
| Helper to validate legal subtractive combinations (in roman numerals) | |
| problems: | |
| - 156 | |
| sample_problems: [] | |
| -/ | |
| def validSubtractiveOrder : List Char β Bool | |
| | [] | [_] => true | |
| | c1 :: c2 :: rest => | |
| match romanCharToValue c1, romanCharToValue c2 with | |
| | v1, v2 => | |
| if v1 < v2 then | |
| -- check if c1 and c2 form a legal subtractive pair | |
| (c1, c2) β validSubtractivePairs β§ validSubtractiveOrder rest | |
| else if v1 = 0 β¨ v2 = 0 then | |
| false | |
| else | |
| validSubtractiveOrder (c2 :: rest) | |
| /-- | |
| name: isValidRoman | |
| use: | | |
| Function to check if a string is a roman numeral | |
| problems: | |
| - 156 | |
| sample_problems: [] | |
| -/ | |
| def isValidRoman (s : String) : Bool := | |
| s.data.all (Ξ» c => romanCharToValue c β 0) β§ | |
| validRepetition s.data β§ | |
| validSubtractiveOrder s.data | |
| /-- | |
| name: romanToDecimalAux | |
| use: | | |
| Helper to convert list of roman characters to decimal | |
| problems: | |
| - 156 | |
| sample_problems: [] | |
| -/ | |
| def romanToDecimalAux : List Char β Nat | |
| | [] => 0 | |
| | c1 :: c2 :: rest => | |
| let val1 := romanCharToValue c1 | |
| let val2 := romanCharToValue c2 | |
| if val1 < val2 then | |
| -- subtractive notation | |
| (val2 - val1) + romanToDecimalAux rest | |
| else | |
| val1 + romanToDecimalAux (c2 :: rest) | |
| | [c] => romanCharToValue c | |
| /-- | |
| name: romanToDecimalAux | |
| use: | | |
| Function to convert a valid lowercase Roman numeral string to Nat | |
| problems: | |
| - 156 | |
| sample_problems: [] | |
| -/ | |
| def romanToDecimal (s : String) : Nat := | |
| romanToDecimalAux s.data",, | |
| "def right_angle_triangle(a: Nat, b: Nat, c: Nat) -> Bool","Given the lengths of the three sides of a triangle. Return True if the three | |
| sides form a right-angled triangle, False otherwise. | |
| A right-angled triangle is a triangle in which one angle is right angle or | |
| 90 degree. | |
| ","[{""input"": [3, 4, 5], ""expected_output"": true}, {""input"": [1, 2, 3], ""expected_output"": false}]","def right_angle_triangle(a: Nat, b: Nat, c: Nat) -> Bool | |
| """"""Given the lengths of the three sides of a triangle. Return True if the three | |
| sides form a right-angled triangle, False otherwise. | |
| A right-angled triangle is a triangle in which one angle is right angle or | |
| 90 degree. | |
| """"""","def problem_spec | |
| -- function signature | |
| (impl: Nat β Nat β Nat β Bool) | |
| -- inputs | |
| (a b c: Nat) := | |
| -- spec | |
| let spec (result: Bool) := | |
| result β | |
| 0 < a β§ 0 < b β§ 0 < c β§ | |
| ((a * a + b * b = c * c) β¨ | |
| (a * a + c * c = b * b) β¨ | |
| (b * b + c * c = a * a)) | |
| -- program terminates | |
| β result, impl a b c = result β§ | |
| -- return value satisfies spec | |
| spec result","def generated_spec | |
| -- function signature | |
| (impl: Nat β Nat β Nat β Bool) | |
| -- inputs | |
| (a b c: Nat) : 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 b c: Nat) : Bool :=,sorry,"-- #test implementation ([1, 2, 2, -4]: List Int) = (-9: Int) | |
| -- #test implementation ([0, 1]: List Int) = (0: Int) | |
| -- #test implementation ([]: List Int) = none","theorem correctness | |
| (a b c: Nat) | |
| : problem_spec implementation a b c :=",sorry,,, | |
| def find_max(words: List String) -> String,"Write a function that accepts a list of strings. | |
| The list contains different words. Return the word with maximum number | |
| of unique characters. If multiple strings have maximum number of unique | |
| characters, return the one which comes first in lexicographical order. | |
| ","[{""input"": [""name"", ""of"", ""string""], ""expected_output"": ""string""}, {""input"": [""name"", ""enam"", ""game""], ""expected_output"": ""enam""}, {""input"": [""aaaaaaa"", ""bb"", ""cc""], ""expected_output"": ""aaaaaaa""}]","def find_max(words: List String) -> String | |
| """"""Write a function that accepts a list of strings. | |
| The list contains different words. Return the word with maximum number | |
| of unique characters. If multiple strings have maximum number of unique | |
| characters, return the one which comes first in lexicographical order. | |
| """"""","def problem_spec | |
| -- function signature | |
| (impl: List String β String) | |
| -- inputs | |
| (words: List String) := | |
| let unique_chars (string: String) := | |
| let string_idx := {i: Nat | i < string.length}.toFinset; | |
| let characters := string_idx.image (fun i => string.toList.get! i); | |
| characters.card; | |
| -- spec | |
| let spec (result: String) := | |
| (result = """" β words.length = 0) β§ | |
| (words.length != 0 β result β words β§ | |
| let unique_chars_list := words.map unique_chars; | |
| let max_unique_chars := unique_chars_list.max?.get!; | |
| unique_chars result = max_unique_chars β§ | |
| β i : Nat, i < words.length β | |
| unique_chars_list[i]! = max_unique_chars β | |
| result β€ words[i]!); | |
| -- program terminates | |
| β result, impl words = result β§ | |
| -- return value satisfies spec | |
| spec result","def generated_spec | |
| -- function signature | |
| (impl: List String β String) | |
| -- inputs | |
| (words: List String) : Prop :=","theorem spec_isomorphism: | |
| β impl, | |
| (β words, problem_spec impl words) β | |
| (β words, generated_spec impl words) :=",sorry,def implementation (words: List String) : String :=,sorry,"-- #test implementation [""name"", ""of"", ""string""]= ""string"" | |
| -- #test implementation [""name"", ""enam"", ""game""] = ""enam"" | |
| -- #test implementation [""aaaaaaa"", ""bb"" ,""cc""] = ""aaaaaaa""","theorem correctness | |
| (words: List String) | |
| : problem_spec implementation words :=",sorry,,, | |
| "def eat(number: Nat, need: Nat, remaining: Nat) -> List Nat","You're a hungry rabbit, and you already have eaten a certain number of carrots, | |
| but now you need to eat more carrots to complete the day's meals. | |
| you should return an array of [ total number of eaten carrots after your meals, | |
| the number of carrots left after your meals ] | |
| if there are not enough remaining carrots, you will eat all remaining carrots, but will still be hungry. | |
| Variables: | |
| @number : integer | |
| the number of carrots that you have eaten. | |
| @need : integer | |
| the number of carrots that you need to eat. | |
| @remaining : integer | |
| the number of remaining carrots thet exist in stock | |
| Constrain: | |
| * 0 <= number <= 1000 | |
| * 0 <= need <= 1000 | |
| * 0 <= remaining <= 1000 | |
| ","[{""input"": [5, 6, 10], ""expected_output"": [11, 4]}, {""input"": [4, 8, 9], ""expected_output"": [12, 1]}, {""input"": [1, 10, 10], ""expected_output"": [11, 0]}, {""input"": [2, 11, 5], ""expected_output"": [7, 0]}]","def eat(number: Nat, need: Nat, remaining: Nat) -> List Nat | |
| """"""You're a hungry rabbit, and you already have eaten a certain number of carrots, | |
| but now you need to eat more carrots to complete the day's meals. | |
| you should return an array of [ total number of eaten carrots after your meals, | |
| the number of carrots left after your meals ] | |
| if there are not enough remaining carrots, you will eat all remaining carrots, but will still be hungry. | |
| Variables: | |
| @number : integer | |
| the number of carrots that you have eaten. | |
| @need : integer | |
| the number of carrots that you need to eat. | |
| @remaining : integer | |
| the number of remaining carrots thet exist in stock | |
| Constrain: | |
| * 0 <= number <= 1000 | |
| * 0 <= need <= 1000 | |
| * 0 <= remaining <= 1000 | |
| """"""","def problem_spec | |
| -- function signature | |
| (impl: Nat β Nat β Nat β List Nat) | |
| -- inputs | |
| (number need remaining: Nat) := | |
| -- spec | |
| let spec (result: List Nat) := | |
| number β€ 1000 β need β€ 1000 β remaining β€ 1000 β | |
| result.length = 2 β§ | |
| (need β€ remaining β result[0]! - need = number β§ | |
| need = remaining - result[1]!) β§ | |
| (remaining < need β result[0]! - remaining = number β§ | |
| result[1]! = 0); | |
| -- program terminates | |
| β result, impl number need remaining = result β§ | |
| -- return value satisfies spec | |
| spec result","def generated_spec | |
| -- function signature | |
| (impl: Nat β Nat β Nat β List Nat) | |
| -- inputs | |
| (a b c : Nat) : 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 b c: Nat) : List Nat :=,sorry,"-- #test implementation 5 6 10 = [11, 4] | |
| -- #test implementation 4 8 9 = [12, 1] | |
| -- #test implementation 1 10 10 = [11, 0] | |
| -- #test implementation 2 11 5 = [7, 0]","theorem correctness | |
| (a b c: Nat) | |
| : problem_spec implementation a b c :=",sorry,,, | |
| "def do_algebra(operator: List String, operand: List Nat) -> Int","Given two lists operator, and operand. The first list has basic algebra operations, and | |
| the second list is a list of integers. Use the two given lists to build the algebric | |
| expression and return the evaluation of this expression. | |
| The basic algebra operations: | |
| Addition ( + ) | |
| Subtraction ( - ) | |
| Multiplication ( * ) | |
| Floor division ( // ) | |
| Exponentiation ( ** ) | |
| Note: | |
| The length of operator list is equal to the length of operand list minus one. | |
| Operand is a list of of non-negative integers. | |
| Operator list has at least one operator, and operand list has at least two operands. | |
| ","[{""input"": [[""+"", ""*"", ""-""], [2, 3, 4, 5]], ""expected_output"": 9}]","def do_algebra(operator: List String, operand: List Nat) -> Int | |
| """"""Given two lists operator, and operand. The first list has basic algebra operations, and | |
| the second list is a list of integers. Use the two given lists to build the algebric | |
| expression and return the evaluation of this expression. | |
| The basic algebra operations: | |
| Addition ( + ) | |
| Subtraction ( - ) | |
| Multiplication ( * ) | |
| Floor division ( // ) | |
| Exponentiation ( ** ) | |
| Note: | |
| The length of operator list is equal to the length of operand list minus one. | |
| Operand is a list of of non-negative integers. | |
| Operator list has at least one operator, and operand list has at least two operands. | |
| """"""","def problem_spec | |
| -- function signature | |
| (impl: List String β List Nat β Int) | |
| -- inputs | |
| (operator : List String) | |
| (operand : List Nat) := | |
| -- spec | |
| let spec (result: Int) := | |
| operator.length = operand.length - 1 β§ 0 < operator.length β§ operand.all (fun n => 0 β€ n) β | |
| let inline_tokens : List String := mergeAlternately operand operator | |
| evalArith_precedence inline_tokens result | |
| -- program terminates | |
| β result, impl operator operand = result β§ | |
| -- return value satisfies spec | |
| spec result","def generated_spec | |
| -- function signature | |
| (impl: List String β List Nat β Int) | |
| -- inputs | |
| (operator : List String) | |
| (operand : List Nat) : Prop :=","theorem spec_isomorphism: | |
| β impl, | |
| (β operator operand, problem_spec impl operator operand) β | |
| (β operator operand, generated_spec impl operator operand) :=",sorry,def implementation (operator: List String) (operand : List Nat) : Int :=,sorry,"-- #test implementation ['+', '*', '-'] [2,3,4,5] = 9","theorem correctness | |
| (operator : List String) (operand : List Nat) | |
| : problem_spec implementation operator operand :=",sorry,"/-- | |
| name: mergeAlternately | |
| use: | | |
| Helper Methods to mergeAlternately a list of strings | |
| problems: | |
| - 160 | |
| sample_problems: [] | |
| -/ | |
| def mergeAlternately : List Nat β List String β List String | |
| | [], [] => [] | |
| | [], y :: ys => y :: mergeAlternately [] ys | |
| | x :: xs, [] => x.repr :: mergeAlternately xs [] | |
| | x :: xs, y :: ys => x.repr :: y :: mergeAlternately xs ys | |
| /-- | |
| name: applyOp | |
| use: | | |
| Helper method to apply operations on two integers | |
| problems: | |
| - 160 | |
| sample_problems: [] | |
| -/ | |
| def applyOp (x y : Int) : String β Option Int | |
| | ""+"" => some (x + y) | |
| | ""-"" => some (x - y) | |
| | ""*"" => some (x * y) | |
| | ""//"" => if y == 0 then none else some (x / y) | |
| | ""**"" => | |
| if x < 0 then none | |
| else some (Int.ofNat ((Int.toNat x) ^ (Int.toNat y))) | |
| | _ => none | |
| /-- | |
| name: evalArith_pass | |
| use: | | |
| Noncomputable relational spec for a single step evaluation (any op, ignoring precedence). | |
| problems: | |
| - 160 | |
| sample_problems: [] | |
| -/ | |
| inductive evalArith_pass : List String β Int β Prop | |
| | num {s : String} {n : Nat} (h : s.toNat! = n) : | |
| evalArith_pass [s] (Int.ofNat n) | |
| | binOp {ts1 ts2 : List String} {op : String} {r1 r2 r : Int} | |
| (h1 : evalArith_pass ts1 r1) | |
| (h2 : evalArith_pass ts2 r2) | |
| (hop : applyOp r1 r2 op = some r) : | |
| evalArith_pass (ts1 ++ op :: ts2) r | |
| /-- | |
| name: evalArith_exp | |
| use: | | |
| Relational spec for exponentiation (highest precedence). | |
| problems: | |
| - 160 | |
| sample_problems: [] | |
| -/ | |
| inductive evalArith_exp : List String β Int β Prop | |
| | of_pass {ts r} (h : evalArith_pass ts r) : evalArith_exp ts r | |
| | step {ts1 ts2 r1 r2 r} (h1 : evalArith_exp ts1 r1) (h2 : evalArith_exp ts2 r2) | |
| (hop : applyOp r1 r2 ""**"" = some r) : | |
| evalArith_exp (ts1 ++ ""**"" :: ts2) r | |
| /-- | |
| name: evalArith_mul | |
| use: | | |
| Relational spec for multiplication/division (middle precedence). | |
| problems: | |
| - 160 | |
| sample_problems: [] | |
| -/ | |
| inductive evalArith_mul : List String β Int β Prop | |
| | of_exp {ts r} (h : evalArith_exp ts r) : evalArith_mul ts r | |
| | step {ts1 ts2 r1 r2 r} (h1 : evalArith_mul ts1 r1) (h2 : evalArith_mul ts2 r2) | |
| (hop : applyOp r1 r2 ""*"" = some r β¨ applyOp r1 r2 ""//"" = some r) : | |
| evalArith_mul (ts1 ++ ""*"" :: ts2) r | |
| /-- | |
| name: evalArith_mul | |
| use: | | |
| Relational spec for addition/subtraction (lowest precedence). | |
| problems: | |
| - 160 | |
| sample_problems: [] | |
| -/ | |
| inductive evalArith_add : List String β Int β Prop | |
| | of_mul {ts r} (h : evalArith_mul ts r) : evalArith_add ts r | |
| | step {ts1 ts2 r1 r2 r} (h1 : evalArith_add ts1 r1) (h2 : evalArith_add ts2 r2) | |
| (hop : applyOp r1 r2 ""+"" = some r β¨ applyOp r1 r2 ""-"" = some r) : | |
| evalArith_add (ts1 ++ ""+"" :: ts2) r | |
| /-- | |
| name: evalArith_mul | |
| use: | | |
| Main function to evaluate an expression | |
| problems: | |
| - 160 | |
| sample_problems: [] | |
| -/ | |
| def evalArith_precedence (ts : List String) (r : Int) : Prop := | |
| evalArith_add ts r",, | |
| def solve(string : String) -> String,"You are given a string s. | |
| if s[i] is a letter, reverse its case from lower to upper or vise versa, | |
| otherwise keep it as it is. | |
| If the string contains no letters, reverse the string. | |
| The function should return the resulted string. | |
| ","[{""input"": ""1234"", ""expected_output"": ""4321""}, {""input"": ""ab"", ""expected_output"": ""AB""}, {""input"": ""#a@C"", ""expected_output"": ""#A@c""}]","def solve(string : String) -> String | |
| """"""You are given a string s. | |
| if s[i] is a letter, reverse its case from lower to upper or vise versa, | |
| otherwise keep it as it is. | |
| If the string contains no letters, reverse the string. | |
| The function should return the resulted string. | |
| """"""","def problem_spec | |
| -- function signature | |
| (impl: String β String) | |
| -- inputs | |
| (string : String) := | |
| -- spec | |
| let spec (result: String) := | |
| result.length = string.length β§ | |
| let hasNoAlphabet := string.all (Ξ» c => not (c.isAlpha)); | |
| (hasNoAlphabet β | |
| result.toList = string.toList.reverse) β§ | |
| (hasNoAlphabet = false β | |
| β i, i < string.length β | |
| let c := string.get! β¨iβ©; | |
| (c.isAlpha β ((c.isLower β c.toUpper = result.get! β¨iβ©) β¨ | |
| (c.isUpper β c.toLower = result.get! β¨iβ©))) β§ | |
| (Β¬ c.isAlpha β c = result.get! β¨iβ©)) | |
| -- program terminates | |
| β result, impl string = result β§ | |
| -- return value satisfies spec | |
| spec result","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 ""1234"" = ""4321"" | |
| -- #test implementation ""ab"" = ""AB"" | |
| -- #test implementation ""#a@C"" = ""#A@c""","theorem correctness | |
| (s: String) | |
| : problem_spec implementation s :=",sorry,,, | |
| "def generate_integers(a : Nat, b : Nat) -> List Nat","Given two positive integers a and b, return the even digits between a | |
| and b, in ascending order. | |
| ","[{""input"": [2, 8], ""expected_output"": [2, 4, 6, 8]}, {""input"": [8, 2], ""expected_output"": [2, 4, 6, 8]}, {""input"": [10, 14], ""expected_output"": [10, 12, 14]}]","def generate_integers(a : Nat, b : Nat) -> List Nat | |
| """"""Given two positive integers a and b, return the even digits between a | |
| and b, in ascending order. | |
| """"""","def problem_spec | |
| -- function signature | |
| (impl: Nat β Nat β List Nat) | |
| -- inputs | |
| (a b : Nat) := | |
| let isAscendingBy2 (r : List Nat) := | |
| β i, i < r.length - 1 β r[i+1]! - r[i]! = 2 | |
| -- spec | |
| let spec (result: List Nat) := | |
| result.all (fun n => n % 2 = 0) β§ isAscendingBy2 result β§ | |
| 1 < result.length β§ | |
| let min_a_b := min a b; | |
| let max_a_b := max a b; | |
| if min_a_b = max_a_b β§ (min_a_b % 2 = 1) | |
| then result = [] | |
| else ((result[0]! = if 2 β£ min_a_b then min_a_b else (min_a_b + 1)) β§ | |
| (result[result.length-1]! = if 2 β£ max_a_b then max_a_b else max_a_b - 1)) | |
| -- program terminates | |
| β result, impl a b = result β§ | |
| -- return value satisfies spec | |
| spec result","def generated_spec | |
| -- function signature | |
| (impl: Nat β Nat β List Nat) | |
| -- inputs | |
| (a b : Nat) : Prop :=","theorem spec_isomorphism: | |
| β impl, | |
| (β a b, problem_spec impl a b) β | |
| (β a b, generated_spec impl a b) :=",sorry,def implementation (a b: Nat) : List Nat :=,sorry,"-- #test implementation 2 8 = [2, 4, 6, 8] | |
| -- #test implementation 8 2 = [2, 4, 6, 8] | |
| -- #test implementation 10 14 = [10, 12, 14]","theorem correctness | |
| (a b: Nat) | |
| : problem_spec implementation a b :=",sorry,,, | |