17456
|
1 |
(* Title: CCL/ex/Flag.thy
|
0
|
2 |
ID: $Id$
|
1474
|
3 |
Author: Martin Coen, Cambridge University Computer Laboratory
|
0
|
4 |
Copyright 1993 University of Cambridge
|
|
5 |
*)
|
|
6 |
|
17456
|
7 |
header {* Dutch national flag program -- except that the point of Dijkstra's example was to use
|
|
8 |
arrays and this uses lists. *}
|
|
9 |
|
|
10 |
theory Flag
|
|
11 |
imports List
|
|
12 |
begin
|
0
|
13 |
|
|
14 |
consts
|
|
15 |
Colour :: "i set"
|
17456
|
16 |
red :: "i"
|
|
17 |
white :: "i"
|
|
18 |
blue :: "i"
|
0
|
19 |
ccase :: "[i,i,i,i]=>i"
|
|
20 |
flag :: "i"
|
|
21 |
|
17456
|
22 |
axioms
|
0
|
23 |
|
17456
|
24 |
Colour_def: "Colour == Unit + Unit + Unit"
|
|
25 |
red_def: "red == inl(one)"
|
|
26 |
white_def: "white == inr(inl(one))"
|
|
27 |
blue_def: "blue == inr(inr(one))"
|
0
|
28 |
|
17456
|
29 |
ccase_def: "ccase(c,r,w,b) == when(c,%x. r,%wb. when(wb,%x. w,%x. b))"
|
0
|
30 |
|
17456
|
31 |
flag_def: "flag == lam l. letrec
|
|
32 |
flagx l be lcase(l,<[],<[],[]>>,
|
|
33 |
%h t. split(flagx(t),%lr p. split(p,%lw lb.
|
|
34 |
ccase(h, <red$lr,<lw,lb>>,
|
|
35 |
<lr,<white$lw,lb>>,
|
|
36 |
<lr,<lw,blue$lb>>))))
|
|
37 |
in flagx(l)"
|
0
|
38 |
|
17456
|
39 |
Flag_def:
|
|
40 |
"Flag(l,x) == ALL lr:List(Colour).ALL lw:List(Colour).ALL lb:List(Colour).
|
|
41 |
x = <lr,<lw,lb>> -->
|
|
42 |
(ALL c:Colour.(c mem lr = true --> c=red) &
|
|
43 |
(c mem lw = true --> c=white) &
|
|
44 |
(c mem lb = true --> c=blue)) &
|
1149
|
45 |
Perm(l,lr @ lw @ lb)"
|
0
|
46 |
|
17456
|
47 |
ML {* use_legacy_bindings (the_context ()) *}
|
0
|
48 |
|
17456
|
49 |
end
|