test/Tools/isac/Knowledge/partial_fractions.sml
author Walther Neuper <neuper@ist.tugraz.at>
Thu, 05 Jan 2012 17:43:48 +0100
changeset 42359 b9d382f20232
parent 42352 52ffa99930b2
child 42376 9e59542132b3
permissions -rwxr-xr-x
quick&dirty solution for "drop_questionmarks"

The "ansatz" rules contradict the principle, that the rhs must not contain
variables which do not occur in the lhs: "A", "B", etc introduced in rhs
appear as Var ("?A" etc) in the calculation.

3 ad-hoch solutions were considered:
(1) A_ansatz, B_ansatz, etc are constants defined before the rules
+ logically cleanest
- constants do not work as bound variables in the subsequent equation
(2) put a "Calc (drop_questionsmarks ..." into the ansatz rule set
- drop_questionmarks (?A / (...)..)" would be shown to the user
(3) call "drop_questionmarks" as a script expression
- first "?A" etc appear and then disappear without explicit reason.

The case (3) has been taken as preliminary solution.
     1 (* Title:  partial fraction decomposition
     2    Author: Jan Rocnik
     3    (c) due to copyright terms
     4 *)
     5 
     6 "--------------------------------------------------------";
     7 "table of contents --------------------------------------";
     8 "--------------------------------------------------------";
     9 "----------- why helpless here ? ------------------------";
    10 "----------- why not nxt = Model_Problem here ? ---------";
    11 "----------- fun factors_from_solution ------------------";
    12 "----------- Logic.unvarify_global ----------------------";
    13 "----------- eval_drop_questionmarks --------------------";
    14 "--------------------------------------------------------";
    15 "--------------------------------------------------------";
    16 "--------------------------------------------------------";
    17 
    18 
    19 "----------- why helpless here ? ------------------------";
    20 "----------- why helpless here ? ------------------------";
    21 "----------- why helpless here ? ------------------------";
    22 val fmz = ["filterExpression (X z = 3 / (z - 1/4 + -1/8 * (1/(z::real))))", 
    23   "stepResponse (x[n::real]::bool)"];
    24 val (dI,pI,mI) = ("Isac", ["inverse", "Z_Transform", "SignalProcessing"], 
    25   ["SignalProcessing","Z_Transform","inverse"]);
    26 val (p,_,f,nxt,_,pt)  = CalcTreeTEST [(fmz, (dI,pI,mI))]; 
    27 val (p,_,f,nxt,_,pt) = me nxt p [] pt; "Add_Given";
    28 val (p,_,f,nxt,_,pt) = me nxt p [] pt; "Add_Find";
    29 val (p,_,f,nxt,_,pt) = me nxt p [] pt; "Specify_Theory";
    30 val (p,_,f,nxt,_,pt) = me nxt p [] pt; "Specify_Problem";
    31 val (p,_,f,nxt,_,pt) = me nxt p [] pt; "Specify_Method";
    32 val (p,_,f,nxt,_,pt) = me nxt p [] pt; "nxt = Apply_Method";
    33 val (p,_,f,nxt,_,pt) = me nxt p [] pt; "nxt = Rewrite (ruleZY, Inverse_Z_Transform.ruleZY) --> X z = 3 / (z - 1 / 4 + -1 / 8 * (1 / z))";
    34 val (p''',_,f,nxt''',_,pt''') = me nxt p [] pt; "nxt = Rewrite_Set norm_Rational --> X' z = 3 / (z * (z - 1 / 4 + -1 / 8 * (1 / z)))";
    35 "~~~~~ fun me, args:"; val ((_,tac), (p:pos'), _, (pt:ptree)) = (nxt, p, [], pt);
    36 val ("ok", (_, _, ptp)) = locatetac tac (pt,p)
    37 val (pt, p) = ptp;
    38 "~~~~~ fun step, args:"; val (((ip as (_,p_)):pos'), ((ptp as (pt,p), tacis):calcstate)) = 
    39                            (p, ((pt, e_pos'),[]));
    40 val pIopt = get_pblID (pt,ip);
    41 ip = ([],Res); "false";
    42 tacis; " = []";
    43 pIopt; (* = SOME ["inverse", "Z_Transform", "SignalProcessing"]*)
    44 member op = [Pbl,Met] p_ andalso is_none (get_obj g_env pt (fst p)); "false";
    45 (*nxt_solve_ (pt,ip); "WAS isalist2list applied to NON-list 'no_meth'"
    46    THIS MEANS: replace no_meth by [no_meth] in Script.*)
    47 (*WAS val ("helpless",_) = step p ((pt, e_pos'),[]) *)
    48 (*WAS val (p,_,f,nxt,_,pt) = me nxt p [] pt; "Empty_Tac instead SubProblem";*)
    49 
    50 "----------- why not nxt = Model_Problem here ? ---------";
    51 "----------- why not nxt = Model_Problem here ? ---------";
    52 "----------- why not nxt = Model_Problem here ? ---------";
    53 val (p,_,f,nxt,_,pt) = me nxt''' p''' [] pt'''; 
    54 "~~~~~ fun me, args:"; val (((_,tac):tac'_), (p:pos'), _, (pt:ptree)) = (nxt, p, c, pt);
    55 val ("ok", (_, _, ptp)) = locatetac tac (pt,p);
    56 val (pt, p) = ptp;
    57 "~~~~~ fun step, args:"; val (((ip as (_,p_)):pos'), ((ptp as (pt,p), tacis):calcstate)) =
    58                            (p, ((pt, e_pos'),[]));
    59 val pIopt = get_pblID (pt,ip);
    60 ip = ([],Res); " = false";
    61 tacis; " = []";                                         
    62 pIopt (* = SOME ["inverse", "Z_Transform", "SignalProcessing"]*);
    63 member op = [Pbl,Met] p_ andalso is_none (get_obj g_env pt (fst p)); " = false";
    64 (*                               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ leads into
    65 nxt_solve_, which is definitely WRONG (should be nxt_specify_ for FIND_ADD).
    66 This ERROR seems to be introduced together with ctxt, concerns Apply_Method without init_form.
    67 See TODO.txt
    68 *)
    69 
    70 "----------- fun factors_from_solution ------------------";
    71 "----------- fun factors_from_solution ------------------";
    72 "----------- fun factors_from_solution ------------------";
    73 val ctxt = ProofContext.init_global @{theory Isac};
    74 val SOME t = parseNEW ctxt "factors_from_solution [(z::real) = 1 / 2, z = -1 / 4]";
    75 val SOME (_, t') = eval_factors_from_solution "" 0 t thy;
    76 if term2str t' =
    77  "factors_from_solution [z = 1 / 2, z = -1 / 4] =\n(z + -1 * (1 / 2)) * (z + -1 * (-1 / 4))"
    78 then () else error "factors_from_solution broken";
    79 
    80 "----------- Logic.unvarify_global ----------------------";
    81 "----------- Logic.unvarify_global ----------------------";
    82 "----------- Logic.unvarify_global ----------------------";
    83 val A_var = parseNEW ctxt "A::real" |> the |> Logic.varify_global
    84 val B_var = parseNEW ctxt "B::real" |> the |> Logic.varify_global
    85 
    86 val denom1 = parseNEW ctxt "(z + -1 * (1 / 2))::real" |> the;
    87 val denom2 = parseNEW ctxt "(z + -1 * (-1 / 4))::real" |> the;
    88 
    89 val test = HOLogic.mk_binop "Groups.plus_class.plus"
    90   (HOLogic.mk_binop "Rings.inverse_class.divide" (A_var, denom1),
    91    HOLogic.mk_binop "Rings.inverse_class.divide" (B_var, denom2));
    92 
    93 if term2str test = "?A / (z + -1 * (1 / 2)) + ?B / (z + -1 * (-1 / 4))" then ()
    94   else error "HOLogic.mk_binop broken ?";
    95 
    96 (* Logic.unvarify_global test
    97 ---> exception TERM raised (line 539 of "logic.ML"): Illegal fixed variable: "z"
    98 thus we need another fun var2free in termC.sml*)
    99 
   100 "----------- eval_drop_questionmarks --------------------";
   101 "----------- eval_drop_questionmarks --------------------";
   102 "----------- eval_drop_questionmarks --------------------";
   103 if term2str test = "?A / (z + -1 * (1 / 2)) + ?B / (z + -1 * (-1 / 4))"
   104 then () else error "test setup (ctxt!) probably changed";
   105 
   106 val t = Const ("Partial_Fractions.drop_questionmarks", HOLogic.realT --> HOLogic.realT) $ test;
   107 
   108 val SOME (_, t') = eval_drop_questionmarks "drop_questionmarks" 0 t @{theory Isac};
   109 if term2str t' = "drop_questionmarks (?A / (z + -1 * (1 / 2)) + ?B / (z + -1 * (-1 / 4))) =" ^
   110   "\nA / (z + -1 * (1 / 2)) + B / (z + -1 * (-1 / 4))"
   111 then () else error "eval_drop_questionmarks broken";
   112