51 intros |
51 intros |
52 Skip: "(SKIP,s) -[eval]-> s" |
52 Skip: "(SKIP,s) -[eval]-> s" |
53 |
53 |
54 Assign: "(e,s) -|[eval]-> (v,s') ==> (x := e, s) -[eval]-> s'(x:=v)" |
54 Assign: "(e,s) -|[eval]-> (v,s') ==> (x := e, s) -[eval]-> s'(x:=v)" |
55 |
55 |
56 Semi: "[| (c0,s) -[eval]-> s2; (c1,s2) -[eval]-> s1 |] |
56 Semi: "[| (c0,s) -[eval]-> s2; (c1,s2) -[eval]-> s1 |] |
57 ==> (c0 ;; c1, s) -[eval]-> s1" |
57 ==> (c0 ;; c1, s) -[eval]-> s1" |
58 |
58 |
59 IfTrue: "[| (e,s) -|[eval]-> (0,s'); (c0,s') -[eval]-> s1 |] |
59 IfTrue: "[| (e,s) -|[eval]-> (0,s'); (c0,s') -[eval]-> s1 |] |
60 ==> (IF e THEN c0 ELSE c1, s) -[eval]-> s1" |
60 ==> (IF e THEN c0 ELSE c1, s) -[eval]-> s1" |
61 |
61 |
62 IfFalse: "[| (e,s) -|[eval]-> (Suc 0, s'); (c1,s') -[eval]-> s1 |] |
62 IfFalse: "[| (e,s) -|[eval]-> (Suc 0, s'); (c1,s') -[eval]-> s1 |] |
63 ==> (IF e THEN c0 ELSE c1, s) -[eval]-> s1" |
63 ==> (IF e THEN c0 ELSE c1, s) -[eval]-> s1" |
64 |
64 |
65 WhileFalse: "(e,s) -|[eval]-> (Suc 0, s1) |
65 WhileFalse: "(e,s) -|[eval]-> (Suc 0, s1) |
66 ==> (WHILE e DO c, s) -[eval]-> s1" |
66 ==> (WHILE e DO c, s) -[eval]-> s1" |
67 |
67 |
68 WhileTrue: "[| (e,s) -|[eval]-> (0,s1); |
68 WhileTrue: "[| (e,s) -|[eval]-> (0,s1); |
69 (c,s1) -[eval]-> s2; (WHILE e DO c, s2) -[eval]-> s3 |] |
69 (c,s1) -[eval]-> s2; (WHILE e DO c, s2) -[eval]-> s3 |] |
70 ==> (WHILE e DO c, s) -[eval]-> s3" |
70 ==> (WHILE e DO c, s) -[eval]-> s3" |
71 |
71 |
72 declare exec.intros [intro] |
72 declare exec.intros [intro] |
73 |
73 |
74 |
74 |
75 inductive_cases |
75 inductive_cases |
76 [elim!]: "(SKIP,s) -[eval]-> t" |
76 [elim!]: "(SKIP,s) -[eval]-> t" |
77 and [elim!]: "(x:=a,s) -[eval]-> t" |
77 and [elim!]: "(x:=a,s) -[eval]-> t" |
78 and [elim!]: "(c1;;c2, s) -[eval]-> t" |
78 and [elim!]: "(c1;;c2, s) -[eval]-> t" |
79 and [elim!]: "(IF e THEN c1 ELSE c2, s) -[eval]-> t" |
79 and [elim!]: "(IF e THEN c1 ELSE c2, s) -[eval]-> t" |
80 and exec_WHILE_case: "(WHILE b DO c,s) -[eval]-> t" |
80 and exec_WHILE_case: "(WHILE b DO c,s) -[eval]-> t" |
81 |
81 |
82 |
82 |
83 text{*Justifies using "exec" in the inductive definition of "eval"*} |
83 text{*Justifies using "exec" in the inductive definition of "eval"*} |
84 lemma exec_mono: "A<=B ==> exec(A) <= exec(B)" |
84 lemma exec_mono: "A<=B ==> exec(A) <= exec(B)" |
85 apply (unfold exec.defs ) |
85 apply (unfold exec.defs ) |
109 "-|->" :: "[exp*state,nat*state] => bool" (infixl 50) |
109 "-|->" :: "[exp*state,nat*state] => bool" (infixl 50) |
110 |
110 |
111 translations |
111 translations |
112 "esig -|-> (n,s)" <= "(esig,n,s) \<in> eval" |
112 "esig -|-> (n,s)" <= "(esig,n,s) \<in> eval" |
113 "esig -|-> ns" == "(esig,ns ) \<in> eval" |
113 "esig -|-> ns" == "(esig,ns ) \<in> eval" |
114 |
114 |
115 inductive eval |
115 inductive eval |
116 intros |
116 intros |
117 N [intro!]: "(N(n),s) -|-> (n,s)" |
117 N [intro!]: "(N(n),s) -|-> (n,s)" |
118 |
118 |
119 X [intro!]: "(X(x),s) -|-> (s(x),s)" |
119 X [intro!]: "(X(x),s) -|-> (s(x),s)" |
120 |
120 |
121 Op [intro]: "[| (e0,s) -|-> (n0,s0); (e1,s0) -|-> (n1,s1) |] |
121 Op [intro]: "[| (e0,s) -|-> (n0,s0); (e1,s0) -|-> (n1,s1) |] |
122 ==> (Op f e0 e1, s) -|-> (f n0 n1, s1)" |
122 ==> (Op f e0 e1, s) -|-> (f n0 n1, s1)" |
123 |
123 |
124 valOf [intro]: "[| (c,s) -[eval]-> s0; (e,s0) -|-> (n,s1) |] |
124 valOf [intro]: "[| (c,s) -[eval]-> s0; (e,s0) -|-> (n,s1) |] |
125 ==> (VALOF c RESULTIS e, s) -|-> (n, s1)" |
125 ==> (VALOF c RESULTIS e, s) -|-> (n, s1)" |
126 |
126 |
127 monos exec_mono |
127 monos exec_mono |
128 |
128 |
129 |
129 |
130 inductive_cases |
130 inductive_cases |
131 [elim!]: "(N(n),sigma) -|-> (n',s')" |
131 [elim!]: "(N(n),sigma) -|-> (n',s')" |
132 and [elim!]: "(X(x),sigma) -|-> (n,s')" |
132 and [elim!]: "(X(x),sigma) -|-> (n,s')" |
133 and [elim!]: "(Op f a1 a2,sigma) -|-> (n,s')" |
133 and [elim!]: "(Op f a1 a2,sigma) -|-> (n,s')" |
134 and [elim!]: "(VALOF c RESULTIS e, s) -|-> (n, s1)" |
134 and [elim!]: "(VALOF c RESULTIS e, s) -|-> (n, s1)" |
135 |
135 |
136 |
136 |
137 lemma var_assign_eval [intro!]: "(X x, s(x:=n)) -|-> (n, s(x:=n))" |
137 lemma var_assign_eval [intro!]: "(X x, s(x:=n)) -|-> (n, s(x:=n))" |
138 by (rule fun_upd_same [THEN subst], fast) |
138 by (rule fun_upd_same [THEN subst], fast) |
139 |
139 |
144 lemma split_lemma: |
144 lemma split_lemma: |
145 "{((e,s),(n,s')). P e s n s'} = Collect (split (%v. split (split P v)))" |
145 "{((e,s),(n,s')). P e s n s'} = Collect (split (%v. split (split P v)))" |
146 by auto |
146 by auto |
147 |
147 |
148 text{*New induction rule. Note the form of the VALOF induction hypothesis*} |
148 text{*New induction rule. Note the form of the VALOF induction hypothesis*} |
149 lemma eval_induct: |
149 lemma eval_induct |
150 "[| (e,s) -|-> (n,s'); |
150 [case_names N X Op valOf, consumes 1, induct set: eval]: |
151 !!n s. P (N n) s n s; |
151 "[| (e,s) -|-> (n,s'); |
152 !!s x. P (X x) s (s x) s; |
152 !!n s. P (N n) s n s; |
153 !!e0 e1 f n0 n1 s s0 s1. |
153 !!s x. P (X x) s (s x) s; |
154 [| (e0,s) -|-> (n0,s0); P e0 s n0 s0; |
154 !!e0 e1 f n0 n1 s s0 s1. |
155 (e1,s0) -|-> (n1,s1); P e1 s0 n1 s1 |
155 [| (e0,s) -|-> (n0,s0); P e0 s n0 s0; |
156 |] ==> P (Op f e0 e1) s (f n0 n1) s1; |
156 (e1,s0) -|-> (n1,s1); P e1 s0 n1 s1 |
157 !!c e n s s0 s1. |
157 |] ==> P (Op f e0 e1) s (f n0 n1) s1; |
158 [| (c,s) -[eval Int {((e,s),(n,s')). P e s n s'}]-> s0; |
158 !!c e n s s0 s1. |
159 (c,s) -[eval]-> s0; |
159 [| (c,s) -[eval Int {((e,s),(n,s')). P e s n s'}]-> s0; |
160 (e,s0) -|-> (n,s1); P e s0 n s1 |] |
160 (c,s) -[eval]-> s0; |
161 ==> P (VALOF c RESULTIS e) s n s1 |
161 (e,s0) -|-> (n,s1); P e s0 n s1 |] |
|
162 ==> P (VALOF c RESULTIS e) s n s1 |
162 |] ==> P e s n s'" |
163 |] ==> P e s n s'" |
163 apply (erule eval.induct, blast) |
164 apply (induct set: eval) |
164 apply blast |
165 apply blast |
165 apply blast |
166 apply blast |
|
167 apply blast |
166 apply (frule Int_lower1 [THEN exec_mono, THEN subsetD]) |
168 apply (frule Int_lower1 [THEN exec_mono, THEN subsetD]) |
167 apply (auto simp add: split_lemma) |
169 apply (auto simp add: split_lemma) |
168 done |
170 done |
169 |
171 |
170 |
172 |
171 text{*Lemma for Function_eval. The major premise is that (c,s) executes to s1 |
173 text{*Lemma for Function_eval. The major premise is that (c,s) executes to s1 |
172 using eval restricted to its functional part. Note that the execution |
174 using eval restricted to its functional part. Note that the execution |
173 (c,s) -[eval]-> s2 can use unrestricted eval! The reason is that |
175 (c,s) -[eval]-> s2 can use unrestricted eval! The reason is that |
174 the execution (c,s) -[eval Int {...}]-> s1 assures us that execution is |
176 the execution (c,s) -[eval Int {...}]-> s1 assures us that execution is |
175 functional on the argument (c,s). |
177 functional on the argument (c,s). |
176 *} |
178 *} |
177 lemma com_Unique: |
179 lemma com_Unique: |
178 "(c,s) -[eval Int {((e,s),(n,t)). \<forall>nt'. (e,s) -|-> nt' --> (n,t)=nt'}]-> s1 |
180 "(c,s) -[eval Int {((e,s),(n,t)). \<forall>nt'. (e,s) -|-> nt' --> (n,t)=nt'}]-> s1 |
179 ==> \<forall>s2. (c,s) -[eval]-> s2 --> s2=s1" |
181 ==> \<forall>s2. (c,s) -[eval]-> s2 --> s2=s1" |
180 apply (erule exec.induct, simp_all) |
182 apply (induct set: exec) |
|
183 apply simp_all |
181 apply blast |
184 apply blast |
182 apply force |
185 apply force |
183 apply blast |
186 apply blast |
184 apply blast |
187 apply blast |
185 apply blast |
188 apply blast |
186 apply (blast elim: exec_WHILE_case) |
189 apply (blast elim: exec_WHILE_case) |
187 apply (erule_tac V = "(?c,s2) -[?ev]-> s3" in thin_rl) |
190 apply (erule_tac V = "(?c,s2) -[?ev]-> s3" in thin_rl) |
188 apply clarify |
191 apply clarify |
189 apply (erule exec_WHILE_case, blast+) |
192 apply (erule exec_WHILE_case, blast+) |
190 done |
193 done |
191 |
194 |
192 |
195 |
193 text{*Expression evaluation is functional, or deterministic*} |
196 text{*Expression evaluation is functional, or deterministic*} |
194 theorem single_valued_eval: "single_valued eval" |
197 theorem single_valued_eval: "single_valued eval" |
195 apply (unfold single_valued_def) |
198 apply (unfold single_valued_def) |
196 apply (intro allI, rule impI) |
199 apply (intro allI, rule impI) |
197 apply (simp (no_asm_simp) only: split_tupled_all) |
200 apply (simp (no_asm_simp) only: split_tupled_all) |
198 apply (erule eval_induct) |
201 apply (erule eval_induct) |
199 apply (drule_tac [4] com_Unique) |
202 apply (drule_tac [4] com_Unique) |
200 apply (simp_all (no_asm_use)) |
203 apply (simp_all (no_asm_use)) |
201 apply blast+ |
204 apply blast+ |
202 done |
205 done |
203 |
206 |
204 |
207 lemma eval_N_E [dest!]: "(N n, s) -|-> (v, s') ==> (v = n & s' = s)" |
205 lemma eval_N_E_lemma: "(e,s) -|-> (v,s') ==> (e = N n) --> (v=n & s'=s)" |
208 by (induct e == "N n" s v s' set: eval) simp_all |
206 by (erule eval_induct, simp_all) |
|
207 |
|
208 lemmas eval_N_E [dest!] = eval_N_E_lemma [THEN mp, OF _ refl] |
|
209 |
|
210 |
209 |
211 text{*This theorem says that "WHILE TRUE DO c" cannot terminate*} |
210 text{*This theorem says that "WHILE TRUE DO c" cannot terminate*} |
212 lemma while_true_E [rule_format]: |
211 lemma while_true_E: |
213 "(c', s) -[eval]-> t ==> (c' = WHILE (N 0) DO c) --> False" |
212 "(c', s) -[eval]-> t ==> c' = WHILE (N 0) DO c ==> False" |
214 by (erule exec.induct, auto) |
213 by (induct set: exec) auto |
215 |
214 |
216 |
215 |
217 subsection{* Equivalence of IF e THEN c;;(WHILE e DO c) ELSE SKIP and |
216 subsection{* Equivalence of IF e THEN c;;(WHILE e DO c) ELSE SKIP and |
218 WHILE e DO c *} |
217 WHILE e DO c *} |
219 |
218 |
220 lemma while_if1 [rule_format]: |
219 lemma while_if1: |
221 "(c',s) -[eval]-> t |
220 "(c',s) -[eval]-> t |
222 ==> (c' = WHILE e DO c) --> |
221 ==> c' = WHILE e DO c ==> |
223 (IF e THEN c;;c' ELSE SKIP, s) -[eval]-> t" |
222 (IF e THEN c;;c' ELSE SKIP, s) -[eval]-> t" |
224 by (erule exec.induct, auto) |
223 by (induct set: exec) auto |
225 |
224 |
226 lemma while_if2 [rule_format]: |
225 lemma while_if2: |
227 "(c',s) -[eval]-> t |
226 "(c',s) -[eval]-> t |
228 ==> (c' = IF e THEN c;;(WHILE e DO c) ELSE SKIP) --> |
227 ==> c' = IF e THEN c;;(WHILE e DO c) ELSE SKIP ==> |
229 (WHILE e DO c, s) -[eval]-> t" |
228 (WHILE e DO c, s) -[eval]-> t" |
230 by (erule exec.induct, auto) |
229 by (induct set: exec) auto |
231 |
230 |
232 |
231 |
233 theorem while_if: |
232 theorem while_if: |
234 "((IF e THEN c;;(WHILE e DO c) ELSE SKIP, s) -[eval]-> t) = |
233 "((IF e THEN c;;(WHILE e DO c) ELSE SKIP, s) -[eval]-> t) = |
235 ((WHILE e DO c, s) -[eval]-> t)" |
234 ((WHILE e DO c, s) -[eval]-> t)" |
236 by (blast intro: while_if1 while_if2) |
235 by (blast intro: while_if1 while_if2) |
237 |
236 |
238 |
237 |
239 |
238 |
240 subsection{* Equivalence of (IF e THEN c1 ELSE c2);;c |
239 subsection{* Equivalence of (IF e THEN c1 ELSE c2);;c |
241 and IF e THEN (c1;;c) ELSE (c2;;c) *} |
240 and IF e THEN (c1;;c) ELSE (c2;;c) *} |
242 |
241 |
243 lemma if_semi1 [rule_format]: |
242 lemma if_semi1: |
244 "(c',s) -[eval]-> t |
243 "(c',s) -[eval]-> t |
245 ==> (c' = (IF e THEN c1 ELSE c2);;c) --> |
244 ==> c' = (IF e THEN c1 ELSE c2);;c ==> |
246 (IF e THEN (c1;;c) ELSE (c2;;c), s) -[eval]-> t" |
245 (IF e THEN (c1;;c) ELSE (c2;;c), s) -[eval]-> t" |
247 by (erule exec.induct, auto) |
246 by (induct set: exec) auto |
248 |
247 |
249 lemma if_semi2 [rule_format]: |
248 lemma if_semi2: |
250 "(c',s) -[eval]-> t |
249 "(c',s) -[eval]-> t |
251 ==> (c' = IF e THEN (c1;;c) ELSE (c2;;c)) --> |
250 ==> c' = IF e THEN (c1;;c) ELSE (c2;;c) ==> |
252 ((IF e THEN c1 ELSE c2);;c, s) -[eval]-> t" |
251 ((IF e THEN c1 ELSE c2);;c, s) -[eval]-> t" |
253 by (erule exec.induct, auto) |
252 by (induct set: exec) auto |
254 |
253 |
255 theorem if_semi: "(((IF e THEN c1 ELSE c2);;c, s) -[eval]-> t) = |
254 theorem if_semi: "(((IF e THEN c1 ELSE c2);;c, s) -[eval]-> t) = |
256 ((IF e THEN (c1;;c) ELSE (c2;;c), s) -[eval]-> t)" |
255 ((IF e THEN (c1;;c) ELSE (c2;;c), s) -[eval]-> t)" |
257 by (blast intro: if_semi1 if_semi2) |
256 by (blast intro: if_semi1 if_semi2) |
258 |
257 |
259 |
258 |
260 |
259 |
261 subsection{* Equivalence of VALOF c1 RESULTIS (VALOF c2 RESULTIS e) |
260 subsection{* Equivalence of VALOF c1 RESULTIS (VALOF c2 RESULTIS e) |
262 and VALOF c1;;c2 RESULTIS e |
261 and VALOF c1;;c2 RESULTIS e |
263 *} |
262 *} |
264 |
263 |
265 lemma valof_valof1 [rule_format]: |
264 lemma valof_valof1: |
266 "(e',s) -|-> (v,s') |
265 "(e',s) -|-> (v,s') |
267 ==> (e' = VALOF c1 RESULTIS (VALOF c2 RESULTIS e)) --> |
266 ==> e' = VALOF c1 RESULTIS (VALOF c2 RESULTIS e) ==> |
268 (VALOF c1;;c2 RESULTIS e, s) -|-> (v,s')" |
267 (VALOF c1;;c2 RESULTIS e, s) -|-> (v,s')" |
269 by (erule eval_induct, auto) |
268 by (induct set: eval) auto |
270 |
269 |
271 |
270 lemma valof_valof2: |
272 lemma valof_valof2 [rule_format]: |
|
273 "(e',s) -|-> (v,s') |
271 "(e',s) -|-> (v,s') |
274 ==> (e' = VALOF c1;;c2 RESULTIS e) --> |
272 ==> e' = VALOF c1;;c2 RESULTIS e ==> |
275 (VALOF c1 RESULTIS (VALOF c2 RESULTIS e), s) -|-> (v,s')" |
273 (VALOF c1 RESULTIS (VALOF c2 RESULTIS e), s) -|-> (v,s')" |
276 by (erule eval_induct, auto) |
274 by (induct set: eval) auto |
277 |
275 |
278 theorem valof_valof: |
276 theorem valof_valof: |
279 "((VALOF c1 RESULTIS (VALOF c2 RESULTIS e), s) -|-> (v,s')) = |
277 "((VALOF c1 RESULTIS (VALOF c2 RESULTIS e), s) -|-> (v,s')) = |
280 ((VALOF c1;;c2 RESULTIS e, s) -|-> (v,s'))" |
278 ((VALOF c1;;c2 RESULTIS e, s) -|-> (v,s'))" |
281 by (blast intro: valof_valof1 valof_valof2) |
279 by (blast intro: valof_valof1 valof_valof2) |
282 |
280 |
283 |
281 |
284 subsection{* Equivalence of VALOF SKIP RESULTIS e and e *} |
282 subsection{* Equivalence of VALOF SKIP RESULTIS e and e *} |
285 |
283 |
286 lemma valof_skip1 [rule_format]: |
284 lemma valof_skip1: |
287 "(e',s) -|-> (v,s') |
285 "(e',s) -|-> (v,s') |
288 ==> (e' = VALOF SKIP RESULTIS e) --> |
286 ==> e' = VALOF SKIP RESULTIS e ==> |
289 (e, s) -|-> (v,s')" |
287 (e, s) -|-> (v,s')" |
290 by (erule eval_induct, auto) |
288 by (induct set: eval) auto |
291 |
289 |
292 lemma valof_skip2: |
290 lemma valof_skip2: |
293 "(e,s) -|-> (v,s') ==> (VALOF SKIP RESULTIS e, s) -|-> (v,s')" |
291 "(e,s) -|-> (v,s') ==> (VALOF SKIP RESULTIS e, s) -|-> (v,s')" |
294 by blast |
292 by blast |
295 |
293 |
296 theorem valof_skip: |
294 theorem valof_skip: |
297 "((VALOF SKIP RESULTIS e, s) -|-> (v,s')) = ((e, s) -|-> (v,s'))" |
295 "((VALOF SKIP RESULTIS e, s) -|-> (v,s')) = ((e, s) -|-> (v,s'))" |
298 by (blast intro: valof_skip1 valof_skip2) |
296 by (blast intro: valof_skip1 valof_skip2) |
299 |
297 |
300 |
298 |
301 subsection{* Equivalence of VALOF x:=e RESULTIS x and e *} |
299 subsection{* Equivalence of VALOF x:=e RESULTIS x and e *} |
302 |
300 |
303 lemma valof_assign1 [rule_format]: |
301 lemma valof_assign1: |
304 "(e',s) -|-> (v,s'') |
302 "(e',s) -|-> (v,s'') |
305 ==> (e' = VALOF x:=e RESULTIS X x) --> |
303 ==> e' = VALOF x:=e RESULTIS X x ==> |
306 (\<exists>s'. (e, s) -|-> (v,s') & (s'' = s'(x:=v)))" |
304 (\<exists>s'. (e, s) -|-> (v,s') & (s'' = s'(x:=v)))" |
307 apply (erule eval_induct) |
305 by (induct set: eval) (simp_all del: fun_upd_apply, clarify, auto) |
308 apply (simp_all del: fun_upd_apply, clarify, auto) |
|
309 done |
|
310 |
306 |
311 lemma valof_assign2: |
307 lemma valof_assign2: |
312 "(e,s) -|-> (v,s') ==> (VALOF x:=e RESULTIS X x, s) -|-> (v,s'(x:=v))" |
308 "(e,s) -|-> (v,s') ==> (VALOF x:=e RESULTIS X x, s) -|-> (v,s'(x:=v))" |
313 by blast |
309 by blast |
314 |
|
315 |
310 |
316 end |
311 end |