src/HOLCF/IOA/meta_theory/ioa_package.ML
author mueller
Thu Apr 22 11:00:30 1999 +0200 (1999-04-22)
changeset 6467 863834a37769
child 6508 b8a1e395edd7
permissions -rw-r--r--
added frontend syntax for IOA, moved trivial examples to folder ex;
mueller@6467
     1
(*  Title:      ioa_package.ML
mueller@6467
     2
    ID:         $Id$
mueller@6467
     3
*)
mueller@6467
     4
mueller@6467
     5
signature IOA_PACKAGE =
mueller@6467
     6
sig
mueller@6467
     7
  val add_ioa: string -> string ->
mueller@6467
     8
		 (string) list -> (string) list -> (string) list ->
mueller@6467
     9
		(string * string) list -> string ->
mueller@6467
    10
		(string * string * (string * string)list) list
mueller@6467
    11
	-> theory -> theory
mueller@6467
    12
 val add_ioa_i : string -> string ->
mueller@6467
    13
                 (string) list -> (string) list -> (string) list ->
mueller@6467
    14
                (string * string) list -> string ->
mueller@6467
    15
                (string * string * (string * string)list) list
mueller@6467
    16
	-> theory -> theory
mueller@6467
    17
 val add_composition : string -> (string)list -> theory -> theory
mueller@6467
    18
 val add_composition_i : string -> (string)list -> theory -> theory
mueller@6467
    19
 val add_hiding : string -> string -> (string)list -> theory -> theory
mueller@6467
    20
 val add_hiding_i : string -> string -> (string)list -> theory -> theory
mueller@6467
    21
 val add_restriction : string -> string -> (string)list -> theory -> theory
mueller@6467
    22
 val add_restriction_i : string -> string -> (string)list -> theory -> theory
mueller@6467
    23
 val add_rename : string -> string -> string -> theory -> theory
mueller@6467
    24
 val add_rename_i : string -> string -> string -> theory -> theory
mueller@6467
    25
end;
mueller@6467
    26
mueller@6467
    27
structure IoaPackage(* FIXME : IOA_PACKAGE *) =
mueller@6467
    28
struct
mueller@6467
    29
mueller@6467
    30
local
mueller@6467
    31
mueller@6467
    32
exception malformed;
mueller@6467
    33
mueller@6467
    34
(* for usage of hidden function no_attributes of structure Thm : *)
mueller@6467
    35
fun no_attributes x = (x, []);
mueller@6467
    36
mueller@6467
    37
(* stripping quotes *)
mueller@6467
    38
fun strip [] = [] |
mueller@6467
    39
strip ("\""::r) = strip r |
mueller@6467
    40
strip (a::r) = a :: (strip r);
mueller@6467
    41
fun strip_quote s = implode(strip(explode(s)));
mueller@6467
    42
mueller@6467
    43
(* used by *_of_varlist *)
mueller@6467
    44
fun extract_first (a,b) = strip_quote a;
mueller@6467
    45
fun extract_second (a,b) = strip_quote b;
mueller@6467
    46
(* following functions producing sth from a varlist *)
mueller@6467
    47
fun comma_list_of_varlist [] = "" |
mueller@6467
    48
comma_list_of_varlist [a] = extract_first a |
mueller@6467
    49
comma_list_of_varlist (a::r) = (extract_first a) ^ "," ^ (comma_list_of_varlist r);
mueller@6467
    50
fun primed_comma_list_of_varlist [] = "" |
mueller@6467
    51
primed_comma_list_of_varlist [a] = (extract_first a) ^ "'" |
mueller@6467
    52
primed_comma_list_of_varlist (a::r) = (extract_first a) ^ "'," ^
mueller@6467
    53
 (primed_comma_list_of_varlist r);
mueller@6467
    54
fun type_product_of_varlist [] = "" |
mueller@6467
    55
type_product_of_varlist [a] = "(" ^ extract_second(a) ^ ")" |
mueller@6467
    56
type_product_of_varlist(a::r) = "(" ^ extract_second(a) ^ ")*" ^ type_product_of_varlist r;
mueller@6467
    57
mueller@6467
    58
(* listing a list *)
mueller@6467
    59
fun list_elements_of [] = "" |
mueller@6467
    60
list_elements_of (a::r) = a ^ " " ^ (list_elements_of r);
mueller@6467
    61
mueller@6467
    62
(* extracting type parameters from a type list *)
mueller@6467
    63
