src/Tools/isac/Specify/step-specify.sml
author Walther Neuper <walther.neuper@jku.at>
Mon, 11 May 2020 11:38:52 +0200
changeset 59962 6a59d252345d
parent 59960 d0637de46bfa
child 59965 0763aec4c5b6
permissions -rw-r--r--
error -> raise ERROR
walther@59747
     1
(* Title:  Specify/step-specify.sml
walther@59747
     2
   Author: Walther Neuper 2019
walther@59747
     3
   (c) due to copyright terms
walther@59747
     4
*)
walther@59747
     5
walther@59747
     6
signature STEP_SPECIFY =
walther@59747
     7
sig
walther@59791
     8
(*val do_next: Step.specify_do_next requires LI.by_tactic, which is not yet known in Step_Specify*)
walther@59806
     9
  val by_tactic_input: Tactic.input -> Calc.T -> Chead.calcstate'
walther@59806
    10
  val by_tactic: Tactic.T -> Calc.T -> string * Chead.calcstate'
walther@59810
    11
(* ---- keep, probably required later in devel. ----------------------------------------------- *)
walther@59946
    12
  val nxt_specify_init_calc: Formalise.T -> Calc.T * State_Steps.T
walther@59886
    13
(*/-------------------------------------------------------- ! aktivate for Test_Isac BEGIN ---\* )
walther@59886
    14
