test/Tools/isac/Interpret/lucas-interpreter.sml
author Walther Neuper <walther.neuper@jku.at>
Sat, 08 Feb 2020 16:33:27 +0100
changeset 59797 a7727cceb2a0
parent 59795 24c9cbf8731c
child 59798 3eca30214739
permissions -rw-r--r--
step separated wrt Solve .. Specify
wneuper@59561
     1
(* Title:  "Interpret/lucas-interpreter.sml"
wneuper@59561
     2
   Author: Walther Neuper
wneuper@59561
     3
   (c) due to copyright terms
wneuper@59561
     4
*)
wneuper@59561
     5
wneuper@59561
     6
"-----------------------------------------------------------------------------------------------";
wneuper@59561
     7
"table of contents -----------------------------------------------------------------------------";
wneuper@59561
     8
"-----------------------------------------------------------------------------------------------";
wneuper@59561
     9
"----------- Take as 1st stac in program -------------------------------------------------------";
walther@59670
    10
"----------- re-build: fun locate_input_tactic -------------------------------------------------";
walther@59670
    11
"----------- fun locate_input_tactic Helpless, but applicable ----------------------------------";
walther@59783
    12
"----------- re-build: fun find_next_step ------------------------------------------------------";
walther@59781
    13
"----------- re-build: fun find_next_step, mini ------------------------------------------------";
walther@59783
    14
"----------- re-build: fun locate_input_term ---------------------------------------------------";
wneuper@59561
    15
"-----------------------------------------------------------------------------------------------";
wneuper@59561
    16
"-----------------------------------------------------------------------------------------------";
wneuper@59561
    17
"-----------------------------------------------------------------------------------------------";
wneuper@59561
    18
wneuper@59561
    19
"----------- Take as 1st stac in program -------------------------------------------------------";
wneuper@59561
    20
"----------- Take as 1st stac in program -------------------------------------------------------";
wneuper@59561
    21
"----------- Take as 1st stac in program -------------------------------------------------------";
wneuper@59561
    22
val p = e_pos'; val c = []; 
wneuper@59561
    23
val (p,_,f,nxt,_,pt) = 
wneuper@59561
    24
    CalcTreeTEST 
wneuper@59561
    25
        [(["functionTerm (x^^^2 + 1)", "integrateBy x", "antiDerivative FF"],
wneuper@59561
    26
          ("Integrate", ["integrate","function"], ["diff","integration"]))];
wneuper@59561
    27
val (p,_,f,nxt,_,pt) = me nxt p c pt; (*nxt = ("Tac ", ...) --> Add_Given...*)
wneuper@59561
    28
val (p,_,f,nxt,_,pt) = me nxt p c pt;
wneuper@59561
    29
val (p,_,f,nxt,_,pt) = me nxt p c pt;
wneuper@59561
    30
val (p,_,f,nxt,_,pt) = me nxt p c pt;
wneuper@59561
    31
val (p,_,f,nxt,_,pt) = me nxt p c pt;
wneuper@59561
    32
val (p,_,f,nxt,_,pt) = me nxt p c pt;
wneuper@59561
    33
val (p,_,f,nxt,_,pt) = me nxt p c pt;
walther@59749
    34
case nxt of (Apply_Method ["diff", "integration"]) => ()
wneuper@59561
    35
          | _ => error "integrate.sml -- me method [diff,integration] -- spec";
wneuper@59561
    36
"----- step 8: returns nxt = Rewrite_Set_Inst ([\"(''bdv'', x)\"],\"integration\")";
wneuper@59561
    37
walther@59749
    38