(* fun param_tupel thy [] res = res |
mueller@6467
    64
param_tupel thy ((Type(_,l))::r) res = param_tupel thy (l @ r) res |
mueller@6467
    65
param_tupel thy ((TFree(a,_))::r) res = 
mueller@6467
    66
if (a mem res) then (param_tupel thy r res) else (param_tupel thy r (a::res)) |
mueller@6467
    67
param_tupel thy (a::r) res =
mueller@6467
    68
error ("one component of a statetype is a TVar: " ^ (Sign.string_of_typ (sign_of thy) a));
mueller@6467
    69
*)
mueller@6467
    70
mueller@6467
    71
(* used by constr_list *)
mueller@6467
    72
fun extract_constrs thy [] = [] |
mueller@6467
    73
extract_constrs thy (a::r) =
mueller@6467
    74
let
mueller@6467
    75
fun is_prefix [] s = true
mueller@6467
    76
| is_prefix (p::ps) [] = false
mueller@6467
    77
| is_prefix (p::ps) (x::xs) = (p=x) andalso (is_prefix ps xs);
mueller@6467
    78
fun delete_bold [] = []
mueller@6467
    79
| delete_bold (x::xs) = if (is_prefix ("\^["::"["::"1"::"m"::[]) (x::xs))
mueller@6467
    80
        then (let val (_::_::_::s) = xs in delete_bold s end)
mueller@6467
    81
        else (if (is_prefix ("\^["::"["::"0"::"m"::[]) (x::xs))
mueller@6467
    82
                then  (let val (_::_::_::s) = xs in delete_bold s end)
mueller@6467
    83
                else (x::delete_bold xs));
mueller@6467
    84
fun delete_bold_string s = implode(delete_bold(explode s));
mueller@6467
    85
(* from a constructor term in *.induct (with quantifiers,
mueller@6467
    86
"Trueprop" and ?P stripped away) delivers the head *)
mueller@6467
    87
fun extract_hd (_ $ Abs(_,_,r)) = extract_hd r |
mueller@6467
    88
extract_hd (Const("Trueprop",_) $ r) = extract_hd r |
mueller@6467
    89
extract_hd (Var(_,_) $ r) = extract_hd r |
mueller@6467
    90
extract_hd (a $ b) = extract_hd a |
mueller@6467
    91
extract_hd (Const(s,_)) = s |
mueller@6467
    92
extract_hd _ = raise malformed;
mueller@6467
    93
(* delivers constructor term string from a prem of *.induct *)
mueller@6467
    94
fun extract_constr thy (_ $ Abs(a,T,r)) = extract_constr thy (snd(variant_abs(a,T,r)))|
mueller@6467
    95
extract_constr thy (Const("Trueprop",_) $ r) = extract_constr thy r |
mueller@6467
    96
extract_constr thy (Var(_,_) $ r) =  delete_bold_string(Sign.string_of_term (sign_of thy) r) |
mueller@6467
    97
extract_constr _ _ = raise malformed;
mueller@6467
    98
in
mueller@6467
    99
(extract_hd a,extract_constr thy a) :: (extract_constrs thy r)
mueller@6467
   100
end;
mueller@6467
   101
mueller@6467
   102
(* delivering list of constructor terms of a datatype *)
mueller@6467
   103
fun constr_list thy atyp =
mueller@6467
   104
let
mueller@6467
   105
fun act_name thy (Type(s,_)) = s |
mueller@6467
   106
act_name _ s = 
mueller@6467
   107
error("malformed action type: " ^ (Sign.string_of_typ (sign_of thy) s));
mueller@6467
   108
fun afpl ("." :: a) = [] |
mueller@6467
   109
afpl [] = [] |
mueller@6467
   110
afpl (a::r) = a :: (afpl r);
mueller@6467
   111
fun unqualify s = implode(rev(afpl(rev(explode s))));
mueller@6467
   112
val q_atypstr = act_name thy atyp;
mueller@6467
   113
val uq_atypstr = unqualify q_atypstr;
mueller@6467
   114
val prem = prems_of (get_thm thy (uq_atypstr ^ ".induct"));
mueller@6467
   115
in
mueller@6467
   116
extract_constrs thy prem
mueller@6467
   117
handle malformed =>
mueller@6467
   118
error("malformed theorem : " ^ uq_atypstr ^ ".induct")
mueller@6467
   119
end;
mueller@6467
   120
mueller@6467
   121
