test/Tools/isac/ADDTESTS/course/SignalProcess/Build_Inverse_Z_Transform.thy
author Walther Neuper <neuper@ist.tugraz.at>
Thu, 13 Oct 2011 15:03:28 +0200
branchdecompose-isar
changeset 42315 c2e6ac4a5d04
parent 42310 55931ca19f4d
child 42335 7bb5070f2415
permissions -rwxr-xr-x
Build_Inverse_Z_Transform 1 step further

the expected error in isac:
prep. repair Apply_Method without init_form
was a simple error in the CTP-based program
neuper@42301
     1
(* Title:  Build_Inverse_Z_Transform
neuper@42279
     2
   Author: Jan Rocnik
neuper@42279
     3
   (c) copyright due to lincense terms.
neuper@42279
     4
12345678901234567890123456789012345678901234567890123456789012345678901234567890
neuper@42279
     5
        10        20        30        40        50        60        70        80
neuper@42279
     6
*)
neuper@42279
     7
jan@42298
     8
theory Build_Inverse_Z_Transform imports Isac
neuper@42289
     9
  
neuper@42289
    10
begin
neuper@42279
    11
neuper@42289
    12
text{* We stepwise build Inverse_Z_Transform.thy as an exercise.
jan@42299
    13
  Because subsection "Stepwise Check the Program" requires 
jan@42299
    14
  Inverse_Z_Transform.thy as a subtheory of Isac.thy, the setup has been changed 
jan@42299
    15
  from "theory Inverse_Z_Transform imports Isac begin.." to the above.
neuper@42279
    16
neuper@42279
    17
  ATTENTION WITH NAMES OF IDENTIFIERS WHEN GOING INTO INTERNALS:
neuper@42279
    18
  Here in this theory there are the internal names twice, for instance we have
neuper@42279
    19
  (Thm.derivation_name @{thm rule1} = "Build_Inverse_Z_Transform.rule1") = true;
neuper@42279
    20
  but actually in us will be "Inverse_Z_Transform.rule1"
neuper@42279
    21
*}
neuper@42279
    22
ML {*val thy = @{theory Isac};*}
neuper@42279
    23
neuper@42279
    24
neuper@42279
    25
section {*trials towards Z transform *}
neuper@42279
    26
text{*===============================*}
neuper@42279
    27
subsection {*terms*}
neuper@42279
    28
ML {*
neuper@42279
    29
@{term "1 < || z ||"};
neuper@42279
    30
@{term "z / (z - 1)"};
neuper@42279
    31
@{term "-u -n - 1"};
neuper@42279
    32
@{term "-u [-n - 1]"}; (*[ ] denotes lists !!!*)
neuper@42279
    33
@{term "z /(z - 1) = -u [-n - 1]"};Isac
neuper@42279
    34
@{term "1 < || z || ==> z / (z - 1) = -u [-n - 1]"};
neuper@42279
    35
term2str @{term "1 < || z || ==> z / (z - 1) = -u [-n - 1]"};
neuper@42279
    36
*}
neuper@42279
    37
ML {*
neuper@42279
    38
(*alpha -->  "</alpha>" *)
neuper@42279
    39
@{term "\<alpha> "};
neuper@42279
    40
@{term "\<delta> "};
neuper@42279
    41
@{term "\<phi> "};
neuper@42279
    42
@{term "\<rho> "};
neuper@42279
    43
term2str @{term "\<rho> "};
neuper@42279
    44
*}
neuper@42279
    45
neuper@42279
    46
subsection {*rules*}
neuper@42279
    47
(*axiomatization "z / (z - 1) = -u [-n - 1]" Illegal variable name: "z / (z - 1) = -u [-n - 1]" *)
neuper@42279
    48
(*definition     "z / (z - 1) = -u [-n - 1]" Bad head of lhs: existing constant "op /"*)
neuper@42279
    49
axiomatization where 
neuper@42279
    50
  rule1: "1 = \<delta>[n]" and
neuper@42279
    51
  rule2: "|| z || > 1 ==> z / (z - 1) = u [n]" and
neuper@42279
    52
  rule3: "|| z || < 1 ==> z / (z - 1) = -u [-n - 1]" and 
neuper@42279
    53
  rule4: "|| z || > || \<alpha> || ==> z / (z - \<alpha>) = \<alpha>^^^n * u [n]" and
neuper@42279
    54
  rule5: "|| z || < || \<alpha> || ==> z / (z - \<alpha>) = -(\<alpha>^^^n) * u [-n - 1]" and
neuper@42279
    55
  rule6: "|| z || > 1 ==> z/(z - 1)^^^2 = n * u [n]"
neuper@42279
    56
ML {*
neuper@42279
    57
@{thm rule1};
neuper@42279
    58
@{thm rule2};
neuper@42279
    59
@{thm rule3};
neuper@42279
    60
@{thm rule4};
neuper@42279
    61
*}
neuper@42279
    62
neuper@42279
    63
subsection {*apply rules*}
neuper@42279
    64
