test/Tools/isac/Knowledge/diffapp.sml
author Walther Neuper <neuper@ist.tugraz.at>
Wed, 23 Mar 2011 17:20:39 +0100
branchdecompose-isar
changeset 41943 f33f6959948b
parent 41928 20138d6136cd
child 42166 911c49949ba9
permissions -rw-r--r--
make Test_Isac.thy run in jEdit; intermed.

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