-
Notifications
You must be signed in to change notification settings - Fork 1
/
ArrayMap.dfy
46 lines (39 loc) · 968 Bytes
/
ArrayMap.dfy
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
// 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
invariant 0 <= i <= a.Length;
invariant forall j :: 0 <= j < i ==> a[j] == f(j)
{
a[i] := f(i);
i := i + 1;
}
}
/*method GenericSort<A>(cmp: (A, A) -> bool, a: array<A>)
requires a != null
requires forall x, y :: a !in cmp.reads(x, y)
requires forall x, y :: cmp.requires(x, y)
modifies a
ensures forall x, y :: cmp.requires(x, y)
ensures forall x, y :: 0 <= x < y < a.Length ==> cmp(a[x], a[y])
{
var i := 0;
while i < a.Length
modifies a
{
var j := i - 1;
while j >= 0 && !cmp(a[j], a[i])
modifies a
{
a[i], a[j] := a[j], a[i];
j := j - 1;
}
i := i + 1;
}
}*/