Skip to content

Commit

Permalink
Merge pull request #23 from JetBrains-Research/123,126
Browse files Browse the repository at this point in the history
fix markup
  • Loading branch information
alex28sh authored Nov 16, 2024
2 parents 7b31c28 + 44538d6 commit 6031d0c
Show file tree
Hide file tree
Showing 42 changed files with 125 additions and 218 deletions.
4 changes: 2 additions & 2 deletions Bench/009-rolling-max.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ def rolling_max(numbers: List[int]) -> List[int]:
# post-conditions-end

# impl-start
running_max = None # type: Optional[int]
result = [] # type: List[int]
running_max : Optional[int] = None
result : List[int] = []

i = 0
while i < len(numbers):
Expand Down
6 changes: 3 additions & 3 deletions Bench/011-string_xor.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ def xor(a : int, b : int) -> int:
# pre-conditions-end

# impl-start
result = int(0) # type : int
result : int = int(0)
if (a) == (b):
result = 0
else:
Expand Down Expand Up @@ -39,8 +39,8 @@ def string__xor(a : List[int], b : List[int]) -> List[int]:
# post-conditions-end

# impl-start
result = list([int(0)] * 0) # type : List[int]
d_4_i_ = int(0) # type : int
result : List[int] = []
d_4_i_ : int = int(0)
while (d_4_i_) < (len(a)):
# invariants-start
Invariant(Acc(list_pred(b)))
Expand Down
12 changes: 5 additions & 7 deletions Bench/020-find-closest-elements.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,10 @@ def find__closest__elements(s : List[int]) -> Tuple[int, int]:
# post-conditions-end

# impl-start
l = (s)[0] # type : int
h = (s)[1] # type : int
d_4_d_ = dist(l, h) # type : int
d_5_i_ = int(0) # type : int
d_5_i_ = 0
l : int = (s)[0]
h : int = (s)[1]
d_4_d_ : int = dist(l, h)
d_5_i_ : int = 0
# assert-start
Assert(Exists(int, lambda d_6_a_:
Exists(int, lambda d_7_b_:
Expand All @@ -57,8 +56,7 @@ def find__closest__elements(s : List[int]) -> Tuple[int, int]:
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_])]]))))
# invariants-end
d_10_j_ = int(0) # type : int
d_10_j_ = (d_5_i_) + (1)
d_10_j_ : int = (d_5_i_) + (1)
# assert-start
Assert(Forall(int, lambda d_8_a_:
Forall(int, lambda d_9_b_:
Expand Down
4 changes: 2 additions & 2 deletions Bench/027-flip_case.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,8 @@ def flip__case(s : List[int]) -> List[int] :
# post-conditions-end

# impl-start
res = list([int(0)] * len(s)) # type : List[int]
i = int(0) # type : int
res : List[int] = list([int(0)] * len(s))
i : int = int(0)
while i < len(s):
# invariants-start
Invariant(Acc(list_pred(s)))
Expand Down
8 changes: 3 additions & 5 deletions Bench/030-get-positive.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,8 @@ def get__positive(l : List[int]) -> List[int]:
# post-conditions-end

# impl-start
result = list([0] * 0) # type : List[int]
d_5_i_ = int(0) # type : int
d_5_i_ = 0
result : List[int] = []
d_5_i_ : int = 0
while (d_5_i_) < (len(l)):
# invariants-start
Invariant(Acc(list_pred(result)))
Expand All @@ -40,8 +39,7 @@ def get__positive(l : List[int]) -> List[int]:
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_])))))))
# invariants-end
d_13_n_ = int(0) # type : int
d_13_n_ = (l)[d_5_i_]
d_13_n_ : int = (l)[d_5_i_]
if (d_13_n_) > (0):
d_17_res__prev_ = result
# assert-start
Expand Down
6 changes: 2 additions & 4 deletions Bench/031-is-prime.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,8 @@ def is__prime(k : int) -> bool:
# post-conditions-end

# impl-start
result = False # type : bool
d_2_i_ = int(0) # type : int
d_2_i_ = 2
result = True
d_2_i_ : int = 2
result : bool = True
while (d_2_i_) < (k):
# invariants-start
Invariant(((2) <= (d_2_i_)) and ((d_2_i_) <= (k)))
Expand Down
6 changes: 2 additions & 4 deletions Bench/035-max-element.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,8 @@ def max__element(l : List[int]) -> int:
# post-conditions-end

# impl-start
result = int(0) # type : int
result = (l)[0]
d_2_i_ = int(0) # type : int
d_2_i_ = 1
result : int = (l)[0]
d_2_i_ : int = 1
while (d_2_i_) < (len(l)):
# invariants-start
Invariant(Acc(list_pred(l)))
Expand Down
4 changes: 1 addition & 3 deletions Bench/041-car_race_collision.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,5 @@ def car__race__collision(n : int) -> int:
# post-conditions-end

