author | wenzelm |
Tue, 28 Oct 1997 17:58:35 +0100 | |
changeset 4029 | 22f2d1b17f97 |
parent 3014 | f5554654d211 |
child 4091 | 771b1f6422a8 |
permissions | -rw-r--r-- |
1461 | 1 |
(* Title: ZF/ex/comb.ML |
0 | 2 |
ID: $Id$ |
1461 | 3 |
Author: Lawrence C Paulson |
0 | 4 |
Copyright 1993 University of Cambridge |
5 |
||
515 | 6 |
Combinatory Logic example: the Church-Rosser Theorem |
7 |
Curiously, combinators do not include free variables. |
|
8 |
||
9 |
Example taken from |
|
10 |
J. Camilleri and T. F. Melham. |
|
11 |
Reasoning with Inductively Defined Relations in the HOL Theorem Prover. |
|
12 |
Report 265, University of Cambridge Computer Laboratory, 1992. |
|
13 |
||
14 |
HOL system proofs may be found in |
|
15 |
/usr/groups/theory/hvg-aftp/contrib/rule-induction/cl.ml |
|
16 |
*) |
|
17 |
||
18 |
open Comb; |
|
19 |
||
3014
f5554654d211
Moved diamond_trancl (which is independent of the rest) to the top
paulson
parents:
2954
diff
changeset
|
20 |
(*** Transitive closure preserves the Church-Rosser property ***) |
f5554654d211
Moved diamond_trancl (which is independent of the rest) to the top
paulson
parents:
2954
diff
changeset
|
21 |
|
f5554654d211
Moved diamond_trancl (which is independent of the rest) to the top
paulson
parents:
2954
diff
changeset
|
22 |
goalw Comb.thy [diamond_def] |
f5554654d211
Moved diamond_trancl (which is independent of the rest) to the top
paulson
parents:
2954
diff
changeset
|
23 |
"!!x y r. [| diamond(r); <x,y>:r^+ |] ==> \ |
f5554654d211
Moved diamond_trancl (which is independent of the rest) to the top
paulson
parents:
2954
diff
changeset
|
24 |
\ ALL y'. <x,y'>:r --> (EX z. <y',z>: r^+ & <y,z>: r)"; |
f5554654d211
Moved diamond_trancl (which is independent of the rest) to the top
paulson
parents:
2954
diff
changeset
|
25 |
by (etac trancl_induct 1); |
f5554654d211
Moved diamond_trancl (which is independent of the rest) to the top
paulson
parents:
2954
diff
changeset
|
26 |
by (blast_tac (!claset addIs [r_into_trancl]) 1); |
f5554654d211
Moved diamond_trancl (which is independent of the rest) to the top
paulson
parents:
2954
diff
changeset
|
27 |
by (slow_best_tac (!claset addSDs [spec RS mp] |
f5554654d211
Moved diamond_trancl (which is independent of the rest) to the top
paulson
parents:
2954
diff
changeset
|
28 |
addIs [r_into_trancl, trans_trancl RS transD]) 1); |
f5554654d211
Moved diamond_trancl (which is independent of the rest) to the top
paulson
parents:
2954
diff
changeset
|
29 |
val diamond_strip_lemmaE = result() RS spec RS mp RS exE; |
f5554654d211
Moved diamond_trancl (which is independent of the rest) to the top
paulson
parents:
2954
diff
changeset
|
30 |
|
f5554654d211
Moved diamond_trancl (which is independent of the rest) to the top
paulson
parents:
2954
diff
changeset
|
31 |
val [major] = goal Comb.thy "diamond(r) ==> diamond(r^+)"; |
f5554654d211
Moved diamond_trancl (which is independent of the rest) to the top
paulson
parents:
2954
diff
changeset
|
32 |
by (rewtac diamond_def); (*unfold only in goal, not in premise!*) |
f5554654d211
Moved diamond_trancl (which is independent of the rest) to the top
paulson
parents:
2954
diff
changeset
|
33 |
by (rtac (impI RS allI RS allI) 1); |
f5554654d211
Moved diamond_trancl (which is independent of the rest) to the top
paulson
parents:
2954
diff
changeset
|
34 |
by (etac trancl_induct 1); |
f5554654d211
Moved diamond_trancl (which is independent of the rest) to the top
paulson
parents:
2954
diff
changeset
|
35 |
by (ALLGOALS (*Seems to be a brittle, undirected search*) |
f5554654d211
Moved diamond_trancl (which is independent of the rest) to the top
paulson
parents:
2954
diff
changeset
|
36 |
(slow_best_tac (!claset addIs [r_into_trancl, trans_trancl RS transD] |
f5554654d211
Moved diamond_trancl (which is independent of the rest) to the top
paulson
parents:
2954
diff
changeset
|
37 |
addEs [major RS diamond_strip_lemmaE]))); |
f5554654d211
Moved diamond_trancl (which is independent of the rest) to the top
paulson
parents:
2954
diff
changeset
|
38 |
qed "diamond_trancl"; |
f5554654d211
Moved diamond_trancl (which is independent of the rest) to the top
paulson
parents:
2954
diff
changeset
|
39 |
|
f5554654d211
Moved diamond_trancl (which is independent of the rest) to the top
paulson
parents:
2954
diff
changeset
|
40 |
|
515 | 41 |
val [_,_,comb_Ap] = comb.intrs; |
42 |
val Ap_E = comb.mk_cases comb.con_defs "p#q : comb"; |
|
43 |
||
3014
f5554654d211
Moved diamond_trancl (which is independent of the rest) to the top
paulson
parents:
2954
diff
changeset
|
44 |
AddSIs comb.intrs; |
f5554654d211
Moved diamond_trancl (which is independent of the rest) to the top
paulson
parents:
2954
diff
changeset
|
45 |
AddSEs comb.free_SEs; |
f5554654d211
Moved diamond_trancl (which is independent of the rest) to the top
paulson
parents:
2954
diff
changeset
|
46 |
|
515 | 47 |
|
48 |
(*** Results about Contraction ***) |
|
49 |
||
50 |
(*For type checking: replaces a-1->b by a,b:comb *) |
|
51 |
val contract_combE2 = contract.dom_subset RS subsetD RS SigmaE2; |
|
52 |
val contract_combD1 = contract.dom_subset RS subsetD RS SigmaD1; |
|
53 |
val contract_combD2 = contract.dom_subset RS subsetD RS SigmaD2; |
|
54 |
||
55 |
goal Comb.thy "field(contract) = comb"; |
|
2954 | 56 |
by (blast_tac (!claset addIs [contract.K] addSEs [contract_combE2]) 1); |
760 | 57 |
qed "field_contract_eq"; |
515 | 58 |
|
782
200a16083201
added bind_thm for theorems defined by "standard ..."
clasohm
parents:
760
diff
changeset
|
59 |
bind_thm ("reduction_refl", |
200a16083201
added bind_thm for theorems defined by "standard ..."
clasohm
parents:
760
diff
changeset
|
60 |
(field_contract_eq RS equalityD2 RS subsetD RS rtrancl_refl)); |
515 | 61 |
|
782
200a16083201
added bind_thm for theorems defined by "standard ..."
clasohm
parents:
760
diff
changeset
|
62 |
bind_thm ("rtrancl_into_rtrancl2", |
200a16083201
added bind_thm for theorems defined by "standard ..."
clasohm
parents:
760
diff
changeset
|
63 |
(r_into_rtrancl RS (trans_rtrancl RS transD))); |
515 | 64 |
|
3014
f5554654d211
Moved diamond_trancl (which is independent of the rest) to the top
paulson
parents:
2954
diff
changeset
|
65 |
AddSIs [reduction_refl, contract.K, contract.S]; |
f5554654d211
Moved diamond_trancl (which is independent of the rest) to the top
paulson
parents:
2954
diff
changeset
|
66 |
|
f5554654d211
Moved diamond_trancl (which is independent of the rest) to the top
paulson
parents:
2954
diff
changeset
|
67 |
val reduction_rls = [contract.K RS rtrancl_into_rtrancl2, |
1461 | 68 |
contract.S RS rtrancl_into_rtrancl2, |
69 |
contract.Ap1 RS rtrancl_into_rtrancl2, |
|
70 |
contract.Ap2 RS rtrancl_into_rtrancl2]; |
|
515 | 71 |
|
72 |
(*Example only: not used*) |
|
73 |
goalw Comb.thy [I_def] "!!p. p:comb ==> I#p ---> p"; |
|
3014
f5554654d211
Moved diamond_trancl (which is independent of the rest) to the top
paulson
parents:
2954
diff
changeset
|
74 |
by (blast_tac (!claset addIs reduction_rls) 1); |
782
200a16083201
added bind_thm for theorems defined by "standard ..."
clasohm
parents:
760
diff
changeset
|
75 |
qed "reduce_I"; |
515 | 76 |
|
77 |
goalw Comb.thy [I_def] "I: comb"; |
|
3014
f5554654d211
Moved diamond_trancl (which is independent of the rest) to the top
paulson
parents:
2954
diff
changeset
|
78 |
by (Blast_tac 1); |
760 | 79 |
qed "comb_I"; |
515 | 80 |
|
81 |
(** Non-contraction results **) |
|
0 | 82 |
|
515 | 83 |
(*Derive a case for each combinator constructor*) |
84 |
val K_contractE = contract.mk_cases comb.con_defs "K -1-> r"; |
|
85 |
val S_contractE = contract.mk_cases comb.con_defs "S -1-> r"; |
|
86 |
val Ap_contractE = contract.mk_cases comb.con_defs "p#q -1-> r"; |
|
87 |
||
3014
f5554654d211
Moved diamond_trancl (which is independent of the rest) to the top
paulson
parents:
2954
diff
changeset
|
88 |
AddIs [contract.Ap1, contract.Ap2]; |
2469 | 89 |
AddSEs [K_contractE, S_contractE, Ap_contractE]; |
515 | 90 |
|
91 |
goalw Comb.thy [I_def] "!!r. I -1-> r ==> P"; |
|
2954 | 92 |
by (Blast_tac 1); |
782
200a16083201
added bind_thm for theorems defined by "standard ..."
clasohm
parents:
760
diff
changeset
|
93 |
qed "I_contract_E"; |
515 | 94 |
|
95 |
goal Comb.thy "!!p r. K#p -1-> r ==> (EX q. r = K#q & p -1-> q)"; |
|
2954 | 96 |
by (Blast_tac 1); |
782
200a16083201
added bind_thm for theorems defined by "standard ..."
clasohm
parents:
760
diff
changeset
|
97 |
qed "K1_contractD"; |
515 | 98 |
|
99 |
goal Comb.thy "!!p r. [| p ---> q; r: comb |] ==> p#r ---> q#r"; |
|
100 |
by (forward_tac [rtrancl_type RS subsetD RS SigmaD1] 1); |
|
101 |
by (dtac (field_contract_eq RS equalityD1 RS subsetD) 1); |
|
102 |
by (etac rtrancl_induct 1); |
|
2954 | 103 |
by (blast_tac (!claset addIs reduction_rls) 1); |
515 | 104 |
by (etac (trans_rtrancl RS transD) 1); |
3014
f5554654d211
Moved diamond_trancl (which is independent of the rest) to the top
paulson
parents:
2954
diff
changeset
|
105 |
by (blast_tac (!claset addIs (contract_combD2::reduction_rls)) 1); |
782
200a16083201
added bind_thm for theorems defined by "standard ..."
clasohm
parents:
760
diff
changeset
|
106 |
qed "Ap_reduce1"; |
515 | 107 |
|
108 |
goal Comb.thy "!!p r. [| p ---> q; r: comb |] ==> r#p ---> r#q"; |
|
109 |
by (forward_tac [rtrancl_type RS subsetD RS SigmaD1] 1); |
|
110 |
by (dtac (field_contract_eq RS equalityD1 RS subsetD) 1); |
|
111 |
by (etac rtrancl_induct 1); |
|
2954 | 112 |
by (blast_tac (!claset addIs reduction_rls) 1); |
515 | 113 |
by (etac (trans_rtrancl RS transD) 1); |
3014
f5554654d211
Moved diamond_trancl (which is independent of the rest) to the top
paulson
parents:
2954
diff
changeset
|
114 |
by (blast_tac (!claset addIs (contract_combD2::reduction_rls)) 1); |
782
200a16083201
added bind_thm for theorems defined by "standard ..."
clasohm
parents:
760
diff
changeset
|
115 |
qed "Ap_reduce2"; |
515 | 116 |
|
117 |
(** Counterexample to the diamond property for -1-> **) |
|
118 |
||
119 |
goal Comb.thy "K#I#(I#I) -1-> I"; |
|
120 |
by (REPEAT (ares_tac [contract.K, comb_I, comb_Ap] 1)); |
|
782
200a16083201
added bind_thm for theorems defined by "standard ..."
clasohm
parents:
760
diff
changeset
|
121 |
qed "KIII_contract1"; |
515 | 122 |
|
123 |
goalw Comb.thy [I_def] "K#I#(I#I) -1-> K#I#((K#I)#(K#I))"; |
|
124 |
by (DEPTH_SOLVE (resolve_tac (comb.intrs @ contract.intrs) 1)); |
|
782
200a16083201
added bind_thm for theorems defined by "standard ..."
clasohm
parents:
760
diff
changeset
|
125 |
qed "KIII_contract2"; |
515 | 126 |
|
127 |
goal Comb.thy "K#I#((K#I)#(K#I)) -1-> I"; |
|
128 |
by (REPEAT (ares_tac (comb.intrs @ [contract.K, comb_I]) 1)); |
|
782
200a16083201
added bind_thm for theorems defined by "standard ..."
clasohm
parents:
760
diff
changeset
|
129 |
qed "KIII_contract3"; |
515 | 130 |
|
131 |
goalw Comb.thy [diamond_def] "~ diamond(contract)"; |
|
2954 | 132 |
by (blast_tac (!claset addIs [KIII_contract1,KIII_contract2,KIII_contract3] |
3014
f5554654d211
Moved diamond_trancl (which is independent of the rest) to the top
paulson
parents:
2954
diff
changeset
|
133 |
addSEs [I_contract_E]) 1); |
782
200a16083201
added bind_thm for theorems defined by "standard ..."
clasohm
parents:
760
diff
changeset
|
134 |
qed "not_diamond_contract"; |
515 | 135 |
|
0 | 136 |
|
137 |
||
515 | 138 |
(*** Results about Parallel Contraction ***) |
139 |
||
140 |
(*For type checking: replaces a=1=>b by a,b:comb *) |
|
141 |
val parcontract_combE2 = parcontract.dom_subset RS subsetD RS SigmaE2; |
|
142 |
val parcontract_combD1 = parcontract.dom_subset RS subsetD RS SigmaD1; |
|
143 |
val parcontract_combD2 = parcontract.dom_subset RS subsetD RS SigmaD2; |
|
144 |
||
145 |
goal Comb.thy "field(parcontract) = comb"; |
|
2954 | 146 |
by (blast_tac (!claset addIs [parcontract.K] |
2496 | 147 |
addSEs [parcontract_combE2]) 1); |
782
200a16083201
added bind_thm for theorems defined by "standard ..."
clasohm
parents:
760
diff
changeset
|
148 |
qed "field_parcontract_eq"; |
515 | 149 |
|
150 |
(*Derive a case for each combinator constructor*) |
|
151 |
val K_parcontractE = parcontract.mk_cases comb.con_defs "K =1=> r"; |
|
152 |
val S_parcontractE = parcontract.mk_cases comb.con_defs "S =1=> r"; |
|
153 |
val Ap_parcontractE = parcontract.mk_cases comb.con_defs "p#q =1=> r"; |
|
154 |
||
2469 | 155 |
AddIs parcontract.intrs; |
156 |
AddSEs [Ap_E, K_parcontractE, S_parcontractE, Ap_parcontractE]; |
|
515 | 157 |
|
158 |
(*** Basic properties of parallel contraction ***) |
|
159 |
||
160 |
goal Comb.thy "!!p r. K#p =1=> r ==> (EX p'. r = K#p' & p =1=> p')"; |
|
2954 | 161 |
by (Blast_tac 1); |
782
200a16083201
added bind_thm for theorems defined by "standard ..."
clasohm
parents:
760
diff
changeset
|
162 |
qed "K1_parcontractD"; |
515 | 163 |
|
164 |
goal Comb.thy "!!p r. S#p =1=> r ==> (EX p'. r = S#p' & p =1=> p')"; |
|
2954 | 165 |
by (Blast_tac 1); |
782
200a16083201
added bind_thm for theorems defined by "standard ..."
clasohm
parents:
760
diff
changeset
|
166 |
qed "S1_parcontractD"; |
515 | 167 |
|
168 |
goal Comb.thy |
|
169 |
"!!p q r. S#p#q =1=> r ==> (EX p' q'. r = S#p'#q' & p =1=> p' & q =1=> q')"; |
|
2954 | 170 |
by (blast_tac (!claset addSDs [S1_parcontractD]) 1); |
782
200a16083201
added bind_thm for theorems defined by "standard ..."
clasohm
parents:
760
diff
changeset
|
171 |
qed "S2_parcontractD"; |
515 | 172 |
|
173 |
(*Church-Rosser property for parallel contraction*) |
|
174 |
goalw Comb.thy [diamond_def] "diamond(parcontract)"; |
|
175 |
by (rtac (impI RS allI RS allI) 1); |
|
1732 | 176 |
by (etac parcontract.induct 1); |
515 | 177 |
by (ALLGOALS |
3014
f5554654d211
Moved diamond_trancl (which is independent of the rest) to the top
paulson
parents:
2954
diff
changeset
|
178 |
(blast_tac (!claset addSDs [K1_parcontractD, S2_parcontractD] |
f5554654d211
Moved diamond_trancl (which is independent of the rest) to the top
paulson
parents:
2954
diff
changeset
|
179 |
addIs [parcontract_combD2]))); |
782
200a16083201
added bind_thm for theorems defined by "standard ..."
clasohm
parents:
760
diff
changeset
|
180 |
qed "diamond_parcontract"; |
515 | 181 |
|
182 |
(*** Equivalence of p--->q and p===>q ***) |
|
183 |
||
184 |
goal Comb.thy "!!p q. p-1->q ==> p=1=>q"; |
|
1732 | 185 |
by (etac contract.induct 1); |
2954 | 186 |
by (ALLGOALS Blast_tac); |
782
200a16083201
added bind_thm for theorems defined by "standard ..."
clasohm
parents:
760
diff
changeset
|
187 |
qed "contract_imp_parcontract"; |
0 | 188 |
|
515 | 189 |
goal Comb.thy "!!p q. p--->q ==> p===>q"; |
190 |
by (forward_tac [rtrancl_type RS subsetD RS SigmaD1] 1); |
|
191 |
by (dtac (field_contract_eq RS equalityD1 RS subsetD) 1); |
|
192 |
by (etac rtrancl_induct 1); |
|
2954 | 193 |
by (blast_tac (!claset addIs [r_into_trancl]) 1); |
194 |
by (blast_tac (!claset addIs [contract_imp_parcontract, |
|
195 |
r_into_trancl, trans_trancl RS transD]) 1); |
|
782
200a16083201
added bind_thm for theorems defined by "standard ..."
clasohm
parents:
760
diff
changeset
|
196 |
qed "reduce_imp_parreduce"; |
515 | 197 |
|
0 | 198 |
|
515 | 199 |
goal Comb.thy "!!p q. p=1=>q ==> p--->q"; |
1732 | 200 |
by (etac parcontract.induct 1); |
2954 | 201 |
by (blast_tac (!claset addIs reduction_rls) 1); |
202 |
by (blast_tac (!claset addIs reduction_rls) 1); |
|
203 |
by (blast_tac (!claset addIs reduction_rls) 1); |
|
3014
f5554654d211
Moved diamond_trancl (which is independent of the rest) to the top
paulson
parents:
2954
diff
changeset
|
204 |
by (blast_tac |
f5554654d211
Moved diamond_trancl (which is independent of the rest) to the top
paulson
parents:
2954
diff
changeset
|
205 |
(!claset addIs [trans_rtrancl RS transD, |
f5554654d211
Moved diamond_trancl (which is independent of the rest) to the top
paulson
parents:
2954
diff
changeset
|
206 |
Ap_reduce1, Ap_reduce2, parcontract_combD1, |
f5554654d211
Moved diamond_trancl (which is independent of the rest) to the top
paulson
parents:
2954
diff
changeset
|
207 |
parcontract_combD2]) 1); |
760 | 208 |
qed "parcontract_imp_reduce"; |
515 | 209 |
|
210 |
goal Comb.thy "!!p q. p===>q ==> p--->q"; |
|
211 |
by (forward_tac [trancl_type RS subsetD RS SigmaD1] 1); |
|
212 |
by (dtac (field_parcontract_eq RS equalityD1 RS subsetD) 1); |
|
213 |
by (etac trancl_induct 1); |
|
214 |
by (etac parcontract_imp_reduce 1); |
|
215 |
by (etac (trans_rtrancl RS transD) 1); |
|
216 |
by (etac parcontract_imp_reduce 1); |
|
782
200a16083201
added bind_thm for theorems defined by "standard ..."
clasohm
parents:
760
diff
changeset
|
217 |
qed "parreduce_imp_reduce"; |
515 | 218 |
|
219 |
goal Comb.thy "p===>q <-> p--->q"; |
|
220 |
by (REPEAT (ares_tac [iffI, parreduce_imp_reduce, reduce_imp_parreduce] 1)); |
|
782
200a16083201
added bind_thm for theorems defined by "standard ..."
clasohm
parents:
760
diff
changeset
|
221 |
qed "parreduce_iff_reduce"; |
515 | 222 |
|
223 |
writeln"Reached end of file."; |