test/Tools/isac/Knowledge/diffapp.sml
author Walther Neuper <wneuper@ist.tugraz.at>
Thu, 22 Dec 2016 11:36:20 +0100
changeset 59279 255c853ea2f0
parent 59248 5eba5e6d5266
child 59370 b829919afd7b
permissions -rw-r--r--
renamed Ctree.ptree --> Ctree.ctree
     1 (* tests for IsacKnowledge/DiffApp
     2    author Walther Neuper 000301
     3    (c) due to copyright terms
     4 
     5    use"../smltest/IsacKnowledge/diffapp.sml";
     6    use"diffapp.sml";
     7 *)
     8 
     9 trace_rewrite := false;
    10 "Contents----------------------------------------------";
    11 "              Specify_Problem (match_itms_oris)       ";
    12 "              test specify, fmz <> []                  ";
    13 "              test specify, fmz = []                  ";
    14 "          problemtypes + formalizations               ";
    15 "-------------------- ctree of {(a,b). is-max ... ----------------";
    16 "--------- me .. scripts for maximum-example ---------------------";
    17 "--------- autoCalc .. scripts for maximum-example ---------------";
    18 
    19 "--------------------- 30.4.03: maximum .. rewrite_set_ list_rls ---------";
    20 "---------------------- 1.5.03: Make_fun_by_explicit ---------------------";
    21 "---------------------- 2.5.03: Make_fun_by_new_variable -----------------";
    22 
    23 
    24 
    25 
    26 
    27 " #################################################### ";
    28 "          problemtypes + formalizations               ";
    29 " #################################################### ";
    30 " -------------- [maximum_of,function] --------------- ";
    31 val pbt = 
    32     ["fixedValues f_ix","maximum m_m","valuesFor v_s","relations r_s"];
    33 (*=== inhibit exn 110722=============================================================
    34 map (the o (parseold thy)) pbt;
    35 === inhibit exn 110722=============================================================*)
    36 val fmz =
    37     ["fixedValues [r=Arbfix]","maximum A",
    38      "valuesFor [a,b]",
    39      "relations [A=a*b, (a/2)^^^2 + (b/2)^^^2 = r^^^2]",
    40      "relations [A=a*b, (a/2)^^^2 + (b/2)^^^2 = r^^^2]",
    41      "relations [A=a*b, a/2=r*sin alpha, b/2=r*cos alpha]",
    42 
    43      "boundVariable a","boundVariable b","boundVariable alpha",
    44      "interval {x::real. 0 <= x & x <= 2*r}",
    45      "interval {x::real. 0 <= x & x <= 2*r}",
    46      "interval {x::real. 0 <= x & x <= pi}",
    47      "errorBound (eps=(0::real))"];
    48 (*=== inhibit exn 110722=============================================================
    49 map (the o (parseold thy)) fmz;
    50 " -------------- [make,function] -------------- ";
    51 === inhibit exn 110722=============================================================*)
    52 val pbt = 
    53     ["functionOf f_f","boundVariable v_v","equalities eqs",
    54      "functionTerm f_0_0"];
    55 (*=== inhibit exn 110722=============================================================
    56 map (the o (parseold thy)) pbt;
    57 val fmz12 =
    58     ["functionOf A","boundVariable a","boundVariable b",
    59      "equalities [A=a*b, (a/2)^^^2 + (b/2)^^^2 = r^^^2]",
    60      (*28.11.00: "functionTerm (A_0=Undef)"*)"functionTerm (Undef)"];
    61 map (the o (parseold thy)) fmz12;
    62 val fmz3 =
    63     ["functionOf A","boundVariable a","boundVariable b",
    64      "equalities [A=a*b, a/2=r*sin alpha, b/2=r*cos alpha]",
    65      (*28.11.00: "functionTerm (A_0=Undef)"*)"functionTerm (Undef)"];
    66 map (the o (parseold thy)) fmz3;
    67 " --------- [univar,equation] --------- ";
    68 val pbt = 
    69     ["equality e_e","solveFor v_v","solutions v_i_i"];
    70 map (the o (parseold thy)) pbt;
    71 val fmz =
    72     ["equality ((a/2)^^^2 + (b/2)^^^2 = r^^^2)",
    73      "solveFor b","solutions b_i"];
    74 map (the o (parseold thy)) fmz;
    75 " ---- [on_interval,maximum_of,function] ---- ";
    76 val pbt = 
    77     ["functionTerm t_t","boundVariable v_v","interval itv_v",
    78      "errorBound err_r","maxArgument v_0"];
    79 map (the o (parseold thy)) pbt;
    80 val fmz12 =
    81     [(*28.11.00: "functionTerm (A_0 = a*sqrt(#4*r^^^#2 - a^^^#2))",*)
    82      "functionTerm (a*sqrt(4*r^^^2 - a^^^2))",
    83      (*28.11.00: "functionTerm (A_0 = b*sqrt(#4*r^^^#2 - b^^^#2))",*)
    84      "functionTerm (b*sqrt(4*r^^^2 - b^^^2))",
    85      "boundVariable a","boundVariable b",
    86      "interval {x::real. 0 <= x & x <= 2*r}",
    87      "errorBound (eps=0)","maxArgument (a_0=Undef)"];
    88 map (the o (parseold thy)) fmz12;
    89 val fmz3 =
    90     [(*28.11.00: "functionTerm (A_0 = (#2*r*sin alpha)*(#2*r*cos alpha))",*)
    91      "functionTerm ((2*r*sin alpha)*(2*r*cos alpha))",
    92      "boundVariable alpha",
    93      "interval {x::real. 0 <= x & x <= pi}",
    94      "errorBound (eps=0)","maxArgument (a_0=Undef)"];
    95 map (the o (parseold thy)) fmz3;
    96 " --------- [derivative_of,function] --------- ";
    97 val pbt = 
    98     ["functionTerm f_f","boundVariable v_v","derivative f_f'"];
    99 map (the o (parseold thy)) pbt;
   100 val fmz =
   101     [(*28.11.00: "functionTerm (A_0=a*#2*sqrt r^^^#2 - (a//#2)^^^#2)",*)
   102      "functionTerm (a*2*sqrt r^^^2 - (a/2)^^^2)",
   103      "boundVariable a",
   104      (*28.11.00: "derivative (A_0'=Undef)"*)"derivative (Undef)"];
   105 map (the o (parseold thy)) fmz;
   106 " --------- [find_values,tool] --------- ";
   107 val pbt = 
   108     ["maxArgument ma_a","functionTerm f_f","boundVariable v_v",
   109      "valuesFor vls_s","additionalRels r_s"];
   110 map (the o (parseold thy)) pbt;
   111 val fmz1 =
   112     ["maxArgument (a_0=(srqt 2)*r)",
   113      (*28.11.00: "functionTerm (A_0=a*#2*sqrt r^^^#2 - (a//#2)^^^#2)",*)
   114      "functionTerm (a*2*sqrt r^^^2 - (a/2)^^^2)",
   115      "boundVariable a",
   116      "valuesFor [a,b]","maximum A",
   117      "additionalRels [(a/2)^^^2 + (b/2)^^^2 = r^^^2]"];
   118 map (the o (parseold thy)) fmz1;
   119 
   120 === inhibit exn 110722=============================================================*)
   121 
   122 
   123 "-------------------- ctree of {(a,b). is-max ... --------------------------";
   124 "-------------------- ctree of {(a,b). is-max ... --------------------------";
   125 "-------------------- ctree of {(a,b). is-max ... --------------------------";
   126 
   127 (* Teil von max-on-surface.sml,
   128    der nach Init_Proof -> prep_ori wieder l"auft
   129    (f"ur tests mit neuer pos')
   130    use"test-max-surf1.sml";
   131 
   132    Compiler.Control.Print.printDepth:=7; (*4 is default*)
   133    Compiler.Control.Print.printDepth:=4; (*4 is default*)
   134    *)
   135 
   136 (* --vvv-- ausgeliehen von test-root-equ/sml *)
   137 val loc = e_istate;
   138 val (dI',pI',mI') =
   139   ("Script",["sqroot-test","univariate","equation"],
   140    ["Script","squ-equ-test2"]);
   141 val fmz = ["equality (sqrt(9+4*x)=sqrt x + sqrt(5+x))",
   142 	   "solveFor x","errorBound (eps=0)",
   143 	   "solutions L"];
   144 (*
   145 val (mI,m) = ("Init_Proof",Init_Proof (fmz, (dI',pI',mI')));
   146 val ((p,p_),_,_,_,_,(_,pt,_)) = do_ (mI,m) e_pos'[1](e_scr,EmptyPtree,[]);
   147  --^^^-- ausgeliehen von test-root-equ/sml *)
   148 (*-------------- 9.6.03 --- cappend_ ... term -------irreparabler test
   149 val (pt,_) = 
   150   cappend_problem EmptyPtree [] loc ([],(dI',pI',mI'));
   151 val pos = (lev_on o lev_dn) [];
   152 (* val pos = ([1]) *)
   153 val (pt,_) = cappend_parent pt pos loc "{(a,b). is-max ..." 
   154     Empty_Tac TransitiveB;
   155 val pos = (lev_on o lev_dn) pos;
   156 (*val pos = ([1,1])*)
   157 val (pt,_) = cappend_atomic pt pos loc "{(a,b). is-max ..." 
   158     Empty_Tac ("[1,1]:{(a,b). is-extremum ...",[]) Complete;
   159 val pos = lev_on pos;
   160 (*val pos = ([1,2])*)
   161 val (pt,_) = cappend_atomic pt pos loc "{(a,b). is-extremum ..." 
   162     Empty_Tac ("[1,2]:{(a,b). f_x(a,b) ...",[]) Complete;
   163 val pos = lev_up pos;
   164 (*val pos = ([1])*)
   165 val (pt,_) = append_result pt pos e_istate ("[1#]:{(a,b). f_x(a,b) ...",[])
   166     Complete;
   167 
   168 val pos = lev_on pos;
   169 (*val pos = ([2]) *)
   170 val (pt,_) = cappend_atomic pt pos loc "{(a,b). f_x(a,b) ..." 
   171     Empty_Tac ("[2]:{(a,b). f_x & f_xx &...",[]) Complete;
   172 val pos = lev_on pos;
   173 (*al pos = [3] : pos*)
   174 val (pt,_) = cappend_parent pt pos loc "{(a,b). f_x & f_xx &..." 
   175     Empty_Tac TransitiveB;
   176 val pos = (lev_on o lev_dn) pos;
   177 (*pos = ([3,1]) *)
   178 val (pt,_) = cappend_atomic pt pos loc "{(a,b). f_x & f_xx & ..." 
   179     Empty_Tac ("[3,1]:{(a,b). f_x & f_xx } cup ...",[]) Complete;
   180 val pos = lev_on pos;
   181 (*pos = ([3,2]) *)
   182 val (pt,_) = cappend_atomic pt pos loc "{(a,b). f_x & f_xx } cup.."
   183     Empty_Tac ("[3,2]:{(a,b). f_x ..} cup ...",[]) Complete;
   184 
   185 val pos = lev_up pos;
   186 (*pos = ([3]) *)
   187 val (pt,_) = append_result pt pos e_istate ("[3#]:{(a,b). f_x ..} cup..",[])
   188     Complete;
   189 val pos = lev_on pos;
   190 (*val pos = [4] : pos *)
   191 val (pt,_) = cappend_parent pt pos loc "{(a,b). f_x ..} cup ..." 
   192     Empty_Tac IntersectB;
   193 val pos = (lev_on o lev_dn) pos;
   194 (*val pos = ([4,1]) *)
   195 val (pt,_) = cappend_parent pt pos loc "set_1 = ..." 
   196     Empty_Tac SequenceB;
   197 
   198 
   199 val pos = (lev_on o lev_dn) pos;
   200 (*val pos = ([4,1,1]) *)
   201 val (pt,_) = cappend_parent(*pbl*) pt pos loc"f_x = d/dx x^3 ..."
   202     Empty_Tac TransitiveB;
   203 val pos = (lev_on o lev_dn) pos;
   204 (*val pos = ([4,1,1,1]) *)
   205 val (pt,_) = cappend_parent pt pos loc "d/dx x^3 ..." 
   206     Empty_Tac TransitiveB;
   207 val pos = (lev_on o lev_dn) pos;
   208 (*val pos = ([4,1,1,1,1]) *)
   209 val (pt,_) = cappend_atomic pt pos loc "d/dx x^3 ..." 
   210     Empty_Tac ("[4,1,1,1,1]:3x^2 + d/dx ...",[]) Complete;
   211 val pos = lev_on pos;
   212 (*val pos = ([4,1,1,1,2]) *)
   213 val (pt,_) = cappend_atomic pt pos loc "3x^2 + d/dx ..." 
   214     Empty_Tac ("[4,1,1,1,2]:3x^2 + 0 + d/dx ...",[]) Complete;
   215 val pos = lev_on pos;
   216 (*pos = ([4,1,1,1,3]) *)
   217 val (pt,_) = cappend_atomic pt pos loc "3x^2 + 0 + d/dx ..." 
   218     Empty_Tac ("[4,1,1,1,3]:3x^2 + 0 -3 ...",[]) Complete;
   219 "--- 1 ---";
   220 val pos = lev_up pos;
   221 (*pos = ([4,1,1,1]) *)
   222 val (pt,_) = append_result pt pos e_istate ("[4,1,1,1#]:3x^2 -3.",[])Complete;
   223 "--- 2 ---";
   224 val pos = lev_up pos;
   225 (*val pos = ([4,1,1]) *)
   226 val (pt,_) = append_result pt pos e_istate ("[4,1,1#]:found 3x^2 -3 ...",[])
   227     Complete;
   228 "--- 3 ---";
   229 val pos = lev_on pos;
   230 (*val pos = ([4,1,2]+) *)
   231 val (pt,_) = cappend_parent(*pbl*) pt pos loc "f_y = d/dy x^3 ..."
   232     Empty_Tac TransitiveB;
   233 "--- 4 ---";
   234 writeln (pr_ctree pr_short pt);
   235 
   236 (*
   237 .    ----- pblobj -----
   238 1.   {(a,b). is-max ...
   239 1.1.   {(a,b). is-max ...
   240 1.2.   {(a,b). is-extremum ...
   241 2.   {(a,b). f_x(a,b) ...
   242 3.   {(a,b). f_x & f_xx &...
   243 3.1.   {(a,b). f_x & f_xx & ...
   244 3.2.   {(a,b). f_x & f_xx } cup..
   245 4.   {(a,b). f_x ..} cup ...
   246 4.1.   set_1 = ...
   247 4.1.1.   f_x = d/dx x^3 ...
   248 4.1.1.1.   d/dx x^3 ...
   249 4.1.1.1.1.   d/dx x^3 ...
   250 4.1.1.1.2.   3x^2 + d/dx ...
   251 4.1.1.1.3.   3x^2 + 0 + d/dx ...
   252 4.1.2.   f_y = d/dy x^3 ...
   253   
   254  use"test-max-surf1.sml";
   255    *)
   256 -------------- 9.6.03 --- cappend_ ... term -------irreparabler test---*)
   257 
   258 
   259 "--------- me .. scripts for maximum-example ---------------------";
   260 "--------- me .. scripts for maximum-example ---------------------";
   261 "--------- me .. scripts for maximum-example ---------------------";
   262 
   263 val fmz =
   264     ["fixedValues [r=Arbfix]","maximum A",
   265      "valuesFor [a,b]",
   266      "relations [A=a*b, (a/2)^^^2 + (b/2)^^^2 = r^^^2]",
   267      "relations [A=a*b, (a/2)^^^2 + (b/2)^^^2 = r^^^2]",
   268      "relations [A=a*b, a/2=r*sin alpha, b/2=r*cos alpha]",
   269 
   270      "boundVariable a","boundVariable b","boundVariable alpha",
   271      "interval {x::real. 0 <= x & x <= 2*r}",
   272      "interval {x::real. 0 <= x & x <= 2*r}",
   273      "interval {x::real. 0 <= x & x <= pi}",
   274      "errorBound (eps=(0::real))"];
   275 val (dI',pI',mI') =
   276   ("DiffApp",["maximum_of","function"],
   277    ["DiffApp","max_by_calculus"]);
   278 
   279 val (p,_,f,nxt,_,pt) = CalcTreeTEST [(fmz, (dI',pI',mI'))];
   280 (*=== inhibit exn 110722=============================================================
   281 val (p,_,f,nxt,_,pt) = me nxt p c pt;
   282 val (p,_,f,nxt,_,pt) = me nxt p c pt;
   283 val (p,_,f,nxt,_,pt) = me nxt p c pt;
   284 val (p,_,f,nxt,_,pt) = me nxt p c pt;
   285 val (p,_,f,nxt,_,pt) = (me nxt p c pt) handle e => OldGoals.print_exn e;
   286 val (p,_,f,nxt,_,pt) = me nxt p c pt;
   287 val (p,_,f,nxt,_,pt) = me nxt p c pt;
   288 val (p,_,f,nxt,_,pt) = me nxt p c pt;
   289 val (p,_,f,nxt,_,pt) = me nxt p c pt;
   290 case nxt of (_, Specify_Method ["DiffApp","max_by_calculus"]) => ()
   291 	  | _ => error "diffapp.sml: max-exp me, nxt = Specify_Method";
   292 
   293 val oris = fst3 (get_obj g_origin pt (fst p)); writeln(oris2str oris);
   294 val pits = get_obj g_pbl pt (fst p); writeln(itms2str_ ctxt pits);
   295 
   296 val (p,_,f,nxt,_,pt) = me nxt p c pt;
   297 val mits = get_obj g_met pt (fst p); writeln(itms2str_ ctxt mits);
   298 val (p,_,f,nxt,_,pt) = me nxt p c pt;
   299 val (p,_,f,nxt,_,pt) = me nxt p c pt;
   300 val (p,_,f,nxt,_,pt) = me nxt p c pt;
   301 case nxt of (_,Apply_Method ["DiffApp","max_by_calculus"] ) => ()
   302 	  | _ => error "diffapp.sml: max-exp me, nxt = Apply_Method";
   303 val (p,_,f,nxt,_,pt) = me nxt p c pt;
   304 === inhibit exn 110722=============================================================*)
   305 
   306 (*since 0508 Apply_Method does the 1st step, if NONE init_form -------------
   307 (*val nxt = ("Subproblem",Subproblem ("DiffApp",["make","function"]))*)
   308 val (p,_,f,nxt,_,pt) = (me nxt p c pt) handle e => print_exn_G e;
   309 (*val nxt = ("Refine_Tacitly",Refine_Tacitly ["make","function"])*)
   310 val (p,_,f,nxt,_,pt) = me nxt p c pt;
   311 (*val nxt = ("Model_Problem",Model_Problem ["by_explicit","make","function"])*)
   312 ----------------------------------------------------------------------------*)
   313 case nxt of (_, Model_Problem(*["by_explicit", "make", "function"]*)) => ()
   314 	  | _ => error "diffapp.sml: max-exp me, nxt = Model_Problem";
   315 
   316 (*=== inhibit exn 110722=============================================================
   317 val (p,_,f,nxt,_,pt) = me nxt p c pt;
   318 val (p,_,f,nxt,_,pt) = me nxt p c pt;
   319 val (p,_,f,nxt,_,pt) = me nxt p c pt;
   320 val (p,_,f,nxt,_,pt) = me nxt p c pt;
   321 val (p,_,f,nxt,_,pt) = me nxt p c pt;
   322 === inhibit exn 110722=============================================================*)
   323 
   324 val oris = fst3 (get_obj g_origin pt (fst p));writeln(oris2str oris);
   325 val pits = get_obj g_pbl pt (fst p);writeln(itms2str_ ctxt pits);
   326 
   327 (*=== inhibit exn 110722=============================================================
   328 val (p,_,f,nxt,_,pt) = me nxt p c pt;
   329 val (p,_,f,nxt,_,pt) = me nxt p c pt;
   330 val (p,_,f,nxt,_,pt) = me nxt p c pt;
   331 val (p,_,f,nxt,_,pt) = me nxt p c pt;
   332 case nxt of (_, Apply_Method ["DiffApp", "make_fun_by_explicit"]) => ()
   333 	  | _ => error "diffapp.sml: max-exp Apply_Method ([1], Met) ";
   334 === inhibit exn 110722=============================================================*)
   335 
   336 (*----since WN050901 (ie. corr. mathengine#nxt_specify_ ..nxt_spec Pbl->p_
   337 we get at ...
   338 val (p,_,f,nxt,_,pt) = me nxt p c pt;
   339 ...
   340 ### assod: NotAss m= Subproblem'  ,
   341  stac= Substitute
   342  [(b, (rhs o hd)
   343        (Subproblem (thy, [normalize, polynomial, univariate, equation])))]
   344  (hd (filterVar A [A = a * b, (a / 2) ^^^ 2 + (b / 2) ^^^ 2 = r ^^^ 2]))
   345 *** stac2tac_ TODO: no match for Substitute
   346 ***  [(b, (rhs o hd)
   347 ***        (Subproblem (thy, [normalize, polynomial, univariate, equation])))]
   348 ***  (hd (filterVar A [A = a * b, (a / 2) ^^^ 2 + (b / 2) ^^^ 2 = r ^^^ 2]))
   349 Exception- ERROR raised
   350 
   351 ############################################################################
   352 # presumerably didnt work before either, but not detected due to Emtpy_Tac #
   353 ############################################################################
   354 
   355 (*val nxt = Subproblem ("DiffApp",["univariate","equation"]))   *)
   356 val (p,_,f,nxt,_,pt) = me nxt p c pt;
   357 (*val nxt = Refine_Tacitly ["univariate","equation"])*)
   358 
   359 val oris = fst3 (get_obj g_origin pt (fst p));writeln(oris2str oris);
   360 val pits = get_obj g_pbl pt (fst p);writeln(itms2str_ ctxt pits);
   361 
   362 val (p,_,f,nxt,_,pt) = me nxt p c pt;
   363 val (p,_,f,nxt,_,pt) = me nxt p c pt;
   364 val (p,_,f,nxt,_,pt) = me nxt p c pt;val (p,_,f,nxt,_,pt) = me nxt p c pt;
   365 val (p,_,f,nxt,_,pt) = me nxt p c pt;val (p,_,f,nxt,_,pt) = me nxt p c pt;
   366 val (p,_,f,nxt,_,pt) = me nxt p c pt;val (p,_,f,nxt,_,pt) = me nxt p c pt;
   367 (*val nxt = ("Apply_Method",Apply_Method ["PolyEq","normalize_poly"])*)
   368 
   369 val (p,_,f,nxt,_,pt) = me nxt p c pt;
   370 (*val f = Form' (FormKF (~1,EdUndef,3,Nundef,"A = a * b"))*)
   371 val (p,_,f,nxt,_,pt) = me nxt p c pt;
   372 val (p,_,f,nxt,_,pt) = me nxt p c pt;val (p,_,f,nxt,_,pt) = me nxt p c pt;
   373 val (p,_,f,nxt,_,pt) = me nxt p c pt;val (p,_,f,nxt,_,pt) = me nxt p c pt;
   374 val (p,_,f,nxt,_,pt) = me nxt p c pt;val (p,_,f,nxt,_,pt) = me nxt p c pt;
   375 val (p,_,f,nxt,_,pt) = me nxt p c pt;val (p,_,f,nxt,_,pt) = me nxt p c pt;
   376 val (p,_,f,nxt,_,pt) = me nxt p c pt;val (p,_,f,nxt,_,pt) = me nxt p c pt;
   377 val (p,_,f,nxt,_,pt) = me nxt p c pt;val (p,_,f,nxt,_,pt) = me nxt p c pt;
   378 val (p,_,f,nxt,_,pt) = me nxt p c pt;val (p,_,f,nxt,_,pt) = me nxt p c pt;
   379 (*val f = Form' (FormKF (~1,EdUndef,4,Nundef,"[b = A / a]"))*)
   380 
   381 ------------------------------------------------------------------------*)
   382 
   383 (*val f =
   384 Error' (Error_ "Refine_Tacitly [\"univariate\",\"equation\"] not applicable")*)
   385 
   386 
   387 (*----postponed.15.5.03 run scripts for maximum-example: univariate equation*)
   388 (*=== inhibit exn 110722=============================================================
   389 
   390 val (p,_,f,nxt,_,pt) = (me nxt p c pt) handle e => OldGoals.print_exn e; 
   391 === inhibit exn 110722=============================================================*)
   392 
   393 val oris = fst3 (get_obj g_origin pt (fst p));writeln(oris2str oris);
   394 
   395 val pits = get_obj g_pbl pt (fst p);writeln(itms2str_ ctxt pits);
   396 val pits = get_obj g_pbl pt [];writeln(itms2str_ ctxt pits);
   397 
   398 val mits = get_obj g_met pt (fst p);writeln(itms2str_ ctxt mits);
   399 val mits = get_obj g_met pt [];writeln(itms2str_ ctxt mits);
   400 
   401 (*=== inhibit exn 110722=============================================================
   402 itms2args thy ["DiffApp","max_by_calculus"] mits;
   403 
   404 val (p,_,f,nxt,_,pt) = me nxt p c pt;
   405 === inhibit exn 110722=============================================================*)
   406 
   407 (*---*)
   408 
   409 "--------- autoCalc .. scripts for maximum-example ---------------";
   410 "--------- autoCalc .. scripts for maximum-example ---------------";
   411 "--------- autoCalc .. scripts for maximum-example ---------------";
   412 (*++++++++ see systest/inform.sml 'complete_metitms' ++++++++*)
   413  reset_states ();
   414 val fmz =
   415     ["fixedValues [r=Arbfix]","maximum A",
   416      "valuesFor [a,b]",
   417      "relations [A=a*b, (a/2)^2 + (b/2)^2 = r^2]",
   418      "relations [A=a*b, (a/2)^2 + (b/2)^2 = r^2]",
   419      "relations [A=a*b, a/2=r*sin alpha, b/2=r*cos alpha]",
   420 
   421      "boundVariable a","boundVariable b","boundVariable alpha",
   422      "interval {x::real. 0 <= x & x <= 2*r}",
   423      "interval {x::real. 0 <= x & x <= 2*r}",
   424      "interval {x::real. 0 <= x & x <= pi}",
   425      "errorBound (eps=(0::real))"];
   426 val (dI',pI',mI') =
   427   ("DiffApp",["maximum_of","function"],
   428    ["DiffApp","max_by_calculus"]);
   429 
   430  CalcTree [(fmz, (dI',pI',mI'))];
   431  Iterator 1; moveActiveRoot 1;
   432  autoCalculate 1 CompleteCalcHead;
   433  refFormula 1 (get_pos 1 1); 
   434 
   435  fetchProposedTactic 1;
   436  autoCalculate 1 (Step 1);
   437 
   438  fetchProposedTactic 1;
   439  autoCalculate 1 (Step 1);
   440  (*Subproblem on_interval maximum_of function*)
   441  autoCalculate 1 CompleteCalcHead;
   442 
   443  fetchProposedTactic 1;
   444  val ((pt,p),_) = get_calc 1;
   445  val mits = get_obj g_met pt (fst p);
   446  writeln (itms2str_ ctxt mits);
   447 (*
   448  if itms2str_ ctxt mits = "[\n(1 ,[1] ,true ,#Given ,Cor functionEq (hd r_s) ,(t_, [hd r_s])),\n(2 ,[1] ,true ,#Given ,Cor boundVariable v_v ,(v_, [v_])),\n(3 ,[1] ,true ,#Given ,Cor interval itv_ ,(itv_, [itv_])),\n(4 ,[1] ,true ,#Find ,Cor maxArgument v__0 ,(v_0, [v__0]))]" then ()
   449  else error "diffapp.sml: diff.behav. in autoCalc .. scripts for max 1";
   450 *)
   451  (*FIXME: the environments contain identifers, and NOT values ?!?!?*)
   452 (* WN051209 while extending 'fun step' for initac, this became better ...
   453  if itms2str_ ctxt mits = "[\n(1 ,[1,2,3] ,true ,#Given ,Cor fixedValues [r = Arbfix] ,(f_ix, [[r = Arbfix]])),\n(2 ,[1,2,3] ,true ,#Find ,Cor maximum A ,(m_, [A])),\n(3 ,[1,2,3] ,true ,#Find ,Cor valuesFor [a, b] ,(v_s, [[a],[b]])),\n(4 ,[1,2] ,true ,#Relate ,Cor relations [A = a * b, (a / 2) ^^^ 2 + (b / 2) ^^^ 2 = r ^^^ 2] ,(r_s, [[A = a * b],[(a / 2) ^^^ 2 + (b / 2) ^^^ 2 = r ^^^ 2]])),\n(6 ,[1] ,true ,#undef ,Cor boundVariable a ,(v_, [a])),\n(9 ,[1,2] ,true ,#undef ,Cor interval {x. 0 <= x & x <= 2 * r} ,(itv_, [{x. 0 <= x & x <= 2 * r}])),\n(11 ,[1,2,3] ,true ,#undef ,Cor errorBound (eps = 0) ,(err_, [eps = 0]))]" then ()
   454  else error "diffapp.sml: diff.behav. in autoCalc .. scripts for max 1";
   455 *)
   456 
   457 
   458 
   459 "--------------------- 30.4.03: maximum .. rewrite_set_ list_rls ---------";
   460 "--------------------- 30.4.03: maximum .. rewrite_set_ list_rls ---------";
   461 "--------------------- 30.4.03: maximum .. rewrite_set_ list_rls ---------";
   462 str2term
   463   "Script Maximum_value(f_ix::bool list)(m_m::real) (r_s::bool list)\
   464    \      (v_v::real) (itv_v::real set) (err_r::bool) =          \ 
   465    \ (let e_e = (hd o (filterVar m_m)) r_s;              \
   466    \      t_t = (if 1 < length_h r_s                            \
   467    \           then (SubProblem (Reals_s,[make,function],[no_met])\
   468    \                     [REAL m_m, REAL v_v, BOOL_LIST r_s])\
   469    \           else (hd r_s));                                \
   470    \      (mx_x::real) = SubProblem (Reals_s,[on_interval,max_of,function], \
   471    \                                [Isac,maximum_on_interval])\
   472    \                               [BOOL t_t, REAL v_v, REAL_SET itv_v]\
   473    \ in ((SubProblem (Reals_s,[find_values,tool],[Isac,find_values])   \
   474    \      [REAL mx_x, REAL (Rhs t_t), REAL v_v, REAL m_m,     \
   475    \       BOOL_LIST (dropWhile (ident e_e) r_s)])::bool list))";
   476 
   477 val f_ix = (str2term "f_ix::bool list", 
   478 	    str2term "[r=Arbfix]");
   479 val m_m   = (str2term "m_m::real", 
   480 	    str2term "A");
   481 val r_s  = (str2term "rs_s::bool list", 
   482 	    str2term "[A = a*b, (a/2)^^^2 + (b/2)^^^2 = r^^^2]");
   483 val v_v   = (str2term "v_v::real", 
   484 	    str2term "b");
   485 val itv_v = (str2term "itv_v::real set", 
   486 	    str2term "{x::real. 0 <= x & x <= 2*r}");
   487 val err_r = (str2term "err_r::bool", 
   488 	    str2term "eps=0");
   489 val env = [f_ix, m_m, r_s ,v_v, itv_v, err_r];
   490 
   491 (*--- 1.line in script ---*)
   492 val t = str2term "(hd o (filterVar m_m)) (r_s::bool list)";
   493 val s = subst_atomic env t;
   494 term2str s;
   495 "(hd o filterVar A) [A = a * b, (a / 2) ^^^ 2 + (b / 2) ^^^ 2 = r ^^^ 2]";
   496 (*=== inhibit exn 110726=============================================================
   497 val SOME (s',_) = rewrite_set_ thy false list_rls s;
   498 val s'' = term2str s';
   499 if s''="A = a * b" then () else error "new behaviour with list_rls 1.1.";
   500 === inhibit exn 110726=============================================================*)
   501 val env = env @ [(str2term "e_e::bool",str2term "A = a * b")];
   502 
   503 (*--- 2.line: condition alone ---*)
   504 val t = str2term "1 < length_h (r_s::bool list)";
   505 val s = subst_atomic env t;
   506 term2str s;
   507 "1 < length_h [A = a * b, (a / 2) ^^^ 2 + (b / 2) ^^^ 2 = r ^^^ 2]";
   508 (*=== inhibit exn 110726=============================================================
   509 val SOME (s',_) = rewrite_set_ thy false list_rls s;
   510 val s'' = term2str s';
   511 if s''="HOL.True" then () else error "new behaviour with list_rls 1.2.";
   512 === inhibit exn 110726=============================================================*)
   513 
   514 (*--- 2.line in script ---*)
   515 val t = str2term 
   516 	    "(if 1 < length_h r_s                            \
   517    \           then (SubProblem (Reals_s,[make,function],[no_met])\
   518    \                     [REAL m_m, REAL v_v, BOOL_LIST r_s])\
   519    \           else (hd r_s))";
   520 val s = subst_atomic env t;
   521 term2str s;
   522 "if 1 < length_h [A = a * b, (a / 2) ^^^ 2 + (b / 2) ^^^ 2 = r ^^^ 2]\
   523 \then SubProblem (Reals_s, [make, function], [no_met])\
   524 \      [REAL A, REAL b,\
   525 \       BOOL_LIST [A = a * b, (a / 2) ^^^ 2 + (b / 2) ^^^ 2 = r ^^^ 2]]\
   526 \else hd [A = a * b, (a / 2) ^^^ 2 + (b / 2) ^^^ 2 = r ^^^ 2]";
   527 (*=== inhibit exn 110726=============================================================
   528 val SOME (s',_) = rewrite_set_ thy false list_rls s;
   529 val s'' = term2str s';
   530 if s'' = 
   531 "SubProblem (Reals_s, [make, function], [no_met])\n\
   532 \ [REAL A, REAL b,\n\
   533 \  BOOL_LIST [A = a * b, (a / 2) ^^^ 2 + (b / 2) ^^^ 2 = r ^^^ 2]]" then ()
   534 else error "new behaviour with list_rls 1.3.";
   535 === inhibit exn 110726=============================================================*)
   536 val env = env @ [(str2term "t_t::bool",
   537 		  str2term "A = (2*sqrt(r^^^2-(b/2)^^^2)) * b")];
   538 
   539 
   540 
   541 "---------------------- 1.5.03: Make_fun_by_explicit ---------------------";
   542 "---------------------- 1.5.03: Make_fun_by_explicit ---------------------";
   543 "---------------------- 1.5.03: Make_fun_by_explicit ---------------------";
   544 str2term
   545    "Script Make_fun_by_explicit (f_f::real) (v_v::real)         \
   546    \      (eqs::bool list) =                                 \
   547    \ (let h_h  = (hd o (filterVar f_f)) eqs;                   \
   548    \      e_1 = hd (dropWhile (ident h_h) eqs);               \
   549    \      v_s = dropWhile (ident f_f) (Vars h_h);                \
   550    \      v_1 = hd (dropWhile (ident v_v) v_s);                \
   551    \      (s_1::bool list)=(SubProblem(Reals_s,[univar,equation],[no_met])\
   552    \                          [BOOL e_1, REAL v_1])\
   553    \ in Substitute [(v_1 = (rhs o hd) s_1)] h_h)";
   554 val f_f = (str2term "f_f::real", 
   555 	  str2term "A");
   556 val v_v = (str2term "v_v::real", 
   557 	  str2term "b");
   558 val eqs=(str2term "eqs::bool list", 
   559 	  str2term "[A = a * b, (a / 2) ^^^ 2 + (b / 2) ^^^ 2 = r ^^^ 2]");
   560 val env = [f_f, v_v, eqs];
   561 
   562 (*--- 1.line in script ---*)
   563 val t = str2term "(hd o (filterVar v_v)) (eqs::bool list)";
   564 val s = subst_atomic env t;
   565 term2str s;
   566 val t = str2term 
   567      "(hd o filterVar b) [A = a * b, (a / 2) ^^^ 2 + (b / 2) ^^^ 2 = r ^^^ 2]";
   568 val SOME (t',_) = rewrite_set_ thy false list_rls t;
   569 val s' = term2str t';
   570 (*=== inhibit exn 110726=============================================================
   571 if s' = "A = a * b" then () else error "new behaviour with list_rls 2.1";
   572 === inhibit exn 110726=============================================================*)
   573 val env = env @ [(str2term "h_h::bool", str2term s')];
   574 
   575 (*--- 2.line in script ---*)
   576 val t = str2term "hd (dropWhile (ident h_h) (eqs::bool list))";
   577 val s = subst_atomic env t;
   578 term2str s;
   579 val t = str2term 
   580 	    "hd (dropWhile (ident (A = a * b))\
   581 	    \     [A = a * b, (a / 2) ^^^ 2 + (b / 2) ^^^ 2 = r ^^^ 2])";
   582 (*=== inhibit exn 110726=============================================================
   583 mem_rls "dropWhile_Cons" list_rls;
   584 mem_rls "Atools.ident" list_rls;
   585 val SOME (t',_) = rewrite_set_ thy false list_rls t;
   586 val s' = term2str t';
   587 if s' = "(a / 2) ^^^ 2 + (b / 2) ^^^ 2 = r ^^^ 2" then () 
   588 else error "new behaviour with list_rls 2.2";
   589 === inhibit exn 110726=============================================================*)
   590 val env = env @ [(str2term "e_1::bool", str2term s')];
   591 
   592 (*--- 3.line in script ---*)
   593 val t = str2term "dropWhile (ident f_f) (Vars (h_h::bool))";
   594 val s = subst_atomic env t;
   595 term2str s;
   596 val t = str2term "dropWhile (ident A) (Vars (A = a * b))";
   597 (*=== inhibit exn 110726=============================================================
   598 val SOME (t',_) = rewrite_set_ thy false list_rls t;
   599 val s' = term2str t';
   600 if s' = "[a, b]" then () else error "new behaviour with list_rls 2.3";
   601 === inhibit exn 110726=============================================================*)
   602 val env = env @ [(str2term "vs_s::real list", str2term s')];
   603 
   604 (*--- 4.line in script ---*)
   605 val t = str2term "hd (dropWhile (ident v_v) v_s)";
   606 val s = subst_atomic env t;
   607 term2str s;
   608 val t = str2term "hd (dropWhile (ident b) [a, b])";
   609 (*=== inhibit exn 110726=============================================================
   610 val SOME (t',_) = rewrite_set_ thy false list_rls t;
   611 val s' = term2str t';
   612 if s' = "a" then () else error "new behaviour with list_rls 2.4.";
   613 === inhibit exn 110726=============================================================*)
   614 val env = env @ [(str2term "v_1::real", str2term s')];
   615 
   616 (*--- 5.line in script ---*)
   617 val t = str2term "(SubProblem(Reals_s,[univar,equation],[no_met])\
   618 		 \           [BOOL e_1, REAL v_1])";
   619 val s = subst_atomic env t;
   620 term2str s;
   621 "SubProblem (Reals_s, [univar, equation], [no_met])\n\
   622 \ [BOOL ((a / 2) ^^^ 2 + (b / 2) ^^^ 2 = r ^^^ 2), REAL a]";
   623 val env = env @ [(str2term "s_1::bool list", 
   624 		  str2term "[a = 2 * sqrt (r^^^2 - (b/2)^^^2)]")];
   625 
   626 (*--- 6.line in script ---*)
   627 val t = str2term "Substitute [(v_1 = (rhs o hd) (s_1::bool list))] (h_h::bool)";
   628 val s = subst_atomic env t;
   629 term2str s;
   630 val t = str2term 
   631 "Substitute [(a = (rhs o hd) [a = 2 * sqrt (r ^^^ 2 - (b / 2) ^^^ 2)])]\n\
   632 \ (A = a * b)";
   633 (*=== inhibit exn 110726=============================================================
   634 mem_rls "Tools.rhs" list_rls;
   635 val SOME (t',_) = rewrite_set_ thy false list_rls t;
   636 val s' = term2str t';
   637 if s' = "Substitute [a = 2 * sqrt (r ^^^ 2 - (b / 2) ^^^ 2)] (A = a * b)" 
   638 then () else error "new behaviour with list_rls 2.6.";
   639 === inhibit exn 110726=============================================================*)
   640 
   641 
   642 "---------------------- 2.5.03: Make_fun_by_new_variable -----------------";
   643 "---------------------- 2.5.03: Make_fun_by_new_variable -----------------";
   644 "---------------------- 2.5.03: Make_fun_by_new_variable -----------------";
   645 str2term
   646   "Script Make_fun_by_new_variable (f_f::real) (v_v::real)     \
   647    \      (eqs::bool list) =                                 \
   648    \(let h_h = (hd o (filterVar f_f)) eqs;             \
   649    \     es_s = dropWhile (ident h_h) eqs;                    \
   650    \     v_s = dropWhile (ident f_f) (Vars h_h);                \
   651    \     v_1 = nth_h 1 v_s;                                   \
   652    \     v_2 = nth_h 2 v_s;                                   \
   653    \     e_1 = (hd o (filterVar v_1)) es_s;            \
   654    \     e_2 = (hd o (filterVar v_2)) es_s;            \
   655    \  (s_1::bool list) = (SubProblem (Reals_s,[univar,equation],[no_met])\
   656    \                    [BOOL e_1, REAL v_1]);\
   657    \  (s_2::bool list) = (SubProblem (Reals_s,[univar,equation],[no_met])\
   658    \                    [BOOL e_2, REAL v_2])\
   659    \in Substitute [(v_1 = (rhs o hd) s_1),(v_2 = (rhs o hd) s_2)] h_h)";
   660 val f_ = (str2term "f_f::real", 
   661 	  str2term "A");
   662 val v_v = (str2term "v_v::real", 
   663 	  str2term "alpha");
   664 val eqs=(str2term "eqs::bool list", 
   665 	  str2term "[A=a*b, a/2=r*sin alpha, b/2=r*cos alpha]");
   666 val env = [f_f, v_v, eqs];
   667 
   668 (*--- 1.line in script ---*)
   669 val t = str2term "(hd o (filterVar (f_f::real))) (eqs::bool list)";
   670 val s = subst_atomic env t;
   671 term2str s;
   672 val t = str2term 
   673 "(hd o filterVar A) [A = a * b, a / 2 = r * sin alpha, b / 2 = r * cos alpha]";
   674 trace_rewrite := false;
   675 val SOME (t',_) = rewrite_set_ thy false list_rls t;
   676 trace_rewrite:=false;
   677 val s' = term2str t';
   678 (*=== inhibit exn 110726=============================================================
   679 if s' = "A = a * b" then() else error "new behaviour with list_rls 3.1.";
   680 val env = env @ [(str2term "h_h::bool", str2term s')];
   681 === inhibit exn 110726=============================================================*)
   682 
   683 (*--- 2.line in script ---*)
   684 val t = str2term "dropWhile (ident (h_h::bool)) (eqs::bool list)";
   685 val s = subst_atomic env t;
   686 term2str s;
   687 val t = str2term 
   688 "dropWhile (ident (A = a * b))\
   689 \ [A = a * b, a / 2 = r * sin alpha, b / 2 = r * cos alpha]";
   690 (*=== inhibit exn 110726=============================================================
   691 val SOME (t',_) = rewrite_set_ thy false list_rls t;
   692 val s' = term2str t';
   693 if s' = "[a / 2 = r * sin alpha, b / 2 = r * cos alpha]" 
   694 then () else error "new behaviour with list_rls 3.2.";
   695 === inhibit exn 110726=============================================================*)
   696 val env = env @ [(str2term "es_s::bool list", str2term s')];
   697 
   698 (*--- 3.line in script ---*)
   699 val t = str2term "dropWhile (ident (f_f::real)) (Vars (h_h::bool))";
   700 val s = subst_atomic env t;
   701 term2str s;
   702 val t = str2term "dropWhile (ident A) (Vars (A = a * b))";
   703 (*=== inhibit exn 110726=============================================================
   704 val SOME (t',_) = rewrite_set_ thy false list_rls t;
   705 val s' = term2str t';
   706 if s' = "[a, b]" then () else error "new behaviour with list_rls 3.3.";
   707 === inhibit exn 110726=============================================================*)
   708 val env = env @ [(str2term "vs_s::real list", str2term s')];
   709 
   710 (*--- 4.line in script ---*)
   711 val t = str2term "nth_h 1 v_s";
   712 val s = subst_atomic env t;
   713 term2str s;
   714 val t = str2term "nth_h 1 [a, b]";
   715 (*=== inhibit exn 110726=============================================================
   716 val SOME (t',_) = rewrite_set_ thy false list_rls t;
   717 val s' = term2str t';
   718 if s' = "a" then () else error "new behaviour with list_rls 3.4.";
   719 === inhibit exn 110726=============================================================*)
   720 val env = env @ [(str2term "v_1", str2term s')];
   721 
   722 (*--- 5.line in script ---*)
   723 val t = str2term "nth_h 2 v_s";
   724 val s = subst_atomic env t;
   725 term2str s;
   726 val t = str2term "nth_h 2 [a, b]";
   727 (*=== inhibit exn 110726=============================================================
   728 val SOME (t',_) = rewrite_set_ thy false list_rls t;
   729 val s' = term2str t';
   730 if s' = "b" then () else error "new behaviour with list_rls 3.5.";
   731 === inhibit exn 110726=============================================================*)
   732 val env = env @ [(str2term "v_2", str2term s')];
   733 
   734 (*--- 6.line in script ---*)
   735 val t = str2term "(hd o (filterVar v_1)) (es_s::bool list)";
   736 val s = subst_atomic env t;
   737 term2str s;
   738 val t = str2term 
   739 	   "(hd o filterVar a) [a / 2 = r * sin alpha, b / 2 = r * cos alpha]";
   740 val SOME (t',_) = rewrite_set_ thy false list_rls t;
   741 val s' = term2str t';
   742 (*=== inhibit exn 110726=============================================================
   743 if s' = "a / 2 = r * sin alpha" then () 
   744 else error "new behaviour with list_rls 3.6.";
   745 === inhibit exn 110726=============================================================*)
   746 val e_1 = str2term "e_1::bool";
   747 val env = env @ [(e_1, str2term s')];
   748 
   749 (*--- 7.line in script ---*)
   750 val t = str2term "(hd o (filterVar v_2)) (es_s::bool list)";
   751 val s = subst_atomic env t;
   752 term2str s;
   753 val t = str2term 
   754 	  "(hd o filterVar b) [a / 2 = r * sin alpha, b / 2 = r * cos alpha]";
   755 val SOME (t',_) = rewrite_set_ thy false list_rls t;
   756 val s' = term2str t';
   757 (*=== inhibit exn 110726=============================================================
   758 if s' = "b / 2 = r * cos alpha" then () 
   759 else error "new behaviour with list_rls 3.7.";
   760 === inhibit exn 110726=============================================================*)
   761 val env = env @ [(str2term "e_2::bool", str2term s')];
   762 
   763 (*--- 8.line in script ---*)
   764 val t = str2term "(SubProblem (Reals_s,[univar,equation],[no_met])\
   765 		 \            [BOOL e_1, REAL v_1])";
   766 val s = subst_atomic env t;
   767 term2str s;
   768 "SubProblem (Reals_s, [univar, equation], [no_met])\
   769 	    \ [BOOL (a / 2 = r * sin alpha), REAL a]";
   770 val s_1 = str2term "[a = 2*r*sin alpha]";
   771 val env = env @ [(str2term "s_1::bool list", s_1)];
   772 
   773 (*--- 9.line in script ---*)
   774 val t = str2term "(SubProblem (Reals_s,[univar,equation],[no_met])\
   775    \                    [BOOL e_2, REAL v_2])";
   776 val s = subst_atomic env t;
   777 term2str s;
   778 "SubProblem (Reals_, [univar, equation], [no_met])\
   779 	    \ [BOOL (b / 2 = r * cos alpha), REAL b]";
   780 val s_2 = str2term "[b = 2*r*cos alpha]";
   781 val env = env @ [(str2term "s_2::bool list", s_2)];
   782 
   783 (*--- 10.line in script ---*)
   784 val t = str2term 
   785 "Substitute [(v_1 = (rhs o hd) s_1),(v_2 = (rhs o hd) s_2)] (h_h::bool)";
   786 val s = subst_atomic env t;
   787 term2str s;
   788 "Substitute\n [(a = (rhs o hd) [a = 2 * r * sin alpha]),\
   789 \              (b = (rhs o hd) [b = 2 * r * cos alpha])] (A = a * b)";
   790 val SOME (s',_) = rewrite_set_ thy false list_rls s;
   791 val s'' = term2str s';
   792 (*=== inhibit exn 110726=============================================================
   793 if s'' = 
   794 "Substitute [a = 2 * r * sin alpha, b = 2 * r * cos alpha] (A = a * b)"
   795 then () else error "new behaviour with list_rls 3.10.";
   796 ===== inhibit exn 110722===========================================================*)
   797