src/Tools/isac/Interpret/generate.sml
author Walther Neuper <wneuper@ist.tugraz.at>
Wed, 14 Dec 2016 14:20:25 +0100
changeset 59268 c988bdecd7be
parent 59267 aab874fdd910
child 59269 1da53d1540fe
permissions -rw-r--r--
signature for redesigned mout
     1 (* use"ME/generate.sml";
     2    use"generate.sml";
     3    *)
     4 signature CALC_TREE =
     5 sig (*vvv request into signature is incremental with *.sml *)
     6   (* for calchead.sml --------------------------------------------------------------  vvv *)
     7   type taci
     8   val e_taci : taci
     9   datatype pblmet = Method of metID | Problem of pblID | Upblmet
    10   datatype mout =
    11     EmptyMout
    12   | Error' of string
    13   | FormKF of cterm'
    14   | PpcKF of pblmet * item ppc
    15   | RefinedKF of pblID * (itm list * (bool * term) list)
    16   val generate1 : theory -> tac_ -> istate * Proof.context ->
    17     pos' -> ptree -> pos' * pos' list * mout * ptree (* for calchead.sml ^^^ *)
    18   val init_istate : tac -> term -> istate (* for solve.sml *)
    19   val init_pbl : (string * (term * 'a)) list -> itm list
    20   val init_pbl' : (string * (term * term)) list -> itm list
    21   val embed_deriv : taci list -> ptree * pos' -> pos' list * (ptree * pos') (* for inform.sml *)
    22   val generate_hard : (* for solve.sml *)
    23     theory -> tac_ -> pos' -> ptree -> pos' * pos' list * mout * ptree
    24   val generate : (tac * tac_ * (pos' * (istate * Proof.context))) list ->
    25     ptree * pos' list * pos' -> ptree * pos' list * pos' (* for mathengine.sml *)
    26   val generate_inconsistent_rew : subs option * thm'' -> term -> istate * Proof.context ->
    27     pos' -> ptree -> ptree * pos' (* for interface.sml *)
    28 (*/-------------------------------------------------------- ! aktivate for Test_Isac BEGIN ---\* )
    29 ( *\--- ! aktivate for Test_Isac END ----------------------------------------------------------/*)
    30 end
    31 
    32 (**)
    33 structure Ctree(**): CALC_TREE(**) =
    34 (**)
    35 struct
    36 (* initialize istate for Detail_Set *)
    37 fun init_istate (Rewrite_Set rls) t =
    38     (case assoc_rls rls of
    39       Rrls {scr = Rfuns {init_state = ii, ...}, ...} => RrlsState (ii t)
    40     | Rls {scr = EmptyScr, ...} => 
    41       error ("interSteps>..>init_istate: \"" ^ rls ^ "\" has EmptyScr." ^
    42         "use prep_rls' for storing rule-sets !")
    43     | Rls {scr = Prog s, ...} => (ScrState ([(one_scr_arg s, t)], [], NONE, e_term, Sundef, true))
    44     | Seq {scr=EmptyScr,...} => 
    45       error ("interSteps>..>init_istate: \"" ^ rls ^ "\" has EmptyScr." ^
    46 		    "use prep_rls' for storing rule-sets !")
    47     | Seq {scr = Prog s,...} => (ScrState ([(one_scr_arg s, t)], [], NONE, e_term, Sundef, true))
    48     | _ => error "init_istate Rewrite_Set: uncovered case assoc_rls")
    49   | init_istate (Rewrite_Set_Inst (subs, rls)) t =
    50     let
    51       val v = case subs2subst (assoc_thy "Isac") subs of
    52         (_, v) :: _ => v
    53       | _ => error "init_istate: uncovered case "
    54     (*...we suppose the substitution of only _one_ bound variable*)
    55     in case assoc_rls rls of
    56       Rls {scr = EmptyScr, ...} => 
    57         error ("interSteps>..>init_istate: \""^rls^"\" has EmptyScr." ^
    58           "use prep_rls' for storing rule-sets !")
    59 	  | Rls {scr = Prog s, ...} =>
    60 	    let val (form, bdv) = two_scr_arg s
    61 	    in (ScrState ([(form, t), (bdv, v)], [], NONE, e_term, Sundef,true))
    62 	    end
    63 	  | Seq {scr = EmptyScr, ...} => 
    64 	    error ("interSteps>..>init_istate: \""^rls^"\" has EmptyScr." ^
    65 	      "use prep_rls' for storing rule-sets !")
    66 	  | Seq {scr = Prog s,...} =>
    67 	    let val (form, bdv) = two_scr_arg s
    68 	    in (ScrState ([(form, t), (bdv, v)],[], NONE, e_term, Sundef,true))
    69 	    end
    70     | _ => error "init_istate Rewrite_Set_Inst: uncovered case assoc_rls"
    71     end
    72   | init_istate tac _ = error ("init_istate: uncovered definition for " ^ tac2str tac)
    73 
    74 (* a taci holds alle information required to build a node in the calc-tree;
    75    a taci is assumed to be used efficiently such that the calc-tree
    76    resulting from applying a taci need not be stored separately;
    77    see "type calcstate" *)
    78 (*TODO.WN0504 redesign ??? or redesign generate ?? see "fun generate"
    79   TODO.WN0512 ? redesign this _list_:
    80   # only used for [Apply_Method + (Take or Subproblem)], i.e. for initacs
    81   # the latter problem may be resolved automatically if "fun autocalc" is 
    82     not any more used for the specify-phase and for changing the phases*)
    83 type taci = 
    84   (tac *                        (* for comparison with input tac             *)      
    85    tac_ *                       (* for ptree generation                      *)
    86    (pos' *                      (* after applying tac_, for ptree generation *)
    87     (istate * Proof.context)))  (* after applying tac_, for ptree generation *)
    88 val e_taci = (Empty_Tac, Empty_Tac_, (e_pos', (e_istate, e_ctxt))): taci
    89 fun taci2str ((tac, tac_, (pos', (istate, _))):taci) =
    90   "( " ^ tac2str tac ^ ", " ^ tac_2str tac_ ^ ", ( " ^ pos'2str pos' ^ ", " ^
    91   istate2str istate ^ " ))"
    92 fun tacis2str tacis = (strs2str o (map (linefeed o taci2str))) tacis
    93 
    94 datatype pblmet =     (*%^%*)
    95   Upblmet             (*undefined*)
    96 | Problem of pblID    (*%^%*)
    97 | Method of metID;    (*%^%*)
    98 fun pblmet2str (Problem pblID) = "Problem " ^ strs2str pblID (*%^%*)
    99   | pblmet2str (Method metID) = "Method " ^ metID2str metID (*%^%*)
   100   | pblmet2str x = error ("pblmet2str: uncovered definition " ^ pblmet2str x)
   101 
   102 (*3.5.00: TODO: foppFK eliminated in interface FE-KE !!!*)
   103 datatype foppFK =                  (* in DG cases div 2 *)
   104   EmptyFoppFK         (*DG internal*)
   105 | FormFK of cterm'
   106 | PpcFK of cterm' ppc
   107 fun foppFK2str (FormFK ct') ="FormFK " ^ ct'
   108   | foppFK2str (PpcFK  ppc) ="PpcFK " ^ ppc2str ppc
   109   | foppFK2str EmptyFoppFK  ="EmptyFoppFK"
   110 
   111 datatype nest = Open | Closed | Nundef;
   112 fun nest2str Open = "Open"
   113   | nest2str Closed = "Closed"
   114   | nest2str Nundef = "Nundef"
   115 
   116 type indent = int;
   117 datatype edit = EdUndef | Write | Protect;
   118                                    (* bridge --> kernel *)
   119                                    (* bridge <-> kernel *)
   120 (* needed in dialog.sml *)         (* bridge <-- kernel *)
   121 fun edit2str EdUndef = "EdUndef"
   122   | edit2str Write = "Write"
   123   | edit2str Protect = "Protect";
   124 
   125 datatype inout = (*FIXME.WN1105 drop this: was required for proto0 with dialog in sml*)
   126   Error_ of string                                             (*<--*)
   127 | FormKF of cellID * edit * indent * nest * cterm'             (*<--*)
   128 | PpcKF of cellID * edit * indent * nest * (pblmet * item ppc) (*<--*)
   129 | RefineKF of match list                                       (*<--*)
   130 | RefinedKF of (pblID * ((itm list) * ((bool * term) list)))   (*<--*)
   131 
   132 fun inout2str End_Proof = "End_Proof"
   133   | inout2str (Error_  s) = "Error_ "^s
   134   | inout2str (FormKF (cellID, edit, indent, nest, ct')) =  
   135 	       "FormKF ("^(string_of_int cellID)^","
   136 	       ^(edit2str edit)^","^(string_of_int indent)^","
   137 	       ^(nest2str nest)^",("
   138 	       ^ct' ^")"
   139   | inout2str (PpcKF (cellID, edit, indent, nest, (pm,itemppc))) =
   140 	       "PpcKF ("^(string_of_int cellID)^","
   141 	       ^(edit2str edit)^","^(string_of_int indent)^","
   142 	       ^(nest2str nest)^",("
   143 	       ^(pblmet2str pm)^","^(itemppc2str itemppc)^"))"
   144   | inout2str (RefineKF ms)  = "RefineKF "^(matchs2str ms)
   145   | inout2str _ = error "inout2str: uncovered definition"
   146 fun inouts2str ios = (strs2str' o (map inout2str)) ios
   147 
   148 (*
   149   datatype mout = EmptyMout | Error' of inout | Form' of inout | Problems of inout
   150 *)
   151 datatype mout =
   152   FormKF of cterm'
   153 | PpcKF of (pblmet * item ppc) 
   154 | RefinedKF of pblID * (itm list * (bool * term) list)
   155 | Error' of string
   156 | EmptyMout
   157 
   158 fun mout2str (FormKF cterm') = "FormKF " ^ cterm'
   159   | mout2str (PpcKF  (pm, itemppc)) = "PpcKF (" ^ pblmet2str pm ^ "," ^ itemppc2str itemppc ^ ")"
   160   | mout2str (RefinedKF  (pblID, ls)) = "mout2str: RefinedKF not impl."
   161   | mout2str (Error'  str) = "Error' " ^ str
   162   | mout2str (EmptyMout    ) = "EmptyMout"
   163 
   164 (* init pbl with ...,dsc,empty | [] *)
   165 fun init_pbl pbt = 
   166   let
   167     fun pbt2itm (f, (d, _)) = ((0, [], false, f, Inc ((d, []), (e_term, []))) : itm)
   168   in map pbt2itm pbt end
   169 
   170 (* take formal parameters from pbt, for transfer from pbl/met-hierarchy *)
   171 fun init_pbl' pbt = 
   172   let 
   173     fun pbt2itm (f, (d, t)) = ((0, [], false, f, Inc((d, [t]), (e_term, []))) : itm)
   174   in map pbt2itm pbt end
   175 
   176 (*generate 1 ppobj in ptree*)
   177 (*TODO.WN0501: take calcstate as an argument (see embed_derive etc.)?specify?*)
   178 fun generate1 thy (Add_Given' (_, itmlist)) _ (pos as (p, p_)) pt = 
   179     (pos: pos', [], PpcKF (Upblmet, itms2itemppc thy [][]),
   180        case p_ of
   181          Pbl => update_pbl pt p itmlist
   182 	     | Met => update_met pt p itmlist
   183        | _ => error ("uncovered case " ^ pos_2str p_))
   184     (* WN110515 probably declare_constraints with input item (without dsc) --
   185       -- important when specifying without formalisation *)
   186   | generate1 thy (Add_Find' (_, itmlist)) _ (pos as (p, p_)) pt = 
   187     (pos, [], (PpcKF (Upblmet, itms2itemppc thy [] [])),
   188        case p_ of
   189          Pbl => update_pbl pt p itmlist
   190 	     | Met => update_met pt p itmlist
   191        | _ => error ("uncovered case " ^ pos_2str p_))
   192     (*WN110515 probably declare_constraints with input item (without dsc)*)
   193   | generate1 thy (Add_Relation' (_, itmlist)) _ (pos as (p, p_)) pt = 
   194     (pos, [],  PpcKF (Upblmet, itms2itemppc thy [] []),
   195        case p_ of
   196          Pbl => update_pbl pt p itmlist
   197 	     | Met => update_met pt p itmlist
   198        | _ => error ("uncovered case " ^ pos_2str p_))
   199   | generate1 thy (Specify_Theory' domID) _ (pos as (p,_)) pt = 
   200     (pos, [] , PpcKF  (Upblmet, itms2itemppc thy [] []),
   201       update_domID pt p domID)
   202   | generate1 thy (Specify_Problem' (pI, (_, (itms, _)))) _ (p, _) pt = 
   203     let
   204       val pt = update_pbl pt p itms
   205       val pt = update_pblID pt p pI
   206     in
   207       ((p, Pbl), [], PpcKF (Upblmet, itms2itemppc thy [] []), pt)
   208     end
   209   | generate1 thy (Specify_Method' (mID, oris, itms)) _ (p, _) pt = 
   210     let
   211       val pt = update_oris pt p oris
   212       val pt = update_met pt p itms
   213       val pt = update_metID pt p mID
   214     in
   215       ((p, Met), [], PpcKF (Upblmet, itms2itemppc thy [] []), pt)
   216     end
   217   | generate1 thy (Model_Problem' (_, itms, met)) _ (pos as (p,_)) pt =
   218     let 
   219       val pt = update_pbl pt p itms
   220 	    val pt = update_met pt p met
   221     in
   222       (pos, [], PpcKF (Upblmet, itms2itemppc thy [] []), pt)
   223     end
   224   | generate1 thy (Refine_Tacitly' (_, pIre, domID, metID, pbl)) _ (pos as (p, _)) pt = 
   225     let
   226       val pt = update_pbl pt p pbl
   227       val pt = update_orispec pt p (domID, pIre, metID)
   228     in
   229       (pos, [], PpcKF (Upblmet, itms2itemppc thy [] []), pt)
   230     end
   231   | generate1 thy (Refine_Problem' (pI, _)) _ (pos as (p, _)) pt =
   232     let
   233       val (dI, _, mI) = get_obj g_spec pt p
   234       val pt = update_spec pt p (dI, pI, mI)
   235     in
   236       (pos, [], PpcKF (Upblmet, itms2itemppc thy [] []), pt)
   237     end
   238   | generate1 _ (Apply_Method' (_, topt, is, ctxt)) _ (pos as (p, _)) pt = 
   239     (case topt of 
   240       SOME t => 
   241         let val (pt, c) = cappend_form pt p (is, ctxt) t
   242         in (pos, c, EmptyMout, pt) end
   243     | NONE => (pos, [], EmptyMout, update_env pt p (SOME (is, ctxt))))
   244   | generate1 _ (Take' t) l (p, _) pt = (* val (Take' t) = m; *)
   245     let
   246       val p =
   247         let val (ps, p') = split_last p (* no connex to prev.ppobj *)
   248 	      in if p' = 0 then ps @ [1] else p end
   249       val (pt, c) = cappend_form pt p l t
   250     in
   251       ((p, Frm): pos', c, FormKF (term2str t), pt)
   252     end
   253   | generate1 _ (Begin_Trans' t) l (p, Frm) pt =
   254     let
   255       val (pt, c) = cappend_form pt p l t
   256       val pt = update_branch pt p TransitiveB (*040312*)
   257       (* replace the old PrfOjb ~~~~~ *)
   258       val p = (lev_on o lev_dn (* starts with [...,0] *)) p
   259       val (pt, c') = cappend_form pt p l t (*FIXME.0402 same istate ???*)
   260     in
   261       ((p, Frm), c @ c', FormKF (term2str t), pt)
   262     end
   263   | generate1 thy (Begin_Trans' t) l (p, Res) pt = 
   264     (*append after existing PrfObj    vvvvvvvvvvvvv*)
   265     generate1 thy (Begin_Trans' t) l (lev_on p, Frm) pt
   266   | generate1 _ (End_Trans' tasm) l (p, _) pt =
   267     let
   268       val p' = lev_up p
   269       val (pt, c) = append_result pt p' l tasm Complete
   270     in
   271       ((p', Res), c, FormKF (term2str t), pt)
   272     end
   273   | generate1 _ (Rewrite_Inst' (_, _, _, _, subs', thm', f, (f', asm))) (is, ctxt) (p, _) pt =
   274     let
   275       val (pt, c) = cappend_atomic pt p (is, insert_assumptions asm ctxt) f
   276         (Rewrite_Inst (subst2subs subs', thm')) (f',asm) Complete;
   277       val pt = update_branch pt p TransitiveB
   278     in
   279       ((p, Res), c, FormKF (term2str f'), pt)
   280     end
   281  | generate1 _ (Rewrite' (_, _, _, _, thm', f, (f', asm))) (is, ctxt) (p, _) pt =
   282    let
   283      val (pt, c) = cappend_atomic pt p (is, insert_assumptions asm ctxt) f
   284        (Rewrite thm') (f', asm) Complete
   285      val pt = update_branch pt p TransitiveB
   286    in
   287     ((p, Res), c, FormKF (term2str f'), pt)
   288    end
   289   | generate1 thy (Rewrite_Asm' all) l p pt = generate1 thy (Rewrite' all) l p pt
   290   | generate1 _ (Rewrite_Set_Inst' (_, _, subs', rls', f, (f', asm))) (is, ctxt) (p, _) pt =
   291     let
   292       val (pt, c) = cappend_atomic pt p (is, insert_assumptions asm ctxt) f 
   293         (Rewrite_Set_Inst (subst2subs subs', id_rls rls')) (f', asm) Complete
   294       val pt = update_branch pt p TransitiveB
   295     in
   296       ((p, Res), c, FormKF (term2str f'), pt)
   297     end
   298   | generate1 thy (Detail_Set_Inst' (_, _, subs, rls, f, (_, asm))) (is, ctxt) (p, _) pt =
   299     let
   300       val ctxt' = insert_assumptions asm ctxt
   301       val (pt, _) = cappend_form pt p (is, ctxt') f 
   302       val pt = update_branch pt p TransitiveB
   303       val is = init_istate (Rewrite_Set_Inst (subst2subs subs, id_rls rls)) f 
   304       val tac_ = Apply_Method' (e_metID, SOME t, is, ctxt')
   305       val pos' = ((lev_on o lev_dn) p, Frm)
   306     in
   307       generate1 thy tac_ (is, ctxt') pos' pt (*implicit Take*)
   308     end
   309   | generate1 _ (Rewrite_Set' (_, _, rls', f, (f', asm))) (is, ctxt) (p, _) pt =
   310     let
   311       val (pt, c) = cappend_atomic pt p (is, insert_assumptions asm ctxt) f 
   312         (Rewrite_Set (id_rls rls')) (f',asm) Complete
   313       val pt = update_branch pt p TransitiveB
   314     in
   315       ((p, Res), c, FormKF (term2str f'), pt)
   316     end
   317   | generate1 thy (Detail_Set' (_, _, rls, f, (_, asm))) (is, ctxt) (p, _) pt =
   318     let
   319       val ctxt' = insert_assumptions asm ctxt
   320       val (pt, _) = cappend_form pt p (is, ctxt') f 
   321       val pt = update_branch pt p TransitiveB
   322       val is = init_istate (Rewrite_Set (id_rls rls)) f
   323       val tac_ = Apply_Method' (e_metID, SOME t, is, ctxt')
   324       val pos' = ((lev_on o lev_dn) p, Frm)
   325     in
   326       generate1 thy tac_ (is, ctxt') pos' pt (*implicit Take*)
   327     end
   328   | generate1 _ (Check_Postcond' (_, (scval, asm))) l (p, _) pt =
   329       let
   330         val (pt, c) = append_result pt p l (scval, asm) Complete
   331       in
   332         ((p, Res), c, FormKF (term2str scval), pt)
   333       end
   334   | generate1 _ (Calculate' (_, op_, f, (f', _))) l (p, _) pt =
   335       let
   336         val (pt,c) = cappend_atomic pt p l f (Calculate op_) (f', []) Complete
   337       in
   338         ((p, Res), c, FormKF (term2str f'), pt)
   339       end
   340   | generate1 _ (Check_elementwise' (consts, pred, (f', asm))) l (p, _) pt =
   341       let
   342         val (pt,c) = cappend_atomic pt p l consts (Check_elementwise pred) (f',asm) Complete
   343       in
   344         ((p, Res), c, FormKF (term2str f'), pt)
   345       end
   346   | generate1 _ (Or_to_List' (ors, list)) l (p, _) pt =
   347       let
   348         val (pt,c) = cappend_atomic pt p l ors Or_to_List (list, []) Complete
   349       in
   350         ((p, Res), c, FormKF (term2str list), pt)
   351       end
   352   | generate1 _ (Substitute' (_, _, subte, t, t')) l (p, _) pt =
   353       let
   354         val (pt,c) =
   355           cappend_atomic pt p l t (Substitute (subte2sube subte)) (t',[]) Complete
   356         in ((p, Res), c, FormKF (term2str t'), pt) 
   357         end
   358   | generate1 _ (Tac_ (_, f, id, f')) l (p, _) pt =
   359       let
   360         val (pt, c) = cappend_atomic pt p l (str2term f) (Tac id) (str2term f', []) Complete
   361       in
   362         ((p,Res), c, FormKF f', pt)
   363       end
   364   | generate1 thy (Subproblem' ((domID, pblID, metID), oris, hdl, fmz_, ctxt, f)) l (p, _) pt =
   365     let
   366 	    val (pt, c) = cappend_problem pt p l (fmz_, (domID, pblID, metID)) (oris, (domID, pblID, metID), hdl)
   367       val pt = update_ctxt pt p ctxt
   368 	    val f = Syntax.string_of_term (thy2ctxt thy) f
   369     in
   370       ((p, Pbl), c, FormKF f, pt)
   371     end
   372   | generate1 _ m' _ _ _ = error ("generate1: not impl.for " ^ tac_2str m')
   373 
   374 fun generate_inconsistent_rew (subs_opt, thm') f' (is, ctxt) (pos as (p,_)) pt =
   375   let
   376     val f = get_curr_formula (pt, pos)
   377     val pos' as (p', _) = (lev_on p, Res)
   378     val (pt, _) = case subs_opt of
   379       NONE => cappend_atomic pt p' (is, insert_assumptions [] ctxt) f
   380         (Rewrite thm') (f', []) Inconsistent
   381     | SOME subs => cappend_atomic pt p' (is, insert_assumptions [] ctxt) f
   382         (Rewrite_Inst (subs, thm')) (f', []) Inconsistent
   383     val pt = update_branch pt p' TransitiveB
   384   in (pt, pos') end
   385 
   386 fun generate_hard thy m' (p,p_) pt =
   387   let  
   388     val p = case p_ of
   389       Frm => p | Res => lev_on p
   390     | _ => error ("generate_hard: call by " ^ pos'2str (p,p_))
   391   in generate1 thy m' (e_istate, e_ctxt) (p,p_) pt end
   392 
   393 (* tacis are in reverse order from nxt_solve_/specify_: last = fst to insert *)
   394 fun generate ([]: taci list) ptp = ptp
   395   | generate tacis (pt, c, _: pos'(*!dropped!WN0504redesign generate/tacis?*))= 
   396     let
   397       val (tacis', (_, tac_, (p, is))) = split_last tacis
   398 	    val (p',c',_,pt') = generate1 (assoc_thy "Isac") tac_ is p pt
   399     in
   400       generate tacis' (pt', c@c', p')
   401     end
   402 
   403 (* update pos in tacis for embedding by generate *)
   404 fun insert_pos (_: pos) [] = []
   405   | insert_pos (p: pos) (((tac, tac_, (_, ist)): taci) :: tacis) = 
   406     ((tac, tac_, ((p, Res), ist)): taci) :: (insert_pos (lev_on p) tacis)
   407 
   408 fun res_from_taci (_, Rewrite' (_, _, _, _, _, _,(res, asm)), _) = (res, asm)
   409   | res_from_taci (_, Rewrite_Set' (_, _, _, _, (res, asm)), _) = (res, asm)
   410   | res_from_taci (_, tac_, _) = error ("res_from_taci: called with" ^ tac_2str tac_)
   411 
   412 (* embed the tacis created by a '_deriv'ation; sys.form <> input.form
   413   tacis are in order, thus are reverted for generate *)
   414 fun embed_deriv (tacis: taci list) (pt, pos as (p, Frm): pos') =
   415   (*inform at Frm: replace the whole PrfObj by a Transitive-ProfObj FIXME?0402
   416     and transfer the istate (from _after_ compare_deriv) from Frm to Res*)
   417     let
   418       val (res, asm) = (res_from_taci o last_elem) tacis
   419     	val (ist, ctxt) = case get_obj g_loc pt p of
   420     	  (SOME (ist, ctxt), _) => (ist, ctxt)
   421       | (NONE, _) => error "embed_deriv Frm: uncovered case get_obj"
   422     	val form = get_obj g_form pt p
   423           (*val p = lev_on p; ---------------only difference to (..,Res) below*)
   424     	val tacis = (Begin_Trans, Begin_Trans' form, (pos, (Uistate, ctxt))) ::
   425     		(insert_pos ((lev_on o lev_dn) p) tacis) @ [(End_Trans, End_Trans' (res, asm),
   426     			(pos_plus (length tacis) (lev_dn p, Res), (new_val res ist, ctxt)))]
   427     	val {nrls, ...} = get_met (get_obj g_metID pt (par_pblobj pt p))
   428     	val (pt, c, pos as (p, _)) = generate (rev tacis) (pt, [], (p, Res))
   429     	val pt = update_tac pt p (Derive (id_rls nrls))
   430     	val pt = update_branch pt p TransitiveB
   431     in (c, (pt, pos: pos')) end
   432   | embed_deriv tacis (pt, (p, Res)) =
   433     (*inform at Res: append a Transitive-PrfObj FIXME?0402 other branch-types ?
   434       and transfer the istate (from _after_ compare_deriv) from Res to new Res*)
   435     let val (res, asm) = (res_from_taci o last_elem) tacis
   436     	val (ist, ctxt) = case get_obj g_loc pt p of
   437     	  (_, SOME (ist, ctxt)) => (ist, ctxt)
   438       | (_, NONE) => error "embed_deriv Frm: uncovered case get_obj"
   439     	val (f, _) = get_obj g_result pt p
   440     	val p = lev_on p(*---------------only difference to (..,Frm) above*);
   441     	val tacis = (Begin_Trans, Begin_Trans' f, ((p, Frm), (Uistate, ctxt))) ::
   442     		(insert_pos ((lev_on o lev_dn) p) tacis) @ [(End_Trans, End_Trans' (res, asm), 
   443     			(pos_plus (length tacis) (lev_dn p, Res), (new_val res ist, ctxt)))];
   444     	val {nrls, ...} = get_met (get_obj g_metID pt (par_pblobj pt p))
   445     	val (pt, c, pos as (p, _)) = generate (rev tacis) (pt, [], (p, Res))
   446     	val pt = update_tac pt p (Derive (id_rls nrls))
   447     	val pt = update_branch pt p TransitiveB
   448     in (c, (pt, pos)) end
   449   | embed_deriv _ _ = error "embed_deriv: uncovered definition"
   450 end