test/Tools/isac/Interpret/lucas-interpreter.sml
author Walther Neuper <walther.neuper@jku.at>
Thu, 09 Apr 2020 17:13:17 +0200
changeset 59861 65ec9f679c3f
parent 59852 ea7e6679080e
child 59863 0dcc8f801578
permissions -rw-r--r--
separate struct. UnparseC, shift code to ThmC
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@59781
    12
"----------- re-build: fun find_next_step, mini ------------------------------------------------";
walther@59783
    13
"----------- re-build: fun locate_input_term ---------------------------------------------------";
wneuper@59561
    14
"-----------------------------------------------------------------------------------------------";
wneuper@59561
    15
"-----------------------------------------------------------------------------------------------";
wneuper@59561
    16
"-----------------------------------------------------------------------------------------------";
wneuper@59561
    17
wneuper@59561
    18
"----------- Take as 1st stac in program -------------------------------------------------------";
wneuper@59561
    19
"----------- Take as 1st stac in program -------------------------------------------------------";
wneuper@59561
    20
"----------- Take as 1st stac in program -------------------------------------------------------";
walther@59834
    21
"compare --- Apply_Method with initial Take by Step.do_next --- in test/../step-solve ----------";
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);
walther@59804
    39
"~~~~~ fun Step.by_tactic, 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@59852
    56
(*+*)pstate2str (the_pstate is) = "([\"\n(f_f, x ^^^ 2 + 1)\",\"\n(v_v, x)\"], [], empty, NONE, \n??.empty, ORundef, false, true)";
walther@59848
    57
      val ini = LItool.implicit_take 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@59852
    63