fun check_for_constr thy atyp (a $ b) =
mueller@6467
   122
let
mueller@6467
   123
fun all_free (Free(_,_)) = true |
mueller@6467
   124
all_free (a $ b) = if (all_free a) then (all_free b) else false |
mueller@6467
   125
all_free _ = false; 
mueller@6467
   126
in 
mueller@6467
   127
if (all_free b) then (check_for_constr thy atyp a) else false
mueller@6467
   128
end |
mueller@6467
   129
check_for_constr thy atyp (Const(a,_)) =
mueller@6467
   130
let
mueller@6467
   131
val cl = constr_list thy atyp;
mueller@6467
   132
fun fstmem a [] = false |
mueller@6467
   133
fstmem a ((f,s)::r) = if (a=f) then true else (fstmem a r)
mueller@6467
   134
in
mueller@6467
   135
if (fstmem a cl) then true else false
mueller@6467
   136
end |
mueller@6467
   137
check_for_constr _ _ _ = false;
mueller@6467
   138
mueller@6467
   139
(* delivering the free variables of a constructor term *)
mueller@6467
   140
fun free_vars_of (t1 $ t2) = (free_vars_of t1) @ (free_vars_of t2) |
mueller@6467
   141
free_vars_of (Const(_,_)) = [] |
mueller@6467
   142
free_vars_of (Free(a,_)) = [a] |
mueller@6467
   143
free_vars_of _ = raise malformed;
mueller@6467
   144
mueller@6467
   145
(* making a constructor set from a constructor term (of signature) *)
mueller@6467
   146
fun constr_set_string thy atyp ctstr =
mueller@6467
   147
let
mueller@6467
   148
val trm = #t(rep_cterm(read_cterm (sign_of thy) (ctstr,atyp)));
mueller@6467
   149
val l = free_vars_of trm
mueller@6467
   150
in
mueller@6467
   151
if (check_for_constr thy atyp trm) then
mueller@6467
   152
(if (l=[]) then ("{" ^ ctstr ^ "}")
mueller@6467
   153
else "(UN " ^ (list_elements_of l) ^ ". {" ^ ctstr ^ "})")
mueller@6467
   154
else (raise malformed) 
mueller@6467
   155
handle malformed => 
mueller@6467
   156
error("malformed action term: " ^ (Sign.string_of_term (sign_of thy) trm))
mueller@6467
   157
end;
mueller@6467
   158
mueller@6467
   159
(* extracting constructor heads *)
mueller@6467
   160
fun constructor_head thy atypstr s =
mueller@6467
   161
let
mueller@6467
   162
fun hd_of (Const(a,_)) = a |
mueller@6467
   163
hd_of (t $ _) = hd_of t |
mueller@6467
   164
hd_of _ = raise malformed;
mueller@6467
   165
val trm = #t(rep_cterm(read_cterm (sign_of thy) (s,#T(rep_ctyp(read_ctyp (sign_of thy) atypstr))) ))
mueller@6467
   166
in
mueller@6467
   167
hd_of trm handle malformed =>
mueller@6467
   168
error("malformed constructor of datatype " ^ atypstr ^ ": " ^ s)
mueller@6467
   169
end;
mueller@6467
   170
fun constructor_head_list _ _ [] = [] |
mueller@6467
   171
constructor_head_list thy atypstr (a::r) =
mueller@6467
   172
 (constructor_head thy atypstr a)::(constructor_head_list thy atypstr r);
mueller@6467
   173
mueller@6467
   174
(* producing an action set *)
mueller@6467
   175
fun action_set_string thy atyp [] = "{}" |
mueller@6467
   176
action_set_string thy atyp [a] = constr_set_string thy atyp (strip_quote a) |
mueller@6467
   177
action_set_string thy atyp (a::r) = (constr_set_string thy atyp (strip_quote a)) ^
mueller@6467
   178
         " Un " ^ (action_set_string thy atyp r);
mueller@6467
   179
mueller@6467
   180
(* used by extend *)
mueller@6467
   181
fun pstr s [] = "(" ^ s ^ "' = " ^ s ^ ")" |
mueller@6467
   182
pstr s ((a,b)::r) =
mueller@6467
   183
if (s=a) then ("(" ^ s ^ "' = (" ^ b ^ "))") else (pstr s r);
mueller@6467
   184
fun poststring [] l = "" |
mueller@6467
   185
poststring [(a,b)] l = pstr a l |
mueller@6467
   186
