diff --git "a/benchmark.csv" "b/benchmark.csv" new file mode 100644--- /dev/null +++ "b/benchmark.csv" @@ -0,0 +1,7945 @@ +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, +/ 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, +/ 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,,,