-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #6 from alex28sh/096
41, 46, 126, 135, 138, 146
- Loading branch information
Showing
19 changed files
with
483 additions
and
97 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
from typing import cast, List, Dict, Set, Optional, Union | ||
from nagini_contracts.contracts import * | ||
|
||
def car__race__collision(n : int) -> int: | ||
Requires((n) >= (0)) | ||
Ensures((Result()) == ((n) * (n))) | ||
cnt = int(0) # type : int | ||
cnt = (n) * (n) | ||
return cnt |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
from typing import cast, List, Dict, Set, Optional, Union | ||
from nagini_contracts.contracts import * | ||
|
||
@Pure | ||
def fib4__rec(n : int) -> int : | ||
Requires(n >= 0) | ||
if (((n) == (0)) or ((n) == (1))) or ((n) == (2)): | ||
return 0 | ||
elif (n) == (3): | ||
return 1 | ||
elif True: | ||
return (((fib4__rec((n) - (1))) + (fib4__rec((n) - (2)))) + (fib4__rec((n) - (3)))) + (fib4__rec((n) - (4))) | ||
|
||
def fib4(n : int) -> int: | ||
Requires(n >= 0) | ||
Ensures((Result()) == (fib4__rec(n))) | ||
result = int(0) # type : int | ||
if (((n) == (0)) or ((n) == (1))) or ((n) == (2)): | ||
result = 0 | ||
return result | ||
if (n) == (3): | ||
result = 1 | ||
return result | ||
d_0_a_ = int(0) # type : int | ||
d_1_b_ = int(0) # type : int | ||
d_2_c_ = int(0) # type : int | ||
d_3_d_ = int(0) # type : int | ||
rhs0_ = 0 # type : int | ||
rhs1_ = 0 # type : int | ||
rhs2_ = 0 # type : int | ||
rhs3_ = 1 # type : int | ||
d_0_a_ = rhs0_ | ||
d_1_b_ = rhs1_ | ||
d_2_c_ = rhs2_ | ||
d_3_d_ = rhs3_ | ||
d_4_i_ = int(0) # type : int | ||
d_4_i_ = 4 | ||
while (d_4_i_) <= (n): | ||
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)))) | ||
d_5_temp_ = int(0) # type : int | ||
d_5_temp_ = (((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 = d_3_d_ | ||
return result |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
from typing import cast, List, Dict, Set, Optional, Union | ||
from nagini_contracts.contracts import * | ||
|
||
|
||
def is__sorted(a : List[int]) -> bool: | ||
Requires(Acc(list_pred(a))) | ||
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)))))) | ||
f = False # type : bool | ||
if (len(a)) == (0): | ||
f = True | ||
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_])))))) | ||
return f | ||
d_3_is__asc_ = False # type : bool | ||
d_3_is__asc_ = True | ||
d_4_i_ = int(0) # type : int | ||
d_4_i_ = 1 | ||
while (d_4_i_) < (len(a)): | ||
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_])))))) | ||
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_): | ||
f = False | ||
return f | ||
d_4_i_ = 0 | ||
d_7_has__no__more__that__2_ = False # type : bool | ||
d_7_has__no__more__that__2_ = True | ||
while (d_4_i_) < (len(a)): | ||
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_]))))))) | ||
d_9_count_ = int(0) # type : int | ||
d_9_count_ = 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 = d_7_has__no__more__that__2_ | ||
return f | ||
|
||
@Pure | ||
def count_set(a : List[int], x : int, i : int) -> int: | ||
Requires(Acc(list_pred(a), 1/2)) | ||
Requires(((0) <= (i)) and ((i) <= (len(a)))) | ||
if (i) == 0: | ||
return 0 | ||
else: | ||
return (count_set(a, x, (i) - (1))) + (((a)[(i) - (1)]) == (x)) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
from typing import cast, List, Dict, Set, Optional, Union | ||
from nagini_contracts.contracts import * | ||
|
||
def can__arrange(arr : List[int]) -> int: | ||
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_]))))) | ||
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()) >= (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)]))))) | ||
pos = int(0) # type : int | ||
d_4_i_ = int(0) # type : int | ||
d_4_i_ = 1 | ||
pos = -1 | ||
while (d_4_i_) < (len(arr)): | ||
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)]))))) | ||
if ((arr)[d_4_i_]) < ((arr)[(d_4_i_) - (1)]): | ||
pos = d_4_i_ | ||
d_4_i_ = (d_4_i_) + (1) | ||
return pos | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
from typing import cast, List, Dict, Set, Optional, Union | ||
from nagini_contracts.contracts import * | ||
|
||
def is__equal__to__sum__even(n : int) -> bool: | ||
Ensures((Result()) == ((((n % 2)) == (0)) and ((n) >= (8)))) | ||
b = False # type : bool | ||
b = (((n % 2)) == (0)) and ((n) >= (8)) | ||
return b |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
from typing import cast, List, Dict, Set, Optional, Union | ||
from nagini_contracts.contracts import * | ||
|
||
@Pure | ||
def first__digit(n : int) -> int : | ||
Requires(((0) <= (n))) | ||
Ensures(0 <= Result() and (Result()) < (10)) | ||
if n < 10: | ||
return n | ||
else: | ||
return first__digit(n // 10) | ||
|
||
@Pure | ||
def last__digit(n : int) -> int : | ||
return (n % 10) | ||
|
||
def specialFilter(s : List[int]) -> List[int]: | ||
Requires(Acc(list_pred(s))) | ||
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_])))) | ||
r = list([int(0)] * 0) # type : List[int] | ||
d_3_i_ = int(0) # type : int | ||
d_3_i_ = 0 | ||
r = list([]) | ||
while (d_3_i_) < (len(s)): | ||
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_])))) | ||
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) | ||
return r |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
from nagini_contracts.contracts import * | ||
|
||
def truncate_number(number: float) -> float: | ||
Requires(float("0.0") <= number) | ||
Ensures(float("0.0") <= number - Result() and number - Result() < float("1.0")) | ||
return number % float("1.0") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
from typing import cast, List, Dict, Set, Optional, Union | ||
from nagini_contracts.contracts import * | ||
|
||
def CalculateTriangleArea(a : float, h : float) -> float: | ||
Requires(((h) >= float("0.0")) and ((a) >= float("0.0"))) | ||
Ensures((Result()) == (((h) * (a)) / (float("2.0")))) | ||
area = ((h) * (a)) / float("2.0") # type : float | ||
return area |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.