test/Tools/isac/MathEngine/mathengine-stateless.sml
author wneuper <walther.neuper@jku.at>
Mon, 19 Apr 2021 15:02:00 +0200
changeset 60230 0ca0f9363ad3
parent 60217 1d9fee958a46
child 60242 73ee61385493
permissions -rw-r--r--
long identifiers for occurences in test/../termC.sml
walther@59820
     1
(* Title:  tests for MathEngine/mathengine-stateless.sml
walther@59820
     2
   Author: Walther Neuper 2000, 2006, 2020
neuper@37906
     3
   (c) due to copyright terms
neuper@55460
     4
neuper@55460
     5
theory Test_Some imports Build_Thydata begin 
neuper@55460
     6
ML {* KEStore_Elems.set_ref_thy @{theory};
neuper@55460
     7
  fun autoCalculate' cI auto = autoCalculate cI auto |> Future.join *}
wenzelm@60217
     8
ML_file "$ISABELLE_ISAC_TEST/Tools/isac/Interpret/mathengine.sml"
neuper@37906
     9
*)
neuper@38065
    10
"--------------------------------------------------------";
neuper@38065
    11
"table of contents --------------------------------------";
neuper@38065
    12
"--------------------------------------------------------";
walther@60230
    13
"----------- change to TermC.parse ctxt -----------------------";
neuper@38065
    14
"----------- debugging setContext..pbl_ -----------------";
neuper@38065
    15
"----------- tryrefine ----------------------------------";
t@42225
    16
"----------- search for Or_to_List ----------------------";
neuper@42279
    17
"----------- check thy in CalcTreeTEST ------------------";
walther@59875
    18
"----------- identified error in fun getTactic, ThmC.string_of_thm ---------------";
neuper@55486
    19
"----------- improved fun getTactic for interSteps and numeral calculations --";
neuper@38065
    20
"--------------------------------------------------------";
neuper@38065
    21
"--------------------------------------------------------";
neuper@38065
    22
"--------------------------------------------------------";
neuper@37906
    23
walther@60230
    24
"----------- change to TermC.parse ctxt -----------------------";
walther@60230
    25
"----------- change to TermC.parse ctxt -----------------------";
walther@60230
    26
"----------- change to TermC.parse ctxt -----------------------";
neuper@41940
    27
"===== start calculation: from problem description (fmz) to origin";
walther@59997
    28
val fmz = ["realTestGiven (((1+2)*4/3)^^^2)", "realTestFind s"];
neuper@41940
    29
val (thyID, pblID, metID) =
neuper@41940
    30
  ("Test", ["calculate", "test"], ["Test", "test_calculate"]);
walther@59679
    31
(*======= Isabelle2013-2 --> Isabelle2014: unclear, why this test ever run =====================*)
neuper@37906
    32
neuper@38065
    33
"----------- debugging setContext..pbl_ -----------------";
neuper@38065
    34
"----------- debugging setContext..pbl_ -----------------";
neuper@38065
    35
"----------- debugging setContext..pbl_ -----------------";
s1210629013@55445
    36
reset_states ();
walther@59997
    37
CalcTree [(["equality (x+1=(2::real))", "solveFor x", "solutions L"], 
walther@59997
    38
  ("Test", ["sqroot-test", "univariate", "equation", "test"],
walther@59997
    39
   ["Test", "squ-equ-test-subpbl1"]))];
neuper@37906
    40
Iterator 1;
neuper@37906
    41
moveActiveRoot 1; modelProblem 1;
neuper@37906
    42
neuper@37906
    43
val pos as (p,_) = ([],Pbl);
neuper@37906
    44
val guh = "pbl_equ_univ";
walther@60010
    45
(********************************)checkContext 1 pos guh;(**************************************)
walther@60010
    46
val ((pt, ([], Pbl)), []) = get_calc 1;
neuper@37906
    47
val pp = par_pblobj pt p;
walther@59974
    48
val keID = Ptool.guh2kestoreID guh;
walther@60010
    49
case context_pbl keID pt pp of (true, ["univariate", "equation"], _, _, _) => ()
neuper@38031
    50
| _ => error "mathengine.sml: context_pbl .. pbl_equ_univ checked";
neuper@37906
    51
walther@59903
    52
case get_obj g_spec pt p of (_, ["empty_probl_id"], _) => ()
neuper@38031
    53
| _ => error "mathengine.sml: context_pbl .. pbl still empty";
walther@60010
    54
(********************************)setContext 1 pos guh;(***************************************)
walther@60010
    55
val ((pt, ([], Pbl)), []) = get_calc 1;
walther@59997
    56
case get_obj g_spec pt p of (_, ["univariate", "equation"], _) => ()
neuper@38031
    57
| _ => error "mathengine.sml: context_pbl .. pbl set";
neuper@37906
    58
neuper@37906
    59
neuper@37906
    60
setContext 1 pos "met_eq_lin";
neuper@37906
    61
val ((pt,_),_) = get_calc 1;
walther@60010
    62
case get_obj g_spec pt p of
walther@60014
    63
  ("empty_thy_id", ["univariate", "equation"], ["LinEq", "solve_lineq_equation"]) => ()
neuper@38031
    64
| _ => error "mathengine.sml: context_pbl .. pbl set";
neuper@37906
    65
neuper@37906
    66
neuper@38065
    67
"----------- tryrefine ----------------------------------";
neuper@38065
    68
"----------- tryrefine ----------------------------------";
neuper@38065
    69
"----------- tryrefine ----------------------------------";
s1210629013@55445
    70
reset_states ();
neuper@37906
    71
CalcTree [(["equality (x/(x^2 - 6*x+9) - 1/(x^2 - 3*x) =1/x)", 
neuper@37906
    72
	    "solveFor x", "solutions L"],
walther@59997
    73
	   ("RatEq",["univariate", "equation"],["no_met"]))];
neuper@37906
    74
Iterator 1;
wneuper@59248
    75
moveActiveRoot 1; autoCalculate 1 CompleteCalc;
neuper@37906
    76
neuper@37906
    77
refineProblem 1 ([1],Res) "pbl_equ_univ" 
neuper@37906
    78
(*gives "pbl_equ_univ_rat" correct*);
neuper@37906
    79
walther@59997
    80
refineProblem 1 ([1],Res) (Ptool.pblID2guh ["LINEAR", "univariate", "equation"])
neuper@38065
    81
(*gives "pbl_equ_univ_lin" incorrect*);
neuper@38065
    82
neuper@42394
    83
"--------- search for Or_to_List ------------------------";
neuper@42394
    84
"--------- search for Or_to_List ------------------------";
t@42225
    85
"--------- search for Or_to_List ------------------------";
walther@59997
    86
val fmz = ["equality (x^^^2 + 4*x + 5 = (2::real))", "solveFor x", "solutions L"];
walther@59997
    87
val (dI',pI',mI') = ("Isac_Knowledge", ["univariate", "equation"], ["no_met"])
t@42225
    88
val (p,_,f,nxt,_,pt) = CalcTreeTEST [(fmz, (dI',pI',mI'))];
t@42225
    89
val (p,_,f,nxt,_,pt) = me nxt p [] pt;
t@42225
    90
val (p,_,f,nxt,_,pt) = me nxt p [] pt;
t@42225
    91
val (p,_,f,nxt,_,pt) = me nxt p [] pt;
t@42225
    92
val (p,_,f,nxt,_,pt) = me nxt p [] pt;
t@42225
    93
val (p,_,f,nxt,_,pt) = me nxt p [] pt;
t@42225
    94
val (p,_,f,nxt,_,pt) = me nxt p [] pt;
t@42225
    95
val (p,_,f,nxt,_,pt) = me nxt p [] pt;
t@42225
    96
val (p,_,f,nxt,_,pt) = me nxt p [] pt;
t@42225
    97
val (p,_,f,nxt,_,pt) = me nxt p [] pt;
t@42225
    98
val (p,_,f,nxt,_,pt) = me nxt p [] pt; (*nxt = ("Subproblem"*)
t@42225
    99
val (p,_,f,nxt,_,pt) = me nxt p [] pt;
t@42225
   100
val (p,_,f,nxt,_,pt) = me nxt p [] pt;
t@42225
   101
val (p,_,f,nxt,_,pt) = me nxt p [] pt;
t@42225
   102
val (p,_,f,nxt,_,pt) = me nxt p [] pt;
t@42225
   103
val (p,_,f,nxt,_,pt) = me nxt p [] pt;
t@42225
   104
val (p,_,f,nxt,_,pt) = me nxt p [] pt;
t@42225
   105
val (p,_,f,nxt,_,pt) = me nxt p [] pt;
t@42225
   106
val (p,_,f,nxt,_,pt) = me nxt p [] pt;
t@42225
   107
val (p,_,f,nxt,_,pt) = me nxt p [] pt;
t@42225
   108
val (p,_,f,nxt,_,pt) = me nxt p [] pt;
walther@59749
   109
"~~~~~ fun me, args:"; val (tac, (p:pos'), (_:NEW(*remove*)), (pt:ctree)) = 
t@42225
   110
                            (nxt, p, [], pt);
walther@59804
   111
val ("ok", (_, _, ptp))  = Step.by_tactic tac (pt,p)
t@42225
   112
val (pt, p) = ptp;
walther@59981
   113
"~~~~~ fun Step.do_next, args:"; val (((ip as (_,p_)):pos'), ((ptp as (pt,p), tacis):Calc.state_pre)) =
t@42225
   114
                          (p, ((pt, e_pos'),[]));
t@42225
   115
val pIopt = get_pblID (pt,ip);
t@42225
   116
ip = ([],Res); (*false*)
t@42225
   117
ip = p; (*false*)
walther@60017
   118
member op = [Pbl,Met] p_; (*false*)
walther@59760
   119
"~~~~~ fun do_next, args:"; val (ptp as (pt, pos as (p,p_))) = (pt,ip);
walther@60154
   120
MethodC.id_empty = get_obj g_metID pt (par_pblobj pt p); (*false*)
t@42225
   121
val thy' = get_obj g_domID pt (par_pblobj pt p);
walther@59831
   122
val ((ist, ctxt), sc) = resume_prog thy' (p,p_) pt;
walther@59841
   123
walther@59791
   124
val Next_Step (istate, ctxt, tac) = LI.find_next_step sc (pt,pos) ist ctxt; (*WAS Empty_Tac_: tac_*)
walther@59734
   125
case tac of Or_to_List' _ => ()
t@42225
   126
| _ => error "Or_to_List broken ?"
akargl@42108
   127
neuper@42394
   128
neuper@42279
   129
"----------- check thy in CalcTreeTEST ------------------";
neuper@42279
   130
"----------- check thy in CalcTreeTEST ------------------";
neuper@42279
   131
"----------- check thy in CalcTreeTEST ------------------";
neuper@42279
   132
"WN1109 with Inverse_Z_Transform.thy when starting tests with CalcTreeTEST \n" ^
neuper@42279
   133
"we got the message: ME_Isa: thy 'Build_Inverse_Z_Transform' not in system \n" ^
neuper@42279
   134
"Below there are the steps which found out the reason: \n" ^
neuper@42279
   135
"store_pbt mistakenly stored that theory.";
wneuper@59592
   136
val ctxt = Proof_Context.init_global @{theory Isac_Knowledge};
neuper@42279
   137
val SOME t = parseNEW ctxt "filterExpression (X  = 3 / (z - 1/4 + -1/8 * (1/(z::real))))";
neuper@42279
   138
val SOME t = parseNEW ctxt "stepResponse (x[n::real]::bool)";
akargl@42108
   139
wneuper@59550
   140
val fmz = ["filterExpression (X  = 3 / (z - 1/4 + -1/8 * (1/(z::real))))", "boundVariable z",
neuper@42279
   141
  "stepResponse (x[n::real]::bool)"];
wneuper@59592
   142
val (dI,pI,mI) = ("Isac_Knowledge", ["Inverse", "Z_Transform", "SignalProcessing"], 
walther@59997
   143
  ["SignalProcessing", "Z_Transform", "Inverse"]);
neuper@42279
   144
neuper@42279
   145
val (p,_,fb,nxt,_,pt)  = CalcTreeTEST [(fmz, (dI,pI,mI))]; 
neuper@42279
   146
(*WAS ME_Isa: thy 'Build_Inverse_Z_Transform' not in system*)
neuper@42279
   147
walther@59941
   148
"~~~~~ T fun CalcTreeTEST, args:"; val [(fmz, sp):Formalise.T] = [(fmz, (dI,pI,mI))];
neuper@42279
   149
"~~~~~ fun nxt_specify_init_calc, args:"; val (fmz, (dI, pI, mI)) = (fmz, sp);
walther@59881
   150
	      val thy = ThyC.get_theory dI;
neuper@42279
   151
    mI = ["no_met"]; (*false*)
walther@59970
   152
	          val pors = Problem.from_store pI |> #ppc |> O_Model.init fmz thy;
walther@59952
   153
            val pctxt = ContextC.initialise' thy fmz;
walther@59970
   154
	      val {cas, ppc, thy=thy',...} = Problem.from_store pI; (*take dI from _refined_ pbl*)
neuper@42279
   155
	"tracing bottom up"; Context.theory_name thy' = "Build_Inverse_Z_Transform"; (*WAS true*)
walther@59918
   156
      val dI = Context.theory_name (ThyC.parent_of thy thy');
neuper@42279
   157
"tracing bottom up"; dI = "Build_Inverse_Z_Transform"; (*WAS true*)
neuper@42279
   158
    cas = NONE; (*true*)
neuper@42279
   159
	      val hdl = pblterm dI pI;
walther@59846
   160
        val (pt, _) = cappend_problem e_ctree [] (Istate.empty, pctxt) (fmz, (dI, pI, mI))
walther@59846
   161
				  (pors, (dI, pI, mI), hdl, ContextC.empty)
walther@59821
   162
;
walther@59806
   163
"~~~~~ fun Step_Specify.by_tactic_input, args:"; val ((tac as Model_Problem), (pt, pos as (p,p_))) = (Model_Problem, (pt, ([], Pbl)));
neuper@42279
   164
      val PblObj {origin = (oris, ospec, _), probl, spec, ctxt, ...} = get_obj I pt p;
neuper@42279
   165
"tracing bottom up"; #1(ospec) = "Build_Inverse_Z_Transform"; (*WAS true*)
neuper@42279
   166
walther@59983
   167
"~~~~~ fun References.select, args:"; val ((odI, opI, omI), (dI, pI, mI)) = (ospec, spec);
walther@59879
   168
dI = ThyC.id_empty; (*true*)
neuper@42279
   169
odI = "Build_Inverse_Z_Transform"; (*true*)
walther@59903
   170
dI = "empty_thy_id"; (*true*)
walther@59983
   171
"~~~~~ after fun References.select:";
walther@59983
   172
      val (dI, pI, mI) = References.select ospec spec;
neuper@42279
   173
"tracing bottom up"; dI = "Build_Inverse_Z_Transform"; (*WAS true*)
walther@59881
   174
      val thy = ThyC.get_theory dI; (*caused ME_Isa: thy 'Build_Inverse_Z_Transform' not in system*)
neuper@42279
   175
walther@59875
   176
"----------- identified error in fun getTactic, ThmC.string_of_thm ---------------";
walther@59875
   177
"----------- identified error in fun getTactic, ThmC.string_of_thm ---------------";
walther@59875
   178
"----------- identified error in fun getTactic, ThmC.string_of_thm ---------------";
neuper@55482
   179
reset_states ();
neuper@55482
   180
CalcTree [(["equality (x+1=(2::real))", "solveFor x", "solutions L"],
walther@59997
   181
  ("Test",["sqroot-test", "univariate", "equation", "test"],["Test", "squ-equ-test-subpbl1"]))];
neuper@55482
   182
moveActiveRoot 1;
wneuper@59248
   183
autoCalculate 1 CompleteCalcHead;
walther@59747
   184
autoCalculate 1 (Steps 1);
walther@59747
   185
autoCalculate 1 (Steps 1);
walther@59747
   186
autoCalculate 1 (Steps 1);
neuper@55482
   187
getTactic 1 ([1],Frm); (*<RULESET> norm_equation </RULESET>*)
neuper@55482
   188
interSteps 1 ([1],Res);
neuper@55482
   189
"~~~~~ fun interSteps, args:"; val (cI, ip) = (1, ([1],Res));
neuper@55482
   190
val ((pt,p), tacis) = get_calc cI;
neuper@55482
   191
(not o is_interpos) ip = false;
neuper@55482
   192
val ip' = lev_pred' pt ip;
walther@59833
   193
"~~~~~ fun go, args:"; val (pt, (pos as (p,p_):pos')) = (pt, ip);
neuper@55482
   194
(*         ^^^^^^^^^ not in test/../ *)
neuper@55482
   195
    val nd = get_nd pt p
neuper@55482
   196
    val cn = children nd;
neuper@55482
   197
null cn = false;
neuper@55482
   198
(is_rewset o (get_obj g_tac nd)) [(*root of nd*)] = true;
neuper@55482
   199
"~~~~~ fun detailrls, args:"; val (pt, (pos as (p,p_):pos')) = (pt, pos);
neuper@55482
   200
(*         ^^^^^^^^^ only once in test/../solve.sml*)
neuper@55482
   201
    val t = get_obj g_form pt p
neuper@55482
   202
	  val tac = get_obj g_tac pt p
neuper@55482
   203
	  val rls = (assoc_rls o rls_of) tac
neuper@55482
   204
    val ctxt = get_ctxt pt pos
walther@59851
   205
(*rls = Rule_Set.Repeat {calc = [], erls = ...*)
walther@59935
   206
          val is = Istate.init_detail tac t
wneuper@59583
   207
	        (*TODO.WN060602 Pstate (["(t_, Problem (Isac,[equation,univar]))"]
neuper@55482
   208
				    is wrong for simpl, but working ?!? *)
walther@60154
   209
	        val tac_ = Apply_Method' (MethodC.id_empty(*WN0402: see Step.add !?!*), SOME t, is, ctxt)
neuper@55482
   210
	        val pos' = ((lev_on o lev_dn) p, Frm)
walther@59881
   211
	        val thy = ThyC.get_theory "Isac_Knowledge"
walther@59932
   212
	        val (_,_,_,pt') = (*implicit Take*)Step.add tac_ (is, ctxt) (pt, pos');
neuper@55482
   213
	        (*val (_,_,(pt'',_)) = *)complete_solve CompleteSubpbl [] (pt',pos');
neuper@55482
   214
	        (*                   ^^^^^^^^^^^^^^ in test/../mathengine.sml*)
neuper@55482
   215
	        (* in pt'': tac = Rewrite ("rnorm_equation_add", "Test.rnorm_equation_add")},
neuper@55482
   216
                                                           ^^^^^^^^^^^^^^^^^^^^^^^^^^^*)
walther@59672
   217
"~~~~~ fun complete_solve , args:"; val (auto, c, (ptp as (_, p as (_,p_)): ctree * pos')) =
neuper@55482
   218
  (CompleteSubpbl, [], (pt',pos'));
neuper@55482
   219
p = ([], Res) = false;
walther@60017
   220
member op = [Pbl,Met] p_ = false;
walther@59762
   221
val (_, (_, c', ptp')) = Step_Solve.do_next ptp;
neuper@55482
   222
(* in pt': tac = Rewrite ("rnorm_equation_add", "Test.rnorm_equation_add")},
neuper@55482
   223
                                                ^^^^^^^^^^^^^^^^^^^^^^^^^^^*)
walther@59760
   224
"~~~~~ fun do_next , args:"; val ((ptp as (pt, pos as (p,p_)))) = (ptp);
walther@60154
   225
MethodC.id_empty = get_obj g_metID pt (par_pblobj pt p) = false;
neuper@55482
   226
          val thy' = get_obj g_domID pt (par_pblobj pt p);
walther@59831
   227
	        val ((ist, ctxt), sc) = resume_prog thy' (p,p_) pt;
walther@59791
   228
	        val Next_Step (is, ctxt, tac_) = LI.find_next_step sc (pt,pos) ist ctxt;
neuper@55482
   229
(*tac_ = Rewrite' (..., ("rnorm_equation_add", "Test.rnorm_equation_add"), ...) !!!!!!!!!!!!!!!!*)
walther@59680
   230
walther@59680
   231
(*----- outcommented during cleanup of args in lucas-interpreter.sml ------------------------\\* )
walther@59772
   232
"~~~~~ fun find_next_step , args:"; val (thy, (ptp as (pt, pos as (p, _)):ctree * pos'), 
walther@59676
   233
  (sc as Prog (h $ body)), (Pstate (ist as (E,l,rls,a,v,s,b)), ctxt)) = ((thy',srls), (pt,pos), sc, is);
neuper@55482
   234
l = [] = false;
walther@59784
   235
go_scan_up thy ptp sc ist true (*--> Accept_Tac (Rewrite' (.., (.., "Test.rnorm_equation_add"), ...)
walther@59772
   236
  BUT WE FIND IN THE CODE ABOVE IN find_next_step:*)
neuper@55482
   237
;
neuper@55482
   238
(*----------------------------------------------------------------------------------------------*)
walther@59875
   239
if ThmC.string_of_thm @{thm rnorm_equation_add} =  "\<not> ?b =!= 0 \<Longrightarrow> (?a = ?b) = (?a + - 1 * ?b = 0)"
walther@59875
   240
then () else error "ThmC.string_of_thm changed";
walther@59875
   241
if ThmC.string_of_thm @{thm rnorm_equation_add} =  "\<not> ?b =!= 0 \<Longrightarrow> (?a = ?b) = (?a + - 1 * ?b = 0)"
neuper@55482
   242
then () else error "string_of_thm changed";
neuper@55482
   243
(*----------------------------------------------------------------------------------------------*)
neuper@55482
   244
;
neuper@55482
   245
(*SEARCH FOR THE ERROR WENT DOWN TO THE END OF THIS TEST, AND THEN UP TO HERE AGAIN*)
wneuper@59562
   246
"~~~~~ fun begin_end_prog, args:"; val (tac_, is, (pt, pos as (p,p_))) = (tac_, is, ptp);
neuper@55482
   247
        val pos =
neuper@55482
   248
          case pos of
neuper@55482
   249
		        (p, Met) => ((lev_on o lev_dn) p, Frm)(*begin script*)
neuper@55482
   250
		      | (p, Res) => (lev_on p,Res) (*somewhere in script*)
neuper@55482
   251
		      | _ => pos;
walther@59932
   252
Step.add tac_ is pos pt;
neuper@55482
   253
(* tac = Rewrite ("rnorm_equation_add", "Test.rnorm_equation_add")},
neuper@55482
   254
                                        ^^^^^^^^^^^^^^^^^^^^^^^^^^^*)
walther@59932
   255
"~~~~~ fun add, args:"; val (thy, (Rewrite' (thy',ord',rls',pa,thm',f,(f',asm))), 
walther@59881
   256
  (is, ctxt), (p,p_), pt) = ((ThyC.get_theory "Isac_Knowledge"), tac_, is, pos, pt);
walther@59728
   257
        val (pt,c) = cappend_atomic pt p (is, ContextC.insert_assumptions asm ctxt) f
wneuper@59253
   258
          (Rewrite thm') (f',asm) Complete;
neuper@55482
   259
(* in pt: tac = Rewrite ("rnorm_equation_add", "Test.rnorm_equation_add")},
neuper@55482
   260
                                               ^^^^^^^^^^^^^^^^^^^^^^^^^^^*)
neuper@55482
   261
"~~~~~ fun cappend_atomic, args:"; val (pt, p, ist_res, f, r, f', s) = 
walther@59728
   262
  (pt, p, (is, ContextC.insert_assumptions asm ctxt), f, (Rewrite thm'), (f',asm), Complete);
walther@59844
   263
existpt p pt andalso Tactic.is_empty (get_obj g_tac pt p) = false;
neuper@55482
   264
apfst (append_atomic p ist_res f r f' s) (cut_tree pt (p,Frm));
neuper@55482
   265
apfst : ('a -> 'b) -> 'a * 'c -> 'b * 'c;
wneuper@59279
   266
(append_atomic p ist_res f r f' s) : ctree -> ctree;
neuper@55482
   267
;
neuper@55482
   268
(* HERE THE ERROR OCCURED IN THE FIRST APPROACH
neuper@55482
   269
  getTactic 1 ([1,1],Frm); <ERROR> syserror in getTactic </ERROR>  <<<<<=========================*)
neuper@55482
   270
"~~~~~ fun getTactic, args:"; val (cI, (p:pos')) = (1, ([1,1],Frm));
neuper@55482
   271
val ((pt,_),_) = get_calc cI
walther@59983
   272
val (form, tac, asms) = ME_Misc.pt_extract (pt, p)
neuper@55482
   273
val SOME ta = tac;
neuper@55482
   274
"~~~~~ fun gettacticOK2xml, args:"; val ((cI:calcID), tac) = (cI, ta);
wneuper@59262
   275
val i = 2;
neuper@55482
   276
"~~~~~ fun tac2xml, args:"; val (j, (Rewrite thm')) = (i, tac);
wneuper@59252
   277
"~~~~~ fun thm'2xml, args:"; val (j, ((ID, form) : thm'')) = ((j+i), thm');
neuper@55482
   278
ID = "rnorm_equation_add";
neuper@55482
   279
@{thm rnorm_equation_add};
walther@59868
   280
(UnparseC.term o Thm.prop_of) form = "~ ?b =!= 0 ==> (?a = ?b) = (?a + -1 * ?b = 0)"
neuper@55482
   281
  (*?!? should be "\<not> ?b =!= 0 \<Longrightarrow> (?a = ?b) = (?a + -1 * ?b = 0)"*)
neuper@55482
   282
(*thmstr2xml (j+i) form;
neuper@55482
   283
ERROR Undeclared constant: "Test.rnorm_equation_add" ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^*)
neuper@55482
   284
;
walther@59983
   285
Test_Tool.show_pt pt;
neuper@55482
   286
(*[
neuper@55482
   287
(([], Frm), solve (x + 1 = 2, x)),
neuper@55482
   288
(([1], Frm), x + 1 = 2),
neuper@55482
   289
(([1,1], Frm), x + 1 = 2),
neuper@55482
   290
(([1,1], Res), x + 1 + -1 * 2 = 0),
neuper@55482
   291
(([1], Res), x + 1 + -1 * 2 = 0),
neuper@55482
   292
(([2], Res), -1 + x = 0)]
neuper@55482
   293
neuper@55482
   294
pt;   --> tac = Rewrite ("rnorm_equation_add", "Test.rnorm_equation_add")*)
walther@59679
   295
( *----- outcommented during cleanup of args in lucas-interpreter.sml ------------------------//*)
neuper@55482
   296
neuper@55486
   297
"----------- improved fun getTactic for interSteps and numeral calculations --";
neuper@55486
   298
"----------- improved fun getTactic for interSteps and numeral calculations --";
neuper@55486
   299
"----------- improved fun getTactic for interSteps and numeral calculations --";
neuper@55486
   300
reset_states (); val cI = 1;
neuper@55486
   301
CalcTree [(["equality (x+1=(2::real))", "solveFor x", "solutions L"],
walther@59997
   302
  ("Test",["sqroot-test", "univariate", "equation", "test"],["Test", "squ-equ-test-subpbl1"]))];
neuper@55486
   303
moveActiveRoot 1;
wneuper@59248
   304
autoCalculate 1 CompleteCalcHead;
walther@59747
   305
autoCalculate 1 (Steps 1);
neuper@55486
   306
neuper@55486
   307
    val cs = get_calc cI             (* we improve from the calcstate here [*] *);
neuper@55486
   308
    val pos as (_,p_) = get_pos cI 1 (* we improve from the calcstate here [*] *);
neuper@55486
   309
wneuper@59123
   310
appendFormula 1 "x + 4 + -3 = 2" (*|> Future.join*);
neuper@55486
   311
interSteps 1 ([1],Res); (* already done by appendFormula, now showed to frontend *)
neuper@55486
   312
getTactic 1 ([1,1], Res); 
neuper@55486
   313
  (*<ID> sym_#add_Float ((~3,0), (0,0)) __ ((4,0), (0,0)) </ID>  <<<<<================== to improve
neuper@55486
   314
  <ISA> 1 + x = -3 + (4 + x) </ISA>*)
neuper@55486
   315
neuper@55486
   316
val ((pt''',p'''), tacis''') = get_calc cI;
walther@59983
   317
Test_Tool.show_pt pt'''
neuper@55486
   318
(*[
neuper@55486
   319
(([], Frm), solve (x + 1 = 2, x)),
neuper@55486
   320
(([1], Frm), x + 1 = 2),
neuper@55486
   321
(([1,1], Frm), x + 1 = 2),
neuper@55486
   322
(([1,1], Res), 1 + x = 2),
neuper@55486
   323
(([1,2], Res), -3 + (4 + x) = 2),
neuper@55486
   324
(([1,3], Res), -3 + (x + 4) = 2),
neuper@55486
   325
(([1,4], Res), x + 4 + -3 = 2),
neuper@55486
   326
(([1], Res), x + 4 + -3 = 2)]*)
neuper@55486
   327
;
neuper@55486
   328
"~~~~~ fun appendFormula', args:"; val (cI, ifo) = (1, "x + 4 + -3 = 2");
neuper@55486
   329
(*  val cs = get_calc cI             (* we improve from the calcstate here [*] *);
neuper@55486
   330
    val pos as (_,p_) = get_pos cI 1 (* we improve from the calcstate here [*] *);*)
walther@59798
   331
val ("ok", cs' as (_, _, ptp')) = Step.do_next pos cs;
walther@59798
   332
(*val ("ok", (_, c, ptp as (_,p))) = *)Step_Solve.by_term ptp' (encode ifo);
walther@59797
   333
"~~~~~ fun Step_Solve.by_term , args:"; val (cs as (_, _, ptp as (pt, pos as (p, p_))), istr) =
neuper@55486
   334
  (cs', (encode ifo));
walther@60230
   335
val SOME f_in = TermC.parse (ThyC.get_theory "Isac_Knowledge") istr
wneuper@59188
   336
	      val f_in = Thm.term_of f_in
neuper@55486
   337
	      val f_succ = get_curr_formula (pt, pos);
neuper@55486
   338
f_succ = f_in  = false;
walther@59982
   339
val NONE = CAS_Cmd.input f_in 
neuper@55486
   340
			          val pos_pred = lev_back' pos
neuper@55486
   341
			          (* f_pred ---"step pos cs"---> f_succ in appendFormula *)
neuper@55486
   342
			          val f_pred = get_curr_formula (pt, pos_pred);
neuper@55486
   343
			          (*val msg_calcstate' = *)compare_step ([], [], (pt, pos_pred)) f_in (*<<=====*);
neuper@55486
   344
"~~~~~ fun compare_step, args:"; val (((tacis, c, ptp as (pt, pos as (p,p_)))), ifo) = 
neuper@55486
   345
  (([], [], (pt, pos_pred)), f_in);
neuper@55486
   346
    val fo =
neuper@55486
   347
      case p_ of
neuper@55486
   348
        Frm => get_obj g_form pt p
neuper@55486
   349
			| Res => (fst o (get_obj g_result pt)) p
walther@59861
   350
			| _ => TermC.empty (*on PblObj is fo <> ifo*);
walther@60154
   351
	  val {nrls, ...} = MethodC.from_store (get_obj g_metID pt (par_pblobj pt p))
walther@59852
   352
	  val {rew_ord, erls, rules, ...} = Rule_Set.rep nrls;
walther@59907
   353
	  (*val (found, der) = *)Derive.steps rew_ord erls rules fo ifo; (*<---------------*)
walther@59906
   354
"~~~~~ fun .concat_deriv, args:"; val (rew_ord, erls, rules, fo, ifo) =
neuper@55486
   355
  (rew_ord, erls, rules, fo, ifo);
walther@59861
   356
    fun derivat ([]:(term * rule * (term * term list)) list) = TermC.empty
neuper@55486
   357
      | derivat dt = (#1 o #3 o last_elem) dt
neuper@55486
   358
    fun equal (_,_,(t1, _)) (_,_,(t2, _)) = t1=t2
walther@59907
   359
    (*val  fod = *)Derive.do_one (Isac"") erls rules (snd rew_ord) NONE  fo;
walther@59907
   360
    (*val ifod = *)Derive.do_one (Isac"") erls rules (snd rew_ord) NONE ifo;
neuper@55486
   361