diff --git a/Bench/012-longest.py b/Bench/012-longest.py new file mode 100644 index 0000000..66eba3d --- /dev/null +++ b/Bench/012-longest.py @@ -0,0 +1,49 @@ +from typing import cast, List, Dict, Set, Optional, Union, Tuple +from nagini_contracts.contracts import * + +@Pure +def getVal(mx: Optional[int]) -> int: + Requires(mx is not None) + return mx + +def longest(strings : List[List[int]]) -> Optional[int]: + Requires(Acc(list_pred(strings))) + Requires(Forall(strings, lambda d_0_s_: Acc(list_pred(d_0_s_)))) + Ensures(Acc(list_pred(strings))) + Ensures(Forall(strings, lambda d_0_s_: Acc(list_pred(d_0_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())]))))))) + result : Optional[int] = None + if (len(strings)) != (0): + d_5_i_ = int(0) # type : int + d_5_i_ = 0 + d_6_mx_ = int(0) # type : int + d_6_mx_ = -1 + while (d_5_i_) < (len(strings)): + 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)]))), [[((strings)[d_4_j_])]])))) + 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_ + Assert(Forall(int, lambda x: Implies(x >= 0 and x < result, len(strings[result]) > len(strings[x])))) + d_5_i_ = (d_5_i_) + (1) + return result \ No newline at end of file diff --git a/Bench/098-count_upper.py b/Bench/098-count_upper.py new file mode 100644 index 0000000..5ef3afa --- /dev/null +++ b/Bench/098-count_upper.py @@ -0,0 +1,43 @@ +from typing import cast, List, Dict, Set, Optional, Union, Tuple +from nagini_contracts.contracts import * + +@Pure +def count__upper__fun(s : List[int], i : int, j : int) -> int: + Requires(Acc(list_pred(s))) + Requires(((0) <= (i)) and ((i) <= (j)) and ((j) <= (len(s)))) + Ensures((Result()) >= (0)) + if i == j: + return 0 + else: + if is__upper__vowel((s)[j - 1]) and (j - 1) % 2 == 0: + return (1) + (count__upper__fun(s, i, j - 1)) + else: + return count__upper__fun(s, i, j - 1) + + +def count__upper(s : List[int]) -> int: + Requires(Acc(list_pred(s))) + Ensures((Result()) >= (0)) + Ensures(Acc(list_pred(s))) + Ensures((Result()) == (count__upper__fun(s, 0, len(s)))) + cnt = int(0) # type : int + cnt = 0 + d_1_i_ = int(0) # type : int + d_1_i_ = 0 + + while (d_1_i_) < (len(s)): + 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_))) + 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_))) + if (is__upper__vowel((s)[d_1_i_])) and (((d_1_i_ % 2)) == (0)): + cnt = (cnt) + (1) + d_1_i_ = (d_1_i_) + (1) + return cnt + +@Pure +def is__upper__vowel(c : int) -> bool : + return (((((c) == (0)) or ((c) == (1))) or ((c) == (2))) or ((c) == (3))) or ((c) == (4)) diff --git a/Bench/136-largest_smallest_integers.py b/Bench/136-largest_smallest_integers.py new file mode 100644 index 0000000..fbb8676 --- /dev/null +++ b/Bench/136-largest_smallest_integers.py @@ -0,0 +1,44 @@ +from typing import cast, List, Dict, Set, Optional, Union, Tuple +from nagini_contracts.contracts import * + +@Pure +def getVal(mx: Optional[int]) -> int: + Requires(mx is not None) + return mx + +def largest__smallest__integers(arr : List[int]) -> Tuple[Optional[int], Optional[int]]: + Requires(Acc(list_pred(arr))) + 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 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()[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])))))) + a : Optional[int] = None + b : Optional[int] = None + d_4_i_ = int(0) + while (d_4_i_) < (len(arr)): + 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(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 ((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)))))) + 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) + return (a, b) diff --git a/WIP/006-parse_nested_parens.py b/WIP/006-parse_nested_parens.py index cb5e84b..d488be3 100644 --- a/WIP/006-parse_nested_parens.py +++ b/WIP/006-parse_nested_parens.py @@ -2,6 +2,7 @@ from nagini_contracts.contracts import * # def parse__paren__group(s : List[int]) -> int: +# 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_]) == (1)) or (((s)[d_0_i_]) == (2))))) # Ensures((Result()) >= (0)) @@ -12,6 +13,9 @@ # d_2_i_ = int(0) # type : int # d_2_i_ = 0 # while (d_2_i_) < (len(s)): +# Invariant(Acc(list_pred(s))) +# Invariant(((d_2_i_) >= (0)) and ((d_2_i_) <= (len(s)))) +# Invariant(max__depth >= 0) # d_3_c_ = (s)[d_2_i_] # type : int # if (d_3_c_) == (1): # d_1_depth_ = (d_1_depth_) + (1) @@ -22,38 +26,84 @@ # d_2_i_ = (d_2_i_) + (1) # return max__depth -def split(s : List[int]) -> List[List[int]]: - # 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))))) - # Ensures(Acc(list_pred(Result()))) - # Ensures(Forall(int, lambda d_5_i_: Implies(d_5_i_ >= 0 and d_5_i_ < len(Result()), Acc(list_pred(Result()[d_5_i_]))))) +def split(s : List[int], res : List[List[int]]) -> None: + Requires(Acc(list_pred(s))) + Requires(Acc(list_pred(res))) + Requires(Forall(res, lambda x: Acc(list_pred(x), 1/2))) + 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))))) + Ensures(Acc(list_pred(res))) + Ensures(Forall(res, 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(res), (len(res[d_10_j_])) > (0)))) # Ensures(Forall(int, lambda d_10_j_: # not (d_10_j_ >= 0 and d_10_j_ < len(Result())) or ((Forall(int, lambda d_11_j_: # not (((d_11_j_) >= (0)) and ((d_11_j_) < (len(Result()[d_10_j_])))) or ((((Result()[d_10_j_])[d_11_j_]) == (1)) or (((Result()[d_10_j_])[d_11_j_]) == (2))))) and ((len(Result()[d_10_j_])) > (0))))) - res = list([([int(0)] * 0)] * 0) # type : List[List[int]] - d_7_current__string_ = list([int(0)] * 0) # type : List[int] + # res : List[List[int]] = [] # type : List[List[int]] + res = [] + d_7_current__string_ : List[int] = [] # type : List[int] d_8_i_ = int(0) # type : int d_8_i_ = 0 while (d_8_i_) < (len(s)): - # Invariant(Acc(list_pred(res))) - # Invariant(Forall(int, lambda d_9_j_: Implies(d_9_j_ >= 0 and d_9_j_ < len(res), Acc(list_pred(res[d_9_j_]))))) - # Invariant(((d_8_i_) >= (0)) and ((d_8_i_) <= (len(s)))) - # Invariant(Forall(int, lambda d_9_j_: - # not (((d_9_j_) >= (0)) and ((d_9_j_) < (len(d_7_current__string_)))) or ((((d_7_current__string_)[d_9_j_]) == (1)) or (((d_7_current__string_)[d_9_j_]) == (2))))) + Invariant(Acc(list_pred(res))) + Invariant(Acc(list_pred(d_7_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(res, lambda x: Acc(list_pred(x), 1/2))) + Invariant(Forall(int, lambda d_10_j_: + (Implies(d_10_j_ >= 0 and d_10_j_ < len(res), ((len(res[d_10_j_])) > (0))), [[]]))) # Invariant(Forall(int, lambda d_10_j_: - # not (d_10_j_ >= 0 and d_10_j_ < len(res)) or ((Forall(int, lambda d_11_j_: - # not (((d_11_j_) >= (0)) and ((d_11_j_) < (len(res[d_10_j_])))) or ((((res[d_10_j_])[d_11_j_]) == (1)) or (((res[d_10_j_])[d_11_j_]) == (2))))) and ((len(res[d_10_j_])) > (0))))) + # (not (d_10_j_ >= 0 and d_10_j_ < len(res)) or + # ((Forall(int, lambda d_11_j_: + # not (((d_11_j_) >= (0)) and ((d_11_j_) < (len(res[d_10_j_])))) or + # ((((res[d_10_j_])[d_11_j_]) == (1)) or (((res[d_10_j_])[d_11_j_]) == (2))))))))) # , [[res[d_10_j_]]] + # Invariant(Forall(res, lambda x: + # ((Forall(int, lambda d_11_j_: + # (not (((d_11_j_) >= (0)) and ((d_11_j_) < (len(x)))) or + # ((((x)[d_11_j_]) == (1)) or (((x)[d_11_j_]) == (2))), [[]]))), [[]]))) # , [[res[d_10_j_]]] + # Invariant(Forall(int, lambda d_10_j_: + # (not (d_10_j_ >= 0 and d_10_j_ < len(res)) or + # ((Forall(int, lambda d_11_j_: + # not (((d_11_j_) >= (0)) and ((d_11_j_) < (len(res[d_10_j_])))) or + # ((((res[d_10_j_])[d_11_j_]) == (1)) or (((res[d_10_j_])[d_11_j_]) == (2)))))), [[res[d_10_j_]]]))) # , [[res[d_10_j_]]] if ((s)[d_8_i_]) == (3): - if (d_7_current__string_) != []: - res = (res) + [d_7_current__string_] + Assert(Forall(int, lambda d_10_j_: + (Implies(d_10_j_ >= 0 and d_10_j_ < len(res), ((len(res[d_10_j_])) > (0))), [[]]))) + if len(d_7_current__string_) > 0: + d_7_copy = list(d_7_current__string_) + Assert(len(d_7_current__string_) > 0) + Assert(len(d_7_copy) > 0) + Assert(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)))), [[]]))) + Assert(Forall(int, lambda d_9_j_: + (not (d_9_j_ >= 0 and d_9_j_ < len(d_7_copy)) or + ((d_7_copy[d_9_j_]) == (1) or (d_7_copy[d_9_j_]) == (2)), [[]]))) + Assert(Forall(int, lambda d_10_j_: + (Implies(d_10_j_ >= 0 and d_10_j_ < len(res), ((len(res[d_10_j_])) > (0))), [[]]))) + res = (res) + [d_7_copy] + Assert(Forall(int, lambda d_10_j_: + (Implies(d_10_j_ >= 0 and d_10_j_ < len(res), ((len(res[d_10_j_])) > (0))), [[]]))) d_7_current__string_ = [] else: d_7_current__string_ = (d_7_current__string_) + [(s)[d_8_i_]] d_8_i_ = (d_8_i_) + (1) - if (d_7_current__string_) != []: + Assert(Forall(int, lambda d_10_j_: + (Implies(d_10_j_ >= 0 and d_10_j_ < len(res), ((len(res[d_10_j_])) > (0))), [[]]))) + if len(d_7_current__string_) > 0: + # Assert(Forall(int, lambda d_10_j_: + # (Implies(d_10_j_ >= 0 and d_10_j_ < len(res), ((len(res[d_10_j_])) > (0)))))) res = (res) + [d_7_current__string_] + # Assert(Forall(int, lambda d_10_j_: + # (Implies(d_10_j_ >= 0 and d_10_j_ < len(res), ((len(res[d_10_j_])) > (0)))))) d_7_current__string_ = [] - return res + Assert(Forall(int, lambda d_10_j_: + (Implies(d_10_j_ >= 0 and d_10_j_ < len(res), ((len(res[d_10_j_])) > (0))), [[]]))) # def parse__nested__parens(paren__string : List[int]) -> List[int]: # Requires(Forall(int, lambda d_12_i_: diff --git a/WIP/012-longest.py b/WIP/012-longest.py index 86f370e..d016b37 100644 --- a/WIP/012-longest.py +++ b/WIP/012-longest.py @@ -1,26 +1,68 @@ from typing import cast, List, Dict, Set, Optional, Union, Tuple from nagini_contracts.contracts import * -@Pure -def getVal(mx: Optional[int]) -> int: - Requires(mx is not None) - return mx +# @Pure +# def getVal(mx: Optional[int]) -> int: +# Requires(mx is not None) +# return mx -def longest(strings : List[List[int]]) -> Optional[int]: +# def longest(strings : List[List[int]]) -> Optional[int]: +# Requires(Acc(list_pred(strings))) +# Requires(Forall(strings, lambda d_0_s_: Acc(list_pred(d_0_s_)))) +# Ensures(Acc(list_pred(strings))) +# Ensures(Forall(strings, lambda d_0_s_: Acc(list_pred(d_0_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())]))))))) +# result : Optional[int] = None +# if (len(strings)) != (0): +# d_5_i_ = int(0) # type : int +# d_5_i_ = 0 +# d_6_mx_ = int(0) # type : int +# d_6_mx_ = -1 +# while (d_5_i_) < (len(strings)): +# 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)]))), [[((strings)[d_4_j_])]])))) +# 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_ +# Assert(Forall(int, lambda x: Implies(x >= 0 and x < result, len(strings[result]) > len(strings[x])))) +# d_5_i_ = (d_5_i_) + (1) +# return result + +def longest(strings : List[List[int]]) -> Optional[List[int]]: Requires(Acc(list_pred(strings))) Requires(Forall(strings, lambda d_0_s_: Acc(list_pred(d_0_s_)))) Ensures(Acc(list_pred(strings))) Ensures(Forall(strings, lambda d_0_s_: Acc(list_pred(d_0_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(((Result()) == (None)) == ((len(strings)) == (0))) + Ensures(Implies((Result()) != (None), Acc(list_pred((Result()))))) + # Ensures(not ((Result()) != (None)) or (Forall(int, lambda d_1_s_: + # not ((d_1_s_) >= 0 and d_1_s_ < len(strings)) or ((len((Result()))) >= (len(strings[d_1_s_])))))) # Ensures(not ((Result()) != (None)) or (Exists(List[int], lambda d_2_s_: - # ((d_2_s_) in (strings)) and ((len(d_2_s_)) == (len(getVal(Result()))))))) + # ((d_2_s_) in (strings)) and ((len(d_2_s_)) == (len((Result()))))))) # Ensures(not ((Result()) != (None)) or (Exists(int, lambda d_3_i_: - # ((((0) <= (d_3_i_)) and ((d_3_i_) < (len(strings)))) and (((strings)[d_3_i_]) == (getVal(Result())))) and (Forall(int, lambda d_4_j_: - # not (((0) <= (d_4_j_)) and ((d_4_j_) < (d_3_i_))) or ((len((strings)[d_4_j_])) < (len(getVal(Result()))))))))) - result = int(0) # type : Optional[int] + # ((((0) <= (d_3_i_)) and ((d_3_i_) < (len(strings)))) and (((strings)[d_3_i_]) == ((Result())))) and (Forall(int, lambda d_4_j_: + # not (((0) <= (d_4_j_)) and ((d_4_j_) < (d_3_i_))) or ((len((strings)[d_4_j_])) < (len((Result()))))))))) + result : Optional[List[int]] = list([int(0)] * 0) result = None if (len(strings)) != (0): d_5_i_ = int(0) # type : int @@ -30,21 +72,27 @@ def longest(strings : List[List[int]]) -> Optional[int]: while (d_5_i_) < (len(strings)): Invariant(Acc(list_pred(strings))) Invariant(Forall(strings, lambda d_0_s_: Acc(list_pred(d_0_s_)))) + Invariant(Implies(result is not None, Acc(list_pred(result)))) Invariant(((d_5_i_) >= (0)) and ((d_5_i_) <= (len(strings)))) - Invariant(((d_6_mx_) == (-1)) == ((result) is (None))) + Invariant(((d_6_mx_) == (-1)) == ((result) == (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 ((d_6_mx_) == (len(strings[getVal(result)])))) - # Invariant(not ((d_5_i_) > (0)) or (Forall(List[char], lambda d_7_s_: - # not ((d_7_s_) in (list((strings)[0:d_5_i_:]))) or ((d_6_mx_) >= (len(d_7_s_)))))) + Invariant(not ((d_5_i_) > (0)) or (result is not None)) + Invariant(Acc(list_pred((result)))) + Invariant(Implies((d_5_i_) > (0), Acc(list_pred((result))))) + Invariant(not ((d_5_i_) > (0)) or ((d_6_mx_) == (len((result))))) + # Invariant(not ((d_5_i_) > (0)) or (Forall(int, lambda d_7_s_: + # not ((d_7_s_) >= 0 and d_7_s_ < d_5_i_) or ((d_6_mx_) >= (len(strings[d_7_s_])))))) # Invariant(not ((d_5_i_) > (0)) or (Exists(List[int], lambda d_8_s_: # ((d_8_s_) in (strings)) and ((d_6_mx_) == (len(d_8_s_)))))) # Invariant(not ((result) != (None)) or (Exists(int, lambda d_9_i_: - # ((((0) <= (d_9_i_)) and ((d_9_i_) < (len(strings)))) and (((strings)[d_9_i_]) == (getVal(result)))) and (Forall(int, lambda d_10_j_: - # not (((0) <= (d_10_j_)) and ((d_10_j_) < (d_9_i_))) or ((len((strings)[d_10_j_])) < (len(getVal(result))))))))) - if result is None or (len((strings)[d_5_i_])) > (len(strings[getVal(result)])): + # ((((0) <= (d_9_i_)) and ((d_9_i_) < (len(strings)))) and (((strings)[d_9_i_]) == ((result)))) and (Forall(int, lambda d_10_j_: + # not (((0) <= (d_10_j_)) and ((d_10_j_) < (d_9_i_))) or ((len((strings)[d_10_j_])) < (len((result))))))))) + if (len((strings)[d_5_i_])) > (d_6_mx_): d_6_mx_ = len((strings)[d_5_i_]) - result = d_5_i_ + result = list((strings)[d_5_i_]) + Assert(Acc(list_pred(result))) + Assert(d_6_mx_ >= 0) + Assert(result is not None) + Assert(Acc(list_pred(result))) d_5_i_ = (d_5_i_) + (1) - return result \ No newline at end of file + return result diff --git a/WIP/094-skjkasdkd.py b/WIP/094-skjkasdkd.py new file mode 100644 index 0000000..52de351 --- /dev/null +++ b/WIP/094-skjkasdkd.py @@ -0,0 +1,87 @@ +from typing import cast, List, Dict, Set, Optional, Union, Tuple +from nagini_contracts.contracts import * + +def skjkasdkd(lst : List[int]) -> int: + Requires(Acc(list_pred(lst))) + Requires(Forall(int, lambda d_0_i_: Implies(((0) <= (d_0_i_)) and ((d_0_i_) < (len(lst))), ((lst)[d_0_i_]) >= (0)))) + Requires(Exists(int, lambda d_0_i_: + (((0) <= (d_0_i_)) and ((d_0_i_) < (len(lst)))) and (is__prime((lst)[d_0_i_])))) + Ensures(Acc(list_pred(lst))) + Ensures((Result()) == (digits__sum(max__seq(filter__primes(lst))))) + dsum = int(0) # type : int + d_1_primes_ = list([int(0)] * 0) # type : List[int] + d_1_primes_ = list([]) + d_2_i_ = int(0) # type : int + d_2_i_ = 0 + while (d_2_i_) < (len(lst)): + Invariant(Acc(list_pred(d_1_primes_))) + Invariant(Acc(list_pred(lst))) + Invariant(Forall(int, lambda d_0_i_: Implies(((0) <= (d_0_i_)) and ((d_0_i_) < (len(lst))), ((lst)[d_0_i_]) >= (0)))) + Invariant(Forall(int, lambda d_0_i_: Implies(((0) <= (d_0_i_)) and ((d_0_i_) < (len(d_1_primes_))), ((d_1_primes_)[d_0_i_]) >= (0)))) + Invariant(((0) <= (d_2_i_)) and ((d_2_i_) <= (len(lst)))) + # Invariant((d_1_primes_) == (filter__primes(list((lst)[:d_2_i_:])))) + if is__prime((lst)[d_2_i_]): + d_1_primes_ = (d_1_primes_) + [(lst)[d_2_i_]] + Assert((filter__primes(list((lst)[:(d_2_i_) + (1):]))) == ((filter__primes(list((lst)[:d_2_i_:]))) + ((list([(lst)[d_2_i_]]) if is__prime((lst)[d_2_i_]) else list([]))))) + d_2_i_ = (d_2_i_) + (1) + Assert((list((lst)[:len(lst):])) == (lst)) + d_3_max__prime_ = int(0) # type : int + d_3_max__prime_ = (d_1_primes_)[0] + d_2_i_ = 1 + while (d_2_i_) < (len(d_1_primes_)): + Invariant(Acc(list_pred(d_1_primes_))) + Invariant(Acc(list_pred(lst))) + Invariant(((1) <= (d_2_i_)) and ((d_2_i_) <= (len(d_1_primes_)))) + Invariant(Forall(int, lambda d_4_j_: + not (((0) <= (d_4_j_)) and ((d_4_j_) < (d_2_i_))) or ((d_3_max__prime_) >= ((d_1_primes_)[d_4_j_])))) + Invariant((d_3_max__prime_) == (max__seq(list((d_1_primes_)[:d_2_i_:])))) + d_3_max__prime_ = max(d_3_max__prime_, (d_1_primes_)[d_2_i_]) + Assert((max__seq(list((d_1_primes_)[:(d_2_i_) + (1):]))) == (max(max__seq(list((d_1_primes_)[:d_2_i_:])), (d_1_primes_)[d_2_i_]))) + d_2_i_ = (d_2_i_) + (1) + Assert((list((d_1_primes_)[:len(d_1_primes_):])) == (d_1_primes_)) + Assert((d_3_max__prime_) == (max__seq(d_1_primes_))) + dsum = digits__sum(d_3_max__prime_) + return dsum + +@Pure +def digits__sum(x : int) -> int : + Requires((x) >= (0)) + if x < 10: + return x % 10 + else: + return (x % 10) + digits__sum(x // 10) + +@Pure +def max__seq(lst : List[int], i : int, j : int) -> int : + Requires(Acc(list_pred(lst))) + Requires(((0) <= (i)) and ((i) <= (j)) and ((j) <= (len(lst)))) + if j == i + 1: + return (lst)[j - 1] + else: + return max((lst)[j - 1], max__seq(lst, i, j - 1)) + +@Pure +def get_max_prime(list : List[int], i : int, j : int) -> int: + Requires() + +# @staticmethod +# def filter__primes(lst : List[int]) -> List[int] : +# if (len(lst)) == (0): +# return list([]) +# elif True: +# d_7_tail_ = filter__primes(list((lst)[1::])) # type : List[int] +# return ((list([(lst)[0]]) if is__prime((lst)[0]) else list([]))) + (d_7_tail_) + +@Pure +def max(a : int, b : int) -> int : + if (a) > (b): + return a + elif True: + return b + +@Pure +def is__prime(k : int) -> bool : + Requires((k) >= (0)) + return ((k) != (1)) and (Forall(int, lambda d_8_i_: + not (((2) <= (d_8_i_)) and ((d_8_i_) < (k))) or (((k % d_8_i_)) != (0)))) + diff --git a/WIP/115-max_fill.py b/WIP/115-max_fill.py new file mode 100644 index 0000000..163ecf6 --- /dev/null +++ b/WIP/115-max_fill.py @@ -0,0 +1,80 @@ +from typing import cast, List, Dict, Set, Optional, Union, Tuple +from nagini_contracts.contracts import * + +def max__fill(grid : List[List[int]], capacity : int) -> int: + Requires(Acc(list_pred(grid), 1/2)) + Requires(Forall(grid, lambda grid0: Acc(list_pred(grid0), 1/2))) + Requires((capacity) > (0)) + Requires(Forall(int, lambda d_0_i_: + Forall(int, lambda d_1_j_: + not ((((0) <= (d_0_i_)) and ((d_0_i_) < (len(grid)))) and (((0) <= (d_1_j_)) and ((d_1_j_) < (len((grid)[d_0_i_]))))) or (((((grid)[d_0_i_])[d_1_j_]) == (0)) or ((((grid)[d_0_i_])[d_1_j_]) == (1)))))) + Ensures(Acc(list_pred(grid), 1/2)) + Ensures(Forall(grid, lambda grid0: Acc(list_pred(grid0), 1/2))) + # Ensures((Result()) == (psum2(0, len(grid), grid, capacity))) + cnt = int(0) # type : int + d_2_i_ = int(0) # type : int + d_2_i_ = 0 + cnt = 0 + while (d_2_i_) < (len(grid)): + Invariant(capacity > 0) + Invariant(Acc(list_pred(grid), 1/2)) + Invariant(Forall(grid, lambda grid0: Acc(list_pred(grid0), 1/2))) + Invariant(((0) <= (d_2_i_)) and ((d_2_i_) <= (len(grid)))) + # Invariant(Forall(int, lambda d_0_i_: + # (Implies(d_0_i_ >= 0 and d_0_i_ < len(grid), + # psum2(0, d_0_i_ + 1, grid, capacity) == (psum2(0, d_0_i_, grid, capacity) + (psum(0, len(grid[d_0_i_]), grid[d_0_i_]) + capacity - 1) // capacity)), [[]]))) + # Invariant(cnt == (psum2(0, d_2_i_, grid, capacity))) + Assume(Forall(int, lambda d_0_i_: + (Implies(d_0_i_ >= 0 and d_0_i_ < len(grid), + psum2(0, d_0_i_ + 1, grid, capacity) == (psum2(0, d_0_i_, grid, capacity) + (psum(0, len(grid[d_0_i_]), grid[d_0_i_]) + capacity - 1) // capacity)), + [[grid[d_0_i_]]]))) + d_4_j_ = int(0) # type : int + d_4_j_ = 0 + d_5_sum__j_ = int(0) # type : int + d_5_sum__j_ = 0 + while (d_4_j_) < (len((grid)[d_2_i_])): + Invariant(capacity > 0) + Invariant(Acc(list_pred(grid), 1/2)) + Invariant(Forall(grid, lambda grid0: Acc(list_pred(grid0), 1/2))) + Invariant(((0) <= (d_2_i_)) and ((d_2_i_) < (len(grid)))) + Invariant(((0) <= (d_4_j_)) and ((d_4_j_) <= (len((grid)[d_2_i_])))) + Invariant(Forall(int, lambda d_0_i_: + (Implies(d_0_i_ >= 0 and d_0_i_ < len(grid), + psum2(0, d_0_i_ + 1, grid, capacity) == (psum2(0, d_0_i_, grid, capacity) + (psum(0, len(grid[d_0_i_]), grid[d_0_i_]) + capacity - 1) // capacity)), + [[grid[d_0_i_]]]))) + Invariant((psum2(0, d_2_i_ + 1, grid, capacity)) == (psum2(0, d_2_i_, grid, capacity) + (psum(0, len(grid[d_2_i_]), grid[d_2_i_]) + capacity - 1) // capacity)) + # Invariant((psum(0, d_4_j_ + 1, grid[d_2_i_])) == ((psum(0, d_4_j_, grid[d_2_i_]) + (grid[d_2_i_])[d_4_j_]))) + # Invariant(Forall(int, lambda x: + # (not (((0) <= (x)) and ((x) < (len(grid[d_2_i_])))) or + # ((psum(0, x + 1, grid[d_2_i_])) == (psum(0, x, grid[d_2_i_]) + grid[d_2_i_][x])), [[psum(0, x + 1, grid[d_2_i_])]]))) + # Invariant(cnt == (psum2(0, d_2_i_, grid, capacity))) + # Invariant((d_5_sum__j_) == (psum(0, d_4_j_, grid[d_2_i_]))) + # Assert((psum(0, d_4_j_ + 1, grid[d_2_i_])) == ((psum(0, d_4_j_, grid[d_2_i_]) + (grid[d_2_i_])[d_4_j_]))) + d_5_sum__j_ = (d_5_sum__j_) + (((grid)[d_2_i_])[d_4_j_]) + d_4_j_ = (d_4_j_) + (1) + d_6_current__el_ = int(0) # type : int + d_6_current__el_ = ((((d_5_sum__j_) + (capacity)) - (1)) // capacity) + Assert((psum2(0, d_2_i_ + 1, grid, capacity)) == (psum2(0, d_2_i_, grid, capacity) + (psum(0, len(grid[d_2_i_]), grid[d_2_i_]) + capacity - 1) // capacity)) + cnt = (cnt) + (d_6_current__el_) + d_2_i_ = (d_2_i_) + (1) + return cnt + +@Pure +def psum2(i : int, j : int, s : List[List[int]], capacity : int) -> int : + Requires(Acc(list_pred(s), 1/2)) + Requires(Forall(s, lambda x: Acc(list_pred(x), 1/2))) + Requires(capacity > 0) + Requires(0 <= i and i <= j and j <= len(s)) + if i == j: + return 0 + else: + return ((psum(0, len(s[j - 1]), s[j - 1]) + capacity - 1) // capacity) + (psum2(i, j - 1, s, capacity)) + +@Pure +def psum(i : int, j : int, s : List[int]) -> int : + Requires(Acc(list_pred(s), 1/2)) + Requires(0 <= i and i <= j and j <= len(s)) + if i == j: + return 0 + else: + return (s)[j - 1] + (psum(i, j - 1, s)) \ No newline at end of file diff --git a/WIP/130-tri.py b/WIP/130-tri.py index d1f4390..529ca6f 100644 --- a/WIP/130-tri.py +++ b/WIP/130-tri.py @@ -15,8 +15,8 @@ def Tribonacci(n : int) -> List[int]: Requires((n) >= (0)) Ensures(Acc(list_pred(Result()))) Ensures((len(Result())) == ((n) + (1))) - # Ensures(Forall(int, lambda d_0_i_: - # Implies(((0) <= (d_0_i_)) and ((d_0_i_) <= (n)), ((Result())[d_0_i_]) == (tri(d_0_i_))))) + Ensures(Forall(int, lambda d_0_i_: + Implies(((0) <= (d_0_i_)) and ((d_0_i_) <= (n)), ((Result())[d_0_i_]) == (tri(d_0_i_))))) result = list([int(0)] * (n + 1)) # type : List[int] result[0] = 1 Assert(result[0] == tri(0)) @@ -41,11 +41,17 @@ def Tribonacci(n : int) -> List[int]: Invariant(Forall(int, lambda x: (Implies(2 <= x and x <= n and x % 2 == 1, tri(x) == (tri(x - 2) + tri(x - 1) + ((x + 3) // 2))), [[tri(x)]]))) Invariant(result[(d_1_i_) - (2)] == tri(d_1_i_ - 2)) Invariant(result[(d_1_i_) - (1)] == tri(d_1_i_ - 1)) - # Invariant(Forall(int, lambda d_2_j_: - # (Implies(((0) <= (d_2_j_)) and ((d_2_j_) < (d_1_i_)), ((result)[d_2_j_]) == (tri(d_2_j_))), [[tri(d_2_j_)]]))) + Invariant(Forall(int, lambda d_2_j_: + (Implies(((0) <= (d_2_j_)) and ((d_2_j_) < (d_1_i_)), ((result)[d_2_j_]) == (tri(d_2_j_))), [[tri(d_2_j_)]]))) # , [[(result)[d_2_j_]]] + Assert(Forall(int, lambda d_2_j_: + (Implies(((0) <= (d_2_j_)) and ((d_2_j_) < (d_1_i_)), ((result)[d_2_j_]) == (tri(d_2_j_))), [[tri(d_2_j_)]]))) # , [[(result)[d_2_j_]]] if ((d_1_i_ % 2)) == (0): result[d_1_i_] = (1) + ((d_1_i_ // 2)) Assert(((result)[d_1_i_]) == (tri(d_1_i_))) + Assert(Forall(int, lambda d_2_j_: + (Implies(((0) <= (d_2_j_)) and ((d_2_j_) < (d_1_i_)), ((result)[d_2_j_]) == (tri(d_2_j_))), [[tri(d_2_j_)]]))) + Assert(Forall(int, lambda d_2_j_: + (Implies(((0) <= (d_2_j_)) and ((d_2_j_) <= (d_1_i_)), ((result)[d_2_j_]) == (tri(d_2_j_))), [[tri(d_2_j_)]]))) else: Assert(result[(d_1_i_) - (2)] == tri(d_1_i_ - 2)) Assert(result[(d_1_i_) - (1)] == tri(d_1_i_ - 1)) @@ -53,6 +59,12 @@ def Tribonacci(n : int) -> List[int]: result[d_1_i_] = (((result)[(d_1_i_) - (2)]) + ((result)[(d_1_i_) - (1)])) + ((((d_1_i_) + (3)) // 2)) Assert(Implies((result)[(d_1_i_) - (2)] == tri(d_1_i_ - 2) and (result)[(d_1_i_) - (1)] == tri(d_1_i_ - 1), result[d_1_i_] == tri(d_1_i_))) Assert(((result)[d_1_i_]) == (tri(d_1_i_))) + Assert(Forall(int, lambda d_2_j_: + (Implies(((0) <= (d_2_j_)) and ((d_2_j_) < (d_1_i_)), ((result)[d_2_j_]) == (tri(d_2_j_))), [[tri(d_2_j_)]]))) + Assert(Forall(int, lambda d_2_j_: + (Implies(((0) <= (d_2_j_)) and ((d_2_j_) <= (d_1_i_)), ((result)[d_2_j_]) == (tri(d_2_j_))), [[tri(d_2_j_)]]))) Assert(((result)[d_1_i_]) == (tri(d_1_i_))) + Assert(Forall(int, lambda d_2_j_: + (Implies(((0) <= (d_2_j_)) and ((d_2_j_) <= (d_1_i_)), ((result)[d_2_j_]) == (tri(d_2_j_))), [[tri(d_2_j_)]]))) d_1_i_ = (d_1_i_) + (1) return result diff --git a/WIP/136-largest_smallest_integers.py b/WIP/136-largest_smallest_integers.py deleted file mode 100644 index c4705a9..0000000 --- a/WIP/136-largest_smallest_integers.py +++ /dev/null @@ -1,48 +0,0 @@ -from typing import cast, List, Dict, Set, Optional, Union, Tuple -from nagini_contracts.contracts import * - -@Pure -def getVal(mx: Optional[int]) -> int: - Requires(mx is not None) - return mx - -def largest__smallest__integers(arr : List[int]) -> Tuple[Optional[int], Optional[int]]: - Requires(Acc(list_pred(arr))) - 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 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()[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])))))) - # a = int(0) # type : Optional[int] - # b = int(0) # type : Optional[int] - a = None # type : Optional[int] - # b = None # type : Optional[int] - d_4_i_ = int(0) # type : int - d_4_i_ = 0 - while (d_4_i_) < (len(arr)): - Invariant(Acc(list_pred(arr))) - # Invariant(a is None or isinstance(a, int)) - 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(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 ((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)))))) - 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) - return (a, a)