src/Tools/isac/Specify/step-specify.sml
author Walther Neuper <walther.neuper@jku.at>
Mon, 25 May 2020 16:52:38 +0200
changeset 60002 0073ca6530bb
parent 60001 f9ec666a1e02
child 60003 59f1162489c5
permissions -rw-r--r--
prep.resolve hacks introduced with funpack, part 3
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@59990
     9
(*TODO: vvvvvvvvvvvvvv unify code*)
walther@59981
    10
  val by_tactic_input: Tactic.input -> Calc.T -> Calc.state_post
walther@59981
    11
  val by_tactic: Tactic.T -> Calc.T -> string * Calc.state_post
walther@59990
    12
(*TODO: ^^^^^^^^^^^^^^ unify code*)
walther@59975
    13
walther@59975
    14
  val hack_until_review_Specify_1: Method.id -> I_Model.T -> I_Model.T
walther@59975
    15
  val hack_until_review_Specify_2: Method.id -> I_Model.T -> I_Model.T
walther@59810
    16
(* ---- keep, probably required later in devel. ----------------------------------------------- *)
walther@59946
    17
  val nxt_specify_init_calc: Formalise.T -> Calc.T * State_Steps.T
walther@59886
    18
(*/-------------------------------------------------------- ! aktivate for Test_Isac BEGIN ---\* )
walther@59886
    19
