intermed. ctxt ..: Add_Given doesnt work due to wrong ctxt in Subproblem
cleanup before getting ctxt into Subproblem usable for x+1=2
1 (* Title: Specify-phase: specifying and modeling a problem or a subproblem. The
2 most important types are declared in mstools.sml.
3 Author: Walther Neuper 991122, Mathias Lehnfeld
4 (c) due to copyright terms
6 12345678901234567890123456789012345678901234567890123456789012345678901234567890
7 10 20 30 40 50 60 70 80
10 (* TODO interne Funktionen aus sig entfernen *)
13 datatype additm = Add of SpecifyTools.itm | Err of string
14 val all_dsc_in : SpecifyTools.itm_ list -> Term.term list
15 val all_modspec : ptree * pos' -> ptree * pos'
16 datatype appl = Appl of tac_ | Notappl of string
20 SpecifyTools.ori list ->
21 SpecifyTools.itm list ->
22 (string * (Term.term * Term.term)) list -> cterm' -> additm
25 val chk_vars : term ppc -> string * Term.term list
27 theory -> int * term list * term list -> term
29 theory -> term list * term list -> term list
30 val complete_metitms :
31 SpecifyTools.ori list ->
32 SpecifyTools.itm list ->
33 SpecifyTools.itm list -> pat list -> SpecifyTools.itm list
34 val complete_mod_ : ori list * pat list * pat list * itm list ->
36 val complete_mod : ptree * pos' -> ptree * (pos * pos_)
37 val complete_spec : ptree * pos' -> ptree * pos'
39 pat list -> preori list -> pat -> preori
40 val e_calcstate : calcstate
41 val e_calcstate' : calcstate'
42 val eq1 : ''a -> 'b * (''a * 'c) -> bool
44 ''a -> Term.term -> 'b * 'c * 'd * ''a * SpecifyTools.itm_ -> bool
45 val eq4 : ''a -> 'b * ''a list * 'c * 'd * 'e -> bool
47 'a * 'b * 'c * 'd * SpecifyTools.itm_ ->
48 'e * 'f * 'g * Term.term * 'h -> bool
49 val eq_dsc : SpecifyTools.itm * SpecifyTools.itm -> bool
50 val eq_pos' : ''a * pos_ -> ''a * pos_ -> bool
51 val f_mout : theory -> mout -> Term.term
53 SpecifyTools.ori list ->
54 SpecifyTools.itm list -> SpecifyTools.ori list
56 SpecifyTools.ori list ->
57 ('a * (Term.term * 'b)) list -> SpecifyTools.ori list
58 val foldl1 : ('a * 'a -> 'a) -> 'a list -> 'a
59 val foldr1 : ('a * 'a -> 'a) -> 'a list -> 'a
60 val form : 'a -> ptree -> (string * ('a * pos_) * Term.term) list
61 val formres : 'a -> ptree -> (string * ('a * pos_) * Term.term) list
62 val gen_ins' : ('a * 'a -> bool) -> 'a * 'a list -> 'a list
64 (string * (pos * pos_) * Term.term) list list ->
65 pos -> ptree list -> (string * (pos * pos_) * Term.term) list
67 (string * (pos * pos_) * Term.term) list list ->
68 posel list -> ptree list -> (string * (pos * pos_) * Term.term) list
69 val get_interval : pos' -> pos' -> int -> ptree -> (pos' * term) list
70 val get_ocalhd : ptree * pos' -> ocalhd
71 val get_spec_form : tac_ -> pos' -> ptree -> mout
74 SpecifyTools.ori -> SpecifyTools.itm -> string * cterm'
75 val getr_ct : theory -> SpecifyTools.ori -> string * cterm'
76 val has_list_type : Term.term -> bool
77 val header : pos_ -> pblID -> metID -> pblmet
80 int * SpecifyTools.vats * bool * string * SpecifyTools.itm_ ->
81 SpecifyTools.itm list -> SpecifyTools.itm list
83 SpecifyTools.itm -> SpecifyTools.itm list -> SpecifyTools.itm list
84 val is_complete_mod : ptree * pos' -> bool
85 val is_complete_mod_ : SpecifyTools.itm list -> bool
86 val is_complete_modspec : ptree * pos' -> bool
87 val is_complete_spec : ptree * pos' -> bool
88 val is_copy_named : 'a * ('b * Term.term) -> bool
89 val is_copy_named_idstr : string -> bool
90 val is_error : SpecifyTools.itm_ -> bool
91 val is_field_correct : ''a -> ''b -> (''a * ''b list) list -> bool
95 SpecifyTools.ori list ->
96 Term.term -> string * SpecifyTools.ori * Term.term list
97 val is_list_type : Term.typ -> bool
100 SpecifyTools.itm list ->
103 ('a * (Term.term * Term.term)) list -> string * SpecifyTools.itm
104 val is_parsed : SpecifyTools.itm_ -> bool
105 val is_untouched : SpecifyTools.itm -> bool
110 (int list * string * Term.term * Term.term list) list ->
111 (int list * string * Term.term * Term.term list) list
113 theory -> pat list -> Term.term list -> SpecifyTools.ori list
114 val maxl : int list -> int
115 val match_ags_msg : string list -> Term.term -> Term.term list -> unit
116 val memI : ''a list -> ''a -> bool
117 val mk_additem : string -> cterm' -> tac
118 val mk_delete : theory -> string -> SpecifyTools.itm_ -> tac
120 theory -> pat -> Term.term -> SpecifyTools.preori option
123 SpecifyTools.ori list ->
124 (string * (Term.term * 'a)) list ->
125 SpecifyTools.itm list -> (string * cterm') option
126 val nxt_model_pbl : tac_ -> ptree * (int list * pos_) -> tac_
130 SpecifyTools.ori list ->
132 SpecifyTools.itm list * SpecifyTools.itm list ->
133 (string * (Term.term * 'a)) list * (string * (Term.term * 'b)) list ->
135 val nxt_specif : tac -> ptree * (int list * pos_) -> calcstate'
136 val nxt_specif_additem :
137 string -> cterm' -> ptree * (int list * pos_) -> calcstate'
138 val nxt_specify_init_calc : fmz -> calcstate
139 val ocalhd_complete :
140 SpecifyTools.itm list ->
141 (bool * Term.term) list -> domID * pblID * metID -> bool
143 pat list -> ori -> itm
146 Term.term -> Term.term list -> SpecifyTools.ori -> SpecifyTools.itm
149 int * SpecifyTools.vats * bool * string * SpecifyTools.itm_ ->
150 SpecifyTools.itm list ->
151 (int * SpecifyTools.vats * bool * string * SpecifyTools.itm_) list
152 val parse_ok : SpecifyTools.itm_ list -> bool
153 val posform2str : pos' * ptform -> string
154 val posforms2str : (pos' * ptform) list -> string
155 val posterms2str : (pos' * term) list -> string (*tests only*)
156 val ppc135list : 'a SpecifyTools.ppc -> 'a list
157 val ppc2list : 'a SpecifyTools.ppc -> 'a list
159 ptree * (int list * pos_) ->
160 ptform * tac option * Term.term list
161 val pt_form : ppobj -> ptform
162 val pt_model : ppobj -> pos_ -> ptform
163 val reset_calchead : ptree * pos' -> ptree * pos'
167 Term.term * Term.term list ->
168 (int * SpecifyTools.vats * string * Term.term * Term.term list) list
169 -> string * SpecifyTools.ori * Term.term list
174 (int * SpecifyTools.vats * string * Term.term * Term.term list) list
175 -> string * SpecifyTools.ori * Term.term list
177 int -> SpecifyTools.itm list -> SpecifyTools.itm option
178 val show_pt : ptree -> unit
179 val some_spec : spec -> spec -> spec
185 (posel list * pos_) * ((posel list * pos_) * istate) * mout * tac *
187 val specify_additem :
193 (pos * pos_) * ((pos * pos_) * istate) * mout * tac * safe * ptree
194 val tag_form : theory -> term * term -> term
195 val test_types : Proof.context -> Term.term * Term.term list -> string
196 val typeless : Term.term -> Term.term
197 val unbound_ppc : term SpecifyTools.ppc -> Term.term list
198 val vals_of_oris : SpecifyTools.ori list -> Term.term list
199 val variants_in : Term.term list -> int
200 val vars_of_pbl_ : ('a * ('b * Term.term)) list -> Term.term list
201 val vars_of_pbl_' : ('a * ('b * Term.term)) list -> Term.term list
208 structure CalcHead (**): CALC_HEAD(**) =
214 (*.the state wich is stored after each step of calculation; it contains
215 the calc-state and a list of [tac,istate](="tacis") to be applied next.
216 the last_elem tacis is the first to apply to the calc-state and
217 the (only) one shown to the front-end as the 'proposed tac'.
218 the calc-state resulting from the application of tacis is not stored,
219 because the tacis hold enough information for efficiently rebuilding
220 this state just by "fun generate ".*)
222 (ptree * pos') * (*the calc-state to which the tacis could be applied*)
223 (taci list); (*ev. several (hidden) steps;
224 in REVERSE order: first tac_ to apply is last_elem*)
225 val e_calcstate = ((EmptyPtree, e_pos'), [e_taci]):calcstate;
227 (*the state used during one calculation within the mathengine; it contains
228 a list of [tac,istate](="tacis") which generated the the calc-state;
229 while this state's tacis are extended by each (internal) step,
230 the calc-state is used for creating new nodes in the calc-tree
231 (eg. applicable_in requires several particular nodes of the calc-tree)
232 and then replaced by the the newly created;
233 on leave of the mathengine the resuing calc-state is dropped anyway,
234 because the tacis hold enought information for efficiently rebuilding
235 this state just by "fun generate ".*)
237 taci list * (*cas. several (hidden) steps;
238 in REVERSE order: first tac_ to apply is last_elem*)
239 pos' list * (*a "continuous" sequence of pos',
240 deleted by application of taci list*)
241 (ptree * pos'); (*the calc-state resulting from the application of tacis*)
242 val e_calcstate' = ([e_taci], [e_pos'], (EmptyPtree, e_pos')):calcstate';
244 (*FIXXXME.WN020430 intermediate hack for fun ass_up*)
245 fun f_mout thy (Form' (FormKF (_,_,_,_,f))) = (term_of o the o (parse thy)) f
246 | f_mout thy _ = error "f_mout: not called with formula";
249 (*.is the calchead complete ?.*)
250 fun ocalhd_complete (its: itm list) (pre: (bool * term) list) (dI,pI,mI) =
251 foldl and_ (true, map #3 its) andalso
252 foldl and_ (true, map #1 pre) andalso
253 dI<>e_domID andalso pI<>e_pblID andalso mI<>e_metID;
256 (* make a term 'typeless' for comparing with another 'typeless' term;
257 'type-less' usually is illtyped *)
258 fun typeless (Const(s,_)) = (Const(s,e_type))
259 | typeless (Free(s,_)) = (Free(s,e_type))
260 | typeless (Var(n,_)) = (Var(n,e_type))
261 | typeless (Bound i) = (Bound i)
262 | typeless (Abs(s,_,t)) = Abs(s,e_type, typeless t)
263 | typeless (t1 $ t2) = (typeless t1) $ (typeless t2);
265 > val (SOME ct) = parse thy "max_relation (A=#2*a*b - a^^^#2)";
266 > val (_,t1) = split_dsc_t hs (term_of ct);
267 > val (SOME ct) = parse thy "A=#2*a*b - a^^^#2";
268 > val (_,t2) = split_dsc_t hs (term_of ct);
269 > typeless t1 = typeless t2;
275 (*.to an input (d,ts) find the according ori and insert the ts.*)
276 (*WN.11.03: + dont take first inter<>[]*)
277 fun seek_oridts ctxt sel (d,ts) [] =
278 ("seek_oridts: input ('" ^
279 (Print_Mode.setmp [] (Syntax.string_of_term ctxt) (comp_dts (d,ts))) ^
280 "') not found in oris (typed)",
283 | seek_oridts ctxt sel (d,ts) ((id, vat, sel', d', ts')::oris) =
284 if sel = sel' andalso d = d' andalso (inter op = ts ts') <> [] then
285 ("", (id, vat, sel, d, inter op = ts ts'), ts') else
286 seek_oridts ctxt sel (d, ts) oris;
288 (*.to an input (_,ts) find the according ori and insert the ts.*)
289 fun seek_orits ctxt sel ts [] =
290 ("seek_orits: input (_, '" ^ strs2str (map (Print_Mode.setmp [](Syntax.string_of_term
292 "') not found in oris (typed)", e_ori_, [])
293 | seek_orits ctxt sel ts ((id,vat,sel',d,ts')::(oris:ori list)) =
294 if sel = sel' andalso (inter op = ts ts') <> []
297 (id,vat,sel,d, inter op = ts ts'):ori,
299 else (((strs2str' o map (Print_Mode.setmp [] (Syntax.string_of_term
304 else seek_orits ctxt sel ts oris;
306 > val ((id,vat,sel',d,ts')::(ori':ori)) = ori;
307 > seek_orits thy sel ts [(id,vat,sel',d,ts')];
308 uncaught exception TYPE
309 > seek_orits thy sel ts [];
310 uncaught exception TYPE
313 (*find_first item with #1 equal to id*)
314 fun seek_ppc id [] = NONE
315 | seek_ppc id (p::(ppc:itm list)) =
316 if id = #1 p then SOME p else seek_ppc id ppc;
320 (*---------------------------------------------(3) nach ptyps.sml 23.3.02*)
323 datatype appl = Appl of tac_ | Notappl of string;
325 fun ppc2list ({Given=gis,Where=whs,Find=fis,
326 With=wis,Relate=res}: 'a ppc) =
327 gis @ whs @ fis @ wis @ res;
328 fun ppc135list ({Given=gis,Find=fis,Relate=res,...}: 'a ppc) =
334 (* get the number of variants in a problem in 'original',
335 assumes equal descriptions in immediate sequence *)
337 let fun eq(x,y) = head_of x = head_of y;
338 fun cnt eq [] y n = ([n],[])
339 | cnt eq (x::xs) y n = if eq(x,y) then cnt eq xs y (n+1)
341 fun coll eq xs [] = xs
342 | coll eq xs (y::ys) =
343 let val (n,ys') = cnt eq (y::ys) y 0;
344 in if ys' = [] then xs @ n else coll eq (xs @ n) ys' end;
345 val vts = subtract op = [1] (distinct (coll eq [] ts));
346 in case vts of [] => 1 | [n] => n
347 | _ => error "different variants in formalization" end;
349 > cnt (op=) [2,2,2,4,5,5,5,5,5] 2 0;
350 val it = ([3],[4,5,5,5,5,5]) : int list * int list
351 > coll (op=) [] [1,2,2,2,4,5,5,5,5,5];
352 val it = [1,3,1,5] : int list
355 fun is_list_type (Type("List.list",_)) = true
356 | is_list_type _ = false;
357 (* fun destr (Type(str,sort)) = (str,sort);
358 > val (SOME ct) = parse thy "lll::real list";
359 > val ty = (#T o rep_cterm) ct;
363 val it = ("List.list",["RealDef.real"]) : string * typ list
364 > atomty ((#t o rep_cterm) ct);
366 *** Free ( lll, real list)
369 > val (SOME ct) = parse thy "[lll::real]";
370 > val ty = (#T o rep_cterm) ct;
374 val it = ("List.list",["'a"]) : string * typ list
375 > atomty ((#t o rep_cterm) ct);
377 *** Const ( List.list.Cons, [real, real list] => real list)
378 *** Free ( lll, real)
379 *** Const ( List.list.Nil, real list)
381 > val (SOME ct) = parse thy "lll";
382 > val ty = (#T o rep_cterm) ct;
384 val it = false : bool *)
387 fun has_list_type (Free(_,T)) = is_list_type T
388 | has_list_type _ = false;
390 > val (SOME ct) = parse thy "lll::real list";
391 > has_list_type (term_of ct);
393 > val (SOME ct) = parse thy "[lll::real]";
394 > has_list_type (term_of ct);
395 val it = false : bool *)
397 fun is_parsed (Syn _) = false
398 | is_parsed _ = true;
399 fun parse_ok its = foldl and_ (true, map is_parsed its);
401 fun all_dsc_in itm_s =
403 fun d_in (Cor ((d,_),_)) = [d]
406 | d_in (Inc ((d,_),_)) = [d]
407 | d_in (Sup (d,_)) = [d]
408 | d_in (Mis (d,_)) = [d];
409 in (flat o (map d_in)) itm_s end;
412 fun is_Syn (Syn _) = true
413 | is_Syn (Typ _) = true
416 fun is_error (Cor (_,ts)) = false
417 | is_error (Sup (_,ts)) = false
418 | is_error (Inc (_,ts)) = false
419 | is_error (Mis (_,ts)) = false
423 fun ct_in (Syn (c)) = c
424 | ct_in (Typ (c)) = c
425 | ct_in _ = error "ct_in called for Cor .. Sup";
428 (*#############################################################*)
429 (*#############################################################*)
430 (* vvv--- aus nnewcode.sml am 30.1.00 ---vvv *)
433 (* testdaten besorgen:
434 use"test-coil-kernel.sml";
435 val (PblObj{origin=(oris,_,_),meth={ppc=itms,...},...}) =
440 variant V: oris union ppc => int, id ID: oris union ppc => int
443 EX vt:V. ALL r:oris --> EX i:ppc. ID r = ID i & complete i
446 @vt = max sum(i : ppc) V i
452 > ((vts_cnt (vts_in itms))) itms;
457 > val vts = vts_in itms;
458 val vts = [1,2,3] : int list
459 > val nvts = vts_cnt vts itms;
460 val nvts = [(1,6),(2,5),(3,7)] : (int * int) list
461 > val mx = max2 nvts;
462 val mx = (3,7) : int * int
463 > val v = max_vt itms;
465 --------------------------
469 (*.get the first term in ts from ori.*)
470 (* val (_,_,fd,d,ts) = hd miss;
472 fun getr_ct thy ((_, _, fd, d, ts) : ori) =
473 (fd, (Print_Mode.setmp [] (Syntax.string_of_term (thy2ctxt thy)) o
474 comp_dts) (d,[hd ts]) : cterm');
475 (* val t = comp_dts (d,[hd ts]);
478 (* get a term from ori, notyet input in itm.
479 the term from ori is thrown back to a string in order to reuse
480 machinery for immediate input by the user. *)
481 fun geti_ct thy ((_, _, _, d, ts) : ori) ((_, _, _, fd, itm_) : itm) =
482 (fd, Print_Mode.setmp [] ((Syntax.string_of_term (thy2ctxt thy)) o comp_dts)
483 (d, subtract op = (ts_in itm_) ts) : cterm');
484 fun geti_ct thy ((_, _, _, d, ts) : ori) ((_, _, _, fd, itm_) : itm) =
485 (fd, Print_Mode.setmp [] ((Syntax.string_of_term (thy2ctxt thy)) o comp_dts)
486 (d, subtract op = (ts_in itm_) ts) : cterm');
488 (* in FE dsc, not dat: this is in itms ...*)
489 fun is_untouched ((_,_,false,_,Inc((_,[]),_)):itm) = true
490 | is_untouched _ = false;
493 (* select an item in oris, notyet input in itms
494 (precondition: in itms are only Cor, Sup, Inc) *)
497 | x mem (y :: ys) = x = y orelse x mem ys;
499 fun nxt_add thy ([]:ori list) pbt itms = (*root (only) ori...fmz=[]*)
501 fun test_d d ((i,_,_,_,itm_):itm) = (d = (d_in itm_)) andalso i<>0;
502 fun is_elem itms (f,(d,t)) =
503 case find_first (test_d d) itms of
504 SOME _ => true | NONE => false;
505 in case filter_out (is_elem itms) pbt of
506 (* val ((f,(d,_))::itms) = filter_out (is_elem itms) pbt;
510 ((Print_Mode.setmp [] (Syntax.string_of_term (thy2ctxt thy))) o
511 comp_dts) (d, []) : cterm')
514 (* val (thy,itms) = (assoc_thy (if dI=e_domID then dI' else dI),pbl);
516 | nxt_add thy oris pbt itms =
518 fun testr_vt v ori = (curry (op mem) v) (#2 (ori:ori))
519 andalso (#3 ori) <>"#undef";
520 fun testi_vt v itm = (curry (op mem) v) (#2 (itm:itm));
521 fun test_id ids r = curry (op mem) (#1 (r:ori)) ids;
522 fun test_subset (itm:itm) ((_,_,_,d,ts):ori) =
523 (d_in (#5 itm)) = d andalso subset op = (ts_in (#5 itm), ts);
524 fun false_and_not_Sup((i,v,false,f,Sup _):itm) = false
525 | false_and_not_Sup (i,v,false,f, _) = true
526 | false_and_not_Sup _ = false;
528 val v = if itms = [] then 1 else max_vt itms;
529 val vors = if v = 0 then oris else filter (testr_vt v) oris;(*oris..vat*)
530 val vits = if v = 0 then itms (*because of dsc without dat*)
531 else filter (testi_vt v) itms; (*itms..vat*)
532 val icl = filter false_and_not_Sup vits; (* incomplete *)
534 then case filter_out (test_id (map #1 vits)) vors of
536 (* val miss = filter_out (test_id (map #1 vits)) vors;
538 | miss => SOME (getr_ct thy (hd miss))
540 case find_first (test_subset (hd icl)) vors of
541 (* val SOME ori = find_first (test_subset (hd icl)) vors;
543 NONE => error "nxt_add: EX itm. not(dat(itm)<=dat(ori))"
544 | SOME ori => SOME (geti_ct thy ori (hd icl))
550 fun mk_delete thy "#Given" itm_ = Del_Given (itm_out thy itm_)
551 | mk_delete thy "#Find" itm_ = Del_Find (itm_out thy itm_)
552 | mk_delete thy "#Relate" itm_ = Del_Relation(itm_out thy itm_)
553 | mk_delete thy str _ =
554 error ("mk_delete: called with field '"^str^"'");
555 fun mk_additem "#Given" ct = Add_Given ct
556 | mk_additem "#Find" ct = Add_Find ct
557 | mk_additem "#Relate"ct = Add_Relation ct
559 error ("mk_additem: called with field '"^str^"'");
562 (* determine the next step of specification;
563 not done here: Refine_Tacitly (otherwise *** unknown method: (..., no_met))
564 eg. in rootpbl 'no_met':
566 preok predicates are _all_ ok (and problem matches completely)
567 oris immediately from formalization
568 (dI',pI',mI') specification coming from author/parent-problem
569 (pbl, item lists specified by user
570 met) -"-, tacitly completed by copy_probl
571 (dI,pI,mI) specification explicitly done by the user
572 (pbt, mpc) problem type, guard of method
574 fun nxt_spec Pbl preok (oris : ori list) ((dI', pI', mI') : spec)
575 ((pbl : itm list), (met : itm list)) (pbt, mpc) ((dI, pI, mI) : spec) =
576 ((*tracing"### nxt_spec Pbl";*)
577 if dI' = e_domID andalso dI = e_domID then (Pbl, Specify_Theory dI')
578 else if pI' = e_pblID andalso pI = e_pblID then (Pbl, Specify_Problem pI')
579 else case find_first (is_error o #5) (pbl:itm list) of
580 SOME (_, _, _, fd, itm_) =>
582 (assoc_thy (if dI = e_domID then dI' else dI)) fd itm_)
584 ((*tracing"### nxt_spec is_error NONE";*)
585 case nxt_add (assoc_thy (if dI = e_domID then dI' else dI))
587 SOME (fd,ct') => ((*tracing"### nxt_spec nxt_add SOME";*)
588 (Pbl, mk_additem fd ct'))
589 | NONE => (*pbl-items complete*)
590 if not preok then (Pbl, Refine_Problem pI')
592 if dI = e_domID then (Pbl, Specify_Theory dI')
593 else if pI = e_pblID then (Pbl, Specify_Problem pI')
594 else if mI = e_metID then (Pbl, Specify_Method mI')
596 case find_first (is_error o #5) met of
597 SOME (_,_,_,fd,itm_) =>
598 (Met, mk_delete (assoc_thy dI) fd itm_)
600 (case nxt_add (assoc_thy dI) oris mpc met of
601 SOME (fd,ct') => (*30.8.01: pre?!?*)
602 (Met, mk_additem fd ct')
604 ((*Solv 3.4.00*)Met, Apply_Method mI))))
606 | nxt_spec Met preok oris (dI',pI',mI') (pbl, met) (pbt,mpc) (dI,pI,mI) =
607 ((*tracing"### nxt_spec Met"; *)
608 case find_first (is_error o #5) met of
609 SOME (_,_,_,fd,itm_) =>
610 (Met, mk_delete (assoc_thy (if dI=e_domID then dI' else dI)) fd itm_)
612 case nxt_add (assoc_thy (if dI=e_domID then dI' else dI))oris mpc met of
613 SOME (fd,ct') => (Met, mk_additem fd ct')
615 ((*tracing"### nxt_spec Met: nxt_add NONE";*)
616 if dI = e_domID then (Met, Specify_Theory dI')
617 else if pI = e_pblID then (Met, Specify_Problem pI')
618 else if not preok then (Met, Specify_Method mI)
619 else (Met, Apply_Method mI)));
622 val itms = [(1,[1],true,"#Find",Cor(e_term,[e_term])):itm,
623 (2,[2],true,"#Find",Syn("empty"))];
626 fun is_field_correct sel d dscpbt =
627 case assoc (dscpbt, sel) of
629 | SOME ds => member op = ds d;
631 (*. update the itm_ already input, all..from ori .*)
632 (* val (id,vt,fd,d,ts) = (i,v,f,d,ts\\ts');
634 fun ori_2itm itm_ pid all ((id,vt,fd,d,ts):ori) =
636 val ts' = union op = (ts_in itm_) ts;
637 val pval = pbl_ids' d ts'
638 (*WN.9.5.03: FIXXXME [#0, epsilon]
639 here would upd_penv be called for [#0, epsilon] etc. *)
640 val complete = if eq_set op = (ts', all) then true else false;
643 (if fd = "#undef" then (id,vt,complete,fd,Sup(d,ts'))
644 else (id,vt,complete,fd,Cor((d,ts'),(pid, pval)))):itm
645 | (Syn c) => error ("ori_2itm wants to overwrite "^c)
646 | (Typ c) => error ("ori_2itm wants to overwrite "^c)
647 | (Inc _) => if complete
648 then (id,vt,true ,fd, Cor ((d,ts'),(pid, pval)))
649 else (id,vt,false,fd, Inc ((d,ts'),(pid, pval)))
650 | (Sup ((*_,_*)d,ts')) => (*4.9.01 lost env*)
651 (*if fd = "#undef" then*) (id,vt,complete,fd,Sup(d,ts'))
652 (*else (id,vt,complete,fd,Cor((d,ts'),e))*)
653 (* 28.1.00: not completely clear ---^^^ etc.*)
654 (* 4.9.01: Mis just copied---vvv *)
655 | (Mis _) => if complete
656 then (id,vt,true ,fd, Cor ((d,ts'),(pid, pval)))
657 else (id,vt,false,fd, Inc ((d,ts'),(pid, pval)))
661 fun eq1 d (_,(d',_)) = (d = d');
662 fun eq3 f d (_,_,_,f',itm_) = f = f' andalso d = (d_in itm_);
665 (* 'all' ts from ori; ts is the input; (ori carries rest of info)
666 9.01: this + ori_2itm is _VERY UNCLEAR_ ? overhead ?
667 pval: value for problem-environment _NOT_ checked for 'inter' --
668 -- FIXXME.WN.11.03 the generation of penv has to go to insert_ppc
669 (as it has been done for input_icalhd+insert_ppc' in 11.03)*)
670 (*. is_input ori itms <=>
671 EX itm. (1) ori(field,dsc) = itm(field,dsc) & (2..4)
672 (2) ori(ts) subset itm(ts) --- Err "already input"
673 (3) ori(ts) inter itm(ts) = empty --- new: ori(ts)
674 (4) -"- <> empty --- new: ori(ts) \\ inter .*)
675 (* val(itms,(i,v,f,d,ts)) = (ppc,ori');
677 fun is_notyet_input ctxt (itms:itm list) all ((i,v,f,d,ts):ori) pbt =
678 case find_first (eq1 d) pbt of
679 SOME (_,(_,pid)) =>(* val SOME (_,(_,pid)) = find_first (eq1 d) pbt;
680 val SOME (_,_,_,_,itm_)=find_first (eq3 f d) itms;
682 (case find_first (eq3 f d) itms of
683 SOME (_,_,_,_,itm_) =>
685 val ts' = inter op = (ts_in itm_) ts;
686 in if subset op = (ts, ts')
688 map (Print_Mode.setmp [] (Syntax.string_of_term ctxt))) ts') ^
689 " already input", e_itm) (*2*)
691 ori_2itm itm_ pid all (i,v,f,d,
692 subtract op = ts' ts)) (*3,4*)
694 | NONE => ("", ori_2itm (Inc ((e_term,[]),(pid,[])))
695 pid all (i,v,f,d,ts)) (*1*)
697 | NONE => ("", ori_2itm (Sup (d,ts))
698 e_term all (i,v,f,d,ts));
700 fun test_types ctxt (d,ts) =
702 (*val s = !show_types; val _ = show_types:= true;*)
703 val opt = (try comp_dts) (d,ts);
704 val msg = case opt of
706 | NONE => ((Print_Mode.setmp [] (Syntax.string_of_term ctxt) d) ^
708 ((strs2str' o map (Print_Mode.setmp [] (Syntax.string_of_term
711 (*val _ = show_types:= s*)
716 fun maxl [] = error "maxl of []"
719 | mx x (y::ys) = if x < (y:int) then mx y ys else mx x ys
723 (*. is the input term t known in oris ?
724 give feedback on all(?) strange input;
725 return _all_ terms already input to this item (e.g. valuesFor a,b) .*)
726 fun is_known ctxt sel ori t =
728 val _ = tracing ("RM is_known: t=" ^ term2str t);
729 val ots = (distinct o flat o (map #5)) (ori:ori list);
730 val oids = ((map (fst o dest_Free)) o distinct o
731 flat o (map vars)) ots;
732 val (d, ts) = split_dts t;
733 val ids = map (fst o dest_Free)
734 ((distinct o (flat o (map vars))) ts);
735 in if (subtract op = oids ids) <> []
736 then (("identifiers "^(strs2str' (subtract op = oids ids)) ^
737 " not in example"), e_ori_, [])
741 if not (subset op = (map typeless ts, map typeless ots))
742 then (("terms '" ^ ((strs2str' o
743 (map (Print_Mode.setmp [] (Syntax.string_of_term ctxt)))) ts) ^
744 "' not in example (typeless)"), e_ori_, [])
746 (case seek_orits ctxt sel ts ori of
747 ("", ori_ as (_,_,_,d,ts), all) =>
748 (case test_types ctxt (d,ts) of
749 "" => ("", ori_, all)
750 | msg => (msg, e_ori_, []))
751 | (msg,_,_) => (msg, e_ori_, []))
753 if member op = (map #4 ori) d
754 then seek_oridts ctxt sel (d,ts) ori
755 else ((Print_Mode.setmp [] (Syntax.string_of_term ctxt) d) ^
756 " not in example", (0, [], sel, d, ts), [])
760 (*. for return-value of appl_add .*)
763 | Err of string; (*error-message*)
766 (** add an item to the model; check wrt. oris and pbt **)
767 (* in contrary to oris<>[] below, this part handles user-input
768 extremely acceptive, i.e. accept input instead error-msg *)
769 fun appl_add ctxt sel [] ppc pbt ct =
771 val i = 1 + (if ppc = [] then 0 else map #1 ppc |> maxl);
773 case parseNEW ctxt ct of
774 NONE => Add (i, [], false, sel, Syn ct)
776 let val (d, ts) = split_dts t;
779 then Add (i, [], false, sel, Mis (dsc_unknown, hd ts))
781 (case find_first (eq1 d) pbt of
782 NONE => Add (i, [], true, sel, Sup (d,ts))
783 | SOME (f, (_, id)) =>
784 let fun eq2 d (i, _, _, _, itm_) =
785 d = (d_in itm_) andalso i <> 0;
786 in case find_first (eq2 d) ppc of
787 NONE => Add (i, [], true, f,Cor ((d, ts), (id, pbl_ids' d ts)))
788 | SOME (i', _, _, _, itm_) =>
792 val in_itm = ts_in itm_;
793 val ts' = union op = ts in_itm;
794 val i'' = if in_itm = [] then i else i';
795 in Add (i'', [], true, f, Cor ((d, ts'), (id, pbl_ids' d ts'))) end
796 else Add (i', [], true, f, Cor ((d, ts),(id, pbl_ids' d ts)))
800 | appl_add ctxt sel oris ppc pbt str =
801 case parseNEW ctxt str of
802 NONE => Err ("appl_add: syntax error in '" ^ str ^ "'")
804 case is_known ctxt sel oris t of
806 (case is_notyet_input ctxt ppc all ori' pbt of
808 | (msg, _) => Err ("[error] appl_add: is_notyet_input: " ^ msg))
809 | (msg, _, _) => Err ("[error] appl_add: is_known: " ^ msg);
812 (** make oris from args of the stac SubProblem and from pbt **)
813 (* can this formal argument (of a model-pattern) be omitted in the arg-list
814 of a SubProblem ? see ME/ptyps.sml 'type met ' *)
815 fun is_copy_named_idstr str =
816 case (rev o Symbol.explode) str of
817 "'":: _ ::"'"::_ => (tracing ((strs2str o (rev o Symbol.explode))
818 "is_copy_named_idstr: " ^ str ^ " T"); true)
819 | _ => (tracing ((strs2str o (rev o Symbol.explode))
820 "is_copy_named_idstr: " ^ str ^ " F"); false);
821 fun is_copy_named (_, (_, t)) = (is_copy_named_idstr o free2str) t;
823 (*.should this formal argument (of a model-pattern) create a new identifier?.*)
824 fun is_copy_named_generating_idstr str =
825 if is_copy_named_idstr str
826 then case (rev o Symbol.explode) str of
827 "'"::"'"::"'"::_ => false
830 fun is_copy_named_generating (_, (_, t)) =
831 (is_copy_named_generating_idstr o free2str) t;
833 (*.split type-wrapper from scr-arg and build part of an ori;
834 an type-error is reported immediately, raises an exn,
835 subsequent handling of exn provides 2nd part of error message.*)
836 fun mtc thy ((str, (dsc, _)):pat) (ty $ var) =
837 (* val (thy, (str, (dsc, _)), (ty $ var)) =
840 (cterm_of thy (dsc $ var);(*type check*)
841 SOME ((([1], str, dsc, (*[var]*)
842 split_dts' (dsc, var))): preori)(*:ori without leading #*))
843 handle e as TYPE _ =>
844 (tracing (dashs 70 ^ "\n"
845 ^"*** ERROR while creating the items for the model of the ->problem\n"
846 ^"*** from the ->stac with ->typeconstructor in arglist:\n"
847 ^"*** item (->description ->value): "^term2str dsc^" "^term2str var^"\n"
848 ^"*** description: "^(term_detail2str dsc)
849 ^"*** value: "^(term_detail2str var)
850 ^"*** typeconstructor in script: "^(term_detail2str ty)
851 ^"*** checked by theory: "^(theory2str thy)^"\n"
853 (*OldGoals.print_exn e; raises exn again*)
854 writeln (PolyML.makestring e);
856 (*raise ERROR "actual args do not match formal args";FIXXXME.WN100916*)
859 (*.match each pat of the model-pattern with an actual argument;
860 precondition: copy-named vars are filtered out.*)
861 fun matc thy ([]:pat list) _ (oris:preori list) = oris
862 | matc thy pbt [] _ =
864 error ("actual arg(s) missing for '"^pats2str pbt
865 ^"' i.e. should be 'copy-named' by '*_._'"))
866 | matc thy ((p as (s,(d,t)))::pbt) (a::ags) oris =
867 (* val (thy, ((p as (s,(d,t)))::pbt), (a::ags), oris) =
868 (thy, pbt', ags, []);
870 val (thy, ((p as (s,(d,t)))::pbt), (a::ags), oris) =
871 (thy, pbt, ags, (oris @ [ori]));
873 (*del?..*)if (is_copy_named_idstr o free2str) t then oris
874 else(*..del?*) let val opt = mtc thy p a;
876 (* val SOME ori = mtc thy p a;
878 SOME ori => matc thy pbt ags (oris @ [ori])
879 | NONE => [](*WN050903 skipped by exn handled in match_ags*)
881 (* run subp-rooteq.sml until Init_Proof before ...
882 > val Nd (PblObj {origin=(oris,_,_),...},_) = pt;(*from test/subp-rooteq.sml*)
883 > fun xxxfortest (_,a,b,c,d) = (a,b,c,d);val oris = map xxxfortest oris;
885 other vars as in mtc ..
886 > matc thy (drop_last pbt) ags [];
887 val it = ([[1],"#Given",Const #,[#]),(0,[#],"#Given",Const #,[#])],2)*)
890 (* generate a new variable "x_i" name from a related given one "x"
891 by use of oris relating "v_i_" (is_copy_named!) to "v_"
892 e.g. (v_, x) & (v_i_, ?) --> (v_i_, x_i) *)
894 (* generate a new variable "x_i" name from a related given one "x"
895 by use of oris relating "v_v'i'" (is_copy_named!) to "v_v"
896 e.g. (v_v, x) & (v_v'i', ?) --> (v_v'i', x_i),
897 but leave is_copy_named_generating as is, e.t. ss''' *)
898 fun cpy_nam (pbt:pat list) (oris:preori list) (p as (field,(dsc,t)):pat) =
899 (if is_copy_named_generating p
900 then (*WN051014 kept strange old code ...*)
901 let fun sel (_,_,d,ts) = comp_ts (d, ts)
902 val cy' = (implode o (drop_last_n 3) o Symbol.explode o free2str) t
903 val ext = (last_elem o drop_last o Symbol.explode o free2str) t
904 val vars' = map (free2str o snd o snd) pbt (*cpy-nam filtered_out*)
905 val vals = map sel oris
906 val cy_ext = (free2str o the) (assoc (vars'~~vals, cy'))^"_"^ext
907 in ([1], field, dsc, [mk_free (type_of t) cy_ext]):preori end
908 else ([1], field, dsc, [t])
910 handle _ => error ("cpy_nam: for "^(term2str t));
912 (*.match the actual arguments of a SubProblem with a model-pattern
913 and create an ori list (in root-pbl created from formalization).
914 expects ags:pats = 1:1, while copy-named are filtered out of pats;
915 if no 1:1 the exn raised by matc/mtc and handled at call.
916 copy-named pats are appended in order to get them into the model-items.*)
917 fun match_ags thy (pbt:pat list) ags =
918 let fun flattup (i,(var,bool,str,itm_)) = (i,var,bool,str,itm_);
919 val pbt' = filter_out is_copy_named pbt;
920 val cy = filter is_copy_named pbt;
921 val oris' = matc thy pbt' ags [];
922 val cy' = map (cpy_nam pbt' oris') cy;
923 val ors = add_id (oris' @ cy');
924 (*appended in order to get ^^^^^ into the model-items*)
925 in (map flattup ors):ori list end;
927 (*.report part of the error-msg which is not available in match_args.*)
928 fun match_ags_msg pI stac ags =
929 let (*val s = !show_types
930 val _ = show_types:= true*)
931 val pats = (#ppc o get_pbt) pI
932 val msg = (dots 70^"\n"
933 ^"*** problem "^strs2str pI^" has the ...\n"
934 ^"*** model-pattern "^pats2str pats^"\n"
935 ^"*** stac '"^term2str stac^"' has the ...\n"
936 ^"*** arg-list "^terms2str ags^"\n"
938 (*WN100921 ^^^^ expect TYPE errormsg below; lost with Isa09*)
939 (*val _ = show_types:= s*)
943 (*get the variables out of a pbl_; FIXME.WN.0311: is_copy_named ...obscure!!!*)
944 fun vars_of_pbl_ pbl_ =
945 let fun var_of_pbl_ (gfr,(dsc,t)) = t
946 in ((map var_of_pbl_) o (filter_out is_copy_named)) pbl_ end;
947 fun vars_of_pbl_' pbl_ =
948 let fun var_of_pbl_ (gfr,(dsc,t)) = t:term
949 in ((map var_of_pbl_)(* o (filter_out is_copy_named)*)) pbl_ end;
951 fun overwrite_ppc thy itm ppc =
953 fun repl ppc' (_,_,_,_,itm_) [] =
954 error ("overwrite_ppc: " ^ (itm_2str_ (thy2ctxt thy) itm_) ^
956 | repl ppc' itm (p::ppc) =
957 if (#1 itm) = (#1 (p:itm)) then ppc' @ [itm] @ ppc
958 else repl (ppc' @ [p]) itm ppc
959 in repl [] itm ppc end;
961 (*10.3.00: insert the already compiled itm into model;
962 ev. filter_out untouched (in FE: (0,...)) item related to insert-item *)
965 fun insert_ppc thy itm ppc =
967 fun eq_untouched d ((0,_,_,_,itm_):itm) = (d = d_in itm_)
968 | eq_untouched _ _ = false;
971 (*tracing("### insert_ppc: itm= "^(itm2str_ itm));*)
972 case seek_ppc (#1 itm) ppc of
973 (* val SOME xxx = seek_ppc (#1 itm) ppc;
975 SOME _ => (*itm updated in is_notyet_input WN.11.03*)
976 overwrite_ppc thy itm ppc
977 | NONE => (ppc @ [itm]));
978 in filter_out (eq_untouched ((d_in o #5) itm)) ppc' end;
980 (*from Isabelle/src/Pure/library.ML, _appends_ a new element*)
981 fun gen_ins' eq (x, xs) = if gen_mem eq (x, xs) then xs else xs @ [x];
983 fun eq_dsc ((_,_,_,_,itm_):itm, (_,_,_,_,iitm_):itm) =
984 (d_in itm_) = (d_in iitm_);
985 (*insert_ppc = insert_ppc' for appl_add', input_icalhd 11.03,
986 handles superfluous items carelessly*)
987 fun insert_ppc' itm itms = gen_ins' eq_dsc (itm, itms);
989 > gen_ins' eee (4,[1,3,5,7]);
990 val it = [1, 3, 5, 7, 4] : int list*)
993 (*. output the headline to a ppc .*)
994 fun header p_ pI mI =
995 case p_ of Pbl => Problem (if pI = e_pblID then [] else pI)
997 | pos => error ("header called with "^ pos_2str pos);
1000 fun specify_additem sel (ct,_) (p,Met) c pt =
1002 val (PblObj{meth=met,origin=(oris,(dI',pI',mI'),_),
1003 probl=pbl,spec=(dI,pI,mI),...}) = get_obj I pt p;
1004 val thy = if dI = e_domID then assoc_thy dI' else assoc_thy dI;
1005 (*val ppt = if pI = e_pblID then get_pbt pI' else get_pbt pI;*)
1006 val cpI = if pI = e_pblID then pI' else pI;
1007 val cmI = if mI = e_metID then mI' else mI;
1008 val {ppc,pre,prls,...} = get_met cmI;
1009 val ctxt = get_ctxt pt (p,Met);
1010 in case appl_add ctxt sel oris met ppc ct of
1011 Add itm (*..union old input *) =>
1012 let (* val Add itm = appl_add thy sel oris met (#ppc (get_met cmI)) ct;
1014 val met' = insert_ppc thy itm met;
1015 (*val pt' = update_met pt p met';*)
1016 val ((p,Met),_,_,pt') =
1017 generate1 thy (case sel of
1018 "#Given" => Add_Given' (ct, met')
1019 | "#Find" => Add_Find' (ct, met')
1020 | "#Relate"=> Add_Relation'(ct, met'))
1021 (Uistate, e_ctxt) (p,Met) pt
1022 val pre' = check_preconds thy prls pre met'
1023 val pb = foldl and_ (true, map fst pre')
1024 (*val _=tracing("@@@ specify_additem: Met Add before nxt_spec")*)
1026 nxt_spec Met pb oris (dI',pI',mI') (pbl,met')
1027 ((#ppc o get_pbt) cpI,ppc) (dI,pI,mI);
1028 in ((p,p_), ((p,p_),Uistate),
1029 Form' (PpcKF (0,EdUndef,(length p),Nundef,
1030 (Method cmI, itms2itemppc thy met' pre'))),
1033 let val pre' = check_preconds thy prls pre met
1034 val pb = foldl and_ (true, map fst pre')
1035 (*val _=tracing("@@@ specify_additem: Met Err before nxt_spec")*)
1037 nxt_spec Met pb oris (dI',pI',mI') (pbl,met)
1038 ((#ppc o get_pbt) cpI,(#ppc o get_met) cmI) (dI,pI,mI);
1039 in ((p,p_), ((p,p_),Uistate), Error' (Error_ msg), nxt, Safe,pt) end
1043 | specify_additem sel (ct,_) (pos as (p,_(*Frm, Pbl*))) c pt =
1045 val (PblObj{meth=met,origin=(oris,(dI',pI',mI'),_),
1046 probl=pbl,spec=(dI,pI,mI),...}) = get_obj I pt p;
1047 val thy = if dI = e_domID then assoc_thy dI' else assoc_thy dI;
1048 val cpI = if pI = e_pblID then pI' else pI;
1049 val cmI = if mI = e_metID then mI' else mI;
1050 val {ppc,where_,prls,...} = get_pbt cpI;
1051 val ctxt = get_ctxt pt pos;
1052 in case appl_add ctxt sel oris pbl ppc ct of
1053 Add itm (*..union old input *) =>
1054 (* val Add itm = appl_add thy sel oris pbl ppc ct;
1057 (*val _= tracing("###specify_additem: itm= "^(itm2str_ itm));*)
1058 val pbl' = insert_ppc thy itm pbl
1059 val ((p,Pbl),_,_,pt') =
1060 generate1 thy (case sel of
1061 "#Given" => Add_Given' (ct, pbl')
1062 | "#Find" => Add_Find' (ct, pbl')
1063 | "#Relate"=> Add_Relation'(ct, pbl'))
1064 (Uistate, e_ctxt) (p,Pbl) pt
1065 val pre = check_preconds thy prls where_ pbl'
1066 val pb = foldl and_ (true, map fst pre)
1067 (*val _=tracing("@@@ specify_additem: Pbl Add before nxt_spec")*)
1069 nxt_spec Pbl pb oris (dI',pI',mI') (pbl',met)
1070 (ppc,(#ppc o get_met) cmI) (dI,pI,mI);
1071 val ppc = if p_= Pbl then pbl' else met;
1072 in ((p,p_), ((p,p_),Uistate),
1073 Form' (PpcKF (0,EdUndef,(length p),Nundef,
1075 itms2itemppc thy ppc pre))), nxt,Safe,pt') end
1078 let val pre = check_preconds thy prls where_ pbl
1079 val pb = foldl and_ (true, map fst pre)
1080 (*val _=tracing("@@@ specify_additem: Pbl Err before nxt_spec")*)
1082 nxt_spec Pbl pb oris (dI',pI',mI') (pbl,met)
1083 (ppc,(#ppc o get_met) cmI) (dI,pI,mI);
1084 in ((p,p_), ((p,p_),Uistate), Error' (Error_ msg), nxt, Safe,pt) end
1087 fun specify (Init_Proof' (fmz,(dI',pI',mI'))) (_:pos') (_:cid) (_:ptree)=
1088 let (* either """"""""""""""" all empty or complete *)
1089 val thy = assoc_thy dI';
1091 if dI' = e_domID orelse pI' = e_pblID
1093 else pI' |> #ppc o get_pbt |> prep_ori fmz thy
1094 val (pt,c) = cappend_problem e_ptree [] (e_istate, ctxt) (fmz,(dI',pI',mI'))
1095 (oris, (dI',pI',mI'),e_term)
1096 (*val pt = update_env pt [] (SOME (e_istate, ctxt)) FIXME.WN110511*)
1097 val {ppc, prls, where_, ...} = get_pbt pI'
1098 val (pbl, pre, pb) = ([], [], false)
1102 (([], Pbl), (([], Pbl), Uistate),
1103 Form' (PpcKF (0, EdUndef, (length []), Nundef,
1104 (Problem [], itms2itemppc (assoc_thy dI') pbl pre))),
1105 Refine_Tacitly pI', Safe, pt)
1107 (([], Pbl), (([], Pbl), Uistate),
1108 Form' (PpcKF (0, EdUndef, (length []), Nundef,
1109 (Problem [], itms2itemppc (assoc_thy dI') pbl pre))),
1110 Model_Problem, Safe, pt)
1113 (*ONLY for STARTING modeling phase*)
1114 | specify (Model_Problem' (_,pbl,met)) (pos as (p,p_)) c pt =
1116 val (PblObj{origin=(oris,(dI',pI',mI'),_), spec=(dI,_,_),...}) = get_obj I pt p
1117 val thy' = if dI = e_domID then dI' else dI
1118 val thy = assoc_thy thy'
1119 val {ppc,prls,where_,...} = get_pbt pI'
1120 val pre = check_preconds thy prls where_ pbl
1121 val pb = foldl and_ (true, map fst pre)
1122 val ((p,_),_,_,pt) = generate1 thy (Model_Problem'([],pbl,met)) (Uistate, e_ctxt) pos pt
1123 val (_,nxt) = nxt_spec Pbl pb oris (dI',pI',mI') (pbl,met)
1124 (ppc,(#ppc o get_met) mI') (dI',pI',mI');
1125 in ((p, Pbl), ((p, p_), Uistate),
1126 Form' (PpcKF (0, EdUndef, length p, Nundef,
1127 (Problem pI', itms2itemppc (assoc_thy dI') pbl pre))),
1131 (*. called only if no_met is specified .*)
1132 | specify (Refine_Tacitly' (pI,pIre,_,_,_)) (pos as (p,_)) c pt =
1134 val (PblObj{origin=(oris,(dI',pI',mI'),_), meth=met, ...}) = get_obj I pt p;
1135 val {prls,met,ppc,thy,where_,...} = get_pbt pIre
1136 val (domID, metID) =
1137 (string_of_thy thy, if length met = 0 then e_metID else hd met)
1138 val ((p,_),_,_,pt) =
1139 generate1 thy (Refine_Tacitly'(pI,pIre,domID,metID,(*pbl*)[]))
1140 (Uistate, e_ctxt) pos pt
1141 val (pbl, pre, pb) = ([], [], false)
1142 in ((p, Pbl), (pos, Uistate),
1143 Form' (PpcKF (0,EdUndef,(length p),Nundef,
1144 (Problem pIre, itms2itemppc (assoc_thy dI') pbl pre))),
1145 Model_Problem, Safe, pt)
1148 | specify (Refine_Problem' (rfd as (pI,_))) pos c pt =
1150 val (pos,_,_,pt) = generate1 (assoc_thy "Isac")
1151 (Refine_Problem' rfd) (Uistate, e_ctxt) pos pt
1152 in (pos(*p,Pbl*), (pos(*p,Pbl*),Uistate), Problems (RefinedKF rfd),
1153 Model_Problem, Safe, pt)
1156 | specify (Specify_Problem' (pI, (ok, (itms, pre)))) (pos as (p,_)) c pt =
1157 let val (PblObj {origin=(oris,(dI',pI',mI'),_), spec=(dI,_,mI),
1158 meth=met, ...}) = get_obj I pt p;
1159 (*val pt = update_pbl pt p itms;
1160 val pt = update_pblID pt p pI;*)
1161 val thy = assoc_thy dI
1162 val ((p,Pbl),_,_,pt)=
1163 generate1 thy (Specify_Problem' (pI, (ok, (itms, pre)))) (Uistate, e_ctxt) pos pt
1164 val dI'' = assoc_thy (if dI=e_domID then dI' else dI);
1165 val mI'' = if mI=e_metID then mI' else mI;
1166 (*val _=tracing("@@@ specify (Specify_Problem) before nxt_spec")*)
1167 val (_,nxt) = nxt_spec Pbl ok oris (dI',pI',mI') (itms, met)
1168 ((#ppc o get_pbt) pI,(#ppc o get_met) mI'') (dI,pI,mI);
1169 in ((p,Pbl), (pos,Uistate),
1170 Form' (PpcKF (0,EdUndef,(length p),Nundef,
1171 (Problem pI, itms2itemppc dI'' itms pre))),
1173 (* val Specify_Method' mID = nxt; val (p,_) = p;
1174 val Specify_Method' mID = m;
1175 specify (Specify_Method' mID) (p,p_) c pt;
1177 | specify (Specify_Method' (mID,_,_)) (pos as (p,_)) c pt =
1178 let val (PblObj {origin=(oris,(dI',pI',mI'),_), probl=pbl, spec=(dI,pI,mI),
1179 meth=met, ...}) = get_obj I pt p;
1180 val {ppc,pre,prls,...} = get_met mID
1181 val thy = assoc_thy dI
1182 val oris = add_field' thy ppc oris;
1183 (*val pt = update_oris pt p oris; 20.3.02: repl. "#undef"*)
1184 val dI'' = if dI=e_domID then dI' else dI;
1185 val pI'' = if pI = e_pblID then pI' else pI;
1186 val met = if met=[] then pbl else met;
1187 val (ok, (itms, pre')) = match_itms_oris thy met (ppc,pre,prls ) oris;
1188 (*val pt = update_met pt p itms;
1189 val pt = update_metID pt p mID*)
1191 generate1 thy (Specify_Method' (mID, oris, itms)) (Uistate, e_ctxt) pos pt
1192 (*val _=tracing("@@@ specify (Specify_Method) before nxt_spec")*)
1193 val (_,nxt) = nxt_spec Met (*ok*)true oris (dI',pI',mI') (pbl, itms)
1194 ((#ppc o get_pbt) pI'',ppc) (dI'',pI'',mID);
1195 in (pos, (pos,Uistate),
1196 Form' (PpcKF (0,EdUndef,(length p),Nundef,
1197 (Method mID, itms2itemppc (assoc_thy dI'') itms pre'))),
1199 (* val Add_Find' ct = nxt; val sel = "#Find";
1201 | specify (Add_Given' ct) p c pt = specify_additem "#Given" ct p c pt
1202 | specify (Add_Find' ct) p c pt = specify_additem "#Find" ct p c pt
1203 | specify (Add_Relation' ct) p c pt=specify_additem"#Relate"ct p c pt
1204 (* val Specify_Theory' domID = m;
1205 val (Specify_Theory' domID, (p,p_)) = (m, pos);
1207 | specify (Specify_Theory' domID) (pos as (p,p_)) c pt =
1208 let val p_ = case p_ of Met => Met | _ => Pbl
1209 val thy = assoc_thy domID;
1210 val (PblObj{origin=(oris,(dI',pI',mI'),_), meth=met,
1211 probl=pbl, spec=(dI,pI,mI),...}) = get_obj I pt p;
1212 val mppc = case p_ of Met => met | _ => pbl;
1213 val cpI = if pI = e_pblID then pI' else pI;
1214 val {prls=per,ppc,where_=pwh,...} = get_pbt cpI
1215 val cmI = if mI = e_metID then mI' else mI;
1216 val {prls=mer,ppc=mpc,pre=mwh,...} = get_met cmI
1219 Met => (check_preconds thy mer mwh met)
1220 | _ => (check_preconds thy per pwh pbl)
1221 val pb = foldl and_ (true, map fst pre)
1224 (*val _=tracing("@@@ specify (Specify_Theory) THEN before nxt_spec")*)
1225 val (p_,nxt) = nxt_spec p_ pb oris (dI',pI',mI')
1226 (pbl,met) (ppc,mpc) (dI,pI,mI);
1227 in ((p,p_), (pos,Uistate),
1228 Form'(PpcKF (0,EdUndef,(length p), Nundef,
1229 (header p_ pI cmI, itms2itemppc thy mppc pre))),
1231 else (*FIXME: check ppc wrt. (new!) domID ..? still parsable?*)
1233 (*val pt = update_domID pt p domID;11.8.03*)
1234 val ((p,p_),_,_,pt) = generate1 thy (Specify_Theory' domID)
1235 (Uistate, e_ctxt) (p,p_) pt
1236 (*val _=tracing("@@@ specify (Specify_Theory) ELSE before nxt_spec")*)
1237 val (p_,nxt) = nxt_spec p_ pb oris (dI',pI',mI') (pbl,met)
1238 (ppc,mpc) (domID,pI,mI);
1239 in ((p,p_), (pos,Uistate),
1240 Form' (PpcKF (0, EdUndef, (length p),Nundef,
1241 (header p_ pI cmI, itms2itemppc thy mppc pre))),
1244 (* itms2itemppc thy [](*mpc*) pre
1246 | specify m' _ _ _ =
1247 error ("specify: not impl. for "^tac_2str m');
1249 fun nxt_specif_additem sel ct (ptp as (pt, (p, Pbl))) =
1251 val (PblObj{meth=met,origin=(oris,(dI',pI',_),_),
1252 probl=pbl,spec=(dI,pI,_),...}) = get_obj I pt p;
1253 val thy = if dI = e_domID then assoc_thy dI' else assoc_thy dI;
1254 val cpI = if pI = e_pblID then pI' else pI;
1255 val ctxt = get_ctxt pt (p, Pbl); (*FIXME.WN110511 repair*)
1257 case appl_add ctxt sel oris pbl ((#ppc o get_pbt) cpI) ct of
1258 Add itm (*..union old input *) =>
1260 (*val _=tracing("###nxt_specif_additem: itm= "^(itm2str_ itm));*)
1261 val pbl' = insert_ppc thy itm pbl
1264 "#Given" => (Add_Given ct, Add_Given' (ct, pbl'))
1265 | "#Find" => (Add_Find ct, Add_Find' (ct, pbl'))
1266 | "#Relate"=> (Add_Relation ct, Add_Relation'(ct, pbl'))
1267 val ((p,Pbl),c,_,pt') =
1268 generate1 thy tac_ (Uistate, e_ctxt) (p,Pbl) pt
1269 in ([(tac,tac_,((p,Pbl),(Uistate, e_ctxt)))], c, (pt',(p,Pbl))):calcstate'
1272 (*TODO.WN03 pass error-msgs to the frontend..
1273 FIXME ..and dont abuse a tactic for that purpose*)
1274 ([(Tac msg, Tac_ (Thy_Info.get_theory "Pure", msg,msg,msg),
1275 (e_pos', (e_istate, e_ctxt)))], [], ptp)
1277 | nxt_specif_additem sel ct (ptp as (pt,(p,Met))) =
1279 val (PblObj{meth=met,origin=(oris,(dI',pI',mI'),_),
1280 probl=pbl,spec=(dI,pI,mI),...}) = get_obj I pt p;
1281 val thy = if dI = e_domID then assoc_thy dI' else assoc_thy dI;
1282 val cmI = if mI = e_metID then mI' else mI;
1283 val ctxt = get_ctxt pt (p,Met); (*FIXME.WN110511 repair*)
1285 case appl_add ctxt sel oris met ((#ppc o get_met) cmI) ct of
1286 Add itm (*..union old input *) =>
1288 val met' = insert_ppc thy itm met;
1291 "#Given" => (Add_Given ct, Add_Given' (ct, met'))
1292 | "#Find" => (Add_Find ct, Add_Find' (ct, met'))
1293 | "#Relate"=> (Add_Relation ct, Add_Relation'(ct, met'))
1294 val ((p,Met),c,_,pt') =
1295 generate1 thy tac_ (Uistate, e_ctxt) (p,Met) pt
1296 in ([(tac,tac_,((p,Met), (Uistate, e_ctxt)))], c, (pt',(p,Met))) end
1297 | Err msg => ([(*tacis*)], [], ptp)
1298 (*nxt_me collects tacis until not hide; here just no progress*)
1301 fun ori2Coritm pbt ((i,v,f,d,ts):ori) =
1302 (i,v,true,f, Cor ((d,ts),(((snd o snd o the o (find_first (eq1 d))) pbt)
1303 handle _ => error ("ori2Coritm: dsc "^
1305 "in ori, but not in pbt")
1307 fun ori2Coritm (pbt:pat list) ((i,v,f,d,ts):ori) =
1308 ((i,v,true,f, Cor ((d,ts),((snd o snd o the o
1309 (find_first (eq1 d))) pbt,ts))):itm)
1310 handle _ => (*dsc in oris, but not in pbl pat list: keep this dsc*)
1311 ((i,v,true,f, Cor ((d,ts),(d,ts))):itm);
1314 (*filter out oris which have same description in itms*)
1315 fun filter_outs oris [] = oris
1316 | filter_outs oris (i::itms) =
1317 let val ors = filter_out ((curry op= ((d_in o #5) (i:itm))) o
1318 (#4:ori -> term)) oris;
1319 in filter_outs ors itms end;
1321 fun memI a b = member op = a b;
1322 (*filter oris which are in pbt, too*)
1323 fun filter_pbt oris pbt =
1324 let val dscs = map (fst o snd) pbt
1325 in filter ((memI dscs) o (#4: ori -> term)) oris end;
1327 (*.combine itms from pbl + met and complete them wrt. pbt.*)
1328 (*FIXXXME.WN031205 complete_metitms doesnt handle incorrect itms !*)
1330 fun x mem [] = false
1331 | x mem (y :: ys) = x = y orelse x mem ys;
1333 fun complete_metitms (oris:ori list) (pits:itm list) (mits:itm list) met =
1334 (* val met = (#ppc o get_met) ["DiffApp","max_by_calculus"];
1336 let val vat = max_vt pits;
1338 (filter ((curry (op mem) vat) o (#2:itm -> int list)) mits);
1339 val ors = filter ((curry (op mem) vat) o (#2:ori -> int list)) oris;
1340 val os = filter_outs ors itms;
1341 (*WN.12.03?: does _NOT_ add itms from met ?!*)
1342 in itms @ (map (ori2Coritm met) os) end
1347 (*.complete model and guard of a calc-head .*)
1349 fun x mem [] = false
1350 | x mem (y :: ys) = x = y orelse x mem ys;
1352 fun complete_mod_ (oris, mpc, ppc, probl) =
1353 let val pits = filter_out ((curry op= false) o (#3: itm -> bool)) probl
1354 val vat = if probl = [] then 1 else max_vt probl
1355 val pors = filter ((curry (op mem) vat) o (#2:ori -> int list)) oris
1356 val pors = filter_outs pors pits (*which are in pbl already*)
1357 val pors = (filter_pbt pors ppc) (*which are in pbt, too*)
1359 val pits = pits @ (map (ori2Coritm ppc) pors)
1360 val mits = complete_metitms oris pits [] mpc
1364 fun some_spec ((odI, opI, omI):spec) ((dI, pI, mI):spec) =
1365 (if dI = e_domID then odI else dI,
1366 if pI = e_pblID then opI else pI,
1367 if mI = e_metID then omI else mI):spec;
1370 (*.find a next applicable tac (for calcstate) and update ptree
1371 (for ev. finding several more tacs due to hide).*)
1372 (*FIXXXME: unify ... fun nxt_specif = nxt_spec + applicable_in + specify !!*)
1373 (*WN.24.10.03 ~~~~~~~~~~~~~~ -> tac -> tac_ -> -"- as arg*)
1374 (*WN.24.10.03 fun nxt_solv = ...................................??*)
1375 fun nxt_specif (tac as Model_Problem) (pt, pos as (p,p_)) =
1377 val PblObj {origin = (oris, ospec, _), probl, spec, ...} = get_obj I pt p
1378 val (dI, pI, mI) = some_spec ospec spec
1379 val thy = assoc_thy dI
1380 val mpc = (#ppc o get_met) mI (* just for reuse complete_mod_ *)
1381 val {cas, ppc, ...} = get_pbt pI
1382 val pbl = init_pbl ppc (* fill in descriptions *)
1383 (*----------------if you think, this should be done by the Dialog
1384 in the java front-end, search there for WN060225-modelProblem----*)
1386 case cas of NONE => (pbl, [])
1387 | _ => complete_mod_ (oris, mpc, ppc, probl)
1388 (*----------------------------------------------------------------*)
1389 val tac_ = Model_Problem' (pI, pbl, met)
1390 val (pos,c,_,pt) = generate1 thy tac_ (Uistate, e_ctxt) pos pt
1391 in ([(tac,tac_, (pos, (Uistate, e_ctxt)))], c, (pt,pos)):calcstate' end
1393 | nxt_specif (Add_Given ct) ptp = nxt_specif_additem "#Given" ct ptp
1394 | nxt_specif (Add_Find ct) ptp = nxt_specif_additem "#Find" ct ptp
1395 | nxt_specif (Add_Relation ct) ptp = nxt_specif_additem"#Relate" ct ptp
1397 (*. called only if no_met is specified .*)
1398 | nxt_specif (Refine_Tacitly pI) (ptp as (pt, pos as (p,_))) =
1400 val (PblObj {origin = (oris, (dI,_,_),_), ...}) = get_obj I pt p
1401 val opt = refine_ori oris pI
1406 val {met,ppc,...} = get_pbt pI'
1407 val pbl = init_pbl ppc
1408 (*val pt = update_pbl pt p pbl ..done by Model_Problem*)
1409 val mI = if length met = 0 then e_metID else hd met
1410 val thy = assoc_thy dI
1412 generate1 thy (Refine_Tacitly' (pI,pI',dI,mI,(*pbl*)[]))
1413 (Uistate, e_ctxt) pos pt
1414 in ([(Refine_Tacitly pI, Refine_Tacitly' (pI,pI',dI,mI,(*pbl*)[]),
1415 (pos, (Uistate, e_ctxt)))], c, (pt,pos))
1417 | NONE => ([], [], ptp)
1420 | nxt_specif (Refine_Problem pI) (ptp as (pt, pos as (p,_))) =
1422 val (PblObj {origin=(_,(dI,_,_),_),spec=(dI',_,_), probl, ...}) = get_obj I pt p
1423 val thy = if dI' = e_domID then dI else dI'
1425 case refine_pbl (assoc_thy thy) pI probl of
1426 NONE => ([], [], ptp)
1427 | SOME (rfd as (pI',_)) =>
1429 val (pos,c,_,pt) = generate1 (assoc_thy thy)
1430 (Refine_Problem' rfd) (Uistate, e_ctxt) pos pt
1431 in ([(Refine_Problem pI, Refine_Problem' rfd,
1432 (pos, (Uistate, e_ctxt)))], c, (pt,pos))
1436 | nxt_specif (Specify_Problem pI) (pt, pos as (p,_)) =
1438 val (PblObj {origin=(oris,(dI,_,_),_),spec=(dI',pI',_), probl, ...}) = get_obj I pt p;
1439 val thy = assoc_thy (if dI' = e_domID then dI else dI');
1440 val {ppc,where_,prls,...} = get_pbt pI
1441 val pbl as (_,(itms,_)) =
1442 if pI'=e_pblID andalso pI=e_pblID
1443 then (false, (init_pbl ppc, []))
1444 else match_itms_oris thy probl (ppc,where_,prls) oris(*FIXXXXXME?*)
1445 (*FIXXXME~~~~~~~~~~~~~~~: take pbl and compare with new pI WN.8.03*)
1446 val ((p,Pbl),c,_,pt) =
1447 generate1 thy (Specify_Problem' (pI, pbl)) (Uistate, e_ctxt) pos pt
1448 in ([(Specify_Problem pI, Specify_Problem' (pI, pbl),
1449 (pos,(Uistate, e_ctxt)))], c, (pt,pos))
1452 (*transfers oris (not required in pbl) to met-model for script-env
1453 FIXME.WN.8.03: application of several mIDs to SAME model?*)
1454 | nxt_specif (Specify_Method mID) (ptp as (pt, pos as (p,_))) =
1456 val (PblObj {origin=(oris,(dI',pI',mI'),_), probl=pbl, spec=(dI,pI,mI), meth=met, ...}) = get_obj I pt p;
1457 val {ppc,pre,prls,...} = get_met mID
1458 val thy = assoc_thy dI
1459 val oris = add_field' thy ppc oris;
1460 val dI'' = if dI=e_domID then dI' else dI;
1461 val pI'' = if pI = e_pblID then pI' else pI;
1462 val met = if met=[] then pbl else met;(*WN0602 what if more itms in met?*)
1463 val (ok, (itms, pre')) = match_itms_oris thy met (ppc,pre,prls ) oris;
1465 generate1 thy (Specify_Method' (mID, oris, itms)) (Uistate, e_ctxt) pos pt
1466 in ([(Specify_Method mID, Specify_Method' (mID, oris, itms),
1467 (pos,(Uistate, e_ctxt)))], c, (pt,pos))
1470 | nxt_specif (Specify_Theory dI) (pt, pos as (p,Pbl)) =
1472 val (dI',_,_) = get_obj g_spec pt p
1474 generate1 (assoc_thy "Isac") (Specify_Theory' dI) (Uistate, e_ctxt) pos pt
1475 in (*FIXXXME: check if pbl can still be parsed*)
1476 ([(Specify_Theory dI, Specify_Theory' dI, (pos,(Uistate, e_ctxt)))], c,
1480 | nxt_specif (Specify_Theory dI) (pt, pos as (p,Met)) =
1482 val (dI',_,_) = get_obj g_spec pt p
1484 generate1 (assoc_thy "Isac") (Specify_Theory' dI) (Uistate, e_ctxt) pos pt
1485 in (*FIXXXME: check if met can still be parsed*)
1486 ([(Specify_Theory dI, Specify_Theory' dI, (pos,(Uistate, e_ctxt)))], c,
1491 error ("nxt_specif: not impl. for "^tac2str m');
1493 (* get the values from oris; handle the term list w.r.t. penv *)
1495 fun x mem [] = false
1496 | x mem (y :: ys) = x = y orelse x mem ys;
1498 fun vals_of_oris oris =
1499 ((map (mkval' o (#5:ori -> term list))) o
1500 (filter ((curry (op mem) 1) o (#2:ori -> int list)))) oris
1503 (* create a calc-tree with oris via an cas.refined pbl *)
1504 fun nxt_specify_init_calc (([], (dI, pI, mI)) : fmz) =
1506 then (* from pbl-browser or from CAS cmd with pI=[e_pblID] *)
1508 val {cas, met, ppc, thy, ...} = get_pbt pI
1509 val dI = if dI = "" then theory2theory' thy else dI
1510 val thy = assoc_thy dI
1511 val mI = if mI = [] then hd met else mI
1512 val hdl = case cas of NONE => pblterm dI pI | SOME t => t
1513 val (pt,_) = cappend_problem e_ptree [] (Uistate, e_ctxt) ([], (dI,pI,mI))
1514 ([], (dI,pI,mI), hdl)
1515 val pt = update_spec pt [] (dI,pI,mI)
1516 val pits = init_pbl' ppc
1517 val pt = update_pbl pt [] pits
1518 in ((pt, ([] ,Pbl)), []) : calcstate end
1521 then (* from met-browser *)
1523 val {ppc,...} = get_met mI
1524 val dI = if dI = "" then "Isac" else dI
1525 val thy = assoc_thy dI;
1526 val (pt,_) = cappend_problem e_ptree [] (e_istate, e_ctxt) ([], (dI,pI,mI))
1527 ([], (dI,pI,mI), e_term(*FIXME met*));
1528 val pt = update_spec pt [] (dI,pI,mI);
1529 val mits = init_pbl' ppc;
1530 val pt = update_met pt [] mits;
1531 in ((pt, ([], Met)), []) : calcstate end
1532 else (* new example, pepare for interactive modeling *)
1533 let val (pt,_) = cappend_problem e_ptree [] (e_istate, e_ctxt) ([], e_spec)
1534 ([], e_spec, e_term)
1535 in ((pt, ([], Pbl)), []) : calcstate end
1537 | nxt_specify_init_calc (fmz : fmz_, (dI, pI, mI) : spec) =
1538 let (* both """"""""""""""""""""""""" either empty or complete *)
1539 val thy = assoc_thy dI
1540 val (pI, (pors, pctxt), mI) =
1544 val (pors, pctxt) = get_pbt pI |> #ppc |> prep_ori fmz thy;
1545 val pI' = refine_ori' pors pI;
1546 in (pI', (pors(*refinement over models with diff.precond only*), pctxt),
1547 (hd o #met o get_pbt) pI') end
1548 else (pI, get_pbt pI |> #ppc |> prep_ori fmz thy, mI)
1549 val {cas, ppc, thy=thy',...} = get_pbt pI (*take dI from _refined_ pbl*)
1550 val dI = theory2theory' (maxthy thy thy');
1553 NONE => pblterm dI pI
1554 | SOME t => subst_atomic ((vars_of_pbl_' ppc) ~~~ vals_of_oris pors) t;
1555 val (pt, _) = cappend_problem e_ptree [] (e_istate, pctxt) (fmz, (dI, pI, mI))
1556 (pors, (dI, pI, mI), hdl)
1557 (* val pt = update_env pt [] (SOME (e_istate, pctxt)) FIXME.WN110511*)
1558 in ((pt, ([], Pbl)),
1559 fst3 (nxt_specif Model_Problem (pt, ([], Pbl)))) : calcstate
1565 fun get_spec_form (m:tac_) ((p,p_):pos') (pt:ptree) =
1566 (* case appl_spec p pt m of /// 19.1.00
1567 Notappl e => Error' (Error_ e)
1569 *) let val (_,_,f,_,_,_) = specify m (p,p_) [] pt
1573 (*fun tag_form thy (formal, given) = cterm_of thy
1574 (((head_of o term_of) given) $ (term_of formal)); WN100819*)
1575 fun tag_form thy (formal, given) =
1576 (let val gf = (head_of given) $ formal;
1577 val _ = cterm_of thy gf
1580 error ("calchead.tag_form: " ^
1581 Print_Mode.setmp [] (Syntax.string_of_term
1582 (thy2ctxt thy)) given ^ " .. " ^
1583 Print_Mode.setmp [] (Syntax.string_of_term
1584 (thy2ctxt thy)) formal ^
1585 " ..types do not match");
1586 (* val formal = (the o (parse thy)) "[R::real]";
1587 > val given = (the o (parse thy)) "fixed_values (cs::real list)";
1588 > tag_form thy (formal, given);
1589 val it = "fixed_values [R]" : cterm
1592 fun chktyp thy (n, fs, gs) =
1593 ((writeln o (Print_Mode.setmp [] (Syntax.string_of_term (thy2ctxt thy))) o
1595 (writeln o (Print_Mode.setmp [] (Syntax.string_of_term (thy2ctxt thy))) o
1597 tag_form thy (nth n fs, nth n gs));
1598 fun chktyps thy (fs, gs) = map (tag_form thy) (fs ~~ gs);
1600 (* #####################################################
1601 find the failing item:
1603 > val tag__form = chktyp (n,formals,givens);
1604 > (type_of o term_of o (nth n)) formals;
1605 > (type_of o term_of o (nth n)) givens;
1606 > atomty ((term_of o (nth n)) formals);
1607 > atomty ((term_of o (nth n)) givens);
1608 > atomty (term_of tag__form);
1609 > use_thy"isa-98-1-HOL-plus/knowl-base/DiffAppl";
1610 ##################################################### *)
1612 (* #####################################################
1614 val origin = ["sqrt(9+4*x)=sqrt x + sqrt(5+x)","x::rat","(+0)"];
1615 val formals = map (the o (parse thy)) origin;
1617 val given = ["equation (lhs=rhs)",
1618 "bound_variable bdv", (* TODO type *)
1620 val where_ = ["e is_root_equation_in bdv",
1622 "apx is_const_expr"];
1623 val find = ["L::rat set"];
1624 val with_ = ["L = {bdv. || ((%x. lhs) bdv) - ((%x. rhs) bdv) || < apx}"];
1625 val chkpbl = map (the o (parse thy)) (given @ where_ @ find @ with_);
1626 val givens = map (the o (parse thy)) given;
1628 val tag__forms = chktyps (formals, givens);
1629 map ((atomty) o term_of) tag__forms;
1630 ##################################################### *)
1633 (* check pbltypes, announces one failure a time *)
1634 (*fun chk_vars ctppc =
1635 let val {Given=gi,Where=wh,Find=fi,With=wi,Relate=re} =
1636 appc flat (mappc (vars o term_of) ctppc)
1637 in if (wh\\gi) <> [] then ("wh\\gi",wh\\gi)
1638 else if (re\\(gi union fi)) <> []
1639 then ("re\\(gi union fi)",re\\(gi union fi))
1640 else ("ok",[]) end;*)
1641 fun chk_vars ctppc =
1642 let val {Given=gi,Where=wh,Find=fi,With=wi,Relate=re} =
1643 appc flat (mappc vars ctppc)
1644 val chked = subtract op = gi wh
1645 in if chked <> [] then ("wh\\gi", chked)
1646 else let val chked = subtract op = (union op = gi fi) re
1648 then ("re\\(gi union fi)", chked)
1653 (* check a new pbltype: variables (Free) unbound by given, find*)
1654 fun unbound_ppc ctppc =
1655 let val {Given=gi,Find=fi,Relate=re,...} =
1656 appc flat (mappc vars ctppc)
1657 in distinct (*re\\(gi union fi)*)
1658 (subtract op = (union op = gi fi) re) end;
1660 > val org = {Given=["[R=(R::real)]"],Where=[],
1661 Find=["[A::real]"],With=[],
1662 Relate=["[A=#2*a*b - a^^^#2, (a//#2)^^^#2 + (b//#2)^^^#2 = R^^^#2]"]
1664 > val ctppc = mappc (the o (parse thy)) org;
1665 > unbound_ppc ctppc;
1666 val it = [("a","RealDef.real"),("b","RealDef.real")] : (string * typ) list
1670 (* f, a binary operator, is nested rightassociative *)
1673 fun fld f (x::[]) = x
1674 | fld f (x::x'::[]) = f (x',x)
1675 | fld f (x::x'::xs) = f (fld f (x'::xs),x);
1676 in ((fld f) o rev) xs end;
1678 > val (SOME ct) = parse thy "[a=b,c=d,e=f]";
1679 > val ces = map (cterm_of thy) (isalist2list (term_of ct));
1680 > val conj = foldr1 HOLogic.mk_conj (isalist2list (term_of ct));
1681 > cterm_of thy conj;
1682 val it = "(a = b & c = d) & e = f" : cterm
1685 (* f, a binary operator, is nested leftassociative *)
1686 fun foldl1 f (x::[]) = x
1687 | foldl1 f (x::x'::[]) = f (x,x')
1688 | foldl1 f (x::x'::xs) = f (x,foldl1 f (x'::xs));
1690 > val (SOME ct) = parse thy "[a=b,c=d,e=f,g=h]";
1691 > val ces = map (cterm_of thy) (isalist2list (term_of ct));
1692 > val conj = foldl1 HOLogic.mk_conj (isalist2list (term_of ct));
1693 > cterm_of thy conj;
1694 val it = "a = b & c = d & e = f & g = h" : cterm
1698 (* called only once, if a Subproblem has been located in the script*)
1699 fun nxt_model_pbl (Subproblem'((_,pblID,metID),_,_,_,_)) ptp =
1702 (snd3 o hd o fst3) (nxt_specif (Refine_Tacitly pblID) ptp)
1703 | _ => (snd3 o hd o fst3) (nxt_specif Model_Problem ptp))
1704 (*all stored in tac_ itms^^^^^^^^^^*)
1705 | nxt_model_pbl tac_ _ =
1706 error ("nxt_model_pbl: called by tac= " ^ tac_2str tac_);
1708 (*fun eq1 d (_,(d',_)) = (d = d'); ---modspec.sml*)
1709 fun eq4 v (_,vts,_,_,_) = member op = vts v;
1710 fun eq5 (_,_,_,_,itm_) (_,_,_,d,_) = d_in itm_ = d;
1713 (*.complete _NON_empty calc-head for autocalc (sub-)pbl from oris
1714 + met from fmz; assumes pos on PblObj, meth = [].*)
1715 fun complete_mod (pt, pos as (p, p_):pos') =
1716 (* val (pt, (p, _)) = (pt, p);
1717 val (pt, (p, _)) = (pt, pos);
1719 let val _= if p_ <> Pbl
1720 then tracing("###complete_mod: only impl.for Pbl, called with "^
1721 pos'2str pos) else ()
1722 val (PblObj{origin=(oris, ospec, hdl), probl, spec,...}) =
1724 val (dI,pI,mI) = some_spec ospec spec
1725 val mpc = (#ppc o get_met) mI
1726 val ppc = (#ppc o get_pbt) pI
1727 val (pits, mits) = complete_mod_ (oris, mpc, ppc, probl)
1728 val pt = update_pblppc pt p pits
1729 val pt = update_metppc pt p mits
1730 in (pt, (p,Met):pos') end
1732 (*| complete_mod (pt, pos as (p, Met):pos') =
1733 error ("###complete_mod: only impl.for Pbl, called with "^
1736 (*.complete _EMPTY_ calc-head for autocalc (sub-)pbl from oris(+met from fmz);
1737 oris and spec (incl. pbl-refinement) given from init_calc or SubProblem .*)
1738 fun all_modspec (pt, (p,_):pos') =
1740 val (PblObj{fmz=(fmz_,_), origin=(pors, spec as (dI,pI,mI), hdl),
1741 ...}) = get_obj I pt p;
1742 val thy = assoc_thy dI;
1743 val {ppc,...} = get_met mI;
1744 val mors = prep_ori fmz_ thy ppc |> #1;
1745 val pt = update_pblppc pt p (map (ori2Coritm ppc) pors);
1746 val pt = update_metppc pt p (map (ori2Coritm ppc) mors);
1747 val pt = update_spec pt p (dI,pI,mI);
1748 in (pt, (p,Met): pos') end;
1750 (*WN.12.03: use in nxt_spec, too ? what about variants ???*)
1751 fun is_complete_mod_ ([]: itm list) = false
1752 | is_complete_mod_ itms =
1753 foldl and_ (true, (map #3 itms));
1755 fun is_complete_mod (pt, pos as (p, Pbl): pos') =
1756 if (is_pblobj o (get_obj I pt)) p
1757 then (is_complete_mod_ o (get_obj g_pbl pt)) p
1758 else error ("is_complete_mod: called by PrfObj at "^pos'2str pos)
1759 | is_complete_mod (pt, pos as (p, Met)) =
1760 if (is_pblobj o (get_obj I pt)) p
1761 then (is_complete_mod_ o (get_obj g_met pt)) p
1762 else error ("is_complete_mod: called by PrfObj at "^pos'2str pos)
1763 | is_complete_mod (_, pos) =
1764 error ("is_complete_mod called by " ^ pos'2str pos ^
1765 " (should be Pbl or Met)");
1767 (*.have (thy, pbl, met) _all_ been specified explicitly ?.*)
1768 fun is_complete_spec (pt, pos as (p,_): pos') =
1769 if (not o is_pblobj o (get_obj I pt)) p
1770 then error ("is_complete_spec: called by PrfObj at "^pos'2str pos)
1771 else let val (dI,pI,mI) = get_obj g_spec pt p
1772 in dI<>e_domID andalso pI<>e_pblID andalso mI<>e_metID end;
1773 (*.complete empty items in specification from origin (pbl, met ev.refined);
1774 assumes 'is_complete_mod'.*)
1775 fun complete_spec (pt, pos as (p,_): pos') =
1776 let val PblObj {origin = (_,ospec,_), spec,...} = get_obj I pt p
1777 val pt = update_spec pt p (some_spec ospec spec)
1780 fun is_complete_modspec ptp =
1781 is_complete_mod ptp andalso is_complete_spec ptp;
1786 fun pt_model (PblObj {meth,spec,origin=(_,spec',hdl),...}) Met =
1787 (* val ((PblObj {meth,spec,origin=(_,spec',hdl),...}), Met) = (ppobj, p_);
1789 let val (_,_,metID) = get_somespec' spec spec'
1791 if metID = e_metID then []
1792 else let val {prls,pre=where_,...} = get_met metID
1793 val pre = check_preconds' prls where_ meth 0
1795 val allcorrect = is_complete_mod_ meth
1796 andalso foldl and_ (true, (map #1 pre))
1797 in ModSpec (allcorrect, Met, hdl, meth, pre, spec) end
1798 | pt_model (PblObj {probl,spec,origin=(_,spec',hdl),...}) _(*Frm,Pbl*) =
1799 (* val ((PblObj {probl,spec,origin=(_,spec',hdl),...}),_) = (ppobj, p_);
1801 let val (_,pI,_) = get_somespec' spec spec'
1803 if pI = e_pblID then []
1804 else let val {prls,where_,cas,...} = get_pbt pI
1805 val pre = check_preconds' prls where_ probl 0
1807 val allcorrect = is_complete_mod_ probl
1808 andalso foldl and_ (true, (map #1 pre))
1809 in ModSpec (allcorrect, Pbl, hdl, probl, pre, spec) end;
1812 fun pt_form (PrfObj {form,...}) = Form form
1813 | pt_form (PblObj {probl,spec,origin=(_,spec',_),...}) =
1814 let val (dI, pI, _) = get_somespec' spec spec'
1815 val {cas,...} = get_pbt pI
1817 NONE => Form (pblterm dI pI)
1818 | SOME t => Form (subst_atomic (mk_env probl) t)
1820 (*vvv takes the tac _generating_ the formula=result, asm ok....
1821 fun pt_result (PrfObj {result=(t,asm), tac,...}) =
1823 if null asm then NONE else SOME asm,
1825 | pt_result (PblObj {result=(t,asm), origin = (_,ospec,_), spec,...}) =
1826 let val (_,_,metID) = some_spec ospec spec
1828 if null asm then NONE else SOME asm,
1829 if metID = e_metID then NONE else SOME (Apply_Method metID)) end;
1830 -------------------------------------------------------------------------*)
1833 (*.pt_extract returns
1834 # the formula at pos
1835 # the tactic applied to this formula
1836 # the list of assumptions generated at this formula
1837 (by application of another tac to the preceding formula !)
1838 pos is assumed to come from the frontend, ie. generated by moveDown.*)
1839 (*cannot be in ctree.sml, because ModSpec has to be calculated*)
1840 fun pt_extract (pt,([],Res)) =
1841 (* val (pt,([],Res)) = ptp;
1843 (* ML_TODO 110417 get assumptions from ctxt !? *)
1844 let val (f, asm) = get_obj g_result pt []
1845 in (Form f, NONE, asm) end
1848 | pt_extract (pt,(p,Res)) =
1849 (* val (pt,(p,Res)) = ptp;
1851 let val (f, asm) = get_obj g_result pt p
1852 val tac = if last_onlev pt p
1853 then if is_pblobj' pt (lev_up p)
1854 then let val (PblObj{spec=(_,pI,_),...}) =
1855 get_obj I pt (lev_up p)
1856 in if pI = e_pblID then NONE
1857 else SOME (Check_Postcond pI) end
1858 else SOME End_Trans (*WN0502 TODO for other branches*)
1859 else let val p' = lev_on p
1860 in if is_pblobj' pt p'
1861 then let val (PblObj{origin = (_,(dI,pI,_),_),...}) =
1863 in SOME (Subproblem (dI, pI)) end
1864 else if f = get_obj g_form pt p'
1865 then SOME (get_obj g_tac pt p')
1866 (*because this Frm ~~~is not on worksheet*)
1867 else SOME (Take (term2str (get_obj g_form pt p')))
1869 in (Form f, tac, asm) end
1871 | pt_extract (pt, pos as (p,p_(*Frm,Pbl*))) =
1872 (* val (pt, pos as (p,p_(*Frm,Pbl*))) = ptp;
1873 val (pt, pos as (p,p_(*Frm,Pbl*))) = (pt, p);
1875 let val ppobj = get_obj I pt p
1876 val f = if is_pblobj ppobj then pt_model ppobj p_
1877 else get_obj pt_form pt p
1878 val tac = g_tac ppobj
1879 in (f, SOME tac, []) end;
1882 (**. get the formula from a ctree-node:
1883 take form+res from PblObj and 1.PrfObj and (PrfObj after PblObj)
1884 take res from all other PrfObj's .**)
1885 (*designed for interSteps, outcommented 04 in favour of calcChangedEvent*)
1886 fun formres p (Nd (PblObj {origin = (_,_, h), result = (r, _),...}, _)) =
1887 [("headline", (p, Frm), h),
1888 ("stepform", (p, Res), r)]
1889 | formres p (Nd (PrfObj {form, result = (r, _),...}, _)) =
1890 [("stepform", (p, Frm), form),
1891 ("stepform", (p, Res), r)];
1893 fun form p (Nd (PrfObj {result = (r, _),...}, _)) =
1894 [("stepform", (p, Res), r)]
1896 (*assumes to take whole level, in particular hd -- for use in interSteps*)
1897 fun get_formress fs p [] = flat fs
1898 | get_formress fs p (nd::nds) =
1899 (* start with 'form+res' and continue with trying 'res' only*)
1900 get_forms (fs @ [formres p nd]) (lev_on p) nds
1901 and get_forms fs p [] = flat fs
1902 | get_forms fs p (nd::nds) =
1904 (* start again with 'form+res' ///ugly repeat with Check_elementwise
1905 then get_formress (fs @ [formres p nd]) (lev_on p) nds *)
1906 then get_forms (fs @ [formres p nd]) (lev_on p) nds
1907 (* continue with trying 'res' only*)
1908 else get_forms (fs @ [form p nd]) (lev_on p) nds;
1910 (**.get an 'interval' 'from' 'to' of formulae from a ptree.**)
1911 (*WN050219 made robust against _'to' below or after Complete nodes
1912 by handling exn caused by move_dn*)
1913 (*WN0401 this functionality belongs to ctree.sml,
1914 but fetching a calc_head requires calculations defined in modspec.sml
1915 transfer to ME/me.sml !!!
1916 WN051224 ^^^ doesnt hold any longer, since only the headline of a calc_head
1917 is returned !!!!!!!!!!!!!
1919 fun eq_pos' (p1,Frm) (p2,Frm) = p1 = p2
1920 | eq_pos' (p1,Res) (p2,Res) = p1 = p2
1921 | eq_pos' (p1,Pbl) (p2,p2_) = p1 = p2 andalso (case p2_ of
1925 | eq_pos' (p1,Met) (p2,p2_) = p1 = p2 andalso (case p2_ of
1929 | eq_pos' _ _ = false;
1931 (*.get an 'interval' from the ctree; 'interval' is w.r.t. the
1932 total ordering Position#compareTo(Position p) in the java-code
1933 val get_interval = fn
1934 : pos' -> : from is "move_up 1st-element" to return
1935 pos' -> : to the last element to be returned; from < to
1936 int -> : level: 0 gets the flattest sub-tree possible
1937 >999 gets the deepest sub-tree possible
1939 (pos' * : of the formula
1940 Term.term) : the formula
1943 fun get_interval from to level pt =
1944 (* val (from,level) = (f,lev);
1945 val (from, to, level) = (([3, 2, 1], Res), ([],Res), 9999);
1947 let fun get_inter c (from:pos') (to:pos') lev pt =
1948 (* val (c, from, to, lev) = ([], from, to, level);
1949 ------for recursion.......
1950 val (c, from:pos', to:pos') = (c @ [(from, f)], move_dn [] pt from, to);
1952 if eq_pos' from to orelse from = ([],Res)
1953 (*orelse ... avoids Exception- PTREE "end of calculation" raised,
1954 if 'to' has values NOT generated by move_dn, see systest/me.sml
1955 TODO.WN0501: introduce an order on pos' and check "from > to"..
1956 ...there is an order in Java!
1957 WN051224 the hack got worse with returning term instead ptform*)
1958 then let val (f,_,_) = pt_extract (pt, from)
1960 ModSpec (_,_,headline,_,_,_) => c @ [(from, headline)]
1961 | Form t => c @ [(from, t)]
1964 if lev < lev_of from
1965 then (get_inter c (move_dn [] pt from) to lev pt)
1966 handle (PTREE _(*from move_dn too far*)) => c
1967 else let val (f,_,_) = pt_extract (pt, from)
1968 val term = case f of
1969 ModSpec (_,_,headline,_,_,_)=> headline
1971 in (get_inter (c @ [(from, term)])
1972 (move_dn [] pt from) to lev pt)
1973 handle (PTREE _(*from move_dn too far*))
1974 => c @ [(from, term)] end
1975 in get_inter [] from to level pt end;
1978 fun posform2str (pos:pos', form) =
1979 "("^ pos'2str pos ^", "^
1981 Form f => term2str f
1982 | ModSpec c => term2str (#3 c(*the headline*)))
1984 fun posforms2str pfs = (strs2str' o (map (curry op ^ "\n")) o
1985 (map posform2str)) pfs;
1986 fun posterm2str (pos:pos', t) =
1987 "("^ pos'2str pos ^", "^term2str t^")";
1988 fun posterms2str pfs = (strs2str' o (map (curry op ^ "\n")) o
1989 (map posterm2str)) pfs;
1992 (*WN050225 omits the last step, if pt is incomplete*)
1994 tracing (posterms2str (get_interval ([],Frm) ([],Res) 99999 pt));
1996 (*.get a calchead from a PblObj-node in the ctree;
1997 preconditions must be calculated.*)
1998 fun get_ocalhd (pt, pos' as (p,Pbl):pos') =
1999 let val PblObj {origin = (oris, ospec, hdf'), spec, probl,...} =
2001 val {prls,where_,...} = get_pbt (#2 (some_spec ospec spec))
2002 val pre = check_preconds (assoc_thy"Isac") prls where_ probl
2003 in (ocalhd_complete probl pre spec, Pbl, hdf', probl, pre, spec):ocalhd end
2004 | get_ocalhd (pt, pos' as (p,Met):pos') =
2005 let val PblObj {fmz = fmz as (fmz_,_), origin = (oris, ospec, hdf'),
2008 val {prls,pre,...} = get_met (#3 (some_spec ospec spec))
2009 val pre = check_preconds (assoc_thy"Isac") prls pre meth
2010 in (ocalhd_complete meth pre spec, Met, hdf', meth, pre, spec):ocalhd end;
2012 (*.at the activeFormula set the Model, the Guard and the Specification
2013 to empty and return a CalcHead;
2014 the 'origin' remains (for reconstructing all that).*)
2015 fun reset_calchead (pt, pos' as (p,_):pos') =
2016 let val PblObj {origin = (_, _, hdf'),...} = get_obj I pt p
2017 val pt = update_pbl pt p []
2018 val pt = update_met pt p []
2019 val pt = update_spec pt p e_spec
2020 in (pt, (p,Pbl):pos') end;