src/Tools/isac/ME/calchead.sml
branchisac-update-Isa09-2
changeset 37934 56f10b13005e
parent 37932 722c19bfb6ba
child 37936 8de0b6207074
equal deleted inserted replaced
37933:b65c6037eb6d 37934:56f10b13005e
     4    991122
     4    991122
     5    (c) due to copyright terms
     5    (c) due to copyright terms
     6 
     6 
     7 use"ME/calchead.sml";
     7 use"ME/calchead.sml";
     8 use"calchead.sml";
     8 use"calchead.sml";
       
     9 12345678901234567890123456789012345678901234567890123456789012345678901234567890
       
    10         10        20        30        40        50        60        70        80
     9 *)
    11 *)
    10 
    12 
    11 (* TODO interne Funktionen aus sig entfernen *)
    13 (* TODO interne Funktionen aus sig entfernen *)
    12 signature CALC_HEAD =
    14 signature CALC_HEAD =
    13   sig
    15   sig
    21        SpecifyTools.ori list ->
    23        SpecifyTools.ori list ->
    22        SpecifyTools.itm list ->
    24        SpecifyTools.itm list ->
    23        (string * (Term.term * Term.term)) list -> cterm' -> additm
    25        (string * (Term.term * Term.term)) list -> cterm' -> additm
    24     type calcstate
    26     type calcstate
    25     type calcstate'
    27     type calcstate'
    26     val chk_vars : Thm.cterm SpecifyTools.ppc -> string * Term.term list
    28     val chk_vars : term ppc -> string * Term.term list
    27     val chktyp :
    29     val chktyp :
    28        theory -> int * Thm.cterm list * Thm.cterm list -> Thm.cterm
    30        theory -> int * term list * term list -> term
    29     val chktyps :
    31     val chktyps :
    30        theory -> Thm.cterm list * Thm.cterm list -> Thm.cterm list
    32        theory -> term list * term list -> term list
    31     val complete_metitms :
    33     val complete_metitms :
    32    SpecifyTools.ori list ->
    34    SpecifyTools.ori list ->
    33    SpecifyTools.itm list ->
    35    SpecifyTools.itm list ->
    34    SpecifyTools.itm list -> pat list -> SpecifyTools.itm list
    36    SpecifyTools.itm list -> pat list -> SpecifyTools.itm list
    35     val complete_mod_ : ori list * pat list * pat list * itm list ->
    37     val complete_mod_ : ori list * pat list * pat list * itm list ->
   191        cterm' * 'a ->
   193        cterm' * 'a ->
   192        int list * pos_ ->
   194        int list * pos_ ->
   193        'b ->
   195        'b ->
   194        ptree ->
   196        ptree ->
   195        (pos * pos_) * ((pos * pos_) * istate) * mout * tac * safe * ptree
   197        (pos * pos_) * ((pos * pos_) * istate) * mout * tac * safe * ptree
   196     val tag_form : theory -> Thm.cterm * Thm.cterm -> Thm.cterm
   198     val tag_form : theory -> term * term -> term
   197     val test_types : theory -> Term.term * Term.term list -> string
   199     val test_types : theory -> Term.term * Term.term list -> string
   198     val typeless : Term.term -> Term.term
   200     val typeless : Term.term -> Term.term
   199     val unbound_ppc : Thm.cterm SpecifyTools.ppc -> Term.term list
   201     val unbound_ppc : term SpecifyTools.ppc -> Term.term list
   200     val vals_of_oris : SpecifyTools.ori list -> Term.term list
   202     val vals_of_oris : SpecifyTools.ori list -> Term.term list
   201     val variants_in : Term.term list -> int
   203     val variants_in : Term.term list -> int
   202     val vars_of_pbl_ : ('a * ('b * Term.term)) list -> Term.term list
   204     val vars_of_pbl_ : ('a * ('b * Term.term)) list -> Term.term list
   203     val vars_of_pbl_' : ('a * ('b * Term.term)) list -> Term.term list
   205     val vars_of_pbl_' : ('a * ('b * Term.term)) list -> Term.term list
   204   end
   206   end
   277 
   279 
   278 
   280 
   279 (*.to an input (d,ts) find the according ori and insert the ts.*)
   281 (*.to an input (d,ts) find the according ori and insert the ts.*)
   280 (*WN.11.03: + dont take first inter<>[]*)
   282 (*WN.11.03: + dont take first inter<>[]*)
   281 fun seek_oridts thy sel (d,ts) [] = 
   283 fun seek_oridts thy sel (d,ts) [] = 
   282   ("'"^(Syntax.string_of_term (thy2ctxt' thy) (comp_dts thy (d,ts)))^
   284   ("'"^(Syntax.string_of_term (thy2ctxt thy) (comp_dts thy (d,ts)))^
   283  (*"' not found (typed)", e_ori_:ori, [])          ///11.11.03*)
       
   284    "' not found (typed)", (0,[],sel,d,ts):ori, [])
   285    "' not found (typed)", (0,[],sel,d,ts):ori, [])
   285   (* val (id,vat,sel',d',ts')::oris = ori;
   286   (* val (id,vat,sel',d',ts')::oris = ori;
   286      val (id,vat,sel',d',ts') = ori;
   287      val (id,vat,sel',d',ts') = ori;
   287      *)
   288      *)
   288   | seek_oridts thy sel (d,ts) ((id,vat,sel',d',ts')::(oris:ori list)) =
   289   | seek_oridts thy sel (d,ts) ((id,vat,sel',d',ts')::(oris:ori list)) =
   289     if sel = sel' andalso d=d' andalso (ts inter ts') <> [] 
   290     if sel = sel' andalso d=d' andalso (inter op = ts ts') <> [] 
   290       then if sel = sel' 
   291     then if sel = sel' 
   291 	     then ("",(id,vat,sel,d, ts inter(*!overlap!*) ts'):ori, ts')
   292 	 then ("", 
   292 	   else ((Syntax.string_of_term (thy2ctxt' thy) (comp_dts thy(d,ts)))^
   293                (id,vat,sel,d, inter op = ts ts'):ori, 
   293 		 " not for "^sel, e_ori_, [])
   294                ts')
       
   295 	 else ((Syntax.string_of_term (thy2ctxt thy) (comp_dts thy (d,ts))) 
       
   296                ^ " not for " ^ sel, 
       
   297                e_ori_, 
       
   298                [])
   294     else seek_oridts thy sel (d,ts) oris;
   299     else seek_oridts thy sel (d,ts) oris;
   295 
   300 
   296 (*.to an input (_,ts) find the according ori and insert the ts.*)
   301 (*.to an input (_,ts) find the according ori and insert the ts.*)
   297 fun seek_orits thy sel ts [] = 
   302 fun seek_orits thy sel ts [] = 
   298   ("'"^
   303   ("'"^
   299    (strs2str (map (Syntax.string_of_term (thy2ctxt' thy)) ts))^
   304    (strs2str (map (Syntax.string_of_term (thy2ctxt thy)) ts))^
   300    "' not found (typed)", e_ori_, [])
   305    "' not found (typed)", e_ori_, [])
   301   | seek_orits thy sel ts ((id,vat,sel',d,ts')::(oris:ori list)) =
   306   | seek_orits thy sel ts ((id,vat,sel',d,ts')::(oris:ori list)) =
   302     if sel = sel' andalso (ts inter ts') <> [] 
   307     if sel = sel' andalso (inter op = ts ts') <> [] 
   303       then if sel = sel' 
   308       then if sel = sel' 
   304 	   then ("",(id,vat,sel,d,ts inter(*!overlap!*) ts'):ori, ts')
   309 	   then ("",
   305 	   else (((strs2str' o map (Syntax.string_of_term (thy2ctxt' thy))) ts)^
   310                  (id,vat,sel,d, inter op = ts ts'):ori, 
   306 		 " not for "^sel, e_ori_, [])
   311                  ts')
       
   312 	   else (((strs2str' o map (Syntax.string_of_term (thy2ctxt thy))) ts)
       
   313                  ^ " not for "^sel, 
       
   314                  e_ori_, 
       
   315                  [])
   307     else seek_orits thy sel ts oris;
   316     else seek_orits thy sel ts oris;
   308 (* false
   317 (* false
   309 > val ((id,vat,sel',d,ts')::(ori':ori)) = ori;
   318 > val ((id,vat,sel',d,ts')::(ori':ori)) = ori;
   310 > seek_orits thy sel ts [(id,vat,sel',d,ts')];
   319 > seek_orits thy sel ts [(id,vat,sel',d,ts')];
   311 uncaught exception TYPE
   320 uncaught exception TYPE
   343 			     else ([n], x::xs);
   352 			     else ([n], x::xs);
   344     fun coll eq  xs [] = xs
   353     fun coll eq  xs [] = xs
   345       | coll eq  xs (y::ys) = 
   354       | coll eq  xs (y::ys) = 
   346       let val (n,ys') = cnt eq (y::ys) y 0;
   355       let val (n,ys') = cnt eq (y::ys) y 0;
   347       in if ys' = [] then xs @ n else coll eq  (xs @ n) ys' end;
   356       in if ys' = [] then xs @ n else coll eq  (xs @ n) ys' end;
   348     val vts = (distinct (coll eq [] ts))\\[1];
   357     val vts = subtract op = [1] (distinct (coll eq [] ts));
   349   in case vts of [] => 1 | [n] => n
   358   in case vts of [] => 1 | [n] => n
   350       | _ => error "different variants in formalization" end;
   359       | _ => error "different variants in formalization" end;
   351 (*
   360 (*
   352 > cnt (op=) [2,2,2,4,5,5,5,5,5] 2 0;
   361 > cnt (op=) [2,2,2,4,5,5,5,5,5] 2 0;
   353 val it = ([3],[4,5,5,5,5,5]) : int list * int list
   362 val it = ([3],[4,5,5,5,5,5]) : int list * int list
   395 val it = true : bool
   404 val it = true : bool
   396 > val (SOME ct) = parse thy "[lll::real]";
   405 > val (SOME ct) = parse thy "[lll::real]";
   397 > has_list_type (term_of ct);
   406 > has_list_type (term_of ct);
   398 val it = false : bool *)
   407 val it = false : bool *)
   399 
   408 
   400 
       
   401 
       
   402 
       
   403 (*fdcrs = descriptions in formalization
       
   404   unused 22.11.00
       
   405 fun is_already_input thy fdcrs ts t = 
       
   406   let 
       
   407     val tss = flat (map isalist2list ts);
       
   408 (*28.1.     val (dcr,t') = split_dsc_t fdcrs t; *)
       
   409     val (dcr,[t']) = split_dts t;
       
   410   in if (typeless t') mem (map typeless tss)
       
   411             then ("term '"^(Syntax.string_of_term (thy2ctxt' thy) t')^
       
   412 		  "' already input")
       
   413 	  else "" end;
       
   414 
       
   415 > val pts = appc (map (term_of o the o (parse thy))) pbl;
       
   416 > val ts = #Relate pts;
       
   417 > val t = (term_of o the o (parse thy))"(A=#2*a*b - a^^^#2)";
       
   418 > is_already_input thy ts t;
       
   419 val it = "term 'A = #2 * a * b - a ^^^ #2' already input" : string
       
   420 > val t = (term_of o the o (parse thy))"a=#2*R*sin alpha";
       
   421 > is_already_input thy ts t;
       
   422 val it = "term 'a = #2 * R * sin alpha' already input" : string
       
   423 > val t = (term_of o the o (parse thy))"a=R*sin alpha";
       
   424 > is_already_input thy ts t;
       
   425 val it = "" : string
       
   426 *)
       
   427 
       
   428 
       
   429 fun is_parsed (Syn _) = false
   409 fun is_parsed (Syn _) = false
   430   | is_parsed _ = true;
   410   | is_parsed _ = true;
   431 fun parse_ok its = foldl and_ (true, map is_parsed its);
   411 fun parse_ok its = foldl and_ (true, map is_parsed its);
   432 
   412 
   433 fun all_dsc_in itm_s =
   413 fun all_dsc_in itm_s =
   500 
   480 
   501 (*.get the first term in ts from ori.*)
   481 (*.get the first term in ts from ori.*)
   502 (* val (_,_,fd,d,ts) = hd miss;
   482 (* val (_,_,fd,d,ts) = hd miss;
   503    *)
   483    *)
   504 fun getr_ct thy ((_,_,fd,d,ts):ori) =
   484 fun getr_ct thy ((_,_,fd,d,ts):ori) =
   505   (fd, (string_of_cterm o (comp_dts thy)) (d,[hd ts]):cterm');
   485   (fd, ((Syntax.string_of_term (thy2ctxt thy)) o 
       
   486         (comp_dts thy)) (d,[hd ts]):cterm');
   506 (* val t = comp_dts thy (d,[hd ts]);
   487 (* val t = comp_dts thy (d,[hd ts]);
   507    *)
   488    *)
   508 
   489 
   509 (* get a term from ori, notyet input in itm *)
   490 (* get a term from ori, notyet input in itm *)
   510 fun geti_ct thy ((_,_,_,d,ts):ori) ((_,_,_,fd,itm_):itm) =  
   491 fun geti_ct thy ((_,_,_,d,ts):ori) ((_,_,_,fd,itm_):itm) =  
   511   (fd, (string_of_cterm o (comp_dts thy)) (d,ts \\ (ts_in itm_)):cterm');
   492   (fd, ((Syntax.string_of_term (thy2ctxt thy)) o (comp_dts thy)) 
       
   493            (d, subtract op = (ts_in itm_) ts):cterm');
   512 (* test-maximum.sml fmy <> [], Init_Proof ...
   494 (* test-maximum.sml fmy <> [], Init_Proof ...
   513    val (_,_,_,d,ts) = ori; val (_,_,_,fd,itm_) = hd icl;
   495    val (_,_,_,d,ts) = ori; val (_,_,_,fd,itm_) = hd icl;
   514    val d' $ ts' = (term_of o the o (parse thy)) "fixedValues [r=Arbfix]";
   496    val d' $ ts' = (term_of o the o (parse thy)) "fixedValues [r=Arbfix]";
   515    atomty d;
   497    atomty d;
   516    atomty d';
   498    atomty d';
   517    atomty (hd ts);
   499    atomty (hd ts);
   518    atomty ts';
   500    atomty ts';
   519    cterm_of (sign_of thy) (d $ (hd ts));
   501    Thm.cterm_of thy (d $ (hd ts));
   520    cterm_of (sign_of thy) (d' $ ts');
   502    Thm.cterm_of thy (d' $ ts');
   521 
   503 
   522    comp_dts thy (d,ts);
   504    comp_dts thy (d,ts);
   523    *)
   505    *)
   524 
   506 
   525 
   507 
   528   | is_untouched _ = false;
   510   | is_untouched _ = false;
   529 
   511 
   530 
   512 
   531 (* select an item in oris, notyet input in itms 
   513 (* select an item in oris, notyet input in itms 
   532    (precondition: in itms are only Cor, Sup, Inc) *)
   514    (precondition: in itms are only Cor, Sup, Inc) *)
       
   515 local
       
   516 infix mem;
       
   517 fun x mem [] = false
       
   518   | x mem (y :: ys) = x = y orelse x mem ys;
       
   519 in 
   533 fun nxt_add thy ([]:ori list) pbt itms = (*root (only) ori...fmz=[]*)
   520 fun nxt_add thy ([]:ori list) pbt itms = (*root (only) ori...fmz=[]*)
   534   let
   521   let
   535     fun test_d d ((i,_,_,_,itm_):itm) = (d = (d_in itm_)) andalso i<>0; 
   522     fun test_d d ((i,_,_,_,itm_):itm) = (d = (d_in itm_)) andalso i<>0; 
   536     fun is_elem itms (f,(d,t)) = 
   523     fun is_elem itms (f,(d,t)) = 
   537       case find_first (test_d d) itms of 
   524       case find_first (test_d d) itms of 
   538 	SOME _ => true | NONE => false;
   525 	SOME _ => true | NONE => false;
   539   in case filter_out (is_elem itms) pbt of
   526   in case filter_out (is_elem itms) pbt of
   540 (* val ((f,(d,_))::itms) = filter_out (is_elem itms) pbt;
   527 (* val ((f,(d,_))::itms) = filter_out (is_elem itms) pbt;
   541    *)
   528    *)
   542     (f,(d,_))::itms => 
   529     (f,(d,_))::itms => 
   543       SOME (f:string, (string_of_cterm o comp_dts thy) (d,[]):cterm')
   530       SOME (f:string, ((Syntax.string_of_term (thy2ctxt thy)) o comp_dts thy) (d,[]):cterm')
   544   | _ => NONE end
   531   | _ => NONE end
   545 
   532 
   546 (* val (thy,itms) = (assoc_thy (if dI=e_domID then dI' else dI),pbl);
   533 (* val (thy,itms) = (assoc_thy (if dI=e_domID then dI' else dI),pbl);
   547    *)
   534    *)
   548   | nxt_add thy oris pbt itms =
   535   | nxt_add thy oris pbt itms =
   552     fun testi_vt v itm = (curry (op mem) v) (#2 (itm:itm));
   539     fun testi_vt v itm = (curry (op mem) v) (#2 (itm:itm));
   553     fun test_id ids r = curry (op mem) (#1 (r:ori)) ids;
   540     fun test_id ids r = curry (op mem) (#1 (r:ori)) ids;
   554 (* val itm = hd icl; val (_,_,_,d,ts) = v6;
   541 (* val itm = hd icl; val (_,_,_,d,ts) = v6;
   555    *)
   542    *)
   556     fun test_subset (itm:itm) ((_,_,_,d,ts):ori) = 
   543     fun test_subset (itm:itm) ((_,_,_,d,ts):ori) = 
   557 	(d_in (#5 itm)) = d andalso (ts_in (#5 itm)) subset ts;
   544 	(d_in (#5 itm)) = d andalso subset op = (ts_in (#5 itm), ts);
   558     fun false_and_not_Sup((i,v,false,f,Sup _):itm) = false
   545     fun false_and_not_Sup((i,v,false,f,Sup _):itm) = false
   559       | false_and_not_Sup (i,v,false,f, _) = true
   546       | false_and_not_Sup (i,v,false,f, _) = true
   560       | false_and_not_Sup  _ = false;
   547       | false_and_not_Sup  _ = false;
   561 
   548 
   562     val v = if itms = [] then 1 else max_vt itms;
   549     val v = if itms = [] then 1 else max_vt itms;
   574 	 case find_first (test_subset (hd icl)) vors of
   561 	 case find_first (test_subset (hd icl)) vors of
   575 	     (* val SOME ori = find_first (test_subset (hd icl)) vors;
   562 	     (* val SOME ori = find_first (test_subset (hd icl)) vors;
   576 	      *)
   563 	      *)
   577 	     NONE => raise error "nxt_add: EX itm. not(dat(itm)<=dat(ori))"
   564 	     NONE => raise error "nxt_add: EX itm. not(dat(itm)<=dat(ori))"
   578 	   | SOME ori => SOME (geti_ct thy ori (hd icl))
   565 	   | SOME ori => SOME (geti_ct thy ori (hd icl))
   579   end;
   566   end
       
   567 end;
   580 
   568 
   581 
   569 
   582 
   570 
   583 fun mk_delete thy "#Given"  itm_ = Del_Given   (itm_out thy itm_)
   571 fun mk_delete thy "#Given"  itm_ = Del_Given   (itm_out thy itm_)
   584   | mk_delete thy "#Find"   itm_ = Del_Find    (itm_out thy itm_)
   572   | mk_delete thy "#Find"   itm_ = Del_Find    (itm_out thy itm_)
   697 
   685 
   698 (*3.3.--
   686 (*3.3.--
   699 fun update_itm (cl,d,ts) ((id,vt,_,sl,Cor (_,_)):itm) = 
   687 fun update_itm (cl,d,ts) ((id,vt,_,sl,Cor (_,_)):itm) = 
   700   (id,vt,cl,sl,Cor (d,ts)):itm
   688   (id,vt,cl,sl,Cor (d,ts)):itm
   701   | update_itm (cl,d,ts) (id,vt,_,sl,Syn (_)) =   
   689   | update_itm (cl,d,ts) (id,vt,_,sl,Syn (_)) =   
   702   raise error ("update_itm "^(string_of_cterm (comp_dts thy (d,ts)))^
   690   raise error ("update_itm "^((Syntax.string_of_term (thy2ctxt thy)) (comp_dts thy (d,ts)))^
   703 	       " not not for Syn (s:cterm')")
   691 	       " not not for Syn (s:cterm')")
   704   | update_itm (cl,d,ts) (id,vt,_,sl,Typ (_)) = 
   692   | update_itm (cl,d,ts) (id,vt,_,sl,Typ (_)) = 
   705   raise error ("update_itm "^(string_of_cterm (comp_dts thy (d,ts)))^
   693   raise error ("update_itm "^((Syntax.string_of_term (thy2ctxt thy)) (comp_dts thy (d,ts)))^
   706 	       " not not for Typ (s:cterm')")
   694 	       " not not for Typ (s:cterm')")
   707   | update_itm (cl,d,ts) (id,vt,_,sl,Fal (_,_)) =
   695   | update_itm (cl,d,ts) (id,vt,_,sl,Fal (_,_)) =
   708   (id,vt,cl,sl,Fal (d,ts))
   696   (id,vt,cl,sl,Fal (d,ts))
   709   | update_itm (cl,d,ts) (id,vt,_,sl,Inc (_,_)) =
   697   | update_itm (cl,d,ts) (id,vt,_,sl,Inc (_,_)) =
   710   (id,vt,cl,sl,Inc (d,ts))
   698   (id,vt,cl,sl,Inc (d,ts))
   716 
   704 
   717 
   705 
   718 fun is_field_correct sel d dscpbt =
   706 fun is_field_correct sel d dscpbt =
   719   case assoc (dscpbt, sel) of
   707   case assoc (dscpbt, sel) of
   720     NONE => false
   708     NONE => false
   721   | SOME ds => d mem ds;
   709   | SOME ds => member op = ds d;
   722 
   710 
   723 (*. update the itm_ already input, all..from ori .*)
   711 (*. update the itm_ already input, all..from ori .*)
   724 (* val (id,vt,fd,d,ts) = (i,v,f,d,ts\\ts');
   712 (* val (id,vt,fd,d,ts) = (i,v,f,d,ts\\ts');
   725    *)
   713    *)
   726 fun ori_2itm thy itm_ pid all ((id,vt,fd,d,ts):ori) = 
   714 fun ori_2itm thy itm_ pid all ((id,vt,fd,d,ts):ori) = 
   727   let 
   715   let 
   728     val ts' = union op = (ts_in itm_) ts;
   716     val ts' = union op = (ts_in itm_) ts;
   729     val pval = pbl_ids' thy d ts'
   717     val pval = pbl_ids' thy d ts'
   730 	(*WN.9.5.03: FIXXXME [#0, epsilon]
   718 	(*WN.9.5.03: FIXXXME [#0, epsilon]
   731 	  here would upd_penv be called for [#0, epsilon] etc. *)
   719 	  here would upd_penv be called for [#0, epsilon] etc. *)
   732     val complete = if eq_set (ts', all) then true else false;
   720     val complete = if eq_set op = (ts', all) then true else false;
   733   in case itm_ of
   721   in case itm_ of
   734     (Cor _) => 
   722     (Cor _) => 
   735 	(if fd = "#undef" then (id,vt,complete,fd,Sup(d,ts')) 
   723 	(if fd = "#undef" then (id,vt,complete,fd,Sup(d,ts')) 
   736 	 else (id,vt,complete,fd,Cor((d,ts'),(pid, pval)))):itm
   724 	 else (id,vt,complete,fd,Cor((d,ts'),(pid, pval)))):itm
   737   | (Syn c)     => raise error ("ori_2itm wants to overwrite "^c)
   725   | (Syn c)     => raise error ("ori_2itm wants to overwrite "^c)
   772                             val SOME (_,_,_,_,itm_)=find_first (eq3 f d) itms;
   760                             val SOME (_,_,_,_,itm_)=find_first (eq3 f d) itms;
   773 			   *)
   761 			   *)
   774       (case find_first (eq3 f d) itms of
   762       (case find_first (eq3 f d) itms of
   775 	   SOME (_,_,_,_,itm_) =>
   763 	   SOME (_,_,_,_,itm_) =>
   776 	   let 
   764 	   let 
   777 	       val ts' = (ts_in itm_) inter ts;
   765 	       val ts' = inter op = (ts_in itm_) ts;
   778 	   in if ts subset ts' 
   766 	   in if subset op = (ts, ts') 
   779 	      then (((strs2str' o 
   767 	      then (((strs2str' o 
   780 		      map (Syntax.string_of_term (thy2ctxt' thy))) ts')^
   768 		      map (Syntax.string_of_term (thy2ctxt thy))) ts')^
   781 		    " already input", e_itm)                            (*2*)
   769 		    " already input", e_itm)                            (*2*)
   782 	      else ("", ori_2itm thy itm_ pid all (i,v,f,d,ts\\ts'))    (*3,4*)
   770 	      else ("", 
       
   771                     ori_2itm thy itm_ pid all (i,v,f,d,
       
   772                                                subtract op = ts' ts))   (*3,4*)
   783 	   end
   773 	   end
   784 	 | NONE => ("", ori_2itm thy (Inc ((e_term,[]),(pid,[]))) 
   774 	 | NONE => ("", ori_2itm thy (Inc ((e_term,[]),(pid,[]))) 
   785 				 pid all (i,v,f,d,ts))                  (*1*)
   775 				 pid all (i,v,f,d,ts))                  (*1*)
   786 	)
   776 	)
   787     | NONE => ("", ori_2itm thy (Sup (d,ts)) 
   777     | NONE => ("", ori_2itm thy (Sup (d,ts)) 
   788 			      e_term all (i,v,f,d,ts));
   778 			      e_term all (i,v,f,d,ts));
   789 (*------------------------------------------------
       
   790 fun eq3 f d (_,_,_,f',itm_) = f = f' andalso d = (d_in itm_); 
       
   791 fun is_notyet_input thy itms pval all ((id,vt,fd,d,ts):ori) pbt =
       
   792   case find_first (eq1 d) pbt of
       
   793       SOME (_,(_,pid)) => (* val SOME (_,(_,pid)) = find_first (eq1 d) pbt;
       
   794                               *)
       
   795       (case seek_ppc id itms of
       
   796 	   SOME (id',_,_,_,itm_) =>
       
   797 	   let 
       
   798 	       val ts' = (ts_in itm_) inter ts;
       
   799 	   in if ts'= [] then ("", ori_2itm itm_ (pid, pval) all 
       
   800 					    (id,vt,fd,d,(ts_in itm_)@ts))
       
   801 	      else (((strs2str' o 
       
   802 		      map (Syntax.string_of_term (thy2ctxt' thy))) ts')^
       
   803 		    " already input", e_itm) end
       
   804 	 | NONE => 
       
   805 	   if all = ts 
       
   806 	   then ("", ori_2itm (Cor ((e_term,[]),(pid,[])))
       
   807 			      (pid, pval) all (id,vt,fd,d,ts))
       
   808 	   else ("", ori_2itm (Inc ((e_term,[]),(e_term,[]))) 
       
   809 			      (pid, pval) all (id,vt,fd,d,ts))
       
   810 	)
       
   811     | NONE => ("", ori_2itm (Sup (e_term,[])) 
       
   812 			      (e_term, []) all (id,vt,fd,d,ts));----*)
       
   813 
   779 
   814 fun test_types thy (d,ts) =
   780 fun test_types thy (d,ts) =
   815   let 
   781   let 
   816     val s = !show_types; val _ = show_types:= true;
   782     val s = !show_types; val _ = show_types:= true;
   817     val opt = (try (comp_dts thy)) (d,ts);
   783     val opt = (try (comp_dts thy)) (d,ts);
   818     val msg = case opt of 
   784     val msg = case opt of 
   819       SOME _ => "" 
   785       SOME _ => "" 
   820     | NONE => ((Sign.string_of_term  (sign_of thy) d)^" "^
   786     | NONE => ((Syntax.string_of_term (thy2ctxt thy) d)^" "^
   821 	     ((strs2str' o map (Sign.string_of_term(sign_of thy)))ts)
   787 	     ((strs2str' o map (Syntax.string_of_term (thy2ctxt thy))) ts)
   822 	     ^" is illtyped");
   788 	     ^ " is illtyped");
   823     val _ = show_types:= s
   789     val _ = show_types:= s
   824   in msg end;
   790   in msg end;
   825 
   791 
   826 
   792 
   827 
   793 
   844     val oids = ((map (fst o dest_Free)) o distinct o 
   810     val oids = ((map (fst o dest_Free)) o distinct o 
   845 		flat o (map vars)) ots;
   811 		flat o (map vars)) ots;
   846     val (d,ts(*,pval*)) = split_dts thy t;
   812     val (d,ts(*,pval*)) = split_dts thy t;
   847     val ids = map (fst o dest_Free) 
   813     val ids = map (fst o dest_Free) 
   848       ((distinct o (flat o (map vars))) ts);
   814       ((distinct o (flat o (map vars))) ts);
   849   in if (ids \\ oids) <> []
   815   in if (subtract op = oids ids) <> []
   850      then (("identifiers "^(strs2str' (ids \\ oids))^
   816      then (("identifiers "^(strs2str' (subtract op = oids ids))^
   851 	    " not in example"), e_ori_, [])
   817 	    " not in example"), e_ori_, [])
   852      else 
   818      else 
   853 	 if d = e_term 
   819 	 if d = e_term 
   854 	 then 
   820 	 then 
   855 	     if not ((map typeless ts) subset (map typeless ots))
   821 	     if not (subset op = (map typeless ts, map typeless ots))
   856 	     then (("terms '"^
   822 	     then (("terms '"^
   857 		    ((strs2str' o (map (Sign.string_of_term 
   823 		    ((strs2str' o (map (Syntax.string_of_term 
   858 					    (sign_of thy)))) ts)^
   824 					    (thy2ctxt thy)))) ts)^
   859 		    "' not in example (typeless)"), e_ori_, [])
   825 		    "' not in example (typeless)"), e_ori_, [])
   860 	     else (case seek_orits thy sel ts ori of
   826 	     else (case seek_orits thy sel ts ori of
   861 		       ("", ori_ as (_,_,_,d,ts), all) =>
   827 		       ("", ori_ as (_,_,_,d,ts), all) =>
   862 		       (case test_types thy (d,ts) of
   828 		       (case test_types thy (d,ts) of
   863 			    "" => ("", ori_, all)
   829 			    "" => ("", ori_, all)
   864 			  | msg => (msg, e_ori_, []))
   830 			  | msg => (msg, e_ori_, []))
   865 		     | (msg,_,_) => (msg, e_ori_, []))
   831 		     | (msg,_,_) => (msg, e_ori_, []))
   866 	 else 
   832 	 else 
   867 	     if d mem (map #4 ori) 
   833 	     if member op = (map #4 ori) d
   868 	     then seek_oridts thy sel (d,ts) ori
   834 	     then seek_oridts thy sel (d,ts) ori
   869 	     else ((Syntax.string_of_term (thy2ctxt' thy) d)^
   835 	     else ((Syntax.string_of_term (thy2ctxt thy) d)^
   870 		   (*" not in example", e_ori_, []) ///11.11.03*)
   836 		   (*" not in example", e_ori_, []) ///11.11.03*)
   871 		   " not in example", (0,[],sel,d,ts), [])
   837 		   " not in example", (0,[],sel,d,ts), [])
   872   end;
   838   end;
   873 
   839 
   874 
   840 
   997 
   963 
   998 
   964 
   999 (*.split type-wrapper from scr-arg and build part of an ori;
   965 (*.split type-wrapper from scr-arg and build part of an ori;
  1000    an type-error is reported immediately, raises an exn, 
   966    an type-error is reported immediately, raises an exn, 
  1001    subsequent handling of exn provides 2nd part of error message.*)
   967    subsequent handling of exn provides 2nd part of error message.*)
  1002 fun mtc thy ((str, (dsc, _)):pat) (ty $ var) =
   968 (*fun mtc thy ((str, (dsc, _)):pat) (ty $ var) =   WN100820 made cterm to term 
  1003     (* val (thy, (str, (dsc, _)), (ty $ var)) =
   969     (* val (thy, (str, (dsc, _)), (ty $ var)) =
  1004 	   (thy,  p,               a);
   970 	   (thy,  p,               a);
  1005        *)
   971        *)
  1006     (cterm_of (sign_of thy) (dsc $ var);(*type check*)
   972     (Thm.cterm_of thy (dsc $ var);(*type check*)
  1007      SOME ((([1], str, dsc, (*[var]*)
   973      SOME ((([1], str, dsc, (*[var]*)
  1008 	    split_dts' (dsc, var))): preori)(*:ori without leading #*))
   974 	    split_dts' (dsc, var))): preori)(*:ori without leading #*))
  1009     handle e  as TYPE _ => 
   975     handle e  as TYPE _ => 
  1010 	   (writeln (dashs 70^"\n"
   976 	   (writeln (dashs 70^"\n"
  1011 		      ^"*** ERROR while creating the items for the model of the ->problem\n"
   977 		      ^"*** ERROR while creating the items for the model of the ->problem\n"
  1015 		      ^"*** value: "^(term_detail2str var)
   981 		      ^"*** value: "^(term_detail2str var)
  1016 		      ^"*** typeconstructor in script: "^(term_detail2str ty)
   982 		      ^"*** typeconstructor in script: "^(term_detail2str ty)
  1017 		      ^"*** checked by theory: "^(theory2str thy)^"\n"
   983 		      ^"*** checked by theory: "^(theory2str thy)^"\n"
  1018 		      ^"*** "^dots 66);	     
   984 		      ^"*** "^dots 66);	     
  1019 	     print_exn e; (*raises exn again*)
   985 	     print_exn e; (*raises exn again*)
       
   986 	    NONE);*)
       
   987 fun mtc thy ((str, (dsc, _)):pat) (ty $ var) =
       
   988     (* val (thy, (str, (dsc, _)), (ty $ var)) =
       
   989 	   (thy,  p,               a);
       
   990        *)
       
   991     (Thm.cterm_of thy (dsc $ var);(*type check*)
       
   992      SOME ((([1], str, dsc, (*[var]*)
       
   993 	    split_dts' (dsc, var))): preori)(*:ori without leading #*))
       
   994     handle e  as TYPE _ => 
       
   995 	   (writeln (dashs 70^"\n"
       
   996 		      ^"*** ERROR while creating the items for the model of the ->problem\n"
       
   997 		      ^"*** from the ->stac with ->typeconstructor in arglist:\n"
       
   998 		      ^"*** item (->description ->value): "^term2str dsc^" "^term2str var^"\n"
       
   999 		      ^"*** description: "^(term_detail2str dsc)
       
  1000 		      ^"*** value: "^(term_detail2str var)
       
  1001 		      ^"*** typeconstructor in script: "^(term_detail2str ty)
       
  1002 		      ^"*** checked by theory: "^(theory2str thy)^"\n"
       
  1003 		      ^"*** "^dots 66);	     
       
  1004 	    (*WN100820 postponed: print_exn e; raises exn again*)
  1020 	    NONE);
  1005 	    NONE);
  1021 (*> val pbt = (#ppc o get_pbt) ["univariate","equation"];
  1006 (*> val pbt = (#ppc o get_pbt) ["univariate","equation"];
  1022 > val Const ("Script.SubProblem",_) $
  1007 > val Const ("Script.SubProblem",_) $
  1023 	  (Const ("Pair",_) $ Free (thy', _) $
  1008 	  (Const ("Pair",_) $ Free (thy', _) $
  1024 		 (Const ("Pair",_) $ pblID' $ metID')) $ ags =
  1009 		 (Const ("Pair",_) $ pblID' $ metID')) $ ags =
  1137     in ((map var_of_pbl_)(* o (filter_out is_copy_named)*)) pbl_ end;
  1122     in ((map var_of_pbl_)(* o (filter_out is_copy_named)*)) pbl_ end;
  1138 
  1123 
  1139 fun overwrite_ppc thy itm ppc =
  1124 fun overwrite_ppc thy itm ppc =
  1140   let 
  1125   let 
  1141     fun repl ppc' (_,_,_,_,itm_) [] =
  1126     fun repl ppc' (_,_,_,_,itm_) [] =
  1142       raise error ("overwrite_ppc: "^(itm__2str thy itm_)^" not found")
  1127       raise error ("overwrite_ppc: " ^ (itm_2str_ (thy2ctxt thy) itm_) ^ 
       
  1128                    " not found")
  1143       | repl ppc' itm (p::ppc) =
  1129       | repl ppc' itm (p::ppc) =
  1144 	if (#1 itm) = (#1 (p:itm)) then ppc' @ [itm] @ ppc
  1130 	if (#1 itm) = (#1 (p:itm)) then ppc' @ [itm] @ ppc
  1145 	else repl (ppc' @ [p]) itm ppc
  1131 	else repl (ppc' @ [p]) itm ppc
  1146   in repl [] itm ppc end;
  1132   in repl [] itm ppc end;
  1147 
  1133 
  1184 	     | pos => raise error ("header called with "^ pos_2str pos);
  1170 	     | pos => raise error ("header called with "^ pos_2str pos);
  1185 
  1171 
  1186 
  1172 
  1187 
  1173 
  1188 (* test-printouts ---
  1174 (* test-printouts ---
  1189 val _=writeln("### insert_ppc: (d,ts)="^(string_of_cterm(comp_dts thy(d,ts))));
  1175 val _=writeln("### insert_ppc: (d,ts)="^((Syntax.string_of_term (thy2ctxt thy))(comp_dts thy(d,ts))));
  1190  val _=writeln("### insert_ppc: pts= "^
  1176  val _=writeln("### insert_ppc: pts= "^
  1191 (strs2str' o map (Syntax.string_of_term (thy2ctxt' thy))) pts);
  1177 (strs2str' o map (Syntax.string_of_term (thy2ctxt thy))) pts);
  1192 
  1178 
  1193 
  1179 
  1194  val sel = "#Given"; val Add_Given' ct = m;
  1180  val sel = "#Given"; val Add_Given' ct = m;
  1195 
  1181 
  1196  val sel = "#Find"; val Add_Find' (ct,_) = m; 
  1182  val sel = "#Find"; val Add_Find' (ct,_) = m; 
  1382   | specify (Specify_Problem' (pI, (ok, (itms, pre)))) (pos as (p,_)) c pt =
  1368   | specify (Specify_Problem' (pI, (ok, (itms, pre)))) (pos as (p,_)) c pt =
  1383   let val (PblObj {origin=(oris,(dI',pI',mI'),_), spec=(dI,_,mI), 
  1369   let val (PblObj {origin=(oris,(dI',pI',mI'),_), spec=(dI,_,mI), 
  1384 		   meth=met, ...}) = get_obj I pt p;
  1370 		   meth=met, ...}) = get_obj I pt p;
  1385     (*val pt = update_pbl pt p itms;
  1371     (*val pt = update_pbl pt p itms;
  1386     val pt = update_pblID pt p pI;*)
  1372     val pt = update_pblID pt p pI;*)
       
  1373     val thy = assoc_thy dI
  1387     val ((p,Pbl),_,_,pt)= 
  1374     val ((p,Pbl),_,_,pt)= 
  1388 	generate1 thy (Specify_Problem' (pI, (ok, (itms, pre)))) Uistate pos pt
  1375 	generate1 thy (Specify_Problem' (pI, (ok, (itms, pre)))) Uistate pos pt
  1389     val dI'' = assoc_thy (if dI=e_domID then dI' else dI);
  1376     val dI'' = assoc_thy (if dI=e_domID then dI' else dI);
  1390     val mI'' = if mI=e_metID then mI' else mI;
  1377     val mI'' = if mI=e_metID then mI' else mI;
  1391   (*val _=writeln("@@@ specify (Specify_Problem) before nxt_spec")*)
  1378   (*val _=writeln("@@@ specify (Specify_Problem) before nxt_spec")*)
  1498 	       
  1485 	       
  1499 	 | Err msg => 
  1486 	 | Err msg => 
  1500 	   (*TODO.WN03 pass error-msgs to the frontend..
  1487 	   (*TODO.WN03 pass error-msgs to the frontend..
  1501              FIXME ..and dont abuse a tactic for that purpose*)
  1488              FIXME ..and dont abuse a tactic for that purpose*)
  1502 	   ([(Tac msg,
  1489 	   ([(Tac msg,
  1503 	      Tac_ (ProtoPure.thy, msg,msg,msg),
  1490 	      Tac_ (theory "Pure", msg,msg,msg),
  1504 	      (e_pos', e_istate))], [], ptp) 
  1491 	      (e_pos', e_istate))], [], ptp) 
  1505     end
  1492     end
  1506 
  1493 
  1507 (* val sel = "#Find"; val (p,_) = p; val Add_Find' ct = nxt;
  1494 (* val sel = "#Find"; val (p,_) = p; val Add_Find' ct = nxt;
  1508    val (_,_,f,nxt',_,pt')= nxt_specif_additem sel ct (p,Met) c pt;
  1495    val (_,_,f,nxt',_,pt')= nxt_specif_additem sel ct (p,Met) c pt;
  1556   | filter_outs oris (i::itms) = 
  1543   | filter_outs oris (i::itms) = 
  1557     let val ors = filter_out ((curry op= ((d_in o #5) (i:itm))) o 
  1544     let val ors = filter_out ((curry op= ((d_in o #5) (i:itm))) o 
  1558 			      (#4:ori -> term)) oris;
  1545 			      (#4:ori -> term)) oris;
  1559     in filter_outs ors itms end;
  1546     in filter_outs ors itms end;
  1560 
  1547 
  1561 fun memI a b = b mem a;
  1548 fun memI a b = member op = a b;
  1562 (*filter oris which are in pbt, too*)
  1549 (*filter oris which are in pbt, too*)
  1563 fun filter_pbt oris pbt =
  1550 fun filter_pbt oris pbt =
  1564     let val dscs = map (fst o snd) pbt
  1551     let val dscs = map (fst o snd) pbt
  1565     in filter ((memI dscs) o (#4: ori -> term)) oris end;
  1552     in filter ((memI dscs) o (#4: ori -> term)) oris end;
  1566 
  1553 
  1567 (*.combine itms from pbl + met and complete them wrt. pbt.*)
  1554 (*.combine itms from pbl + met and complete them wrt. pbt.*)
  1568 (*FIXXXME.WN031205 complete_metitms doesnt handle incorrect itms !*)
  1555 (*FIXXXME.WN031205 complete_metitms doesnt handle incorrect itms !*)
       
  1556 local
       
  1557 infix mem;
       
  1558 fun x mem [] = false
       
  1559   | x mem (y :: ys) = x = y orelse x mem ys;
       
  1560 in 
  1569 fun complete_metitms (oris:ori list) (pits:itm list) (mits:itm list) met = 
  1561 fun complete_metitms (oris:ori list) (pits:itm list) (mits:itm list) met = 
  1570 (* val met = (#ppc o get_met) ["DiffApp","max_by_calculus"];
  1562 (* val met = (#ppc o get_met) ["DiffApp","max_by_calculus"];
  1571    *)
  1563    *)
  1572     let val vat = max_vt pits;
  1564     let val vat = max_vt pits;
  1573         val itms = pits @ 
  1565         val itms = pits @ 
  1574 		   (filter ((curry (op mem) vat) o (#2:itm -> int list)) mits);
  1566 		   (filter ((curry (op mem) vat) o (#2:itm -> int list)) mits);
  1575 	val ors = filter ((curry (op mem) vat) o (#2:ori -> int list)) oris;
  1567 	val ors = filter ((curry (op mem) vat) o (#2:ori -> int list)) oris;
  1576         val os = filter_outs ors itms;
  1568         val os = filter_outs ors itms;
  1577     (*WN.12.03?: does _NOT_ add itms from met ?!*)
  1569     (*WN.12.03?: does _NOT_ add itms from met ?!*)
  1578     in itms @ (map (ori2Coritm met) os) end;
  1570     in itms @ (map (ori2Coritm met) os) end
       
  1571 end;
  1579 
  1572 
  1580 
  1573 
  1581 
  1574 
  1582 (*.complete model and guard of a calc-head .*)
  1575 (*.complete model and guard of a calc-head .*)
       
  1576 local
       
  1577 infix mem;
       
  1578 fun x mem [] = false
       
  1579   | x mem (y :: ys) = x = y orelse x mem ys;
       
  1580 in 
  1583 fun complete_mod_ (oris, mpc, ppc, probl) =
  1581 fun complete_mod_ (oris, mpc, ppc, probl) =
  1584     let	val pits = filter_out ((curry op= false) o (#3: itm -> bool)) probl
  1582     let	val pits = filter_out ((curry op= false) o (#3: itm -> bool)) probl
  1585 	val vat = if probl = [] then 1 else max_vt probl
  1583 	val vat = if probl = [] then 1 else max_vt probl
  1586 	val pors = filter ((curry (op mem) vat) o (#2:ori -> int list)) oris
  1584 	val pors = filter ((curry (op mem) vat) o (#2:ori -> int list)) oris
  1587 	val pors = filter_outs pors pits (*which are in pbl already*)
  1585 	val pors = filter_outs pors pits (*which are in pbl already*)
  1588         val pors = (filter_pbt pors ppc) (*which are in pbt, too*)
  1586         val pors = (filter_pbt pors ppc) (*which are in pbt, too*)
  1589 
  1587 
  1590 	val pits = pits @ (map (ori2Coritm ppc) pors)
  1588 	val pits = pits @ (map (ori2Coritm ppc) pors)
  1591 	val mits = complete_metitms oris pits [] mpc
  1589 	val mits = complete_metitms oris pits [] mpc
  1592     in (pits, mits) end;
  1590     in (pits, mits) end
       
  1591 end;
  1593 
  1592 
  1594 fun some_spec ((odI, opI, omI):spec) ((dI, pI, mI):spec) =
  1593 fun some_spec ((odI, opI, omI):spec) ((dI, pI, mI):spec) =
  1595     (if dI = e_domID then odI else dI,
  1594     (if dI = e_domID then odI else dI,
  1596      if pI = e_pblID then opI else pI,
  1595      if pI = e_pblID then opI else pI,
  1597      if mI = e_metID then omI else mI):spec;
  1596      if mI = e_metID then omI else mI):spec;
  1604 (*WN.24.10.03        fun nxt_solv   = ...................................??*)
  1603 (*WN.24.10.03        fun nxt_solv   = ...................................??*)
  1605 fun nxt_specif (tac as Model_Problem) (pt, pos as (p,p_)) =
  1604 fun nxt_specif (tac as Model_Problem) (pt, pos as (p,p_)) =
  1606   let
  1605   let
  1607     val (PblObj{origin=(oris,ospec,_),probl,spec,...}) = get_obj I pt p
  1606     val (PblObj{origin=(oris,ospec,_),probl,spec,...}) = get_obj I pt p
  1608     val (dI,pI,mI) = some_spec ospec spec
  1607     val (dI,pI,mI) = some_spec ospec spec
       
  1608     val thy = assoc_thy dI
  1609     val mpc = (#ppc o get_met) mI (*just for reuse complete_mod_*)
  1609     val mpc = (#ppc o get_met) mI (*just for reuse complete_mod_*)
  1610     val {cas,ppc,...} = get_pbt pI
  1610     val {cas,ppc,...} = get_pbt pI
  1611     val pbl = init_pbl ppc (*fill in descriptions*)
  1611     val pbl = init_pbl ppc (*fill in descriptions*)
  1612     (*--------------if you think, this should be done by the Dialog 
  1612     (*--------------if you think, this should be done by the Dialog 
  1613      in the java front-end, search there for WN060225-modelProblem----*)
  1613      in the java front-end, search there for WN060225-modelProblem----*)
  1632 	   SOME pI' => 
  1632 	   SOME pI' => 
  1633 	   let val {met,ppc,...} = get_pbt pI'
  1633 	   let val {met,ppc,...} = get_pbt pI'
  1634 	       val pbl = init_pbl ppc
  1634 	       val pbl = init_pbl ppc
  1635 	       (*val pt = update_pbl pt p pbl ..done by Model_Problem*)
  1635 	       (*val pt = update_pbl pt p pbl ..done by Model_Problem*)
  1636 	       val mI = if length met = 0 then e_metID else hd met
  1636 	       val mI = if length met = 0 then e_metID else hd met
       
  1637                val thy = assoc_thy dI
  1637 	       val (pos,c,_,pt) = 
  1638 	       val (pos,c,_,pt) = 
  1638 		   generate1 thy (Refine_Tacitly' (pI,pI',dI,mI,(*pbl*)[])) 
  1639 		   generate1 thy (Refine_Tacitly' (pI,pI',dI,mI,(*pbl*)[])) 
  1639 			     Uistate pos pt
  1640 			     Uistate pos pt
  1640 	   in ([(Refine_Tacitly pI, Refine_Tacitly' (pI,pI',dI,mI,(*pbl*)[]),
  1641 	   in ([(Refine_Tacitly pI, Refine_Tacitly' (pI,pI',dI,mI,(*pbl*)[]),
  1641 		 (pos, Uistate))], c, (pt,pos)) end
  1642 		 (pos, Uistate))], c, (pt,pos)) end
  1708 
  1709 
  1709   | nxt_specif m' _ = 
  1710   | nxt_specif m' _ = 
  1710     raise error ("nxt_specif: not impl. for "^tac2str m');
  1711     raise error ("nxt_specif: not impl. for "^tac2str m');
  1711 
  1712 
  1712 (*.get the values from oris; handle the term list w.r.t. penv.*)
  1713 (*.get the values from oris; handle the term list w.r.t. penv.*)
       
  1714 
       
  1715 local
       
  1716 infix mem;
       
  1717 fun x mem [] = false
       
  1718   | x mem (y :: ys) = x = y orelse x mem ys;
       
  1719 in 
  1713 fun vals_of_oris oris =
  1720 fun vals_of_oris oris =
  1714     ((map (mkval' o (#5:ori -> term list))) o 
  1721     ((map (mkval' o (#5:ori -> term list))) o 
  1715      (filter ((curry (op mem) 1) o (#2:ori -> int list)))) oris;
  1722      (filter ((curry (op mem) 1) o (#2:ori -> int list)))) oris
       
  1723 end;
  1716 
  1724 
  1717 
  1725 
  1718 
  1726 
  1719 (*.create a calc-tree with oris via an cas.refined pbl.*)
  1727 (*.create a calc-tree with oris via an cas.refined pbl.*)
  1720 fun nxt_specify_init_calc (([],(dI,pI,mI)): fmz) =
  1728 fun nxt_specify_init_calc (([],(dI,pI,mI)): fmz) =
  1780   | Appl => 
  1788   | Appl => 
  1781 *)    let val (_,_,f,_,_,_) = specify m (p,p_) [] pt
  1789 *)    let val (_,_,f,_,_,_) = specify m (p,p_) [] pt
  1782       in f end;
  1790       in f end;
  1783 
  1791 
  1784 
  1792 
  1785 
  1793 (*fun tag_form thy (formal, given) = Thm.cterm_of thy
  1786 
  1794 	      (((head_of o term_of) given) $ (term_of formal)); WN100819*)
  1787 
  1795 fun tag_form thy (formal, given) =
  1788 
  1796     (let val gf = (head_of given) $ formal;
  1789 (* --------------------- ME --------------------- *)
  1797          val _ = Thm.cterm_of thy gf
  1790 fun tag_form thy (formal, given) = cterm_of (sign_of thy) 
  1798      in gf end)
  1791 	      (((head_of o term_of) given) $ (term_of formal));
  1799     handle _ => raise error ("calchead.tag_form: " ^ 
       
  1800                              Syntax.string_of_term (thy2ctxt thy) given ^
       
  1801                              " .. " ^
       
  1802                              Syntax.string_of_term (thy2ctxt thy) formal ^
       
  1803                          " ..types do not match");
  1792 (* val formal = (the o (parse thy)) "[R::real]";
  1804 (* val formal = (the o (parse thy)) "[R::real]";
  1793 > val given = (the o (parse thy)) "fixed_values (cs::real list)";
  1805 > val given = (the o (parse thy)) "fixed_values (cs::real list)";
  1794 > tag_form thy (formal, given);
  1806 > tag_form thy (formal, given);
  1795 val it = "fixed_values [R]" : cterm
  1807 val it = "fixed_values [R]" : cterm
  1796 *)
  1808 *)
  1797 fun chktyp thy (n, fs, gs) = 
  1809 fun chktyp thy (n, fs, gs) = 
  1798   ((writeln o string_of_cterm o (nth n)) fs;
  1810   ((writeln o (Syntax.string_of_term (thy2ctxt thy)) o (nth n)) fs;
  1799    (writeln o string_of_cterm o (nth n)) gs;
  1811    (writeln o (Syntax.string_of_term (thy2ctxt thy)) o (nth n)) gs;
  1800    tag_form thy (nth n fs, nth n gs));
  1812    tag_form thy (nth n fs, nth n gs));
  1801 
  1813 
  1802 fun chktyps thy (fs, gs) = map (tag_form thy) (fs ~~ gs);
  1814 fun chktyps thy (fs, gs) = map (tag_form thy) (fs ~~ gs);
  1803 
  1815 
  1804 (* #####################################################
  1816 (* #####################################################
  1842      else if (re\\(gi union fi)) <> [] 
  1854      else if (re\\(gi union fi)) <> [] 
  1843 	    then ("re\\(gi union fi)",re\\(gi union fi))
  1855 	    then ("re\\(gi union fi)",re\\(gi union fi))
  1844 	  else ("ok",[]) end;*)
  1856 	  else ("ok",[]) end;*)
  1845 fun chk_vars ctppc = 
  1857 fun chk_vars ctppc = 
  1846   let val {Given=gi,Where=wh,Find=fi,With=wi,Relate=re} = 
  1858   let val {Given=gi,Where=wh,Find=fi,With=wi,Relate=re} = 
  1847           appc flat (mappc (vars o term_of) ctppc)
  1859           appc flat (mappc vars ctppc)
  1848       val chked = subtract op = gi wh
  1860       val chked = subtract op = gi wh
  1849   in if chked <> [] then ("wh\\gi", chked)
  1861   in if chked <> [] then ("wh\\gi", chked)
  1850      else let val chked = subtract op = (union op = gi fi) re
  1862      else let val chked = subtract op = (union op = gi fi) re
  1851           in if chked  <> []
  1863           in if chked  <> []
  1852 	     then ("re\\(gi union fi)", chked)
  1864 	     then ("re\\(gi union fi)", chked)
  1855   end;
  1867   end;
  1856 
  1868 
  1857 (* check a new pbltype: variables (Free) unbound by given, find*) 
  1869 (* check a new pbltype: variables (Free) unbound by given, find*) 
  1858 fun unbound_ppc ctppc =
  1870 fun unbound_ppc ctppc =
  1859   let val {Given=gi,Find=fi,Relate=re,...} = 
  1871   let val {Given=gi,Find=fi,Relate=re,...} = 
  1860     appc flat (mappc (vars o term_of) ctppc)
  1872     appc flat (mappc vars ctppc)
  1861   in distinct (*re\\(gi union fi)*) 
  1873   in distinct (*re\\(gi union fi)*) 
  1862               (subtract op = (union op = gi fi) re) end;
  1874               (subtract op = (union op = gi fi) re) end;
  1863 (*
  1875 (*
  1864 > val org = {Given=["[R=(R::real)]"],Where=[],
  1876 > val org = {Given=["[R=(R::real)]"],Where=[],
  1865 	   Find=["[A::real]"],With=[],
  1877 	   Find=["[A::real]"],With=[],
  1878       | fld f (x::x'::[]) = f (x',x)
  1890       | fld f (x::x'::[]) = f (x',x)
  1879       | fld f (x::x'::xs) = f (fld f (x'::xs),x);
  1891       | fld f (x::x'::xs) = f (fld f (x'::xs),x);
  1880   in ((fld f) o rev) xs end;
  1892   in ((fld f) o rev) xs end;
  1881 (*
  1893 (*
  1882 > val (SOME ct) = parse thy "[a=b,c=d,e=f]";
  1894 > val (SOME ct) = parse thy "[a=b,c=d,e=f]";
  1883 > val ces = map (cterm_of (sign_of thy)) (isalist2list (term_of ct));
  1895 > val ces = map (Thm.cterm_of thy) (isalist2list (term_of ct));
  1884 > val conj = foldr1 HOLogic.mk_conj (isalist2list (term_of ct));
  1896 > val conj = foldr1 HOLogic.mk_conj (isalist2list (term_of ct));
  1885 > cterm_of (sign_of thy) conj;
  1897 > Thm.cterm_of thy conj;
  1886 val it = "(a = b & c = d) & e = f" : cterm
  1898 val it = "(a = b & c = d) & e = f" : cterm
  1887 *)
  1899 *)
  1888 
  1900 
  1889 (* f, a binary operator, is nested leftassociative *)
  1901 (* f, a binary operator, is nested leftassociative *)
  1890 fun foldl1 f (x::[]) = x
  1902 fun foldl1 f (x::[]) = x
  1891   | foldl1 f (x::x'::[]) = f (x,x')
  1903   | foldl1 f (x::x'::[]) = f (x,x')
  1892   | foldl1 f (x::x'::xs) = f (x,foldl1 f (x'::xs));
  1904   | foldl1 f (x::x'::xs) = f (x,foldl1 f (x'::xs));
  1893 (*
  1905 (*
  1894 > val (SOME ct) = parse thy "[a=b,c=d,e=f,g=h]";
  1906 > val (SOME ct) = parse thy "[a=b,c=d,e=f,g=h]";
  1895 > val ces = map (cterm_of (sign_of thy)) (isalist2list (term_of ct));
  1907 > val ces = map (Thm.cterm_of thy) (isalist2list (term_of ct));
  1896 > val conj = foldl1 HOLogic.mk_conj (isalist2list (term_of ct));
  1908 > val conj = foldl1 HOLogic.mk_conj (isalist2list (term_of ct));
  1897 > cterm_of (sign_of thy) conj;
  1909 > Thm.cterm_of thy conj;
  1898 val it = "a = b & c = d & e = f & g = h" : cterm
  1910 val it = "a = b & c = d & e = f & g = h" : cterm
  1899 *)
  1911 *)
  1900 
  1912 
  1901 
  1913 
  1902 (* called only once, if a Subproblem has been located in the script*)
  1914 (* called only once, if a Subproblem has been located in the script*)
  1918 > nxt_model_pbl mst;
  1930 > nxt_model_pbl mst;
  1919 val it = Refine_Tacitly ["univariate","equation"] : tac
  1931 val it = Refine_Tacitly ["univariate","equation"] : tac
  1920 *)
  1932 *)
  1921 
  1933 
  1922 (*fun eq1 d (_,(d',_)) = (d = d'); ---modspec.sml*)
  1934 (*fun eq1 d (_,(d',_)) = (d = d'); ---modspec.sml*)
  1923 fun eq4 v (_,vts,_,_,_) = v mem vts;
  1935 fun eq4 v (_,vts,_,_,_) = member op = vts v;
  1924 (*((curry (op mem)) (vat:int)) o (#2:ori -> int list);*)
       
  1925 fun eq5 (_,_,_,_,itm_) (_,_,_,d,_) = d_in itm_ = d;
  1936 fun eq5 (_,_,_,_,itm_) (_,_,_,d,_) = d_in itm_ = d;
  1926 
  1937 
  1927  
  1938  
  1928 
  1939 
  1929 (*
  1940 (*