this repo has no description
1%% odd-even sort
2%% y is the sorted version of x, all trues before falses
3predicate oesort(array[int] of var bool:x, array[int] of var bool:y)=
4 let { int: c = card(index_set(x)) } in
5 if c == 1 then x[1] == y[1]
6 elseif c == 2 then comparator(x[1],x[2],y[1],y[2])
7 else
8 let {
9 array[1..c div 2] of var bool:xf = [x[i] | i in 1..c div 2],
10 array[1..c div 2] of var bool:xl = [x[i] | i in c div 2 +1..c],
11 array[1..c div 2] of var bool:tf,
12 array[1..c div 2] of var bool:tl } in
13 oesort(xf,tf) /\ oesort(xl,tl) /\ oemerge(tf ++ tl, y)
14 endif;
15
16%% odd-even merge
17%% y is the sorted version of x, all trues before falses
18%% assumes first half of x is sorted, and second half of x
19predicate oemerge(array[int] of var bool:x, array[int] of var bool:y)=
20 let { int: c = card(index_set(x)) } in
21 if c == 1 then x[1] == y[1]
22 elseif c == 2 then comparator(x[1],x[2],y[1],y[2])
23 else
24 let { array[1..c div 2] of var bool:xo =
25 [ x[i] | i in 1..c where i mod 2 == 1],
26 array[1..c div 2] of var bool:xe =
27 [ x[i] | i in 1..c where i mod 2 == 0],
28 array[1..c div 2] of var bool:to,
29 array[1..c div 2] of var bool:te } in
30 oemerge(xo,to) /\ oemerge(xe,te) /\
31 y[1] = to[1] /\
32 forall(i in 1..c div 2 -1)(
33 comparator(te[i],to[i+1],y[2*i],y[2*i+1])) /\
34 y[c] = te[c div 2]
35 endif;
36
37% comparator o1 = max(i1,i2), o2 = min(i1,i2)
38predicate comparator(var bool:i1,var bool:i2,var bool:o1,var bool:o2)=
39 (o1 = (i1 \/ i2)) /\ (o2 = (i1 /\ i2));