poststring ((a,b)::r) l = (pstr a l) ^ " & " ^ (poststring r l);
mueller@6467
   187
mueller@6467
   188
(* extends a (action string,condition,assignlist) tupel by a
mueller@6467
   189
(action term,action string,condition,pseudo_condition,bool) tupel, used by extended_list 
mueller@6467
   190
(where bool indicates whether there is a precondition *)
mueller@6467
   191
fun extend thy atyp statetupel (actstr,r,[]) =
mueller@6467
   192
let
mueller@6467
   193
val trm = #t(rep_cterm(read_cterm (sign_of thy) (actstr,atyp)));
mueller@6467
   194
val rtrm = #t(rep_cterm(read_cterm (sign_of thy) (r,Type("bool",[]))));
mueller@6467
   195
val flag = if (rtrm=Const("True",Type("bool",[]))) then false else true
mueller@6467
   196
in
mueller@6467
   197
if (check_for_constr thy atyp trm)
mueller@6467
   198
then (trm,actstr, "(" ^ r ^ ") & " ^ (poststring statetupel []),r,flag)
mueller@6467
   199
else
mueller@6467
   200
error("transition " ^ actstr ^ " is not a pure constructor term")
mueller@6467
   201
end |
mueller@6467
   202
extend thy atyp statetupel (actstr,r,(a,b)::c) =
mueller@6467
   203
let
mueller@6467
   204
fun pseudo_poststring [] = "" |
mueller@6467
   205
pseudo_poststring ((a,b)::[]) = "(" ^ a ^ " = (" ^ b ^ "))" |
mueller@6467
   206
pseudo_poststring ((a,b)::r) = "(" ^ a ^ " = (" ^ b ^ ")) & " ^ (pseudo_poststring r); 
mueller@6467
   207
val trm = #t(rep_cterm(read_cterm (sign_of thy) (actstr,atyp)));
mueller@6467
   208
val rtrm = #t(rep_cterm(read_cterm (sign_of thy) (r,Type("bool",[]))));
mueller@6467
   209
val flag = if (rtrm=Const("True",Type("bool",[]))) then false else true
mueller@6467
   210
in
mueller@6467
   211
if (check_for_constr thy atyp trm) then
mueller@6467
   212
(if ((a="") andalso (b="") andalso (c=[])) then (trm,actstr,r,"True",false)
mueller@6467
   213
(* the case with transrel *)
mueller@6467
   214
 else 
mueller@6467
   215
 (trm,actstr,"(" ^ r ^ ") & " ^ (poststring statetupel ((a,b)::c)),
mueller@6467
   216
	"(" ^ r ^ ") & " ^ (pseudo_poststring ((a,b)::c)),flag))
mueller@6467
   217
else
mueller@6467
   218
error("transition " ^ actstr ^ " is not a pure constructor term")
mueller@6467
   219
end;
mueller@6467
   220
(* used by make_alt_string *) 
mueller@6467
   221
fun extended_list _ _ _ [] = [] |
mueller@6467
   222
extended_list thy atyp statetupel (a::r) =
mueller@6467
   223
	 (extend thy atyp statetupel a) :: (extended_list thy atyp statetupel r);
mueller@6467
   224
mueller@6467
   225
(* used by write_alts *)
mueller@6467
   226
fun write_alt thy (chead,tr) inp out int [] =
mueller@6467
   227
if (chead mem inp) then
mueller@6467
   228
(
mueller@6467
   229
error("Input action " ^ tr ^ " was not specified")
mueller@6467
   230
) else (
mueller@6467
   231
if (chead mem (out@int)) then
mueller@6467
   232
(writeln("Action " ^ tr ^ " was completedly disabled due to missing specification")) else print("");
mueller@6467
   233
(tr ^ " => False",tr ^ " => False")) |
mueller@6467
   234
write_alt thy (chead,ctrm) inp out int ((a,b,c,d,e)::r) =
mueller@6467
   235
let
mueller@6467
   236
fun hd_of (Const(a,_)) = a |
mueller@6467
   237
hd_of (t $ _) = hd_of t |
mueller@6467
   238
hd_of _ = raise malformed;
mueller@6467
   239
fun occurs_again c [] = false |
mueller@6467
   240
occurs_again c ((a,_,_,_,_)::r) = if (c=(hd_of a)) then true else (occurs_again c r);
mueller@6467
   241
in
mueller@6467
   242
if (chead=(hd_of a)) then 
mueller@6467
   243
(if ((chead mem inp) andalso e) then (
mueller@6467
   244
error("Input action " ^ b ^ " has a precondition")
mueller@6467
   245
) else (if (chead mem (inp@out@int)) then 
mueller@6467
   246
		(if (occurs_again chead r) then (
mueller@6467
   247
error("Two specifications for action: " ^ b)
mueller@6467
   248
		) else (b ^ " => " ^ c,b ^ " => " ^ d))
mueller@6467
   249
	else (
mueller@6467
   250
error("Action " ^ b ^ " is not in automaton signature")
mueller@6467
   251
))) else (write_alt thy (chead,ctrm) inp out int r)
mueller@6467
   252
handle malformed =>
mueller@6467
   253
error ("malformed action term: " ^ (Sign.string_of_term (sign_of thy) a))
mueller@6467
   254
end;
mueller@6467
   255
mueller@6467
   256
(* used by make_alt_string *)
mueller@6467
   257
fun write_alts thy (a,b) inp out int [] ttr = (a,b) |
mueller@6467
   258
write_alts thy (a,b) inp out int [c] ttr =
mueller@6467
   259
let
mueller@6467
   260
val wa = write_alt thy c inp out int ttr
mueller@6467
   261
in
mueller@6467
   262
 (a ^ (fst wa),b ^ (snd wa))
mueller@6467
   263
end |
mueller@6467
   264
write_alts thy (a,b) inp out int (c::r) ttr =
mueller@6467
   265
let
mueller@6467
   266
val wa = write_alt thy c inp out int ttr
mueller@6467
   267
in
mueller@6467
   268
 write_alts thy (a ^ (fst wa) ^ " | ", b ^ (snd wa) ^ " | ") inp out int r ttr
mueller@6467
   269
end;
mueller@6467
   270
mueller@6467
   271
fun make_alt_string thy inp out int atyp statetupel trans =
mueller@6467
   272
let
mueller@6467
   273
val cl = constr_list thy atyp;
mueller@6467
   274
val ttr = extended_list thy atyp statetupel trans;
mueller@6467
   275
in
mueller@6467
   276
write_alts thy ("","") inp out int cl ttr
mueller@6467
   277
end;
mueller@6467
   278
mueller@6467
   279
(* used in gen_add_ioa *)
mueller@6467
   280
fun check_free_primed (Free(a,_)) = 
mueller@6467
   281
let
mueller@6467
   282
val (f::r) = rev(explode a)
mueller@6467
   283
in
mueller@6467
   284
if (f="'") then [a] else []
mueller@6467
   285
end | 
mueller@6467
   286
check_free_primed (a $ b) = ((check_free_primed a) @ (check_free_primed b)) |
mueller@6467
   287
check_free_primed (Abs(_,_,t)) = check_free_primed t |
mueller@6467
   288
check_free_primed _ = [];
mueller@6467
   289
mueller@6467
   290
fun overlap [] _ = true |
mueller@6467
   291
overlap (a::r) l = if (a mem l) then (
mueller@6467
   292
error("Two occurences of action " ^ a ^ " in automaton signature")
mueller@6467
   293
) else (overlap r l);
mueller@6467
   294
mueller@6467
   295
(* delivering some types of an automaton *)
mueller@6467
   296
fun aut_type_of thy aut_name =
mueller@6467
   297
let
mueller@6467
   298
fun left_of (( _ $ left) $ _) = left |
mueller@6467
   299
left_of _ = raise malformed;
mueller@6467
   300
val aut_def = concl_of(get_thm thy (aut_name ^ "_def"));
mueller@6467
   301
in
mueller@6467
   302
(#T(rep_cterm(cterm_of (sign_of thy) (left_of aut_def))))
mueller@6467
   303
handle malformed => error ("malformed_theorem : " ^ aut_name ^ "_def")
mueller@6467
   304
end;
mueller@6467
   305
mueller@6467
   306
fun act_type_of thy (Type(pair1,(Type(pair_asig,(Type(actionset,[acttyp])::_))::_))) = acttyp |
mueller@6467
   307
act_type_of thy t = error ("could not extract action type of following automaton type:\n" ^
mueller@6467
   308
(Sign.string_of_typ (sign_of thy) t));
mueller@6467
   309
fun st_type_of thy (Type(pair1,_::(Type(pair2,Type(initial_set,[statetyp])::_))::_)) = statetyp |
mueller@6467
   310
st_type_of thy t = error ("could not extract state type of following automaton type:\n" ^
mueller@6467
   311
(Sign.string_of_typ (sign_of thy) t));
mueller@6467
   312
mueller@6467
   313
fun comp_st_type_of thy [a] = st_type_of thy (aut_type_of thy a) |
mueller@6467
   314
comp_st_type_of thy (a::r) = Type("*",[st_type_of thy (aut_type_of thy a), comp_st_type_of thy r]) |
mueller@6467
   315
comp_st_type_of _ _ = error "empty automaton list";
mueller@6467
   316
mueller@6467
   317
(* checking consistency of action types (for composition) *)
mueller@6467
   318
fun check_ac thy (a::r) =
mueller@6467
   319
let
mueller@6467
   320
fun ch_f_a thy acttyp [] = acttyp |
mueller@6467
   321
ch_f_a thy acttyp (a::r) =
mueller@6467
   322
let
mueller@6467
   323
val auttyp = aut_type_of thy a;
mueller@6467
   324
val ac = (act_type_of thy auttyp);
mueller@6467
   325
in
mueller@6467
   326
if (ac=acttyp) then (ch_f_a thy acttyp r) else (error "A")
mueller@6467
   327
end;
mueller@6467
   328
val auttyp = aut_type_of thy a;
mueller@6467
   329
val acttyp = (act_type_of thy auttyp);
mueller@6467
   330
in
mueller@6467
   331
ch_f_a thy acttyp r
mueller@6467
   332
end |
mueller@6467
   333
check_ac _ [] = error "empty automaton list";
mueller@6467
   334
mueller@6467
   335
fun clist [] = "" |
mueller@6467
   336
clist [a] = a |
mueller@6467
   337
clist (a::r) = a ^ " || " ^ (clist r);
mueller@6467
   338
mueller@6467
   339
(* gen_add_ioa *)
mueller@6467
   340
mueller@6467
   341
fun gen_add_ioa prep_term automaton_name action_type inp out int statetupel ini trans thy =
mueller@6467
   342
(writeln("Constructing automaton " ^ automaton_name ^ "...");
mueller@6467
   343
let
mueller@6467
   344
val state_type_string = type_product_of_varlist(statetupel);
mueller@6467
   345
val styp = #T(rep_ctyp (read_ctyp (sign_of thy) state_type_string)) ;
mueller@6467
   346
val state_vars_tupel = "(" ^ (comma_list_of_varlist statetupel) ^ ")";
mueller@6467
   347
val state_vars_primed = "(" ^ (primed_comma_list_of_varlist statetupel) ^ ")";
mueller@6467
   348
val atyp = #T(rep_ctyp (read_ctyp (sign_of thy) action_type));
mueller@6467
   349
val inp_set_string = action_set_string thy atyp inp;
mueller@6467
   350
val out_set_string = action_set_string thy atyp out;
mueller@6467
   351
val int_set_string = action_set_string thy atyp int;
mueller@6467
   352
val inp_head_list = constructor_head_list thy action_type inp;
mueller@6467
   353
val out_head_list = constructor_head_list thy action_type out;
mueller@6467
   354
val int_head_list = constructor_head_list thy action_type int;
mueller@6467
   355
val overlap_flag = ((overlap inp out) andalso (overlap inp int) andalso (overlap out int)); 
mueller@6467
   356
val alt_string = make_alt_string thy inp_head_list out_head_list int_head_list 
mueller@6467
   357
							atyp statetupel trans;
mueller@6467
   358
val thy2 = (thy
mueller@6467
   359
|> ContConsts.add_consts
mueller@6467
   360
[(automaton_name ^ "_initial", "(" ^ state_type_string ^ ")set" ,NoSyn),
mueller@6467
   361
(automaton_name ^ "_asig", "(" ^ action_type ^ ")signature" ,NoSyn),
mueller@6467
   362
(automaton_name ^ "_trans",
mueller@6467
   363
 "(" ^ action_type ^ "," ^ state_type_string ^ ")transition set" ,NoSyn),
mueller@6467
   364
(automaton_name, "(" ^ action_type ^ "," ^ state_type_string ^ ")ioa" ,NoSyn)]
mueller@6467
   365
|> (PureThy.add_defs o map no_attributes) (* old: Attributes.none *)
mueller@6467
   366
[(automaton_name ^ "_initial_def",
mueller@6467
   367
automaton_name ^ "_initial == {" ^ state_vars_tupel ^ "." ^ ini ^ "}"),
mueller@6467
   368
(automaton_name ^ "_asig_def",
mueller@6467
   369
automaton_name ^ "_asig == (" ^
mueller@6467
   370
 inp_set_string ^ "," ^ out_set_string ^ "," ^ int_set_string ^ ")"),
mueller@6467
   371
(automaton_name ^ "_trans_def",
mueller@6467
   372
automaton_name ^ "_trans == {(" ^
mueller@6467
   373
 state_vars_tupel ^ ", act_of_" ^ automaton_name ^ ", " ^ state_vars_primed ^
mueller@6467
   374
"). case act_of_" ^ automaton_name ^ " of " ^ fst(alt_string) ^ "}"),
mueller@6467
   375
(automaton_name ^ "_def",
mueller@6467
   376
automaton_name ^ " == (" ^ automaton_name ^ "_asig, " ^ automaton_name ^
mueller@6467
   377
"_initial, " ^ automaton_name ^ "_trans,{},{})")
mueller@6467
   378
])
mueller@6467
   379
val chk_prime_list = (check_free_primed (#t(rep_cterm(read_cterm (sign_of thy2)
mueller@6467
   380
( "case act_of_" ^ automaton_name ^ " of " ^ snd(alt_string),Type("bool",[]))))));
mueller@6467
   381
in
mueller@6467
   382
(
mueller@6467
   383
if (chk_prime_list = []) then thy2
mueller@6467
   384
else (
mueller@6467
   385
error("Precondition or assignment terms in postconditions contain following primed variables:\n"
mueller@6467
   386
 ^ (list_elements_of chk_prime_list)))
mueller@6467
   387
)
mueller@6467
   388
end)
mueller@6467
   389
