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