test/Tools/isac/ADDTESTS/course/phst11/T3_MathEngine.thy
author Walther Neuper <neuper@ist.tugraz.at>
Mon, 02 Sep 2013 16:16:08 +0200
changeset 52101 c3f399ce32af
parent 42081 b5a91fb4330c
child 59111 c730b643bc0e
permissions -rw-r--r--
Test_Isac works again, almost ..

4 files raise errors:
# Interpret/solve.sml: "solve.sml: interSteps on norm_Rational 2"
# Interpret/inform.sml: "inform.sml: [rational,simplification] 2"
# Knowledge/partial_fractions.sml: "autoCalculate for met_partial_fraction changed: final result"
# Knowledge/eqsystem.sml: "eqsystem.sml: exp 7.70 normalize 4x4 by rewrite changed"

The chunk of changes is due to the fact, that Isac's code still is unstable.
The changes are accumulated since e8f46493af82.
     1 (*
     2 cd /usr/local/Isabelle/test/Tools/isac/ADDTESTS/course/
     3 /usr/local/Isabelle/bin/isabelle jedit -l Isac T2_Rewriting.thy &
     4 *)
     5 
     6 theory T3_MathEngine imports Isac begin
     7 
     8 chapter {* ISACs mathematics engine *}
     9 text {* This is a brief introduction to ISACs mathematics engine (ME). The
    10   goal of the introduction is enabling authors to test new developments of
    11   knowledge.
    12   As an example we continue the previous one on rewriting. The previous
    13   chapter raised questions about didactics and stated open developments problems.
    14   So, let us assume, some additional knowledge has been added to solve some of
    15   the open problems with '-' in simplification.
    16   Now we want to test, if 
    17       Vereinfache (5*e + 6*f - 8*g - 9 - 7*e - 4*f + 10*g + 12)
    18   really simplifies to
    19       3 - 2 * e + 2 * f + 2 * g
    20 *}
    21 
    22 section {* Knowledge for automated solving the example problem *}
    23 text {* ISAC wants to show possibilities for next steps, if learners get stuck.
    24   So, at least ISAC needs to be able to solve a problem automatically. For this
    25   purpose, ISAC requires three kinds of knowledge, (1) rules to apply (2) a 
    26   specification of the problem and (3) a method solving the problem.
    27 
    28   ad (1) The rules required for simplifying our example are found in theory
    29   ~~/Tools/isac/Knowledge/PolyMinus.thy. 
    30 
    31   ad (2) The problem of 'vereinfachen' is one of many other problems;
    32   the function 'get_pbt' gets the one we need:  
    33 *}
    34 ML {* show_ptyps ();
    35   get_pbt ["plus_minus", "polynom", "vereinfachen"];
    36 *}
    37 text {* However, 'get_pbt' shows an internal format; for a human readable format
    38   see http://www.ist.tugraz.at/projects/isac/www/kbase/pbl/index_pbl.html
    39   Note, that in this tree you first lookup "vereinfachen", then "polynom" and
    40   finally "plus_minus", the same as you see from 'show_ptyps ()'.
    41   However, we call the problem "plus_minus - polynom - vereinfachen".
    42 
    43   ad (3) The method solving the problem is also one of many others; the function
    44   'get_met' gets the one we need:
    45 *}
    46 ML {*
    47 show_mets ();
    48 get_met ["simplification","for_polynomials","with_minus"];
    49 *}
    50 text {* For a readable format of the method look up the definition in
    51   ~~/Tools/isac/Knowledge/PolyMinus.thy or 
    52   http://www.ist.tugraz.at/projects/isac/www/kbase/met/index_met.html
    53   The path to the method "simplification - for_polynomials - with_minus" is
    54   not reversed like the one to the problem, because the structure of the
    55   methods' container is not yet clarified.
    56 *}
    57 
    58 section {* Testing the example problem *}
    59 text {* Now we have all the knowledge ISAC requires for guiding the learner:
    60   (1) the theory "PolyMinus", (2) the problem ["plus_minus","polynom","vereinfachen"]
    61   and (3) the method ["simplification","for_polynomials","with_minus"].
    62 
    63   So we can start testing the example by calling 'CalcTreeTEST':
    64 *}
    65 ML {* val (p,_,f,nxt,_,pt) = 
    66       CalcTreeTEST 
    67         [(["Term (5*e + 6*f - 8*g - 9 - 7*e - 4*f + 10*g + 12)",
    68            "normalform N"],
    69 	          ("PolyMinus",["plus_minus","polynom","vereinfachen"],
    70 	           ["simplification","for_polynomials","with_minus"]))];
    71 *}
    72 text {* The function 'CalcTreeTEST' returns the following values:
    73   p:    the position in the calculation
    74   f:    the formula produced by this step of calculation.
    75         In this case 'f' is an incomplete model of the problem.
    76   nxt:  the tactic suggested to do the next step
    77   pt:   the _whole_ calculation in an internal format; the calculation 'pt'
    78         will be fed back into the mathematics engine, the function 'me' below,
    79         'me' is purely functional, no further data remains in the memory.
    80         'me' returns the same data as 'CalcTreeTEST'.
    81 
    82   The first tactic suggested by ISAC is 'Model_Problem', we use this tactic
    83   (stored in 'nxt') and enter the 'specification phase'.
    84 *}
    85 
    86 section {* Specifying the example problem *}
    87 text {* Often the specification phase is hidden from the learner by the dialog 
    88   module; here we see the mathematics engine at work directly.
    89 
    90   Only note the tactic 'nxt' suggested for the next step:
    91 *}
    92 ML {* val c = [(*this is an unimportant, but necessary detail*)];
    93   val (p,_,f,nxt,_,pt) = me nxt p c pt;
    94   val (p,_,f,nxt,_,pt) = me nxt p c pt;
    95 *}
    96 text{* The tactics 'Add_Given' and 'Add_Find' inserted the respective values
    97   into the model. Then 'Specify_Theory' determines the knowledge item no.1 from
    98   above, 'Specify_Problem' item 2 and 'Specify_Method' item 3.
    99 *}
   100 ML {* 
   101   val (p,_,f,nxt,_,pt) = me nxt p c pt;
   102   val (p,_,f,nxt,_,pt) = me nxt p c pt;
   103   val (p,_,f,nxt,_,pt) = me nxt p c pt;
   104   val (p,_,f,nxt,_,pt) = me nxt p c pt;
   105 *}
   106 text{* The final suggestion 'Apply_Method' completes the specification phase
   107   and starts the 'solving phase', which is guided by the method determined.
   108 *}
   109 
   110 section {* Solving the example problem *}
   111 text {* Now let us observe, how the method ["simplification","for_polynomials",
   112   "with_minus"] guides through simplification by rewriting. For that purpose
   113   we increase the 'print_depth' (with the disadvantage of extending the output)
   114   and print out the results by use of 'f2str'.
   115   Please, note only 'nxt' close to the beginning of the output and the resulting
   116   term at the end:
   117 *}
   118 ML {* print_depth 40; *}
   119 ML {* val (p,_,f,nxt,_,pt) = me nxt p c pt; f2str f; *}
   120 ML {* val (p,_,f,nxt,_,pt) = me nxt p c pt; f2str f; *}
   121 ML {* val (p,_,f,nxt,_,pt) = me nxt p c pt; f2str f; *}
   122 ML {* val (p,_,f,nxt,_,pt) = me nxt p c pt; f2str f; *}
   123 ML {* print_depth 3; *}
   124 text{* And, please, note that the result of applying the 'nxt' ruleset is to be
   125   found in the output of the next step !
   126 *}
   127 
   128 section {* Completing the example problem *}
   129 text {* The 'nxt' tactic suggested above was 'Check_Postcond'. That means, a
   130   perfect mathematics engine has to prove the socalled 'postcondition' of the
   131   current problem; this is not yet implemented in the current version of ISAC.
   132 *}
   133 ML {* val (p,_,f,nxt,_,pt) = me nxt p c pt; f2str f; *}
   134 text{* Now the mathematics engine has found the end of the calculation.
   135 
   136   With 'show_pt' the calculation can be inspected (in a more or less readable
   137   format) by clicking the checkbox <Tracing> on top of the <Output> window:
   138 *}
   139 ML {* show_pt pt *}
   140 
   141 
   142 section {* Test further examples *}
   143 text{* Now it is easy to do further examples: just put another calculation into
   144   the formalisation:
   145 *}
   146 ML {* val (p,_,f,nxt,_,pt) = 
   147       CalcTreeTEST 
   148         [(["Term (1 + 2 + 3)", "normalform N"],
   149 	          ("PolyMinus",["plus_minus","polynom","vereinfachen"],
   150 	           ["simplification","for_polynomials","with_minus"]))];
   151 *}
   152 ML {* val (p,_,f,nxt,_,pt) = me nxt p c pt; *}
   153 text{* and repeat this ML line as often as required ...*}
   154 
   155 end