src/Tools/isac/Interpret/solve-step.sml
author wneuper <Walther.Neuper@jku.at>
Tue, 16 Aug 2022 12:21:21 +0200
changeset 60527 ff2da703f546
parent 60509 2e0b7ca391dc
child 60530 edb91d2a28c1
permissions -rw-r--r--
prepare src for: push ctxt throught Lucas-Interpretation
walther@59920
     1
(* Title:  Specify/solve-step.sml
walther@59920
     2
   Author: Walther Neuper
walther@59920
     3
   (c) due to copyright terms
walther@59920
     4
walther@59920
     5
Code for the solve-phase in analogy to structure Specify_Step for the specify-phase.
walther@59920
     6
*)
walther@59920
     7
walther@59920
     8
signature SOLVE_STEP =
walther@59920
     9
sig
walther@59921
    10
  val check: Tactic.input -> Calc.T -> Applicable.T
walther@59959
    11
  val add: Tactic.T -> Istate_Def.T * Proof.context -> Calc.T -> Test_Out.T
walther@59935
    12
walther@59959
    13
  val add_general: Tactic.T -> Istate_Def.T * Proof.context -> Calc.T -> Test_Out.T
walther@59932
    14
  val s_add_general: State_Steps.T ->
walther@59932
    15
    Ctree.ctree * Pos.pos' list * Pos.pos' -> Ctree.ctree * Pos.pos' list * Pos.pos'
walther@59933
    16
  val add_hard:
walther@59959
    17
    theory -> Tactic.T -> Pos.pos' -> Ctree.ctree -> Test_Out.T
walther@59932
    18
walther@59935
    19
  val get_ruleset: 'a -> Pos.pos -> Ctree.ctree ->
Walther@60509
    20
    string * ThyC.id * Rewrite_Ord.id * Rule_Def.rule_set * bool
walther@59935
    21
  val get_eval: string -> Pos.pos ->Ctree.ctree ->
walther@59935
    22
    string * ThyC.id * (string * Rule_Def.eval_fn)
wenzelm@60223
    23
\<^isac_test>\<open>
walther@59935
    24
  val rew_info: Rule_Def.rule_set -> string * Rule_Def.rule_set * Rule_Def.calc list
wenzelm@60223
    25
\<close>
walther@59920
    26
end
walther@59920
    27
walther@59920
    28
(**)
walther@59996
    29
structure Solve_Step(**): SOLVE_STEP(**) =
walther@59920
    30
struct
walther@59920
    31
(**)
walther@59920
    32
walther@59935
    33
(** get data from Calc.T **)
walther@59935
    34
walther@59935
    35
(* the source is the parent node, either a problem or a Rule_Set (with inter_steps) *)
walther@59935
    36
