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