3 val find_next_step: Calc.T -> string * (Pos.pos_ * Tactic.input)
4 val find_next_step': Pos.pos_ -> bool -> O_Model.T -> References.T -> I_Model.T * I_Model.T ->
5 Model_Pattern.T * Model_Pattern.T -> References.T -> Pos.pos_ * Tactic.input
6 val do_all: Calc.T -> Calc.T
7 val finish_phase: Calc.T -> Calc.T
9 val item_to_add: theory -> O_Model.T -> Model_Pattern.T -> I_Model.T ->
10 (Model_Def.m_field * TermC.as_string) option
11 val item_to_add': theory -> O_Model.T -> Model_Pattern.T -> I_Model.T ->
12 (Model_Def.m_field * TermC.as_string) option
13 (*TODO: vvvvvvvvvvvvvv unify code*)
14 val by_tactic_input': string -> TermC.as_string -> Calc.T -> Calc.state_post
15 val by_tactic': string -> TermC.as_string -> Calc.T -> string * Calc.state_post
16 (*TODO: ^^^^^^^^^^^^^^ unify code*)
17 (* ---- for tests only: shifted from below to remove the Warning "unused" at fun.def. --------- *)
19 (*/-------------------------------------------------------- ! aktivate for Test_Isac BEGIN ---\* )
21 ( *\--- ! aktivate for Test_Isac END ----------------------------------------------------------/*)
25 structure Specify(**): SPECIFY(**) =
30 select an item in oris, notyet input in itms
31 (precondition: in itms are only I_Model.Cor, I_Model.Sup, I_Model.Inc)
34 oris: from formalization 'type fmz', structured for efficient access
35 pbt : the problem-pattern to be matched with oris in order to get itms
36 itms: already input items
38 fun item_to_add' thy [] pbt itms = (*root (only) ori...fmz=[]*)
40 fun test_d d (i, _, _, _, itm_) = (d = (I_Model.d_in itm_)) andalso i <> 0
41 fun is_elem itms (_, (d, _)) =
42 case find_first (test_d d) itms of SOME _ => true | NONE => false
44 case filter_out (is_elem itms) pbt of
45 (f, (d, _)) :: _ => SOME (f, ((UnparseC.term_in_thy thy) o Input_Descript.join) (d, []))
48 | item_to_add' thy oris _ itms =
50 (*OLD*)fun testr_vt v ori = Library.member op= (#2 (ori : O_Model.single)) v andalso (#3 ori) <> "#undef"
51 (*OLD*)fun testi_vt v itm = Library.member op= (#2 (itm : I_Model.single)) v
52 fun test_id ids r = Library.member op= ids (#1 (r : O_Model.single))
53 fun test_subset itm (_, _, _, d, ts) =
54 (I_Model.d_in (#5 (itm: I_Model.single))) = d andalso subset op = (I_Model.ts_in (#5 itm), ts)
55 fun false_and_not_Sup (_, _, false, _, I_Model.Sup _) = false
56 | false_and_not_Sup (_, _, false, _, _) = true
57 | false_and_not_Sup _ = false
58 val v = if itms = [] then 1 else I_Model.max_vt itms
59 val vors = if v = 0 then oris else filter (testr_vt v) oris (* oris..vat *)
62 then itms (* because of dsc without dat *)
63 else filter (testi_vt v) itms; (* itms..vat *)
64 val icl = filter false_and_not_Sup vits; (* incomplete *)
67 case filter_out (test_id (map #1 vits)) vors of
69 | miss => SOME (O_Model.getr_ct thy (hd miss))
71 case find_first (test_subset (hd icl)) vors of
72 NONE => raise ERROR "item_to_add': types or dsc DO NOT MATCH BETWEEN fmz --- pbt"
73 | SOME ori => SOME (I_Model.geti_ct thy ori (hd icl))
76 (* preliminary doubling of code, ONLY difference SHALL BE in fun testr_vt *)
77 fun item_to_add thy [] pbt itms = (*root (only) ori...fmz=[]*)
79 fun test_d d (i, _, _, _, itm_) = (d = (I_Model.d_in itm_)) andalso i <> 0
80 fun is_elem itms (_, (d, _)) =
81 case find_first (test_d d) itms of SOME _ => true | NONE => false
83 case filter_out (is_elem itms) pbt of
84 (f, (d, _)) :: _ => SOME (f, ((UnparseC.term_in_thy thy) o Input_Descript.join) (d, []))
87 | item_to_add thy oris _ itms =
89 (*NEW*)fun testr_vt v ori = Library.member op= (#2 (ori : O_Model.single)) v (*andalso (#3 ori) <> "#undef"*)
90 (*OLD* )fun testr_vt v ori = Library.member op= (#2 (ori : O_Model.single)) v andalso (#3 ori) <> "#undef"
91 ( *OLD*)fun testi_vt v itm = Library.member op= (#2 (itm : I_Model.single)) v
92 fun test_id ids r = Library.member op= ids (#1 (r : O_Model.single))
93 fun test_subset itm (_, _, _, d, ts) =
94 (I_Model.d_in (#5 (itm: I_Model.single))) = d andalso subset op = (I_Model.ts_in (#5 itm), ts)
95 fun false_and_not_Sup (_, _, false, _, I_Model.Sup _) = false
96 | false_and_not_Sup (_, _, false, _, _) = true
97 | false_and_not_Sup _ = false
98 val v = if itms = [] then 1 else I_Model.max_vt itms
99 val vors = if v = 0 then oris else filter (testr_vt v) oris (* oris..vat *)
102 then itms (* because of dsc without dat *)
103 else filter (testi_vt v) itms; (* itms..vat *)
104 val icl = filter false_and_not_Sup vits; (* incomplete *)
107 case filter_out (test_id (map #1 vits)) vors of
109 | miss => SOME (O_Model.getr_ct thy (hd miss))
111 case find_first (test_subset (hd icl)) vors of
112 NONE => raise ERROR "item_to_add': types or dsc DO NOT MATCH BETWEEN fmz --- pbt"
113 | SOME ori => SOME (I_Model.geti_ct thy ori (hd icl))
117 fun find_next_step (pt, (p, p_)) =
119 (*OLD*)val (pblobj, met, origin, oris, dI', pI', mI', pbl, dI, pI, mI) =
120 (*OLD*) case Ctree.get_obj I pt p of
121 (*OLD*) pblobj as (Ctree.PblObj {meth, origin = origin as (oris, (dI', pI', mI'), _),
122 (*OLD*) probl, spec = (dI, pI, mI), ...}) => (pblobj, meth, origin, oris, dI', pI', mI', probl, dI, pI, mI)
123 (*OLD*) | Ctree.PrfObj _ => raise ERROR "nxt_specify_: not on PrfObj"
125 (*OLD*) if Ctree.just_created_ pblobj (*by Subproblem*) andalso origin <> Ctree.e_origin then
127 (*NEW* )val pblobj as {meth = met, origin = origin as (oris, (dI', pI', mI'), _), probl = pbl,
128 (*NEW*) spec = (dI, pI, mI), ctxt, ...} = Calc.specify_data (pt, (p, p_));
130 (*NEW*) if Ctree.just_created (pt, (p, p_)) andalso origin <> Ctree.e_origin then
133 ["no_met"] => ("ok", (Pos.Pbl, Tactic.Refine_Tacitly pI'))
134 | _ => ("ok", (Pos.Pbl, Tactic.Model_Problem))
137 (*NEW* ) References.select (dI', pI', mI') (dI, pI, mI) ( *NEW*)
138 val cpI = if pI = Problem.id_empty then pI' else pI;
139 val cmI = if mI = Method.id_empty then mI' else mI;
140 val {ppc = pbt, prls, where_, ...} = Problem.from_store cpI;
141 val pre = Pre_Conds.check' "thy 100820" prls where_ pbl;
142 val preok = foldl and_ (true, map fst pre);
143 (*FIXME.WN0308: ~~~~~: just check true in itms of pbl/met?*)
144 val mpc = (#ppc o Method.from_store) cmI
147 (*vvvvvvv---------------------------*)
149 (if dI' = ThyC.id_empty andalso dI = ThyC.id_empty then ("dummy", (Pos.Pbl, Tactic.Specify_Theory dI'))
150 else if pI' = Problem.id_empty andalso pI = Problem.id_empty then ("dummy", (Pos.Pbl, Tactic.Specify_Problem pI'))
152 case find_first (I_Model.is_error o #5) pbl of
153 SOME (_, _, _, fd, itm_) =>
154 ("dummy", (Pos.Pbl, P_Model.mk_delete (ThyC.get_theory
155 (if dI = ThyC.id_empty then dI' else dI)) fd itm_))
157 (case item_to_add' (ThyC.get_theory (if dI = ThyC.id_empty then dI' else dI)) oris pbt pbl of
158 SOME (fd, ct') => ("dummy", (Pos.Pbl, P_Model.mk_additem fd ct'))
159 | NONE => (*pbl-items complete*)
160 if not preok then ("dummy", (Pos.Pbl, Tactic.Refine_Problem pI'))
161 else if dI = ThyC.id_empty then ("dummy", (Pos.Pbl, Tactic.Specify_Theory dI'))
162 else if pI = Problem.id_empty then ("dummy", (Pos.Pbl, Tactic.Specify_Problem pI'))
163 else if mI = Method.id_empty then ("dummy", (Pos.Pbl, Tactic.Specify_Method mI'))
165 case find_first (I_Model.is_error o #5) met of
166 SOME (_, _, _, fd, itm_) => ("dummy", (Pos.Met, P_Model.mk_delete (ThyC.get_theory dI) fd itm_))
168 (case item_to_add (ThyC.get_theory dI) oris mpc met of
169 SOME (fd, ct') => ("dummy", (Pos.Met, P_Model.mk_additem fd ct')) (*30.8.01: pre?!?*)
170 | NONE => ("dummy", (Pos.Met, Tactic.Apply_Method mI)))))
171 (*vvvvvvv---------------------------*)
173 (case find_first (I_Model.is_error o #5) met of
174 SOME (_,_,_, fd, itm_) => ("dummy", (Pos.Met, P_Model.mk_delete (ThyC.get_theory (if dI = ThyC.id_empty then dI' else dI)) fd itm_))
176 case item_to_add (ThyC.get_theory (if dI = ThyC.id_empty then dI' else dI)) oris mpc met of
177 SOME (fd, ct') => ("dummy", (Pos.Met, P_Model.mk_additem fd ct')) (*->->*)
179 (if dI = ThyC.id_empty then ("dummy", (Pos.Met, Tactic.Specify_Theory dI'))
180 else if pI = Problem.id_empty then ("dummy", (Pos.Met, Tactic.Specify_Problem pI'))
181 else if not preok then ("dummy", (Pos.Met, Tactic.Specify_Method mI))
182 else ("dummy", (Pos.Met, Tactic.Apply_Method mI))))
183 | p_ => raise ERROR ("Specify.find_next_step called with " ^ Pos.pos_2str p_)
188 TODO: unify code with Specify.find_next_step ! ! ! USED ONLY to determine Pos.Pbl .. Pos.Met
190 determine the next step of specification;
191 not done here: Refine_Tacitly (otherwise *** unknown method: (..., no_met))
192 eg. in rootpbl 'no_met':
194 preok predicates are _all_ ok (and problem matches completely)
195 oris immediately from formalization
196 (dI',pI',mI') specification coming from author/parent-problem
197 (pbl, item lists specified by user
198 met) -"-, tacitly completed by copy_probl
199 (dI,pI,mI) specification explicitly done by the user
200 (pbt, mpc) problem type, guard of method
202 (*--------------vvvvvvv *)
203 fun find_next_step' Pos.Pbl preok oris (dI', pI', mI') (pbl, met) (pbt, mpc) (dI, pI, mI) =
204 (if dI' = ThyC.id_empty andalso dI = ThyC.id_empty then (Pos.Pbl, Tactic.Specify_Theory dI')
205 else if pI' = Problem.id_empty andalso pI = Problem.id_empty then (Pos.Pbl, Tactic.Specify_Problem pI')
207 case find_first (I_Model.is_error o #5) pbl of
208 SOME (_, _, _, fd, itm_) =>
209 (Pos.Pbl, P_Model.mk_delete (ThyC.get_theory (if dI = ThyC.id_empty then dI' else dI)) fd itm_)
211 (case item_to_add' (ThyC.get_theory (if dI = ThyC.id_empty then dI' else dI)) oris pbt pbl of
212 SOME (fd, ct') => (Pos.Pbl, P_Model.mk_additem fd ct')
213 | NONE => (*pbl-items complete*)
214 if not preok then (Pos.Pbl, Tactic.Refine_Problem pI')
215 else if dI = ThyC.id_empty then (Pos.Pbl, Tactic.Specify_Theory dI')
216 else if pI = Problem.id_empty then (Pos.Pbl, Tactic.Specify_Problem pI')
217 else if mI = Method.id_empty then (Pos.Pbl, Tactic.Specify_Method mI')
219 case find_first (I_Model.is_error o #5) met of
220 SOME (_, _, _, fd, itm_) => (Pos.Met, P_Model.mk_delete (ThyC.get_theory dI) fd itm_)
222 (case item_to_add (ThyC.get_theory dI) oris mpc met of
223 SOME (fd, ct') => (Pos.Met, P_Model.mk_additem fd ct') (*30.8.01: pre?!?*)
224 | NONE => (Pos.Met, Tactic.Apply_Method mI))))
225 (*--------------vvvvvvv *)
226 | find_next_step' Pos.Met preok oris (dI', pI', _) (_, met) (_ ,mpc) (dI, pI, mI) =
227 (case find_first (I_Model.is_error o #5) met of
228 SOME (_,_,_,fd,itm_) => (Pos.Met, P_Model.mk_delete (ThyC.get_theory (if dI = ThyC.id_empty then dI' else dI)) fd itm_)
230 case item_to_add (ThyC.get_theory (if dI = ThyC.id_empty then dI' else dI)) oris mpc met of
231 SOME (fd,ct') => (Pos.Met, P_Model.mk_additem fd ct')
233 (if dI = ThyC.id_empty then (Pos.Met, Tactic.Specify_Theory dI')
234 else if pI = Problem.id_empty then (Pos.Met, Tactic.Specify_Problem pI')
235 else if not preok then (Pos.Met, Tactic.Specify_Method mI)
236 else (Pos.Met, Tactic.Apply_Method mI)))
237 | find_next_step' p _ _ _ _ _ _ = raise ERROR ("find_next_step': uncovered case with " ^ Pos.pos_2str p)
239 fun by_tactic' sel ct (pt, pos as (p, Pos.Met)) =
241 val (met, oris, (dI', pI', mI'), pbl, (dI, pI, mI), ctxt) = Specification.get_data (pt, pos)
242 val thy = if dI = ThyC.id_empty then ThyC.get_theory dI' else ThyC.get_theory dI
243 val cpI = if pI = Problem.id_empty then pI' else pI
244 val cmI = if mI = Method.id_empty then mI' else mI
245 val {ppc, pre, prls, ...} = Method.from_store cmI
247 case I_Model.check_single ctxt sel oris met ppc ct of
248 I_Model.Add itm => (*..union old input *)
250 val met' = I_Model.add_single thy itm met
251 val tac' = I_Model.get_tac sel (ct, met')
253 case Specify_Step.add tac' (Istate_Def.Uistate, ctxt) (pt, (p, Pos.Met)) of
254 ((p, Pos.Met), _, _, pt') => (p, pt')
255 | _ => raise ERROR "by_tactic': uncovered case of generate1"
256 val pre' = Pre_Conds.check' thy prls pre met'
257 val pb = foldl and_ (true, map fst pre')
258 val (p_, _) = find_next_step' Pos.Met pb oris (dI',pI',mI') (pbl,met')
259 ((#ppc o Problem.from_store) cpI,ppc) (dI,pI,mI);
261 ("ok", ([], [], (pt', (p, p_))))
265 val pre' = Pre_Conds.check' thy prls pre met
266 val pb = foldl and_ (true, map fst pre')
267 val (p_, _) = find_next_step' Pos.Met pb oris (dI',pI',mI') (pbl,met)
268 ((#ppc o Problem.from_store) cpI,(#ppc o Method.from_store) cmI) (dI,pI,mI);
270 (msg, ([], [], (pt, (p, p_))))
273 | by_tactic' sel ct (pt, pos as (p, _(*Frm, Pbl*))) =
275 val (met, oris, (dI', pI', mI'), pbl, (dI, pI, mI), ctxt) = Specification.get_data (pt, pos)
276 val thy = if dI = ThyC.id_empty then ThyC.get_theory dI' else ThyC.get_theory dI
277 val cpI = if pI = Problem.id_empty then pI' else pI
278 val cmI = if mI = Method.id_empty then mI' else mI
279 val {ppc, where_, prls, ...} = Problem.from_store cpI
281 case I_Model.check_single ctxt sel oris pbl ppc ct of
282 I_Model.Add itm => (*..union old input *)
284 val pbl' = I_Model.add_single thy itm pbl
285 val tac' = I_Model.get_tac sel (ct, pbl')
287 case Specify_Step.add tac' (Istate_Def.Uistate, ctxt) (pt, (p, Pos.Pbl)) of
288 ((p, Pos.Pbl), _, _, pt') => (p, pt')
289 | _ => raise ERROR "by_tactic': uncovered case of Specify_Step.add"
290 (* only for getting final p_ ..*)
291 val pre = Pre_Conds.check' thy prls where_ pbl';
292 val pb = foldl and_ (true, map fst pre);
293 val (p_, _) = find_next_step' Pos.Pbl pb oris (dI',pI',mI')
294 (pbl',met) (ppc, (#ppc o Method.from_store) cmI) (dI, pI, mI);
296 ("ok", ([], [], (pt', (p, p_))))
300 val pre = Pre_Conds.check' thy prls where_ pbl
301 val pb = foldl and_ (true, map fst pre)
302 val (p_, _(*Tactic.input*)) = find_next_step' Pos.Pbl pb oris (dI', pI', mI')
303 (pbl, met) (ppc, (#ppc o Method.from_store) cmI) (dI, pI, mI)
305 (msg, ([], [], (pt, (p, p_))))
309 (*FIXME.WN110515 declare_constraints for ct (without dsc) into PblObj{ctxt, ...}
310 -- for input from scratch*)
311 fun by_tactic_input' sel ct (ptp as (pt, (p, Pos.Pbl))) =
313 val (oris, dI', pI', dI, pI, pbl, ctxt) = case Ctree.get_obj I pt p of
314 Ctree.PblObj {origin = (oris, (dI', pI', _), _), spec = (dI, pI, _), probl = pbl, ctxt, ...} =>
315 (oris, dI', pI', dI, pI, pbl, ctxt)
316 | _ => raise ERROR "specify (Specify_Theory': uncovered case get_obj"
317 val thy = if dI = ThyC.id_empty then ThyC.get_theory dI' else ThyC.get_theory dI;
318 val cpI = if pI = Problem.id_empty then pI' else pI;
320 case I_Model.check_single ctxt sel oris pbl ((#ppc o Problem.from_store) cpI) ct of
321 I_Model.Add itm (*..union old input *) =>
323 val pbl' = I_Model.add_single thy itm pbl
324 val (tac, tac_) = case sel of
325 "#Given" => (Tactic.Add_Given ct, Tactic.Add_Given' (ct, pbl'))
326 | "#Find" => (Tactic.Add_Find ct, Tactic.Add_Find' (ct, pbl'))
327 | "#Relate"=> (Tactic.Add_Relation ct, Tactic.Add_Relation'(ct, pbl'))
328 | sel => raise ERROR ("by_tactic_input': uncovered case of" ^ sel)
330 case Specify_Step.add tac_ (Istate_Def.Uistate, ctxt) (pt, (p, Pos.Pbl)) of
331 ((p, Pos.Pbl), c, _, pt') => (p, c, pt')
332 | _ => raise ERROR "by_tactic_input': uncovered case generate1"
334 ([(tac, tac_, ((p, Pos.Pbl), (Istate_Def.Uistate, ctxt)))], c, (pt', (p, Pos.Pbl)))
336 | I_Model.Err msg => (*TODO.WN03 pass error-msgs to the frontend..
337 FIXME ..and dont abuse a tactic for that purpose*)
338 ([(Tactic.Tac msg, Tactic.Tac_ (ThyC.get_theory "Isac_Knowledge", msg,msg,msg),
339 (Pos.e_pos', (Istate_Def.empty, ContextC.empty)))], [], ptp)
341 | by_tactic_input' sel ct (ptp as (pt, (p, Pos.Met))) =
343 (*NEW* ) *.specify_data ( *NEW*)
344 val (oris, dI', mI', dI, mI, met, ctxt) = case Ctree.get_obj I pt p of
345 Ctree.PblObj {origin = (oris, (dI', _, mI'), _), spec = (dI, _, mI), meth = met,ctxt, ...} =>
346 (oris, dI', mI', dI, mI, met, ctxt)
347 | _ => raise ERROR "by_tactic_input' Met: uncovered case get_obj"
348 (*NEW* ) References.select ( *NEW*)
349 val thy = if dI = ThyC.id_empty then ThyC.get_theory dI' else ThyC.get_theory dI;
350 val cmI = if mI = Method.id_empty then mI' else mI;
352 case I_Model.check_single ctxt sel oris met ((#ppc o Method.from_store) cmI) ct of
353 I_Model.Add itm (*..union old input *) =>
355 val met' = I_Model.add_single thy itm met;
356 val (tac,tac_) = case sel of
357 "#Given" => (Tactic.Add_Given ct, Tactic.Add_Given' (ct, met'))
358 | "#Find" => (Tactic.Add_Find ct, Tactic.Add_Find' (ct, met'))
359 | "#Relate"=> (Tactic.Add_Relation ct, Tactic.Add_Relation'(ct, met'))
360 | sel => raise ERROR ("by_tactic_input' Met: uncovered case of" ^ sel)
362 case Specify_Step.add tac_ (Istate_Def.Uistate, ctxt) (pt, (p, Pos.Met)) of
363 ((p, Pos.Met), c, _, pt') => (p, c, pt')
364 | _ => raise ERROR "by_tactic_input': uncovered case generate1 (WARNING WHY ?)"
366 ([(tac, tac_, ((p, Pos.Met), (Istate_Def.Uistate, ctxt)))], c, (pt', (p, Pos.Met)))
368 | I_Model.Err _ => ([(*tacis*)], [], ptp) (*nxt_me collects tacis until not hide; here just no progress*)
370 | by_tactic_input' _ _ (_, p) = raise ERROR ("by_tactic_input' not impl. for" ^ Pos.pos'2str p)
372 (* complete _NON_empty calc-head for autocalc (sub-)pbl from oris
373 + met from fmz; assumes pos on PblObj, meth = [] *)
374 fun finish_phase (pt, pos as (p, p_)) =
376 val _ = if p_ <> Pos.Pbl
377 then raise ERROR ("###finish_phase: only impl.for Pbl, called with " ^ Pos.pos'2str pos)
379 val (oris, ospec, probl, spec) = case Ctree.get_obj I pt p of
380 Ctree.PblObj {origin = (oris, ospec, _), probl, spec, ...} => (oris, ospec, probl, spec)
381 | _ => raise ERROR "finish_phase: unvered case get_obj"
382 val (_, pI, mI) = References.select ospec spec
383 val mpc = (#ppc o Method.from_store) mI
384 val ppc = (#ppc o Problem.from_store) pI
385 val (pits, mits) = I_Model.complete_method (oris, mpc, ppc, probl)
386 val pt = Ctree.update_pblppc pt p pits
387 val pt = Ctree.update_metppc pt p mits
388 in (pt, (p, Pos.Met)) end
390 (* do all specification in one single step:
391 complete calc-head for autocalc (sub-)pbl from oris (+ met from fmz);
392 oris and spec (incl. pbl-refinement) given from init_calc or SubProblem
394 fun do_all (pt, (p, _)) =
396 val (pors, dI, pI, mI) = case Ctree.get_obj I pt p of
397 Ctree.PblObj {origin = (pors, (dI, pI, mI), _), ...}
398 => (pors, dI, pI, mI)
399 | _ => raise ERROR "do_all: uncovered case get_obj"
400 val {ppc, ...} = Method.from_store mI
401 val (_, vals) = O_Model.values' pors
402 val ctxt = ContextC.initialise dI vals
403 val (pt, _) = Ctree.cupdate_problem pt p ((dI, pI, mI),
404 map (I_Model.complete' ppc) pors, map (I_Model.complete' ppc) pors, ctxt)