1 (* Title: tools for 'modeling' und 'specifying' to be used in
2 modspec.sml. The types are separated into this file,
3 because some of them are stored in the calc-tree, and thus are required
5 TODO: allocate elements of Selem and of Stool appropriately
6 Author: Walther Neuper, Mathias Lehnfeld
7 (c) due to copyright terms
10 signature SPECIFY_TOOL =
12 val check_preconds : 'a -> Rule.rls -> term list -> Model.itm list -> (bool * term) list
13 val check_preconds' : Rule.rls -> term list -> Model.itm list -> 'a -> (bool * term) list
15 datatype match_ = Match_ of Celem.pblID * (Model.itm list * (bool * term) list) | NoMatch_
16 val refined_ : match_ list -> match_ option
17 datatype match = Matches of Celem.pblID * Model.item Model.ppc | NoMatch of Celem.pblID * Model.item Model.ppc
18 val matchs2str : match list -> string
19 val common_subthy : theory * theory -> theory
20 (* ---- for tests only: shifted from below to remove the Warning "unused" at fun.def. --------- *)
21 val pres2str : (bool * term) list -> string
22 val refined : match list -> Celem.pblID
23 (*/-------------------------------------------------------- ! aktivate for Test_Isac BEGIN ---\* )
25 ( *\--- ! aktivate for Test_Isac END ----------------------------------------------------------/*)
27 (*----- unused code, kept as hints to design ideas ---------------------------------------------*)
28 val pblID_of_match : match -> Celem.pblID
29 val refined_IDitms : match list -> match option
32 structure Stool(**) : SPECIFY_TOOL(**) =
36 Matches of Celem.pblID * Model.item Model.ppc
37 | NoMatch of Celem.pblID * Model.item Model.ppc;
38 fun match2str (Matches (pI, ppc)) = "Matches (" ^ strs2str pI ^ ", " ^ Model.itemppc2str ppc ^ ")"
39 | match2str (NoMatch (pI, ppc)) = "NoMatch (" ^ strs2str pI ^ ", " ^ Model.itemppc2str ppc ^ ")";
40 fun matchs2str ms = (strs2str o (map match2str)) ms;
41 fun pblID_of_match (Matches (pI, _)) = pI
42 | pblID_of_match (NoMatch (pI, _)) = pI;
44 (* 10.03 for Refine_Problem *)
46 Match_ of Celem.pblID * (( Model.itm list) * ((bool * term) list))
49 (* the refined pbt is the last_element Matches in the list *)
50 fun is_matches (Matches _) = true
51 | is_matches _ = false;
52 fun matches_pblID (Matches (pI, _)) = pI
53 | matches_pblID _ = error "matches_pblID: uncovered case in fun.def.";
54 fun refined ms = ((matches_pblID o the o (find_first is_matches) o rev) ms)
56 fun refined_IDitms ms = ((find_first is_matches) o rev) ms;
58 (* the refined pbt is the last_element Matches in the list, for Refine_Problem, tryrefine *)
59 fun is_matches_ (Match_ _) = true
60 | is_matches_ _ = false;
61 fun refined_ ms = ((find_first is_matches_) o rev) ms;
63 (* check a predicate labelled with indication of incomplete substitution;
64 rls -> (* for eval_true *)
65 bool * (* have _all_ variables(Free) from the model-pattern
66 been substituted by a value from the pattern's environment ?*)
67 term -> (* the precondition *)
68 bool * (* has the precondition evaluated to true *)
69 term (* the precondition (for map) *)
71 fun evalprecond _ (false, pre) =
72 (*NOT ALL Free's have been substituted, eg. because of incomplete model*)
74 | evalprecond prls (true, pre) =
75 if Rewrite.eval_true (Celem.assoc_thy "Isac_Knowledge") (* for Pattern.match *)
76 [pre] prls (* pre parsed, prls.thy *)
80 fun pre2str (b, t) = pair2str (bool2str b, Rule.term2str t);
81 fun pres2str pres = strs2str' (map (Celem.linefeed o pre2str) pres);
83 (* check preconditions, return true if all true *)
84 fun check_preconds' _ [] _ _ = [] (* empty preconditions are true *)
85 | check_preconds' prls pres pbl _ (* FIXME.WN0308 mvat re-introduce *) =
87 val env = Model.mk_env pbl;
88 val pres' = map (TermC.subst_atomic_all env) pres;
89 in map (evalprecond prls) pres' end;
90 fun check_preconds _(*thy*) prls pres pbl = check_preconds' prls pres pbl (Model.max_vt pbl);
93 fun common_subthy (thy1, thy2) =
94 if Context.subthy (thy1, thy2) then thy2
95 else if Context.subthy (thy2, thy1) then thy1
96 else Celem.assoc_thy "Isac_Knowledge"