test/Tools/isac/Interpret/lucas-interpreter.sml
author Walther Neuper <walther.neuper@jku.at>
Wed, 03 Feb 2021 16:39:44 +0100
changeset 60154 2ab0d1523731
parent 60023 113997e55e71
child 60242 73ee61385493
permissions -rw-r--r--
Isac's MethodC not shadowing Isabelle's Method
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@59997
    11
"----------- fun locate_input_tactic Helpless, NOT 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"],
walther@59997
    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@59922
    40
val Applicable.Yes m = Step.check tac (pt, p);
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@60154
    46
      val {srls, ...} = MethodC.from_store 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@59881
    51
      val thy = ThyC.get_theory 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@59868
    79
(*+*) if UnparseC.term 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 -------------------------------------------------";
walther@59997
    93
val fmz = ["equality (x+1=(2::real))", "solveFor x", "solutions L"];
walther@59997
    94
val (dI',pI',mI') = ("Test", ["sqroot-test", "univariate", "equation", "test"],
walther@59997
    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@59921
   114
      val Applicable.Yes m = (*case*) Solve_Step.check tac (pt, p) (*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@60154
   121
    (*if*) MethodC.id_empty = 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@59932
   172
                    Step.add 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@59981
   177
"~~~~~ from Step_Solve.by_tactic \<longrightarrow> Step.by_tactic return:"; val ((msg, cs' : Calc.state_post))
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@59937
   195
   (p, [] : NEW, TESTg_form (pt, p), (Tactic.tac2IDstr tac, tac), Celem.Sundef, pt);
walther@59670
   196
"~~~~~ from me to TOOPLEVEL return:"; val (p,_,f,nxt,_,pt)
walther@59937
   197
   = (*** )xxx( ***) (p, [] : NEW, TESTg_form (pt, p), (Tactic.tac2IDstr tac, tac), Celem.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@59997
   240
"----------- fun locate_input_tactic Helpless, NOT applicable ----------------------------------";
walther@59997
   241
"----------- fun locate_input_tactic Helpless, NOT applicable ----------------------------------";
walther@59997
   242
"----------- fun locate_input_tactic Helpless, NOT 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@59997
   246
	   ("PolyMinus",["plus_minus", "polynom", "vereinfachen"],
walther@59997
   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@59921
   268
(** )val ("ok", (_, _, ptp as (pt, p))) =( **)
walther@59921
   269
      Step.by_tactic (hd (specific_from_prog pt p)) (pt, p);
walther@59921
   270
"~~~~~ fun by_tactic , args:"; val (tac, (ptp as (pt, p))) = (hd (specific_from_prog pt p), (pt, p));
walther@59921
   271
      val Applicable.Yes m = (*case*) Solve_Step.check tac (pt, p) (*of*);
walther@59755
   272
      (*if*) Tactic.for_specify' m; (*false*)
walther@59670
   273
walther@59806
   274
Step_Solve.by_tactic m (pt, p);
walther@59806
   275
"~~~~~ fun by_tactic , args:"; val (m, (pt, po as (p, p_))) = (m, (pt, p));
walther@60154
   276
    (*if*) MethodC.id_empty = get_obj g_metID pt (par_pblobj pt p) (*else*);
walther@59670
   277
	      val thy' = get_obj g_domID pt (par_pblobj pt p);
walther@59831
   278
	      val (is, sc) = LItool.resume_prog thy' (p,p_) pt;
walther@59670
   279
walther@59686
   280
  (*case*) locate_input_tactic sc (pt, po) (fst is) (snd is) m (*of*);
walther@59692
   281
"~~~~~ fun locate_input_tactic , args:"; val ((Rule.Prog prog), (cstate as (pt, (*?*)pos(*?*))), istate, ctxt, tac)
walther@59670
   282
  = (sc, (pt, po), (fst is), (snd is), m);
walther@59790
   283
      val srls = LItool.get_simplifier cstate (*TODO: shift into Istate.T*);
walther@59670
   284
walther@59692
   285
  (*case*) scan_to_tactic1 (prog, (cstate, ctxt, tac)) istate (*of*);
walther@59692
   286
"~~~~~ fun scan_to_tactic1 , args:"; val ((prog, (cctt as ((_, p), _, _))), (Istate.Pstate (ist as {path, ...})))
walther@59692
   287
  = ((prog, (cstate, ctxt, tac)), istate);
walther@59686
   288
    (*if*) path = [] orelse ((last_elem o fst) p = 0 andalso snd p = Res) (*else*);
walther@59670
   289
walther@59692
   290
           go_scan_up1 (prog, cctt) ist;
walther@59997
   291
"~~~~~ fun go_scan_up1 , args:"; val ((pcct as (prog, _)), (ist as {path, ...}))
walther@59692
   292
  = ((prog, cctt), ist);
walther@59686
   293
  (*if*) 1 < length path (*then*);
walther@59670
   294
walther@60023
   295
           scan_up1 pcct (ist |> path_up) (TermC.sub_at (path_up' path) prog);
walther@59997
   296
"~~~~~ and scan_up1 , args:"; val (pcct, ist, (Const ("Tactical.Try"(*2*), _) $ _))
walther@60023
   297
  = (pcct, (ist |> path_up), (TermC.sub_at (path_up' path) prog));
walther@59670
   298
walther@59997
   299
           go_scan_up1 pcct ist;
walther@59997
   300
"~~~~~ and go_scan_up1 , args:"; val ((pcct as (prog, _)), (ist as {path, ...}))
walther@59997
   301
  = (pcct, ist);
walther@59686
   302
  (*if*) 1 < length path (*then*);
walther@59670
   303
walther@60023
   304
           scan_up1 pcct (ist |> path_up) (TermC.sub_at (path_up' path) prog);
walther@59997
   305
"~~~~~ and scan_up1 , args:"; val ((pcct as (prog, cct as (cstate, _, _))), ist,
walther@59688
   306
    (Const ("Tactical.Chain"(*3*), _) $ _ ))
walther@60023
   307
  = (pcct, (ist |> path_up), (TermC.sub_at (path_up' path) prog));
walther@59692
   308
       val e2 = check_Seq_up ist prog
walther@59686
   309
;
walther@59997
   310
  (*case*) scan_dn1 cct (ist |> path_up_down [R] |> set_or ORundef) e2 (*of*);
walther@59997
   311
"~~~~~ fun scan_dn1 , args:"; val (yyy, ist, (Const ("Tactical.Chain"(*2*), _) $ e1 $ e2))
walther@59997
   312
  = (cct, (ist |> path_up_down [R] |> set_or ORundef), e2);
walther@59670
   313
walther@59997
   314
  (*case*) scan_dn1 cct (ist |> path_down [L, R]) e1 (*of*);
walther@59691
   315
"~~~~~ fun scan_dn1 , args:"; val (xxx, ist, (Const ("Tactical.Try"(*2*), _) $ e))
walther@59997
   316
  = (cct, (ist |> path_down [L, R]), e1);
walther@59670
   317
walther@59997
   318
  (*case*) scan_dn1 cct (ist |> path_down [R]) e (*of*);
walther@59686
   319
    (*======= end of scanning tacticals, a leaf =======*)
walther@59997
   320
"~~~~~ fun scan_dn1 , args:"; val ((cct as (_, ctxt, _)), (ist as {eval, ...}), t)
walther@59997
   321
  = (cct, (ist |> path_down [R]), e);
walther@59997
   322
    (*if*) Tactical.contained_in t (*else*);
walther@59997
   323
  val (Program.Tac prog_tac, form_arg) = (*case*)
walther@59997
   324
    LItool.check_leaf "locate" ctxt eval (get_subst ist) t (*of*);
walther@59997
   325
walther@59997
   326
           check_tac1 cct ist (prog_tac, form_arg);
walther@59997
   327
"~~~~~ fun check_tac1 , args:"; val (((pt, p), ctxt, tac), (ist as {act_arg, or, ...}), (prog_tac, form_arg)) =
walther@59997
   328
  (cct, ist, (prog_tac, form_arg));
walther@59997
   329
val LItool.Not_Associated = (*case*)
walther@59997
   330
  LItool.associate pt ctxt (tac, prog_tac) (*of*);
walther@59997
   331
     val _(*ORundef*) = (*case*) or (*of*);
walther@59997
   332
     val Applicable.Yes m' =
walther@59997
   333
          (*case*) Solve_Step.check (LItool.tac_from_prog pt (ThyC.get_theory "Isac_Knowledge") prog_tac) (pt, p) (*of*);
walther@59997
   334
walther@59997
   335
  Reject_Tac1 (ist |> set_subst_false (form_arg, Tactic.result m'), ctxt, tac)
walther@59997
   336
          (*return from check_tac1*);
walther@59997
   337
"~~~~~ from fun check_tac1 \<longrightarrow>fun scan_dn1 \<longrightarrow>fun scan_dn1  \<longrightarrow>fun locate_input_tactic , return:"; val (Reject_Tac1 _) =
walther@59997
   338
  (Reject_Tac1 (ist |> set_subst_false (form_arg, Tactic.result m'), ctxt, tac));
walther@59997
   339
walther@59997
   340
(*/----- original before child of 7e314dd233fd -------------------------------------------------\* )
walther@59997
   341
    val (Program.Tac prog_tac, form_arg) = (*case*) check_leaf "locate" ctxt eval (get_subst ist) t (*of*);
walther@59844
   342
      val Not_Associated = (*case*) associate pt ctxt (tac, stac) (*of*);
walther@59718
   343
      val ORundef = (*case*) or (*of*);
walther@59920
   344
  val Applicable.No "norm_equation not applicable" =    
walther@59921
   345
      (*case*) Solve_Step.check (LItool.tac_from_prog pt (ThyC.get_theory "Isac_Knowledge") stac) (pt, p) (*of*);
walther@59670
   346
walther@59712
   347
   (Term_Val1 act_arg) (* return value *);
walther@59670
   348
walther@59670
   349
val Rewrite' ("PolyMinus", "tless_true", _, _, ("tausche_minus",_ (*"?b ist_monom \<Longrightarrow> ?a kleiner ?b \<Longrightarrow> ?b - ?a = - ?a + ?b"*)),
walther@59670
   350
   t, (res, asm)) = m;
walther@59686
   351
walther@59777
   352
if pstate2str ist =
walther@59852
   353
  "([\"\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
   354
  "- (8 * g) + (- 9 + 12 + 5 * e - 7 * e + (6 - 4) * f) + 10 * g, ORundef, true, false)"
walther@59670
   355
andalso
walther@59868
   356
  UnparseC.term t = "- (8 * g) + (- 9 + 12 + 5 * e - 7 * e + (6 - 4) * f) + 10 * g"
walther@59670
   357
andalso
walther@59868
   358
  UnparseC.term res = "- (8 * g) + (- 9 + 12 + 5 * e - 7 * e + (- 4 + 6) * f) + 10 * g"
walther@59670
   359
andalso
walther@59868
   360
  UnparseC.terms asm = "[\"4 kleiner 6\",\"6 ist_monom\"]"
walther@59670
   361
then () else error "locate_input_tactic Helpless, but applicable CHANGED";
walther@59997
   362
( *\----- original before child of 7e314dd233fd -------------------------------------------------/*)
wneuper@59562
   363
walther@59680
   364
walther@59792
   365
"----------- re-build: fun find_next_step, mini ------------------------------------------------";
walther@59792
   366
"----------- re-build: fun find_next_step, mini ------------------------------------------------";
walther@59792
   367
"----------- re-build: fun find_next_step, mini ------------------------------------------------";
walther@59792
   368
val fmz = ["Term (a + a ::real)", "normalform n_n"];
walther@59997
   369
val (dI',pI',mI') = ("Poly",["polynomial", "simplification"],["simplification", "for_polynomials"]);
walther@59734
   370
val (p,_,f,nxt,_,pt) = CalcTreeTEST [(fmz, (dI',pI',mI'))];
walther@59765
   371
(*[], Pbl*)val (_, ([(tac, _, _)], _, (pt, p))) = Step.do_next p ((pt, Pos.e_pos'), []);(*Model_Problem*)
walther@59792
   372
(*[], Pbl*)val (_, ([(tac, _, _)], _, (pt, p))) = Step.do_next p ((pt, Pos.e_pos'), []);(*Specify_Theory "Poly"*)
walther@59792
   373
(*[], Pbl*)val (_, ([(tac, _, _)], _, (pt, p))) = Step.do_next p ((pt, Pos.e_pos'), []);(*Specify_Problem ["polynomial", "simplification"]*)
walther@59792
   374
(*[], Met*)val (_, ([(tac, _, _)], _, (pt, p))) = Step.do_next p ((pt, e_pos'), []);(*Specify_Method  ["simplification", "for_polynomials"]*)
walther@59792
   375
(*1], Frm*)val (_, ([(tac, _, _)], _, (pt, p))) = Step.do_next p ((pt, e_pos'), []);(*Apply_Method ["simplification", "for_polynomials"]*)
walther@59792
   376
(*[1], Res*)val (_, ([(tac'''''_', _, _)], _, (pt'''''_', p'''''_'))) =
walther@59734
   377
walther@59792
   378
      Step.do_next p ((pt, e_pos'), []);(*Rewrite_Set "norm_Poly"*)
walther@59792
   379
(*//------------------ go into 1 ------------------------------------------------------------\\*)
walther@59792
   380
"~~~~~ fun do_next , args:"; val ((ip as (_, p_)), (ptp as (pt, p), tacis))
walther@59792
   381
  = (p, ((pt, e_pos'), []));
walther@59792
   382
  val pIopt = Ctree.get_pblID (pt, ip);
walther@59792
   383
    (*if*)  ip = ([], Res) (*else*);
walther@59792
   384
      val _ = (*case*) tacis (*of*);
walther@59792
   385
      val SOME _ = (*case*) pIopt (*of*);
walther@60017
   386
      (*if*) member op = [Pos.Pbl, Pos.Met] p_ (*else*);
walther@59734
   387
walther@59792
   388
val ("ok", ([(Rewrite_Set "norm_Poly", _, _)], _, (_, ([1], Res)))) =
walther@59792
   389
Step_Solve.do_next (pt, ip);
walther@59792
   390
"~~~~~ and do_next , args:"; val (ptp as (pt, pos as (p, p_))) =  (pt, ip);
walther@60154
   391
    (*if*) MethodC.id_empty = get_obj g_metID pt (par_pblobj pt p) (*else*);
walther@59734
   392
        val thy' = get_obj g_domID pt (par_pblobj pt p);
walther@59831
   393
	      val ((ist, ctxt), sc) = LItool.resume_prog thy' (p,p_) pt;
walther@59734
   394
walther@59878
   395
val Next_Step (_, _, Rewrite_Set' ("Poly", _, Rule_Set.Sequence {id = "norm_Poly", ...}, _, _)) =
walther@59792
   396
           LI.find_next_step sc (pt, pos) ist ctxt (*of*);
walther@59792
   397
"~~~~~ fun find_next_step , args:"; val ((Rule.Prog prog), (ptp as(pt, (p, _))), (Pstate ist), ctxt)
walther@59734
   398
  = (sc, (pt, pos), ist, ctxt);
walther@59734
   399
walther@59878
   400
val Accept_Tac (Rewrite_Set' ("Poly", _, Rule_Set.Sequence {id = "norm_Poly", ...}, _, _), _, _) =
walther@59792
   401
  (*case*) scan_to_tactic (prog, (ptp, ctxt)) (Pstate ist) (*of*);
walther@59792
   402
"~~~~~ fun scan_to_tactic , args:"; val ((prog, cc), (Pstate (ist as {path, ...})))
walther@59792
   403
  = ((prog, (ptp, ctxt)), (Pstate ist));
walther@59792
   404
  (*if*) path = [] (*then*);
walther@59734
   405
walther@59878
   406
val Accept_Tac (Rewrite_Set' ("Poly", _, Rule_Set.Sequence {id = "norm_Poly", ...}, _, _), _, _) =
walther@59792
   407
            scan_dn cc (trans_scan_dn ist) (Program.body_of prog);
walther@59792
   408
"~~~~~ fun scan_dn , args:"; val ((cc as (_, ctxt)), (ist as {eval, ...}), t)
walther@59792
   409
  = (cc, (trans_scan_dn ist), (Program.body_of prog));
walther@59792
   410
    (*if*) Tactical.contained_in t (*else*);
walther@59792
   411
      val (Program.Tac prog_tac, form_arg) = (*case*) LItool.check_leaf "next  " ctxt eval (get_subst ist) t (*of*);
walther@59734
   412
walther@59878
   413
val Accept_Tac (Rewrite_Set' ("Poly", _, Rule_Set.Sequence {id = "norm_Poly", ...}, _, _), _, _) =
walther@59799
   414
          check_tac cc ist (prog_tac, form_arg)  (*return from xxx*);
walther@59792
   415
"~~~~~ from fun scan_dn\<longrightarrow>fun scan_to_tactic\<longrightarrow>fun find_next_step, return:"; val (Accept_Tac (tac, ist, ctxt))
walther@59799
   416
  = (check_tac cc ist (prog_tac, form_arg));
walther@59734
   417
walther@59792
   418
    Next_Step (Pstate ist, Tactic.insert_assumptions tac ctxt, tac)  (*return from find_next_step*);
walther@59792
   419
"~~~~~ from fun find_next_step\<longrightarrow>and do_next\<longrightarrow>fun zzz, return:"; val (Next_Step (ist, ctxt, tac))
walther@59792
   420
  = (Next_Step (Pstate ist, Tactic.insert_assumptions tac ctxt, tac));
walther@59734
   421
walther@59792
   422
           LI.by_tactic tac (ist, Tactic.insert_assumptions tac ctxt) ptp  (*return from and do_next*);
walther@59792
   423
"~~~~~ from and do_next\<longrightarrow>fun do_next\<longrightarrow>toplevel, return:"; val  (_, ([(tac''''', _, _)], _, (pt''''', p''''')))
walther@59793
   424
  = (LI.by_tactic tac (ist, Tactic.insert_assumptions tac ctxt) ptp);
walther@59792
   425
(*\\------------------ end of go into 1 -----------------------------------------------------//*)
walther@59734
   426
walther@59792
   427
(*[], Res*)val (_, ([(tac''''', _, _)], _, (pt''''', p'''''))) =
walther@59792
   428
walther@59792
   429
      Step.do_next p'''''_' ((pt'''''_', Pos.e_pos'), []);(* Check_Postcond ["polynomial", "simplification"]*)
walther@59792
   430
(*//------------------ go into 2 ------------------------------------------------------------\\*)
walther@59792
   431
"~~~~~ fun do_next , args:"; val ((ip as (_, p_)), (ptp as (pt, p), tacis))
walther@59792
   432
  = (p''''', ((pt''''', e_pos'), []));
walther@59792
   433
  val pIopt = Ctree.get_pblID (pt, ip);
walther@59792
   434
    (*if*)  ip = ([], Res) (*else*);
walther@59792
   435
      val _ = (*case*) tacis (*of*);
walther@59792
   436
      val SOME _ = (*case*) pIopt (*of*);
walther@60017
   437
      (*if*) member op = [Pos.Pbl, Pos.Met] p_ (*else*);
walther@59792
   438
walther@59792
   439
val ("ok", ([(Check_Postcond ["polynomial", "simplification"], _, _)], _, (_, ([], Res)))) =
walther@59792
   440
Step_Solve.do_next (pt, ip);
walther@59792
   441
"~~~~~ and do_next , args:"; val (ptp as (pt, pos as (p, p_))) =  (pt, ip);
walther@60154
   442
    (*if*) MethodC.id_empty = get_obj g_metID pt (par_pblobj pt p) (*else*);
walther@59792
   443
        val thy' = get_obj g_domID pt (par_pblobj pt p);
walther@59831
   444
	      val ((ist, ctxt), sc) = LItool.resume_prog thy' (p,p_) pt;
walther@59792
   445
walther@59792
   446
  (** )val End_Program (ist, tac) = 
walther@59793
   447
 ( *case*) LI.find_next_step sc (pt, pos) ist ctxt (*of*);
walther@59792
   448
"~~~~~ fun find_next_step , args:"; val ((Rule.Prog prog), (ptp as(pt, (p, _))), (Pstate ist), ctxt)
walther@59792
   449
  = (sc, (pt, pos), ist, ctxt);
walther@59792
   450
walther@59792
   451
(*  val Term_Val (Const ("Groups.times_class.times", _) $ Free ("2", _) $ Free ("a", _))*)
walther@59792
   452
  (** )val Term_Val prog_result =
walther@59792
   453
 ( *case*) scan_to_tactic (prog, (ptp, ctxt)) (Pstate ist) (*of*);
walther@59792
   454
"~~~~~ fun scan_to_tactic , args:"; val ((prog, cc), (Pstate (ist as {path, ...})))
walther@59792
   455
  = ((prog, (ptp, ctxt)), (Pstate ist));
walther@59792
   456
  (*if*) path = [] (*else*);
walther@59792
   457
walther@59792
   458
           go_scan_up (prog, cc) (trans_scan_up ist |> set_found);
walther@59792
   459
"~~~~~ fun go_scan_up , args:"; val ((pcc as (sc, _)), (ist as {path, act_arg, found_accept, ...}))
walther@59792
   460
  = ((prog, cc), (trans_scan_up ist(*|> set_found !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! *)));
walther@59792
   461
    (*if*) path = [R] (*then*);
walther@59792
   462
      (*if*) found_accept = true (*then*);
walther@59792
   463
walther@59792
   464
      Term_Val act_arg (*return from go_scan_up*);
walther@59792
   465
"~~~~~ from fun go_scan_up\<longrightarrow>fun scan_to_tactic, return:"; val (Term_Val prog_result) = (Term_Val act_arg);
walther@59792
   466
walther@59792
   467
    Term_Val prog_result  (*return from scan_to_tactic*);
walther@59792
   468
"~~~~~ from fun scan_to_tactic\<longrightarrow>fun find_next_step, return:"; val (Term_Val prog_result) = (Term_Val prog_result);
walther@59838
   469
    val (true, p', _) = (*case*) parent_node pt p (*of*);
walther@59792
   470
              val (_, pblID, _) = get_obj g_spec pt p';
walther@59792
   471
walther@59843
   472
     End_Program (Pstate ist, Tactic.Check_Postcond' (pblID, prog_result))
walther@59792
   473
     (*return from find_next_step*);
walther@59792
   474
"~~~~~ from fun find_next_step\<longrightarrow>and do_next\<longrightarrow>fun zzz, return:"; val (End_Program (ist, tac))
walther@59843
   475
  = (End_Program (Pstate ist, Tactic.Check_Postcond' (pblID,prog_result)));
walther@59792
   476
      val _ = (*case*) tac (*of*);
walther@59792
   477
walther@59792
   478
val ("ok", ([(Check_Postcond ["polynomial", "simplification"], _, _)], _, (_, ([], Res))))
walther@59793
   479
   = LI.by_tactic tac (ist, ctxt) ptp (*return from and do_next*);
walther@59792
   480
"~~~~~ from and do_next\<longrightarrow>top level, return:"; val (_, ([(tac''''', _, _)], _, (pt''''', p''''')))
walther@59793
   481
  = (LI.by_tactic tac (ist, ctxt) ptp);
walther@59792
   482
(*\\------------------ end of go into 2 -----------------------------------------------------//*)
walther@59792
   483
walther@59792
   484
(*[], Und*)val (msg, ([], _, (pt, p))) = Step.do_next p''''' ((pt''''', Pos.e_pos'), []);(**)
walther@59792
   485
walther@59983
   486
Test_Tool.show_pt_tac pt; (*[
walther@59792
   487
([], Frm), Simplify (a + a)
walther@59997
   488
. . . . . . . . . . Apply_Method ["simplification", "for_polynomials"],
walther@59792
   489
([1], Frm), a + a
walther@59792
   490
. . . . . . . . . . Rewrite_Set "norm_Poly",
walther@59792
   491
([1], Res), 2 * a
walther@59997
   492
. . . . . . . . . . Check_Postcond ["polynomial", "simplification"],
walther@59792
   493
([], Res), 2 * a]*)
walther@59792
   494
walther@59792
   495
(*/--- final test ---------------------------------------------------------------------------\\*)
walther@59734
   496
val (res, asm) = (get_obj g_result pt (fst p));
walther@59868
   497
if UnparseC.term res = "2 * a" andalso map UnparseC.term asm = []
walther@59792
   498
andalso p = ([], Und) andalso msg = "end-of-calculation"
walther@59792
   499
andalso pr_ctree pr_short pt = ".    ----- pblobj -----\n1.   a + a\n"
walther@59792
   500
then 
walther@59792
   501
  case tac''''' of Check_Postcond ["polynomial", "simplification"] => () 
walther@59792
   502
  | _ => error "re-build: fun find_next_step, mini 1"
walther@59792
   503
else error "re-build: fun find_next_step, mini 2"
wneuper@59575
   504
wneuper@59575
   505
walther@59783
   506
"----------- re-build: fun locate_input_term ---------------------------------------------------";
walther@59783
   507
"----------- re-build: fun locate_input_term ---------------------------------------------------";
walther@59783
   508
"----------- re-build: fun locate_input_term ---------------------------------------------------";
walther@59795
   509
(*cp from inform.sml
walther@59795
   510
 ----------- appendFormula: on Res + late deriv ------------------------------------------------*)
walther@59997
   511
val fmz = ["equality (x+1=(2::real))", "solveFor x", "solutions L"];
walther@59997
   512
val (dI',pI',mI') = ("Test", ["sqroot-test", "univariate", "equation", "test"],
walther@59997
   513
   ["Test", "squ-equ-test-subpbl1"]);
walther@59795
   514
val (p,_,f,nxt,_,pt) = CalcTreeTEST [(fmz, (dI',pI',mI'))];
walther@59795
   515
val (p,_,f,nxt,_,pt) = me nxt p [] pt;
walther@59795
   516
val (p,_,f,nxt,_,pt) = me nxt p [] pt;
walther@59795
   517
val (p,_,f,nxt,_,pt) = me nxt p [] pt;
walther@59795
   518
val (p,_,f,nxt,_,pt) = me nxt p [] pt;
walther@59795
   519
val (p,_,f,nxt,_,pt) = me nxt p [] pt;
walther@59795
   520
val (p,_,f,nxt,_,pt) = me nxt p [] pt;
walther@59795
   521
(*[], Met*)val (p,_,f,nxt,_,pt) = me nxt p [] pt; (*Apply_Method ["Test", "squ-equ-test-subpbl1"]*);
walther@59783
   522
walther@59795
   523
(*[1], Frm*)val (p,_,f,nxt,_,pt) = me nxt p [] pt;(*Rewrite_Set "norm_equation"*)
walther@59795
   524
(*+*)if f2str f = "x + 1 = 2" then () else error "locate_input_term at ([1], Frm) CHANGED";
walther@59783
   525
walther@59795
   526
(*[1], Res*)val (p,_,f,nxt,_,pt) = me nxt p [] pt;(*Rewrite_Set "Test_simplify"*)
walther@59795
   527
(*+*)if f2str f = "x + 1 + -1 * 2 = 0" then () else error "locate_input_term at ([1], Frm) CHANGED";
walther@59783
   528
walther@59983
   529
Test_Tool.show_pt_tac pt; (*[
walther@59795
   530
([], Frm), solve (x + 1 = 2, x)
walther@59997
   531
. . . . . . . . . . Apply_Method ["Test", "squ-equ-test-subpbl1"],
walther@59795
   532
([1], Frm), x + 1 = 2
walther@59795
   533
. . . . . . . . . . Rewrite_Set "norm_equation",
walther@59795
   534
([1], Res), x + 1 + -1 * 2 = 0             ///Check_Postcond..ERROR*)
walther@59795
   535
walther@59797
   536
(*//---------- appendFormula 1 "x = 1" \<longrightarrow> Step_Solve.inform \<longrightarrow> LI.locate_input_term ----------\\*)
walther@59868
   537
"~~~~~ fun appendFormula , args:"; val ((*cI, *) ifo: TermC.as_string) = ((**) "x = 1");
walther@59795
   538
    val cs = (*get_calc cI*) ((pt, p), [(*nxt, nxt_, (pos, (ist, ctxt))*)])
walther@59795
   539
    val pos = (*get_pos cI 1*) p
walther@59795
   540
walther@59795
   541
(*+*)val ptp''''' = (pt, p);
walther@59795
   542
(*+*)if snd ptp''''' = ([1], Res) then () else error "old_cs changed";
walther@59983
   543
(*+*)Test_Tool.show_pt_tac pt; (*[
walther@59795
   544
(*+*)([], Frm), solve (x + 1 = 2, x)
walther@59997
   545
(*+*). . . . . . . . . . Apply_Method ["Test", "squ-equ-test-subpbl1"],
walther@59795
   546
(*+*)([1], Frm), x + 1 = 2
walther@59795
   547
(*+*). . . . . . . . . . Rewrite_Set "norm_equation",
walther@59795
   548
(*+*)([1], Res), x + 1 + -1 * 2 = 0      ///Check_Postcond*)
walther@59795
   549
walther@59798
   550
  val ("ok", cs' as (_, _, ptp')) =
walther@59795
   551
    (*case*) Step.do_next pos cs (*of*);
walther@59795
   552
walther@59795
   553
val ("ok", (_(*use in DG !!!*), [], ptp''''' as (pt''''', p'''''))) = (*case*)
walther@59798
   554
     Step_Solve.by_term ptp' (encode ifo) (*of*);
walther@59798
   555
"~~~~~ fun Step_Solve.by_term , args:"; val ((pt, pos as (p, _)), istr)
walther@59798
   556
  = (ptp', (encode ifo));
walther@59795
   557
  val SOME f_in =
walther@59881
   558
    (*case*) TermC.parse (ThyC.get_theory "Isac_Knowledge") istr (*of*);
walther@59795
   559
  	  val f_in = Thm.term_of f_in
walther@59795
   560
      val pos_pred = lev_back(*'*) pos
walther@59795
   561
  	  val f_pred = Ctree.get_curr_formula (pt, pos_pred);
walther@59795
   562
  	  val f_succ = Ctree.get_curr_formula (pt, pos);
walther@59795
   563
      (*if*) f_succ = f_in (*else*);
walther@59795
   564
  val NONE =
walther@59982
   565
        (*case*) CAS_Cmd.input f_in (*of*);
walther@59795
   566
walther@59795
   567
(*old* )     val (_, _, metID) = get_obj g_spec pt (par_pblobj pt p)
walther@60154
   568
(*old*)     val {scr = prog, ...} = MethodC.from_store metID
walther@59807
   569
(*old*)     val istate = get_istate_LI pt pos
walther@59795
   570
(*old*)     val ctxt = get_ctxt pt pos
walther@59795
   571
  val LI.Found_Step (cstate'''''_', _(*istate*), _(*ctxt*)) = (*case*)
walther@59795
   572
        LI.locate_input_term prog (pt, pos) istate ctxt f_in (*of*);
walther@59795
   573
"~~~~~ fun locate_input_term , args:"; val ((Rule.Prog _),  ((pt, pos) : Calc.T), (_ : Istate.T), (_ : Proof.context), tm)
walther@59795
   574
  = (prog, (pt, pos), istate, ctxt, f_in);
walther@59795
   575
( *old*)
walther@59795
   576
walther@59795
   577
(*NEW*) LI.locate_input_term (pt, pos) f_in (*of*);
walther@59795
   578
"~~~~~ fun locate_input_term , args:"; val ((pt, pos), tm) = ((pt, pos), f_in);
walther@59795
   579
   		val pos_pred = Pos.lev_back' pos (*f_pred ---"step pos cs"---> f_succ in appendFormula*)
walther@59795
   580
walther@59795
   581
  val ("ok", (_, _, cstate as (pt', pos'))) =
walther@59795
   582
   		(*case*) compare_step ([], [], (pt, pos_pred)) tm (*of*);
walther@59795
   583
walther@59795
   584
(*old* )
walther@59807
   585
    Found_Step (cstate, get_istate_LI pt' pos', get_ctxt pt' pos')  (*return from locate_input_term*);
walther@59795
   586
( *old*)
walther@59795
   587
(*NEW*)     Found_Step cstate (*return from locate_input_term*);
walther@59795
   588
       (*LI.Found_Step ( *)cstate(*, _(*istate*), _(*ctxt*))( *return from locate_input_term*);
walther@59797
   589
"~~~~~ from fun locate_input_term\<longrightarrow>fun Step_Solve.by_term, return:"; val ("ok", (_(*use in DG !!!*), c, ptp as (_, p)))
walther@59795
   590
  = (("ok" , ([], [], cstate (* already contains istate, ctxt *))));
walther@59795
   591
walther@59797
   592
    ("ok", ((*_ use in DG !!!,*) c, ptp(* as (_*), p))(*)*)(*return from Step_Solve.by_term*);
walther@59797
   593
"~~~~~ from fun Step_Solve.by_term\<longrightarrow>(fun appendFormula)!toplevel, return:"; val ("ok", (_(*use in DG !!!*), [], ptp''''' as (pt''''', p''''')))
walther@59795
   594
  = ("ok", ([], [], ptp));
walther@59795
   595
walther@59795
   596
(*fun me requires nxt...*)
walther@59795
   597
    Step.do_next p''''' (ptp''''', []);
walther@59795
   598
  val ("ok", ([(nxt'''''_' as Check_Postcond ["LINEAR", "univariate", "equation", "test"], _, _)], _,
walther@59795
   599
    (pt'''''_', p'''''_'))) = Step.do_next p''''' (ptp''''', [])
walther@59797
   600
(*\\---------- appendFormula 1 "x = 1" \<longrightarrow> Step_Solve.inform \<longrightarrow> LI.locate_input_term ----------//*)
walther@59795
   601
walther@59797
   602
(*//----- REPLACED BY appendFormula 1 "x = 1" \<longrightarrow> Step_Solve.inform \<longrightarrow> LI.locate_input_term -----\\* )
walther@59795
   603
 (*[2], Res*)val (p,_,f,nxt,_,pt) = me nxt p [] pt; (*nxt = Subproblem ("Test", ["LINEAR", "univariate", "equation", "test"])*)
walther@59795
   604
 (*[3], Pbl*)val (p,_,f,nxt,_,pt) = me nxt p [] pt; (*nxt = Model_Problem*)
walther@59795
   605
 (*[3], Pbl*)val (p,_,f,nxt,_,pt) = me nxt p [] pt; (*nxt = Add_Given "equality (-1 + x = 0)"*)
walther@59795
   606
 (*[3], Pbl*)val (p,_,f,nxt,_,pt) = me nxt p [] pt; (*nxt = Add_Given "solveFor x"*)
walther@59795
   607
 (*[3], Pbl*)val (p,_,f,nxt,_,pt) = me nxt p [] pt; (*nxt = Add_Find "solutions x_i"*)
walther@59795
   608
 (*[3], Pbl*)val (p,_,f,nxt,_,pt) = me nxt p [] pt; (*nxt = Specify_Theory "Test"*)
walther@59795
   609
 (*[3], Pbl*)val (p,_,f,nxt,_,pt) = me nxt p [] pt; (*nxt = Specify_Problem ["LINEAR", "univariate", "equation", "test"]*)
walther@59795
   610
 (*[3], Pbl*)val (p,_,f,nxt,_,pt) = me nxt p [] pt; (*nxt = Specify_Method ["Test", "solve_linear"]*)
walther@59795
   611
 (*[3], Met*)val (p,_,f,nxt,_,pt) = me nxt p [] pt; (*nxt = Apply_Method ["Test", "solve_linear"]*)
walther@59795
   612
 (*[3, 1], Frm*)val (p,_,f,nxt,_,pt) = me nxt p [] pt; (*nxt = Rewrite_Set_Inst (["(''bdv'', x)"], "isolate_bdv")*)
walther@59795
   613
 (*[3, 1], Res*)val (p,_,f,nxt,_,pt) = me nxt p [] pt; (*nxt = Rewrite_Set "Test_simplify"*)
walther@59795
   614
 (*[3, 2], Res*)val (p,_,f,nxt,_,pt) = me nxt p [] pt; (*nxt = Check_Postcond ["LINEAR", "univariate", "equation", "test"]*)
walther@59797
   615
( *\\----- REPLACED BY appendFormula 1 "x = 1" \<longrightarrow> Step_Solve.inform \<longrightarrow> LI.locate_input_term -----//*)
walther@59795
   616
walther@59795
   617
 (*[3], Res*)val (p,_,f,nxt,_,pt) = me nxt'''''_' p'''''_' [] pt'''''_'; (*nxt = Check_elementwise "Assumptions"*)
walther@59795
   618
 (*[4], Res*)val (p,_,f,nxt,_,pt) = me nxt p [] pt; (*nxt = Check_Postcond ["sqroot-test", "univariate", "equation", "test"]*)
walther@59795
   619
 (*[], Res*)val (p,_,f,nxt,_,pt) = me nxt p [] pt; (*nxt = End_Proof'*)
walther@59795
   620
walther@59795
   621
(*/--- final test ---------------------------------------------------------------------------\\*)
walther@59795
   622
if p = ([], Res) andalso f2str f = "[x = 1]" andalso pr_ctree pr_short pt =
walther@59795
   623
   ".    ----- pblobj -----\n" ^
walther@59795
   624
   "1.   x + 1 = 2\n" ^
walther@59795
   625
   "2.   x + 1 + -1 * 2 = 0\n" ^
walther@59795
   626
   "3.    ----- pblobj -----\n" ^
walther@59795
   627
   "3.1.   -1 + x = 0\n" ^
walther@59795
   628
   "3.2.   x = 0 + -1 * -1\n" ^
walther@59795
   629
   "3.2.1.   x = 0 + -1 * -1\n" ^
walther@59795
   630
   "3.2.2.   x = 0 + 1\n" (*ATTENTION: see complete Calc below*)
walther@59795
   631
then case nxt of End_Proof' => () | _ => error "re-build: fun locate_input_term CHANGED 1"
walther@59795
   632
else error "re-build: fun locate_input_term CHANGED 2";
walther@59795
   633
walther@59983
   634
Test_Tool.show_pt_tac pt; (*[
walther@59795
   635
([], Frm), solve (x + 1 = 2, x)
walther@59997
   636
. . . . . . . . . . Apply_Method ["Test", "squ-equ-test-subpbl1"],
walther@59795
   637
([1], Frm), x + 1 = 2
walther@59795
   638
. . . . . . . . . . Rewrite_Set "norm_equation",
walther@59795
   639
([1], Res), x + 1 + -1 * 2 = 0
walther@59795
   640
. . . . . . . . . . Rewrite_Set "Test_simplify",
walther@59795
   641
([2], Res), -1 + x = 0
walther@59997
   642
. . . . . . . . . . Subproblem (Test, ["LINEAR", "univariate", "equation", "test"]),
walther@59795
   643
([3], Pbl), solve (-1 + x = 0, x)
walther@59997
   644
. . . . . . . . . . Apply_Method ["Test", "solve_linear"],
walther@59795
   645
([3,1], Frm), -1 + x = 0
walther@59795
   646
. . . . . . . . . . Rewrite_Set_Inst ([(''bdv'', x)], "isolate_bdv"),
walther@59795
   647
([3,1], Res), x = 0 + -1 * -1
walther@59795
   648
. . . . . . . . . . Derive Test_simplify,
walther@59795
   649
([3,2,1], Frm), x = 0 + -1 * -1
walther@59795
   650
. . . . . . . . . . Rewrite ("#: -1 * -1 = 1", "-1 * -1 = 1"),
walther@59795
   651
([3,2,1], Res), x = 0 + 1
walther@59795
   652
. . . . . . . . . . Rewrite ("radd_0", "0 + ?k = ?k"),
walther@59795
   653
([3,2,2], Res), x = 1
walther@59846
   654
. . . . . . . . . . Tactic.input_to_string not impl. for ?!,
walther@59795
   655
([3,2], Res), x = 1
walther@59997
   656
. . . . . . . . . . Check_Postcond ["LINEAR", "univariate", "equation", "test"],
walther@59795
   657
([3], Res), [x = 1]
walther@59997
   658
. . . . . . . . . . Check_Postcond ["sqroot-test", "univariate", "equation", "test"],
walther@59795
   659
([], Res), [x = 1]]*)