1 (* Title: HOLCF/ex/Loop.ML |
1 (* Title: HOLCF/ex/Loop.ML |
2 ID: $Id$ |
2 ID: $Id$ |
3 Author: Franz Regensburger |
3 Author: Franz Regensburger |
4 Copyright 1993 Technische Universitaet Muenchen |
4 Copyright 1993 Technische Universitaet Muenchen |
5 |
5 |
6 Lemmas for theory loop.thy |
6 Theory for a loop primitive like while |
7 *) |
7 *) |
8 |
8 |
9 open Loop; |
9 (* ------------------------------------------------------------------------- *) |
10 |
10 (* access to definitions *) |
11 (* --------------------------------------------------------------------------- *) |
11 (* ------------------------------------------------------------------------- *) |
12 (* access to definitions *) |
|
13 (* --------------------------------------------------------------------------- *) |
|
14 |
12 |
15 val step_def2 = prove_goalw Loop.thy [step_def] |
13 val step_def2 = prove_goalw Loop.thy [step_def] |
16 "step`b`g`x = If b`x then g`x else x fi" |
14 "step`b`g`x = If b`x then g`x else x fi" |
17 (fn prems => |
15 (fn prems => |
18 [ |
16 [ |
38 (fix_tac5 while_def2 1), |
36 (fix_tac5 while_def2 1), |
39 (Simp_tac 1) |
37 (Simp_tac 1) |
40 ]); |
38 ]); |
41 |
39 |
42 val while_unfold2 = prove_goal Loop.thy |
40 val while_unfold2 = prove_goal Loop.thy |
43 "!x. while`b`g`x = while`b`g`(iterate k (step`b`g) x)" |
41 "ALL x. while`b`g`x = while`b`g`(iterate k (step`b`g) x)" |
44 (fn prems => |
42 (fn prems => |
45 [ |
43 [ |
46 (nat_ind_tac "k" 1), |
44 (nat_ind_tac "k" 1), |
47 (simp_tac HOLCF_ss 1), |
45 (simp_tac HOLCF_ss 1), |
48 (rtac allI 1), |
46 (rtac allI 1), |
76 (rtac (while_unfold2 RS spec) 1), |
74 (rtac (while_unfold2 RS spec) 1), |
77 (Simp_tac 1) |
75 (Simp_tac 1) |
78 ]); |
76 ]); |
79 |
77 |
80 |
78 |
81 (* --------------------------------------------------------------------------- *) |
79 (* ------------------------------------------------------------------------- *) |
82 (* properties of while and iterations *) |
80 (* properties of while and iterations *) |
83 (* --------------------------------------------------------------------------- *) |
81 (* ------------------------------------------------------------------------- *) |
84 |
82 |
85 val loop_lemma1 = prove_goal Loop.thy |
83 val loop_lemma1 = prove_goal Loop.thy |
86 "[|? y. b`y=FF; iterate k (step`b`g) x = UU|]==>iterate(Suc k) (step`b`g) x=UU" |
84 "[| EX y. b`y=FF; iterate k (step`b`g) x = UU |] \ |
|
85 \ ==>iterate(Suc k) (step`b`g) x=UU" |
87 (fn prems => |
86 (fn prems => |
88 [ |
87 [ |
89 (cut_facts_tac prems 1), |
88 (cut_facts_tac prems 1), |
90 (Simp_tac 1), |
89 (Simp_tac 1), |
91 (rtac trans 1), |
90 (rtac trans 1), |
96 (asm_simp_tac HOLCF_ss 1), |
95 (asm_simp_tac HOLCF_ss 1), |
97 (asm_simp_tac HOLCF_ss 1) |
96 (asm_simp_tac HOLCF_ss 1) |
98 ]); |
97 ]); |
99 |
98 |
100 val loop_lemma2 = prove_goal Loop.thy |
99 val loop_lemma2 = prove_goal Loop.thy |
101 "[|? y. b`y=FF;iterate (Suc k) (step`b`g) x ~=UU |]==>\ |
100 "[|EX y. b`y=FF;iterate (Suc k) (step`b`g) x ~=UU |]==>\ |
102 \iterate k (step`b`g) x ~=UU" |
101 \iterate k (step`b`g) x ~=UU" |
103 (fn prems => |
102 (fn prems => |
104 [ |
103 [ |
105 (cut_facts_tac prems 1), |
104 (cut_facts_tac prems 1), |
106 (rtac contrapos 1), |
105 (rtac contrapos 1), |
108 (atac 1), |
107 (atac 1), |
109 (atac 1) |
108 (atac 1) |
110 ]); |
109 ]); |
111 |
110 |
112 val loop_lemma3 = prove_goal Loop.thy |
111 val loop_lemma3 = prove_goal Loop.thy |
113 "[|!x. INV x & b`x=TT & g`x~=UU --> INV (g`x);\ |
112 "[| ALL x. INV x & b`x=TT & g`x~=UU --> INV (g`x);\ |
114 \? y. b`y=FF; INV x|] ==>\ |
113 \ EX y. b`y=FF; INV x |] \ |
115 \iterate k (step`b`g) x ~=UU --> INV (iterate k (step`b`g) x)" |
114 \==> iterate k (step`b`g) x ~=UU --> INV (iterate k (step`b`g) x)" |
116 (fn prems => |
115 (fn prems => |
117 [ |
116 [ |
118 (cut_facts_tac prems 1), |
117 (cut_facts_tac prems 1), |
119 (nat_ind_tac "k" 1), |
118 (nat_ind_tac "k" 1), |
120 (Asm_simp_tac 1), |
119 (Asm_simp_tac 1), |
153 (rtac while_unfold3 1), |
152 (rtac while_unfold3 1), |
154 (asm_simp_tac HOLCF_ss 1) |
153 (asm_simp_tac HOLCF_ss 1) |
155 ]); |
154 ]); |
156 |
155 |
157 val loop_lemma5 = prove_goal Loop.thy |
156 val loop_lemma5 = prove_goal Loop.thy |
158 "!k. b`(iterate k (step`b`g) x) ~= FF ==>\ |
157 "ALL k. b`(iterate k (step`b`g) x) ~= FF ==>\ |
159 \ !m. while`b`g`(iterate m (step`b`g) x)=UU" |
158 \ ALL m. while`b`g`(iterate m (step`b`g) x)=UU" |
160 (fn prems => |
159 (fn prems => |
161 [ |
160 [ |
162 (cut_facts_tac prems 1), |
161 (cut_facts_tac prems 1), |
163 (stac while_def2 1), |
162 (stac while_def2 1), |
164 (rtac fix_ind 1), |
163 (rtac fix_ind 1), |
181 (contr_tac 1) |
180 (contr_tac 1) |
182 ]); |
181 ]); |
183 |
182 |
184 |
183 |
185 val loop_lemma6 = prove_goal Loop.thy |
184 val loop_lemma6 = prove_goal Loop.thy |
186 "!k. b`(iterate k (step`b`g) x) ~= FF ==> while`b`g`x=UU" |
185 "ALL k. b`(iterate k (step`b`g) x) ~= FF ==> while`b`g`x=UU" |
187 (fn prems => |
186 (fn prems => |
188 [ |
187 [ |
189 (res_inst_tac [("t","x")] (iterate_0 RS subst) 1), |
188 (res_inst_tac [("t","x")] (iterate_0 RS subst) 1), |
190 (rtac (loop_lemma5 RS spec) 1), |
189 (rtac (loop_lemma5 RS spec) 1), |
191 (resolve_tac prems 1) |
190 (resolve_tac prems 1) |
192 ]); |
191 ]); |
193 |
192 |
194 val loop_lemma7 = prove_goal Loop.thy |
193 val loop_lemma7 = prove_goal Loop.thy |
195 "while`b`g`x ~= UU ==> ? k. b`(iterate k (step`b`g) x) = FF" |
194 "while`b`g`x ~= UU ==> EX k. b`(iterate k (step`b`g) x) = FF" |
196 (fn prems => |
195 (fn prems => |
197 [ |
196 [ |
198 (cut_facts_tac prems 1), |
197 (cut_facts_tac prems 1), |
199 (etac swap 1), |
198 (etac swap 1), |
200 (rtac loop_lemma6 1), |
199 (rtac loop_lemma6 1), |
201 (fast_tac HOL_cs 1) |
200 (fast_tac HOL_cs 1) |
202 ]); |
201 ]); |
203 |
202 |
204 val loop_lemma8 = prove_goal Loop.thy |
203 val loop_lemma8 = prove_goal Loop.thy |
205 "while`b`g`x ~= UU ==> ? y. b`y=FF" |
204 "while`b`g`x ~= UU ==> EX y. b`y=FF" |
206 (fn prems => |
205 (fn prems => |
207 [ |
206 [ |
208 (cut_facts_tac prems 1), |
207 (cut_facts_tac prems 1), |
209 (dtac loop_lemma7 1), |
208 (dtac loop_lemma7 1), |
210 (fast_tac HOL_cs 1) |
209 (fast_tac HOL_cs 1) |
214 (* ------------------------------------------------------------------------- *) |
213 (* ------------------------------------------------------------------------- *) |
215 (* an invariant rule for loops *) |
214 (* an invariant rule for loops *) |
216 (* ------------------------------------------------------------------------- *) |
215 (* ------------------------------------------------------------------------- *) |
217 |
216 |
218 val loop_inv2 = prove_goal Loop.thy |
217 val loop_inv2 = prove_goal Loop.thy |
219 "[| (!y. INV y & b`y=TT & g`y ~= UU --> INV (g`y));\ |
218 "[| (ALL y. INV y & b`y=TT & g`y ~= UU --> INV (g`y));\ |
220 \ (!y. INV y & b`y=FF --> Q y);\ |
219 \ (ALL y. INV y & b`y=FF --> Q y);\ |
221 \ INV x; while`b`g`x~=UU |] ==> Q (while`b`g`x)" |
220 \ INV x; while`b`g`x~=UU |] ==> Q (while`b`g`x)" |
222 (fn prems => |
221 (fn prems => |
223 [ |
222 [ |
224 (res_inst_tac [("P","%k. b`(iterate k (step`b`g) x)=FF")] exE 1), |
223 (res_inst_tac [("P","%k. b`(iterate k (step`b`g) x)=FF")] exE 1), |
225 (rtac loop_lemma7 1), |
224 (rtac loop_lemma7 1), |
232 (rtac (loop_lemma3 RS mp) 1), |
231 (rtac (loop_lemma3 RS mp) 1), |
233 (resolve_tac prems 1), |
232 (resolve_tac prems 1), |
234 (rtac loop_lemma8 1), |
233 (rtac loop_lemma8 1), |
235 (resolve_tac prems 1), |
234 (resolve_tac prems 1), |
236 (resolve_tac prems 1), |
235 (resolve_tac prems 1), |
237 (rtac classical2 1), |
236 (rtac notI2 1), |
238 (resolve_tac prems 1), |
237 (resolve_tac prems 1), |
239 (etac box_equals 1), |
238 (etac box_equals 1), |
240 (rtac (loop_lemma4 RS spec RS mp RS sym) 1), |
239 (rtac (loop_lemma4 RS spec RS mp RS sym) 1), |
241 (atac 1), |
240 (atac 1), |
242 (rtac refl 1) |
241 (rtac refl 1) |