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