1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110
|
default Order dec
$include <prelude.sail>
$include <smt.sail>
overload operator % = emod_int
/* The variable p in these tests should have a proof attached at the loop.
First, tests with pure loop bodies. */
val test1 : forall 'n, 'n > 0. (int('n),int) -> int
function test1(n,m) = {
p : range(0,'n) = n;
foreach (i from 0 to m) {
p = (p + 1) % n;
};
p
}
val test2 : forall 'n, 'n > 0. (int('n),int) -> int
function test2(n,m) = {
p : range(0,'n) = n;
q : int = 0;
foreach (i from 0 to m) {
p = (p + 1) % n;
q = q + 1;
};
p+q
}
val test3 : forall 'n, 'n > 0. (int('n),int) -> int
function test3(n,m) = {
p : range(0,'n) = n;
repeat {
p = (p + 1) % n;
} until p == 0;
p
}
termination_measure test3 until p
val test4 : forall 'n, 'n > 0. (int('n),int) -> int
function test4(n,m) = {
p : range(0,'n) = n;
q : int = 0;
repeat {
p = (p + 1) % n;
q = q + 1;
} until p == 0;
p+q
}
termination_measure test4 until p
/* Now with loop bodies with an assertion */
val test1e : forall 'n, 'n > 0. (int('n),int) -> int effect {escape}
function test1e(n,m) = {
p : range(0,'n) = n;
foreach (i from 0 to m) {
assert(p >= 0);
p = (p + 1) % n;
};
p
}
val test2e : forall 'n, 'n > 0. (int('n),int) -> int effect {escape}
function test2e(n,m) = {
p : range(0,'n) = n;
q : int = 0;
foreach (i from 0 to m) {
assert(p >= 0);
p = (p + 1) % n;
q = q + 1;
};
p+q
}
val test3e : forall 'n, 'n > 0. (int('n),int) -> int effect {escape}
function test3e(n,m) = {
p : range(0,'n) = n;
repeat {
assert(p >= 0);
p = (p + 1) % n;
} until p == 0;
p
}
termination_measure test3e until p
val test4e : forall 'n, 'n > 0. (int('n),int) -> int effect {escape}
function test4e(n,m) = {
p : range(0,'n) = n;
q : int = 0;
repeat {
assert(p >= 0);
p = (p + 1) % n;
q = q + 1;
} until p == 0;
p+q
}
termination_measure test4e until p
|