src/Tools/isac/Interpret/solve.sml
author Walther Neuper <wneuper@ist.tugraz.at>
Tue, 13 Aug 2019 19:33:09 +0200
changeset 59579 4c0a5425396b
parent 59578 0c03bd7c33ea
child 59581 8733ecc08913
permissions -rw-r--r--
lucin: repair [Text_Isac/../inverse_z_transform.sml]

note: meth "Inverse_sub" is the only test, which revealed a missing ' in associate;
.. there are too few test for Rewrite (without _Set etc)
neuper@41968
     1
(* Title:  solve an example by interpreting a method's script
neuper@41968
     2
   Author: Walther Neuper 1999
neuper@41968
     3
   (c) copyright due to lincense terms.
neuper@37906
     4
*)
neuper@37906
     5
wneuper@59562
     6
signature SOLVE_PHASE =
wneuper@59286
     7
sig
wneuper@59286
     8
  datatype auto = CompleteCalc | CompleteCalcHead | CompleteModel | CompleteSubpbl 
wneuper@59286
     9
  | CompleteToSubpbl | Step of int
wneuper@59286
    10
  val autoord : auto -> int
wneuper@59286
    11
  type tac'_
wneuper@59571
    12
  val mk_tac'_ : Tactic.input -> string * Tactic.input
wneuper@59286
    13
  val specsteps : string list
wneuper@59286
    14
wneuper@59286
    15
  val all_solve : auto -> Ctree.pos' list -> Ctree.state ->
wneuper@59286
    16
    string * Ctree.pos' list * (Ctree.ctree * (int list * Ctree.pos_))
wneuper@59286
    17
  val complete_solve :
wneuper@59286
    18
     auto -> Ctree.pos' list -> Ctree.state -> string * Ctree.pos' list * Ctree.state
wneuper@59571
    19
  val solve : string * Tactic.T -> Ctree.state -> string * Chead.calcstate'
wneuper@59286
    20
wneuper@59562
    21
  val inform : Chead.calcstate' -> string -> string * Chead.calcstate'
wneuper@59562
    22
wneuper@59286
    23
  val detailrls : Ctree.ctree -> Ctree.pos' -> string * Ctree.ctree * Ctree.pos'
wneuper@59310
    24
(* ---- for tests only: shifted from below to remove the Warning "unused" at fun.def. --------- *)
wneuper@59286
    25
  val get_form : tac'_ -> Ctree.pos' -> Ctree.ctree -> Generate.mout
wneuper@59299
    26
(*/-------------------------------------------------------- ! aktivate for Test_Isac BEGIN ---\* )
wneuper@59570
    27
  (*NONE*)
wneuper@59299
    28