# impl-start
cnt = int(0) # type : int
cnt = (n) * (n)
return cnt
return n * n
# impl-end
9 changes: 3 additions & 6 deletions Bench/043-pairs-sum-to-zero.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,8 @@ def pairs__sum__to__zero(l : List[int]) -> bool:
# post-conditions-end

# impl-start
result = False # type : bool
result = False
d_4_i_ = int(0) # type : int
d_4_i_ = 0
result : bool = False
d_4_i_ : int = 0
while (d_4_i_) < (len(l)):
# invariants-start
Invariant(Acc(list_pred(l)))
Expand All @@ -31,8 +29,7 @@ def pairs__sum__to__zero(l : List[int]) -> bool:
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))))))
# invariants-end
d_9_j_ = int(0) # type : int
d_9_j_ = 0
d_9_j_ : int = 0
while (d_9_j_) < (len(l)):
# invariants-start
Invariant(Acc(list_pred(l)))
Expand Down
8 changes: 3 additions & 5 deletions Bench/050-encode_shift.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,8 @@ def encode__shift(s : List[int]) -> List[int]:
# post-conditions-end

# impl-start
t : List[int] = [] # type : List[int]
d_2_i_ = int(0) # type : int
d_2_i_ = 0
t : List[int] = []
d_2_i_ : int = 0
while (d_2_i_) < (len(s)):
# invariants-start
Invariant(Acc(list_pred(t)))
Expand Down Expand Up @@ -61,8 +60,7 @@ def decode__shift(s : List[int]) -> List[int]:

# impl-start
t : List[int] = []
d_6_i_ = int(0) # type : int
d_6_i_ = 0
d_6_i_ : int = 0
while (d_6_i_) < (len(s)):
# invariants-start
Invariant(Acc(list_pred(t)))
Expand Down
8 changes: 3 additions & 5 deletions Bench/051-remove-vowels.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,8 @@ def remove__vowels(text : List[int]) -> List[int]:
# post-conditions-end

# impl-start
s = list([int(0)] * 0) # type : List[int]
s = []
d_3_i_ = int(0) # type : int
d_3_i_ = 0
s : List[int] = []
d_3_i_ : int = 0
while (d_3_i_) < (len(text)):
# invariants-start
Invariant(Acc(list_pred(text)))
Expand All @@ -33,7 +31,7 @@ def remove__vowels(text : List[int]) -> List[int]:
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))))
# invariants-end
d_7_c_ = (text)[d_3_i_] # type : int
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)
Expand Down
16 changes: 5 additions & 11 deletions Bench/055-fib.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,29 +29,23 @@ def ComputeFib(n : int) -> int:
# post-conditions-end

# impl-start
result = int(0) # type : int
result : int = int(0)
if (n) == (0):
result = 0
return result
if (n) == (1):
result = 1
return result
d_0_a_ = int(0) # type : int
d_1_b_ = int(0) # type : int
rhs0_ = 0 # type : int
rhs1_ = 1 # type : int
d_0_a_ = rhs0_
d_1_b_ = rhs1_
d_2_i_ = int(0) # type : int
d_2_i_ = 2
d_0_a_ : int = 0
d_1_b_ : int = 1
d_2_i_ : int = 2
while (d_2_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))))
# invariants-end
d_3_temp_ = int(0) # type : int
d_3_temp_ = (d_0_a_) + (d_1_b_)
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)
Expand Down
15 changes: 5 additions & 10 deletions Bench/057-monotonic.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,11 @@ def monotonic(xs : List[int]) -> bool:
# post-conditions-end

# impl-start
result = False # type : bool
if (len(xs)) == (1):
result = True
return result
d_4_increasing_ = False # type : bool
d_4_increasing_ = True
d_5_decreasing_ = False # type : bool
d_5_decreasing_ = True
d_6_i_ = int(0) # type : int
d_6_i_ = 1
return True
d_4_increasing_ : bool = True
d_5_decreasing_ : bool = True
d_6_i_ : int = 1
while (d_6_i_) < (len(xs)):
# invariants-start
Invariant(Acc(list_pred(xs)))
Expand All @@ -42,6 +37,6 @@ def monotonic(xs : List[int]) -> bool:
if ((xs)[(d_6_i_) - (1)]) <= ((xs)[d_6_i_]):
d_5_decreasing_ = False
d_6_i_ = (d_6_i_) + (1)
result = (d_4_increasing_) or (d_5_decreasing_)
result : bool = (d_4_increasing_) or (d_5_decreasing_)
return result
# impl-end
8 changes: 3 additions & 5 deletions Bench/058-common.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,8 @@ def common(l1 : List[int], l2 : List[int]) -> List[int]:
# post-conditions-end

