187 re-use the basic quote/antiquote translations as already defined in |
187 re-use the basic quote/antiquote translations as already defined in |
188 Isabelle/Pure (see @{ML Syntax_Trans.quote_tr}, and |
188 Isabelle/Pure (see @{ML Syntax_Trans.quote_tr}, and |
189 @{ML Syntax_Trans.quote_tr'},). *} |
189 @{ML Syntax_Trans.quote_tr'},). *} |
190 |
190 |
191 syntax |
191 syntax |
192 "_quote" :: "'b \<Rightarrow> ('a \<Rightarrow> 'b)" ("(.'(_').)" [0] 1000) |
192 "_quote" :: "'b \<Rightarrow> ('a \<Rightarrow> 'b)" |
193 "_antiquote" :: "('a \<Rightarrow> 'b) \<Rightarrow> 'b" ("\<acute>_" [1000] 1000) |
193 "_antiquote" :: "('a \<Rightarrow> 'b) \<Rightarrow> 'b" ("\<acute>_" [1000] 1000) |
194 "_Subst" :: "'a bexp \<Rightarrow> 'b \<Rightarrow> idt \<Rightarrow> 'a bexp" |
194 "_Subst" :: "'a bexp \<Rightarrow> 'b \<Rightarrow> idt \<Rightarrow> 'a bexp" ("_[_'/\<acute>_]" [1000] 999) |
195 ("_[_'/\<acute>_]" [1000] 999) |
195 "_Assert" :: "'a \<Rightarrow> 'a set" ("(\<lbrace>_\<rbrace>)" [0] 1000) |
196 "_Assert" :: "'a \<Rightarrow> 'a set" ("(\<lbrace>_\<rbrace>)" [0] 1000) |
196 "_Assign" :: "idt \<Rightarrow> 'b \<Rightarrow> 'a com" ("(\<acute>_ :=/ _)" [70, 65] 61) |
197 "_Assign" :: "idt \<Rightarrow> 'b \<Rightarrow> 'a com" ("(\<acute>_ :=/ _)" [70, 65] 61) |
197 "_Cond" :: "'a bexp \<Rightarrow> 'a com \<Rightarrow> 'a com \<Rightarrow> 'a com" |
198 "_Cond" :: "'a bexp \<Rightarrow> 'a com \<Rightarrow> 'a com \<Rightarrow> 'a com" |
198 ("(0IF _/ THEN _/ ELSE _/ FI)" [0, 0, 0] 61) |
199 ("(0IF _/ THEN _/ ELSE _/ FI)" [0, 0, 0] 61) |
199 "_While_inv" :: "'a bexp \<Rightarrow> 'a assn \<Rightarrow> 'a com \<Rightarrow> 'a com" |
200 "_While_inv" :: "'a bexp \<Rightarrow> 'a assn \<Rightarrow> 'a com \<Rightarrow> 'a com" |
200 ("(0WHILE _/ INV _ //DO _ /OD)" [0, 0, 0] 61) |
201 ("(0WHILE _/ INV _ //DO _ /OD)" [0, 0, 0] 61) |
201 "_While" :: "'a bexp \<Rightarrow> 'a com \<Rightarrow> 'a com" ("(0WHILE _ //DO _ /OD)" [0, 0] 61) |
202 "_While" :: "'a bexp \<Rightarrow> 'a com \<Rightarrow> 'a com" |
|
203 ("(0WHILE _ //DO _ /OD)" [0, 0] 61) |
|
204 |
202 |
205 translations |
203 translations |
206 "\<lbrace>b\<rbrace>" \<rightharpoonup> "CONST Collect .(b)." |
204 "\<lbrace>b\<rbrace>" \<rightharpoonup> "CONST Collect (_quote b)" |
207 "B [a/\<acute>x]" \<rightharpoonup> "\<lbrace>\<acute>(_update_name x (\<lambda>_. a)) \<in> B\<rbrace>" |
205 "B [a/\<acute>x]" \<rightharpoonup> "\<lbrace>\<acute>(_update_name x (\<lambda>_. a)) \<in> B\<rbrace>" |
208 "\<acute>x := a" \<rightharpoonup> "CONST Basic .(\<acute>(_update_name x (\<lambda>_. a)))." |
206 "\<acute>x := a" \<rightharpoonup> "CONST Basic (_quote (\<acute>(_update_name x (\<lambda>_. a))))" |
209 "IF b THEN c1 ELSE c2 FI" \<rightharpoonup> "CONST Cond \<lbrace>b\<rbrace> c1 c2" |
207 "IF b THEN c1 ELSE c2 FI" \<rightharpoonup> "CONST Cond \<lbrace>b\<rbrace> c1 c2" |
210 "WHILE b INV i DO c OD" \<rightharpoonup> "CONST While \<lbrace>b\<rbrace> i c" |
208 "WHILE b INV i DO c OD" \<rightharpoonup> "CONST While \<lbrace>b\<rbrace> i c" |
211 "WHILE b DO c OD" \<rightleftharpoons> "WHILE b INV CONST undefined DO c OD" |
209 "WHILE b DO c OD" \<rightleftharpoons> "WHILE b INV CONST undefined DO c OD" |
212 |
210 |
213 parse_translation {* |
211 parse_translation {* |
214 let |
212 let |
215 fun quote_tr [t] = Syntax_Trans.quote_tr @{syntax_const "_antiquote"} t |
213 fun quote_tr [t] = Syntax_Trans.quote_tr @{syntax_const "_antiquote"} t |
216 | quote_tr ts = raise TERM ("quote_tr", ts); |
214 | quote_tr ts = raise TERM ("quote_tr", ts); |
326 \<Longrightarrow> \<turnstile> \<lbrace>\<acute>P\<rbrace> IF \<acute>b THEN c1 ELSE c2 FI Q" |
324 \<Longrightarrow> \<turnstile> \<lbrace>\<acute>P\<rbrace> IF \<acute>b THEN c1 ELSE c2 FI Q" |
327 by (rule cond) (simp_all add: Valid_def) |
325 by (rule cond) (simp_all add: Valid_def) |
328 |
326 |
329 text {* While statements --- with optional invariant. *} |
327 text {* While statements --- with optional invariant. *} |
330 |
328 |
331 lemma [intro?]: |
329 lemma [intro?]: "\<turnstile> (P \<inter> b) c P \<Longrightarrow> \<turnstile> P (While b P c) (P \<inter> -b)" |
332 "\<turnstile> (P \<inter> b) c P \<Longrightarrow> \<turnstile> P (While b P c) (P \<inter> -b)" |
|
333 by (rule while) |
330 by (rule while) |
334 |
331 |
335 lemma [intro?]: |
332 lemma [intro?]: "\<turnstile> (P \<inter> b) c P \<Longrightarrow> \<turnstile> P (While b undefined c) (P \<inter> -b)" |
336 "\<turnstile> (P \<inter> b) c P \<Longrightarrow> \<turnstile> P (While b undefined c) (P \<inter> -b)" |
|
337 by (rule while) |
333 by (rule while) |
338 |
334 |
339 |
335 |
340 lemma [intro?]: |
336 lemma [intro?]: |
341 "\<turnstile> \<lbrace>\<acute>P \<and> \<acute>b\<rbrace> c \<lbrace>\<acute>P\<rbrace> |
337 "\<turnstile> \<lbrace>\<acute>P \<and> \<acute>b\<rbrace> c \<lbrace>\<acute>P\<rbrace> |