( *\--- ! aktivate for Test_Isac END ----------------------------------------------------------/*)
wneuper@59310
    29
wneuper@59310
    30
(*----- unused code, kept as hints to design ideas ---------------------------------------------*)
wneuper@59310
    31
  (* NONE *)
wneuper@59286
    32
end
wneuper@59286
    33
wneuper@59286
    34
(**)
wneuper@59562
    35
structure Solve(**): SOLVE_PHASE(**) =
wneuper@59273
    36
struct
wneuper@59286
    37
(**)
wneuper@59276
    38
open Ctree;
wneuper@59273
    39
neuper@37906
    40
type mstID = string;
wneuper@59571
    41
type tac'_ = mstID * Tactic.input; (*DG <-> ME*)
neuper@37906
    42
wneuper@59286
    43
fun mk_tac'_   m = case m of (* scr not cleaned -- will disappear eventually *)
wneuper@59571
    44
  Tactic.Init_Proof (ppc, spec)    => ("Init_Proof", Tactic.Init_Proof (ppc, spec )) 
wneuper@59571
    45
| Tactic.Model_Problem             => ("Model_Problem", Tactic.Model_Problem)
wneuper@59571
    46
| Tactic.Refine_Tacitly pblID      => ("Refine_Tacitly", Tactic.Refine_Tacitly pblID)
wneuper@59571
    47
| Tactic.Refine_Problem pblID      => ("Refine_Problem", Tactic.Refine_Problem pblID)
wneuper@59571
    48
| Tactic.Add_Given cterm'          => ("Add_Given", Tactic.Add_Given cterm') 
wneuper@59571
    49
| Tactic.Del_Given cterm'          => ("Del_Given", Tactic.Del_Given cterm') 
wneuper@59571
    50
| Tactic.Add_Find cterm'           => ("Add_Find", Tactic.Add_Find cterm') 
wneuper@59571
    51
| Tactic.Del_Find cterm'           => ("Del_Find", Tactic.Del_Find cterm') 
wneuper@59571
    52
| Tactic.Add_Relation cterm'       => ("Add_Relation", Tactic.Add_Relation cterm') 
wneuper@59571
    53
| Tactic.Del_Relation cterm'       => ("Del_Relation", Tactic.Del_Relation cterm') 
neuper@37906
    54
wneuper@59571
    55
| Tactic.Specify_Theory domID	    => ("Specify_Theory", Tactic.Specify_Theory domID) 
wneuper@59571
    56
| Tactic.Specify_Problem pblID     => ("Specify_Problem", Tactic.Specify_Problem pblID)
wneuper@59571
    57
| Tactic.Specify_Method metID	    => ("Specify_Method", Tactic.Specify_Method metID) 
wneuper@59571
    58
| Tactic.Apply_Method metID	    => ("Apply_Method", Tactic.Apply_Method metID) 
wneuper@59571
    59
| Tactic.Check_Postcond pblID	    => ("Check_Postcond", Tactic.Check_Postcond pblID)
wneuper@59571
    60
| Tactic.Free_Solve                => ("Free_Solve", Tactic.Free_Solve)
neuper@37906
    61
		    
wneuper@59571
    62
| Tactic.Rewrite_Inst (subs, thm') => ("Rewrite_Inst", Tactic.Rewrite_Inst (subs, thm')) 
wneuper@59571
    63
| Tactic.Rewrite thm'		    => ("Rewrite", Tactic.Rewrite thm') 
wneuper@59571
    64
| Tactic.Rewrite_Asm thm'	    => ("Rewrite_Asm", Tactic.Rewrite_Asm thm') 
wneuper@59571
    65
| Tactic.Rewrite_Set_Inst (subs, rls')
wneuper@59571
    66
               => ("Rewrite_Set_Inst", Tactic.Rewrite_Set_Inst (subs, rls')) 
wneuper@59571
    67
| Tactic.Rewrite_Set rls'          => ("Rewrite_Set", Tactic.Rewrite_Set rls') 
wneuper@59571
    68
| Tactic.End_Ruleset		    => ("End_Ruleset", Tactic.End_Ruleset)
neuper@37906
    69
wneuper@59571
    70
| Tactic.End_Detail                => ("End_Detail", Tactic.End_Detail)
wneuper@59571
    71
| Tactic.Detail_Set rls'           => ("Detail_Set", Tactic.Detail_Set rls')
wneuper@59571
    72
| Tactic.Detail_Set_Inst (s, rls') => ("Detail_Set_Inst", Tactic.Detail_Set_Inst (s, rls'))
neuper@37906
    73
wneuper@59571
    74
| Tactic.Calculate op_             => ("Calculate", Tactic.Calculate op_)
wneuper@59571
    75
| Tactic.Substitute sube           => ("Substitute", Tactic.Substitute sube) 
wneuper@59571
    76
| Tactic.Apply_Assumption cts'	    => ("Apply_Assumption", Tactic.Apply_Assumption cts')
neuper@37906
    77
wneuper@59571
    78
| Tactic.Take cterm'               => ("Take", Tactic.Take cterm') 
wneuper@59571
    79
| Tactic.Take_Inst cterm'          => ("Take_Inst", Tactic.Take_Inst cterm') 
wneuper@59571
    80
| Tactic.Subproblem (domID, pblID) => ("Subproblem", Tactic.Subproblem (domID, pblID)) 
neuper@37906
    81
(*
wneuper@59571
    82
| Tactic.Subproblem_Full(spec,cts')=> ("Subproblem_Full", Tactic.Subproblem_Full(spec,cts')) 
neuper@37906
    83
*)
wneuper@59571
    84
| Tactic.End_Subproblem            => ("End_Subproblem", Tactic.End_Subproblem)
wneuper@59571
    85
| Tactic.CAScmd cterm'		    => ("CAScmd", Tactic.CAScmd cterm')
neuper@37906
    86
			    
wneuper@59571
    87
| Tactic.Split_And                 => ("Split_And", Tactic.Split_And) 
wneuper@59571
    88
| Tactic.Conclude_And		    => ("Conclude_And", Tactic.Conclude_And) 
wneuper@59571
    89
| Tactic.Split_Or                  => ("Split_Or", Tactic.Split_Or) 
wneuper@59571
    90
| Tactic.Conclude_Or		    => ("Conclude_Or", Tactic.Conclude_Or) 
wneuper@59571
    91
| Tactic.Begin_Trans               => ("Begin_Trans", Tactic.Begin_Trans) 
wneuper@59571
    92
| Tactic.End_Trans		    => ("End_Trans", Tactic.End_Trans) 
wneuper@59571
    93
| Tactic.Begin_Sequ                => ("Begin_Sequ", Tactic.Begin_Sequ) 
wneuper@59571
    94
| Tactic.End_Sequ                  => ("End_Sequ", Tactic.Begin_Sequ) 
wneuper@59571
    95
| Tactic.Split_Intersect           => ("Split_Intersect", Tactic.Split_Intersect) 
wneuper@59571
    96
| Tactic.End_Intersect		    => ("End_Intersect", Tactic.End_Intersect) 
wneuper@59571
    97
| Tactic.Check_elementwise cterm'  => ("Check_elementwise", Tactic.Check_elementwise cterm')
wneuper@59571
    98
| Tactic.Or_to_List                => ("Or_to_List", Tactic.Or_to_List) 
wneuper@59571
    99
| Tactic.Collect_Trues	            => ("Collect_Results", Tactic.Collect_Trues) 
neuper@37906
   100
			    
wneuper@59571
   101
| Tactic.Empty_Tac               => ("Empty_Tac", Tactic.Empty_Tac)
wneuper@59571
   102
| Tactic.Tac string              => ("Tac", Tactic.Tac string)
wneuper@59571
   103
| Tactic.End_Proof'                => ("End_Proof'", Tactic.End_Proof')
wneuper@59286
   104
| _ => error "mk_tac'_: uncovered case"; 
neuper@37906
   105
wneuper@59279
   106
type squ = ctree; (* TODO: safe etc. *)
neuper@37906
   107
wneuper@59286
   108
val specsteps = ["Init_Proof", "Refine_Tacitly", "Refine_Problem", "Model_Problem",
wneuper@59286
   109
  "Add_Given", "Del_Given", "Add_Find", "Del_Find", "Add_Relation", "Del_Relation",
wneuper@59286
   110
  "Specify_Theory", "Specify_Problem", "Specify_Method"];
neuper@37906
   111
wneuper@59578
   112
(*FIXME.WN050821 compare solve    ...   begin_end_prog:
wneuper@59578
   113
        WN190811: solve ("Apply_Method",.. used by root-pbl + by locate_input_tactic !!!
wneuper@59578
   114
*)
wneuper@59571
   115
fun solve ("Apply_Method", m as Tactic.Apply_Method' (mI, _, _, _)) (pt, (pos as (p, _))) =
wneuper@59286
   116
    let val {srls, ...} = Specify.get_met mI;
wneuper@59286
   117
      val itms = case get_obj I pt p of
wneuper@59286
   118
        PblObj {meth=itms, ...} => itms
wneuper@59286
   119
      | _ => error "solve Apply_Method: uncovered case get_obj"
wneuper@59286
   120
      val thy' = get_obj g_domID pt p;
wneuper@59405
   121
      val thy = Celem.assoc_thy thy';
wneuper@59286
   122
      val (is, env, ctxt, sc) = case Lucin.init_scrstate thy itms mI of
wneuper@59572
   123
        (is as Istate.ScrState (env,_,_,_,_,_), ctxt, sc) =>  (is, env, ctxt, sc)
wneuper@59286
   124
      | _ => error "solve Apply_Method: uncovered case init_scrstate"
wneuper@59286
   125
      val ini = Lucin.init_form thy sc env;
wneuper@59286
   126
      val p = lev_dn p;
wneuper@59286
   127
    in 
wneuper@59286
   128
      case ini of
wneuper@59286
   129
	      SOME t =>
wneuper@59286
   130
          let val (pos,c,_, pt) = 
wneuper@59571
   131
		        Generate.generate1 thy (Tactic.Apply_Method' (mI, SOME t, is, ctxt))
wneuper@59286
   132
		        (is, ctxt) (lev_on p, Frm)(*implicit Take*) pt;
wneuper@59571
   133
	        in ("ok",([(Tactic.Apply_Method mI, Tactic.Apply_Method' (mI, SOME t, is, ctxt), 
wneuper@59286
   134
		        ((lev_on p, Frm), (is, ctxt)))], c, (pt, pos))) 
wneuper@59286
   135
	        end	      
wneuper@59286
   136
	    | NONE => (*execute the first tac in the Script, compare solve m*)
wneuper@59286
   137
	        let
wneuper@59559
   138
            val (m', (is', ctxt'), _) = LucinNEW.determine_next_tactic (thy', srls) (pt, (p, Res)) sc (is, ctxt);
wneuper@59286
   139
	        in 
wneuper@59569
   140
            case LucinNEW.locate_input_tactic sc (pt, (p, Res)) is' ctxt' m' of
wneuper@59569
   141
              LucinNEW.Safe_Step (cstate, istate, ctxt, tac) =>
wneuper@59578
   142
		            ("ok", ([(Lucin.tac_2tac tac, tac, (snd cstate, (istate, ctxt)))], [(*ctree NOT cut*)], cstate))
wneuper@59286
   143
		        | _ => (* NotLocatable *)
wneuper@59405
   144
		            let val (p, ps, _, pt) = Generate.generate_hard (Celem.assoc_thy "Isac") m (p, Frm) pt;
wneuper@59286
   145
		            in 
wneuper@59286
   146
		              ("not-found-in-script",([(Lucin.tac_2tac m, m, (pos, (is, ctxt)))], ps, (pt, p))) 
wneuper@59286
   147
		            end
wneuper@59286
   148
	        end
wneuper@59286
   149
    end
wneuper@59571
   150
  | solve ("Free_Solve", Tactic.Free_Solve')  (pt, po as (p, _)) =
wneuper@59286
   151
    let
wneuper@59286
   152
      val p' = lev_dn_ (p, Res);
wneuper@59405
   153
      val pt = update_metID pt (par_pblobj pt p) Celem.e_metID;
wneuper@59286
   154
    in
wneuper@59572
   155
      ("ok", ([(Tactic.Empty_Tac, Tactic.Empty_Tac_, (po, (Istate.Uistate, Selem.e_ctxt)))], [], (pt,p')))
wneuper@59286
   156
    end
wneuper@59571
   157
  | solve ("Check_Postcond", Tactic.Check_Postcond' (pI, _)) (pt, (p, p_)) =
wneuper@59286
   158
    let
wneuper@59286
   159
      val pp = par_pblobj pt p
wneuper@59286
   160
      val asm = 
wneuper@59286
   161
        (case get_obj g_tac pt p of
wneuper@59571
   162
		       Tactic.Check_elementwise _ => (*collects and instantiates asms*)
wneuper@59286
   163
		         (snd o (get_obj g_result pt)) p
wneuper@59286
   164
		     | _ => get_assumptions_ pt (p,p_))
wneuper@59286
   165
	      handle _ => [] (*WN.27.5.03 asms in subpbls not completely clear*)
wneuper@59286
   166
      val metID = get_obj g_metID pt pp;
wneuper@59286
   167
      val {srls = srls, scr = sc, ...} = Specify.get_met metID;
wneuper@59286
   168
      val (loc, E, l, a, b, ctxt) = case get_loc pt (p, p_) of
wneuper@59572
   169
        loc as (Istate.ScrState (E, l, a, _, _, b), ctxt) => (loc, E, l, a, b, ctxt)
wneuper@59286
   170
      | _ => error "solve Check_Postcond: uncovered case get_loc"
wneuper@59286
   171
      val thy' = get_obj g_domID pt pp;
wneuper@59405
   172
      val thy = Celem.assoc_thy thy';
wneuper@59559
   173
      val (_, _, (scval, scsaf)) = LucinNEW.determine_next_tactic (thy', srls) (pt, (p, p_)) sc loc;
wneuper@59286
   174
    in 
wneuper@59286
   175
      if pp = [] 
wneuper@59286
   176
      then
wneuper@59286
   177
	      let 
wneuper@59572
   178
          val is = Istate.ScrState (E,l,a,scval,scsaf,b)
wneuper@59571
   179
	        val tac_ = Tactic.Check_Postcond' (pI, (scval, asm))
wneuper@59286
   180
	        val (pos, ps, _, pt) = Generate.generate1 thy tac_ (is, ctxt) (pp, Res) pt;
wneuper@59571
   181
	      in ("ok", ([(Tactic.Check_Postcond pI, tac_, ((pp, Res), (is, ctxt)))], ps, (pt, pos))) end
wneuper@59286
   182
      else
wneuper@59286
   183
        let (*resume script of parpbl, transfer value of subpbl-script*)
wneuper@59286
   184
          val ppp = par_pblobj pt (lev_up p);
wneuper@59286
   185
	        val thy' = get_obj g_domID pt ppp;
wneuper@59405
   186
          val thy = Celem.assoc_thy thy';
wneuper@59286
   187
          val (E, l, a, b, ctxt') = case get_loc pt (pp, Frm) of
wneuper@59572
   188
            (Istate.ScrState (E, l, a, _, _, b), ctxt') => (E, l, a, b, ctxt')
wneuper@59286
   189
          | _ => error "solve Check_Postcond resume script of parpbl: uncovered case get_loc"
wneuper@59577
   190
	        val ctxt'' = ContextC.from_subpbl_to_caller ctxt scval ctxt'
wneuper@59571
   191
          val ((p, p_), ps, _, pt) = Generate.generate1 thy (Tactic.Check_Postcond' (pI, (scval, asm)))
wneuper@59572
   192
		        (Istate.ScrState (E,l,a,scval,scsaf,b), ctxt'') (pp,Res) pt;
wneuper@59571
   193
       in ("ok", ([(Tactic.Check_Postcond pI, Tactic.Check_Postcond'(pI, (scval, asm)),
wneuper@59572
   194
  	      ((pp, Res), (Istate.ScrState (E, l, a, scval, scsaf, b), ctxt'')))], ps, (pt, (p, p_)))) end
wneuper@59286
   195
     end
wneuper@59571
   196
  | solve (_, Tactic.End_Proof'') (pt, (p, p_)) =
wneuper@59572
   197
    ("end-proof", ([(Tactic.Empty_Tac, Tactic.Empty_Tac_, (([], Res), (Istate.Uistate, Selem.e_ctxt)))], [], (pt, (p, p_))))
wneuper@59571
   198
  | solve (_, Tactic.End_Detail' t) (pt, (p, p_)) = (* could be done by generate1 ?!? *)
wneuper@59286
   199
    let (*Rewrite_Set* done at Detail_Set*: this result is already in ctree*)
wneuper@59286
   200
      val pr = (lev_up p, Res)
wneuper@59286
   201
    in
wneuper@59571
   202
      ("ok", ([(Tactic.End_Detail, Tactic.End_Detail' t , ((p, p_), get_loc pt (p, p_)))], [], (pt, pr)))
wneuper@59286
   203
    end
wneuper@59579
   204
    (* ======= general case ======= *)
wneuper@59286
   205
  | solve (_, m) (pt, po as (p, p_)) =
wneuper@59405
   206
    if Celem.e_metID = get_obj g_metID pt (par_pblobj pt p) (*29.8.02: could be detail, too !!*)
wneuper@59286
   207
    then
wneuper@59286
   208
      let
wneuper@59286
   209
        val ctxt = get_ctxt pt po
wneuper@59405
   210
        val ((p,p_),ps,_,pt) = Generate.generate1 (Celem.assoc_thy (get_obj g_domID pt (par_pblobj pt p))) 
wneuper@59572
   211
		      m (Istate.e_istate, ctxt) (p, p_) pt;
wneuper@59286
   212
	    in ("no-method-specified", (*Free_Solve*)
wneuper@59572
   213
	      ([(Tactic.Empty_Tac, Tactic.Empty_Tac_, ((p, p_), (Istate.Uistate, ctxt)))], ps, (pt, (p, p_))))
wneuper@59286
   214
      end
wneuper@59286
   215
    else
wneuper@59286
   216
	    let 
wneuper@59286
   217
	      val thy' = get_obj g_domID pt (par_pblobj pt p);
wneuper@59569
   218
	      val (_, is, sc) = Lucin.from_pblobj_or_detail' thy' (p,p_) pt;
wneuper@59286
   219
	    in
wneuper@59569
   220
        case LucinNEW.locate_input_tactic sc (pt, po) (fst is) (snd is) m  of
wneuper@59569
   221
	        LucinNEW.Safe_Step (cstate, istate, ctxt, tac) =>
wneuper@59569
   222
		        ("ok", ([(Lucin.tac_2tac tac, tac, (snd cstate, (istate, ctxt)))], [(*ctree NOT cut*)], cstate))
wneuper@59569
   223
	      | LucinNEW.Unsafe_Step (cstate, istate, ctxt, tac) =>
wneuper@59569
   224
		        ("ok", ([(Lucin.tac_2tac tac, tac, (snd cstate, (istate, ctxt)))], [(*ctree NOT cut*)], cstate))
wneuper@59286
   225
	      | _ => (* NotLocatable *)
wneuper@59286
   226
	        let 
wneuper@59405
   227
	          val (p,ps, _, pt) = Generate.generate_hard (Celem.assoc_thy "Isac") m (p, p_) pt;
wneuper@59286
   228
	        in
wneuper@59286
   229
	          ("not-found-in-script", ([(Lucin.tac_2tac m, m, (po, is))], ps, (pt, p)))
wneuper@59286
   230
          end
wneuper@59286
   231
	    end;
neuper@37906
   232
wneuper@59286
   233
(* says how may steps of a calculation should be done by "fun autocalc"
wneuper@59286
   234
   FIXXXME040624: does NOT match interfaces/ITOCalc.java
wneuper@59286
   235
   TODO.WN0512 redesign togehter with autocalc ?                     *)
neuper@37906
   236
datatype auto = 
wneuper@59260
   237
  Step of int      (*1 do #int steps (may stop in model/specify)
wneuper@59260
   238
                       IS VERY INEFFICIENT IN MODEL/SPECIY                    *)
neuper@37906
   239
| CompleteModel    (*2 complete modeling
wneuper@59260
   240
                       if model complete, finish specifying                   *)
wneuper@59260
   241
| CompleteCalcHead (*3 complete model/specify in one go                       *)
neuper@37906
   242
| CompleteToSubpbl (*4 stop at the next begin of a subproblem,
wneuper@59260
   243
                       if none, complete the actual (sub)problem              *)
wneuper@59260
   244
| CompleteSubpbl   (*5 complete the actual (sub)problem (incl.ev.subproblems) *)
wneuper@59260
   245
| CompleteCalc;    (*6 complete the calculation as a whole                    *)
neuper@42092
   246
neuper@37906
   247
fun autoord (Step _ ) = 1
neuper@37906
   248
  | autoord CompleteModel = 2
neuper@37906
   249
  | autoord CompleteCalcHead = 3
neuper@37906
   250
  | autoord CompleteToSubpbl = 4
neuper@37906
   251
  | autoord CompleteSubpbl = 5
neuper@37906
   252
  | autoord CompleteCalc = 6;
neuper@37906
   253
wneuper@59286
   254
fun complete_solve auto c (ptp as (_, p as (_, p_))) =
wneuper@59286
   255
    if p = ([], Res)
wneuper@59286
   256
    then ("end-of-calculation", [], ptp)
neuper@41997
   257
    else
wneuper@59286
   258
      if member op = [Pbl,Met] p_
wneuper@59286
   259
      then
wneuper@59286
   260
        let
wneuper@59286
   261
          val ptp = Chead.all_modspec ptp
wneuper@59286
   262
	        val (_, c', ptp) = all_solve auto c ptp
wneuper@59286
   263
	      in complete_solve auto (c @ c') ptp end
wneuper@59286
   264
      else
wneuper@59562
   265
        case LucinNEW.do_solve_step ptp of
wneuper@59571
   266
	        ((Tactic.Subproblem _, _, _) :: _, c', ptp') =>
wneuper@59286
   267
	          if autoord auto < 5
wneuper@59286
   268
            then ("ok", c @ c', ptp)
wneuper@59286
   269
	          else
wneuper@59286
   270
              let
wneuper@59286
   271
                val ptp = Chead.all_modspec ptp'
wneuper@59286
   272
	             val (_, c'', ptp) = all_solve auto (c @ c') ptp
wneuper@59286
   273
	           in complete_solve auto (c @ c'@ c'') ptp end
wneuper@59571
   274
	      | ((Tactic.Check_Postcond _, _, _) :: _, c', ptp' as (_, p')) =>
wneuper@59286
   275
	        if autoord auto < 6 orelse p' = ([], Res)
neuper@41997
   276
          then ("ok", c @ c', ptp')
neuper@41997
   277
	        else complete_solve auto (c @ c') ptp'
wneuper@59571
   278
	      | ((Tactic.End_Detail, _, _) :: _, c', ptp') => 
neuper@41997
   279
	        if autoord auto < 6
neuper@41997
   280
          then ("ok", c @ c', ptp')
neuper@41997
   281
	        else complete_solve auto (c @ c') ptp'
wneuper@59286
   282
	      | (_, c', ptp') => complete_solve auto (c @ c') ptp'
wneuper@59279
   283
and all_solve auto c (ptp as (pt, pos as (p,_)): ctree * pos') = 
wneuper@59286
   284
    let
wneuper@59286
   285
      val (_, _, mI) = get_obj g_spec pt p
wneuper@59286
   286
      val ctxt = get_ctxt pt pos
wneuper@59572
   287
      val (_, c', ptp) = LucinNEW.begin_end_prog (Tactic.Apply_Method' (mI, NONE, Istate.e_istate, ctxt)) (Istate.e_istate, ctxt) ptp
wneuper@59286
   288
    in
wneuper@59286
   289
      complete_solve auto (c @ c') ptp
wneuper@59286
   290
    end;
neuper@41997
   291
neuper@41997
   292
(* aux.fun for detailrls with Rrls, reverse rewriting *)
wneuper@59286
   293
fun rul_terms_2nds _ nds _ [] = nds
s1210629013@52153
   294
  | rul_terms_2nds thy nds t ((rule, res as (t', _)) :: rts) =
wneuper@59572
   295
    (append_atomic [] (Istate.e_istate, Selem.e_ctxt) t (Tactic.rule2tac thy [] rule) res Complete EmptyPtree) ::
wneuper@59286
   296
      (rul_terms_2nds thy nds t' rts);
neuper@37906
   297
neuper@41997
   298
(* detail steps done internally by Rewrite_Set* into ctree by use of a script *)
wneuper@59286
   299
fun detailrls pt (pos as (p, _)) = 
neuper@41997
   300
  let
neuper@41997
   301
    val t = get_obj g_form pt p
neuper@41997
   302
	  val tac = get_obj g_tac pt p
wneuper@59571
   303
	  val rls = (assoc_rls o Tactic.rls_of) tac
neuper@41997
   304
    val ctxt = get_ctxt pt pos
neuper@41997
   305
  in
neuper@41997
   306
    case rls of
wneuper@59416
   307
	    Rule.Rrls {scr = Rule.Rfuns {init_state, ...}, ...} => 
wneuper@59286
   308
	    let
wneuper@59286
   309
        val (_, _, _, rul_terms) = init_state t
wneuper@59286
   310
	      val newnds = rul_terms_2nds (Proof_Context.theory_of ctxt) [] t rul_terms
wneuper@59286
   311
	      val pt''' = ins_chn newnds pt p 
wneuper@59286
   312
	    in ("detailrls", pt''', (p @ [length newnds], Res)) end
neuper@41997
   313
	  | _ =>
wneuper@59286
   314
	    let
wneuper@59286
   315
        val is = Generate.init_istate tac t
wneuper@59286
   316
	      (*TODO.WN060602 ScrState (["(t_, Problem (Isac,[equation,univar]))"]
wneuper@59286
   317
			    is wrong for simpl, but working ?!? *)
wneuper@59571
   318
	      val tac_ = Tactic.Apply_Method' (Celem.e_metID(*WN0402: see generate1 !?!*), SOME t, is, ctxt)
wneuper@59286
   319
	      val pos' = ((lev_on o lev_dn) p, Frm)
wneuper@59405
   320
	      val thy = Celem.assoc_thy "Isac"
wneuper@59286
   321
	      val (_, _, _, pt') = Generate.generate1 thy tac_ (is, ctxt) pos' pt (* implicit Take *)
wneuper@59286
   322
	      val (_,_, (pt'', _)) = complete_solve CompleteSubpbl [] (pt', pos')
wneuper@59286
   323
	      val newnds = children (get_nd pt'' p)
wneuper@59286
   324
	      val pt''' = ins_chn newnds pt p (*complete_solve cuts branches after*)
wneuper@59411
   325
	    in ("detailrls", pt''', (p @ [length newnds], Res)) end
neuper@41997
   326
  end;
neuper@37906
   327
wneuper@59286
   328
fun get_form (mI, m) (p,p_) pt = 
wneuper@59286
   329
  case Applicable.applicable_in (p, p_) pt m of
wneuper@59271
   330
    Chead.Notappl e => Generate.Error' e
wneuper@59265
   331
  | Chead.Appl m => 
neuper@37935
   332
      if member op = specsteps mI
wneuper@59286
   333
      then
wneuper@59286
   334
        let val (_, _, f, _, _, _) = Chead.specify m (p, p_) [] pt
wneuper@59286
   335
        in f end
wneuper@59286
   336
      else Generate.EmptyMout;
wneuper@59562
   337
wneuper@59562
   338
fun inform (next_cs as (_, _, (pt, pos as (p, _))): Chead.calcstate') istr =
wneuper@59562
   339
  let
wneuper@59562
   340
    val ctxt = get_ctxt pt pos (*see TODO.thy*)
wneuper@59562
   341
  in
wneuper@59562
   342
    case TermC.parse (Celem.assoc_thy "Isac") istr of
wneuper@59562
   343
      NONE => ("syntax error in '" ^ istr ^ "'", Chead.e_calcstate' (*TODO: previous cs'*))
wneuper@59562
   344
    | SOME f_in =>
wneuper@59562
   345
      let
wneuper@59562
   346
    	  val f_in = Thm.term_of f_in
wneuper@59562
   347
        val pos_pred = lev_back(*'*) pos
wneuper@59562
   348
    	  val f_pred = Ctree.get_curr_formula (pt, pos_pred);
wneuper@59562
   349
    	  val f_succ = Ctree.get_curr_formula (pt, pos);
wneuper@59562
   350
      in
wneuper@59562
   351
        if f_succ = f_in
wneuper@59562
   352
        then ("same-formula", next_cs) (* ctree not cut with replaceFormula *)
wneuper@59562
   353
        else
wneuper@59562
   354
          case Inform.cas_input f_in of
wneuper@59562
   355
            SOME (pt, _) => ("ok",([], [], (pt, (p, Ctree.Met))))
wneuper@59562
   356
			    | NONE => (*/-------------------------------------- NEW fun locate_input_formula------*)
