author | wenzelm |
Fri, 08 Dec 2023 16:01:42 +0100 | |
changeset 79209 | fe24edf8acda |
parent 74723 | f05c73bf5968 |
child 80636 | 4041e7c8059d |
permissions | -rw-r--r-- |
42153 | 1 |
(* Title: HOL/Hoare/hoare_syntax.ML |
2 |
Author: Leonor Prensa Nieto & Tobias Nipkow |
|
74503
403ce50e6a2a
separated commands from annotations to be able to abstract about the latter only
nipkow
parents:
72998
diff
changeset
|
3 |
Author: Walter Guttmann (initial extension to total-correctness proofs) |
403ce50e6a2a
separated commands from annotations to be able to abstract about the latter only
nipkow
parents:
72998
diff
changeset
|
4 |
Author: Tobias Nipkow (complete version of total correctness with separate anno type) |
42153 | 5 |
|
6 |
Syntax translations for Hoare logic. |
|
7 |
*) |
|
8 |
||
9 |
signature HOARE_SYNTAX = |
|
10 |
sig |
|
72987
b1be35908165
clarified modules: avoid multiple uses of the same ML file;
wenzelm
parents:
72806
diff
changeset
|
11 |
val hoare_vars_tr: Proof.context -> term list -> term |
b1be35908165
clarified modules: avoid multiple uses of the same ML file;
wenzelm
parents:
72806
diff
changeset
|
12 |
val hoare_tc_vars_tr: Proof.context -> term list -> term |
b1be35908165
clarified modules: avoid multiple uses of the same ML file;
wenzelm
parents:
72806
diff
changeset
|
13 |
val spec_tr': string -> Proof.context -> term list -> term |
b1be35908165
clarified modules: avoid multiple uses of the same ML file;
wenzelm
parents:
72806
diff
changeset
|
14 |
val setup: |
b1be35908165
clarified modules: avoid multiple uses of the same ML file;
wenzelm
parents:
72806
diff
changeset
|
15 |
{Basic: string, Skip: string, Seq: string, Cond: string, While: string, |
b1be35908165
clarified modules: avoid multiple uses of the same ML file;
wenzelm
parents:
72806
diff
changeset
|
16 |
Valid: string, ValidTC: string} -> theory -> theory |
42153 | 17 |
end; |
18 |
||
19 |
structure Hoare_Syntax: HOARE_SYNTAX = |
|
20 |
struct |
|
21 |
||
72987
b1be35908165
clarified modules: avoid multiple uses of the same ML file;
wenzelm
parents:
72806
diff
changeset
|
22 |
(** theory data **) |
b1be35908165
clarified modules: avoid multiple uses of the same ML file;
wenzelm
parents:
72806
diff
changeset
|
23 |
|
b1be35908165
clarified modules: avoid multiple uses of the same ML file;
wenzelm
parents:
72806
diff
changeset
|
24 |
structure Data = Theory_Data |
b1be35908165
clarified modules: avoid multiple uses of the same ML file;
wenzelm
parents:
72806
diff
changeset
|
25 |
( |
b1be35908165
clarified modules: avoid multiple uses of the same ML file;
wenzelm
parents:
72806
diff
changeset
|
26 |
type T = |
b1be35908165
clarified modules: avoid multiple uses of the same ML file;
wenzelm
parents:
72806
diff
changeset
|
27 |
{Basic: string, Skip: string, Seq: string, Cond: string, While: string, |
b1be35908165
clarified modules: avoid multiple uses of the same ML file;
wenzelm
parents:
72806
diff
changeset
|
28 |
Valid: string, ValidTC: string} option; |
b1be35908165
clarified modules: avoid multiple uses of the same ML file;
wenzelm
parents:
72806
diff
changeset
|
29 |
val empty: T = NONE; |
b1be35908165
clarified modules: avoid multiple uses of the same ML file;
wenzelm
parents:
72806
diff
changeset
|
30 |
fun merge (data1, data2) = |
b1be35908165
clarified modules: avoid multiple uses of the same ML file;
wenzelm
parents:
72806
diff
changeset
|
31 |
if is_some data1 andalso is_some data2 andalso data1 <> data2 then |
b1be35908165
clarified modules: avoid multiple uses of the same ML file;
wenzelm
parents:
72806
diff
changeset
|
32 |
error "Cannot merge syntax from different Hoare Logics" |
b1be35908165
clarified modules: avoid multiple uses of the same ML file;
wenzelm
parents:
72806
diff
changeset
|
33 |
else merge_options (data1, data2); |
b1be35908165
clarified modules: avoid multiple uses of the same ML file;
wenzelm
parents:
72806
diff
changeset
|
34 |
); |
b1be35908165
clarified modules: avoid multiple uses of the same ML file;
wenzelm
parents:
72806
diff
changeset
|
35 |
|
b1be35908165
clarified modules: avoid multiple uses of the same ML file;
wenzelm
parents:
72806
diff
changeset
|
36 |
fun const_syntax ctxt which = |
b1be35908165
clarified modules: avoid multiple uses of the same ML file;
wenzelm
parents:
72806
diff
changeset
|
37 |
(case Data.get (Proof_Context.theory_of ctxt) of |
b1be35908165
clarified modules: avoid multiple uses of the same ML file;
wenzelm
parents:
72806
diff
changeset
|
38 |
SOME consts => which consts |
b1be35908165
clarified modules: avoid multiple uses of the same ML file;
wenzelm
parents:
72806
diff
changeset
|
39 |
| NONE => error "Undefined Hoare syntax consts"); |
b1be35908165
clarified modules: avoid multiple uses of the same ML file;
wenzelm
parents:
72806
diff
changeset
|
40 |
|
b1be35908165
clarified modules: avoid multiple uses of the same ML file;
wenzelm
parents:
72806
diff
changeset
|
41 |
val syntax_const = Syntax.const oo const_syntax; |
b1be35908165
clarified modules: avoid multiple uses of the same ML file;
wenzelm
parents:
72806
diff
changeset
|
42 |
|
b1be35908165
clarified modules: avoid multiple uses of the same ML file;
wenzelm
parents:
72806
diff
changeset
|
43 |
|
b1be35908165
clarified modules: avoid multiple uses of the same ML file;
wenzelm
parents:
72806
diff
changeset
|
44 |
|
42153 | 45 |
(** parse translation **) |
46 |
||
47 |
local |
|
48 |
||
49 |
fun idt_name (Free (x, _)) = SOME x |
|
69597 | 50 |
| idt_name (Const (\<^syntax_const>\<open>_constrain\<close>, _) $ t $ _) = idt_name t |
42153 | 51 |
| idt_name _ = NONE; |
52 |
||
53 |
fun eq_idt tu = |
|
59058
a78612c67ec0
renamed "pairself" to "apply2", in accordance to @{apply 2};
wenzelm
parents:
55659
diff
changeset
|
54 |
(case apply2 idt_name tu of |
42153 | 55 |
(SOME x, SOME y) => x = y |
56 |
| _ => false); |
|
57 |
||
42284 | 58 |
fun mk_abstuple [x] body = Syntax_Trans.abs_tr [x, body] |
42153 | 59 |
| mk_abstuple (x :: xs) body = |
69597 | 60 |
Syntax.const \<^const_syntax>\<open>case_prod\<close> $ Syntax_Trans.abs_tr [x, mk_abstuple xs body]; |
42153 | 61 |
|
62 |
fun mk_fbody x e [y] = if eq_idt (x, y) then e else y |
|
63 |
| mk_fbody x e (y :: xs) = |
|
69597 | 64 |
Syntax.const \<^const_syntax>\<open>Pair\<close> $ |
42153 | 65 |
(if eq_idt (x, y) then e else y) $ mk_fbody x e xs; |
66 |
||
67 |
fun mk_fexp x e xs = mk_abstuple xs (mk_fbody x e xs); |
|
68 |
||
69 |
||
70 |
(* bexp_tr & assn_tr *) |
|
71 |
(*all meta-variables for bexp except for TRUE are translated as if they |
|
72 |
were boolean expressions*) |
|
73 |
||
55659 | 74 |
fun bexp_tr (Const ("TRUE", _)) _ = Syntax.const "TRUE" (* FIXME !? *) |
69597 | 75 |
| bexp_tr b xs = Syntax.const \<^const_syntax>\<open>Collect\<close> $ mk_abstuple xs b; |
42153 | 76 |
|
69597 | 77 |
fun assn_tr r xs = Syntax.const \<^const_syntax>\<open>Collect\<close> $ mk_abstuple xs r; |
42153 | 78 |
|
72806
4fa08e083865
Extension of session HOL/Hoare with total correctness proof system by Walter Guttmann
nipkow
parents:
69597
diff
changeset
|
79 |
fun var_tr v xs = mk_abstuple xs v; |
4fa08e083865
Extension of session HOL/Hoare with total correctness proof system by Walter Guttmann
nipkow
parents:
69597
diff
changeset
|
80 |
|
42153 | 81 |
|
82 |
(* com_tr *) |
|
83 |
||
72987
b1be35908165
clarified modules: avoid multiple uses of the same ML file;
wenzelm
parents:
72806
diff
changeset
|
84 |
fun com_tr ctxt = |
b1be35908165
clarified modules: avoid multiple uses of the same ML file;
wenzelm
parents:
72806
diff
changeset
|
85 |
let |
b1be35908165
clarified modules: avoid multiple uses of the same ML file;
wenzelm
parents:
72806
diff
changeset
|
86 |
fun tr (Const (\<^syntax_const>\<open>_assign\<close>, _) $ x $ e) xs = |
74503
403ce50e6a2a
separated commands from annotations to be able to abstract about the latter only
nipkow
parents:
72998
diff
changeset
|
87 |
(syntax_const ctxt #Basic $ mk_fexp x e xs, Syntax.const \<^const_syntax>\<open>Abasic\<close>) |
72987
b1be35908165
clarified modules: avoid multiple uses of the same ML file;
wenzelm
parents:
72806
diff
changeset
|
88 |
| tr (Const (\<^syntax_const>\<open>_Seq\<close>,_) $ c1 $ c2) xs = |
74503
403ce50e6a2a
separated commands from annotations to be able to abstract about the latter only
nipkow
parents:
72998
diff
changeset
|
89 |
let val (c1',a1) = tr c1 xs; |
403ce50e6a2a
separated commands from annotations to be able to abstract about the latter only
nipkow
parents:
72998
diff
changeset
|
90 |
val (c2',a2) = tr c2 xs |
403ce50e6a2a
separated commands from annotations to be able to abstract about the latter only
nipkow
parents:
72998
diff
changeset
|
91 |
in (syntax_const ctxt #Seq $ c1' $ c2', Syntax.const \<^const_syntax>\<open>Aseq\<close> $ a1 $ a2) end |
72987
b1be35908165
clarified modules: avoid multiple uses of the same ML file;
wenzelm
parents:
72806
diff
changeset
|
92 |
| tr (Const (\<^syntax_const>\<open>_Cond\<close>,_) $ b $ c1 $ c2) xs = |
74503
403ce50e6a2a
separated commands from annotations to be able to abstract about the latter only
nipkow
parents:
72998
diff
changeset
|
93 |
let val (c1',a1) = tr c1 xs; |
403ce50e6a2a
separated commands from annotations to be able to abstract about the latter only
nipkow
parents:
72998
diff
changeset
|
94 |
val (c2',a2) = tr c2 xs |
403ce50e6a2a
separated commands from annotations to be able to abstract about the latter only
nipkow
parents:
72998
diff
changeset
|
95 |
in (syntax_const ctxt #Cond $ bexp_tr b xs $ c1' $ c2', |
403ce50e6a2a
separated commands from annotations to be able to abstract about the latter only
nipkow
parents:
72998
diff
changeset
|
96 |
Syntax.const \<^const_syntax>\<open>Acond\<close> $ a1 $ a2) |
403ce50e6a2a
separated commands from annotations to be able to abstract about the latter only
nipkow
parents:
72998
diff
changeset
|
97 |
end |
403ce50e6a2a
separated commands from annotations to be able to abstract about the latter only
nipkow
parents:
72998
diff
changeset
|
98 |
| tr (Const (\<^syntax_const>\<open>_While\<close>,_) $ b $ i $ v $ c) xs = |
403ce50e6a2a
separated commands from annotations to be able to abstract about the latter only
nipkow
parents:
72998
diff
changeset
|
99 |
let val (c',a) = tr c xs |
403ce50e6a2a
separated commands from annotations to be able to abstract about the latter only
nipkow
parents:
72998
diff
changeset
|
100 |
val (v',A) = case v of |
403ce50e6a2a
separated commands from annotations to be able to abstract about the latter only
nipkow
parents:
72998
diff
changeset
|
101 |
Const (\<^const_syntax>\<open>HOL.eq\<close>, _) $ z $ t => (t, Syntax_Trans.abs_tr [z, a]) | |
74723 | 102 |
t => (t, Abs ("n", dummyT, a)) |
74503
403ce50e6a2a
separated commands from annotations to be able to abstract about the latter only
nipkow
parents:
72998
diff
changeset
|
103 |
in (syntax_const ctxt #While $ bexp_tr b xs $ c', |
403ce50e6a2a
separated commands from annotations to be able to abstract about the latter only
nipkow
parents:
72998
diff
changeset
|
104 |
Syntax.const \<^const_syntax>\<open>Awhile\<close> |
403ce50e6a2a
separated commands from annotations to be able to abstract about the latter only
nipkow
parents:
72998
diff
changeset
|
105 |
$ assn_tr i xs $ var_tr v' xs $ A) |
403ce50e6a2a
separated commands from annotations to be able to abstract about the latter only
nipkow
parents:
72998
diff
changeset
|
106 |
end |
403ce50e6a2a
separated commands from annotations to be able to abstract about the latter only
nipkow
parents:
72998
diff
changeset
|
107 |
| tr (Const (\<^syntax_const>\<open>_While0\<close>,_) $ b $ I $ c) xs = |
403ce50e6a2a
separated commands from annotations to be able to abstract about the latter only
nipkow
parents:
72998
diff
changeset
|
108 |
let val (c',a) = tr c xs |
403ce50e6a2a
separated commands from annotations to be able to abstract about the latter only
nipkow
parents:
72998
diff
changeset
|
109 |
in (syntax_const ctxt #While $ bexp_tr b xs $ c', |
403ce50e6a2a
separated commands from annotations to be able to abstract about the latter only
nipkow
parents:
72998
diff
changeset
|
110 |
Syntax.const \<^const_syntax>\<open>Awhile\<close> |
403ce50e6a2a
separated commands from annotations to be able to abstract about the latter only
nipkow
parents:
72998
diff
changeset
|
111 |
$ assn_tr I xs $ var_tr (Syntax.const \<^const_syntax>\<open>zero_class.zero\<close>) xs |
403ce50e6a2a
separated commands from annotations to be able to abstract about the latter only
nipkow
parents:
72998
diff
changeset
|
112 |
$ absdummy dummyT a) |
403ce50e6a2a
separated commands from annotations to be able to abstract about the latter only
nipkow
parents:
72998
diff
changeset
|
113 |
end |
403ce50e6a2a
separated commands from annotations to be able to abstract about the latter only
nipkow
parents:
72998
diff
changeset
|
114 |
| tr t _ = (t, Syntax.const \<^const_syntax>\<open>Abasic\<close>) |
72987
b1be35908165
clarified modules: avoid multiple uses of the same ML file;
wenzelm
parents:
72806
diff
changeset
|
115 |
in tr end; |
42153 | 116 |
|
69597 | 117 |
fun vars_tr (Const (\<^syntax_const>\<open>_idts\<close>, _) $ idt $ vars) = idt :: vars_tr vars |
42153 | 118 |
| vars_tr t = [t]; |
119 |
||
120 |
in |
|
121 |
||
72987
b1be35908165
clarified modules: avoid multiple uses of the same ML file;
wenzelm
parents:
72806
diff
changeset
|
122 |
fun hoare_vars_tr ctxt [vars, pre, prg, post] = |
42153 | 123 |
let val xs = vars_tr vars |
74503
403ce50e6a2a
separated commands from annotations to be able to abstract about the latter only
nipkow
parents:
72998
diff
changeset
|
124 |
val (c',a) = com_tr ctxt prg xs |
403ce50e6a2a
separated commands from annotations to be able to abstract about the latter only
nipkow
parents:
72998
diff
changeset
|
125 |
in syntax_const ctxt #Valid $ assn_tr pre xs $ c' $ a $ assn_tr post xs end |
72987
b1be35908165
clarified modules: avoid multiple uses of the same ML file;
wenzelm
parents:
72806
diff
changeset
|
126 |
| hoare_vars_tr _ ts = raise TERM ("hoare_vars_tr", ts); |
42153 | 127 |
|
72987
b1be35908165
clarified modules: avoid multiple uses of the same ML file;
wenzelm
parents:
72806
diff
changeset
|
128 |
fun hoare_tc_vars_tr ctxt [vars, pre, prg, post] = |
72806
4fa08e083865
Extension of session HOL/Hoare with total correctness proof system by Walter Guttmann
nipkow
parents:
69597
diff
changeset
|
129 |
let val xs = vars_tr vars |
74503
403ce50e6a2a
separated commands from annotations to be able to abstract about the latter only
nipkow
parents:
72998
diff
changeset
|
130 |
val (c',a) = com_tr ctxt prg xs |
403ce50e6a2a
separated commands from annotations to be able to abstract about the latter only
nipkow
parents:
72998
diff
changeset
|
131 |
in syntax_const ctxt #ValidTC $ assn_tr pre xs $ c' $ a $ assn_tr post xs end |
72987
b1be35908165
clarified modules: avoid multiple uses of the same ML file;
wenzelm
parents:
72806
diff
changeset
|
132 |
| hoare_tc_vars_tr _ ts = raise TERM ("hoare_tc_vars_tr", ts); |
72806
4fa08e083865
Extension of session HOL/Hoare with total correctness proof system by Walter Guttmann
nipkow
parents:
69597
diff
changeset
|
133 |
|
42153 | 134 |
end; |
135 |
||
136 |
||
137 |
||
138 |
(** print translation **) |
|
139 |
||
140 |
local |
|
141 |
||
142 |
fun dest_abstuple |
|
69597 | 143 |
(Const (\<^const_syntax>\<open>case_prod\<close>, _) $ Abs (v, _, body)) = |
42153 | 144 |
subst_bound (Syntax.free v, dest_abstuple body) |
145 |
| dest_abstuple (Abs (v,_, body)) = subst_bound (Syntax.free v, body) |
|
146 |
| dest_abstuple tm = tm; |
|
147 |
||
69597 | 148 |
fun abs2list (Const (\<^const_syntax>\<open>case_prod\<close>, _) $ Abs (x, T, t)) = Free (x, T) :: abs2list t |
55659 | 149 |
| abs2list (Abs (x, T, _)) = [Free (x, T)] |
42153 | 150 |
| abs2list _ = []; |
151 |
||
69597 | 152 |
fun mk_ts (Const (\<^const_syntax>\<open>case_prod\<close>, _) $ Abs (_, _, t)) = mk_ts t |
55659 | 153 |
| mk_ts (Abs (_, _, t)) = mk_ts t |
69597 | 154 |
| mk_ts (Const (\<^const_syntax>\<open>Pair\<close>, _) $ a $ b) = a :: mk_ts b |
42153 | 155 |
| mk_ts t = [t]; |
156 |
||
69597 | 157 |
fun mk_vts (Const (\<^const_syntax>\<open>case_prod\<close>,_) $ Abs (x, _, t)) = |
42153 | 158 |
(Syntax.free x :: abs2list t, mk_ts t) |
159 |
| mk_vts (Abs (x, _, t)) = ([Syntax.free x], [t]) |
|
55659 | 160 |
| mk_vts _ = raise Match; |
42153 | 161 |
|
55659 | 162 |
fun find_ch [] _ _ = (false, (Syntax.free "not_ch", Syntax.free "not_ch")) (* FIXME no_ch!? *) |
42153 | 163 |
| find_ch ((v, t) :: vts) i xs = |
164 |
if t = Bound i then find_ch vts (i - 1) xs |
|
165 |
else (true, (v, subst_bounds (xs, t))); |
|
166 |
||
69597 | 167 |
fun is_f (Const (\<^const_syntax>\<open>case_prod\<close>, _) $ Abs _) = true |
55659 | 168 |
| is_f (Abs _) = true |
169 |
| is_f _ = false; |
|
42153 | 170 |
|
171 |
||
172 |
(* assn_tr' & bexp_tr'*) |
|
173 |
||
69597 | 174 |
fun assn_tr' (Const (\<^const_syntax>\<open>Collect\<close>, _) $ T) = dest_abstuple T |
175 |
| assn_tr' (Const (\<^const_syntax>\<open>inter\<close>, _) $ |
|
176 |
(Const (\<^const_syntax>\<open>Collect\<close>, _) $ T1) $ (Const (\<^const_syntax>\<open>Collect\<close>, _) $ T2)) = |
|
177 |
Syntax.const \<^const_syntax>\<open>inter\<close> $ dest_abstuple T1 $ dest_abstuple T2 |
|
42153 | 178 |
| assn_tr' t = t; |
179 |
||
69597 | 180 |
fun bexp_tr' (Const (\<^const_syntax>\<open>Collect\<close>, _) $ T) = dest_abstuple T |
42153 | 181 |
| bexp_tr' t = t; |
182 |
||
74503
403ce50e6a2a
separated commands from annotations to be able to abstract about the latter only
nipkow
parents:
72998
diff
changeset
|
183 |
fun var_tr' xo T = |
403ce50e6a2a
separated commands from annotations to be able to abstract about the latter only
nipkow
parents:
72998
diff
changeset
|
184 |
let val n = dest_abstuple T |
403ce50e6a2a
separated commands from annotations to be able to abstract about the latter only
nipkow
parents:
72998
diff
changeset
|
185 |
in case xo of NONE => n | SOME x => Syntax.const \<^const_syntax>\<open>HOL.eq\<close> $ Syntax.free x $ n end |
72806
4fa08e083865
Extension of session HOL/Hoare with total correctness proof system by Walter Guttmann
nipkow
parents:
69597
diff
changeset
|
186 |
|
42153 | 187 |
|
188 |
(* com_tr' *) |
|
189 |
||
72987
b1be35908165
clarified modules: avoid multiple uses of the same ML file;
wenzelm
parents:
72806
diff
changeset
|
190 |
fun mk_assign ctxt f = |
42153 | 191 |
let |
192 |
val (vs, ts) = mk_vts f; |
|
72987
b1be35908165
clarified modules: avoid multiple uses of the same ML file;
wenzelm
parents:
72806
diff
changeset
|
193 |
val (ch, (a, b)) = find_ch (vs ~~ ts) (length vs - 1) (rev vs); |
42153 | 194 |
in |
195 |
if ch |
|
72987
b1be35908165
clarified modules: avoid multiple uses of the same ML file;
wenzelm
parents:
72806
diff
changeset
|
196 |
then Syntax.const \<^syntax_const>\<open>_assign\<close> $ a $ b |
b1be35908165
clarified modules: avoid multiple uses of the same ML file;
wenzelm
parents:
72806
diff
changeset
|
197 |
else syntax_const ctxt #Skip |
42153 | 198 |
end; |
199 |
||
74503
403ce50e6a2a
separated commands from annotations to be able to abstract about the latter only
nipkow
parents:
72998
diff
changeset
|
200 |
fun com_tr' ctxt (t,a) = |
72987
b1be35908165
clarified modules: avoid multiple uses of the same ML file;
wenzelm
parents:
72806
diff
changeset
|
201 |
let |
b1be35908165
clarified modules: avoid multiple uses of the same ML file;
wenzelm
parents:
72806
diff
changeset
|
202 |
val (head, args) = apfst (try (#1 o Term.dest_Const)) (Term.strip_comb t); |
b1be35908165
clarified modules: avoid multiple uses of the same ML file;
wenzelm
parents:
72806
diff
changeset
|
203 |
fun arg k = nth args (k - 1); |
b1be35908165
clarified modules: avoid multiple uses of the same ML file;
wenzelm
parents:
72806
diff
changeset
|
204 |
val n = length args; |
74503
403ce50e6a2a
separated commands from annotations to be able to abstract about the latter only
nipkow
parents:
72998
diff
changeset
|
205 |
val (_, args_a) = apfst (try (#1 o Term.dest_Const)) (Term.strip_comb a); |
403ce50e6a2a
separated commands from annotations to be able to abstract about the latter only
nipkow
parents:
72998
diff
changeset
|
206 |
fun arg_a k = nth args_a (k - 1) |
72987
b1be35908165
clarified modules: avoid multiple uses of the same ML file;
wenzelm
parents:
72806
diff
changeset
|
207 |
in |
74503
403ce50e6a2a
separated commands from annotations to be able to abstract about the latter only
nipkow
parents:
72998
diff
changeset
|
208 |
case head of |
72987
b1be35908165
clarified modules: avoid multiple uses of the same ML file;
wenzelm
parents:
72806
diff
changeset
|
209 |
NONE => t |
b1be35908165
clarified modules: avoid multiple uses of the same ML file;
wenzelm
parents:
72806
diff
changeset
|
210 |
| SOME c => |
b1be35908165
clarified modules: avoid multiple uses of the same ML file;
wenzelm
parents:
72806
diff
changeset
|
211 |
if c = const_syntax ctxt #Basic andalso n = 1 andalso is_f (arg 1) then |
b1be35908165
clarified modules: avoid multiple uses of the same ML file;
wenzelm
parents:
72806
diff
changeset
|
212 |
mk_assign ctxt (arg 1) |
b1be35908165
clarified modules: avoid multiple uses of the same ML file;
wenzelm
parents:
72806
diff
changeset
|
213 |
else if c = const_syntax ctxt #Seq andalso n = 2 then |
74503
403ce50e6a2a
separated commands from annotations to be able to abstract about the latter only
nipkow
parents:
72998
diff
changeset
|
214 |
Syntax.const \<^syntax_const>\<open>_Seq\<close> |
403ce50e6a2a
separated commands from annotations to be able to abstract about the latter only
nipkow
parents:
72998
diff
changeset
|
215 |
$ com_tr' ctxt (arg 1, arg_a 1) $ com_tr' ctxt (arg 2, arg_a 2) |
72987
b1be35908165
clarified modules: avoid multiple uses of the same ML file;
wenzelm
parents:
72806
diff
changeset
|
216 |
else if c = const_syntax ctxt #Cond andalso n = 3 then |
b1be35908165
clarified modules: avoid multiple uses of the same ML file;
wenzelm
parents:
72806
diff
changeset
|
217 |
Syntax.const \<^syntax_const>\<open>_Cond\<close> $ |
74503
403ce50e6a2a
separated commands from annotations to be able to abstract about the latter only
nipkow
parents:
72998
diff
changeset
|
218 |
bexp_tr' (arg 1) $ com_tr' ctxt (arg 2, arg_a 1) $ com_tr' ctxt (arg 3, arg_a 2) |
403ce50e6a2a
separated commands from annotations to be able to abstract about the latter only
nipkow
parents:
72998
diff
changeset
|
219 |
else if c = const_syntax ctxt #While andalso n = 2 then |
403ce50e6a2a
separated commands from annotations to be able to abstract about the latter only
nipkow
parents:
72998
diff
changeset
|
220 |
let val (xo,a') = case arg_a 3 of |
403ce50e6a2a
separated commands from annotations to be able to abstract about the latter only
nipkow
parents:
72998
diff
changeset
|
221 |
Abs(x,_,a) => (if loose_bvar1(a,0) then SOME x else NONE, |
403ce50e6a2a
separated commands from annotations to be able to abstract about the latter only
nipkow
parents:
72998
diff
changeset
|
222 |
subst_bound (Syntax.free x, a)) | |
403ce50e6a2a
separated commands from annotations to be able to abstract about the latter only
nipkow
parents:
72998
diff
changeset
|
223 |
t => (NONE,t) |
403ce50e6a2a
separated commands from annotations to be able to abstract about the latter only
nipkow
parents:
72998
diff
changeset
|
224 |
in Syntax.const \<^syntax_const>\<open>_While\<close> |
403ce50e6a2a
separated commands from annotations to be able to abstract about the latter only
nipkow
parents:
72998
diff
changeset
|
225 |
$ bexp_tr' (arg 1) $ assn_tr' (arg_a 1) $ var_tr' xo (arg_a 2) $ com_tr' ctxt (arg 2, a') |
403ce50e6a2a
separated commands from annotations to be able to abstract about the latter only
nipkow
parents:
72998
diff
changeset
|
226 |
end |
403ce50e6a2a
separated commands from annotations to be able to abstract about the latter only
nipkow
parents:
72998
diff
changeset
|
227 |
else t |
72987
b1be35908165
clarified modules: avoid multiple uses of the same ML file;
wenzelm
parents:
72806
diff
changeset
|
228 |
end; |
42153 | 229 |
|
230 |
in |
|
231 |
||
74503
403ce50e6a2a
separated commands from annotations to be able to abstract about the latter only
nipkow
parents:
72998
diff
changeset
|
232 |
fun spec_tr' syn ctxt [p, c, a, q] = |
403ce50e6a2a
separated commands from annotations to be able to abstract about the latter only
nipkow
parents:
72998
diff
changeset
|
233 |
Syntax.const syn $ assn_tr' p $ com_tr' ctxt (c,a) $ assn_tr' q; |
42153 | 234 |
|
235 |
end; |
|
236 |
||
72987
b1be35908165
clarified modules: avoid multiple uses of the same ML file;
wenzelm
parents:
72806
diff
changeset
|
237 |
|
b1be35908165
clarified modules: avoid multiple uses of the same ML file;
wenzelm
parents:
72806
diff
changeset
|
238 |
(** setup **) |
b1be35908165
clarified modules: avoid multiple uses of the same ML file;
wenzelm
parents:
72806
diff
changeset
|
239 |
|
72998
7ea253f93606
more robust: clarified error when merging Hoare_Logic + Hoare_Logic_Abort;
wenzelm
parents:
72987
diff
changeset
|
240 |
val _ = |
7ea253f93606
more robust: clarified error when merging Hoare_Logic + Hoare_Logic_Abort;
wenzelm
parents:
72987
diff
changeset
|
241 |
Theory.setup |
7ea253f93606
more robust: clarified error when merging Hoare_Logic + Hoare_Logic_Abort;
wenzelm
parents:
72987
diff
changeset
|
242 |
(Sign.parse_translation |
7ea253f93606
more robust: clarified error when merging Hoare_Logic + Hoare_Logic_Abort;
wenzelm
parents:
72987
diff
changeset
|
243 |
[(\<^syntax_const>\<open>_hoare_vars\<close>, hoare_vars_tr), |
7ea253f93606
more robust: clarified error when merging Hoare_Logic + Hoare_Logic_Abort;
wenzelm
parents:
72987
diff
changeset
|
244 |
(\<^syntax_const>\<open>_hoare_vars_tc\<close>, hoare_tc_vars_tr)]); |
7ea253f93606
more robust: clarified error when merging Hoare_Logic + Hoare_Logic_Abort;
wenzelm
parents:
72987
diff
changeset
|
245 |
|
72987
b1be35908165
clarified modules: avoid multiple uses of the same ML file;
wenzelm
parents:
72806
diff
changeset
|
246 |
fun setup consts = |
b1be35908165
clarified modules: avoid multiple uses of the same ML file;
wenzelm
parents:
72806
diff
changeset
|
247 |
Data.put (SOME consts) #> |
b1be35908165
clarified modules: avoid multiple uses of the same ML file;
wenzelm
parents:
72806
diff
changeset
|
248 |
Sign.print_translation |
b1be35908165
clarified modules: avoid multiple uses of the same ML file;
wenzelm
parents:
72806
diff
changeset
|
249 |
[(#Valid consts, spec_tr' \<^syntax_const>\<open>_hoare\<close>), |
b1be35908165
clarified modules: avoid multiple uses of the same ML file;
wenzelm
parents:
72806
diff
changeset
|
250 |
(#ValidTC consts, spec_tr' \<^syntax_const>\<open>_hoare_tc\<close>)]; |
b1be35908165
clarified modules: avoid multiple uses of the same ML file;
wenzelm
parents:
72806
diff
changeset
|
251 |
|
42153 | 252 |
end; |