(*+*)pstate2str (the_pstate is') = "([\"\n(f_f, x ^^^ 2 + 1)\",\"\n(v_v, x)\"], [R,L,R], empty, 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@59861
    79
(*+*) if UnparseC.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@59806
    89
walther@59670
    90
"----------- re-build: fun locate_input_tactic -------------------------------------------------";
walther@59670
    91
"----------- re-build: fun locate_input_tactic -------------------------------------------------";
walther@59670
    92
"----------- re-build: fun locate_input_tactic -------------------------------------------------";
wneuper@59562
    93
val fmz = ["equality (x+1=(2::real))", "solveFor x","solutions L"];
walther@59670
    94
val (dI',pI',mI') = ("Test", ["sqroot-test","univariate","equation","test"],
wneuper@59562
    95
   ["Test","squ-equ-test-subpbl1"]);
wneuper@59562
    96
val (p,_,f,nxt,_,pt) = CalcTreeTEST [(fmz, (dI',pI',mI'))];
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;
wneuper@59562
   102
val (p,_,f,nxt,_,pt) = me nxt p [] pt;
walther@59670
   103
(*[], Met*)val (p,_,f,nxt,_,pt) = me nxt p [] pt; (*nxt = (_, Apply_Method ["Test", "squ-equ-test-subpbl1"])*);
walther@59670
   104
(*[1], Frm*)val (p,_,f,nxt,_,pt) = me nxt p [] pt; (*nxt = ("Rewrite_Set", Rewrite_Set "norm_equation")*)
wneuper@59562
   105
walther@59781
   106
(*//------------------ begin step into ------------------------------------------------------\\*)
walther@59686
   107
(*[1], Res*)val (p'''''_''',_,f,nxt'''''_''',_,pt'''''_''') = me nxt p [] pt; (*nxt = Rewrite_Set "Test_simplify"*)
wneuper@59562
   108
walther@59749
   109
"~~~~~ fun me , args:"; val (tac, p, _(*NEW remove*), pt) = (nxt, p, [], pt);
wneuper@59562
   110
walther@59806
   111
    (** )val (***)xxxx(***) ( *("ok", (_, _, (pt, p))) =( **)  (*case*)
walther@59806
   112
      Step.by_tactic tac (pt,p) (*of*);
walther@59806
   113
"~~~~~ fun by_tactic , args:"; val (tac, (ptp as (pt, p))) = (tac, (pt,p));
walther@59755
   114
      val Applicable.Appl m = (*case*) Applicable.applicable_in p pt tac (*of*);
walther@59755
   115
      (*if*) Tactic.for_specify' m; (*false*)
walther@59670
   116
walther@59806
   117
    (** )val (***)xxxxx_x(***) ( *(msg, cs') =( **)
walther@59806
   118
Step_Solve.by_tactic m ptp;
walther@59806
   119
"~~~~~ fun by_tactic , args:"; val (m, (pt, po as (p, p_))) = (m, ptp);
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@59831
   123
	      val (is, sc) = LItool.resume_prog 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@59844
   155
    val LItool.Associated (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@59811
   172
                    Generate.generate1 tac (istate, ctxt) (pt, (lev_on p, Pbl));
walther@59686
   173
            (*in*)
walther@59670
   174
walther@59704
   175
         	  	    ("ok", ([(Tactic.input_from_T tac, tac, (p'', (istate, ctxt)))],
walther@59686
   176
                    [(*ctree NOT cut*)], (pt', p'')))  (*return value*);
walther@59806
   177
"~~~~~ from Step_Solve.by_tactic \<longrightarrow> Step.by_tactic return:"; val ((msg, cs' : calcstate'))
walther@59806
   178
  =               ("ok", ([(Tactic.input_from_T tac, tac, (p'', (istate, ctxt)) )],
walther@59806
   179
                    [(*ctree NOT cut*)], (pt', p'')));
walther@59670
   180
walther@59804
   181
"~~~~~ from Step.by_tactic to me return:"; val (("ok", (_, _, (pt, p)))) = (*** )xxxx( ***) ("ok", cs');
wneuper@59562
   182
	  val (_, ts) =
walther@59765
   183
	    (case Step.do_next p ((pt, Pos.e_pos'), []) of
wneuper@59562
   184
		    ("ok", (ts as (_, _, _) :: _, _, _)) => ("", ts)
wneuper@59562
   185
	    | ("helpless", _) => ("helpless: cannot propose tac", [])
wneuper@59562
   186
	    | ("no-fmz-spec", _) => error "no-fmz-spec"
wneuper@59562
   187
	    | ("end-of-calculation", (ts, _, _)) => ("", ts)
wneuper@59562
   188
	    | _ => error "me: uncovered case")
wneuper@59562
   189
	      handle ERROR msg => raise ERROR msg
wneuper@59562
   190
	  val tac = 
wneuper@59562
   191
      case ts of 
wneuper@59562
   192
        tacis as (_::_) => let val (tac, _, _) = last_elem tacis in tac end 
walther@59694
   193
		  | _ => if p = ([], Pos.Res) then Tactic.End_Proof' else Tactic.Empty_Tac;
wneuper@59562
   194
walther@59675
   195
   (p, [] : NEW, TESTg_form (pt, p), (Tactic.tac2IDstr tac, tac), Telem.Sundef, pt);
walther@59670
   196
"~~~~~ from me to TOOPLEVEL return:"; val (p,_,f,nxt,_,pt)
walther@59675
   197
   = (*** )xxx( ***) (p, [] : NEW, TESTg_form (pt, p), (Tactic.tac2IDstr tac, tac), Telem.Sundef, pt);
walther@59670
   198
walther@59670
   199
(*//--------------------- check results from modified me ----------------------------------\\*)
walther@59686
   200
if p = ([2], Res) andalso
walther@59686
   201
  pr_ctree pr_short pt = ".    ----- pblobj -----\n1.   x + 1 = 2\n2.   x + 1 = 2\n"
walther@59670
   202
then
walther@59670
   203
  (case nxt of ("Rewrite_Set", Rewrite_Set "Test_simplify") => ()
walther@59670
   204
   | _ => error "")
walther@59670
   205
else error "check results from modified me CHANGED";
walther@59670
   206
(*\\--------------------- check results from modified me ----------------------------------//*)
walther@59670
   207
walther@59670
   208
"~~~~~ from me to TOPLEVEL return:"; val (p,_,f,nxt,_,pt) = (*** )xxx( ***) (**)(p, 000, f, nxt, 000, pt)(**);
walther@59781
   209
(*\\------------------ end step into --------------------------------------------------------//*)
walther@59686
   210
walther@59686
   211
(*[3], Res*)val (p,_,f,nxt,_,pt) = me nxt'''''_''' p'''''_''' [] pt'''''_'''; (*nxt = Subproblem ("Test", ["LINEAR", "univariate", "equation", "test"])*)
walther@59670
   212
(*[3], Pbl*)val (p,_,f,nxt,_,pt) = me nxt p [] pt; (*nxt = Model_Problem*)
walther@59670
   213
(*[3], Pbl*)val (p,_,f,nxt,_,pt) = me nxt p [] pt; (*nxt = Add_Given "equality (-1 + x = 0)"*)
walther@59670
   214
(*[3], Pbl*)val (p,_,f,nxt,_,pt) = me nxt p [] pt; (*nxt = Add_Given "solveFor x"*)
walther@59670
   215
(*[3], Pbl*)val (p,_,f,nxt,_,pt) = me nxt p [] pt; (*nxt = Add_Find "solutions x_i"*)
walther@59670
   216
(*[3], Pbl*)val (p,_,f,nxt,_,pt) = me nxt p [] pt; (*nxt = Specify_Theory "Test"*)
walther@59670
   217
(*[3], Pbl*)val (p,_,f,nxt,_,pt) = me nxt p [] pt; (*nxt = Specify_Problem ["LINEAR", "univariate", "equation", "test"]*)
walther@59670
   218
(*[3], Pbl*)val (p,_,f,nxt,_,pt) = me nxt p [] pt; (*nxt = Specify_Method ["Test", "solve_linear"]*)
walther@59670
   219
(*[3], Met*)val (p,_,f,nxt,_,pt) = me nxt p [] pt; (*nxt = Apply_Method ["Test", "solve_linear"]*)
walther@59670
   220
(*[3, 1], Frm*)val (p,_,f,nxt,_,pt) = me nxt p [] pt; (*nxt = Rewrite_Set_Inst (["(''bdv'', x)"], "isolate_bdv")*)
walther@59670
   221
(*[3, 1], Res*)val (p,_,f,nxt,_,pt) = me nxt p [] pt; (*nxt = Rewrite_Set "Test_simplify"*)
walther@59670
   222
(*[3, 2], Res*)val (p,_,f,nxt,_,pt) = me nxt p [] pt; (*nxt = Check_Postcond ["LINEAR", "univariate", "equation", "test"]*)
wneuper@59562
   223
(*[3], Res*)val (p,_,f,nxt,_,pt) = me nxt p [] pt; (*nxt = Check_elementwise "Assumptions"*)
wneuper@59562
   224
(*[4], Res*)val (p,_,f,nxt,_,pt) = me nxt p [] pt; (*nxt = Check_Postcond ["sqroot-test", "univariate", "equation", "test"]*)
wneuper@59562
   225
(*[], Res*)val (p,_,f,nxt,_,pt) = me nxt p [] pt; (*nxt = End_Proof'*)
wneuper@59562
   226
walther@59670
   227
(*/--------------------- final test ----------------------------------\\*)
walther@59749
   228
if p = ([], Res) andalso f2str f = "[x = 1]" andalso pr_ctree pr_short pt =
walther@59670
   229
  ".    ----- pblobj -----\n" ^
walther@59670
   230
  "1.   x + 1 = 2\n" ^
walther@59670
   231
  "2.   x + 1 + -1 * 2 = 0\n" ^
walther@59670
   232
  "3.    ----- pblobj -----\n" ^
walther@59670
   233
  "3.1.   -1 + x = 0\n" ^
walther@59670
   234
  "3.2.   x = 0 + -1 * -1\n" ^
walther@59670
   235
  "4.   [x = 1]\n"
walther@59749
   236
then case nxt of End_Proof' => () | _ => error "re-build: fun locate_input_tactic changed 1"
walther@59749
   237
else error "re-build: fun locate_input_tactic changed 2";
wneuper@59562
   238
walther@59670
   239
walther@59670
   240
"----------- fun locate_input_tactic Helpless, but applicable ----------------------------------";
walther@59670
   241
"----------- fun locate_input_tactic Helpless, but applicable ----------------------------------";
walther@59670
   242
"----------- fun locate_input_tactic Helpless, but applicable ----------------------------------";
walther@59670
   243
(*cp from -- try fun applyTactics ------- *)
walther@59670
   244
val (p,_,f,nxt,_,pt) = CalcTreeTEST [(["Term (5*e + 6*f - 8*g - 9 - 7*e - 4*f + 10*g + 12)",
walther@59670
   245
	    "normalform N"],
walther@59670
   246
	   ("PolyMinus",["plus_minus","polynom","vereinfachen"],
walther@59670
   247
	    ["simplification","for_polynomials","with_minus"]))];
walther@59670
   248
val (p,_,f,nxt,_,pt) = me nxt p [] pt; val (p,_,f,nxt,_,pt) = me nxt p [] pt;
walther@59670
   249
val (p,_,f,nxt,_,pt) = me nxt p [] pt; val (p,_,f,nxt,_,pt) = me nxt p [] pt;
walther@59670
   250
val (p,_,f,nxt,_,pt) = me nxt p [] pt; val (p,_,f,nxt,_,pt) = me nxt p [] pt;
walther@59670
   251
(*[1], Frm*)val (p,_,f,nxt,_,pt) = me nxt p [] pt; (*nxt = Rewrite_Set "ordne_alphabetisch"*)
walther@59670
   252
(*[1], Res*)val (p,_,f,nxt,_,pt) = me nxt p [] pt; (*nxt = Rewrite_Set "fasse_zusammen"*)
walther@59670
   253
walther@59846
   254
(*+*)if map Tactic.input_to_string (specific_from_prog pt p) =
walther@59670
   255
   ["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
   256
    "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@59823
   257
  then () else error "specific_from_prog ([1], Res) CHANGED";
walther@59823
   258
(*[2], Res*)val ("ok", (_, _, ptp as (pt, p))) = Step.by_tactic (hd (specific_from_prog pt p)) (pt, p);
walther@59670
   259
walther@59846
   260
(*+*)if map Tactic.input_to_string (specific_from_prog pt p) =
walther@59670
   261
   ["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
   262
    "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
   263
    "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@59823
   264
  then () else error "specific_from_prog ([1], Res) CHANGED";
walther@59823
   265
(* = ([3], Res)*)val ("ok", (_, _, ptp as (pt, p))) = Step.by_tactic (hd (specific_from_prog pt p)) (pt, p);
walther@59670
   266
walther@59670
   267
(*//----------------- exception PTREE "get_obj f EmptyPtree" raised --------------------------\\*)
walther@59823
   268
(** )val ("ok", (_, _, ptp as (pt, p))) =( **) Step.by_tactic (hd (specific_from_prog pt p)) (pt, p);
walther@59823
   269
"~~~~~ fun Step.by_tactic , args:"; val (tac, (ptp as (pt, p))) = (hd (specific_from_prog pt p), (pt, p));
walther@59755
   270
      val Applicable.Appl m = (*case*) Applicable.applicable_in p pt tac (*of*);
walther@59755
   271
      (*if*) Tactic.for_specify' m; (*false*)
walther@59670
   272
walther@59806
   273
Step_Solve.by_tactic m (pt, p);
walther@59806
   274
"~~~~~ fun by_tactic , args:"; val (m, (pt, po as (p, p_))) = (m, (pt, p));
walther@59670
   275
    (*if*) Celem.e_metID = get_obj g_metID pt (par_pblobj pt p) (*else*);
walther@59670
   276
	      val thy' = get_obj g_domID pt (par_pblobj pt p);
walther@59831
   277
	      val (is, sc) = LItool.resume_prog thy' (p,p_) pt;
walther@59670
   278
walther@59686
   279
  (*case*) locate_input_tactic sc (pt, po) (fst is) (snd is) m (*of*);
walther@59692
   280
"~~~~~ fun locate_input_tactic , args:"; val ((Rule.Prog prog), (cstate as (pt, (*?*)pos(*?*))), istate, ctxt, tac)
walther@59670
   281
  = (sc, (pt, po), (fst is), (snd is), m);
walther@59790
   282
      val srls = LItool.get_simplifier cstate (*TODO: shift into Istate.T*);
walther@59670
   283
walther@59692
   284
  (*case*) scan_to_tactic1 (prog, (cstate, ctxt, tac)) istate (*of*);
walther@59692
   285
"~~~~~ fun scan_to_tactic1 , args:"; val ((prog, (cctt as ((_, p), _, _))), (Istate.Pstate (ist as {path, ...})))
walther@59692
   286
  = ((prog, (cstate, ctxt, tac)), istate);
walther@59686
   287
    (*if*) path = [] orelse ((last_elem o fst) p = 0 andalso snd p = Res) (*else*);
walther@59670
   288
walther@59692
   289
           go_scan_up1 (prog, cctt) ist;
walther@59692
   290
"~~~~~ and go_scan_up1 , args:"; val ((yyy as (prog, _)), (ist as {path, ...}))
walther@59692
   291
  = ((prog, cctt), ist);
walther@59686
   292
  (*if*) 1 < length path (*then*);
walther@59670
   293
walther@59767
   294
           scan_up1 yyy (ist |> path_up) (at_location (path_up' path) prog);
walther@59691
   295
"~~~~~ fun scan_up1 , args:"; val (yyy, ist, (Const ("Tactical.Try"(*2*), _) $ _))
walther@59767
   296
  = (yyy, (ist |> path_up), (at_location (path_up' path) prog));
walther@59670
   297
walther@59691
   298
           go_scan_up1 yyy ist;
walther@59692
   299
"~~~~~ and go_scan_up1 , args:"; val ((yyy as (prog, _)), (ist as {path, ...}))
walther@59686
   300
  = (yyy, ist);
walther@59686
   301
  (*if*) 1 < length path (*then*);
walther@59670
   302
walther@59767
   303
           scan_up1 yyy (ist |> path_up) (at_location (path_up' path) prog);
walther@59692
   304
"~~~~~ fun scan_up1 , args:"; val ((yyy as (prog, xxx as (cstate, _, _))), ist,
walther@59688
   305
    (Const ("Tactical.Chain"(*3*), _) $ _ ))
walther@59767
   306
  = (yyy, (ist |> path_up), (at_location (path_up' path) prog));
walther@59692
   307
       val e2 = check_Seq_up ist prog
walther@59686
   308
;
walther@59718
   309
  (*case*) scan_dn1 xxx (ist |> path_up_down [R] |> set_or ORundef) e (*of*);
walther@59691
   310
"~~~~~ fun scan_dn1 , args:"; val (yyy, ist, (Const ("Tactical.Chain"(*2*), _) $ _ $ _))
walther@59718
   311
  = (xxx, (ist |> path_up_down [R] |> set_or ORundef), e2);
walther@59670
   312
walther@59691
   313
  (*case*) scan_dn1 xxx (ist |> path_down [L, R]) e1 (*of*);
walther@59691
   314
"~~~~~ fun scan_dn1 , args:"; val (xxx, ist, (Const ("Tactical.Try"(*2*), _) $ e))
walther@59686
   315
  = (xxx, (ist |> path_down [L, R]), e1);
walther@59670
   316
walther@59691
   317
  (*case*) scan_dn1 xxx (ist |> path_down [R]) e (*of*);
walther@59686
   318
    (*======= end of scanning tacticals, a leaf =======*)
walther@59709
   319
"~~~~~ fun scan_dn1 , args:"; val (((pt, p), ctxt, tac), (ist as {eval, act_arg, or, ...}), t)
walther@59686
   320
  = (xxx, (ist |> path_down [R]), e);
walther@59772
   321
    val (Program.Tac stac, a') = (*case*) check_leaf "locate" ctxt eval (get_subst ist) t (*of*);
walther@59844
   322
      val Not_Associated = (*case*) associate pt ctxt (tac, stac) (*of*);
walther@59718
   323
      val ORundef = (*case*) or (*of*);
walther@59686
   324
  val Notappl "norm_equation not applicable" =    
walther@59823
   325
      (*case*) Applicable.applicable_in p pt (LItool.tac_from_prog pt (Celem.assoc_thy "Isac_Knowledge") stac) (*of*);
walther@59670
   326
walther@59712
   327
   (Term_Val1 act_arg) (* return value *);
walther@59670
   328
walther@59670
   329
val Rewrite' ("PolyMinus", "tless_true", _, _, ("tausche_minus",_ (*"?b ist_monom \<Longrightarrow> ?a kleiner ?b \<Longrightarrow> ?b - ?a = - ?a + ?b"*)),
walther@59670
   330
   t, (res, asm)) = m;
walther@59686
   331
walther@59777
   332
if pstate2str ist =
walther@59852
   333
  "([\"\n(t_t, 5 * e + 6 * f - 8 * g - 9 - 7 * e - 4 * f + 10 * g + 12)\"], [R,L,R,R,L,R,R], empty, SOME t_t, \n" ^
walther@59787
   334
  "- (8 * g) + (- 9 + 12 + 5 * e - 7 * e + (6 - 4) * f) + 10 * g, ORundef, true, false)"
walther@59670
   335
andalso
walther@59861
   336
  UnparseC.term2str t = "- (8 * g) + (- 9 + 12 + 5 * e - 7 * e + (6 - 4) * f) + 10 * g"
walther@59670
   337
andalso
walther@59861
   338
  UnparseC.term2str res = "- (8 * g) + (- 9 + 12 + 5 * e - 7 * e + (- 4 + 6) * f) + 10 * g"
walther@59670
   339
andalso
walther@59861
   340
  UnparseC.terms2str asm = "[\"4 kleiner 6\",\"6 ist_monom\"]"
walther@59670
   341
then () else error "locate_input_tactic Helpless, but applicable CHANGED";
wneuper@59562
   342
walther@59680
   343
walther@59792
   344
"----------- re-build: fun find_next_step, mini ------------------------------------------------";
walther@59792
   345
"----------- re-build: fun find_next_step, mini ------------------------------------------------";
walther@59792
   346
"----------- re-build: fun find_next_step, mini ------------------------------------------------";
walther@59792
   347
val fmz = ["Term (a + a ::real)", "normalform n_n"];
walther@59792
   348
val (dI',pI',mI') = ("Poly",["polynomial","simplification"],["simplification","for_polynomials"]);
walther@59734
   349
val (p,_,f,nxt,_,pt) = CalcTreeTEST [(fmz, (dI',pI',mI'))];
walther@59765
   350
(*[], Pbl*)val (_, ([(tac, _, _)], _, (pt, p))) = Step.do_next p ((pt, Pos.e_pos'), []);(*Model_Problem*)
walther@59792
   351
(*[], Pbl*)val (_, ([(tac, _, _)], _, (pt, p))) = Step.do_next p ((pt, Pos.e_pos'), []);(*Specify_Theory "Poly"*)
walther@59792
   352
(*[], Pbl*)val (_, ([(tac, _, _)], _, (pt, p))) = Step.do_next p ((pt, Pos.e_pos'), []);(*Specify_Problem ["polynomial", "simplification"]*)
walther@59792
   353
(*[], Met*)val (_, ([(tac, _, _)], _, (pt, p))) = Step.do_next p ((pt, e_pos'), []);(*Specify_Method  ["simplification", "for_polynomials"]*)
walther@59792
   354
(*1], Frm*)val (_, ([(tac, _, _)], _, (pt, p))) = Step.do_next p ((pt, e_pos'), []);(*Apply_Method ["simplification", "for_polynomials"]*)
walther@59792
   355
(*[1], Res*)val (_, ([(tac'''''_', _, _)], _, (pt'''''_', p'''''_'))) =
walther@59734
   356
walther@59792
   357
      Step.do_next p ((pt, e_pos'), []);(*Rewrite_Set "norm_Poly"*)
walther@59792
   358
(*//------------------ go into 1 ------------------------------------------------------------\\*)
walther@59792
   359
"~~~~~ fun do_next , args:"; val ((ip as (_, p_)), (ptp as (pt, p), tacis))
walther@59792
   360
  = (p, ((pt, e_pos'), []));
walther@59792
   361
  val pIopt = Ctree.get_pblID (pt, ip);
walther@59792
   362
    (*if*)  ip = ([], Res) (*else*);
walther@59792
   363
      val _ = (*case*) tacis (*of*);
walther@59792
   364
      val SOME _ = (*case*) pIopt (*of*);
walther@59839
   365
      (*if*) member op = [Pos.Pbl, Pos.Met] p_ (*else*);
walther@59734
   366
walther@59792
   367
val ("ok", ([(Rewrite_Set "norm_Poly", _, _)], _, (_, ([1], Res)))) =
walther@59792
   368
Step_Solve.do_next (pt, ip);
walther@59792
   369
"~~~~~ and do_next , args:"; val (ptp as (pt, pos as (p, p_))) =  (pt, ip);
walther@59734
   370
    (*if*) Celem.e_metID = get_obj g_metID pt (par_pblobj pt p) (*else*);
walther@59734
   371
        val thy' = get_obj g_domID pt (par_pblobj pt p);
walther@59831
   372
	      val ((ist, ctxt), sc) = LItool.resume_prog thy' (p,p_) pt;
walther@59734
   373
walther@59851
   374
val Next_Step (_, _, Rewrite_Set' ("Poly", _, Rule_Set.Seqence {id = "norm_Poly", ...}, _, _)) =
walther@59792
   375
           LI.find_next_step sc (pt, pos) ist ctxt (*of*);
walther@59792
   376
"~~~~~ fun find_next_step , args:"; val ((Rule.Prog prog), (ptp as(pt, (p, _))), (Pstate ist), ctxt)
walther@59734
   377
  = (sc, (pt, pos), ist, ctxt);
walther@59734
   378
walther@59851
   379
val Accept_Tac (Rewrite_Set' ("Poly", _, Rule_Set.Seqence {id = "norm_Poly", ...}, _, _), _, _) =
walther@59792
   380
  (*case*) scan_to_tactic (prog, (ptp, ctxt)) (Pstate ist) (*of*);
walther@59792
   381
"~~~~~ fun scan_to_tactic , args:"; val ((prog, cc), (Pstate (ist as {path, ...})))
walther@59792
   382
  = ((prog, (ptp, ctxt)), (Pstate ist));
walther@59792
   383
  (*if*) path = [] (*then*);
walther@59734
   384
walther@59851
   385
val Accept_Tac (Rewrite_Set' ("Poly", _, Rule_Set.Seqence {id = "norm_Poly", ...}, _, _), _, _) =
walther@59792
   386
            scan_dn cc (trans_scan_dn ist) (Program.body_of prog);
walther@59792
   387
"~~~~~ fun scan_dn , args:"; val ((cc as (_, ctxt)), (ist as {eval, ...}), t)
walther@59792
   388
  = (cc, (trans_scan_dn ist), (Program.body_of prog));
walther@59792
   389
    (*if*) Tactical.contained_in t (*else*);
walther@59792
   390
      val (Program.Tac prog_tac, form_arg) = (*case*) LItool.check_leaf "next  " ctxt eval (get_subst ist) t (*of*);
walther@59734
   391
walther@59851
   392
val Accept_Tac (Rewrite_Set' ("Poly", _, Rule_Set.Seqence {id = "norm_Poly", ...}, _, _), _, _) =
walther@59799
   393
          check_tac cc ist (prog_tac, form_arg)  (*return from xxx*);
walther@59792
   394
"~~~~~ from fun scan_dn\<longrightarrow>fun scan_to_tactic\<longrightarrow>fun find_next_step, return:"; val (Accept_Tac (tac, ist, ctxt))
walther@59799
   395
  = (check_tac cc ist (prog_tac, form_arg));
walther@59734
   396
walther@59792
   397
    Next_Step (Pstate ist, Tactic.insert_assumptions tac ctxt, tac)  (*return from find_next_step*);
walther@59792
   398
"~~~~~ from fun find_next_step\<longrightarrow>and do_next\<longrightarrow>fun zzz, return:"; val (Next_Step (ist, ctxt, tac))
walther@59792
   399
  = (Next_Step (Pstate ist, Tactic.insert_assumptions tac ctxt, tac));
walther@59734
   400
walther@59792
   401
           LI.by_tactic tac (ist, Tactic.insert_assumptions tac ctxt) ptp  (*return from and do_next*);
walther@59792
   402
"~~~~~ from and do_next\<longrightarrow>fun do_next\<longrightarrow>toplevel, return:"; val  (_, ([(tac''''', _, _)], _, (pt''''', p''''')))
walther@59793
   403
  = (LI.by_tactic tac (ist, Tactic.insert_assumptions tac ctxt) ptp);
walther@59792
   404
(*\\------------------ end of go into 1 -----------------------------------------------------//*)
walther@59734
   405
walther@59792
   406
(*[], Res*)val (_, ([(tac''''', _, _)], _, (pt''''', p'''''))) =
walther@59792
   407
walther@59792
   408
      Step.do_next p'''''_' ((pt'''''_', Pos.e_pos'), []);(* Check_Postcond ["polynomial", "simplification"]*)
walther@59792
   409
(*//------------------ go into 2 ------------------------------------------------------------\\*)
walther@59792
   410
"~~~~~ fun do_next , args:"; val ((ip as (_, p_)), (ptp as (pt, p), tacis))
walther@59792
   411
  = (p''''', ((pt''''', e_pos'), []));
walther@59792
   412
  val pIopt = Ctree.get_pblID (pt, ip);
walther@59792
   413
    (*if*)  ip = ([], Res) (*else*);
walther@59792
   414
      val _ = (*case*) tacis (*of*);
walther@59792
   415
      val SOME _ = (*case*) pIopt (*of*);
walther@59839
   416
      (*if*) member op = [Pos.Pbl, Pos.Met] p_ (*else*);
walther@59792
   417
walther@59792
   418
val ("ok", ([(Check_Postcond ["polynomial", "simplification"], _, _)], _, (_, ([], Res)))) =
walther@59792
   419
Step_Solve.do_next (pt, ip);
walther@59792
   420
"~~~~~ and do_next , args:"; val (ptp as (pt, pos as (p, p_))) =  (pt, ip);
walther@59792
   421
    (*if*) Celem.e_metID = get_obj g_metID pt (par_pblobj pt p) (*else*);
walther@59792
   422
        val thy' = get_obj g_domID pt (par_pblobj pt p);
walther@59831
   423
	      val ((ist, ctxt), sc) = LItool.resume_prog thy' (p,p_) pt;
walther@59792
   424
walther@59792
   425
  (** )val End_Program (ist, tac) = 
walther@59793
   426
 ( *case*) LI.find_next_step sc (pt, pos) ist ctxt (*of*);
walther@59792
   427
"~~~~~ fun find_next_step , args:"; val ((Rule.Prog prog), (ptp as(pt, (p, _))), (Pstate ist), ctxt)
walther@59792
   428
  = (sc, (pt, pos), ist, ctxt);
walther@59792
   429
walther@59792
   430
(*  val Term_Val (Const ("Groups.times_class.times", _) $ Free ("2", _) $ Free ("a", _))*)
walther@59792
   431
  (** )val Term_Val prog_result =
walther@59792
   432
 ( *case*) scan_to_tactic (prog, (ptp, ctxt)) (Pstate ist) (*of*);
walther@59792
   433
"~~~~~ fun scan_to_tactic , args:"; val ((prog, cc), (Pstate (ist as {path, ...})))
walther@59792
   434
  = ((prog, (ptp, ctxt)), (Pstate ist));
walther@59792
   435
  (*if*) path = [] (*else*);
walther@59792
   436
walther@59792
   437
           go_scan_up (prog, cc) (trans_scan_up ist |> set_found);
walther@59792
   438
"~~~~~ fun go_scan_up , args:"; val ((pcc as (sc, _)), (ist as {path, act_arg, found_accept, ...}))
walther@59792
   439
  = ((prog, cc), (trans_scan_up ist(*|> set_found !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! *)));
walther@59792
   440
    (*if*) path = [R] (*then*);
walther@59792
   441
      (*if*) found_accept = true (*then*);
walther@59792
   442
walther@59792
   443
      Term_Val act_arg (*return from go_scan_up*);
walther@59792
   444
"~~~~~ from fun go_scan_up\<longrightarrow>fun scan_to_tactic, return:"; val (Term_Val prog_result) = (Term_Val act_arg);
walther@59792
   445
walther@59792
   446
    Term_Val prog_result  (*return from scan_to_tactic*);
walther@59792
   447
"~~~~~ from fun scan_to_tactic\<longrightarrow>fun find_next_step, return:"; val (Term_Val prog_result) = (Term_Val prog_result);
walther@59838
   448
    val (true, p', _) = (*case*) parent_node pt p (*of*);
walther@59792
   449
              val (_, pblID, _) = get_obj g_spec pt p';
walther@59792
   450
walther@59843
   451
     End_Program (Pstate ist, Tactic.Check_Postcond' (pblID, prog_result))
walther@59792
   452
     (*return from find_next_step*);
walther@59792
   453
"~~~~~ from fun find_next_step\<longrightarrow>and do_next\<longrightarrow>fun zzz, return:"; val (End_Program (ist, tac))
walther@59843
   454
  = (End_Program (Pstate ist, Tactic.Check_Postcond' (pblID,prog_result)));
walther@59792
   455
      val _ = (*case*) tac (*of*);
walther@59792
   456
walther@59792
   457
val ("ok", ([(Check_Postcond ["polynomial", "simplification"], _, _)], _, (_, ([], Res))))
walther@59793
   458
   = LI.by_tactic tac (ist, ctxt) ptp (*return from and do_next*);
walther@59792
   459
"~~~~~ from and do_next\<longrightarrow>top level, return:"; val (_, ([(tac''''', _, _)], _, (pt''''', p''''')))
walther@59793
   460
  = (LI.by_tactic tac (ist, ctxt) ptp);
walther@59792
   461
(*\\------------------ end of go into 2 -----------------------------------------------------//*)
walther@59792
   462
walther@59792
   463
(*[], Und*)val (msg, ([], _, (pt, p))) = Step.do_next p''''' ((pt''''', Pos.e_pos'), []);(**)
walther@59792
   464
walther@59792
   465
show_pt_tac pt; (*[
walther@59792
   466
([], Frm), Simplify (a + a)
walther@59792
   467
. . . . . . . . . . Apply_Method ["simplification","for_polynomials"],
walther@59792
   468
([1], Frm), a + a
walther@59792
   469
. . . . . . . . . . Rewrite_Set "norm_Poly",
walther@59792
   470
([1], Res), 2 * a
walther@59792
   471
. . . . . . . . . . Check_Postcond ["polynomial","simplification"],
walther@59792
   472
([], Res), 2 * a]*)
walther@59792
   473
walther@59792
   474
(*/--- final test ---------------------------------------------------------------------------\\*)
walther@59734
   475
val (res, asm) = (get_obj g_result pt (fst p));
walther@59861
   476
if UnparseC.term2str res = "2 * a" andalso map UnparseC.term2str asm = []
walther@59792
   477
andalso p = ([], Und) andalso msg = "end-of-calculation"
walther@59792
   478
andalso pr_ctree pr_short pt = ".    ----- pblobj -----\n1.   a + a\n"
walther@59792
   479
then 
walther@59792
   480
  case tac''''' of Check_Postcond ["polynomial", "simplification"] => () 
walther@59792
   481
  | _ => error "re-build: fun find_next_step, mini 1"
walther@59792
   482
else error "re-build: fun find_next_step, mini 2"
wneuper@59575
   483
wneuper@59575
   484
walther@59783
   485
"----------- re-build: fun locate_input_term ---------------------------------------------------";
walther@59783
   486
"----------- re-build: fun locate_input_term ---------------------------------------------------";
walther@59783
   487
"----------- re-build: fun locate_input_term ---------------------------------------------------";
walther@59795
   488
(*cp from inform.sml
walther@59795
   489
 ----------- appendFormula: on Res + late deriv ------------------------------------------------*)
walther@59795
   490
val fmz = ["equality (x+1=(2::real))", "solveFor x","solutions L"];
walther@59795
   491
val (dI',pI',mI') = ("Test", ["sqroot-test","univariate","equation","test"],
walther@59795
   492
   ["Test","squ-equ-test-subpbl1"]);
walther@59795
   493
val (p,_,f,nxt,_,pt) = CalcTreeTEST [(fmz, (dI',pI',mI'))];
walther@59795
   494
val (p,_,f,nxt,_,pt) = me nxt p [] pt;
walther@59795
   495
val (p,_,f,nxt,_,pt) = me nxt p [] pt;
walther@59795
   496
val (p,_,f,nxt,_,pt) = me nxt p [] pt;
walther@59795
   497
val (p,_,f,nxt,_,pt) = me nxt p [] pt;
walther@59795
   498
val (p,_,f,nxt,_,pt) = me nxt p [] pt;
walther@59795
   499
val (p,_,f,nxt,_,pt) = me nxt p [] pt;
walther@59795
   500
(*[], Met*)val (p,_,f,nxt,_,pt) = me nxt p [] pt; (*Apply_Method ["Test", "squ-equ-test-subpbl1"]*);
walther@59783
   501
walther@59795
   502
(*[1], Frm*)val (p,_,f,nxt,_,pt) = me nxt p [] pt;(*Rewrite_Set "norm_equation"*)
walther@59795
   503
(*+*)if f2str f = "x + 1 = 2" then () else error "locate_input_term at ([1], Frm) CHANGED";
walther@59783
   504
walther@59795
   505
(*[1], Res*)val (p,_,f,nxt,_,pt) = me nxt p [] pt;(*Rewrite_Set "Test_simplify"*)
walther@59795
   506
(*+*)if f2str f = "x + 1 + -1 * 2 = 0" then () else error "locate_input_term at ([1], Frm) CHANGED";
walther@59783
   507
walther@59795
   508
show_pt_tac pt; (*[
walther@59795
   509
([], Frm), solve (x + 1 = 2, x)
walther@59795
   510
. . . . . . . . . . Apply_Method ["Test","squ-equ-test-subpbl1"],
walther@59795
   511
([1], Frm), x + 1 = 2
walther@59795
   512
. . . . . . . . . . Rewrite_Set "norm_equation",
walther@59795
   513
([1], Res), x + 1 + -1 * 2 = 0             ///Check_Postcond..ERROR*)
walther@59795
   514
walther@59797
   515
(*//---------- appendFormula 1 "x = 1" \<longrightarrow> Step_Solve.inform \<longrightarrow> LI.locate_input_term ----------\\*)
walther@59795
   516
"~~~~~ fun appendFormula , args:"; val ((*cI, *) ifo: Rule.cterm') = ((**) "x = 1");
walther@59795
   517
    val cs = (*get_calc cI*) ((pt, p), [(*nxt, nxt_, (pos, (ist, ctxt))*)])
walther@59795
   518
    val pos = (*get_pos cI 1*) p
walther@59795
   519
walther@59795
   520
(*+*)val ptp''''' = (pt, p);
walther@59795
   521
(*+*)if snd ptp''''' = ([1], Res) then () else error "old_cs changed";
walther@59795
   522
(*+*)show_pt_tac pt; (*[
walther@59795
   523
(*+*)([], Frm), solve (x + 1 = 2, x)
walther@59795
   524
(*+*). . . . . . . . . . Apply_Method ["Test","squ-equ-test-subpbl1"],
walther@59795
   525
(*+*)([1], Frm), x + 1 = 2
walther@59795
   526
(*+*). . . . . . . . . . Rewrite_Set "norm_equation",
walther@59795
   527
(*+*)([1], Res), x + 1 + -1 * 2 = 0      ///Check_Postcond*)
walther@59795
   528
walther@59798
   529
  val ("ok", cs' as (_, _, ptp')) =
walther@59795
   530
    (*case*) Step.do_next pos cs (*of*);
walther@59795
   531
walther@59795
   532
val ("ok", (_(*use in DG !!!*), [], ptp''''' as (pt''''', p'''''))) = (*case*)
walther@59798
   533
     Step_Solve.by_term ptp' (encode ifo) (*of*);
walther@59798
   534
"~~~~~ fun Step_Solve.by_term , args:"; val ((pt, pos as (p, _)), istr)
walther@59798
   535
  = (ptp', (encode ifo));
walther@59795
   536
  val SOME f_in =
walther@59795
   537
    (*case*) TermC.parse (Celem.assoc_thy "Isac_Knowledge") istr (*of*);
walther@59795
   538
  	  val f_in = Thm.term_of f_in
walther@59795
   539
      val pos_pred = lev_back(*'*) pos
walther@59795
   540
  	  val f_pred = Ctree.get_curr_formula (pt, pos_pred);
walther@59795
   541
  	  val f_succ = Ctree.get_curr_formula (pt, pos);
walther@59795
   542
      (*if*) f_succ = f_in (*else*);
walther@59795
   543
  val NONE =
walther@59822
   544
        (*case*) In_Chead.cas_input f_in (*of*);
walther@59795
   545
walther@59795
   546
(*old* )     val (_, _, metID) = get_obj g_spec pt (par_pblobj pt p)
walther@59795
   547
(*old*)     val {scr = prog, ...} = Specify.get_met metID
walther@59807
   548
(*old*)     val istate = get_istate_LI pt pos
walther@59795
   549
(*old*)     val ctxt = get_ctxt pt pos
walther@59795
   550
  val LI.Found_Step (cstate'''''_', _(*istate*), _(*ctxt*)) = (*case*)
walther@59795
   551
        LI.locate_input_term prog (pt, pos) istate ctxt f_in (*of*);
walther@59795
   552
"~~~~~ fun locate_input_term , args:"; val ((Rule.Prog _),  ((pt, pos) : Calc.T), (_ : Istate.T), (_ : Proof.context), tm)
walther@59795
   553
  = (prog, (pt, pos), istate, ctxt, f_in);
walther@59795
   554
( *old*)
walther@59795
   555
walther@59795
   556
(*NEW*) LI.locate_input_term (pt, pos) f_in (*of*);
walther@59795
   557
"~~~~~ fun locate_input_term , args:"; val ((pt, pos), tm) = ((pt, pos), f_in);
walther@59795
   558
   		val pos_pred = Pos.lev_back' pos (*f_pred ---"step pos cs"---> f_succ in appendFormula*)
walther@59795
   559
walther@59795
   560
  val ("ok", (_, _, cstate as (pt', pos'))) =
walther@59795
   561
   		(*case*) compare_step ([], [], (pt, pos_pred)) tm (*of*);
walther@59795
   562
walther@59795
   563
(*old* )
walther@59807
   564
    Found_Step (cstate, get_istate_LI pt' pos', get_ctxt pt' pos')  (*return from locate_input_term*);
walther@59795
   565
( *old*)
walther@59795
   566
(*NEW*)     Found_Step cstate (*return from locate_input_term*);
walther@59795
   567
       (*LI.Found_Step ( *)cstate(*, _(*istate*), _(*ctxt*))( *return from locate_input_term*);
walther@59797
   568
"~~~~~ from fun locate_input_term\<longrightarrow>fun Step_Solve.by_term, return:"; val ("ok", (_(*use in DG !!!*), c, ptp as (_, p)))
walther@59795
   569
  = (("ok" , ([], [], cstate (* already contains istate, ctxt *))));
walther@59795
   570
walther@59797
   571
    ("ok", ((*_ use in DG !!!,*) c, ptp(* as (_*), p))(*)*)(*return from Step_Solve.by_term*);
walther@59797
   572
"~~~~~ from fun Step_Solve.by_term\<longrightarrow>(fun appendFormula)!toplevel, return:"; val ("ok", (_(*use in DG !!!*), [], ptp''''' as (pt''''', p''''')))
walther@59795
   573
  = ("ok", ([], [], ptp));
walther@59795
   574
walther@59795
   575
(*fun me requires nxt...*)
walther@59795
   576
    Step.do_next p''''' (ptp''''', []);
walther@59795
   577
  val ("ok", ([(nxt'''''_' as Check_Postcond ["LINEAR", "univariate", "equation", "test"], _, _)], _,
walther@59795
   578
    (pt'''''_', p'''''_'))) = Step.do_next p''''' (ptp''''', [])
walther@59797
   579
(*\\---------- appendFormula 1 "x = 1" \<longrightarrow> Step_Solve.inform \<longrightarrow> LI.locate_input_term ----------//*)
walther@59795
   580
walther@59797
   581
(*//----- REPLACED BY appendFormula 1 "x = 1" \<longrightarrow> Step_Solve.inform \<longrightarrow> LI.locate_input_term -----\\* )
walther@59795
   582
 (*[2], Res*)val (p,_,f,nxt,_,pt) = me nxt p [] pt; (*nxt = Subproblem ("Test", ["LINEAR", "univariate", "equation", "test"])*)
walther@59795
   583
 (*[3], Pbl*)val (p,_,f,nxt,_,pt) = me nxt p [] pt; (*nxt = Model_Problem*)
walther@59795
   584
 (*[3], Pbl*)val (p,_,f,nxt,_,pt) = me nxt p [] pt; (*nxt = Add_Given "equality (-1 + x = 0)"*)
walther@59795
   585
 (*[3], Pbl*)val (p,_,f,nxt,_,pt) = me nxt p [] pt; (*nxt = Add_Given "solveFor x"*)
walther@59795
   586
 (*[3], Pbl*)val (p,_,f,nxt,_,pt) = me nxt p [] pt; (*nxt = Add_Find "solutions x_i"*)
walther@59795
   587
 (*[3], Pbl*)val (p,_,f,nxt,_,pt) = me nxt p [] pt; (*nxt = Specify_Theory "Test"*)
walther@59795
   588
 (*[3], Pbl*)val (p,_,f,nxt,_,pt) = me nxt p [] pt; (*nxt = Specify_Problem ["LINEAR", "univariate", "equation", "test"]*)
walther@59795
   589
 (*[3], Pbl*)val (p,_,f,nxt,_,pt) = me nxt p [] pt; (*nxt = Specify_Method ["Test", "solve_linear"]*)
walther@59795
   590
 (*[3], Met*)val (p,_,f,nxt,_,pt) = me nxt p [] pt; (*nxt = Apply_Method ["Test", "solve_linear"]*)
walther@59795
   591
 (*[3, 1], Frm*)val (p,_,f,nxt,_,pt) = me nxt p [] pt; (*nxt = Rewrite_Set_Inst (["(''bdv'', x)"], "isolate_bdv")*)
walther@59795
   592
 (*[3, 1], Res*)val (p,_,f,nxt,_,pt) = me nxt p [] pt; (*nxt = Rewrite_Set "Test_simplify"*)
walther@59795
   593
 (*[3, 2], Res*)val (p,_,f,nxt,_,pt) = me nxt p [] pt; (*nxt = Check_Postcond ["LINEAR", "univariate", "equation", "test"]*)
walther@59797
   594
( *\\----- REPLACED BY appendFormula 1 "x = 1" \<longrightarrow> Step_Solve.inform \<longrightarrow> LI.locate_input_term -----//*)
walther@59795
   595
walther@59795
   596
 (*[3], Res*)val (p,_,f,nxt,_,pt) = me nxt'''''_' p'''''_' [] pt'''''_'; (*nxt = Check_elementwise "Assumptions"*)
walther@59795
   597
 (*[4], Res*)val (p,_,f,nxt,_,pt) = me nxt p [] pt; (*nxt = Check_Postcond ["sqroot-test", "univariate", "equation", "test"]*)
walther@59795
   598
 (*[], Res*)val (p,_,f,nxt,_,pt) = me nxt p [] pt; (*nxt = End_Proof'*)
walther@59795
   599
walther@59795
   600
(*/--- final test ---------------------------------------------------------------------------\\*)
walther@59795
   601
if p = ([], Res) andalso f2str f = "[x = 1]" andalso pr_ctree pr_short pt =
walther@59795
   602
   ".    ----- pblobj -----\n" ^
walther@59795
   603
   "1.   x + 1 = 2\n" ^
walther@59795
   604
   "2.   x + 1 + -1 * 2 = 0\n" ^
walther@59795
   605
   "3.    ----- pblobj -----\n" ^
walther@59795
   606
   "3.1.   -1 + x = 0\n" ^
walther@59795
   607
   "3.2.   x = 0 + -1 * -1\n" ^
walther@59795
   608
   "3.2.1.   x = 0 + -1 * -1\n" ^
walther@59795
   609
   "3.2.2.   x = 0 + 1\n" (*ATTENTION: see complete Calc below*)
walther@59795
   610
then case nxt of End_Proof' => () | _ => error "re-build: fun locate_input_term CHANGED 1"
walther@59795
   611
else error "re-build: fun locate_input_term CHANGED 2";
walther@59795
   612
walther@59795
   613
show_pt_tac pt; (*[
walther@59795
   614
([], Frm), solve (x + 1 = 2, x)
walther@59795
   615
. . . . . . . . . . Apply_Method ["Test","squ-equ-test-subpbl1"],
walther@59795
   616
([1], Frm), x + 1 = 2
walther@59795
   617
. . . . . . . . . . Rewrite_Set "norm_equation",
walther@59795
   618
([1], Res), x + 1 + -1 * 2 = 0
walther@59795
   619
. . . . . . . . . . Rewrite_Set "Test_simplify",
walther@59795
   620
([2], Res), -1 + x = 0
walther@59795
   621
. . . . . . . . . . Subproblem (Test, ["LINEAR","univariate","equation","test"]),
walther@59795
   622
([3], Pbl), solve (-1 + x = 0, x)
walther@59795
   623
. . . . . . . . . . Apply_Method ["Test","solve_linear"],
walther@59795
   624
([3,1], Frm), -1 + x = 0
walther@59795
   625
. . . . . . . . . . Rewrite_Set_Inst ([(''bdv'', x)], "isolate_bdv"),
walther@59795
   626
([3,1], Res), x = 0 + -1 * -1
walther@59795
   627
. . . . . . . . . . Derive Test_simplify,
walther@59795
   628
([3,2,1], Frm), x = 0 + -1 * -1
walther@59795
   629
. . . . . . . . . . Rewrite ("#: -1 * -1 = 1", "-1 * -1 = 1"),
walther@59795
   630
([3,2,1], Res), x = 0 + 1
walther@59795
   631
. . . . . . . . . . Rewrite ("radd_0", "0 + ?k = ?k"),
walther@59795
   632
([3,2,2], Res), x = 1
walther@59846
   633
. . . . . . . . . . Tactic.input_to_string not impl. for ?!,
walther@59795
   634
([3,2], Res), x = 1
walther@59795
   635
. . . . . . . . . . Check_Postcond ["LINEAR","univariate","equation","test"],
walther@59795
   636
([3], Res), [x = 1]
walther@59795
   637
. . . . . . . . . . Check_Postcond ["sqroot-test","univariate","equation","test"],
walther@59795
   638
([], Res), [x = 1]]*)