wneuper@59562
   357
            let
wneuper@59562
   358
       (*NEW*)val (_, _, metID) = get_obj g_spec pt (par_pblobj pt p)
wneuper@59562
   359
       (*NEW*)val {scr = prog, ...} = Specify.get_met metID
wneuper@59562
   360
       (*NEW*)val istate = get_istate pt pos
wneuper@59562
   361
       (*NEW*)val ctxt = get_ctxt pt pos
wneuper@59562
   362
            in
wneuper@59562
   363
              case LucinNEW.locate_input_formula prog (pt, pos) istate ctxt f_in of
wneuper@59562
   364
                LucinNEW.Step (cstate, _(*istate*), _(*ctxt*)) =>
wneuper@59562
   365
                ("ok" , ([], [], cstate (* already contains istate, ctxt *)))
wneuper@59562
   366
              | LucinNEW.Not_Derivable calcstate' =>
wneuper@59562
   367
                let
wneuper@59562
   368
            		  val pp = Ctree.par_pblobj pt p
wneuper@59562
   369
            		  val (errpats, nrls, prog) = case Specify.get_met (Ctree.get_obj Ctree.g_metID pt pp) of
wneuper@59562
   370
              		    {errpats, nrls, scr = Rule.Prog prog, ...} => (errpats, nrls, prog)
wneuper@59562
   371
              		  | _ => error "inform: uncovered case of get_met"
wneuper@59562
   372
            		  val env = case Ctree.get_istate pt pos of
wneuper@59572
   373
              		    Istate.ScrState (env, _, _, _, _, _) => env
wneuper@59562
   374
              		  | _ => error "inform: uncovered case of get_istate"
wneuper@59562
   375
            		in
wneuper@59562
   376
            		  case Inform.check_error_patterns (f_pred, f_in) (prog, env) (errpats, nrls) of
wneuper@59562
   377
            		    SOME errpatID => ("error pattern #" ^ errpatID ^ "#", calcstate')
wneuper@59562
   378
            		  | NONE => ("no derivation found", calcstate')
wneuper@59562
   379
                end
wneuper@59562
   380
            end
wneuper@59562
   381
      end
wneuper@59562
   382
  end
wneuper@59562
   383
wneuper@59273
   384
end