ML {*
neuper@42279
    65
val inverse_Z = append_rls "inverse_Z" e_rls
neuper@42279
    66
  [ Thm  ("rule3",num_str @{thm rule3}),
neuper@42279
    67
    Thm  ("rule4",num_str @{thm rule4}),
neuper@42279
    68
    Thm  ("rule1",num_str @{thm rule1})   
neuper@42279
    69
  ];
neuper@42279
    70
neuper@42279
    71
val t = str2term "z / (z - 1) + z / (z - \<alpha>) + 1";
neuper@42279
    72
val SOME (t', asm) = rewrite_set_ thy true inverse_Z t;
neuper@42279
    73
term2str t' = "z / (z - ?\<delta> [?n]) + z / (z - \<alpha>) + ?\<delta> [?n]"; (*attention rule1 !!!*)
neuper@42279
    74
*}
neuper@42279
    75
ML {*
neuper@42279
    76
val (thy, ro, er) = (@{theory Isac}, tless_true, eval_rls);
neuper@42279
    77
*}
neuper@42279
    78
ML {*
neuper@42279
    79
val SOME (t, asm1) = rewrite_ thy ro er true (num_str @{thm rule3}) t;
neuper@42279
    80
term2str t = "- ?u [- ?n - 1] + z / (z - \<alpha>) + 1"; (*- real *)
neuper@42301
    81
term2str t;*}
neuper@42279
    82
ML {*
neuper@42279
    83
val SOME (t, asm2) = rewrite_ thy ro er true (num_str @{thm rule4}) t;
neuper@42279
    84
term2str t = "- ?u [- ?n - 1] + \<alpha> ^^^ ?n * ?u [?n] + 1"; (*- real *)
neuper@42279
    85
term2str t;
neuper@42279
    86
*}
neuper@42279
    87
ML {*
neuper@42279
    88
val SOME (t, asm3) = rewrite_ thy ro er true (num_str @{thm rule1}) t;
neuper@42279
    89
term2str t = "- ?u [- ?n - 1] + \<alpha> ^^^ ?n * ?u [?n] + ?\<delta> [?n]"; (*- real *)
neuper@42279
    90
term2str t;
neuper@42279
    91
*}
neuper@42279
    92
ML {*
neuper@42279
    93
terms2str (asm1 @ asm2 @ asm3);
neuper@42279
    94
*}
neuper@42279
    95
jan@42296
    96
section {*Prepare steps for CTP-based programming language*}
jan@42296
    97
text{*TODO insert Calculation (Referenz?!)
jan@42296
    98
jan@42296
    99
The goal... realized in sections below, in Sect.\ref{spec-meth} and Sect.\ref{prog-steps} 
jan@42296
   100
jan@42296
   101
the reader is advised to jump between the subsequent subsections and the respective steps in Sect.\ref{prog-steps} 
jan@42296
   102
jan@42296
   103
*}
jan@42296
   104
subsection {*prepare expression \label{prep-expr}*}
neuper@42279
   105
ML {*
neuper@42279
   106
val ctxt = ProofContext.init_global @{theory Isac};
neuper@42279
   107
val ctxt = declare_constraints' [@{term "z::real"}] ctxt;
neuper@42279
   108
neuper@42279
   109
val SOME fun1 = parseNEW ctxt "X z = 3 / (z - 1/4 + -1/8 * z ^^^ -1)"; term2str fun1;
neuper@42279
   110
val SOME fun1' = parseNEW ctxt "X z = 3 / (z - 1/4 + -1/8 * (1/z))"; term2str fun1';
neuper@42279
   111
*}
neuper@42279
   112
jan@42298
   113
subsubsection {*multply with z*}
neuper@42279
   114
axiomatization where
neuper@42279
   115
  ruleZY: "(X z = a / b) = (X' z = a / (z * b))"
neuper@42279
   116
neuper@42279
   117
ML {*
neuper@42279
   118
val (thy, ro, er) = (@{theory Isac}, tless_true, eval_rls);
neuper@42279
   119
val SOME (fun2, asm1) = rewrite_ thy ro er true  @{thm ruleZY} fun1; term2str fun2;
neuper@42279
   120
val SOME (fun2', asm1) = rewrite_ thy ro er true  @{thm ruleZY} fun1'; term2str fun2';
neuper@42279
   121
neuper@42279
   122
val SOME (fun3,_) = rewrite_set_ @{theory Isac} false norm_Rational fun2;
neuper@42279
   123
term2str fun3; (*fails on x^^^(-1) TODO*)
neuper@42279
   124
val SOME (fun3',_) = rewrite_set_ @{theory Isac} false norm_Rational fun2';
neuper@42279
   125
term2str fun3'; (*OK*)
neuper@42289
   126
*}
neuper@42279
   127
jan@42298
   128
subsubsection {*get argument of X': z is the variable the equation is solved for*}
jan@42298
   129
text{*grep... Atools.thy, Tools.thy contain general utilities: eval_argument_in, eval_rhs, eval_lhs,...
jan@42298
   130
jan@42298
   131
grep -r "fun eva_" ... shows all functions witch can be used in a script.
jan@42298
   132
lookup this files how to build and handle such functions.
jan@42298
   133
jan@42298
   134
the next section shows how to introduce such a function.
jan@42298
   135
*}
jan@42298
   136
neuper@42302
   137
subsubsection {*Decompose given term into lhs = rhs*}
neuper@42302
   138
ML {*
neuper@42302
   139
  val (_, expr) = HOLogic.dest_eq fun3'; term2str expr;
neuper@42302
   140
  val (_, denom) = HOLogic.dest_bin "Rings.inverse_class.divide" (type_of expr) expr;
neuper@42302
   141
  term2str denom = "-1 + -2 * z + 8 * z ^^^ 2";
neuper@42302
   142
*}
neuper@42302
   143
text {*we have rhs in the Script language, but we need a function 
neuper@42302
   144
  which gets the denominator of a fraction*}
jan@42298
   145
jan@42298
   146
text{*---------------------------begin partial fractions snip--------------------------*}
jan@42298
   147
jan@42298
   148
subsubsection {*get the denominator out of a fraction*}
jan@42298
   149
text {*get denominator should become a constant for the isabelle parser: *}
jan@42298
   150
jan@42298
   151
consts
neuper@42302
   152
  get_denominator :: "real => real"
jan@42298
   153
neuper@42302
   154
text {* With the above definition we run into problems with parsing the Script InverseZTransform:
neuper@42302
   155
  This leads to "ambiguous parse trees" and we avoid this by shifting the definition
neuper@42302
   156
  to Rationa.thy and re-building Isac.
neuper@42302
   157
  ATTENTION: from now on Build_Inverse_Z_Transform mimics a build from scratch;
neuper@42302
   158
  it only works due to re-building Isac several times (indicated explicityl).
neuper@42302
   159
*}
jan@42300
   160
jan@42298
   161
ML {*
neuper@42301
   162
(*("get_denominator", ("Rational.get_denominator", eval_get_denominator ""))*)
jan@42298
   163
fun eval_get_denominator (thmid:string) _ 
neuper@42301
   164
		      (t as Const ("Rational.get_denominator", _) $
jan@42298
   165
              (Const ("Rings.inverse_class.divide", _) $ num $
jan@42298
   166
                denom)) thy = 
neuper@42302
   167
        SOME (mk_thmid thmid "" 
jan@42298
   168
            (Print_Mode.setmp [] (Syntax.string_of_term (thy2ctxt thy)) denom) "", 
jan@42298
   169
	          Trueprop $ (mk_equality (t, denom)))
jan@42300
   170
  | eval_get_denominator _ _ _ _ = NONE; 
jan@42299
   171
jan@42298
   172
*}
neuper@42302
   173
text {* tests of eval_get_denominator see test/Knowledge/rational.sml*}
neuper@42289
   174
jan@42297
   175
jan@42297
   176
text{*---------------------------end partial fractions snip--------------------------*}
neuper@42279
   177
neuper@42279
   178
subsection {*solve equation*}
neuper@42279
   179
text {*this type of equation if too general for the present program*}
neuper@42279
   180
ML {*
neuper@42279
   181
"----------- Minisubplb/100-init-rootp (*OK*)bl.sml ---------------------";
neuper@42279
   182
val denominator = parseNEW ctxt "z^^^2 - 1/4*z - 1/8 = 0";
neuper@42279
   183
val fmz = ["equality (z^^^2 - 1/4*z - 1/8 = (0::real))", "solveFor z","solutions L"];
neuper@42279
   184
val (dI',pI',mI') =("Isac", ["univariate","equation"], ["no_met"]);
neuper@42279
   185
(*                           ^^^^^^^^^^^^^^^^^^^^^^ TODO: ISAC determines type of eq*)
neuper@42279
   186
*}
neuper@42279
   187
text {*Does the Equation Match the Specification ?*}
neuper@42279
   188
ML {*
neuper@42279
   189
match_pbl fmz (get_pbt ["univariate","equation"]);
neuper@42279
   190
*}
neuper@42279
   191
ML {*Context.theory_name thy = "Isac"(*==================================================*)*}
neuper@42279
   192
neuper@42279
   193
ML {*
neuper@42303
   194
val denominator = parseNEW ctxt "-1 + -2 * z + 8 * z ^^^ 2 = 0";
neuper@42279
   195
val fmz =                                            (*specification*)
neuper@42303
   196
  ["equality (-1 + -2 * z + 8 * z ^^^ 2 = (0::real))", (*equality*)
neuper@42279
   197
   "solveFor z",                                     (*bound variable*)
neuper@42279
   198
   "solutions L"];                                   (*identifier for solution*)
jan@42300
   199
neuper@42279
   200
val (dI',pI',mI') =
neuper@42303
   201
  ("Isac", ["abcFormula","degree_2","polynomial","univariate","equation"], ["no_met"]);
neuper@42279
   202
*}
neuper@42279
   203
text {*Does the Other Equation Match the Specification ?*}
neuper@42279
   204
ML {*
neuper@42303
   205
match_pbl fmz (get_pbt ["abcFormula","degree_2","polynomial","univariate","equation"]);
neuper@42279
   206
*}
neuper@42279
   207
text {*Solve Equation Stepwise*}
neuper@42279
   208
ML {*
neuper@42303
   209
*}
neuper@42303
   210
ML {*
neuper@42279
   211
val (p,_,f,nxt,_,pt) = CalcTreeTEST [(fmz, (dI',pI',mI'))];
neuper@42279
   212
val (p,_,f,nxt,_,pt) = me nxt p [] pt;
neuper@42279
   213
val (p,_,f,nxt,_,pt) = me nxt p [] pt;
neuper@42279
   214
val (p,_,f,nxt,_,pt) = me nxt p [] pt;
neuper@42279
   215
val (p,_,f,nxt,_,pt) = me nxt p [] pt;
neuper@42279
   216
val (p,_,f,nxt,_,pt) = me nxt p [] pt;
neuper@42279
   217
val (p,_,f,nxt,_,pt) = me nxt p [] pt;
neuper@42279
   218
val (p,_,f,nxt,_,pt) = me nxt p [] pt;
neuper@42279
   219
val (p,_,f,nxt,_,pt) = me nxt p [] pt;
neuper@42279
   220
val (p,_,f,nxt,_,pt) = me nxt p [] pt;
neuper@42279
   221
val (p,_,f,nxt,_,pt) = me nxt p [] pt;
neuper@42279
   222
val (p,_,f,nxt,_,pt) = me nxt p [] pt;         
neuper@42279
   223
val (p,_,f,nxt,_,pt) = me nxt p [] pt; (*nxt =..,Check_elementwise "Assumptions")*)
neuper@42279
   224
val (p,_,f,nxt,_,pt) = me nxt p [] pt;         
neuper@42279
   225
val (p,_,f,nxt,_,pt) = me nxt p [] pt; f2str f;
neuper@42303
   226
(*[z = 1 / 2, z = -1 / 4]*)
neuper@42279
   227
show_pt pt; 
neuper@42279
   228
val SOME f = parseNEW ctxt "[z=1/2, z=-1/4]";
neuper@42279
   229
*}
neuper@42279
   230
neuper@42279
   231
subsection {*partial fraction decomposition*}
neuper@42279
   232
subsubsection {*solution of the equation*}
neuper@42279
   233
ML {*
neuper@42279
   234
val SOME solutions = parseNEW ctxt "[z=1/2, z=-1/4]";
neuper@42279
   235
term2str solutions;
neuper@42279
   236
atomty solutions;
neuper@42279
   237
*}
neuper@42279
   238
neuper@42279
   239
subsubsection {*get solutions out of list*}
neuper@42279
   240
text {*in isac's CTP-based programming language: let$ $s_1 = NTH 1$ solutions; $s_2 = NTH 2...$*}
neuper@42279
   241
ML {*
neuper@42279
   242
val Const ("List.list.Cons", _) $ s_1 $ (Const ("List.list.Cons", _) $
neuper@42279
   243
      s_2 $ Const ("List.list.Nil", _)) = solutions;
neuper@42279
   244
term2str s_1;
neuper@42279
   245
term2str s_2;
neuper@42279
   246
*}
neuper@42279
   247
neuper@42279
   248
ML {* (*Solutions as Denominator --> Denominator1 = z - Zeropoint1, Denominator2 = z-Zeropoint2,...*)
neuper@42279
   249
val xx = HOLogic.dest_eq s_1;
neuper@42279
   250
val s_1' = HOLogic.mk_binop "Groups.minus_class.minus" xx;
neuper@42279
   251
val xx = HOLogic.dest_eq s_2;
neuper@42279
   252
val s_2' = HOLogic.mk_binop "Groups.minus_class.minus" xx;
neuper@42279
   253
term2str s_1';
neuper@42279
   254
term2str s_2';
neuper@42279
   255
*}
neuper@42279
   256
neuper@42279
   257
subsubsection {*build expression*}
neuper@42279
   258
text {*in isac's CTP-based programming language: let s_1 = Take numerator / (s_1 * s_2)*}
neuper@42279
   259
ML {*
neuper@42279
   260
(*The Main Denominator is the multiplikation of the partial fraction denominators*)
neuper@42279
   261
val denominator' = HOLogic.mk_binop "Groups.times_class.times" (s_1', s_2') ;
neuper@42279
   262
val SOME numerator = parseNEW ctxt "3::real";
neuper@42279
   263
neuper@42279
   264
val expr' = HOLogic.mk_binop "Rings.inverse_class.divide" (numerator, denominator');
neuper@42279
   265
term2str expr';
neuper@42279
   266
*}
neuper@42279
   267
neuper@42279
   268
subsubsection {*Ansatz - create partial fractions out of our expression*}
neuper@42302
   269
ML {*Context.theory_name thy = "Isac"*}
neuper@42279
   270
neuper@42279
   271
axiomatization where
neuper@42279
   272
  ansatz2: "n / (a*b) = A/a + B/(b::real)" and
neuper@42279
   273
  multiply_eq2: "(n / (a*b) = A/a + B/b) = (a*b*(n  / (a*b)) = a*b*(A/a + B/b))"
neuper@42279
   274
neuper@42279
   275
ML {*
neuper@42279
   276
(*we use our ansatz2 to rewrite our expression and get an equilation with our expression on the left and the partial fractions of it on the right side*)
neuper@42279
   277
val SOME (t1,_) = rewrite_ @{theory Isac} e_rew_ord e_rls false @{thm ansatz2} expr';
neuper@42279
   278
term2str t1; atomty t1;
neuper@42279
   279
val eq1 = HOLogic.mk_eq (expr', t1);
neuper@42279
   280
term2str eq1;
neuper@42279
   281
*}
neuper@42279
   282
ML {*
neuper@42279
   283
(*eliminate the demoninators by multiplying the left and the right side with the main denominator*)
neuper@42279
   284
val SOME (eq2,_) = rewrite_ @{theory Isac} e_rew_ord e_rls false @{thm multiply_eq2} eq1;
neuper@42279
   285
term2str eq2;
neuper@42279
   286
*}
neuper@42279
   287
ML {*
neuper@42279
   288
(*simplificatoin*)
neuper@42279
   289
val SOME (eq3,_) = rewrite_set_ @{theory Isac} false norm_Rational eq2;
neuper@42279
   290
term2str eq3; (*?A ?B not simplified*)
neuper@42279
   291
*}
neuper@42279
   292
ML {*
neuper@42279
   293
val SOME fract1 =
neuper@42279
   294
  parseNEW ctxt "(z - 1 / 2) * (z - -1 / 4) * (A / (z - 1 / 2) + B / (z - -1 / 4))"; (*A B !*)
neuper@42279
   295
val SOME (fract2,_) = rewrite_set_ @{theory Isac} false norm_Rational fract1;
neuper@42279
   296
term2str fract2 = "(A + -2 * B + 4 * A * z + 4 * B * z) / 4";
neuper@42279
   297
(*term2str fract2 = "A * (1 / 4 + z) + B * (-1 / 2 + z)" would be more traditional*)
neuper@42279
   298
*}
neuper@42279
   299
ML {*
neuper@42279
   300
val (numerator, denominator) = HOLogic.dest_eq eq3;
neuper@42279
   301
val eq3' = HOLogic.mk_eq (numerator, fract1); (*A B !*)
neuper@42279
   302
term2str eq3';
neuper@42279
   303
(*MANDATORY: simplify (and remove denominator) otherwise 3 = 0*)
neuper@42279
   304
val SOME (eq3'' ,_) = rewrite_set_ @{theory Isac} false norm_Rational eq3';
neuper@42279
   305
term2str eq3'';
neuper@42279
   306
*}
neuper@42279
   307
ML {*Context.theory_name thy = "Isac"(*==================================================*)*}
neuper@42279
   308
neuper@42279
   309
subsubsection {*get first koeffizient*}
neuper@42279
   310
neuper@42279
   311
ML {*
neuper@42279
   312
(*substitude z with the first zeropoint to get A*)
neuper@42279
   313
val SOME (eq4_1,_) = rewrite_terms_ @{theory Isac} e_rew_ord e_rls [s_1] eq3'';
neuper@42279
   314
term2str eq4_1;
neuper@42279
   315
neuper@42279
   316
val SOME (eq4_2,_) = rewrite_set_ @{theory Isac} false norm_Rational eq4_1;
neuper@42279
   317
term2str eq4_2;
neuper@42279
   318
neuper@42279
   319
val fmz = ["equality (3 = 3 * A / (4::real))", "solveFor A","solutions L"];
neuper@42279
   320
val (dI',pI',mI') =("Isac", ["univariate","equation"], ["no_met"]);
neuper@42279
   321
(*solve the simple linear equilation for A TODO: return eq, not list of eq*)
neuper@42279
   322
val (p,_,fa,nxt,_,pt) = CalcTreeTEST [(fmz, (dI',pI',mI'))];
neuper@42279
   323
val (p,_,fa,nxt,_,pt) = me nxt p [] pt;
neuper@42279
   324
val (p,_,fa,nxt,_,pt) = me nxt p [] pt;
neuper@42279
   325
val (p,_,fa,nxt,_,pt) = me nxt p [] pt;
neuper@42279
   326
val (p,_,fa,nxt,_,pt) = me nxt p [] pt;
neuper@42279
   327
val (p,_,fa,nxt,_,pt) = me nxt p [] pt;
neuper@42279
   328
val (p,_,fa,nxt,_,pt) = me nxt p [] pt;
neuper@42279
   329
val (p,_,fa,nxt,_,pt) = me nxt p [] pt;
neuper@42279
   330
val (p,_,fa,nxt,_,pt) = me nxt p [] pt;
neuper@42279
   331
val (p,_,fa,nxt,_,pt) = me nxt p [] pt;
neuper@42279
   332
val (p,_,fa,nxt,_,pt) = me nxt p [] pt;
neuper@42279
   333
val (p,_,fa,nxt,_,pt) = me nxt p [] pt;
neuper@42279
   334
val (p,_,fa,nxt,_,pt) = me nxt p [] pt;
neuper@42279
   335
val (p,_,fa,nxt,_,pt) = me nxt p [] pt;
neuper@42279
   336
val (p,_,fa,nxt,_,pt) = me nxt p [] pt;
neuper@42279
   337
val (p,_,fa,nxt,_,pt) = me nxt p [] pt;
neuper@42279
   338
val (p,_,fa,nxt,_,pt) = me nxt p [] pt;
neuper@42279
   339
val (p,_,fa,nxt,_,pt) = me nxt p [] pt;
neuper@42279
   340
val (p,_,fa,nxt,_,pt) = me nxt p [] pt;
neuper@42279
   341
val (p,_,fa,nxt,_,pt) = me nxt p [] pt;
neuper@42279
   342
val (p,_,fa,nxt,_,pt) = me nxt p [] pt;
neuper@42279
   343
val (p,_,fa,nxt,_,pt) = me nxt p [] pt;
neuper@42279
   344
val (p,_,fa,nxt,_,pt) = me nxt p [] pt;
neuper@42279
   345
val (p,_,fa,nxt,_,pt) = me nxt p [] pt;
neuper@42279
   346
val (p,_,fa,nxt,_,pt) = me nxt p [] pt;
neuper@42279
   347
val (p,_,fa,nxt,_,pt) = me nxt p [] pt;
neuper@42279
   348
val (p,_,fa,nxt,_,pt) = me nxt p [] pt;
neuper@42279
   349
val (p,_,fa,nxt,_,pt) = me nxt p [] pt; 
neuper@42279
   350
f2str fa;
neuper@42279
   351
*}
neuper@42279
   352
neuper@42279
   353
subsubsection {*get second koeffizient*}
neuper@42279
   354
ML {*thy*}
neuper@42279
   355
neuper@42279
   356
ML {*
neuper@42279
   357
(*substitude z with the second zeropoint to get B*)
neuper@42279
   358
val SOME (eq4b_1,_) = rewrite_terms_ @{theory Isac} e_rew_ord e_rls [s_2] eq3'';
neuper@42279
   359
term2str eq4b_1;
neuper@42279
   360
neuper@42279
   361
val SOME (eq4b_2,_) = rewrite_set_ @{theory Isac} false norm_Rational eq4b_1;
neuper@42279
   362
term2str eq4b_2;
neuper@42279
   363
*}
neuper@42279
   364
ML {*
neuper@42279
   365
(*solve the simple linear equilation for B TODO: return eq, not list of eq*)
neuper@42279
   366
val fmz = ["equality (3 = -3 * B / (4::real))", "solveFor B","solutions L"];
neuper@42279
   367
val (dI',pI',mI') =("Isac", ["univariate","equation"], ["no_met"]);
neuper@42279
   368
val (p,_,fb,nxt,_,pt) = CalcTreeTEST [(fmz, (dI',pI',mI'))];
neuper@42279
   369
val (p,_,fb,nxt,_,pt) = me nxt p [] pt;
neuper@42279
   370
val (p,_,fb,nxt,_,pt) = me nxt p [] pt;
neuper@42279
   371
val (p,_,fb,nxt,_,pt) = me nxt p [] pt;
neuper@42279
   372
val (p,_,fb,nxt,_,pt) = me nxt p [] pt;
neuper@42279
   373
val (p,_,fb,nxt,_,pt) = me nxt p [] pt;
neuper@42279
   374
val (p,_,fb,nxt,_,pt) = me nxt p [] pt;
neuper@42279
   375
val (p,_,fb,nxt,_,pt) = me nxt p [] pt;
neuper@42279
   376
val (p,_,fb,nxt,_,pt) = me nxt p [] pt;
neuper@42279
   377
val (p,_,fb,nxt,_,pt) = me nxt p [] pt;
neuper@42279
   378
val (p,_,fb,nxt,_,pt) = me nxt p [] pt;
neuper@42279
   379
val (p,_,fb,nxt,_,pt) = me nxt p [] pt;
neuper@42279
   380
val (p,_,fb,nxt,_,pt) = me nxt p [] pt;
neuper@42279
   381
val (p,_,fb,nxt,_,pt) = me nxt p [] pt;
neuper@42279
   382
val (p,_,fb,nxt,_,pt) = me nxt p [] pt;
neuper@42279
   383
val (p,_,fb,nxt,_,pt) = me nxt p [] pt;
neuper@42279
   384
val (p,_,fb,nxt,_,pt) = me nxt p [] pt;
neuper@42279
   385
val (p,_,fb,nxt,_,pt) = me nxt p [] pt;
neuper@42279
   386
val (p,_,fb,nxt,_,pt) = me nxt p [] pt;
neuper@42279
   387
val (p,_,fb,nxt,_,pt) = me nxt p [] pt;
neuper@42279
   388
val (p,_,fb,nxt,_,pt) = me nxt p [] pt;
neuper@42279
   389
val (p,_,fb,nxt,_,pt) = me nxt p [] pt;
neuper@42279
   390
val (p,_,fb,nxt,_,pt) = me nxt p [] pt;
neuper@42279
   391
val (p,_,fb,nxt,_,pt) = me nxt p [] pt;
neuper@42279
   392
val (p,_,fb,nxt,_,pt) = me nxt p [] pt;
neuper@42279
   393
val (p,_,fb,nxt,_,pt) = me nxt p [] pt;
neuper@42279
   394
val (p,_,fb,nxt,_,pt) = me nxt p [] pt;
neuper@42279
   395
val (p,_,fb,nxt,_,pt) = me nxt p [] pt; 
neuper@42279
   396
f2str fb;
neuper@42279
   397
*}
neuper@42279
   398
neuper@42279
   399
ML {* (*check koeffizients*)
neuper@42279
   400
if f2str fa = "[A = 4]" then () else error "part.fract. eq4_1";
neuper@42279
   401
if f2str fb = "[B = -4]" then () else error "part.fract. eq4_1";
neuper@42279
   402
*}
neuper@42279
   403
neuper@42279
   404
subsubsection {*substitute expression with solutions*}
neuper@42279
   405
ML {*
neuper@42279
   406
*}
neuper@42279
   407
ML {*thy*}
neuper@42279
   408
jan@42296
   409
section {*Implement the Specification and the Method \label{spec-meth}*}
neuper@42279
   410
text{*==============================================*}
neuper@42279
   411
subsection{*Define the Field Descriptions for the specification*}
neuper@42279
   412
consts
neuper@42279
   413
  filterExpression  :: "bool => una"
neuper@42279
   414
  stepResponse      :: "bool => una"
neuper@42279
   415
neuper@42279
   416
subsection{*Define the Specification*}
neuper@42279
   417
ML {*
neuper@42279
   418
store_pbt
neuper@42279
   419
 (prep_pbt thy "pbl_SP" [] e_pblID
neuper@42279
   420
 (["SignalProcessing"], [], e_rls, NONE, []));
neuper@42279
   421
store_pbt
neuper@42279
   422
 (prep_pbt thy "pbl_SP_Ztrans" [] e_pblID
neuper@42279
   423
 (["Z_Transform","SignalProcessing"], [], e_rls, NONE, []));
neuper@42279
   424
*}
neuper@42279
   425
ML {*thy*}
neuper@42279
   426
ML {*
neuper@42279
   427
store_pbt
neuper@42279
   428
 (prep_pbt thy "pbl_SP_Ztrans_inv" [] e_pblID
neuper@42279
   429
 (["inverse", "Z_Transform", "SignalProcessing"],
neuper@42279
   430
  [("#Given" ,["filterExpression X_eq"]),
neuper@42279
   431
   ("#Find"  ,["stepResponse n_eq"])
neuper@42279
   432
  ],
neuper@42279
   433
  append_rls "e_rls" e_rls [(*for preds in where_*)], NONE, 
neuper@42279
   434
  [["SignalProcessing","Z_Transform","inverse"]]));
neuper@42279
   435
neuper@42279
   436
show_ptyps();
neuper@42279
   437
get_pbt ["inverse","Z_Transform","SignalProcessing"];
neuper@42279
   438
*}
neuper@42279
   439
neuper@42279
   440
subsection {*Define Name and Signature for the Method*}
neuper@42279
   441
consts
neuper@42279
   442
  InverseZTransform :: "[bool, bool] => bool"
neuper@42279
   443
    ("((Script InverseZTransform (_ =))// (_))" 9)
neuper@42279
   444
neuper@42279
   445
subsection {*Setup Parent Nodes in Hierarchy of Method*}
neuper@42279
   446
ML {*
neuper@42279
   447
store_met
neuper@42279
   448
 (prep_met thy "met_SP" [] e_metID
neuper@42279
   449
 (["SignalProcessing"], [],
neuper@42279
   450
   {rew_ord'="tless_true", rls'= e_rls, calc = [], srls = e_rls, prls = e_rls,
neuper@42279
   451
    crls = e_rls, nrls = e_rls}, "empty_script"));
neuper@42279
   452
store_met
neuper@42279
   453
 (prep_met thy "met_SP_Ztrans" [] e_metID
neuper@42279
   454
 (["SignalProcessing", "Z_Transform"], [],
neuper@42279
   455
   {rew_ord'="tless_true", rls'= e_rls, calc = [], srls = e_rls, prls = e_rls,
neuper@42279
   456
    crls = e_rls, nrls = e_rls}, "empty_script"));
neuper@42279
   457
*}
neuper@42279
   458
ML {*
neuper@42279
   459
store_met
neuper@42279
   460
 (prep_met thy "met_SP_Ztrans_inv" [] e_metID
neuper@42279
   461
 (["SignalProcessing", "Z_Transform", "inverse"], 
neuper@42279
   462
  [("#Given" ,["filterExpression X_eq"]),
neuper@42279
   463
   ("#Find"  ,["stepResponse n_eq"])
neuper@42279
   464
  ],
neuper@42279
   465
   {rew_ord'="tless_true", rls'= e_rls, calc = [], srls = e_rls, prls = e_rls,
neuper@42279
   466
    crls = e_rls, nrls = e_rls},
neuper@42279
   467
  "empty_script"
neuper@42279
   468
 ));
neuper@42279
   469
*}
neuper@42279
   470
ML {*
neuper@42279
   471
store_met
neuper@42279
   472
 (prep_met thy "met_SP_Ztrans_inv" [] e_metID
neuper@42279
   473
 (["SignalProcessing", "Z_Transform", "inverse"], 
neuper@42279
   474
  [("#Given" ,["filterExpression X_eq"]),
neuper@42279
   475
   ("#Find"  ,["stepResponse n_eq"])
neuper@42279
   476
  ],
neuper@42279
   477
   {rew_ord'="tless_true", rls'= e_rls, calc = [], srls = e_rls, prls = e_rls,
neuper@42279
   478
    crls = e_rls, nrls = e_rls},
neuper@42279
   479
  "Script InverseZTransform (Xeq::bool) =" ^
neuper@42279
   480
  " (let X = Take Xeq;" ^
neuper@42279
   481
  "      X = Rewrite ruleZY False X" ^
neuper@42279
   482
  "  in X)"
neuper@42279
   483
 ));
jan@42299
   484
*}
jan@42299
   485
ML {*
neuper@42279
   486
show_mets();
jan@42299
   487
*}
jan@42299
   488
ML {*
neuper@42279
   489
get_met ["SignalProcessing","Z_Transform","inverse"];
neuper@42279
   490
*}
neuper@42279
   491
jan@42296
   492
section {*Program in CTP-based language \label{prog-steps}*}
neuper@42279
   493
text{*=================================*}
neuper@42279
   494
subsection {*Stepwise extend Program*}
neuper@42279
   495
ML {*
neuper@42279
   496
val str = 
neuper@42279
   497
"Script InverseZTransform (Xeq::bool) =" ^
neuper@42279
   498
" Xeq";
neuper@42279
   499
*}
neuper@42279
   500
ML {*
neuper@42279
   501
val str = 
neuper@42279
   502
"Script InverseZTransform (Xeq::bool) =" ^ (*(1/z) instead of z ^^^ -1*)
neuper@42279
   503
" (let X = Take Xeq;" ^
neuper@42279
   504
"      X' = Rewrite ruleZY False X;" ^ (*z * denominator*)
neuper@42279
   505
"      X' = (Rewrite_Set norm_Rational False) X'" ^ (*simplify*)
neuper@42279
   506
"  in X)";
neuper@42279
   507
(*NONE*)
neuper@42279
   508
"Script InverseZTransform (Xeq::bool) =" ^ (*(1/z) instead of z ^^^ -1*)
neuper@42279
   509
" (let X = Take Xeq;" ^
neuper@42279
   510
"      X' = Rewrite ruleZY False X;" ^ (*z * denominator*)
neuper@42279
   511
"      X' = (Rewrite_Set norm_Rational False) X';" ^ (*simplify*)
neuper@42279
   512
"      X' = (SubProblem (Isac',[pqFormula,degree_2,polynomial,univariate,equation], [no_met])   " ^
neuper@42279
   513
    "                 [BOOL e_e, REAL v_v])" ^
neuper@42279
   514
"  in X)";
neuper@42279
   515
*}
neuper@42279
   516
ML {*
neuper@42279
   517
val str = 
neuper@42279
   518
"Script InverseZTransform (Xeq::bool) =" ^ (*(1/z) instead of z ^^^ -1*)
neuper@42279
   519
" (let X = Take Xeq;" ^
neuper@42279
   520
"      X' = Rewrite ruleZY False X;" ^ (*z * denominator*)
neuper@42279
   521
"      X' = (Rewrite_Set norm_Rational False) X';" ^ (*simplify*)
neuper@42279
   522
"      funterm = rhs X'" ^ (*drop X'= for equation solving*)
neuper@42279
   523
"  in X)";
neuper@42279
   524
*}
neuper@42279
   525
ML {*
neuper@42290
   526
val str = 
neuper@42290
   527
"Script InverseZTransform (X_eq::bool) =" ^ (*(1/z) instead of z ^^^ -1*)
neuper@42290
   528
" (let X = Take X_eq;" ^
neuper@42290
   529
"      X' = Rewrite ruleZY False X;" ^ (*z * denominator*)
neuper@42290
   530
"      X' = (Rewrite_Set norm_Rational False) X';" ^ (*simplify*)
jan@42298
   531
"      (X'_z::real) = lhs X';" ^
jan@42298
   532
"      (z::real) = argument_in X'_z;" ^
jan@42298
   533
"      (funterm::real) = rhs X';" ^ (*drop X' z = for equation solving*)
jan@42298
   534
"      (denom::real) = get_denominator funterm;" ^ (*get_denominator*)
jan@42298
   535
"      (equ::bool) = (denom = (0::real));" ^
neuper@42290
   536
"      (L_L::bool list) =                                    " ^
neuper@42290
   537
"            (SubProblem (Test',                            " ^
neuper@42290
   538
"                         [linear,univariate,equation,test]," ^
neuper@42290
   539
"                         [Test,solve_linear])              " ^
neuper@42290
   540
"                        [BOOL equ, REAL z])              " ^
neuper@42290
   541
"  in X)"
neuper@42290
   542
;
neuper@42290
   543
neuper@42279
   544
parse thy str;
neuper@42279
   545
val sc = ((inst_abs thy) o term_of o the o (parse thy)) str;
neuper@42279
   546
atomty sc;
neuper@42279
   547
neuper@42279
   548
*}
jan@42300
   549
jan@42300
   550
text {*
jan@42300
   551
This ruleset contains all functions that are in the script; 
jan@42300
   552
The evaluation of the functions is done by rewriting using this ruleset.
jan@42300
   553
*}
jan@42300
   554
neuper@42279
   555
ML {*
neuper@42290
   556
val srls = Rls {id="srls_InverseZTransform", 
neuper@42290
   557
		  preconds = [], rew_ord = ("termlessI",termlessI), 
neuper@42290
   558
		  erls = append_rls "erls_in_srls_InverseZTransform" e_rls
neuper@42290
   559
				    [(*for asm in NTH_CONS ...*) Calc ("Orderings.ord_class.less",eval_equ "#less_"),
neuper@42290
   560
				     (*2nd NTH_CONS pushes n+-1 into asms*) Calc("Groups.plus_class.plus", eval_binop "#add_")
neuper@42290
   561
				    ], 
neuper@42290
   562
  srls = Erls, calc = [],
neuper@42290
   563
		  rules =
neuper@42290
   564
    [Thm ("NTH_CONS",num_str @{thm NTH_CONS}),
neuper@42290
   565
			     Calc("Groups.plus_class.plus", eval_binop "#add_"),
neuper@42290
   566
			     Thm ("NTH_NIL",num_str @{thm NTH_NIL}),
neuper@42290
   567
			     Calc("Tools.lhs", eval_lhs"eval_lhs_"), (*<=== ONLY USED*)
neuper@42290
   568
			     Calc("Tools.rhs", eval_rhs"eval_rhs_"), (*<=== ONLY USED*)
jan@42300
   569
			     Calc("Atools.argument'_in", eval_argument_in "Atools.argument'_in"),
neuper@42301
   570
     Calc("Rational.get_denominator",
neuper@42301
   571
       eval_get_denominator "Rational.get_denominator")
neuper@42290
   572
			    ],
neuper@42290
   573
		  scr = EmptyScr};
neuper@42279
   574
*}
neuper@42279
   575
neuper@42279
   576
neuper@42279
   577
subsection {*Store Final Version of Program for Execution*}
neuper@42279
   578
ML {*
neuper@42279
   579
store_met
neuper@42279
   580
 (prep_met thy "met_SP_Ztrans_inv" [] e_metID
neuper@42279
   581
 (["SignalProcessing", "Z_Transform", "inverse"], 
neuper@42279
   582
  [("#Given" ,["filterExpression X_eq"]),
neuper@42279
   583
   ("#Find"  ,["stepResponse n_eq"])
neuper@42279
   584
  ],
neuper@42290
   585
   {rew_ord'="tless_true", rls'= e_rls, calc = [], srls = srls, 
neuper@42290
   586
    prls = e_rls,
neuper@42279
   587
    crls = e_rls, nrls = e_rls},
neuper@42289
   588
"Script InverseZTransform (X_eq::bool) =" ^ (*(1/z) instead of z ^^^ -1*)
neuper@42289
   589
" (let X = Take X_eq;" ^
neuper@42279
   590
"      X' = Rewrite ruleZY False X;" ^ (*z * denominator*)
neuper@42279
   591
"      X' = (Rewrite_Set norm_Rational False) X';" ^ (*simplify*)
jan@42298
   592
"      (X'_z::real) = lhs X';" ^ (**)
neuper@42303
   593
"      (zzz::real) = argument_in X'_z;" ^ (**)
jan@42298
   594
"      (funterm::real) = rhs X';" ^ (*drop X' z = for equation solving*)
jan@42298
   595
"      (denom::real) = get_denominator funterm;" ^ (*get_denominator*)
jan@42298
   596
"      (equ::bool) = (denom = (0::real));" ^
neuper@42303
   597
neuper@42303
   598
"      (L_L::bool list) = (SubProblem (PolyEq'," ^
neuper@42315
   599
"          [abcFormula,degree_2,polynomial,univariate,equation],[no_met])" ^
neuper@42303
   600
"        [BOOL equ, REAL zzz])              " ^
neuper@42279
   601
"  in X)"
neuper@42279
   602
 ));
neuper@42279
   603
*}
neuper@42279
   604
neuper@42281
   605
subsection {*Check the Program*}
neuper@42279
   606
neuper@42281
   607
subsubsection {*Check the formalization*}
neuper@42279
   608
ML {*
neuper@42279
   609
val fmz = ["filterExpression (X  = 3 / (z - 1/4 + -1/8 * (1/(z::real))))", 
neuper@42279
   610
  "stepResponse (x[n::real]::bool)"];
neuper@42279
   611
val (dI,pI,mI) = ("Isac", ["inverse", "Z_Transform", "SignalProcessing"], 
neuper@42279
   612
  ["SignalProcessing","Z_Transform","inverse"]);
neuper@42281
   613
neuper@42281
   614
val ([(1, [1], "#Given", Const ("Inverse_Z_Transform.filterExpression", _),
neuper@42281
   615
            [Const ("HOL.eq", _) $ _ $ _]),
neuper@42281
   616
           (2, [1], "#Find", Const ("Inverse_Z_Transform.stepResponse", _),
neuper@42281
   617
            [Free ("x", _) $ _])],
neuper@42281
   618
          _) = prep_ori fmz thy ((#ppc o get_pbt) pI);
neuper@42281
   619
*}
neuper@42290
   620
ML {*
neuper@42290
   621
val Script sc = (#scr o get_met) ["SignalProcessing","Z_Transform","inverse"];
neuper@42290
   622
atomty sc;
neuper@42290
   623
*}
neuper@42281
   624
neuper@42281
   625
subsubsection {*Stepwise check the program*}
neuper@42281
   626
ML {*
neuper@42302
   627
trace_rewrite := false;
neuper@42306
   628
trace_script := false; print_depth 9;
neuper@42281
   629
val fmz = ["filterExpression (X z = 3 / (z - 1/4 + -1/8 * (1/(z::real))))", 
neuper@42281
   630
  "stepResponse (x[n::real]::bool)"];
neuper@42281
   631
val (dI,pI,mI) = ("Isac", ["inverse", "Z_Transform", "SignalProcessing"], 
neuper@42281
   632
  ["SignalProcessing","Z_Transform","inverse"]);
neuper@42310
   633
val (p,_,f,nxt,_,pt)  = CalcTreeTEST [(fmz, (dI,pI,mI))];
neuper@42310
   634
*}
neuper@42310
   635
ML {*
neuper@42303
   636
val (p,_,f,nxt,_,pt) = me nxt p [] pt; "Add_Given";
neuper@42303
   637
val (p,_,f,nxt,_,pt) = me nxt p [] pt; "Add_Find";
neuper@42303
   638
val (p,_,f,nxt,_,pt) = me nxt p [] pt; "Specify_Theory";
neuper@42303
   639
val (p,_,f,nxt,_,pt) = me nxt p [] pt; "Specify_Problem";
neuper@42303
   640
val (p,_,f,nxt,_,pt) = me nxt p [] pt; "Specify_Method";
jan@42296
   641
val (p,_,f,nxt,_,pt) = me nxt p [] pt; "nxt = Apply_Method";
jan@42297
   642
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))"; (*TODO naming!*)
jan@42296
   643
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@42315
   644
val (p,_,f,nxt,_,pt) = me nxt p [] pt; "nxt = SubProblem";
jan@42300
   645
*}
neuper@42305
   646
text {* Instead of nxt = Subproblem above we had Empty_Tac; the search for the reason 
neuper@42305
   647
  considered the following points:
neuper@42303
   648
  # what shows show_pt pt; ...
neuper@42303
   649
    (([2], Res), ?X' z = 24 / (-1 + -2 * z + 8 * z ^^^ 2))] ..calculation ok,
neuper@42303
   650
    but no "next" step found: should be "nxt = Subproblem" ?!?
neuper@42303
   651
  # what shows trace_script := true; we read bottom up ...
neuper@42303
   652
    @@@ next   leaf 'SubProbfrom
neuper@42303
   653
     (PolyEq', [abcFormula, degree_2, polynomial, univariate, equation],
neuper@42303
   654
      no_meth)
neuper@42303
   655
     [BOOL equ, REAL z]' ---> STac 'SubProblem
neuper@42303
   656
     (PolyEq', [abcFormula, degree_2, polynomial, univariate, equation],
neuper@42303
   657
      no_meth)
neuper@42303
   658
     [BOOL (-1 + -2 * z + 8 * z ^^^ 2 = 0), REAL z]'
neuper@42305
   659
    ... and see the SubProblem with correct arguments from searching next step
neuper@42305
   660
    (program text !!!--->!!! STac (script tactic) with arguments evaluated.)
neuper@42310
   661
  # do we have the right Script ...difference in the argumentsdifference in the arguments
neuper@42303
   662
    val Script s = (#scr o get_met) ["SignalProcessing","Z_Transform","inverse"];
neuper@42303
   663
    writeln (term2str s);
neuper@42310
   664
    ... shows the right script.difference in the arguments
neuper@42305
   665
  # test --- why helpless here ? --- shows: replace no_meth by [no_meth] in Script
neuper@42301
   666
*}
neuper@42315
   667
neuper@42301
   668
ML {*
neuper@42315
   669
val (p,_,f,nxt,_,pt) = me nxt p [] pt; "nxt = Model_Problem";
neuper@42306
   670
*}
neuper@42306
   671
text {* Instead of nxt = Model_Problem above we had Empty_Tac; the search for the reason 
neuper@42310
   672
  considered the following points:difference in the arguments
neuper@42306
   673
  # comparison with subsection { *solve equation* }: there solving this equation works,
neuper@42315
   674
    so there must be some difference in the arguments of the Subproblem:
neuper@42315
   675
    RIGHT: we had [no_meth] instead of [no_met] ;-))
neuper@42305
   676
*}
neuper@42305
   677
ML {*
neuper@42315
   678
val (p,_,f,nxt,_,pt) = me nxt p [] pt; "nxt = Add_Given equality (-1 + -2 * z + 8 * z ^^^ 2 = 0)";
neuper@42315
   679
val (p,_,f,nxt,_,pt) = me nxt p [] pt; "nxt = Add_Given solveFor z";
neuper@42315
   680
val (p,_,f,nxt,_,pt) = me nxt p [] pt; "nxt = Add_Find solutions z_i";
neuper@42315
   681
val (p,_,f,nxt,_,pt) = me nxt p [] pt; "nxt = Specify_Theory Isac";
neuper@42301
   682
*}
neuper@42315
   683
text {* We had "nxt = Empty_Tac instead Specify_Theory; 
neuper@42315
   684
  the search for the reason considered the following points:
neuper@42302
   685
  # was there an error message ? NO --ok
neuper@42302
   686
  # has "nxt = Add_Find" been inserted in pt: get_obj g_pbl pt (fst p); YES --ok
neuper@42302
   687
  # what is the returned "formula": print_depth 999; f; print_depth 999; --
neuper@42302
   688
    {Find = [Correct "solutions z_i"], With = [], 
neuper@42302
   689
     Given = [Correct "equality (-1 + -2 * z + 8 * z ^^^ 2 = 0)", Correct "solveFor z"],
neuper@42302
   690
     Where = [False "matches (z = 0) (-1 + -2 * z + 8 * z ^^^ 2 = 0) |\n
neuper@42302
   691
                     matches (?b * z = 0) (-1 + -2 * z + 8 * z ^^^ 2 = 0) |\n
neuper@42302
   692
                     matches (?a + z = 0) (-1 + -2 * z + 8 * z ^^^ 2 = 0) |\n
neuper@42302
   693
                     matches (?a + ?b * z = 0) (-1 + -2 * z + 8 * z ^^^ 2 = 0)"],
neuper@42302
   694
     Relate = []}
neuper@42302
   695
     -- the only False is the reason: the Where (the precondition) is False for good reasons:
neuper@42302
   696
     the precondition seems to check for linear equations, not for the one we want to solve!
neuper@42302
   697
  Removed this error by correcting the Script
neuper@42302
   698
  from SubProblem (PolyEq', [linear,univariate,equation,test], [Test,solve_linear]
neuper@42302
   699
  to   SubProblem (PolyEq', [abcFormula,degree_2,polynomial,univariate,equation],
neuper@42303
   700
                   [PolyEq,solve_d2_polyeq_abc_equation]
neuper@42302
   701
  You find the appropriate type of equation at
neuper@42302
   702
    http://www.ist.tugraz.at/projects/isac/www/kbase/pbl/index_pbl.html
neuper@42302
   703
  and the respective method in Knowledge/PolyEq.thy at the respective store_pbt.
neuper@42302
   704
  Or you leave the selection of the appropriate type to isac as done in the final Script ;-))
neuper@42302
   705
*}
neuper@42302
   706
ML {*
neuper@42315
   707
val (p,_,f,nxt,_,pt) = me nxt p [] pt; "nxt = Specify_Problem [abcFormula,...";
neuper@42315
   708
val (p,_,f,nxt,_,pt) = me nxt p [] pt; "nxt = Specify_Method [PolyEq,solve_d2_polyeq_abc_equation";
neuper@42315
   709
val (p,_,f,nxt,_,pt) = me nxt p [] pt; "nxt = Apply_Method [PolyEq,solve_d2_polyeq_abc_equation";
neuper@42315
   710
val (p,_,f,nxt,_,pt) = me nxt p [] pt; "nxt = Rewrite_Set_Inst ([(bdv, z)], d2_polyeq_abcFormula_simplify";
neuper@42289
   711
show_pt pt;
neuper@42279
   712
*}
neuper@42279
   713
ML {*
neuper@42279
   714
*}
neuper@42279
   715
ML {*
neuper@42279
   716
*}
neuper@42279
   717
ML {*
neuper@42279
   718
*}
neuper@42279
   719
neuper@42279
   720
neuper@42279
   721
section {*Write Tests for Crucial Details*}
neuper@42279
   722
text{*===================================*}
neuper@42279
   723
ML {*
neuper@42279
   724
neuper@42279
   725
*}
neuper@42279
   726
neuper@42279
   727
section {*Integrate Program into Knowledge*}
neuper@42279
   728
ML {*
neuper@42290
   729
@{theory Isac}
neuper@42279
   730
*}
neuper@42279
   731
neuper@42279
   732
end
neuper@42279
   733