fun rew_info (Rule_Def.Repeat {erls, rew_ord = (rew_ord', _), calc = ca, ...}) =
walther@59935
    37
    (rew_ord', erls, ca)
walther@59935
    38
  | rew_info (Rule_Set.Sequence {erls, rew_ord = (rew_ord', _), calc = ca, ...}) =
walther@59935
    39
    (rew_ord', erls, ca)
walther@59935
    40
  | rew_info (Rule_Set.Rrls {erls, rew_ord = (rew_ord', _), calc = ca, ...}) =
walther@59935
    41
    (rew_ord', erls, ca)
walther@59962
    42
  | rew_info rls = raise ERROR ("rew_info called with '" ^ Rule_Set.id rls ^ "'");
walther@59935
    43
walther@59935
    44
fun get_ruleset _ p pt = 
walther@59935
    45
  let 
walther@59935
    46
    val (pbl, p', rls') = Ctree.parent_node pt p
walther@59935
    47
  in                                                      
walther@59935
    48
    if pbl
walther@59935
    49
    then 
walther@59935
    50
      let 
walther@59935
    51
        val thy' = Ctree.get_obj Ctree.g_domID pt p'
walther@60154
    52
        val {rew_ord', erls, ...} = MethodC.from_store (Ctree.get_obj Ctree.g_metID pt p')              
walther@59935
    53
	    in ("OK", thy', rew_ord', erls, false) end
walther@59935
    54
     else 
walther@59935
    55
      let
walther@59935
    56
        val thy' = Ctree.get_obj Ctree.g_domID pt (Ctree.par_pblobj pt p)
walther@59935
    57
		    val (rew_ord', erls, _) = rew_info rls'
walther@59935
    58
		  in ("OK", thy', rew_ord', erls, false) end
walther@59935
    59
  end;
walther@59935
    60
walther@59935
    61
fun get_eval scrop p pt = 
walther@59935
    62
  let
walther@59935
    63
    val (pbl, p', rls') =  Ctree.parent_node pt p
walther@59935
    64
  in
walther@59935
    65
    if pbl
walther@59935
    66
    then
walther@59935
    67
      let
walther@59935
    68
        val thy' = Ctree.get_obj Ctree.g_domID pt p'
walther@60154
    69
        val {calc = scr_isa_fns, ...} = MethodC.from_store (Ctree.get_obj Ctree.g_metID pt p')
walther@59935
    70
        val opt = assoc (scr_isa_fns, scrop)
walther@59935
    71
	    in
walther@59935
    72
	      case opt of
walther@59935
    73
	        SOME isa_fn => ("OK", thy', isa_fn)
walther@59935
    74
	      | NONE => ("applicable_in Calculate: unknown '" ^ scrop ^ "'", "", ("", Eval_Def.e_evalfn))
walther@59935
    75
	    end
walther@59935
    76
    else 
walther@59935
    77
		  let
walther@59935
    78
		    val thy' = Ctree.get_obj Ctree.g_domID pt (Ctree.par_pblobj pt p);
walther@59935
    79
		    val (_, _,(*_,*)scr_isa_fns) = rew_info rls'(*rls*)
walther@59935
    80
		  in
walther@59935
    81
		    case assoc (scr_isa_fns, scrop) of
walther@59935
    82
		      SOME isa_fn => ("OK",thy',isa_fn)
walther@59935
    83
		    | NONE => ("applicable_in Calculate: unknown '" ^ scrop ^ "'", "", ("", Eval_Def.e_evalfn))
walther@59935
    84
		  end
walther@59935
    85
  end;
walther@59935
    86
walther@59935
    87
(** Solve_Step.check **)
walther@59935
    88
walther@59922
    89
(*
walther@59922
    90
  check tactics (input by the user, mostly) for applicability
walther@59922
    91
  and determine as much of the result of the tactic as possible initially.
walther@59922
    92
*)
walther@59932
    93
fun check (Tactic.Apply_Method mI) (pt, (p, _)) =
walther@59932
    94
      let
walther@59932
    95
        val (dI, pI, probl, ctxt) = case Ctree.get_obj I pt p of
walther@59932
    96
          Ctree.PblObj {origin = (_, (dI, pI, _), _), probl, ctxt, ...} => (dI, pI, probl, ctxt)
walther@59932
    97
        | _ => raise ERROR "Specify_Step.check Apply_Method: uncovered case Ctree.get_obj"
walther@59970
    98
        val {where_, ...} = Problem.from_store pI
Walther@60477
    99
        val pres = map (I_Model.environment probl |> subst_atomic) where_
walther@59932
   100
        val ctxt = if ContextC.is_empty ctxt (*vvvvvvvvvvvvvv DO THAT EARLIER?!?*)
walther@59932
   101
          then ThyC.get_theory dI |> Proof_Context.init_global |> ContextC.insert_assumptions pres
walther@59932
   102
          else ctxt
walther@59932
   103
      in
walther@59932
   104
        Applicable.Yes (Tactic.Apply_Method' (mI, NONE, Istate_Def.empty (*filled later*), ctxt))
walther@59932
   105
      end
walther@59932
   106
  | check (Tactic.Calculate op_) (cs as (pt, (p, _))) =
walther@59923
   107
      let 
walther@59935
   108
        val (msg, thy', isa_fn) = get_eval op_ p pt;
walther@59928
   109
        val f = Calc.current_formula cs;
walther@59923
   110
      in
walther@59923
   111
        if msg = "OK"
walther@59923
   112
        then
Walther@60500
   113
    	    case Rewrite.calculate_ (ThyC.id_to_ctxt thy') isa_fn f of
walther@59923
   114
    	      SOME (f', (id, thm))
walther@59923
   115
    	        => Applicable.Yes (Tactic.Calculate' (thy', op_, f, (f', (id, thm))))
walther@59929
   116
    	    | NONE => Applicable.No ("'calculate " ^ op_ ^ "' not applicable") 
walther@59923
   117
        else Applicable.No msg                                              
walther@59923
   118
      end
walther@59928
   119
  | check (Tactic.Check_Postcond pI) (_, _) = (*TODO: only applicable, if evaluating to True*)
walther@59928
   120
      Applicable.Yes (Tactic.Check_Postcond' (pI, TermC.empty))
walther@59928
   121
  | check (Tactic.Check_elementwise pred) cs =
walther@59923
   122
      let 
walther@59928
   123
        val f = Calc.current_formula cs;
walther@59923
   124
      in
walther@59928
   125
        Applicable.Yes (Tactic.Check_elementwise' (f, pred, (f, [])))
walther@59923
   126
      end
walther@59923
   127
  | check Tactic.Empty_Tac _ = Applicable.No "Empty_Tac is not applicable"
walther@59929
   128
  | check (Tactic.Free_Solve) _ = Applicable.Yes (Tactic.Free_Solve')
walther@59929
   129
  | check Tactic.Or_to_List cs =
walther@59928
   130
       let 
walther@59929
   131
        val f = Calc.current_formula cs;
walther@59929
   132
        val ls = Prog_Expr.or2list f;
walther@59929
   133
      in
walther@59929
   134
        Applicable.Yes (Tactic.Or_to_List' (f, ls))
walther@59923
   135
      end
walther@59929
   136
  | check (Tactic.Rewrite thm) (cs as (pt, (p, _))) = 
walther@59923
   137
      let
walther@59935
   138
        val (msg, thy', ro, rls', _) = get_ruleset thm p pt;
Walther@60506
   139
        val thy = ThyC.get_theory thy';
Walther@60506
   140
        val ctxt = Proof_Context.init_global thy;
walther@59928
   141
        val f = Calc.current_formula cs;
walther@59923
   142
      in
walther@59923
   143
        if msg = "OK" 
walther@59923
   144
        then
Walther@60506
   145
          case Rewrite.rewrite_ ctxt (assoc_rew_ord thy ro) rls' false (snd thm) f of
walther@59929
   146
            SOME (f',asm) => Applicable.Yes (Tactic.Rewrite' (thy', ro, rls', false, thm, f, (f', asm)))
walther@59929
   147
          | NONE => Applicable.No ((thm |> fst |> quote) ^ " not applicable") 
walther@59923
   148
        else Applicable.No msg
walther@59923
   149
      end
Walther@60527
   150
  | check (Tactic.Rewrite_Inst (subs, thm)) (cs as (pt, pos as (p, _))) = 
walther@59921
   151
      let 
walther@59921
   152
        val pp = Ctree.par_pblobj pt p;
Walther@60527
   153
(*ctxt*)
walther@59921
   154
        val thy' = Ctree.get_obj Ctree.g_domID pt pp;
walther@59921
   155
        val thy = ThyC.get_theory thy';
Walther@60500
   156
        val ctxt = Proof_Context.init_global thy;
Walther@60527
   157
(*ctxt* )
Walther@60527
   158
val ctxt = Ctree.get_loc pt pos |> snd
Walther@60527
   159
val thy = Proof_Context.theory_of ctxt
Walther@60527
   160
val thy' = Context.theory_name thy
Walther@60527
   161
( *ctxt*)
walther@60154
   162
        val {rew_ord' = ro', erls = erls, ...} = MethodC.from_store (Ctree.get_obj Ctree.g_metID pt pp);
walther@59928
   163
        val f = Calc.current_formula cs;
Walther@60500
   164
        val subst = Subst.T_from_input ctxt subs; (*TODO: input requires parse _: _ -> _ option*)
walther@59921
   165
      in 
Walther@60506
   166
        case Rewrite.rewrite_inst_ ctxt (assoc_rew_ord thy ro') erls false subst (snd thm) f of
walther@59929
   167
          SOME (f', asm) =>
walther@59929
   168
            Applicable.Yes (Tactic.Rewrite_Inst' (thy', ro', erls, false, subst, thm, f, (f', asm)))
walther@59929
   169
        | NONE => Applicable.No (fst thm ^ " not applicable")
walther@59921
   170
      end
Walther@60527
   171
  | check (Tactic.Rewrite_Set rls) (cs as (pt, pos as (p, _))) =
walther@59921
   172
      let 
Walther@60527
   173
(*ctxt*)
walther@59923
   174
        val pp = Ctree.par_pblobj pt p; 
walther@59921
   175
        val thy' = Ctree.get_obj Ctree.g_domID pt pp;
Walther@60527
   176
(*ctxt* )
Walther@60527
   177
val ctxt = Ctree.get_loc pt pos |> snd
Walther@60527
   178
val thy = Proof_Context.theory_of ctxt
Walther@60527
   179
val thy' = Context.theory_name thy
Walther@60527
   180
( *ctxt*)
walther@59928
   181
        val f = Calc.current_formula cs;
walther@59923
   182
      in
Walther@60500
   183
        case Rewrite.rewrite_set_ (ThyC.id_to_ctxt thy') false (assoc_rls rls) f of
walther@59921
   184
          SOME (f', asm)
walther@59923
   185
            => Applicable.Yes (Tactic.Rewrite_Set' (thy', false, assoc_rls rls, f, (f', asm)))
walther@59923
   186
          | NONE => Applicable.No (rls ^ " not applicable")
walther@59921
   187
      end
Walther@60527
   188
  | check (Tactic.Rewrite_Set_Inst (subs, rls)) (cs as (pt, pos as (p, _))) =
walther@59921
   189
      let 
Walther@60527
   190
(*ctxt*)
walther@59921
   191
        val pp = Ctree.par_pblobj pt p;
walther@59921
   192
        val thy' = Ctree.get_obj Ctree.g_domID pt pp;
walther@59921
   193
        val thy = ThyC.get_theory thy';
Walther@60500
   194
        val ctxt = Proof_Context.init_global thy;
Walther@60527
   195
(*ctxt* )
Walther@60527
   196
val ctxt = Ctree.get_loc pt pos |> snd
Walther@60527
   197
val thy = Proof_Context.theory_of ctxt
Walther@60527
   198
val thy' = Context.theory_name thy
Walther@60527
   199
( *ctxt*)
walther@59928
   200
        val f = Calc.current_formula cs;
Walther@60500
   201
    	  val subst = Subst.T_from_input ctxt subs; (*TODO: input requires parse _: _ -> _ option*)
walther@59921
   202
      in 
Walther@60500
   203
        case Rewrite.rewrite_set_inst_ ctxt false subst (assoc_rls rls) f of
walther@59928
   204
          SOME (f', asm)
walther@59921
   205
            => Applicable.Yes (Tactic.Rewrite_Set_Inst' (thy', false, subst, assoc_rls rls, f, (f', asm)))
walther@59921
   206
        | NONE => Applicable.No (rls ^ " not applicable")
walther@59921
   207
      end
walther@59928
   208
  | check (Tactic.Subproblem (domID, pblID)) (_, _) = 
walther@60154
   209
      Applicable.Yes (Tactic.Subproblem' ((domID, pblID, MethodC.id_empty), [], 
walther@59928
   210
			  TermC.empty, [], ContextC.empty, Auto_Prog.subpbl domID pblID))
Walther@60527
   211
  | check (Tactic.Substitute sube) (cs as (pt, pos as (p, _))) =
walther@59928
   212
      let
walther@59928
   213
        val pp = Ctree.par_pblobj pt p
Walther@60527
   214
(*ctxt*)
walther@59928
   215
        val thy = ThyC.get_theory (Ctree.get_obj Ctree.g_domID pt pp)
Walther@60500
   216
        val ctxt = Proof_Context.init_global thy;
Walther@60527
   217
(*ctxt* )
Walther@60527
   218
val ctxt = Ctree.get_loc pt pos |> snd
Walther@60527
   219
val thy = Proof_Context.theory_of ctxt
Walther@60527
   220
val thy' = Context.theory_name thy
Walther@60527
   221
( *ctxt*)
walther@59928
   222
        val f = Calc.current_formula cs;
walther@60154
   223
		    val {rew_ord', erls, ...} = MethodC.from_store (Ctree.get_obj Ctree.g_metID pt pp)
walther@59929
   224
		    val subte = Subst.input_to_terms sube (*TODO: input requires parse _: _ -> _ option*)
walther@59928
   225
		    val subst = Subst.T_from_string_eqs thy sube
Walther@60506
   226
		    val ro = assoc_rew_ord thy rew_ord'
walther@59928
   227
		  in
walther@59928
   228
		    if foldl and_ (true, map TermC.contains_Var subte)
walther@59928
   229
		    then (*1*)
walther@59928
   230
		      let val f' = subst_atomic subst f
walther@59928
   231
		      in if f = f'
walther@59928
   232
		        then Applicable.No (Subst.string_eqs_to_string sube ^ " not applicable")
walther@59928
   233
		        else Applicable.Yes (Tactic.Substitute' (ro, erls, subte, f, f'))
walther@59928
   234
		      end
walther@59928
   235
		    else (*2*)
Walther@60500
   236
		      case Rewrite.rewrite_terms_ ctxt ro erls subte f of
walther@59928
   237
		        SOME (f', _) =>  Applicable.Yes (Tactic.Substitute' (ro, erls, subte, f, f'))
walther@59928
   238
		      | NONE => Applicable.No (Subst.string_eqs_to_string sube ^ " not applicable")
walther@59928
   239
		  end
walther@59928
   240
  | check (Tactic.Tac id) (cs as (pt, (p, _))) =
walther@59929
   241
      let 
Walther@60527
   242
(*ctxt*)
walther@59929
   243
        val pp = Ctree.par_pblobj pt p; 
walther@59929
   244
        val thy' = Ctree.get_obj Ctree.g_domID pt pp;
walther@59929
   245
        val thy = ThyC.get_theory thy';
Walther@60527
   246
(*ctxt* )
Walther@60527
   247
val ctxt = Ctree.get_loc pt pos |> snd
Walther@60527
   248
val thy = Proof_Context.theory_of ctxt
Walther@60527
   249
val thy' = Context.theory_name thy
Walther@60527
   250
( *ctxt*)
walther@59929
   251
        val f = Calc.current_formula cs;
walther@59936
   252
      in
walther@59936
   253
        Applicable.Yes (Tactic.Tac_ (thy, UnparseC.term f, id, UnparseC.term f))
walther@59921
   254
      end
walther@59923
   255
  | check (Tactic.Take str) _ = Applicable.Yes (Tactic.Take' (TermC.str2term str)) (* always applicable ?*)
walther@59929
   256
  | check (Tactic.Begin_Trans) cs =
walther@59929
   257
      Applicable.Yes (Tactic.Begin_Trans' (Calc.current_formula cs))
walther@59923
   258
  | check (Tactic.End_Trans) (pt, (p, p_)) = (*TODO: check parent branches*)
walther@59923
   259
    if p_ = Pos.Res 
walther@59923
   260
	  then Applicable.Yes (Tactic.End_Trans' (Ctree.get_obj Ctree.g_result pt p))
walther@59923
   261
    else Applicable.No "'End_Trans' is not applicable at the beginning of a transitive sequence"
walther@59921
   262
  | check Tactic.End_Proof' _ = Applicable.Yes Tactic.End_Proof''
walther@59921
   263
  | check m _ = raise ERROR ("Solve_Step.check called for " ^ Tactic.input_to_string m);
walther@59920
   264
walther@59935
   265
walther@59935
   266
(** Solve_Step.add **)
walther@59935
   267
walther@59932
   268
fun add (Tactic.Apply_Method' (_, topt, is, _)) (_, ctxt) (pt, pos as (p, _)) = 
walther@59932
   269
    (case topt of 
walther@59932
   270
      SOME t => 
walther@59932
   271
        let val (pt, c) = Ctree.cappend_form pt p (is, ctxt) t
walther@59959
   272
        in (pos, c, Test_Out.EmptyMout, pt) end
walther@59959
   273
    | NONE => (pos, [], Test_Out.EmptyMout, pt))
walther@59932
   274
  | add (Tactic.Take' t) l (pt, (p, _)) = (* val (Take' t) = m; *)
walther@59931
   275
    let
walther@59931
   276
      val p =
walther@59931
   277
        let val (ps, p') = split_last p (* no connex to prev.ppobj *)
walther@59931
   278
	      in if p' = 0 then ps @ [1] else p end
walther@59931
   279
      val (pt, c) = Ctree.cappend_form pt p l t
walther@59931
   280
    in
walther@59959
   281
      ((p, Pos.Frm), c, Test_Out.FormKF (UnparseC.term t), pt)
walther@59931
   282
    end
walther@59931
   283
  | add (Tactic.Begin_Trans' t) l (pt, (p, Pos.Frm)) =
walther@59931
   284
    let
walther@59931
   285
      val (pt, c) = Ctree.cappend_form pt p l t
walther@59931
   286
      val pt = Ctree.update_branch pt p Ctree.TransitiveB (*040312*)
walther@59931
   287
      (* replace the old PrfOjb ~~~~~ *)
walther@59931
   288
      val p = (Pos.lev_on o Pos.lev_dn (* starts with [...,0] *)) p
walther@59931
   289
      val (pt, c') = Ctree.cappend_form pt p l t (*FIXME.0402 same istate ???*)
walther@59931
   290
    in
walther@59959
   291
      ((p, Pos.Frm), c @ c', Test_Out.FormKF (UnparseC.term t), pt)
walther@59931
   292
    end
walther@59931
   293
  | add (Tactic.Begin_Trans' t) l (pt, (p, Pos.Res)) = 
walther@59931
   294
    (*append after existing PrfObj    vvvvvvvvvvvvv*)
walther@59931
   295
    add (Tactic.Begin_Trans' t) l (pt, (Pos.lev_on p, Pos.Frm))
walther@59931
   296
  | add (Tactic.End_Trans' tasm) l (pt, (p, _)) =
walther@59931
   297
    let
walther@59931
   298
      val p' = Pos.lev_up p
walther@59931
   299
      val (pt, c) = Ctree.append_result pt p' l tasm Ctree.Complete
walther@59931
   300
    in
walther@59959
   301
      ((p', Pos.Res), c, Test_Out.FormKF "DUMMY" (*term2str t ..ERROR (t) has not been declared*), pt)
walther@59931
   302
    end
walther@59931
   303
  | add (Tactic.Rewrite_Inst' (_, _, _, _, subs', thm', f, (f', asm))) (is, ctxt) (pt, (p, _)) =
walther@59931
   304
    let
walther@59931
   305
      val (pt, c) = Ctree.cappend_atomic pt p (is, ctxt) f
walther@59931
   306
        (Tactic.Rewrite_Inst (Subst.T_to_input subs', thm')) (f',asm) Ctree.Complete;
walther@59931
   307
      val pt = Ctree.update_branch pt p Ctree.TransitiveB
walther@59931
   308
    in
walther@59959
   309
      ((p, Pos.Res), c, Test_Out.FormKF (UnparseC.term f'), pt)
walther@59931
   310
    end
walther@59931
   311
 | add (Tactic.Rewrite' (_, _, _, _, thm', f, (f', asm))) (is, ctxt) (pt, (p, _)) =
walther@59931
   312
   let
walther@59931
   313
     val (pt, c) = Ctree.cappend_atomic pt p (is, ctxt) f (Tactic.Rewrite thm') (f', asm) Ctree.Complete
walther@59931
   314
     val pt = Ctree.update_branch pt p Ctree.TransitiveB
walther@59931
   315
   in
walther@59959
   316
    ((p, Pos.Res), c, Test_Out.FormKF (UnparseC.term f'), pt)
walther@59931
   317
   end
walther@59931
   318
  | add (Tactic.Rewrite_Set_Inst' (_, _, subs', rls', f, (f', asm))) (is, ctxt) (pt, (p, _)) =
walther@59931
   319
    let
walther@59931
   320
      val (pt, c) = Ctree.cappend_atomic pt p (is, ctxt) f 
walther@59931
   321
        (Tactic.Rewrite_Set_Inst (Subst.T_to_input subs', Rule_Set.id rls')) (f', asm) Ctree.Complete
walther@59931
   322
      val pt = Ctree.update_branch pt p Ctree.TransitiveB
walther@59931
   323
    in
walther@59959
   324
      ((p, Pos.Res), c, Test_Out.FormKF (UnparseC.term f'), pt)
walther@59931
   325
    end
walther@59931
   326
  | add (Tactic.Rewrite_Set' (_, _, rls', f, (f', asm))) (is, ctxt) (pt, (p, _)) =
walther@59931
   327
    let
walther@59931
   328
      val (pt, c) = Ctree.cappend_atomic pt p (is, ctxt) f 
walther@59931
   329
        (Tactic.Rewrite_Set (Rule_Set.id rls')) (f', asm) Ctree.Complete
walther@59931
   330
      val pt = Ctree.update_branch pt p Ctree.TransitiveB
walther@59931
   331
    in
walther@59959
   332
      ((p, Pos.Res), c, Test_Out.FormKF (UnparseC.term f'), pt)
walther@59931
   333
    end
walther@59931
   334
  | add (Tactic.Check_Postcond' (_, scval)) l (pt, (p, _)) =
walther@59931
   335
      let
walther@59931
   336
        val (pt, c) = Ctree.append_result pt p l (scval, []) Ctree.Complete
walther@59931
   337
      in
walther@59959
   338
        ((p, Pos.Res), c, Test_Out.FormKF (UnparseC.term scval), pt)
walther@59931
   339
      end
walther@59931
   340
  | add (Tactic.Calculate' (_, op_, f, (f', _))) l (pt, (p, _)) =
walther@59931
   341
      let
walther@59931
   342
        val (pt,c) = Ctree.cappend_atomic pt p l f (Tactic.Calculate op_) (f', []) Ctree.Complete
walther@59931
   343
      in
walther@59959
   344
        ((p, Pos.Res), c, Test_Out.FormKF (UnparseC.term f'), pt)
walther@59931
   345
      end
walther@59931
   346
  | add (Tactic.Check_elementwise' (consts, pred, (f', asm))) l (pt, (p, _)) =
walther@59931
   347
      let
walther@59931
   348
        val (pt,c) = Ctree.cappend_atomic pt p l consts (Tactic.Check_elementwise pred) (f', asm) Ctree.Complete
walther@59931
   349
      in
walther@59959
   350
        ((p, Pos.Res), c, Test_Out.FormKF (UnparseC.term f'), pt)
walther@59931
   351
      end
walther@59931
   352
  | add (Tactic.Or_to_List' (ors, list)) l (pt, (p, _)) =
walther@59931
   353
      let
walther@59931
   354
        val (pt,c) = Ctree.cappend_atomic pt p l ors Tactic.Or_to_List (list, []) Ctree.Complete
walther@59931
   355
      in
walther@59959
   356
        ((p, Pos.Res), c, Test_Out.FormKF (UnparseC.term list), pt)
walther@59931
   357
      end
walther@59931
   358
  | add (Tactic.Substitute' (_, _, subte, t, t')) l (pt, (p, _)) =
walther@59931
   359
      let
walther@59931
   360
        val (pt,c) =
walther@59931
   361
          Ctree.cappend_atomic pt p l t (Tactic.Substitute (Subst.eqs_to_input subte)) (t',[]) Ctree.Complete
walther@59959
   362
        in ((p, Pos.Res), c, Test_Out.FormKF (UnparseC.term t'), pt) 
walther@59931
   363
        end
walther@59931
   364
  | add (Tactic.Tac_ (_, f, id, f')) l (pt, (p, _)) =
walther@59931
   365
      let
walther@59931
   366
        val (pt, c) = Ctree.cappend_atomic pt p l (TermC.str2term f) (Tactic.Tac id) (TermC.str2term f', []) Ctree.Complete
walther@59931
   367
      in
walther@59959
   368
        ((p,Pos.Res), c, Test_Out.FormKF f', pt)
walther@59931
   369
      end
walther@59931
   370
  | add (Tactic.Subproblem' ((domID, pblID, metID), oris, hdl, fmz_, ctxt_specify, f))
walther@59931
   371
      (l as (_, ctxt)) (pt, (p, _)) =
walther@59932
   372
      let
walther@59932
   373
  	    val (pt, c) = Ctree.cappend_problem pt p l (fmz_, (domID, pblID, metID))
walther@59932
   374
  	      (oris, (domID, pblID, metID), hdl, ctxt_specify)
walther@60360
   375
  	    val f = Syntax.string_of_term ctxt f
walther@59932
   376
      in
walther@59959
   377
        ((p, Pos.Pbl), c, Test_Out.FormKF f, pt)
walther@59932
   378
      end
walther@59932
   379
  | add m' _ (_, pos) =
walther@59932
   380
      raise ERROR ("Solve_Step.add: not impl.for " ^ Tactic.string_of m' ^ " at " ^ Pos.pos'2str pos)
walther@59932
   381
walther@59932
   382
(* LI switches between solve-phase and specify-phase *)
walther@59932
   383
fun add_general tac ic cs =
walther@59932
   384
  if Tactic.for_specify' tac
walther@59933
   385
  then Specify_Step.add tac ic cs
walther@59932
   386
  else add tac ic cs
walther@59932
   387
walther@59933
   388
(* the order of State_Steps is reversed: insert last element first  *)
walther@59932
   389
fun s_add_general [] ptp = ptp
walther@59932
   390
  | s_add_general tacis (pt, c, _) = 
walther@59931
   391
    let
walther@59932
   392
      val (tacis', (_, tac_, (p, is))) = split_last tacis
walther@59933
   393
	    val (p', c', _, pt') = add_general tac_ is (pt, p)
walther@59931
   394
    in
walther@59932
   395
      s_add_general tacis' (pt', c@c', p')
walther@59931
   396
    end
walther@59932
   397
walther@59933
   398
(* a still undeveloped concept: do a calculation without LI *)
walther@59933
   399
fun add_hard _(*thy*) m' (p, p_) pt =
walther@59933
   400
  let  
walther@59933
   401
    val p = case p_ of
walther@59933
   402
      Pos.Frm => p | Pos.Res => Pos.lev_on p
walther@59962
   403
    | _ => raise ERROR ("generate_hard: call by " ^ Pos.pos'2str (p,p_))
walther@59933
   404
  in
walther@59933
   405
    add_general m' (Istate_Def.empty, ContextC.empty) (pt, (p, p_))
walther@59933
   406
  end
walther@59931
   407
walther@59920
   408
(**)end(**);