# impl-start
c = list([int(0)] * 0) # type : List[int]
d_2_i_ = int(0) # type : int
d_2_i_ = 0
c : List[int] = []
d_2_i_ : int = 0
while (d_2_i_) < (len(l1)):
# invariants-start
Invariant(Acc(list_pred(c)))
Expand All @@ -54,8 +53,7 @@ def common(l1 : List[int], l2 : List[int]) -> List[int]:
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_])]])))
# invariants-end
d_5_j_ = int(0) # type : int
d_5_j_ = 0
d_5_j_ : int = 0
while (d_5_j_) < (len(l2)):
# invariants-start
Invariant(Acc(list_pred(c)))
Expand Down
6 changes: 2 additions & 4 deletions Bench/060-sum-to-n.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,8 @@ def sum__squares(n : int) -> int:
# post-conditions-end

# impl-start
r = int(0) # type : int
r = 0
d_2_k_ = int(0) # type : int
d_2_k_ = 0
r : int = 0
d_2_k_ : int = 0
while (d_2_k_) < (n):
# invariants-start
Invariant(((0) <= (d_2_k_)) and ((d_2_k_) <= (n)))
Expand Down
6 changes: 2 additions & 4 deletions Bench/062-derivative.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,8 @@ def derivative(xs : List[int]) -> List[int]:
# post-conditions-end

# impl-start
result = list([int(0)] * 0) # type : List[int]
result = list([])
d_1_i_ = int(0) # type : int
d_1_i_ = 1
result : List[int] = []
d_1_i_ : int = 1
while (d_1_i_) < (len(xs)):
# invariants-start
Invariant(Acc(list_pred(result)))
Expand Down
6 changes: 2 additions & 4 deletions Bench/064-vowel_count.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,8 @@ def vowel__count(s : List[int]) -> int:
# post-conditions-end

# impl-start
count = int(0) # type : int
count = 0
d_1_i_ = int(0) # type : int
d_1_i_ = 0
count : int = 0
d_1_i_ : int = 0
while (d_1_i_) < (len(s)):
# invariants-start
Invariant(Acc(list_pred(s)))
Expand Down
9 changes: 5 additions & 4 deletions Bench/066-digitSum.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,17 +25,18 @@ def upper__sum(s : List[int]) -> int:
# post-conditions-end

# impl-start
res = int(0) # type : int
res = 0
d_1_i_ = int(0) # type : int
d_1_i_ = 0
res : int = 0
d_1_i_ : int = 0
while (d_1_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)))
# 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-end
res = (res) + (((s)[d_1_i_]))
d_1_i_ = (d_1_i_) + (1)
return res
Expand Down
2 changes: 1 addition & 1 deletion Bench/083-starts_one_ends.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ def CountNumbersStartingOrEndingWithOne(n : int) -> int:
# post-conditions-end

# impl-start
count = int(0) # type : int
count : int = int(0)
if (n) == (1):
count = 1
elif True:
Expand Down
6 changes: 2 additions & 4 deletions Bench/084-solve.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,8 @@ def solve(n : int) -> int:
# post-conditions-end

# impl-start
r = int(0) # type : int
d_0_m_ = int(0) # type : int
d_0_m_ = n
r = 0
d_0_m_ : int = n
r : int = 0
while (d_0_m_) > (0):
# invariants-start
Invariant(((0) <= (d_0_m_)) and ((d_0_m_) <= (n)))
Expand Down
6 changes: 2 additions & 4 deletions Bench/085-add.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,8 @@ def add(v : List[int]) -> int:
# post-conditions-end

# impl-start
r = int(0) # type : int
r = 0
d_2_k_ = int(0) # type : int
d_2_k_ = 0
r : int = 0
d_2_k_ : int = 0
while (d_2_k_) < (len(v)):
# invariants-start
Invariant(Acc(list_pred(v)))
Expand Down
7 changes: 3 additions & 4 deletions Bench/089-encrypt.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ def rot__sym(c : int) -> int :
# post-conditions-end

# impl-start
d_0_alph_ = c - 0 # type : int
d_0_alph_ : int = c - 0
return ((d_0_alph_) + ((2) * (2))) % 26
# impl-end

Expand All @@ -34,9 +34,8 @@ def encrypt(s : List[int]) -> List[int]:
# post-conditions-end

# impl-start
r : List[int] = [] # type : List[int]
d_3_i_ = int(0) # type : int
d_3_i_ = 0
r : List[int] = []
d_3_i_ : int = 0
while (d_3_i_) < (len(s)):
# invariants-start
Invariant(Acc(list_pred(s)))
Expand Down
Loading

0 comments on commit 6031d0c

Please sign in to comment.