author | paulson |
Thu, 26 Sep 1996 15:14:23 +0200 | |
changeset 2033 | 639de962ded4 |
parent 1461 | 6bcb44e4d6e5 |
child 2445 | 51993fea433f |
permissions | -rw-r--r-- |
1461 | 1 |
(* Title: HOLCF/ex/Loop.ML |
244 | 2 |
ID: $Id$ |
1461 | 3 |
Author: Franz Regensburger |
4 |
Copyright 1993 Technische Universitaet Muenchen |
|
244 | 5 |
|
6 |
Lemmas for theory loop.thy |
|
7 |
*) |
|
8 |
||
9 |
open Loop; |
|
10 |
||
11 |
(* --------------------------------------------------------------------------- *) |
|
12 |
(* access to definitions *) |
|
13 |
(* --------------------------------------------------------------------------- *) |
|
14 |
||
1043 | 15 |
val step_def2 = prove_goalw Loop.thy [step_def] |
1168
74be52691d62
The curried version of HOLCF is now just called HOLCF. The old
regensbu
parents:
1043
diff
changeset
|
16 |
"step`b`g`x = If b`x then g`x else x fi" |
244 | 17 |
(fn prems => |
1461 | 18 |
[ |
19 |
(Simp_tac 1) |
|
20 |
]); |
|
244 | 21 |
|
1043 | 22 |
val while_def2 = prove_goalw Loop.thy [while_def] |
1168
74be52691d62
The curried version of HOLCF is now just called HOLCF. The old
regensbu
parents:
1043
diff
changeset
|
23 |
"while`b`g = fix`(LAM f x. If b`x then f`(g`x) else x fi)" |
244 | 24 |
(fn prems => |
1461 | 25 |
[ |
26 |
(Simp_tac 1) |
|
27 |
]); |
|
244 | 28 |
|
29 |
||
30 |
(* ------------------------------------------------------------------------- *) |
|
31 |
(* rekursive properties of while *) |
|
32 |
(* ------------------------------------------------------------------------- *) |
|
33 |
||
1043 | 34 |
val while_unfold = prove_goal Loop.thy |
1168
74be52691d62
The curried version of HOLCF is now just called HOLCF. The old
regensbu
parents:
1043
diff
changeset
|
35 |
"while`b`g`x = If b`x then while`b`g`(g`x) else x fi" |
244 | 36 |
(fn prems => |
1461 | 37 |
[ |
38 |
(fix_tac5 while_def2 1), |
|
39 |
(Simp_tac 1) |
|
40 |
]); |
|
244 | 41 |
|
1043 | 42 |
val while_unfold2 = prove_goal Loop.thy |
1461 | 43 |
"!x.while`b`g`x = while`b`g`(iterate k (step`b`g) x)" |
244 | 44 |
(fn prems => |
1461 | 45 |
[ |
46 |
(nat_ind_tac "k" 1), |
|
47 |
(simp_tac HOLCF_ss 1), |
|
48 |
(rtac allI 1), |
|
49 |
(rtac trans 1), |
|
2033 | 50 |
(stac while_unfold 1), |
1461 | 51 |
(rtac refl 2), |
2033 | 52 |
(stac iterate_Suc2 1), |
1461 | 53 |
(rtac trans 1), |
54 |
(etac spec 2), |
|
2033 | 55 |
(stac step_def2 1), |
1461 | 56 |
(res_inst_tac [("p","b`x")] trE 1), |
57 |
(asm_simp_tac HOLCF_ss 1), |
|
2033 | 58 |
(stac while_unfold 1), |
1461 | 59 |
(res_inst_tac [("s","UU"),("t","b`UU")]ssubst 1), |
60 |
(etac (flat_tr RS flat_codom RS disjE) 1), |
|
61 |
(atac 1), |
|
62 |
(etac spec 1), |
|
63 |
(simp_tac HOLCF_ss 1), |
|
64 |
(asm_simp_tac HOLCF_ss 1), |
|
65 |
(asm_simp_tac HOLCF_ss 1), |
|
2033 | 66 |
(stac while_unfold 1), |
1461 | 67 |
(asm_simp_tac HOLCF_ss 1) |
68 |
]); |
|
244 | 69 |
|
1043 | 70 |
val while_unfold3 = prove_goal Loop.thy |
1461 | 71 |
"while`b`g`x = while`b`g`(step`b`g`x)" |
244 | 72 |
(fn prems => |
1461 | 73 |
[ |
74 |
(res_inst_tac [("s", |
|
75 |
"while`b`g`(iterate (Suc 0) (step`b`g) x)")] trans 1), |
|
76 |
(rtac (while_unfold2 RS spec) 1), |
|
77 |
(Simp_tac 1) |
|
78 |
]); |
|
244 | 79 |
|
80 |
||
81 |
(* --------------------------------------------------------------------------- *) |
|
82 |
(* properties of while and iterations *) |
|
83 |
(* --------------------------------------------------------------------------- *) |
|
84 |
||
1043 | 85 |
val loop_lemma1 = prove_goal Loop.thy |
1168
74be52691d62
The curried version of HOLCF is now just called HOLCF. The old
regensbu
parents:
1043
diff
changeset
|
86 |
"[|? y.b`y=FF; iterate k (step`b`g) x = UU|]==>iterate(Suc k) (step`b`g) x=UU" |
244 | 87 |
(fn prems => |
1461 | 88 |
[ |
89 |
(cut_facts_tac prems 1), |
|
90 |
(Simp_tac 1), |
|
91 |
(rtac trans 1), |
|
92 |
(rtac step_def2 1), |
|
93 |
(asm_simp_tac HOLCF_ss 1), |
|
94 |
(etac exE 1), |
|
95 |
(etac (flat_tr RS flat_codom RS disjE) 1), |
|
96 |
(asm_simp_tac HOLCF_ss 1), |
|
97 |
(asm_simp_tac HOLCF_ss 1) |
|
98 |
]); |
|
244 | 99 |
|
1043 | 100 |
val loop_lemma2 = prove_goal Loop.thy |
1168
74be52691d62
The curried version of HOLCF is now just called HOLCF. The old
regensbu
parents:
1043
diff
changeset
|
101 |
"[|? y.b`y=FF;iterate (Suc k) (step`b`g) x ~=UU |]==>\ |
74be52691d62
The curried version of HOLCF is now just called HOLCF. The old
regensbu
parents:
1043
diff
changeset
|
102 |
\iterate k (step`b`g) x ~=UU" |
244 | 103 |
(fn prems => |
1461 | 104 |
[ |
105 |
(cut_facts_tac prems 1), |
|
106 |
(rtac contrapos 1), |
|
107 |
(etac loop_lemma1 2), |
|
108 |
(atac 1), |
|
109 |
(atac 1) |
|
110 |
]); |
|
244 | 111 |
|
1043 | 112 |
val loop_lemma3 = prove_goal Loop.thy |
1168
74be52691d62
The curried version of HOLCF is now just called HOLCF. The old
regensbu
parents:
1043
diff
changeset
|
113 |
"[|!x. INV x & b`x=TT & g`x~=UU --> INV (g`x);\ |
74be52691d62
The curried version of HOLCF is now just called HOLCF. The old
regensbu
parents:
1043
diff
changeset
|
114 |
\? y.b`y=FF; INV x|] ==>\ |
74be52691d62
The curried version of HOLCF is now just called HOLCF. The old
regensbu
parents:
1043
diff
changeset
|
115 |
\iterate k (step`b`g) x ~=UU --> INV (iterate k (step`b`g) x)" |
244 | 116 |
(fn prems => |
1461 | 117 |
[ |
118 |
(cut_facts_tac prems 1), |
|
119 |
(nat_ind_tac "k" 1), |
|
120 |
(Asm_simp_tac 1), |
|
121 |
(strip_tac 1), |
|
122 |
(simp_tac (!simpset addsimps [step_def2]) 1), |
|
123 |
(res_inst_tac [("p","b`(iterate k1 (step`b`g) x)")] trE 1), |
|
124 |
(etac notE 1), |
|
125 |
(asm_simp_tac (HOLCF_ss addsimps [step_def2] ) 1), |
|
126 |
(asm_simp_tac HOLCF_ss 1), |
|
127 |
(rtac mp 1), |
|
128 |
(etac spec 1), |
|
129 |
(asm_simp_tac (HOLCF_ss delsimps [iterate_Suc] |
|
1267 | 130 |
addsimps [loop_lemma2] ) 1), |
1461 | 131 |
(res_inst_tac [("s","iterate (Suc k1) (step`b`g) x"), |
132 |
("t","g`(iterate k1 (step`b`g) x)")] ssubst 1), |
|
133 |
(atac 2), |
|
134 |
(asm_simp_tac (HOLCF_ss addsimps [step_def2] ) 1), |
|
135 |
(asm_simp_tac (HOLCF_ss delsimps [iterate_Suc] |
|
1267 | 136 |
addsimps [loop_lemma2] ) 1) |
1461 | 137 |
]); |
244 | 138 |
|
139 |
||
1043 | 140 |
val loop_lemma4 = prove_goal Loop.thy |
1168
74be52691d62
The curried version of HOLCF is now just called HOLCF. The old
regensbu
parents:
1043
diff
changeset
|
141 |
"!x. b`(iterate k (step`b`g) x)=FF --> while`b`g`x= iterate k (step`b`g) x" |
244 | 142 |
(fn prems => |
1461 | 143 |
[ |
144 |
(nat_ind_tac "k" 1), |
|
145 |
(Simp_tac 1), |
|
146 |
(strip_tac 1), |
|
2033 | 147 |
(stac while_unfold 1), |
1461 | 148 |
(asm_simp_tac HOLCF_ss 1), |
149 |
(rtac allI 1), |
|
2033 | 150 |
(stac iterate_Suc2 1), |
1461 | 151 |
(strip_tac 1), |
152 |
(rtac trans 1), |
|
153 |
(rtac while_unfold3 1), |
|
154 |
(asm_simp_tac HOLCF_ss 1) |
|
155 |
]); |
|
244 | 156 |
|
1043 | 157 |
val loop_lemma5 = prove_goal Loop.thy |
1168
74be52691d62
The curried version of HOLCF is now just called HOLCF. The old
regensbu
parents:
1043
diff
changeset
|
158 |
"!k. b`(iterate k (step`b`g) x) ~= FF ==>\ |
74be52691d62
The curried version of HOLCF is now just called HOLCF. The old
regensbu
parents:
1043
diff
changeset
|
159 |
\ !m. while`b`g`(iterate m (step`b`g) x)=UU" |
244 | 160 |
(fn prems => |
1461 | 161 |
[ |
162 |
(cut_facts_tac prems 1), |
|
2033 | 163 |
(stac while_def2 1), |
1461 | 164 |
(rtac fix_ind 1), |
165 |
(rtac (allI RS adm_all) 1), |
|
166 |
(rtac adm_eq 1), |
|
167 |
(cont_tacR 1), |
|
168 |
(Simp_tac 1), |
|
169 |
(rtac allI 1), |
|
170 |
(Simp_tac 1), |
|
171 |
(res_inst_tac [("p","b`(iterate m (step`b`g) x)")] trE 1), |
|
172 |
(asm_simp_tac HOLCF_ss 1), |
|
173 |
(asm_simp_tac HOLCF_ss 1), |
|
174 |
(res_inst_tac [("s","xa`(iterate (Suc m) (step`b`g) x)")] trans 1), |
|
175 |
(etac spec 2), |
|
176 |
(rtac cfun_arg_cong 1), |
|
177 |
(rtac trans 1), |
|
178 |
(rtac (iterate_Suc RS sym) 2), |
|
179 |
(asm_simp_tac (HOLCF_ss addsimps [step_def2]) 1), |
|
180 |
(dtac spec 1), |
|
181 |
(contr_tac 1) |
|
182 |
]); |
|
244 | 183 |
|
184 |
||
1043 | 185 |
val loop_lemma6 = prove_goal Loop.thy |
1168
74be52691d62
The curried version of HOLCF is now just called HOLCF. The old
regensbu
parents:
1043
diff
changeset
|
186 |
"!k. b`(iterate k (step`b`g) x) ~= FF ==> while`b`g`x=UU" |
244 | 187 |
(fn prems => |
1461 | 188 |
[ |
189 |
(res_inst_tac [("t","x")] (iterate_0 RS subst) 1), |
|
190 |
(rtac (loop_lemma5 RS spec) 1), |
|
191 |
(resolve_tac prems 1) |
|
192 |
]); |
|
244 | 193 |
|
1043 | 194 |
val loop_lemma7 = prove_goal Loop.thy |
1168
74be52691d62
The curried version of HOLCF is now just called HOLCF. The old
regensbu
parents:
1043
diff
changeset
|
195 |
"while`b`g`x ~= UU ==> ? k. b`(iterate k (step`b`g) x) = FF" |
244 | 196 |
(fn prems => |
1461 | 197 |
[ |
198 |
(cut_facts_tac prems 1), |
|
199 |
(etac swap 1), |
|
200 |
(rtac loop_lemma6 1), |
|
201 |
(fast_tac HOL_cs 1) |
|
202 |
]); |
|
244 | 203 |
|
1043 | 204 |
val loop_lemma8 = prove_goal Loop.thy |
1168
74be52691d62
The curried version of HOLCF is now just called HOLCF. The old
regensbu
parents:
1043
diff
changeset
|
205 |
"while`b`g`x ~= UU ==> ? y. b`y=FF" |
244 | 206 |
(fn prems => |
1461 | 207 |
[ |
208 |
(cut_facts_tac prems 1), |
|
209 |
(dtac loop_lemma7 1), |
|
210 |
(fast_tac HOL_cs 1) |
|
211 |
]); |
|
244 | 212 |
|
213 |
||
1168
74be52691d62
The curried version of HOLCF is now just called HOLCF. The old
regensbu
parents:
1043
diff
changeset
|
214 |
(* ------------------------------------------------------------------------- *) |
74be52691d62
The curried version of HOLCF is now just called HOLCF. The old
regensbu
parents:
1043
diff
changeset
|
215 |
(* an invariant rule for loops *) |
74be52691d62
The curried version of HOLCF is now just called HOLCF. The old
regensbu
parents:
1043
diff
changeset
|
216 |
(* ------------------------------------------------------------------------- *) |
244 | 217 |
|
1043 | 218 |
val loop_inv2 = prove_goal Loop.thy |
1168
74be52691d62
The curried version of HOLCF is now just called HOLCF. The old
regensbu
parents:
1043
diff
changeset
|
219 |
"[| (!y. INV y & b`y=TT & g`y ~= UU --> INV (g`y));\ |
74be52691d62
The curried version of HOLCF is now just called HOLCF. The old
regensbu
parents:
1043
diff
changeset
|
220 |
\ (!y. INV y & b`y=FF --> Q y);\ |
74be52691d62
The curried version of HOLCF is now just called HOLCF. The old
regensbu
parents:
1043
diff
changeset
|
221 |
\ INV x; while`b`g`x~=UU |] ==> Q (while`b`g`x)" |
244 | 222 |
(fn prems => |
1461 | 223 |
[ |
224 |
(res_inst_tac [("P","%k. b`(iterate k (step`b`g) x)=FF")] exE 1), |
|
225 |
(rtac loop_lemma7 1), |
|
226 |
(resolve_tac prems 1), |
|
2033 | 227 |
(stac (loop_lemma4 RS spec RS mp) 1), |
1461 | 228 |
(atac 1), |
229 |
(rtac (nth_elem (1,prems) RS spec RS mp) 1), |
|
230 |
(rtac conjI 1), |
|
231 |
(atac 2), |
|
232 |
(rtac (loop_lemma3 RS mp) 1), |
|
233 |
(resolve_tac prems 1), |
|
234 |
(rtac loop_lemma8 1), |
|
235 |
(resolve_tac prems 1), |
|
236 |
(resolve_tac prems 1), |
|
237 |
(rtac classical3 1), |
|
238 |
(resolve_tac prems 1), |
|
239 |
(etac box_equals 1), |
|
240 |
(rtac (loop_lemma4 RS spec RS mp RS sym) 1), |
|
241 |
(atac 1), |
|
242 |
(rtac refl 1) |
|
243 |
]); |
|
244 | 244 |
|
1043 | 245 |
val loop_inv3 = prove_goal Loop.thy |
1168
74be52691d62
The curried version of HOLCF is now just called HOLCF. The old
regensbu
parents:
1043
diff
changeset
|
246 |
"[| !!y.[| INV y; b`y=TT; g`y~=UU|] ==> INV (g`y);\ |
74be52691d62
The curried version of HOLCF is now just called HOLCF. The old
regensbu
parents:
1043
diff
changeset
|
247 |
\ !!y.[| INV y; b`y=FF|]==> Q y;\ |
74be52691d62
The curried version of HOLCF is now just called HOLCF. The old
regensbu
parents:
1043
diff
changeset
|
248 |
\ INV x; while`b`g`x~=UU |] ==> Q (while`b`g`x)" |
244 | 249 |
(fn prems => |
1461 | 250 |
[ |
251 |
(rtac loop_inv2 1), |
|
252 |
(rtac allI 1), |
|
253 |
(rtac impI 1), |
|
254 |
(resolve_tac prems 1), |
|
255 |
(fast_tac HOL_cs 1), |
|
256 |
(fast_tac HOL_cs 1), |
|
257 |
(fast_tac HOL_cs 1), |
|
258 |
(rtac allI 1), |
|
259 |
(rtac impI 1), |
|
260 |
(resolve_tac prems 1), |
|
261 |
(fast_tac HOL_cs 1), |
|
262 |
(fast_tac HOL_cs 1), |
|
263 |
(resolve_tac prems 1), |
|
264 |
(resolve_tac prems 1) |
|
265 |
]); |
|
244 | 266 |
|
1043 | 267 |
val loop_inv = prove_goal Loop.thy |
244 | 268 |
"[| P(x);\ |
1168
74be52691d62
The curried version of HOLCF is now just called HOLCF. The old
regensbu
parents:
1043
diff
changeset
|
269 |
\ !!y.P y ==> INV y;\ |
74be52691d62
The curried version of HOLCF is now just called HOLCF. The old
regensbu
parents:
1043
diff
changeset
|
270 |
\ !!y.[| INV y; b`y=TT; g`y~=UU|] ==> INV (g`y);\ |
74be52691d62
The curried version of HOLCF is now just called HOLCF. The old
regensbu
parents:
1043
diff
changeset
|
271 |
\ !!y.[| INV y; b`y=FF|]==> Q y;\ |
74be52691d62
The curried version of HOLCF is now just called HOLCF. The old
regensbu
parents:
1043
diff
changeset
|
272 |
\ while`b`g`x ~= UU |] ==> Q (while`b`g`x)" |
244 | 273 |
(fn prems => |
1461 | 274 |
[ |
275 |
(rtac loop_inv3 1), |
|
276 |
(eresolve_tac prems 1), |
|
277 |
(atac 1), |
|
278 |
(atac 1), |
|
279 |
(resolve_tac prems 1), |
|
280 |
(atac 1), |
|
281 |
(atac 1), |
|
282 |
(resolve_tac prems 1), |
|
283 |
(resolve_tac prems 1), |
|
284 |
(resolve_tac prems 1) |
|
285 |
]); |