test_ID
stringlengths
3
3
test_file
stringlengths
14
119
ground_truth
stringlengths
70
28.7k
hints_removed
stringlengths
58
28.7k
200
Dafny_tmp_tmpmvs2dmry_examples2.dfy
method add_by_inc(x: nat, y:nat) returns (z:nat) ensures z == x+y; { z := x; var i := 0; while (i < y) decreases y-i; invariant 0 <= i <= y; invariant z == x + i; { z := z+1; i := i+1; } assert (z == x+y); assert (i == y); } method Product(m: nat, n:nat) return...
method add_by_inc(x: nat, y:nat) returns (z:nat) ensures z == x+y; { z := x; var i := 0; while (i < y) { z := z+1; i := i+1; } } method Product(m: nat, n:nat) returns (res:nat) ensures res == m*n; { var m1: nat := m; res:=0; while (m1 != 0) { var n1: na...
201
Dafny_tmp_tmpmvs2dmry_pancakesort_findmax.dfy
// returns an index of the largest element of array 'a' in the range [0..n) method findMax (a : array<int>, n : int) returns (r:int) requires a.Length > 0 requires 0 < n <= a.Length ensures 0 <= r < n <= a.Length; ensures forall k :: 0 <= k < n <= a.Length ==> a[r] >= a[k]; ensures multiset(a[..]) == multiset(old(a[..]...
// returns an index of the largest element of array 'a' in the range [0..n) method findMax (a : array<int>, n : int) returns (r:int) requires a.Length > 0 requires 0 < n <= a.Length ensures 0 <= r < n <= a.Length; ensures forall k :: 0 <= k < n <= a.Length ==> a[r] >= a[k]; ensures multiset(a[..]) == multiset(old(a[..]...
202
Dafny_tmp_tmpmvs2dmry_pancakesort_flip.dfy
// flips (i.e., reverses) array elements in the range [0..num] method flip (a: array<int>, num: int) requires a.Length > 0; requires 0 <= num < a.Length; modifies a; ensures forall k :: 0 <= k <= num ==> a[k] == old(a[num-k]) ensures forall k :: num < k < a.Length ==> a[k] == old(a[k]) // ensures multiset(a[..]) == old...
// flips (i.e., reverses) array elements in the range [0..num] method flip (a: array<int>, num: int) requires a.Length > 0; requires 0 <= num < a.Length; modifies a; ensures forall k :: 0 <= k <= num ==> a[k] == old(a[num-k]) ensures forall k :: num < k < a.Length ==> a[k] == old(a[k]) // ensures multiset(a[..]) == old...
203
Dafny_tmp_tmpv_d3qi10_2_min.dfy
function min(a: int, b: int): int ensures min(a, b) <= a && min(a, b) <= b ensures min(a, b) == a || min(a, b) == b { if a < b then a else b } method minMethod(a: int, b: int) returns (c: int) ensures c <= a && c <= b ensures c == a || c == b // Ou encore: ensures c == min(a, b) { if a...
function min(a: int, b: int): int ensures min(a, b) <= a && min(a, b) <= b ensures min(a, b) == a || min(a, b) == b { if a < b then a else b } method minMethod(a: int, b: int) returns (c: int) ensures c <= a && c <= b ensures c == a || c == b // Ou encore: ensures c == min(a, b) { if a...
204
Dafny_tmp_tmpv_d3qi10_3_cumsum.dfy
function sum(a: array<int>, i: int): int requires 0 <= i < a.Length reads a { a[i] + if i == 0 then 0 else sum(a, i - 1) } method cumsum(a: array<int>, b: array<int>) requires a.Length == b.Length && a.Length > 0 && a != b // when you change a , that's not the same object than b . //requires...
function sum(a: array<int>, i: int): int requires 0 <= i < a.Length reads a { a[i] + if i == 0 then 0 else sum(a, i - 1) } method cumsum(a: array<int>, b: array<int>) requires a.Length == b.Length && a.Length > 0 && a != b // when you change a , that's not the same object than b . //requires...
205
FMSE-2022-2023_tmp_tmp6_x_ba46_Lab10_Lab10.dfy
predicate IsOdd(x: int) { x % 2 == 1 } newtype Odd = n : int | IsOdd(n) witness 3 trait OddListSpec { var s: seq<Odd> var capacity: nat predicate Valid() reads this { 0 <= |s| <= this.capacity && forall i :: 0 <= i < |s| ==> IsOdd(s[i] as int) } method insert(inde...
predicate IsOdd(x: int) { x % 2 == 1 } newtype Odd = n : int | IsOdd(n) witness 3 trait OddListSpec { var s: seq<Odd> var capacity: nat predicate Valid() reads this { 0 <= |s| <= this.capacity && forall i :: 0 <= i < |s| ==> IsOdd(s[i] as int) } method insert(inde...
206
FMSE-2022-2023_tmp_tmp6_x_ba46_Lab1_Lab1.dfy
/// Types defined as part of Tasks 3, 5 and 9 // Since we have created the IsOddNat predicate we use it to define the new Odd subsort newtype Odd = n : int | IsOddNat(n) witness 1 // Since we have created the IsEvenNat predicate we use it to define the new Even subsort newtype Even = n : int | IsEvenNat(n) witness 2 ...
/// Types defined as part of Tasks 3, 5 and 9 // Since we have created the IsOddNat predicate we use it to define the new Odd subsort newtype Odd = n : int | IsOddNat(n) witness 1 // Since we have created the IsEvenNat predicate we use it to define the new Even subsort newtype Even = n : int | IsEvenNat(n) witness 2 ...
207
FMSE-2022-2023_tmp_tmp6_x_ba46_Lab2_Lab2.dfy
/* * Task 2: Define the natural numbers as an algebraic data type * * Being an inductive data type, it's required that we have a base case constructor and an inductive one. */ datatype Nat = Zero | S(Pred: Nat) /// Task 2 // Exercise (a'): proving that the successor constructor is injective /* * It's known that ...
/* * Task 2: Define the natural numbers as an algebraic data type * * Being an inductive data type, it's required that we have a base case constructor and an inductive one. */ datatype Nat = Zero | S(Pred: Nat) /// Task 2 // Exercise (a'): proving that the successor constructor is injective /* * It's known that ...
208
FMSE-2022-2023_tmp_tmp6_x_ba46_Lab3_Lab3.dfy
/* * Task 2: Define in Dafny the conatural numbers as a coinductive datatype * * Being a coinductive data type, it's required that we have a base case constructor and an inductive one * (as is the case with inductive ones as well) */ codatatype Conat = Zero | Succ(Pred: Conat) // Exercise (a): explain why the f...
/* * Task 2: Define in Dafny the conatural numbers as a coinductive datatype * * Being a coinductive data type, it's required that we have a base case constructor and an inductive one * (as is the case with inductive ones as well) */ codatatype Conat = Zero | Succ(Pred: Conat) // Exercise (a): explain why the f...
209
Final-Project-Dafny_tmp_tmpmcywuqox_Attempts_Exercise3_Increment_Array.dfy
method incrementArray(a:array<int>) requires a.Length > 0 ensures forall i :: 0 <= i < a.Length ==> a[i] == old(a[i]) + 1 modifies a { var j : int := 0; while(j < a.Length) invariant 0 <= j <= a.Length invariant forall i :: j <= i < a.Length ==> a[i] == old(a[i]) invariant forall i :: 0 <= i < j =...
method incrementArray(a:array<int>) requires a.Length > 0 ensures forall i :: 0 <= i < a.Length ==> a[i] == old(a[i]) + 1 modifies a { var j : int := 0; while(j < a.Length) { a[j] := a[j] + 1; j := j+1; } }
210
Final-Project-Dafny_tmp_tmpmcywuqox_Attempts_Exercise4_Find_Max.dfy
method findMax(a:array<int>) returns (pos:int, maxVal: int) requires a.Length > 0; requires forall i :: 0 <= i < a.Length ==> a[i] >= 0; ensures forall i :: 0 <= i < a.Length ==> a[i] <= maxVal; ensures exists i :: 0 <= i < a.Length && a[i] == maxVal; ensures 0 <= pos < a.Length ensures a[pos] == maxVal; {...
method findMax(a:array<int>) returns (pos:int, maxVal: int) requires a.Length > 0; requires forall i :: 0 <= i < a.Length ==> a[i] >= 0; ensures forall i :: 0 <= i < a.Length ==> a[i] <= maxVal; ensures exists i :: 0 <= i < a.Length && a[i] == maxVal; ensures 0 <= pos < a.Length ensures a[pos] == maxVal; {...
211
Final-Project-Dafny_tmp_tmpmcywuqox_Attempts_Exercise6_Binary_Search.dfy
method binarySearch(a:array<int>, val:int) returns (pos:int) requires a.Length > 0 requires forall i, j :: 0 <= i < j < a.Length ==> a[i] <= a[j] ensures 0 <= pos < a.Length ==> a[pos] == val ensures pos < 0 || pos >= a.Length ==> forall i :: 0 <= i < a.Length ==> a[i] != val { var left := 0; var right :...
method binarySearch(a:array<int>, val:int) returns (pos:int) requires a.Length > 0 requires forall i, j :: 0 <= i < j < a.Length ==> a[i] <= a[j] ensures 0 <= pos < a.Length ==> a[pos] == val ensures pos < 0 || pos >= a.Length ==> forall i :: 0 <= i < a.Length ==> a[i] != val { var left := 0; var right :...
212
Final-Project-Dafny_tmp_tmpmcywuqox_Attempts_Insertion_Sort_Normal.dfy
predicate sorted (a: array<int>) reads a { sortedA(a, a.Length) } predicate sortedA (a: array<int>, i: int) requires 0 <= i <= a.Length reads a { forall k :: 0 < k < i ==> a[k-1] <= a[k] } method lookForMin (a: array<int>, i: int) returns (m: int) requires 0 <= i < a.Length ensures i <= m < a.Length ensure...
predicate sorted (a: array<int>) reads a { sortedA(a, a.Length) } predicate sortedA (a: array<int>, i: int) requires 0 <= i <= a.Length reads a { forall k :: 0 < k < i ==> a[k-1] <= a[k] } method lookForMin (a: array<int>, i: int) returns (m: int) requires 0 <= i < a.Length ensures i <= m < a.Length ensure...
213
Final-Project-Dafny_tmp_tmpmcywuqox_Attempts_Insertion_Sorted_Standard.dfy
predicate InsertionSorted(Array: array<int>, left: int, right: int) requires 0 <= left <= right <= Array.Length reads Array { forall i,j :: left <= i < j < right ==> Array[i] <= Array[j] } method sorting(Array: array<int>) requires Array.Length > 1 ensures InsertionSorted(Array, ...
predicate InsertionSorted(Array: array<int>, left: int, right: int) requires 0 <= left <= right <= Array.Length reads Array { forall i,j :: left <= i < j < right ==> Array[i] <= Array[j] } method sorting(Array: array<int>) requires Array.Length > 1 ensures InsertionSorted(Array, ...
214
Final-Project-Dafny_tmp_tmpmcywuqox_Attempts_Merge_Sort.dfy
method mergeSort(a: array<int>) modifies a { sorting(a, 0, a.Length-1); } method merging(a: array<int>, low: int, medium: int, high: int) requires 0 <= low <= medium <= high < a.Length modifies a { var x := 0; var y := 0; var z := 0; var a1: array<int> := new [medium - low + 1]; var a2: array<int> := new [...
method mergeSort(a: array<int>) modifies a { sorting(a, 0, a.Length-1); } method merging(a: array<int>, low: int, medium: int, high: int) requires 0 <= low <= medium <= high < a.Length modifies a { var x := 0; var y := 0; var z := 0; var a1: array<int> := new [medium - low + 1]; var a2: array<int> := new [...
215
Final-Project-Dafny_tmp_tmpmcywuqox_Attempts_Quick_Sort.dfy
predicate quickSorted(Seq: seq<int>) { forall idx_1, idx_2 :: 0 <= idx_1 < idx_2 < |Seq| ==> Seq[idx_1] <= Seq[idx_2] } method threshold(thres:int,Seq:seq<int>) returns (Seq_1:seq<int>,Seq_2:seq<int>) ensures (forall x | x in Seq_1 :: x <= thres) && (forall x | x in Seq_2 :: x >= thres) ensures |Seq_1| + |Seq_2|...
predicate quickSorted(Seq: seq<int>) { forall idx_1, idx_2 :: 0 <= idx_1 < idx_2 < |Seq| ==> Seq[idx_1] <= Seq[idx_2] } method threshold(thres:int,Seq:seq<int>) returns (Seq_1:seq<int>,Seq_2:seq<int>) ensures (forall x | x in Seq_1 :: x <= thres) && (forall x | x in Seq_2 :: x >= thres) ensures |Seq_1| + |Seq_2|...
216
Final-Project-Dafny_tmp_tmpmcywuqox_Attempts_Selection_Sort_Standard.dfy
method selectionSorted(Array: array<int>) modifies Array ensures multiset(old(Array[..])) == multiset(Array[..]) { var idx := 0; while (idx < Array.Length) invariant 0 <= idx <= Array.Length invariant forall i,j :: 0 <= i < idx <= j < Array.Length ==> Array[i] <= Array[j] invariant forall i,j :: 0...
method selectionSorted(Array: array<int>) modifies Array ensures multiset(old(Array[..])) == multiset(Array[..]) { var idx := 0; while (idx < Array.Length) { var minIndex := idx; var idx' := idx + 1; while (idx' < Array.Length) { if (Array[idx'] < Array[minIndex]) { minIndex := ...
217
Final-Project-Dafny_tmp_tmpmcywuqox_Final_Project_3.dfy
method nonZeroReturn(x: int) returns (y: int) ensures y != 0 { if x == 0 { return x + 1; } else { return -x; } } method test() { var input := nonZeroReturn(-1); assert input != 0; }
method nonZeroReturn(x: int) returns (y: int) ensures y != 0 { if x == 0 { return x + 1; } else { return -x; } } method test() { var input := nonZeroReturn(-1); }
218
FlexWeek_tmp_tmpc_tfdj_3_ex2.dfy
// 2. Given an array of positive and negative integers, it returns an array of the absolute value of all the integers. [-4,1,5,-2,-5]->[4,1,5,2,5] function abs(a:int):nat { if a < 0 then -a else a } method aba(a:array<int>)returns (b:array<int>) ensures a.Length == b.Length // needed for next line ensures forall ...
// 2. Given an array of positive and negative integers, it returns an array of the absolute value of all the integers. [-4,1,5,-2,-5]->[4,1,5,2,5] function abs(a:int):nat { if a < 0 then -a else a } method aba(a:array<int>)returns (b:array<int>) ensures a.Length == b.Length // needed for next line ensures forall ...
219
FlexWeek_tmp_tmpc_tfdj_3_ex3.dfy
method Max(a:array<nat>)returns(m:int) ensures a.Length > 0 ==> forall k :: 0<=k<a.Length ==> m >= a[k]// not strong enough ensures a.Length == 0 ==> m == -1 ensures a.Length > 0 ==> m in a[..] // finally at the top // approach did not work for recusrive function { if(a.Length == 0){ return -1; } as...
method Max(a:array<nat>)returns(m:int) ensures a.Length > 0 ==> forall k :: 0<=k<a.Length ==> m >= a[k]// not strong enough ensures a.Length == 0 ==> m == -1 ensures a.Length > 0 ==> m in a[..] // finally at the top // approach did not work for recusrive function { if(a.Length == 0){ return -1; } va...
220
FlexWeek_tmp_tmpc_tfdj_3_ex4.dfy
method join(a:array<int>,b:array<int>) returns (c:array<int>) ensures a[..] + b[..] == c[..] ensures multiset(a[..] + b[..]) == multiset(c[..]) ensures multiset(a[..]) + multiset(b[..]) == multiset(c[..]) ensures a.Length+b.Length == c.Length // Forall ensures forall i :: 0<=i<a.Length ==> c[i] == a[i] ensures forall...
method join(a:array<int>,b:array<int>) returns (c:array<int>) ensures a[..] + b[..] == c[..] ensures multiset(a[..] + b[..]) == multiset(c[..]) ensures multiset(a[..]) + multiset(b[..]) == multiset(c[..]) ensures a.Length+b.Length == c.Length // Forall ensures forall i :: 0<=i<a.Length ==> c[i] == a[i] ensures forall...
221
FlexWeek_tmp_tmpc_tfdj_3_reverse.dfy
// Write an *iterative* Dafny method Reverse with signature: // method Reverse(a: array<char>) returns (b: array<char>) // which takes an input array of characters 'a' and outputs array 'b' consisting of // the elements of the input array in reverse order. The following conditions apply: // - the input array...
// Write an *iterative* Dafny method Reverse with signature: // method Reverse(a: array<char>) returns (b: array<char>) // which takes an input array of characters 'a' and outputs array 'b' consisting of // the elements of the input array in reverse order. The following conditions apply: // - the input array...
222
Formal-Methods-Project_tmp_tmphh2ar2xv_BubbleSort.dfy
predicate sorted(a: array?<int>, l: int, u: int) reads a; requires a != null; { forall i, j :: 0 <= l <= i <= j <= u < a.Length ==> a[i] <= a[j] } predicate partitioned(a: array?<int>, i: int) reads a requires a != null { forall k, k' :: 0 <= k <= i < k' < a.Length ==> a[k] <= a[k'] } method Bu...
predicate sorted(a: array?<int>, l: int, u: int) reads a; requires a != null; { forall i, j :: 0 <= l <= i <= j <= u < a.Length ==> a[i] <= a[j] } predicate partitioned(a: array?<int>, i: int) reads a requires a != null { forall k, k' :: 0 <= k <= i < k' < a.Length ==> a[k] <= a[k'] } method Bu...
223
Formal-Methods-Project_tmp_tmphh2ar2xv_Factorial.dfy
method Fact(x: int) returns (y: int) requires x >= 0; { y := 1; var z := 0; while(z != x) decreases x - z; invariant 0 <= x-z; { z := z + 1; y := y * z; } } method Main() { var a := Fact(87); print a; }
method Fact(x: int) returns (y: int) requires x >= 0; { y := 1; var z := 0; while(z != x) { z := z + 1; y := y * z; } } method Main() { var a := Fact(87); print a; }
224
Formal-Verification-Project_tmp_tmp9gmwsmyp_strings3.dfy
predicate isPrefixPred(pre:string, str:string) { (|pre| <= |str|) && pre == str[..|pre|] } predicate isNotPrefixPred(pre:string, str:string) { (|pre| > |str|) || pre != str[..|pre|] } lemma PrefixNegationLemma(pre:string, str:string) ensures isPrefixPred(pre,str) <==> !isNotPrefixPred(pre,str) ensures !isPre...
predicate isPrefixPred(pre:string, str:string) { (|pre| <= |str|) && pre == str[..|pre|] } predicate isNotPrefixPred(pre:string, str:string) { (|pre| > |str|) || pre != str[..|pre|] } lemma PrefixNegationLemma(pre:string, str:string) ensures isPrefixPred(pre,str) <==> !isNotPrefixPred(pre,str) ensures !isPre...
225
Formal-Verification_tmp_tmpuyt21wjt_Dafny_strings1.dfy
predicate isPrefixPredicate(pre: string, str:string) { |str| >= |pre| && pre <= str } method isPrefix(pre: string, str: string) returns (res: bool) ensures |pre| > |str| ==> !res ensures res == isPrefixPredicate(pre, str) { if |pre| > |str| {return false;} var i := 0; while i < |pre| decreases |pr...
predicate isPrefixPredicate(pre: string, str:string) { |str| >= |pre| && pre <= str } method isPrefix(pre: string, str: string) returns (res: bool) ensures |pre| > |str| ==> !res ensures res == isPrefixPredicate(pre, str) { if |pre| > |str| {return false;} var i := 0; while i < |pre| { if pre[i]...
226
Formal-Verification_tmp_tmpuyt21wjt_Dafny_strings3.dfy
// We spent 2h each on this assignment predicate isPrefixPred(pre:string, str:string) { (|pre| <= |str|) && pre == str[..|pre|] } predicate isNotPrefixPred(pre:string, str:string) { (|pre| > |str|) || pre != str[..|pre|] } lemma PrefixNegationLemma(pre:string, str:string) ensures isPrefixPred(pre,str) <==> !...
// We spent 2h each on this assignment predicate isPrefixPred(pre:string, str:string) { (|pre| <= |str|) && pre == str[..|pre|] } predicate isNotPrefixPred(pre:string, str:string) { (|pre| > |str|) || pre != str[..|pre|] } lemma PrefixNegationLemma(pre:string, str:string) ensures isPrefixPred(pre,str) <==> !...
227
Formal-methods-of-software-development_tmp_tmppryvbyty_Bloque 1_Lab3.dfy
method multipleReturns (x:int, y:int) returns (more:int, less:int) requires y > 0 ensures less < x < more method multipleReturns2 (x:int, y:int) returns (more:int, less:int) requires y > 0 ensures more + less == 2*x // TODO: Hacer en casa method multipleReturns3 (x:int, y:int) returns (more:int, less:int) requires ...
method multipleReturns (x:int, y:int) returns (more:int, less:int) requires y > 0 ensures less < x < more method multipleReturns2 (x:int, y:int) returns (more:int, less:int) requires y > 0 ensures more + less == 2*x // TODO: Hacer en casa method multipleReturns3 (x:int, y:int) returns (more:int, less:int) requires ...
228
Formal-methods-of-software-development_tmp_tmppryvbyty_Bloque 2_Lab6.dfy
/*predicate palindrome<T(==)> (s:seq<T>) { forall i:: 0<=i<|s| ==> s[i] == s[|s|-i-1] } */ // SUM OF A SEQUENCE OF INTEGERS function sum(v: seq<int>): int decreases v { if v==[] then 0 else if |v|==1 then v[0] else v[0]+sum(v[1..]) } /* method vector_Sum(v:seq<int>) returns (x:int) ensures x == sum(v)...
/*predicate palindrome<T(==)> (s:seq<T>) { forall i:: 0<=i<|s| ==> s[i] == s[|s|-i-1] } */ // SUM OF A SEQUENCE OF INTEGERS function sum(v: seq<int>): int { if v==[] then 0 else if |v|==1 then v[0] else v[0]+sum(v[1..]) } /* method vector_Sum(v:seq<int>) returns (x:int) ensures x == sum(v) { var ...
229
Formal-methods-of-software-development_tmp_tmppryvbyty_Examenes_Beni_Heusel-Benedikt-Ass-1.dfy
// APELLIDOS: Heusel // NOMBRE: Benedikt // ESPECIALIDAD: ninguna (Erasmus) // ESTÁ PERFECTO, NO HAY NINGUN COMENTARIO MAS ABAJO // EJERCICIO 1 // Demostrar el lemma div10_Lemma por inducción en n // y luego usarlo para demostrar el lemma div10Forall_Lemma function exp (x:int,e:nat):int { if e == 0 then 1 else x *...
// APELLIDOS: Heusel // NOMBRE: Benedikt // ESPECIALIDAD: ninguna (Erasmus) // ESTÁ PERFECTO, NO HAY NINGUN COMENTARIO MAS ABAJO // EJERCICIO 1 // Demostrar el lemma div10_Lemma por inducción en n // y luego usarlo para demostrar el lemma div10Forall_Lemma function exp (x:int,e:nat):int { if e == 0 then 1 else x *...
230
FormalMethods_tmp_tmpvda2r3_o_dafny_Invariants_ex1.dfy
method Mult(x:nat, y:nat) returns (r:nat) ensures r == x * y { // Valores passados por parâmetros são imutáveis var m := x; var n := y; r := 0; // Soma sucessiva para multiplicar dois números. while m > 0 invariant m*n+r == x*y invariant m>=0 { r := r + n; m := m - 1;...
method Mult(x:nat, y:nat) returns (r:nat) ensures r == x * y { // Valores passados por parâmetros são imutáveis var m := x; var n := y; r := 0; // Soma sucessiva para multiplicar dois números. while m > 0 { r := r + n; m := m - 1; } return r; // NOT(m>0) ^ Inv ==> r =...
231
FormalMethods_tmp_tmpvda2r3_o_dafny_Invariants_ex2.dfy
function Potencia(x:nat, y:nat):nat { if y == 0 then 1 else x * Potencia(x, y-1) } method Pot(x:nat, y:nat) returns (r:nat) ensures r == Potencia(x,y) { r := 1; var b := x; var e := y; while e > 0 invariant Potencia(b,e) * r == Potencia(x,y) { r := r * b; e := e - 1;...
function Potencia(x:nat, y:nat):nat { if y == 0 then 1 else x * Potencia(x, y-1) } method Pot(x:nat, y:nat) returns (r:nat) ensures r == Potencia(x,y) { r := 1; var b := x; var e := y; while e > 0 { r := r * b; e := e - 1; } return r; } /* Inv = Pot(2,3) Teste ...
232
Formal_Verification_With_Dafny_tmp_tmp5j79rq48_Counter.dfy
class Counter { var value : int ; constructor init() ensures value == 0; { value := 0 ; } method getValue() returns (x:int) ensures x == value; { x := value ; } method inc() modifies this`value requires value >= 0; ensures value == old(value) + 1; { value := value + ...
class Counter { var value : int ; constructor init() ensures value == 0; { value := 0 ; } method getValue() returns (x:int) ensures x == value; { x := value ; } method inc() modifies this`value requires value >= 0; ensures value == old(value) + 1; { value := value + ...
233
Formal_Verification_With_Dafny_tmp_tmp5j79rq48_LimitedStack.dfy
// A LIFO queue (aka a stack) with limited capacity. class LimitedStack{ var capacity : int; // capacity, max number of elements allowed on the stack. var arr : array<int>; // contents of stack. var top : int; // The index of the top of the stack, or -1 if the stack is empty // This predicate...
// A LIFO queue (aka a stack) with limited capacity. class LimitedStack{ var capacity : int; // capacity, max number of elements allowed on the stack. var arr : array<int>; // contents of stack. var top : int; // The index of the top of the stack, or -1 if the stack is empty // This predicate...
234
HATRA-2022-Paper_tmp_tmp5texxy8l_copilot_verification_Binary Search_binary_search.dfy
// Dafny verification of binary search alogirthm from binary_search.py // Inspired by: https://ece.uwaterloo.ca/~agurfink/stqam/rise4fun-Dafny/#h211 method BinarySearch(arr: array<int>, target: int) returns (index: int) requires distinct(arr) requires sorted(arr) ensures -1 <= index < arr.Length ensure...
// Dafny verification of binary search alogirthm from binary_search.py // Inspired by: https://ece.uwaterloo.ca/~agurfink/stqam/rise4fun-Dafny/#h211 method BinarySearch(arr: array<int>, target: int) returns (index: int) requires distinct(arr) requires sorted(arr) ensures -1 <= index < arr.Length ensure...
235
HATRA-2022-Paper_tmp_tmp5texxy8l_copilot_verification_Largest Sum_largest_sum.dfy
// CoPilot function converted to dafny method largest_sum(nums: array<int>, k: int) returns (sum: int) requires nums.Length > 0 ensures max_sum_subarray(nums, sum, 0, nums.Length) { var max_sum := 0; var current_sum := 0; var i := 0; while (i < nums.Length) invariant 0 <= i <= nums...
// CoPilot function converted to dafny method largest_sum(nums: array<int>, k: int) returns (sum: int) requires nums.Length > 0 ensures max_sum_subarray(nums, sum, 0, nums.Length) { var max_sum := 0; var current_sum := 0; var i := 0; while (i < nums.Length) { current_sum := cur...
236
HATRA-2022-Paper_tmp_tmp5texxy8l_copilot_verification_Sort Array_sort_array.dfy
method sortArray(arr: array<int>) returns (arr_sorted: array<int>) // Requires array length to be between 0 and 10000 requires 0 <= arr.Length < 10000 // Ensuring the arry has been sorted ensures sorted(arr_sorted, 0, arr_sorted.Length) // Ensuring that we have not modified elements but have only ch...
method sortArray(arr: array<int>) returns (arr_sorted: array<int>) // Requires array length to be between 0 and 10000 requires 0 <= arr.Length < 10000 // Ensuring the arry has been sorted ensures sorted(arr_sorted, 0, arr_sorted.Length) // Ensuring that we have not modified elements but have only ch...
237
HATRA-2022-Paper_tmp_tmp5texxy8l_copilot_verification_Two Sum_two_sum.dfy
method twoSum(nums: array<int>, target: int) returns (index1: int, index2: int) requires 2 <= nums.Length requires exists i, j :: (0 <= i < j < nums.Length && nums[i] + nums[j] == target) ensures index1 != index2 ensures 0 <= index1 < nums.Length ensures 0 <= index2 < nums.Length ensures nums[in...
method twoSum(nums: array<int>, target: int) returns (index1: int, index2: int) requires 2 <= nums.Length requires exists i, j :: (0 <= i < j < nums.Length && nums[i] + nums[j] == target) ensures index1 != index2 ensures 0 <= index1 < nums.Length ensures 0 <= index2 < nums.Length ensures nums[in...
238
Invoker_tmp_tmpypx0gs8x_dafny_abstract-interpreter_SimpleVerifier.dfy
module Ints { const U32_BOUND: nat := 0x1_0000_0000 newtype u32 = x:int | 0 <= x < 0x1_0000_0000 newtype i32 = x: int | -0x8000_0000 <= x < 0x8000_0000 } module Lang { import opened Ints datatype Reg = R0 | R1 | R2 | R3 datatype Expr = | Const(n: u32) // overflow during addition is an error ...
module Ints { const U32_BOUND: nat := 0x1_0000_0000 newtype u32 = x:int | 0 <= x < 0x1_0000_0000 newtype i32 = x: int | -0x8000_0000 <= x < 0x8000_0000 } module Lang { import opened Ints datatype Reg = R0 | R1 | R2 | R3 datatype Expr = | Const(n: u32) // overflow during addition is an error ...
239
M2_tmp_tmp2laaavvl_Software Verification_Exercices_Exo4-CountAndReturn.dfy
method CountToAndReturnN(n: int) returns (r: int) requires n >= 0 ensures r == n { var i := 0; while i < n invariant 0 <= i <= n { i := i + 1; } r := i; }
method CountToAndReturnN(n: int) returns (r: int) requires n >= 0 ensures r == n { var i := 0; while i < n { i := i + 1; } r := i; }
240
M2_tmp_tmp2laaavvl_Software Verification_Exercices_Exo7-ComputeSum.dfy
function Sum(n:nat):nat { if n==0 then 0 else n + Sum(n-1) } method ComputeSum(n:nat) returns (s:nat) ensures s ==Sum(n) { s := 0; var i := 0; while i< n invariant 0 <= i <= n invariant s == Sum(i) { s := s + i + 1; i := i+1; } }
function Sum(n:nat):nat { if n==0 then 0 else n + Sum(n-1) } method ComputeSum(n:nat) returns (s:nat) ensures s ==Sum(n) { s := 0; var i := 0; while i< n { s := s + i + 1; i := i+1; } }
241
M2_tmp_tmp2laaavvl_Software Verification_Exercices_Exo9-Carre.dfy
method Carre(a: nat) returns (c: nat) ensures c == a*a { var i := 0; c := 0; while i != a invariant 0 <= i <= a invariant c == i*i decreases a - i { c := c + 2*i +1; i := i + 1; } }
method Carre(a: nat) returns (c: nat) ensures c == a*a { var i := 0; c := 0; while i != a { c := c + 2*i +1; i := i + 1; } }
242
MFDS_tmp_tmpvvr5y1t9_Assignments_Ass-1-2020-21-Sol-eGela.dfy
// Ejercicio 1: Demostrar por inducci�n el siguiente lema: lemma EcCuadDiv2_Lemma (x:int) requires x >= 1 ensures (x*x + x) % 2 == 0 { if x != 1 { EcCuadDiv2_Lemma(x-1); assert x*x+x == ((x-1)*(x-1) + (x-1)) + 2*x; } } // Ejercicio 2: Demostrar por inducci�n el siguiente lema // Ind...
// Ejercicio 1: Demostrar por inducci�n el siguiente lema: lemma EcCuadDiv2_Lemma (x:int) requires x >= 1 ensures (x*x + x) % 2 == 0 { if x != 1 { EcCuadDiv2_Lemma(x-1); } } // Ejercicio 2: Demostrar por inducci�n el siguiente lema // Indicaciones: (1) Puedes llamar al lema del ejercicio an...
243
MFES_2021_tmp_tmpuljn8zd9_Exams_Special_Exam_03_2020_4_CatalanNumbers.dfy
function C(n: nat): nat decreases n { if n == 0 then 1 else (4 * n - 2) * C(n-1) / (n + 1) } method calcC(n: nat) returns (res: nat) ensures res == C(n) { var i := 0; res := 1; assert res == C(i) && 0 <= i <= n; while i < n decreases n - i //a - loop variant invariant res ...
function C(n: nat): nat { if n == 0 then 1 else (4 * n - 2) * C(n-1) / (n + 1) } method calcC(n: nat) returns (res: nat) ensures res == C(n) { var i := 0; res := 1; while i < n { ghost var v0 := n - i; i := i + 1; res := (4 * i - 2) * res / (i + 1); } }
244
MFES_2021_tmp_tmpuljn8zd9_FCUL_Exercises_10_find.dfy
method find(a: array<int>, key: int) returns(index: int) requires a.Length > 0; ensures 0 <= index <= a.Length; ensures index < a.Length ==> a[index] == key; { index := 0; while index < a.Length && a[index] != key decreases a.Length - index invariant 0 <= index <= a.Length ...
method find(a: array<int>, key: int) returns(index: int) requires a.Length > 0; ensures 0 <= index <= a.Length; ensures index < a.Length ==> a[index] == key; { index := 0; while index < a.Length && a[index] != key { index := index + 1; } }
245
MFES_2021_tmp_tmpuljn8zd9_FCUL_Exercises_8_sum.dfy
function calcSum(n: nat) : nat { n * (n - 1) / 2 } method sum(n: nat) returns(s: nat) ensures s == calcSum(n + 1) { s := 0; var i := 0; while i < n decreases n - i invariant 0 <= i <= n invariant s == calcSum(i + 1) { i := i + 1; s := s + i; } }
function calcSum(n: nat) : nat { n * (n - 1) / 2 } method sum(n: nat) returns(s: nat) ensures s == calcSum(n + 1) { s := 0; var i := 0; while i < n { i := i + 1; s := s + i; } }
246
MFES_2021_tmp_tmpuljn8zd9_PracticalClasses_TP3_2_Insertion_Sort.dfy
// Sorts array 'a' using the insertion sort algorithm. method insertionSort(a: array<int>) modifies a ensures isSorted(a, 0, a.Length) ensures multiset(a[..]) == multiset(old(a[..])) { var i := 0; while i < a.Length decreases a.Length - i invariant 0 <= i <= a.Length invar...
// Sorts array 'a' using the insertion sort algorithm. method insertionSort(a: array<int>) modifies a ensures isSorted(a, 0, a.Length) ensures multiset(a[..]) == multiset(old(a[..])) { var i := 0; while i < a.Length { var j := i; while j > 0 && a[j-1] > a[j] { ...
247
MFES_2021_tmp_tmpuljn8zd9_TheoreticalClasses_Power.dfy
/* * Formal verification of O(n) and O(log n) algorithms to calculate the natural * power of a real number (x^n), illustrating the usage of lemmas. * FEUP, MIEIC, MFES, 2020/21. */ // Initial specification/definition of x^n, recursive, functional style, // with time and space complexity O(n). function power(x: real,...
/* * Formal verification of O(n) and O(log n) algorithms to calculate the natural * power of a real number (x^n), illustrating the usage of lemmas. * FEUP, MIEIC, MFES, 2020/21. */ // Initial specification/definition of x^n, recursive, functional style, // with time and space complexity O(n). function power(x: real,...
248
MFS_tmp_tmpmmnu354t_Praticas_TP9_Power.dfy
/* * Formal verification of O(n) and O(log n) algorithms to calculate the natural * power of a real number (x^n), illustrating the usage of lemmas. * FEUP, M.EIC, MFS, 2021/22. */ // Initial specification/definition of x^n, recursive, functional style, // with time and space complexity O(n). function power(x: real, ...
/* * Formal verification of O(n) and O(log n) algorithms to calculate the natural * power of a real number (x^n), illustrating the usage of lemmas. * FEUP, M.EIC, MFS, 2021/22. */ // Initial specification/definition of x^n, recursive, functional style, // with time and space complexity O(n). function power(x: real, ...
249
MFS_tmp_tmpmmnu354t_Testes anteriores_T2_ex5_2020_2.dfy
method leq(a: array<int>, b: array<int>) returns (result: bool) ensures result <==> (a.Length <= b.Length && a[..] == b[..a.Length]) || (exists k :: 0 <= k < a.Length && k < b.Length && a[..k] == b[..k] && a[k] < b[k]) { var i := 0; while i < a.Length && i < b.Length decreases a.Length - i ...
method leq(a: array<int>, b: array<int>) returns (result: bool) ensures result <==> (a.Length <= b.Length && a[..] == b[..a.Length]) || (exists k :: 0 <= k < a.Length && k < b.Length && a[..k] == b[..k] && a[k] < b[k]) { var i := 0; while i < a.Length && i < b.Length { if a[i] < b[i] { return ...
250
MIEIC_mfes_tmp_tmpq3ho7nve_TP3_binary_search.dfy
// Checks if array 'a' is sorted. predicate isSorted(a: array<int>) reads a { forall i, j :: 0 <= i < j < a.Length ==> a[i] <= a[j] } // Finds a value 'x' in a sorted array 'a', and returns its index, // or -1 if not found. method binarySearch(a: array<int>, x: int) returns (index: int) requires isSorted(a...
// Checks if array 'a' is sorted. predicate isSorted(a: array<int>) reads a { forall i, j :: 0 <= i < j < a.Length ==> a[i] <= a[j] } // Finds a value 'x' in a sorted array 'a', and returns its index, // or -1 if not found. method binarySearch(a: array<int>, x: int) returns (index: int) requires isSorted(a...
251
MIEIC_mfes_tmp_tmpq3ho7nve_exams_appeal_20_p4.dfy
function F(n: nat): nat { if n <= 2 then n else F(n-1) + F(n-3)} method calcF(n: nat) returns (res: nat) ensures res == F(n) { var a, b, c := 0, 1, 2; var i := 0; while i < n decreases n-i invariant 0 <= i <= n invariant a == F(i) && b == F(i+1) && c == F(i+2) { a, b, c := b, c, a + c; ...
function F(n: nat): nat { if n <= 2 then n else F(n-1) + F(n-3)} method calcF(n: nat) returns (res: nat) ensures res == F(n) { var a, b, c := 0, 1, 2; var i := 0; while i < n { a, b, c := b, c, a + c; i := i + 1; } res := a; }
252
MIEIC_mfes_tmp_tmpq3ho7nve_exams_mt2_19_p4.dfy
function R(n: nat): nat { if n == 0 then 0 else if R(n-1) > n then R(n-1) - n else R(n-1) + n } method calcR(n: nat) returns (r: nat) ensures r == R(n) { r := 0; var i := 0; while i < n decreases n-i invariant 0 <= i <= n invariant r == R(i) { i := i + 1; ...
function R(n: nat): nat { if n == 0 then 0 else if R(n-1) > n then R(n-1) - n else R(n-1) + n } method calcR(n: nat) returns (r: nat) ensures r == R(n) { r := 0; var i := 0; while i < n { i := i + 1; if r > i { r := r - i; } else { r := r +...
253
MIEIC_mfes_tmp_tmpq3ho7nve_exams_mt2_19_p5.dfy
type T = int // example // Partitions a nonempty array 'a', by reordering the elements in the array, // so that elements smaller than a chosen pivot are placed to the left of the // pivot, and values greater or equal than the pivot are placed to the right of // the pivot. Returns the pivot position. method partition...
type T = int // example // Partitions a nonempty array 'a', by reordering the elements in the array, // so that elements smaller than a chosen pivot are placed to the left of the // pivot, and values greater or equal than the pivot are placed to the right of // the pivot. Returns the pivot position. method partition...
254
MIEIC_mfes_tmp_tmpq3ho7nve_exams_special_20_p5.dfy
type T = int // for demo purposes, but could be another type predicate sorted(a: array<T>, n: nat) requires n <= a.Length reads a { forall i,j :: 0 <= i < j < n ==> a[i] <= a[j] } // Use binary search to find an appropriate position to insert a value 'x' // in a sorted array 'a', so that it remains sorted...
type T = int // for demo purposes, but could be another type predicate sorted(a: array<T>, n: nat) requires n <= a.Length reads a { forall i,j :: 0 <= i < j < n ==> a[i] <= a[j] } // Use binary search to find an appropriate position to insert a value 'x' // in a sorted array 'a', so that it remains sorted...
255
Metodos_Formais_tmp_tmpbez22nnn_Aula_2_ex1.dfy
method Mult(x:nat, y:nat) returns (r: nat) ensures r == x * y { var m := x; var n := y; r:=0; while m > 0 invariant m >= 0 invariant m*n+r == x*y { r := r + n; m := m - 1; } return r; }
method Mult(x:nat, y:nat) returns (r: nat) ensures r == x * y { var m := x; var n := y; r:=0; while m > 0 { r := r + n; m := m - 1; } return r; }
256
Metodos_Formais_tmp_tmpbez22nnn_Aula_2_ex2.dfy
function Potencia(x: nat, y: nat): nat { if y == 0 then 1 else x * Potencia(x, y-1) } method Pot(x: nat, y: nat) returns (r: nat) ensures r == Potencia(x,y) { var b := x; var e := y; r := 1; while e > 0 invariant Potencia(b, e) * r == Potencia(x,y) { r := b * r; e ...
function Potencia(x: nat, y: nat): nat { if y == 0 then 1 else x * Potencia(x, y-1) } method Pot(x: nat, y: nat) returns (r: nat) ensures r == Potencia(x,y) { var b := x; var e := y; r := 1; while e > 0 { r := b * r; e := e - 1; } return r; }
257
Metodos_Formais_tmp_tmpbez22nnn_Aula_4_ex1.dfy
predicate Par(n:int) { n % 2 == 0 } method FazAlgo (a:int, b:int) returns (x:int, y:int) requires a >= b && Par (a-b) { x := a; y := b; while x != y invariant x >= y invariant Par(x-y) decreases x-y { x := x - 1; y := y + 1; } }
predicate Par(n:int) { n % 2 == 0 } method FazAlgo (a:int, b:int) returns (x:int, y:int) requires a >= b && Par (a-b) { x := a; y := b; while x != y { x := x - 1; y := y + 1; } }
258
Metodos_Formais_tmp_tmpbez22nnn_Aula_4_ex3.dfy
function Fib(n:nat):nat { if n < 2 then n else Fib(n-2) + Fib(n-1) } method ComputeFib(n:nat) returns (x:nat) ensures x == Fib(n) { var i := 0; x := 0; var y := 1; while i < n decreases n - i invariant 0 <= i <= n invariant x == Fib(i) invariant y == Fib(i+1) { x...
function Fib(n:nat):nat { if n < 2 then n else Fib(n-2) + Fib(n-1) } method ComputeFib(n:nat) returns (x:nat) ensures x == Fib(n) { var i := 0; x := 0; var y := 1; while i < n { x, y := y, x + y; i := i + 1; } } method Teste() { var n := 3; var f := ComputeF...
259
Metodos_Formais_tmp_tmpql2hwcsh_Arrays_explicacao.dfy
// Array<T> = visualização de um array // Uma busca ordenada em um array // Buscar: Array<Z>xZ -> Z (Z é inteiro) // Pré: True (pré-condição é sempre verdadeira) // Pos: R < 0 => Para todo i pertencente aos naturais(0 <= i < A.length => A[i] != X) e // 0 <= R < A.length => A[R] = x // // método em qualquer linguagem: ...
// Array<T> = visualização de um array // Uma busca ordenada em um array // Buscar: Array<Z>xZ -> Z (Z é inteiro) // Pré: True (pré-condição é sempre verdadeira) // Pos: R < 0 => Para todo i pertencente aos naturais(0 <= i < A.length => A[i] != X) e // 0 <= R < A.length => A[R] = x // // método em qualquer linguagem: ...
260
Metodos_Formais_tmp_tmpql2hwcsh_Arrays_somatorioArray.dfy
// Deve ser criado uma função explicando o que é um somatório // Somatorio: Array<N> -> N // Pre: True // Pos: Somatorio(A) = somatório de i = 0 até |A|-1 os valores das posições do array pelo i // // function é uma fórmula matemática, ele não possui variaveis globais // Soma: Array<N>xN -> N // { Soma(A,0) = A[0] // ...
// Deve ser criado uma função explicando o que é um somatório // Somatorio: Array<N> -> N // Pre: True // Pos: Somatorio(A) = somatório de i = 0 até |A|-1 os valores das posições do array pelo i // // function é uma fórmula matemática, ele não possui variaveis globais // Soma: Array<N>xN -> N // { Soma(A,0) = A[0] // ...
261
Metodos_Formais_tmp_tmpql2hwcsh_Invariantes_fatorial2.dfy
function Fat(n:nat):nat { if n == 0 then 1 else n*Fat(n-1) } method Fatorial(n:nat) returns (f:nat) ensures f == Fat(n) { f := 1; var i := 1; while i <= n decreases n-i //variante invariant 1 <= i <= n+1 //invariante invariant f == Fat(i-1) //invariante { f := f * i;...
function Fat(n:nat):nat { if n == 0 then 1 else n*Fat(n-1) } method Fatorial(n:nat) returns (f:nat) ensures f == Fat(n) { f := 1; var i := 1; while i <= n { f := f * i; i := i + 1; } return f; } // i | n | variante // 1 | 3 | 2 // 2 | 3 | 1 // 3 | 3 | 0 // 4 | 3 | -1 // var...
262
Metodos_Formais_tmp_tmpql2hwcsh_Invariantes_fibonacci.dfy
// Provando fibonacci function Fib(n:nat):nat { if n < 2 then n else Fib(n-2) + Fib(n-1) } method ComputeFib(n:nat) returns (x:nat) ensures x == Fib(n) { var i := 0; x := 0; var y := 1; while i < n decreases n-i invariant 0 <= i <= n invariant x == Fib(i) invariant y == Fib(...
// Provando fibonacci function Fib(n:nat):nat { if n < 2 then n else Fib(n-2) + Fib(n-1) } method ComputeFib(n:nat) returns (x:nat) ensures x == Fib(n) { var i := 0; x := 0; var y := 1; while i < n { x, y := y, x + y; //multiplas atribuições i := i + 1; } } // Fibon...
263
Metodos_Formais_tmp_tmpql2hwcsh_Invariantes_multiplicador.dfy
// Exemplo de invariantes // Invariante significa que o valor não muda desde a pré-condição até a pós-condição method Mult(x:nat, y:nat) returns (r:nat) ensures r == x * y { // parâmetros de entrada são imutáveis, por isso // é preciso a atribuir a variáveis locais para usar em blocos de códigos para mudar ...
// Exemplo de invariantes // Invariante significa que o valor não muda desde a pré-condição até a pós-condição method Mult(x:nat, y:nat) returns (r:nat) ensures r == x * y { // parâmetros de entrada são imutáveis, por isso // é preciso a atribuir a variáveis locais para usar em blocos de códigos para mudar ...
264
Metodos_Formais_tmp_tmpql2hwcsh_Invariantes_potencia.dfy
// Potência // deve ser especificado a potência, porque ele não existe n dafny // Função recursiva da potência function Potencia(x:nat, y:nat):nat { if y == 0 then 1 else x * Potencia(x,y-1) } // Quero agora implementar como uma função não recursiva method Pot(x:nat, y:nat) returns (r:nat) ensures r == P...
// Potência // deve ser especificado a potência, porque ele não existe n dafny // Função recursiva da potência function Potencia(x:nat, y:nat):nat { if y == 0 then 1 else x * Potencia(x,y-1) } // Quero agora implementar como uma função não recursiva method Pot(x:nat, y:nat) returns (r:nat) ensures r == P...
265
Prog-Fun-Solutions_tmp_tmp7_gmnz5f_extra_mod.dfy
ghost function f(n: nat): nat { if n == 0 then 1 else if n%2 == 0 then 1 + 2*f(n/2) else 2*f(n/2) } method mod(n:nat) returns (a:nat) ensures a == f(n) { var x:nat := 0; var y:nat := 1; var k:nat := n; while k > 0 invariant f(n) == x + y*f(k) invariant 0 <= k <= n decreases k...
ghost function f(n: nat): nat { if n == 0 then 1 else if n%2 == 0 then 1 + 2*f(n/2) else 2*f(n/2) } method mod(n:nat) returns (a:nat) ensures a == f(n) { var x:nat := 0; var y:nat := 1; var k:nat := n; while k > 0 { if (k%2 == 0) { x := x + y; } else { ...
266
Prog-Fun-Solutions_tmp_tmp7_gmnz5f_extra_mod2.dfy
ghost function f2(n: nat): nat { if n == 0 then 0 else 5*f2(n/3) + n%4 } method mod2(n:nat) returns (a:nat) ensures a == f2(n) { var x:nat := 1; var y:nat := 0; var k:nat := n; while k > 0 invariant f2(n) == x*f2(k) + y invariant 0 <= k <= n decreases k { assert f2(n)...
ghost function f2(n: nat): nat { if n == 0 then 0 else 5*f2(n/3) + n%4 } method mod2(n:nat) returns (a:nat) ensures a == f2(n) { var x:nat := 1; var y:nat := 0; var k:nat := n; while k > 0 { y := x*(k%4) + y; x := 5*x; k := k/3; } a := y; }
267
Prog-Fun-Solutions_tmp_tmp7_gmnz5f_extra_pow.dfy
ghost function pow(a: int, e: nat): int { if e == 0 then 1 else a*pow(a, e-1) } method Pow(a: nat, n: nat) returns (y: nat) ensures y == pow(a, n) { var x:nat := 1; var k:nat := 0; while k < n invariant x == pow(a, k) invariant 0 <= k <= n decreases n-k { assert x == pow(a, k);...
ghost function pow(a: int, e: nat): int { if e == 0 then 1 else a*pow(a, e-1) } method Pow(a: nat, n: nat) returns (y: nat) ensures y == pow(a, n) { var x:nat := 1; var k:nat := 0; while k < n { x := a*x; k := k + 1; } y := x; }
268
Prog-Fun-Solutions_tmp_tmp7_gmnz5f_extra_sum.dfy
ghost function sum(n: nat): int { if n == 0 then 0 else n + sum(n - 1) } method Sum(n: nat) returns (s: int) ensures s == sum(n) { var x:nat := 0; var y:nat := 1; var k:nat := n; while k > 0 invariant sum(n) == x + y*sum(k) invariant 0 <= k <= n decreases k { assert sum(n...
ghost function sum(n: nat): int { if n == 0 then 0 else n + sum(n - 1) } method Sum(n: nat) returns (s: int) ensures s == sum(n) { var x:nat := 0; var y:nat := 1; var k:nat := n; while k > 0 { x := x + y*k; k := k-1; } s := x; }
269
Prog-Fun-Solutions_tmp_tmp7_gmnz5f_mockExam2_p2.dfy
// problem 2: // name: Gabriele Berardi // s-number: s4878728 // table: XXX method problem2(p:int, q:int, X:int, Y:int) returns (r:int, s:int) requires p == 2*X + Y && q == X + 3 ensures r == X && s == Y { assert p == 2*X + Y && q == X + 3; r, s := p, q; assert r == 2*X + Y && s == X + 3; r :=...
// problem 2: // name: Gabriele Berardi // s-number: s4878728 // table: XXX method problem2(p:int, q:int, X:int, Y:int) returns (r:int, s:int) requires p == 2*X + Y && q == X + 3 ensures r == X && s == Y { r, s := p, q; r := r - 2*s + 6; s := s - 3; r,s := s, r; }
270
Prog-Fun-Solutions_tmp_tmp7_gmnz5f_mockExam2_p3.dfy
// problem 3: // name: ....... (fill in your name) // s-number: s....... (fill in your student number) // table: ....... (fill in your table number) method problem3(m:int, X:int) returns (r:int) requires X >= 0 && (2*m == 1 - X || m == X + 3) ensures r == X { assert X >= 0 && (X == 1 - 2*m || m-3 == X); ...
// problem 3: // name: ....... (fill in your name) // s-number: s....... (fill in your student number) // table: ....... (fill in your table number) method problem3(m:int, X:int) returns (r:int) requires X >= 0 && (2*m == 1 - X || m == X + 3) ensures r == X { r := m; if (1-2*r >= 0) { r := 2*...
271
Prog-Fun-Solutions_tmp_tmp7_gmnz5f_mockExam2_p5.dfy
// problem 5: // name: Gabriele Berardi // s-number: s4878728 // table: XXXX ghost function f(n: int): int { if n < 0 then 0 else 3*f(n-5) + n } method problem5(n:nat) returns (x: int) ensures x == f(n) { var a := 1; var b := 0; var k := n; while k >= 0 invariant f(n) == a*f(k) + b ...
// problem 5: // name: Gabriele Berardi // s-number: s4878728 // table: XXXX ghost function f(n: int): int { if n < 0 then 0 else 3*f(n-5) + n } method problem5(n:nat) returns (x: int) ensures x == f(n) { var a := 1; var b := 0; var k := n; while k >= 0 { b := a*k + b; ...
272
Prog-Fun-Solutions_tmp_tmp7_gmnz5f_mockExam2_p6.dfy
// problem 6: // name: Gabriele Berardi // s-number: s4878728 // table: XXXXX ghost function f(n: int): int { if n <= 0 then 1 else n + f(n-1)*f(n-2) } ghost function fSum(n: nat): int { // give the body of this function // it should return Sum(i: 0<=i < n: f(i)) if n <= 0 then 0 else f(n-1) + fSum(n-...
// problem 6: // name: Gabriele Berardi // s-number: s4878728 // table: XXXXX ghost function f(n: int): int { if n <= 0 then 1 else n + f(n-1)*f(n-2) } ghost function fSum(n: nat): int { // give the body of this function // it should return Sum(i: 0<=i < n: f(i)) if n <= 0 then 0 else f(n-1) + fSum(n-...
273
Program-Verification-Dataset_tmp_tmpgbdrlnu__Dafny_advanced examples_ArrayMap.dfy
// RUN: /print:log.bpl method ArrayMap<A>(f: int -> A, a: array<A>) requires a != null requires forall j :: 0 <= j < a.Length ==> f.requires(j) requires forall j :: 0 <= j < a.Length ==> a !in f.reads(j) modifies a ensures forall j :: 0 <= j < a.Length ==> a[j] == f(j) { var i := 0; while i < a.Length ...
// RUN: /print:log.bpl method ArrayMap<A>(f: int -> A, a: array<A>) requires a != null requires forall j :: 0 <= j < a.Length ==> f.requires(j) requires forall j :: 0 <= j < a.Length ==> a !in f.reads(j) modifies a ensures forall j :: 0 <= j < a.Length ==> a[j] == f(j) { var i := 0; while i < a.Length ...
274
Program-Verification-Dataset_tmp_tmpgbdrlnu__Dafny_advanced examples_EvenPredicate.dfy
// RUN: /compile:0 /nologo function IsEven(a : int) : bool requires a >= 0 { if a == 0 then true else if a == 1 then false else IsEven(a - 2) } lemma EvenSquare(a : int) requires a >= 0 ensures IsEven(a) ==> IsEven(a * a) { if a >= 2 && IsEven(a) { EvenSquare(a - 2); ...
// RUN: /compile:0 /nologo function IsEven(a : int) : bool requires a >= 0 { if a == 0 then true else if a == 1 then false else IsEven(a - 2) } lemma EvenSquare(a : int) requires a >= 0 ensures IsEven(a) ==> IsEven(a * a) { if a >= 2 && IsEven(a) { EvenSquare(a - 2); ...
275
Program-Verification-Dataset_tmp_tmpgbdrlnu__Dafny_advanced examples_GenericMax.dfy
method GenericMax<A>(cmp: (A, A) -> bool, a: array<A>) returns (max: A) requires a != null && a.Length > 0 requires forall x, y :: cmp.requires(x, y) requires forall x, y :: cmp(x, y) || cmp(y, x); requires forall x, y, z :: cmp(x, y) && cmp(y, z) ==> cmp(x, z); ensures forall x :: 0 <= x < a.Length ==> ...
method GenericMax<A>(cmp: (A, A) -> bool, a: array<A>) returns (max: A) requires a != null && a.Length > 0 requires forall x, y :: cmp.requires(x, y) requires forall x, y :: cmp(x, y) || cmp(y, x); requires forall x, y, z :: cmp(x, y) && cmp(y, z) ==> cmp(x, z); ensures forall x :: 0 <= x < a.Length ==> ...
276
Program-Verification-Dataset_tmp_tmpgbdrlnu__Dafny_advanced examples_InsertionSort.dfy
predicate sorted (a:array<int>, start:int, end:int) // all "before" end are sorted requires a!=null requires 0<=start<=end<=a.Length reads a { forall j,k:: start<=j<k<end ==> a[j]<=a[k] } method InsertionSort (a:array<int>) requires a!=null && a.Length>1 ensures sorted(...
predicate sorted (a:array<int>, start:int, end:int) // all "before" end are sorted requires a!=null requires 0<=start<=end<=a.Length reads a { forall j,k:: start<=j<k<end ==> a[j]<=a[k] } method InsertionSort (a:array<int>) requires a!=null && a.Length>1 ensures sorted(...
277
Program-Verification-Dataset_tmp_tmpgbdrlnu__Dafny_advanced examples_MatrixMultiplication.dfy
function RowColumnProduct(m1: array2<int>, m2: array2<int>, row: nat, column: nat): int reads m1 reads m2 requires m1 != null && m2 != null && m1.Length1 == m2.Length0 requires row < m1.Length0 && column < m2.Length1 { RowColumnProductFrom(m1, m2, row, column, 0) } function RowColumnProductFrom(m1:...
function RowColumnProduct(m1: array2<int>, m2: array2<int>, row: nat, column: nat): int reads m1 reads m2 requires m1 != null && m2 != null && m1.Length1 == m2.Length0 requires row < m1.Length0 && column < m2.Length1 { RowColumnProductFrom(m1, m2, row, column, 0) } function RowColumnProductFrom(m1:...
278
Program-Verification-Dataset_tmp_tmpgbdrlnu__Dafny_advanced examples_Modules.dfy
// RUN: /compile:1 abstract module Interface { type T function F(): T predicate P(x: T) lemma FP() ensures P(F()) } module Implementation refines Interface { predicate P(x: T) { false } } abstract module User { import I : Interface lemma Main() ensures I.P(I....
// RUN: /compile:1 abstract module Interface { type T function F(): T predicate P(x: T) lemma FP() ensures P(F()) } module Implementation refines Interface { predicate P(x: T) { false } } abstract module User { import I : Interface lemma Main() ensures I.P(I....
279
Program-Verification-Dataset_tmp_tmpgbdrlnu__Dafny_advanced examples_OneHundredPrisonersAndALightbulb.dfy
// RUN: /compile:0 /nologo method CardinalitySubsetLt<T>(A: set<T>, B: set<T>) requires A < B ensures |A| < |B| decreases B { var b :| b in B && b !in A; var B' := B - {b}; assert |B| == |B'| + 1; if A < B' { CardinalitySubsetLt(A, B'); } else { assert A == B'; } } method strategy<T>(P: set<...
// RUN: /compile:0 /nologo method CardinalitySubsetLt<T>(A: set<T>, B: set<T>) requires A < B ensures |A| < |B| { var b :| b in B && b !in A; var B' := B - {b}; if A < B' { CardinalitySubsetLt(A, B'); } else { } } method strategy<T>(P: set<T>, Special: T) returns (count: int) requires |P| > 1 && S...
280
Program-Verification-Dataset_tmp_tmpgbdrlnu__Dafny_advanced examples_Percentile.dfy
// Sum of elements of A from indices 0 to end. // end is inclusive! (not James's normal way of thinking!!) function SumUpto(A: array<real>, end: int): real requires -1 <= end < A.Length reads A { if end == -1 then 0.0 else A[end] + SumUpto(A, end-1) } function Sum(A: array<real>): real reads A { Su...
// Sum of elements of A from indices 0 to end. // end is inclusive! (not James's normal way of thinking!!) function SumUpto(A: array<real>, end: int): real requires -1 <= end < A.Length reads A { if end == -1 then 0.0 else A[end] + SumUpto(A, end-1) } function Sum(A: array<real>): real reads A { Su...
281
Program-Verification-Dataset_tmp_tmpgbdrlnu__Dafny_advanced examples_Refinement.dfy
// RUN: /nologo /rlimit:10000000 /noNLarith abstract module Interface { function addSome(n: nat): nat ensures addSome(n) > n } abstract module Mod { import A : Interface method m() { assert 6 <= A.addSome(5); print "Test\n"; } } module Implementation refines Interface { fu...
// RUN: /nologo /rlimit:10000000 /noNLarith abstract module Interface { function addSome(n: nat): nat ensures addSome(n) > n } abstract module Mod { import A : Interface method m() { print "Test\n"; } } module Implementation refines Interface { function addSome(n: nat): nat ...
282
Program-Verification-Dataset_tmp_tmpgbdrlnu__Dafny_advanced examples_ReverseString.dfy
// RUN: /compile:0 predicate reversed (arr : array<char>, outarr: array<char>) requires arr != null && outarr != null //requires 0<=k<=arr.Length-1 requires arr.Length == outarr.Length reads arr, outarr { forall k :: 0<=k<=arr.Length-1 ==> outarr[k] == arr[(arr.Length-1-k)] } method yarra(arr : array<char>) returns...
// RUN: /compile:0 predicate reversed (arr : array<char>, outarr: array<char>) requires arr != null && outarr != null //requires 0<=k<=arr.Length-1 requires arr.Length == outarr.Length reads arr, outarr { forall k :: 0<=k<=arr.Length-1 ==> outarr[k] == arr[(arr.Length-1-k)] } method yarra(arr : array<char>) returns...
283
Program-Verification-Dataset_tmp_tmpgbdrlnu__Dafny_advanced examples_demo.dfy
method Partition(a: array<int>) returns (lo: int, hi: int) modifies a ensures 0 <= lo <= hi <= a.Length ensures forall x | 0 <= x < lo :: a[x] < 0 ensures forall x | lo <= x < hi :: a[x] == 0 ensures forall x | hi <= x < a.Length :: a[x] > 0 { var i := 0; var j := a.Length; var k := a.Length; while i...
method Partition(a: array<int>) returns (lo: int, hi: int) modifies a ensures 0 <= lo <= hi <= a.Length ensures forall x | 0 <= x < lo :: a[x] < 0 ensures forall x | lo <= x < hi :: a[x] == 0 ensures forall x | hi <= x < a.Length :: a[x] > 0 { var i := 0; var j := a.Length; var k := a.Length; while i...
284
Program-Verification-Dataset_tmp_tmpgbdrlnu__Dafny_algorithms and leetcode_ProgramProofs_ch15.dfy
predicate SplitPoint(a: array<int>, n: int) reads a requires 0 <= n <= n { forall i,j :: 0 <= i < n <= j < a.Length ==> a[i] <= a[j] } 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[..])) { ...
predicate SplitPoint(a: array<int>, n: int) reads a requires 0 <= n <= n { forall i,j :: 0 <= i < n <= j < a.Length ==> a[i] <= a[j] } 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[..])) { ...
285
Program-Verification-Dataset_tmp_tmpgbdrlnu__Dafny_algorithms and leetcode_examples_bubblesort.dfy
//https://stackoverflow.com/questions/69364687/how-to-prove-time-complexity-of-bubble-sort-using-dafny function NChoose2(n: int): int { n * (n - 1) / 2 } // sum of all integers in the range [lo, hi) // (inclusive of lo, exclusive of hi) function SumRange(lo: int, hi: int): int decreases hi - lo { if lo >= hi the...
//https://stackoverflow.com/questions/69364687/how-to-prove-time-complexity-of-bubble-sort-using-dafny function NChoose2(n: int): int { n * (n - 1) / 2 } // sum of all integers in the range [lo, hi) // (inclusive of lo, exclusive of hi) function SumRange(lo: int, hi: int): int { if lo >= hi then 0 else SumRange(...
286
Program-Verification-Dataset_tmp_tmpgbdrlnu__Dafny_algorithms and leetcode_examples_relativeOrder.dfy
predicate IsEven (n: int) { n % 2 == 0 } method FindEvenNumbers (arr: array<int>) returns (evenNumbers: array<int>) ensures forall x :: x in arr[..] && IsEven(x) ==> x in evenNumbers[..]; ensures forall x :: x !in arr[..] ==> x !in evenNumbers[..] ensures forall k, l :: 0 <= k < l < evenNumbers.Length ==>...
predicate IsEven (n: int) { n % 2 == 0 } method FindEvenNumbers (arr: array<int>) returns (evenNumbers: array<int>) ensures forall x :: x in arr[..] && IsEven(x) ==> x in evenNumbers[..]; ensures forall x :: x !in arr[..] ==> x !in evenNumbers[..] ensures forall k, l :: 0 <= k < l < evenNumbers.Length ==>...
287
Program-Verification-Dataset_tmp_tmpgbdrlnu__Dafny_algorithms and leetcode_examples_simpleMultiplication.dfy
method Foo(y: int, x: int) returns (z: int) requires 0 <= y ensures z == x*y { var a: int := 0; z := 0; while a != y invariant 0 <= a <= y invariant z == a*x decreases y-a { z := z + x; a := a + 1; } return z; } function stringToSet(s: string): (r: set<char>) ensures forall x :: 0 <...
method Foo(y: int, x: int) returns (z: int) requires 0 <= y ensures z == x*y { var a: int := 0; z := 0; while a != y { z := z + x; a := a + 1; } return z; } function stringToSet(s: string): (r: set<char>) ensures forall x :: 0 <= x < |s| ==> s[x] in r { set x | 0 <= x < |s| :: s[x] } //ensu...
288
Program-Verification-Dataset_tmp_tmpgbdrlnu__Dafny_algorithms and leetcode_heap2.dfy
class Heap { var arr: array<int> constructor Heap (input: array<int>) ensures this.arr == input { this.arr := input; } function parent(idx: int): int { if idx == 0 then -1 else if idx % 2 == 0 then (idx-2)/2 else (idx-1)/2 } predicate IsMaxHeap(input: seq<int>) { forall i :: 0...
class Heap { var arr: array<int> constructor Heap (input: array<int>) ensures this.arr == input { this.arr := input; } function parent(idx: int): int { if idx == 0 then -1 else if idx % 2 == 0 then (idx-2)/2 else (idx-1)/2 } predicate IsMaxHeap(input: seq<int>) { forall i :: 0...
289
Program-Verification-Dataset_tmp_tmpgbdrlnu__Dafny_algorithms and leetcode_leetcode_BoatsToSavePeople.dfy
/* function numRescueBoats(people: number[], limit: number): number { //people.sort((a,b) => a-b); binsort(people, limit); let boats = 0; let lower = 0, upper = people.length-1; while(lower <= upper) { if(people[upper] == limit || people[upper]+people[lower] > limit) { boats++ ...
/* function numRescueBoats(people: number[], limit: number): number { //people.sort((a,b) => a-b); binsort(people, limit); let boats = 0; let lower = 0, upper = people.length-1; while(lower <= upper) { if(people[upper] == limit || people[upper]+people[lower] > limit) { boats++ ...
290
Program-Verification-Dataset_tmp_tmpgbdrlnu__Dafny_algorithms and leetcode_leetcode_FindPivotIndex.dfy
/* https://leetcode.com/problems/find-pivot-index/description/ Given an array of integers nums, calculate the pivot index of this array. The pivot index is the index where the sum of all the numbers strictly to the left of the index is equal to the sum of all the numbers strictly to the index's right. If the index is...
/* https://leetcode.com/problems/find-pivot-index/description/ Given an array of integers nums, calculate the pivot index of this array. The pivot index is the index where the sum of all the numbers strictly to the left of the index is equal to the sum of all the numbers strictly to the index's right. If the index is...
291
Program-Verification-Dataset_tmp_tmpgbdrlnu__Dafny_algorithms and leetcode_leetcode_ReverseLinkedList.dfy
/* https://leetcode.com/problems/reverse-linked-list/description/ * class ListNode { * val: number * next: ListNode | null * constructor(val?: number, next?: ListNode | null) { * this.val = (val===undefined ? 0 : val) * this.next = (next===undefined ? null : next) * } * } functi...
/* https://leetcode.com/problems/reverse-linked-list/description/ * class ListNode { * val: number * next: ListNode | null * constructor(val?: number, next?: ListNode | null) { * this.val = (val===undefined ? 0 : val) * this.next = (next===undefined ? null : next) * } * } functi...
292
Program-Verification-Dataset_tmp_tmpgbdrlnu__Dafny_algorithms and leetcode_leetcode_lc-remove-element.dfy
//https://leetcode.com/problems/remove-element/ method removeElement(nums: array<int>, val: int) returns (i: int) ensures forall k :: 0 < k < i < nums.Length ==> nums[k] != val modifies nums { i := 0; var end := nums.Length - 1; while i <= end invariant 0 <= i <= nums.Length invaria...
//https://leetcode.com/problems/remove-element/ method removeElement(nums: array<int>, val: int) returns (i: int) ensures forall k :: 0 < k < i < nums.Length ==> nums[k] != val modifies nums { i := 0; var end := nums.Length - 1; while i <= end { if(nums[i] == val) { if(nums[...
293
Program-Verification-Dataset_tmp_tmpgbdrlnu__Dafny_algorithms and leetcode_leetcode_pathSum.dfy
//https://leetcode.com/problems/path-sum /** function hasPathSum(root: TreeNode | null, targetSum: number): boolean { if(root == null) { return false; } if(root.val-targetSum == 0 && root.left == null && root.right == null) { return true; } return hasPathSum(root.left, targetSum-root...
//https://leetcode.com/problems/path-sum /** function hasPathSum(root: TreeNode | null, targetSum: number): boolean { if(root == null) { return false; } if(root.val-targetSum == 0 && root.left == null && root.right == null) { return true; } return hasPathSum(root.left, targetSum-root...
294
Program-Verification-Dataset_tmp_tmpgbdrlnu__Dafny_algorithms and leetcode_leetcode_stairClimbing.dfy
/* You are climbing a staircase. It takes n steps to reach the top. Each time you can either climb 1 or 2 steps. In how many distinct ways can you climb to the top? function climbStairs(n: number): number { let steps = new Array(n+1); steps[0] = 0; steps[1] = 1; steps[2] = 2; for(let i = 3; i <= n;...
/* You are climbing a staircase. It takes n steps to reach the top. Each time you can either climb 1 or 2 steps. In how many distinct ways can you climb to the top? function climbStairs(n: number): number { let steps = new Array(n+1); steps[0] = 0; steps[1] = 1; steps[2] = 2; for(let i = 3; i <= n;...
295
Program-Verification-Dataset_tmp_tmpgbdrlnu__Dafny_algorithms and leetcode_leetcode_validAnagram.dfy
method toMultiset(s: string) returns (mset: multiset<char>) ensures multiset(s) == mset { mset := multiset{}; for i := 0 to |s| invariant mset == multiset(s[0..i]) { assert s == s[0..i] + [s[i]] + s[(i+1)..]; // assert multiset(s) == multiset(s[0..i])+multiset{s[i]}+multiset(s[...
method toMultiset(s: string) returns (mset: multiset<char>) ensures multiset(s) == mset { mset := multiset{}; for i := 0 to |s| { // assert multiset(s) == multiset(s[0..i])+multiset{s[i]}+multiset(s[(i+1)..]); mset := mset + multiset{s[i]}; } // assert mset == multiset(s[0..|s|...
296
Program-Verification-Dataset_tmp_tmpgbdrlnu__Dafny_algorithms and leetcode_lib_seq.dfy
module Seq { export reveals * function ToSet<A>(xs: seq<A>): set<A> ensures forall x :: x in ToSet(xs) ==> x in xs ensures forall x :: x !in ToSet(xs) ==> x !in xs { if xs == [] then {} else {xs[0]}+ToSet(xs[1..]) } predicate substring1<A(==)>(sub: seq<A>, super: seq<A>) { ...
module Seq { export reveals * function ToSet<A>(xs: seq<A>): set<A> ensures forall x :: x in ToSet(xs) ==> x in xs ensures forall x :: x !in ToSet(xs) ==> x !in xs { if xs == [] then {} else {xs[0]}+ToSet(xs[1..]) } predicate substring1<A(==)>(sub: seq<A>, super: seq<A>) { ...
297
Program-Verification-Dataset_tmp_tmpgbdrlnu__Dafny_algorithms and leetcode_math_pearson.dfy
function eight(x: nat):nat { 9 * x + 5 } predicate isOdd(x: nat) { x % 2 == 1 } predicate isEven(x: nat) { x % 2 == 0 } lemma eightL(x: nat) requires isOdd(x) ensures isEven(eight(x)) { } function nineteenf(x: nat): nat { 7*x+4 } function nineteens(x: nat): nat { 3*x+11 } lemma ninet...
function eight(x: nat):nat { 9 * x + 5 } predicate isOdd(x: nat) { x % 2 == 1 } predicate isEven(x: nat) { x % 2 == 0 } lemma eightL(x: nat) requires isOdd(x) ensures isEven(eight(x)) { } function nineteenf(x: nat): nat { 7*x+4 } function nineteens(x: nat): nat { 3*x+11 } lemma ninet...
298
Program-Verification-Dataset_tmp_tmpgbdrlnu__Dafny_basic examples_BubbleSort.dfy
predicate sorted(a:array<int>, from:int, to:int) requires a != null; reads a; requires 0 <= from <= to <= a.Length; { forall u, v :: from <= u < v < to ==> a[u] <= a[v] } predicate pivot(a:array<int>, to:int, pvt:int) requires a != null; reads a; requires 0 <= pvt < to <= a.Length; { forall u, v :: 0 <...
predicate sorted(a:array<int>, from:int, to:int) requires a != null; reads a; requires 0 <= from <= to <= a.Length; { forall u, v :: from <= u < v < to ==> a[u] <= a[v] } predicate pivot(a:array<int>, to:int, pvt:int) requires a != null; reads a; requires 0 <= pvt < to <= a.Length; { forall u, v :: 0 <...
299
Program-Verification-Dataset_tmp_tmpgbdrlnu__Dafny_basic examples_BubbleSort_sol.dfy
predicate sorted_between (a:array<int>, from:nat, to:nat) reads a; requires a != null; requires from <= to; requires to <= a.Length; { forall i,j :: from <= i < j < to && 0 <= i < j < a.Length ==> a[i] <= a[j] } predicate sorted (a:array<int>) reads a; requires a!=null; { sorted_between (a, 0, a.Leng...
predicate sorted_between (a:array<int>, from:nat, to:nat) reads a; requires a != null; requires from <= to; requires to <= a.Length; { forall i,j :: from <= i < j < to && 0 <= i < j < a.Length ==> a[i] <= a[j] } predicate sorted (a:array<int>) reads a; requires a!=null; { sorted_between (a, 0, a.Leng...