17456
|
1 |
(* Title: CCL/CCL.thy
|
0
|
2 |
ID: $Id$
|
1474
|
3 |
Author: Martin Coen
|
0
|
4 |
Copyright 1993 University of Cambridge
|
|
5 |
*)
|
|
6 |
|
17456
|
7 |
header {* Classical Computational Logic for Untyped Lambda Calculus
|
|
8 |
with reduction to weak head-normal form *}
|
0
|
9 |
|
17456
|
10 |
theory CCL
|
|
11 |
imports Gfp
|
|
12 |
begin
|
0
|
13 |
|
17456
|
14 |
text {*
|
|
15 |
Based on FOL extended with set collection, a primitive higher-order
|
|
16 |
logic. HOL is too strong - descriptions prevent a type of programs
|
|
17 |
being defined which contains only executable terms.
|
|
18 |
*}
|
0
|
19 |
|
17456
|
20 |
classes prog < "term"
|
|
21 |
defaultsort prog
|
|
22 |
|
|
23 |
arities fun :: (prog, prog) prog
|
|
24 |
|
|
25 |
typedecl i
|
|
26 |
arities i :: prog
|
|
27 |
|
0
|
28 |
|
|
29 |
consts
|
|
30 |
(*** Evaluation Judgement ***)
|
|
31 |
"--->" :: "[i,i]=>prop" (infixl 20)
|
|
32 |
|
|
33 |
(*** Bisimulations for pre-order and equality ***)
|
|
34 |
"[=" :: "['a,'a]=>o" (infixl 50)
|
|
35 |
SIM :: "[i,i,i set]=>o"
|
17456
|
36 |
POgen :: "i set => i set"
|
|
37 |
EQgen :: "i set => i set"
|
|
38 |
PO :: "i set"
|
|
39 |
EQ :: "i set"
|
0
|
40 |
|
|
41 |
(*** Term Formers ***)
|
17456
|
42 |
true :: "i"
|
|
43 |
false :: "i"
|
0
|
44 |
pair :: "[i,i]=>i" ("(1<_,/_>)")
|
|
45 |
lambda :: "(i=>i)=>i" (binder "lam " 55)
|
17456
|
46 |
"case" :: "[i,i,i,[i,i]=>i,(i=>i)=>i]=>i"
|
0
|
47 |
"`" :: "[i,i]=>i" (infixl 56)
|
|
48 |
bot :: "i"
|
17456
|
49 |
"fix" :: "(i=>i)=>i"
|
0
|
50 |
|
|
51 |
(*** Defined Predicates ***)
|
17456
|
52 |
Trm :: "i => o"
|
|
53 |
Dvg :: "i => o"
|
0
|
54 |
|
17456
|
55 |
axioms
|
0
|
56 |
|
|
57 |
(******* EVALUATION SEMANTICS *******)
|
|
58 |
|
|
59 |
(** This is the evaluation semantics from which the axioms below were derived. **)
|
|
60 |
(** It is included here just as an evaluator for FUN and has no influence on **)
|
|
61 |
(** inference in the theory CCL. **)
|
|
62 |
|
17456
|
63 |
trueV: "true ---> true"
|
|
64 |
falseV: "false ---> false"
|
|
65 |
pairV: "<a,b> ---> <a,b>"
|
|
66 |
lamV: "lam x. b(x) ---> lam x. b(x)"
|
|
67 |
caseVtrue: "[| t ---> true; d ---> c |] ==> case(t,d,e,f,g) ---> c"
|
|
68 |
caseVfalse: "[| t ---> false; e ---> c |] ==> case(t,d,e,f,g) ---> c"
|
|
69 |
caseVpair: "[| t ---> <a,b>; f(a,b) ---> c |] ==> case(t,d,e,f,g) ---> c"
|
|
70 |
caseVlam: "[| t ---> lam x. b(x); g(b) ---> c |] ==> case(t,d,e,f,g) ---> c"
|
0
|
71 |
|
|
72 |
(*** Properties of evaluation: note that "t ---> c" impies that c is canonical ***)
|
|
73 |
|
17456
|
74 |
canonical: "[| t ---> c; c==true ==> u--->v;
|
|
75 |
c==false ==> u--->v;
|
|
76 |
!!a b. c==<a,b> ==> u--->v;
|
|
77 |
!!f. c==lam x. f(x) ==> u--->v |] ==>
|
1149
|
78 |
u--->v"
|
0
|
79 |
|
|
80 |
(* Should be derivable - but probably a bitch! *)
|
17456
|
81 |
substitute: "[| a==a'; t(a)--->c(a) |] ==> t(a')--->c(a')"
|
0
|
82 |
|
|
83 |
(************** LOGIC ***************)
|
|
84 |
|
|
85 |
(*** Definitions used in the following rules ***)
|
|
86 |
|
17456
|
87 |
apply_def: "f ` t == case(f,bot,bot,%x y. bot,%u. u(t))"
|
|
88 |
bot_def: "bot == (lam x. x`x)`(lam x. x`x)"
|
|
89 |
fix_def: "fix(f) == (lam x. f(x`x))`(lam x. f(x`x))"
|
0
|
90 |
|
|
91 |
(* The pre-order ([=) is defined as a simulation, and behavioural equivalence (=) *)
|
|
92 |
(* as a bisimulation. They can both be expressed as (bi)simulations up to *)
|
|
93 |
(* behavioural equivalence (ie the relations PO and EQ defined below). *)
|
|
94 |
|
17456
|
95 |
SIM_def:
|
|
96 |
"SIM(t,t',R) == (t=true & t'=true) | (t=false & t'=false) |
|
|
97 |
(EX a a' b b'. t=<a,b> & t'=<a',b'> & <a,a'> : R & <b,b'> : R) |
|
3837
|
98 |
(EX f f'. t=lam x. f(x) & t'=lam x. f'(x) & (ALL x.<f(x),f'(x)> : R))"
|
0
|
99 |
|
17456
|
100 |
POgen_def: "POgen(R) == {p. EX t t'. p=<t,t'> & (t = bot | SIM(t,t',R))}"
|
|
101 |
EQgen_def: "EQgen(R) == {p. EX t t'. p=<t,t'> & (t = bot & t' = bot | SIM(t,t',R))}"
|
0
|
102 |
|
17456
|
103 |
PO_def: "PO == gfp(POgen)"
|
|
104 |
EQ_def: "EQ == gfp(EQgen)"
|
0
|
105 |
|
|
106 |
(*** Rules ***)
|
|
107 |
|
|
108 |
(** Partial Order **)
|
|
109 |
|
17456
|
110 |
po_refl: "a [= a"
|
|
111 |
po_trans: "[| a [= b; b [= c |] ==> a [= c"
|
|
112 |
po_cong: "a [= b ==> f(a) [= f(b)"
|
0
|
113 |
|
|
114 |
(* Extend definition of [= to program fragments of higher type *)
|
17456
|
115 |
po_abstractn: "(!!x. f(x) [= g(x)) ==> (%x. f(x)) [= (%x. g(x))"
|
0
|
116 |
|
|
117 |
(** Equality - equivalence axioms inherited from FOL.thy **)
|
|
118 |
(** - congruence of "=" is axiomatised implicitly **)
|
|
119 |
|
17456
|
120 |
eq_iff: "t = t' <-> t [= t' & t' [= t"
|
0
|
121 |
|
|
122 |
(** Properties of canonical values given by greatest fixed point definitions **)
|
17456
|
123 |
|
|
124 |
PO_iff: "t [= t' <-> <t,t'> : PO"
|
|
125 |
EQ_iff: "t = t' <-> <t,t'> : EQ"
|
0
|
126 |
|
|
127 |
(** Behaviour of non-canonical terms (ie case) given by the following beta-rules **)
|
|
128 |
|
17456
|
129 |
caseBtrue: "case(true,d,e,f,g) = d"
|
|
130 |
caseBfalse: "case(false,d,e,f,g) = e"
|
|
131 |
caseBpair: "case(<a,b>,d,e,f,g) = f(a,b)"
|
|
132 |
caseBlam: "case(lam x. b(x),d,e,f,g) = g(b)"
|
|
133 |
caseBbot: "case(bot,d,e,f,g) = bot" (* strictness *)
|
0
|
134 |
|
|
135 |
(** The theory is non-trivial **)
|
17456
|
136 |
distinctness: "~ lam x. b(x) = bot"
|
0
|
137 |
|
|
138 |
(*** Definitions of Termination and Divergence ***)
|
|
139 |
|
17456
|
140 |
Dvg_def: "Dvg(t) == t = bot"
|
|
141 |
Trm_def: "Trm(t) == ~ Dvg(t)"
|
0
|
142 |
|
17456
|
143 |
text {*
|
0
|
144 |
Would be interesting to build a similar theory for a typed programming language:
|
|
145 |
ie. true :: bool, fix :: ('a=>'a)=>'a etc......
|
|
146 |
|
|
147 |
This is starting to look like LCF.
|
17456
|
148 |
What are the advantages of this approach?
|
|
149 |
- less axiomatic
|
0
|
150 |
- wfd induction / coinduction and fixed point induction available
|
17456
|
151 |
*}
|
|
152 |
|
|
153 |
ML {* use_legacy_bindings (the_context ()) *}
|
|
154 |
|
|
155 |
end
|