mueller@6467
   390
fun gen_add_composition prep_term automaton_name aut_list thy =
mueller@6467
   391
(writeln("Constructing automaton " ^ automaton_name ^ "...");
mueller@6467
   392
let
mueller@6467
   393
val acttyp = check_ac thy aut_list; 
mueller@6467
   394
val st_typ = comp_st_type_of thy aut_list; 
mueller@6467
   395
val comp_list = clist aut_list;
mueller@6467
   396
in
mueller@6467
   397
thy
mueller@6467
   398
|> ContConsts.add_consts_i
mueller@6467
   399
[(automaton_name,
mueller@6467
   400
Type("*",
mueller@6467
   401
[Type("*",[Type("set",[acttyp]),Type("*",[Type("set",[acttyp]),Type("set",[acttyp])])]),
mueller@6467
   402
 Type("*",[Type("set",[st_typ]),
mueller@6467
   403
  Type("*",[Type("set",[Type("*",[st_typ,Type("*",[acttyp,st_typ])])]),
mueller@6467
   404
   Type("*",[Type("set",[Type("set",[acttyp])]),Type("set",[Type("set",[acttyp])])])])])])
mueller@6467
   405
,NoSyn)]
mueller@6467
   406
|> (PureThy.add_defs o map no_attributes)
mueller@6467
   407
[(automaton_name ^ "_def",
mueller@6467
   408
automaton_name ^ " == " ^ comp_list)]
mueller@6467
   409
end)
mueller@6467
   410
