From 8f684a88ca65381db307cc307a0260d6116f659f Mon Sep 17 00:00:00 2001 From: alex28sh Date: Tue, 3 Dec 2024 20:16:30 +0100 Subject: [PATCH] renamed vars --- Bench/001-separate-paren-groups.py | 62 +++---- Bench/003-below-zero.py | 32 ++-- Bench/006-parse_nested_parens.py | 126 ++++++------- Bench/007-filter_by_substring.py | 56 +++--- Bench/008-sum-product.py | 24 +-- Bench/010-is_palindrome.py | 74 ++++---- Bench/011-string_xor.py | 42 ++--- Bench/012-longest.py | 58 +++--- Bench/016-count_distinct_characters.py | 32 ++-- Bench/020-find-closest-elements.py | 108 +++++------ Bench/024-largest-divisor.py | 8 +- Bench/026-remove_duplicates.py | 38 ++-- Bench/027-flip_case.py | 8 +- Bench/029-filter_by_prefix.py | 22 +-- Bench/030-get-positive.py | 72 ++++---- Bench/031-is-prime.py | 26 +-- Bench/033-sort_third.py | 132 ++++++------- Bench/034-unique.py | 210 ++++++++++----------- Bench/035-max-element.py | 28 +-- Bench/036-fizz_buzz.py | 28 +-- Bench/037-sort_even.py | 132 ++++++------- Bench/040-triples-sum-to-zero.py | 82 ++++----- Bench/042-incr-list.py | 20 +- Bench/043-pairs-sum-to-zero.py | 60 +++--- Bench/046-fib4.py | 36 ++-- Bench/048-is-palindrome.py | 18 +- Bench/049-modp.py | 14 +- Bench/050-encode_shift.py | 48 ++--- Bench/051-remove-vowels.py | 38 ++-- Bench/052-below-threshold.py | 18 +- Bench/054-same-chars.py | 8 +- Bench/055-fib.py | 24 +-- Bench/056-correct_bracketing.py | 12 +- Bench/057-monotonic.py | 44 ++--- Bench/058-common.py | 58 +++--- Bench/060-sum-to-n.py | 12 +- Bench/062-derivative.py | 20 +- Bench/063-fibfib.py | 30 +-- Bench/064-vowel_count.py | 18 +- Bench/066-digitSum.py | 16 +- Bench/068-pluck.py | 58 +++--- Bench/069-search.py | 14 +- Bench/070-strange_sort_list.py | 122 ++++++------ Bench/072-will_it_fly.py | 50 ++--- Bench/073-smallest_change.py | 16 +- Bench/075-is_multiply_prime.py | 246 ++++++++++++------------- Bench/078-hex_key.py | 16 +- Bench/080-is_happy.py | 18 +- Bench/082-prime-length.py | 26 +-- Bench/084-solve.py | 12 +- Bench/085-add.py | 12 +- Bench/088-sort_array.py | 134 +++++++------- Bench/089-encrypt.py | 44 ++--- Bench/093-encode.py | 36 ++-- Bench/096-count_up_to.py | 28 +-- Bench/098-count_upper.py | 20 +- Bench/100-make_a_pile.py | 22 +-- Bench/102-choose_num.py | 22 +-- Bench/104-unique_digits.py | 222 +++++++++++----------- Bench/105-by_length.py | 200 ++++++++++---------- Bench/106-f.py | 84 ++++----- Bench/108-count_nums.py | 14 +- Bench/109-move_one_ball.py | 82 ++++----- Bench/110-exchange.py | 4 +- Bench/112-reverse_delete.py | 66 +++---- Bench/114-minSubArraySum.py | 70 +++---- Bench/116-sort_array.py | 80 ++++---- Bench/118-get_closest_vowel.py | 28 +-- Bench/119-match_parens.py | 24 +-- Bench/121-solution.py | 12 +- Bench/122-add_elements.py | 18 +- Bench/123-get_odd_collatz.py | 156 ++++++++-------- Bench/126-is_sorted.py | 74 ++++---- Bench/127-intersection.py | 14 +- Bench/128-prod_signs.py | 32 ++-- Bench/133-sum-squares.py | 14 +- Bench/135_can_arrange.py | 36 ++-- Bench/136-largest_smallest_integers.py | 50 ++--- Bench/139-special_factorial.py | 22 +-- Bench/142-sum_squares.py | 16 +- Bench/146_specialFilter.py | 40 ++-- Bench/150-x_or_y.py | 6 +- Bench/151-double_the_difference.py | 16 +- Bench/152-compare.py | 18 +- Bench/154-cycpattern_check.py | 28 +-- Bench/155_even_odd_count.py | 16 +- Bench/161-solve.py | 74 ++++---- Bench/163-generate_integers.py | 40 ++-- 88 files changed, 2173 insertions(+), 2173 deletions(-) diff --git a/Bench/001-separate-paren-groups.py b/Bench/001-separate-paren-groups.py index 33cc29b..a9f22d5 100644 --- a/Bench/001-separate-paren-groups.py +++ b/Bench/001-separate-paren-groups.py @@ -64,50 +64,50 @@ def IsValidParentheses1(s : List[int], i : int, depth : int) -> bool : def separate__paren__groups(paren__string : List[int]) -> List[List[int]]: # pre-conditions-start Requires(Acc(list_pred(paren__string))) - Requires(Forall(int, lambda d_0_i_: - not (((d_0_i_) >= (0)) and ((d_0_i_) < (len(paren__string)))) or ((((paren__string)[d_0_i_]) == (0)) or (((paren__string)[d_0_i_]) == (1))))) - Requires(Forall(int, lambda d_1_i_: - not (((0) <= (d_1_i_)) and ((d_1_i_) <= (len(paren__string)))) or (IsValidParentheses(paren__string, d_1_i_, 0)))) + Requires(Forall(int, lambda i: + not (((i) >= (0)) and ((i) < (len(paren__string)))) or ((((paren__string)[i]) == (0)) or (((paren__string)[i]) == (1))))) + Requires(Forall(int, lambda i: + not (((0) <= (i)) and ((i) <= (len(paren__string)))) or (IsValidParentheses(paren__string, i, 0)))) Requires(IsValidParentheses2(paren__string, 0, 0)) # pre-conditions-end # post-conditions-start Ensures(Acc(list_pred(ResultT(List[List[int]])))) Ensures(Forall(ResultT(List[List[int]]), lambda x: Acc(list_pred(x), 1/2))) - Ensures((Forall(int, lambda d_2_i_: - not (((0) <= (d_2_i_)) and ((d_2_i_) < (len(Result())))) or (IsValidParentheses1((Result())[d_2_i_], 0, 0))))) + Ensures((Forall(int, lambda i: + not (((0) <= (i)) and ((i) < (len(Result())))) or (IsValidParentheses1((Result())[i], 0, 0))))) # post-conditions-end # impl-start res : List[List[int]] = [] - d_3_current__string_ : List[int] = [] - d_4_current__depth_ : int = int(0) - d_5_i_ : int = int(0) - while (d_5_i_) < (len(paren__string)): + current__string : List[int] = [] + current__depth : int = int(0) + i : int = int(0) + while (i) < (len(paren__string)): # invariants-start Invariant(Acc(list_pred(res))) - Invariant(Acc(list_pred(d_3_current__string_))) + Invariant(Acc(list_pred(current__string))) Invariant(Acc(list_pred(paren__string))) - Invariant(Forall(res, lambda d_4_i_: Acc(list_pred(d_4_i_), 1/2))) - Invariant(((0) <= (d_5_i_)) and ((d_5_i_) <= (len(paren__string)))) - Invariant(Forall(int, lambda d_0_i_: - not (((d_0_i_) >= (0)) and ((d_0_i_) < (len(paren__string)))) or ((((paren__string)[d_0_i_]) == (0)) or (((paren__string)[d_0_i_]) == (1))))) - Invariant(Forall(int, lambda d_1_i_: - not (((0) <= (d_1_i_)) and ((d_1_i_) <= (len(paren__string)))) or (IsValidParentheses(paren__string, d_1_i_, 0)))) - Invariant((Forall(int, lambda d_6_i1_: - not (((0) <= (d_6_i1_)) and ((d_6_i1_) < (len(res)))) or (IsValidParentheses1((res)[d_6_i1_], 0, 0))))) - Invariant(IsValidParentheses(paren__string, d_5_i_, 0)) + Invariant(Forall(res, lambda i: Acc(list_pred(i), 1/2))) + Invariant(((0) <= (i)) and ((i) <= (len(paren__string)))) + Invariant(Forall(int, lambda i: + not (((i) >= (0)) and ((i) < (len(paren__string)))) or ((((paren__string)[i]) == (0)) or (((paren__string)[i]) == (1))))) + Invariant(Forall(int, lambda i: + not (((0) <= (i)) and ((i) <= (len(paren__string)))) or (IsValidParentheses(paren__string, i, 0)))) + Invariant((Forall(int, lambda i1: + not (((0) <= (i1)) and ((i1) < (len(res)))) or (IsValidParentheses1((res)[i1], 0, 0))))) + Invariant(IsValidParentheses(paren__string, i, 0)) # invariants-end - d_7_c_ = (paren__string)[d_5_i_] - if (d_7_c_) == (0): - d_4_current__depth_ = (d_4_current__depth_) + (1) - d_3_current__string_ = (d_3_current__string_) + [d_7_c_] - elif (d_7_c_) == (1): - d_4_current__depth_ = (d_4_current__depth_) - (1) - d_3_current__string_ = (d_3_current__string_) + [d_7_c_] - if (d_4_current__depth_) == (0): - res = (res) + [d_3_current__string_] - d_3_current__string_ = [] - d_5_i_ = (d_5_i_) + (1) + c = (paren__string)[i] + if (c) == (0): + current__depth = (current__depth) + (1) + current__string = (current__string) + [c] + elif (c) == (1): + current__depth = (current__depth) - (1) + current__string = (current__string) + [c] + if (current__depth) == (0): + res = (res) + [current__string] + current__string = [] + i = (i) + (1) return res # impl-end diff --git a/Bench/003-below-zero.py b/Bench/003-below-zero.py index 5843bbb..a314bfa 100644 --- a/Bench/003-below-zero.py +++ b/Bench/003-below-zero.py @@ -21,34 +21,34 @@ def below__zero(ops : List[int]) -> bool: # pre-conditions-end # post-conditions-start Ensures(Acc(list_pred(ops))) - Ensures(not (Result()) or (Forall(int, lambda d_1_i_: - not (((0) <= (d_1_i_)) and ((d_1_i_) <= (len(ops)))) or ((psum(0, d_1_i_, ops)) >= (0))))) - Ensures(not (not(Result())) or (Exists(int, lambda d_2_i_: - (((0) <= (d_2_i_)) and ((d_2_i_) <= (len(ops)))) and ((psum(0, d_2_i_, ops)) < (0))))) + Ensures(not (Result()) or (Forall(int, lambda i: + not (((0) <= (i)) and ((i) <= (len(ops)))) or ((psum(0, i, ops)) >= (0))))) + Ensures(not (not(Result())) or (Exists(int, lambda i: + (((0) <= (i)) and ((i) <= (len(ops)))) and ((psum(0, i, ops)) < (0))))) # post-conditions-end # impl-start - d_3_balance_ : int = 0 - d_4_i_ : int = 0 + balance : int = 0 + i : int = 0 - while (d_4_i_) < (len(ops)): + while (i) < (len(ops)): # invariants-start Invariant(Acc(list_pred(ops))) - Invariant(((0) <= (d_4_i_)) and ((d_4_i_) <= (len(ops)))) - Invariant((d_3_balance_) == (psum(0, d_4_i_, ops))) - Invariant(Forall(int, lambda d_2_i_: (not (((0) <= (d_2_i_)) and ((d_2_i_) < (len(ops)))) or ((psum(0, d_2_i_ + 1, ops)) == (psum(0, d_2_i_, ops) + ops[d_2_i_])), [[psum(0, d_2_i_ + 1, ops)]]))) - Invariant(Forall(int, lambda d_5_j_: - (not (((0) <= (d_5_j_)) and ((d_5_j_) <= (d_4_i_))) or ((psum(0, d_5_j_, ops)) >= (0)), [[psum(0, d_5_j_, ops)]]))) + Invariant(((0) <= (i)) and ((i) <= (len(ops)))) + Invariant((balance) == (psum(0, i, ops))) + Invariant(Forall(int, lambda i: (not (((0) <= (i)) and ((i) < (len(ops)))) or ((psum(0, i + 1, ops)) == (psum(0, i, ops) + ops[i])), [[psum(0, i + 1, ops)]]))) + Invariant(Forall(int, lambda j: + (not (((0) <= (j)) and ((j) <= (i))) or ((psum(0, j, ops)) >= (0)), [[psum(0, j, ops)]]))) # invariants-end # assert-start - Assert((psum(0, (d_4_i_) + (1), ops)) == ((psum(0, d_4_i_, ops)) + ((ops)[d_4_i_]))) + Assert((psum(0, (i) + (1), ops)) == ((psum(0, i, ops)) + ((ops)[i]))) # assert-end - d_3_balance_ = (d_3_balance_) + ((ops)[d_4_i_]) - if (d_3_balance_) < (0): + balance = (balance) + ((ops)[i]) + if (balance) < (0): return False - d_4_i_ = (d_4_i_) + (1) + i = (i) + (1) return True # impl-end diff --git a/Bench/006-parse_nested_parens.py b/Bench/006-parse_nested_parens.py index 9d7271c..19e71f8 100644 --- a/Bench/006-parse_nested_parens.py +++ b/Bench/006-parse_nested_parens.py @@ -15,25 +15,25 @@ def parseparengroup(s : List[int]) -> int: # post-conditions-end # impl-start - d_1_depth_ : int = 0 + depth : int = 0 max__depth : int = 0 - d_2_i_ : int = 0 - while (d_2_i_) < (len(s)): + i : int = 0 + while (i) < (len(s)): # invariants-start Invariant(Acc(list_pred(s), 1/2)) - Invariant(((d_2_i_) >= (0)) and ((d_2_i_) <= (len(s)))) + Invariant(((i) >= (0)) and ((i) <= (len(s)))) Invariant(max__depth >= 0) Invariant(contains12(s)) Invariant(get_len(s)) # invariants-end - d_3_c_ : int = (s)[d_2_i_] - if (d_3_c_) == (1): - d_1_depth_ = (d_1_depth_) + (1) - if (d_1_depth_) > (max__depth): - max__depth = d_1_depth_ + c : int = (s)[i] + if (c) == (1): + depth = (depth) + (1) + if (depth) > (max__depth): + max__depth = depth else: - d_1_depth_ = (d_1_depth_) - (1) - d_2_i_ = (d_2_i_) + (1) + depth = (depth) - (1) + i = (i) + (1) return max__depth # impl-end @@ -54,97 +54,97 @@ def contains12(s : List[int]) -> bool: # pre-conditions-end # pure-start - return Forall(int, lambda d_0_i_: - Implies(d_0_i_ >= 0 and d_0_i_ < len(s), s[d_0_i_] == 1 or s[d_0_i_] == 2)) + return Forall(int, lambda i: + Implies(i >= 0 and i < len(s), s[i] == 1 or s[i] == 2)) # pure-end def split(s : List[int]) -> List[List[int]]: # pre-conditions-start Requires(Acc(list_pred(s))) - Requires(Forall(int, lambda d_4_i_: - not (((d_4_i_) >= (0)) and ((d_4_i_) < (len(s)))) or (((((s)[d_4_i_]) == (1)) or (((s)[d_4_i_]) == (2))) or (((s)[d_4_i_]) == (3))))) + Requires(Forall(int, lambda i: + not (((i) >= (0)) and ((i) < (len(s)))) or (((((s)[i]) == (1)) or (((s)[i]) == (2))) or (((s)[i]) == (3))))) # pre-conditions-end # post-conditions-start Ensures(Acc(list_pred(ResultT(List[List[int]])))) Ensures(Forall(ResultT(List[List[int]]), lambda x: Acc(list_pred(x), 1/2))) - Ensures(Forall(int, lambda d_10_j_: - Implies(d_10_j_ >= 0 and d_10_j_ < len(ResultT(List[List[int]])), (get_len(ResultT(List[List[int]])[d_10_j_]))))) - Ensures(Forall(int, lambda d_10_j_: - (Implies(d_10_j_ >= 0 and d_10_j_ < len(Result()), - contains12(Result()[d_10_j_])), [[contains12(Result()[d_10_j_])]]))) + Ensures(Forall(int, lambda j: + Implies(j >= 0 and j < len(ResultT(List[List[int]])), (get_len(ResultT(List[List[int]])[j]))))) + Ensures(Forall(int, lambda j: + (Implies(j >= 0 and j < len(Result()), + contains12(Result()[j])), [[contains12(Result()[j])]]))) # post-conditions-end # impl-start res : List[List[int]] = [] - d_7_current__string_ : List[int] = [] - d_8_i_ : int = 0 - while (d_8_i_) < (len(s)): + current__string : List[int] = [] + i : int = 0 + while (i) < (len(s)): # invariants-start Invariant(Acc(list_pred(res))) Invariant(Forall(res, lambda x: Acc(list_pred(x), 1/2))) - Invariant(Acc(list_pred(d_7_current__string_))) + Invariant(Acc(list_pred(current__string))) Invariant(Acc(list_pred(s))) - Invariant(((d_8_i_) >= (0)) and ((d_8_i_) <= (len(s)))) - Invariant(Forall(int, lambda d_4_i_: - (not (((d_4_i_) >= (0)) and ((d_4_i_) < (len(s)))) or (((((s)[d_4_i_]) == (1)) or - (((s)[d_4_i_]) == (2))) or (((s)[d_4_i_]) == (3))), [[]]))) - Invariant(Forall(int, lambda d_4_i_: - (not (((d_4_i_) >= (0)) and ((d_4_i_) < (len(d_7_current__string_)))) or - (((((d_7_current__string_)[d_4_i_]) == (1)) or (((d_7_current__string_)[d_4_i_]) == (2)))), [[]]))) - Invariant(Forall(int, lambda d_10_j_: - (Implies(d_10_j_ >= 0 and d_10_j_ < len(res), ((get_len(res[d_10_j_])))), [[]]))) - Invariant(Forall(int, lambda d_10_j_: - (Implies(d_10_j_ >= 0 and d_10_j_ < len(res), - contains12(res[d_10_j_])), [[contains12(res[d_10_j_])]]))) + Invariant(((i) >= (0)) and ((i) <= (len(s)))) + Invariant(Forall(int, lambda i: + (not (((i) >= (0)) and ((i) < (len(s)))) or (((((s)[i]) == (1)) or + (((s)[i]) == (2))) or (((s)[i]) == (3))), [[]]))) + Invariant(Forall(int, lambda i: + (not (((i) >= (0)) and ((i) < (len(current__string)))) or + (((((current__string)[i]) == (1)) or (((current__string)[i]) == (2)))), [[]]))) + Invariant(Forall(int, lambda j: + (Implies(j >= 0 and j < len(res), ((get_len(res[j])))), [[]]))) + Invariant(Forall(int, lambda j: + (Implies(j >= 0 and j < len(res), + contains12(res[j])), [[contains12(res[j])]]))) # invariants-end - if ((s)[d_8_i_]) == (3): - if len(d_7_current__string_) > 0: - d_7_copy = list(d_7_current__string_) + if ((s)[i]) == (3): + if len(current__string) > 0: + d_7_copy = list(current__string) res = (res) + [d_7_copy] - d_7_current__string_ = [] + current__string = [] else: - d_7_current__string_ = (d_7_current__string_) + [(s)[d_8_i_]] - d_8_i_ = (d_8_i_) + (1) - if len(d_7_current__string_) > 0: - d_7_copy = list(d_7_current__string_) + current__string = (current__string) + [(s)[i]] + i = (i) + (1) + if len(current__string) > 0: + d_7_copy = list(current__string) # assert-start Assert(get_len(d_7_copy)) # assert-end res = (res) + [d_7_copy] - d_7_current__string_ = [] + current__string = [] return res # impl-end def parse__nested__parens(paren__string : List[int]) -> List[int]: # pre-conditions-start Requires(Acc(list_pred(paren__string))) - Requires(Forall(int, lambda d_12_i_: - not (((d_12_i_) >= (0)) and ((d_12_i_) < (len(paren__string)))) or (((((paren__string)[d_12_i_]) == (3)) or (((paren__string)[d_12_i_]) == (1))) or (((paren__string)[d_12_i_]) == (2))))) + Requires(Forall(int, lambda i: + not (((i) >= (0)) and ((i) < (len(paren__string)))) or (((((paren__string)[i]) == (3)) or (((paren__string)[i]) == (1))) or (((paren__string)[i]) == (2))))) # pre-conditions-end # post-conditions-start Ensures(Acc(list_pred(Result()))) - Ensures(Forall(ResultT(List[int]), lambda d_13_x_: ((d_13_x_) >= (0)))) + Ensures(Forall(ResultT(List[int]), lambda x: ((x) >= (0)))) # post-conditions-end # impl-start res : List[int] = [] - d_14_strings_ : List[List[int]] = split(paren__string) - d_15_i_ : int = int(0) - while (d_15_i_) < (len(d_14_strings_)): + strings : List[List[int]] = split(paren__string) + i : int = int(0) + while (i) < (len(strings)): # invariants-start - Invariant(Acc(list_pred(d_14_strings_))) + Invariant(Acc(list_pred(strings))) Invariant(Acc(list_pred(res))) - Invariant(Forall(d_14_strings_, lambda x: Acc(list_pred(x), 1/2))) - Invariant(0 <= d_15_i_ and d_15_i_ <= len(d_14_strings_)) - Invariant(Forall(res, lambda d_16_x_: ((d_16_x_) >= (0)))) - Invariant(Forall(int, lambda d_10_j_: - Implies(d_10_j_ >= 0 and d_10_j_ < len(d_14_strings_), (get_len(d_14_strings_[d_10_j_]))))) - Invariant(Forall(int, lambda d_10_j_: - (Implies(d_10_j_ >= 0 and d_10_j_ < len(d_14_strings_), - contains12(d_14_strings_[d_10_j_])), [[contains12(d_14_strings_[d_10_j_])]]))) + Invariant(Forall(strings, lambda x: Acc(list_pred(x), 1/2))) + Invariant(0 <= i and i <= len(strings)) + Invariant(Forall(res, lambda x: ((x) >= (0)))) + Invariant(Forall(int, lambda j: + Implies(j >= 0 and j < len(strings), (get_len(strings[j]))))) + Invariant(Forall(int, lambda j: + (Implies(j >= 0 and j < len(strings), + contains12(strings[j])), [[contains12(strings[j])]]))) # invariants-end - d_17_cur_ : int = parseparengroup((d_14_strings_)[d_15_i_]) - res = (res) + [d_17_cur_] - d_15_i_ = (d_15_i_) + (1) + cur : int = parseparengroup((strings)[i]) + res = (res) + [cur] + i = (i) + (1) return res # impl-end diff --git a/Bench/007-filter_by_substring.py b/Bench/007-filter_by_substring.py index f13016a..6a78aca 100644 --- a/Bench/007-filter_by_substring.py +++ b/Bench/007-filter_by_substring.py @@ -16,13 +16,13 @@ def checkSubstring(s : List[int], sub : List[int]) -> bool: if (len(sub)) == (0): result = True elif (len(s)) >= (len(sub)): - d_0_i_ : int = 0 - while (d_0_i_) <= ((len(s)) - (len(sub))): + i : int = 0 + while (i) <= ((len(s)) - (len(sub))): # invariants-start Invariant(Acc(list_pred(s), 1/2)) Invariant(Acc(list_pred(sub), 1/2)) Invariant(len(s) - len(sub) >= 0) - Invariant(((0) <= (d_0_i_)) and ((d_0_i_) <= 1 + ((len(s)) - (len(sub))))) + Invariant(((0) <= (i)) and ((i) <= 1 + ((len(s)) - (len(sub))))) # invariants-end x = 0 fl = True @@ -31,16 +31,16 @@ def checkSubstring(s : List[int], sub : List[int]) -> bool: Invariant(Acc(list_pred(s), 1/2)) Invariant(Acc(list_pred(sub), 1/2)) Invariant(len(s) - len(sub) >= 0) - Invariant(((0) <= (d_0_i_)) and ((d_0_i_) <= ((len(s)) - (len(sub))))) + Invariant(((0) <= (i)) and ((i) <= ((len(s)) - (len(sub))))) Invariant(x >= 0 and x <= len(sub)) # invariants-end - if sub[x] != s[d_0_i_ + x]: + if sub[x] != s[i + x]: fl = False break x = x + 1 if fl: result = True - d_0_i_ = (d_0_i_) + (1) + i = (i) + (1) return result # impl-end @@ -52,7 +52,7 @@ def EqArrays(a : List[int], x : List[int]) -> bool : # pre-conditions-end # pure-start - return len(a) == len(x) and Forall(int, lambda d_0_i_: Implies(0 <= d_0_i_ and d_0_i_ < len(a), (a)[d_0_i_] == x[d_0_i_])) + return len(a) == len(x) and Forall(int, lambda i: Implies(0 <= i and i < len(a), (a)[i] == x[i])) # pure-end @Pure @@ -60,51 +60,51 @@ def InArray(a : List[List[int]], x : List[int]) -> bool : # pre-conditions-start Requires(Acc(list_pred(a))) Requires(Acc(list_pred(x))) - Requires(Forall(a, lambda d_0_s_: Acc(list_pred(d_0_s_)))) + Requires(Forall(a, lambda s: Acc(list_pred(s)))) # pre-conditions-end # pure-start - return Exists(int, lambda d_0_s_: - (Implies(((0) <= (d_0_s_)) and ((d_0_s_) < (len((a)))), - EqArrays(a[d_0_s_], x)))) + return Exists(int, lambda s: + (Implies(((0) <= (s)) and ((s) < (len((a)))), + EqArrays(a[s], x)))) # pure-end def filter__by__substring(strings : List[List[int]], substring : List[int]) -> List[List[int]]: # pre-conditions-start Requires(Acc(list_pred(strings))) - Requires(Forall(strings, lambda d_0_s_: Acc(list_pred(d_0_s_)))) + Requires(Forall(strings, lambda s: Acc(list_pred(s)))) Requires(Acc(list_pred(substring))) # pre-conditions-end # post-conditions-start Ensures(Acc(list_pred(strings))) - Ensures(Forall(strings, lambda d_0_s_: Acc(list_pred(d_0_s_)))) + Ensures(Forall(strings, lambda s: Acc(list_pred(s)))) Ensures(Acc(list_pred(Result()))) - Ensures(Forall(ResultT(List[List[int]]), lambda d_0_s_: Acc(list_pred(d_0_s_)))) + Ensures(Forall(ResultT(List[List[int]]), lambda s: Acc(list_pred(s)))) Ensures((len(Result())) <= (len(strings))) - Ensures(Forall(int, lambda d_3_i_: - (Implies(0 <= d_3_i_ and d_3_i_ < len(Result()), InArray(strings, Result()[d_3_i_]))))) + Ensures(Forall(int, lambda i: + (Implies(0 <= i and i < len(Result()), InArray(strings, Result()[i]))))) # post-conditions-end # impl-start res : List[List[int]] = [] - d_2_i_ : int = 0 - while (d_2_i_) < (len(strings)): + i : int = 0 + while (i) < (len(strings)): # invariants-start Invariant(Acc(list_pred(res))) Invariant(Acc(list_pred(strings))) Invariant(Acc(list_pred(substring))) - Invariant(Forall(strings, lambda d_0_s_: Acc(list_pred(d_0_s_)))) - Invariant(Forall(res, lambda d_3_s_: Acc(list_pred(d_3_s_)))) - Invariant(((0) <= (d_2_i_)) and ((d_2_i_) <= (len(strings)))) - Invariant((len(res)) <= (d_2_i_)) - Invariant(Forall(int, lambda d_3_i_: - (Implies(0 <= d_3_i_ and d_3_i_ < len(res), InArray(strings, res[d_3_i_])), [[InArray(strings, res[d_3_i_])]]))) + Invariant(Forall(strings, lambda s: Acc(list_pred(s)))) + Invariant(Forall(res, lambda s: Acc(list_pred(s)))) + Invariant(((0) <= (i)) and ((i) <= (len(strings)))) + Invariant((len(res)) <= (i)) + Invariant(Forall(int, lambda i: + (Implies(0 <= i and i < len(res), InArray(strings, res[i])), [[InArray(strings, res[i])]]))) # invariants-end - d_4_check_ : bool = checkSubstring((strings)[d_2_i_], substring) - if d_4_check_: - cpy = list((strings)[d_2_i_]) + check : bool = checkSubstring((strings)[i], substring) + if check: + cpy = list((strings)[i]) res = (res) + [cpy] - d_2_i_ = (d_2_i_) + (1) + i = (i) + (1) return res # impl-end diff --git a/Bench/008-sum-product.py b/Bench/008-sum-product.py index 82ad4e6..3ef4149 100644 --- a/Bench/008-sum-product.py +++ b/Bench/008-sum-product.py @@ -42,25 +42,25 @@ def sum__product(numbers : List[int]) -> Tuple[int, int]: # impl-start s : int = 0 p : int = 1 - d_2_i_ : int = 0 - while (d_2_i_) < (len(numbers)): + i : int = 0 + while (i) < (len(numbers)): # invariants-start Invariant(Acc(list_pred(numbers))) - Invariant(((0) <= (d_2_i_)) and ((d_2_i_) <= (len(numbers)))) - Invariant((s) == (psum(0, d_2_i_, numbers))) - Invariant(Forall(int, lambda d_2_i_: (not (((0) <= (d_2_i_)) and ((d_2_i_) < (len(numbers)))) or ((psum(0, d_2_i_ + 1, numbers)) == (psum(0, d_2_i_, numbers) + numbers[d_2_i_])), [[psum(0, d_2_i_ + 1, numbers)]]))) - Invariant(Forall(int, lambda d_2_i_: (not (((0) <= (d_2_i_)) and ((d_2_i_) < (len(numbers)))) or ((prod(0, d_2_i_ + 1, numbers)) == (prod(0, d_2_i_, numbers) * numbers[d_2_i_])), [[prod(0, d_2_i_ + 1, numbers)]]))) - Invariant((p) == (prod(0, d_2_i_, numbers))) + Invariant(((0) <= (i)) and ((i) <= (len(numbers)))) + Invariant((s) == (psum(0, i, numbers))) + Invariant(Forall(int, lambda i: (not (((0) <= (i)) and ((i) < (len(numbers)))) or ((psum(0, i + 1, numbers)) == (psum(0, i, numbers) + numbers[i])), [[psum(0, i + 1, numbers)]]))) + Invariant(Forall(int, lambda i: (not (((0) <= (i)) and ((i) < (len(numbers)))) or ((prod(0, i + 1, numbers)) == (prod(0, i, numbers) * numbers[i])), [[prod(0, i + 1, numbers)]]))) + Invariant((p) == (prod(0, i, numbers))) # invariants-end # assert-start - Assert((psum(0, (d_2_i_) + (1), numbers)) == ((psum(0, d_2_i_, numbers) + (numbers)[d_2_i_]))) + Assert((psum(0, (i) + (1), numbers)) == ((psum(0, i, numbers) + (numbers)[i]))) # assert-end - s = (s) + ((numbers)[d_2_i_]) + s = (s) + ((numbers)[i]) # assert-start - Assert((prod(0, d_2_i_ + 1, numbers)) == ((prod(0, d_2_i_, numbers)) * ((numbers)[d_2_i_]))) + Assert((prod(0, i + 1, numbers)) == ((prod(0, i, numbers)) * ((numbers)[i]))) # assert-end - p = (p) * ((numbers)[d_2_i_]) - d_2_i_ = (d_2_i_) + (1) + p = (p) * ((numbers)[i]) + i = (i) + (1) return s, p # impl-end diff --git a/Bench/010-is_palindrome.py b/Bench/010-is_palindrome.py index 98e42db..53bfb30 100644 --- a/Bench/010-is_palindrome.py +++ b/Bench/010-is_palindrome.py @@ -11,29 +11,29 @@ def is__palindrome(start : int, s : List[int]) -> bool: Ensures(Acc(list_pred(s), 1/2)) Ensures(((0) <= (start)) and ((start) < (len(s)))) Ensures((len(s)) > (0)) - Ensures((Result()) == (Forall(int, lambda d_0_k_: - not (((start) <= (d_0_k_)) and ((d_0_k_) < (len(s)))) or (((s)[d_0_k_]) == ((s)[((len(s)) - (1)) - (d_0_k_ - start)]))))) + Ensures((Result()) == (Forall(int, lambda k: + not (((start) <= (k)) and ((k) < (len(s)))) or (((s)[k]) == ((s)[((len(s)) - (1)) - (k - start)]))))) Ensures(Result() == is__palindrome__fun(start, s)) # post-conditions-end # impl-start - d_1_i_ : int = start - d_2_j_ : int = (len(s)) - (1) - while (d_1_i_) < (d_2_j_): + i : int = start + j : int = (len(s)) - (1) + while (i) < (j): # invariants-start Invariant(Acc(list_pred(s), 1/2)) Invariant(((0) <= (start)) and ((start) < (len(s)))) - Invariant(d_1_i_ <= d_2_j_ + 1) - Invariant(((start) <= (d_1_i_)) and ((d_1_i_) < (len(s)))) - Invariant(((start) <= (d_2_j_)) and ((d_2_j_) < (len(s)))) - Invariant((d_2_j_ - start) == (((len(s)) - (d_1_i_)) - (1))) - Invariant(Forall(int, lambda d_3_k_: - not (((start) <= (d_3_k_)) and ((d_3_k_) < (d_1_i_))) or (((s)[d_3_k_]) == ((s)[((len(s)) - (1)) - (d_3_k_ - start)])))) + Invariant(i <= j + 1) + Invariant(((start) <= (i)) and ((i) < (len(s)))) + Invariant(((start) <= (j)) and ((j) < (len(s)))) + Invariant((j - start) == (((len(s)) - (i)) - (1))) + Invariant(Forall(int, lambda k: + not (((start) <= (k)) and ((k) < (i))) or (((s)[k]) == ((s)[((len(s)) - (1)) - (k - start)])))) # invariants-end - if ((s)[d_1_i_]) != ((s)[d_2_j_]): + if ((s)[i]) != ((s)[j]): return False - d_1_i_ = (d_1_i_) + (1) - d_2_j_ = (d_2_j_) - (1) + i = (i) + (1) + j = (j) - (1) return True # impl-end @@ -45,8 +45,8 @@ def is__palindrome__fun(start : int, s : List[int]) -> bool : # pre-conditions-end # pure-start - return Forall(int, lambda d_4_k_: - not (((start) <= (d_4_k_)) and ((d_4_k_) < (len(s)))) or (((s)[d_4_k_]) == ((s)[((len(s)) - (1)) - (d_4_k_ - start)]))) + return Forall(int, lambda k: + not (((start) <= (k)) and ((k) < (len(s)))) or (((s)[k]) == ((s)[((len(s)) - (1)) - (k - start)]))) # pure-end @Pure @@ -57,8 +57,8 @@ def starts__with(result : List[int], s : List[int]) -> bool : # pre-conditions-end # pure-start - return ((len(result)) >= (len(s))) and (Forall(int, lambda d_5_k_: - not (((0) <= (d_5_k_)) and ((d_5_k_) < (len(s)))) or (((result)[d_5_k_]) == ((s)[d_5_k_])))) + return ((len(result)) >= (len(s))) and (Forall(int, lambda k: + not (((0) <= (k)) and ((k) < (len(s)))) or (((result)[k]) == ((s)[k])))) # pure-end def make__palindrome(s : List[int]) -> List[int]: @@ -78,19 +78,19 @@ def make__palindrome(s : List[int]) -> List[int]: if (len(s)) == (0): result = [] return result - d_6_beginning__of__suffix_ : int = int(0) - d_8_flag_ : bool = is__palindrome(d_6_beginning__of__suffix_, s) - while not(d_8_flag_): + beginning__of__suffix : int = int(0) + flag : bool = is__palindrome(beginning__of__suffix, s) + while not(flag): # invariants-start Invariant(Acc(list_pred(s))) Invariant(len(s) > 0) - Invariant((((d_6_beginning__of__suffix_) >= (0)) and (((d_6_beginning__of__suffix_) + (1)) < (len(s)))) or ((d_8_flag_) and (((d_6_beginning__of__suffix_) >= (0)) and ((d_6_beginning__of__suffix_) < (len(s)))))) - Invariant(Implies(d_8_flag_, is__palindrome__fun(d_6_beginning__of__suffix_, s))) + Invariant((((beginning__of__suffix) >= (0)) and (((beginning__of__suffix) + (1)) < (len(s)))) or ((flag) and (((beginning__of__suffix) >= (0)) and ((beginning__of__suffix) < (len(s)))))) + Invariant(Implies(flag, is__palindrome__fun(beginning__of__suffix, s))) # invariants-end - d_6_beginning__of__suffix_ = (d_6_beginning__of__suffix_) + (1) - d_8_flag_ = is__palindrome(d_6_beginning__of__suffix_, s) - d_10_reversed_ : List[int] = reverse(d_6_beginning__of__suffix_, s) - result = (s) + (d_10_reversed_) + beginning__of__suffix = (beginning__of__suffix) + (1) + flag = is__palindrome(beginning__of__suffix, s) + reversed : List[int] = reverse(beginning__of__suffix, s) + result = (s) + (reversed) return result # impl-end @@ -105,24 +105,24 @@ def reverse(end : int, str : List[int]) -> List[int]: Ensures(Acc(list_pred(Result()))) Ensures(str == Old(str)) Ensures((len(Result())) == (end)) - Ensures(Forall(int, lambda d_11_k_: - not (((0) <= (d_11_k_)) and ((d_11_k_) < (end))) or (((Result())[d_11_k_]) == ((str)[((end) - (1)) - (d_11_k_)])))) + Ensures(Forall(int, lambda k: + not (((0) <= (k)) and ((k) < (end))) or (((Result())[k]) == ((str)[((end) - (1)) - (k)])))) # post-conditions-end # impl-start rev : List[int] = [] - d_12_i_ : int = 0 - while (d_12_i_) < (end): + i : int = 0 + while (i) < (end): # invariants-start Invariant(Acc(list_pred(str), 1/2)) Invariant(Acc(list_pred(rev))) Invariant(0 <= end and end < len(str)) - Invariant(((d_12_i_) >= (0)) and ((d_12_i_) <= (end))) - Invariant((len(rev)) == (d_12_i_)) - Invariant(Forall(int, lambda d_13_k_: - not (((0) <= (d_13_k_)) and ((d_13_k_) < (d_12_i_))) or (((rev)[d_13_k_]) == ((str)[(end - (1)) - (d_13_k_)])))) + Invariant(((i) >= (0)) and ((i) <= (end))) + Invariant((len(rev)) == (i)) + Invariant(Forall(int, lambda k: + not (((0) <= (k)) and ((k) < (i))) or (((rev)[k]) == ((str)[(end - (1)) - (k)])))) # invariants-end - rev = (rev) + [(str)[(end - (d_12_i_)) - (1)]] - d_12_i_ = (d_12_i_) + (1) + rev = (rev) + [(str)[(end - (i)) - (1)]] + i = (i) + (1) return rev # impl-end diff --git a/Bench/011-string_xor.py b/Bench/011-string_xor.py index 526bcdc..2f43762 100644 --- a/Bench/011-string_xor.py +++ b/Bench/011-string_xor.py @@ -21,10 +21,10 @@ def string__xor(a : List[int], b : List[int]) -> List[int]: Requires(Acc(list_pred(b))) Requires(Acc(list_pred(a))) Requires((len(a)) == (len(b))) - Requires(Forall(int, lambda d_0_i_: - not (((0) <= (d_0_i_)) and ((d_0_i_) < (len(a)))) or ((((a)[d_0_i_]) == (0)) or (((a)[d_0_i_]) == (1))))) - Requires(Forall(int, lambda d_1_i_: - not (((0) <= (d_1_i_)) and ((d_1_i_) < (len(b)))) or ((((b)[d_1_i_]) == (0)) or (((b)[d_1_i_]) == (1))))) + Requires(Forall(int, lambda i: + not (((0) <= (i)) and ((i) < (len(a)))) or ((((a)[i]) == (0)) or (((a)[i]) == (1))))) + Requires(Forall(int, lambda i: + not (((0) <= (i)) and ((i) < (len(b)))) or ((((b)[i]) == (0)) or (((b)[i]) == (1))))) # pre-conditions-end # post-conditions-start Ensures(Acc(list_pred(b))) @@ -32,32 +32,32 @@ def string__xor(a : List[int], b : List[int]) -> List[int]: Ensures(Acc(list_pred(Result()))) Ensures((len(a)) == (len(b))) Ensures((len(Result())) == (len(a))) - Ensures(Forall(int, lambda d_2_i_: - not (((0) <= (d_2_i_)) and ((d_2_i_) < (len(Result())))) or ((((Result())[d_2_i_]) == (0)) or (((Result())[d_2_i_]) == (1))))) - Ensures(Forall(int, lambda d_3_i_: - not (((0) <= (d_3_i_)) and ((d_3_i_) < (len(Result())))) or (((Result())[d_3_i_]) == ((0 if ((a)[d_3_i_]) == ((b)[d_3_i_]) else 1))))) + Ensures(Forall(int, lambda i: + not (((0) <= (i)) and ((i) < (len(Result())))) or ((((Result())[i]) == (0)) or (((Result())[i]) == (1))))) + Ensures(Forall(int, lambda i: + not (((0) <= (i)) and ((i) < (len(Result())))) or (((Result())[i]) == ((0 if ((a)[i]) == ((b)[i]) else 1))))) # post-conditions-end # impl-start result : List[int] = [] - d_4_i_ : int = int(0) - while (d_4_i_) < (len(a)): + i : int = int(0) + while (i) < (len(a)): # invariants-start Invariant(Acc(list_pred(b))) Invariant(Acc(list_pred(a))) Invariant(Acc(list_pred(result))) Invariant((len(a)) == (len(b))) - Invariant(((d_4_i_) >= (0)) and ((d_4_i_) <= (len(a)))) - Invariant((len(result)) == (d_4_i_)) - Invariant(Forall(int, lambda d_0_i_: - not (((0) <= (d_0_i_)) and ((d_0_i_) < (len(a)))) or ((((a)[d_0_i_]) == (0)) or (((a)[d_0_i_]) == (1))))) - Invariant(Forall(int, lambda d_1_i_: - not (((0) <= (d_1_i_)) and ((d_1_i_) < (len(b)))) or ((((b)[d_1_i_]) == (0)) or (((b)[d_1_i_]) == (1))))) - Invariant(Forall(int, lambda d_5_j_: - not (((0) <= (d_5_j_)) and ((d_5_j_) < (d_4_i_))) or (((result)[d_5_j_]) == ((0 if ((a)[d_5_j_]) == ((b)[d_5_j_]) else 1))))) + Invariant(((i) >= (0)) and ((i) <= (len(a)))) + Invariant((len(result)) == (i)) + Invariant(Forall(int, lambda i: + not (((0) <= (i)) and ((i) < (len(a)))) or ((((a)[i]) == (0)) or (((a)[i]) == (1))))) + Invariant(Forall(int, lambda i: + not (((0) <= (i)) and ((i) < (len(b)))) or ((((b)[i]) == (0)) or (((b)[i]) == (1))))) + Invariant(Forall(int, lambda j: + not (((0) <= (j)) and ((j) < (i))) or (((result)[j]) == ((0 if ((a)[j]) == ((b)[j]) else 1))))) # invariants-end - d_6_bitResult_ = (0 if ((a)[d_4_i_]) == ((b)[d_4_i_]) else 1) - result = (result) + [d_6_bitResult_] - d_4_i_ = (d_4_i_) + (1) + bitResult = (0 if ((a)[i]) == ((b)[i]) else 1) + result = (result) + [bitResult] + i = (i) + (1) return result # impl-end diff --git a/Bench/012-longest.py b/Bench/012-longest.py index 6627102..0d8c2ec 100644 --- a/Bench/012-longest.py +++ b/Bench/012-longest.py @@ -14,50 +14,50 @@ def getVal(mx: Optional[int]) -> int: def longest(strings : List[List[int]]) -> Optional[int]: # pre-conditions-start Requires(Acc(list_pred(strings))) - Requires(Forall(strings, lambda d_0_s_: Acc(list_pred(d_0_s_)))) + Requires(Forall(strings, lambda s: Acc(list_pred(s)))) # pre-conditions-end # post-conditions-start Ensures(Acc(list_pred(strings))) - Ensures(Forall(strings, lambda d_0_s_: Acc(list_pred(d_0_s_)))) + Ensures(Forall(strings, lambda s: Acc(list_pred(s)))) Ensures(((Result()) is (None)) == ((len(strings)) == (0))) Ensures(Implies(Result() is not None, getVal(Result()) >= 0 and getVal(Result()) < len(strings))) - Ensures(not ((Result()) is not (None)) or (Forall(int, lambda d_1_s_: - not ((d_1_s_) >= 0 and d_1_s_ < len(strings)) or ((len(strings[getVal(Result())])) >= (len(strings[d_1_s_])))))) - Ensures(not (Result() is not None) or (Exists(int, lambda d_1_s_: - ((d_1_s_) >= 0 and d_1_s_ < len(strings)) and ((len(strings[getVal(Result())])) == (len(strings[d_1_s_])))))) - Ensures(not ((Result()) is not (None)) or (Forall(int, lambda d_4_j_: - (not (((0) <= (d_4_j_)) and ((d_4_j_) < (Result()))) or ((len((strings)[d_4_j_])) < (len(strings[getVal(Result())]))))))) + Ensures(not ((Result()) is not (None)) or (Forall(int, lambda s: + not ((s) >= 0 and s < len(strings)) or ((len(strings[getVal(Result())])) >= (len(strings[s])))))) + Ensures(not (Result() is not None) or (Exists(int, lambda s: + ((s) >= 0 and s < len(strings)) and ((len(strings[getVal(Result())])) == (len(strings[s])))))) + Ensures(not ((Result()) is not (None)) or (Forall(int, lambda j: + (not (((0) <= (j)) and ((j) < (Result()))) or ((len((strings)[j])) < (len(strings[getVal(Result())]))))))) # post-conditions-end # impl-start result : Optional[int] = None if (len(strings)) != (0): - d_5_i_ : int = 0 - d_6_mx_ : int = -1 - while (d_5_i_) < (len(strings)): + i : int = 0 + mx : int = -1 + while (i) < (len(strings)): # invariants-start Invariant(Acc(list_pred(strings))) - Invariant(Forall(strings, lambda d_0_s_: Acc(list_pred(d_0_s_)))) - Invariant(((d_5_i_) >= (0)) and ((d_5_i_) <= (len(strings)))) - Invariant(((d_6_mx_) == (-1)) == ((result) is (None))) - Invariant(not ((d_5_i_) == (0)) or ((d_6_mx_) == (-1))) - Invariant(Implies(result is not None, getVal(result) >= 0 and getVal(result) < d_5_i_)) - Invariant(Implies(result is not None, len(strings[getVal(result)]) == d_6_mx_)) - Invariant(not ((d_5_i_) > (0)) or (result is not None)) - Invariant(not ((d_5_i_) > (0)) or ((d_6_mx_) == (len(strings[getVal(result)])))) - Invariant(not (result is not None) or (Forall(int, lambda d_1_s_: - not ((d_1_s_) >= 0 and d_1_s_ < d_5_i_) or ((len(strings[getVal(result)])) >= (len(strings[d_1_s_])))))) - Invariant(not (result is not None) or (Exists(int, lambda d_1_s_: - ((d_1_s_) >= 0 and d_1_s_ < d_5_i_) and ((len(strings[getVal(result)])) == (len(strings[d_1_s_])))))) - Invariant(not ((result) is not (None)) or (Forall(int, lambda d_4_j_: - (not (((0) <= (d_4_j_)) and ((d_4_j_) < (result))) or ((len((strings)[d_4_j_])) < (len(strings[getVal(result)]))))))) + Invariant(Forall(strings, lambda s: Acc(list_pred(s)))) + Invariant(((i) >= (0)) and ((i) <= (len(strings)))) + Invariant(((mx) == (-1)) == ((result) is (None))) + Invariant(not ((i) == (0)) or ((mx) == (-1))) + Invariant(Implies(result is not None, getVal(result) >= 0 and getVal(result) < i)) + Invariant(Implies(result is not None, len(strings[getVal(result)]) == mx)) + Invariant(not ((i) > (0)) or (result is not None)) + Invariant(not ((i) > (0)) or ((mx) == (len(strings[getVal(result)])))) + Invariant(not (result is not None) or (Forall(int, lambda s: + not ((s) >= 0 and s < i) or ((len(strings[getVal(result)])) >= (len(strings[s])))))) + Invariant(not (result is not None) or (Exists(int, lambda s: + ((s) >= 0 and s < i) and ((len(strings[getVal(result)])) == (len(strings[s])))))) + Invariant(not ((result) is not (None)) or (Forall(int, lambda j: + (not (((0) <= (j)) and ((j) < (result))) or ((len((strings)[j])) < (len(strings[getVal(result)]))))))) # invariants-end - if result is None or (len((strings)[d_5_i_])) > (len(strings[getVal(result)])): - d_6_mx_ = len((strings)[d_5_i_]) - result = d_5_i_ + if result is None or (len((strings)[i])) > (len(strings[getVal(result)])): + mx = len((strings)[i]) + result = i # assert-start Assert(Forall(int, lambda x: Implies(x >= 0 and x < result, len(strings[result]) > len(strings[x])))) # assert-end - d_5_i_ = (d_5_i_) + (1) + i = (i) + (1) return result # impl-end diff --git a/Bench/016-count_distinct_characters.py b/Bench/016-count_distinct_characters.py index 3f71984..785a3d0 100644 --- a/Bench/016-count_distinct_characters.py +++ b/Bench/016-count_distinct_characters.py @@ -5,8 +5,8 @@ def contains_char(s : List[int], c : int, i : int, j : int) -> bool: # pre-conditions-start Requires(Acc(list_pred(s))) - Requires(Forall(int, lambda d_0_i_: - not (((0) <= (d_0_i_)) and ((d_0_i_) < (len(s)))) or (((97) <= ((s)[d_0_i_])) and (((s)[d_0_i_]) <= (122))))) + Requires(Forall(int, lambda i: + not (((0) <= (i)) and ((i) < (len(s)))) or (((97) <= ((s)[i])) and (((s)[i]) <= (122))))) Requires(0 <= i and i <= j and j <= len(s)) Requires(((97) <= (c)) and ((c) <= (122))) # pre-conditions-end @@ -22,8 +22,8 @@ def contains_char(s : List[int], c : int, i : int, j : int) -> bool: def count_chars_inter(s : List[int], c : int) -> int: # pre-conditions-start Requires(Acc(list_pred(s))) - Requires(Forall(int, lambda d_0_i_: - not (((0) <= (d_0_i_)) and ((d_0_i_) < (len(s)))) or (((97) <= ((s)[d_0_i_])) and (((s)[d_0_i_]) <= (122))))) + Requires(Forall(int, lambda i: + not (((0) <= (i)) and ((i) < (len(s)))) or (((97) <= ((s)[i])) and (((s)[i]) <= (122))))) Requires(((97) <= (c)) and ((c) <= (123))) # pre-conditions-end @@ -37,29 +37,29 @@ def count_chars_inter(s : List[int], c : int) -> int: def count_distinct_characters(s : List[int]) -> int: # pre-conditions-start Requires(Acc(list_pred(s))) - Requires(Forall(int, lambda d_1_i_: - not (((0) <= (d_1_i_)) and ((d_1_i_) < (len(s)))) or (((97) <= ((s)[d_1_i_])) and (((s)[d_1_i_]) <= (122))))) + Requires(Forall(int, lambda i: + not (((0) <= (i)) and ((i) < (len(s)))) or (((97) <= ((s)[i])) and (((s)[i]) <= (122))))) # pre-conditions-end # post-conditions-start Ensures(Acc(list_pred(s))) - Ensures(Forall(int, lambda d_1_i_: - not (((0) <= (d_1_i_)) and ((d_1_i_) < (len(s)))) or (((97) <= ((s)[d_1_i_])) and (((s)[d_1_i_]) <= (122))))) + Ensures(Forall(int, lambda i: + not (((0) <= (i)) and ((i) < (len(s)))) or (((97) <= ((s)[i])) and (((s)[i]) <= (122))))) Ensures((Result()) == count_chars_inter(s, 123)) # post-conditions-end # impl-start c : int = int(0) - d_2_i_ : int = int(97) - while (d_2_i_) <= (122): + i : int = int(97) + while (i) <= (122): # invariants-start Invariant(Acc(list_pred(s))) - Invariant(((97) <= (d_2_i_)) and ((d_2_i_) <= (123))) - Invariant(Forall(int, lambda d_1_i_: - not (((0) <= (d_1_i_)) and ((d_1_i_) < (len(s)))) or (((97) <= ((s)[d_1_i_])) and (((s)[d_1_i_]) <= (122))))) - Invariant(c == count_chars_inter(s, d_2_i_)) + Invariant(((97) <= (i)) and ((i) <= (123))) + Invariant(Forall(int, lambda i: + not (((0) <= (i)) and ((i) < (len(s)))) or (((97) <= ((s)[i])) and (((s)[i]) <= (122))))) + Invariant(c == count_chars_inter(s, i)) # invariants-end - if contains_char(s, d_2_i_, 0, len(s)): + if contains_char(s, i, 0, len(s)): c = c + 1 - d_2_i_ = d_2_i_ + 1 + i = i + 1 return c # impl-end diff --git a/Bench/020-find-closest-elements.py b/Bench/020-find-closest-elements.py index 20a87d8..99078a8 100644 --- a/Bench/020-find-closest-elements.py +++ b/Bench/020-find-closest-elements.py @@ -23,84 +23,84 @@ def find__closest__elements(s : List[int]) -> Tuple[int, int]: # post-conditions-start Ensures(Acc(list_pred(s))) Ensures(len(s) >= 2) - Ensures(Exists(int, lambda d_0_a_: - Exists(int, lambda d_1_b_: - ((0 <= d_0_a_ and d_0_a_ < d_1_b_ and d_1_b_ < len(s)) and ((Result()[0]) == ((s)[d_0_a_])) and (Result()[1]) == ((s)[d_1_b_]))))) - Ensures(Forall(int, lambda d_2_a_: - Forall(int, lambda d_3_b_: - Implies((0 <= d_2_a_ and (d_2_a_) < (len(s)) and 0 <= d_3_b_ and d_3_b_ < len(s)) and (d_2_a_ != d_3_b_), (dist(Result()[0], Result()[1])) <= (dist((s)[d_2_a_], (s)[d_3_b_])))))) + Ensures(Exists(int, lambda a: + Exists(int, lambda b: + ((0 <= a and a < b and b < len(s)) and ((Result()[0]) == ((s)[a])) and (Result()[1]) == ((s)[b]))))) + Ensures(Forall(int, lambda a: + Forall(int, lambda b: + Implies((0 <= a and (a) < (len(s)) and 0 <= b and b < len(s)) and (a != b), (dist(Result()[0], Result()[1])) <= (dist((s)[a], (s)[b])))))) # post-conditions-end # impl-start l : int = (s)[0] h : int = (s)[1] - d_4_d_ : int = dist(l, h) - d_5_i_ : int = 0 + d : int = dist(l, h) + i : int = 0 # assert-start - Assert(Exists(int, lambda d_6_a_: - Exists(int, lambda d_7_b_: - ((0 <= d_6_a_ and (d_6_a_) < (d_7_b_) and d_7_b_ < len(s))) and ((l) == ((s)[d_6_a_])) and ((h) == ((s)[d_7_b_]))))) + Assert(Exists(int, lambda a: + Exists(int, lambda b: + ((0 <= a and (a) < (b) and b < len(s))) and ((l) == ((s)[a])) and ((h) == ((s)[b]))))) # assert-end - while (d_5_i_) < (len(s)): + while (i) < (len(s)): # invariants-start Invariant(Acc(list_pred(s))) - Invariant(((0) <= (d_5_i_)) and ((d_5_i_) <= (len(s)))) - Invariant((d_4_d_) == (dist(l, h))) + Invariant(((0) <= (i)) and ((i) <= (len(s)))) + Invariant((d) == (dist(l, h))) Invariant((len(s)) >= (2)) - Invariant(Exists(int, lambda d_6_a_: - Exists(int, lambda d_7_b_: - ((0 <= d_6_a_ and d_6_a_ < d_7_b_ and d_7_b_ < len(s) and ((l) == ((s)[d_6_a_]))) and ((h) == ((s)[d_7_b_])))))) + Invariant(Exists(int, lambda a: + Exists(int, lambda b: + ((0 <= a and a < b and b < len(s) and ((l) == ((s)[a]))) and ((h) == ((s)[b])))))) Invariant(Forall(int, lambda x: Forall(int, lambda y: (Implies((0 <= x and x < len(s) and 0 <= y and y < len(s)), dist(s[x], s[y]) == dist(s[y], s[x])), [[dist(s[x], s[y]) == dist(s[y], s[x])]])))) - Invariant(Forall(int, lambda d_8_a_: - Forall(int, lambda d_9_b_: - (Implies((0 <= d_8_a_ and (d_8_a_) < (d_5_i_) and 0 <= d_9_b_ and d_9_b_ < len(s)) and (d_8_a_ != d_9_b_), (dist(l, h)) <= (dist((s)[d_8_a_], (s)[d_9_b_]))), [[dist((s)[d_8_a_], (s)[d_9_b_])]])))) + Invariant(Forall(int, lambda a: + Forall(int, lambda b: + (Implies((0 <= a and (a) < (i) and 0 <= b and b < len(s)) and (a != b), (dist(l, h)) <= (dist((s)[a], (s)[b]))), [[dist((s)[a], (s)[b])]])))) # invariants-end - d_10_j_ : int = (d_5_i_) + (1) + j : int = (i) + (1) # assert-start - Assert(Forall(int, lambda d_8_a_: - Forall(int, lambda d_9_b_: - (Implies((0 <= d_8_a_ and (d_8_a_) < (d_5_i_) and 0 <= d_9_b_ and d_9_b_ < len(s)) and (d_8_a_ != d_9_b_), (dist(l, h)) <= (dist((s)[d_8_a_], (s)[d_9_b_]))), [[dist((s)[d_8_a_], (s)[d_9_b_])]])))) - Assert(Forall(int, lambda x: (Implies(x >= 0 and x < d_5_i_, dist(l, h) <= dist(s[x], s[d_5_i_])), [[dist(s[x], s[d_5_i_])]]))) + Assert(Forall(int, lambda a: + Forall(int, lambda b: + (Implies((0 <= a and (a) < (i) and 0 <= b and b < len(s)) and (a != b), (dist(l, h)) <= (dist((s)[a], (s)[b]))), [[dist((s)[a], (s)[b])]])))) + Assert(Forall(int, lambda x: (Implies(x >= 0 and x < i, dist(l, h) <= dist(s[x], s[i])), [[dist(s[x], s[i])]]))) # assert-end - while (d_10_j_) < (len(s)): + while (j) < (len(s)): # invariants-start Invariant(Acc(list_pred(s))) - Invariant(((0) <= (d_5_i_)) and ((d_5_i_) < (len(s)))) - Invariant(((d_5_i_) < (d_10_j_)) and ((d_10_j_) <= (len(s)))) - Invariant((d_4_d_) == (dist(l, h))) + Invariant(((0) <= (i)) and ((i) < (len(s)))) + Invariant(((i) < (j)) and ((j) <= (len(s)))) + Invariant((d) == (dist(l, h))) Invariant((len(s)) >= (2)) - Invariant(Exists(int, lambda d_11_a_: - Exists(int, lambda d_12_b_: - ((((0 <= d_11_a_ and d_11_a_ < d_12_b_ and d_12_b_ < len(s)) ) and ((l) == ((s)[d_11_a_]))) and ((h) == ((s)[d_12_b_])))))) + Invariant(Exists(int, lambda a: + Exists(int, lambda b: + ((((0 <= a and a < b and b < len(s)) ) and ((l) == ((s)[a]))) and ((h) == ((s)[b])))))) Invariant(Forall(int, lambda x: Forall(int, lambda y: (Implies((0 <= x and x < len(s) and 0 <= y and y < len(s)), dist(s[x], s[y]) == dist(s[y], s[x])), [[dist(s[x], s[y]) == dist(s[y], s[x])]])))) - Invariant(Forall(int, lambda x: (Implies(x >= 0 and x < d_5_i_, dist(s[d_5_i_], s[x]) == dist(s[x], s[d_5_i_])), [[dist(s[d_5_i_], s[x])]]))) - Invariant(Forall(int, lambda x: (Implies(x >= 0 and x < d_5_i_, Implies(dist(l, h) <= dist(s[x], s[d_5_i_]), dist(l, h) <= dist(s[d_5_i_], s[x]))), [[dist(s[d_5_i_], s[x])]]))) - Invariant(Forall(int, lambda x: (Implies(x >= 0 and x < d_5_i_, dist(l, h) <= dist(s[x], s[d_5_i_])), [[dist(s[x], s[d_5_i_])]]))) - Invariant(Forall(int, lambda x: (Implies(x >= 0 and x < d_5_i_, dist(l, h) <= dist(s[d_5_i_], s[x])), [[dist(s[d_5_i_], s[x])]]))) - Invariant(Forall(int, lambda d_13_a_: - Forall(int, lambda d_14_b_: - (Implies((((d_13_a_ == (d_5_i_) and d_5_i_ < d_14_b_ and d_14_b_ < d_10_j_))) and (d_13_a_ != d_14_b_), (dist(l, h)) <= (dist((s)[d_13_a_], (s)[d_14_b_]))), [[dist((s)[d_13_a_], (s)[d_14_b_])]])))) - Invariant(Forall(int, lambda d_13_a_: - Forall(int, lambda d_14_b_: - (Implies((((d_13_a_ == (d_5_i_) and 0 <= d_14_b_ and d_14_b_ < d_10_j_))) and (d_13_a_ != d_14_b_), (dist(l, h)) <= (dist((s)[d_13_a_], (s)[d_14_b_]))), [[dist((s)[d_13_a_], (s)[d_14_b_])]])))) - Invariant(Forall(int, lambda d_13_a_: - Forall(int, lambda d_14_b_: - (Implies(((0 <= d_13_a_ and (d_13_a_) < (d_5_i_) and 0 <= d_14_b_ and d_14_b_ < len(s))) and (d_13_a_ != d_14_b_), (dist(l, h)) <= (dist((s)[d_13_a_], (s)[d_14_b_]))), [[dist((s)[d_13_a_], (s)[d_14_b_])]])))) + Invariant(Forall(int, lambda x: (Implies(x >= 0 and x < i, dist(s[i], s[x]) == dist(s[x], s[i])), [[dist(s[i], s[x])]]))) + Invariant(Forall(int, lambda x: (Implies(x >= 0 and x < i, Implies(dist(l, h) <= dist(s[x], s[i]), dist(l, h) <= dist(s[i], s[x]))), [[dist(s[i], s[x])]]))) + Invariant(Forall(int, lambda x: (Implies(x >= 0 and x < i, dist(l, h) <= dist(s[x], s[i])), [[dist(s[x], s[i])]]))) + Invariant(Forall(int, lambda x: (Implies(x >= 0 and x < i, dist(l, h) <= dist(s[i], s[x])), [[dist(s[i], s[x])]]))) + Invariant(Forall(int, lambda a: + Forall(int, lambda b: + (Implies((((a == (i) and i < b and b < j))) and (a != b), (dist(l, h)) <= (dist((s)[a], (s)[b]))), [[dist((s)[a], (s)[b])]])))) + Invariant(Forall(int, lambda a: + Forall(int, lambda b: + (Implies((((a == (i) and 0 <= b and b < j))) and (a != b), (dist(l, h)) <= (dist((s)[a], (s)[b]))), [[dist((s)[a], (s)[b])]])))) + Invariant(Forall(int, lambda a: + Forall(int, lambda b: + (Implies(((0 <= a and (a) < (i) and 0 <= b and b < len(s))) and (a != b), (dist(l, h)) <= (dist((s)[a], (s)[b]))), [[dist((s)[a], (s)[b])]])))) # invariants-end - if d_5_i_ != d_10_j_ and (dist((s)[d_5_i_], (s)[d_10_j_])) <= (d_4_d_): - l = (s)[d_5_i_] - h = (s)[d_10_j_] - d_4_d_ = dist(l, h) - d_10_j_ = (d_10_j_) + (1) + if i != j and (dist((s)[i], (s)[j])) <= (d): + l = (s)[i] + h = (s)[j] + d = dist(l, h) + j = (j) + (1) # assert-start - Assert(Forall(int, lambda d_8_a_: - Forall(int, lambda d_9_b_: - (Implies((0 <= d_8_a_ and (d_8_a_) <= (d_5_i_) and 0 <= d_9_b_ and d_9_b_ < len(s)) and (d_8_a_ != d_9_b_), (dist(l, h)) <= (dist((s)[d_8_a_], (s)[d_9_b_]))), [[dist((s)[d_8_a_], (s)[d_9_b_])]])))) + Assert(Forall(int, lambda a: + Forall(int, lambda b: + (Implies((0 <= a and (a) <= (i) and 0 <= b and b < len(s)) and (a != b), (dist(l, h)) <= (dist((s)[a], (s)[b]))), [[dist((s)[a], (s)[b])]])))) # assert-end - d_5_i_ = (d_5_i_) + (1) + i = (i) + (1) return (l, h) # impl-end diff --git a/Bench/024-largest-divisor.py b/Bench/024-largest-divisor.py index f81d0a8..fcf8721 100644 --- a/Bench/024-largest-divisor.py +++ b/Bench/024-largest-divisor.py @@ -8,8 +8,8 @@ def largest__divisor(n : int) -> int: # post-conditions-start Ensures(((1) <= (Result())) and ((Result()) < (n))) Ensures(((n % Result())) == (0)) - Ensures(Forall(int, lambda d_0_k_: - not (((Result()) < (d_0_k_)) and ((d_0_k_) < (n))) or (((n % d_0_k_)) != (0)))) + Ensures(Forall(int, lambda k: + not (((Result()) < (k)) and ((k) < (n))) or (((n % k)) != (0)))) # post-conditions-end # impl-start @@ -17,8 +17,8 @@ def largest__divisor(n : int) -> int: while (d) >= (1): # invariants-start Invariant(((1) <= (d)) and ((d) < (n))) - Invariant(Forall(int, lambda d_1_k_: - not (((d) < (d_1_k_)) and ((d_1_k_) < (n))) or (((n % d_1_k_)) != (0)))) + Invariant(Forall(int, lambda k: + not (((d) < (k)) and ((k) < (n))) or (((n % k)) != (0)))) # invariants-end if ((n % d)) == (0): d = d diff --git a/Bench/026-remove_duplicates.py b/Bench/026-remove_duplicates.py index cbc8690..822286e 100644 --- a/Bench/026-remove_duplicates.py +++ b/Bench/026-remove_duplicates.py @@ -10,40 +10,40 @@ def remove__duplicates(a : List[int]) -> List[int]: Ensures(Acc(list_pred(Result()))) Ensures(len(a) == len(Old(a))) Ensures(len(a) >= len(Result())) - Ensures(Forall(int, lambda d_2_i_: - Implies(((0) <= (d_2_i_)) and ((d_2_i_) < (len(a))) and (count__rec(a, a[d_2_i_], len(a)) == 1), exists_check(Result(), a[d_2_i_])))) - Ensures(Forall(int, lambda d_1_i_: - not (((0) <= (d_1_i_)) and ((d_1_i_) < (len(Result())))) or (count_check(a, (Result())[d_1_i_])))) + Ensures(Forall(int, lambda i: + Implies(((0) <= (i)) and ((i) < (len(a))) and (count__rec(a, a[i], len(a)) == 1), exists_check(Result(), a[i])))) + Ensures(Forall(int, lambda i: + not (((0) <= (i)) and ((i) < (len(Result())))) or (count_check(a, (Result())[i])))) # post-conditions-end # impl-start result : List[int] = [] - d_4_i_ : int = 0 + i : int = 0 a_old = list(a) - while (d_4_i_) < (len(a)): + while (i) < (len(a)): # invariants-start Invariant(Acc(list_pred(result))) Invariant(Acc(list_pred(a), 1/2)) Invariant(Acc(list_pred(a_old), 1/2)) Invariant(len(a) == len(a_old)) - Invariant(Forall(int, lambda d_3_i_: (Implies(d_3_i_ >= 0 and d_3_i_ < len(a), a_old[d_3_i_] == a[d_3_i_])))) - Invariant(((0) <= (d_4_i_)) and ((d_4_i_) <= (len(a)))) - Invariant(len(result) <= d_4_i_) - Invariant(Forall(int, lambda d_2_i_: - (Implies(((0) <= (d_2_i_)) and ((d_2_i_) < (d_4_i_)) and (count__rec(a, a[d_2_i_], len(a)) == 1), exists_check(result, a[d_2_i_])), + Invariant(Forall(int, lambda i: (Implies(i >= 0 and i < len(a), a_old[i] == a[i])))) + Invariant(((0) <= (i)) and ((i) <= (len(a)))) + Invariant(len(result) <= i) + Invariant(Forall(int, lambda i: + (Implies(((0) <= (i)) and ((i) < (i)) and (count__rec(a, a[i], len(a)) == 1), exists_check(result, a[i])), [[]]))) - Invariant(Forall(int, lambda d_1_i_: - (not (((0) <= (d_1_i_)) and ((d_1_i_) < (len(result)))) or (count_check(a, (result)[d_1_i_])), + Invariant(Forall(int, lambda i: + (not (((0) <= (i)) and ((i) < (len(result)))) or (count_check(a, (result)[i])), [[]]))) # invariants-end - d_8_cnt_ : int = count__rec(a, (a)[d_4_i_], len(a)) - if (d_8_cnt_) == (1): - result = (result) + [(a)[d_4_i_]] + cnt : int = count__rec(a, (a)[i], len(a)) + if (cnt) == (1): + result = (result) + [(a)[i]] # assert-start Assert(count__rec(a, result[len(result) - 1], len(a)) == 1) # assert-end - d_4_i_ = (d_4_i_) + (1) + i = (i) + (1) return result # impl-end @@ -54,8 +54,8 @@ def exists_check(a : List[int], x : int) -> bool: # pre-conditions-end # pure-start - return Exists(int, lambda d_0_i_: - ((((0) <= (d_0_i_)) and ((d_0_i_) < (len((a)))) and ((a)[d_0_i_]) == (x)))) + return Exists(int, lambda i: + ((((0) <= (i)) and ((i) < (len((a)))) and ((a)[i]) == (x)))) # pure-end @Pure diff --git a/Bench/027-flip_case.py b/Bench/027-flip_case.py index 2025b8d..fb700b9 100644 --- a/Bench/027-flip_case.py +++ b/Bench/027-flip_case.py @@ -42,8 +42,8 @@ def flip__case(s : List[int]) -> List[int] : Ensures(Acc(list_pred(s))) Ensures(Acc(list_pred(Result()))) Ensures((len(Result())) == (len(s))) - Ensures(Forall(int, lambda d_0_i_: (Implies(((0) <= (d_0_i_)) and ((d_0_i_) < (len(s))), lower((s)[d_0_i_]) == upper((Result())[d_0_i_]))))) - Ensures(Forall(int, lambda d_0_i_: (Implies(((0) <= (d_0_i_)) and ((d_0_i_) < (len(s))), upper((s)[d_0_i_]) == lower((Result())[d_0_i_]))))) + Ensures(Forall(int, lambda i: (Implies(((0) <= (i)) and ((i) < (len(s))), lower((s)[i]) == upper((Result())[i]))))) + Ensures(Forall(int, lambda i: (Implies(((0) <= (i)) and ((i) < (len(s))), upper((s)[i]) == lower((Result())[i]))))) # post-conditions-end # impl-start @@ -55,8 +55,8 @@ def flip__case(s : List[int]) -> List[int] : Invariant(Acc(list_pred(res))) Invariant(((0) <= (i)) and ((i) <= (len(s)))) Invariant((len(res)) == (len(s))) - Invariant(Forall(int, lambda d_0_i_: (Implies(((0) <= (d_0_i_)) and ((d_0_i_) < (i)), lower((s)[d_0_i_]) == upper((res)[d_0_i_]))))) - Invariant(Forall(int, lambda d_0_i_: (Implies(((0) <= (d_0_i_)) and ((d_0_i_) < (i)), upper((s)[d_0_i_]) == lower((res)[d_0_i_]))))) + Invariant(Forall(int, lambda i: (Implies(((0) <= (i)) and ((i) < (i)), lower((s)[i]) == upper((res)[i]))))) + Invariant(Forall(int, lambda i: (Implies(((0) <= (i)) and ((i) < (i)), upper((s)[i]) == lower((res)[i]))))) # invariants-end res[i] = flip__char(s[i]) i = i + 1 diff --git a/Bench/029-filter_by_prefix.py b/Bench/029-filter_by_prefix.py index e59a0d8..9fd8344 100644 --- a/Bench/029-filter_by_prefix.py +++ b/Bench/029-filter_by_prefix.py @@ -48,29 +48,29 @@ def filter__by__prefix(xs : List[List[int]], p : List[int]) -> List[int]: Ensures(Acc(list_pred(xs))) Ensures(Forall(xs, lambda x : Acc(list_pred(x)))) Ensures(Acc(list_pred(Result()))) - Ensures(Forall(int, lambda d_2_j_: - Implies(d_2_j_ >= 0 and d_2_j_ < len(Result()), Result()[d_2_j_] >= 0 and Result()[d_2_j_] < len(xs)))) - Ensures(Forall(int, lambda d_0_i_: - not (((0) <= (d_0_i_)) and ((d_0_i_) < (len(Result())))) or (starts__with(xs[Result()[d_0_i_]], p, 0)))) + Ensures(Forall(int, lambda j: + Implies(j >= 0 and j < len(Result()), Result()[j] >= 0 and Result()[j] < len(xs)))) + Ensures(Forall(int, lambda i: + not (((0) <= (i)) and ((i) < (len(Result())))) or (starts__with(xs[Result()[i]], p, 0)))) # post-conditions-end # impl-start filtered : List[int] = [] - d_1_i_ : int = 0 - while (d_1_i_) < (len(xs)): + i : int = 0 + while (i) < (len(xs)): # invariants-start Invariant(Acc(list_pred(filtered))) Invariant(Acc(list_pred(xs), 1/2)) Invariant(Acc(list_pred(p), 1/2)) - Invariant(((0) <= (d_1_i_)) and ((d_1_i_) <= (len(xs)))) + Invariant(((0) <= (i)) and ((i) <= (len(xs)))) Invariant(Forall(xs, lambda x : Acc(list_pred(x)))) Invariant(Forall(filtered, lambda i: - (i >= 0 and i < d_1_i_))) + (i >= 0 and i < i))) Invariant(Forall(filtered, lambda i: (starts__with(xs[i], p, 0), [[starts__with(xs[i], p, 0)]]))) # invariants-end - if starts__with__fun((xs)[d_1_i_], p, 0): - filtered = (filtered) + [d_1_i_] - d_1_i_ = (d_1_i_) + (1) + if starts__with__fun((xs)[i], p, 0): + filtered = (filtered) + [i] + i = (i) + (1) return filtered # impl-end diff --git a/Bench/030-get-positive.py b/Bench/030-get-positive.py index fd36eee..995eee1 100644 --- a/Bench/030-get-positive.py +++ b/Bench/030-get-positive.py @@ -8,54 +8,54 @@ def get__positive(l : List[int]) -> List[int]: # post-conditions-start Ensures(Acc(list_pred(l))) Ensures(Acc(list_pred(Result()))) - Ensures(Forall(int, lambda d_0_i_: - not (((d_0_i_) >= (0)) and ((d_0_i_) < (len(Result())))) or (((Result())[d_0_i_]) > (0)))) + Ensures(Forall(int, lambda i: + not (((i) >= (0)) and ((i) < (len(Result())))) or (((Result())[i]) > (0)))) Ensures((len(Result())) <= (len(l))) - Ensures(Forall(int, lambda d_1_i1_: - not (((d_1_i1_) >= (0)) and ((d_1_i1_) < (len(l)))) or (not (((l)[d_1_i1_]) > (0)) or (Exists(int, lambda d_2_i2_: - (((d_2_i2_) >= (0)) and ((d_2_i2_) < (len(Result())))) and (((Result())[d_2_i2_]) == ((l)[d_1_i1_]))))))) - Ensures(((len(Result())) == (0)) or (Forall(int, lambda d_3_i1_: - not (((d_3_i1_) >= (0)) and ((d_3_i1_) < (len(Result())))) or (Exists(int, lambda d_4_i2_: - (((d_4_i2_) >= (0)) and ((d_4_i2_) < (len(l)))) and (((l)[d_4_i2_]) == ((Result())[d_3_i1_]))))))) + Ensures(Forall(int, lambda i1: + not (((i1) >= (0)) and ((i1) < (len(l)))) or (not (((l)[i1]) > (0)) or (Exists(int, lambda i2: + (((i2) >= (0)) and ((i2) < (len(Result())))) and (((Result())[i2]) == ((l)[i1]))))))) + Ensures(((len(Result())) == (0)) or (Forall(int, lambda i1: + not (((i1) >= (0)) and ((i1) < (len(Result())))) or (Exists(int, lambda i2: + (((i2) >= (0)) and ((i2) < (len(l)))) and (((l)[i2]) == ((Result())[i1]))))))) # post-conditions-end # impl-start result : List[int] = [] - d_5_i_ : int = 0 - while (d_5_i_) < (len(l)): + i : int = 0 + while (i) < (len(l)): # invariants-start Invariant(Acc(list_pred(result))) Invariant(Acc(list_pred(l))) - Invariant(((d_5_i_) >= (0)) and ((d_5_i_) <= (len(l)))) - Invariant((len(result)) <= (d_5_i_)) - Invariant(Forall(int, lambda d_6_i1_: - not (((d_6_i1_) >= (0)) and ((d_6_i1_) < (len(result)))) or (((result)[d_6_i1_]) > (0)))) - Invariant(not ((d_5_i_) > (0)) or (not (((l)[(d_5_i_) - (1)]) > (0)) or (Exists(int, lambda d_7_i2_: - (((d_7_i2_) >= (0)) and ((d_7_i2_) < (len(result)))) and (((result)[d_7_i2_]) == ((l)[(d_5_i_) - (1)])))))) - Invariant(Forall(int, lambda d_9_i1_: - not (((d_9_i1_) >= (0)) and ((d_9_i1_) < (d_5_i_))) or (not (((l)[d_9_i1_]) > (0)) or (Exists(int, lambda d_10_i2_: - (((d_10_i2_) >= (0)) and ((d_10_i2_) < (len(result)))) and (((result)[d_10_i2_]) == ((l)[d_9_i1_]))))))) - Invariant(((len(result)) == (0)) or (Forall(int, lambda d_11_i1_: - not (((d_11_i1_) >= (0)) and ((d_11_i1_) < (len(result)))) or (Exists(int, lambda d_12_i2_: - (((d_12_i2_) >= (0)) and ((d_12_i2_) < (len(l)))) and (((l)[d_12_i2_]) == ((result)[d_11_i1_]))))))) + Invariant(((i) >= (0)) and ((i) <= (len(l)))) + Invariant((len(result)) <= (i)) + Invariant(Forall(int, lambda i1: + not (((i1) >= (0)) and ((i1) < (len(result)))) or (((result)[i1]) > (0)))) + Invariant(not ((i) > (0)) or (not (((l)[(i) - (1)]) > (0)) or (Exists(int, lambda i2: + (((i2) >= (0)) and ((i2) < (len(result)))) and (((result)[i2]) == ((l)[(i) - (1)])))))) + Invariant(Forall(int, lambda i1: + not (((i1) >= (0)) and ((i1) < (i))) or (not (((l)[i1]) > (0)) or (Exists(int, lambda i2: + (((i2) >= (0)) and ((i2) < (len(result)))) and (((result)[i2]) == ((l)[i1]))))))) + Invariant(((len(result)) == (0)) or (Forall(int, lambda i1: + not (((i1) >= (0)) and ((i1) < (len(result)))) or (Exists(int, lambda i2: + (((i2) >= (0)) and ((i2) < (len(l)))) and (((l)[i2]) == ((result)[i1]))))))) # invariants-end - d_13_n_ : int = (l)[d_5_i_] - if (d_13_n_) > (0): - d_17_res__prev_ = result + n : int = (l)[i] + if (n) > (0): + res__prev = result # assert-start - Assert(Forall(int, lambda d_14_i1_: - not (((d_14_i1_) >= (0)) and ((d_14_i1_) < (d_5_i_))) or (not (((l)[d_14_i1_]) > (0)) or (Exists(int, lambda d_15_i2_: - (((d_15_i2_) >= (0)) and ((d_15_i2_) < (len(result)))) and (((result)[d_15_i2_]) == ((l)[d_14_i1_]))))))) + Assert(Forall(int, lambda i1: + not (((i1) >= (0)) and ((i1) < (i))) or (not (((l)[i1]) > (0)) or (Exists(int, lambda i2: + (((i2) >= (0)) and ((i2) < (len(result)))) and (((result)[i2]) == ((l)[i1]))))))) # assert-end - result = (result) + ([d_13_n_]) + result = (result) + ([n]) # assert-start - Assert(((result)[(len(result)) - (1)]) == (d_13_n_)) - Assert(Forall(int, lambda d_16_i1_: - not (((d_16_i1_) >= (0)) and ((d_16_i1_) < (len(d_17_res__prev_)))) or (((d_17_res__prev_)[d_16_i1_]) == ((result)[d_16_i1_])))) - Assert(Forall(int, lambda d_18_i1_: - not (((d_18_i1_) >= (0)) and ((d_18_i1_) < (d_5_i_))) or (not (((l)[d_18_i1_]) > (0)) or (Exists(int, lambda d_19_i2_: - (((d_19_i2_) >= (0)) and ((d_19_i2_) < (len(d_17_res__prev_)))) and (((d_17_res__prev_)[d_19_i2_]) == ((l)[d_18_i1_]))))))) + Assert(((result)[(len(result)) - (1)]) == (n)) + Assert(Forall(int, lambda i1: + not (((i1) >= (0)) and ((i1) < (len(res__prev)))) or (((res__prev)[i1]) == ((result)[i1])))) + Assert(Forall(int, lambda i1: + not (((i1) >= (0)) and ((i1) < (i))) or (not (((l)[i1]) > (0)) or (Exists(int, lambda i2: + (((i2) >= (0)) and ((i2) < (len(res__prev)))) and (((res__prev)[i2]) == ((l)[i1]))))))) # assert-end - d_5_i_ = (d_5_i_) + (1) + i = (i) + (1) return result # impl-end diff --git a/Bench/031-is-prime.py b/Bench/031-is-prime.py index 2e1b0c6..ceb702f 100644 --- a/Bench/031-is-prime.py +++ b/Bench/031-is-prime.py @@ -6,25 +6,25 @@ def is__prime(k : int) -> bool: Requires((k) >= (2)) # pre-conditions-end # post-conditions-start - Ensures(not (Result()) or (Forall(int, lambda d_0_i_: - not (((2) <= (d_0_i_)) and ((d_0_i_) < (k))) or ((k % d_0_i_) != (0))))) - Ensures(not (not(Result())) or (Exists(int, lambda d_1_j_: - (((2) <= (d_1_j_)) and ((d_1_j_) < (k))) and (((k % d_1_j_)) == (0))))) + Ensures(not (Result()) or (Forall(int, lambda i: + not (((2) <= (i)) and ((i) < (k))) or ((k % i) != (0))))) + Ensures(not (not(Result())) or (Exists(int, lambda j: + (((2) <= (j)) and ((j) < (k))) and (((k % j)) == (0))))) # post-conditions-end # impl-start - d_2_i_ : int = 2 + i : int = 2 result : bool = True - while (d_2_i_) < (k): + while (i) < (k): # invariants-start - Invariant(((2) <= (d_2_i_)) and ((d_2_i_) <= (k))) - Invariant(not (not(result)) or (Exists(int, lambda d_3_j_: - (((2) <= (d_3_j_)) and ((d_3_j_) < (d_2_i_))) and (((k % d_3_j_)) == (0))))) - Invariant(not (result) or (Forall(int, lambda d_4_j_: - not (((2) <= (d_4_j_)) and ((d_4_j_) < (d_2_i_))) or (((k % d_4_j_)) != (0))))) + Invariant(((2) <= (i)) and ((i) <= (k))) + Invariant(not (not(result)) or (Exists(int, lambda j: + (((2) <= (j)) and ((j) < (i))) and (((k % j)) == (0))))) + Invariant(not (result) or (Forall(int, lambda j: + not (((2) <= (j)) and ((j) < (i))) or (((k % j)) != (0))))) # invariants-end - if ((k % d_2_i_)) == (0): + if ((k % i)) == (0): result = False - d_2_i_ = (d_2_i_) + (1) + i = (i) + (1) return result # impl-end diff --git a/Bench/033-sort_third.py b/Bench/033-sort_third.py index 532b787..381baac 100644 --- a/Bench/033-sort_third.py +++ b/Bench/033-sort_third.py @@ -10,30 +10,30 @@ def sort__third(a : List[int]) -> List[int]: Ensures(Acc(list_pred(a))) Ensures(Acc(list_pred(Result()))) Ensures((len(Result())) == (len(a))) - Ensures(Forall(int, lambda d_0_i_: - Forall(int, lambda d_1_j_: - not ((((((0) <= (d_0_i_)) and ((d_0_i_) < (d_1_j_))) and ((d_1_j_) < (len(Result())))) and (((d_0_i_ % 3)) == (0))) and (((d_1_j_ % 3)) == (0))) or (((Result())[d_0_i_]) <= ((Result())[d_1_j_]))))) - Ensures(Forall(int, lambda d_2_i_: - not ((((0) <= (d_2_i_)) and ((d_2_i_) < (len(a)))) and (((d_2_i_ % 3)) != (0))) or (((Result())[d_2_i_]) == ((a)[d_2_i_])))) + Ensures(Forall(int, lambda i: + Forall(int, lambda j: + not ((((((0) <= (i)) and ((i) < (j))) and ((j) < (len(Result())))) and (((i % 3)) == (0))) and (((j % 3)) == (0))) or (((Result())[i]) <= ((Result())[j]))))) + Ensures(Forall(int, lambda i: + not ((((0) <= (i)) and ((i) < (len(a)))) and (((i % 3)) != (0))) or (((Result())[i]) == ((a)[i])))) # post-conditions-end # impl-start sorted__even : List[int] = [] - d_3_p_ : List[bool] = list([]) - d_4_i_ : int = 0 - while (d_4_i_) < (len(a)): + p : List[bool] = list([]) + i : int = 0 + while (i) < (len(a)): # invariants-start - Invariant(Acc(list_pred(d_3_p_))) + Invariant(Acc(list_pred(p))) Invariant(Acc(list_pred(sorted__even))) Invariant(Acc(list_pred(a))) - Invariant(((0) <= (d_4_i_)) and ((d_4_i_) <= (len(a)))) - Invariant((len(d_3_p_)) == (d_4_i_)) - Invariant(Forall(int, lambda d_5_j_: - not (((0) <= (d_5_j_)) and ((d_5_j_) < (d_4_i_))) or (((d_3_p_)[d_5_j_]) == (((d_5_j_ % 3)) == (0))))) + Invariant(((0) <= (i)) and ((i) <= (len(a)))) + Invariant((len(p)) == (i)) + Invariant(Forall(int, lambda j: + not (((0) <= (j)) and ((j) < (i))) or (((p)[j]) == (((j % 3)) == (0))))) # invariants-end - d_3_p_ = (d_3_p_) + [((d_4_i_ % 3)) == (0)] - d_4_i_ = (d_4_i_) + (1) - sorted__even = SortSeqPred(a, d_3_p_) + p = (p) + [((i % 3)) == (0)] + i = (i) + (1) + sorted__even = SortSeqPred(a, p) return sorted__even # impl-end @@ -49,75 +49,75 @@ def SortSeqPred(s : List[int], p : List[bool]) -> List[int]: Ensures(Acc(list_pred(Result()))) Ensures((len(s)) == (len(p))) Ensures((len(Result())) == (len(s))) - Ensures(Forall(int, lambda d_6_i_: - Forall(int, lambda d_7_j_: - not ((((((0) <= (d_6_i_)) and ((d_6_i_) < (d_7_j_))) and ((d_7_j_) < (len(Result())))) and ((p)[d_6_i_])) and ((p)[d_7_j_])) or (((Result())[d_6_i_]) <= ((Result())[d_7_j_]))))) - Ensures(Forall(int, lambda d_8_i_: - not ((((0) <= (d_8_i_)) and ((d_8_i_) < (len(s)))) and (not((p)[d_8_i_]))) or (((Result())[d_8_i_]) == ((s)[d_8_i_])))) + Ensures(Forall(int, lambda i: + Forall(int, lambda j: + not ((((((0) <= (i)) and ((i) < (j))) and ((j) < (len(Result())))) and ((p)[i])) and ((p)[j])) or (((Result())[i]) <= ((Result())[j]))))) + Ensures(Forall(int, lambda i: + not ((((0) <= (i)) and ((i) < (len(s)))) and (not((p)[i]))) or (((Result())[i]) == ((s)[i])))) # post-conditions-end # impl-start sorted : List[int] = list(s) - d_9_i_ : int = 0 - while (d_9_i_) < (len(sorted)): + i : int = 0 + while (i) < (len(sorted)): # invariants-start Invariant(Acc(list_pred(sorted))) Invariant(Acc(list_pred(p), 1/2)) Invariant(Acc(list_pred(s), 1/2)) Invariant((len(s)) == (len(p))) - Invariant(((0) <= (d_9_i_)) and ((d_9_i_) <= (len(sorted)))) + Invariant(((0) <= (i)) and ((i) <= (len(sorted)))) Invariant((len(sorted)) == (len(s))) - Invariant(Forall(int, lambda d_14_j_: - not ((((0) <= (d_14_j_)) and ((d_14_j_) < (len(s)))) and (not((p)[d_14_j_]))) or (((sorted)[d_14_j_]) == ((s)[d_14_j_])))) - Invariant(Forall(int, lambda d_10_j_: - (Forall(int, lambda d_11_k_: - (not ((((((0) <= (d_10_j_)) and ((d_10_j_) < (d_11_k_))) and ((d_11_k_) < (d_9_i_))) and ((p)[d_10_j_])) and ((p)[d_11_k_])) or - (((sorted)[d_10_j_]) <= ((sorted)[d_11_k_])), [[(sorted)[d_11_k_]]])), [[sorted[d_10_j_]]]))) - Invariant(Forall(int, lambda d_12_j_: - (not ((((0) <= (d_12_j_)) and ((d_12_j_) < (d_9_i_))) and ((p)[d_12_j_])) or - (Forall(int, lambda d_13_k_: - (not ((((d_9_i_) <= (d_13_k_)) and ((d_13_k_) < (len(sorted)))) and ((p)[d_13_k_])) or - (((sorted)[d_12_j_]) <= ((sorted)[d_13_k_])), [[sorted[d_13_k_]]]))), [[(sorted)[d_12_j_]]]))) + Invariant(Forall(int, lambda j: + not ((((0) <= (j)) and ((j) < (len(s)))) and (not((p)[j]))) or (((sorted)[j]) == ((s)[j])))) + Invariant(Forall(int, lambda j: + (Forall(int, lambda k: + (not ((((((0) <= (j)) and ((j) < (k))) and ((k) < (i))) and ((p)[j])) and ((p)[k])) or + (((sorted)[j]) <= ((sorted)[k])), [[(sorted)[k]]])), [[sorted[j]]]))) + Invariant(Forall(int, lambda j: + (not ((((0) <= (j)) and ((j) < (i))) and ((p)[j])) or + (Forall(int, lambda k: + (not ((((i) <= (k)) and ((k) < (len(sorted)))) and ((p)[k])) or + (((sorted)[j]) <= ((sorted)[k])), [[sorted[k]]]))), [[(sorted)[j]]]))) # invariants-end - if (p)[d_9_i_]: - d_15_minIndex_ : int = d_9_i_ - d_16_j_ : int = (d_9_i_) + (1) - while (d_16_j_) < (len(sorted)): + if (p)[i]: + minIndex : int = i + j : int = (i) + (1) + while (j) < (len(sorted)): # invariants-start Invariant(Acc(list_pred(sorted))) Invariant(Acc(list_pred(p), 1/2)) Invariant(Acc(list_pred(s), 1/2)) Invariant((len(s)) == (len(p))) Invariant((len(sorted)) == (len(s))) - Invariant(0 <= d_9_i_ and d_9_i_ < len(sorted)) - Invariant((((d_9_i_) <= (d_15_minIndex_)) and ((d_15_minIndex_) < (d_16_j_))) and ((d_16_j_) <= (len(sorted)))) - Invariant(p[d_9_i_]) - Invariant((p)[d_15_minIndex_]) - Invariant(Forall(int, lambda d_17_k_: - not ((((d_9_i_) <= (d_17_k_)) and ((d_17_k_) < (d_16_j_))) and ((p)[d_17_k_])) or (((sorted)[d_15_minIndex_]) <= ((sorted)[d_17_k_])))) - Invariant(Forall(int, lambda d_14_j_: - not ((((0) <= (d_14_j_)) and ((d_14_j_) < (len(s)))) and (not((p)[d_14_j_]))) or (((sorted)[d_14_j_]) == ((s)[d_14_j_])))) - Invariant(Forall(int, lambda d_10_j_: - (Forall(int, lambda d_11_k_: - (not ((((((0) <= (d_10_j_)) and ((d_10_j_) < (d_11_k_))) and ((d_11_k_) < (d_9_i_))) and ((p)[d_10_j_])) and ((p)[d_11_k_])) or - (((sorted)[d_10_j_]) <= ((sorted)[d_11_k_])), [[(sorted)[d_11_k_]]])), [[sorted[d_10_j_]]]))) - Invariant(Forall(int, lambda d_12_j_: - (not ((((0) <= (d_12_j_)) and ((d_12_j_) < (d_9_i_))) and ((p)[d_12_j_])) or - (Forall(int, lambda d_13_k_: - (not ((((d_9_i_) <= (d_13_k_)) and ((d_13_k_) < (len(sorted)))) and ((p)[d_13_k_])) or - (((sorted)[d_12_j_]) <= ((sorted)[d_13_k_])), [[sorted[d_13_k_]]]))), [[(sorted)[d_12_j_]]]))) + Invariant(0 <= i and i < len(sorted)) + Invariant((((i) <= (minIndex)) and ((minIndex) < (j))) and ((j) <= (len(sorted)))) + Invariant(p[i]) + Invariant((p)[minIndex]) + Invariant(Forall(int, lambda k: + not ((((i) <= (k)) and ((k) < (j))) and ((p)[k])) or (((sorted)[minIndex]) <= ((sorted)[k])))) + Invariant(Forall(int, lambda j: + not ((((0) <= (j)) and ((j) < (len(s)))) and (not((p)[j]))) or (((sorted)[j]) == ((s)[j])))) + Invariant(Forall(int, lambda j: + (Forall(int, lambda k: + (not ((((((0) <= (j)) and ((j) < (k))) and ((k) < (i))) and ((p)[j])) and ((p)[k])) or + (((sorted)[j]) <= ((sorted)[k])), [[(sorted)[k]]])), [[sorted[j]]]))) + Invariant(Forall(int, lambda j: + (not ((((0) <= (j)) and ((j) < (i))) and ((p)[j])) or + (Forall(int, lambda k: + (not ((((i) <= (k)) and ((k) < (len(sorted)))) and ((p)[k])) or + (((sorted)[j]) <= ((sorted)[k])), [[sorted[k]]]))), [[(sorted)[j]]]))) # invariants-end - if ((p)[d_16_j_]) and (((sorted)[d_16_j_]) < ((sorted)[d_15_minIndex_])): - d_15_minIndex_ = d_16_j_ - d_16_j_ = (d_16_j_) + (1) - if (d_15_minIndex_) != (d_9_i_): + if ((p)[j]) and (((sorted)[j]) < ((sorted)[minIndex])): + minIndex = j + j = (j) + (1) + if (minIndex) != (i): # assert-start - Assert((p)[d_15_minIndex_]) - Assert(p[d_9_i_]) + Assert((p)[minIndex]) + Assert(p[i]) # assert-end - rhs0_ : int = (sorted)[d_9_i_] - (sorted)[d_9_i_] = (sorted)[d_15_minIndex_] - (sorted)[d_15_minIndex_] = rhs0_ - d_9_i_ = (d_9_i_) + (1) + rhs0_ : int = (sorted)[i] + (sorted)[i] = (sorted)[minIndex] + (sorted)[minIndex] = rhs0_ + i = (i) + (1) return sorted # impl-end diff --git a/Bench/034-unique.py b/Bench/034-unique.py index 1dd8ff6..e43eced 100644 --- a/Bench/034-unique.py +++ b/Bench/034-unique.py @@ -8,8 +8,8 @@ def InArray(a : List[int], x : int) -> bool: # pre-conditions-end # pure-start - return Exists(int, lambda d_0_i_: - ((((0) <= (d_0_i_)) and ((d_0_i_) < (len((a)))) and ((a)[d_0_i_]) == (x)))) + return Exists(int, lambda i: + ((((0) <= (i)) and ((i) < (len((a)))) and ((a)[i]) == (x)))) # pure-end @@ -17,53 +17,53 @@ def InArray(a : List[int], x : int) -> bool: def uniqueSorted(s : List[int]) -> List[int]: # pre-conditions-start Requires(Acc(list_pred(s), 1/2)) - Requires(Forall(int, lambda d_0_i_: - Forall(int, lambda d_1_j_: - Implies((((0) <= (d_0_i_)) and ((d_0_i_) < (d_1_j_))) and ((d_1_j_) < (len(s))), - ((s)[d_0_i_]) <= ((s)[d_1_j_]))))) + Requires(Forall(int, lambda i: + Forall(int, lambda j: + Implies((((0) <= (i)) and ((i) < (j))) and ((j) < (len(s))), + ((s)[i]) <= ((s)[j]))))) # pre-conditions-end # post-conditions-start Ensures(Acc(list_pred(s), 1/2)) Ensures(Acc(list_pred(Result()))) - Ensures(Forall(int, lambda d_9_k_: - (Implies(((0) <= (d_9_k_)) and ((d_9_k_) < (len(Result()))), InArray(s, Result()[d_9_k_]))))) - Ensures(Forall(int, lambda d_2_i_: - Forall(int, lambda d_3_j_: - not ((((0) <= (d_2_i_)) and ((d_2_i_) < (d_3_j_))) and ((d_3_j_) < (len(Result())))) or (((Result())[d_2_i_]) < ((Result())[d_3_j_]))))) + Ensures(Forall(int, lambda k: + (Implies(((0) <= (k)) and ((k) < (len(Result()))), InArray(s, Result()[k]))))) + Ensures(Forall(int, lambda i: + Forall(int, lambda j: + not ((((0) <= (i)) and ((i) < (j))) and ((j) < (len(Result())))) or (((Result())[i]) < ((Result())[j]))))) # post-conditions-end # impl-start result : List[int] = [] - d_6_i_ : int = 0 - while (d_6_i_) < (len(s)): + i : int = 0 + while (i) < (len(s)): # invariants-start Invariant(Acc(list_pred(result))) Invariant(Acc(list_pred(s), 1/2)) - Invariant(Forall(int, lambda d_0_i_: - Forall(int, lambda d_1_j_: - Implies((((0) <= (d_0_i_)) and ((d_0_i_) < (d_1_j_))) and ((d_1_j_) < (len(s))), - ((s)[d_0_i_]) <= ((s)[d_1_j_]))))) - Invariant(((0) <= (d_6_i_)) and ((d_6_i_) <= (len(s)))) - Invariant(Forall(int, lambda d_9_k_: - (Implies(((0) <= (d_9_k_)) and ((d_9_k_) < (len(result))), InArray(s, result[d_9_k_])), [[InArray(s, result[d_9_k_])]]))) - Invariant(Implies(d_6_i_ < len(s), - Forall(int, lambda d_2_i_: - (Implies(((0) <= (d_2_i_)) and ((d_2_i_) < (len(result))), result[d_2_i_] <= s[d_6_i_]), [[result[d_2_i_]]])))) - Invariant(Forall(int, lambda d_7_k_: - (Forall(int, lambda d_8_l_: - (not ((((0) <= (d_7_k_)) and ((d_7_k_) < (d_8_l_))) and ((d_8_l_) < (len(result)))) or (((result)[d_7_k_]) < ((result)[d_8_l_])), - [[(result)[d_8_l_]]])), - [[(result)[d_7_k_]]]))) + Invariant(Forall(int, lambda i: + Forall(int, lambda j: + Implies((((0) <= (i)) and ((i) < (j))) and ((j) < (len(s))), + ((s)[i]) <= ((s)[j]))))) + Invariant(((0) <= (i)) and ((i) <= (len(s)))) + Invariant(Forall(int, lambda k: + (Implies(((0) <= (k)) and ((k) < (len(result))), InArray(s, result[k])), [[InArray(s, result[k])]]))) + Invariant(Implies(i < len(s), + Forall(int, lambda i: + (Implies(((0) <= (i)) and ((i) < (len(result))), result[i] <= s[i]), [[result[i]]])))) + Invariant(Forall(int, lambda k: + (Forall(int, lambda l: + (not ((((0) <= (k)) and ((k) < (l))) and ((l) < (len(result)))) or (((result)[k]) < ((result)[l])), + [[(result)[l]]])), + [[(result)[k]]]))) # invariants-end - if ((len(result)) == (0)) or (((result)[(len(result)) - (1)]) != ((s)[d_6_i_])): + if ((len(result)) == (0)) or (((result)[(len(result)) - (1)]) != ((s)[i])): # assert-start - Assert(Implies(len(result) > 0, result[len(result) - 1] < s[d_6_i_])) + Assert(Implies(len(result) > 0, result[len(result) - 1] < s[i])) Assert(Implies(len(result) > 0, - Forall(int, lambda d_11_j_: - Implies(0 <= d_11_j_ and d_11_j_ < len(result), result[d_11_j_] < s[d_6_i_])))) + Forall(int, lambda j: + Implies(0 <= j and j < len(result), result[j] < s[i])))) # assert-end - result = (result) + [(s)[d_6_i_]] - d_6_i_ = (d_6_i_) + (1) + result = (result) + [(s)[i]] + i = (i) + (1) return result # impl-end @@ -74,27 +74,27 @@ def unique(s : List[int]) -> List[int]: # post-conditions-start Ensures(Acc(list_pred(s))) Ensures(Acc(list_pred(Result()))) - Ensures(Forall(int, lambda d_9_k_: - (Implies(((0) <= (d_9_k_)) and ((d_9_k_) < (len(Result()))), InArray(s, Result()[d_9_k_]))))) - Ensures(Forall(int, lambda d_2_i_: - Forall(int, lambda d_3_j_: - not ((((0) <= (d_2_i_)) and ((d_2_i_) < (d_3_j_))) and ((d_3_j_) < (len(Result())))) or (((Result())[d_2_i_]) < ((Result())[d_3_j_]))))) + Ensures(Forall(int, lambda k: + (Implies(((0) <= (k)) and ((k) < (len(Result()))), InArray(s, Result()[k]))))) + Ensures(Forall(int, lambda i: + Forall(int, lambda j: + not ((((0) <= (i)) and ((i) < (j))) and ((j) < (len(Result())))) or (((Result())[i]) < ((Result())[j]))))) # post-conditions-end # impl-start a = BubbleSort(s) # assert-start - Assert(Forall(int, lambda d_9_k_: - (Implies(((0) <= (d_9_k_)) and ((d_9_k_) < (len(a))), InArray(s, a[d_9_k_]))))) + Assert(Forall(int, lambda k: + (Implies(((0) <= (k)) and ((k) < (len(a))), InArray(s, a[k]))))) # assert-end b = uniqueSorted(a) # assert-start - Assert(Forall(int, lambda d_9_k_: - (Implies(((0) <= (d_9_k_)) and ((d_9_k_) < (len(a))), InArray(s, a[d_9_k_]))))) - Assert(Forall(int, lambda d_9_k_: - (Implies(((0) <= (d_9_k_)) and ((d_9_k_) < (len(b))), InArray(a, b[d_9_k_]))))) - Assert(Forall(int, lambda d_9_k_: - (Implies(((0) <= (d_9_k_)) and ((d_9_k_) < (len(b))), InArray(s, b[d_9_k_]))))) + Assert(Forall(int, lambda k: + (Implies(((0) <= (k)) and ((k) < (len(a))), InArray(s, a[k]))))) + Assert(Forall(int, lambda k: + (Implies(((0) <= (k)) and ((k) < (len(b))), InArray(a, b[k]))))) + Assert(Forall(int, lambda k: + (Implies(((0) <= (k)) and ((k) < (len(b))), InArray(s, b[k]))))) # assert-end return b # impl-end @@ -107,83 +107,83 @@ def BubbleSort(a1 : List[int]) -> List[int]: Ensures(Acc(list_pred(a1), 1/2)) Ensures(Acc(list_pred(Result()))) Ensures((len(a1)) == (len(Result()))) - Ensures(Forall(int, lambda d_0_i_: - Forall(int, lambda d_1_j_: - Implies((((0) <= (d_0_i_)) and ((d_0_i_) < (d_1_j_))) and ((d_1_j_) < (len((Result())))), ((Result())[d_0_i_]) <= ((Result())[d_1_j_]))))) - Ensures(Forall(int, lambda d_9_k_: - (Implies(((0) <= (d_9_k_)) and ((d_9_k_) < (len(Result()))), InArray(a1, Result()[d_9_k_]))))) + Ensures(Forall(int, lambda i: + Forall(int, lambda j: + Implies((((0) <= (i)) and ((i) < (j))) and ((j) < (len((Result())))), ((Result())[i]) <= ((Result())[j]))))) + Ensures(Forall(int, lambda k: + (Implies(((0) <= (k)) and ((k) < (len(Result()))), InArray(a1, Result()[k]))))) # post-conditions-end # impl-start a : List[int] = [] - d_2_i_ : int = int(0) - while d_2_i_ < len(a1): + i : int = int(0) + while i < len(a1): # invariants-start Invariant(Acc(list_pred(a))) Invariant(Acc(list_pred(a1), 1/2)) - Invariant(len(a) == d_2_i_) - Invariant(0 <= d_2_i_ and d_2_i_ <= len(a1)) - Invariant(Forall(int, lambda d_9_k_: - (Implies(((0) <= (d_9_k_)) and ((d_9_k_) < (d_2_i_)), a[d_9_k_] == a1[d_9_k_])))) - Invariant(Forall(int, lambda d_9_k_: - (Implies(((0) <= (d_9_k_)) and ((d_9_k_) < (d_2_i_)), InArray(a1, a[d_9_k_])), [[InArray(a1, a[d_9_k_])]]))) - Invariant(Forall(int, lambda d_9_k_: - (Implies(((0) <= (d_9_k_)) and ((d_9_k_) < (d_2_i_)), InArray(a, a1[d_9_k_])), [[InArray(a, a1[d_9_k_])]]))) + Invariant(len(a) == i) + Invariant(0 <= i and i <= len(a1)) + Invariant(Forall(int, lambda k: + (Implies(((0) <= (k)) and ((k) < (i)), a[k] == a1[k])))) + Invariant(Forall(int, lambda k: + (Implies(((0) <= (k)) and ((k) < (i)), InArray(a1, a[k])), [[InArray(a1, a[k])]]))) + Invariant(Forall(int, lambda k: + (Implies(((0) <= (k)) and ((k) < (i)), InArray(a, a1[k])), [[InArray(a, a1[k])]]))) # invariants-end - a = a + [a1[d_2_i_]] + a = a + [a1[i]] # assert-start - Assert(InArray(a1, a[d_2_i_])) + Assert(InArray(a1, a[i])) # assert-end - d_2_i_ = d_2_i_ + 1 - d_2_i_ = (len((a))) - (1) - while (d_2_i_) > (0): + i = i + 1 + i = (len((a))) - (1) + while (i) > (0): # invariants-start Invariant(Acc(list_pred(a))) Invariant(Acc(list_pred(a1), 1/2)) Invariant((len(a1)) == (len(a))) - Invariant(not ((d_2_i_) < (0)) or ((len((a))) == (0))) - Invariant(((-1) <= (d_2_i_)) and ((d_2_i_) < (len((a))))) - Invariant(Forall(int, lambda d_3_ii_: - (Forall(int, lambda d_4_jj_: - (Implies((((d_2_i_) <= (d_3_ii_)) and ((d_3_ii_) < (d_4_jj_))) and ((d_4_jj_) < (len((a)))), ((a)[d_3_ii_]) <= ((a)[d_4_jj_])), - [[(a)[d_4_jj_]]])), - [[(a)[d_3_ii_]]]))) - Invariant(Forall(int, lambda d_5_k_: - (Forall(int, lambda d_6_k_k_: - (Implies(((((0) <= (d_5_k_)) and ((d_5_k_) <= (d_2_i_))) and ((d_2_i_) < (d_6_k_k_)) and (d_6_k_k_) < (len((a)))), ((a)[d_5_k_]) <= ((a)[d_6_k_k_])), - [[(a)[d_6_k_k_]]])), - [[(a)[d_5_k_]]]))) - Invariant(Forall(int, lambda d_9_k_: - (Implies(((0) <= (d_9_k_)) and ((d_9_k_) < (len(a))), InArray(a1, a[d_9_k_])), [[InArray(a1, a[d_9_k_])]]))) + Invariant(not ((i) < (0)) or ((len((a))) == (0))) + Invariant(((-1) <= (i)) and ((i) < (len((a))))) + Invariant(Forall(int, lambda ii: + (Forall(int, lambda jj: + (Implies((((i) <= (ii)) and ((ii) < (jj))) and ((jj) < (len((a)))), ((a)[ii]) <= ((a)[jj])), + [[(a)[jj]]])), + [[(a)[ii]]]))) + Invariant(Forall(int, lambda k: + (Forall(int, lambda k_k: + (Implies(((((0) <= (k)) and ((k) <= (i))) and ((i) < (k_k)) and (k_k) < (len((a)))), ((a)[k]) <= ((a)[k_k])), + [[(a)[k_k]]])), + [[(a)[k]]]))) + Invariant(Forall(int, lambda k: + (Implies(((0) <= (k)) and ((k) < (len(a))), InArray(a1, a[k])), [[InArray(a1, a[k])]]))) # invariants-end - d_7_j_ : int = 0 - while (d_7_j_) < (d_2_i_): + j : int = 0 + while (j) < (i): # invariants-start Invariant(Acc(list_pred(a))) Invariant(Acc(list_pred(a1), 1/2)) Invariant((len(a1)) == (len(a))) - Invariant((((0) < (d_2_i_)) and ((d_2_i_) < (len((a))))) and (((0) <= (d_7_j_)) and ((d_7_j_) <= (d_2_i_)))) - Invariant(Forall(int, lambda d_8_ii_: - (Forall(int, lambda d_9_jj_: - (Implies((((d_2_i_) <= (d_8_ii_)) and ((d_8_ii_) <= (d_9_jj_))) and ((d_9_jj_) < (len((a)))), ((a)[d_8_ii_]) <= ((a)[d_9_jj_])), - [[(a)[d_9_jj_]]])), - [[(a)[d_8_ii_]]]))) - Invariant(Forall(int, lambda d_10_k_: - (Forall(int, lambda d_11_k_k_: - (Implies(((((0) <= (d_10_k_)) and ((d_10_k_) <= (d_2_i_))) and ((d_2_i_) < (d_11_k_k_))) and ((d_11_k_k_) < (len((a)))), ((a)[d_10_k_]) <= ((a)[d_11_k_k_])), - [[(a)[d_11_k_k_]]])), - [[(a)[d_10_k_]]]))) - Invariant(Forall(int, lambda d_12_k_: - (Implies(((0) <= (d_12_k_)) and ((d_12_k_) <= (d_7_j_)), ((a)[d_12_k_]) <= ((a)[d_7_j_])), - [[(a)[d_12_k_]]]))) - Invariant(Forall(int, lambda d_9_k_: - (Implies(((0) <= (d_9_k_)) and ((d_9_k_) < (len(a))), InArray(a1, a[d_9_k_])), [[InArray(a1, a[d_9_k_])]]))) + Invariant((((0) < (i)) and ((i) < (len((a))))) and (((0) <= (j)) and ((j) <= (i)))) + Invariant(Forall(int, lambda ii: + (Forall(int, lambda jj: + (Implies((((i) <= (ii)) and ((ii) <= (jj))) and ((jj) < (len((a)))), ((a)[ii]) <= ((a)[jj])), + [[(a)[jj]]])), + [[(a)[ii]]]))) + Invariant(Forall(int, lambda k: + (Forall(int, lambda k_k: + (Implies(((((0) <= (k)) and ((k) <= (i))) and ((i) < (k_k))) and ((k_k) < (len((a)))), ((a)[k]) <= ((a)[k_k])), + [[(a)[k_k]]])), + [[(a)[k]]]))) + Invariant(Forall(int, lambda k: + (Implies(((0) <= (k)) and ((k) <= (j)), ((a)[k]) <= ((a)[j])), + [[(a)[k]]]))) + Invariant(Forall(int, lambda k: + (Implies(((0) <= (k)) and ((k) < (len(a))), InArray(a1, a[k])), [[InArray(a1, a[k])]]))) # invariants-end - if ((a)[d_7_j_]) > ((a)[(d_7_j_) + (1)]): - rhs0_ : int = (a)[(d_7_j_) + (1)] - (a)[(d_7_j_) + (1)] = (a)[d_7_j_] - (a)[d_7_j_] = rhs0_ - d_7_j_ = (d_7_j_) + (1) - d_2_i_ = (d_2_i_) - (1) + if ((a)[j]) > ((a)[(j) + (1)]): + rhs0_ : int = (a)[(j) + (1)] + (a)[(j) + (1)] = (a)[j] + (a)[j] = rhs0_ + j = (j) + (1) + i = (i) - (1) return a # impl-end diff --git a/Bench/035-max-element.py b/Bench/035-max-element.py index 32c700c..b42493f 100644 --- a/Bench/035-max-element.py +++ b/Bench/035-max-element.py @@ -8,26 +8,26 @@ def max__element(l : List[int]) -> int: # pre-conditions-end # post-conditions-start Ensures(Acc(list_pred(l))) - Ensures(Forall(int, lambda d_0_i_: - not (((d_0_i_) >= (0)) and ((d_0_i_) < (len(l)))) or (((l)[d_0_i_]) <= (Result())))) - Ensures(Exists(int, lambda d_1_i_: - (((d_1_i_) >= (0)) and ((d_1_i_) < (len(l)))) and (((l)[d_1_i_]) == (Result())))) + Ensures(Forall(int, lambda i: + not (((i) >= (0)) and ((i) < (len(l)))) or (((l)[i]) <= (Result())))) + Ensures(Exists(int, lambda i: + (((i) >= (0)) and ((i) < (len(l)))) and (((l)[i]) == (Result())))) # post-conditions-end # impl-start result : int = (l)[0] - d_2_i_ : int = 1 - while (d_2_i_) < (len(l)): + i : int = 1 + while (i) < (len(l)): # invariants-start Invariant(Acc(list_pred(l))) - Invariant(((d_2_i_) >= (1)) and ((d_2_i_) <= (len(l)))) - Invariant(Forall(int, lambda d_3_i1_: - not (((d_3_i1_) >= (0)) and ((d_3_i1_) < (d_2_i_))) or (((l)[d_3_i1_]) <= (result)))) - Invariant(Exists(int, lambda d_4_i1_: - (((d_4_i1_) >= (0)) and ((d_4_i1_) < (d_2_i_))) and (((l)[d_4_i1_]) == (result)))) + Invariant(((i) >= (1)) and ((i) <= (len(l)))) + Invariant(Forall(int, lambda i1: + not (((i1) >= (0)) and ((i1) < (i))) or (((l)[i1]) <= (result)))) + Invariant(Exists(int, lambda i1: + (((i1) >= (0)) and ((i1) < (i))) and (((l)[i1]) == (result)))) # invariants-end - if ((l)[d_2_i_]) > (result): - result = (l)[d_2_i_] - d_2_i_ = (d_2_i_) + (1) + if ((l)[i]) > (result): + result = (l)[i] + i = (i) + (1) return result # impl-end diff --git a/Bench/036-fizz_buzz.py b/Bench/036-fizz_buzz.py index e6a6b96..b2f5f0c 100644 --- a/Bench/036-fizz_buzz.py +++ b/Bench/036-fizz_buzz.py @@ -12,18 +12,18 @@ def fizz__buzz(n : int) -> int: # impl-start result : int = 0 - d_1_i_ : int = 0 - while (d_1_i_) < (n): + i : int = 0 + while (i) < (n): # invariants-start - Invariant(((0) <= (d_1_i_)) and ((d_1_i_) <= (n))) + Invariant(((0) <= (i)) and ((i) <= (n))) Invariant(Forall(int, lambda x : (Implies(x >= 0 and x < n, fizz_buzz_fun(x + 1) == (count7__r(x) if ((x % 11 == 0) or (x % 13 == 0)) else 0) + fizz_buzz_fun(x)), [[fizz_buzz_fun(x + 1)]]))) - Invariant(result == fizz_buzz_fun(d_1_i_)) + Invariant(result == fizz_buzz_fun(i)) # invariants-end - if (((d_1_i_ % 11)) == (0)) or (((d_1_i_ % 13)) == (0)): - d_4_cnt_ : int = count7(d_1_i_) - result = (result) + (d_4_cnt_) - d_1_i_ = (d_1_i_) + (1) + if (((i % 11)) == (0)) or (((i % 13)) == (0)): + cnt : int = count7(i) + result = (result) + (cnt) + i = (i) + (1) return result # impl-end @@ -55,15 +55,15 @@ def count7(x : int) -> int: # impl-start count : int = 0 - d_6_y_ : int = x - while (d_6_y_) > (0): + y : int = x + while (y) > (0): # invariants-start - Invariant(((0) <= (d_6_y_)) and ((d_6_y_) <= (x))) - Invariant(((count) + (count7__r(d_6_y_))) == (count7__r(x))) + Invariant(((0) <= (y)) and ((y) <= (x))) + Invariant(((count) + (count7__r(y))) == (count7__r(x))) # invariants-end - if ((d_6_y_ % 10)) == (7): + if ((y % 10)) == (7): count = (count) + (1) - d_6_y_ = d_6_y_ // 10 + y = y // 10 return count # impl-end diff --git a/Bench/037-sort_even.py b/Bench/037-sort_even.py index a4970aa..bb51509 100644 --- a/Bench/037-sort_even.py +++ b/Bench/037-sort_even.py @@ -10,30 +10,30 @@ def sorted__even(a : List[int]) -> List[int]: Ensures(Acc(list_pred(a))) Ensures(Acc(list_pred(Result()))) Ensures((len(Result())) == (len(a))) - Ensures(Forall(int, lambda d_0_i_: - Forall(int, lambda d_1_j_: - not ((((((0) <= (d_0_i_)) and ((d_0_i_) < (d_1_j_))) and ((d_1_j_) < (len(Result())))) and (((d_0_i_ % 2)) == (0))) and (((d_1_j_ % 2)) == (0))) or (((Result())[d_0_i_]) <= ((Result())[d_1_j_]))))) - Ensures(Forall(int, lambda d_2_i_: - not ((((0) <= (d_2_i_)) and ((d_2_i_) < (len(a)))) and (((d_2_i_ % 2)) == (1))) or (((Result())[d_2_i_]) == ((a)[d_2_i_])))) + Ensures(Forall(int, lambda i: + Forall(int, lambda j: + not ((((((0) <= (i)) and ((i) < (j))) and ((j) < (len(Result())))) and (((i % 2)) == (0))) and (((j % 2)) == (0))) or (((Result())[i]) <= ((Result())[j]))))) + Ensures(Forall(int, lambda i: + not ((((0) <= (i)) and ((i) < (len(a)))) and (((i % 2)) == (1))) or (((Result())[i]) == ((a)[i])))) # post-conditions-end # impl-start sorted__even : List[int] =[] - d_3_p_ : List[bool] = [] - d_4_i_ : int = 0 - while (d_4_i_) < (len(a)): + p : List[bool] = [] + i : int = 0 + while (i) < (len(a)): # invariants-start - Invariant(Acc(list_pred(d_3_p_))) + Invariant(Acc(list_pred(p))) Invariant(Acc(list_pred(sorted__even))) Invariant(Acc(list_pred(a))) - Invariant(((0) <= (d_4_i_)) and ((d_4_i_) <= (len(a)))) - Invariant((len(d_3_p_)) == (d_4_i_)) - Invariant(Forall(int, lambda d_5_j_: - not (((0) <= (d_5_j_)) and ((d_5_j_) < (d_4_i_))) or (((d_3_p_)[d_5_j_]) == (((d_5_j_ % 2)) == (0))))) + Invariant(((0) <= (i)) and ((i) <= (len(a)))) + Invariant((len(p)) == (i)) + Invariant(Forall(int, lambda j: + not (((0) <= (j)) and ((j) < (i))) or (((p)[j]) == (((j % 2)) == (0))))) # invariants-end - d_3_p_ = (d_3_p_) + [((d_4_i_ % 2)) == (0)] - d_4_i_ = (d_4_i_) + (1) - sorted__even = SortSeqPred(a, d_3_p_) + p = (p) + [((i % 2)) == (0)] + i = (i) + (1) + sorted__even = SortSeqPred(a, p) return sorted__even # impl-end @@ -49,75 +49,75 @@ def SortSeqPred(s : List[int], p : List[bool]) -> List[int]: Ensures(Acc(list_pred(Result()))) Ensures((len(s)) == (len(p))) Ensures((len(Result())) == (len(s))) - Ensures(Forall(int, lambda d_6_i_: - Forall(int, lambda d_7_j_: - not ((((((0) <= (d_6_i_)) and ((d_6_i_) < (d_7_j_))) and ((d_7_j_) < (len(Result())))) and ((p)[d_6_i_])) and ((p)[d_7_j_])) or (((Result())[d_6_i_]) <= ((Result())[d_7_j_]))))) - Ensures(Forall(int, lambda d_8_i_: - not ((((0) <= (d_8_i_)) and ((d_8_i_) < (len(s)))) and (not((p)[d_8_i_]))) or (((Result())[d_8_i_]) == ((s)[d_8_i_])))) + Ensures(Forall(int, lambda i: + Forall(int, lambda j: + not ((((((0) <= (i)) and ((i) < (j))) and ((j) < (len(Result())))) and ((p)[i])) and ((p)[j])) or (((Result())[i]) <= ((Result())[j]))))) + Ensures(Forall(int, lambda i: + not ((((0) <= (i)) and ((i) < (len(s)))) and (not((p)[i]))) or (((Result())[i]) == ((s)[i])))) # post-conditions-end # impl-start sorted : List[int] = list(s) - d_9_i_ : int = 0 - while (d_9_i_) < (len(sorted)): + i : int = 0 + while (i) < (len(sorted)): # invariants-start Invariant(Acc(list_pred(sorted))) Invariant(Acc(list_pred(p), 1/2)) Invariant(Acc(list_pred(s), 1/2)) Invariant((len(s)) == (len(p))) - Invariant(((0) <= (d_9_i_)) and ((d_9_i_) <= (len(sorted)))) + Invariant(((0) <= (i)) and ((i) <= (len(sorted)))) Invariant((len(sorted)) == (len(s))) - Invariant(Forall(int, lambda d_14_j_: - not ((((0) <= (d_14_j_)) and ((d_14_j_) < (len(s)))) and (not((p)[d_14_j_]))) or (((sorted)[d_14_j_]) == ((s)[d_14_j_])))) - Invariant(Forall(int, lambda d_10_j_: - (Forall(int, lambda d_11_k_: - (not ((((((0) <= (d_10_j_)) and ((d_10_j_) < (d_11_k_))) and ((d_11_k_) < (d_9_i_))) and ((p)[d_10_j_])) and ((p)[d_11_k_])) or - (((sorted)[d_10_j_]) <= ((sorted)[d_11_k_])), [[(sorted)[d_11_k_]]])), [[sorted[d_10_j_]]]))) - Invariant(Forall(int, lambda d_12_j_: - (not ((((0) <= (d_12_j_)) and ((d_12_j_) < (d_9_i_))) and ((p)[d_12_j_])) or - (Forall(int, lambda d_13_k_: - (not ((((d_9_i_) <= (d_13_k_)) and ((d_13_k_) < (len(sorted)))) and ((p)[d_13_k_])) or - (((sorted)[d_12_j_]) <= ((sorted)[d_13_k_])), [[sorted[d_13_k_]]]))), [[(sorted)[d_12_j_]]]))) + Invariant(Forall(int, lambda j: + not ((((0) <= (j)) and ((j) < (len(s)))) and (not((p)[j]))) or (((sorted)[j]) == ((s)[j])))) + Invariant(Forall(int, lambda j: + (Forall(int, lambda k: + (not ((((((0) <= (j)) and ((j) < (k))) and ((k) < (i))) and ((p)[j])) and ((p)[k])) or + (((sorted)[j]) <= ((sorted)[k])), [[(sorted)[k]]])), [[sorted[j]]]))) + Invariant(Forall(int, lambda j: + (not ((((0) <= (j)) and ((j) < (i))) and ((p)[j])) or + (Forall(int, lambda k: + (not ((((i) <= (k)) and ((k) < (len(sorted)))) and ((p)[k])) or + (((sorted)[j]) <= ((sorted)[k])), [[sorted[k]]]))), [[(sorted)[j]]]))) # invariants-end - if (p)[d_9_i_]: - d_15_minIndex_ : int = d_9_i_ - d_16_j_ : int = (d_9_i_) + (1) - while (d_16_j_) < (len(sorted)): + if (p)[i]: + minIndex : int = i + j : int = (i) + (1) + while (j) < (len(sorted)): # invariants-start Invariant(Acc(list_pred(sorted))) Invariant(Acc(list_pred(p), 1/2)) Invariant(Acc(list_pred(s), 1/2)) Invariant((len(s)) == (len(p))) Invariant((len(sorted)) == (len(s))) - Invariant(0 <= d_9_i_ and d_9_i_ < len(sorted)) - Invariant((((d_9_i_) <= (d_15_minIndex_)) and ((d_15_minIndex_) < (d_16_j_))) and ((d_16_j_) <= (len(sorted)))) - Invariant(p[d_9_i_]) - Invariant((p)[d_15_minIndex_]) - Invariant(Forall(int, lambda d_17_k_: - not ((((d_9_i_) <= (d_17_k_)) and ((d_17_k_) < (d_16_j_))) and ((p)[d_17_k_])) or (((sorted)[d_15_minIndex_]) <= ((sorted)[d_17_k_])))) - Invariant(Forall(int, lambda d_14_j_: - not ((((0) <= (d_14_j_)) and ((d_14_j_) < (len(s)))) and (not((p)[d_14_j_]))) or (((sorted)[d_14_j_]) == ((s)[d_14_j_])))) - Invariant(Forall(int, lambda d_10_j_: - (Forall(int, lambda d_11_k_: - (not ((((((0) <= (d_10_j_)) and ((d_10_j_) < (d_11_k_))) and ((d_11_k_) < (d_9_i_))) and ((p)[d_10_j_])) and ((p)[d_11_k_])) or - (((sorted)[d_10_j_]) <= ((sorted)[d_11_k_])), [[(sorted)[d_11_k_]]])), [[sorted[d_10_j_]]]))) - Invariant(Forall(int, lambda d_12_j_: - (not ((((0) <= (d_12_j_)) and ((d_12_j_) < (d_9_i_))) and ((p)[d_12_j_])) or - (Forall(int, lambda d_13_k_: - (not ((((d_9_i_) <= (d_13_k_)) and ((d_13_k_) < (len(sorted)))) and ((p)[d_13_k_])) or - (((sorted)[d_12_j_]) <= ((sorted)[d_13_k_])), [[sorted[d_13_k_]]]))), [[(sorted)[d_12_j_]]]))) + Invariant(0 <= i and i < len(sorted)) + Invariant((((i) <= (minIndex)) and ((minIndex) < (j))) and ((j) <= (len(sorted)))) + Invariant(p[i]) + Invariant((p)[minIndex]) + Invariant(Forall(int, lambda k: + not ((((i) <= (k)) and ((k) < (j))) and ((p)[k])) or (((sorted)[minIndex]) <= ((sorted)[k])))) + Invariant(Forall(int, lambda j: + not ((((0) <= (j)) and ((j) < (len(s)))) and (not((p)[j]))) or (((sorted)[j]) == ((s)[j])))) + Invariant(Forall(int, lambda j: + (Forall(int, lambda k: + (not ((((((0) <= (j)) and ((j) < (k))) and ((k) < (i))) and ((p)[j])) and ((p)[k])) or + (((sorted)[j]) <= ((sorted)[k])), [[(sorted)[k]]])), [[sorted[j]]]))) + Invariant(Forall(int, lambda j: + (not ((((0) <= (j)) and ((j) < (i))) and ((p)[j])) or + (Forall(int, lambda k: + (not ((((i) <= (k)) and ((k) < (len(sorted)))) and ((p)[k])) or + (((sorted)[j]) <= ((sorted)[k])), [[sorted[k]]]))), [[(sorted)[j]]]))) # invariants-end - if ((p)[d_16_j_]) and (((sorted)[d_16_j_]) < ((sorted)[d_15_minIndex_])): - d_15_minIndex_ = d_16_j_ - d_16_j_ = (d_16_j_) + (1) - if (d_15_minIndex_) != (d_9_i_): + if ((p)[j]) and (((sorted)[j]) < ((sorted)[minIndex])): + minIndex = j + j = (j) + (1) + if (minIndex) != (i): # assert-start - Assert((p)[d_15_minIndex_]) - Assert(p[d_9_i_]) + Assert((p)[minIndex]) + Assert(p[i]) # assert-end - rhs0_ : int = (sorted)[d_9_i_] - (sorted)[d_9_i_] = (sorted)[d_15_minIndex_] - (sorted)[d_15_minIndex_] = rhs0_ - d_9_i_ = (d_9_i_) + (1) + rhs0_ : int = (sorted)[i] + (sorted)[i] = (sorted)[minIndex] + (sorted)[minIndex] = rhs0_ + i = (i) + (1) return sorted # impl-end diff --git a/Bench/040-triples-sum-to-zero.py b/Bench/040-triples-sum-to-zero.py index 6121d99..36816a5 100644 --- a/Bench/040-triples-sum-to-zero.py +++ b/Bench/040-triples-sum-to-zero.py @@ -7,59 +7,59 @@ def triples__sum__to__zero(l : List[int]) -> bool: # pre-conditions-end # post-conditions-start Ensures(Acc(list_pred(l))) - Ensures(Implies(not(Result()), Forall(int, lambda d_3_i_: - Forall(int, lambda d_4_j_: - Forall(int, lambda d_5_k_: - Implies((((((((0) <= (d_3_i_)) and ((d_3_i_) < (len(l)))) and (((0) <= (d_4_j_)) and ((d_4_j_) < (len(l))))) and (((0) <= (d_5_k_)) and ((d_5_k_) < (len(l))))) and ((d_3_i_) != (d_4_j_))) and ((d_4_j_) != (d_5_k_))) and ((d_3_i_) != (d_5_k_)), ((((l)[d_3_i_]) + ((l)[d_4_j_])) + ((l)[d_5_k_])) != (0))))))) - Ensures(Implies(Result(), Exists(int, lambda d_0_i_: - Exists(int, lambda d_1_j_: - Exists(int, lambda d_2_k_: - ((((((((0) <= (d_0_i_)) and ((d_0_i_) < (len(l)))) and (((0) <= (d_1_j_)) and ((d_1_j_) < (len(l))))) and (((0) <= (d_2_k_)) and ((d_2_k_) < (len(l))))) and ((d_0_i_) != (d_1_j_))) and ((d_1_j_) != (d_2_k_))) and ((d_0_i_) != (d_2_k_))) and (((((l)[d_0_i_]) + ((l)[d_1_j_])) + ((l)[d_2_k_])) == (0))))))) + Ensures(Implies(not(Result()), Forall(int, lambda i: + Forall(int, lambda j: + Forall(int, lambda k: + Implies((((((((0) <= (i)) and ((i) < (len(l)))) and (((0) <= (j)) and ((j) < (len(l))))) and (((0) <= (k)) and ((k) < (len(l))))) and ((i) != (j))) and ((j) != (k))) and ((i) != (k)), ((((l)[i]) + ((l)[j])) + ((l)[k])) != (0))))))) + Ensures(Implies(Result(), Exists(int, lambda i: + Exists(int, lambda j: + Exists(int, lambda k: + ((((((((0) <= (i)) and ((i) < (len(l)))) and (((0) <= (j)) and ((j) < (len(l))))) and (((0) <= (k)) and ((k) < (len(l))))) and ((i) != (j))) and ((j) != (k))) and ((i) != (k))) and (((((l)[i]) + ((l)[j])) + ((l)[k])) == (0))))))) # post-conditions-end # impl-start - d_6_i_ : int = 0 - while (d_6_i_) < (len(l)): + i : int = 0 + while (i) < (len(l)): # invariants-start Invariant(Acc(list_pred(l), 1/2)) - Invariant(((d_6_i_) >= (0)) and ((d_6_i_) <= (len(l)))) - Invariant(Forall(int, lambda d_7_i1_: - Forall(int, lambda d_8_j_: - Forall(int, lambda d_9_k_: - (Implies((((((((0) <= (d_7_i1_)) and ((d_7_i1_) < (d_6_i_))) and (((0) <= (d_8_j_)) and ((d_8_j_) < (len(l))))) and (((0) <= (d_9_k_)) and ((d_9_k_) < (len(l))))) and ((d_7_i1_) != (d_8_j_))) and ((d_8_j_) != (d_9_k_))) and ((d_7_i1_) != (d_9_k_)), ((((l)[d_7_i1_]) + ((l)[d_8_j_])) + ((l)[d_9_k_])) != (0)), [[(((l)[d_7_i1_]) + ((l)[d_8_j_])) + ((l)[d_9_k_])]]))))) + Invariant(((i) >= (0)) and ((i) <= (len(l)))) + Invariant(Forall(int, lambda i1: + Forall(int, lambda j: + Forall(int, lambda k: + (Implies((((((((0) <= (i1)) and ((i1) < (i))) and (((0) <= (j)) and ((j) < (len(l))))) and (((0) <= (k)) and ((k) < (len(l))))) and ((i1) != (j))) and ((j) != (k))) and ((i1) != (k)), ((((l)[i1]) + ((l)[j])) + ((l)[k])) != (0)), [[(((l)[i1]) + ((l)[j])) + ((l)[k])]]))))) # invariants-end - d_13_j_ : int = 0 - while (d_13_j_) < (len(l)): + j : int = 0 + while (j) < (len(l)): # invariants-start Invariant(Acc(list_pred(l), 1/2)) - Invariant(((d_6_i_) >= (0)) and ((d_6_i_) < (len(l)))) - Invariant(((d_13_j_) >= (0)) and ((d_13_j_) <= (len(l)))) - Invariant(Forall(int, lambda d_14_i1_: - Forall(int, lambda d_15_j_: - Forall(int, lambda d_16_k_: - (Implies(((((((((0) <= (d_14_i1_)) and ((d_14_i1_) < (d_6_i_))) and (((0) <= (d_15_j_)) and ((d_15_j_) < (len(l))))) and (((0) <= (d_16_k_)) and ((d_16_k_) < (len(l)))))) or - (d_14_i1_ == d_6_i_ and (d_15_j_) >= 0 and (d_15_j_) < d_13_j_ and (d_16_k_) >= 0 and (d_16_k_) < len(l))) - and ((d_14_i1_) != (d_15_j_)) and ((d_15_j_) != (d_16_k_))) and ((d_14_i1_) != (d_16_k_)), ((((l)[d_14_i1_]) + ((l)[d_15_j_])) + ((l)[d_16_k_])) != (0)), [[(((l)[d_14_i1_]) + ((l)[d_15_j_])) + ((l)[d_16_k_])]]))))) + Invariant(((i) >= (0)) and ((i) < (len(l)))) + Invariant(((j) >= (0)) and ((j) <= (len(l)))) + Invariant(Forall(int, lambda i1: + Forall(int, lambda j: + Forall(int, lambda k: + (Implies(((((((((0) <= (i1)) and ((i1) < (i))) and (((0) <= (j)) and ((j) < (len(l))))) and (((0) <= (k)) and ((k) < (len(l)))))) or + (i1 == i and (j) >= 0 and (j) < j and (k) >= 0 and (k) < len(l))) + and ((i1) != (j)) and ((j) != (k))) and ((i1) != (k)), ((((l)[i1]) + ((l)[j])) + ((l)[k])) != (0)), [[(((l)[i1]) + ((l)[j])) + ((l)[k])]]))))) # invariants-end - d_24_k_ : int = 0 - while (d_24_k_) < (len(l)): + k : int = 0 + while (k) < (len(l)): # invariants-start Invariant(Acc(list_pred(l), 1/2)) - Invariant(((d_6_i_) >= (0)) and ((d_6_i_) < (len(l)))) - Invariant(((d_13_j_) >= (0)) and ((d_13_j_) < (len(l)))) - Invariant(((d_24_k_) >= (0)) and ((d_24_k_) <= (len(l)))) - Invariant(Forall(int, lambda d_14_i1_: - Forall(int, lambda d_15_j_: - Forall(int, lambda d_16_k_: - (Implies(((((((((0) <= (d_14_i1_)) and ((d_14_i1_) < (d_6_i_))) and (((0) <= (d_15_j_)) and ((d_15_j_) < (len(l))))) and (((0) <= (d_16_k_)) and ((d_16_k_) < (len(l)))))) or - (d_14_i1_ == d_6_i_ and (d_15_j_) >= 0 and (d_15_j_) < d_13_j_ and (d_16_k_) >= 0 and (d_16_k_) < len(l)) or - (d_14_i1_ == d_6_i_ and (d_15_j_) == d_13_j_ and (d_16_k_) >= 0 and (d_16_k_) < d_24_k_)) - and ((d_14_i1_) != (d_15_j_)) and ((d_15_j_) != (d_16_k_))) and ((d_14_i1_) != (d_16_k_)), ((((l)[d_14_i1_]) + ((l)[d_15_j_])) + ((l)[d_16_k_])) != (0)), [[(((l)[d_14_i1_]) + ((l)[d_15_j_])) + ((l)[d_16_k_])]]))))) + Invariant(((i) >= (0)) and ((i) < (len(l)))) + Invariant(((j) >= (0)) and ((j) < (len(l)))) + Invariant(((k) >= (0)) and ((k) <= (len(l)))) + Invariant(Forall(int, lambda i1: + Forall(int, lambda j: + Forall(int, lambda k: + (Implies(((((((((0) <= (i1)) and ((i1) < (i))) and (((0) <= (j)) and ((j) < (len(l))))) and (((0) <= (k)) and ((k) < (len(l)))))) or + (i1 == i and (j) >= 0 and (j) < j and (k) >= 0 and (k) < len(l)) or + (i1 == i and (j) == j and (k) >= 0 and (k) < k)) + and ((i1) != (j)) and ((j) != (k))) and ((i1) != (k)), ((((l)[i1]) + ((l)[j])) + ((l)[k])) != (0)), [[(((l)[i1]) + ((l)[j])) + ((l)[k])]]))))) # invariants-end - if ((((d_6_i_) != (d_13_j_)) and ((d_13_j_) != (d_24_k_))) and ((d_6_i_) != (d_24_k_))) and (((((l)[d_6_i_]) + ((l)[d_13_j_])) + ((l)[d_24_k_])) == (0)): + if ((((i) != (j)) and ((j) != (k))) and ((i) != (k))) and (((((l)[i]) + ((l)[j])) + ((l)[k])) == (0)): return True - d_24_k_ = (d_24_k_) + (1) - d_13_j_ = (d_13_j_) + (1) - d_6_i_ = (d_6_i_) + (1) + k = (k) + (1) + j = (j) + (1) + i = (i) + (1) return False # impl-end diff --git a/Bench/042-incr-list.py b/Bench/042-incr-list.py index dd6d6bf..752c28f 100644 --- a/Bench/042-incr-list.py +++ b/Bench/042-incr-list.py @@ -9,23 +9,23 @@ def incr__list(l : List[int]) -> List[int]: Ensures(Acc(list_pred(l))) Ensures(Acc(list_pred(Result()))) Ensures((len(Result())) == (len(l))) - Ensures(Forall(int, lambda d_0_i_: - not (((0) <= (d_0_i_)) and ((d_0_i_) < (len(l)))) or (((Result())[d_0_i_]) == (((l)[d_0_i_]) + (1))))) + Ensures(Forall(int, lambda i: + not (((0) <= (i)) and ((i) < (len(l)))) or (((Result())[i]) == (((l)[i]) + (1))))) # post-conditions-end # impl-start result : List[int] = list([]) - d_1_i_ : int = 0 - while (d_1_i_) < (len(l)): + i : int = 0 + while (i) < (len(l)): # invariants-start Invariant(Acc(list_pred(result))) Invariant(Acc(list_pred(l))) - Invariant(((0) <= (d_1_i_)) and ((d_1_i_) <= (len(l)))) - Invariant((len(result)) == (d_1_i_)) - Invariant(Forall(int, lambda d_2_i1_: - not (((0) <= (d_2_i1_)) and ((d_2_i1_) < (d_1_i_))) or (((result)[d_2_i1_]) == (((l)[d_2_i1_]) + (1))))) + Invariant(((0) <= (i)) and ((i) <= (len(l)))) + Invariant((len(result)) == (i)) + Invariant(Forall(int, lambda i1: + not (((0) <= (i1)) and ((i1) < (i))) or (((result)[i1]) == (((l)[i1]) + (1))))) # invariants-end - result = (result) + ([((l)[d_1_i_]) + (1)]) - d_1_i_ = (d_1_i_) + (1) + result = (result) + ([((l)[i]) + (1)]) + i = (i) + (1) return result # impl-end diff --git a/Bench/043-pairs-sum-to-zero.py b/Bench/043-pairs-sum-to-zero.py index 90bf5d0..1cc76df 100644 --- a/Bench/043-pairs-sum-to-zero.py +++ b/Bench/043-pairs-sum-to-zero.py @@ -7,46 +7,46 @@ def pairs__sum__to__zero(l : List[int]) -> bool: # pre-conditions-end # post-conditions-start Ensures(Acc(list_pred(l))) - Ensures(not (Result()) or (Exists(int, lambda d_0_i_: - Exists(int, lambda d_1_j_: - (((((0) <= (d_0_i_)) and ((d_0_i_) < (len(l)))) and (((0) <= (d_1_j_)) and ((d_1_j_) < (len(l))))) and ((d_0_i_) != (d_1_j_))) and ((((l)[d_0_i_]) + ((l)[d_1_j_])) == (0)))))) - Ensures(not (not(Result())) or (Forall(int, lambda d_2_i_: - Forall(int, lambda d_3_j_: - (not (((((0) <= (d_2_i_)) and ((d_2_i_) < (len(l)))) and (((0) <= (d_3_j_)) and ((d_3_j_) < (len(l))))) and ((d_2_i_) != (d_3_j_))) or ((((l)[d_2_i_]) + ((l)[d_3_j_])) != (0)), [[((l)[d_2_i_]) + ((l)[d_3_j_])]]))))) + Ensures(not (Result()) or (Exists(int, lambda i: + Exists(int, lambda j: + (((((0) <= (i)) and ((i) < (len(l)))) and (((0) <= (j)) and ((j) < (len(l))))) and ((i) != (j))) and ((((l)[i]) + ((l)[j])) == (0)))))) + Ensures(not (not(Result())) or (Forall(int, lambda i: + Forall(int, lambda j: + (not (((((0) <= (i)) and ((i) < (len(l)))) and (((0) <= (j)) and ((j) < (len(l))))) and ((i) != (j))) or ((((l)[i]) + ((l)[j])) != (0)), [[((l)[i]) + ((l)[j])]]))))) # post-conditions-end # impl-start result : bool = False - d_4_i_ : int = 0 - while (d_4_i_) < (len(l)): + i : int = 0 + while (i) < (len(l)): # invariants-start Invariant(Acc(list_pred(l))) - Invariant(((d_4_i_) >= (0)) and ((d_4_i_) <= (len(l)))) - Invariant(Implies(not(result), Forall(int, lambda d_5_i1_: - Forall(int, lambda d_6_j_: - (Implies(((((0) <= (d_5_i1_)) and ((d_5_i1_) < (d_4_i_))) and (((0) <= (d_6_j_)) and ((d_6_j_) < (len(l))))) and ((d_5_i1_) != (d_6_j_)), (((l)[d_5_i1_]) + ((l)[d_6_j_])) != (0)), [[((l)[d_5_i1_]) + ((l)[d_6_j_])]]))))) - Invariant(not (result) or (Exists(int, lambda d_7_i1_: - Exists(int, lambda d_8_j_: - (((((0) <= (d_7_i1_)) and ((d_7_i1_) < (d_4_i_))) and (((0) <= (d_8_j_)) and ((d_8_j_) < (len(l))))) and ((d_7_i1_) != (d_8_j_))) and ((((l)[d_7_i1_]) + ((l)[d_8_j_])) == (0)))))) + Invariant(((i) >= (0)) and ((i) <= (len(l)))) + Invariant(Implies(not(result), Forall(int, lambda i1: + Forall(int, lambda j: + (Implies(((((0) <= (i1)) and ((i1) < (i))) and (((0) <= (j)) and ((j) < (len(l))))) and ((i1) != (j)), (((l)[i1]) + ((l)[j])) != (0)), [[((l)[i1]) + ((l)[j])]]))))) + Invariant(not (result) or (Exists(int, lambda i1: + Exists(int, lambda j: + (((((0) <= (i1)) and ((i1) < (i))) and (((0) <= (j)) and ((j) < (len(l))))) and ((i1) != (j))) and ((((l)[i1]) + ((l)[j])) == (0)))))) # invariants-end - d_9_j_ : int = 0 - while (d_9_j_) < (len(l)): + j : int = 0 + while (j) < (len(l)): # invariants-start Invariant(Acc(list_pred(l))) - Invariant(((d_4_i_) >= (0)) and ((d_4_i_) < (len(l)))) - Invariant(((d_9_j_) >= (0)) and ((d_9_j_) <= (len(l)))) - Invariant(Implies(not(result), Forall(int, lambda d_5_i1_: - Forall(int, lambda d_6_j_: - (Implies((((((0) <= (d_5_i1_)) and ((d_5_i1_) < (d_4_i_))) and (((0) <= (d_6_j_)) and ((d_6_j_) < (len(l))))) or (d_5_i1_ == d_4_i_ and ((0) <= (d_6_j_)) and ((d_6_j_) < (d_9_j_)))) and ((d_5_i1_) != (d_6_j_)), (((l)[d_5_i1_]) + ((l)[d_6_j_])) != (0)), [[((l)[d_5_i1_]) + ((l)[d_6_j_])]]))))) - Invariant(not (result) or ((Exists(int, lambda d_13_i1_: - Exists(int, lambda d_14_j1_: - (((((0) <= (d_13_i1_)) and ((d_13_i1_) < (d_4_i_))) and (((0) <= (d_14_j1_)) and ((d_14_j1_) < (len(l))))) and ((d_13_i1_) != (d_14_j1_))) and ((((l)[d_13_i1_]) + ((l)[d_14_j1_])) == (0))))) - or (Exists(int, lambda d_15_j1_: - ((((0) <= (d_15_j1_)) and ((d_15_j1_) < (d_9_j_))) and ((d_4_i_) != (d_15_j1_))) and ((((l)[d_4_i_]) + ((l)[d_15_j1_])) == (0)))))) + Invariant(((i) >= (0)) and ((i) < (len(l)))) + Invariant(((j) >= (0)) and ((j) <= (len(l)))) + Invariant(Implies(not(result), Forall(int, lambda i1: + Forall(int, lambda j: + (Implies((((((0) <= (i1)) and ((i1) < (i))) and (((0) <= (j)) and ((j) < (len(l))))) or (i1 == i and ((0) <= (j)) and ((j) < (j)))) and ((i1) != (j)), (((l)[i1]) + ((l)[j])) != (0)), [[((l)[i1]) + ((l)[j])]]))))) + Invariant(not (result) or ((Exists(int, lambda i1: + Exists(int, lambda j1: + (((((0) <= (i1)) and ((i1) < (i))) and (((0) <= (j1)) and ((j1) < (len(l))))) and ((i1) != (j1))) and ((((l)[i1]) + ((l)[j1])) == (0))))) + or (Exists(int, lambda j1: + ((((0) <= (j1)) and ((j1) < (j))) and ((i) != (j1))) and ((((l)[i]) + ((l)[j1])) == (0)))))) # invariants-end - if ((d_4_i_) != (d_9_j_)) and ((((l)[d_4_i_]) + ((l)[d_9_j_])) == (0)): + if ((i) != (j)) and ((((l)[i]) + ((l)[j])) == (0)): result = True - d_9_j_ = (d_9_j_) + (1) - d_4_i_ = (d_4_i_) + (1) + j = (j) + (1) + i = (i) + (1) return result # impl-end diff --git a/Bench/046-fib4.py b/Bench/046-fib4.py index 2b801a9..a599add 100644 --- a/Bench/046-fib4.py +++ b/Bench/046-fib4.py @@ -29,25 +29,25 @@ def fib4(n : int) -> int: return 0 if (n) == (3): return 1 - d_0_a_ : int = 0 - d_1_b_ : int = 0 - d_2_c_ : int = 0 - d_3_d_ : int = 1 - d_4_i_ : int = 4 - while (d_4_i_) <= (n): + a : int = 0 + b : int = 0 + c : int = 0 + d : int = 1 + i : int = 4 + while (i) <= (n): # invariants-start - Invariant(((4) <= (d_4_i_)) and ((d_4_i_) <= ((n) + (1)))) - Invariant((d_0_a_) == (fib4__rec((d_4_i_) - (4)))) - Invariant((d_1_b_) == (fib4__rec((d_4_i_) - (3)))) - Invariant((d_2_c_) == (fib4__rec((d_4_i_) - (2)))) - Invariant((d_3_d_) == (fib4__rec((d_4_i_) - (1)))) + Invariant(((4) <= (i)) and ((i) <= ((n) + (1)))) + Invariant((a) == (fib4__rec((i) - (4)))) + Invariant((b) == (fib4__rec((i) - (3)))) + Invariant((c) == (fib4__rec((i) - (2)))) + Invariant((d) == (fib4__rec((i) - (1)))) # invariants-end - d_5_temp_ : int = (((d_3_d_) + (d_2_c_)) + (d_1_b_)) + (d_0_a_) - d_0_a_ = d_1_b_ - d_1_b_ = d_2_c_ - d_2_c_ = d_3_d_ - d_3_d_ = d_5_temp_ - d_4_i_ = (d_4_i_) + (1) - result : int = d_3_d_ + temp : int = (((d) + (c)) + (b)) + (a) + a = b + b = c + c = d + d = temp + i = (i) + (1) + result : int = d return result # impl-end diff --git a/Bench/048-is-palindrome.py b/Bench/048-is-palindrome.py index 7c74717..b9b95ab 100644 --- a/Bench/048-is-palindrome.py +++ b/Bench/048-is-palindrome.py @@ -7,22 +7,22 @@ def is__palindrome(text : List[int]) -> bool: # pre-conditions-end # post-conditions-start Ensures(Acc(list_pred(text))) - Ensures((Result()) == (Forall(int, lambda d_0_i_: - not (((d_0_i_) >= (0)) and ((d_0_i_) < (len(text)))) or (((text)[d_0_i_]) == ((text)[((len(text)) - (d_0_i_)) - (1)]))))) + Ensures((Result()) == (Forall(int, lambda i: + not (((i) >= (0)) and ((i) < (len(text)))) or (((text)[i]) == ((text)[((len(text)) - (i)) - (1)]))))) # post-conditions-end # impl-start result : bool = True - d_1_i_ : int = 0 - while (d_1_i_) < ((len(text) // 2)): + i : int = 0 + while (i) < ((len(text) // 2)): # invariants-start Invariant(Acc(list_pred(text))) - Invariant(((0) <= (d_1_i_)) and ((d_1_i_) <= ((len(text) // 2)))) - Invariant((result) == (Forall(int, lambda d_2_i1_: - not (((d_2_i1_) >= (0)) and ((d_2_i1_) < (d_1_i_))) or (((text)[d_2_i1_]) == ((text)[((len(text)) - (d_2_i1_)) - (1)]))))) + Invariant(((0) <= (i)) and ((i) <= ((len(text) // 2)))) + Invariant((result) == (Forall(int, lambda i1: + not (((i1) >= (0)) and ((i1) < (i))) or (((text)[i1]) == ((text)[((len(text)) - (i1)) - (1)]))))) # invariants-end - if ((text)[d_1_i_]) != ((text)[((len(text)) - (d_1_i_)) - (1)]): + if ((text)[i]) != ((text)[((len(text)) - (i)) - (1)]): result = False - d_1_i_ = (d_1_i_) + (1) + i = (i) + (1) return result # impl-end diff --git a/Bench/049-modp.py b/Bench/049-modp.py index 063a278..6dae246 100644 --- a/Bench/049-modp.py +++ b/Bench/049-modp.py @@ -26,17 +26,17 @@ def modp(n : int, p : int) -> int: # impl-start r : int = (1 % p) - d_0_i_ : int = 0 - while (d_0_i_) < (n): + i : int = 0 + while (i) < (n): # invariants-start - Invariant(((0) <= (d_0_i_)) and ((d_0_i_) <= (n))) - Invariant(Forall(int, lambda d_0_i_: (Implies(d_0_i_ >= 0 and d_0_i_ < n, modp__rec(d_0_i_ + 1, p) == (modp__rec(d_0_i_, p) * 2) % p)))) - Invariant((r) == (modp__rec(d_0_i_, p))) + Invariant(((0) <= (i)) and ((i) <= (n))) + Invariant(Forall(int, lambda i: (Implies(i >= 0 and i < n, modp__rec(i + 1, p) == (modp__rec(i, p) * 2) % p)))) + Invariant((r) == (modp__rec(i, p))) # invariants-end # assert-start - Assert(modp__rec(d_0_i_ + 1, p) == (modp__rec(d_0_i_, p) * 2) % p) + Assert(modp__rec(i + 1, p) == (modp__rec(i, p) * 2) % p) # assert-end r = (((r) * (2)) % p) - d_0_i_ = (d_0_i_) + (1) + i = (i) + (1) return r # impl-end diff --git a/Bench/050-encode_shift.py b/Bench/050-encode_shift.py index 02c71b6..c4b5f93 100644 --- a/Bench/050-encode_shift.py +++ b/Bench/050-encode_shift.py @@ -18,61 +18,61 @@ def decode__char(c : int) -> int : def encode__shift(s : List[int]) -> List[int]: # pre-conditions-start Requires(Acc(list_pred(s))) - Requires(Forall(int, lambda d_0_i_: - not (((0) <= (d_0_i_)) and ((d_0_i_) < (len(s)))) or (((97) <= ((s)[d_0_i_])) and (((s)[d_0_i_]) <= (122))))) + Requires(Forall(int, lambda i: + not (((0) <= (i)) and ((i) < (len(s)))) or (((97) <= ((s)[i])) and (((s)[i]) <= (122))))) # pre-conditions-end # post-conditions-start Ensures(Acc(list_pred(Result()))) Ensures(Acc(list_pred(s))) Ensures((len(s)) == (len(Result()))) - Ensures(Forall(int, lambda d_1_i_: - not (((0) <= (d_1_i_)) and ((d_1_i_) < (len(s)))) or (((Result())[d_1_i_]) == (encode__char((s)[d_1_i_]))))) + Ensures(Forall(int, lambda i: + not (((0) <= (i)) and ((i) < (len(s)))) or (((Result())[i]) == (encode__char((s)[i]))))) # post-conditions-end # impl-start t : List[int] = [] - d_2_i_ : int = 0 - while (d_2_i_) < (len(s)): + i : int = 0 + while (i) < (len(s)): # invariants-start Invariant(Acc(list_pred(t))) Invariant(Acc(list_pred(s))) - Invariant(((0) <= (d_2_i_)) and ((d_2_i_) <= (len(s)))) - Invariant((len(t)) == (d_2_i_)) - Invariant(Forall(int, lambda d_3_j_: - (not (((0) <= (d_3_j_)) and ((d_3_j_) < (d_2_i_))) or (((t)[d_3_j_]) == (encode__char((s)[d_3_j_]))), [[encode__char((s)[d_3_j_])]]))) + Invariant(((0) <= (i)) and ((i) <= (len(s)))) + Invariant((len(t)) == (i)) + Invariant(Forall(int, lambda j: + (not (((0) <= (j)) and ((j) < (i))) or (((t)[j]) == (encode__char((s)[j]))), [[encode__char((s)[j])]]))) # invariants-end - t = (t) + [encode__char((s)[d_2_i_])] - d_2_i_ = (d_2_i_) + (1) + t = (t) + [encode__char((s)[i])] + i = (i) + (1) return t # impl-end def decode__shift(s : List[int]) -> List[int]: # pre-conditions-start Requires(Acc(list_pred(s))) - Requires(Forall(int, lambda d_4_i_: - not (((0) <= (d_4_i_)) and ((d_4_i_) < (len(s)))) or (((97) <= ((s)[d_4_i_])) and (((s)[d_4_i_]) <= (122))))) + Requires(Forall(int, lambda i: + not (((0) <= (i)) and ((i) < (len(s)))) or (((97) <= ((s)[i])) and (((s)[i]) <= (122))))) # pre-conditions-end # post-conditions-start Ensures(Acc(list_pred(Result()))) Ensures(Acc(list_pred(s))) Ensures((len(s)) == (len(Result()))) - Ensures(Forall(int, lambda d_5_i_: - not (((0) <= (d_5_i_)) and ((d_5_i_) < (len(s)))) or (((Result())[d_5_i_]) == (decode__char((s)[d_5_i_]))))) + Ensures(Forall(int, lambda i: + not (((0) <= (i)) and ((i) < (len(s)))) or (((Result())[i]) == (decode__char((s)[i]))))) # post-conditions-end # impl-start t : List[int] = [] - d_6_i_ : int = 0 - while (d_6_i_) < (len(s)): + i : int = 0 + while (i) < (len(s)): # invariants-start Invariant(Acc(list_pred(t))) Invariant(Acc(list_pred(s))) - Invariant(((0) <= (d_6_i_)) and ((d_6_i_) <= (len(s)))) - Invariant((len(t)) == (d_6_i_)) - Invariant(Forall(int, lambda d_7_j_: - (not (((0) <= (d_7_j_)) and ((d_7_j_) < (d_6_i_))) or (((t)[d_7_j_]) == (decode__char((s)[d_7_j_]))), [[decode__char((s)[d_7_j_])]]))) + Invariant(((0) <= (i)) and ((i) <= (len(s)))) + Invariant((len(t)) == (i)) + Invariant(Forall(int, lambda j: + (not (((0) <= (j)) and ((j) < (i))) or (((t)[j]) == (decode__char((s)[j]))), [[decode__char((s)[j])]]))) # invariants-end - t = (t) + [decode__char((s)[d_6_i_])] - d_6_i_ = (d_6_i_) + (1) + t = (t) + [decode__char((s)[i])] + i = (i) + (1) return t # impl-end diff --git a/Bench/051-remove-vowels.py b/Bench/051-remove-vowels.py index 58aa941..d31536a 100644 --- a/Bench/051-remove-vowels.py +++ b/Bench/051-remove-vowels.py @@ -8,32 +8,32 @@ def remove__vowels(text : List[int]) -> List[int]: # post-conditions-start Ensures(Acc(list_pred(text))) Ensures(Acc(list_pred(Result()))) - Ensures(Forall(int, lambda d_0_i_: - not (((d_0_i_) >= (0)) and ((d_0_i_) < (len(Result())))) or (((((((Result())[d_0_i_]) != (0)) and (((Result())[d_0_i_]) != (1))) and (((Result())[d_0_i_]) != (2))) and (((Result())[d_0_i_]) != (3))) and (((Result())[d_0_i_]) != (4))))) - Ensures(Forall(int, lambda d_1_i_: - not (((d_1_i_) >= (0)) and ((d_1_i_) < (len(Result())))) or (((Result())[d_1_i_]) in (text)))) - Ensures(Forall(int, lambda d_2_j_: - not ((((((((d_2_j_) >= (0)) and ((d_2_j_) < (len(text)))) and (((text)[d_2_j_]) != (0))) and (((text)[d_2_j_]) != (1))) and (((text)[d_2_j_]) != (2))) and (((text)[d_2_j_]) != (3))) and (((text)[d_2_j_]) != (4))) or (((text)[d_2_j_]) in (Result())))) + Ensures(Forall(int, lambda i: + not (((i) >= (0)) and ((i) < (len(Result())))) or (((((((Result())[i]) != (0)) and (((Result())[i]) != (1))) and (((Result())[i]) != (2))) and (((Result())[i]) != (3))) and (((Result())[i]) != (4))))) + Ensures(Forall(int, lambda i: + not (((i) >= (0)) and ((i) < (len(Result())))) or (((Result())[i]) in (text)))) + Ensures(Forall(int, lambda j: + not ((((((((j) >= (0)) and ((j) < (len(text)))) and (((text)[j]) != (0))) and (((text)[j]) != (1))) and (((text)[j]) != (2))) and (((text)[j]) != (3))) and (((text)[j]) != (4))) or (((text)[j]) in (Result())))) # post-conditions-end # impl-start s : List[int] = [] - d_3_i_ : int = 0 - while (d_3_i_) < (len(text)): + i : int = 0 + while (i) < (len(text)): # invariants-start Invariant(Acc(list_pred(text))) Invariant(Acc(list_pred(s))) - Invariant(((0) <= (d_3_i_)) and ((d_3_i_) <= (len(text)))) - Invariant(Forall(int, lambda d_4_i_: - not (((d_4_i_) >= (0)) and ((d_4_i_) < (len(s)))) or (((((((s)[d_4_i_]) != (0)) and (((s)[d_4_i_]) != (1))) and (((s)[d_4_i_]) != (2))) and (((s)[d_4_i_]) != (3))) and (((s)[d_4_i_]) != (4))))) - Invariant(Forall(int, lambda d_5_i_: - not (((d_5_i_) >= (0)) and ((d_5_i_) < (len(s)))) or (((s)[d_5_i_]) in (text)))) - Invariant(Forall(int, lambda d_6_j_: - not ((((((((d_6_j_) >= (0)) and ((d_6_j_) < (d_3_i_))) and (((text)[d_6_j_]) != (0))) and (((text)[d_6_j_]) != (1))) and (((text)[d_6_j_]) != (2))) and (((text)[d_6_j_]) != (3))) and (((text)[d_6_j_]) != (4))) or (((text)[d_6_j_]) in (s)))) + Invariant(((0) <= (i)) and ((i) <= (len(text)))) + Invariant(Forall(int, lambda i: + not (((i) >= (0)) and ((i) < (len(s)))) or (((((((s)[i]) != (0)) and (((s)[i]) != (1))) and (((s)[i]) != (2))) and (((s)[i]) != (3))) and (((s)[i]) != (4))))) + Invariant(Forall(int, lambda i: + not (((i) >= (0)) and ((i) < (len(s)))) or (((s)[i]) in (text)))) + Invariant(Forall(int, lambda j: + not ((((((((j) >= (0)) and ((j) < (i))) and (((text)[j]) != (0))) and (((text)[j]) != (1))) and (((text)[j]) != (2))) and (((text)[j]) != (3))) and (((text)[j]) != (4))) or (((text)[j]) in (s)))) # invariants-end - d_7_c_ : int = (text)[d_3_i_] - if (((((d_7_c_) != (0)) and ((d_7_c_) != (1))) and ((d_7_c_) != (2))) and ((d_7_c_) != (3))) and ((d_7_c_) != (4)): - s = (s) + [d_7_c_] - d_3_i_ = (d_3_i_) + (1) + c : int = (text)[i] + if (((((c) != (0)) and ((c) != (1))) and ((c) != (2))) and ((c) != (3))) and ((c) != (4)): + s = (s) + [c] + i = (i) + (1) return s # impl-end diff --git a/Bench/052-below-threshold.py b/Bench/052-below-threshold.py index bfed2a5..7c316a5 100644 --- a/Bench/052-below-threshold.py +++ b/Bench/052-below-threshold.py @@ -7,22 +7,22 @@ def below__threshold(l : List[int], t : int) -> bool: # pre-conditions-end # post-conditions-start Ensures(Acc(list_pred(l))) - Ensures((Result()) == (Forall(int, lambda d_0_i_: - not (((d_0_i_) >= (0)) and ((d_0_i_) < (len(l)))) or (((l)[d_0_i_]) < (t))))) + Ensures((Result()) == (Forall(int, lambda i: + not (((i) >= (0)) and ((i) < (len(l)))) or (((l)[i]) < (t))))) # post-conditions-end # impl-start b : bool = True - d_1_i_ : int = 0 - while (d_1_i_) < (len(l)): + i : int = 0 + while (i) < (len(l)): # invariants-start Invariant(Acc(list_pred(l))) - Invariant(((0) <= (d_1_i_)) and ((d_1_i_) <= (len(l)))) - Invariant((b) == (Forall(int, lambda d_2_i1_: - not (((d_2_i1_) >= (0)) and ((d_2_i1_) < (d_1_i_))) or (((l)[d_2_i1_]) < (t))))) + Invariant(((0) <= (i)) and ((i) <= (len(l)))) + Invariant((b) == (Forall(int, lambda i1: + not (((i1) >= (0)) and ((i1) < (i))) or (((l)[i1]) < (t))))) # invariants-end - if ((l)[d_1_i_]) >= (t): + if ((l)[i]) >= (t): b = False - d_1_i_ = (d_1_i_) + (1) + i = (i) + (1) return b # impl-end diff --git a/Bench/054-same-chars.py b/Bench/054-same-chars.py index 9ec395f..488b3a5 100644 --- a/Bench/054-same-chars.py +++ b/Bench/054-same-chars.py @@ -9,11 +9,11 @@ def same_chars(s0: List[int], s1: List[int]) -> bool: # post-conditions-start Ensures(Acc(list_pred(s0))) Ensures(Acc(list_pred(s1))) - Ensures(Result() == (Forall(int, lambda d_0_i_ : Implies(((0 <= d_0_i_) and (d_0_i_ < len(s0))), s0[d_0_i_] in s1)) and - Forall(int, lambda d_1_i_ : Implies(((0 <= d_1_i_) and (d_1_i_ < len(s1))), s1[d_1_i_] in s0)))) + Ensures(Result() == (Forall(int, lambda i : Implies(((0 <= i) and (i < len(s0))), s0[i] in s1)) and + Forall(int, lambda i : Implies(((0 <= i) and (i < len(s1))), s1[i] in s0)))) # post-conditions-end # impl-start - return (Forall(int, lambda d_0_i_ : Implies(((0 <= d_0_i_) and (d_0_i_ < len(s0))), s0[d_0_i_] in s1)) and - Forall(int, lambda d_1_i_ : Implies(((0 <= d_1_i_) and (d_1_i_ < len(s1))), s1[d_1_i_] in s0))) + return (Forall(int, lambda i : Implies(((0 <= i) and (i < len(s0))), s0[i] in s1)) and + Forall(int, lambda i : Implies(((0 <= i) and (i < len(s1))), s1[i] in s0))) # impl-end diff --git a/Bench/055-fib.py b/Bench/055-fib.py index 6237d44..d42c19b 100644 --- a/Bench/055-fib.py +++ b/Bench/055-fib.py @@ -36,19 +36,19 @@ def ComputeFib(n : int) -> int: if (n) == (1): result = 1 return result - d_0_a_ : int = 0 - d_1_b_ : int = 1 - d_2_i_ : int = 2 - while (d_2_i_) <= (n): + a : int = 0 + b : int = 1 + i : int = 2 + while (i) <= (n): # invariants-start - Invariant(((2) <= (d_2_i_)) and ((d_2_i_) <= ((n) + (1)))) - Invariant((d_0_a_) == (fib((d_2_i_) - (2)))) - Invariant((d_1_b_) == (fib((d_2_i_) - (1)))) + Invariant(((2) <= (i)) and ((i) <= ((n) + (1)))) + Invariant((a) == (fib((i) - (2)))) + Invariant((b) == (fib((i) - (1)))) # invariants-end - d_3_temp_ : int = (d_0_a_) + (d_1_b_) - d_0_a_ = d_1_b_ - d_1_b_ = d_3_temp_ - d_2_i_ = (d_2_i_) + (1) - result = d_1_b_ + temp : int = (a) + (b) + a = b + b = temp + i = (i) + (1) + result = b return result # impl-end diff --git a/Bench/056-correct_bracketing.py b/Bench/056-correct_bracketing.py index 6e9c582..d962408 100644 --- a/Bench/056-correct_bracketing.py +++ b/Bench/056-correct_bracketing.py @@ -18,13 +18,13 @@ def CalBal(s : List[int], i : int, j : int) -> int: def correct_bracketing(s : List[int]) -> bool: # pre-conditions-start Requires(Acc(list_pred(s))) - Requires(Forall(int, lambda d_0_i_: - not (((d_0_i_) >= (0)) and ((d_0_i_) < (len(s)))) or ((((s)[d_0_i_]) == (0)) or (((s)[d_0_i_]) == (1))))) + Requires(Forall(int, lambda i: + not (((i) >= (0)) and ((i) < (len(s)))) or ((((s)[i]) == (0)) or (((s)[i]) == (1))))) # pre-conditions-end # post-conditions-start Ensures(Acc(list_pred(s))) - Ensures(Forall(int, lambda d_0_i_: - not (((d_0_i_) >= (0)) and ((d_0_i_) < (len(s)))) or ((((s)[d_0_i_]) == (0)) or (((s)[d_0_i_]) == (1))))) + Ensures(Forall(int, lambda i: + not (((i) >= (0)) and ((i) < (len(s)))) or ((((s)[i]) == (0)) or (((s)[i]) == (1))))) Ensures(Implies(Result(), Forall(int, lambda x: (Implies(x >= 0 and x <= len(s), CalBal(s, 0, x) >= 0))))) Ensures(Implies(Forall(int, lambda x: (Implies(x >= 0 and x <= len(s), CalBal(s, 0, x) >= 0))), Result())) # post-conditions-end @@ -37,8 +37,8 @@ def correct_bracketing(s : List[int]) -> bool: # invariants-start Invariant(Acc(list_pred(s), 1/2)) Invariant(0 <= i and i <= len(s)) - Invariant(Forall(int, lambda d_0_i_: - not (((d_0_i_) >= (0)) and ((d_0_i_) < (len(s)))) or ((((s)[d_0_i_]) == (0)) or (((s)[d_0_i_]) == (1))))) + Invariant(Forall(int, lambda i: + not (((i) >= (0)) and ((i) < (len(s)))) or ((((s)[i]) == (0)) or (((s)[i]) == (1))))) Invariant(Forall(int, lambda x : (Implies(x >= 0 and x < len(s), CalBal(s, 0, x + 1) == CalBal(s, 0, x) + (1 if s[x] == 0 else -1)), [[CalBal(s, 0, x + 1)]]))) Invariant(depth >= 0) Invariant(depth == CalBal(s, 0, i)) diff --git a/Bench/057-monotonic.py b/Bench/057-monotonic.py index 2366113..4973ea4 100644 --- a/Bench/057-monotonic.py +++ b/Bench/057-monotonic.py @@ -8,35 +8,35 @@ def monotonic(xs : List[int]) -> bool: # pre-conditions-end # post-conditions-start Ensures(Acc(list_pred(xs))) - Ensures((Result()) == ((Forall(int, lambda d_0_i_: - Forall(int, lambda d_1_j_: - not ((((0) <= (d_0_i_)) and ((d_0_i_) < (d_1_j_))) and ((d_1_j_) < (len(xs)))) or (((xs)[d_0_i_]) < ((xs)[d_1_j_]))))) or (Forall(int, lambda d_2_i_: - Forall(int, lambda d_3_j_: - not ((((0) <= (d_2_i_)) and ((d_2_i_) < (d_3_j_))) and ((d_3_j_) < (len(xs)))) or (((xs)[d_2_i_]) > ((xs)[d_3_j_]))))))) + Ensures((Result()) == ((Forall(int, lambda i: + Forall(int, lambda j: + not ((((0) <= (i)) and ((i) < (j))) and ((j) < (len(xs)))) or (((xs)[i]) < ((xs)[j]))))) or (Forall(int, lambda i: + Forall(int, lambda j: + not ((((0) <= (i)) and ((i) < (j))) and ((j) < (len(xs)))) or (((xs)[i]) > ((xs)[j]))))))) # post-conditions-end # impl-start if (len(xs)) == (1): return True - d_4_increasing_ : bool = True - d_5_decreasing_ : bool = True - d_6_i_ : int = 1 - while (d_6_i_) < (len(xs)): + increasing : bool = True + decreasing : bool = True + i : int = 1 + while (i) < (len(xs)): # invariants-start Invariant(Acc(list_pred(xs))) - Invariant(((1) <= (d_6_i_)) and ((d_6_i_) <= (len(xs)))) - Invariant((d_4_increasing_) == (Forall(int, lambda d_7_j_: - Forall(int, lambda d_8_k_: - not ((((0) <= (d_7_j_)) and ((d_7_j_) < (d_8_k_))) and ((d_8_k_) < (d_6_i_))) or (((xs)[d_7_j_]) < ((xs)[d_8_k_])))))) - Invariant((d_5_decreasing_) == (Forall(int, lambda d_9_j_: - Forall(int, lambda d_10_k_: - not ((((0) <= (d_9_j_)) and ((d_9_j_) < (d_10_k_))) and ((d_10_k_) < (d_6_i_))) or (((xs)[d_9_j_]) > ((xs)[d_10_k_])))))) + Invariant(((1) <= (i)) and ((i) <= (len(xs)))) + Invariant((increasing) == (Forall(int, lambda j: + Forall(int, lambda k: + not ((((0) <= (j)) and ((j) < (k))) and ((k) < (i))) or (((xs)[j]) < ((xs)[k])))))) + Invariant((decreasing) == (Forall(int, lambda j: + Forall(int, lambda k: + not ((((0) <= (j)) and ((j) < (k))) and ((k) < (i))) or (((xs)[j]) > ((xs)[k])))))) # invariants-end - if ((xs)[(d_6_i_) - (1)]) >= ((xs)[d_6_i_]): - d_4_increasing_ = False - if ((xs)[(d_6_i_) - (1)]) <= ((xs)[d_6_i_]): - d_5_decreasing_ = False - d_6_i_ = (d_6_i_) + (1) - result : bool = (d_4_increasing_) or (d_5_decreasing_) + if ((xs)[(i) - (1)]) >= ((xs)[i]): + increasing = False + if ((xs)[(i) - (1)]) <= ((xs)[i]): + decreasing = False + i = (i) + (1) + result : bool = (increasing) or (decreasing) return result # impl-end diff --git a/Bench/058-common.py b/Bench/058-common.py index 084068a..0321ef3 100644 --- a/Bench/058-common.py +++ b/Bench/058-common.py @@ -8,8 +8,8 @@ def NotInArray(a : List[int], x : int) -> bool : # pre-conditions-end # pure-start - return Forall(int, lambda d_0_i_: - (Implies(((0) <= (d_0_i_)) and ((d_0_i_) < (len((a)))), ((a)[d_0_i_]) != (x)), [[(a)[d_0_i_]]])) + return Forall(int, lambda i: + (Implies(((0) <= (i)) and ((i) < (len((a)))), ((a)[i]) != (x)), [[(a)[i]]])) # pure-end @Pure @@ -20,9 +20,9 @@ def ExistsBoth(a : List[int], b : List[int], x : int) -> bool: # pre-conditions-end # pure-start - return Exists(int, lambda d_0_i_: - (Implies(((0) <= (d_0_i_)) and ((d_0_i_) < (len((a)))), ((a)[d_0_i_]) == (x)))) and Exists(int, lambda d_0_i_: - (Implies(((0) <= (d_0_i_)) and ((d_0_i_) < (len((b)))), ((b)[d_0_i_]) == (x)))) + return Exists(int, lambda i: + (Implies(((0) <= (i)) and ((i) < (len((a)))), ((a)[i]) == (x)))) and Exists(int, lambda i: + (Implies(((0) <= (i)) and ((i) < (len((b)))), ((b)[i]) == (x)))) # pure-end def common(l1 : List[int], l2 : List[int]) -> List[int]: @@ -34,48 +34,48 @@ def common(l1 : List[int], l2 : List[int]) -> List[int]: Ensures(Acc(list_pred(l2), 1/2)) Ensures(Acc(list_pred(l1), 1/2)) Ensures(Acc(list_pred(Result()))) - Ensures(Forall(int, lambda d_4_j_: - (Implies(((d_4_j_) >= 0 and d_4_j_ < len(l1)), Implies((Exists(int, lambda x: x >= 0 and x< len(l2) and l2[x] == l1[d_4_j_])), Exists(int, lambda x: x >= 0 and x< len(Result()) and Result()[x] == l1[d_4_j_])))))) + Ensures(Forall(int, lambda j: + (Implies(((j) >= 0 and j < len(l1)), Implies((Exists(int, lambda x: x >= 0 and x< len(l2) and l2[x] == l1[j])), Exists(int, lambda x: x >= 0 and x< len(Result()) and Result()[x] == l1[j])))))) # post-conditions-end # impl-start c : List[int] = [] - d_2_i_ : int = 0 - while (d_2_i_) < (len(l1)): + i : int = 0 + while (i) < (len(l1)): # invariants-start Invariant(Acc(list_pred(c))) Invariant(Acc(list_pred(l2), 1/2)) Invariant(Acc(list_pred(l1), 1/2)) - Invariant(((d_2_i_) >= (0)) and ((d_2_i_) <= (len(l1)))) - Invariant(Forall(int, lambda d_4_j_: - (Implies(((d_4_j_) >= 0 and d_4_j_ < d_2_i_), Implies((Exists(int, lambda x: x >= 0 and x< len(l2) and l2[x] == l1[d_4_j_])), Exists(int, lambda x: x >= 0 and x< len(c) and c[x] == l1[d_4_j_]))), - [[l1[d_4_j_]]]))) - Invariant(Forall(int, lambda d_0_i_: - (Implies((d_0_i_) >= 0 and d_0_i_ < len(c), ExistsBoth(l1, l2, c[d_0_i_])), [[ExistsBoth(l1, l2, c[d_0_i_])]]))) + Invariant(((i) >= (0)) and ((i) <= (len(l1)))) + Invariant(Forall(int, lambda j: + (Implies(((j) >= 0 and j < i), Implies((Exists(int, lambda x: x >= 0 and x< len(l2) and l2[x] == l1[j])), Exists(int, lambda x: x >= 0 and x< len(c) and c[x] == l1[j]))), + [[l1[j]]]))) + Invariant(Forall(int, lambda i: + (Implies((i) >= 0 and i < len(c), ExistsBoth(l1, l2, c[i])), [[ExistsBoth(l1, l2, c[i])]]))) # invariants-end - d_5_j_ : int = 0 - while (d_5_j_) < (len(l2)): + j : int = 0 + while (j) < (len(l2)): # invariants-start Invariant(Acc(list_pred(c))) Invariant(Acc(list_pred(l2), 1/2)) Invariant(Acc(list_pred(l1), 1/2)) - Invariant(((d_2_i_) >= (0)) and ((d_2_i_) < (len(l1)))) - Invariant(((d_5_j_) >= (0)) and ((d_5_j_) <= (len(l2)))) - Invariant(Forall(int, lambda d_4_j_: - (Implies(((d_4_j_) >= 0 and d_4_j_ < d_2_i_), Implies((Exists(int, lambda x: x >= 0 and x< len(l2) and l2[x] == l1[d_4_j_])), Exists(int, lambda x: x >= 0 and x< len(c) and c[x] == l1[d_4_j_]))), - [[l1[d_4_j_]]]))) - Invariant(Implies(Exists(int, lambda x: x >= 0 and x < d_5_j_ and l2[x] == l1[d_2_i_]), Exists(int, lambda x: x >= 0 and x < len(c) and c[x] == l1[d_2_i_]))) - Invariant(Forall(int, lambda d_0_i_: - (Implies((d_0_i_) >= 0 and d_0_i_ < len(c), ExistsBoth(l1, l2, c[d_0_i_])), [[ExistsBoth(l1, l2, c[d_0_i_])]]))) + Invariant(((i) >= (0)) and ((i) < (len(l1)))) + Invariant(((j) >= (0)) and ((j) <= (len(l2)))) + Invariant(Forall(int, lambda j: + (Implies(((j) >= 0 and j < i), Implies((Exists(int, lambda x: x >= 0 and x< len(l2) and l2[x] == l1[j])), Exists(int, lambda x: x >= 0 and x< len(c) and c[x] == l1[j]))), + [[l1[j]]]))) + Invariant(Implies(Exists(int, lambda x: x >= 0 and x < j and l2[x] == l1[i]), Exists(int, lambda x: x >= 0 and x < len(c) and c[x] == l1[i]))) + Invariant(Forall(int, lambda i: + (Implies((i) >= 0 and i < len(c), ExistsBoth(l1, l2, c[i])), [[ExistsBoth(l1, l2, c[i])]]))) # invariants-end - if ((l1)[d_2_i_]) == ((l2)[d_5_j_]) and NotInArray(c, (l1)[d_2_i_]): - c = c + [((l1)[d_2_i_])] + if ((l1)[i]) == ((l2)[j]) and NotInArray(c, (l1)[i]): + c = c + [((l1)[i])] # assert-start Assert((Exists(int, lambda x : x >= 0 and x < len(l1) and (c[len(c) - 1]) == (l1[x])))) Assert((Exists(int, lambda x : x >= 0 and x < len(l2) and (c[len(c) - 1]) == (l2[x])))) Assert(ExistsBoth(l1, l2, c[len(c) - 1])) # assert-end - d_5_j_ = (d_5_j_) + (1) - d_2_i_ = (d_2_i_) + (1) + j = (j) + (1) + i = (i) + (1) return c # impl-end diff --git a/Bench/060-sum-to-n.py b/Bench/060-sum-to-n.py index ecb502c..7f7aef4 100644 --- a/Bench/060-sum-to-n.py +++ b/Bench/060-sum-to-n.py @@ -24,13 +24,13 @@ def sum__squares(n : int) -> int: # impl-start r : int = 0 - d_2_k_ : int = 0 - while (d_2_k_) < (n): + k : int = 0 + while (k) < (n): # invariants-start - Invariant(((0) <= (d_2_k_)) and ((d_2_k_) <= (n))) - Invariant((r) == (psum(0, d_2_k_ - 1))) + Invariant(((0) <= (k)) and ((k) <= (n))) + Invariant((r) == (psum(0, k - 1))) # invariants-end - r = (r) + ((d_2_k_) + (1)) - d_2_k_ = (d_2_k_) + (1) + r = (r) + ((k) + (1)) + k = (k) + (1) return r # impl-end diff --git a/Bench/062-derivative.py b/Bench/062-derivative.py index 1621962..94141b4 100644 --- a/Bench/062-derivative.py +++ b/Bench/062-derivative.py @@ -10,23 +10,23 @@ def derivative(xs : List[int]) -> List[int]: Ensures(Acc(list_pred(xs))) Ensures(Acc(list_pred(Result()))) Ensures((len(Result())) == ((len(xs)) - (1))) - Ensures(Forall(int, lambda d_0_i_: - not (((0) <= (d_0_i_)) and ((d_0_i_) < (len(Result())))) or (((Result())[d_0_i_]) == (((xs)[(d_0_i_) + (1)]) * ((d_0_i_) + (1)))))) + Ensures(Forall(int, lambda i: + not (((0) <= (i)) and ((i) < (len(Result())))) or (((Result())[i]) == (((xs)[(i) + (1)]) * ((i) + (1)))))) # post-conditions-end # impl-start result : List[int] = [] - d_1_i_ : int = 1 - while (d_1_i_) < (len(xs)): + i : int = 1 + while (i) < (len(xs)): # invariants-start Invariant(Acc(list_pred(result))) Invariant(Acc(list_pred(xs))) - Invariant(((1) <= (d_1_i_)) and ((d_1_i_) <= (len(xs)))) - Invariant((len(result)) == ((d_1_i_) - (1))) - Invariant(Forall(int, lambda d_2_j_: - not (((0) <= (d_2_j_)) and ((d_2_j_) < (len(result)))) or (((result)[d_2_j_]) == (((xs)[(d_2_j_) + (1)]) * ((d_2_j_) + (1)))))) + Invariant(((1) <= (i)) and ((i) <= (len(xs)))) + Invariant((len(result)) == ((i) - (1))) + Invariant(Forall(int, lambda j: + not (((0) <= (j)) and ((j) < (len(result)))) or (((result)[j]) == (((xs)[(j) + (1)]) * ((j) + (1)))))) # invariants-end - result = (result) + [((xs)[d_1_i_]) * (d_1_i_)] - d_1_i_ = (d_1_i_) + (1) + result = (result) + [((xs)[i]) * (i)] + i = (i) + (1) return result # impl-end diff --git a/Bench/063-fibfib.py b/Bench/063-fibfib.py index 25a6134..114ab3c 100644 --- a/Bench/063-fibfib.py +++ b/Bench/063-fibfib.py @@ -33,22 +33,22 @@ def ComputeFibFib(n : int) -> int: return 0 if (n) == (2): return 1 - d_0_a_ : int = 0 - d_1_b_ : int = 0 - d_2_c_ : int = 1 - d_3_i_ : int = 3 - while (d_3_i_) <= (n): + a : int = 0 + b : int = 0 + c : int = 1 + i : int = 3 + while (i) <= (n): # invariants-start - Invariant(((3) <= (d_3_i_)) and ((d_3_i_) <= ((n) + (1)))) - Invariant((d_0_a_) == (fibfib((d_3_i_) - (3)))) - Invariant((d_1_b_) == (fibfib((d_3_i_) - (2)))) - Invariant((d_2_c_) == (fibfib((d_3_i_) - (1)))) + Invariant(((3) <= (i)) and ((i) <= ((n) + (1)))) + Invariant((a) == (fibfib((i) - (3)))) + Invariant((b) == (fibfib((i) - (2)))) + Invariant((c) == (fibfib((i) - (1)))) # invariants-end - d_4_temp_ : int = ((d_2_c_) + (d_1_b_)) + (d_0_a_) - d_0_a_ = d_1_b_ - d_1_b_ = d_2_c_ - d_2_c_ = d_4_temp_ - d_3_i_ = (d_3_i_) + (1) - result : int = d_2_c_ + temp : int = ((c) + (b)) + (a) + a = b + b = c + c = temp + i = (i) + (1) + result : int = c return result # impl-end diff --git a/Bench/064-vowel_count.py b/Bench/064-vowel_count.py index 4ad923c..e328a25 100644 --- a/Bench/064-vowel_count.py +++ b/Bench/064-vowel_count.py @@ -13,22 +13,22 @@ def vowel__count(s : List[int]) -> int: # impl-start count : int = 0 - d_1_i_ : int = 0 - while (d_1_i_) < (len(s)): + i : int = 0 + while (i) < (len(s)): # invariants-start Invariant(Acc(list_pred(s))) - Invariant(((0) <= (d_1_i_)) and ((d_1_i_) <= (len(s)))) + Invariant(((0) <= (i)) and ((i) <= (len(s)))) Invariant(count >= 0) - Invariant(Forall(int, lambda d_0_i_: - (Implies(d_0_i_ >= 0 and d_0_i_ < len(s), count_fun(0, d_0_i_ + 1, s) == count_fun(0, d_0_i_, s) + (1 if is__vowel(s[d_0_i_]) else 0)), [[count_fun(0, d_0_i_ + 1, s)]]))) - Invariant((count) == (count_fun(0, d_1_i_, s))) + Invariant(Forall(int, lambda i: + (Implies(i >= 0 and i < len(s), count_fun(0, i + 1, s) == count_fun(0, i, s) + (1 if is__vowel(s[i]) else 0)), [[count_fun(0, i + 1, s)]]))) + Invariant((count) == (count_fun(0, i, s))) # invariants-end # assert-start - Assert(count_fun(0, d_1_i_ + 1, s) == count_fun(0, d_1_i_, s) + (1 if is__vowel(s[d_1_i_]) else 0)) + Assert(count_fun(0, i + 1, s) == count_fun(0, i, s) + (1 if is__vowel(s[i]) else 0)) # assert-end - if is__vowel((s)[d_1_i_]): + if is__vowel((s)[i]): count = (count) + (1) - d_1_i_ = (d_1_i_) + (1) + i = (i) + (1) count = (count) + ((1 if ((len(s)) > (0)) and (((s)[(len(s)) - (1)]) == (121)) else 0)) return count # impl-end diff --git a/Bench/066-digitSum.py b/Bench/066-digitSum.py index cc3479f..801ab48 100644 --- a/Bench/066-digitSum.py +++ b/Bench/066-digitSum.py @@ -26,19 +26,19 @@ def upper__sum(s : List[int]) -> int: # impl-start res : int = 0 - d_1_i_ : int = 0 - while (d_1_i_) < (len(s)): + i : int = 0 + while (i) < (len(s)): # invariants-start Invariant(Acc(list_pred(s))) - Invariant(((0) <= (d_1_i_)) and ((d_1_i_) <= (len(s)))) - Invariant(Forall(int, lambda d_0_i_: (Implies(((0) <= (d_0_i_)) and ((d_0_i_) < (len(s))), upper__sum__rec(0, d_0_i_ + 1, s) == upper__sum__rec(0, d_0_i_, s) + s[d_0_i_]), [[upper__sum__rec(0, d_1_i_ + 1, s)]]))) - Invariant((res) == (upper__sum__rec(0, d_1_i_, s))) + Invariant(((0) <= (i)) and ((i) <= (len(s)))) + Invariant(Forall(int, lambda i: (Implies(((0) <= (i)) and ((i) < (len(s))), upper__sum__rec(0, i + 1, s) == upper__sum__rec(0, i, s) + s[i]), [[upper__sum__rec(0, i + 1, s)]]))) + Invariant((res) == (upper__sum__rec(0, i, s))) # invariants-end # assert-start - Assert(upper__sum__rec(0, d_1_i_ + 1, s) == upper__sum__rec(0, d_1_i_, s) + s[d_1_i_]) + Assert(upper__sum__rec(0, i + 1, s) == upper__sum__rec(0, i, s) + s[i]) # assert-end - res = (res) + (((s)[d_1_i_])) - d_1_i_ = (d_1_i_) + (1) + res = (res) + (((s)[i])) + i = (i) + (1) return res # impl-end diff --git a/Bench/068-pluck.py b/Bench/068-pluck.py index 7bd0c9c..76df1c7 100644 --- a/Bench/068-pluck.py +++ b/Bench/068-pluck.py @@ -5,8 +5,8 @@ def PluckSmallestEven(nodes : List[int]) -> List[int]: # pre-conditions-start Requires(Acc(list_pred(nodes))) Requires((len(nodes)) <= (10000)) - Requires(Forall(int, lambda d_0_i_: - not (((0) <= (d_0_i_)) and ((d_0_i_) < (len(nodes)))) or (((nodes)[d_0_i_]) >= (0)))) + Requires(Forall(int, lambda i: + not (((0) <= (i)) and ((i) < (len(nodes)))) or (((nodes)[i]) >= (0)))) # pre-conditions-end # post-conditions-start Ensures(Acc(list_pred(nodes))) @@ -14,43 +14,43 @@ def PluckSmallestEven(nodes : List[int]) -> List[int]: Ensures(((len(Result())) == (0)) or ((len(Result())) == (2))) Ensures(not ((len(Result())) == (2)) or ((((0) <= ((Result())[1])) and (((Result())[1]) < (len(nodes)))) and (((nodes)[(Result())[1]]) == ((Result())[0])))) Ensures(not ((len(Result())) == (2)) or ((((Result())[0] % 2)) == (0))) - Ensures(not ((len(Result())) == (2)) or (Forall(int, lambda d_1_i_: - not ((((0) <= (d_1_i_)) and ((d_1_i_) < (len(nodes)))) and ((((nodes)[d_1_i_] % 2)) == (0))) or (((Result())[0]) <= ((nodes)[d_1_i_]))))) - Ensures(not ((len(Result())) == (2)) or (Forall(int, lambda d_2_i_: - not (((0) <= (d_2_i_)) and ((d_2_i_) < ((Result())[1]))) or (((((nodes)[d_2_i_] % 2)) != (0)) or (((nodes)[d_2_i_]) > ((Result())[0])))))) - Ensures(not ((len(Result())) == (0)) or (Forall(int, lambda d_3_i_: - not (((0) <= (d_3_i_)) and ((d_3_i_) < (len(nodes)))) or ((((nodes)[d_3_i_] % 2)) != (0))))) + Ensures(not ((len(Result())) == (2)) or (Forall(int, lambda i: + not ((((0) <= (i)) and ((i) < (len(nodes)))) and ((((nodes)[i] % 2)) == (0))) or (((Result())[0]) <= ((nodes)[i]))))) + Ensures(not ((len(Result())) == (2)) or (Forall(int, lambda i: + not (((0) <= (i)) and ((i) < ((Result())[1]))) or (((((nodes)[i] % 2)) != (0)) or (((nodes)[i]) > ((Result())[0])))))) + Ensures(not ((len(Result())) == (0)) or (Forall(int, lambda i: + not (((0) <= (i)) and ((i) < (len(nodes)))) or ((((nodes)[i] % 2)) != (0))))) # post-conditions-end # impl-start result : List[int] = [] - d_4_smallestEven_ : int = -1 - d_5_smallestIndex_ : int = -1 - d_6_i_ : int = int(0) - while d_6_i_ < len(nodes): + smallestEven : int = -1 + smallestIndex : int = -1 + i : int = int(0) + while i < len(nodes): # invariants-start Invariant(Acc(list_pred(result))) Invariant(Acc(list_pred(nodes))) - Invariant(((0) <= (d_6_i_)) and ((d_6_i_) <= (len(nodes)))) - Invariant(((d_4_smallestEven_) == (-1)) == ((d_5_smallestIndex_) == (-1))) - Invariant(not ((d_5_smallestIndex_) != (-1)) or (((0) <= (d_5_smallestIndex_)) and ((d_5_smallestIndex_) < (d_6_i_)))) - Invariant(not ((d_5_smallestIndex_) != (-1)) or (((nodes)[d_5_smallestIndex_]) == (d_4_smallestEven_))) - Invariant(not ((d_4_smallestEven_) != (-1)) or (((d_4_smallestEven_ % 2)) == (0))) - Invariant(not ((d_4_smallestEven_) != (-1)) or (Forall(int, lambda d_7_j_: - (not ((((0) <= (d_7_j_)) and ((d_7_j_) < (d_6_i_))) and ((((nodes)[d_7_j_] % 2)) == (0))) or ((d_4_smallestEven_) <= ((nodes)[d_7_j_])), [[(nodes)[d_7_j_]]])))) - Invariant(not ((d_5_smallestIndex_) != (-1)) or (Forall(int, lambda d_8_j_: - (not (((0) <= (d_8_j_)) and ((d_8_j_) < (d_5_smallestIndex_))) or ((((nodes)[d_8_j_] % 2)) != (0)) or (((nodes)[d_8_j_]) > (d_4_smallestEven_)), [[(nodes)[d_8_j_]]])))) - Invariant(not ((d_5_smallestIndex_) == (-1)) or (Forall(int, lambda d_9_j_: - (not (((0) <= (d_9_j_)) and ((d_9_j_) < (d_6_i_))) or ((((nodes)[d_9_j_] % 2)) != (0)), [[(nodes)[d_9_j_]]])))) + Invariant(((0) <= (i)) and ((i) <= (len(nodes)))) + Invariant(((smallestEven) == (-1)) == ((smallestIndex) == (-1))) + Invariant(not ((smallestIndex) != (-1)) or (((0) <= (smallestIndex)) and ((smallestIndex) < (i)))) + Invariant(not ((smallestIndex) != (-1)) or (((nodes)[smallestIndex]) == (smallestEven))) + Invariant(not ((smallestEven) != (-1)) or (((smallestEven % 2)) == (0))) + Invariant(not ((smallestEven) != (-1)) or (Forall(int, lambda j: + (not ((((0) <= (j)) and ((j) < (i))) and ((((nodes)[j] % 2)) == (0))) or ((smallestEven) <= ((nodes)[j])), [[(nodes)[j]]])))) + Invariant(not ((smallestIndex) != (-1)) or (Forall(int, lambda j: + (not (((0) <= (j)) and ((j) < (smallestIndex))) or ((((nodes)[j] % 2)) != (0)) or (((nodes)[j]) > (smallestEven)), [[(nodes)[j]]])))) + Invariant(not ((smallestIndex) == (-1)) or (Forall(int, lambda j: + (not (((0) <= (j)) and ((j) < (i))) or ((((nodes)[j] % 2)) != (0)), [[(nodes)[j]]])))) # invariants-end - if ((((nodes)[d_6_i_] % 2)) == (0)) and (((d_4_smallestEven_) == (-1)) or (((nodes)[d_6_i_]) < (d_4_smallestEven_))): - d_4_smallestEven_ = (nodes)[d_6_i_] - d_5_smallestIndex_ = d_6_i_ - d_6_i_ = d_6_i_ + 1 - if (d_5_smallestIndex_) == (-1): + if ((((nodes)[i] % 2)) == (0)) and (((smallestEven) == (-1)) or (((nodes)[i]) < (smallestEven))): + smallestEven = (nodes)[i] + smallestIndex = i + i = i + 1 + if (smallestIndex) == (-1): result = list([]) return result else: - result = list([d_4_smallestEven_, d_5_smallestIndex_]) + result = list([smallestEven, smallestIndex]) return result # impl-end diff --git a/Bench/069-search.py b/Bench/069-search.py index 1cb7c3f..514fe1c 100644 --- a/Bench/069-search.py +++ b/Bench/069-search.py @@ -26,20 +26,20 @@ def freq(s : List[int], x : int) -> int: # impl-start count : int = 0 - d_1_i_ : int = 0 - while (d_1_i_) < (len(s)): + i : int = 0 + while (i) < (len(s)): # invariants-start Invariant(Acc(list_pred(s))) - Invariant(((0) <= (d_1_i_)) and ((d_1_i_) <= (len(s)))) + Invariant(((0) <= (i)) and ((i) <= (len(s)))) Invariant(Forall(int, lambda y : (Implies(y >= 0 and y < len(s), freq_req(0, y + 1, s, x) == freq_req(0, y, s, x) + (s[y] == x)), [[freq_req(0, y + 1, s, x)]]))) - Invariant(count == freq_req(0, d_1_i_, s, x)) + Invariant(count == freq_req(0, i, s, x)) # invariants-end # assert-start - Assert(freq_req(0, d_1_i_ + 1, s, x) == freq_req(0, d_1_i_, s, x) + (s[d_1_i_] == x)) + Assert(freq_req(0, i + 1, s, x) == freq_req(0, i, s, x) + (s[i] == x)) # assert-end - if ((s)[d_1_i_]) == (x): + if ((s)[i]) == (x): count = (count) + (1) - d_1_i_ = (d_1_i_) + (1) + i = (i) + (1) return count # impl-end diff --git a/Bench/070-strange_sort_list.py b/Bench/070-strange_sort_list.py index 2c37b0c..8bc2695 100644 --- a/Bench/070-strange_sort_list.py +++ b/Bench/070-strange_sort_list.py @@ -9,42 +9,42 @@ def strange__sort__list__helper(s : List[int]) -> Tuple[List[int], List[int]]: Ensures(Acc(list_pred(s))) Ensures(Acc(list_pred(Result()[0]))) Ensures(Acc(list_pred(Result()[1]))) - Ensures(Forall(int, lambda d_0_i_: - Forall(int, lambda d_1_j_: - Implies((((0) <= (d_0_i_)) and ((d_0_i_) < (d_1_j_))) and ((d_1_j_) < (len((Result()[0])))), ((Result()[0])[d_0_i_]) <= ((Result()[0])[d_1_j_]))))) + Ensures(Forall(int, lambda i: + Forall(int, lambda j: + Implies((((0) <= (i)) and ((i) < (j))) and ((j) < (len((Result()[0])))), ((Result()[0])[i]) <= ((Result()[0])[j]))))) Ensures(((len(s)) == (len(Result()[0]))) and ((len(Result()[0])) == (len(Result()[1])))) - Ensures(Forall(int, lambda d_0_i_: - not ((((0) <= (d_0_i_)) and ((d_0_i_) < (len(s)))) and (((d_0_i_ % 2)) == (0))) or (((Result()[1])[d_0_i_]) == ((Result()[0])[(d_0_i_ // 2)])))) - Ensures(Forall(int, lambda d_1_i_: - not ((((0) <= (d_1_i_)) and ((d_1_i_) < (len(s)))) and (((d_1_i_ % 2)) == (1))) or (((Result()[1])[d_1_i_]) == ((Result()[0])[((len(s)) - ((((d_1_i_) - (1)) // 2))) - (1)])))) + Ensures(Forall(int, lambda i: + not ((((0) <= (i)) and ((i) < (len(s)))) and (((i % 2)) == (0))) or (((Result()[1])[i]) == ((Result()[0])[(i // 2)])))) + Ensures(Forall(int, lambda i: + not ((((0) <= (i)) and ((i) < (len(s)))) and (((i % 2)) == (1))) or (((Result()[1])[i]) == ((Result()[0])[((len(s)) - ((((i) - (1)) // 2))) - (1)])))) # post-conditions-end # impl-start sorted : List[int] = BubbleSort(s) strange : List[int] = list(s) - d_2_i_ : int = 0 - while (d_2_i_) < (len(s)): + i : int = 0 + while (i) < (len(s)): # invariants-start Invariant(Acc(list_pred(strange))) Invariant(Acc(list_pred(sorted))) Invariant(Acc(list_pred(s))) - Invariant(((0) <= (d_2_i_)) and ((d_2_i_) <= (len(s)))) + Invariant(((0) <= (i)) and ((i) <= (len(s)))) Invariant(len(sorted) == len(s)) Invariant((len(strange)) == len(s)) - Invariant(Forall(int, lambda d_0_i_: - Forall(int, lambda d_1_j_: - Implies((((0) <= (d_0_i_)) and ((d_0_i_) < (d_1_j_))) and ((d_1_j_) < (len((sorted)))), ((sorted)[d_0_i_]) <= ((sorted)[d_1_j_]))))) - Invariant(Forall(int, lambda d_3_j_: - (Implies((((0) <= (d_3_j_)) and ((d_3_j_) < (d_2_i_))) and (((d_3_j_ % 2)) == (0)), ((strange)[d_3_j_]) == ((sorted)[(d_3_j_ // 2)])), [[(strange)[d_3_j_]]]))) - Invariant(Forall(int, lambda d_4_j_: - (Implies((((0) <= (d_4_j_)) and ((d_4_j_) < (d_2_i_))) and (((d_4_j_ % 2)) == (1)), ((strange)[d_4_j_]) == ((sorted)[((len(s)) - ((((d_4_j_) - (1)) // 2))) - (1)])), [[(strange)[d_4_j_]]]))) + Invariant(Forall(int, lambda i: + Forall(int, lambda j: + Implies((((0) <= (i)) and ((i) < (j))) and ((j) < (len((sorted)))), ((sorted)[i]) <= ((sorted)[j]))))) + Invariant(Forall(int, lambda j: + (Implies((((0) <= (j)) and ((j) < (i))) and (((j % 2)) == (0)), ((strange)[j]) == ((sorted)[(j // 2)])), [[(strange)[j]]]))) + Invariant(Forall(int, lambda j: + (Implies((((0) <= (j)) and ((j) < (i))) and (((j % 2)) == (1)), ((strange)[j]) == ((sorted)[((len(s)) - ((((j) - (1)) // 2))) - (1)])), [[(strange)[j]]]))) # invariants-end - if ((d_2_i_ % 2)) == (0): - strange[d_2_i_] = (sorted)[(d_2_i_ // 2)] + if ((i % 2)) == (0): + strange[i] = (sorted)[(i // 2)] else: - d_5_r_ : int = (((d_2_i_) - (1)) // 2) - strange[d_2_i_] = (sorted)[((len(s)) - (d_5_r_)) - (1)] - d_2_i_ = (d_2_i_) + (1) + r : int = (((i) - (1)) // 2) + strange[i] = (sorted)[((len(s)) - (r)) - (1)] + i = (i) + (1) return (sorted, strange) # impl-end @@ -71,58 +71,58 @@ def BubbleSort(a1 : List[int]) -> List[int]: Ensures(Acc(list_pred(a1))) Ensures(Acc(list_pred(Result()))) Ensures((len(a1)) == (len(Result()))) - Ensures(Forall(int, lambda d_0_i_: - Forall(int, lambda d_1_j_: - Implies((((0) <= (d_0_i_)) and ((d_0_i_) < (d_1_j_))) and ((d_1_j_) < (len((Result())))), ((Result())[d_0_i_]) <= ((Result())[d_1_j_]))))) + Ensures(Forall(int, lambda i: + Forall(int, lambda j: + Implies((((0) <= (i)) and ((i) < (j))) and ((j) < (len((Result())))), ((Result())[i]) <= ((Result())[j]))))) # post-conditions-end # impl-start a : List[int] = list(a1) - d_2_i_ : int = (len((a))) - (1) - while (d_2_i_) > (0): + i : int = (len((a))) - (1) + while (i) > (0): # invariants-start Invariant(Acc(list_pred(a))) Invariant(Acc(list_pred(a1))) Invariant((len(a1)) == (len(a))) - Invariant(not ((d_2_i_) < (0)) or ((len((a))) == (0))) - Invariant(((-1) <= (d_2_i_)) and ((d_2_i_) < (len((a))))) - Invariant(Forall(int, lambda d_3_ii_: - (Forall(int, lambda d_4_jj_: - (Implies((((d_2_i_) <= (d_3_ii_)) and ((d_3_ii_) < (d_4_jj_))) and ((d_4_jj_) < (len((a)))), ((a)[d_3_ii_]) <= ((a)[d_4_jj_])), - [[(a)[d_4_jj_]]])), - [[(a)[d_3_ii_]]]))) - Invariant(Forall(int, lambda d_5_k_: - (Forall(int, lambda d_6_k_k_: - (Implies(((((0) <= (d_5_k_)) and ((d_5_k_) <= (d_2_i_))) and ((d_2_i_) < (d_6_k_k_)) and (d_6_k_k_) < (len((a)))), ((a)[d_5_k_]) <= ((a)[d_6_k_k_])), - [[(a)[d_6_k_k_]]])), - [[(a)[d_5_k_]]]))) + Invariant(not ((i) < (0)) or ((len((a))) == (0))) + Invariant(((-1) <= (i)) and ((i) < (len((a))))) + Invariant(Forall(int, lambda ii: + (Forall(int, lambda jj: + (Implies((((i) <= (ii)) and ((ii) < (jj))) and ((jj) < (len((a)))), ((a)[ii]) <= ((a)[jj])), + [[(a)[jj]]])), + [[(a)[ii]]]))) + Invariant(Forall(int, lambda k: + (Forall(int, lambda k_k: + (Implies(((((0) <= (k)) and ((k) <= (i))) and ((i) < (k_k)) and (k_k) < (len((a)))), ((a)[k]) <= ((a)[k_k])), + [[(a)[k_k]]])), + [[(a)[k]]]))) # invariants-end - d_7_j_ : int = 0 - while (d_7_j_) < (d_2_i_): + j : int = 0 + while (j) < (i): # invariants-start Invariant(Acc(list_pred(a))) Invariant(Acc(list_pred(a1))) Invariant((len(a1)) == (len(a))) - Invariant((((0) < (d_2_i_)) and ((d_2_i_) < (len((a))))) and (((0) <= (d_7_j_)) and ((d_7_j_) <= (d_2_i_)))) - Invariant(Forall(int, lambda d_8_ii_: - (Forall(int, lambda d_9_jj_: - (Implies((((d_2_i_) <= (d_8_ii_)) and ((d_8_ii_) <= (d_9_jj_))) and ((d_9_jj_) < (len((a)))), ((a)[d_8_ii_]) <= ((a)[d_9_jj_])), - [[(a)[d_9_jj_]]])), - [[(a)[d_8_ii_]]]))) - Invariant(Forall(int, lambda d_10_k_: - (Forall(int, lambda d_11_k_k_: - (Implies(((((0) <= (d_10_k_)) and ((d_10_k_) <= (d_2_i_))) and ((d_2_i_) < (d_11_k_k_))) and ((d_11_k_k_) < (len((a)))), ((a)[d_10_k_]) <= ((a)[d_11_k_k_])), - [[(a)[d_11_k_k_]]])), - [[(a)[d_10_k_]]]))) - Invariant(Forall(int, lambda d_12_k_: - (Implies(((0) <= (d_12_k_)) and ((d_12_k_) <= (d_7_j_)), ((a)[d_12_k_]) <= ((a)[d_7_j_])), - [[(a)[d_12_k_]]]))) + Invariant((((0) < (i)) and ((i) < (len((a))))) and (((0) <= (j)) and ((j) <= (i)))) + Invariant(Forall(int, lambda ii: + (Forall(int, lambda jj: + (Implies((((i) <= (ii)) and ((ii) <= (jj))) and ((jj) < (len((a)))), ((a)[ii]) <= ((a)[jj])), + [[(a)[jj]]])), + [[(a)[ii]]]))) + Invariant(Forall(int, lambda k: + (Forall(int, lambda k_k: + (Implies(((((0) <= (k)) and ((k) <= (i))) and ((i) < (k_k))) and ((k_k) < (len((a)))), ((a)[k]) <= ((a)[k_k])), + [[(a)[k_k]]])), + [[(a)[k]]]))) + Invariant(Forall(int, lambda k: + (Implies(((0) <= (k)) and ((k) <= (j)), ((a)[k]) <= ((a)[j])), + [[(a)[k]]]))) # invariants-end - if ((a)[d_7_j_]) > ((a)[(d_7_j_) + (1)]): - rhs0_ : int = (a)[(d_7_j_) + (1)] - (a)[(d_7_j_) + (1)] = (a)[d_7_j_] - (a)[d_7_j_] = rhs0_ - d_7_j_ = (d_7_j_) + (1) - d_2_i_ = (d_2_i_) - (1) + if ((a)[j]) > ((a)[(j) + (1)]): + rhs0_ : int = (a)[(j) + (1)] + (a)[(j) + (1)] = (a)[j] + (a)[j] = rhs0_ + j = (j) + (1) + i = (i) - (1) return a # impl-end diff --git a/Bench/072-will_it_fly.py b/Bench/072-will_it_fly.py index e923bcc..6009b5a 100644 --- a/Bench/072-will_it_fly.py +++ b/Bench/072-will_it_fly.py @@ -13,40 +13,40 @@ def will__it__fly(s : List[int], w : int) -> bool: # impl-start result : bool = True - d_0_i_ : int = 0 - d_1_j_ : int = (len(s)) - (1) - while (d_0_i_) < (d_1_j_): + i : int = 0 + j : int = (len(s)) - (1) + while (i) < (j): # invariants-start Invariant(Acc(list_pred(s))) - Invariant(((0) <= (d_0_i_)) and ((d_0_i_) < (len(s)))) - Invariant(((0) <= (d_1_j_)) and ((d_1_j_) < (len(s)))) - Invariant((d_1_j_) == (((len(s)) - (d_0_i_)) - (1))) - Invariant(Forall(int, lambda d_2_k_: - not (((0) <= (d_2_k_)) and ((d_2_k_) < (d_0_i_))) or (((s)[d_2_k_]) == ((s)[((len(s)) - (1)) - (d_2_k_)])))) + Invariant(((0) <= (i)) and ((i) < (len(s)))) + Invariant(((0) <= (j)) and ((j) < (len(s)))) + Invariant((j) == (((len(s)) - (i)) - (1))) + Invariant(Forall(int, lambda k: + not (((0) <= (k)) and ((k) < (i))) or (((s)[k]) == ((s)[((len(s)) - (1)) - (k)])))) # invariants-end - if ((s)[d_0_i_]) != ((s)[d_1_j_]): + if ((s)[i]) != ((s)[j]): result = False return result - d_0_i_ = (d_0_i_) + (1) - d_1_j_ = (d_1_j_) - (1) - d_3_total_ : int = 0 - d_0_i_ = 0 - while (d_0_i_) < (len(s)): + i = (i) + (1) + j = (j) - (1) + total : int = 0 + i = 0 + while (i) < (len(s)): # invariants-start Invariant(Acc(list_pred(s))) - Invariant(((0) <= (d_0_i_)) and ((d_0_i_) <= (len(s)))) - Invariant(Forall(int, lambda d_2_i_: (not (((0) <= (d_2_i_)) and ((d_2_i_) < (len(s)))) or ((psum(0, d_2_i_ + 1, s)) == (psum(0, d_2_i_, s) + s[d_2_i_])), [[psum(0, d_2_i_ + 1, s)]]))) - Invariant((d_3_total_) == (psum(0, d_0_i_, s))) - Invariant(Forall(int, lambda d_2_k_: - not (((0) <= (d_2_k_)) and ((d_2_k_) < (len(s)))) or (((s)[d_2_k_]) == ((s)[((len(s)) - (1)) - (d_2_k_)])))) + Invariant(((0) <= (i)) and ((i) <= (len(s)))) + Invariant(Forall(int, lambda i: (not (((0) <= (i)) and ((i) < (len(s)))) or ((psum(0, i + 1, s)) == (psum(0, i, s) + s[i])), [[psum(0, i + 1, s)]]))) + Invariant((total) == (psum(0, i, s))) + Invariant(Forall(int, lambda k: + not (((0) <= (k)) and ((k) < (len(s)))) or (((s)[k]) == ((s)[((len(s)) - (1)) - (k)])))) # invariants-end # assert-start - Assert((psum(0, (d_0_i_) + (1), s)) == ((psum(0, d_0_i_, s) + (s)[d_0_i_]))) + Assert((psum(0, (i) + (1), s)) == ((psum(0, i, s) + (s)[i]))) # assert-end - d_3_total_ = (d_3_total_) + ((s)[d_0_i_]) - d_0_i_ = (d_0_i_) + (1) - return (d_3_total_) <= (w) + total = (total) + ((s)[i]) + i = (i) + (1) + return (total) <= (w) # impl-end @Pure @@ -56,8 +56,8 @@ def is__palindrome__pred(s : List[int]) -> bool : # pre-conditions-end # pure-start - return Forall(int, lambda d_4_k_: - not (((0) <= (d_4_k_)) and ((d_4_k_) < (len(s)))) or (((s)[d_4_k_]) == ((s)[((len(s)) - (1)) - (d_4_k_)]))) + return Forall(int, lambda k: + not (((0) <= (k)) and ((k) < (len(s)))) or (((s)[k]) == ((s)[((len(s)) - (1)) - (k)]))) # pure-end @Pure diff --git a/Bench/073-smallest_change.py b/Bench/073-smallest_change.py index dd36724..da1063e 100644 --- a/Bench/073-smallest_change.py +++ b/Bench/073-smallest_change.py @@ -32,20 +32,20 @@ def smallest__change(s : List[int]) -> int: # impl-start c : int = 0 - d_1_i_ : int = 0 - while (d_1_i_) < ((len(s) // 2)): + i : int = 0 + while (i) < ((len(s) // 2)): # invariants-start Invariant(Acc(list_pred(s))) - Invariant(((0) <= (d_1_i_)) and ((d_1_i_) <= ((len(s) // 2)))) - Invariant(Forall(int, lambda d_0_i_: (Implies(d_0_i_ >= 0 and d_0_i_ < len(s) // 2, smallest__change__fun(s, 0, d_0_i_ + 1) == (smallest__change__fun(s, 0, d_0_i_) + 1 if (s)[d_0_i_] != (s)[len(s) - d_0_i_ - 1] else smallest__change__fun(s, 0, d_0_i_))), [[smallest__change__fun(s, 0, d_0_i_ + 1)]]))) - Invariant(c == smallest__change__fun(s, 0, d_1_i_)) + Invariant(((0) <= (i)) and ((i) <= ((len(s) // 2)))) + Invariant(Forall(int, lambda i: (Implies(i >= 0 and i < len(s) // 2, smallest__change__fun(s, 0, i + 1) == (smallest__change__fun(s, 0, i) + 1 if (s)[i] != (s)[len(s) - i - 1] else smallest__change__fun(s, 0, i))), [[smallest__change__fun(s, 0, i + 1)]]))) + Invariant(c == smallest__change__fun(s, 0, i)) # invariants-end # assert-start - Assert(smallest__change__fun(s, 0, d_1_i_ + 1) == (smallest__change__fun(s, 0, d_1_i_) + 1 if (s)[d_1_i_] != (s)[len(s) - d_1_i_ - 1] else smallest__change__fun(s, 0, d_1_i_))) + Assert(smallest__change__fun(s, 0, i + 1) == (smallest__change__fun(s, 0, i) + 1 if (s)[i] != (s)[len(s) - i - 1] else smallest__change__fun(s, 0, i))) # assert-end - if ((s)[d_1_i_]) != ((s)[((len(s)) - (1)) - (d_1_i_)]): + if ((s)[i]) != ((s)[((len(s)) - (1)) - (i)]): c = (c) + (1) - d_1_i_ = (d_1_i_) + (1) + i = (i) + (1) return c # impl-end diff --git a/Bench/075-is_multiply_prime.py b/Bench/075-is_multiply_prime.py index b82b228..24318c6 100644 --- a/Bench/075-is_multiply_prime.py +++ b/Bench/075-is_multiply_prime.py @@ -4,8 +4,8 @@ @Pure def Prime(p : int) -> bool : # pure-start - return ((p) > (1)) and (Forall(int, lambda d_0_k_: - not (((1) < (d_0_k_)) and ((d_0_k_) < (p))) or (((p % d_0_k_)) != (0)))) + return ((p) > (1)) and (Forall(int, lambda k: + not (((1) < (k)) and ((k) < (p))) or (((p % k)) != (0)))) # pure-end def is__prime(k : int) -> bool: @@ -13,27 +13,27 @@ def is__prime(k : int) -> bool: Requires((k) >= (2)) # pre-conditions-end # post-conditions-start - Ensures(not (Result()) or (Forall(int, lambda d_0_i_: - not (((2) <= (d_0_i_)) and ((d_0_i_) < (k))) or ((k % d_0_i_) != (0))))) - Ensures(not (not(Result())) or (Exists(int, lambda d_1_j_: - (((2) <= (d_1_j_)) and ((d_1_j_) < (k))) and (((k % d_1_j_)) == (0))))) + Ensures(not (Result()) or (Forall(int, lambda i: + not (((2) <= (i)) and ((i) < (k))) or ((k % i) != (0))))) + Ensures(not (not(Result())) or (Exists(int, lambda j: + (((2) <= (j)) and ((j) < (k))) and (((k % j)) == (0))))) Ensures(Result() == Prime(k)) # post-conditions-end # impl-start - d_2_i_ : int = 2 + i : int = 2 result : bool = True - while (d_2_i_) < (k): + while (i) < (k): # invariants-start - Invariant(((2) <= (d_2_i_)) and ((d_2_i_) <= (k))) - Invariant(not (not(result)) or (Exists(int, lambda d_3_j_: - (((2) <= (d_3_j_)) and ((d_3_j_) < (d_2_i_))) and (((k % d_3_j_)) == (0))))) - Invariant(not (result) or (Forall(int, lambda d_4_j_: - not (((2) <= (d_4_j_)) and ((d_4_j_) < (d_2_i_))) or (((k % d_4_j_)) != (0))))) + Invariant(((2) <= (i)) and ((i) <= (k))) + Invariant(not (not(result)) or (Exists(int, lambda j: + (((2) <= (j)) and ((j) < (i))) and (((k % j)) == (0))))) + Invariant(not (result) or (Forall(int, lambda j: + not (((2) <= (j)) and ((j) < (i))) or (((k % j)) != (0))))) # invariants-end - if ((k % d_2_i_)) == (0): + if ((k % i)) == (0): result = False - d_2_i_ = (d_2_i_) + (1) + i = (i) + (1) return result # impl-end @@ -42,130 +42,130 @@ def is__multiply__prime(x : int) -> bool: Requires((x) > (1)) # pre-conditions-end # post-conditions-start - Ensures(Implies(Result(), Exists(int, lambda d_1_a_: - d_1_a_< x and - ((Prime(d_1_a_)) and - Exists(int, lambda d_2_b_: - d_2_b_ < x and - (Prime(d_2_b_)) and - Exists(int, lambda d_3_c_: - (d_3_c_ < x) and (Prime(d_3_c_)) and ((x) == (((d_1_a_) * (d_2_b_)) * (d_3_c_))))))))) - Ensures(Implies(not(Result()), Forall(int, lambda d_10_i_: - (Implies(1 < d_10_i_ and d_10_i_ < x, - Forall(int, lambda d_11_j_: - (Implies((1 < d_11_j_ and d_11_j_ < x), - (Forall(int, lambda d_12_k_: - (Implies(1 < d_12_k_ and d_12_k_ < x, - Implies((Prime(d_10_i_)), Implies((Prime(d_11_j_)), Implies(Prime(d_12_k_), ((x) != (((d_10_i_) * (d_11_j_) * (d_12_k_))))))))))))))))))) + Ensures(Implies(Result(), Exists(int, lambda a: + a< x and + ((Prime(a)) and + Exists(int, lambda b: + b < x and + (Prime(b)) and + Exists(int, lambda c: + (c < x) and (Prime(c)) and ((x) == (((a) * (b)) * (c))))))))) + Ensures(Implies(not(Result()), Forall(int, lambda i: + (Implies(1 < i and i < x, + Forall(int, lambda j: + (Implies((1 < j and j < x), + (Forall(int, lambda k: + (Implies(1 < k and k < x, + Implies((Prime(i)), Implies((Prime(j)), Implies(Prime(k), ((x) != (((i) * (j) * (k))))))))))))))))))) # post-conditions-end # impl-start - d_4_a_ : int = int(2) + a : int = int(2) result : bool = False - while d_4_a_ < x: + while a < x: # invariants-start Invariant(x >= 2) - Invariant(d_4_a_ >= 2 and d_4_a_ <= x) - Invariant(Implies(result, Exists(int, lambda d_1_a_: - d_1_a_< x and - ((Prime(d_1_a_)) and - Exists(int, lambda d_2_b_: - d_2_b_ < x and - (Prime(d_2_b_)) and - Exists(int, lambda d_3_c_: - (d_3_c_ < x) and (Prime(d_3_c_)) and ((x) == (((d_1_a_) * (d_2_b_)) * (d_3_c_))))))))) - Invariant(Implies(not(result), Forall(int, lambda d_10_i_: - (Implies(1 < d_10_i_ and d_10_i_ < d_4_a_, - Forall(int, lambda d_11_j_: - (Implies((1 < d_11_j_ and d_11_j_ < x), - (Forall(int, lambda d_12_k_: - (Implies(1 < d_12_k_ and d_12_k_ < x, - Implies((Prime(d_10_i_)), Implies((Prime(d_11_j_)), Implies(Prime(d_12_k_), ((x) != (((d_10_i_) * (d_11_j_) * (d_12_k_)))))))), - [[Prime(d_12_k_)]])))), - [[Prime(d_11_j_)]]))), - [[Prime(d_10_i_)]])))) + Invariant(a >= 2 and a <= x) + Invariant(Implies(result, Exists(int, lambda a: + a< x and + ((Prime(a)) and + Exists(int, lambda b: + b < x and + (Prime(b)) and + Exists(int, lambda c: + (c < x) and (Prime(c)) and ((x) == (((a) * (b)) * (c))))))))) + Invariant(Implies(not(result), Forall(int, lambda i: + (Implies(1 < i and i < a, + Forall(int, lambda j: + (Implies((1 < j and j < x), + (Forall(int, lambda k: + (Implies(1 < k and k < x, + Implies((Prime(i)), Implies((Prime(j)), Implies(Prime(k), ((x) != (((i) * (j) * (k)))))))), + [[Prime(k)]])))), + [[Prime(j)]]))), + [[Prime(i)]])))) # invariants-end - if is__prime(d_4_a_): - d_5_b_ : int = int(2) - while d_5_b_ < x: + if is__prime(a): + b : int = int(2) + while b < x: # invariants-start Invariant(x >= 2) - Invariant(Prime(d_4_a_)) - Invariant(d_4_a_ >= 2 and d_4_a_ < x) - Invariant(d_5_b_ >= 2 and d_5_b_ <= x) - Invariant(Implies(result, Exists(int, lambda d_1_a_: - d_1_a_< x and - ((Prime(d_1_a_)) and - Exists(int, lambda d_2_b_: - d_2_b_ < x and - (Prime(d_2_b_)) and - Exists(int, lambda d_3_c_: - (d_3_c_ < x) and (Prime(d_3_c_)) and ((x) == (((d_1_a_) * (d_2_b_)) * (d_3_c_))))))))) - Invariant(Implies(not(result), Forall(int, lambda d_10_i_: - (Implies(1 < d_10_i_ and d_10_i_ < d_4_a_, - Forall(int, lambda d_11_j_: - (Implies((1 < d_11_j_ and d_11_j_ < x), - (Forall(int, lambda d_12_k_: - (Implies(1 < d_12_k_ and d_12_k_ < x, - Implies((Prime(d_10_i_)), Implies((Prime(d_11_j_)), Implies(Prime(d_12_k_), ((x) != (((d_10_i_) * (d_11_j_) * (d_12_k_)))))))), - [[Prime(d_12_k_)]])))), - [[Prime(d_11_j_)]]))), - [[Prime(d_10_i_)]])))) + Invariant(Prime(a)) + Invariant(a >= 2 and a < x) + Invariant(b >= 2 and b <= x) + Invariant(Implies(result, Exists(int, lambda a: + a< x and + ((Prime(a)) and + Exists(int, lambda b: + b < x and + (Prime(b)) and + Exists(int, lambda c: + (c < x) and (Prime(c)) and ((x) == (((a) * (b)) * (c))))))))) + Invariant(Implies(not(result), Forall(int, lambda i: + (Implies(1 < i and i < a, + Forall(int, lambda j: + (Implies((1 < j and j < x), + (Forall(int, lambda k: + (Implies(1 < k and k < x, + Implies((Prime(i)), Implies((Prime(j)), Implies(Prime(k), ((x) != (((i) * (j) * (k)))))))), + [[Prime(k)]])))), + [[Prime(j)]]))), + [[Prime(i)]])))) Invariant(Implies(not(result), - Forall(int, lambda d_11_j_: - (Implies((1 < d_11_j_ and d_11_j_ < d_5_b_), - (Forall(int, lambda d_12_k_: - (Implies(1 < d_12_k_ and d_12_k_ < x, - Implies((Prime(d_11_j_)), Implies(Prime(d_12_k_), (x) != (((d_4_a_) * (d_11_j_) * (d_12_k_)))))), - [[Prime(d_12_k_)]])))), - [[Prime(d_11_j_)]])))) + Forall(int, lambda j: + (Implies((1 < j and j < b), + (Forall(int, lambda k: + (Implies(1 < k and k < x, + Implies((Prime(j)), Implies(Prime(k), (x) != (((a) * (j) * (k)))))), + [[Prime(k)]])))), + [[Prime(j)]])))) # invariants-end - if is__prime(d_5_b_): - d_6_c_ : int = int(2) - while d_6_c_ < x: + if is__prime(b): + c : int = int(2) + while c < x: # invariants-start Invariant(x >= 2) - Invariant(Prime(d_4_a_)) - Invariant(Prime(d_5_b_)) - Invariant(d_4_a_ >= 2 and d_4_a_ < x) - Invariant(d_5_b_ >= 2 and d_5_b_ < x) - Invariant(d_6_c_ >= 2 and d_6_c_ <= x) - Invariant(Implies(result, Exists(int, lambda d_1_a_: - d_1_a_< x and - ((Prime(d_1_a_)) and - Exists(int, lambda d_2_b_: - d_2_b_ < x and - (Prime(d_2_b_)) and - Exists(int, lambda d_3_c_: - (d_3_c_ < x) and (Prime(d_3_c_)) and ((x) == (((d_1_a_) * (d_2_b_)) * (d_3_c_))))))))) - Invariant(Implies(not(result), Forall(int, lambda d_10_i_: - (Implies(1 < d_10_i_ and d_10_i_ < d_4_a_, - Forall(int, lambda d_11_j_: - (Implies((1 < d_11_j_ and d_11_j_ < x), - (Forall(int, lambda d_12_k_: - (Implies(1 < d_12_k_ and d_12_k_ < x, - Implies((Prime(d_10_i_)), Implies((Prime(d_11_j_)), Implies(Prime(d_12_k_), ((x) != (((d_10_i_) * (d_11_j_) * (d_12_k_)))))))), - [[Prime(d_12_k_)]])))), - [[Prime(d_11_j_)]]))), - [[Prime(d_10_i_)]])))) + Invariant(Prime(a)) + Invariant(Prime(b)) + Invariant(a >= 2 and a < x) + Invariant(b >= 2 and b < x) + Invariant(c >= 2 and c <= x) + Invariant(Implies(result, Exists(int, lambda a: + a< x and + ((Prime(a)) and + Exists(int, lambda b: + b < x and + (Prime(b)) and + Exists(int, lambda c: + (c < x) and (Prime(c)) and ((x) == (((a) * (b)) * (c))))))))) + Invariant(Implies(not(result), Forall(int, lambda i: + (Implies(1 < i and i < a, + Forall(int, lambda j: + (Implies((1 < j and j < x), + (Forall(int, lambda k: + (Implies(1 < k and k < x, + Implies((Prime(i)), Implies((Prime(j)), Implies(Prime(k), ((x) != (((i) * (j) * (k)))))))), + [[Prime(k)]])))), + [[Prime(j)]]))), + [[Prime(i)]])))) Invariant(Implies(not(result), - Forall(int, lambda d_11_j_: - (Implies((1 < d_11_j_ and d_11_j_ < d_5_b_), - (Forall(int, lambda d_12_k_: - (Implies(1 < d_12_k_ and d_12_k_ < x, - Implies((Prime(d_11_j_)), Implies(Prime(d_12_k_), (x) != (((d_4_a_) * (d_11_j_) * (d_12_k_)))))), - [[Prime(d_12_k_)]])))), - [[Prime(d_11_j_)]])))) + Forall(int, lambda j: + (Implies((1 < j and j < b), + (Forall(int, lambda k: + (Implies(1 < k and k < x, + Implies((Prime(j)), Implies(Prime(k), (x) != (((a) * (j) * (k)))))), + [[Prime(k)]])))), + [[Prime(j)]])))) Invariant(Implies(not(result), - Forall(int, lambda d_12_k_: - (Implies(1 < d_12_k_ and d_12_k_ < d_6_c_, - Implies((Prime(d_12_k_)), ((x) != (((d_4_a_) * (d_5_b_) * (d_12_k_)))))), - [[Prime(d_12_k_)]])))) + Forall(int, lambda k: + (Implies(1 < k and k < c, + Implies((Prime(k)), ((x) != (((a) * (b) * (k)))))), + [[Prime(k)]])))) # invariants-end - if (is__prime(d_6_c_)) and ((x) == (((d_4_a_) * (d_5_b_)) * (d_6_c_))): + if (is__prime(c)) and ((x) == (((a) * (b)) * (c))): result = True - d_6_c_ = d_6_c_ + 1 - d_5_b_ = d_5_b_ + 1 - d_4_a_ = d_4_a_ + 1 + c = c + 1 + b = b + 1 + a = a + 1 return result # impl-end diff --git a/Bench/078-hex_key.py b/Bench/078-hex_key.py index 18f4e6b..c2b24bb 100644 --- a/Bench/078-hex_key.py +++ b/Bench/078-hex_key.py @@ -35,20 +35,20 @@ def count__prime__hex__digits(s : List[int]) -> int: # impl-start count : int = 0 - d_1_i_ : int = 0 - while (d_1_i_) < (len(s)): + i : int = 0 + while (i) < (len(s)): # invariants-start Invariant(Acc(list_pred(s))) - Invariant(((0) <= (d_1_i_)) and ((d_1_i_) <= (len(s)))) - Invariant((count) == (count__prime__hex__digits__rec(0, d_1_i_, s))) - Invariant(count >= 0 and count <= d_1_i_) + Invariant(((0) <= (i)) and ((i) <= (len(s)))) + Invariant((count) == (count__prime__hex__digits__rec(0, i, s))) + Invariant(count >= 0 and count <= i) Invariant(Forall(int, lambda x : (Implies(x >= 0 and x < len(s), (count__prime__hex__digits__rec(0, x + 1, s)) == ((count__prime__hex__digits__rec(0, x, s) + ((1 if IsPrimeHexDigit((s)[x]) else 0))))), [[count__prime__hex__digits__rec(0, x + 1, s)]]))) # invariants-end # assert-start - Assert((count__prime__hex__digits__rec(0, d_1_i_ + 1, s)) == ((count__prime__hex__digits__rec(0, d_1_i_, s) + ((1 if IsPrimeHexDigit((s)[d_1_i_]) else 0))))) + Assert((count__prime__hex__digits__rec(0, i + 1, s)) == ((count__prime__hex__digits__rec(0, i, s) + ((1 if IsPrimeHexDigit((s)[i]) else 0))))) # assert-end - count = (count) + ((1 if IsPrimeHexDigit((s)[d_1_i_]) else 0)) - d_1_i_ = (d_1_i_) + (1) + count = (count) + ((1 if IsPrimeHexDigit((s)[i]) else 0)) + i = (i) + (1) return count # impl-end diff --git a/Bench/080-is_happy.py b/Bench/080-is_happy.py index d255e40..8c8cbdd 100644 --- a/Bench/080-is_happy.py +++ b/Bench/080-is_happy.py @@ -19,8 +19,8 @@ def Happy(s : List[int]) -> bool : # pre-conditions-end # pure-start - return ((len(s)) >= (3)) and (Forall(int, lambda d_0_i_: - Implies(((0) < (d_0_i_)) and ((d_0_i_) < ((len(s)) - (1))), ThreeDistinct(s, d_0_i_)))) + return ((len(s)) >= (3)) and (Forall(int, lambda i: + Implies(((0) < (i)) and ((i) < ((len(s)) - (1))), ThreeDistinct(s, i)))) # pure-end def IsHappy(s : List[int]) -> bool: @@ -35,17 +35,17 @@ def IsHappy(s : List[int]) -> bool: # impl-start if (len(s)) < (3): return False - d_1_i_ : int = 1 - while (d_1_i_) < ((len(s)) - (1)): + i : int = 1 + while (i) < ((len(s)) - (1)): # invariants-start Invariant(Acc(list_pred(s))) - Invariant(((0) < (d_1_i_)) and ((d_1_i_) <= ((len(s)) - (1)))) + Invariant(((0) < (i)) and ((i) <= ((len(s)) - (1)))) Invariant(len(s) >= 3) - Invariant(Forall(int, lambda d_2_j_: - Implies(((0) < (d_2_j_)) and ((d_2_j_) < (d_1_i_)), ThreeDistinct(s, d_2_j_)))) + Invariant(Forall(int, lambda j: + Implies(((0) < (j)) and ((j) < (i)), ThreeDistinct(s, j)))) # invariants-end - if not(ThreeDistinct(s, d_1_i_)): + if not(ThreeDistinct(s, i)): return False - d_1_i_ = (d_1_i_) + (1) + i = (i) + (1) return True # impl-end diff --git a/Bench/082-prime-length.py b/Bench/082-prime-length.py index 61f8d18..e9245e0 100644 --- a/Bench/082-prime-length.py +++ b/Bench/082-prime-length.py @@ -6,25 +6,25 @@ def is__prime(s : str) -> bool: Requires((len(s)) >= (2)) # pre-conditions-end # post-conditions-start - Ensures(not (Result()) or (Forall(int, lambda d_0_i_: - not (((2) <= (d_0_i_)) and ((d_0_i_) < (len(s)))) or ((len(s) % d_0_i_) != (0))))) - Ensures(not (not(Result())) or (Exists(int, lambda d_1_j_: - (((2) <= (d_1_j_)) and ((d_1_j_) < (len(s)))) and (((len(s) % d_1_j_)) == (0))))) + Ensures(not (Result()) or (Forall(int, lambda i: + not (((2) <= (i)) and ((i) < (len(s)))) or ((len(s) % i) != (0))))) + Ensures(not (not(Result())) or (Exists(int, lambda j: + (((2) <= (j)) and ((j) < (len(s)))) and (((len(s) % j)) == (0))))) # post-conditions-end # impl-start - d_2_i_ : int = 2 + i : int = 2 result : bool = True - while (d_2_i_) < (len(s)): + while (i) < (len(s)): # invariants-start - Invariant(((2) <= (d_2_i_)) and ((d_2_i_) <= (len(s)))) - Invariant(not (not(result)) or (Exists(int, lambda d_3_j_: - (((2) <= (d_3_j_)) and ((d_3_j_) < (d_2_i_))) and (((len(s) % d_3_j_)) == (0))))) - Invariant(not (result) or (Forall(int, lambda d_4_j_: - not (((2) <= (d_4_j_)) and ((d_4_j_) < (d_2_i_))) or (((len(s) % d_4_j_)) != (0))))) + Invariant(((2) <= (i)) and ((i) <= (len(s)))) + Invariant(not (not(result)) or (Exists(int, lambda j: + (((2) <= (j)) and ((j) < (i))) and (((len(s) % j)) == (0))))) + Invariant(not (result) or (Forall(int, lambda j: + not (((2) <= (j)) and ((j) < (i))) or (((len(s) % j)) != (0))))) # invariants-end - if ((len(s) % d_2_i_)) == (0): + if ((len(s) % i)) == (0): result = False - d_2_i_ = (d_2_i_) + (1) + i = (i) + (1) return result # impl-end diff --git a/Bench/084-solve.py b/Bench/084-solve.py index 8352cae..ab17392 100644 --- a/Bench/084-solve.py +++ b/Bench/084-solve.py @@ -11,16 +11,16 @@ def solve(n : int) -> int: # post-conditions-end # impl-start - d_0_m_ : int = n + m : int = n r : int = 0 - while (d_0_m_) > (0): + while (m) > (0): # invariants-start - Invariant(((0) <= (d_0_m_)) and ((d_0_m_) <= (n))) + Invariant(((0) <= (m)) and ((m) <= (n))) Invariant(r >= 0) - Invariant(((r) + (popcount(d_0_m_))) == (popcount(n))) + Invariant(((r) + (popcount(m))) == (popcount(n))) # invariants-end - r = (r) + ((d_0_m_ % 2)) - d_0_m_ = (d_0_m_ // 2) + r = (r) + ((m % 2)) + m = (m // 2) return r # impl-end diff --git a/Bench/085-add.py b/Bench/085-add.py index 11dcb05..05ac684 100644 --- a/Bench/085-add.py +++ b/Bench/085-add.py @@ -26,14 +26,14 @@ def add(v : List[int]) -> int: # impl-start r : int = 0 - d_2_k_ : int = 0 - while (d_2_k_) < (len(v)): + k : int = 0 + while (k) < (len(v)): # invariants-start Invariant(Acc(list_pred(v))) - Invariant(((0) <= (d_2_k_)) and ((d_2_k_) <= (len(v)))) - Invariant((r) == (psum(0, d_2_k_ - 1, v))) + Invariant(((0) <= (k)) and ((k) <= (len(v)))) + Invariant((r) == (psum(0, k - 1, v))) # invariants-end - r = (r) + (((v)[d_2_k_] if ((((d_2_k_) % 2) == 1) and ((v)[d_2_k_] % 2 == 0)) else 0)) - d_2_k_ = (d_2_k_) + (1) + r = (r) + (((v)[k] if ((((k) % 2) == 1) and ((v)[k] % 2 == 0)) else 0)) + k = (k) + (1) return r # impl-end diff --git a/Bench/088-sort_array.py b/Bench/088-sort_array.py index 39dfc99..8a6b9d5 100644 --- a/Bench/088-sort_array.py +++ b/Bench/088-sort_array.py @@ -9,12 +9,12 @@ def sort__array(s : List[int]) -> List[int]: Ensures(Acc(list_pred(s))) Ensures(Acc(list_pred(Result()))) Ensures((len(Result())) == (len(s))) - Ensures(not (((len(s)) > (0)) and ((((((s)[0]) + ((s)[(len(s)) - (1)])) % 2)) == (0))) or (Forall(int, lambda d_0_i_: - Forall(int, lambda d_1_j_: - not ((((0) <= (d_0_i_)) and ((d_0_i_) < (d_1_j_))) and ((d_1_j_) < (len(Result())))) or (((Result())[d_0_i_]) >= ((Result())[d_1_j_])))))) - Ensures(not (((len(s)) > (0)) and ((((((s)[0]) + ((s)[(len(s)) - (1)])) % 2)) != (0))) or (Forall(int, lambda d_2_i_: - Forall(int, lambda d_3_j_: - not ((((0) <= (d_2_i_)) and ((d_2_i_) < (d_3_j_))) and ((d_3_j_) < (len(Result())))) or (((Result())[d_2_i_]) <= ((Result())[d_3_j_])))))) + Ensures(not (((len(s)) > (0)) and ((((((s)[0]) + ((s)[(len(s)) - (1)])) % 2)) == (0))) or (Forall(int, lambda i: + Forall(int, lambda j: + not ((((0) <= (i)) and ((i) < (j))) and ((j) < (len(Result())))) or (((Result())[i]) >= ((Result())[j])))))) + Ensures(not (((len(s)) > (0)) and ((((((s)[0]) + ((s)[(len(s)) - (1)])) % 2)) != (0))) or (Forall(int, lambda i: + Forall(int, lambda j: + not ((((0) <= (i)) and ((i) < (j))) and ((j) < (len(Result())))) or (((Result())[i]) <= ((Result())[j])))))) # post-conditions-end # impl-start @@ -26,17 +26,17 @@ def sort__array(s : List[int]) -> List[int]: # assert-start Assert(len(s) > 0) # assert-end - d_4_t_ : List[int] = BubbleSort(s) + t : List[int] = BubbleSort(s) # assert-start - Assert(Forall(int, lambda d_0_i_: - Forall(int, lambda d_1_j_: - Implies((((0) <= (d_0_i_)) and ((d_0_i_) < (d_1_j_))) and ((d_1_j_) < (len((d_4_t_)))), ((d_4_t_)[d_0_i_]) <= ((d_4_t_)[d_1_j_]))))) + Assert(Forall(int, lambda i: + Forall(int, lambda j: + Implies((((0) <= (i)) and ((i) < (j))) and ((j) < (len((t)))), ((t)[i]) <= ((t)[j]))))) # assert-end - sorted = reverse(d_4_t_) + sorted = reverse(t) # assert-start - Assert(Forall(int, lambda d_0_i_: - Forall(int, lambda d_1_j_: - Implies((((0) <= (d_0_i_)) and ((d_0_i_) < (d_1_j_))) and ((d_1_j_) < (len((sorted)))), ((sorted)[d_0_i_]) >= ((sorted)[d_1_j_]))))) + Assert(Forall(int, lambda i: + Forall(int, lambda j: + Implies((((0) <= (i)) and ((i) < (j))) and ((j) < (len((sorted)))), ((sorted)[i]) >= ((sorted)[j]))))) Assert(((len(s)) > (0)) and ((((((s)[0]) + ((s)[(len(s)) - (1)])) % 2)) == (0))) # assert-end return sorted @@ -46,9 +46,9 @@ def sort__array(s : List[int]) -> List[int]: # assert-end sorted = BubbleSort(s) # assert-start - Assert(Forall(int, lambda d_0_i_: - Forall(int, lambda d_1_j_: - Implies((((0) <= (d_0_i_)) and ((d_0_i_) < (d_1_j_))) and ((d_1_j_) < (len((sorted)))), ((sorted)[d_0_i_]) <= ((sorted)[d_1_j_]))))) + Assert(Forall(int, lambda i: + Forall(int, lambda j: + Implies((((0) <= (i)) and ((i) < (j))) and ((j) < (len((sorted)))), ((sorted)[i]) <= ((sorted)[j]))))) Assert(((len(s)) > (0)) and ((((((s)[0]) + ((s)[(len(s)) - (1)])) % 2)) != (0))) # assert-end return sorted @@ -65,27 +65,27 @@ def reverse(str : List[int]) -> List[int]: Ensures(Forall(int, lambda x: Forall(int, lambda y: not (((0) <= (x)) and ((x) < (y)) and ((y) < (len(Result())))) or ((Result())[x] >= (Result())[y])))) Ensures(str == Old(str)) Ensures((len(Result())) == (len(str))) - Ensures(Forall(int, lambda d_11_k_: - not (((0) <= (d_11_k_)) and ((d_11_k_) < (len(str)))) or (((Result())[d_11_k_]) == ((str)[((len(str)) - (1)) - (d_11_k_)])))) + Ensures(Forall(int, lambda k: + not (((0) <= (k)) and ((k) < (len(str)))) or (((Result())[k]) == ((str)[((len(str)) - (1)) - (k)])))) # post-conditions-end # impl-start rev : List[int] = [] - d_12_i_ : int = 0 - while (d_12_i_) < (len(str)): + i : int = 0 + while (i) < (len(str)): # invariants-start Invariant(Acc(list_pred(str), 1/2)) Invariant(Acc(list_pred(rev))) Invariant(Forall(int, lambda x: Forall(int, lambda y: not (((0) <= (x)) and ((x) < (y)) and ((y) < (len(str)))) or ((str)[x] <= (str)[y])))) - Invariant(((d_12_i_) >= (0)) and ((d_12_i_) <= (len(str)))) - Invariant((len(rev)) == (d_12_i_)) - Invariant(Forall(int, lambda d_13_k_: - not (((0) <= (d_13_k_)) and ((d_13_k_) < (d_12_i_))) or (((rev)[d_13_k_]) == ((str)[(len(str) - (1)) - (d_13_k_)])))) - Invariant(Forall(int, lambda x: Forall(int, lambda y: (not (((0) <= (x)) and ((x) < (len(rev))) and (0 <= y and (y) < (len(str) - d_12_i_))) or ((str)[y] <= (rev)[x]), [[str[y] <= rev[x]]])))) + Invariant(((i) >= (0)) and ((i) <= (len(str)))) + Invariant((len(rev)) == (i)) + Invariant(Forall(int, lambda k: + not (((0) <= (k)) and ((k) < (i))) or (((rev)[k]) == ((str)[(len(str) - (1)) - (k)])))) + Invariant(Forall(int, lambda x: Forall(int, lambda y: (not (((0) <= (x)) and ((x) < (len(rev))) and (0 <= y and (y) < (len(str) - i))) or ((str)[y] <= (rev)[x]), [[str[y] <= rev[x]]])))) Invariant(Forall(int, lambda x: Forall(int, lambda y: (not (((0) <= (x)) and ((x) < (y)) and ((y) < (len(rev)))) or ((rev)[x] >= (rev)[y]), [[rev[x] >= rev[y]]])))) # invariants-end - rev = (rev) + [(str)[(len(str) - (d_12_i_)) - (1)]] - d_12_i_ = (d_12_i_) + (1) + rev = (rev) + [(str)[(len(str) - (i)) - (1)]] + i = (i) + (1) return rev # impl-end @@ -97,58 +97,58 @@ def BubbleSort(a1 : List[int]) -> List[int]: Ensures(Acc(list_pred(a1), 1/2)) Ensures(Acc(list_pred(Result()))) Ensures((len(a1)) == (len(Result()))) - Ensures(Forall(int, lambda d_0_i_: - Forall(int, lambda d_1_j_: - Implies((((0) <= (d_0_i_)) and ((d_0_i_) < (d_1_j_))) and ((d_1_j_) < (len((Result())))), ((Result())[d_0_i_]) <= ((Result())[d_1_j_]))))) + Ensures(Forall(int, lambda i: + Forall(int, lambda j: + Implies((((0) <= (i)) and ((i) < (j))) and ((j) < (len((Result())))), ((Result())[i]) <= ((Result())[j]))))) # post-conditions-end # impl-start a : List[int] = list(a1) - d_2_i_ : int = (len((a))) - (1) - while (d_2_i_) > (0): + i : int = (len((a))) - (1) + while (i) > (0): # invariants-start Invariant(Acc(list_pred(a))) Invariant(Acc(list_pred(a1), 1/2)) Invariant((len(a1)) == (len(a))) - Invariant(not ((d_2_i_) < (0)) or ((len((a))) == (0))) - Invariant(((-1) <= (d_2_i_)) and ((d_2_i_) < (len((a))))) - Invariant(Forall(int, lambda d_3_ii_: - (Forall(int, lambda d_4_jj_: - (Implies((((d_2_i_) <= (d_3_ii_)) and ((d_3_ii_) < (d_4_jj_))) and ((d_4_jj_) < (len((a)))), ((a)[d_3_ii_]) <= ((a)[d_4_jj_])), - [[(a)[d_4_jj_]]])), - [[(a)[d_3_ii_]]]))) - Invariant(Forall(int, lambda d_5_k_: - (Forall(int, lambda d_6_k_k_: - (Implies(((((0) <= (d_5_k_)) and ((d_5_k_) <= (d_2_i_))) and ((d_2_i_) < (d_6_k_k_)) and (d_6_k_k_) < (len((a)))), ((a)[d_5_k_]) <= ((a)[d_6_k_k_])), - [[(a)[d_6_k_k_]]])), - [[(a)[d_5_k_]]]))) + Invariant(not ((i) < (0)) or ((len((a))) == (0))) + Invariant(((-1) <= (i)) and ((i) < (len((a))))) + Invariant(Forall(int, lambda ii: + (Forall(int, lambda jj: + (Implies((((i) <= (ii)) and ((ii) < (jj))) and ((jj) < (len((a)))), ((a)[ii]) <= ((a)[jj])), + [[(a)[jj]]])), + [[(a)[ii]]]))) + Invariant(Forall(int, lambda k: + (Forall(int, lambda k_k: + (Implies(((((0) <= (k)) and ((k) <= (i))) and ((i) < (k_k)) and (k_k) < (len((a)))), ((a)[k]) <= ((a)[k_k])), + [[(a)[k_k]]])), + [[(a)[k]]]))) # invariants-end - d_7_j_ : int = 0 - while (d_7_j_) < (d_2_i_): + j : int = 0 + while (j) < (i): # invariants-start Invariant(Acc(list_pred(a))) Invariant(Acc(list_pred(a1), 1/2)) Invariant((len(a1)) == (len(a))) - Invariant((((0) < (d_2_i_)) and ((d_2_i_) < (len((a))))) and (((0) <= (d_7_j_)) and ((d_7_j_) <= (d_2_i_)))) - Invariant(Forall(int, lambda d_8_ii_: - (Forall(int, lambda d_9_jj_: - (Implies((((d_2_i_) <= (d_8_ii_)) and ((d_8_ii_) <= (d_9_jj_))) and ((d_9_jj_) < (len((a)))), ((a)[d_8_ii_]) <= ((a)[d_9_jj_])), - [[(a)[d_9_jj_]]])), - [[(a)[d_8_ii_]]]))) - Invariant(Forall(int, lambda d_10_k_: - (Forall(int, lambda d_11_k_k_: - (Implies(((((0) <= (d_10_k_)) and ((d_10_k_) <= (d_2_i_))) and ((d_2_i_) < (d_11_k_k_))) and ((d_11_k_k_) < (len((a)))), ((a)[d_10_k_]) <= ((a)[d_11_k_k_])), - [[(a)[d_11_k_k_]]])), - [[(a)[d_10_k_]]]))) - Invariant(Forall(int, lambda d_12_k_: - (Implies(((0) <= (d_12_k_)) and ((d_12_k_) <= (d_7_j_)), ((a)[d_12_k_]) <= ((a)[d_7_j_])), - [[(a)[d_12_k_]]]))) + Invariant((((0) < (i)) and ((i) < (len((a))))) and (((0) <= (j)) and ((j) <= (i)))) + Invariant(Forall(int, lambda ii: + (Forall(int, lambda jj: + (Implies((((i) <= (ii)) and ((ii) <= (jj))) and ((jj) < (len((a)))), ((a)[ii]) <= ((a)[jj])), + [[(a)[jj]]])), + [[(a)[ii]]]))) + Invariant(Forall(int, lambda k: + (Forall(int, lambda k_k: + (Implies(((((0) <= (k)) and ((k) <= (i))) and ((i) < (k_k))) and ((k_k) < (len((a)))), ((a)[k]) <= ((a)[k_k])), + [[(a)[k_k]]])), + [[(a)[k]]]))) + Invariant(Forall(int, lambda k: + (Implies(((0) <= (k)) and ((k) <= (j)), ((a)[k]) <= ((a)[j])), + [[(a)[k]]]))) # invariants-end - if ((a)[d_7_j_]) > ((a)[(d_7_j_) + (1)]): - rhs0_ : int = (a)[(d_7_j_) + (1)] - (a)[(d_7_j_) + (1)] = (a)[d_7_j_] - (a)[d_7_j_] = rhs0_ - d_7_j_ = (d_7_j_) + (1) - d_2_i_ = (d_2_i_) - (1) + if ((a)[j]) > ((a)[(j) + (1)]): + rhs0_ : int = (a)[(j) + (1)] + (a)[(j) + (1)] = (a)[j] + (a)[j] = rhs0_ + j = (j) + (1) + i = (i) - (1) return a # impl-end diff --git a/Bench/089-encrypt.py b/Bench/089-encrypt.py index d7514c9..14fb4a6 100644 --- a/Bench/089-encrypt.py +++ b/Bench/089-encrypt.py @@ -12,45 +12,45 @@ def rot__sym(c : int) -> int : # post-conditions-end # pure-start - d_0_alph_ : int = c - 0 - return ((d_0_alph_) + ((2) * (2))) % 26 + alph : int = c - 0 + return ((alph) + ((2) * (2))) % 26 # pure-end def encrypt(s : List[int]) -> List[int]: # pre-conditions-start Requires(Acc(list_pred(s))) - Requires(Forall(int, lambda d_1_i_: - not (((0) <= (d_1_i_)) and ((d_1_i_) < (len(s)))) or (((0) <= ((s)[d_1_i_])) and (((s)[d_1_i_]) <= (25))))) + Requires(Forall(int, lambda i: + not (((0) <= (i)) and ((i) < (len(s)))) or (((0) <= ((s)[i])) and (((s)[i]) <= (25))))) # pre-conditions-end # post-conditions-start Ensures(Acc(list_pred(s))) Ensures(Acc(list_pred(Result()))) Ensures((len(Result())) == (len(s))) - Ensures(Forall(int, lambda d_1_i_: - not (((0) <= (d_1_i_)) and ((d_1_i_) < (len(s)))) or (((0) <= ((s)[d_1_i_])) and (((s)[d_1_i_]) <= (25))))) - Ensures(Forall(int, lambda d_1_i_: - not (((0) <= (d_1_i_)) and ((d_1_i_) < (len(Result())))) or (((0) <= ((Result())[d_1_i_])) and (((Result())[d_1_i_]) <= (25))))) - Ensures(Forall(int, lambda d_2_i_: - not (((0) <= (d_2_i_)) and ((d_2_i_) < (len(s)))) or (((Result())[d_2_i_]) == (rot__sym((s)[d_2_i_]))))) + Ensures(Forall(int, lambda i: + not (((0) <= (i)) and ((i) < (len(s)))) or (((0) <= ((s)[i])) and (((s)[i]) <= (25))))) + Ensures(Forall(int, lambda i: + not (((0) <= (i)) and ((i) < (len(Result())))) or (((0) <= ((Result())[i])) and (((Result())[i]) <= (25))))) + Ensures(Forall(int, lambda i: + not (((0) <= (i)) and ((i) < (len(s)))) or (((Result())[i]) == (rot__sym((s)[i]))))) # post-conditions-end # impl-start r : List[int] = [] - d_3_i_ : int = 0 - while (d_3_i_) < (len(s)): + i : int = 0 + while (i) < (len(s)): # invariants-start Invariant(Acc(list_pred(s))) Invariant(Acc(list_pred(r))) - Invariant(((0) <= (d_3_i_)) and ((d_3_i_) <= (len(s)))) - Invariant((len(r)) == (d_3_i_)) - Invariant(Forall(int, lambda d_1_i_: - not (((0) <= (d_1_i_)) and ((d_1_i_) < (len(s)))) or (((0) <= ((s)[d_1_i_])) and (((s)[d_1_i_]) <= (25))))) - Invariant(Forall(int, lambda d_1_i_: - not (((0) <= (d_1_i_)) and ((d_1_i_) < (len(r)))) or (((0) <= ((r)[d_1_i_])) and (((r)[d_1_i_]) <= (25))))) - Invariant(Forall(int, lambda d_4_j_: - (not (((0) <= (d_4_j_)) and ((d_4_j_) < (d_3_i_))) or (((r)[d_4_j_]) == (rot__sym((s)[d_4_j_]))), [[rot__sym((s)[d_4_j_])]]))) + Invariant(((0) <= (i)) and ((i) <= (len(s)))) + Invariant((len(r)) == (i)) + Invariant(Forall(int, lambda i: + not (((0) <= (i)) and ((i) < (len(s)))) or (((0) <= ((s)[i])) and (((s)[i]) <= (25))))) + Invariant(Forall(int, lambda i: + not (((0) <= (i)) and ((i) < (len(r)))) or (((0) <= ((r)[i])) and (((r)[i]) <= (25))))) + Invariant(Forall(int, lambda j: + (not (((0) <= (j)) and ((j) < (i))) or (((r)[j]) == (rot__sym((s)[j]))), [[rot__sym((s)[j])]]))) # invariants-end - r = (r) + [rot__sym((s)[d_3_i_])] - d_3_i_ = (d_3_i_) + (1) + r = (r) + [rot__sym((s)[i])] + i = (i) + (1) return r # impl-end diff --git a/Bench/093-encode.py b/Bench/093-encode.py index 4c70841..72ca721 100644 --- a/Bench/093-encode.py +++ b/Bench/093-encode.py @@ -4,38 +4,38 @@ def encode(s : List[int]) -> List[int]: # pre-conditions-start Requires(Acc(list_pred(s))) - Requires(Forall(int, lambda d_0_i_: - not (((0) <= (d_0_i_)) and ((d_0_i_) < (len(s)))) or ((((97) <= ((s)[d_0_i_])) and (((s)[d_0_i_]) <= (122))) or (((65) <= ((s)[d_0_i_])) and (((s)[d_0_i_]) <= (90)))))) + Requires(Forall(int, lambda i: + not (((0) <= (i)) and ((i) < (len(s)))) or ((((97) <= ((s)[i])) and (((s)[i]) <= (122))) or (((65) <= ((s)[i])) and (((s)[i]) <= (90)))))) # pre-conditions-end # post-conditions-start Ensures(Acc(list_pred(Result()))) Ensures(Acc(list_pred(s))) Ensures((len(s)) == (len(Result()))) - Ensures(Forall(int, lambda d_1_i_: - not ((((0) <= (d_1_i_)) and ((d_1_i_) < (len(s)))) and (is__vowel((s)[d_1_i_]))) or (((Result())[d_1_i_]) == (rot2(swap__case((s)[d_1_i_])))))) - Ensures(Forall(int, lambda d_2_i_: - not ((((0) <= (d_2_i_)) and ((d_2_i_) < (len(s)))) and (not(is__vowel((s)[d_2_i_])))) or (((Result())[d_2_i_]) == (swap__case((s)[d_2_i_]))))) + Ensures(Forall(int, lambda i: + not ((((0) <= (i)) and ((i) < (len(s)))) and (is__vowel((s)[i]))) or (((Result())[i]) == (rot2(swap__case((s)[i])))))) + Ensures(Forall(int, lambda i: + not ((((0) <= (i)) and ((i) < (len(s)))) and (not(is__vowel((s)[i])))) or (((Result())[i]) == (swap__case((s)[i]))))) # post-conditions-end # impl-start t : List[int] = [] - d_3_i_ : int = 0 - while (d_3_i_) < (len(s)): + i : int = 0 + while (i) < (len(s)): # invariants-start Invariant(Acc(list_pred(t))) Invariant(Acc(list_pred(s))) - Invariant(((0) <= (d_3_i_)) and ((d_3_i_) <= (len(s)))) - Invariant((len(t)) == (d_3_i_)) - Invariant(Forall(int, lambda d_4_j_: - (not ((((0) <= (d_4_j_)) and ((d_4_j_) < (d_3_i_))) and (is__vowel((s)[d_4_j_]))) or (((t)[d_4_j_]) == (rot2(swap__case((s)[d_4_j_])))), [[rot2(swap__case((s)[d_4_j_]))]]))) - Invariant(Forall(int, lambda d_5_j_: - (not ((((0) <= (d_5_j_)) and ((d_5_j_) < (d_3_i_))) and (not(is__vowel((s)[d_5_j_])))) or (((t)[d_5_j_]) == (swap__case((s)[d_5_j_]))), [[swap__case((s)[d_5_j_])]]))) + Invariant(((0) <= (i)) and ((i) <= (len(s)))) + Invariant((len(t)) == (i)) + Invariant(Forall(int, lambda j: + (not ((((0) <= (j)) and ((j) < (i))) and (is__vowel((s)[j]))) or (((t)[j]) == (rot2(swap__case((s)[j])))), [[rot2(swap__case((s)[j]))]]))) + Invariant(Forall(int, lambda j: + (not ((((0) <= (j)) and ((j) < (i))) and (not(is__vowel((s)[j])))) or (((t)[j]) == (swap__case((s)[j]))), [[swap__case((s)[j])]]))) # invariants-end - if is__vowel((s)[d_3_i_]): - t = (t) + [rot2(swap__case((s)[d_3_i_]))] + if is__vowel((s)[i]): + t = (t) + [rot2(swap__case((s)[i]))] else: - t = (t) + [swap__case((s)[d_3_i_])] - d_3_i_ = (d_3_i_) + (1) + t = (t) + [swap__case((s)[i])] + i = (i) + (1) return t # impl-end diff --git a/Bench/096-count_up_to.py b/Bench/096-count_up_to.py index 687427a..c783a2a 100644 --- a/Bench/096-count_up_to.py +++ b/Bench/096-count_up_to.py @@ -4,8 +4,8 @@ @Pure def IsPrime(n : int) -> bool : # pure-start - return ((n) > (1)) and (Forall(int, lambda d_0_k_: - Implies(((2) <= (d_0_k_)) and ((d_0_k_) < (n)), ((n % d_0_k_)) != (0)))) + return ((n) > (1)) and (Forall(int, lambda k: + Implies(((2) <= (k)) and ((k) < (n)), ((n % k)) != (0)))) # pure-end def CountUpTo(n : int) -> List[int]: @@ -14,28 +14,28 @@ def CountUpTo(n : int) -> List[int]: # pre-conditions-end # post-conditions-start Ensures(Acc(list_pred(Result()))) - Ensures(Forall(int, lambda d_2_i_: - not (((0) <= (d_2_i_)) and ((d_2_i_) < (len(Result())))) or (((Result())[d_2_i_]) < (n)))) - Ensures(Forall(int, lambda d_1_i_: - not (((0) <= (d_1_i_)) and ((d_1_i_) < (len(Result())))) or (IsPrime((Result())[d_1_i_])))) + Ensures(Forall(int, lambda i: + not (((0) <= (i)) and ((i) < (len(Result())))) or (((Result())[i]) < (n)))) + Ensures(Forall(int, lambda i: + not (((0) <= (i)) and ((i) < (len(Result())))) or (IsPrime((Result())[i])))) # post-conditions-end # impl-start primes : List[int] = [] if (n) <= (2): return primes - d_4_i_ : int = 2 - while (d_4_i_) < (n): + i : int = 2 + while (i) < (n): # invariants-start Invariant(Acc(list_pred(primes))) - Invariant(((2) <= (d_4_i_)) and ((d_4_i_) <= (n))) + Invariant(((2) <= (i)) and ((i) <= (n))) Invariant(Forall(int, lambda x: Implies(x >= 0 and x < len(primes), 2 <= primes[x] and primes[x] < n))) - Invariant(Forall(int, lambda d_5_j_: - (Implies(((0) <= (d_5_j_)) and ((d_5_j_) < (len(primes))), IsPrime((primes)[d_5_j_])), [[IsPrime((primes)[d_5_j_])]]))) + Invariant(Forall(int, lambda j: + (Implies(((0) <= (j)) and ((j) < (len(primes))), IsPrime((primes)[j])), [[IsPrime((primes)[j])]]))) # invariants-end - if IsPrime(d_4_i_): - primes = primes + [(d_4_i_)] - d_4_i_ = (d_4_i_) + (1) + if IsPrime(i): + primes = primes + [(i)] + i = (i) + (1) return primes # impl-end diff --git a/Bench/098-count_upper.py b/Bench/098-count_upper.py index 5e8c522..268d86f 100644 --- a/Bench/098-count_upper.py +++ b/Bench/098-count_upper.py @@ -34,24 +34,24 @@ def count__upper(s : List[int]) -> int: # impl-start cnt : int = 0 - d_1_i_ : int = 0 + i : int = 0 - while (d_1_i_) < (len(s)): + while (i) < (len(s)): # invariants-start Invariant(Acc(list_pred(s))) - Invariant(((0) <= (d_1_i_)) and ((d_1_i_) <= (len(s)))) - Invariant(Forall(int, lambda d_0_i_: (Implies(d_0_i_ >= 0 and d_0_i_ < len(s), - count__upper__fun(s, 0, d_0_i_ + 1) == (count__upper__fun(s, 0, d_0_i_) + (1) if is__upper__vowel(s[d_0_i_]) and d_0_i_ % 2 == 0 else count__upper__fun(s, 0, d_0_i_))), - [[count__upper__fun(s, 0, d_0_i_ + 1)]]))) - Invariant((cnt) == (count__upper__fun(s, 0, d_1_i_))) + Invariant(((0) <= (i)) and ((i) <= (len(s)))) + Invariant(Forall(int, lambda i: (Implies(i >= 0 and i < len(s), + count__upper__fun(s, 0, i + 1) == (count__upper__fun(s, 0, i) + (1) if is__upper__vowel(s[i]) and i % 2 == 0 else count__upper__fun(s, 0, i))), + [[count__upper__fun(s, 0, i + 1)]]))) + Invariant((cnt) == (count__upper__fun(s, 0, i))) # invariants-end # assert-start - Assert(count__upper__fun(s, 0, d_1_i_ + 1) == (count__upper__fun(s, 0, d_1_i_) + (1) if is__upper__vowel(s[d_1_i_]) and d_1_i_ % 2 == 0 else count__upper__fun(s, 0, d_1_i_))) + Assert(count__upper__fun(s, 0, i + 1) == (count__upper__fun(s, 0, i) + (1) if is__upper__vowel(s[i]) and i % 2 == 0 else count__upper__fun(s, 0, i))) # assert-end - if (is__upper__vowel((s)[d_1_i_])) and (((d_1_i_ % 2)) == (0)): + if (is__upper__vowel((s)[i])) and (((i % 2)) == (0)): cnt = (cnt) + (1) - d_1_i_ = (d_1_i_) + (1) + i = (i) + (1) return cnt # impl-end diff --git a/Bench/100-make_a_pile.py b/Bench/100-make_a_pile.py index d80ad85..5b3a6c9 100644 --- a/Bench/100-make_a_pile.py +++ b/Bench/100-make_a_pile.py @@ -8,8 +8,8 @@ def make__a__pile(n : int) -> List[int]: # post-conditions-start Ensures(Acc(list_pred(Result()))) Ensures((len(Result())) == (n)) - Ensures(Forall(int, lambda d_0_i_: - Implies(((1) <= (d_0_i_)) and ((d_0_i_) < (n)), ((Result())[d_0_i_]) == (((Result())[(d_0_i_) - (1)]) + (2))))) + Ensures(Forall(int, lambda i: + Implies(((1) <= (i)) and ((i) < (n)), ((Result())[i]) == (((Result())[(i) - (1)]) + (2))))) Ensures(Implies((n) > (0), ((Result())[0]) == (n))) # post-conditions-end @@ -18,19 +18,19 @@ def make__a__pile(n : int) -> List[int]: if (n) == (0): return pile pile = [n] - d_1_i_ : int = 1 - while (d_1_i_) < (n): + i : int = 1 + while (i) < (n): # invariants-start Invariant(Acc(list_pred(pile))) - Invariant(len(pile) == d_1_i_) + Invariant(len(pile) == i) Invariant(len(pile) > 0) - Invariant(((0) <= (d_1_i_)) and ((d_1_i_) <= (n))) - Invariant((len(pile)) == (d_1_i_)) - Invariant(Forall(int, lambda d_2_j_: - Implies(((1) <= (d_2_j_)) and ((d_2_j_) < (d_1_i_)), ((pile)[d_2_j_]) == (((pile)[(d_2_j_) - (1)]) + (2))))) + Invariant(((0) <= (i)) and ((i) <= (n))) + Invariant((len(pile)) == (i)) + Invariant(Forall(int, lambda j: + Implies(((1) <= (j)) and ((j) < (i)), ((pile)[j]) == (((pile)[(j) - (1)]) + (2))))) Invariant(Implies((n) > (0), ((pile)[0]) == (n))) # invariants-end - pile = (pile) + [((pile)[(d_1_i_) - (1)]) + (2)] - d_1_i_ = (d_1_i_) + (1) + pile = (pile) + [((pile)[(i) - (1)]) + (2)] + i = (i) + (1) return pile # impl-end diff --git a/Bench/102-choose_num.py b/Bench/102-choose_num.py index 8f2f8d9..ef31f09 100644 --- a/Bench/102-choose_num.py +++ b/Bench/102-choose_num.py @@ -8,8 +8,8 @@ def choose__num(x : int, y : int) -> int: # post-conditions-start Ensures(((Result()) == (-1)) or (((Result()) >= (x)) and ((Result()) <= (y)))) Ensures(((Result()) == (-1)) or (((Result() % 2)) == (0))) - Ensures(((Result()) == (-1)) or (Forall(int, lambda d_0_i_: - not ((((x) <= (d_0_i_)) and ((d_0_i_) <= (y))) and (((d_0_i_ % 2)) == (0))) or ((Result()) >= (d_0_i_))))) + Ensures(((Result()) == (-1)) or (Forall(int, lambda i: + not ((((x) <= (i)) and ((i) <= (y))) and (((i % 2)) == (0))) or ((Result()) >= (i))))) Ensures(((Result()) == (-1)) == ((x) >= (y))) # post-conditions-end @@ -21,17 +21,17 @@ def choose__num(x : int, y : int) -> int: num = x elif True: num = (x) + (1) - d_1_i_ : int = (x) + (2) - while (d_1_i_) <= (y): + i : int = (x) + (2) + while (i) <= (y): # invariants-start - Invariant(((d_1_i_) >= (x)) and ((d_1_i_) <= ((y) + (1)))) + Invariant(((i) >= (x)) and ((i) <= ((y) + (1)))) Invariant(((num) == (-1)) or (((num % 2)) == (0))) - Invariant(Forall(int, lambda d_2_j_: - not ((((x) <= (d_2_j_)) and ((d_2_j_) < (d_1_i_))) and (((d_2_j_ % 2)) == (0))) or ((num) >= (d_2_j_)))) - Invariant(((num) == (-1)) or (((num) >= (x)) and ((num) < (d_1_i_)))) + Invariant(Forall(int, lambda j: + not ((((x) <= (j)) and ((j) < (i))) and (((j % 2)) == (0))) or ((num) >= (j)))) + Invariant(((num) == (-1)) or (((num) >= (x)) and ((num) < (i)))) # invariants-end - if ((d_1_i_ % 2)) == (0): - num = d_1_i_ - d_1_i_ = (d_1_i_) + (1) + if ((i % 2)) == (0): + num = i + i = (i) + (1) return num # impl-end diff --git a/Bench/104-unique_digits.py b/Bench/104-unique_digits.py index 7f66eff..c340016 100644 --- a/Bench/104-unique_digits.py +++ b/Bench/104-unique_digits.py @@ -9,8 +9,8 @@ def InArray(a : List[int], x : int) -> bool: # pre-conditions-end # pure-start - return Exists(int, lambda d_0_i_: - ((((0) <= (d_0_i_)) and ((d_0_i_) < (len((a)))) and ((a)[d_0_i_]) == (x)))) + return Exists(int, lambda i: + ((((0) <= (i)) and ((i) < (len((a)))) and ((a)[i]) == (x)))) # pure-end @Pure @@ -26,142 +26,142 @@ def HasNoEvenDigit(n : int) -> bool : def UniqueDigits(x : List[int]) -> List[int]: # pre-conditions-start Requires(Acc(list_pred(x), 1/2)) - Requires(Forall(int, lambda d_0_i_: Implies(d_0_i_ >= 0 and d_0_i_ < len(x), (x[d_0_i_] >= 0)))) + Requires(Forall(int, lambda i: Implies(i >= 0 and i < len(x), (x[i] >= 0)))) # pre-conditions-end # post-conditions-start Ensures(Acc(list_pred(x), 1/2)) Ensures(Acc(list_pred(Result()))) Ensures(len(Result()) <= len(x)) - Ensures(Forall(int, lambda d_0_i_: Implies(d_0_i_ >= 0 and d_0_i_ < len(x), (x[d_0_i_] >= 0)))) - Ensures(Forall(int, lambda d_0_i_: Implies(d_0_i_ >= 0 and d_0_i_ < len(Result()), (Result()[d_0_i_] >= 0)))) - Ensures(Forall(int, lambda d_0_i_: - not (((0) <= (d_0_i_)) and ((d_0_i_) < (len(Result())))) or (HasNoEvenDigit((Result())[d_0_i_])))) - Ensures(Forall(int, lambda d_8_e_: - not (((d_8_e_) >= 0 and d_8_e_ < len(x)) and (HasNoEvenDigit(x[d_8_e_]))) or - (Exists(int, lambda d_9_j_: - (d_9_j_ >= 0 and d_9_j_ < len(Result())) and Result()[d_9_j_] == x[d_8_e_])))) - Ensures(Forall(int, lambda d_7_e_: - not ((d_7_e_) >= 0 and d_7_e_ < len(Result())) or (InArray(x, Result()[d_7_e_])))) - Ensures(Forall(int, lambda d_1_i_: - Forall(int, lambda d_2_j_: - not ((((0) <= (d_1_i_)) and ((d_1_i_) < (d_2_j_))) and ((d_2_j_) < (len(Result())))) or (((Result())[d_1_i_]) <= ((Result())[d_2_j_]))))) + Ensures(Forall(int, lambda i: Implies(i >= 0 and i < len(x), (x[i] >= 0)))) + Ensures(Forall(int, lambda i: Implies(i >= 0 and i < len(Result()), (Result()[i] >= 0)))) + Ensures(Forall(int, lambda i: + not (((0) <= (i)) and ((i) < (len(Result())))) or (HasNoEvenDigit((Result())[i])))) + Ensures(Forall(int, lambda e: + not (((e) >= 0 and e < len(x)) and (HasNoEvenDigit(x[e]))) or + (Exists(int, lambda j: + (j >= 0 and j < len(Result())) and Result()[j] == x[e])))) + Ensures(Forall(int, lambda e: + not ((e) >= 0 and e < len(Result())) or (InArray(x, Result()[e])))) + Ensures(Forall(int, lambda i: + Forall(int, lambda j: + not ((((0) <= (i)) and ((i) < (j))) and ((j) < (len(Result())))) or (((Result())[i]) <= ((Result())[j]))))) # post-conditions-end # impl-start result : List[int] = [] - d_5_i_ = 0 + i = 0 - while d_5_i_ < len(x): + while i < len(x): # invariants-start Invariant(Acc(list_pred(result))) Invariant(Acc(list_pred(x), 1/2)) - Invariant(0 <= d_5_i_ and d_5_i_ <= len(x)) - Invariant(len(result) <= d_5_i_) - Invariant(Forall(int, lambda d_0_i_: Implies(d_0_i_ >= 0 and d_0_i_ < len(x), (x[d_0_i_] >= 0)))) - Invariant(Forall(int, lambda d_0_i_: Implies(d_0_i_ >= 0 and d_0_i_ < len(result), (result[d_0_i_] >= 0)))) - Invariant(Forall(int, lambda d_6_j_: - (Implies(((0) <= (d_6_j_)) and ((d_6_j_) < (len(result))), HasNoEvenDigit((result)[d_6_j_])), [[HasNoEvenDigit((result)[d_6_j_])]]))) - Invariant(Forall(int, lambda d_8_e_: - (Implies(((d_8_e_) >= 0 and d_8_e_ < d_5_i_) and (HasNoEvenDigit(x[d_8_e_])), - Exists(int, lambda d_9_j_: - (d_9_j_ >= 0 and d_9_j_ < len(result)) and result[d_9_j_] == x[d_8_e_])), - [[(HasNoEvenDigit(x[d_8_e_]))]]))) - Invariant(Forall(int, lambda d_7_e_: - (Implies((d_7_e_) >= 0 and d_7_e_ < len(result), - InArray(x, result[d_7_e_])), - [[InArray(x, result[d_7_e_])]]))) + Invariant(0 <= i and i <= len(x)) + Invariant(len(result) <= i) + Invariant(Forall(int, lambda i: Implies(i >= 0 and i < len(x), (x[i] >= 0)))) + Invariant(Forall(int, lambda i: Implies(i >= 0 and i < len(result), (result[i] >= 0)))) + Invariant(Forall(int, lambda j: + (Implies(((0) <= (j)) and ((j) < (len(result))), HasNoEvenDigit((result)[j])), [[HasNoEvenDigit((result)[j])]]))) + Invariant(Forall(int, lambda e: + (Implies(((e) >= 0 and e < i) and (HasNoEvenDigit(x[e])), + Exists(int, lambda j: + (j >= 0 and j < len(result)) and result[j] == x[e])), + [[(HasNoEvenDigit(x[e]))]]))) + Invariant(Forall(int, lambda e: + (Implies((e) >= 0 and e < len(result), + InArray(x, result[e])), + [[InArray(x, result[e])]]))) # invariants-end - if HasNoEvenDigit((x)[d_5_i_]): - result = (result) + [(x)[d_5_i_]] - d_5_i_ = (d_5_i_) + (1) - d_9_i_ : int = 0 - while (d_9_i_) < (len(result)): + if HasNoEvenDigit((x)[i]): + result = (result) + [(x)[i]] + i = (i) + (1) + i : int = 0 + while (i) < (len(result)): # invariants-start Invariant(Acc(list_pred(result))) Invariant(Acc(list_pred(x), 1/2)) Invariant(len(result) <= len(x)) - Invariant(((0) <= (d_9_i_)) and ((d_9_i_) <= (len(result)))) - Invariant(Forall(int, lambda d_0_i_: - (Implies(d_0_i_ >= 0 and d_0_i_ < len(x), (x[d_0_i_] >= 0)), [[x[d_0_i_]]]))) - Invariant(Forall(int, lambda d_0_i_: - (Implies(d_0_i_ >= 0 and d_0_i_ < len(result), (result[d_0_i_] >= 0)), [[result[d_0_i_]]]))) - Invariant(Forall(int, lambda d_6_j_: - (Implies(((0) <= (d_6_j_)) and ((d_6_j_) < (len(result))), HasNoEvenDigit((result)[d_6_j_])), [[HasNoEvenDigit((result)[d_6_j_])]]))) - Invariant(Forall(int, lambda d_8_e_: - (Implies(((d_8_e_) >= 0 and d_8_e_ < len(x)) and (HasNoEvenDigit(x[d_8_e_])), - Exists(int, lambda d_9_j_: - (d_9_j_ >= 0 and d_9_j_ < len(result)) and result[d_9_j_] == x[d_8_e_])), - [[(HasNoEvenDigit(x[d_8_e_]))]]))) - Invariant(Forall(int, lambda d_7_e_: - (Implies((d_7_e_) >= 0 and d_7_e_ < len(result), - InArray(x, result[d_7_e_])), - [[InArray(x, result[d_7_e_])]]))) - Invariant(Forall(int, lambda d_10_j_: - (Forall(int, lambda d_11_k_: - (not ((((0) <= (d_10_j_)) and ((d_10_j_) < (d_11_k_))) and ((d_11_k_) < (d_9_i_))) or (((result)[d_10_j_]) <= ((result)[d_11_k_])), - [[(result)[d_11_k_]]])), - [[(result)[d_10_j_]]]))) - Invariant(Forall(int, lambda d_12_j_: - (not ((((0) <= (d_12_j_)) and ((d_12_j_) < (d_9_i_)))) or - (Forall(int, lambda d_13_k_: - (not ((((d_9_i_) <= (d_13_k_)) and ((d_13_k_) < (len(result))))) or - (((result)[d_12_j_]) <= ((result)[d_13_k_])), - [[result[d_13_k_]]]))), - [[(result)[d_12_j_]]]))) + Invariant(((0) <= (i)) and ((i) <= (len(result)))) + Invariant(Forall(int, lambda i: + (Implies(i >= 0 and i < len(x), (x[i] >= 0)), [[x[i]]]))) + Invariant(Forall(int, lambda i: + (Implies(i >= 0 and i < len(result), (result[i] >= 0)), [[result[i]]]))) + Invariant(Forall(int, lambda j: + (Implies(((0) <= (j)) and ((j) < (len(result))), HasNoEvenDigit((result)[j])), [[HasNoEvenDigit((result)[j])]]))) + Invariant(Forall(int, lambda e: + (Implies(((e) >= 0 and e < len(x)) and (HasNoEvenDigit(x[e])), + Exists(int, lambda j: + (j >= 0 and j < len(result)) and result[j] == x[e])), + [[(HasNoEvenDigit(x[e]))]]))) + Invariant(Forall(int, lambda e: + (Implies((e) >= 0 and e < len(result), + InArray(x, result[e])), + [[InArray(x, result[e])]]))) + Invariant(Forall(int, lambda j: + (Forall(int, lambda k: + (not ((((0) <= (j)) and ((j) < (k))) and ((k) < (i))) or (((result)[j]) <= ((result)[k])), + [[(result)[k]]])), + [[(result)[j]]]))) + Invariant(Forall(int, lambda j: + (not ((((0) <= (j)) and ((j) < (i)))) or + (Forall(int, lambda k: + (not ((((i) <= (k)) and ((k) < (len(result))))) or + (((result)[j]) <= ((result)[k])), + [[result[k]]]))), + [[(result)[j]]]))) # invariants-end - d_17_minIndex_ : int = d_9_i_ - d_18_j_ : int = (d_9_i_) + (1) - while (d_18_j_) < (len(result)): + minIndex : int = i + j : int = (i) + (1) + while (j) < (len(result)): # invariants-start Invariant(Acc(list_pred(result))) Invariant(Acc(list_pred(x), 1/2)) Invariant(len(result) <= len(x)) - Invariant(((0) <= (d_9_i_)) and ((d_9_i_) < (len(result)))) - Invariant(Forall(int, lambda d_0_i_: - (Implies(d_0_i_ >= 0 and d_0_i_ < len(x), (x[d_0_i_] >= 0)), [[x[d_0_i_]]]))) - Invariant(Forall(int, lambda d_0_i_: - (Implies(d_0_i_ >= 0 and d_0_i_ < len(result), (result[d_0_i_] >= 0)), [[result[d_0_i_]]]))) - Invariant((((d_9_i_) <= (d_17_minIndex_)) and ((d_17_minIndex_) < (d_18_j_))) and ((d_18_j_) <= (len(result)))) - Invariant(Forall(int, lambda d_6_j_: - (Implies(((0) <= (d_6_j_)) and ((d_6_j_) < (len(result))), HasNoEvenDigit((result)[d_6_j_])), [[HasNoEvenDigit((result)[d_6_j_])]]))) - Invariant(HasNoEvenDigit((result)[d_17_minIndex_])) - Invariant(Forall(int, lambda d_8_e_: - (Implies(((d_8_e_) >= 0 and d_8_e_ < len(x)) and (HasNoEvenDigit(x[d_8_e_])), - Exists(int, lambda d_9_j_: - (d_9_j_ >= 0 and d_9_j_ < len(result)) and result[d_9_j_] == x[d_8_e_])), - [[(HasNoEvenDigit(x[d_8_e_]))]]))) - Invariant(Forall(int, lambda d_7_e_: - (Implies((d_7_e_) >= 0 and d_7_e_ < len(result), - InArray(x, result[d_7_e_])), - [[InArray(x, result[d_7_e_])]]))) - Invariant(Forall(int, lambda d_10_j_: - (Forall(int, lambda d_11_k_: - (not ((((0) <= (d_10_j_)) and ((d_10_j_) < (d_11_k_))) and ((d_11_k_) < (d_9_i_))) or (((result)[d_10_j_]) <= ((result)[d_11_k_])), - [[(result)[d_11_k_]]])), - [[(result)[d_10_j_]]]))) - Invariant(Forall(int, lambda d_19_k_: - (not (((d_9_i_) <= (d_19_k_)) and ((d_19_k_) < (d_18_j_))) or (((result)[d_17_minIndex_]) <= ((result)[d_19_k_])), [[((result)[d_19_k_])]]))) - Invariant(Forall(int, lambda d_12_j_: - (not ((((0) <= (d_12_j_)) and ((d_12_j_) < (d_9_i_)))) or - (Forall(int, lambda d_13_k_: - (not ((((d_9_i_) <= (d_13_k_)) and ((d_13_k_) < (len(result))))) or - (((result)[d_12_j_]) <= ((result)[d_13_k_])), - [[result[d_13_k_]]]))), - [[(result)[d_12_j_]]]))) + Invariant(((0) <= (i)) and ((i) < (len(result)))) + Invariant(Forall(int, lambda i: + (Implies(i >= 0 and i < len(x), (x[i] >= 0)), [[x[i]]]))) + Invariant(Forall(int, lambda i: + (Implies(i >= 0 and i < len(result), (result[i] >= 0)), [[result[i]]]))) + Invariant((((i) <= (minIndex)) and ((minIndex) < (j))) and ((j) <= (len(result)))) + Invariant(Forall(int, lambda j: + (Implies(((0) <= (j)) and ((j) < (len(result))), HasNoEvenDigit((result)[j])), [[HasNoEvenDigit((result)[j])]]))) + Invariant(HasNoEvenDigit((result)[minIndex])) + Invariant(Forall(int, lambda e: + (Implies(((e) >= 0 and e < len(x)) and (HasNoEvenDigit(x[e])), + Exists(int, lambda j: + (j >= 0 and j < len(result)) and result[j] == x[e])), + [[(HasNoEvenDigit(x[e]))]]))) + Invariant(Forall(int, lambda e: + (Implies((e) >= 0 and e < len(result), + InArray(x, result[e])), + [[InArray(x, result[e])]]))) + Invariant(Forall(int, lambda j: + (Forall(int, lambda k: + (not ((((0) <= (j)) and ((j) < (k))) and ((k) < (i))) or (((result)[j]) <= ((result)[k])), + [[(result)[k]]])), + [[(result)[j]]]))) + Invariant(Forall(int, lambda k: + (not (((i) <= (k)) and ((k) < (j))) or (((result)[minIndex]) <= ((result)[k])), [[((result)[k])]]))) + Invariant(Forall(int, lambda j: + (not ((((0) <= (j)) and ((j) < (i)))) or + (Forall(int, lambda k: + (not ((((i) <= (k)) and ((k) < (len(result))))) or + (((result)[j]) <= ((result)[k])), + [[result[k]]]))), + [[(result)[j]]]))) # invariants-end - if ((result)[d_18_j_]) < ((result)[d_17_minIndex_]): - d_17_minIndex_ = d_18_j_ - d_18_j_ = (d_18_j_) + (1) - if (d_17_minIndex_) != (d_9_i_): - d_20_temp_ : int = (result)[d_9_i_] + if ((result)[j]) < ((result)[minIndex]): + minIndex = j + j = (j) + (1) + if (minIndex) != (i): + temp : int = (result)[i] # assert-start - Assert(HasNoEvenDigit((result)[d_17_minIndex_])) + Assert(HasNoEvenDigit((result)[minIndex])) # assert-end - result[d_9_i_] = (result)[d_17_minIndex_] + result[i] = (result)[minIndex] # assert-start - Assert(HasNoEvenDigit(d_20_temp_)) + Assert(HasNoEvenDigit(temp)) # assert-end - result[d_17_minIndex_] = d_20_temp_ - d_9_i_ = (d_9_i_) + (1) + result[minIndex] = temp + i = (i) + (1) return result # impl-end diff --git a/Bench/105-by_length.py b/Bench/105-by_length.py index dc89834..547179d 100644 --- a/Bench/105-by_length.py +++ b/Bench/105-by_length.py @@ -21,128 +21,128 @@ def SortReverseAndName(arr : List[int]) -> List[str]: Ensures(Acc(list_pred(arr))) Ensures(Acc(list_pred(Result()))) Ensures((len(Result())) <= (len(arr))) - Ensures(Forall(int, lambda d_0_i_: - Implies(((0) <= (d_0_i_)) and ((d_0_i_) < (len(Result()))), - WithinRangeString(Result()[d_0_i_])))) + Ensures(Forall(int, lambda i: + Implies(((0) <= (i)) and ((i) < (len(Result()))), + WithinRangeString(Result()[i])))) # post-conditions-end # impl-start - d_1_validNumbers_ : List[int] = [] - d_2_i_ : int = int(0) - while (d_2_i_) < (len(arr)): + validNumbers : List[int] = [] + i : int = int(0) + while (i) < (len(arr)): # invariants-start - Invariant(Acc(list_pred(d_1_validNumbers_))) + Invariant(Acc(list_pred(validNumbers))) Invariant(Acc(list_pred(arr))) - Invariant(((0) <= (d_2_i_)) and ((d_2_i_) <= (len(arr)))) - Invariant((len(d_1_validNumbers_)) <= (d_2_i_)) - Invariant(Forall(int, lambda d_3_j_: - (Implies(((0) <= (d_3_j_)) and ((d_3_j_) < (len(d_1_validNumbers_))), WithinRange(d_1_validNumbers_[d_3_j_])), + Invariant(((0) <= (i)) and ((i) <= (len(arr)))) + Invariant((len(validNumbers)) <= (i)) + Invariant(Forall(int, lambda j: + (Implies(((0) <= (j)) and ((j) < (len(validNumbers))), WithinRange(validNumbers[j])), [[]]))) # invariants-end - if WithinRange((arr)[d_2_i_]): - d_1_validNumbers_ = (d_1_validNumbers_) + [(arr)[d_2_i_]] - d_2_i_ = (d_2_i_) + (1) + if WithinRange((arr)[i]): + validNumbers = (validNumbers) + [(arr)[i]] + i = (i) + (1) # assert-start - Assert(len(d_1_validNumbers_) <= len(arr)) + Assert(len(validNumbers) <= len(arr)) # assert-end - d_1_validNumbers_ = BubbleSort(d_1_validNumbers_) + validNumbers = BubbleSort(validNumbers) - d_1_validNumbers_ = reverse(d_1_validNumbers_) - d_2_i_ = 0 + validNumbers = reverse(validNumbers) + i = 0 result : List[str] = [] - while (d_2_i_) < (len(d_1_validNumbers_)): + while (i) < (len(validNumbers)): # invariants-start - Invariant(Acc(list_pred(d_1_validNumbers_))) + Invariant(Acc(list_pred(validNumbers))) Invariant(Acc(list_pred(result))) Invariant(Acc(list_pred(arr))) - Invariant(((0) <= (d_2_i_)) and ((d_2_i_) <= (len(d_1_validNumbers_)))) - Invariant(len(d_1_validNumbers_) <= len(arr)) - Invariant(d_2_i_ <= len(arr)) - Invariant((len(result)) == (d_2_i_)) - Invariant(Forall(int, lambda d_9_j_: - (Implies(((0) <= (d_9_j_)) and ((d_9_j_) < (len(d_1_validNumbers_))), ((1) <= ((d_1_validNumbers_)[d_9_j_])) and (((d_1_validNumbers_)[d_9_j_]) <= (9))), - [[(d_1_validNumbers_)[d_9_j_]]]))) - Invariant(Forall(int, lambda d_0_i_: - (Implies(((0) <= (d_0_i_)) and ((d_0_i_) < (len(result))), - WithinRangeString(result[d_0_i_])), + Invariant(((0) <= (i)) and ((i) <= (len(validNumbers)))) + Invariant(len(validNumbers) <= len(arr)) + Invariant(i <= len(arr)) + Invariant((len(result)) == (i)) + Invariant(Forall(int, lambda j: + (Implies(((0) <= (j)) and ((j) < (len(validNumbers))), ((1) <= ((validNumbers)[j])) and (((validNumbers)[j]) <= (9))), + [[(validNumbers)[j]]]))) + Invariant(Forall(int, lambda i: + (Implies(((0) <= (i)) and ((i) < (len(result))), + WithinRangeString(result[i])), [[]]))) # invariants-end - result = (result) + [NumberToName((d_1_validNumbers_)[d_2_i_])] - d_2_i_ = (d_2_i_) + (1) + result = (result) + [NumberToName((validNumbers)[i])] + i = (i) + (1) return result # impl-end def BubbleSort(a1 : List[int]) -> List[int]: # pre-conditions-start Requires(Acc(list_pred(a1), 1/2)) - Requires(Forall(int, lambda d_4_j_: - Implies(((0) <= (d_4_j_)) and ((d_4_j_) < (len(a1))), ((1) <= ((a1)[d_4_j_])) and (((a1)[d_4_j_]) <= (9))))) + Requires(Forall(int, lambda j: + Implies(((0) <= (j)) and ((j) < (len(a1))), ((1) <= ((a1)[j])) and (((a1)[j]) <= (9))))) # pre-conditions-end # post-conditions-start Ensures(Acc(list_pred(a1), 1/2)) Ensures(Acc(list_pred(Result()))) - Ensures(Forall(int, lambda d_4_j_: - Implies(((0) <= (d_4_j_)) and ((d_4_j_) < (len(Result()))), ((1) <= ((Result())[d_4_j_])) and (((Result())[d_4_j_]) <= (9))))) + Ensures(Forall(int, lambda j: + Implies(((0) <= (j)) and ((j) < (len(Result()))), ((1) <= ((Result())[j])) and (((Result())[j]) <= (9))))) Ensures((len(a1)) == (len(Result()))) - Ensures(Forall(int, lambda d_0_i_: - Forall(int, lambda d_1_j_: - Implies((((0) <= (d_0_i_)) and ((d_0_i_) < (d_1_j_))) and ((d_1_j_) < (len((Result())))), ((Result())[d_0_i_]) <= ((Result())[d_1_j_]))))) + Ensures(Forall(int, lambda i: + Forall(int, lambda j: + Implies((((0) <= (i)) and ((i) < (j))) and ((j) < (len((Result())))), ((Result())[i]) <= ((Result())[j]))))) # post-conditions-end # impl-start a : List[int] = list(a1) - d_2_i_ : int = (len((a))) - (1) - while (d_2_i_) > (0): + i : int = (len((a))) - (1) + while (i) > (0): # invariants-start Invariant(Acc(list_pred(a))) Invariant(Acc(list_pred(a1), 1/2)) - Invariant(Forall(int, lambda d_4_j_: - (Implies(((0) <= (d_4_j_)) and ((d_4_j_) < (len(a))), ((1) <= ((a)[d_4_j_])) and (((a)[d_4_j_]) <= (9))), - [[(a)[d_4_j_]]]))) + Invariant(Forall(int, lambda j: + (Implies(((0) <= (j)) and ((j) < (len(a))), ((1) <= ((a)[j])) and (((a)[j]) <= (9))), + [[(a)[j]]]))) Invariant((len(a1)) == (len(a))) - Invariant(Implies((d_2_i_) < (0), (len((a))) == (0))) - Invariant(((-1) <= (d_2_i_)) and ((d_2_i_) < (len((a))))) - Invariant(Forall(int, lambda d_3_ii_: - (Forall(int, lambda d_4_jj_: - (Implies((((d_2_i_) <= (d_3_ii_)) and ((d_3_ii_) < (d_4_jj_))) and ((d_4_jj_) < (len((a)))), ((a)[d_3_ii_]) <= ((a)[d_4_jj_])), - [[(a)[d_4_jj_]]])), - [[(a)[d_3_ii_]]]))) - Invariant(Forall(int, lambda d_5_k_: - (Forall(int, lambda d_6_k_k_: - (Implies(((((0) <= (d_5_k_)) and ((d_5_k_) <= (d_2_i_))) and ((d_2_i_) < (d_6_k_k_)) and (d_6_k_k_) < (len((a)))), ((a)[d_5_k_]) <= ((a)[d_6_k_k_])), - [[(a)[d_6_k_k_]]])), - [[(a)[d_5_k_]]]))) + Invariant(Implies((i) < (0), (len((a))) == (0))) + Invariant(((-1) <= (i)) and ((i) < (len((a))))) + Invariant(Forall(int, lambda ii: + (Forall(int, lambda jj: + (Implies((((i) <= (ii)) and ((ii) < (jj))) and ((jj) < (len((a)))), ((a)[ii]) <= ((a)[jj])), + [[(a)[jj]]])), + [[(a)[ii]]]))) + Invariant(Forall(int, lambda k: + (Forall(int, lambda k_k: + (Implies(((((0) <= (k)) and ((k) <= (i))) and ((i) < (k_k)) and (k_k) < (len((a)))), ((a)[k]) <= ((a)[k_k])), + [[(a)[k_k]]])), + [[(a)[k]]]))) # invariants-end - d_7_j_ : int = 0 - while (d_7_j_) < (d_2_i_): + j : int = 0 + while (j) < (i): # invariants-start Invariant(Acc(list_pred(a))) Invariant(Acc(list_pred(a1), 1/2)) - Invariant(Forall(int, lambda d_4_j_: - (Implies(((0) <= (d_4_j_)) and ((d_4_j_) < (len(a))), ((1) <= ((a)[d_4_j_])) and (((a)[d_4_j_]) <= (9))), - [[(a)[d_4_j_]]]))) + Invariant(Forall(int, lambda j: + (Implies(((0) <= (j)) and ((j) < (len(a))), ((1) <= ((a)[j])) and (((a)[j]) <= (9))), + [[(a)[j]]]))) Invariant((len(a1)) == (len(a))) - Invariant((((0) < (d_2_i_)) and ((d_2_i_) < (len((a))))) and (((0) <= (d_7_j_)) and ((d_7_j_) <= (d_2_i_)))) - Invariant(Forall(int, lambda d_8_ii_: - (Forall(int, lambda d_9_jj_: - (Implies((((d_2_i_) <= (d_8_ii_)) and ((d_8_ii_) <= (d_9_jj_))) and ((d_9_jj_) < (len((a)))), ((a)[d_8_ii_]) <= ((a)[d_9_jj_])), - [[(a)[d_9_jj_]]])), - [[(a)[d_8_ii_]]]))) - Invariant(Forall(int, lambda d_10_k_: - (Forall(int, lambda d_11_k_k_: - (Implies(((((0) <= (d_10_k_)) and ((d_10_k_) <= (d_2_i_))) and ((d_2_i_) < (d_11_k_k_))) and ((d_11_k_k_) < (len((a)))), ((a)[d_10_k_]) <= ((a)[d_11_k_k_])), - [[(a)[d_11_k_k_]]])), - [[(a)[d_10_k_]]]))) - Invariant(Forall(int, lambda d_12_k_: - (Implies(((0) <= (d_12_k_)) and ((d_12_k_) <= (d_7_j_)), ((a)[d_12_k_]) <= ((a)[d_7_j_])), - [[(a)[d_12_k_]]]))) + Invariant((((0) < (i)) and ((i) < (len((a))))) and (((0) <= (j)) and ((j) <= (i)))) + Invariant(Forall(int, lambda ii: + (Forall(int, lambda jj: + (Implies((((i) <= (ii)) and ((ii) <= (jj))) and ((jj) < (len((a)))), ((a)[ii]) <= ((a)[jj])), + [[(a)[jj]]])), + [[(a)[ii]]]))) + Invariant(Forall(int, lambda k: + (Forall(int, lambda k_k: + (Implies(((((0) <= (k)) and ((k) <= (i))) and ((i) < (k_k))) and ((k_k) < (len((a)))), ((a)[k]) <= ((a)[k_k])), + [[(a)[k_k]]])), + [[(a)[k]]]))) + Invariant(Forall(int, lambda k: + (Implies(((0) <= (k)) and ((k) <= (j)), ((a)[k]) <= ((a)[j])), + [[(a)[k]]]))) # invariants-end - if ((a)[d_7_j_]) > ((a)[(d_7_j_) + (1)]): - rhs0_ : int = (a)[(d_7_j_) + (1)] - (a)[(d_7_j_) + (1)] = (a)[d_7_j_] - (a)[d_7_j_] = rhs0_ - d_7_j_ = (d_7_j_) + (1) - d_2_i_ = (d_2_i_) - (1) + if ((a)[j]) > ((a)[(j) + (1)]): + rhs0_ : int = (a)[(j) + (1)] + (a)[(j) + (1)] = (a)[j] + (a)[j] = rhs0_ + j = (j) + (1) + i = (i) - (1) return a # impl-end @@ -150,49 +150,49 @@ def reverse(str : List[int]) -> List[int]: # pre-conditions-start Requires(Acc(list_pred(str), 1/2)) Requires(Forall(int, lambda x: Forall(int, lambda y: Implies(((0) <= (x)) and ((x) < (y)) and ((y) < (len(str))), (str)[x] <= (str)[y])))) - Requires(Forall(int, lambda d_4_j_: - Implies(((0) <= (d_4_j_)) and ((d_4_j_) < (len(str))), ((1) <= ((str)[d_4_j_])) and (((str)[d_4_j_]) <= (9))))) + Requires(Forall(int, lambda j: + Implies(((0) <= (j)) and ((j) < (len(str))), ((1) <= ((str)[j])) and (((str)[j]) <= (9))))) # pre-conditions-end # post-conditions-start Ensures(Acc(list_pred(str), 1/2)) Ensures(Acc(list_pred(Result()))) - Ensures(Forall(int, lambda d_4_j_: - Implies(((0) <= (d_4_j_)) and ((d_4_j_) < (len(str))), ((1) <= ((str)[d_4_j_])) and (((str)[d_4_j_]) <= (9))))) + Ensures(Forall(int, lambda j: + Implies(((0) <= (j)) and ((j) < (len(str))), ((1) <= ((str)[j])) and (((str)[j]) <= (9))))) Ensures(Forall(int, lambda x: Forall(int, lambda y: Implies(((0) <= (x)) and ((x) < (y)) and ((y) < (len(Result()))), (Result())[x] >= (Result())[y])))) Ensures(str == Old(str)) Ensures((len(Result())) == (len(str))) - Ensures(Forall(int, lambda d_11_k_: - Implies(((0) <= (d_11_k_)) and ((d_11_k_) < (len(str))), ((Result())[d_11_k_]) == ((str)[((len(str)) - (1)) - (d_11_k_)])))) + Ensures(Forall(int, lambda k: + Implies(((0) <= (k)) and ((k) < (len(str))), ((Result())[k]) == ((str)[((len(str)) - (1)) - (k)])))) # post-conditions-end # impl-start rev : List[int] = [] - d_12_i_ : int = 0 - while (d_12_i_) < (len(str)): + i : int = 0 + while (i) < (len(str)): # invariants-start Invariant(Acc(list_pred(str), 1/2)) Invariant(Acc(list_pred(rev))) - Invariant(Forall(int, lambda d_4_j_: - (Implies(((0) <= (d_4_j_)) and ((d_4_j_) < (len(str))), ((1) <= ((str)[d_4_j_])) and (((str)[d_4_j_]) <= (9))), [[str[d_4_j_]]]))) - Invariant(Forall(int, lambda d_4_j_: - ( Implies(((0) <= (d_4_j_)) and ((d_4_j_) < (len(rev))), ((1) <= ((rev)[d_4_j_])) and (((rev)[d_4_j_]) <= (9))), [[rev[d_4_j_]]]))) + Invariant(Forall(int, lambda j: + (Implies(((0) <= (j)) and ((j) < (len(str))), ((1) <= ((str)[j])) and (((str)[j]) <= (9))), [[str[j]]]))) + Invariant(Forall(int, lambda j: + ( Implies(((0) <= (j)) and ((j) < (len(rev))), ((1) <= ((rev)[j])) and (((rev)[j]) <= (9))), [[rev[j]]]))) Invariant(Forall(int, lambda x: (Forall(int, lambda y: (Implies(((0) <= (x)) and ((x) < (y)) and ((y) < (len(str))), (str)[x] <= (str)[y]), [[str[y]]])), [[str[x]]]))) - Invariant(((d_12_i_) >= (0)) and ((d_12_i_) <= (len(str)))) - Invariant((len(rev)) == (d_12_i_)) - Invariant(Forall(int, lambda d_13_k_: - Implies(((0) <= (d_13_k_)) and ((d_13_k_) < (d_12_i_)), ((rev)[d_13_k_]) == ((str)[(len(str) - (1)) - (d_13_k_)])))) + Invariant(((i) >= (0)) and ((i) <= (len(str)))) + Invariant((len(rev)) == (i)) + Invariant(Forall(int, lambda k: + Implies(((0) <= (k)) and ((k) < (i)), ((rev)[k]) == ((str)[(len(str) - (1)) - (k)])))) Invariant(Forall(int, lambda x: Forall(int, lambda y: - (Implies(((0) <= (x)) and ((x) < (len(rev))) and (0 <= y and (y) < (len(str) - d_12_i_)), (str)[y] <= (rev)[x]), [[str[y] <= rev[x]]])))) + (Implies(((0) <= (x)) and ((x) < (len(rev))) and (0 <= y and (y) < (len(str) - i)), (str)[y] <= (rev)[x]), [[str[y] <= rev[x]]])))) Invariant(Forall(int, lambda x: Forall(int, lambda y: (Implies(((0) <= (x)) and ((x) < (y)) and ((y) < (len(rev))), (rev)[x] >= (rev)[y]), [[rev[x] >= rev[y]]])))) # invariants-end - rev = (rev) + [(str)[(len(str) - (d_12_i_)) - (1)]] - d_12_i_ = (d_12_i_) + (1) + rev = (rev) + [(str)[(len(str) - (i)) - (1)]] + i = (i) + (1) return rev # impl-end diff --git a/Bench/106-f.py b/Bench/106-f.py index e796398..4740df4 100644 --- a/Bench/106-f.py +++ b/Bench/106-f.py @@ -40,61 +40,61 @@ def f(n : int) -> List[int]: # post-conditions-start Ensures(Acc(list_pred(Result()))) Ensures((len(Result())) == (n)) - Ensures(Forall(int, lambda d_2_i_: - not ((((d_2_i_) >= (0)) and ((d_2_i_) < (len(Result())))) and (((d_2_i_ % 2)) == (0))) or (((Result())[d_2_i_]) == (factorial__spec(d_2_i_ - 1))))) - Ensures(Forall(int, lambda d_3_i_: - not ((((d_3_i_) >= (0)) and ((d_3_i_) < (len(Result())))) and (((d_3_i_ % 2)) != (0))) or (((Result())[d_3_i_]) == (sum__spec(d_3_i_ - 1))))) + Ensures(Forall(int, lambda i: + not ((((i) >= (0)) and ((i) < (len(Result())))) and (((i % 2)) == (0))) or (((Result())[i]) == (factorial__spec(i - 1))))) + Ensures(Forall(int, lambda i: + not ((((i) >= (0)) and ((i) < (len(Result())))) and (((i % 2)) != (0))) or (((Result())[i]) == (sum__spec(i - 1))))) # post-conditions-end # impl-start result : List[int] = [] - d_4_i_ : int = 0 - while (d_4_i_) < (n): + i : int = 0 + while (i) < (n): # invariants-start Invariant(Acc(list_pred(result))) - Invariant(((d_4_i_) >= (0)) and ((d_4_i_) <= (n))) - Invariant((len(result)) == (d_4_i_)) - Invariant(Forall(int, lambda d_5_i_: - (Implies((((d_5_i_) >= (0)) and ((d_5_i_) < (len(result)))) and (((d_5_i_ % 2)) == (0)), ((result)[d_5_i_]) == (factorial__spec(d_5_i_ - 1))), [[factorial__spec(d_5_i_ - 1)]]))) - Invariant(Forall(int, lambda d_6_i_: - (Implies((((d_6_i_) >= (0)) and ((d_6_i_) < (len(result)))) and (((d_6_i_ % 2)) != (0)), ((result)[d_6_i_]) == (sum__spec(d_6_i_ - 1))), [[sum__spec(d_6_i_ - 1)]]))) + Invariant(((i) >= (0)) and ((i) <= (n))) + Invariant((len(result)) == (i)) + Invariant(Forall(int, lambda i: + (Implies((((i) >= (0)) and ((i) < (len(result)))) and (((i % 2)) == (0)), ((result)[i]) == (factorial__spec(i - 1))), [[factorial__spec(i - 1)]]))) + Invariant(Forall(int, lambda i: + (Implies((((i) >= (0)) and ((i) < (len(result)))) and (((i % 2)) != (0)), ((result)[i]) == (sum__spec(i - 1))), [[sum__spec(i - 1)]]))) # invariants-end - if ((d_4_i_ % 2)) == (0): - d_7_x_ : int = 1 - d_8_j_ : int = 0 - while (d_8_j_) < (d_4_i_): + if ((i % 2)) == (0): + x : int = 1 + j : int = 0 + while (j) < (i): # invariants-start Invariant(Acc(list_pred(result))) - Invariant(((d_4_i_) >= (0)) and ((d_4_i_) <= (n))) - Invariant((len(result)) == (d_4_i_)) - Invariant(((d_8_j_) >= (0)) and ((d_8_j_) <= (d_4_i_))) - Invariant((d_7_x_) == (factorial__spec(d_8_j_ - 1))) - Invariant(Forall(int, lambda d_5_i_: - (Implies((((d_5_i_) >= (0)) and ((d_5_i_) < (len(result)))) and (((d_5_i_ % 2)) == (0)), ((result)[d_5_i_]) == (factorial__spec(d_5_i_ - 1))), [[factorial__spec(d_5_i_ - 1)]]))) - Invariant(Forall(int, lambda d_6_i_: - (Implies((((d_6_i_) >= (0)) and ((d_6_i_) < (len(result)))) and (((d_6_i_ % 2)) != (0)), ((result)[d_6_i_]) == (sum__spec(d_6_i_ - 1))), [[sum__spec(d_6_i_ - 1)]]))) + Invariant(((i) >= (0)) and ((i) <= (n))) + Invariant((len(result)) == (i)) + Invariant(((j) >= (0)) and ((j) <= (i))) + Invariant((x) == (factorial__spec(j - 1))) + Invariant(Forall(int, lambda i: + (Implies((((i) >= (0)) and ((i) < (len(result)))) and (((i % 2)) == (0)), ((result)[i]) == (factorial__spec(i - 1))), [[factorial__spec(i - 1)]]))) + Invariant(Forall(int, lambda i: + (Implies((((i) >= (0)) and ((i) < (len(result)))) and (((i % 2)) != (0)), ((result)[i]) == (sum__spec(i - 1))), [[sum__spec(i - 1)]]))) # invariants-end - d_7_x_ = (d_7_x_) * (d_8_j_ + 1) - d_8_j_ = (d_8_j_) + (1) - result = (result) + [d_7_x_] + x = (x) * (j + 1) + j = (j) + (1) + result = (result) + [x] else: - d_9_x_ : int = 0 - d_10_j_ : int = 0 - while (d_10_j_) < (d_4_i_): + x : int = 0 + j : int = 0 + while (j) < (i): # invariants-start Invariant(Acc(list_pred(result))) - Invariant(((d_4_i_) >= (0)) and ((d_4_i_) <= (n))) - Invariant((len(result)) == (d_4_i_)) - Invariant(((d_10_j_) >= (0)) and ((d_10_j_) <= (d_4_i_))) - Invariant((d_9_x_) == (sum__spec(d_10_j_ - 1))) - Invariant(Forall(int, lambda d_5_i_: - (Implies((((d_5_i_) >= (0)) and ((d_5_i_) < (len(result)))) and (((d_5_i_ % 2)) == (0)), ((result)[d_5_i_]) == (factorial__spec(d_5_i_ - 1))), [[factorial__spec(d_5_i_ - 1)]]))) - Invariant(Forall(int, lambda d_6_i_: - (Implies((((d_6_i_) >= (0)) and ((d_6_i_) < (len(result)))) and (((d_6_i_ % 2)) != (0)), ((result)[d_6_i_]) == (sum__spec(d_6_i_ - 1))), [[sum__spec(d_6_i_ - 1)]]))) + Invariant(((i) >= (0)) and ((i) <= (n))) + Invariant((len(result)) == (i)) + Invariant(((j) >= (0)) and ((j) <= (i))) + Invariant((x) == (sum__spec(j - 1))) + Invariant(Forall(int, lambda i: + (Implies((((i) >= (0)) and ((i) < (len(result)))) and (((i % 2)) == (0)), ((result)[i]) == (factorial__spec(i - 1))), [[factorial__spec(i - 1)]]))) + Invariant(Forall(int, lambda i: + (Implies((((i) >= (0)) and ((i) < (len(result)))) and (((i % 2)) != (0)), ((result)[i]) == (sum__spec(i - 1))), [[sum__spec(i - 1)]]))) # invariants-end - d_9_x_ = (d_9_x_) + (d_10_j_ + 1) - d_10_j_ = (d_10_j_) + (1) - result = (result) + [d_9_x_] - d_4_i_ = (d_4_i_) + (1) + x = (x) + (j + 1) + j = (j) + (1) + result = (result) + [x] + i = (i) + (1) return result # impl-end diff --git a/Bench/108-count_nums.py b/Bench/108-count_nums.py index 4bfb513..3d6b9b9 100644 --- a/Bench/108-count_nums.py +++ b/Bench/108-count_nums.py @@ -12,22 +12,22 @@ def count__nums(s : List[int]) -> int: # impl-start cnt : int = 0 - d_1_i_ : int = 0 - while (d_1_i_) < (len(s)): + i : int = 0 + while (i) < (len(s)): # invariants-start Invariant(Acc(list_pred(s))) - Invariant(((0) <= (d_1_i_)) and ((d_1_i_) <= (len(s)))) + Invariant(((0) <= (i)) and ((i) <= (len(s)))) Invariant(Forall(int, lambda x : (Implies(0 <= x and x < len(s), get_positive(0, x + 1, s) == ((digits__sum(s[x]) > 0) + get_positive(0, x, s))), [[get_positive(0, x + 1, s)]]))) - Invariant((cnt) == (get_positive(0, d_1_i_, s))) + Invariant((cnt) == (get_positive(0, i, s))) # invariants-end # assert-start - Assert(get_positive(0, d_1_i_ + 1, s) == (digits__sum(s[d_1_i_]) > 0) + get_positive(0, d_1_i_, s)) + Assert(get_positive(0, i + 1, s) == (digits__sum(s[i]) > 0) + get_positive(0, i, s)) # assert-end - if (digits__sum((s)[d_1_i_])) > (0): + if (digits__sum((s)[i])) > (0): cnt = (cnt) + (1) - d_1_i_ = (d_1_i_) + (1) + i = (i) + (1) return cnt # impl-end diff --git a/Bench/109-move_one_ball.py b/Bench/109-move_one_ball.py index 7d51aa0..ab3914d 100644 --- a/Bench/109-move_one_ball.py +++ b/Bench/109-move_one_ball.py @@ -10,34 +10,34 @@ def is__sorted(a : List[int], l : int, r : int) -> bool : # pre-conditions-end # pure-start - return Forall(int, lambda d_0_i_: - Forall(int, lambda d_1_j_: - not ((((l) <= (d_0_i_)) and ((d_0_i_) < (d_1_j_))) and ((d_1_j_) < (r))) or (((a)[d_0_i_]) <= ((a)[d_1_j_])))) + return Forall(int, lambda i: + Forall(int, lambda j: + not ((((l) <= (i)) and ((i) < (j))) and ((j) < (r))) or (((a)[i]) <= ((a)[j])))) # pure-end def move__one__ball(a : List[int]) -> bool: # pre-conditions-start Requires(Acc(list_pred(a))) Requires((len(a)) > (0)) - Requires(Forall(int, lambda d_2_i_: - Forall(int, lambda d_3_j_: - not (((((0) <= (d_2_i_)) and ((d_2_i_) < (len(a)))) and (((0) <= (d_3_j_)) and ((d_3_j_) < (len(a))))) and ((d_2_i_) != (d_3_j_))) or (((a)[d_2_i_]) != ((a)[d_3_j_]))))) + Requires(Forall(int, lambda i: + Forall(int, lambda j: + not (((((0) <= (i)) and ((i) < (len(a)))) and (((0) <= (j)) and ((j) < (len(a))))) and ((i) != (j))) or (((a)[i]) != ((a)[j]))))) # pre-conditions-end # post-conditions-start Ensures(Acc(list_pred(a))) - Ensures(Forall(int, lambda d_2_i_: - Forall(int, lambda d_3_j_: - not (((((0) <= (d_2_i_)) and ((d_2_i_) < (len(a)))) and (((0) <= (d_3_j_)) and ((d_3_j_) < (len(a))))) and ((d_2_i_) != (d_3_j_))) or (((a)[d_2_i_]) != ((a)[d_3_j_]))))) - Ensures(Implies(Result(), Exists(int, lambda d_4_i_: - (((0) <= (d_4_i_)) and ((d_4_i_) < (len(a)))) and (is__sorted(a, 0, d_4_i_) and is__sorted(a, d_4_i_, len(a)) and (Forall(int, lambda d_5_j_: - Implies(0 <= d_5_j_ and d_5_j_ < d_4_i_, - Forall(int, lambda d_6_j_: - Implies(d_4_i_ <= d_6_j_ and d_6_j_ < len(a), a[d_5_j_] > a[d_6_j_]))))))))) - Ensures(Implies(Exists(int, lambda d_4_i_: - (((0) <= (d_4_i_)) and ((d_4_i_) < (len(a)))) and (is__sorted(a, 0, d_4_i_) and is__sorted(a, d_4_i_, len(a)) and (Forall(int, lambda d_5_j_: - Implies(0 <= d_5_j_ and d_5_j_ < d_4_i_, - Forall(int, lambda d_6_j_: - Implies(d_4_i_ <= d_6_j_ and d_6_j_ < len(a), a[d_5_j_] > a[d_6_j_]))))))), Result())) + Ensures(Forall(int, lambda i: + Forall(int, lambda j: + not (((((0) <= (i)) and ((i) < (len(a)))) and (((0) <= (j)) and ((j) < (len(a))))) and ((i) != (j))) or (((a)[i]) != ((a)[j]))))) + Ensures(Implies(Result(), Exists(int, lambda i: + (((0) <= (i)) and ((i) < (len(a)))) and (is__sorted(a, 0, i) and is__sorted(a, i, len(a)) and (Forall(int, lambda j: + Implies(0 <= j and j < i, + Forall(int, lambda j: + Implies(i <= j and j < len(a), a[j] > a[j]))))))))) + Ensures(Implies(Exists(int, lambda i: + (((0) <= (i)) and ((i) < (len(a)))) and (is__sorted(a, 0, i) and is__sorted(a, i, len(a)) and (Forall(int, lambda j: + Implies(0 <= j and j < i, + Forall(int, lambda j: + Implies(i <= j and j < len(a), a[j] > a[j]))))))), Result())) # post-conditions-end # impl-start @@ -46,34 +46,34 @@ def move__one__ball(a : List[int]) -> bool: Assert(is__sorted(a, 0, len(a))) # assert-end return True - d_5_i_ : int = 0 - d_6_min__index_ : int = 0 - while (d_5_i_) < (len(a)): + i : int = 0 + min__index : int = 0 + while (i) < (len(a)): # invariants-start Invariant(Acc(list_pred(a))) - Invariant(((0) <= (d_5_i_)) and ((d_5_i_) <= (len(a)))) - Invariant(((0) <= (d_6_min__index_)) and ((d_6_min__index_) < (len(a)))) - Invariant(Forall(int, lambda d_2_i_: - (Forall(int, lambda d_3_j_: - (not (((((0) <= (d_2_i_)) and ((d_2_i_) < (len(a)))) and (((0) <= (d_3_j_)) and ((d_3_j_) < (len(a))))) and ((d_2_i_) != (d_3_j_))) or (((a)[d_2_i_]) != ((a)[d_3_j_])) - , [[(a)[d_3_j_]]])) - , [[a[d_2_i_]]]))) - Invariant(Forall(int, lambda d_7_j_: - (not ((((0) <= (d_7_j_)) and ((d_7_j_) < (d_5_i_))) and ((d_6_min__index_) != (d_7_j_))) or (((a)[d_6_min__index_]) < ((a)[d_7_j_])), [[(a)[d_7_j_]]]))) + Invariant(((0) <= (i)) and ((i) <= (len(a)))) + Invariant(((0) <= (min__index)) and ((min__index) < (len(a)))) + Invariant(Forall(int, lambda i: + (Forall(int, lambda j: + (not (((((0) <= (i)) and ((i) < (len(a)))) and (((0) <= (j)) and ((j) < (len(a))))) and ((i) != (j))) or (((a)[i]) != ((a)[j])) + , [[(a)[j]]])) + , [[a[i]]]))) + Invariant(Forall(int, lambda j: + (not ((((0) <= (j)) and ((j) < (i))) and ((min__index) != (j))) or (((a)[min__index]) < ((a)[j])), [[(a)[j]]]))) # invariants-end - if ((a)[d_5_i_]) < ((a)[d_6_min__index_]): - d_6_min__index_ = d_5_i_ - d_5_i_ = (d_5_i_) + (1) + if ((a)[i]) < ((a)[min__index]): + min__index = i + i = (i) + (1) # assert-start - Assert(Implies(is__sorted(a, 0, d_6_min__index_) and is__sorted(a, d_6_min__index_, len(a)) and d_6_min__index_ == 0, + Assert(Implies(is__sorted(a, 0, min__index) and is__sorted(a, min__index, len(a)) and min__index == 0, is__sorted(a, 0, len(a)))) - Assert(Implies(is__sorted(a, 0, d_6_min__index_) and is__sorted(a, d_6_min__index_, len(a)) and d_6_min__index_ != 0 and a[len(a) - 1] < a[0], - (Forall(int, lambda d_5_j_: - Implies(0 <= d_5_j_ and d_5_j_ < d_6_min__index_, - Forall(int, lambda d_6_j_: - Implies(d_6_min__index_ <= d_6_j_ and d_6_j_ < len(a), a[d_5_j_] > a[d_6_j_]))))))) + Assert(Implies(is__sorted(a, 0, min__index) and is__sorted(a, min__index, len(a)) and min__index != 0 and a[len(a) - 1] < a[0], + (Forall(int, lambda j: + Implies(0 <= j and j < min__index, + Forall(int, lambda j: + Implies(min__index <= j and j < len(a), a[j] > a[j]))))))) # assert-end - can : bool = is__sorted(a, 0, d_6_min__index_) and is__sorted(a, d_6_min__index_, len(a)) and (d_6_min__index_ == 0 or a[len(a) - 1] < a[0]) + can : bool = is__sorted(a, 0, min__index) and is__sorted(a, min__index, len(a)) and (min__index == 0 or a[len(a) - 1] < a[0]) return can # impl-end diff --git a/Bench/110-exchange.py b/Bench/110-exchange.py index 6dccd71..b745ce2 100644 --- a/Bench/110-exchange.py +++ b/Bench/110-exchange.py @@ -44,8 +44,8 @@ def Exchange(lst1 : List[int], lst2 : List[int]) -> str: # post-conditions-end # impl-start - d_1_totalEvens_ : int = CountEvens(0, lst1) + CountEvens(0, lst2) - if (d_1_totalEvens_) >= (len(lst1)): + totalEvens : int = CountEvens(0, lst1) + CountEvens(0, lst2) + if (totalEvens) >= (len(lst1)): result = "YES" elif True: result = "NO" diff --git a/Bench/112-reverse_delete.py b/Bench/112-reverse_delete.py index 78263d6..aea17df 100644 --- a/Bench/112-reverse_delete.py +++ b/Bench/112-reverse_delete.py @@ -8,8 +8,8 @@ def InArray(a : List[int], x : int) -> bool : # pre-conditions-end # pure-start - return Exists(int, lambda d_0_i_: - ((((0) <= (d_0_i_)) and ((d_0_i_) < (len((a)))) and ((a)[d_0_i_]) == (x)))) + return Exists(int, lambda i: + ((((0) <= (i)) and ((i) < (len((a)))) and ((a)[i]) == (x)))) # pure-end @Pure @@ -19,8 +19,8 @@ def NotInArray(a : List[int], x : int) -> bool : # pre-conditions-end # pure-start - return Forall(int, lambda d_0_i_: - (Implies(((0) <= (d_0_i_)) and ((d_0_i_) < (len((a)))), ((a)[d_0_i_]) != (x)))) + return Forall(int, lambda i: + (Implies(((0) <= (i)) and ((i) < (len((a)))), ((a)[i]) != (x)))) # pure-end @Pure @@ -44,33 +44,33 @@ def reverse__delete(s : List[int], chars : List[int]) -> Tuple[List[int], bool]: Ensures(Acc(list_pred(s))) Ensures(Acc(list_pred(chars))) Ensures((Result()[1]) == (is__palindrome__pred(Result()[0]))) - Ensures(Forall(int, lambda d_0_i_: - not (((0) <= (d_0_i_)) and ((d_0_i_) < (len(Result()[0])))) or (NotInArray(chars, (Result()[0])[d_0_i_])))) - Ensures(Forall(int, lambda d_1_i_: - not (((0) <= (d_1_i_)) and ((d_1_i_) < (len(Result()[0])))) or (InArray(s, (Result()[0])[d_1_i_])))) - Ensures(Forall(int, lambda d_6_j_: - not ((((0) <= (d_6_j_)) and ((d_6_j_) < (len(s))))) or (implArrays(chars, Result()[0], (s)[d_6_j_])))) + Ensures(Forall(int, lambda i: + not (((0) <= (i)) and ((i) < (len(Result()[0])))) or (NotInArray(chars, (Result()[0])[i])))) + Ensures(Forall(int, lambda i: + not (((0) <= (i)) and ((i) < (len(Result()[0])))) or (InArray(s, (Result()[0])[i])))) + Ensures(Forall(int, lambda j: + not ((((0) <= (j)) and ((j) < (len(s))))) or (implArrays(chars, Result()[0], (s)[j])))) # post-conditions-end # impl-start res : List[int] = [] - d_3_i_ : int = 0 - while (d_3_i_) < (len(s)): + i : int = 0 + while (i) < (len(s)): # invariants-start Invariant(Acc(list_pred(res))) Invariant(Acc(list_pred(s))) Invariant(Acc(list_pred(chars))) - Invariant(((0) <= (d_3_i_)) and ((d_3_i_) <= (len(s)))) - Invariant(Forall(int, lambda d_4_i_: - (not (((0) <= (d_4_i_)) and ((d_4_i_) < (len(res)))) or (NotInArray(chars, (res)[d_4_i_])), [[]]))) - Invariant(Forall(int, lambda d_5_i_: - (not (((0) <= (d_5_i_)) and ((d_5_i_) < (len(res)))) or (InArray(s, res[d_5_i_])), [[InArray(s, res[d_5_i_])]]))) - Invariant(Forall(int, lambda d_6_j_: - (not ((((0) <= (d_6_j_)) and ((d_6_j_) < (d_3_i_)))) or (implArrays(chars, res, (s)[d_6_j_])), [[InArray(res, (s)[d_6_j_])]]))) + Invariant(((0) <= (i)) and ((i) <= (len(s)))) + Invariant(Forall(int, lambda i: + (not (((0) <= (i)) and ((i) < (len(res)))) or (NotInArray(chars, (res)[i])), [[]]))) + Invariant(Forall(int, lambda i: + (not (((0) <= (i)) and ((i) < (len(res)))) or (InArray(s, res[i])), [[InArray(s, res[i])]]))) + Invariant(Forall(int, lambda j: + (not ((((0) <= (j)) and ((j) < (i)))) or (implArrays(chars, res, (s)[j])), [[InArray(res, (s)[j])]]))) # invariants-end - if NotInArray(chars, (s)[d_3_i_]): - res = (res) + [(s)[d_3_i_]] - d_3_i_ = (d_3_i_) + (1) + if NotInArray(chars, (s)[i]): + res = (res) + [(s)[i]] + i = (i) + (1) is__palindrome : bool = is__palindrome__fun(res) return (res, is__palindrome) # impl-end @@ -81,24 +81,24 @@ def is__palindrome__fun(text : List[int]) -> bool: # pre-conditions-end # post-conditions-start Ensures(Acc(list_pred(text), 1/2)) - Ensures((Result()) == (Forall(int, lambda d_0_i_: - not (((d_0_i_) >= (0)) and ((d_0_i_) < (len(text)))) or (((text)[d_0_i_]) == ((text)[((len(text)) - (d_0_i_)) - (1)]))))) + Ensures((Result()) == (Forall(int, lambda i: + not (((i) >= (0)) and ((i) < (len(text)))) or (((text)[i]) == ((text)[((len(text)) - (i)) - (1)]))))) Ensures(Result() == is__palindrome__pred(text)) # post-conditions-end # impl-start result : bool = True - d_1_i_ : int = 0 - while (d_1_i_) < ((len(text) // 2)): + i : int = 0 + while (i) < ((len(text) // 2)): # invariant-start Invariant(Acc(list_pred(text), 1/2)) - Invariant(((0) <= (d_1_i_)) and ((d_1_i_) <= ((len(text) // 2)))) - Invariant((result) == (Forall(int, lambda d_2_i1_: - (not (((d_2_i1_) >= (0)) and ((d_2_i1_) < (d_1_i_))) or (((text)[d_2_i1_]) == ((text)[((len(text)) - (d_2_i1_)) - (1)])), [[]])))) + Invariant(((0) <= (i)) and ((i) <= ((len(text) // 2)))) + Invariant((result) == (Forall(int, lambda i1: + (not (((i1) >= (0)) and ((i1) < (i))) or (((text)[i1]) == ((text)[((len(text)) - (i1)) - (1)])), [[]])))) # invariant-end - if ((text)[d_1_i_]) != ((text)[((len(text)) - (d_1_i_)) - (1)]): + if ((text)[i]) != ((text)[((len(text)) - (i)) - (1)]): result = False - d_1_i_ = (d_1_i_) + (1) + i = (i) + (1) return result # impl-end @@ -109,6 +109,6 @@ def is__palindrome__pred(s : List[int]) -> bool : # pre-conditions-end # pure-start - return Forall(int, lambda d_10_k_: - (not (((0) <= (d_10_k_)) and ((d_10_k_) < (len(s)))) or (((s)[d_10_k_]) == ((s)[((len(s)) - (1)) - (d_10_k_)])))) + return Forall(int, lambda k: + (not (((0) <= (k)) and ((k) < (len(s)))) or (((s)[k]) == ((s)[((len(s)) - (1)) - (k)])))) # pure-end diff --git a/Bench/114-minSubArraySum.py b/Bench/114-minSubArraySum.py index acda110..262f453 100644 --- a/Bench/114-minSubArraySum.py +++ b/Bench/114-minSubArraySum.py @@ -21,53 +21,53 @@ def minSubArraySum(a : List[int]) -> int: # pre-conditions-end # post-conditions-start Ensures(Acc(list_pred(a))) - Ensures(Forall(int, lambda d_1_p_: - Forall(int, lambda d_2_q_: - not ((((0) <= (d_1_p_)) and ((d_1_p_) <= (d_2_q_))) and ((d_2_q_) <= (len(a)))) or ((Sum(a, d_1_p_, d_2_q_)) >= (Result()))))) - Ensures(Exists(int, lambda d_3_k_: - Exists(int, lambda d_4_m_: - ((((0) <= (d_3_k_)) and ((d_3_k_) <= (d_4_m_))) and ((d_4_m_) <= (len(a)))) and ((Result()) == (Sum(a, d_3_k_, d_4_m_)))))) + Ensures(Forall(int, lambda p: + Forall(int, lambda q: + not ((((0) <= (p)) and ((p) <= (q))) and ((q) <= (len(a)))) or ((Sum(a, p, q)) >= (Result()))))) + Ensures(Exists(int, lambda k: + Exists(int, lambda m: + ((((0) <= (k)) and ((k) <= (m))) and ((m) <= (len(a)))) and ((Result()) == (Sum(a, k, m)))))) # post-conditions-end # impl-start s : int = int(0) - d_5_k_ : int = int(0) - d_6_m_ : int = int(0) - d_7_n_ : int = int(0) - d_8_c_ : int = int(0) - d_9_t_ : int = int(0) - while (d_7_n_) < (len(a)): + k : int = int(0) + m : int = int(0) + n : int = int(0) + c : int = int(0) + t : int = int(0) + while (n) < (len(a)): # invariants-start Invariant(Acc(list_pred(a))) - Invariant(((0) <= (d_7_n_)) and ((d_7_n_) <= (len(a)))) - Invariant(Forall(int, lambda d_1_p_: (Implies(0 <= d_1_p_ and d_1_p_ < len(a), Sum(a, 0, d_1_p_ + 1) == Sum(a, 0, d_1_p_) + a[d_1_p_])))) + Invariant(((0) <= (n)) and ((n) <= (len(a)))) + Invariant(Forall(int, lambda p: (Implies(0 <= p and p < len(a), Sum(a, 0, p + 1) == Sum(a, 0, p) + a[p])))) Invariant(Forall(int, lambda st: Implies(st >= 0 and st < len(a), - Forall(int, lambda d_1_p_: (Implies(st <= d_1_p_ and d_1_p_ < len(a), Sum(a, st, d_1_p_ + 1) == Sum(a, st, d_1_p_) + a[d_1_p_])))))) - Invariant(((((0) <= (d_8_c_)) and ((d_8_c_) <= (d_7_n_))) and ((d_7_n_) <= (len(a))))) - Invariant(((d_9_t_) == (Sum(a, d_8_c_, d_7_n_)))) - Invariant(((((0) <= (d_5_k_)) and ((d_5_k_) <= (d_6_m_))) and ((d_6_m_) <= (d_7_n_)))) - Invariant(((s) == (Sum(a, d_5_k_, d_6_m_)))) - Invariant(Forall(int, lambda d_10_b_: - not (((0) <= (d_10_b_)) and ((d_10_b_) <= (d_7_n_))) or ((Sum(a, d_10_b_, d_7_n_)) >= (Sum(a, d_8_c_, d_7_n_))))) - Invariant(Sum(a, d_8_c_, d_7_n_) >= Sum(a, d_5_k_, d_6_m_)) - Invariant(Forall(int, lambda d_11_p_: - Forall(int, lambda d_12_q_: - (not ((((0) <= (d_11_p_)) and ((d_11_p_) <= (d_12_q_))) and ((d_12_q_) <= (d_7_n_))) or ((Sum(a, d_11_p_, d_12_q_)) >= (Sum(a, d_5_k_, d_6_m_))), [[Sum(a, d_11_p_, d_12_q_)]])))) + Forall(int, lambda p: (Implies(st <= p and p < len(a), Sum(a, st, p + 1) == Sum(a, st, p) + a[p])))))) + Invariant(((((0) <= (c)) and ((c) <= (n))) and ((n) <= (len(a))))) + Invariant(((t) == (Sum(a, c, n)))) + Invariant(((((0) <= (k)) and ((k) <= (m))) and ((m) <= (n)))) + Invariant(((s) == (Sum(a, k, m)))) + Invariant(Forall(int, lambda b: + not (((0) <= (b)) and ((b) <= (n))) or ((Sum(a, b, n)) >= (Sum(a, c, n))))) + Invariant(Sum(a, c, n) >= Sum(a, k, m)) + Invariant(Forall(int, lambda p: + Forall(int, lambda q: + (not ((((0) <= (p)) and ((p) <= (q))) and ((q) <= (n))) or ((Sum(a, p, q)) >= (Sum(a, k, m))), [[Sum(a, p, q)]])))) # invariants-end # assert-start - Assert(Sum(a, d_8_c_, d_7_n_ + 1) == Sum(a, d_8_c_, d_7_n_) + a[d_7_n_]) + Assert(Sum(a, c, n + 1) == Sum(a, c, n) + a[n]) # assert-end - d_9_t_ = (d_9_t_) + ((a)[d_7_n_]) - d_7_n_ = (d_7_n_) + (1) - if (d_9_t_) > (0): - d_8_c_ = d_7_n_ - d_9_t_ = 0 - elif (s) > (d_9_t_): - d_5_k_ = d_8_c_ - d_6_m_ = d_7_n_ - s = d_9_t_ + t = (t) + ((a)[n]) + n = (n) + (1) + if (t) > (0): + c = n + t = 0 + elif (s) > (t): + k = c + m = n + s = t return s # impl-end diff --git a/Bench/116-sort_array.py b/Bench/116-sort_array.py index fcd5fa9..d0ecb5c 100644 --- a/Bench/116-sort_array.py +++ b/Bench/116-sort_array.py @@ -24,63 +24,63 @@ def BubbleSort(a1 : List[int]) -> List[int]: Ensures(Acc(list_pred(Result()))) Ensures((len(a1)) == (len(Result()))) Ensures(Forall(int, lambda i : Implies(i >= 0 and i < len(Result()), Result()[i] >= 0))) - Ensures(Forall(int, lambda d_0_i_: - Forall(int, lambda d_1_j_: - Implies((((0) <= (d_0_i_)) and ((d_0_i_) < (d_1_j_))) and ((d_1_j_) < (len((Result())))), popcount((Result())[d_0_i_]) <= popcount((Result())[d_1_j_]))))) + Ensures(Forall(int, lambda i: + Forall(int, lambda j: + Implies((((0) <= (i)) and ((i) < (j))) and ((j) < (len((Result())))), popcount((Result())[i]) <= popcount((Result())[j]))))) # post-conditions-end # impl-start a : List[int] = list(a1) - d_2_i_ : int = (len((a))) - (1) - while (d_2_i_) > (0): + i : int = (len((a))) - (1) + while (i) > (0): # invariants-start Invariant(Acc(list_pred(a))) Invariant(Forall(int, lambda i : Implies(i >= 0 and i < len(a), a[i] >= 0))) Invariant(Acc(list_pred(a1), 1/2)) Invariant((len(a1)) == (len(a))) - Invariant(not ((d_2_i_) < (0)) or ((len((a))) == (0))) - Invariant(((-1) <= (d_2_i_)) and ((d_2_i_) < (len((a))))) - Invariant(Forall(int, lambda d_3_ii_: - (Forall(int, lambda d_4_jj_: - (Implies((((d_2_i_) <= (d_3_ii_)) and ((d_3_ii_) < (d_4_jj_))) and ((d_4_jj_) < (len((a)))), popcount((a)[d_3_ii_]) <= popcount((a)[d_4_jj_])), - [[popcount((a)[d_4_jj_])]])), - [[popcount((a)[d_3_ii_])]]))) - Invariant(Forall(int, lambda d_5_k_: - (Forall(int, lambda d_6_k_k_: - (Implies(((((0) <= (d_5_k_)) and ((d_5_k_) <= (d_2_i_))) and ((d_2_i_) < (d_6_k_k_)) and (d_6_k_k_) < (len((a)))), popcount((a)[d_5_k_]) <= popcount((a)[d_6_k_k_])), - [[popcount((a)[d_6_k_k_])]])), - [[popcount((a)[d_5_k_])]]))) + Invariant(not ((i) < (0)) or ((len((a))) == (0))) + Invariant(((-1) <= (i)) and ((i) < (len((a))))) + Invariant(Forall(int, lambda ii: + (Forall(int, lambda jj: + (Implies((((i) <= (ii)) and ((ii) < (jj))) and ((jj) < (len((a)))), popcount((a)[ii]) <= popcount((a)[jj])), + [[popcount((a)[jj])]])), + [[popcount((a)[ii])]]))) + Invariant(Forall(int, lambda k: + (Forall(int, lambda k_k: + (Implies(((((0) <= (k)) and ((k) <= (i))) and ((i) < (k_k)) and (k_k) < (len((a)))), popcount((a)[k]) <= popcount((a)[k_k])), + [[popcount((a)[k_k])]])), + [[popcount((a)[k])]]))) # invariants-end - d_7_j_ : int = 0 - while (d_7_j_) < (d_2_i_): + j : int = 0 + while (j) < (i): # invariants-start Invariant(Acc(list_pred(a))) Invariant(Forall(int, lambda i : Implies(i >= 0 and i < len(a), a[i] >= 0))) Invariant(Acc(list_pred(a1), 1/2)) Invariant((len(a1)) == (len(a))) - Invariant((((0) < (d_2_i_)) and ((d_2_i_) < (len((a))))) and (((0) <= (d_7_j_)) and ((d_7_j_) <= (d_2_i_)))) - Invariant(Forall(int, lambda d_8_ii_: - (Forall(int, lambda d_9_jj_: - (Implies((((d_2_i_) <= (d_8_ii_)) and ((d_8_ii_) <= (d_9_jj_))) and ((d_9_jj_) < (len((a)))), popcount((a)[d_8_ii_]) <= popcount((a)[d_9_jj_])), - [[popcount((a)[d_9_jj_])]])), - [[popcount((a)[d_8_ii_])]]))) - Invariant(Forall(int, lambda d_10_k_: - (Forall(int, lambda d_11_k_k_: - (Implies(((((0) <= (d_10_k_)) and ((d_10_k_) <= (d_2_i_))) and ((d_2_i_) < (d_11_k_k_))) and ((d_11_k_k_) < (len((a)))), popcount((a)[d_10_k_]) <= popcount((a)[d_11_k_k_])), - [[popcount((a)[d_11_k_k_])]])), - [[popcount((a)[d_10_k_])]]))) - Invariant(Forall(int, lambda d_12_k_: - (Implies(((0) <= (d_12_k_)) and ((d_12_k_) <= (d_7_j_)), popcount((a)[d_12_k_]) <= popcount((a)[d_7_j_])), - [[popcount((a)[d_12_k_])]]))) + Invariant((((0) < (i)) and ((i) < (len((a))))) and (((0) <= (j)) and ((j) <= (i)))) + Invariant(Forall(int, lambda ii: + (Forall(int, lambda jj: + (Implies((((i) <= (ii)) and ((ii) <= (jj))) and ((jj) < (len((a)))), popcount((a)[ii]) <= popcount((a)[jj])), + [[popcount((a)[jj])]])), + [[popcount((a)[ii])]]))) + Invariant(Forall(int, lambda k: + (Forall(int, lambda k_k: + (Implies(((((0) <= (k)) and ((k) <= (i))) and ((i) < (k_k))) and ((k_k) < (len((a)))), popcount((a)[k]) <= popcount((a)[k_k])), + [[popcount((a)[k_k])]])), + [[popcount((a)[k])]]))) + Invariant(Forall(int, lambda k: + (Implies(((0) <= (k)) and ((k) <= (j)), popcount((a)[k]) <= popcount((a)[j])), + [[popcount((a)[k])]]))) # invariants-end - if popcount((a)[d_7_j_]) > popcount((a)[(d_7_j_) + (1)]): - rhs0_ : int = (a)[(d_7_j_) + (1)] - (a)[(d_7_j_) + (1)] = (a)[d_7_j_] - (a)[d_7_j_] = rhs0_ + if popcount((a)[j]) > popcount((a)[(j) + (1)]): + rhs0_ : int = (a)[(j) + (1)] + (a)[(j) + (1)] = (a)[j] + (a)[j] = rhs0_ # assert-start - Assert(popcount((a)[d_7_j_]) <= popcount((a)[(d_7_j_) + (1)])) + Assert(popcount((a)[j]) <= popcount((a)[(j) + (1)])) # assert-end - d_7_j_ = (d_7_j_) + (1) - d_2_i_ = (d_2_i_) - (1) + j = (j) + (1) + i = (i) - (1) return a # impl-end diff --git a/Bench/118-get_closest_vowel.py b/Bench/118-get_closest_vowel.py index 9febf47..72f23a0 100644 --- a/Bench/118-get_closest_vowel.py +++ b/Bench/118-get_closest_vowel.py @@ -16,18 +16,18 @@ def IsConsonant(c : int) -> bool : def get__closest__vowel(word : List[int]) -> List[int]: # pre-conditions-start Requires(Acc(list_pred(word))) - Requires(Forall(int, lambda d_0_i_: - not (((0) <= (d_0_i_)) and ((d_0_i_) < (len(word)))) or ((((65) <= ((word)[d_0_i_])) and (((word)[d_0_i_]) <= (90))) or (((97) <= ((word)[d_0_i_])) and (((word)[d_0_i_]) <= (122)))))) + Requires(Forall(int, lambda i: + not (((0) <= (i)) and ((i) < (len(word)))) or ((((65) <= ((word)[i])) and (((word)[i]) <= (90))) or (((97) <= ((word)[i])) and (((word)[i]) <= (122)))))) # pre-conditions-end # post-conditions-start Ensures(Acc(list_pred(word))) Ensures(Acc(list_pred(Result()))) Ensures((len(Result())) <= (1)) Ensures(not ((len(Result())) == (1)) or (IsVowel((Result())[0]))) - Ensures(not ((len(Result())) == (1)) or (Exists(int, lambda d_1_i_: - ((((((1) <= (d_1_i_)) and (((d_1_i_) + (1)) < (len(word)))) and (IsVowel((word)[d_1_i_]))) and (IsConsonant((word)[(d_1_i_) - (1)]))) and (IsConsonant((word)[(d_1_i_) + (1)]))) and ( + Ensures(not ((len(Result())) == (1)) or (Exists(int, lambda i: + ((((((1) <= (i)) and (((i) + (1)) < (len(word)))) and (IsVowel((word)[i]))) and (IsConsonant((word)[(i) - (1)]))) and (IsConsonant((word)[(i) + (1)]))) and ( Forall(int, lambda j: - not (j > d_1_i_ and j <= len(word) - 2) or (((not(IsVowel((word)[j]))) or (not(IsConsonant((word)[j - 1])))) or (not(IsConsonant((word)[j + 1]))))))))) + not (j > i and j <= len(word) - 2) or (((not(IsVowel((word)[j]))) or (not(IsConsonant((word)[j - 1])))) or (not(IsConsonant((word)[j + 1]))))))))) # post-conditions-end # impl-start @@ -35,21 +35,21 @@ def get__closest__vowel(word : List[int]) -> List[int]: if (len(word)) < (3): result = [] return result - d_5_i_ : int = (len(word)) - (2) - while (d_5_i_) > (0): + i : int = (len(word)) - (2) + while (i) > (0): # invariants-start Invariant(Acc(list_pred(word))) Invariant(Acc(list_pred(result))) - Invariant(((0) <= (d_5_i_)) and ((d_5_i_) <= ((len(word)) - (2)))) - Invariant(Forall(int, lambda d_6_j_: - not (((d_5_i_) < (d_6_j_)) and ((d_6_j_) < ((len(word)) - (1)))) or (((not(IsVowel((word)[d_6_j_]))) or (not(IsConsonant((word)[(d_6_j_) - (1)])))) or (not(IsConsonant((word)[(d_6_j_) + (1)])))))) + Invariant(((0) <= (i)) and ((i) <= ((len(word)) - (2)))) Invariant(Forall(int, lambda j: - not (j > d_5_i_ and j <= len(word) - 2) or (((not(IsVowel((word)[j]))) or (not(IsConsonant((word)[j - 1])))) or (not(IsConsonant((word)[j + 1])))))) + not (((i) < (j)) and ((j) < ((len(word)) - (1)))) or (((not(IsVowel((word)[j]))) or (not(IsConsonant((word)[(j) - (1)])))) or (not(IsConsonant((word)[(j) + (1)])))))) + Invariant(Forall(int, lambda j: + not (j > i and j <= len(word) - 2) or (((not(IsVowel((word)[j]))) or (not(IsConsonant((word)[j - 1])))) or (not(IsConsonant((word)[j + 1])))))) # invariants-end - if ((IsVowel((word)[d_5_i_])) and (IsConsonant((word)[(d_5_i_) - (1)]))) and (IsConsonant((word)[(d_5_i_) + (1)])): - result = [(word)[d_5_i_]] + if ((IsVowel((word)[i])) and (IsConsonant((word)[(i) - (1)]))) and (IsConsonant((word)[(i) + (1)])): + result = [(word)[i]] return result - d_5_i_ = (d_5_i_) - (1) + i = (i) - (1) result = [] return result # impl-end diff --git a/Bench/119-match_parens.py b/Bench/119-match_parens.py index 82e79d3..ebcd683 100644 --- a/Bench/119-match_parens.py +++ b/Bench/119-match_parens.py @@ -18,20 +18,20 @@ def CalBal(s : List[int], i : int, j : int, acc : int) -> int: def checkFixed(s1 : List[int], s2 : List[int]) -> bool: # pre-conditions-start Requires(Acc(list_pred(s1))) - Requires(Forall(int, lambda d_0_i_: - not (((d_0_i_) >= (0)) and ((d_0_i_) < (len(s1)))) or ((((s1)[d_0_i_]) == (0)) or (((s1)[d_0_i_]) == (1))))) + Requires(Forall(int, lambda i: + not (((i) >= (0)) and ((i) < (len(s1)))) or ((((s1)[i]) == (0)) or (((s1)[i]) == (1))))) Requires(Acc(list_pred(s2))) - Requires(Forall(int, lambda d_0_i_: - not (((d_0_i_) >= (0)) and ((d_0_i_) < (len(s2)))) or ((((s2)[d_0_i_]) == (0)) or (((s2)[d_0_i_]) == (1))))) + Requires(Forall(int, lambda i: + not (((i) >= (0)) and ((i) < (len(s2)))) or ((((s2)[i]) == (0)) or (((s2)[i]) == (1))))) # pre-conditions-end # post-conditions-start Ensures(Acc(list_pred(s1))) - Ensures(Forall(int, lambda d_0_i_: - not (((d_0_i_) >= (0)) and ((d_0_i_) < (len(s1)))) or ((((s1)[d_0_i_]) == (0)) or (((s1)[d_0_i_]) == (1))))) + Ensures(Forall(int, lambda i: + not (((i) >= (0)) and ((i) < (len(s1)))) or ((((s1)[i]) == (0)) or (((s1)[i]) == (1))))) Ensures(Acc(list_pred(s2))) - Ensures(Forall(int, lambda d_0_i_: - not (((d_0_i_) >= (0)) and ((d_0_i_) < (len(s2)))) or ((((s2)[d_0_i_]) == (0)) or (((s2)[d_0_i_]) == (1))))) + Ensures(Forall(int, lambda i: + not (((i) >= (0)) and ((i) < (len(s2)))) or ((((s2)[i]) == (0)) or (((s2)[i]) == (1))))) Ensures(Implies(Result(), Forall(int, lambda x: (Implies(x >= 0 and x <= len(s1), CalBal(s1, 0, x, 0) >= 0))))) Ensures(Implies(Result(), Forall(int, lambda x: (Implies(x >= 0 and x <= len(s2), CalBal(s1, 0, len(s1), 0) + CalBal(s2, 0, x, 0) >= 0))))) @@ -48,8 +48,8 @@ def checkFixed(s1 : List[int], s2 : List[int]) -> bool: # invariants-start Invariant(Acc(list_pred(s1), 1/2)) Invariant(0 <= i and i <= len(s1)) - Invariant(Forall(int, lambda d_0_i_: - not (((d_0_i_) >= (0)) and ((d_0_i_) < (len(s1)))) or ((((s1)[d_0_i_]) == (0)) or (((s1)[d_0_i_]) == (1))))) + Invariant(Forall(int, lambda i: + not (((i) >= (0)) and ((i) < (len(s1)))) or ((((s1)[i]) == (0)) or (((s1)[i]) == (1))))) Invariant(Forall(int, lambda x : (Implies(x >= 0 and x < len(s1), CalBal(s1, 0, x + 1, 0) == CalBal(s1, 0, x, 0) + (1 if s1[x] == 0 else -1)), [[CalBal(s1, 0, x + 1, 0)]]))) Invariant(bal == CalBal(s1, 0, i, 0)) Invariant(bal >= 0) @@ -77,8 +77,8 @@ def checkFixed(s1 : List[int], s2 : List[int]) -> bool: Invariant(Acc(list_pred(s1), 1/2)) Invariant(Acc(list_pred(s2), 1/2)) Invariant(0 <= i and i <= len(s2)) - Invariant(Forall(int, lambda d_0_i_: - not (((d_0_i_) >= (0)) and ((d_0_i_) < (len(s2)))) or ((((s2)[d_0_i_]) == (0)) or (((s2)[d_0_i_]) == (1))))) + Invariant(Forall(int, lambda i: + not (((i) >= (0)) and ((i) < (len(s2)))) or ((((s2)[i]) == (0)) or (((s2)[i]) == (1))))) Invariant(Forall(int, lambda x: (Implies(x >= 0 and x < len(s1), CalBal(s1, 0, x, 0) >= 0), [[CalBal(s1, 0, x, 0) >= 0]]))) Invariant(Forall(int, lambda x : (Implies(x >= 0 and x < len(s2), CalBal(s2, 0, x + 1, 0) == CalBal(s2, 0, x, 0) + (1 if s2[x] == 0 else -1)), [[CalBal(s2, 0, x + 1, 0)]]))) Invariant(bal == CalBal(s1, 0, len(s1), 0) + CalBal(s2, 0, i, 0)) diff --git a/Bench/121-solution.py b/Bench/121-solution.py index a20fb51..02a8b77 100644 --- a/Bench/121-solution.py +++ b/Bench/121-solution.py @@ -26,14 +26,14 @@ def add(v : List[int]) -> int: # impl-start r : int = 0 - d_2_k_ : int = 0 - while (d_2_k_) < (len(v)): + k : int = 0 + while (k) < (len(v)): # invariants-start Invariant(Acc(list_pred(v))) - Invariant(((0) <= (d_2_k_)) and ((d_2_k_) <= (len(v)))) - Invariant((r) == (psum(0, d_2_k_ - 1, v))) + Invariant(((0) <= (k)) and ((k) <= (len(v)))) + Invariant((r) == (psum(0, k - 1, v))) # invariants-end - r = (r) + (((v)[d_2_k_] if ((((d_2_k_) % 2) == 0) and ((v)[d_2_k_] % 2 == 1)) else 0)) - d_2_k_ = (d_2_k_) + (1) + r = (r) + (((v)[k] if ((((k) % 2) == 0) and ((v)[k] % 2 == 1)) else 0)) + k = (k) + (1) return r # impl-end diff --git a/Bench/122-add_elements.py b/Bench/122-add_elements.py index 3aaa71a..c4f9553 100644 --- a/Bench/122-add_elements.py +++ b/Bench/122-add_elements.py @@ -28,20 +28,20 @@ def SumElementsWithAtMostTwoDigits(lst : List[int], k : int) -> int: # impl-start sum : int = 0 - d_3_i_ : int = 0 - while d_3_i_ < k: + i : int = 0 + while i < k: # invariants-start Invariant(Acc(list_pred(lst))) Invariant(1 <= k and k <= len(lst)) - Invariant(((0) <= (d_3_i_)) and ((d_3_i_) <= (len(lst))) and d_3_i_ <= k) - Invariant(Forall(int, lambda d_3_i_ : (Implies(d_3_i_ >= 0 and d_3_i_ < k, sum__chars__rec(0, d_3_i_ + 1, lst) == sum__chars__rec(0, d_3_i_, lst) + ((lst)[d_3_i_] if (lst)[d_3_i_] < 100 else 0)), [[sum__chars__rec(0, d_3_i_ + 1, lst)]]))) - Invariant((sum) == (sum__chars__rec(0, d_3_i_, lst))) + Invariant(((0) <= (i)) and ((i) <= (len(lst))) and i <= k) + Invariant(Forall(int, lambda i : (Implies(i >= 0 and i < k, sum__chars__rec(0, i + 1, lst) == sum__chars__rec(0, i, lst) + ((lst)[i] if (lst)[i] < 100 else 0)), [[sum__chars__rec(0, i + 1, lst)]]))) + Invariant((sum) == (sum__chars__rec(0, i, lst))) # invariants-end # assert-start - Assert(sum__chars__rec(0, d_3_i_ + 1, lst) == sum__chars__rec(0, d_3_i_, lst) + ((lst)[d_3_i_] if (lst)[d_3_i_] < 100 else 0)) + Assert(sum__chars__rec(0, i + 1, lst) == sum__chars__rec(0, i, lst) + ((lst)[i] if (lst)[i] < 100 else 0)) # assert-end - if (lst)[d_3_i_] < 100: - sum = (sum) + ((lst)[d_3_i_]) - d_3_i_ = (d_3_i_) + (1) + if (lst)[i] < 100: + sum = (sum) + ((lst)[i]) + i = (i) + (1) return sum # impl-end diff --git a/Bench/123-get_odd_collatz.py b/Bench/123-get_odd_collatz.py index 75788ca..81f3062 100644 --- a/Bench/123-get_odd_collatz.py +++ b/Bench/123-get_odd_collatz.py @@ -50,13 +50,13 @@ def next__odd__collatz__iter(n : int) -> int: next : int = n if ((next % 2)) == (1): next = ((3) * (next)) + (1) - d_0_start_ : int = next + start : int = next while ((next % 2)) == (0): # invariants-start Invariant((next) > (0)) Invariant(not (((next % 2)) == (0)) or ((next__odd__collatz(next)) == (next__odd__collatz(n)))) - Invariant(not (((next % 2)) == (0)) or ((iterate__to__odd(next)) == (iterate__to__odd(d_0_start_)))) - Invariant(not (((next % 2)) == (1)) or ((next) == (iterate__to__odd(d_0_start_)))) + Invariant(not (((next % 2)) == (0)) or ((iterate__to__odd(next)) == (iterate__to__odd(start)))) + Invariant(not (((next % 2)) == (1)) or ((next) == (iterate__to__odd(start)))) # invariants-end next = (next // 2) return next @@ -69,42 +69,42 @@ def get__odd__collatz__unsorted(n : int) -> List[int]: # pre-conditions-end # post-conditions-start Ensures(Acc(list_pred(Result()))) - Ensures(Forall(int, lambda d_1_i_: - not (((0) <= (d_1_i_)) and ((d_1_i_) < (len(Result())))) or ((((Result())[d_1_i_] > 0))))) - Ensures(Forall(int, lambda d_1_i_: - not (((0) <= (d_1_i_)) and ((d_1_i_) < (len(Result())))) or ((((Result())[d_1_i_] % 2)) == (1)))) - Ensures(Forall(int, lambda d_2_i_: - not (((1) <= (d_2_i_)) and ((d_2_i_) < (len(Result())))) or (((Result())[d_2_i_]) == (next__odd__collatz((Result())[(d_2_i_) - (1)]))))) + Ensures(Forall(int, lambda i: + not (((0) <= (i)) and ((i) < (len(Result())))) or ((((Result())[i] > 0))))) + Ensures(Forall(int, lambda i: + not (((0) <= (i)) and ((i) < (len(Result())))) or ((((Result())[i] % 2)) == (1)))) + Ensures(Forall(int, lambda i: + not (((1) <= (i)) and ((i) < (len(Result())))) or (((Result())[i]) == (next__odd__collatz((Result())[(i) - (1)]))))) # post-conditions-end # impl-start odd__collatz : List[int] = [] - d_3_cur_ : int = n - if ((d_3_cur_ % 2)) == (0): - d_3_cur_ = next__odd__collatz__iter(d_3_cur_) - odd__collatz = [d_3_cur_] + cur : int = n + if ((cur % 2)) == (0): + cur = next__odd__collatz__iter(cur) + odd__collatz = [cur] # assert-start Assert(len(odd__collatz) == 1) - Assert(Forall(int, lambda d_5_i_: - (not (((1) <= (d_5_i_)) and ((d_5_i_) < (len(odd__collatz))))))) - Assert(Forall(int, lambda d_5_i_: - (not (((1) <= (d_5_i_)) and ((d_5_i_) < (len(odd__collatz)))) or (((odd__collatz)[d_5_i_]) == (next__odd__collatz((odd__collatz)[(d_5_i_) - (1)]))), [[next__odd__collatz((odd__collatz)[(d_5_i_) - (1)])]]))) + Assert(Forall(int, lambda i: + (not (((1) <= (i)) and ((i) < (len(odd__collatz))))))) + Assert(Forall(int, lambda i: + (not (((1) <= (i)) and ((i) < (len(odd__collatz)))) or (((odd__collatz)[i]) == (next__odd__collatz((odd__collatz)[(i) - (1)]))), [[next__odd__collatz((odd__collatz)[(i) - (1)])]]))) # assert-end while ((odd__collatz)[(len(odd__collatz)) - (1)]) != (1): # invariants-start Invariant(Acc(list_pred(odd__collatz))) - Invariant((d_3_cur_) > (0)) + Invariant((cur) > (0)) Invariant((len(odd__collatz)) > (0)) - Invariant(Forall(int, lambda d_4_i_: - (not (((0) <= (d_4_i_)) and ((d_4_i_) < (len(odd__collatz)))) or ((((odd__collatz)[d_4_i_] > 0)))))) - Invariant(Forall(int, lambda d_4_i_: - (not (((0) <= (d_4_i_)) and ((d_4_i_) < (len(odd__collatz)))) or ((((odd__collatz)[d_4_i_] % 2)) == (1))))) - Invariant(Forall(int, lambda d_5_i_: - (not (((1) <= (d_5_i_)) and ((d_5_i_) < (len(odd__collatz)))) or (((odd__collatz)[d_5_i_]) == (next__odd__collatz((odd__collatz)[(d_5_i_) - (1)]))), [[next__odd__collatz((odd__collatz)[(d_5_i_) - (1)])]]))) + Invariant(Forall(int, lambda i: + (not (((0) <= (i)) and ((i) < (len(odd__collatz)))) or ((((odd__collatz)[i] > 0)))))) + Invariant(Forall(int, lambda i: + (not (((0) <= (i)) and ((i) < (len(odd__collatz)))) or ((((odd__collatz)[i] % 2)) == (1))))) + Invariant(Forall(int, lambda i: + (not (((1) <= (i)) and ((i) < (len(odd__collatz)))) or (((odd__collatz)[i]) == (next__odd__collatz((odd__collatz)[(i) - (1)]))), [[next__odd__collatz((odd__collatz)[(i) - (1)])]]))) # invariants-end odd__collatz = (odd__collatz) + [next__odd__collatz__iter((odd__collatz)[(len(odd__collatz)) - (1)])] # assert-start - Assert(Forall(int, lambda d_5_i_: - (not (((1) <= (d_5_i_)) and ((d_5_i_) < (len(odd__collatz)))) or (((odd__collatz)[d_5_i_]) == (next__odd__collatz((odd__collatz)[(d_5_i_) - (1)]))), [[next__odd__collatz((odd__collatz)[(d_5_i_) - (1)])]]))) + Assert(Forall(int, lambda i: + (not (((1) <= (i)) and ((i) < (len(odd__collatz)))) or (((odd__collatz)[i]) == (next__odd__collatz((odd__collatz)[(i) - (1)]))), [[next__odd__collatz((odd__collatz)[(i) - (1)])]]))) # assert-end return odd__collatz # impl-end @@ -117,69 +117,69 @@ def get__odd__collatz(n : int) -> List[int]: # pre-conditions-end # post-conditions-start Ensures(Acc(list_pred(Result()))) - Ensures(Forall(int, lambda d_6_i_: - Forall(int, lambda d_7_j_: - not ((((0) <= (d_6_i_)) and ((d_6_i_) < (d_7_j_))) and ((d_7_j_) < (len(Result())))) or (((Result())[d_6_i_]) <= ((Result())[d_7_j_]))))) - Ensures(Forall(int, lambda d_8_i_: - not (((0) <= (d_8_i_)) and ((d_8_i_) < (len(Result())))) or ((((Result())[d_8_i_] % 2)) == (1)))) + Ensures(Forall(int, lambda i: + Forall(int, lambda j: + not ((((0) <= (i)) and ((i) < (j))) and ((j) < (len(Result())))) or (((Result())[i]) <= ((Result())[j]))))) + Ensures(Forall(int, lambda i: + not (((0) <= (i)) and ((i) < (len(Result())))) or ((((Result())[i] % 2)) == (1)))) # post-conditions-end # impl-start sorted : List[int] = [] sorted = get__odd__collatz__unsorted(n) - d_12_unsorted_ : List[int] = list(sorted) - d_9_i_ : int = 0 - while (d_9_i_) < (len(sorted)): + unsorted : List[int] = list(sorted) + i : int = 0 + while (i) < (len(sorted)): # invariants-start Invariant(Acc(list_pred(sorted))) - Invariant(Acc(list_pred(d_12_unsorted_))) - Invariant(((0) <= (d_9_i_)) and ((d_9_i_) <= (len(sorted)))) - Invariant(Forall(int, lambda d_8_i_: - not (((0) <= (d_8_i_)) and ((d_8_i_) < (len(sorted)))) or ((((sorted)[d_8_i_] % 2)) == (1)))) - Invariant((len(sorted)) == (len(d_12_unsorted_))) - Invariant(Forall(int, lambda d_10_j_: - (Forall(int, lambda d_11_k_: - (not ((((0) <= (d_10_j_)) and ((d_10_j_) < (d_11_k_))) and ((d_11_k_) < (d_9_i_))) or (((sorted)[d_10_j_]) <= ((sorted)[d_11_k_])), - [[(sorted)[d_11_k_]]])), - [[sorted[d_10_j_]]]))) - Invariant(Forall(int, lambda d_12_j_: - (not ((((0) <= (d_12_j_)) and ((d_12_j_) < (d_9_i_)))) or - (Forall(int, lambda d_13_k_: - (not ((((d_9_i_) <= (d_13_k_)) and ((d_13_k_) < (len(sorted))))) or - (((sorted)[d_12_j_]) <= ((sorted)[d_13_k_])), [[sorted[d_13_k_]]]))), [[(sorted)[d_12_j_]]]))) + Invariant(Acc(list_pred(unsorted))) + Invariant(((0) <= (i)) and ((i) <= (len(sorted)))) + Invariant(Forall(int, lambda i: + not (((0) <= (i)) and ((i) < (len(sorted)))) or ((((sorted)[i] % 2)) == (1)))) + Invariant((len(sorted)) == (len(unsorted))) + Invariant(Forall(int, lambda j: + (Forall(int, lambda k: + (not ((((0) <= (j)) and ((j) < (k))) and ((k) < (i))) or (((sorted)[j]) <= ((sorted)[k])), + [[(sorted)[k]]])), + [[sorted[j]]]))) + Invariant(Forall(int, lambda j: + (not ((((0) <= (j)) and ((j) < (i)))) or + (Forall(int, lambda k: + (not ((((i) <= (k)) and ((k) < (len(sorted))))) or + (((sorted)[j]) <= ((sorted)[k])), [[sorted[k]]]))), [[(sorted)[j]]]))) # invariants-end - d_15_minIndex_ : int = d_9_i_ - d_16_j_ : int = (d_9_i_) + (1) - while (d_16_j_) < (len(sorted)): + minIndex : int = i + j : int = (i) + (1) + while (j) < (len(sorted)): # invariants-start Invariant(Acc(list_pred(sorted))) - Invariant(Acc(list_pred(d_12_unsorted_))) - Invariant((len(sorted)) == (len(d_12_unsorted_))) - Invariant(((0) <= (d_9_i_)) and ((d_9_i_) < (len(sorted)))) - Invariant((((d_9_i_) <= (d_15_minIndex_)) and ((d_15_minIndex_) < (d_16_j_))) and ((d_16_j_) <= (len(sorted)))) - Invariant(Forall(int, lambda d_8_i_: - not (((0) <= (d_8_i_)) and ((d_8_i_) < (len(sorted)))) or ((((sorted)[d_8_i_] % 2)) == (1)))) - Invariant(Forall(int, lambda d_10_j_: - (Forall(int, lambda d_11_k_: - (not ((((0) <= (d_10_j_)) and ((d_10_j_) < (d_11_k_))) and ((d_11_k_) < (d_9_i_))) or (((sorted)[d_10_j_]) <= ((sorted)[d_11_k_])), - [[(sorted)[d_11_k_]]])), - [[sorted[d_10_j_]]]))) - Invariant(Forall(int, lambda d_12_j_: - (not ((((0) <= (d_12_j_)) and ((d_12_j_) < (d_9_i_)))) or - (Forall(int, lambda d_13_k_: - (not ((((d_9_i_) <= (d_13_k_)) and ((d_13_k_) < (len(sorted))))) or - (((sorted)[d_12_j_]) <= ((sorted)[d_13_k_])), [[sorted[d_13_k_]]]))), [[(sorted)[d_12_j_]]]))) - Invariant(Forall(int, lambda d_17_k_: - (not (((d_9_i_) <= (d_17_k_)) and ((d_17_k_) < (d_16_j_))) or (((sorted)[d_15_minIndex_]) <= ((sorted)[d_17_k_])), [[(sorted)[d_17_k_]]]))) + Invariant(Acc(list_pred(unsorted))) + Invariant((len(sorted)) == (len(unsorted))) + Invariant(((0) <= (i)) and ((i) < (len(sorted)))) + Invariant((((i) <= (minIndex)) and ((minIndex) < (j))) and ((j) <= (len(sorted)))) + Invariant(Forall(int, lambda i: + not (((0) <= (i)) and ((i) < (len(sorted)))) or ((((sorted)[i] % 2)) == (1)))) + Invariant(Forall(int, lambda j: + (Forall(int, lambda k: + (not ((((0) <= (j)) and ((j) < (k))) and ((k) < (i))) or (((sorted)[j]) <= ((sorted)[k])), + [[(sorted)[k]]])), + [[sorted[j]]]))) + Invariant(Forall(int, lambda j: + (not ((((0) <= (j)) and ((j) < (i)))) or + (Forall(int, lambda k: + (not ((((i) <= (k)) and ((k) < (len(sorted))))) or + (((sorted)[j]) <= ((sorted)[k])), [[sorted[k]]]))), [[(sorted)[j]]]))) + Invariant(Forall(int, lambda k: + (not (((i) <= (k)) and ((k) < (j))) or (((sorted)[minIndex]) <= ((sorted)[k])), [[(sorted)[k]]]))) # invariants-end - if ((sorted)[d_16_j_]) < ((sorted)[d_15_minIndex_]): - d_15_minIndex_ = d_16_j_ - d_16_j_ = (d_16_j_) + (1) - if (d_15_minIndex_) != (d_9_i_): - rhs0_ : int = (sorted)[d_9_i_] - (sorted)[d_9_i_] = (sorted)[d_15_minIndex_] - (sorted)[d_15_minIndex_] = rhs0_ - d_9_i_ = (d_9_i_) + (1) + if ((sorted)[j]) < ((sorted)[minIndex]): + minIndex = j + j = (j) + (1) + if (minIndex) != (i): + rhs0_ : int = (sorted)[i] + (sorted)[i] = (sorted)[minIndex] + (sorted)[minIndex] = rhs0_ + i = (i) + (1) return sorted # impl-end diff --git a/Bench/126-is_sorted.py b/Bench/126-is_sorted.py index 18bd95d..5cf558a 100644 --- a/Bench/126-is_sorted.py +++ b/Bench/126-is_sorted.py @@ -9,56 +9,56 @@ def is__sorted(a : List[int]) -> bool: # post-conditions-start Ensures(Acc(list_pred(a))) Ensures((Result()) == ( - Forall(int, lambda d_0_i_: - Forall(int, lambda d_1_j_: - not ((((0) <= (d_0_i_)) and ((d_0_i_) <= (d_1_j_))) and ((d_1_j_) < (len(a)))) or ((((a)[d_0_i_]) <= ((a)[d_1_j_]))))) - and (Forall(int, lambda d_2_i_: - not (((0) <= (d_2_i_)) and ((d_2_i_) < (len(a)))) or ((count_set(a, (a)[d_2_i_], 0)) <= (2)))))) + Forall(int, lambda i: + Forall(int, lambda j: + not ((((0) <= (i)) and ((i) <= (j))) and ((j) < (len(a)))) or ((((a)[i]) <= ((a)[j]))))) + and (Forall(int, lambda i: + not (((0) <= (i)) and ((i) < (len(a)))) or ((count_set(a, (a)[i], 0)) <= (2)))))) # post-conditions-end # impl-start if (len(a)) == (0): # assert-start - Assert(Forall(int, lambda d_0_i_: - Forall(int, lambda d_1_j_: - not ((((0) <= (d_0_i_)) and ((d_0_i_) <= (d_1_j_))) and ((d_1_j_) < (len(a)))) or ((((a)[d_0_i_]) <= ((a)[d_1_j_])))))) + Assert(Forall(int, lambda i: + Forall(int, lambda j: + not ((((0) <= (i)) and ((i) <= (j))) and ((j) < (len(a)))) or ((((a)[i]) <= ((a)[j])))))) # assert-end return True - d_3_is__asc_ : bool = True - d_4_i_ : int = 1 - while (d_4_i_) < (len(a)): + is__asc : bool = True + i : int = 1 + while (i) < (len(a)): # invariants-start Invariant(Acc(list_pred(a))) - Invariant(((1) <= (d_4_i_)) and ((d_4_i_) <= (len(a)))) - Invariant((d_3_is__asc_) == (Forall(int, lambda d_5_j_: - Forall(int, lambda d_6_k_: - not ((((0) <= (d_5_j_)) and ((d_5_j_) < (d_6_k_))) and ((d_6_k_) < (d_4_i_))) or (((a)[d_5_j_]) <= ((a)[d_6_k_])))))) + Invariant(((1) <= (i)) and ((i) <= (len(a)))) + Invariant((is__asc) == (Forall(int, lambda j: + Forall(int, lambda k: + not ((((0) <= (j)) and ((j) < (k))) and ((k) < (i))) or (((a)[j]) <= ((a)[k])))))) # invariants-end - if ((a)[(d_4_i_) - (1)]) > ((a)[d_4_i_]): - d_3_is__asc_ = False - d_4_i_ = (d_4_i_) + (1) - if not(d_3_is__asc_): + if ((a)[(i) - (1)]) > ((a)[i]): + is__asc = False + i = (i) + (1) + if not(is__asc): return False - d_4_i_ = 0 - d_7_has__no__more__that__2_ : bool = True - while (d_4_i_) < (len(a)): + i = 0 + has__no__more__that__2 : bool = True + while (i) < (len(a)): # invariants-start Invariant(Acc(list_pred(a))) - Invariant(((0) <= (d_4_i_)) and ((d_4_i_) <= (len(a)))) - Invariant((d_3_is__asc_) == - (Forall(int, lambda d_5_j_: - Forall(int, lambda d_6_k_: - not ((((0) <= (d_5_j_)) and ((d_5_j_) < (d_6_k_))) and ((d_6_k_) < (len(a)))) or (((a)[d_5_j_]) <= ((a)[d_6_k_])))))) - Invariant((d_7_has__no__more__that__2_) == (Forall(int, lambda d_8_j_: - not (((0) <= (d_8_j_)) and ((d_8_j_) < (d_4_i_))) or ((count_set(a, (a)[d_8_j_], 0)) <= (2))) and - (Forall(int, lambda d_5_j_: - Forall(int, lambda d_6_k_: - not ((((0) <= (d_5_j_)) and ((d_5_j_) < (d_6_k_))) and ((d_6_k_) < (len(a)))) or (((a)[d_5_j_]) <= ((a)[d_6_k_]))))))) + Invariant(((0) <= (i)) and ((i) <= (len(a)))) + Invariant((is__asc) == + (Forall(int, lambda j: + Forall(int, lambda k: + not ((((0) <= (j)) and ((j) < (k))) and ((k) < (len(a)))) or (((a)[j]) <= ((a)[k])))))) + Invariant((has__no__more__that__2) == (Forall(int, lambda j: + not (((0) <= (j)) and ((j) < (i))) or ((count_set(a, (a)[j], 0)) <= (2))) and + (Forall(int, lambda j: + Forall(int, lambda k: + not ((((0) <= (j)) and ((j) < (k))) and ((k) < (len(a)))) or (((a)[j]) <= ((a)[k]))))))) # invariants-end - d_9_count_ : int = count_set(a, (a)[d_4_i_], 0) - if (d_9_count_) > (2): - d_7_has__no__more__that__2_ = False - d_4_i_ = (d_4_i_) + (1) - f : bool = d_7_has__no__more__that__2_ + count : int = count_set(a, (a)[i], 0) + if (count) > (2): + has__no__more__that__2 = False + i = (i) + (1) + f : bool = has__no__more__that__2 return f # impl-end diff --git a/Bench/127-intersection.py b/Bench/127-intersection.py index e389ed0..eb6d951 100644 --- a/Bench/127-intersection.py +++ b/Bench/127-intersection.py @@ -5,8 +5,8 @@ @Pure def IsPrime(n : int) -> bool : # pure-start - return ((n) > (1)) and (Forall(int, lambda d_0_k_: - not (((2) <= (d_0_k_)) and ((d_0_k_) < (n))) or (((n % d_0_k_)) != (0)))) + return ((n) > (1)) and (Forall(int, lambda k: + not (((2) <= (k)) and ((k) < (n))) or (((n % k)) != (0)))) # pure-end #use-as-unpure @@ -39,11 +39,11 @@ def Intersection(start1 : int, end1 : int, start2 : int, end2 : int) -> str: # post-conditions-end # impl-start - d_1_intersectionStart_ : int = max(start1, start2) - d_2_intersectionEnd_ : int = min(end1, end2) - if (d_1_intersectionStart_) <= (d_2_intersectionEnd_): - d_3_length_ : int = ((d_2_intersectionEnd_) - (d_1_intersectionStart_)) + (1) - if IsPrime(d_3_length_): + intersectionStart : int = max(start1, start2) + intersectionEnd : int = min(end1, end2) + if (intersectionStart) <= (intersectionEnd): + length : int = ((intersectionEnd) - (intersectionStart)) + (1) + if IsPrime(length): return "YES" return "NO" # impl-end diff --git a/Bench/128-prod_signs.py b/Bench/128-prod_signs.py index f75f548..c259203 100644 --- a/Bench/128-prod_signs.py +++ b/Bench/128-prod_signs.py @@ -52,38 +52,38 @@ def prod__signs(numbers : List[int]) -> int: # impl-start s : int = 0 - d_3_i_ : int = 0 - while (d_3_i_) < (len(numbers)): + i : int = 0 + while (i) < (len(numbers)): # invariants-start Invariant(Acc(list_pred(numbers))) - Invariant(((0) <= (d_3_i_)) and ((d_3_i_) <= (len(numbers)))) + Invariant(((0) <= (i)) and ((i) <= (len(numbers)))) Invariant(Forall(int, lambda x : (Implies(0 <= x and x < len(numbers), sum__abs(0, x + 1, numbers) == sum__abs(0, x, numbers) + abs(numbers[x])), [[sum__abs(0, x + 1, numbers)]]))) - Invariant((s) == (sum__abs(0, d_3_i_, numbers))) + Invariant((s) == (sum__abs(0, i, numbers))) Invariant(s >= 0) # invariants-end # assert-start - Assert(sum__abs(0, d_3_i_ + 1, numbers) == sum__abs(0, d_3_i_, numbers) + abs(numbers[d_3_i_])) + Assert(sum__abs(0, i + 1, numbers) == sum__abs(0, i, numbers) + abs(numbers[i])) # assert-end - s = (s) + (abs((numbers)[d_3_i_])) - d_3_i_ = (d_3_i_) + (1) - d_3_i_ = 0 - d_4_cnt_ : int = 0 - while (d_3_i_) < (len(numbers)): + s = (s) + (abs((numbers)[i])) + i = (i) + (1) + i = 0 + cnt : int = 0 + while (i) < (len(numbers)): # invariants-start Invariant(Acc(list_pred(numbers))) Invariant(s == sum__abs(0, len(numbers), numbers)) Invariant(s >= 0) - Invariant(((0) <= (d_3_i_)) and ((d_3_i_) <= (len(numbers)))) + Invariant(((0) <= (i)) and ((i) <= (len(numbers)))) Invariant(Forall(int, lambda x : Implies(0 <= x and x < len(numbers), count_negatives(0, x + 1, numbers) == count_negatives(0, x, numbers) + (1 if numbers[x] < 0 else 0)))) - Invariant((d_4_cnt_) == (count_negatives(0, d_3_i_, numbers))) + Invariant((cnt) == (count_negatives(0, i, numbers))) # invariants-end - if ((numbers)[d_3_i_]) < (0): - d_4_cnt_ = (d_4_cnt_) + (1) - d_3_i_ = (d_3_i_) + (1) - if ((d_4_cnt_ % 2)) == (1): + if ((numbers)[i]) < (0): + cnt = (cnt) + (1) + i = (i) + (1) + if ((cnt % 2)) == (1): s = (0) - (s) return s # impl-end diff --git a/Bench/133-sum-squares.py b/Bench/133-sum-squares.py index c5c9d7a..3358b20 100644 --- a/Bench/133-sum-squares.py +++ b/Bench/133-sum-squares.py @@ -26,15 +26,15 @@ def sum__squares(lst : List[int]) -> int: # impl-start r : int = 0 - d_2_k_ : int = 0 - while (d_2_k_) < (len(lst)): + k : int = 0 + while (k) < (len(lst)): # invariants-start Invariant(Acc(list_pred(lst))) - Invariant(((0) <= (d_2_k_)) and ((d_2_k_) <= (len(lst)))) - Invariant((r) == (psum(0, d_2_k_, lst))) - Invariant(Forall(int, lambda d_2_i_: (not (((0) <= (d_2_i_)) and ((d_2_i_) < (len(lst)))) or ((psum(0, d_2_i_ + 1, lst)) == (psum(0, d_2_i_, lst) + lst[d_2_i_] * lst[d_2_i_])), [[psum(0, d_2_i_ + 1, lst)]]))) + Invariant(((0) <= (k)) and ((k) <= (len(lst)))) + Invariant((r) == (psum(0, k, lst))) + Invariant(Forall(int, lambda i: (not (((0) <= (i)) and ((i) < (len(lst)))) or ((psum(0, i + 1, lst)) == (psum(0, i, lst) + lst[i] * lst[i])), [[psum(0, i + 1, lst)]]))) # invariants-end - r = (r) + ((lst)[d_2_k_]) * ((lst)[d_2_k_]) - d_2_k_ = (d_2_k_) + (1) + r = (r) + ((lst)[k]) * ((lst)[k]) + k = (k) + (1) return r # impl-end diff --git a/Bench/135_can_arrange.py b/Bench/135_can_arrange.py index 9f757c5..1e7cc46 100644 --- a/Bench/135_can_arrange.py +++ b/Bench/135_can_arrange.py @@ -5,35 +5,35 @@ def can__arrange(arr : List[int]) -> int: # pre-conditions-start Requires(Acc(list_pred(arr))) Requires((len(arr)) > (0)) - Requires(Forall(int, lambda d_0_i_: - Forall(int, lambda d_1_j_: - not ((((0) <= (d_0_i_)) and ((d_0_i_) < (d_1_j_))) and ((d_1_j_) < (len(arr)))) or (((arr)[d_0_i_]) != ((arr)[d_1_j_]))))) + Requires(Forall(int, lambda i: + Forall(int, lambda j: + not ((((0) <= (i)) and ((i) < (j))) and ((j) < (len(arr)))) or (((arr)[i]) != ((arr)[j]))))) # pre-conditions-end # post-conditions-start Ensures(Acc(list_pred(arr))) - Ensures(not ((Result()) == (-1)) or (Forall(int, lambda d_2_i_: - not (((1) <= (d_2_i_)) and ((d_2_i_) < (len(arr)))) or (((arr)[d_2_i_]) >= ((arr)[(d_2_i_) - (1)]))))) + Ensures(not ((Result()) == (-1)) or (Forall(int, lambda i: + not (((1) <= (i)) and ((i) < (len(arr)))) or (((arr)[i]) >= ((arr)[(i) - (1)]))))) Ensures(not ((Result()) >= (0)) or ((((1) <= (Result())) and ((Result()) < (len(arr)))) and (((arr)[Result()]) < ((arr)[(Result()) - (1)])))) - Ensures(not ((Result()) >= (0)) or (Forall(int, lambda d_3_i_: - not (((Result()) < (d_3_i_)) and ((d_3_i_) < (len(arr)))) or (((arr)[d_3_i_]) >= ((arr)[(d_3_i_) - (1)]))))) + Ensures(not ((Result()) >= (0)) or (Forall(int, lambda i: + not (((Result()) < (i)) and ((i) < (len(arr)))) or (((arr)[i]) >= ((arr)[(i) - (1)]))))) # post-conditions-end # impl-start - d_4_i_ : int = 1 + i : int = 1 pos : int = -1 - while (d_4_i_) < (len(arr)): + while (i) < (len(arr)): # invariants-start Invariant(Acc(list_pred(arr))) - Invariant(((1) <= (d_4_i_)) and ((d_4_i_) <= (len(arr)))) - Invariant(not ((pos) == (-1)) or (Forall(int, lambda d_5_j_: - not (((1) <= (d_5_j_)) and ((d_5_j_) < (d_4_i_))) or (((arr)[d_5_j_]) >= ((arr)[(d_5_j_) - (1)]))))) - Invariant(not ((pos) >= (0)) or ((((1) <= (pos)) and ((pos) < (d_4_i_))) and (((arr)[pos]) < ((arr)[(pos) - (1)])))) - Invariant(not ((pos) >= (0)) or (Forall(int, lambda d_6_j_: - not (((pos) < (d_6_j_)) and ((d_6_j_) < (d_4_i_))) or (((arr)[d_6_j_]) >= ((arr)[(d_6_j_) - (1)]))))) + Invariant(((1) <= (i)) and ((i) <= (len(arr)))) + Invariant(not ((pos) == (-1)) or (Forall(int, lambda j: + not (((1) <= (j)) and ((j) < (i))) or (((arr)[j]) >= ((arr)[(j) - (1)]))))) + Invariant(not ((pos) >= (0)) or ((((1) <= (pos)) and ((pos) < (i))) and (((arr)[pos]) < ((arr)[(pos) - (1)])))) + Invariant(not ((pos) >= (0)) or (Forall(int, lambda j: + not (((pos) < (j)) and ((j) < (i))) or (((arr)[j]) >= ((arr)[(j) - (1)]))))) # invariants-end - if ((arr)[d_4_i_]) < ((arr)[(d_4_i_) - (1)]): - pos = d_4_i_ - d_4_i_ = (d_4_i_) + (1) + if ((arr)[i]) < ((arr)[(i) - (1)]): + pos = i + i = (i) + (1) return pos # impl-end diff --git a/Bench/136-largest_smallest_integers.py b/Bench/136-largest_smallest_integers.py index 5f86bbe..2c34a60 100644 --- a/Bench/136-largest_smallest_integers.py +++ b/Bench/136-largest_smallest_integers.py @@ -17,42 +17,42 @@ def largest__smallest__integers(arr : List[int]) -> Tuple[Optional[int], Optiona # pre-conditions-end # post-conditions-start Ensures(Acc(list_pred(arr))) - Ensures(not ((Result()[0]) is None) or (Forall(int, lambda d_0_i_: - not (((0) <= (d_0_i_)) and ((d_0_i_) < (len(arr)))) or (((arr)[d_0_i_]) >= (0))))) + Ensures(not ((Result()[0]) is None) or (Forall(int, lambda i: + not (((0) <= (i)) and ((i) < (len(arr)))) or (((arr)[i]) >= (0))))) Ensures(not ((Result()[0]) is not None) or ((((Result()[0])) in (arr)) and (((Result()[0])) < (0)))) - Ensures(not ((Result()[0]) is not None) or (Forall(int, lambda d_1_i_: - not ((((0) <= (d_1_i_)) and ((d_1_i_) < (len(arr)))) and (((arr)[d_1_i_]) < (0))) or (((arr)[d_1_i_]) <= (getVal(Result()[0])))))) - Ensures(not ((Result()[1]) is None) or (Forall(int, lambda d_2_i_: - not (((0) <= (d_2_i_)) and ((d_2_i_) < (len(arr)))) or (((arr)[d_2_i_]) <= (0))))) + Ensures(not ((Result()[0]) is not None) or (Forall(int, lambda i: + not ((((0) <= (i)) and ((i) < (len(arr)))) and (((arr)[i]) < (0))) or (((arr)[i]) <= (getVal(Result()[0])))))) + Ensures(not ((Result()[1]) is None) or (Forall(int, lambda i: + not (((0) <= (i)) and ((i) < (len(arr)))) or (((arr)[i]) <= (0))))) Ensures(not ((Result()[1]) is not None) or (((getVal(Result()[1])) in (arr)) and ((getVal(Result()[1])) > (0)))) - Ensures(not ((Result()[1]) is not None) or (Forall(int, lambda d_3_i_: - not ((((0) <= (d_3_i_)) and ((d_3_i_) < (len(arr)))) and (((arr)[d_3_i_]) > (0))) or (((arr)[d_3_i_]) >= (getVal(Result()[1])))))) + Ensures(not ((Result()[1]) is not None) or (Forall(int, lambda i: + not ((((0) <= (i)) and ((i) < (len(arr)))) and (((arr)[i]) > (0))) or (((arr)[i]) >= (getVal(Result()[1])))))) # post-conditions-end # impl-start a : Optional[int] = None b : Optional[int] = None - d_4_i_ = int(0) - while (d_4_i_) < (len(arr)): + i = int(0) + while (i) < (len(arr)): # invariants-start Invariant(Acc(list_pred(arr))) - Invariant(((0) <= (d_4_i_)) and ((d_4_i_) <= (len(arr)))) - Invariant(not ((a) is None) or (Forall(int, lambda d_5_j_: - not (((0) <= (d_5_j_)) and ((d_5_j_) < (d_4_i_))) or (((arr)[d_5_j_]) >= (0))))) + Invariant(((0) <= (i)) and ((i) <= (len(arr)))) + Invariant(not ((a) is None) or (Forall(int, lambda j: + not (((0) <= (j)) and ((j) < (i))) or (((arr)[j]) >= (0))))) Invariant(Old(a) is None or (Old(a) is not None and Old(a) <= a)) - Invariant(not ((a) is not None) or ((Exists(int, lambda x: x >= 0 and x < d_4_i_ and arr[x] == a)) and ((a) < (0)))) - Invariant(not ((a) is not None) or (Forall(int, lambda d_6_j_: - not ((((0) <= (d_6_j_)) and ((d_6_j_) < (d_4_i_))) and (((arr)[d_6_j_]) < (0))) or (((arr)[d_6_j_]) <= (getVal(a)))))) - Invariant(not ((b) is None) or (Forall(int, lambda d_7_j_: - not (((0) <= (d_7_j_)) and ((d_7_j_) < (d_4_i_))) or (((arr)[d_7_j_]) <= (0))))) + Invariant(not ((a) is not None) or ((Exists(int, lambda x: x >= 0 and x < i and arr[x] == a)) and ((a) < (0)))) + Invariant(not ((a) is not None) or (Forall(int, lambda j: + not ((((0) <= (j)) and ((j) < (i))) and (((arr)[j]) < (0))) or (((arr)[j]) <= (getVal(a)))))) + Invariant(not ((b) is None) or (Forall(int, lambda j: + not (((0) <= (j)) and ((j) < (i))) or (((arr)[j]) <= (0))))) Invariant(not ((b) is not None) or (((getVal(b)) in (arr)) and ((getVal(b)) > (0)))) - Invariant(not ((b) is not None) or (Forall(int, lambda d_8_j_: - not ((((0) <= (d_8_j_)) and ((d_8_j_) < (d_4_i_))) and (((arr)[d_8_j_]) > (0))) or (((arr)[d_8_j_]) >= (getVal(b)))))) + Invariant(not ((b) is not None) or (Forall(int, lambda j: + not ((((0) <= (j)) and ((j) < (i))) and (((arr)[j]) > (0))) or (((arr)[j]) >= (getVal(b)))))) # invariants-end - if (((arr)[d_4_i_]) < (0)) and (((a) is None) or (((arr)[d_4_i_]) >= (a))): - a = ((arr)[d_4_i_]) - if (((arr)[d_4_i_]) > (0)) and (((b) is None) or (((arr)[d_4_i_]) <= (getVal(b)))): - b = ((arr)[d_4_i_]) - d_4_i_ = (d_4_i_) + (1) + if (((arr)[i]) < (0)) and (((a) is None) or (((arr)[i]) >= (a))): + a = ((arr)[i]) + if (((arr)[i]) > (0)) and (((b) is None) or (((arr)[i]) <= (getVal(b)))): + b = ((arr)[i]) + i = (i) + (1) return (a, b) # impl-end diff --git a/Bench/139-special_factorial.py b/Bench/139-special_factorial.py index f1722e9..3a222ba 100644 --- a/Bench/139-special_factorial.py +++ b/Bench/139-special_factorial.py @@ -43,18 +43,18 @@ def special__factorial(n : int) -> int: # impl-start result : int = 1 - d_2_fact_ : int = 1 - d_3_i_ : int = 1 - while (d_3_i_) <= (n): + fact : int = 1 + i : int = 1 + while (i) <= (n): # invariants-start - Invariant(((1) <= (d_3_i_)) and ((d_3_i_) <= (n + 1))) - Invariant(Forall(int, lambda d_2_i_: (not (((0) <= (d_2_i_)) and ((d_2_i_) <= (n))) or ((factorial(d_2_i_ + 1)) == (factorial(d_2_i_) * (d_2_i_ + 1))), [[factorial(d_2_i_ + 1)]]))) - Invariant(Forall(int, lambda d_2_i_: (not (((0) <= (d_2_i_)) and ((d_2_i_) <= (n))) or ((special__factorial__rec(d_2_i_ + 1)) == (special__factorial__rec(d_2_i_) * factorial(d_2_i_ + 1))), [[special__factorial__rec(d_2_i_ + 1)]]))) - Invariant((result) == (special__factorial__rec(d_3_i_ - 1))) - Invariant((d_2_fact_) == (factorial(d_3_i_ - 1))) + Invariant(((1) <= (i)) and ((i) <= (n + 1))) + Invariant(Forall(int, lambda i: (not (((0) <= (i)) and ((i) <= (n))) or ((factorial(i + 1)) == (factorial(i) * (i + 1))), [[factorial(i + 1)]]))) + Invariant(Forall(int, lambda i: (not (((0) <= (i)) and ((i) <= (n))) or ((special__factorial__rec(i + 1)) == (special__factorial__rec(i) * factorial(i + 1))), [[special__factorial__rec(i + 1)]]))) + Invariant((result) == (special__factorial__rec(i - 1))) + Invariant((fact) == (factorial(i - 1))) # invariants-end - d_2_fact_ = (d_2_fact_) * (d_3_i_) - result = (result) * (d_2_fact_) - d_3_i_ = (d_3_i_) + (1) + fact = (fact) * (i) + result = (result) * (fact) + i = (i) + (1) return result # impl-end diff --git a/Bench/142-sum_squares.py b/Bench/142-sum_squares.py index 2e4fe05..b39fb1a 100644 --- a/Bench/142-sum_squares.py +++ b/Bench/142-sum_squares.py @@ -38,16 +38,16 @@ def sum__squares(lst : List[int]) -> int: # impl-start r : int = 0 - d_2_k_ : int = 0 - while (d_2_k_) < (len(lst)): + k : int = 0 + while (k) < (len(lst)): # invariants-start Invariant(Acc(list_pred(lst))) - Invariant(((0) <= (d_2_k_)) and ((d_2_k_) <= (len(lst)))) - Invariant(Forall(int, lambda d_2_i_: (not (((0) <= (d_2_i_)) and ((d_2_i_) < (len(lst)))) or - (psum(0, d_2_i_ + 1, lst) == checkVal(lst[d_2_i_]) + psum(0, d_2_i_, lst)), [[psum(0, d_2_i_ + 1, lst)]]))) - Invariant((r) == (psum(0, d_2_k_, lst))) + Invariant(((0) <= (k)) and ((k) <= (len(lst)))) + Invariant(Forall(int, lambda i: (not (((0) <= (i)) and ((i) < (len(lst)))) or + (psum(0, i + 1, lst) == checkVal(lst[i]) + psum(0, i, lst)), [[psum(0, i + 1, lst)]]))) + Invariant((r) == (psum(0, k, lst))) # invariants-end - r = r + checkVal(lst[d_2_k_]) - d_2_k_ = (d_2_k_) + (1) + r = r + checkVal(lst[k]) + k = (k) + (1) return r # impl-end diff --git a/Bench/146_specialFilter.py b/Bench/146_specialFilter.py index 6014d76..a9ebb68 100644 --- a/Bench/146_specialFilter.py +++ b/Bench/146_specialFilter.py @@ -30,33 +30,33 @@ def specialFilter(s : List[int]) -> List[int]: # post-conditions-start Ensures(Acc(list_pred(s))) Ensures(Acc(list_pred(Result()))) - Ensures(Forall(int, lambda d_0_i_: - not (((0) <= (d_0_i_)) and ((d_0_i_) < (len(Result())))) or (((Result())[d_0_i_]) > (10)))) - Ensures(Forall(int, lambda d_2_i_: - not (((0) <= (d_2_i_)) and ((d_2_i_) < (len(Result())))) or ((((first__digit((Result())[d_2_i_]) % 2)) == (1)) and (((last__digit((Result())[d_2_i_]) % 2)) == (1))))) - Ensures(Forall(int, lambda d_5_i_: - not (((0) <= (d_5_i_)) and ((d_5_i_) < (len(Result())))) or - (Exists(int, lambda x: x >= 0 and x < len(s) and s[x] == Result()[d_5_i_])))) + Ensures(Forall(int, lambda i: + not (((0) <= (i)) and ((i) < (len(Result())))) or (((Result())[i]) > (10)))) + Ensures(Forall(int, lambda i: + not (((0) <= (i)) and ((i) < (len(Result())))) or ((((first__digit((Result())[i]) % 2)) == (1)) and (((last__digit((Result())[i]) % 2)) == (1))))) + Ensures(Forall(int, lambda i: + not (((0) <= (i)) and ((i) < (len(Result())))) or + (Exists(int, lambda x: x >= 0 and x < len(s) and s[x] == Result()[i])))) # post-conditions-end # impl-start r : List[int] = [] - d_3_i_ : int = 0 - while (d_3_i_) < (len(s)): + i : int = 0 + while (i) < (len(s)): # invariants-start Invariant(Acc(list_pred(r))) Invariant(Acc(list_pred(s))) - Invariant(((0) <= (d_3_i_)) and ((d_3_i_) <= (len(s)))) - Invariant(Forall(int, lambda d_5_i_: - not (((0) <= (d_5_i_)) and ((d_5_i_) < (len(r)))) or (((r)[d_5_i_]) > (10)))) - Invariant(Forall(int, lambda d_7_i_: - (not (((0) <= (d_7_i_)) and ((d_7_i_) < (len(r)))) or ((((first__digit((r)[d_7_i_]) % 2)) == (1)) and (((last__digit((r)[d_7_i_]) % 2)) == (1))), [[first__digit((r)[d_7_i_])]]))) - Invariant(Forall(int, lambda d_5_i_: - not (((0) <= (d_5_i_)) and ((d_5_i_) < (len(r)))) or - (Exists(int, lambda x: x >= 0 and x < len(s) and s[x] == r[d_5_i_])))) + Invariant(((0) <= (i)) and ((i) <= (len(s)))) + Invariant(Forall(int, lambda i: + not (((0) <= (i)) and ((i) < (len(r)))) or (((r)[i]) > (10)))) + Invariant(Forall(int, lambda i: + (not (((0) <= (i)) and ((i) < (len(r)))) or ((((first__digit((r)[i]) % 2)) == (1)) and (((last__digit((r)[i]) % 2)) == (1))), [[first__digit((r)[i])]]))) + Invariant(Forall(int, lambda i: + not (((0) <= (i)) and ((i) < (len(r)))) or + (Exists(int, lambda x: x >= 0 and x < len(s) and s[x] == r[i])))) # invariants-end - if ((((s)[d_3_i_]) > (10)) and (((last__digit((s)[d_3_i_]) % 2)) == (1))) and (((first__digit((s)[d_3_i_]) % 2)) == (1)): - r = (r) + [(s)[d_3_i_]] - d_3_i_ = (d_3_i_) + (1) + if ((((s)[i]) > (10)) and (((last__digit((s)[i]) % 2)) == (1))) and (((first__digit((s)[i]) % 2)) == (1)): + r = (r) + [(s)[i]] + i = (i) + (1) return r # impl-end diff --git a/Bench/150-x_or_y.py b/Bench/150-x_or_y.py index 5ff9105..40060ff 100644 --- a/Bench/150-x_or_y.py +++ b/Bench/150-x_or_y.py @@ -4,8 +4,8 @@ @Pure def IsPrime(n : int) -> bool : # pure-start - return ((n) > (1)) and (Forall(int, lambda d_0_k_: - not (((2) <= (d_0_k_)) and ((d_0_k_) < (n))) or (((n % d_0_k_)) != (0)))) + return ((n) > (1)) and (Forall(int, lambda k: + not (((2) <= (k)) and ((k) < (n))) or (((n % k)) != (0)))) # pure-end @@ -23,7 +23,7 @@ def x__or__y(n : int, x : int, y : int) -> int: while i < n: # invariants-start Invariant(2 <= i and i <= n) - Invariant(Forall(int, lambda d_0_k_: not (2 <= d_0_k_ and d_0_k_ < i) or (n % d_0_k_ != 0))) + Invariant(Forall(int, lambda k: not (2 <= k and k < i) or (n % k != 0))) # invariants-end if n % i == 0: return y diff --git a/Bench/151-double_the_difference.py b/Bench/151-double_the_difference.py index 9b12989..2d7397b 100644 --- a/Bench/151-double_the_difference.py +++ b/Bench/151-double_the_difference.py @@ -37,16 +37,16 @@ def double__the__difference(lst : List[int]) -> int: # impl-start r : int = 0 - d_3_k_ : int = 0 - while (d_3_k_) < (len(lst)): + k : int = 0 + while (k) < (len(lst)): # invariants-start Invariant(Acc(list_pred(lst))) - Invariant(((0) <= (d_3_k_)) and ((d_3_k_) <= (len(lst)))) - Invariant((r) == (psum(0, d_3_k_, lst))) - Invariant(Forall(int, lambda d_3_i_: (not (((0) <= (d_3_i_)) and ((d_3_i_) < (len(lst)))) or - (psum(0, d_3_i_ + 1, lst) == checkVal(lst[d_3_i_]) + psum(0, d_3_i_, lst)), [[psum(0, d_3_i_ + 1, lst)]]))) + Invariant(((0) <= (k)) and ((k) <= (len(lst)))) + Invariant((r) == (psum(0, k, lst))) + Invariant(Forall(int, lambda i: (not (((0) <= (i)) and ((i) < (len(lst)))) or + (psum(0, i + 1, lst) == checkVal(lst[i]) + psum(0, i, lst)), [[psum(0, i + 1, lst)]]))) # invariants-end - r = (r) + checkVal(((lst)[d_3_k_])) - d_3_k_ = (d_3_k_) + (1) + r = (r) + checkVal(((lst)[k])) + k = (k) + (1) return r # impl-end diff --git a/Bench/152-compare.py b/Bench/152-compare.py index e7ed6cd..876d3d7 100644 --- a/Bench/152-compare.py +++ b/Bench/152-compare.py @@ -13,26 +13,26 @@ def Compare(scores : List[int], guesses : List[int]) -> List[int]: Ensures(Acc(list_pred(Result()))) Ensures((len((Result()))) == (len((scores)))) Ensures((len((scores))) == (len((guesses)))) - Ensures(Forall(int, lambda d_0_i_: - not (((0) <= (d_0_i_)) and ((d_0_i_) < (len((Result()))))) or (((Result())[d_0_i_]) == (abs(((scores)[d_0_i_]) - ((guesses)[d_0_i_])))))) + Ensures(Forall(int, lambda i: + not (((0) <= (i)) and ((i) < (len((Result()))))) or (((Result())[i]) == (abs(((scores)[i]) - ((guesses)[i])))))) # post-conditions-end # impl-start result : List[int] = [int(0)] * len((scores)) - d_1_i_ : int = 0 - while (d_1_i_) < (len((scores))): + i : int = 0 + while (i) < (len((scores))): # invariants-start Invariant(Acc(list_pred(result))) Invariant(Acc(list_pred(guesses))) Invariant(Acc(list_pred(scores))) - Invariant(((0) <= (d_1_i_)) and ((d_1_i_) <= (len((scores))))) + Invariant(((0) <= (i)) and ((i) <= (len((scores))))) Invariant((len((result))) == (len((scores)))) Invariant((len((scores))) == (len((guesses)))) - Invariant(Forall(int, lambda d_2_k_: - not (((0) <= (d_2_k_)) and ((d_2_k_) < (d_1_i_))) or (((result)[d_2_k_]) == (abs(((scores)[d_2_k_]) - ((guesses)[d_2_k_])))))) + Invariant(Forall(int, lambda k: + not (((0) <= (k)) and ((k) < (i))) or (((result)[k]) == (abs(((scores)[k]) - ((guesses)[k])))))) # invariants-end - (result)[(d_1_i_)] = abs(((scores)[d_1_i_]) - ((guesses)[d_1_i_])) - d_1_i_ = (d_1_i_) + (1) + (result)[(i)] = abs(((scores)[i]) - ((guesses)[i])) + i = (i) + (1) return result # impl-end diff --git a/Bench/154-cycpattern_check.py b/Bench/154-cycpattern_check.py index 9584094..650592e 100644 --- a/Bench/154-cycpattern_check.py +++ b/Bench/154-cycpattern_check.py @@ -9,9 +9,9 @@ def IsSubstring(s : List[int], sub : List[int], n : int) -> bool : # pre-conditions-end # pure-start - return ((len(s)) >= (len(sub))) and (Exists(int, lambda d_0_i_: - (((0) <= (d_0_i_)) and ((d_0_i_) < 1 + ((len(s)) - (len(sub))))) and ( - Forall(int, lambda y: (Implies(y >= 0 and y < len(sub), sub[(n + y) % len(sub)] == s[d_0_i_ + y]), [[sub[(n + y) % len(sub)] == s[d_0_i_ + y]]]))))) + return ((len(s)) >= (len(sub))) and (Exists(int, lambda i: + (((0) <= (i)) and ((i) < 1 + ((len(s)) - (len(sub))))) and ( + Forall(int, lambda y: (Implies(y >= 0 and y < len(sub), sub[(n + y) % len(sub)] == s[i + y]), [[sub[(n + y) % len(sub)] == s[i + y]]]))))) # pure-end def CycpatternCheck(word : List[int], pattern : List[int]) -> bool: @@ -22,24 +22,24 @@ def CycpatternCheck(word : List[int], pattern : List[int]) -> bool: # post-conditions-start Ensures(Acc(list_pred(word))) Ensures(Acc(list_pred(pattern))) - Ensures(not (Result()) or (Exists(int, lambda d_1_i_: - (((0) <= (d_1_i_)) and ((d_1_i_) <= (len(pattern)))) and (IsSubstring(word, pattern, d_1_i_))))) - Ensures(not (not(Result())) or (Forall(int, lambda d_2_i_: - not (((0) <= (d_2_i_)) and ((d_2_i_) <= (len(pattern)))) or (not(IsSubstring(word, pattern, d_2_i_)))))) + Ensures(not (Result()) or (Exists(int, lambda i: + (((0) <= (i)) and ((i) <= (len(pattern)))) and (IsSubstring(word, pattern, i))))) + Ensures(not (not(Result())) or (Forall(int, lambda i: + not (((0) <= (i)) and ((i) <= (len(pattern)))) or (not(IsSubstring(word, pattern, i)))))) # post-conditions-end # impl-start - d_3_i_ : int = 0 - while (d_3_i_) <= (len(pattern)): + i : int = 0 + while (i) <= (len(pattern)): # invariants-start Invariant(Acc(list_pred(word))) Invariant(Acc(list_pred(pattern))) - Invariant(((0) <= (d_3_i_)) and ((d_3_i_) <= ((len(pattern)) + (1)))) - Invariant(Forall(int, lambda d_4_j_: - (Implies(((0) <= (d_4_j_)) and ((d_4_j_) < (d_3_i_)), not(IsSubstring(word, pattern, d_4_j_))), [[IsSubstring(word, pattern, d_4_j_)]]))) + Invariant(((0) <= (i)) and ((i) <= ((len(pattern)) + (1)))) + Invariant(Forall(int, lambda j: + (Implies(((0) <= (j)) and ((j) < (i)), not(IsSubstring(word, pattern, j))), [[IsSubstring(word, pattern, j)]]))) # invariants-end - if IsSubstring(word, pattern, d_3_i_): + if IsSubstring(word, pattern, i): return True - d_3_i_ = (d_3_i_) + (1) + i = (i) + (1) return False # impl-end diff --git a/Bench/155_even_odd_count.py b/Bench/155_even_odd_count.py index 7a168ef..f89a7d4 100644 --- a/Bench/155_even_odd_count.py +++ b/Bench/155_even_odd_count.py @@ -13,17 +13,17 @@ def even__odd__count(n : int) -> Tuple[int, int]: # impl-start even : int = int(0) odd : int = int(0) - d_0_num_ : int = n - while (d_0_num_) > (0): + num : int = n + while (num) > (0): # invariants-start - Invariant(((0) <= (d_0_num_))) + Invariant(((0) <= (num))) Invariant(n > 0) - Invariant(((even) + (even__count(d_0_num_))) == (even__count(n))) - Invariant(((odd) + (odd__count(d_0_num_))) == (odd__count(n))) + Invariant(((even) + (even__count(num))) == (even__count(n))) + Invariant(((odd) + (odd__count(num))) == (odd__count(n))) # invariants-end - even = (even) + ((d_0_num_ % 2) == 0) - odd = (odd) + (d_0_num_ % 2) - d_0_num_ = (d_0_num_ // 10) + even = (even) + ((num % 2) == 0) + odd = (odd) + (num % 2) + num = (num // 10) return (even, odd) # impl-end diff --git a/Bench/161-solve.py b/Bench/161-solve.py index 8bde156..323f4b3 100644 --- a/Bench/161-solve.py +++ b/Bench/161-solve.py @@ -9,42 +9,42 @@ def solve(s : List[int]) -> List[int]: Ensures(Acc(list_pred(Result()), 1/2)) Ensures(Acc(list_pred(s), 1/2)) Ensures((len(s)) == (len(Result()))) - Ensures(Implies(Forall(int, lambda d_0_i_: - not (((0) <= (d_0_i_)) and ((d_0_i_) < (len(s)))) or (not(is__alpha((s)[d_0_i_])))), Forall(int, lambda d_1_i_: - not (((0) <= (d_1_i_)) and ((d_1_i_) < (len(s)))) or (((s)[d_1_i_]) == ((Result())[((len(Result())) - (1)) - (d_1_i_)]))))) - Ensures(Implies(Exists(int, lambda d_2_i_: - (((0) <= (d_2_i_)) and ((d_2_i_) < (len(s)))) and (is__alpha((s)[d_2_i_]))), Forall(int, lambda d_3_i_: - not (((0) <= (d_3_i_)) and ((d_3_i_) < (len(Result())))) or ((((Result())[d_3_i_]) == (flip__case((s)[d_3_i_])) if is__alpha((s)[d_3_i_]) else ((Result())[d_3_i_]) == ((s)[d_3_i_])))))) + Ensures(Implies(Forall(int, lambda i: + not (((0) <= (i)) and ((i) < (len(s)))) or (not(is__alpha((s)[i])))), Forall(int, lambda i: + not (((0) <= (i)) and ((i) < (len(s)))) or (((s)[i]) == ((Result())[((len(Result())) - (1)) - (i)]))))) + Ensures(Implies(Exists(int, lambda i: + (((0) <= (i)) and ((i) < (len(s)))) and (is__alpha((s)[i]))), Forall(int, lambda i: + not (((0) <= (i)) and ((i) < (len(Result())))) or ((((Result())[i]) == (flip__case((s)[i])) if is__alpha((s)[i]) else ((Result())[i]) == ((s)[i])))))) # post-conditions-end # impl-start t : List[int] = [] - d_4_flag_ : bool = False - d_5_i_ : int = 0 - while (d_5_i_) < (len(s)): + flag : bool = False + i : int = 0 + while (i) < (len(s)): # invariants-start Invariant(Acc(list_pred(t))) Invariant(Acc(list_pred(s), 1/2)) - Invariant(((0) <= (d_5_i_)) and ((d_5_i_) <= (len(s)))) - Invariant((len(t)) == (d_5_i_)) - Invariant(Implies(d_4_flag_, Exists(int, lambda d_6_j_: - (((0) <= (d_6_j_)) and ((d_6_j_) < (d_5_i_))) and (is__alpha((s)[d_6_j_]))))) - Invariant(Implies(Exists(int, lambda d_6_j_: - (((0) <= (d_6_j_)) and ((d_6_j_) < (d_5_i_))) and (is__alpha((s)[d_6_j_]))), d_4_flag_)) - Invariant(Implies(not(d_4_flag_), Forall(int, lambda d_7_j_: - Implies(((0) <= (d_7_j_)) and (d_7_j_) < (d_5_i_), not(is__alpha((s)[d_7_j_])))))) - Invariant(Implies(Forall(int, lambda d_7_j_: - Implies(((0) <= (d_7_j_)) and (d_7_j_) < (d_5_i_), not(is__alpha((s)[d_7_j_])))), not(d_4_flag_))) - Invariant(Forall(int, lambda d_7_j_: - (Implies(((0) <= (d_7_j_)) and ((d_7_j_) < (d_5_i_)), ((t)[d_7_j_]) == ((flip__case((s)[d_7_j_]) if is__alpha((s)[d_7_j_]) else (s)[d_7_j_]))), [[]]))) + Invariant(((0) <= (i)) and ((i) <= (len(s)))) + Invariant((len(t)) == (i)) + Invariant(Implies(flag, Exists(int, lambda j: + (((0) <= (j)) and ((j) < (i))) and (is__alpha((s)[j]))))) + Invariant(Implies(Exists(int, lambda j: + (((0) <= (j)) and ((j) < (i))) and (is__alpha((s)[j]))), flag)) + Invariant(Implies(not(flag), Forall(int, lambda j: + Implies(((0) <= (j)) and (j) < (i), not(is__alpha((s)[j])))))) + Invariant(Implies(Forall(int, lambda j: + Implies(((0) <= (j)) and (j) < (i), not(is__alpha((s)[j])))), not(flag))) + Invariant(Forall(int, lambda j: + (Implies(((0) <= (j)) and ((j) < (i)), ((t)[j]) == ((flip__case((s)[j]) if is__alpha((s)[j]) else (s)[j]))), [[]]))) # invariants-end - if is__alpha((s)[d_5_i_]): - t = (t) + [flip__case((s)[d_5_i_])] - d_4_flag_ = True + if is__alpha((s)[i]): + t = (t) + [flip__case((s)[i])] + flag = True else: - t = (t) + [(s)[d_5_i_]] - d_5_i_ = (d_5_i_) + (1) - if not(d_4_flag_): + t = (t) + [(s)[i]] + i = (i) + (1) + if not(flag): t = reverse(t) return t # impl-end @@ -58,24 +58,24 @@ def reverse(str : List[int]) -> List[int]: Ensures(Acc(list_pred(Result()))) Ensures(str == Old(str)) Ensures((len(Result())) == (len(str))) - Ensures(Forall(int, lambda d_11_k_: - not (((0) <= (d_11_k_)) and ((d_11_k_) < (len(str)))) or (((Result())[d_11_k_]) == ((str)[((len(str)) - (1)) - (d_11_k_)])))) + Ensures(Forall(int, lambda k: + not (((0) <= (k)) and ((k) < (len(str)))) or (((Result())[k]) == ((str)[((len(str)) - (1)) - (k)])))) # post-conditions-end # impl-start rev : List[int] = [] - d_12_i_ : int = 0 - while (d_12_i_) < (len(str)): + i : int = 0 + while (i) < (len(str)): # invariants-start Invariant(Acc(list_pred(str), 1/2)) Invariant(Acc(list_pred(rev))) - Invariant(((d_12_i_) >= (0)) and ((d_12_i_) <= (len(str)))) - Invariant((len(rev)) == (d_12_i_)) - Invariant(Forall(int, lambda d_13_k_: - not (((0) <= (d_13_k_)) and ((d_13_k_) < (d_12_i_))) or (((rev)[d_13_k_]) == ((str)[(len(str) - (1)) - (d_13_k_)])))) + Invariant(((i) >= (0)) and ((i) <= (len(str)))) + Invariant((len(rev)) == (i)) + Invariant(Forall(int, lambda k: + not (((0) <= (k)) and ((k) < (i))) or (((rev)[k]) == ((str)[(len(str) - (1)) - (k)])))) # invariants-end - rev = (rev) + [(str)[(len(str) - (d_12_i_)) - (1)]] - d_12_i_ = (d_12_i_) + (1) + rev = (rev) + [(str)[(len(str) - (i)) - (1)]] + i = (i) + (1) return rev # impl-end diff --git a/Bench/163-generate_integers.py b/Bench/163-generate_integers.py index 3d32544..18f9599 100644 --- a/Bench/163-generate_integers.py +++ b/Bench/163-generate_integers.py @@ -24,33 +24,33 @@ def max(a : int, b : int) -> int : def generate__integers(a : int, b : int) -> List[int]: # post-conditions-start Ensures(Acc(list_pred(Result()))) - Ensures(Forall(int, lambda d_0_i_: - not (((d_0_i_) >= (0)) and ((d_0_i_) < (len(Result())))) or ((((Result())[d_0_i_] % 2)) == (0)))) - Ensures(Forall(int, lambda d_1_i_: - not (((d_1_i_) >= (0)) and ((d_1_i_) < (len(Result())))) or (((Result())[d_1_i_]) > 0 and ((Result())[d_1_i_]) < 10))) + Ensures(Forall(int, lambda i: + not (((i) >= (0)) and ((i) < (len(Result())))) or ((((Result())[i] % 2)) == (0)))) + Ensures(Forall(int, lambda i: + not (((i) >= (0)) and ((i) < (len(Result())))) or (((Result())[i]) > 0 and ((Result())[i]) < 10))) # post-conditions-end # impl-start result : List[int] = [] - d_2_left_ : int = min(a, b) - d_3_right_ : int = max(a, b) - d_4_lower_ : int = max(2, d_2_left_) - d_5_upper_ : int = min(8, d_3_right_) - d_6_i_ : int = d_4_lower_ + left : int = min(a, b) + right : int = max(a, b) + lower : int = max(2, left) + upper : int = min(8, right) + i : int = lower - while (d_6_i_) <= (d_5_upper_): + while (i) <= (upper): # invariants-start Invariant(Acc(list_pred(result))) - Invariant(d_6_i_ >= 2) - Invariant(Implies((d_6_i_) <= (d_5_upper_), d_6_i_ <= 8)) - Invariant(d_5_upper_ <= 8) - Invariant(Forall(int, lambda d_7_i_: - not (((d_7_i_) >= (0)) and ((d_7_i_) < (len(result)))) or ((((result)[d_7_i_] % 2)) == (0)))) - Invariant(Forall(int, lambda d_8_j_: - (not (((d_8_j_) >= (0)) and ((d_8_j_) < (len(result)))) or (((result)[d_8_j_]) > 0 and ((result)[d_8_j_]) < 10), [[result[d_8_j_]]]))) + Invariant(i >= 2) + Invariant(Implies((i) <= (upper), i <= 8)) + Invariant(upper <= 8) + Invariant(Forall(int, lambda i: + not (((i) >= (0)) and ((i) < (len(result)))) or ((((result)[i] % 2)) == (0)))) + Invariant(Forall(int, lambda j: + (not (((j) >= (0)) and ((j) < (len(result)))) or (((result)[j]) > 0 and ((result)[j]) < 10), [[result[j]]]))) # invariants-end - if ((d_6_i_ % 2)) == (0): - result = (result) + (([d_6_i_])) - d_6_i_ = (d_6_i_) + (1) + if ((i % 2)) == (0): + result = (result) + (([i])) + i = (i) + (1) return result # impl-end