"~~~~~ fun me, args:"; val (tac, (p:pos'), _, (pt:ctree)) = (nxt, p, c, pt);
wneuper@59561
    39
"~~~~~ fun locatetac, args:"; val (tac, (ptp as (pt, p))) = (tac, (pt,p));
walther@59755
    40
val Appl m = applicable_in p pt tac;
walther@59755
    41
 (*if*) Tactic.for_specify' m; (*false*)
walther@59749
    42
"~~~~~ fun loc_solve_ , args:"; val (m, (pt,pos)) = (m, ptp);
walther@59686
    43
walther@59751
    44
"~~~~~ fun Step_Solve.by_tactic , args:"; val (m as Apply_Method' (mI, _, _, ctxt), (pt, (pos as (p,_))))
walther@59749
    45
  = (m, (pt, pos));
walther@59686
    46
      val {srls, ...} = get_met mI;
walther@59686
    47
      val itms = case get_obj I pt p of
walther@59686
    48
        PblObj {meth=itms, ...} => itms
walther@59686
    49
      | _ => error "solve Apply_Method: uncovered case get_obj"
walther@59686
    50
      val thy' = get_obj g_domID pt p;
walther@59686
    51
      val thy = Celem.assoc_thy thy';
walther@59790
    52
      val srls = LItool.get_simplifier (pt, pos)
walther@59790
    53
      val (is, env, ctxt, sc) = case LItool.init_pstate srls ctxt itms mI of
walther@59686
    54
        (is as Istate.Pstate {env, ...}, ctxt, sc) =>  (is, env, ctxt, sc)
walther@59697
    55
      | _ => error "solve Apply_Method: uncovered case init_pstate";
walther@59784
    56
(*+*)pstate2str (the_pstate is) = "([\"\n(f_f, x ^^^ 2 + 1)\",\"\n(v_v, x)\"], [], e_rls, NONE, \n??.empty, ORundef, false, true)";
walther@59790
    57
      val ini = LItool.init_form thy sc env;
walther@59686
    58
      val p = lev_dn p;
walther@59686
    59
walther@59686
    60
      val NONE = (*case*) ini (*of*);
walther@59734
    61
            val Next_Step (is', ctxt', m') =
walther@59791
    62
              LI.find_next_step sc (pt, (p, Res)) is ctxt;
walther@59784
    63
(*+*)pstate2str (the_pstate is') = "([\"\n(f_f, x ^^^ 2 + 1)\",\"\n(v_v, x)\"], [R,L,R], e_rls, NONE, \nIntegral x ^^^ 2 + 1 D x, ORundef, false, false)";
walther@59686
    64
  val Safe_Step (_, _, Take' _) = (*case*)
walther@59686
    65
           locate_input_tactic sc (pt, (p, Res)) is' ctxt' m' (*of*);
walther@59692
    66
"~~~~~ fun locate_input_tactic , args:"; val ((Prog prog), cstate, istate, ctxt, tac)
walther@59686
    67
  = (sc, (pt, (p, Res)), is', ctxt', m');
walther@59686
    68
walther@59692
    69
    (*case*) scan_to_tactic1 (prog, (cstate, ctxt, tac)) istate (*of*);
walther@59692
    70
"~~~~~ fun scan_to_tactic1 , args:"; val ((prog, (cctt as ((_, p), _, _))), (Istate.Pstate (ist as {path, ...})))
walther@59692
    71
  = ((prog, (cstate, ctxt, tac)), istate);
walther@59686
    72
    (*if*) path = [] orelse ((last_elem o fst) p = 0 andalso snd p = Res) (*then*);
walther@59686
    73
walther@59718
    74
  val Accept_Tac1 (_, _, Take' _) =
walther@59718
    75
       scan_dn1 cctt (ist |> set_path [R] |> set_or ORundef) (Program.body_of prog);
walther@59691
    76
"~~~~~ fun scan_dn1 , args:"; val (xxx, ist, (Const ("HOL.Let", _) $ e $ (Abs (id, T, b))))
walther@59718
    77
  = (cctt, (ist |> set_path [R] |> set_or ORundef), (Program.body_of prog));
walther@59686
    78
walther@59691
    79
(*+*) if term2str e = "Take (Integral f_f D v_v)" then () else error "scan_dn1 Integral changed";
walther@59686
    80
walther@59686
    81
    (*case*)
walther@59691
    82
           scan_dn1 xxx (ist |> path_down [L, R]) e (*of*);
walther@59686
    83
    (*======= end of scanning tacticals, a leaf =======*)
walther@59722
    84
"~~~~~ fun scan_dn1 , args:"; val (((pt, p), ctxt, tac), (ist as {eval, or, ...}), t)
walther@59686
    85
  = (xxx, (ist |> path_down [L, R]), e);
walther@59772
    86
val (Program.Tac stac, a') = check_leaf "locate" ctxt eval (get_subst ist) t;
wneuper@59561
    87
wneuper@59561
    88
walther@59670
    89
"----------- re-build: fun locate_input_tactic -------------------------------------------------";
walther@59670
    90
"----------- re-build: fun locate_input_tactic -------------------------------------------------";
walther@59670
    91
"----------- re-build: fun locate_input_tactic -------------------------------------------------";
wneuper@59562
    92
val fmz = ["equality (x+1=(2::real))", "solveFor x","solutions L"];
walther@59670
    93
val (dI',pI',mI') = ("Test", ["sqroot-test","univariate","equation","test"],
wneuper@59562
    94
   ["Test","squ-equ-test-subpbl1"]);
wneuper@59562
    95
val (p,_,f,nxt,_,pt) = CalcTreeTEST [(fmz, (dI',pI',mI'))];
wneuper@59562
    96
val (p,_,f,nxt,_,pt) = me nxt p [] pt;
wneuper@59562
    97
val (p,_,f,nxt,_,pt) = me nxt p [] pt;
wneuper@59562
    98
val (p,_,f,nxt,_,pt) = me nxt p [] pt;
wneuper@59562
    99
val (p,_,f,nxt,_,pt) = me nxt p [] pt;
wneuper@59562
   100
val (p,_,f,nxt,_,pt) = me nxt p [] pt;
wneuper@59562
   101
val (p,_,f,nxt,_,pt) = me nxt p [] pt;
walther@59670
   102
(*[], Met*)val (p,_,f,nxt,_,pt) = me nxt p [] pt; (*nxt = (_, Apply_Method ["Test", "squ-equ-test-subpbl1"])*);
walther@59670
   103
(*[1], Frm*)val (p,_,f,nxt,_,pt) = me nxt p [] pt; (*nxt = ("Rewrite_Set", Rewrite_Set "norm_equation")*)
wneuper@59562
   104
walther@59781
   105
(*//------------------ begin step into ------------------------------------------------------\\*)
walther@59686
   106
(*[1], Res*)val (p'''''_''',_,f,nxt'''''_''',_,pt'''''_''') = me nxt p [] pt; (*nxt = Rewrite_Set "Test_simplify"*)
wneuper@59562
   107
walther@59749
   108
"~~~~~ fun me , args:"; val (tac, p, _(*NEW remove*), pt) = (nxt, p, [], pt);
wneuper@59562
   109
walther@59670
   110
    (** )val (***)xxxx(***) ( *("ok", (_, _, (pt, p))) =( **)  (*case*) locatetac tac (pt,p) (*of*);
walther@59670
   111
"~~~~~ fun locatetac , args:"; val (tac, (ptp as (pt, p))) = (tac, (pt,p));
walther@59755
   112
      val Applicable.Appl m = (*case*) Applicable.applicable_in p pt tac (*of*);
walther@59755
   113
      (*if*) Tactic.for_specify' m; (*false*)
walther@59670
   114
walther@59749
   115
      (** )val (***)xxxxx(***) ( *Updated (cs' as (_, _, (_, p'))) =( **) loc_solve_ m ptp;
walther@59749
   116
"~~~~~ fun loc_solve_ , args:"; val (m, (pt, pos)) = (m, ptp);
walther@59670
   117
walther@59751
   118
    (** )val (***)xxxxx_x(***) ( *(msg, cs') =( **) Step_Solve.by_tactic m (pt, pos);
walther@59751
   119
"~~~~~ fun Step_Solve.by_tactic , args:"; val (m, (pt, po as (p, p_))) = (m, (pt, pos));
walther@59670
   120
(*+*)val (pt'''''_', (p'''''_', p_'''''_')) = (pt, (p, p_));
walther@59670
   121
    (*if*) Celem.e_metID = get_obj g_metID pt (par_pblobj pt p); (*else*)
walther@59670
   122
	      val thy' = get_obj g_domID pt (par_pblobj pt p);
walther@59790
   123
	      val (_, is, sc) = LItool.from_pblobj' thy' (p,p_) pt;
walther@59670
   124
walther@59670
   125
     locate_input_tactic sc (pt, po) (fst is) (snd is) m;
walther@59692
   126
"~~~~~ fun locate_input_tactic , args:"; val (Prog prog, cstate, istate, ctxt, tac)
walther@59670
   127
    = (sc, (pt, po), (fst is), (snd is), m);
walther@59670
   128
      val srls = get_simplifier cstate;
walther@59670
   129
walther@59718
   130
 (** )val Accept_Tac1 ((is as (_,_,_,_,_,strong_ass), ctxt, ss as((tac', _, ctree, pos', _) :: _))) =( **)
walther@59692
   131
  (*case*) scan_to_tactic1 (prog, (cstate, ctxt, tac)) istate (*of*);
walther@59692
   132
"~~~~~ fun scan_to_tactic1 , args:"; val ((prog, (cctt as ((_, p), _, _))), (Istate.Pstate (ist as {path, ...})))
walther@59692
   133
  = ((prog, (cstate, ctxt, tac)), istate);
walther@59686
   134
    (*if*) path = [] orelse ((last_elem o fst) p = 0 andalso snd p = Res) (*then*);
walther@59670
   135
walther@59670
   136
    (** )val xxxxx_xx = ( **)
walther@59718
   137
           scan_dn1 cctt (ist |> set_path [R] |> set_or ORundef) (Program.body_of prog);
walther@59691
   138
"~~~~~ fun scan_dn1 , args:"; val (xxx, ist, (Const ("HOL.Let", _) $ e $ (Abs (id, T, b))))
walther@59718
   139
  = (cctt, (ist |> set_path [R] |> set_or ORundef), (Program.body_of prog));
walther@59670
   140
walther@59691
   141
  (*case*) scan_dn1 xxx (ist |> path_down [L, R]) e (*of*);
walther@59691
   142
"~~~~~ fun scan_dn1 , args:"; val ((xxx as (cstate, _, _)), ist, (Const ("Tactical.Chain"(*1*), _) $ e1 $ e2 $ a))
walther@59686
   143
  = (xxx, (ist |> path_down [L, R]), e);
walther@59670
   144
walther@59691
   145
  (*case*) scan_dn1 xxx (ist |> path_down_form ([L, L, R], a)) e1 (*of*);
walther@59691
   146
"~~~~~ fun scan_dn1 , args:"; val (xxx, ist, (Const ("Tactical.Try"(*2*), _) $ e))
walther@59686
   147
  = (xxx, (ist |> path_down_form ([L, L, R], a)), e1);
walther@59670
   148
walther@59691
   149
  (*case*) scan_dn1 xxx (ist |> path_down [R]) e (*of*);
walther@59670
   150
    (*======= end of scanning tacticals, a leaf =======*)
walther@59691
   151
"~~~~~ fun scan_dn1 , args:"; val (((pt, p), ctxt, tac), (ist as {env, eval, or, ...}), t)
walther@59686
   152
  = (xxx, (ist |> path_down [R]), e);
walther@59721
   153
    val (Program.Tac stac, a') =
walther@59772
   154
      (*case*) check_leaf "locate" ctxt eval (get_subst ist) t (*of*);
walther@59790
   155
    val LItool.Ass (m, v', ctxt) =
walther@59686
   156
      (*case*) associate pt ctxt (m, stac) (*of*);
walther@59670
   157
walther@59718
   158
       Accept_Tac1 (ist |> set_subst_true  (a', v'), ctxt, m)  (*return value*);
walther@59691
   159
"~~~~~ from scan_dn1 to scan_to_tactic1 return val:"; val (xxxxx_xx)
walther@59718
   160
  = (Accept_Tac1 (ist |> set_subst_true  (a', v'), ctxt, m));
walther@59670
   161
walther@59718
   162
"~~~~~ from scan_to_tactic1 to fun locate_input_tactic return val:"; val Accept_Tac1 ((ist as {assoc, ...}), ctxt, tac')
walther@59718
   163
  = (Accept_Tac1 (ist |> set_subst_true  (a', v'), ctxt, m));
walther@59686
   164
        (*if*) LibraryC.assoc (*then*);
walther@59670
   165
walther@59686
   166
       Safe_Step (Istate.Pstate ist, ctxt, tac')  (*return value*);
walther@59751
   167
"~~~~~ from locate_input_tactic to fun Step_Solve.by_tactic return:"; val Safe_Step (istate, ctxt, tac)
walther@59686
   168
  = (*xxxxx_xx*)(**)Safe_Step (Istate.Pstate ist, ctxt, tac')(**);
walther@59670
   169
walther@59751
   170
(*+*)val (pt, po as (p, p_)) = (pt'''''_', (p'''''_', p_'''''_')); (* from begin of by_tactic *)
walther@59686
   171
                  val (p'', _, _,pt') =
walther@59686
   172
                    Generate.generate1 (Celem.assoc_thy "Isac_Knowledge") tac
walther@59790
   173
                    (* DEL.^^^^^ ContextC.insert_assumptions asms' ctxt 2nd, fst in LItool.associate *)
walther@59686
   174
                      (istate, ctxt) (lev_on p, Pbl) pt;
walther@59686
   175
            (*in*)
walther@59670
   176
walther@59704
   177
         	  	    ("ok", ([(Tactic.input_from_T tac, tac, (p'', (istate, ctxt)))],
walther@59686
   178
                    [(*ctree NOT cut*)], (pt', p'')))  (*return value*);
walther@59751
   179
"~~~~~ from Step_Solve.by_tactic to loc_solve_ return:"; val ((msg, cs' : calcstate'))
walther@59704
   180
  =                    ("ok", ([(Tactic.input_from_T tac, tac, (p'', (istate, ctxt)) )], [(*ctree NOT cut*)], (pt', p'')));
walther@59670
   181
walther@59670
   182
"~~~~~ from loc_solve_ to locatetac return:"; val (Updated (cs' as (_, _, (_, p'))))
walther@59670
   183
   = (*** )xxxxx( ***) (Updated (cs'));
walther@59694
   184
          (*if*) p' = ([], Pos.Res); (*else*)
walther@59670
   185
          ("ok", cs');
walther@59670
   186
"~~~~~ from locatetac to me return:"; val (("ok", (_, _, (pt, p)))) = (*** )xxxx( ***) ("ok", cs');
wneuper@59562
   187
	  val (_, ts) =
walther@59765
   188
	    (case Step.do_next p ((pt, Pos.e_pos'), []) of
wneuper@59562
   189
		    ("ok", (ts as (_, _, _) :: _, _, _)) => ("", ts)
wneuper@59562
   190
	    | ("helpless", _) => ("helpless: cannot propose tac", [])
wneuper@59562
   191
	    | ("no-fmz-spec", _) => error "no-fmz-spec"
wneuper@59562
   192
	    | ("end-of-calculation", (ts, _, _)) => ("", ts)
wneuper@59562
   193
	    | _ => error "me: uncovered case")
wneuper@59562
   194
	      handle ERROR msg => raise ERROR msg
wneuper@59562
   195
	  val tac = 
wneuper@59562
   196
      case ts of 
wneuper@59562
   197
        tacis as (_::_) => let val (tac, _, _) = last_elem tacis in tac end 
walther@59694
   198
		  | _ => if p = ([], Pos.Res) then Tactic.End_Proof' else Tactic.Empty_Tac;
wneuper@59562
   199
walther@59675
   200
   (p, [] : NEW, TESTg_form (pt, p), (Tactic.tac2IDstr tac, tac), Telem.Sundef, pt);
walther@59670
   201
"~~~~~ from me to TOOPLEVEL return:"; val (p,_,f,nxt,_,pt)
walther@59675
   202
   = (*** )xxx( ***) (p, [] : NEW, TESTg_form (pt, p), (Tactic.tac2IDstr tac, tac), Telem.Sundef, pt);
walther@59670
   203
walther@59670
   204
(*//--------------------- check results from modified me ----------------------------------\\*)
walther@59686
   205
if p = ([2], Res) andalso
walther@59686
   206
  pr_ctree pr_short pt = ".    ----- pblobj -----\n1.   x + 1 = 2\n2.   x + 1 = 2\n"
walther@59670
   207
then
walther@59670
   208
  (case nxt of ("Rewrite_Set", Rewrite_Set "Test_simplify") => ()
walther@59670
   209
   | _ => error "")
walther@59670
   210
else error "check results from modified me CHANGED";
walther@59670
   211
(*\\--------------------- check results from modified me ----------------------------------//*)
walther@59670
   212
walther@59670
   213
"~~~~~ from me to TOPLEVEL return:"; val (p,_,f,nxt,_,pt) = (*** )xxx( ***) (**)(p, 000, f, nxt, 000, pt)(**);
walther@59781
   214
(*\\------------------ end step into --------------------------------------------------------//*)
walther@59686
   215
walther@59686
   216
(*[3], Res*)val (p,_,f,nxt,_,pt) = me nxt'''''_''' p'''''_''' [] pt'''''_'''; (*nxt = Subproblem ("Test", ["LINEAR", "univariate", "equation", "test"])*)
walther@59670
   217
(*[3], Pbl*)val (p,_,f,nxt,_,pt) = me nxt p [] pt; (*nxt = Model_Problem*)
walther@59670
   218
(*[3], Pbl*)val (p,_,f,nxt,_,pt) = me nxt p [] pt; (*nxt = Add_Given "equality (-1 + x = 0)"*)
walther@59670
   219
(*[3], Pbl*)val (p,_,f,nxt,_,pt) = me nxt p [] pt; (*nxt = Add_Given "solveFor x"*)
walther@59670
   220
(*[3], Pbl*)val (p,_,f,nxt,_,pt) = me nxt p [] pt; (*nxt = Add_Find "solutions x_i"*)
walther@59670
   221
(*[3], Pbl*)val (p,_,f,nxt,_,pt) = me nxt p [] pt; (*nxt = Specify_Theory "Test"*)
walther@59670
   222
(*[3], Pbl*)val (p,_,f,nxt,_,pt) = me nxt p [] pt; (*nxt = Specify_Problem ["LINEAR", "univariate", "equation", "test"]*)
walther@59670
   223
(*[3], Pbl*)val (p,_,f,nxt,_,pt) = me nxt p [] pt; (*nxt = Specify_Method ["Test", "solve_linear"]*)
walther@59670
   224
(*[3], Met*)val (p,_,f,nxt,_,pt) = me nxt p [] pt; (*nxt = Apply_Method ["Test", "solve_linear"]*)
walther@59670
   225
(*[3, 1], Frm*)val (p,_,f,nxt,_,pt) = me nxt p [] pt; (*nxt = Rewrite_Set_Inst (["(''bdv'', x)"], "isolate_bdv")*)
walther@59670
   226
(*[3, 1], Res*)val (p,_,f,nxt,_,pt) = me nxt p [] pt; (*nxt = Rewrite_Set "Test_simplify"*)
walther@59670
   227
(*[3, 2], Res*)val (p,_,f,nxt,_,pt) = me nxt p [] pt; (*nxt = Check_Postcond ["LINEAR", "univariate", "equation", "test"]*)
wneuper@59562
   228
(*[3], Res*)val (p,_,f,nxt,_,pt) = me nxt p [] pt; (*nxt = Check_elementwise "Assumptions"*)
wneuper@59562
   229
(*[4], Res*)val (p,_,f,nxt,_,pt) = me nxt p [] pt; (*nxt = Check_Postcond ["sqroot-test", "univariate", "equation", "test"]*)
wneuper@59562
   230
(*[], Res*)val (p,_,f,nxt,_,pt) = me nxt p [] pt; (*nxt = End_Proof'*)
wneuper@59562
   231
walther@59670
   232
(*/--------------------- final test ----------------------------------\\*)
walther@59749
   233
if p = ([], Res) andalso f2str f = "[x = 1]" andalso pr_ctree pr_short pt =
walther@59670
   234
  ".    ----- pblobj -----\n" ^
walther@59670
   235
  "1.   x + 1 = 2\n" ^
walther@59670
   236
  "2.   x + 1 + -1 * 2 = 0\n" ^
walther@59670
   237
  "3.    ----- pblobj -----\n" ^
walther@59670
   238
  "3.1.   -1 + x = 0\n" ^
walther@59670
   239
  "3.2.   x = 0 + -1 * -1\n" ^
walther@59670
   240
  "4.   [x = 1]\n"
walther@59749
   241
then case nxt of End_Proof' => () | _ => error "re-build: fun locate_input_tactic changed 1"
walther@59749
   242
else error "re-build: fun locate_input_tactic changed 2";
wneuper@59562
   243
walther@59670
   244
walther@59670
   245
"----------- fun locate_input_tactic Helpless, but applicable ----------------------------------";
walther@59670
   246
"----------- fun locate_input_tactic Helpless, but applicable ----------------------------------";
walther@59670
   247
"----------- fun locate_input_tactic Helpless, but applicable ----------------------------------";
walther@59670
   248
(*cp from -- try fun applyTactics ------- *)
walther@59670
   249
val (p,_,f,nxt,_,pt) = CalcTreeTEST [(["Term (5*e + 6*f - 8*g - 9 - 7*e - 4*f + 10*g + 12)",
walther@59670
   250
	    "normalform N"],
walther@59670
   251
	   ("PolyMinus",["plus_minus","polynom","vereinfachen"],
walther@59670
   252
	    ["simplification","for_polynomials","with_minus"]))];
walther@59670
   253
val (p,_,f,nxt,_,pt) = me nxt p [] pt; val (p,_,f,nxt,_,pt) = me nxt p [] pt;
walther@59670
   254
val (p,_,f,nxt,_,pt) = me nxt p [] pt; val (p,_,f,nxt,_,pt) = me nxt p [] pt;
walther@59670
   255
val (p,_,f,nxt,_,pt) = me nxt p [] pt; val (p,_,f,nxt,_,pt) = me nxt p [] pt;
walther@59670
   256
(*[1], Frm*)val (p,_,f,nxt,_,pt) = me nxt p [] pt; (*nxt = Rewrite_Set "ordne_alphabetisch"*)
walther@59670
   257
(*[1], Res*)val (p,_,f,nxt,_,pt) = me nxt p [] pt; (*nxt = Rewrite_Set "fasse_zusammen"*)
walther@59670
   258
walther@59686
   259
(*+*)if map tac2str (sel_appl_atomic_tacs pt p) =
walther@59670
   260
   ["Rewrite (\"subtrahiere_x_plus_minus\", \"\<lbrakk>?l is_const; ?m is_const\<rbrakk>\n\<Longrightarrow> ?x + ?m * ?v - ?l * ?v = ?x + (?m - ?l) * ?v\")",
walther@59686
   261
    "Rewrite (\"subtrahiere_x_minus_plus\", \"\<lbrakk>?l is_const; ?m is_const\<rbrakk>\n\<Longrightarrow> ?x - ?m * ?v + ?l * ?v = ?x + (- ?m + ?l) * ?v\")"]
walther@59686
   262
  then () else error "sel_appl_atomic_tacs ([1], Res) CHANGED";
walther@59670
   263
(*[2], Res*)val ("ok", (_, _, ptp as (pt, p))) = locatetac (hd (sel_appl_atomic_tacs pt p)) (pt, p);
walther@59670
   264
walther@59686
   265
(*+*)if map tac2str (sel_appl_atomic_tacs pt p) =
walther@59670
   266
   ["Rewrite (\"tausche_minus\", \"\<lbrakk>?b ist_monom; ?a kleiner ?b\<rbrakk>\n\<Longrightarrow> ?b - ?a = - ?a + ?b\")", "Rewrite (\"tausche_plus_minus\", \"?b kleiner ?c \<Longrightarrow> ?a + ?c - ?b = ?a - ?b + ?c\")",
walther@59670
   267
    "Rewrite (\"subtrahiere_x_plus_minus\", \"\<lbrakk>?l is_const; ?m is_const\<rbrakk>\n\<Longrightarrow> ?x + ?m * ?v - ?l * ?v = ?x + (?m - ?l) * ?v\")",
walther@59686
   268
    "Rewrite (\"subtrahiere_x_minus_plus\", \"\<lbrakk>?l is_const; ?m is_const\<rbrakk>\n\<Longrightarrow> ?x - ?m * ?v + ?l * ?v = ?x + (- ?m + ?l) * ?v\")", "Calculate MINUS"]
walther@59686
   269
  then () else error "sel_appl_atomic_tacs ([1], Res) CHANGED";
walther@59670
   270
(* = ([3], Res)*)val ("ok", (_, _, ptp as (pt, p))) = locatetac (hd (sel_appl_atomic_tacs pt p)) (pt, p);
walther@59670
   271
walther@59670
   272
(*//----------------- exception PTREE "get_obj f EmptyPtree" raised --------------------------\\*)
walther@59670
   273
(** )val ("ok", (_, _, ptp as (pt, p))) =( **) locatetac (hd (sel_appl_atomic_tacs pt p)) (pt, p);
walther@59670
   274
"~~~~~ fun locatetac , args:"; val (tac, (ptp as (pt, p))) = (hd (sel_appl_atomic_tacs pt p), (pt, p));
walther@59755
   275
      val Applicable.Appl m = (*case*) Applicable.applicable_in p pt tac (*of*);
walther@59755
   276
      (*if*) Tactic.for_specify' m; (*false*)
walther@59670
   277
walther@59749
   278
      loc_solve_ m ptp;
walther@59749
   279
"~~~~~ fun loc_solve_ , args:"; val (m, (pt, pos)) = (m, ptp);
walther@59751
   280
           Step_Solve.by_tactic m (pt, pos);
walther@59670
   281
  (* ======== general case ======== *)
walther@59751
   282
"~~~~~ fun Step_Solve.by_tactic , args:"; val (m, (pt, po as (p, p_))) = (m, (pt, pos));
walther@59670
   283
    (*if*) Celem.e_metID = get_obj g_metID pt (par_pblobj pt p) (*else*);
walther@59670
   284
	      val thy' = get_obj g_domID pt (par_pblobj pt p);
walther@59790
   285
	      val (_, is, sc) = LItool.from_pblobj_or_detail' thy' (p,p_) pt;
walther@59670
   286
walther@59686
   287
  (*case*) locate_input_tactic sc (pt, po) (fst is) (snd is) m (*of*);
walther@59692
   288
"~~~~~ fun locate_input_tactic , args:"; val ((Rule.Prog prog), (cstate as (pt, (*?*)pos(*?*))), istate, ctxt, tac)
walther@59670
   289
  = (sc, (pt, po), (fst is), (snd is), m);
walther@59790
   290
      val srls = LItool.get_simplifier cstate (*TODO: shift into Istate.T*);
walther@59670
   291
walther@59692
   292
  (*case*) scan_to_tactic1 (prog, (cstate, ctxt, tac)) istate (*of*);
walther@59692
   293
"~~~~~ fun scan_to_tactic1 , args:"; val ((prog, (cctt as ((_, p), _, _))), (Istate.Pstate (ist as {path, ...})))
walther@59692
   294
  = ((prog, (cstate, ctxt, tac)), istate);
walther@59686
   295
    (*if*) path = [] orelse ((last_elem o fst) p = 0 andalso snd p = Res) (*else*);
walther@59670
   296
walther@59692
   297
           go_scan_up1 (prog, cctt) ist;
walther@59692
   298
"~~~~~ and go_scan_up1 , args:"; val ((yyy as (prog, _)), (ist as {path, ...}))
walther@59692
   299
  = ((prog, cctt), ist);
walther@59686
   300
  (*if*) 1 < length path (*then*);
walther@59670
   301
walther@59767
   302
           scan_up1 yyy (ist |> path_up) (at_location (path_up' path) prog);
walther@59691
   303
"~~~~~ fun scan_up1 , args:"; val (yyy, ist, (Const ("Tactical.Try"(*2*), _) $ _))
walther@59767
   304
  = (yyy, (ist |> path_up), (at_location (path_up' path) prog));
walther@59670
   305
walther@59691
   306
           go_scan_up1 yyy ist;
walther@59692
   307
"~~~~~ and go_scan_up1 , args:"; val ((yyy as (prog, _)), (ist as {path, ...}))
walther@59686
   308
  = (yyy, ist);
walther@59686
   309
  (*if*) 1 < length path (*then*);
walther@59670
   310
walther@59767
   311
           scan_up1 yyy (ist |> path_up) (at_location (path_up' path) prog);
walther@59692
   312
"~~~~~ fun scan_up1 , args:"; val ((yyy as (prog, xxx as (cstate, _, _))), ist,
walther@59688
   313
    (Const ("Tactical.Chain"(*3*), _) $ _ ))
walther@59767
   314
  = (yyy, (ist |> path_up), (at_location (path_up' path) prog));
walther@59692
   315
       val e2 = check_Seq_up ist prog
walther@59686
   316
;
walther@59718
   317
  (*case*) scan_dn1 xxx (ist |> path_up_down [R] |> set_or ORundef) e (*of*);
walther@59691
   318
"~~~~~ fun scan_dn1 , args:"; val (yyy, ist, (Const ("Tactical.Chain"(*2*), _) $ _ $ _))
walther@59718
   319
  = (xxx, (ist |> path_up_down [R] |> set_or ORundef), e2);
walther@59670
   320
walther@59691
   321
  (*case*) scan_dn1 xxx (ist |> path_down [L, R]) e1 (*of*);
walther@59691
   322
"~~~~~ fun scan_dn1 , args:"; val (xxx, ist, (Const ("Tactical.Try"(*2*), _) $ e))
walther@59686
   323
  = (xxx, (ist |> path_down [L, R]), e1);
walther@59670
   324
walther@59691
   325
  (*case*) scan_dn1 xxx (ist |> path_down [R]) e (*of*);
walther@59686
   326
    (*======= end of scanning tacticals, a leaf =======*)
walther@59709
   327
"~~~~~ fun scan_dn1 , args:"; val (((pt, p), ctxt, tac), (ist as {eval, act_arg, or, ...}), t)
walther@59686
   328
  = (xxx, (ist |> path_down [R]), e);
walther@59772
   329
    val (Program.Tac stac, a') = (*case*) check_leaf "locate" ctxt eval (get_subst ist) t (*of*);
walther@59686
   330
      val NotAss = (*case*) associate pt ctxt (tac, stac) (*of*);
walther@59718
   331
      val ORundef = (*case*) or (*of*);
walther@59686
   332
  val Notappl "norm_equation not applicable" =    
walther@59790
   333
      (*case*) Applicable.applicable_in p pt (LItool.stac2tac pt (Celem.assoc_thy "Isac_Knowledge") stac) (*of*);
walther@59670
   334
walther@59712
   335
   (Term_Val1 act_arg) (* return value *);
walther@59670
   336
walther@59670
   337
val Rewrite' ("PolyMinus", "tless_true", _, _, ("tausche_minus",_ (*"?b ist_monom \<Longrightarrow> ?a kleiner ?b \<Longrightarrow> ?b - ?a = - ?a + ?b"*)),
walther@59670
   338
   t, (res, asm)) = m;
walther@59686
   339
walther@59777
   340
if pstate2str ist =
walther@59781
   341
  "([\"\n(t_t, 5 * e + 6 * f - 8 * g - 9 - 7 * e - 4 * f + 10 * g + 12)\"], [R,L,R,R,L,R,R], e_rls, SOME t_t, \n" ^
walther@59787
   342
  "- (8 * g) + (- 9 + 12 + 5 * e - 7 * e + (6 - 4) * f) + 10 * g, ORundef, true, false)"
walther@59670
   343
andalso
walther@59670
   344
  term2str t = "- (8 * g) + (- 9 + 12 + 5 * e - 7 * e + (6 - 4) * f) + 10 * g"
walther@59670
   345
andalso
walther@59670
   346
  term2str res = "- (8 * g) + (- 9 + 12 + 5 * e - 7 * e + (- 4 + 6) * f) + 10 * g"
walther@59670
   347
andalso
walther@59670
   348
  terms2str asm = "[\"4 kleiner 6\",\"6 ist_monom\"]"
walther@59670
   349
then () else error "locate_input_tactic Helpless, but applicable CHANGED";
wneuper@59562
   350
walther@59680
   351
walther@59792
   352
"----------- re-build: fun find_next_step, mini ------------------------------------------------";
walther@59792
   353
"----------- re-build: fun find_next_step, mini ------------------------------------------------";
walther@59792
   354
"----------- re-build: fun find_next_step, mini ------------------------------------------------";
walther@59792
   355
val fmz = ["Term (a + a ::real)", "normalform n_n"];
walther@59792
   356
val (dI',pI',mI') = ("Poly",["polynomial","simplification"],["simplification","for_polynomials"]);
walther@59734
   357
val (p,_,f,nxt,_,pt) = CalcTreeTEST [(fmz, (dI',pI',mI'))];
walther@59765
   358
(*[], Pbl*)val (_, ([(tac, _, _)], _, (pt, p))) = Step.do_next p ((pt, Pos.e_pos'), []);(*Model_Problem*)
walther@59792
   359
(*[], Pbl*)val (_, ([(tac, _, _)], _, (pt, p))) = Step.do_next p ((pt, Pos.e_pos'), []);(*Specify_Theory "Poly"*)
walther@59792
   360
(*[], Pbl*)val (_, ([(tac, _, _)], _, (pt, p))) = Step.do_next p ((pt, Pos.e_pos'), []);(*Specify_Problem ["polynomial", "simplification"]*)
walther@59792
   361
(*[], Met*)val (_, ([(tac, _, _)], _, (pt, p))) = Step.do_next p ((pt, e_pos'), []);(*Specify_Method  ["simplification", "for_polynomials"]*)
walther@59792
   362
(*1], Frm*)val (_, ([(tac, _, _)], _, (pt, p))) = Step.do_next p ((pt, e_pos'), []);(*Apply_Method ["simplification", "for_polynomials"]*)
walther@59792
   363
(*[1], Res*)val (_, ([(tac'''''_', _, _)], _, (pt'''''_', p'''''_'))) =
walther@59734
   364
walther@59792
   365
      Step.do_next p ((pt, e_pos'), []);(*Rewrite_Set "norm_Poly"*)
walther@59792
   366
(*//------------------ go into 1 ------------------------------------------------------------\\*)
walther@59792
   367
"~~~~~ fun do_next , args:"; val ((ip as (_, p_)), (ptp as (pt, p), tacis))
walther@59792
   368
  = (p, ((pt, e_pos'), []));
walther@59792
   369
  val pIopt = Ctree.get_pblID (pt, ip);
walther@59792
   370
    (*if*)  ip = ([], Res) (*else*);
walther@59792
   371
      val _ = (*case*) tacis (*of*);
walther@59792
   372
      val SOME _ = (*case*) pIopt (*of*);
walther@59792
   373
      (*if*) member op = [Pos.Pbl, Pos.Met] p_ 
walther@59734
   374
  	                    andalso is_none (Ctree.get_obj Ctree.g_env pt (fst p)) (*else*);
walther@59734
   375
walther@59792
   376
val ("ok", ([(Rewrite_Set "norm_Poly", _, _)], _, (_, ([1], Res)))) =
walther@59792
   377
Step_Solve.do_next (pt, ip);
walther@59792
   378
"~~~~~ and do_next , args:"; val (ptp as (pt, pos as (p, p_))) =  (pt, ip);
walther@59734
   379
    (*if*) Celem.e_metID = get_obj g_metID pt (par_pblobj pt p) (*else*);
walther@59734
   380
        val thy' = get_obj g_domID pt (par_pblobj pt p);
walther@59790
   381
	      val (_, (ist, ctxt), sc) = LItool.from_pblobj_or_detail' thy' (p,p_) pt;
walther@59734
   382
walther@59792
   383
val Next_Step (_, _, Rewrite_Set' ("Poly", _, Seq {id = "norm_Poly", ...}, _, _)) =
walther@59792
   384
           LI.find_next_step sc (pt, pos) ist ctxt (*of*);
walther@59792
   385
"~~~~~ fun find_next_step , args:"; val ((Rule.Prog prog), (ptp as(pt, (p, _))), (Pstate ist), ctxt)
walther@59734
   386
  = (sc, (pt, pos), ist, ctxt);
walther@59734
   387
walther@59792
   388
val Accept_Tac (Rewrite_Set' ("Poly", _, Seq {id = "norm_Poly", ...}, _, _), _, _) =
walther@59792
   389
  (*case*) scan_to_tactic (prog, (ptp, ctxt)) (Pstate ist) (*of*);
walther@59792
   390
"~~~~~ fun scan_to_tactic , args:"; val ((prog, cc), (Pstate (ist as {path, ...})))
walther@59792
   391
  = ((prog, (ptp, ctxt)), (Pstate ist));
walther@59792
   392
  (*if*) path = [] (*then*);
walther@59734
   393
walther@59792
   394
val Accept_Tac (Rewrite_Set' ("Poly", _, Seq {id = "norm_Poly", ...}, _, _), _, _) =
walther@59792
   395
            scan_dn cc (trans_scan_dn ist) (Program.body_of prog);
walther@59792
   396
"~~~~~ fun scan_dn , args:"; val ((cc as (_, ctxt)), (ist as {eval, ...}), t)
walther@59792
   397
  = (cc, (trans_scan_dn ist), (Program.body_of prog));
walther@59792
   398
    (*if*) Tactical.contained_in t (*else*);
walther@59792
   399
      val (Program.Tac prog_tac, form_arg) = (*case*) LItool.check_leaf "next  " ctxt eval (get_subst ist) t (*of*);
walther@59734
   400
walther@59792
   401
val Accept_Tac (Rewrite_Set' ("Poly", _, Seq {id = "norm_Poly", ...}, _, _), _, _) =
walther@59792
   402
          check_tac cc ist (form_arg, prog_tac)  (*return from xxx*);
walther@59792
   403
"~~~~~ from fun scan_dn\<longrightarrow>fun scan_to_tactic\<longrightarrow>fun find_next_step, return:"; val (Accept_Tac (tac, ist, ctxt))
walther@59792
   404
  = (check_tac cc ist (form_arg, prog_tac));
walther@59734
   405
walther@59792
   406
    Next_Step (Pstate ist, Tactic.insert_assumptions tac ctxt, tac)  (*return from find_next_step*);
walther@59792
   407
"~~~~~ from fun find_next_step\<longrightarrow>and do_next\<longrightarrow>fun zzz, return:"; val (Next_Step (ist, ctxt, tac))
walther@59792
   408
  = (Next_Step (Pstate ist, Tactic.insert_assumptions tac ctxt, tac));
walther@59734
   409
walther@59792
   410
           LI.by_tactic tac (ist, Tactic.insert_assumptions tac ctxt) ptp  (*return from and do_next*);
walther@59792
   411
"~~~~~ from and do_next\<longrightarrow>fun do_next\<longrightarrow>toplevel, return:"; val  (_, ([(tac''''', _, _)], _, (pt''''', p''''')))
walther@59793
   412
  = (LI.by_tactic tac (ist, Tactic.insert_assumptions tac ctxt) ptp);
walther@59792
   413
(*\\------------------ end of go into 1 -----------------------------------------------------//*)
walther@59734
   414
walther@59792
   415
(*[], Res*)val (_, ([(tac''''', _, _)], _, (pt''''', p'''''))) =
walther@59792
   416
walther@59792
   417
      Step.do_next p'''''_' ((pt'''''_', Pos.e_pos'), []);(* Check_Postcond ["polynomial", "simplification"]*)
walther@59792
   418
(*//------------------ go into 2 ------------------------------------------------------------\\*)
walther@59792
   419
"~~~~~ fun do_next , args:"; val ((ip as (_, p_)), (ptp as (pt, p), tacis))
walther@59792
   420
  = (p''''', ((pt''''', e_pos'), []));
walther@59792
   421
  val pIopt = Ctree.get_pblID (pt, ip);
walther@59792
   422
    (*if*)  ip = ([], Res) (*else*);
walther@59792
   423
      val _ = (*case*) tacis (*of*);
walther@59792
   424
      val SOME _ = (*case*) pIopt (*of*);
walther@59792
   425
      (*if*) member op = [Pos.Pbl, Pos.Met] p_ 
walther@59792
   426
  	                    andalso is_none (Ctree.get_obj Ctree.g_env pt (fst p)) (*else*);
walther@59792
   427
walther@59792
   428
val ("ok", ([(Check_Postcond ["polynomial", "simplification"], _, _)], _, (_, ([], Res)))) =
walther@59792
   429
Step_Solve.do_next (pt, ip);
walther@59792
   430
"~~~~~ and do_next , args:"; val (ptp as (pt, pos as (p, p_))) =  (pt, ip);
walther@59792
   431
    (*if*) Celem.e_metID = get_obj g_metID pt (par_pblobj pt p) (*else*);
walther@59792
   432
        val thy' = get_obj g_domID pt (par_pblobj pt p);
walther@59792
   433
	      val (_, (ist, ctxt), sc) = LItool.from_pblobj_or_detail' thy' (p,p_) pt;
walther@59792
   434
walther@59792
   435
  (** )val End_Program (ist, tac) = 
walther@59793
   436
 ( *case*) LI.find_next_step sc (pt, pos) ist ctxt (*of*);
walther@59792
   437
"~~~~~ fun find_next_step , args:"; val ((Rule.Prog prog), (ptp as(pt, (p, _))), (Pstate ist), ctxt)
walther@59792
   438
  = (sc, (pt, pos), ist, ctxt);
walther@59792
   439
walther@59792
   440
(*  val Term_Val (Const ("Groups.times_class.times", _) $ Free ("2", _) $ Free ("a", _))*)
walther@59792
   441
  (** )val Term_Val prog_result =
walther@59792
   442
 ( *case*) scan_to_tactic (prog, (ptp, ctxt)) (Pstate ist) (*of*);
walther@59792
   443
"~~~~~ fun scan_to_tactic , args:"; val ((prog, cc), (Pstate (ist as {path, ...})))
walther@59792
   444
  = ((prog, (ptp, ctxt)), (Pstate ist));
walther@59792
   445
  (*if*) path = [] (*else*);
walther@59792
   446
walther@59792
   447
           go_scan_up (prog, cc) (trans_scan_up ist |> set_found);
walther@59792
   448
"~~~~~ fun go_scan_up , args:"; val ((pcc as (sc, _)), (ist as {path, act_arg, found_accept, ...}))
walther@59792
   449
  = ((prog, cc), (trans_scan_up ist(*|> set_found !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! *)));
walther@59792
   450
    (*if*) path = [R] (*then*);
walther@59792
   451
      (*if*) found_accept = true (*then*);
walther@59792
   452
walther@59792
   453
      Term_Val act_arg (*return from go_scan_up*);
walther@59792
   454
"~~~~~ from fun go_scan_up\<longrightarrow>fun scan_to_tactic, return:"; val (Term_Val prog_result) = (Term_Val act_arg);
walther@59792
   455
walther@59792
   456
    Term_Val prog_result  (*return from scan_to_tactic*);
walther@59792
   457
"~~~~~ from fun scan_to_tactic\<longrightarrow>fun find_next_step, return:"; val (Term_Val prog_result) = (Term_Val prog_result);
walther@59792
   458
    val (true, p', _) = (*case*) par_pbl_det pt p (*of*);
walther@59792
   459
              val (_, pblID, _) = get_obj g_spec pt p';
walther@59792
   460
walther@59792
   461
     End_Program (Pstate ist, Tactic.Check_Postcond' (pblID, (prog_result, [])))
walther@59792
   462
     (*return from find_next_step*);
walther@59792
   463
"~~~~~ from fun find_next_step\<longrightarrow>and do_next\<longrightarrow>fun zzz, return:"; val (End_Program (ist, tac))
walther@59792
   464
  = (End_Program (Pstate ist, Tactic.Check_Postcond' (pblID, (prog_result, []))));
walther@59792
   465
      val _ = (*case*) tac (*of*);
walther@59792
   466
walther@59792
   467
val ("ok", ([(Check_Postcond ["polynomial", "simplification"], _, _)], _, (_, ([], Res))))
walther@59793
   468
   = LI.by_tactic tac (ist, ctxt) ptp (*return from and do_next*);
walther@59792
   469
"~~~~~ from and do_next\<longrightarrow>top level, return:"; val (_, ([(tac''''', _, _)], _, (pt''''', p''''')))
walther@59793
   470
  = (LI.by_tactic tac (ist, ctxt) ptp);
walther@59792
   471
(*\\------------------ end of go into 2 -----------------------------------------------------//*)
walther@59792
   472
walther@59792
   473
(*[], Und*)val (msg, ([], _, (pt, p))) = Step.do_next p''''' ((pt''''', Pos.e_pos'), []);(**)
walther@59792
   474
walther@59792
   475
show_pt_tac pt; (*[
walther@59792
   476
([], Frm), Simplify (a + a)
walther@59792
   477
. . . . . . . . . . Apply_Method ["simplification","for_polynomials"],
walther@59792
   478
([1], Frm), a + a
walther@59792
   479
. . . . . . . . . . Rewrite_Set "norm_Poly",
walther@59792
   480
([1], Res), 2 * a
walther@59792
   481
. . . . . . . . . . Check_Postcond ["polynomial","simplification"],
walther@59792
   482
([], Res), 2 * a]*)
walther@59792
   483
walther@59792
   484
(*/--- final test ---------------------------------------------------------------------------\\*)
walther@59734
   485
val (res, asm) = (get_obj g_result pt (fst p));
walther@59792
   486
if term2str res = "2 * a" andalso terms2str asm = "[\"a + a is_polyexp\"]"
walther@59792
   487
andalso p = ([], Und) andalso msg = "end-of-calculation"
walther@59792
   488
andalso pr_ctree pr_short pt = ".    ----- pblobj -----\n1.   a + a\n"
walther@59792
   489
then 
walther@59792
   490
  case tac''''' of Check_Postcond ["polynomial", "simplification"] => () 
walther@59792
   491
  | _ => error "re-build: fun find_next_step, mini 1"
walther@59792
   492
else error "re-build: fun find_next_step, mini 2"
wneuper@59575
   493
wneuper@59575
   494
walther@59783
   495
"----------- re-build: fun locate_input_term ---------------------------------------------------";
walther@59783
   496
"----------- re-build: fun locate_input_term ---------------------------------------------------";
walther@59783
   497
"----------- re-build: fun locate_input_term ---------------------------------------------------";
walther@59795
   498
(*cp from inform.sml
walther@59795
   499
 ----------- appendFormula: on Res + late deriv ------------------------------------------------*)
walther@59795
   500
val fmz = ["equality (x+1=(2::real))", "solveFor x","solutions L"];
walther@59795
   501
val (dI',pI',mI') = ("Test", ["sqroot-test","univariate","equation","test"],
walther@59795
   502
   ["Test","squ-equ-test-subpbl1"]);
walther@59795
   503
val (p,_,f,nxt,_,pt) = CalcTreeTEST [(fmz, (dI',pI',mI'))];
walther@59795
   504
val (p,_,f,nxt,_,pt) = me nxt p [] pt;
walther@59795
   505
val (p,_,f,nxt,_,pt) = me nxt p [] pt;
walther@59795
   506
val (p,_,f,nxt,_,pt) = me nxt p [] pt;
walther@59795
   507
val (p,_,f,nxt,_,pt) = me nxt p [] pt;
walther@59795
   508
val (p,_,f,nxt,_,pt) = me nxt p [] pt;
walther@59795
   509
val (p,_,f,nxt,_,pt) = me nxt p [] pt;
walther@59795
   510
(*[], Met*)val (p,_,f,nxt,_,pt) = me nxt p [] pt; (*Apply_Method ["Test", "squ-equ-test-subpbl1"]*);
walther@59783
   511
walther@59795
   512
(*[1], Frm*)val (p,_,f,nxt,_,pt) = me nxt p [] pt;(*Rewrite_Set "norm_equation"*)
walther@59795
   513
(*+*)if f2str f = "x + 1 = 2" then () else error "locate_input_term at ([1], Frm) CHANGED";
walther@59783
   514
walther@59795
   515
(*[1], Res*)val (p,_,f,nxt,_,pt) = me nxt p [] pt;(*Rewrite_Set "Test_simplify"*)
walther@59795
   516
(*+*)if f2str f = "x + 1 + -1 * 2 = 0" then () else error "locate_input_term at ([1], Frm) CHANGED";
walther@59783
   517
walther@59795
   518
show_pt_tac pt; (*[
walther@59795
   519
([], Frm), solve (x + 1 = 2, x)
walther@59795
   520
. . . . . . . . . . Apply_Method ["Test","squ-equ-test-subpbl1"],
walther@59795
   521
([1], Frm), x + 1 = 2
walther@59795
   522
. . . . . . . . . . Rewrite_Set "norm_equation",
walther@59795
   523
([1], Res), x + 1 + -1 * 2 = 0             ///Check_Postcond..ERROR*)
walther@59795
   524
walther@59797
   525
(*//---------- appendFormula 1 "x = 1" \<longrightarrow> Step_Solve.inform \<longrightarrow> LI.locate_input_term ----------\\*)
walther@59795
   526
"~~~~~ fun appendFormula , args:"; val ((*cI, *) ifo: Rule.cterm') = ((**) "x = 1");
walther@59795
   527
    val cs = (*get_calc cI*) ((pt, p), [(*nxt, nxt_, (pos, (ist, ctxt))*)])
walther@59795
   528
    val pos = (*get_pos cI 1*) p
walther@59795
   529
walther@59795
   530
(*+*)val ptp''''' = (pt, p);
walther@59795
   531
(*+*)if snd ptp''''' = ([1], Res) then () else error "old_cs changed";
walther@59795
   532
(*+*)show_pt_tac pt; (*[
walther@59795
   533
(*+*)([], Frm), solve (x + 1 = 2, x)
walther@59795
   534
(*+*). . . . . . . . . . Apply_Method ["Test","squ-equ-test-subpbl1"],
walther@59795
   535
(*+*)([1], Frm), x + 1 = 2
walther@59795
   536
(*+*). . . . . . . . . . Rewrite_Set "norm_equation",
walther@59795
   537
(*+*)([1], Res), x + 1 + -1 * 2 = 0      ///Check_Postcond*)
walther@59795
   538
walther@59795
   539
  val ("ok", cs') =
walther@59795
   540
    (*case*) Step.do_next pos cs (*of*);
walther@59795
   541
walther@59795
   542
val ("ok", (_(*use in DG !!!*), [], ptp''''' as (pt''''', p'''''))) = (*case*)
walther@59797
   543
     Step_Solve.by_term cs' (encode ifo) (*of*);
walther@59797
   544
"~~~~~ fun Step_Solve.by_term , args:"; val ((next_cs as (_, _, (pt, pos as (p, _))): Chead.calcstate'), istr)
walther@59795
   545
  = (cs', (encode ifo));
walther@59795
   546
  val SOME f_in =
walther@59795
   547
    (*case*) TermC.parse (Celem.assoc_thy "Isac_Knowledge") istr (*of*);
walther@59795
   548
  	  val f_in = Thm.term_of f_in
walther@59795
   549
      val pos_pred = lev_back(*'*) pos
walther@59795
   550
  	  val f_pred = Ctree.get_curr_formula (pt, pos_pred);
walther@59795
   551
  	  val f_succ = Ctree.get_curr_formula (pt, pos);
walther@59795
   552
      (*if*) f_succ = f_in (*else*);
walther@59795
   553
  val NONE =
walther@59795
   554
        (*case*) Inform.cas_input f_in (*of*);
walther@59795
   555
walther@59795
   556
(*old* )     val (_, _, metID) = get_obj g_spec pt (par_pblobj pt p)
walther@59795
   557
(*old*)     val {scr = prog, ...} = Specify.get_met metID
walther@59795
   558
(*old*)     val istate = get_istate pt pos
walther@59795
   559
(*old*)     val ctxt = get_ctxt pt pos
walther@59795
   560
  val LI.Found_Step (cstate'''''_', _(*istate*), _(*ctxt*)) = (*case*)
walther@59795
   561
        LI.locate_input_term prog (pt, pos) istate ctxt f_in (*of*);
walther@59795
   562
"~~~~~ fun locate_input_term , args:"; val ((Rule.Prog _),  ((pt, pos) : Calc.T), (_ : Istate.T), (_ : Proof.context), tm)
walther@59795
   563
  = (prog, (pt, pos), istate, ctxt, f_in);
walther@59795
   564
( *old*)
walther@59795
   565
walther@59795
   566
(*NEW*) LI.locate_input_term (pt, pos) f_in (*of*);
walther@59795
   567
"~~~~~ fun locate_input_term , args:"; val ((pt, pos), tm) = ((pt, pos), f_in);
walther@59795
   568
   		val pos_pred = Pos.lev_back' pos (*f_pred ---"step pos cs"---> f_succ in appendFormula*)
walther@59795
   569
walther@59795
   570
  val ("ok", (_, _, cstate as (pt', pos'))) =
walther@59795
   571
   		(*case*) compare_step ([], [], (pt, pos_pred)) tm (*of*);
walther@59795
   572
walther@59795
   573
(*old* )
walther@59795
   574
    Found_Step (cstate, get_istate pt' pos', get_ctxt pt' pos')  (*return from locate_input_term*);
walther@59795
   575
( *old*)
walther@59795
   576
(*NEW*)     Found_Step cstate (*return from locate_input_term*);
walther@59795
   577
       (*LI.Found_Step ( *)cstate(*, _(*istate*), _(*ctxt*))( *return from locate_input_term*);
walther@59797
   578
"~~~~~ from fun locate_input_term\<longrightarrow>fun Step_Solve.by_term, return:"; val ("ok", (_(*use in DG !!!*), c, ptp as (_, p)))
walther@59795
   579
  = (("ok" , ([], [], cstate (* already contains istate, ctxt *))));
walther@59795
   580
walther@59797
   581
    ("ok", ((*_ use in DG !!!,*) c, ptp(* as (_*), p))(*)*)(*return from Step_Solve.by_term*);
walther@59797
   582
"~~~~~ from fun Step_Solve.by_term\<longrightarrow>(fun appendFormula)!toplevel, return:"; val ("ok", (_(*use in DG !!!*), [], ptp''''' as (pt''''', p''''')))
walther@59795
   583
  = ("ok", ([], [], ptp));
walther@59795
   584
walther@59795
   585
(*fun me requires nxt...*)
walther@59795
   586
    Step.do_next p''''' (ptp''''', []);
walther@59795
   587
  val ("ok", ([(nxt'''''_' as Check_Postcond ["LINEAR", "univariate", "equation", "test"], _, _)], _,
walther@59795
   588
    (pt'''''_', p'''''_'))) = Step.do_next p''''' (ptp''''', [])
walther@59797
   589
(*\\---------- appendFormula 1 "x = 1" \<longrightarrow> Step_Solve.inform \<longrightarrow> LI.locate_input_term ----------//*)
walther@59795
   590
walther@59797
   591
(*//----- REPLACED BY appendFormula 1 "x = 1" \<longrightarrow> Step_Solve.inform \<longrightarrow> LI.locate_input_term -----\\* )
walther@59795
   592
 (*[2], Res*)val (p,_,f,nxt,_,pt) = me nxt p [] pt; (*nxt = Subproblem ("Test", ["LINEAR", "univariate", "equation", "test"])*)
walther@59795
   593
 (*[3], Pbl*)val (p,_,f,nxt,_,pt) = me nxt p [] pt; (*nxt = Model_Problem*)
walther@59795
   594
 (*[3], Pbl*)val (p,_,f,nxt,_,pt) = me nxt p [] pt; (*nxt = Add_Given "equality (-1 + x = 0)"*)
walther@59795
   595
 (*[3], Pbl*)val (p,_,f,nxt,_,pt) = me nxt p [] pt; (*nxt = Add_Given "solveFor x"*)
walther@59795
   596
 (*[3], Pbl*)val (p,_,f,nxt,_,pt) = me nxt p [] pt; (*nxt = Add_Find "solutions x_i"*)
walther@59795
   597
 (*[3], Pbl*)val (p,_,f,nxt,_,pt) = me nxt p [] pt; (*nxt = Specify_Theory "Test"*)
walther@59795
   598
 (*[3], Pbl*)val (p,_,f,nxt,_,pt) = me nxt p [] pt; (*nxt = Specify_Problem ["LINEAR", "univariate", "equation", "test"]*)
walther@59795
   599
 (*[3], Pbl*)val (p,_,f,nxt,_,pt) = me nxt p [] pt; (*nxt = Specify_Method ["Test", "solve_linear"]*)
walther@59795
   600
 (*[3], Met*)val (p,_,f,nxt,_,pt) = me nxt p [] pt; (*nxt = Apply_Method ["Test", "solve_linear"]*)
walther@59795
   601
 (*[3, 1], Frm*)val (p,_,f,nxt,_,pt) = me nxt p [] pt; (*nxt = Rewrite_Set_Inst (["(''bdv'', x)"], "isolate_bdv")*)
walther@59795
   602
 (*[3, 1], Res*)val (p,_,f,nxt,_,pt) = me nxt p [] pt; (*nxt = Rewrite_Set "Test_simplify"*)
walther@59795
   603
 (*[3, 2], Res*)val (p,_,f,nxt,_,pt) = me nxt p [] pt; (*nxt = Check_Postcond ["LINEAR", "univariate", "equation", "test"]*)
walther@59797
   604
( *\\----- REPLACED BY appendFormula 1 "x = 1" \<longrightarrow> Step_Solve.inform \<longrightarrow> LI.locate_input_term -----//*)
walther@59795
   605
walther@59795
   606
 (*[3], Res*)val (p,_,f,nxt,_,pt) = me nxt'''''_' p'''''_' [] pt'''''_'; (*nxt = Check_elementwise "Assumptions"*)
walther@59795
   607
 (*[4], Res*)val (p,_,f,nxt,_,pt) = me nxt p [] pt; (*nxt = Check_Postcond ["sqroot-test", "univariate", "equation", "test"]*)
walther@59795
   608
 (*[], Res*)val (p,_,f,nxt,_,pt) = me nxt p [] pt; (*nxt = End_Proof'*)
walther@59795
   609
walther@59795
   610
(*/--- final test ---------------------------------------------------------------------------\\*)
walther@59795
   611
if p = ([], Res) andalso f2str f = "[x = 1]" andalso pr_ctree pr_short pt =
walther@59795
   612
   ".    ----- pblobj -----\n" ^
walther@59795
   613
   "1.   x + 1 = 2\n" ^
walther@59795
   614
   "2.   x + 1 + -1 * 2 = 0\n" ^
walther@59795
   615
   "3.    ----- pblobj -----\n" ^
walther@59795
   616
   "3.1.   -1 + x = 0\n" ^
walther@59795
   617
   "3.2.   x = 0 + -1 * -1\n" ^
walther@59795
   618
   "3.2.1.   x = 0 + -1 * -1\n" ^
walther@59795
   619
   "3.2.2.   x = 0 + 1\n" (*ATTENTION: see complete Calc below*)
walther@59795
   620
then case nxt of End_Proof' => () | _ => error "re-build: fun locate_input_term CHANGED 1"
walther@59795
   621
else error "re-build: fun locate_input_term CHANGED 2";
walther@59795
   622
walther@59795
   623
show_pt_tac pt; (*[
walther@59795
   624
([], Frm), solve (x + 1 = 2, x)
walther@59795
   625
. . . . . . . . . . Apply_Method ["Test","squ-equ-test-subpbl1"],
walther@59795
   626
([1], Frm), x + 1 = 2
walther@59795
   627
. . . . . . . . . . Rewrite_Set "norm_equation",
walther@59795
   628
([1], Res), x + 1 + -1 * 2 = 0
walther@59795
   629
. . . . . . . . . . Rewrite_Set "Test_simplify",
walther@59795
   630
([2], Res), -1 + x = 0
walther@59795
   631
. . . . . . . . . . Subproblem (Test, ["LINEAR","univariate","equation","test"]),
walther@59795
   632
([3], Pbl), solve (-1 + x = 0, x)
walther@59795
   633
. . . . . . . . . . Apply_Method ["Test","solve_linear"],
walther@59795
   634
([3,1], Frm), -1 + x = 0
walther@59795
   635
. . . . . . . . . . Rewrite_Set_Inst ([(''bdv'', x)], "isolate_bdv"),
walther@59795
   636
([3,1], Res), x = 0 + -1 * -1
walther@59795
   637
. . . . . . . . . . Derive Test_simplify,
walther@59795
   638
([3,2,1], Frm), x = 0 + -1 * -1
walther@59795
   639
. . . . . . . . . . Rewrite ("#: -1 * -1 = 1", "-1 * -1 = 1"),
walther@59795
   640
([3,2,1], Res), x = 0 + 1
walther@59795
   641
. . . . . . . . . . Rewrite ("radd_0", "0 + ?k = ?k"),
walther@59795
   642
([3,2,2], Res), x = 1
walther@59795
   643
. . . . . . . . . . tac2str not impl. for ?!,
walther@59795
   644
([3,2], Res), x = 1
walther@59795
   645
. . . . . . . . . . Check_Postcond ["LINEAR","univariate","equation","test"],
walther@59795
   646
([3], Res), [x = 1]
walther@59795
   647
. . . . . . . . . . Check_Postcond ["sqroot-test","univariate","equation","test"],
walther@59795
   648
([], Res), [x = 1]]*)