mueller@6467
   411
fun gen_add_restriction prep_term automaton_name aut_source actlist thy =
mueller@6467
   412
(writeln("Constructing automaton " ^ automaton_name ^ "...");
mueller@6467
   413
let
mueller@6467
   414
val auttyp = aut_type_of thy aut_source;
mueller@6467
   415
val acttyp = act_type_of thy auttyp; 
mueller@6467
   416
val rest_set = action_set_string thy acttyp actlist
mueller@6467
   417
in
mueller@6467
   418
thy
mueller@6467
   419
|> ContConsts.add_consts_i
mueller@6467
   420
[(automaton_name, auttyp,NoSyn)]
mueller@6467
   421
|> (PureThy.add_defs o map no_attributes)
mueller@6467
   422
[(automaton_name ^ "_def",
mueller@6467
   423
automaton_name ^ " == restrict " ^ aut_source ^ " " ^ rest_set)] 
mueller@6467
   424
end)
mueller@6467
   425
fun gen_add_hiding prep_term automaton_name aut_source actlist thy =
mueller@6467
   426
(writeln("Constructing automaton " ^ automaton_name ^ "...");
mueller@6467
   427
let
mueller@6467
   428
val auttyp = aut_type_of thy aut_source;
mueller@6467
   429
val acttyp = act_type_of thy auttyp; 
mueller@6467
   430
val hid_set = action_set_string thy acttyp actlist
mueller@6467
   431
in
mueller@6467
   432
thy
mueller@6467
   433
|> ContConsts.add_consts_i
mueller@6467
   434
[(automaton_name, auttyp,NoSyn)]
mueller@6467
   435
|> (PureThy.add_defs o map no_attributes)
mueller@6467
   436
[(automaton_name ^ "_def",
mueller@6467
   437
automaton_name ^ " == hide " ^ aut_source ^ " " ^ hid_set)] 
mueller@6467
   438
end)
mueller@6467
   439
