author | wenzelm |
Thu, 26 Apr 2007 16:39:31 +0200 | |
changeset 22819 | a7b425bb668c |
parent 17244 | 0b2ff9541727 |
child 26939 | 1035c89b4c02 |
permissions | -rw-r--r-- |
7299 | 1 |
|
17244 | 2 |
(* $Id$ *) |
3 |
||
4 |
theory MuIOA |
|
5 |
imports IOA MuckeSyn |
|
6 |
begin |
|
6471
08d12ef5fc19
added translation from IOA to mucalculus and corresponding modelchecker examples;
mueller
parents:
diff
changeset
|
7 |
|
08d12ef5fc19
added translation from IOA to mucalculus and corresponding modelchecker examples;
mueller
parents:
diff
changeset
|
8 |
consts |
17244 | 9 |
Internal_of_A :: "'a => bool" |
10 |
Internal_of_C :: "'a => bool" |
|
11 |
Start_of_A :: "'a => bool" |
|
12 |
Start_of_C :: "'a => bool" |
|
13 |
Trans_of_A :: "'a => 'b => bool" |
|
14 |
Trans_of_C :: "'a => 'b => bool" |
|
15 |
IntStep_of_A :: "'a => bool" |
|
16 |
IntStepStar_of_A :: "'a => bool" |
|
17 |
Move_of_A :: "'a => 'b => bool" |
|
18 |
isSimCA :: "'a => bool" |
|
6471
08d12ef5fc19
added translation from IOA to mucalculus and corresponding modelchecker examples;
mueller
parents:
diff
changeset
|
19 |
|
22819 | 20 |
ML {* |
21 |
||
22 |
(* MuIOA.ML declares function mk_sim_oracle used by oracle "Sim" (see MuIOAOracle.thy). |
|
23 |
There, implementation relations for I/O automatons are proved using |
|
24 |
the model checker mucke (invoking cal_mucke_tac defined in MCSyn.ML). *) |
|
25 |
||
26 |
exception SimFailureExn of string; |
|
27 |
||
28 |
val ioa_simps = [thm "asig_of_def", thm "starts_of_def", thm "trans_of_def"]; |
|
29 |
val asig_simps = [thm "asig_inputs_def", thm "asig_outputs_def", |
|
30 |
thm "asig_internals_def", thm "actions_def"]; |
|
31 |
val comp_simps = [thm "par_def", thm "asig_comp_def"]; |
|
32 |
val restrict_simps = [thm "restrict_def", thm "restrict_asig_def"]; |
|
33 |
val hide_simps = [thm "hide_def", thm "hide_asig_def"]; |
|
34 |
val rename_simps = [thm "rename_def", thm "rename_set_def"]; |
|
35 |
||
36 |
local |
|
37 |
||
38 |
exception malformed; |
|
39 |
||
40 |
fun fst_type (Type("*",[a,_])) = a | |
|
41 |
fst_type _ = raise malformed; |
|
42 |
fun snd_type (Type("*",[_,a])) = a | |
|
43 |
snd_type _ = raise malformed; |
|
44 |
||
45 |
fun element_type (Type("set",[a])) = a | |
|
46 |
element_type t = raise malformed; |
|
47 |
||
48 |
fun IntC sg (Const("Trueprop",_) $ ((Const("op <=",_) $ (_ $ concreteIOA)) $ _)) = |
|
49 |
let |
|
50 |
val aut_typ = #T(rep_cterm(cterm_of sg concreteIOA)); |
|
51 |
val sig_typ = fst_type aut_typ; |
|
52 |
val int_typ = fst_type sig_typ |
|
53 |
in |
|
54 |
Const("Asig.internals",Type("fun",[sig_typ,int_typ])) $ |
|
55 |
(Const("Automata.asig_of",Type("fun",[aut_typ,sig_typ])) $ concreteIOA) |
|
6471
08d12ef5fc19
added translation from IOA to mucalculus and corresponding modelchecker examples;
mueller
parents:
diff
changeset
|
56 |
end |
22819 | 57 |
| |
58 |
IntC sg t = |
|
59 |
error("malformed automaton def for IntC:\n" ^ (Sign.string_of_term sg t)); |
|
60 |
||
61 |
fun StartC sg (Const("Trueprop",_) $ ((Const("op <=",_) $ (_ $ concreteIOA)) $ _)) = |
|
62 |
let |
|
63 |
val aut_typ = #T(rep_cterm(cterm_of sg concreteIOA)); |
|
64 |
val st_typ = fst_type(snd_type aut_typ) |
|
65 |
in |
|
66 |
Const("Automata.starts_of",Type("fun",[aut_typ,st_typ])) $ concreteIOA |
|
67 |
end |
|
68 |
| |
|
69 |
StartC sg t = |
|
70 |
error("malformed automaton def for StartC:\n" ^ (Sign.string_of_term sg t)); |
|
71 |
||
72 |
fun TransC sg (Const("Trueprop",_) $ ((Const("op <=",_) $ (_ $ concreteIOA)) $ _)) = |
|
73 |
let |
|
74 |
val aut_typ = #T(rep_cterm(cterm_of sg concreteIOA)); |
|
75 |
val tr_typ = fst_type(snd_type(snd_type aut_typ)) |
|
76 |
in |
|
77 |
Const("Automata.trans_of",Type("fun",[aut_typ,tr_typ])) $ concreteIOA |
|
78 |
end |
|
79 |
| |
|
80 |
TransC sg t = |
|
81 |
error("malformed automaton def for TransC:\n" ^ (Sign.string_of_term sg t)); |
|
82 |
||
83 |
fun IntA sg (Const("Trueprop",_) $ ((Const("op <=",_) $ _) $ (_ $ abstractIOA))) = |
|
84 |
let |
|
85 |
val aut_typ = #T(rep_cterm(cterm_of sg abstractIOA)); |
|
86 |
val sig_typ = fst_type aut_typ; |
|
87 |
val int_typ = fst_type sig_typ |
|
88 |
in |
|
89 |
Const("Asig.internals",Type("fun",[sig_typ,int_typ])) $ |
|
90 |
(Const("Automata.asig_of",Type("fun",[aut_typ,sig_typ])) $ abstractIOA) |
|
91 |
end |
|
92 |
| |
|
93 |
IntA sg t = |
|
94 |
error("malformed automaton def for IntA:\n" ^ (Sign.string_of_term sg t)); |
|
95 |
||
96 |
fun StartA sg (Const("Trueprop",_) $ ((Const("op <=",_) $ _) $ (_ $ abstractIOA))) = |
|
97 |
let |
|
98 |
val aut_typ = #T(rep_cterm(cterm_of sg abstractIOA)); |
|
99 |
val st_typ = fst_type(snd_type aut_typ) |
|
100 |
in |
|
101 |
Const("Automata.starts_of",Type("fun",[aut_typ,st_typ])) $ abstractIOA |
|
102 |
end |
|
103 |
| |
|
104 |
StartA sg t = |
|
105 |
error("malformed automaton def for StartA:\n" ^ (Sign.string_of_term sg t)); |
|
106 |
||
107 |
fun TransA sg (Const("Trueprop",_) $ ((Const("op <=",_) $ _) $ (_ $ abstractIOA))) = |
|
108 |
let |
|
109 |
val aut_typ = #T(rep_cterm(cterm_of sg abstractIOA)); |
|
110 |
val tr_typ = fst_type(snd_type(snd_type aut_typ)) |
|
111 |
in |
|
112 |
Const("Automata.trans_of",Type("fun",[aut_typ,tr_typ])) $ abstractIOA |
|
113 |
end |
|
114 |
| |
|
115 |
TransA sg t = |
|
116 |
error("malformed automaton def for TransA:\n" ^ (Sign.string_of_term sg t)); |
|
117 |
||
118 |
fun delete_ul [] = [] |
|
119 |
| delete_ul (x::xs) = if (is_prefix (op =) ("\^["::"["::"4"::"m"::[]) (x::xs)) |
|
120 |
then (let val (_::_::_::s) = xs in delete_ul s end) |
|
121 |
else (if (is_prefix (op =) ("\^["::"["::"0"::"m"::[]) (x::xs)) |
|
122 |
then (let val (_::_::_::s) = xs in delete_ul s end) |
|
123 |
else (x::delete_ul xs)); |
|
124 |
||
125 |
fun delete_ul_string s = implode(delete_ul (explode s)); |
|
126 |
||
127 |
fun type_list_of sign (Type("*",a::b::_)) = (type_list_of sign a) @ (type_list_of sign b) | |
|
128 |
type_list_of sign a = [(Sign.string_of_typ sign a)]; |
|
129 |
||
130 |
fun structured_tuple l (Type("*",s::t::_)) = |
|
131 |
let |
|
132 |
val (r,str) = structured_tuple l s; |
|
133 |
in |
|
134 |
(fst(structured_tuple r t),"(" ^ str ^ "),(" ^ (snd(structured_tuple r t)) ^ ")") |
|
135 |
end | |
|
136 |
structured_tuple (a::r) t = (r,a) | |
|
137 |
structured_tuple [] _ = raise malformed; |
|
138 |
||
139 |
fun varlist_of _ _ [] = [] | |
|
140 |
varlist_of n s (a::r) = (s ^ (Int.toString(n))) :: (varlist_of (n+1) s r); |
|
141 |
||
142 |
fun string_of [] = "" | |
|
143 |
string_of (a::r) = a ^ " " ^ (string_of r); |
|
144 |
||
145 |
fun tupel_typed_of _ _ _ [] = "" | |
|
146 |
tupel_typed_of sign s n [a] = s ^ (Int.toString(n)) ^ "::" ^ a | |
|
147 |
tupel_typed_of sign s n (a::r) = |
|
148 |
s ^ (Int.toString(n)) ^ "::" ^ a ^ "," ^ (tupel_typed_of sign s (n+1) r); |
|
149 |
||
150 |
fun double_tupel_typed_of _ _ _ _ [] = "" | |
|
151 |
double_tupel_typed_of sign s t n [a] = |
|
152 |
s ^ (Int.toString(n)) ^ "::" ^ a ^ "," ^ |
|
153 |
t ^ (Int.toString(n)) ^ "::" ^ a | |
|
154 |
double_tupel_typed_of sign s t n (a::r) = |
|
155 |
s ^ (Int.toString(n)) ^ "::" ^ a ^ "," ^ |
|
156 |
t ^ (Int.toString(n)) ^ "::" ^ a ^ "," ^ (double_tupel_typed_of sign s t (n+1) r); |
|
157 |
||
158 |
fun tupel_of _ _ _ [] = "" | |
|
159 |
tupel_of sign s n [a] = s ^ (Int.toString(n)) | |
|
160 |
tupel_of sign s n (a::r) = s ^ (Int.toString(n)) ^ "," ^ (tupel_of sign s (n+1) r); |
|
161 |
||
162 |
fun double_tupel_of _ _ _ _ [] = "" | |
|
163 |
double_tupel_of sign s t n [a] = s ^ (Int.toString(n)) ^ "," ^ |
|
164 |
t ^ (Int.toString(n)) | |
|
165 |
double_tupel_of sign s t n (a::r) = s ^ (Int.toString(n)) ^ "," ^ |
|
166 |
t ^ (Int.toString(n)) ^ "," ^ (double_tupel_of sign s t (n+1) r); |
|
167 |
||
168 |
fun eq_string _ _ _ [] = "" | |
|
169 |
eq_string s t n [a] = s ^ (Int.toString(n)) ^ " = " ^ |
|
170 |
t ^ (Int.toString(n)) | |
|
171 |
eq_string s t n (a::r) = |
|
172 |
s ^ (Int.toString(n)) ^ " = " ^ |
|
173 |
t ^ (Int.toString(n)) ^ " & " ^ (eq_string s t (n+1) r); |
|
174 |
||
175 |
fun merge_var_and_type [] [] = "" | |
|
176 |
merge_var_and_type (a::r) (b::s) = "(" ^ a ^ " ::" ^ b ^ ") " ^ (merge_var_and_type r s) | |
|
177 |
merge_var_and_type _ _ = raise malformed; |
|
178 |
||
179 |
in |
|
180 |
||
181 |
fun mk_sim_oracle sign (subgoal, thl) = ( |
|
182 |
let |
|
183 |
val weak_case_congs = (map (#weak_case_cong o snd) o Symtab.dest o DatatypePackage.get_datatypes) sign; |
|
184 |
val concl = Logic.strip_imp_concl subgoal; |
|
185 |
val ic_str = delete_ul_string(Sign.string_of_term sign (IntC sign concl)); |
|
186 |
val ia_str = delete_ul_string(Sign.string_of_term sign (IntA sign concl)); |
|
187 |
val sc_str = delete_ul_string(Sign.string_of_term sign (StartC sign concl)); |
|
188 |
val sa_str = delete_ul_string(Sign.string_of_term sign (StartA sign concl)); |
|
189 |
val tc_str = delete_ul_string(Sign.string_of_term sign (TransC sign concl)); |
|
190 |
val ta_str = delete_ul_string(Sign.string_of_term sign (TransA sign concl)); |
|
191 |
||
192 |
val action_type_str = |
|
193 |
Sign.string_of_typ sign (element_type(#T (rep_cterm(cterm_of sign (IntA sign concl))))); |
|
194 |
||
195 |
val abs_state_type_list = |
|
196 |
type_list_of sign (element_type(#T (rep_cterm(cterm_of sign (StartA sign concl))))); |
|
197 |
val con_state_type_list = |
|
198 |
type_list_of sign (element_type(#T (rep_cterm(cterm_of sign (StartC sign concl))))); |
|
199 |
||
200 |
val tupel_eq = eq_string "s" "t" 0 abs_state_type_list; |
|
201 |
||
202 |
val abs_pre_tupel_typed = tupel_typed_of sign "s" 0 abs_state_type_list; |
|
203 |
val abs_s_t_tupel_typed = double_tupel_typed_of sign "s" "t" 0 abs_state_type_list; |
|
204 |
val con_pre_tupel_typed = tupel_typed_of sign "cs" 0 con_state_type_list; |
|
205 |
val con_s_t_tupel_typed = double_tupel_typed_of sign "cs" "ct" 0 con_state_type_list; |
|
206 |
||
207 |
val abs_pre_tupel = tupel_of sign "s" 0 abs_state_type_list; |
|
208 |
val abs_post_tupel = tupel_of sign "t" 0 abs_state_type_list; |
|
209 |
val abs_s_t_tupel = double_tupel_of sign "s" "t" 0 abs_state_type_list; |
|
210 |
val abs_s_u_tupel = double_tupel_of sign "s" "u" 0 abs_state_type_list; |
|
211 |
val abs_u_t_tupel = double_tupel_of sign "u" "t" 0 abs_state_type_list; |
|
212 |
val abs_u_v_tupel = double_tupel_of sign "u" "v" 0 abs_state_type_list; |
|
213 |
val abs_v_t_tupel = double_tupel_of sign "v" "t" 0 abs_state_type_list; |
|
214 |
val con_pre_tupel = tupel_of sign "cs" 0 con_state_type_list; |
|
215 |
val con_post_tupel = tupel_of sign "ct" 0 con_state_type_list; |
|
216 |
val con_s_t_tupel = double_tupel_of sign "cs" "ct" 0 con_state_type_list; |
|
217 |
||
218 |
val abs_pre_varlist = varlist_of 0 "s" abs_state_type_list; |
|
219 |
val abs_post_varlist = varlist_of 0 "t" abs_state_type_list; |
|
220 |
val abs_u_varlist = varlist_of 0 "u" abs_state_type_list; |
|
221 |
val abs_v_varlist = varlist_of 0 "v" abs_state_type_list; |
|
222 |
val con_pre_varlist = varlist_of 0 "cs" con_state_type_list; |
|
223 |
val con_post_varlist = varlist_of 0 "ct" con_state_type_list; |
|
224 |
||
225 |
val abs_post_str = string_of abs_post_varlist; |
|
226 |
val abs_u_str = string_of abs_u_varlist; |
|
227 |
val con_post_str = string_of con_post_varlist; |
|
228 |
||
229 |
val abs_pre_str_typed = merge_var_and_type abs_pre_varlist abs_state_type_list; |
|
230 |
val abs_u_str_typed = merge_var_and_type abs_u_varlist abs_state_type_list; |
|
231 |
val abs_v_str_typed = merge_var_and_type abs_v_varlist abs_state_type_list; |
|
232 |
val con_pre_str_typed = merge_var_and_type con_pre_varlist con_state_type_list; |
|
233 |
||
234 |
val abs_pre_tupel_struct = snd( |
|
235 |
structured_tuple abs_pre_varlist (element_type(#T(rep_cterm(cterm_of sign (StartA sign concl)))))); |
|
236 |
val abs_post_tupel_struct = snd( |
|
237 |
structured_tuple abs_post_varlist (element_type(#T(rep_cterm(cterm_of sign (StartA sign concl)))))); |
|
238 |
val con_pre_tupel_struct = snd( |
|
239 |
structured_tuple con_pre_varlist (element_type(#T(rep_cterm(cterm_of sign (StartC sign concl)))))); |
|
240 |
val con_post_tupel_struct = snd( |
|
241 |
structured_tuple con_post_varlist (element_type(#T(rep_cterm(cterm_of sign (StartC sign concl)))))); |
|
242 |
in |
|
243 |
( |
|
244 |
OldGoals.push_proof(); |
|
245 |
Goal |
|
246 |
( "(Internal_of_A = (% a::(" ^ action_type_str ^ "). a:(" ^ ia_str^ |
|
247 |
"))) --> (Internal_of_C = (% a::(" ^ action_type_str ^ "). a:(" ^ ic_str ^ |
|
248 |
"))) --> (Start_of_A = (% (" ^ abs_pre_tupel_typed ^ |
|
249 |
"). (" ^ abs_pre_tupel_struct ^ "):(" ^ sa_str ^ |
|
250 |
"))) --> (Start_of_C = (% (" ^ con_pre_tupel_typed ^ |
|
251 |
"). (" ^ con_pre_tupel_struct ^ "):(" ^ sc_str ^ |
|
252 |
"))) --> (Trans_of_A = (% (" ^ abs_s_t_tupel_typed ^ ") (a::(" ^ action_type_str ^ |
|
253 |
")). ((" ^ abs_pre_tupel_struct ^ "),a,(" ^ abs_post_tupel_struct ^ ")):(" ^ ta_str ^ |
|
254 |
"))) --> (Trans_of_C = (% (" ^ con_s_t_tupel_typed ^ ") (a::(" ^ action_type_str ^ |
|
255 |
")). ((" ^ con_pre_tupel_struct ^ "),a,(" ^ con_post_tupel_struct ^ ")):(" ^ tc_str ^ |
|
256 |
"))) --> (IntStep_of_A = (% (" ^ abs_s_t_tupel_typed ^ |
|
257 |
"). ? (a::(" ^ action_type_str ^ |
|
258 |
")). Internal_of_A a & Trans_of_A (" ^ abs_s_t_tupel ^ ") a" ^ |
|
259 |
")) --> (IntStepStar_of_A = mu (% P (" ^ abs_s_t_tupel_typed ^ |
|
260 |
"). (" ^ tupel_eq ^ ") | (? " ^ abs_u_str ^ ". IntStep_of_A (" ^ abs_s_u_tupel ^ |
|
261 |
") & P(" ^ abs_u_t_tupel ^ ")))" ^ |
|
262 |
") --> (Move_of_A = (% (" ^ abs_s_t_tupel_typed ^ ") (a::(" ^ action_type_str ^ |
|
263 |
")). (Internal_of_C a & IntStepStar_of_A(" ^ abs_s_t_tupel ^ |
|
264 |
")) | (? " ^ abs_u_str_typed ^ ". ? " ^ abs_v_str_typed ^ |
|
265 |
". IntStepStar_of_A(" ^ abs_s_u_tupel ^ ") & " ^ |
|
266 |
"Trans_of_A (" ^ abs_u_v_tupel ^ ") a & IntStepStar_of_A(" ^ abs_v_t_tupel ^ "))" ^ |
|
267 |
")) --> (isSimCA = nu (% P (" ^ con_pre_tupel_typed ^ "," ^ abs_pre_tupel_typed ^ |
|
268 |
"). (! (a::(" ^ action_type_str ^ ")) " ^ con_post_str ^ |
|
269 |
". Trans_of_C (" ^ con_s_t_tupel ^ ") a -->" ^ " (? " ^ abs_post_str ^ |
|
270 |
". Move_of_A (" ^ abs_s_t_tupel ^ ") a & P(" ^ con_post_tupel ^ "," ^ abs_post_tupel ^ "))))" ^ |
|
271 |
") --> (! " ^ con_pre_str_typed ^ ". ! " ^ abs_pre_str_typed ^ |
|
272 |
". (Start_of_C (" ^ con_pre_tupel ^ ") & Start_of_A (" ^ abs_pre_tupel ^ |
|
273 |
")) --> isSimCA(" ^ con_pre_tupel ^ "," ^ abs_pre_tupel ^ "))"); |
|
274 |
by (REPEAT (rtac impI 1)); |
|
275 |
by (REPEAT (dtac eq_reflection 1)); |
|
276 |
(* Bis hierher wird im Kapitel 4 erl"autert, ab hier im Kapitel 5 *) |
|
277 |
by (full_simp_tac ((simpset() delcongs (if_weak_cong :: weak_case_congs) |
|
278 |
delsimps [not_iff,split_part]) |
|
279 |
addsimps (thl @ comp_simps @ restrict_simps @ hide_simps @ |
|
280 |
rename_simps @ ioa_simps @ asig_simps)) 1); |
|
281 |
by (full_simp_tac |
|
282 |
(Mucke_ss delcongs (if_weak_cong :: weak_case_congs) delsimps [not_iff,split_part]) 1); |
|
283 |
by (REPEAT (if_full_simp_tac |
|
284 |
(simpset() delcongs (if_weak_cong :: weak_case_congs) delsimps [not_iff,split_part]) 1)); |
|
285 |
by (call_mucke_tac 1); |
|
286 |
(* Bis hierher wird im Kapitel 5 erl"autert, ab hier wieder im Kapitel 4 *) |
|
287 |
by (atac 1); |
|
288 |
result(); |
|
289 |
OldGoals.pop_proof(); |
|
290 |
Logic.strip_imp_concl subgoal |
|
291 |
) |
|
292 |
end) |
|
293 |
handle malformed => |
|
294 |
error("No suitable match to IOA types in " ^ (Sign.string_of_term sign subgoal)); |
|
295 |
||
296 |
end |
|
297 |
||
298 |
*} |
|
299 |
||
300 |
end |