1 (* Title: Specify/specification.sml
2 Author: Walther Neuper, Mathias Lehnfeld
3 (c) due to copyright terms
5 (* Survey on type fmz_ .. type ori .. type itm (in probl, meth) .. formal args of root-/SubProblem
6 and relations between respective list elements: #1#
7 fmz = [ dsc $ v......................................(dsc $ v)..]
8 root problem on pos = ([], _)
9 fmz_ = [(dsc, v).......................................(dsc, v)..]
11 oris = [(dsc, v)..(dsc, v),(dsc, v),(dsc, v)...........(dsc, v)..]
12 \<down> #Given,..,#Relate #Find #undef............#undef \<down>
13 \<down> \<down> \<down> \<down>
14 Specify_Problem + pbl.ppc= [(dsc,id)..(dsc,id),(dsc,id)] \<down> \<down> \<down>
15 \<down> \<down> \<down> \<down>
16 itms = [(dsc, v)..(dsc, v),(dsc, v)] \<down> \<down> \<down>
17 int.modelling +Cor ++++++++++Cor +Cor \<down> \<down> \<down>
18 \<down> \<down> \<down> \<down>
19 Specify_Method + met.ppc= [(dsc,id)..(dsc,id),(dsc,id)] \<down> \<down> \<down>
20 \<down> \<down> \<down> \<down>
21 itms = [(dsc, v)..(dsc, v),(dsc, v),(dsc, v)..(dsc, v)] \<down> \<down>
22 int.modelling +Cor ++++++Cor \<down> \<down>
23 form.args= [ id ..... id , /////// id ....... id ] \<down> \<down>
24 env = [(id, v)..(id, v) , /////// (id, v)....(id, v)] \<down> \<down>
25 interpret code env = [(id, v)..(id, v),(id, v)..(id, v) , /////// (id, v)....(id, v)] \<down> \<down>
26 ..extends env ^^^^^^^^^^^^^^^^ \<down> \<down> \<down> \<down> \<down>
27 \<down> \<down> \<down> \<down> \<down> \<down>
28 SubProblem on pos = ([2], _) \<down> \<down> \<down> \<down> \<down> \<down>
29 form.args= [id ................................ id ]\<down> \<down> \<down>
30 \<down> REAL..BOOL.. \<down> \<down> \<down>
31 \<down> \<down> \<down> \<down>
32 + met.ppc= [(dsc,id).......................(dsc,id)]\<down> \<down> \<down>
33 \<down> \<down> \<down> \<down> \<down>
34 oris = [(dsc, v)...................... (dsc, v) ........... (dsc, v)]\<down>
35 Specify_Problem, int.modelling, Specify_Method, interpret code as above #1# \<down>
37 SubProblem on pos = ([3, 4], _) \<down>
38 form.args= [id ...................... id ] \<down>
39 \<down> REAL..BOOL.. \<down>
40 + met.ppc= [(dsc,id).............(dsc,id)] \<down>
41 oris = [(dsc, v).............(dsc, v)...................(dsc, v)]
42 Specify_Problem, int.modelling, Specify_Method, interpret code as above #1#
45 (1) SubProblem implements sub-function calls such, that the arguments (+ pre- + post-condition)
46 of the functions become concern of interactive modelling.
47 (2) In Isac-terms, the above concerns the phases of modelling and
48 and of specifying (Specify_Problem, Specify_Method),
49 while stepwise construction of solutions is called solving.
50 The latter is supported by Lucas-Interpretation of the functions' body.
51 (3) ori list is determined by fmz_ (in root-pbl) or by args of SubProblem;
52 it is as complete as possible (this has been different up to now).
53 (4) itm list is initialised by pbl-ppc | met-pps and completed (Cor) by stepwise user input.
54 (5) model-pattern of pbl can omit technical items, e.g. boundVariable or functionName,
55 add them to the model-pattern of met and let this input be done automatically;
56 respective items must be in fmz.
58 signature SPECIFICATION =
61 type T = Specification_Def.T
63 (*val reset: Calc.T -> Calc.T*)
64 val reset_calchead: Calc.T -> Calc.T
65 (*val get: Calc.T -> T*)
66 val get_ocalhd: Calc.T -> T
67 (*val complete: I_Model.T -> Pre_Conds.T -> ThyC.id * Problem.id * Method.id -> bool*)
68 val ocalhd_complete: I_Model.T -> Pre_Conds.T -> ThyC.id * Problem.id * Method.id -> bool
69 (*val is_complete: Calc.T -> bool*)
70 val is_complete_mod: Calc.T -> bool
72 (*/------- to Specify from Specification -------\* )
73 (*val find_next_step': Pos.pos_ -> bool -> O_Model.T -> References.T -> I_Model.T * I_Model.T ->
74 Model_Pattern.T * Model_Pattern.T -> References.T -> Pos.pos_ * Tactic.input*)
75 val nxt_spec: Pos.pos_ -> bool -> O_Model.T -> References.T -> I_Model.T * I_Model.T ->
76 Model_Pattern.T * Model_Pattern.T -> References.T -> Pos.pos_ * Tactic.input
77 (*val do_all : Calc.T -> Calc.T*)
78 val all_modspec: Calc.T -> Calc.T
79 (*val finish_phase: Calc.T -> Calc.T*)
80 val complete_mod: Calc.T -> Calc.T
81 (*val nxt_add: theory -> O_Model.T -> Model_Pattern.T -> I_Model.T -> (string * string) option*)
82 val nxt_add: theory -> O_Model.T -> Model_Pattern.T -> I_Model.T -> (string * string) option
83 (*val nxt_specif_additem: string -> TermC.as_string -> Calc.T -> Calc.state_post*)
84 val nxt_specif_additem: string -> TermC.as_string -> Calc.T -> Calc.state_post
85 (*val specify_additem: string -> TermC.as_string -> Calc.T -> string * Calc.state_post*)
86 val specify_additem: string -> TermC.as_string -> Calc.T -> string * Calc.state_post
87 ( *\------- to Specify from Specification -------/*)
89 (* ---- for tests only: shifted from below to remove the Warning "unused" at fun.def. --------- *)
91 (*/-------------------------------------------------------- ! aktivate for Test_Isac BEGIN ---\* )
92 val get: Calc.T -> I_Model.T * O_Model.T * References.T * I_Model.T * References.T * Proof.context
93 val make: I_Model.m_field -> TermC.as_string * I_Model.T -> Tactic.T
94 ( *\--- ! aktivate for Test_Isac END ----------------------------------------------------------/*)
96 (*----- kept as hints to initial design ideas; NOT in src/, NOT in test ------------------------*)
97 val variants_in: term list -> int
98 val is_untouched: I_Model.single -> bool
99 val is_list_type: typ -> bool
100 val parse_ok: I_Model.feedback list -> bool
101 val all_dsc_in: I_Model.feedback list -> term list
102 val chktyps: theory -> term list * term list -> term list (* only in old tests*)
103 val is_complete_modspec: Calc.T -> bool
104 val get_formress: (string * Pos.pos' * term) list list -> Pos.pos -> Ctree.ctree list ->
105 (string * Pos.pos' * term) list
106 val get_forms: (string * Pos.pos' * term) list list -> Pos.pos -> Ctree.ctree list ->
107 (string * Pos.pos' * term) list
111 structure Specification(** ): SPECIFICATION( **) =
115 type T = Specification_Def.T;
117 (* is the calchead complete ? *)
118 fun ocalhd_complete its pre (dI, pI, mI) =
119 foldl and_ (true, map #3 (its: I_Model.T)) andalso
120 foldl and_ (true, map #1 (pre: Pre_Conds.T)) andalso
121 dI <> ThyC.id_empty andalso pI <> Problem.id_empty andalso mI <> Method.id_empty
123 (* get the number of variants in a problem in 'original',
124 assumes equal descriptions in immediate sequence *)
127 fun eq (x, y) = head_of x = head_of y
128 fun cnt _ [] _ n = ([n], [])
129 | cnt eq (x :: xs) y n = if eq (x, y) then cnt eq xs y (n + 1) else ([n], x :: xs)
130 fun coll _ xs [] = xs
131 | coll eq xs (y :: ys) =
132 let val (n, ys') = cnt eq (y :: ys) y 0
133 in if ys' = [] then xs @ n else coll eq (xs @ n) ys' end
134 val vts = subtract op = [1] (distinct (coll eq [] ts))
139 | _ => raise ERROR "different variants in formalization"
142 fun is_list_type (Type ("List.list", _)) = true
143 | is_list_type _ = false
144 fun is_parsed (I_Model.Syn _) = false
146 fun parse_ok its = foldl and_ (true, map is_parsed its)
148 fun all_dsc_in itm_s =
150 fun d_in (I_Model.Cor ((d, _), _)) = [d]
151 | d_in (I_Model.Syn _) = []
152 | d_in (I_Model.Typ _) = []
153 | d_in (I_Model.Inc ((d,_),_)) = [d]
154 | d_in (I_Model.Sup (d,_)) = [d]
155 | d_in (I_Model.Mis (d,_)) = [d]
156 | d_in i = raise ERROR ("all_dsc_in: uncovered case with " ^ I_Model.feedback_to_string' i)
157 in (flat o (map d_in)) itm_s end;
159 (* get the first term in ts from ori *)
160 fun getr_ct thy (_, _, fd, d, ts) =
161 (fd, ((UnparseC.term_in_thy thy) o Input_Descript.join) (d,[hd ts]))
163 (* get a term from ori, notyet input in itm.
164 the term from ori is thrown back to a string in order to reuse
165 machinery for immediate input by the user. *)
166 fun geti_ct thy (_, _, _, d, ts) (_, _, _, fd, itm_) =
167 (fd, ((UnparseC.term_in_thy thy) o Input_Descript.join) (d, subtract op = (I_Model.ts_in itm_) ts))
169 (* in FE dsc, not dat: this is in itms ...*)
170 fun is_untouched (_, _, false, _, I_Model.Inc ((_, []), _)) = true
171 | is_untouched _ = false
173 (* select an item in oris, notyet input in itms
174 (precondition: in itms are only I_Model.Cor, I_Model.Sup, I_Model.Inc) *)
177 oris: from formalization 'type fmz', structured for efficient access
178 pbt : the problem-pattern to be matched with oris in order to get itms
179 itms: already input items
181 fun nxt_add thy [] pbt itms = (*root (only) ori...fmz=[]*)
183 fun test_d d (i, _, _, _, itm_) = (d = (I_Model.d_in itm_)) andalso i <> 0
184 fun is_elem itms (_, (d, _)) =
185 case find_first (test_d d) itms of SOME _ => true | NONE => false
187 case filter_out (is_elem itms) pbt of
188 (f, (d, _)) :: _ => SOME (f, ((UnparseC.term_in_thy thy) o Input_Descript.join) (d, []))
191 | nxt_add thy oris _ itms =
193 fun testr_vt v ori = member op= (#2 (ori : O_Model.single)) v andalso (#3 ori) <> "#undef"
194 fun testi_vt v itm = member op= (#2 (itm : I_Model.single)) v
195 fun test_id ids r = member op= ids (#1 (r : O_Model.single))
196 fun test_subset itm (_, _, _, d, ts) =
197 (I_Model.d_in (#5 (itm: I_Model.single))) = d andalso subset op = (I_Model.ts_in (#5 itm), ts)
198 fun false_and_not_Sup (_, _, false, _, I_Model.Sup _) = false
199 | false_and_not_Sup (_, _, false, _, _) = true
200 | false_and_not_Sup _ = false
201 val v = if itms = [] then 1 else I_Model.max_vt itms
202 val vors = if v = 0 then oris else filter (testr_vt v) oris (* oris..vat *)
205 then itms (* because of dsc without dat *)
206 else filter (testi_vt v) itms; (* itms..vat *)
207 val icl = filter false_and_not_Sup vits; (* incomplete *)
210 then case filter_out (test_id (map #1 vits)) vors of
212 | miss => SOME (getr_ct thy (hd miss))
214 case find_first (test_subset (hd icl)) vors of
215 NONE => raise ERROR "nxt_add: types or dsc DO NOT MATCH BETWEEN fmz --- pbt"
216 | SOME ori => SOME (geti_ct thy ori (hd icl))
219 (*/------- to Specify from Specification -------\*)
221 TODO: unify with Specify.find_next_step ! ! ! USED ONLY to determine Pos.Pbl .. Pos.Met
223 determine the next step of specification;
224 not done here: Refine_Tacitly (otherwise *** unknown method: (..., no_met))
225 eg. in rootpbl 'no_met':
227 preok predicates are _all_ ok (and problem matches completely)
228 oris immediately from formalization
229 (dI',pI',mI') specification coming from author/parent-problem
230 (pbl, item lists specified by user
231 met) -"-, tacitly completed by copy_probl
232 (dI,pI,mI) specification explicitly done by the user
233 (pbt, mpc) problem type, guard of method
235 fun nxt_spec Pos.Pbl preok oris (dI', pI', mI') (pbl, met) (pbt, mpc) (dI, pI, mI) =
236 (if dI' = ThyC.id_empty andalso dI = ThyC.id_empty then (Pos.Pbl, Tactic.Specify_Theory dI')
237 else if pI' = Problem.id_empty andalso pI = Problem.id_empty then (Pos.Pbl, Tactic.Specify_Problem pI')
239 case find_first (I_Model.is_error o #5) pbl of
240 SOME (_, _, _, fd, itm_) =>
241 (Pos.Pbl, P_Model.mk_delete (ThyC.get_theory (if dI = ThyC.id_empty then dI' else dI)) fd itm_)
243 (case nxt_add (ThyC.get_theory (if dI = ThyC.id_empty then dI' else dI)) oris pbt pbl of
244 SOME (fd, ct') => (Pos.Pbl, P_Model.mk_additem fd ct')
245 | NONE => (*pbl-items complete*)
246 if not preok then (Pos.Pbl, Tactic.Refine_Problem pI')
247 else if dI = ThyC.id_empty then (Pos.Pbl, Tactic.Specify_Theory dI')
248 else if pI = Problem.id_empty then (Pos.Pbl, Tactic.Specify_Problem pI')
249 else if mI = Method.id_empty then (Pos.Pbl, Tactic.Specify_Method mI')
251 case find_first (I_Model.is_error o #5) met of
252 SOME (_, _, _, fd, itm_) => (Pos.Met, P_Model.mk_delete (ThyC.get_theory dI) fd itm_)
254 (case nxt_add (ThyC.get_theory dI) oris mpc met of
255 SOME (fd, ct') => (Pos.Met, P_Model.mk_additem fd ct') (*30.8.01: pre?!?*)
256 | NONE => (Pos.Met, Tactic.Apply_Method mI))))
257 | nxt_spec Pos.Met preok oris (dI', pI', _) (_, met) (_ ,mpc) (dI, pI, mI) =
258 (case find_first (I_Model.is_error o #5) met of
259 SOME (_,_,_,fd,itm_) => (Pos.Met, P_Model.mk_delete (ThyC.get_theory (if dI = ThyC.id_empty then dI' else dI)) fd itm_)
261 case nxt_add (ThyC.get_theory (if dI = ThyC.id_empty then dI' else dI)) oris mpc met of
262 SOME (fd,ct') => (Pos.Met, P_Model.mk_additem fd ct')
264 (if dI = ThyC.id_empty then (Pos.Met, Tactic.Specify_Theory dI')
265 else if pI = Problem.id_empty then (Pos.Met, Tactic.Specify_Problem pI')
266 else if not preok then (Pos.Met, Tactic.Specify_Method mI)
267 else (Pos.Met, Tactic.Apply_Method mI)))
268 | nxt_spec p _ _ _ _ _ _ = raise ERROR ("nxt_spec: uncovered case with " ^ Pos.pos_2str p)
269 (*\------- to Specify from Specification -------/*)
271 (* output the headline to a ppc *)
272 fun header p_ pI mI =
274 Pos.Pbl => Test_Out.Problem (if pI = Problem.id_empty then [] else pI)
275 | Pos.Met => Test_Out.Method mI
276 | pos => raise ERROR ("header called with "^ Pos.pos_2str pos)
278 fun make m_field (term_as_string, i_model) =
280 "#Given" => Tactic.Add_Given' (term_as_string, i_model)
281 | "#Find" => Tactic.Add_Find' (term_as_string, i_model)
282 | "#Relate" => Tactic.Add_Relation'(term_as_string, i_model)
283 | str => raise ERROR ("specify_additem Frm, Pbl: uncovered case with " ^ str);
284 fun get (pt, (p, _)) =
285 case Ctree.get_obj I pt p of
286 (Ctree.PblObj {meth, origin = (oris, (dI', pI', mI'), _), probl, spec = (dI, pI, mI), ctxt, ...})
287 => (meth, oris, (dI', pI', mI'), probl, (dI, pI, mI), ctxt)
288 | _ => raise ERROR "specify_additem: uncovered case of get_obj I pt p";
289 fun specify_additem sel ct (pt, pos as (p, Pos.Met)) =
291 val (met, oris, (dI', pI', mI'), pbl, (dI, pI, mI), ctxt) = get (pt, pos)
292 val thy = if dI = ThyC.id_empty then ThyC.get_theory dI' else ThyC.get_theory dI
293 val cpI = if pI = Problem.id_empty then pI' else pI
294 val cmI = if mI = Method.id_empty then mI' else mI
295 val {ppc, pre, prls, ...} = Method.from_store cmI
297 case I_Model.check_single ctxt sel oris met ppc ct of
298 I_Model.Add itm => (*..union old input *)
300 val met' = I_Model.add_single thy itm met
302 case Specify_Step.add (make sel (ct, met')) (Istate_Def.Uistate, ctxt) (pt, (p, Pos.Met)) of
303 ((p, Pos.Met), _, _, pt') => (p, pt')
304 | _ => raise ERROR "specify_additem: uncovered case of generate1"
305 val pre' = Pre_Conds.check' thy prls pre met'
306 val pb = foldl and_ (true, map fst pre')
308 nxt_spec Pos.Met pb oris (dI',pI',mI') (pbl,met')
309 ((#ppc o Problem.from_store) cpI,ppc) (dI,pI,mI);
311 ("ok", ([], [], (pt', (p, p_))))
315 val pre' = Pre_Conds.check' thy prls pre met
316 val pb = foldl and_ (true, map fst pre')
318 nxt_spec Pos.Met pb oris (dI',pI',mI') (pbl,met)
319 ((#ppc o Problem.from_store) cpI,(#ppc o Method.from_store) cmI) (dI,pI,mI);
321 (msg, ([], [], (pt, (p, p_))))
324 | specify_additem sel ct (pt, pos as (p, _(*Frm, Pbl*))) =
326 val (met, oris, (dI', pI', mI'), pbl, (dI, pI, mI), ctxt) = get (pt, pos)
327 val thy = if dI = ThyC.id_empty then ThyC.get_theory dI' else ThyC.get_theory dI
328 val cpI = if pI = Problem.id_empty then pI' else pI
329 val cmI = if mI = Method.id_empty then mI' else mI
330 val {ppc, where_, prls, ...} = Problem.from_store cpI
332 case I_Model.check_single ctxt sel oris pbl ppc ct of
333 I_Model.Add itm => (*..union old input *)
335 val pbl' = I_Model.add_single thy itm pbl
337 case Specify_Step.add (make sel (ct, pbl')) (Istate_Def.Uistate, ctxt) (pt, (p, Pos.Pbl)) of
338 ((p, Pos.Pbl), _, _, pt') => (p, pt')
339 | _ => raise ERROR "specify_additem: uncovered case of Specify_Step.add"
340 (* only for getting final p_ ..*)
341 val pre = Pre_Conds.check' thy prls where_ pbl';
342 val pb = foldl and_ (true, map fst pre);
344 nxt_spec Pos.Pbl pb oris (dI',pI',mI') (pbl',met) (ppc, (#ppc o Method.from_store) cmI) (dI, pI, mI);
346 ("ok", ([], [], (pt', (p, p_))))
350 val pre = Pre_Conds.check' thy prls where_ pbl
351 val pb = foldl and_ (true, map fst pre)
352 val (p_, _(*Tactic.input*)) =
353 nxt_spec Pos.Pbl pb oris (dI', pI', mI') (pbl, met)
354 (ppc, (#ppc o Method.from_store) cmI) (dI, pI, mI)
356 (msg, ([], [], (pt, (p, p_))))
360 (*FIXME.WN110515 declare_constraints for ct (without dsc) into PblObj{ctxt, ...}
361 -- for input from scratch*)
362 fun nxt_specif_additem sel ct (ptp as (pt, (p, Pos.Pbl))) =
364 val (oris, dI', pI', dI, pI, pbl, ctxt) = case Ctree.get_obj I pt p of
365 Ctree.PblObj {origin = (oris, (dI', pI', _), _), spec = (dI, pI, _), probl = pbl, ctxt, ...} =>
366 (oris, dI', pI', dI, pI, pbl, ctxt)
367 | _ => raise ERROR "specify (Specify_Theory': uncovered case get_obj"
368 val thy = if dI = ThyC.id_empty then ThyC.get_theory dI' else ThyC.get_theory dI;
369 val cpI = if pI = Problem.id_empty then pI' else pI;
371 case I_Model.check_single ctxt sel oris pbl ((#ppc o Problem.from_store) cpI) ct of
372 I_Model.Add itm (*..union old input *) =>
374 val pbl' = I_Model.add_single thy itm pbl
375 val (tac, tac_) = case sel of
376 "#Given" => (Tactic.Add_Given ct, Tactic.Add_Given' (ct, pbl'))
377 | "#Find" => (Tactic.Add_Find ct, Tactic.Add_Find' (ct, pbl'))
378 | "#Relate"=> (Tactic.Add_Relation ct, Tactic.Add_Relation'(ct, pbl'))
379 | sel => raise ERROR ("nxt_specif_additem: uncovered case of" ^ sel)
381 case Specify_Step.add tac_ (Istate_Def.Uistate, ctxt) (pt, (p, Pos.Pbl)) of
382 ((p, Pos.Pbl), c, _, pt') => (p, c, pt')
383 | _ => raise ERROR "nxt_specif_additem: uncovered case generate1"
385 ([(tac, tac_, ((p, Pos.Pbl), (Istate_Def.Uistate, ctxt)))], c, (pt', (p, Pos.Pbl)))
387 | I_Model.Err msg => (*TODO.WN03 pass error-msgs to the frontend..
388 FIXME ..and dont abuse a tactic for that purpose*)
389 ([(Tactic.Tac msg, Tactic.Tac_ (ThyC.get_theory "Isac_Knowledge", msg,msg,msg),
390 (Pos.e_pos', (Istate_Def.empty, ContextC.empty)))], [], ptp)
392 | nxt_specif_additem sel ct (ptp as (pt, (p, Pos.Met))) =
394 val (oris, dI', mI', dI, mI, met, ctxt) = case Ctree.get_obj I pt p of
395 Ctree.PblObj {origin = (oris, (dI', _, mI'), _), spec = (dI, _, mI), meth = met,ctxt, ...} =>
396 (oris, dI', mI', dI, mI, met, ctxt)
397 | _ => raise ERROR "nxt_specif_additem Met: uncovered case get_obj"
398 val thy = if dI = ThyC.id_empty then ThyC.get_theory dI' else ThyC.get_theory dI;
399 val cmI = if mI = Method.id_empty then mI' else mI;
401 case I_Model.check_single ctxt sel oris met ((#ppc o Method.from_store) cmI) ct of
402 I_Model.Add itm (*..union old input *) =>
404 val met' = I_Model.add_single thy itm met;
405 val (tac,tac_) = case sel of
406 "#Given" => (Tactic.Add_Given ct, Tactic.Add_Given' (ct, met'))
407 | "#Find" => (Tactic.Add_Find ct, Tactic.Add_Find' (ct, met'))
408 | "#Relate"=> (Tactic.Add_Relation ct, Tactic.Add_Relation'(ct, met'))
409 | sel => raise ERROR ("nxt_specif_additem Met: uncovered case of" ^ sel)
411 case Specify_Step.add tac_ (Istate_Def.Uistate, ctxt) (pt, (p, Pos.Met)) of
412 ((p, Pos.Met), c, _, pt') => (p, c, pt')
413 | _ => raise ERROR "nxt_specif_additem: uncovered case generate1 (WARNING WHY ?)"
415 ([(tac, tac_, ((p, Pos.Met), (Istate_Def.Uistate, ctxt)))], c, (pt', (p, Pos.Met)))
417 | I_Model.Err _ => ([(*tacis*)], [], ptp) (*nxt_me collects tacis until not hide; here just no progress*)
419 | nxt_specif_additem _ _ (_, p) = raise ERROR ("nxt_specif_additem not impl. for" ^ Pos.pos'2str p)
421 (* fun tag_form thy (formal, given) = Thm.global_cterm_of thy
422 (((head_of o Thm.term_of) given) $ (Thm.term_of formal)); WN100819 *)
423 fun tag_form thy (formal, given) =
425 val gf = (head_of given) $ formal;
426 val _ = Thm.global_cterm_of thy gf
428 handle _ => raise ERROR ("calchead.tag_form: " ^ UnparseC.term_in_thy thy given ^
429 " .. " ^ UnparseC.term_in_thy thy formal ^ " ..types do not match")
431 fun chktyps thy (fs, gs) = map (tag_form thy) (fs ~~ gs)
433 (* complete _NON_empty calc-head for autocalc (sub-)pbl from oris
434 + met from fmz; assumes pos on PblObj, meth = [] *)
435 fun complete_mod (pt, pos as (p, p_)) =
437 val _ = if p_ <> Pos.Pbl
438 then raise ERROR ("###complete_mod: only impl.for Pbl, called with " ^ Pos.pos'2str pos)
440 val (oris, ospec, probl, spec) = case Ctree.get_obj I pt p of
441 Ctree.PblObj {origin = (oris, ospec, _), probl, spec, ...} => (oris, ospec, probl, spec)
442 | _ => raise ERROR "complete_mod: unvered case get_obj"
443 val (_, pI, mI) = References.select ospec spec
444 val mpc = (#ppc o Method.from_store) mI
445 val ppc = (#ppc o Problem.from_store) pI
446 val (pits, mits) = I_Model.complete_method (oris, mpc, ppc, probl)
447 val pt = Ctree.update_pblppc pt p pits
448 val pt = Ctree.update_metppc pt p mits
449 in (pt, (p, Pos.Met)) end
451 (* do all specification in one single step:
452 complete calc-head for autocalc (sub-)pbl from oris (+ met from fmz);
453 oris and spec (incl. pbl-refinement) given from init_calc or SubProblem
455 fun all_modspec (pt, (p, _)) =
457 val (pors, dI, pI, mI) = case Ctree.get_obj I pt p of
458 Ctree.PblObj {origin = (pors, (dI, pI, mI), _), ...}
459 => (pors, dI, pI, mI)
460 | _ => raise ERROR "all_modspec: uncovered case get_obj"
461 val {ppc, ...} = Method.from_store mI
462 val (_, vals) = O_Model.values' pors
463 val ctxt = ContextC.initialise dI vals
464 val (pt, _) = Ctree.cupdate_problem pt p ((dI, pI, mI),
465 map (I_Model.complete' ppc) pors, map (I_Model.complete' ppc) pors, ctxt)
470 (*/------- to I_Model from Specification -------\* )
471 (* WN0312: use in nxt_spec, too ? what about variants ??? *)
472 fun is_complete_mod_ [] = false
473 | is_complete_mod_ itms = foldl and_ (true, (map #3 itms))
474 ( *\------- to I_Model from Specification -------/*)
476 fun is_complete_mod (pt, pos as (p, Pos.Pbl)) =
477 if (Ctree.is_pblobj o (Ctree.get_obj I pt)) p
478 then (I_Model.is_complete o (Ctree.get_obj Ctree.g_pbl pt)) p
479 else raise ERROR ("is_complete_mod: called by PrfObj at " ^ Pos.pos'2str pos)
480 | is_complete_mod (pt, pos as (p, Pos.Met)) =
481 if (Ctree.is_pblobj o (Ctree.get_obj I pt)) p
482 then (I_Model.is_complete o (Ctree.get_obj Ctree.g_met pt)) p
483 else raise ERROR ("is_complete_mod: called by PrfObj at " ^ Pos.pos'2str pos)
484 | is_complete_mod (_, pos) =
485 raise ERROR ("is_complete_mod called by " ^ Pos.pos'2str pos ^ " (should be Pbl or Met)")
487 fun is_complete_modspec ptp = is_complete_mod ptp andalso References.are_complete ptp
490 (** get the formula from a ctree-node **)
492 take form+res from PblObj and 1.PrfObj and (PrfObj after PblObj)
493 take res from all other PrfObj's
494 Designed for interSteps, outcommented 04 in favour of calcChangedEvent
496 fun formres p (Ctree.Nd (Ctree.PblObj {origin = (_, _, h), result = (r, _), ...}, _)) =
497 [("headline", (p, Pos.Frm), h), ("stepform", (p, Pos.Res), r)]
498 | formres p (Ctree.Nd (Ctree.PrfObj {form, result = (r, _), ...}, _)) =
499 [("stepform", (p, Pos.Frm), form), ("stepform", (p, Pos.Res), r)]
500 | formres _ _ = raise ERROR "formres: uncovered definition"
501 fun form p (Ctree.Nd (Ctree.PrfObj {result = (r, _), ...}, _)) =
502 [("stepform", (p, Pos.Res), r)]
503 | form _ _ = raise ERROR "form: uncovered definition"
505 (* assumes to take whole level, in particular hd -- for use in interSteps *)
506 fun get_formress fs _ [] = flat fs
507 | get_formress fs p (nd::nds) =
508 (* start with 'form+res' and continue with trying 'res' only*)
509 get_forms (fs @ [formres p nd]) (Pos.lev_on p) nds
510 and get_forms fs _ [] = flat fs
511 | get_forms fs p (nd::nds) =
513 (* start again with 'form+res' ///ugly repeat with Check_elementwise
514 then get_formress (fs @ [formres p nd]) (lev_on p) nds *)
515 then get_forms (fs @ [formres p nd]) (Pos.lev_on p) nds
516 (* continue with trying 'res' only*)
517 else get_forms (fs @ [form p nd]) (Pos.lev_on p) nds;
520 (* get a calchead from a PblObj-node in the ctree; preconditions must be calculated *)
521 fun get_ocalhd (pt, (p, Pos.Pbl)) =
523 val (ospec, hdf', spec, probl) = case Ctree.get_obj I pt p of
524 Ctree.PblObj {origin = (_, ospec, hdf'), spec, probl,...} => (ospec, hdf', spec, probl)
525 | _ => raise ERROR "get_ocalhd Pbl: uncovered case get_obj"
526 val {prls, where_, ...} = Problem.from_store (#2 (References.select ospec spec))
527 val pre = Pre_Conds.check' (ThyC.get_theory "Isac_Knowledge") prls where_ probl
529 (ocalhd_complete probl pre spec, Pos.Pbl, hdf', probl, pre, spec)
531 | get_ocalhd (pt, (p, Pos.Met)) =
533 val (ospec, hdf', spec, meth) = case Ctree.get_obj I pt p of
534 Ctree.PblObj {origin = (_, ospec, hdf'), spec, meth, ...} => (ospec, hdf', spec, meth)
535 | _ => raise ERROR "get_ocalhd Met: uncovered case get_obj"
536 val {prls, pre, ...} = Method.from_store (#3 (References.select ospec spec))
537 val pre = Pre_Conds.check' (ThyC.get_theory "Isac_Knowledge") prls pre meth
539 (ocalhd_complete meth pre spec, Pos.Met, hdf', meth, pre, spec)
541 | get_ocalhd _ = raise ERROR "get_ocalhd: uncovered definition"
543 (* at the activeFormula set the Specification
544 to empty and return a CalcHead;
545 the 'origin' remains (for reconstructing all that) *)
546 fun reset_calchead (pt, (p,_)) =
548 val () = case Ctree.get_obj I pt p of
550 | _ => raise ERROR "reset_calchead: uncovered case get_obj"
551 val pt = Ctree.update_pbl pt p []
552 val pt = Ctree.update_met pt p []
553 val pt = Ctree.update_spec pt p References.empty
554 in (pt, (p, Pos.Pbl)) end