( *\--- ! aktivate for Test_Isac END ----------------------------------------------------------/*)
walther@59747
    15
walther@59747
    16
end
walther@59747
    17
walther@59747
    18
(**)
walther@59747
    19
structure Step_Specify(**): STEP_SPECIFY(**) =
walther@59747
    20
struct
walther@59747
    21
(**)
walther@59763
    22
open Pos
walther@59763
    23
open Ctree
walther@59763
    24
open Chead
walther@59747
    25
walther@59763
    26
(* was fun Math_Engine.nxt_specify_ *)
walther@59806
    27
fun by_tactic_input (tac as Tactic.Model_Problem) (pt, pos as (p, _)) =
walther@59763
    28
    let
walther@59763
    29
      val (oris, ospec, probl, spec, ctxt) = case get_obj I pt p of
walther@59763
    30
        PblObj {origin = (oris, ospec, _), probl, spec, ctxt, ...} => (oris, ospec, probl, spec, ctxt)
walther@59962
    31
      | _ => raise ERROR "by_tactic_input Model_Problem; uncovered case get_obj"
walther@59763
    32
      val (dI, pI, mI) = some_spec ospec spec
walther@59881
    33
      val thy = ThyC.get_theory dI
walther@59763
    34
      val mpc = (#ppc o Specify.get_met) mI (* just for reuse complete_mod_ *)
walther@59763
    35
      val {cas, ppc, ...} = Specify.get_pbt pI
walther@59958
    36
      val pbl = I_Model.init ppc (* fill in descriptions *)
walther@59763
    37
      (*----------------if you think, this should be done by the Dialog 
walther@59763
    38
       in the java front-end, search there for WN060225-modelProblem----*)
walther@59763
    39
      val (pbl, met) = case cas of
walther@59763
    40
        NONE => (pbl, [])
walther@59763
    41
  		| _ => complete_mod_ (oris, mpc, ppc, probl)
walther@59763
    42
      (*----------------------------------------------------------------*)
walther@59763
    43
      val tac_ = Tactic.Model_Problem' (pI, pbl, met)
walther@59933
    44
      val (pos,c,_,pt) = Specify_Step.add tac_ (Istate_Def.Uistate, ctxt) (pt, pos)
walther@59846
    45
    in ([(tac, tac_, (pos, (Istate_Def.Uistate, ContextC.empty)))], c, (pt,pos)) end
walther@59806
    46
  | by_tactic_input (Tactic.Add_Given ct) ptp = nxt_specif_additem "#Given" ct ptp
walther@59806
    47
  | by_tactic_input (Tactic.Add_Find  ct) ptp = nxt_specif_additem "#Find"  ct ptp
walther@59806
    48
  | by_tactic_input (Tactic.Add_Relation ct) ptp = nxt_specif_additem"#Relate" ct ptp
walther@59763
    49
    (*. called only if no_met is specified .*)     
walther@59810
    50
  | by_tactic_input (Tactic.Refine_Tacitly pI) (ptp as (pt, pos as (p, _))) =
walther@59763
    51
    let 
walther@59763
    52
      val (oris, dI, ctxt) = case get_obj I pt p of
walther@59763
    53
        (PblObj {origin = (oris, (dI, _, _), _), ctxt, ...}) => (oris, dI, ctxt)
walther@59962
    54
      | _ => raise ERROR "by_tactic_input Refine_Tacitly: uncovered case get_obj"
walther@59763
    55
      val opt = Specify.refine_ori oris pI
walther@59763
    56
    in 
walther@59763
    57
      case opt of
walther@59763
    58
	      SOME pI' => 
walther@59763
    59
	        let 
walther@59763
    60
            val {met, ...} = Specify.get_pbt pI'
walther@59763
    61
	          (*val pt = update_pbl pt p pbl ..done by Model_Problem*)
walther@59903
    62
	          val mI = if length met = 0 then Method.id_empty else hd met
walther@59881
    63
            val thy = ThyC.get_theory dI
walther@59763
    64
	          val (pos, c, _, pt) = 
walther@59933
    65
		          Specify_Step.add (Tactic.Refine_Tacitly' (pI, pI', dI, mI,(*pbl*)[])) (Istate_Def.Uistate, ctxt) (pt, pos)
walther@59763
    66
	        in
walther@59763
    67
	          ([(Tactic.Refine_Tacitly pI, Tactic.Refine_Tacitly' (pI,pI',dI,mI,(*pbl*)[]),
walther@59846
    68
	              (pos, (Istate_Def.Uistate, ContextC.empty)))], c, (pt,pos)) 
walther@59763
    69
          end
walther@59763
    70
	    | NONE => ([], [], ptp)
walther@59763
    71
    end
walther@59806
    72
  | by_tactic_input (Tactic.Refine_Problem pI) (ptp as (pt, pos as (p,_))) =
walther@59763
    73
    let
walther@59763
    74
      val (dI, dI', probl, ctxt) = case get_obj I pt p of
walther@59763
    75
        PblObj {origin= (_, (dI, _, _), _), spec = (dI', _, _), probl, ctxt, ...} =>
walther@59763
    76
          (dI, dI', probl, ctxt)
walther@59962
    77
      | _ => raise ERROR "by_tactic_input Refine_Problem: uncovered case get_obj"
walther@59879
    78
	    val thy = if dI' = ThyC.id_empty then dI else dI'
walther@59763
    79
    in 
walther@59960
    80
      case Refine.problem (ThyC.get_theory thy) pI probl of
walther@59763
    81
	      NONE => ([], [], ptp)
walther@59763
    82
	    | SOME rfd => 
walther@59763
    83
	      let 
walther@59933
    84
          val (pos,c,_,pt) = Specify_Step.add (Tactic.Refine_Problem' rfd) (Istate_Def.Uistate, ctxt) (pt, pos)
walther@59763
    85
	      in
walther@59846
    86
	        ([(Tactic.Refine_Problem pI, Tactic.Refine_Problem' rfd, (pos, (Istate_Def.Uistate, ContextC.empty)))], c, (pt,pos))
walther@59763
    87
        end
walther@59763
    88
    end
walther@59806
    89
  | by_tactic_input (Tactic.Specify_Problem pI) (pt, pos as (p,_)) =
walther@59763
    90
    let
walther@59763
    91
      val (oris, dI, dI', pI', probl, ctxt) = case get_obj I pt p of
walther@59763
    92
        PblObj {origin = (oris, (dI,_,_),_), spec = (dI',pI',_), probl, ctxt, ...} =>
walther@59763
    93
          (oris, dI, dI', pI', probl, ctxt)
walther@59962
    94
      | _ => raise ERROR ""
walther@59881
    95
	    val thy = ThyC.get_theory (if dI' = ThyC.id_empty then dI else dI');
walther@59763
    96
      val {ppc,where_,prls,...} = Specify.get_pbt pI
walther@59763
    97
	    val pbl = 
walther@59903
    98
	      if pI' = Problem.id_empty andalso pI = Problem.id_empty
walther@59958
    99
	      then (false, (I_Model.init ppc, []))
walther@59763
   100
	      else Specify.match_itms_oris thy probl (ppc,where_,prls) oris
walther@59763
   101
	      (*FIXXXME~~~~~~~~~~~~~~~: take pbl and compare with new pI WN.8.03*)
walther@59810
   102
	    val (c, pt) =
walther@59933
   103
	      case Specify_Step.add (Tactic.Specify_Problem' (pI, pbl)) (Istate_Def.Uistate, ctxt) (pt, pos) of
walther@59810
   104
  	      ((_, Pbl), c, _, pt) => (c, pt)
walther@59962
   105
  	    | _ => raise ERROR ""
walther@59763
   106
    in
walther@59846
   107
      ([(Tactic.Specify_Problem pI, Tactic.Specify_Problem' (pI, pbl), (pos, (Istate_Def.Uistate, ContextC.empty)))], c, (pt, pos))
walther@59763
   108
    end
walther@59763
   109
  (* transfers oris (not required in pbl) to met-model for script-env
walther@59763
   110
     FIXME.WN.8.03: application of several mIDs to SAME model?       *)
walther@59806
   111
  | by_tactic_input (Tactic.Specify_Method mID) (pt, pos as (p,_)) = 
walther@59763
   112
    let
walther@59763
   113
      val (oris, pbl, dI, met, ctxt) = case get_obj I pt p of
walther@59763
   114
        PblObj {origin = (oris, _, _), probl = pbl, spec = (dI, _, _), meth=met, ctxt, ...}
walther@59763
   115
          => (oris, pbl, dI, met, ctxt)
walther@59962
   116
      | _ => raise ERROR "by_tactic_input Specify_Method: uncovered case get_obj"
walther@59763
   117
      val {ppc,pre,prls,...} = Specify.get_met mID
walther@59881
   118
      val thy = ThyC.get_theory dI
walther@59960
   119
      val oris = O_Model.add thy ppc oris
walther@59763
   120
      val met = if met=[] then pbl else met (* WN0602 what if more itms in met? *)
walther@59763
   121
      val (_, (itms, _)) = Specify.match_itms_oris thy met (ppc,pre,prls ) oris
walther@59763
   122
      val itms = Specify.hack_until_review_Specify_2 mID itms
walther@59763
   123
      val (pos, c, _, pt) = 
walther@59933
   124
	      Specify_Step.add (Tactic.Specify_Method' (mID, oris, itms)) (Istate_Def.Uistate, ctxt) (pt, pos)
walther@59763
   125
    in
walther@59846
   126
      ([(Tactic.Specify_Method mID, Tactic.Specify_Method' (mID, oris, itms), (pos, (Istate_Def.Uistate, ContextC.empty)))], c, (pt, pos)) 
walther@59763
   127
    end    
walther@59806
   128
  | by_tactic_input (Tactic.Specify_Theory dI) (pt, pos as (_, Pbl)) =
walther@59763
   129
    let
walther@59763
   130
      val ctxt = get_ctxt pt pos
walther@59763
   131
	    val (pos, c, _, pt) = 
walther@59933
   132
	      Specify_Step.add (Tactic.Specify_Theory' dI)  (Istate_Def.Uistate, ctxt) (pt, pos)
walther@59763
   133
    in (*FIXXXME: check if pbl can still be parsed*)
walther@59763
   134
	    ([(Tactic.Specify_Theory dI, Tactic.Specify_Theory' dI, (pos, (Istate_Def.Uistate, ctxt)))], c,
walther@59763
   135
	      (pt, pos))
walther@59763
   136
    end
walther@59806
   137
  | by_tactic_input (Tactic.Specify_Theory dI) (pt, pos as (_, Met)) =
walther@59763
   138
    let
walther@59763
   139
      val ctxt = get_ctxt pt pos
walther@59933
   140
	    val (pos, c, _, pt) = Specify_Step.add (Tactic.Specify_Theory' dI) (Istate_Def.Uistate, ctxt) (pt, pos)
walther@59763
   141
    in  (*FIXXXME: check if met can still be parsed*)
walther@59763
   142
	    ([(Tactic.Specify_Theory dI, Tactic.Specify_Theory' dI, (pos, (Istate_Def.Uistate, ctxt)))], c, (pt, pos))
walther@59763
   143
    end
walther@59962
   144
  | by_tactic_input m' _ = raise ERROR ("by_tactic_input: not impl. for " ^ Tactic.input_to_string m')
walther@59806
   145
(* was fun Math_Engine.nxt_specify_ *)
walther@59806
   146
walther@59806
   147
walther@59806
   148
(* was fun Chead.specify *)
walther@59926
   149
fun by_tactic (Tactic.Model_Problem' (_, pbl, met)) (pt, pos as (p, _))  =
walther@59806
   150
    let 
walther@59806
   151
      val (oris, dI',pI',mI', dI, ctxt) = case get_obj I pt p of
walther@59806
   152
        PblObj {origin= (oris, (dI', pI', mI'), _), spec= (dI, _, _), ctxt, ...} =>
walther@59806
   153
          (oris, dI',pI',mI', dI, ctxt)
walther@59962
   154
      | _ => raise ERROR "Step_Solve.by_tactic (Model_Problem': uncovered case get_obj"
walther@59879
   155
      val thy' = if dI = ThyC.id_empty then dI' else dI
walther@59881
   156
      val thy = ThyC.get_theory thy'
walther@59806
   157
      val {ppc, prls, where_, ...} = Specify.get_pbt pI'
walther@59806
   158
      val pre = Stool.check_preconds thy prls where_ pbl
walther@59806
   159
      val pb = foldl and_ (true, map fst pre)
walther@59806
   160
      val ((p, _), _, _, pt) =
walther@59933
   161
        Specify_Step.add (Tactic.Model_Problem'([],pbl,met)) (Istate_Def.Uistate, ctxt) (pt, pos)
walther@59806
   162
      val (_, _) = Chead.nxt_spec Pbl pb oris (dI', pI', mI') (pbl, met) 
walther@59806
   163
		    (ppc,(#ppc o Specify.get_met) mI') (dI',pI',mI');
walther@59806
   164
    in
walther@59806
   165
      ("ok", ([], [], (pt, (p, Pbl))))
walther@59806
   166
    end
walther@59806
   167
    (* called only if no_met is specified *)     
walther@59806
   168
  | by_tactic (Tactic.Refine_Tacitly' (pI, pIre, _, _, _)) (pt, pos) =
walther@59806
   169
      let
walther@59806
   170
(*      val (dI', ctxt) = case get_obj I pt p of
walther@59806
   171
          PblObj {origin= (_, (dI', _, _), _), ctxt, ...} => (dI', ctxt)
walther@59962
   172
        | _ => raise ERROR "Step_Solve.by_tactic (Refine_Tacitly': uncovered case get_obj"*)
walther@59806
   173
        val {met, thy,...} = Specify.get_pbt pIre
walther@59903
   174
        val (domID, metID) = (Context.theory_name thy, if length met = 0 then Method.id_empty else hd met)
walther@59806
   175
        val ((p,_), _, _, pt) = 
walther@59933
   176
	        Specify_Step.add (Tactic.Refine_Tacitly' (pI, pIre, domID, metID, [(*pbl*)]))
walther@59846
   177
            (Istate_Def.Uistate, ContextC.empty) (pt, pos)
walther@59806
   178
(* deprecated^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ *)
walther@59806
   179
(*     val (pbl, pre, _) = ([], [], false)*)
walther@59806
   180
      in 
walther@59806
   181
        ("ok", ([], [], (pt,(p, Pbl))))
walther@59806
   182
      end
walther@59806
   183
  | by_tactic (Tactic.Refine_Problem' rfd) (pt, pos)  =
walther@59806
   184
      let
walther@59806
   185
        val ctxt = get_ctxt pt pos
walther@59806
   186
        val (pos, _, _, pt) =
walther@59933
   187
          Specify_Step.add (Tactic.Refine_Problem' rfd) (Istate_Def.Uistate, ctxt) (pt, pos)
walther@59806
   188
      in
walther@59806
   189
        ("ok", ([], [], (pt,pos)))
walther@59806
   190
      end
walther@59806
   191
    (*WN110515 initialise ctxt again from itms and add preconds*)
walther@59810
   192
  | by_tactic (Tactic.Specify_Problem' (pI, (ok, (itms, pre)))) (pt, pos as (p, _)) =
walther@59806
   193
      let
walther@59810
   194
        val (_, _, _, _, dI, _, ctxt, _) = case get_obj I pt p of
walther@59806
   195
          PblObj {origin= (oris, (dI', pI', mI'), _), spec= (dI, _, mI), ctxt, meth = met, ...} =>
walther@59806
   196
            (oris, dI', pI', mI', dI, mI, ctxt, met)
walther@59962
   197
        | _ => raise ERROR "Step_Solve.by_tactic (Specify_Problem': uncovered case get_obj"
walther@59881
   198
        val thy = ThyC.get_theory dI
walther@59806
   199
        val (p, pt) =
walther@59933
   200
          case  Specify_Step.add (Tactic.Specify_Problem' (pI, (ok, (itms, pre)))) (Istate_Def.Uistate, ctxt) (pt, pos) of
walther@59806
   201
            ((p, Pbl), _, _, pt) => (p, pt)
walther@59962
   202
          | _ => raise ERROR "Step_Solve.by_tactic (Specify_Problem': uncovered case generate1 (WARNING WHY ?)"
walther@59806
   203
      in
walther@59806
   204
        ("ok", ([], [], (pt, (p, Pbl))))
walther@59806
   205
      end    
walther@59806
   206
    (*WN110515 initialise ctxt again from itms and add preconds*)
walther@59806
   207
  | by_tactic (Tactic.Specify_Method' (mID, _, _)) (pt,pos as (p, _)) =
walther@59806
   208
      let
walther@59810
   209
        val (oris, _, _, mI', dI, _, pbl, met, ctxt) = case get_obj I pt p of
walther@59806
   210
          PblObj {origin= (oris, (dI', pI', mI'), _), spec= (dI, pI, _), probl = pbl, meth = met, ctxt, ...} =>
walther@59806
   211
             (oris, dI', pI', mI', dI, pI, pbl, met, ctxt)
walther@59962
   212
        | _ => raise ERROR "Step_Solve.by_tactic (Specify_Problem': uncovered case get_obj"
walther@59806
   213
        val {ppc, pre, prls,...} = Specify.get_met mID
walther@59881
   214
        val thy = ThyC.get_theory dI
walther@59960
   215
        val oris = O_Model.add thy ppc oris
walther@59806
   216
        val met = if met = [] then pbl else met
walther@59810
   217
        val (_, (itms, _)) = Specify.match_itms_oris thy met (ppc, pre, prls) oris
walther@59806
   218
        val itms = Specify.hack_until_review_Specify_1 mI' itms
walther@59806
   219
        val (pos, _, _, pt) = 
walther@59933
   220
	        Specify_Step.add (Tactic.Specify_Method' (mID, oris, itms)) (Istate_Def.Uistate, ctxt) (pt, pos)
walther@59806
   221
      in
walther@59806
   222
        ("ok", ([], [], (pt, pos)))
walther@59806
   223
      end    
walther@59806
   224
  | by_tactic (Tactic.Add_Given' (ct, _)) (pt, p)  = Chead.specify_additem "#Given" ct (pt, p)
walther@59806
   225
  | by_tactic (Tactic.Add_Find'  (ct, _)) (pt, p) = Chead.specify_additem "#Find" ct (pt, p)
walther@59806
   226
  | by_tactic (Tactic.Add_Relation' (ct, _)) (pt, p) = Chead.specify_additem"#Relate" ct (pt, p)
walther@59810
   227
  | by_tactic (Tactic.Specify_Theory' domID) (pt, (p,p_)) =
walther@59806
   228
      let
walther@59806
   229
        val p_ = case p_ of Met => Met | _ => Pbl
walther@59881
   230
        val thy = ThyC.get_theory domID
walther@59806
   231
        val (oris, dI', pI', mI', dI, pI, mI, pbl, met, ctxt) = case get_obj I pt p of
walther@59806
   232
          PblObj {origin= (oris, (dI', pI', mI'), _), spec= (dI, pI, mI), probl = pbl, meth = met, ctxt, ...} =>
walther@59806
   233
             (oris, dI', pI', mI', dI, pI, mI, pbl, met, ctxt)
walther@59962
   234
        | _ => raise ERROR "Step_Solve.by_tactic (Specify_Theory': uncovered case get_obj"
walther@59810
   235
        val _ = case p_ of Met => met | _ => pbl
walther@59903
   236
        val cpI = if pI = Problem.id_empty then pI' else pI
walther@59806
   237
        val {prls = per, ppc, where_ = pwh, ...} = Specify.get_pbt cpI
walther@59903
   238
        val cmI = if mI = Method.id_empty then mI' else mI
walther@59806
   239
        val {prls = mer, ppc = mpc, pre= mwh, ...} = Specify.get_met cmI
walther@59806
   240
        val pre = case p_ of
walther@59806
   241
          Met => (Stool.check_preconds thy mer mwh met)
walther@59806
   242
        | _ => (Stool.check_preconds thy per pwh pbl)
walther@59806
   243
        val pb = foldl and_ (true, map fst pre)
walther@59806
   244
      in
walther@59806
   245
        if domID = dI
walther@59806
   246
        then
walther@59810
   247
          let val (p_, _) = nxt_spec p_ pb oris (dI', pI', mI') (pbl, met) (ppc, mpc) (dI, pI, mI)
walther@59806
   248
	        in
walther@59806
   249
            ("ok", ([], [], (pt, (p, p_))))
walther@59806
   250
          end
walther@59806
   251
        else (*FIXME: check ppc wrt. (new!) domID ..? still parsable?*)
walther@59806
   252
	        let 
walther@59933
   253
	          val ((p, p_), _, _, pt) = Specify_Step.add (Tactic.Specify_Theory' domID) (Istate_Def.Uistate, ctxt) (pt, (p,p_))
walther@59810
   254
	          val (p_, _) = nxt_spec p_ pb oris (dI', pI', mI') (pbl, met) (ppc, mpc) (domID, pI, mI)
walther@59806
   255
	        in
walther@59806
   256
            ("ok", ([], [], (pt, (p, p_))))
walther@59806
   257
          end
walther@59806
   258
      end
walther@59806
   259
  | by_tactic _ _ = raise ERROR "Step_Specify.by_tactic uncovered pattern in fun.def"
walther@59806
   260
(* was fun Chead.specify *)
walther@59806
   261
walther@59806
   262
(* create a calc-tree with oris via an cas.refined pbl *)
walther@59806
   263
fun nxt_specify_init_calc ([], (dI, pI, mI)) =
walther@59806
   264
    if pI <> [] 
walther@59806
   265
    then (* from pbl-browser or from CAS cmd with pI=[e_pblID] *)
walther@59806
   266
	    let 
walther@59806
   267
        val {cas, met, ppc, thy, ...} = Specify.get_pbt pI
walther@59880
   268
	      val dI = if dI = "" then Context.theory_name thy else dI
walther@59806
   269
	      val mI = if mI = [] then hd met else mI
walther@59806
   270
	      val hdl = case cas of NONE => Auto_Prog.pblterm dI pI | SOME t => t
walther@59952
   271
	      val (pt, _) = cappend_problem e_ctree [] (Istate_Def.Uistate, ContextC.empty) ([], (dI, pI, mI))
walther@59846
   272
				  ([], (dI,pI,mI), hdl, ContextC.empty)
walther@59806
   273
	      val pt = update_spec pt [] (dI, pI, mI)
walther@59958
   274
	      val pits = I_Model.init ppc
walther@59806
   275
	      val pt = update_pbl pt [] pits
walther@59806
   276
	    in ((pt, ([] , Pbl)), []) end
walther@59806
   277
    else 
walther@59806
   278
      if mI <> [] 
walther@59806
   279
      then (* from met-browser *)
walther@59806
   280
	      let 
walther@59806
   281
          val {ppc, ...} = Specify.get_met mI
walther@59806
   282
	        val dI = if dI = "" then "Isac_Knowledge" else dI
walther@59846
   283
	        val (pt, _) = cappend_problem e_ctree [] (Istate_Def.empty, ContextC.empty)
walther@59861
   284
	          ([], (dI, pI, mI)) ([], (dI, pI, mI), TermC.empty, ContextC.empty)
walther@59806
   285
	        val pt = update_spec pt [] (dI, pI, mI)
walther@59958
   286
	        val mits = I_Model.init ppc
walther@59806
   287
	        val pt = update_met pt [] mits
walther@59806
   288
	      in ((pt, ([], Met)), []) end
walther@59806
   289
      else (* new example, pepare for interactive modeling *)
walther@59806
   290
	      let
walther@59846
   291
	        val (pt, _) = cappend_problem e_ctree [] (Istate_Def.empty, ContextC.empty) 
walther@59902
   292
	          ([], Spec.empty) ([], Spec.empty, TermC.empty, ContextC.empty)
walther@59806
   293
	      in ((pt, ([], Pbl)), []) end
walther@59806
   294
  | nxt_specify_init_calc (fmz, (dI, pI, mI)) = 
walther@59806
   295
    let           (* both """"""""""""""""""""""""" either empty or complete *)
walther@59881
   296
	    val thy = ThyC.get_theory dI
walther@59806
   297
	    val (pI, (pors, pctxt), mI) = 
walther@59806
   298
	      if mI = ["no_met"] 
walther@59806
   299
	      then 
walther@59806
   300
          let 
walther@59952
   301
            val (pors(*, pctxt*)) = Specify.get_pbt pI |> #ppc |> O_Model.init fmz thy;
walther@59952
   302
            val pctxt = ContextC.initialise' thy fmz;
walther@59806
   303
		        val pI' = Specify.refine_ori' pors pI;
walther@59806
   304
		      in (pI', (pors(*refinement over models with diff.precond only*), pctxt),
walther@59806
   305
		        (hd o #met o Specify.get_pbt) pI')
walther@59806
   306
		      end
walther@59952
   307
	      else
walther@59952
   308
	        let
walther@59952
   309
	          val pors = Specify.get_pbt pI |> #ppc |> O_Model.init fmz thy;
walther@59952
   310
            val pctxt = ContextC.initialise' thy fmz;
walther@59952
   311
	        in (pI, (pors, pctxt), mI) end;
walther@59806
   312
	    val {cas, ppc, thy = thy', ...} = Specify.get_pbt pI (*take dI from _refined_ pbl*)
walther@59880
   313
	    val dI = Context.theory_name (Stool.common_subthy (thy, thy'))
walther@59806
   314
	    val hdl = case cas of
walther@59806
   315
		    NONE => Auto_Prog.pblterm dI pI
walther@59806
   316
		  | SOME t => subst_atomic ((vars_of_pbl_' ppc) ~~~ vals_of_oris pors) t
walther@59846
   317
      val (pt, _) = cappend_problem e_ctree [] (Istate_Def.empty, pctxt)
walther@59819
   318
        (fmz, (dI, pI, mI)) (pors, (dI, pI, mI), hdl, pctxt)
walther@59806
   319
    in
walther@59806
   320
      ((pt, ([], Pbl)), fst3 (by_tactic_input Tactic.Model_Problem (pt, ([], Pbl))))
walther@59806
   321
    end
walther@59763
   322
walther@59763
   323
(**)end(**)