author | wenzelm |
Wed, 25 Jun 2025 16:35:25 +0200 | |
changeset 82768 | 8f866fd6fae1 |
parent 80914 | d97fdabd9e2b |
permissions | -rw-r--r-- |
8177 | 1 |
(* Title: HOL/IMPP/Com.thy |
2 |
Author: David von Oheimb (based on a theory by Tobias Nipkow et al), TUM |
|
3 |
*) |
|
4 |
||
63167 | 5 |
section \<open>Semantics of arithmetic and boolean expressions, Syntax of commands\<close> |
8177 | 6 |
|
17477 | 7 |
theory Com |
8 |
imports Main |
|
9 |
begin |
|
10 |
||
42174 | 11 |
type_synonym val = nat |
12 |
(* for the meta theory, this may be anything, but types cannot be refined later *) |
|
13 |
||
17477 | 14 |
typedecl glb |
15 |
typedecl loc |
|
16 |
||
27362 | 17 |
axiomatization |
18 |
Arg :: loc and |
|
17477 | 19 |
Res :: loc |
8177 | 20 |
|
58310 | 21 |
datatype vname = Glb glb | Loc loc |
42174 | 22 |
type_synonym globs = "glb => val" |
23 |
type_synonym locals = "loc => val" |
|
58310 | 24 |
datatype state = st globs locals |
8177 | 25 |
(* for the meta theory, the following would be sufficient: |
17477 | 26 |
typedecl state |
27 |
consts st :: "[globs , locals] => state" |
|
8177 | 28 |
*) |
42174 | 29 |
type_synonym aexp = "state => val" |
30 |
type_synonym bexp = "state => bool" |
|
8177 | 31 |
|
17477 | 32 |
typedecl pname |
8177 | 33 |
|
58310 | 34 |
datatype com |
8177 | 35 |
= SKIP |
80914
d97fdabd9e2b
standardize mixfix annotations via "isabelle update -a -u mixfix_cartouches" --- to simplify systematic editing;
wenzelm
parents:
67613
diff
changeset
|
36 |
| Ass vname aexp (\<open>_:==_\<close> [65, 65 ] 60) |
d97fdabd9e2b
standardize mixfix annotations via "isabelle update -a -u mixfix_cartouches" --- to simplify systematic editing;
wenzelm
parents:
67613
diff
changeset
|
37 |
| Local loc aexp com (\<open>LOCAL _:=_ IN _\<close> [65, 0, 61] 60) |
d97fdabd9e2b
standardize mixfix annotations via "isabelle update -a -u mixfix_cartouches" --- to simplify systematic editing;
wenzelm
parents:
67613
diff
changeset
|
38 |
| Semi com com (\<open>_;; _\<close> [59, 60 ] 59) |
d97fdabd9e2b
standardize mixfix annotations via "isabelle update -a -u mixfix_cartouches" --- to simplify systematic editing;
wenzelm
parents:
67613
diff
changeset
|
39 |
| Cond bexp com com (\<open>IF _ THEN _ ELSE _\<close> [65, 60, 61] 60) |
d97fdabd9e2b
standardize mixfix annotations via "isabelle update -a -u mixfix_cartouches" --- to simplify systematic editing;
wenzelm
parents:
67613
diff
changeset
|
40 |
| While bexp com (\<open>WHILE _ DO _\<close> [65, 61] 60) |
8177 | 41 |
| BODY pname |
80914
d97fdabd9e2b
standardize mixfix annotations via "isabelle update -a -u mixfix_cartouches" --- to simplify systematic editing;
wenzelm
parents:
67613
diff
changeset
|
42 |
| Call vname pname aexp (\<open>_:=CALL _'(_')\<close> [65, 65, 0] 60) |
8177 | 43 |
|
44 |
consts bodies :: "(pname * com) list"(* finitely many procedure definitions *) |
|
27362 | 45 |
definition |
61069 | 46 |
body :: " pname \<rightharpoonup> com" where |
27362 | 47 |
"body = map_of bodies" |
8177 | 48 |
|
49 |
||
50 |
(* Well-typedness: all procedures called must exist *) |
|
51 |
||
23746 | 52 |
inductive WT :: "com => bool" where |
8177 | 53 |
|
17477 | 54 |
Skip: "WT SKIP" |
8177 | 55 |
|
23746 | 56 |
| Assign: "WT (X :== a)" |
8177 | 57 |
|
23746 | 58 |
| Local: "WT c ==> |
17477 | 59 |
WT (LOCAL Y := a IN c)" |
8177 | 60 |
|
23746 | 61 |
| Semi: "[| WT c0; WT c1 |] ==> |
17477 | 62 |
WT (c0;; c1)" |
8177 | 63 |
|
23746 | 64 |
| If: "[| WT c0; WT c1 |] ==> |
17477 | 65 |
WT (IF b THEN c0 ELSE c1)" |
8177 | 66 |
|
23746 | 67 |
| While: "WT c ==> |
17477 | 68 |
WT (WHILE b DO c)" |
8177 | 69 |
|
23746 | 70 |
| Body: "body pn ~= None ==> |
17477 | 71 |
WT (BODY pn)" |
8177 | 72 |
|
23746 | 73 |
| Call: "WT (BODY pn) ==> |
17477 | 74 |
WT (X:=CALL pn(a))" |
75 |
||
76 |
inductive_cases WTs_elim_cases: |
|
77 |
"WT SKIP" "WT (X:==a)" "WT (LOCAL Y:=a IN c)" |
|
78 |
"WT (c1;;c2)" "WT (IF b THEN c1 ELSE c2)" "WT (WHILE b DO c)" |
|
79 |
"WT (BODY P)" "WT (X:=CALL P(a))" |
|
8177 | 80 |
|
27362 | 81 |
definition |
82 |
WT_bodies :: bool where |
|
67613 | 83 |
"WT_bodies = (\<forall>(pn,b) \<in> set bodies. WT b)" |
17477 | 84 |
|
19803 | 85 |
|
63167 | 86 |
ML \<open> |
60754 | 87 |
fun make_imp_tac ctxt = |
88 |
EVERY' [resolve_tac ctxt [mp], fn i => assume_tac ctxt (i + 1), eresolve_tac ctxt [thin_rl]] |
|
63167 | 89 |
\<close> |
19803 | 90 |
|
91 |
lemma finite_dom_body: "finite (dom body)" |
|
92 |
apply (unfold body_def) |
|
93 |
apply (rule finite_dom_map_of) |
|
94 |
done |
|
95 |
||
96 |
lemma WT_bodiesD: "[| WT_bodies; body pn = Some b |] ==> WT b" |
|
97 |
apply (unfold WT_bodies_def body_def) |
|
98 |
apply (drule map_of_SomeD) |
|
99 |
apply fast |
|
100 |
done |
|
101 |
||
102 |
declare WTs_elim_cases [elim!] |
|
8177 | 103 |
|
104 |
end |