-
Notifications
You must be signed in to change notification settings - Fork 0
/
sorting.h
44 lines (39 loc) · 1.19 KB
/
sorting.h
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
#ifndef SPEC_SORTING_H
#define SPEC_SORTING_H
/*@ predicate Swap{L1,L2}(int *a, integer i, integer j) =
\at(a[i],L1) == \at(a[j],L2) &&
\at(a[j],L1) == \at(a[i],L2) &&
\forall integer k; k != i && k != j
==> \at(a[k],L1) == \at(a[k],L2);
*/
/*@ inductive Permut{L1,L2}(int *a, integer l, integer h) {
case Permut_refl{L}:
\forall int *a, integer l, h; Permut{L,L}(a, l, h);
case Permut_sym{L1,L2}:
\forall int *a, integer l, h;
Permut{L1,L2}(a, l, h) ==> Permut{L2,L1}(a, l, h);
case Permut_trans{L1,L2,L3}:
\forall int *a, integer l, h;
Permut{L1,L2}(a, l, h) && Permut{L2,L3}(a, l, h) ==>
Permut{L1,L3}(a, l, h);
case Permut_swap{L1,L2}:
\forall int *a, integer l, h, i, j;
l <= i <= h && l <= j <= h && Swap{L1,L2}(a, i, j) ==>
Permut{L1,L2}(a, l, h);
}
*/
/*@ predicate Sorted{L}(int *a, integer l, integer h) =
\forall integer i,j; l <= i <= j < h ==> a[i] <= a[j];
*/
/*@ requires \valid(t+i);
requires \valid(t+j);
assigns t[i],t[j];
ensures Swap{Old,Here}(t,i,j);
*/
void sort_swap(int t[], int i, int j)
{
int tmp = t[i];
t[i] = t[j];
t[j] = tmp;
}
#endif