mueller@6467
   440
fun ren_act_type_of thy funct =
mueller@6467
   441
let
mueller@6467
   442
(* going into a pseudo-proof-state to enable the use of function read *)
mueller@6467
   443
val _ = goal thy (funct ^ " = t");
mueller@6467
   444
fun arg_typ_of (Type("fun",[a,b])) = a |
mueller@6467
   445
arg_typ_of _ = raise malformed;
mueller@6467
   446
in
mueller@6467
   447
arg_typ_of(#T(rep_cterm(cterm_of (sign_of thy) (read(funct)))))
mueller@6467
   448
handle malformed => error ("could not extract argument type of renaming function term")
mueller@6467
   449
end;
mueller@6467
   450
 
mueller@6467
   451
fun gen_add_rename prep_term automaton_name aut_source fun_name thy =
mueller@6467
   452
(writeln("Constructing automaton " ^ automaton_name ^ "...");
mueller@6467
   453
let
mueller@6467
   454
val auttyp = aut_type_of thy aut_source;
mueller@6467
   455
val st_typ = st_type_of thy auttyp;
mueller@6467
   456
val acttyp = ren_act_type_of thy fun_name
mueller@6467
   457
in
mueller@6467
   458
thy
mueller@6467
   459
|> ContConsts.add_consts_i
mueller@6467
   460
[(automaton_name,
mueller@6467
   461
Type("*",
mueller@6467
   462
[Type("*",[Type("set",[acttyp]),Type("*",[Type("set",[acttyp]),Type("set",[acttyp])])]),
mueller@6467
   463
 Type("*",[Type("set",[st_typ]),
mueller@6467
   464
  Type("*",[Type("set",[Type("*",[st_typ,Type("*",[acttyp,st_typ])])]),
mueller@6467
   465
   Type("*",[Type("set",[Type("set",[acttyp])]),Type("set",[Type("set",[acttyp])])])])])])
mueller@6467
   466
,NoSyn)]
mueller@6467
   467
|> (PureThy.add_defs o map no_attributes)
mueller@6467
   468
[(automaton_name ^ "_def",
mueller@6467
   469
automaton_name ^ " == rename " ^ aut_source ^ " (" ^ fun_name ^ ")")]
mueller@6467
   470
end)
mueller@6467
   471
mueller@6467
   472
(* external interfaces *)
mueller@6467
   473
mueller@6467
   474
fun read_term sg str =
mueller@6467
   475
  read_cterm sg (str, HOLogic.termTVar);
mueller@6467
   476
mueller@6467
   477
fun cert_term sg tm =
mueller@6467
   478
  cterm_of sg tm handle TERM (msg, _) => error msg;
mueller@6467
   479
mueller@6467
   480
in
mueller@6467
   481
mueller@6467
   482
val add_ioa = gen_add_ioa read_term;
mueller@6467
   483
val add_ioa_i = gen_add_ioa cert_term;
mueller@6467
   484
val add_composition = gen_add_composition read_term;
mueller@6467
   485
val add_composition_i = gen_add_composition cert_term;
mueller@6467
   486
val add_hiding = gen_add_hiding read_term;
mueller@6467
   487
val add_hiding_i = gen_add_hiding cert_term;
mueller@6467
   488
val add_restriction = gen_add_restriction read_term;
mueller@6467
   489
val add_restriction_i = gen_add_restriction cert_term;
mueller@6467
   490
val add_rename = gen_add_rename read_term;
mueller@6467
   491
val add_rename_i = gen_add_rename cert_term;
mueller@6467
   492
mueller@6467
   493
end
mueller@6467
   494
mueller@6467
   495
end;