test_ID stringlengths 3 3 | test_file stringlengths 14 119 | ground_truth stringlengths 70 28.7k | hints_removed stringlengths 58 28.7k |
|---|---|---|---|
000 | 630-dafny_tmp_tmpz2kokaiq_Solution.dfy |
function sorted(a: array<int>) : bool
reads a
{
forall i,j : int :: 0 <= i < j < a.Length ==> a[i] <= a[j]
}
method BinarySearch(a: array<int>, x: int) returns (index: int)
requires sorted(a)
ensures 0 <= index < a.Length ==> a[index] == x
ensures index == -1 ==> forall i : int :: 0 <= i < a.Length... |
function sorted(a: array<int>) : bool
reads a
{
forall i,j : int :: 0 <= i < j < a.Length ==> a[i] <= a[j]
}
method BinarySearch(a: array<int>, x: int) returns (index: int)
requires sorted(a)
ensures 0 <= index < a.Length ==> a[index] == x
ensures index == -1 ==> forall i : int :: 0 <= i < a.Length... |
001 | 703FinalProject_tmp_tmpr_10rn4z_DP-GD.dfy | method DPGD_GradientPerturbation (size:int, learning_rate:real, noise_scale:real, gradient_norm_bound:real, iterations:int) returns (Para:real, PrivacyLost:real)
requires iterations>=0
requires size>=0
requires noise_scale >= 1.0
requires -1.0 <= gradient_norm_bound <= 1.0
{
var thetha:array<real> := new real... | method DPGD_GradientPerturbation (size:int, learning_rate:real, noise_scale:real, gradient_norm_bound:real, iterations:int) returns (Para:real, PrivacyLost:real)
requires iterations>=0
requires size>=0
requires noise_scale >= 1.0
requires -1.0 <= gradient_norm_bound <= 1.0
{
var thetha:array<real> := new real... |
002 | 703FinalProject_tmp_tmpr_10rn4z_gaussian.dfy | // VERIFY USING DAFNY:
// /Applications/dafny/dafny /Users/apple/GaussianDP/Dafny/gaussian.dfy
method gaussian (size:int, q: array<real>, q_hat: array<real>) returns (out: array<real>)
requires q_hat.Length==size
requires q.Length==size
requires size > 0
requires arraySquaredSum(q_hat[..]) <= 1.0
{
var i : int := 0;
... | // VERIFY USING DAFNY:
// /Applications/dafny/dafny /Users/apple/GaussianDP/Dafny/gaussian.dfy
method gaussian (size:int, q: array<real>, q_hat: array<real>) returns (out: array<real>)
requires q_hat.Length==size
requires q.Length==size
requires size > 0
requires arraySquaredSum(q_hat[..]) <= 1.0
{
var i : int := 0;
... |
003 | AssertivePrograming_tmp_tmpwf43uz0e_DivMode_Unary.dfy | // Noa Leron 207131871
// Tsuri Farhana 315016907
// definitions borrowed from Rustan Leino's Program Proofs Chapter 7
// (https://program-proofs.com/code.html example code in Dafny; source file 7-Unary.dfy)
datatype Unary = Zero | Suc(pred: Unary)
ghost function UnaryToNat(x: Unary): nat {
match x
case Zero => ... | // Noa Leron 207131871
// Tsuri Farhana 315016907
// definitions borrowed from Rustan Leino's Program Proofs Chapter 7
// (https://program-proofs.com/code.html example code in Dafny; source file 7-Unary.dfy)
datatype Unary = Zero | Suc(pred: Unary)
ghost function UnaryToNat(x: Unary): nat {
match x
case Zero => ... |
004 | AssertivePrograming_tmp_tmpwf43uz0e_Find_Substring.dfy | // Noa Leron 207131871
// Tsuri Farhana 315016907
ghost predicate ExistsSubstring(str1: string, str2: string) {
// string in Dafny is a sequence of characters (seq<char>) and <= on sequences is the prefix relation
exists offset :: 0 <= offset <= |str1| && str2 <= str1[offset..]
}
ghost predicate Post(str1: string,... | // Noa Leron 207131871
// Tsuri Farhana 315016907
ghost predicate ExistsSubstring(str1: string, str2: string) {
// string in Dafny is a sequence of characters (seq<char>) and <= on sequences is the prefix relation
exists offset :: 0 <= offset <= |str1| && str2 <= str1[offset..]
}
ghost predicate Post(str1: string,... |
005 | AssertivePrograming_tmp_tmpwf43uz0e_MergeSort.dfy | // Noa Leron 207131871
// Tsuri Farhana 315016907
predicate Sorted(q: seq<int>) {
forall i,j :: 0 <= i <= j < |q| ==> q[i] <= q[j]
}
/*
Goal: Implement the well known merge sort algorithm in O(a.Length X log_2(a.Length)) time, recursively.
- Divide the contents of the original array into two local arrays
- After ... | // Noa Leron 207131871
// Tsuri Farhana 315016907
predicate Sorted(q: seq<int>) {
forall i,j :: 0 <= i <= j < |q| ==> q[i] <= q[j]
}
/*
Goal: Implement the well known merge sort algorithm in O(a.Length X log_2(a.Length)) time, recursively.
- Divide the contents of the original array into two local arrays
- After ... |
006 | BPTree-verif_tmp_tmpq1z6xm1d_Utils.dfy |
// method CountLessThan(numbers: set<int>, threshold: int) returns (count: int)
// // ensures count == |set i | i in numbers && i < threshold|
// ensures count == |SetLessThan(numbers, threshold)|
// {
// count := 0;
// var ss := numbers;
// while ss != {}
// decreases |ss|
// {
// var i: int :| ... |
// method CountLessThan(numbers: set<int>, threshold: int) returns (count: int)
// // ensures count == |set i | i in numbers && i < threshold|
// ensures count == |SetLessThan(numbers, threshold)|
// {
// count := 0;
// var ss := numbers;
// while ss != {}
// decreases |ss|
// {
// var i: int :| ... |
007 | BinarySearchTree_tmp_tmp_bn2twp5_bst4copy.dfy | datatype Tree = Empty | Node(left: Tree, value: int, right: Tree)
predicate BinarySearchTree(tree: Tree)
decreases tree
{
match tree
case Empty => true
case Node(_,_,_) =>
(tree.left == Empty || tree.left.value < tree.value)
&& (tree.right == Empty || tree.right.value > tree.value)
&& BinarySearchT... | datatype Tree = Empty | Node(left: Tree, value: int, right: Tree)
predicate BinarySearchTree(tree: Tree)
{
match tree
case Empty => true
case Node(_,_,_) =>
(tree.left == Empty || tree.left.value < tree.value)
&& (tree.right == Empty || tree.right.value > tree.value)
&& BinarySearchTree(tree.left) &&... |
008 | CO3408-Advanced-Software-Modelling-Assignment-2022-23-Part-2-A-Specification-Spectacular_tmp_tmp4pj4p2zx_car_park.dfy | class {:autocontracts} CarPark {
const totalSpaces: nat := 10;
const normalSpaces: nat:= 7;
const reservedSpaces: nat := 3;
const badParkingBuffer: int := 5;
var weekend: bool;
var subscriptions: set<string>;
var carPark: set<string>;
var reservedCarPark: set<string>;
constructor()... | class {:autocontracts} CarPark {
const totalSpaces: nat := 10;
const normalSpaces: nat:= 7;
const reservedSpaces: nat := 3;
const badParkingBuffer: int := 5;
var weekend: bool;
var subscriptions: set<string>;
var carPark: set<string>;
var reservedCarPark: set<string>;
constructor()... |
009 | CS494-final-project_tmp_tmp7nof55uq_bubblesort.dfy | //Bubblesort CS 494 submission
//References: https://stackoverflow.com/questions/69364687/how-to-prove-time-complexity-of-bubble-sort-using-dafny/69365785#69365785
// predicate checks if elements of a are in ascending order, two additional conditions are added to allow us to sort in specific range within array
predic... | //Bubblesort CS 494 submission
//References: https://stackoverflow.com/questions/69364687/how-to-prove-time-complexity-of-bubble-sort-using-dafny/69365785#69365785
// predicate checks if elements of a are in ascending order, two additional conditions are added to allow us to sort in specific range within array
predic... |
010 | CS5232_Project_tmp_tmpai_cfrng_LFUSimple.dfy | class LFUCache {
var capacity : int;
var cacheMap : map<int, (int, int)>; //key -> {value, freq}
constructor(capacity: int)
requires capacity > 0;
ensures Valid();
{
this.capacity := capacity;
this.cacheMap := map[];
}
predicate Valid()
reads this;
// reads... | class LFUCache {
var capacity : int;
var cacheMap : map<int, (int, int)>; //key -> {value, freq}
constructor(capacity: int)
requires capacity > 0;
ensures Valid();
{
this.capacity := capacity;
this.cacheMap := map[];
}
predicate Valid()
reads this;
// reads... |
011 | CS5232_Project_tmp_tmpai_cfrng_test.dfy | iterator Gen(start: int) yields (x: int)
yield ensures |xs| <= 10 && x == start + |xs| - 1
{
var i := 0;
while i < 10 invariant |xs| == i {
x := start + i;
yield;
i := i + 1;
}
}
method Main() {
var i := new Gen(30);
while true
invariant i.Valid() && fresh(i._new)
decreases 10 - |i.xs|
... | iterator Gen(start: int) yields (x: int)
yield ensures |xs| <= 10 && x == start + |xs| - 1
{
var i := 0;
while i < 10 invariant |xs| == i {
x := start + i;
yield;
i := i + 1;
}
}
method Main() {
var i := new Gen(30);
while true
{
var m := i.MoveNext();
if (!m) {break; }
print i.x;... |
012 | CSC8204-Dafny_tmp_tmp11yhjb53_stack.dfy | /*
Dafny Tutorial 2: Sequences and Stacks, Predicates and Assertions
In this tutorial we introduce a simple stack model using the functional
style of programming.
*/
type intStack = seq<int>
function isEmpty(s: intStack): bool
{
|s| == 0
}
function push(s: intStack, x: int): intStack
{
s + [x]
}
... | /*
Dafny Tutorial 2: Sequences and Stacks, Predicates and Assertions
In this tutorial we introduce a simple stack model using the functional
style of programming.
*/
type intStack = seq<int>
function isEmpty(s: intStack): bool
{
|s| == 0
}
function push(s: intStack, x: int): intStack
{
s + [x]
}
... |
013 | CSU55004---Formal-Verification_tmp_tmp4ki9iaqy_Project_Project_Part_1_project_pt_1.dfy | //This method should return true iff pre is a prefix of str. That is, str starts with pre
method isPrefix(pre:string, str:string) returns(res:bool)
requires 0 < |pre| <= |str| //This line states that this method requires that pre is less than or equal in length to str. Without this line, an out of bounds error is s... | //This method should return true iff pre is a prefix of str. That is, str starts with pre
method isPrefix(pre:string, str:string) returns(res:bool)
requires 0 < |pre| <= |str| //This line states that this method requires that pre is less than or equal in length to str. Without this line, an out of bounds error is s... |
014 | CVS-Projto1_tmp_tmpb1o0bu8z_Hoare.dfy | method Max (x: nat, y:nat) returns (r:nat)
ensures (r >= x && r >=y)
ensures (r == x || r == y)
{
if (x >= y) { r := x;}
else { r := y;}
}
method Test ()
{
var result := Max(42, 73);
assert result == 73;
}
method m1 (x: int, y: int) returns (z: int)
requires 0 < x < y
ensures z >= 0 && z <= y ... | method Max (x: nat, y:nat) returns (r:nat)
ensures (r >= x && r >=y)
ensures (r == x || r == y)
{
if (x >= y) { r := x;}
else { r := y;}
}
method Test ()
{
var result := Max(42, 73);
}
method m1 (x: int, y: int) returns (z: int)
requires 0 < x < y
ensures z >= 0 && z <= y && z != x
{
//assume ... |
015 | CVS-Projto1_tmp_tmpb1o0bu8z_fact.dfy | function fact (n:nat): nat
decreases n
{if n == 0 then 1 else n * fact(n-1)}
function factAcc (n:nat, a:int): int
decreases n
{if (n==0) then a else factAcc(n-1,n*a)}
function factAlt(n:nat):int
{factAcc(n,1)}
lemma factAcc_correct (n:nat, a:int)
ensures factAcc(n, a) == a*fact(n)
{
}
lemma factAlt_correct (n:na... | function fact (n:nat): nat
{if n == 0 then 1 else n * fact(n-1)}
function factAcc (n:nat, a:int): int
{if (n==0) then a else factAcc(n-1,n*a)}
function factAlt(n:nat):int
{factAcc(n,1)}
lemma factAcc_correct (n:nat, a:int)
ensures factAcc(n, a) == a*fact(n)
{
}
lemma factAlt_correct (n:nat)
ensures factAlt(n) == ... |
016 | CVS-Projto1_tmp_tmpb1o0bu8z_proj1_proj1.dfy | //Exercicio 1.a)
function sum (a:array<int>, i:int, j:int) :int
decreases j
reads a
requires 0 <= i <= j <= a.Length
{
if i == j then
0
else
a[j-1] + sum(a, i, j-1)
}
//Exercicio 1.b)
method query (a:array<int>, i:int, j:int) returns (s:int)
requires 0 <= i <= j <= a.Length
ensures s == sum(a, ... | //Exercicio 1.a)
function sum (a:array<int>, i:int, j:int) :int
reads a
requires 0 <= i <= j <= a.Length
{
if i == j then
0
else
a[j-1] + sum(a, i, j-1)
}
//Exercicio 1.b)
method query (a:array<int>, i:int, j:int) returns (s:int)
requires 0 <= i <= j <= a.Length
ensures s == sum(a, i, j)
{
... |
017 | CVS-Projto1_tmp_tmpb1o0bu8z_searchSort.dfy | method fillK(a: array<int>, n: int, k: int, c: int) returns (b: bool)
requires 0 <= c <= n
requires n == a.Length
{
if c == 0 {
return true;
}
var p := 0;
while p < c
invariant 0 <= p <= c
{
if a[p] != k
{
return false;
... | method fillK(a: array<int>, n: int, k: int, c: int) returns (b: bool)
requires 0 <= c <= n
requires n == a.Length
{
if c == 0 {
return true;
}
var p := 0;
while p < c
{
if a[p] != k
{
return false;
}
p := p + 1;
... |
018 | CVS-handout1_tmp_tmptm52no3k_1.dfy | /* Cumulative Sums over Arrays */
/*
Daniel Cavalheiro 57869
Pedro Nunes 57854
*/
//(a)
function sum(a: array<int>, i: int, j: int): int
reads a
requires 0 <= i <= j <= a.Length
decreases j - i
{
if (i == ... | /* Cumulative Sums over Arrays */
/*
Daniel Cavalheiro 57869
Pedro Nunes 57854
*/
//(a)
function sum(a: array<int>, i: int, j: int): int
reads a
requires 0 <= i <= j <= a.Length
{
if (i == j) then 0
else a... |
019 | CVS-handout1_tmp_tmptm52no3k_2.dfy | /* Functional Lists and Imperative Arrays */
/*
Daniel Cavalheiro 57869
Pedro Nunes 57854
*/
datatype List<T> = Nil | Cons(head: T, tail: List<T>)
function length<T>(l: List<T>): nat
{
match l
case Nil => 0
case Cons(_... | /* Functional Lists and Imperative Arrays */
/*
Daniel Cavalheiro 57869
Pedro Nunes 57854
*/
datatype List<T> = Nil | Cons(head: T, tail: List<T>)
function length<T>(l: List<T>): nat
{
match l
case Nil => 0
case Cons(_... |
020 | Clover_abs.dfy | method Abs(x: int) returns (y: int)
ensures x>=0 ==> x==y
ensures x<0 ==> x+y==0
{
if x < 0 {
return -x;
} else {
return x;
}
}
| method Abs(x: int) returns (y: int)
ensures x>=0 ==> x==y
ensures x<0 ==> x+y==0
{
if x < 0 {
return -x;
} else {
return x;
}
}
|
021 | Clover_all_digits.dfy | method allDigits(s: string) returns (result: bool)
ensures result <==> (forall i :: 0 <= i < |s| ==> s[i] in "0123456789")
{
result:=true ;
for i := 0 to |s|
invariant result <==> (forall ii :: 0 <= ii < i ==> s[ii] in "0123456789")
{
if ! (s[i] in "0123456789"){
return false;
}
}
}
| method allDigits(s: string) returns (result: bool)
ensures result <==> (forall i :: 0 <= i < |s| ==> s[i] in "0123456789")
{
result:=true ;
for i := 0 to |s|
{
if ! (s[i] in "0123456789"){
return false;
}
}
}
|
022 | Clover_array_append.dfy | method append(a:array<int>, b:int) returns (c:array<int>)
ensures a[..] + [b] == c[..]
{
c := new int[a.Length+1];
var i:= 0;
while (i < a.Length)
invariant 0 <= i <= a.Length
invariant forall ii::0<=ii<i ==> c[ii]==a[ii]
{
c[i] := a[i];
i:=i+1;
}
c[a.Length]:=b;
}
| method append(a:array<int>, b:int) returns (c:array<int>)
ensures a[..] + [b] == c[..]
{
c := new int[a.Length+1];
var i:= 0;
while (i < a.Length)
{
c[i] := a[i];
i:=i+1;
}
c[a.Length]:=b;
}
|
023 | Clover_array_concat.dfy | method concat(a:array<int>, b:array<int>) returns (c:array<int>)
ensures c.Length==b.Length+a.Length
ensures forall k :: 0 <= k < a.Length ==> c[k] == a[k]
ensures forall k :: 0 <= k < b.Length ==> c[k+a.Length] == b[k]
{
c := new int[a.Length+b.Length];
var i:= 0;
while (i < c.Length)
invariant 0 <= i ... | method concat(a:array<int>, b:array<int>) returns (c:array<int>)
ensures c.Length==b.Length+a.Length
ensures forall k :: 0 <= k < a.Length ==> c[k] == a[k]
ensures forall k :: 0 <= k < b.Length ==> c[k+a.Length] == b[k]
{
c := new int[a.Length+b.Length];
var i:= 0;
while (i < c.Length)
{
c[i] := if i<... |
024 | Clover_array_copy.dfy | method iter_copy<T(0)>(s: array<T>) returns (t: array<T>)
ensures s.Length==t.Length
ensures forall i::0<=i<s.Length ==> s[i]==t[i]
{
t := new T[s.Length];
var i:= 0;
while (i < s.Length)
invariant 0 <= i <= s.Length
invariant forall x :: 0 <= x < i ==> s[x] == t[x]
{
t[i] := s[i];
i:=i+1;
... | method iter_copy<T(0)>(s: array<T>) returns (t: array<T>)
ensures s.Length==t.Length
ensures forall i::0<=i<s.Length ==> s[i]==t[i]
{
t := new T[s.Length];
var i:= 0;
while (i < s.Length)
{
t[i] := s[i];
i:=i+1;
}
}
|
025 | Clover_array_product.dfy | method arrayProduct(a: array<int>, b: array<int>) returns (c: array<int> )
requires a.Length==b.Length
ensures c.Length==a.Length
ensures forall i:: 0 <= i< a.Length==> a[i] * b[i]==c[i]
{
c:= new int[a.Length];
var i:=0;
while i<a.Length
invariant 0<=i<=a.Length
invariant forall j:: 0 <= j< i==> a[... | method arrayProduct(a: array<int>, b: array<int>) returns (c: array<int> )
requires a.Length==b.Length
ensures c.Length==a.Length
ensures forall i:: 0 <= i< a.Length==> a[i] * b[i]==c[i]
{
c:= new int[a.Length];
var i:=0;
while i<a.Length
{
c[i]:=a[i]*b[i];
i:=i+1;
}
}
|
026 | Clover_array_sum.dfy | method arraySum(a: array<int>, b: array<int>) returns (c: array<int> )
requires a.Length==b.Length
ensures c.Length==a.Length
ensures forall i:: 0 <= i< a.Length==> a[i] + b[i]==c[i]
{
c:= new int[a.Length];
var i:=0;
while i<a.Length
invariant 0<=i<=a.Length
invariant forall j:: 0 <= j< i==> a[j] +... | method arraySum(a: array<int>, b: array<int>) returns (c: array<int> )
requires a.Length==b.Length
ensures c.Length==a.Length
ensures forall i:: 0 <= i< a.Length==> a[i] + b[i]==c[i]
{
c:= new int[a.Length];
var i:=0;
while i<a.Length
{
c[i]:=a[i]+b[i];
i:=i+1;
}
}
|
027 | Clover_avg.dfy | method ComputeAvg(a: int, b: int) returns (avg:int)
ensures avg == (a+b)/2
{
avg:= (a + b) / 2;
}
| method ComputeAvg(a: int, b: int) returns (avg:int)
ensures avg == (a+b)/2
{
avg:= (a + b) / 2;
}
|
028 | Clover_below_zero.dfy | method below_zero(operations: seq<int>) returns (s:array<int>, result:bool)
ensures s.Length == |operations| + 1
ensures s[0]==0
ensures forall i :: 0 <= i < s.Length-1 ==> s[i+1]==s[i]+operations[i]
ensures result == true ==> (exists i :: 1 <= i <= |operations| && s[i] < 0)
ensures result == false ==> forall... | method below_zero(operations: seq<int>) returns (s:array<int>, result:bool)
ensures s.Length == |operations| + 1
ensures s[0]==0
ensures forall i :: 0 <= i < s.Length-1 ==> s[i+1]==s[i]+operations[i]
ensures result == true ==> (exists i :: 1 <= i <= |operations| && s[i] < 0)
ensures result == false ==> forall... |
029 | Clover_binary_search.dfy | method BinarySearch(a: array<int>, key: int) returns (n: int)
requires forall i,j :: 0<=i<j<a.Length ==> a[i]<=a[j]
ensures 0<= n <=a.Length
ensures forall i :: 0<= i < n ==> a[i] < key
ensures n == a.Length ==> forall i :: 0 <= i < a.Length ==> a[i] < key
ensures forall i :: n<= i < a.Length ==> a[i]>=key
{
... | method BinarySearch(a: array<int>, key: int) returns (n: int)
requires forall i,j :: 0<=i<j<a.Length ==> a[i]<=a[j]
ensures 0<= n <=a.Length
ensures forall i :: 0<= i < n ==> a[i] < key
ensures n == a.Length ==> forall i :: 0 <= i < a.Length ==> a[i] < key
ensures forall i :: n<= i < a.Length ==> a[i]>=key
{
... |
030 | Clover_bubble_sort.dfy | method BubbleSort(a: array<int>)
modifies a
ensures forall i,j::0<= i < j < a.Length ==> a[i] <= a[j]
ensures multiset(a[..])==multiset(old(a[..]))
{
var i := a.Length - 1;
while (i > 0)
invariant i < 0 ==> a.Length == 0
invariant -1 <= i < a.Length
invariant forall ii,jj::i <= ii< jj <a.Length ==... | method BubbleSort(a: array<int>)
modifies a
ensures forall i,j::0<= i < j < a.Length ==> a[i] <= a[j]
ensures multiset(a[..])==multiset(old(a[..]))
{
var i := a.Length - 1;
while (i > 0)
{
var j := 0;
while (j < i)
{
if (a[j] > a[j + 1])
{
a[j], a[j + 1] := a[j + 1], a[j];
... |
031 | Clover_cal_ans.dfy | method CalDiv() returns (x:int, y:int)
ensures x==191/7
ensures y==191%7
{
x, y := 0, 191;
while 7 <= y
invariant 0 <= y && 7 * x + y == 191
{
x := x+1;
y:=191-7*x;
}
}
| method CalDiv() returns (x:int, y:int)
ensures x==191/7
ensures y==191%7
{
x, y := 0, 191;
while 7 <= y
{
x := x+1;
y:=191-7*x;
}
}
|
032 | Clover_cal_sum.dfy | method Sum(N:int) returns (s:int)
requires N >= 0
ensures s == N * (N + 1) / 2
{
var n := 0;
s := 0;
while n != N
invariant 0 <= n <= N
invariant s == n * (n + 1) / 2
{
n := n + 1;
s := s + n;
}
}
| method Sum(N:int) returns (s:int)
requires N >= 0
ensures s == N * (N + 1) / 2
{
var n := 0;
s := 0;
while n != N
{
n := n + 1;
s := s + n;
}
}
|
033 | Clover_canyon_search.dfy | method CanyonSearch(a: array<int>, b: array<int>) returns (d:nat)
requires a.Length !=0 && b.Length!=0
requires forall i,j :: 0<=i<j<a.Length ==> a[i]<=a[j]
requires forall i,j :: 0<=i<j<b.Length ==> b[i]<=b[j]
ensures exists i,j:: 0<=i<a.Length && 0<=j<b.Length && d==if a[i] < b[j] then (b[j]-a[i]) else (a[i]-... | method CanyonSearch(a: array<int>, b: array<int>) returns (d:nat)
requires a.Length !=0 && b.Length!=0
requires forall i,j :: 0<=i<j<a.Length ==> a[i]<=a[j]
requires forall i,j :: 0<=i<j<b.Length ==> b[i]<=b[j]
ensures exists i,j:: 0<=i<a.Length && 0<=j<b.Length && d==if a[i] < b[j] then (b[j]-a[i]) else (a[i]-... |
034 | Clover_compare.dfy | method Compare<T(==)>(a: T, b: T) returns (eq: bool)
ensures a==b ==> eq==true
ensures a!=b ==> eq==false
{
if a == b { eq := true; } else { eq := false; }
}
| method Compare<T(==)>(a: T, b: T) returns (eq: bool)
ensures a==b ==> eq==true
ensures a!=b ==> eq==false
{
if a == b { eq := true; } else { eq := false; }
}
|
035 | Clover_convert_map_key.dfy | method convert_map_key(inputs: map<nat, bool>, f: nat->nat) returns(r:map<nat, bool>)
requires forall n1: nat, n2: nat :: n1 != n2 ==> f(n1) != f(n2)
ensures forall k :: k in inputs <==> f(k) in r
ensures forall k :: k in inputs ==> r[f(k)] == inputs[k]
{
r:= map k | k in inputs :: f(k) := inputs[k];
}
| method convert_map_key(inputs: map<nat, bool>, f: nat->nat) returns(r:map<nat, bool>)
requires forall n1: nat, n2: nat :: n1 != n2 ==> f(n1) != f(n2)
ensures forall k :: k in inputs <==> f(k) in r
ensures forall k :: k in inputs ==> r[f(k)] == inputs[k]
{
r:= map k | k in inputs :: f(k) := inputs[k];
}
|
036 | Clover_copy_part.dfy | method copy( src: array<int>, sStart: nat, dest: array<int>, dStart: nat, len: nat) returns (r: array<int>)
requires src.Length >= sStart + len
requires dest.Length >= dStart + len
ensures r.Length == dest.Length
ensures r[..dStart] == dest[..dStart]
ensures r[dStart + len..] == dest[dStart + len..]
ensures... | method copy( src: array<int>, sStart: nat, dest: array<int>, dStart: nat, len: nat) returns (r: array<int>)
requires src.Length >= sStart + len
requires dest.Length >= dStart + len
ensures r.Length == dest.Length
ensures r[..dStart] == dest[..dStart]
ensures r[dStart + len..] == dest[dStart + len..]
ensures... |
037 | Clover_count_lessthan.dfy | method CountLessThan(numbers: set<int>, threshold: int) returns (count: int)
ensures count == |set i | i in numbers && i < threshold|
{
count := 0;
var shrink := numbers;
var grow := {};
while |shrink | > 0
decreases shrink
invariant shrink + grow == numbers
invariant grow !! shrink
invariant ... | method CountLessThan(numbers: set<int>, threshold: int) returns (count: int)
ensures count == |set i | i in numbers && i < threshold|
{
count := 0;
var shrink := numbers;
var grow := {};
while |shrink | > 0
{
var i: int :| i in shrink;
shrink := shrink - {i};
var grow' := grow+{i};
grow := g... |
038 | Clover_double_array_elements.dfy | method double_array_elements(s: array<int>)
modifies s
ensures forall i :: 0 <= i < s.Length ==> s[i] == 2 * old(s[i])
{
var i:= 0;
while (i < s.Length)
invariant 0 <= i <= s.Length
invariant forall x :: i <= x < s.Length ==> s[x] == old(s[x])
invariant forall x :: 0 <= x < i ==> s[x] == 2 * old(s[x... | method double_array_elements(s: array<int>)
modifies s
ensures forall i :: 0 <= i < s.Length ==> s[i] == 2 * old(s[i])
{
var i:= 0;
while (i < s.Length)
{
s[i] := 2 * s[i];
i := i + 1;
}
} |
039 | Clover_double_quadruple.dfy | method DoubleQuadruple(x: int) returns (a: int, b: int)
ensures a == 2 * x && b == 4 * x
{
a := 2 * x;
b := 2 * a;
}
| method DoubleQuadruple(x: int) returns (a: int, b: int)
ensures a == 2 * x && b == 4 * x
{
a := 2 * x;
b := 2 * a;
}
|
040 | Clover_even_list.dfy | method FindEvenNumbers (arr: array<int>) returns (evenNumbers: array<int>)
ensures forall x {:trigger (x%2) }:: x in arr[..] && (x%2==0)==> x in evenNumbers[..]
ensures forall x :: x !in arr[..] ==> x !in evenNumbers[..]
ensures forall k :: 0 <= k < evenNumbers.Length ==> evenNumbers[k] % 2 == 0
ensures forall... | method FindEvenNumbers (arr: array<int>) returns (evenNumbers: array<int>)
ensures forall x {:trigger (x%2) }:: x in arr[..] && (x%2==0)==> x in evenNumbers[..]
ensures forall x :: x !in arr[..] ==> x !in evenNumbers[..]
ensures forall k :: 0 <= k < evenNumbers.Length ==> evenNumbers[k] % 2 == 0
ensures forall... |
041 | Clover_find.dfy | method Find(a: array<int>, key: int) returns (index: int)
ensures -1<=index<a.Length
ensures index!=-1 ==> a[index]==key && (forall i :: 0 <= i < index ==> a[i] != key)
ensures index == -1 ==> (forall i::0 <= i < a.Length ==> a[i] != key)
{
index := 0;
while index < a.Length
invariant 0<=index<=a.Length
... | method Find(a: array<int>, key: int) returns (index: int)
ensures -1<=index<a.Length
ensures index!=-1 ==> a[index]==key && (forall i :: 0 <= i < index ==> a[i] != key)
ensures index == -1 ==> (forall i::0 <= i < a.Length ==> a[i] != key)
{
index := 0;
while index < a.Length
{
if a[index] == key { retur... |
042 | Clover_has_close_elements.dfy | method has_close_elements(numbers: seq<real>, threshold: real) returns (res: bool)
requires threshold >= 0.0
ensures res ==> exists i: int, j: int :: 0 <= i < |numbers| && 0 <= j < |numbers| && i != j && (if numbers[i] - numbers[j] < 0.0 then numbers[j] - numbers[i] else numbers[i] - numbers[j]) < threshold
ensur... | method has_close_elements(numbers: seq<real>, threshold: real) returns (res: bool)
requires threshold >= 0.0
ensures res ==> exists i: int, j: int :: 0 <= i < |numbers| && 0 <= j < |numbers| && i != j && (if numbers[i] - numbers[j] < 0.0 then numbers[j] - numbers[i] else numbers[i] - numbers[j]) < threshold
ensur... |
043 | Clover_insert.dfy | method insert(line:array<char>, l:int, nl:array<char>, p:int, at:int)
requires 0 <= l+p <= line.Length
requires 0 <= p <= nl.Length
requires 0 <= at <= l
modifies line
ensures forall i :: (0<=i<p) ==> line[at+i] == nl[i]
ensures forall i :: (0<=i<at) ==> line[i] == old(line[i])
ensures forall i :: (at+p<=... | method insert(line:array<char>, l:int, nl:array<char>, p:int, at:int)
requires 0 <= l+p <= line.Length
requires 0 <= p <= nl.Length
requires 0 <= at <= l
modifies line
ensures forall i :: (0<=i<p) ==> line[at+i] == nl[i]
ensures forall i :: (0<=i<at) ==> line[i] == old(line[i])
ensures forall i :: (at+p<=... |
044 | Clover_integer_square_root.dfy | method SquareRoot(N:nat) returns (r:nat)
ensures r*r <= N < (r+1)*(r+1)
{
r:=0;
while (r+1)*(r+1)<=N
invariant r*r<=N
{
r:=r+1;
}
}
| method SquareRoot(N:nat) returns (r:nat)
ensures r*r <= N < (r+1)*(r+1)
{
r:=0;
while (r+1)*(r+1)<=N
{
r:=r+1;
}
}
|
045 | Clover_is_even.dfy | method ComputeIsEven(x:int) returns (is_even:bool)
ensures (x % 2 == 0)==is_even
{
is_even:=false;
if x%2==0{
is_even:=true;
}
}
| method ComputeIsEven(x:int) returns (is_even:bool)
ensures (x % 2 == 0)==is_even
{
is_even:=false;
if x%2==0{
is_even:=true;
}
}
|
046 | Clover_is_palindrome.dfy | method IsPalindrome(x: seq<char>) returns (result: bool)
ensures result <==> (forall i :: 0 <= i < |x| ==> x[i] == x[|x| - i - 1])
{
if |x|==0 {
return true;
}
var i := 0;
var j := |x| - 1;
result := true;
while (i < j)
invariant 0<=i<=j+1 && 0<=j < |x|
invariant i+j==|x|-1
invariant (fora... | method IsPalindrome(x: seq<char>) returns (result: bool)
ensures result <==> (forall i :: 0 <= i < |x| ==> x[i] == x[|x| - i - 1])
{
if |x|==0 {
return true;
}
var i := 0;
var j := |x| - 1;
result := true;
while (i < j)
{
if x[i] != x[j] {
result := false;
return;
}
i := i + ... |
047 | Clover_linear_search1.dfy | method LinearSearch(a: array<int>, e: int) returns (n:int)
ensures 0<=n<=a.Length
ensures n==a.Length || a[n]==e
ensures forall i::0<=i < n ==> e!=a[i]
{
n :=0;
while n!=a.Length
invariant 0<=n<=a.Length
invariant forall i::0<=i<n ==> e!=a[i]
{
if e==a[n]{
return;
}
n:=n+1;
}
}
| method LinearSearch(a: array<int>, e: int) returns (n:int)
ensures 0<=n<=a.Length
ensures n==a.Length || a[n]==e
ensures forall i::0<=i < n ==> e!=a[i]
{
n :=0;
while n!=a.Length
{
if e==a[n]{
return;
}
n:=n+1;
}
}
|
048 | Clover_linear_search2.dfy | method LinearSearch(a: array<int>, e: int) returns (n:int)
requires exists i::0<=i<a.Length && a[i]==e
ensures 0<=n<a.Length && a[n]==e
ensures forall k :: 0 <= k < n ==> a[k]!=e
{
n :=0;
while n!=a.Length
invariant 0<=n<=a.Length
invariant forall i::0<=i<n ==> e!=a[i]
{
if e==a[n]{
retur... | method LinearSearch(a: array<int>, e: int) returns (n:int)
requires exists i::0<=i<a.Length && a[i]==e
ensures 0<=n<a.Length && a[n]==e
ensures forall k :: 0 <= k < n ==> a[k]!=e
{
n :=0;
while n!=a.Length
{
if e==a[n]{
return;
}
n:=n+1;
}
}
|
049 | Clover_linear_search3.dfy | method LinearSearch3<T>(a: array<T>, P: T -> bool) returns (n: int)
requires exists i :: 0 <= i < a.Length && P(a[i])
ensures 0 <= n < a.Length && P(a[n])
ensures forall k :: 0 <= k < n ==> !P(a[k])
{
n := 0;
while true
invariant 0 <= n < a.Length
invariant exists i :: n <= i < a.Length && P(a[i])
... | method LinearSearch3<T>(a: array<T>, P: T -> bool) returns (n: int)
requires exists i :: 0 <= i < a.Length && P(a[i])
ensures 0 <= n < a.Length && P(a[n])
ensures forall k :: 0 <= k < n ==> !P(a[k])
{
n := 0;
while true
{
if P(a[n]) {
return;
}
n := n + 1;
}
}
|
050 | Clover_longest_prefix.dfy | method LongestCommonPrefix(str1: seq<char>, str2: seq<char>) returns (prefix: seq<char>)
ensures |prefix| <= |str1| && prefix == str1[0..|prefix|]&& |prefix| <= |str2| && prefix == str2[0..|prefix|]
ensures |prefix|==|str1| || |prefix|==|str2| || (str1[|prefix|]!=str2[|prefix|])
{
prefix := [];
var minLength :=... | method LongestCommonPrefix(str1: seq<char>, str2: seq<char>) returns (prefix: seq<char>)
ensures |prefix| <= |str1| && prefix == str1[0..|prefix|]&& |prefix| <= |str2| && prefix == str2[0..|prefix|]
ensures |prefix|==|str1| || |prefix|==|str2| || (str1[|prefix|]!=str2[|prefix|])
{
prefix := [];
var minLength :=... |
051 | Clover_match.dfy | method Match(s: string, p: string) returns (b: bool)
requires |s| == |p|
ensures b <==> forall n :: 0 <= n < |s| ==> s[n] == p[n] || p[n] == '?'
{
var i := 0;
while i < |s|
invariant 0 <= i <= |s|
invariant forall n :: 0 <= n < i ==> s[n] == p[n] || p[n] == '?'
{
if s[i] != p[i] && p[i] != '?'
... | method Match(s: string, p: string) returns (b: bool)
requires |s| == |p|
ensures b <==> forall n :: 0 <= n < |s| ==> s[n] == p[n] || p[n] == '?'
{
var i := 0;
while i < |s|
{
if s[i] != p[i] && p[i] != '?'
{
return false;
}
i := i + 1;
}
return true;
}
|
052 | Clover_max_array.dfy | method maxArray(a: array<int>) returns (m: int)
requires a.Length >= 1
ensures forall k :: 0 <= k < a.Length ==> m >= a[k]
ensures exists k :: 0 <= k < a.Length && m == a[k]
{
m := a[0];
var index := 1;
while (index < a.Length)
invariant 0 <= index <= a.Length
invariant forall k :: 0 <= k < index ==... | method maxArray(a: array<int>) returns (m: int)
requires a.Length >= 1
ensures forall k :: 0 <= k < a.Length ==> m >= a[k]
ensures exists k :: 0 <= k < a.Length && m == a[k]
{
m := a[0];
var index := 1;
while (index < a.Length)
{
m := if m>a[index] then m else a[index];
index := index + 1;
}
}
|
053 | Clover_min_array.dfy | method minArray(a: array<int>) returns (r:int)
requires a.Length > 0
ensures forall i :: 0 <= i < a.Length ==> r <= a[i]
ensures exists i :: 0 <= i < a.Length && r == a[i]
{
r:=a[0];
var i:=1;
while i<a.Length
invariant 0 <= i <= a.Length
invariant forall x :: 0 <= x < i ==> r <= a[x]
invariant ... | method minArray(a: array<int>) returns (r:int)
requires a.Length > 0
ensures forall i :: 0 <= i < a.Length ==> r <= a[i]
ensures exists i :: 0 <= i < a.Length && r == a[i]
{
r:=a[0];
var i:=1;
while i<a.Length
{
if r>a[i]{
r:=a[i];
}
i:=i+1;
}
}
|
054 | Clover_min_of_two.dfy | method Min(x: int, y:int) returns (z: int)
ensures x<=y ==> z==x
ensures x>y ==> z==y
{
if x < y {
return x;
} else {
return y;
}
}
| method Min(x: int, y:int) returns (z: int)
ensures x<=y ==> z==x
ensures x>y ==> z==y
{
if x < y {
return x;
} else {
return y;
}
}
|
055 | Clover_modify_2d_array.dfy | method modify_array_element(arr: array<array<nat>>, index1: nat, index2: nat, val: nat)
requires index1 < arr.Length
requires index2 < arr[index1].Length
requires forall i: nat, j:nat :: i < arr.Length && j < arr.Length && i != j ==> arr[i] != arr[j]
modifies arr[index1]
ensures forall i: nat :: 0 <= i < arr.... | method modify_array_element(arr: array<array<nat>>, index1: nat, index2: nat, val: nat)
requires index1 < arr.Length
requires index2 < arr[index1].Length
requires forall i: nat, j:nat :: i < arr.Length && j < arr.Length && i != j ==> arr[i] != arr[j]
modifies arr[index1]
ensures forall i: nat :: 0 <= i < arr.... |
056 | Clover_multi_return.dfy | method MultipleReturns(x: int, y: int) returns (more: int, less: int)
ensures more == x+y
ensures less == x-y
{
more := x + y;
less := x - y;
}
| method MultipleReturns(x: int, y: int) returns (more: int, less: int)
ensures more == x+y
ensures less == x-y
{
more := x + y;
less := x - y;
}
|
057 | Clover_online_max.dfy | method onlineMax(a: array<int>, x: int) returns (ghost m:int, p:int)
requires 1<=x<a.Length
requires a.Length!=0
ensures x<=p<a.Length
ensures forall i::0<=i<x==> a[i]<=m
ensures exists i::0<=i<x && a[i]==m
ensures x<=p<a.Length-1 ==> (forall i::0<=i<p ==> a[i]<a[p])
ensures (forall i::x<=i<a.Length && a[... | method onlineMax(a: array<int>, x: int) returns (ghost m:int, p:int)
requires 1<=x<a.Length
requires a.Length!=0
ensures x<=p<a.Length
ensures forall i::0<=i<x==> a[i]<=m
ensures exists i::0<=i<x && a[i]==m
ensures x<=p<a.Length-1 ==> (forall i::0<=i<p ==> a[i]<a[p])
ensures (forall i::x<=i<a.Length && a[... |
058 | Clover_only_once.dfy | method only_once<T(==)>(a: array<T>, key: T) returns (b:bool)
ensures (multiset(a[..])[key] ==1 ) <==> b
{
var i := 0;
b := false;
var keyCount := 0;
while i < a.Length
invariant 0 <= i <= a.Length
invariant multiset(a[..i])[key] == keyCount
invariant b <==> (keyCount == 1)
{
if (a[i] == key... | method only_once<T(==)>(a: array<T>, key: T) returns (b:bool)
ensures (multiset(a[..])[key] ==1 ) <==> b
{
var i := 0;
b := false;
var keyCount := 0;
while i < a.Length
{
if (a[i] == key)
{
keyCount := keyCount + 1;
}
if (keyCount == 1)
{ b := true; }
else
{ b := false; }
... |
059 | Clover_quotient.dfy | method Quotient(x: nat, y:nat) returns (r:int, q:int)
requires y != 0
ensures q * y + r == x && 0 <= r < y && 0 <= q
{
r:=x;
q:=0;
while y<=r
invariant q*y+r==x && r>=0
decreases r
{
r:=r-y;
q:=q+1;
}
}
| method Quotient(x: nat, y:nat) returns (r:int, q:int)
requires y != 0
ensures q * y + r == x && 0 <= r < y && 0 <= q
{
r:=x;
q:=0;
while y<=r
{
r:=r-y;
q:=q+1;
}
}
|
060 | Clover_remove_front.dfy | method remove_front(a:array<int>) returns (c:array<int>)
requires a.Length>0
ensures a[1..] == c[..]
{
c := new int[a.Length-1];
var i:= 1;
while (i < a.Length)
invariant 1 <= i <= a.Length
invariant forall ii::1<=ii<i ==> c[ii-1]==a[ii]
{
c[i-1] := a[i];
i:=i+1;
}
}
| method remove_front(a:array<int>) returns (c:array<int>)
requires a.Length>0
ensures a[1..] == c[..]
{
c := new int[a.Length-1];
var i:= 1;
while (i < a.Length)
{
c[i-1] := a[i];
i:=i+1;
}
}
|
061 | Clover_replace.dfy | method replace(arr: array<int>, k: int)
modifies arr
ensures forall i :: 0 <= i < arr.Length ==> old(arr[i]) > k ==> arr[i] == -1
ensures forall i :: 0 <= i < arr.Length ==> old(arr[i]) <= k ==> arr[i] == old(arr[i])
{
var i := 0;
while i < arr.Length
decreases arr.Length - i
invariant 0 <= i <= arr.L... | method replace(arr: array<int>, k: int)
modifies arr
ensures forall i :: 0 <= i < arr.Length ==> old(arr[i]) > k ==> arr[i] == -1
ensures forall i :: 0 <= i < arr.Length ==> old(arr[i]) <= k ==> arr[i] == old(arr[i])
{
var i := 0;
while i < arr.Length
{
if arr[i] > k {
arr[i] := -1;
}
i :=... |
062 | Clover_return_seven.dfy | method M(x: int) returns (seven: int)
ensures seven==7
{
seven := 7;
}
| method M(x: int) returns (seven: int)
ensures seven==7
{
seven := 7;
}
|
063 | Clover_reverse.dfy | method reverse(a: array<int>)
modifies a
ensures forall i :: 0 <= i < a.Length ==> a[i] == old(a[a.Length - 1 - i])
{
var i := 0;
while i <a.Length / 2
invariant 0 <= i <= a.Length/2
invariant forall k :: 0 <= k < i || a.Length-1-i < k <= a.Length-1 ==> a[k] == old(a[a.Length-1-k])
invariant forall ... | method reverse(a: array<int>)
modifies a
ensures forall i :: 0 <= i < a.Length ==> a[i] == old(a[a.Length - 1 - i])
{
var i := 0;
while i <a.Length / 2
{
a[i], a[a.Length-1-i] := a[a.Length-1-i], a[i];
i := i + 1;
}
}
|
064 | Clover_rotate.dfy | method rotate(a: array<int>, offset:int) returns (b: array<int> )
requires 0<=offset
ensures b.Length==a.Length
ensures forall i::0<=i<a.Length ==> b[i]==a[(i+offset)%a.Length]
{
b:= new int[a.Length];
var i:=0;
while i<a.Length
invariant 0<=i<=a.Length
invariant forall j ::0<=j<i ==> b[j]==a[(j+o... | method rotate(a: array<int>, offset:int) returns (b: array<int> )
requires 0<=offset
ensures b.Length==a.Length
ensures forall i::0<=i<a.Length ==> b[i]==a[(i+offset)%a.Length]
{
b:= new int[a.Length];
var i:=0;
while i<a.Length
{
b[i]:=a[(i+offset)%a.Length];
i:=i+1;
}
} |
065 | Clover_selectionsort.dfy | method SelectionSort(a: array<int>)
modifies a
ensures forall i,j :: 0 <= i < j < a.Length ==> a[i] <= a[j]
ensures multiset(a[..]) == old(multiset(a[..]))
{
var n:= 0;
while n != a.Length
invariant 0 <= n <= a.Length
invariant forall i, j :: 0 <= i < n <= j < a.Length ==> a[i] <= a[j]
invariant f... | method SelectionSort(a: array<int>)
modifies a
ensures forall i,j :: 0 <= i < j < a.Length ==> a[i] <= a[j]
ensures multiset(a[..]) == old(multiset(a[..]))
{
var n:= 0;
while n != a.Length
{
var mindex, m := n, n+1;
while m != a.Length
{
if a[m] < a[mindex] {
mindex := m;
}
... |
066 | Clover_seq_to_array.dfy | method ToArray<T>(xs: seq<T>) returns (a: array<T>)
ensures fresh(a)
ensures a.Length == |xs|
ensures forall i :: 0 <= i < |xs| ==> a[i] == xs[i]
{
a := new T[|xs|](i requires 0 <= i < |xs| => xs[i]);
}
| method ToArray<T>(xs: seq<T>) returns (a: array<T>)
ensures fresh(a)
ensures a.Length == |xs|
ensures forall i :: 0 <= i < |xs| ==> a[i] == xs[i]
{
a := new T[|xs|](i requires 0 <= i < |xs| => xs[i]);
}
|
067 | Clover_set_to_seq.dfy | method SetToSeq<T>(s: set<T>) returns (xs: seq<T>)
ensures multiset(s) == multiset(xs)
{
xs := [];
var left: set<T> := s;
while left != {}
invariant multiset(left) + multiset(xs) == multiset(s)
{
var x :| x in left;
left := left - {x};
xs := xs + [x];
}
}
| method SetToSeq<T>(s: set<T>) returns (xs: seq<T>)
ensures multiset(s) == multiset(xs)
{
xs := [];
var left: set<T> := s;
while left != {}
{
var x :| x in left;
left := left - {x};
xs := xs + [x];
}
}
|
068 | Clover_slope_search.dfy | method SlopeSearch(a: array2<int>, key: int) returns (m:int, n:int)
requires forall i,j,j'::0<=i<a.Length0 && 0<=j<j'<a.Length1 ==> a[i,j]<=a[i,j']
requires forall i,i',j::0<=i<i'<a.Length0 && 0<=j<a.Length1 ==> a[i,j]<=a[i',j]
requires exists i,j :: 0<=i<a.Length0 && 0<=j<a.Length1 && a[i,j]==key
ensures 0<=m<... | method SlopeSearch(a: array2<int>, key: int) returns (m:int, n:int)
requires forall i,j,j'::0<=i<a.Length0 && 0<=j<j'<a.Length1 ==> a[i,j]<=a[i,j']
requires forall i,i',j::0<=i<i'<a.Length0 && 0<=j<a.Length1 ==> a[i,j]<=a[i',j]
requires exists i,j :: 0<=i<a.Length0 && 0<=j<a.Length1 && a[i,j]==key
ensures 0<=m<... |
069 | Clover_swap.dfy | method Swap(X: int, Y: int) returns(x: int, y: int)
ensures x==Y
ensures y==X
{
x, y := X, Y;
var tmp := x;
x := y;
y := tmp;
assert x == Y && y == X;
}
| method Swap(X: int, Y: int) returns(x: int, y: int)
ensures x==Y
ensures y==X
{
x, y := X, Y;
var tmp := x;
x := y;
y := tmp;
}
|
070 | Clover_swap_arith.dfy | method SwapArithmetic(X: int, Y: int) returns(x: int, y: int)
ensures x==Y
ensures y==X
{
x, y := X, Y;
x := y - x;
y := y - x;
x := y + x;
}
| method SwapArithmetic(X: int, Y: int) returns(x: int, y: int)
ensures x==Y
ensures y==X
{
x, y := X, Y;
x := y - x;
y := y - x;
x := y + x;
}
|
071 | Clover_swap_bitvector.dfy | method SwapBitvectors(X: bv8, Y: bv8) returns(x: bv8, y: bv8)
ensures x==Y
ensures y==X
{
x, y := X, Y;
x := x ^ y;
y := x ^ y;
x := x ^ y;
}
| method SwapBitvectors(X: bv8, Y: bv8) returns(x: bv8, y: bv8)
ensures x==Y
ensures y==X
{
x, y := X, Y;
x := x ^ y;
y := x ^ y;
x := x ^ y;
}
|
072 | Clover_swap_in_array.dfy | method swap(arr: array<int>, i: int, j: int)
requires 0 <= i < arr.Length && 0 <= j < arr.Length
modifies arr
ensures arr[i] == old(arr[j]) && arr[j] == old(arr[i])
ensures forall k :: 0 <= k < arr.Length && k != i && k != j ==> arr[k] == old(arr[k])
{
var tmp := arr[i];
arr[i] := arr[j];
arr[j] := tmp;
}... | method swap(arr: array<int>, i: int, j: int)
requires 0 <= i < arr.Length && 0 <= j < arr.Length
modifies arr
ensures arr[i] == old(arr[j]) && arr[j] == old(arr[i])
ensures forall k :: 0 <= k < arr.Length && k != i && k != j ==> arr[k] == old(arr[k])
{
var tmp := arr[i];
arr[i] := arr[j];
arr[j] := tmp;
}... |
073 | Clover_swap_sim.dfy | method SwapSimultaneous(X: int, Y: int) returns(x: int, y: int)
ensures x==Y
ensures y==X
{
x, y := X, Y;
x, y := y, x;
}
| method SwapSimultaneous(X: int, Y: int) returns(x: int, y: int)
ensures x==Y
ensures y==X
{
x, y := X, Y;
x, y := y, x;
}
|
074 | Clover_test_array.dfy | method TestArrayElements(a:array<int>, j: nat)
requires 0<=j < a.Length
modifies a
ensures a[j] == 60
ensures forall k :: 0 <= k < a.Length && k != j ==> a[k] == old(a[k])
{
a[j] := 60;
}
| method TestArrayElements(a:array<int>, j: nat)
requires 0<=j < a.Length
modifies a
ensures a[j] == 60
ensures forall k :: 0 <= k < a.Length && k != j ==> a[k] == old(a[k])
{
a[j] := 60;
}
|
075 | Clover_triple.dfy | method Triple (x:int) returns (r:int)
ensures r==3*x
{
r:= x*3;
}
| method Triple (x:int) returns (r:int)
ensures r==3*x
{
r:= x*3;
}
|
076 | Clover_triple2.dfy | method Triple (x:int) returns (r:int)
ensures r==3*x
{
if {
case x<18 =>
var a,b := 2*x, 4*x;
r:=(a+b)/2;
case 0<=x =>
var y:=2*x;
r:= x+y;
}
}
| method Triple (x:int) returns (r:int)
ensures r==3*x
{
if {
case x<18 =>
var a,b := 2*x, 4*x;
r:=(a+b)/2;
case 0<=x =>
var y:=2*x;
r:= x+y;
}
}
|
077 | Clover_triple3.dfy | method Triple (x:int) returns (r:int)
ensures r==3*x
{
if x==0 {
r:=0;
}
else{
var y:=2*x;
r:= x+y;
}
}
| method Triple (x:int) returns (r:int)
ensures r==3*x
{
if x==0 {
r:=0;
}
else{
var y:=2*x;
r:= x+y;
}
}
|
078 | Clover_triple4.dfy | method Triple (x:int) returns (r:int)
ensures r==3*x
{
var y:= x*2;
r := y+x;
}
| method Triple (x:int) returns (r:int)
ensures r==3*x
{
var y:= x*2;
r := y+x;
}
|
079 | Clover_two_sum.dfy | method twoSum(nums: array<int>, target: int) returns (i: int, j: int)
requires nums.Length > 1
requires exists i,j::0 <= i < j < nums.Length && nums[i] + nums[j] == target
ensures 0 <= i < j < nums.Length && nums[i] + nums[j] == target
ensures forall ii,jj:: (0 <= ii < i && ii < jj < nums.Length) ==> nums[ii]... | method twoSum(nums: array<int>, target: int) returns (i: int, j: int)
requires nums.Length > 1
requires exists i,j::0 <= i < j < nums.Length && nums[i] + nums[j] == target
ensures 0 <= i < j < nums.Length && nums[i] + nums[j] == target
ensures forall ii,jj:: (0 <= ii < i && ii < jj < nums.Length) ==> nums[ii]... |
080 | Clover_update_array.dfy | method UpdateElements(a: array<int>)
requires a.Length >= 8
modifies a
ensures old(a[4]) +3 == a[4]
ensures a[7]==516
ensures forall i::0 <= i<a.Length ==> i != 7 && i != 4 ==> a[i] == old(a[i])
{
a[4] := a[4] + 3;
a[7] := 516;
}
| method UpdateElements(a: array<int>)
requires a.Length >= 8
modifies a
ensures old(a[4]) +3 == a[4]
ensures a[7]==516
ensures forall i::0 <= i<a.Length ==> i != 7 && i != 4 ==> a[i] == old(a[i])
{
a[4] := a[4] + 3;
a[7] := 516;
}
|
081 | Clover_update_map.dfy | method update_map<K(!new), V>(m1: map<K, V>, m2: map<K, V>) returns (r: map<K, V>)
ensures (forall k :: k in m2 ==> k in r)
ensures (forall k :: k in m1 ==> k in r)
ensures (forall k :: k in m2 ==> r[k] == m2[k])
ensures (forall k :: !(k in m2) && k in m1 ==> r[k] == m1[k])
ensures (forall k :: !(k in m2) ... | method update_map<K(!new), V>(m1: map<K, V>, m2: map<K, V>) returns (r: map<K, V>)
ensures (forall k :: k in m2 ==> k in r)
ensures (forall k :: k in m1 ==> k in r)
ensures (forall k :: k in m2 ==> r[k] == m2[k])
ensures (forall k :: !(k in m2) && k in m1 ==> r[k] == m1[k])
ensures (forall k :: !(k in m2) ... |
082 | Correctness_tmp_tmpwqvg5q_4_HoareLogic_exam.dfy | // Redo for exam
function gcd(a: nat, b: nat): nat
lemma r1(a: nat)
ensures gcd(a, 0) == a
lemma r2(a:nat)
ensures gcd(a, a) == a
lemma r3(a: nat, b: nat)
ensures gcd(a, b) == gcd(b, a)
lemma r4 (a: nat, b: nat)
ensures b > 0 ==> gcd(a, b) == gcd(b, a % b)
method GCD1(a: int, b: int) returns (r: i... | // Redo for exam
function gcd(a: nat, b: nat): nat
lemma r1(a: nat)
ensures gcd(a, 0) == a
lemma r2(a:nat)
ensures gcd(a, a) == a
lemma r3(a: nat, b: nat)
ensures gcd(a, b) == gcd(b, a)
lemma r4 (a: nat, b: nat)
ensures b > 0 ==> gcd(a, b) == gcd(b, a % b)
method GCD1(a: int, b: int) returns (r: i... |
083 | Correctness_tmp_tmpwqvg5q_4_MethodCalls_q1.dfy | /**
(a) Verify whether or not the following program
satisfies total correctness.
You should use weakest precondition reasoning
and may extend the loop invariant if required.
You will need to add a decreases clause to prove termination
(a) Weakest precondition proof (without termination) (6 m... | /**
(a) Verify whether or not the following program
satisfies total correctness.
You should use weakest precondition reasoning
and may extend the loop invariant if required.
You will need to add a decreases clause to prove termination
(a) Weakest precondition proof (without termination) (6 m... |
084 | Correctness_tmp_tmpwqvg5q_4_Sorting_Tangent.dfy | /**
Ather, Mohammad Faiz (s4648481/3)
CSSE3100
Assignemnt 3
The University of Queensland
*/
// Question 1
method Tangent(r: array<int>, x: array<int>)
returns (found: bool)
requires forall i:: 1 <= i < x.Length ==>
x[i-1] < x[i]
requires forall i, j ::
0 <= i < j < x.Length ==>
... | /**
Ather, Mohammad Faiz (s4648481/3)
CSSE3100
Assignemnt 3
The University of Queensland
*/
// Question 1
method Tangent(r: array<int>, x: array<int>)
returns (found: bool)
requires forall i:: 1 <= i < x.Length ==>
x[i-1] < x[i]
requires forall i, j ::
0 <= i < j < x.Length ==>
... |
085 | Dafny-Exercises_tmp_tmpjm75muf__Session10Exercises_ExerciseBarrier.dfy |
//Method barrier below receives an array and an integer p
//and returns a boolean b which is true if and only if
//all the positions to the left of p and including also position p contain elements
//that are strictly smaller than all the elements contained in the positions to the right of p
//Examples:
// If v=[... |
//Method barrier below receives an array and an integer p
//and returns a boolean b which is true if and only if
//all the positions to the left of p and including also position p contain elements
//that are strictly smaller than all the elements contained in the positions to the right of p
//Examples:
// If v=[... |
086 | Dafny-Exercises_tmp_tmpjm75muf__Session2Exercises_ExerciseExp.dfy | function exp(x:int, e:int):int
decreases e
requires e >= 0
ensures x > 0 ==> exp(x,e) > 0
{
if e == 0 then 1 else x*exp(x,e-1)
}
lemma exp3_Lemma(n:int)
decreases n
requires n >= 1
ensures (exp(3,n)-1)%2 == 0
{}
lemma mult8_Lemma(n:int)
decreases n
requires n >= 1
ensures (exp(3,2*n) - 1)%... | function exp(x:int, e:int):int
requires e >= 0
ensures x > 0 ==> exp(x,e) > 0
{
if e == 0 then 1 else x*exp(x,e-1)
}
lemma exp3_Lemma(n:int)
requires n >= 1
ensures (exp(3,n)-1)%2 == 0
{}
lemma mult8_Lemma(n:int)
requires n >= 1
ensures (exp(3,2*n) - 1)%8 == 0
{
if(n==1){
}
else{
... |
087 | Dafny-Exercises_tmp_tmpjm75muf__Session2Exercises_ExerciseFibonacci.dfy | function fib(n: nat): nat
decreases n
{
if n == 0 then 0 else
if n == 1 then 1 else
fib(n - 1) + fib(n - 2)
}
method fibonacci1(n:nat) returns (f:nat)
ensures f==fib(n)
{
var i := 0;
f := 0;
var fsig := 1;
while i < n
decreases n - i//write the bound
invariant f==fib(i) ... | function fib(n: nat): nat
{
if n == 0 then 0 else
if n == 1 then 1 else
fib(n - 1) + fib(n - 2)
}
method fibonacci1(n:nat) returns (f:nat)
ensures f==fib(n)
{
var i := 0;
f := 0;
var fsig := 1;
while i < n
{
f, fsig := fsig, f + fsig;
i := i + 1;
}
}
method fibona... |
088 | Dafny-Exercises_tmp_tmpjm75muf__Session2Exercises_ExercisePositive.dfy | predicate positive(s:seq<int>)
{forall u::0<=u<|s| ==> s[u]>=0}
method mpositive(v:array<int>) returns (b:bool)
ensures b==positive(v[0..v.Length])
{
var i:=0;
//1. assert positive(v[..0])
while i<v.Length && v[i]>=0
decreases v.Length - i
invariant 0<=i<=v.Length
invariant positi... | predicate positive(s:seq<int>)
{forall u::0<=u<|s| ==> s[u]>=0}
method mpositive(v:array<int>) returns (b:bool)
ensures b==positive(v[0..v.Length])
{
var i:=0;
//1. assert positive(v[..0])
while i<v.Length && v[i]>=0
{
//2. assert 0<=i<v.Length && positive(v[..i]);
i:=i+1;
//2.... |
089 | Dafny-Exercises_tmp_tmpjm75muf__Session2Exercises_ExerciseSquare_root.dfy | method mroot1(n:int) returns (r:int) //Cost O(root n)
requires n>=0
ensures r>=0 && r*r <= n <(r+1)*(r+1)
{
r:=0;
while (r+1)*(r+1) <=n
invariant r>=0 && r*r <=n
decreases n-r*r
{
r:=r+1;
}
}
method mroot2(n:int) returns (r:int) //Cost O(n)
requires n>=0
ensures r>=0 && r*r <= n <(r+1)*(r+1)
{
... | method mroot1(n:int) returns (r:int) //Cost O(root n)
requires n>=0
ensures r>=0 && r*r <= n <(r+1)*(r+1)
{
r:=0;
while (r+1)*(r+1) <=n
{
r:=r+1;
}
}
method mroot2(n:int) returns (r:int) //Cost O(n)
requires n>=0
ensures r>=0 && r*r <= n <(r+1)*(r+1)
{
r:=n;
while n<r*r
{
r:=r-1;
}
}
method... |
090 | Dafny-Exercises_tmp_tmpjm75muf__Session3Exercises_ExerciseMaximum.dfy | //Algorithm 1: From left to right return the first
method mmaximum1(v:array<int>) returns (i:int)
requires v.Length>0
ensures 0<=i<v.Length
ensures forall k:: 0<=k<v.Length ==> v[i]>=v[k]
{
var j:=1; i:=0;
while(j<v.Length)
decreases v.Length - j
invariant 0<=j<=v.Length
invariant 0<=i... | //Algorithm 1: From left to right return the first
method mmaximum1(v:array<int>) returns (i:int)
requires v.Length>0
ensures 0<=i<v.Length
ensures forall k:: 0<=k<v.Length ==> v[i]>=v[k]
{
var j:=1; i:=0;
while(j<v.Length)
{
if(v[j] > v[i]){i:=j;}
j:=j+1;
}
}
//Algorithm 2: From righ... |
091 | Dafny-Exercises_tmp_tmpjm75muf__Session4Exercises_ExerciseAllEqual.dfy | predicate allEqual(s:seq<int>)
{forall i,j::0<=i<|s| && 0<=j<|s| ==> s[i]==s[j] }
//{forall i,j::0<=i<=j<|s| ==> s[i]==s[j] }
//{forall i::0<i<|s| ==> s[i-1]==s[i]}
//{forall i::0<=i<|s|-1 ==> s[i]==s[i+1]}
//Ordered indexes
lemma equivalenceNoOrder(s:seq<int>)
ensures allEqual(s) <==> forall i,j::0<=i<=j<|s| ==> s[... | predicate allEqual(s:seq<int>)
{forall i,j::0<=i<|s| && 0<=j<|s| ==> s[i]==s[j] }
//{forall i,j::0<=i<=j<|s| ==> s[i]==s[j] }
//{forall i::0<i<|s| ==> s[i-1]==s[i]}
//{forall i::0<=i<|s|-1 ==> s[i]==s[i+1]}
//Ordered indexes
lemma equivalenceNoOrder(s:seq<int>)
ensures allEqual(s) <==> forall i,j::0<=i<=j<|s| ==> s[... |
092 | Dafny-Exercises_tmp_tmpjm75muf__Session4Exercises_ExerciseContained.dfy |
predicate strictSorted(s : seq<int>) {
forall u, w :: 0 <= u < w < |s| ==> s[u] < s[w]
}
method mcontained(v:array<int>,w:array<int>,n:int,m:int) returns (b:bool)
//Specify and implement an O(m+n) algorithm that returns b
//v and w are strictly increasing ordered arrays
//b is true iff the first n elements of v a... |
predicate strictSorted(s : seq<int>) {
forall u, w :: 0 <= u < w < |s| ==> s[u] < s[w]
}
method mcontained(v:array<int>,w:array<int>,n:int,m:int) returns (b:bool)
//Specify and implement an O(m+n) algorithm that returns b
//v and w are strictly increasing ordered arrays
//b is true iff the first n elements of v a... |
093 | Dafny-Exercises_tmp_tmpjm75muf__Session4Exercises_ExerciseFirstNegative.dfy | predicate positive(s:seq<int>)
{forall u::0<=u<|s| ==> s[u]>=0}
method mfirstNegative(v:array<int>) returns (b:bool, i:int)
ensures b <==> exists k::0<=k<v.Length && v[k]<0
ensures b ==> 0<=i<v.Length && v[i]<0 && positive(v[0..i])
{
i:=0;
b:=false;
while (i<v.Length && !b)
invariant 0<=i<=v.Length
invari... | predicate positive(s:seq<int>)
{forall u::0<=u<|s| ==> s[u]>=0}
method mfirstNegative(v:array<int>) returns (b:bool, i:int)
ensures b <==> exists k::0<=k<v.Length && v[k]<0
ensures b ==> 0<=i<v.Length && v[i]<0 && positive(v[0..i])
{
i:=0;
b:=false;
while (i<v.Length && !b)
{
b:=(v[i]<0);
i:=i+1;
}
... |
094 | Dafny-Exercises_tmp_tmpjm75muf__Session4Exercises_ExercisefirstZero.dfy |
method mfirstCero(v:array<int>) returns (i:int)
ensures 0 <=i<=v.Length
ensures forall j:: 0<=j<i ==> v[j]!=0
ensures i!=v.Length ==> v[i]==0
{
i:=0;
while (i<v.Length && v[i]!=0)
invariant 0<=i<=v.Length
invariant forall j:: 0<=j<i ==> v[j]!=0
decreases v.Length -i
{i:=i+1;}
}
|
method mfirstCero(v:array<int>) returns (i:int)
ensures 0 <=i<=v.Length
ensures forall j:: 0<=j<i ==> v[j]!=0
ensures i!=v.Length ==> v[i]==0
{
i:=0;
while (i<v.Length && v[i]!=0)
{i:=i+1;}
}
|
095 | Dafny-Exercises_tmp_tmpjm75muf__Session5Exercises_ExerciseSumElems.dfy | function SumR(s:seq<int>):int
decreases s
{
if (s==[]) then 0
else SumR(s[..|s|-1])+s[|s|-1]
}
function SumL(s:seq<int>):int
decreases s
{
if (s==[]) then 0
else s[0]+SumL(s[1..])
}
lemma concatLast(s:seq<int>,t:seq<int>)
requires t!=[]
ensures (s+t)[..|s+t|-1] == s+(t[..|t|-1])
{}
lemma concatFirst(... | function SumR(s:seq<int>):int
{
if (s==[]) then 0
else SumR(s[..|s|-1])+s[|s|-1]
}
function SumL(s:seq<int>):int
{
if (s==[]) then 0
else s[0]+SumL(s[1..])
}
lemma concatLast(s:seq<int>,t:seq<int>)
requires t!=[]
ensures (s+t)[..|s+t|-1] == s+(t[..|t|-1])
{}
lemma concatFirst(s:seq<int>,t:seq<int>)
r... |
096 | Dafny-Exercises_tmp_tmpjm75muf__Session6Exercises_ExerciseCountEven.dfy |
predicate positive(s:seq<int>)
{forall u::0<=u<|s| ==> s[u]>=0}
predicate isEven(i:int)
requires i>=0
{i%2==0}
function CountEven(s:seq<int>):int
decreases s
requires positive(s)
{if s==[] then 0
else (if (s[|s|-1]%2==0) then 1 else 0)+CountEven(s[..|s|-1])
}
lemma ArrayFacts<T>()
ensures forall v : array<T> ::... |
predicate positive(s:seq<int>)
{forall u::0<=u<|s| ==> s[u]>=0}
predicate isEven(i:int)
requires i>=0
{i%2==0}
function CountEven(s:seq<int>):int
requires positive(s)
{if s==[] then 0
else (if (s[|s|-1]%2==0) then 1 else 0)+CountEven(s[..|s|-1])
}
lemma ArrayFacts<T>()
ensures forall v : array<T> :: v[..v.Lengt... |
097 | Dafny-Exercises_tmp_tmpjm75muf__Session6Exercises_ExerciseCountMin.dfy | function min(v:array<int>,i:int):int
decreases i
reads v
requires 1<=i<=v.Length
ensures forall k::0<=k<i==> v[k]>=min(v,i)
{if (i==1) then v[0]
else if (v[i-1]<=min(v,i-1)) then v[i-1]
else min(v,i-1)
}
function countMin(v:array<int>,x:int, i:int):int
decreases i
reads v
requires 0<=i<=v.Length
ensure... | function min(v:array<int>,i:int):int
reads v
requires 1<=i<=v.Length
ensures forall k::0<=k<i==> v[k]>=min(v,i)
{if (i==1) then v[0]
else if (v[i-1]<=min(v,i-1)) then v[i-1]
else min(v,i-1)
}
function countMin(v:array<int>,x:int, i:int):int
reads v
requires 0<=i<=v.Length
ensures !(x in v[0..i]) ==> co... |
098 | Dafny-Exercises_tmp_tmpjm75muf__Session6Exercises_ExercisePeekSum.dfy |
predicate isPeek(v:array<int>,i:int)
reads v
requires 0<=i<v.Length
{forall k::0<=k<i ==> v[i]>=v[k]}
function peekSum(v:array<int>,i:int):int
decreases i
reads v
requires 0<=i<=v.Length
{
if (i==0) then 0
else if isPeek(v,i-1) then v[i-1]+peekSum(v,i-1)
else peekSum(v,i-1)
}
method mPeekSum(v:ar... |
predicate isPeek(v:array<int>,i:int)
reads v
requires 0<=i<v.Length
{forall k::0<=k<i ==> v[i]>=v[k]}
function peekSum(v:array<int>,i:int):int
reads v
requires 0<=i<=v.Length
{
if (i==0) then 0
else if isPeek(v,i-1) then v[i-1]+peekSum(v,i-1)
else peekSum(v,i-1)
}
method mPeekSum(v:array<int>) retu... |
099 | Dafny-Exercises_tmp_tmpjm75muf__Session7Exercises_ExerciseBinarySearch.dfy | predicate sorted(s : seq<int>) {
forall u, w :: 0 <= u < w < |s| ==> s[u] <= s[w]
}
method binarySearch(v:array<int>, elem:int) returns (p:int)
requires sorted(v[0..v.Length])
ensures -1<=p<v.Length
ensures (forall u::0<=u<=p ==> v[u]<=elem) && (forall w::p<w<v.Length ==> v[w]>elem)
{
var c,f:=0,v.Length-1;
w... | predicate sorted(s : seq<int>) {
forall u, w :: 0 <= u < w < |s| ==> s[u] <= s[w]
}
method binarySearch(v:array<int>, elem:int) returns (p:int)
requires sorted(v[0..v.Length])
ensures -1<=p<v.Length
ensures (forall u::0<=u<=p ==> v[u]<=elem) && (forall w::p<w<v.Length ==> v[w]>elem)
{
var c,f:=0,v.Length-1;
w... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.