( *\--- ! aktivate for Test_Isac END ----------------------------------------------------------/*)
walther@59747
    20
walther@59747
    21
end
walther@59747
    22
walther@59747
    23
(**)
walther@59747
    24
structure Step_Specify(**): STEP_SPECIFY(**) =
walther@59747
    25
struct
walther@59747
    26
(**)
walther@59763
    27
open Pos
walther@59763
    28
open Ctree
walther@59977
    29
open Specification
walther@59747
    30
walther@59975
    31
(*
walther@59975
    32
  hack until review of Specify:
walther@59975
    33
  introduction of Lucas-Interpretation to Isabelle's functioj package enforced
walther@59975
    34
  to make additional variables on the right hand side to arguments of programs.
walther@59975
    35
  These additional arguments are partially handled by these hacks.
walther@59975
    36
*)
walther@59975
    37
fun hack_until_review_Specify_1 metID itms = 
walther@59998
    38
(**)
walther@59975
    39
  if metID = ["Biegelinien", "ausBelastung"]
walther@59975
    40
  then itms @
walther@59975
    41
    [(4, [1], true, "#Given", I_Model.Cor ((Const ("Biegelinie.Biegelinie", Type ("fun", [Type ("fun", [Type ("Real.real", []), Type ("Real.real", [])]), Type ("Input_Descript.una", [])])),
walther@59975
    42
        [Free ("y", Type ("fun", [Type ("Real.real", []), Type ("Real.real", [])]))]),
walther@59975
    43
      (Free ("id_fun", Type ("fun", [Type ("Real.real", []), Type ("Real.real", [])])),
walther@59975
    44
        [Free ("y", Type ("fun", [Type ("Real.real", []), Type ("Real.real", [])]))] ))),
walther@59975
    45
    (5, [1], true, "#Given", I_Model.Cor ((Const ("Biegelinie.AbleitungBiegelinie", Type ("fun", [Type ("fun", [Type ("Real.real", []), Type ("Real.real", [])]), Type ("Input_Descript.una", [])])),
walther@59975
    46
        [Free ("dy", Type ("fun", [Type ("Real.real", []), Type ("Real.real", [])]))]),
walther@59975
    47
      (Free ("id_abl", Type ("fun", [Type ("Real.real", []), Type ("Real.real", [])])),
walther@59975
    48
        [Free ("dy", Type ("fun", [Type ("Real.real", []), Type ("Real.real", [])]))] )))]
walther@59998
    49
  else (**) itms
walther@59975
    50
walther@59975
    51
fun hack_until_review_Specify_2 metID itms = 
walther@59998
    52
(**)
walther@59975
    53
  if metID = ["IntegrierenUndKonstanteBestimmen2"]
walther@59975
    54
  then itms @
walther@59975
    55
    [(4, [1], true, "#Given", I_Model.Cor ((Const ("Biegelinie.Biegelinie", Type ("fun", [Type ("fun", [Type ("Real.real", []), Type ("Real.real", [])]), Type ("Input_Descript.una", [])])),
walther@59975
    56
        [Free ("y", Type ("fun", [Type ("Real.real", []), Type ("Real.real", [])]))]),
walther@59975
    57
      (Free ("id_fun", Type ("fun", [Type ("Real.real", []), Type ("Real.real", [])])),
walther@59975
    58
        [Free ("y", Type ("fun", [Type ("Real.real", []), Type ("Real.real", [])]))] ))),
walther@59975
    59
    (5, [1], true, "#Given", I_Model.Cor ((Const ("Biegelinie.AbleitungBiegelinie", Type ("fun", [Type ("fun", [Type ("Real.real", []), Type ("Real.real", [])]), Type ("Input_Descript.una", [])])),
walther@59975
    60
        [Free ("dy", Type ("fun", [Type ("Real.real", []), Type ("Real.real", [])]))]),
walther@59975
    61
      (Free ("id_abl", Type ("fun", [Type ("Real.real", []), Type ("Real.real", [])])),
walther@59975
    62
        [Free ("dy", Type ("fun", [Type ("Real.real", []), Type ("Real.real", [])]))] )))]
walther@59998
    63
  else (**) itms
walther@59975
    64
walther@59975
    65
walther@59806
    66
fun by_tactic_input (tac as Tactic.Model_Problem) (pt, pos as (p, _)) =
walther@59763
    67
    let
walther@59763
    68
      val (oris, ospec, probl, spec, ctxt) = case get_obj I pt p of
walther@59763
    69
        PblObj {origin = (oris, ospec, _), probl, spec, ctxt, ...} => (oris, ospec, probl, spec, ctxt)
walther@59962
    70
      | _ => raise ERROR "by_tactic_input Model_Problem; uncovered case get_obj"
walther@59995
    71
      val (_, pI, mI) = References.select ospec spec
walther@59988
    72
      val mpc = (#ppc o Method.from_store) mI (* just for reuse I_Model.complete_method *)
walther@59970
    73
      val {cas, ppc, ...} = Problem.from_store pI
walther@59958
    74
      val pbl = I_Model.init ppc (* fill in descriptions *)
walther@59763
    75
      (*----------------if you think, this should be done by the Dialog 
walther@59763
    76
       in the java front-end, search there for WN060225-modelProblem----*)
walther@59763
    77
      val (pbl, met) = case cas of
walther@59763
    78
        NONE => (pbl, [])
walther@59988
    79
  		| _ => I_Model.complete_method (oris, mpc, ppc, probl)
walther@59763
    80
      (*----------------------------------------------------------------*)
walther@59763
    81
      val tac_ = Tactic.Model_Problem' (pI, pbl, met)
walther@59933
    82
      val (pos,c,_,pt) = Specify_Step.add tac_ (Istate_Def.Uistate, ctxt) (pt, pos)
walther@59846
    83
    in ([(tac, tac_, (pos, (Istate_Def.Uistate, ContextC.empty)))], c, (pt,pos)) end
walther@59990
    84
  | by_tactic_input (Tactic.Add_Given ct) ptp = Specify.by_tactic_input' "#Given" ct ptp
walther@59990
    85
  | by_tactic_input (Tactic.Add_Find  ct) ptp = Specify.by_tactic_input' "#Find"  ct ptp
walther@59990
    86
  | by_tactic_input (Tactic.Add_Relation ct) ptp = Specify.by_tactic_input'"#Relate" ct ptp
walther@59763
    87
    (*. called only if no_met is specified .*)     
walther@59810
    88
  | by_tactic_input (Tactic.Refine_Tacitly pI) (ptp as (pt, pos as (p, _))) =
walther@59763
    89
    let 
walther@59763
    90
      val (oris, dI, ctxt) = case get_obj I pt p of
walther@59763
    91
        (PblObj {origin = (oris, (dI, _, _), _), ctxt, ...}) => (oris, dI, ctxt)
walther@59962
    92
      | _ => raise ERROR "by_tactic_input Refine_Tacitly: uncovered case get_obj"
walther@59968
    93
      val opt = Refine.refine_ori oris pI
walther@59763
    94
    in 
walther@59763
    95
      case opt of
walther@59763
    96
	      SOME pI' => 
walther@59763
    97
	        let 
walther@59970
    98
            val {met, ...} = Problem.from_store pI'
walther@59763
    99
	          (*val pt = update_pbl pt p pbl ..done by Model_Problem*)
walther@59903
   100
	          val mI = if length met = 0 then Method.id_empty else hd met
walther@59763
   101
	          val (pos, c, _, pt) = 
walther@59933
   102
		          Specify_Step.add (Tactic.Refine_Tacitly' (pI, pI', dI, mI,(*pbl*)[])) (Istate_Def.Uistate, ctxt) (pt, pos)
walther@59763
   103
	        in
walther@59763
   104
	          ([(Tactic.Refine_Tacitly pI, Tactic.Refine_Tacitly' (pI,pI',dI,mI,(*pbl*)[]),
walther@59846
   105
	              (pos, (Istate_Def.Uistate, ContextC.empty)))], c, (pt,pos)) 
walther@59763
   106
          end
walther@59763
   107
	    | NONE => ([], [], ptp)
walther@59763
   108
    end
walther@59806
   109
  | by_tactic_input (Tactic.Refine_Problem pI) (ptp as (pt, pos as (p,_))) =
walther@59763
   110
    let
walther@59763
   111
      val (dI, dI', probl, ctxt) = case get_obj I pt p of
walther@59763
   112
        PblObj {origin= (_, (dI, _, _), _), spec = (dI', _, _), probl, ctxt, ...} =>
walther@59763
   113
          (dI, dI', probl, ctxt)
walther@59962
   114
      | _ => raise ERROR "by_tactic_input Refine_Problem: uncovered case get_obj"
walther@59879
   115
	    val thy = if dI' = ThyC.id_empty then dI else dI'
walther@59763
   116
    in 
walther@59960
   117
      case Refine.problem (ThyC.get_theory thy) pI probl of
walther@59763
   118
	      NONE => ([], [], ptp)
walther@59763
   119
	    | SOME rfd => 
walther@59763
   120
	      let 
walther@59933
   121
          val (pos,c,_,pt) = Specify_Step.add (Tactic.Refine_Problem' rfd) (Istate_Def.Uistate, ctxt) (pt, pos)
walther@59763
   122
	      in
walther@59846
   123
	        ([(Tactic.Refine_Problem pI, Tactic.Refine_Problem' rfd, (pos, (Istate_Def.Uistate, ContextC.empty)))], c, (pt,pos))
walther@59763
   124
        end
walther@59763
   125
    end
walther@59806
   126
  | by_tactic_input (Tactic.Specify_Problem pI) (pt, pos as (p,_)) =
walther@59763
   127
    let
walther@59763
   128
      val (oris, dI, dI', pI', probl, ctxt) = case get_obj I pt p of
walther@59763
   129
        PblObj {origin = (oris, (dI,_,_),_), spec = (dI',pI',_), probl, ctxt, ...} =>
walther@59763
   130
          (oris, dI, dI', pI', probl, ctxt)
walther@59962
   131
      | _ => raise ERROR ""
walther@59881
   132
	    val thy = ThyC.get_theory (if dI' = ThyC.id_empty then dI else dI');
walther@59970
   133
      val {ppc,where_,prls,...} = Problem.from_store pI
walther@59763
   134
	    val pbl = 
walther@59903
   135
	      if pI' = Problem.id_empty andalso pI = Problem.id_empty
walther@59958
   136
	      then (false, (I_Model.init ppc, []))
walther@59984
   137
	      else M_Match.match_itms_oris thy probl (ppc,where_,prls) oris
walther@59763
   138
	      (*FIXXXME~~~~~~~~~~~~~~~: take pbl and compare with new pI WN.8.03*)
walther@59810
   139
	    val (c, pt) =
walther@59933
   140
	      case Specify_Step.add (Tactic.Specify_Problem' (pI, pbl)) (Istate_Def.Uistate, ctxt) (pt, pos) of
walther@59810
   141
  	      ((_, Pbl), c, _, pt) => (c, pt)
walther@59962
   142
  	    | _ => raise ERROR ""
walther@59763
   143
    in
walther@59846
   144
      ([(Tactic.Specify_Problem pI, Tactic.Specify_Problem' (pI, pbl), (pos, (Istate_Def.Uistate, ContextC.empty)))], c, (pt, pos))
walther@59763
   145
    end
walther@59763
   146
  (* transfers oris (not required in pbl) to met-model for script-env
walther@59763
   147
     FIXME.WN.8.03: application of several mIDs to SAME model?       *)
walther@59806
   148
  | by_tactic_input (Tactic.Specify_Method mID) (pt, pos as (p,_)) = 
walther@59763
   149
    let
walther@59763
   150
      val (oris, pbl, dI, met, ctxt) = case get_obj I pt p of
walther@59763
   151
        PblObj {origin = (oris, _, _), probl = pbl, spec = (dI, _, _), meth=met, ctxt, ...}
walther@59763
   152
          => (oris, pbl, dI, met, ctxt)
walther@59962
   153
      | _ => raise ERROR "by_tactic_input Specify_Method: uncovered case get_obj"
walther@59970
   154
      val {ppc,pre,prls,...} = Method.from_store mID
walther@59881
   155
      val thy = ThyC.get_theory dI
walther@59960
   156
      val oris = O_Model.add thy ppc oris
walther@59763
   157
      val met = if met=[] then pbl else met (* WN0602 what if more itms in met? *)
walther@59984
   158
      val (_, (itms, _)) = M_Match.match_itms_oris thy met (ppc,pre,prls ) oris
walther@59975
   159
      val itms = hack_until_review_Specify_2 mID itms
walther@59763
   160
      val (pos, c, _, pt) = 
walther@59933
   161
	      Specify_Step.add (Tactic.Specify_Method' (mID, oris, itms)) (Istate_Def.Uistate, ctxt) (pt, pos)
walther@59763
   162
    in
walther@59846
   163
      ([(Tactic.Specify_Method mID, Tactic.Specify_Method' (mID, oris, itms), (pos, (Istate_Def.Uistate, ContextC.empty)))], c, (pt, pos)) 
walther@59763
   164
    end    
walther@59806
   165
  | by_tactic_input (Tactic.Specify_Theory dI) (pt, pos as (_, Pbl)) =
walther@59763
   166
    let
walther@59763
   167
      val ctxt = get_ctxt pt pos
walther@59763
   168
	    val (pos, c, _, pt) = 
walther@59933
   169
	      Specify_Step.add (Tactic.Specify_Theory' dI)  (Istate_Def.Uistate, ctxt) (pt, pos)
walther@59763
   170
    in (*FIXXXME: check if pbl can still be parsed*)
walther@59763
   171
	    ([(Tactic.Specify_Theory dI, Tactic.Specify_Theory' dI, (pos, (Istate_Def.Uistate, ctxt)))], c,
walther@59763
   172
	      (pt, pos))
walther@59763
   173
    end
walther@59806
   174
  | by_tactic_input (Tactic.Specify_Theory dI) (pt, pos as (_, Met)) =
walther@59763
   175
    let
walther@59763
   176
      val ctxt = get_ctxt pt pos
walther@59933
   177
	    val (pos, c, _, pt) = Specify_Step.add (Tactic.Specify_Theory' dI) (Istate_Def.Uistate, ctxt) (pt, pos)
walther@59763
   178
    in  (*FIXXXME: check if met can still be parsed*)
walther@59763
   179
	    ([(Tactic.Specify_Theory dI, Tactic.Specify_Theory' dI, (pos, (Istate_Def.Uistate, ctxt)))], c, (pt, pos))
walther@59763
   180
    end
walther@59962
   181
  | by_tactic_input m' _ = raise ERROR ("by_tactic_input: not impl. for " ^ Tactic.input_to_string m')
walther@59806
   182
walther@59926
   183
fun by_tactic (Tactic.Model_Problem' (_, pbl, met)) (pt, pos as (p, _))  =
walther@59806
   184
    let 
walther@59806
   185
      val (oris, dI',pI',mI', dI, ctxt) = case get_obj I pt p of
walther@59806
   186
        PblObj {origin= (oris, (dI', pI', mI'), _), spec= (dI, _, _), ctxt, ...} =>
walther@59806
   187
          (oris, dI',pI',mI', dI, ctxt)
walther@59962
   188
      | _ => raise ERROR "Step_Solve.by_tactic (Model_Problem': uncovered case get_obj"
walther@59879
   189
      val thy' = if dI = ThyC.id_empty then dI' else dI
walther@59881
   190
      val thy = ThyC.get_theory thy'
walther@59970
   191
      val {ppc, prls, where_, ...} = Problem.from_store pI'
walther@59965
   192
      val pre = Pre_Conds.check' thy prls where_ pbl
walther@59806
   193
      val pb = foldl and_ (true, map fst pre)
walther@59806
   194
      val ((p, _), _, _, pt) =
walther@59933
   195
        Specify_Step.add (Tactic.Model_Problem'([],pbl,met)) (Istate_Def.Uistate, ctxt) (pt, pos)
walther@59990
   196
      val (_, _) = Specify.find_next_step' Pbl pb oris (dI', pI', mI') (pbl, met) 
walther@59970
   197
		    (ppc,(#ppc o Method.from_store) mI') (dI',pI',mI');
walther@59806
   198
    in
walther@59806
   199
      ("ok", ([], [], (pt, (p, Pbl))))
walther@59806
   200
    end
walther@59806
   201
    (* called only if no_met is specified *)     
walther@59806
   202
  | by_tactic (Tactic.Refine_Tacitly' (pI, pIre, _, _, _)) (pt, pos) =
walther@59806
   203
      let
walther@59970
   204
        val {met, thy,...} = Problem.from_store pIre
walther@59903
   205
        val (domID, metID) = (Context.theory_name thy, if length met = 0 then Method.id_empty else hd met)
walther@59806
   206
        val ((p,_), _, _, pt) = 
walther@59933
   207
	        Specify_Step.add (Tactic.Refine_Tacitly' (pI, pIre, domID, metID, [(*pbl*)]))
walther@59846
   208
            (Istate_Def.Uistate, ContextC.empty) (pt, pos)
walther@59806
   209
(* deprecated^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ *)
walther@59806
   210
      in 
walther@59806
   211
        ("ok", ([], [], (pt,(p, Pbl))))
walther@59806
   212
      end
walther@59806
   213
  | by_tactic (Tactic.Refine_Problem' rfd) (pt, pos)  =
walther@59806
   214
      let
walther@59806
   215
        val ctxt = get_ctxt pt pos
walther@59806
   216
        val (pos, _, _, pt) =
walther@59933
   217
          Specify_Step.add (Tactic.Refine_Problem' rfd) (Istate_Def.Uistate, ctxt) (pt, pos)
walther@59806
   218
      in
walther@59806
   219
        ("ok", ([], [], (pt,pos)))
walther@59806
   220
      end
walther@59806
   221
    (*WN110515 initialise ctxt again from itms and add preconds*)
walther@59810
   222
  | by_tactic (Tactic.Specify_Problem' (pI, (ok, (itms, pre)))) (pt, pos as (p, _)) =
walther@59806
   223
      let
walther@59995
   224
        val (_, _, _, _, _, _, ctxt, _) = case get_obj I pt p of
walther@59806
   225
          PblObj {origin= (oris, (dI', pI', mI'), _), spec= (dI, _, mI), ctxt, meth = met, ...} =>
walther@59806
   226
            (oris, dI', pI', mI', dI, mI, ctxt, met)
walther@59962
   227
        | _ => raise ERROR "Step_Solve.by_tactic (Specify_Problem': uncovered case get_obj"
walther@59806
   228
        val (p, pt) =
walther@59933
   229
          case  Specify_Step.add (Tactic.Specify_Problem' (pI, (ok, (itms, pre)))) (Istate_Def.Uistate, ctxt) (pt, pos) of
walther@59806
   230
            ((p, Pbl), _, _, pt) => (p, pt)
walther@59962
   231
          | _ => raise ERROR "Step_Solve.by_tactic (Specify_Problem': uncovered case generate1 (WARNING WHY ?)"
walther@59806
   232
      in
walther@59806
   233
        ("ok", ([], [], (pt, (p, Pbl))))
walther@59806
   234
      end    
walther@59806
   235
    (*WN110515 initialise ctxt again from itms and add preconds*)
walther@59806
   236
  | by_tactic (Tactic.Specify_Method' (mID, _, _)) (pt,pos as (p, _)) =
walther@59806
   237
      let
walther@59998
   238
(*OLD*) val (oris, _, _, mI', dI, _, pbl, met, ctxt) = case get_obj I pt p of
walther@59998
   239
(*OLD*)   PblObj {origin= (oris, (dI', pI', mI'), _), spec= (dI, pI, _), probl = pbl, meth = met, ctxt, ...} =>
walther@59998
   240
(*OLD*)      (oris, dI', pI', mI', dI, pI, pbl, met, ctxt)
walther@59998
   241
(*OLD*) | _ => raise ERROR "Step_Solve.by_tactic (Specify_Problem': uncovered case get_obj"
walther@59998
   242
(*OLD*) val {ppc, pre, prls, ...} = Method.from_store mID
walther@59998
   243
(*OLD*) val thy = ThyC.get_theory dI
walther@59998
   244
(*OLD*) val oris = O_Model.add thy ppc oris
walther@59998
   245
(*OLD*) val met = if met = [] then pbl else met (*nonsense, DEL ! ! ! ! ! ! ! ! ! ! ! ! ! ! !*)
walther@59998
   246
(*OLD*) val (_, (itms, _)) = M_Match.match_itms_oris thy met (ppc, pre, prls) oris
walther@59998
   247
(*OLD*) val itms = hack_until_review_Specify_1 mI' itms
walther@59998
   248
(*OLD*) val (pos, _, _, pt) =
walther@59998
   249
(*OLD*)   Specify_Step.add (Tactic.Specify_Method' (mID, oris, itms)) (Istate_Def.Uistate, ctxt) (pt, pos)
walther@60002
   250
(*---*)
walther@60002
   251
(*NEW* ) val {origin = (o_model, o_refs, _), spec = refs, probl = i_prob, meth = i_meth, ctxt,
walther@60001
   252
(*NEW*)    ...} =Calc.specify_data (pt, pos);
walther@59998
   253
(*NEW*) val (dI, _, mID) = References.select o_refs refs;
walther@59998
   254
(*NEW*) val {ppc = m_patt, pre, prls, ...} = Method.from_store mID
walther@59998
   255
(*NEW*) val {origin = (root_model, _, _), ...} = Calc.specify_data (pt, ([], Und))
walther@60001
   256
(*NEW*) val (o_model', ctxt') = O_Model.complete_for_from m_patt root_model (o_model, ctxt)
walther@60001
   257
walther@59998
   258
(*NEW*) val thy = ThyC.get_theory dI
walther@60001
   259
(*NEW*) val (_, (i_model, _)) = M_Match.match_itms_oris thy i_prob (m_patt, pre, prls) o_model';
walther@60001
   260
(*NEW*) val (pos, _, _, pt) = Specify_Step.add (Tactic.Specify_Method' (mID, o_model', i_model))
walther@59998
   261
(*NEW*)   (Istate_Def.Uistate, ctxt') (pt, pos)
walther@59998
   262
( *NEW*)in
walther@59806
   263
        ("ok", ([], [], (pt, pos)))
walther@59806
   264
      end    
walther@59990
   265
  | by_tactic (Tactic.Add_Given' (ct, _)) (pt, p)  = Specify.by_tactic' "#Given" ct (pt, p)
walther@59990
   266
  | by_tactic (Tactic.Add_Find'  (ct, _)) (pt, p) = Specify.by_tactic' "#Find" ct (pt, p)
walther@59990
   267
  | by_tactic (Tactic.Add_Relation' (ct, _)) (pt, p) = Specify.by_tactic'"#Relate" ct (pt, p)
walther@59810
   268
  | by_tactic (Tactic.Specify_Theory' domID) (pt, (p,p_)) =
walther@59806
   269
      let
walther@59806
   270
        val p_ = case p_ of Met => Met | _ => Pbl
walther@59881
   271
        val thy = ThyC.get_theory domID
walther@59806
   272
        val (oris, dI', pI', mI', dI, pI, mI, pbl, met, ctxt) = case get_obj I pt p of
walther@59806
   273
          PblObj {origin= (oris, (dI', pI', mI'), _), spec= (dI, pI, mI), probl = pbl, meth = met, ctxt, ...} =>
walther@59806
   274
             (oris, dI', pI', mI', dI, pI, mI, pbl, met, ctxt)
walther@59962
   275
        | _ => raise ERROR "Step_Solve.by_tactic (Specify_Theory': uncovered case get_obj"
walther@59810
   276
        val _ = case p_ of Met => met | _ => pbl
walther@59903
   277
        val cpI = if pI = Problem.id_empty then pI' else pI
walther@59970
   278
        val {prls = per, ppc, where_ = pwh, ...} = Problem.from_store cpI
walther@59903
   279
        val cmI = if mI = Method.id_empty then mI' else mI
walther@59970
   280
        val {prls = mer, ppc = mpc, pre= mwh, ...} = Method.from_store cmI
walther@59806
   281
        val pre = case p_ of
walther@59965
   282
          Met => (Pre_Conds.check' thy mer mwh met)
walther@59965
   283
        | _ => (Pre_Conds.check' thy per pwh pbl)
walther@59806
   284
        val pb = foldl and_ (true, map fst pre)
walther@59806
   285
      in
walther@59806
   286
        if domID = dI
walther@59806
   287
        then
walther@59990
   288
          let val (p_, _) = Specify.find_next_step' p_ pb oris (dI', pI', mI') (pbl, met) (ppc, mpc) (dI, pI, mI)
walther@59806
   289
	        in
walther@59806
   290
            ("ok", ([], [], (pt, (p, p_))))
walther@59806
   291
          end
walther@59806
   292
        else (*FIXME: check ppc wrt. (new!) domID ..? still parsable?*)
walther@59806
   293
	        let 
walther@59933
   294
	          val ((p, p_), _, _, pt) = Specify_Step.add (Tactic.Specify_Theory' domID) (Istate_Def.Uistate, ctxt) (pt, (p,p_))
walther@59990
   295
	          val (p_, _) = Specify.find_next_step' p_ pb oris (dI', pI', mI') (pbl, met) (ppc, mpc) (domID, pI, mI)
walther@59806
   296
	        in
walther@59806
   297
            ("ok", ([], [], (pt, (p, p_))))
walther@59990
   298
          end                
walther@59806
   299
      end
walther@59806
   300
  | by_tactic _ _ = raise ERROR "Step_Specify.by_tactic uncovered pattern in fun.def"
walther@59977
   301
(* was fun Specification.specify *)
walther@59806
   302
walther@59806
   303
(* create a calc-tree with oris via an cas.refined pbl *)
walther@59806
   304
fun nxt_specify_init_calc ([], (dI, pI, mI)) =
walther@59806
   305
    if pI <> [] 
walther@59806
   306
    then (* from pbl-browser or from CAS cmd with pI=[e_pblID] *)
walther@59806
   307
	    let 
walther@59970
   308
        val {cas, met, ppc, thy, ...} = Problem.from_store pI
walther@59880
   309
	      val dI = if dI = "" then Context.theory_name thy else dI
walther@59806
   310
	      val mI = if mI = [] then hd met else mI
walther@59806
   311
	      val hdl = case cas of NONE => Auto_Prog.pblterm dI pI | SOME t => t
walther@59952
   312
	      val (pt, _) = cappend_problem e_ctree [] (Istate_Def.Uistate, ContextC.empty) ([], (dI, pI, mI))
walther@59846
   313
				  ([], (dI,pI,mI), hdl, ContextC.empty)
walther@59806
   314
	      val pt = update_spec pt [] (dI, pI, mI)
walther@59958
   315
	      val pits = I_Model.init ppc
walther@59806
   316
	      val pt = update_pbl pt [] pits
walther@59806
   317
	    in ((pt, ([] , Pbl)), []) end
walther@59806
   318
    else 
walther@59806
   319
      if mI <> [] 
walther@59806
   320
      then (* from met-browser *)
walther@59806
   321
	      let 
walther@59970
   322
          val {ppc, ...} = Method.from_store mI
walther@59806
   323
	        val dI = if dI = "" then "Isac_Knowledge" else dI
walther@59846
   324
	        val (pt, _) = cappend_problem e_ctree [] (Istate_Def.empty, ContextC.empty)
walther@59861
   325
	          ([], (dI, pI, mI)) ([], (dI, pI, mI), TermC.empty, ContextC.empty)
walther@59806
   326
	        val pt = update_spec pt [] (dI, pI, mI)
walther@59958
   327
	        val mits = I_Model.init ppc
walther@59806
   328
	        val pt = update_met pt [] mits
walther@59806
   329
	      in ((pt, ([], Met)), []) end
walther@59806
   330
      else (* new example, pepare for interactive modeling *)
walther@59806
   331
	      let
walther@59846
   332
	        val (pt, _) = cappend_problem e_ctree [] (Istate_Def.empty, ContextC.empty) 
walther@59976
   333
	          ([], References.empty) ([], References.empty, TermC.empty, ContextC.empty)
walther@59806
   334
	      in ((pt, ([], Pbl)), []) end
walther@59806
   335
  | nxt_specify_init_calc (fmz, (dI, pI, mI)) = 
walther@59806
   336
    let           (* both """"""""""""""""""""""""" either empty or complete *)
walther@59881
   337
	    val thy = ThyC.get_theory dI
walther@59806
   338
	    val (pI, (pors, pctxt), mI) = 
walther@59806
   339
	      if mI = ["no_met"] 
walther@59806
   340
	      then 
walther@59806
   341
          let 
walther@59970
   342
            val (pors(*, pctxt*)) = Problem.from_store pI |> #ppc |> O_Model.init fmz thy;
walther@59952
   343
            val pctxt = ContextC.initialise' thy fmz;
walther@59968
   344
		        val pI' = Refine.refine_ori' pors pI;
walther@59806
   345
		      in (pI', (pors(*refinement over models with diff.precond only*), pctxt),
walther@59970
   346
		        (hd o #met o Problem.from_store) pI')
walther@59806
   347
		      end
walther@59952
   348
	      else
walther@59952
   349
	        let
walther@59970
   350
	          val pors = Problem.from_store pI |> #ppc |> O_Model.init fmz thy;
walther@59952
   351
            val pctxt = ContextC.initialise' thy fmz;
walther@59952
   352
	        in (pI, (pors, pctxt), mI) end;
walther@59970
   353
	    val {cas, ppc, thy = thy', ...} = Problem.from_store pI (*take dI from _refined_ pbl*)
walther@59965
   354
	    val dI = Context.theory_name (ThyC.sub_common (thy, thy'))
walther@59806
   355
	    val hdl = case cas of
walther@59806
   356
		    NONE => Auto_Prog.pblterm dI pI
walther@59987
   357
		  | SOME t => subst_atomic ((Model_Pattern.variables ppc) ~~~ O_Model.values pors) t
walther@59846
   358
      val (pt, _) = cappend_problem e_ctree [] (Istate_Def.empty, pctxt)
walther@59819
   359
        (fmz, (dI, pI, mI)) (pors, (dI, pI, mI), hdl, pctxt)
walther@59806
   360
    in
walther@59806
   361
      ((pt, ([], Pbl)), fst3 (by_tactic_input Tactic.Model_Problem (pt, ([], Pbl))))
walther@59806
   362
    end
walther@59763
   363
walther@59763
   364
(**)end(**)